git @ Cat's Eye Technologies SixtyPical / c8ddbd8
Uninitialized `reserve`d storage becomes .space in .data segment. Cat's Eye Technologies 7 years ago
6 changed file(s) with 39 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
124124 * Initial values for reserved tables
125125 * give length for tables, must be there for reserved, if no init val
126126 * Character tables ("strings" to everybody else)
127 * Put uninitialized `reserve`d data in uninitialized data segment
128127 * Addressing modes — indexed mode on more instructions
129128 * `jsr (vector)`
130129 * `jmp routine`
3030 = sta screen
3131 = rts
3232 =
33 = .data
3334 = .alias screen 1024
3435
3536 Emitting a `repeat`.
5657 = sty screen
5758 = rts
5859 =
60 = four: .byte 4
61 = .data
5962 = .alias screen 1024
60 = four: .byte 4
6163
6264 Nested ifs.
6365
130132 = jmp (save_cinv)
131133 = rts
132134 =
135 = .data
133136 = .alias screen 1024
134137 = .alias cinv 788
135 = save_cinv: .word 0
138 = .space save_cinv 2
136139
137140 Copy command: immediate -> byte
138141
145148 = sta position
146149 = rts
147150 =
148 = position: .byte 0
151 = .data
152 = .space position 1
149153
150154 Copy command: immediate -> word
151155
160164 = sta position+1
161165 = rts
162166 =
163 = position: .word 0
167 = .data
168 = .space position 2
164169
165170 `main` is always emitted first.
166171
181186 = inx
182187 = rts
183188 =
184 = position: .word 0
189 = .data
190 = .space position 2
255255 = ora vbyte
256256 = rts
257257 =
258 = vword: .word 0
259 = vbyte: .byte 0
258 = .data
259 = .space vword 2
260 = .space vbyte 1
260261 = .alias table 1024
261262
262263 | reserve word vword
289290 = eor vbyte
290291 = rts
291292 =
292 = vword: .word 0
293 = vbyte: .byte 0
293 = .data
294 = .space vword 2
295 = .space vbyte 1
294296 = .alias table 1024
295297
296298 | routine main {
00 .org 0
11 .word $0801
2 .data
3 .org $c000
4 .text
25 .org $0801
36 .byte $10, $08, $c9, $07, $9e, $32, $30, $36, $31, $00, $00, $00
99 let
1010 mains = filter (\(Routine name _ _) -> name == "main") routines
1111 allElse = filter (\(Routine name _ _) -> name /= "main") routines
12 initializedDecls = filter (\d -> isInitializedDecl d) decls
13 uninitializedDecls = filter (\d -> not $ isInitializedDecl d) decls
1214 in
1315 emitRoutines p mains ++
1416 emitRoutines p allElse ++
15 emitDecls p decls
17 emitDecls p initializedDecls ++
18 (case uninitializedDecls of
19 [] -> ""
20 _ -> ".data\n" ++ emitDecls p uninitializedDecls)
1621
1722 emitDecls _ [] = ""
1823 emitDecls p (decl:decls) =
1924 emitDecl p decl ++ "\n" ++ emitDecls p decls
2025
2126 emitDecl p (Assign name _ addr) = ".alias " ++ name ++ " " ++ (show addr)
22 emitDecl p (Reserve name typ value)
23 | typ == Byte = name ++ ": .byte " ++ val
24 | typ == Word = name ++ ": .word " ++ val
25 | typ == Vector = name ++ ": .word " ++ val
26 where
27 val = case value of
28 (Just v) -> (show v)
29 Nothing -> "0"
27 emitDecl p (Reserve name typ (Just val))
28 | typ == Byte = name ++ ": .byte " ++ (show val)
29 | typ == Word = name ++ ": .word " ++ (show val)
30 | typ == Vector = name ++ ": .word " ++ (show val)
31
32 emitDecl p (Reserve name typ Nothing)
33 | typ == Byte = ".space " ++ name ++ " 1"
34 | typ == Word = ".space " ++ name ++ " 2"
35 | typ == Vector = ".space " ++ name ++ " 2"
3036
3137 emitDecl p (External name addr) = ".alias " ++ name ++ " " ++ (show addr)
3238 emitDecl p d = error (
101101 isLocationDecl (Reserve _ _ _) = True
102102 isLocationDecl _ = False
103103
104 isInitializedDecl (Assign _ _ _) = False
105 isInitializedDecl (Reserve _ _ (Just _)) = True
106 isInitializedDecl (Reserve _ _ Nothing) = False
107
104108 declaredLocationNames (Program decls _) =
105109 map (getDeclLocationName) (filter (isLocationDecl) decls)
106110