Uninitialized `reserve`d storage becomes .space in .data segment.
Cat's Eye Technologies
9 years ago
124 | 124 | * Initial values for reserved tables |
125 | 125 | * give length for tables, must be there for reserved, if no init val |
126 | 126 | * Character tables ("strings" to everybody else) |
127 | * Put uninitialized `reserve`d data in uninitialized data segment | |
128 | 127 | * Addressing modes — indexed mode on more instructions |
129 | 128 | * `jsr (vector)` |
130 | 129 | * `jmp routine` |
30 | 30 | = sta screen |
31 | 31 | = rts |
32 | 32 | = |
33 | = .data | |
33 | 34 | = .alias screen 1024 |
34 | 35 | |
35 | 36 | Emitting a `repeat`. |
56 | 57 | = sty screen |
57 | 58 | = rts |
58 | 59 | = |
60 | = four: .byte 4 | |
61 | = .data | |
59 | 62 | = .alias screen 1024 |
60 | = four: .byte 4 | |
61 | 63 | |
62 | 64 | Nested ifs. |
63 | 65 | |
130 | 132 | = jmp (save_cinv) |
131 | 133 | = rts |
132 | 134 | = |
135 | = .data | |
133 | 136 | = .alias screen 1024 |
134 | 137 | = .alias cinv 788 |
135 | = save_cinv: .word 0 | |
138 | = .space save_cinv 2 | |
136 | 139 | |
137 | 140 | Copy command: immediate -> byte |
138 | 141 | |
145 | 148 | = sta position |
146 | 149 | = rts |
147 | 150 | = |
148 | = position: .byte 0 | |
151 | = .data | |
152 | = .space position 1 | |
149 | 153 | |
150 | 154 | Copy command: immediate -> word |
151 | 155 | |
160 | 164 | = sta position+1 |
161 | 165 | = rts |
162 | 166 | = |
163 | = position: .word 0 | |
167 | = .data | |
168 | = .space position 2 | |
164 | 169 | |
165 | 170 | `main` is always emitted first. |
166 | 171 | |
181 | 186 | = inx |
182 | 187 | = rts |
183 | 188 | = |
184 | = position: .word 0 | |
189 | = .data | |
190 | = .space position 2 |
255 | 255 | = ora vbyte |
256 | 256 | = rts |
257 | 257 | = |
258 | = vword: .word 0 | |
259 | = vbyte: .byte 0 | |
258 | = .data | |
259 | = .space vword 2 | |
260 | = .space vbyte 1 | |
260 | 261 | = .alias table 1024 |
261 | 262 | |
262 | 263 | | reserve word vword |
289 | 290 | = eor vbyte |
290 | 291 | = rts |
291 | 292 | = |
292 | = vword: .word 0 | |
293 | = vbyte: .byte 0 | |
293 | = .data | |
294 | = .space vword 2 | |
295 | = .space vbyte 1 | |
294 | 296 | = .alias table 1024 |
295 | 297 | |
296 | 298 | | routine main { |
0 | 0 | .org 0 |
1 | 1 | .word $0801 |
2 | .data | |
3 | .org $c000 | |
4 | .text | |
2 | 5 | .org $0801 |
3 | 6 | .byte $10, $08, $c9, $07, $9e, $32, $30, $36, $31, $00, $00, $00 |
9 | 9 | let |
10 | 10 | mains = filter (\(Routine name _ _) -> name == "main") routines |
11 | 11 | allElse = filter (\(Routine name _ _) -> name /= "main") routines |
12 | initializedDecls = filter (\d -> isInitializedDecl d) decls | |
13 | uninitializedDecls = filter (\d -> not $ isInitializedDecl d) decls | |
12 | 14 | in |
13 | 15 | emitRoutines p mains ++ |
14 | 16 | emitRoutines p allElse ++ |
15 | emitDecls p decls | |
17 | emitDecls p initializedDecls ++ | |
18 | (case uninitializedDecls of | |
19 | [] -> "" | |
20 | _ -> ".data\n" ++ emitDecls p uninitializedDecls) | |
16 | 21 | |
17 | 22 | emitDecls _ [] = "" |
18 | 23 | emitDecls p (decl:decls) = |
19 | 24 | emitDecl p decl ++ "\n" ++ emitDecls p decls |
20 | 25 | |
21 | 26 | 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" | |
30 | 36 | |
31 | 37 | emitDecl p (External name addr) = ".alias " ++ name ++ " " ++ (show addr) |
32 | 38 | emitDecl p d = error ( |
101 | 101 | isLocationDecl (Reserve _ _ _) = True |
102 | 102 | isLocationDecl _ = False |
103 | 103 | |
104 | isInitializedDecl (Assign _ _ _) = False | |
105 | isInitializedDecl (Reserve _ _ (Just _)) = True | |
106 | isInitializedDecl (Reserve _ _ Nothing) = False | |
107 | ||
104 | 108 | declaredLocationNames (Program decls _) = |
105 | 109 | map (getDeclLocationName) (filter (isLocationDecl) decls) |
106 | 110 |