git @ Cat's Eye Technologies SixtyPical / 26448cc
More access of word tables. Game works with a word table now! Cat's Eye Technologies 8 years ago
5 changed file(s) with 131 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
227227 = .space locs_lo 4
228228 = .space locs_hi 4
229229
230 Copy command: byte -> indexed word table -> error.
231
232 | reserve byte bbb
233 | reserve word[4] locs
234 | routine main {
235 | ldx #0
236 | copy bbb locs, x
237 | }
238 ? incompatible types 'Byte' and 'Table Word 4'
239
240 Copy command: byte -> low byte of indexed word table
241
242 | reserve byte bbb
243 | reserve word[4] locs
244 | routine main {
245 | ldx #0
246 | copy bbb <locs, x
247 | }
248 = main:
249 = ldx #0
250 = lda bbb
251 = sta locs_lo, x
252 = rts
253 =
254 = .data
255 = .space bbb 1
256 = .space locs_lo 4
257 = .space locs_hi 4
258
259 Copy command: byte -> high byte of indexed word table
260
261 | reserve byte bbb
262 | reserve word[4] locs
263 | routine main {
264 | ldx #0
265 | copy bbb >locs, x
266 | }
267 = main:
268 = ldx #0
269 = lda bbb
270 = sta locs_hi, x
271 = rts
272 =
273 = .data
274 = .space bbb 1
275 = .space locs_lo 4
276 = .space locs_hi 4
277
278 Copy command: low byte of indexed word table -> byte
279
280 | reserve byte bbb
281 | reserve word[4] locs
282 | routine main {
283 | ldx #0
284 | copy <locs, x bbb
285 | }
286 = main:
287 = ldx #0
288 = lda locs_lo, x
289 = sta bbb
290 = rts
291 =
292 = .data
293 = .space bbb 1
294 = .space locs_lo 4
295 = .space locs_hi 4
296
297 Copy command: high byte of indexed word table -> byte
298
299 | reserve byte bbb
300 | reserve word[4] locs
301 | routine main {
302 | ldx #0
303 | copy >locs, x bbb
304 | }
305 = main:
306 = ldx #0
307 = lda locs_hi, x
308 = sta bbb
309 = rts
310 =
311 = .data
312 = .space bbb 1
313 = .space locs_lo 4
314 = .space locs_hi 4
315
230316 `main` is always emitted first.
231317
232318 | reserve word position
136136 }
137137
138138 routine init_game {
139 // this shouldn't be needed!
140 reserve byte temp_a
139141 ldy #0
140142 repeat bne {
141143 lda #$04
142 // *** this is broken ***
143 sta >actor_pos, y
144 sta temp_a
145 copy temp_a >actor_pos, y
144146 tya
145147 clc
146148 asl .a
147149 asl .a
148 sta <actor_pos, y
150 sta temp_a
151 copy temp_a <actor_pos, y
149152 iny
150153 cpy #8
151154 }
104104 emitInstr p r (COPY (NamedLocation (Just st1) src) (Indexed (NamedLocation (Just (Table st2 _)) dst) reg))
105105 | (st1 == Vector && st2 == Vector) || (st1 == Word && st2 == Word) =
106106 "lda " ++ src ++ "\n" ++
107 " sta " ++ dst ++ "_lo, " ++ r ++ "\n" ++
107 " sta " ++ dst ++ "_lo, " ++ (regName reg) ++ "\n" ++
108108 " lda " ++ src ++ "+1\n" ++
109 " sta " ++ dst ++ "_hi, " ++ r
110 where
111 r = case reg of
112 X -> "x"
113 Y -> "y"
109 " sta " ++ dst ++ "_hi, " ++ (regName reg)
110
111 emitInstr p r (COPY (NamedLocation (Just Byte) src)
112 (LowByteOf (Indexed (NamedLocation (Just (Table Word _)) dst) reg))) =
113 "lda " ++ src ++ "\n" ++
114 " sta " ++ dst ++ "_lo, " ++ (regName reg)
115
116 emitInstr p r (COPY (NamedLocation (Just Byte) src)
117 (HighByteOf (Indexed (NamedLocation (Just (Table Word _)) dst) reg))) =
118 "lda " ++ src ++ "\n" ++
119 " sta " ++ dst ++ "_hi, " ++ (regName reg)
120
121 emitInstr p r (COPY (LowByteOf (Indexed (NamedLocation (Just (Table Word _)) src) reg))
122 (NamedLocation (Just Byte) dst)) =
123 "lda " ++ src ++ "_lo, " ++ (regName reg) ++ "\n" ++
124 " sta " ++ dst
125
126 emitInstr p r (COPY (HighByteOf (Indexed (NamedLocation (Just (Table Word _)) src) reg))
127 (NamedLocation (Just Byte) dst)) =
128 "lda " ++ src ++ "_hi, " ++ (regName reg) ++ "\n" ++
129 " sta " ++ dst
114130
115131 emitInstr p r (COPY (Indexed (NamedLocation (Just (Table st1 _)) src) reg) (NamedLocation (Just st2) dst))
116132 | (st1 == Vector && st2 == Vector) || (st1 == Word && st2 == Word) =
117 "lda " ++ src ++ "_lo, " ++ r ++ "\n" ++
133 "lda " ++ src ++ "_lo, " ++ (regName reg) ++ "\n" ++
118134 " sta " ++ dst ++ "\n" ++
119 " lda " ++ src ++ "_hi, " ++ r ++ "\n" ++
135 " lda " ++ src ++ "_hi, " ++ (regName reg) ++ "\n" ++
120136 " sta " ++ dst ++ "+1"
121 where
122 r = case reg of
123 X -> "x"
124 Y -> "y"
125137
126138 emitInstr p r (COPY A (IndirectIndexed (NamedLocation st label) Y)) = "sta (" ++ label ++ "), y"
127139 emitInstr p r (COPY (IndirectIndexed (NamedLocation st label) Y) A) = "lda (" ++ label ++ "), y"
238250 "Internal error: sixtypical doesn't know how to " ++
239251 "emit assembler code for '" ++ (show i) ++ "'")
240252
253
254 regName X = "x"
255 regName Y = "y"
575575 string "copy"
576576 nspaces
577577
578 src <- (try immediate <|> try direct_location)
578 src <- (immediate <|>
579 low_byte_of_absolute <|> high_byte_of_absolute <|> direct_location)
579580 srcI <- many index
580581 lhs <- return $ case (src, srcI) of
581582 ((Immediately s), []) -> (Immediate s)
582583 ((Directly s), []) -> (NamedLocation Nothing s)
583584 ((Directly s), [reg]) -> (Indexed (NamedLocation Nothing s) reg)
584
585 dst <- direct_location
585 ((LowBytely s), [reg]) -> (LowByteOf (Indexed (NamedLocation Nothing s) reg))
586 ((HighBytely s), [reg]) -> (HighByteOf (Indexed (NamedLocation Nothing s) reg))
587
588 dst <- (low_byte_of_absolute <|> high_byte_of_absolute <|> direct_location)
586589 dstI <- many index
587590 rhs <- return $ case (dst, dstI) of
588591 ((Directly d), []) -> (NamedLocation Nothing d)
589592 ((Directly d), [reg]) -> (Indexed (NamedLocation Nothing d) reg)
593 ((LowBytely d), [reg]) -> (LowByteOf (Indexed (NamedLocation Nothing d) reg))
594 ((HighBytely d), [reg]) -> (HighByteOf (Indexed (NamedLocation Nothing d) reg))
590595
591596 return $ COPY lhs rhs
592597
143143 (Indexed (resolve loc) (resolve reg))
144144 resolve (IndirectIndexed loc reg) =
145145 (IndirectIndexed (resolve loc) (resolve reg))
146 resolve (LowByteOf loc) =
147 (LowByteOf (resolve loc))
148 resolve (HighByteOf loc) =
149 (HighByteOf (resolve loc))
146150 resolve other =
147151 other
148152