git @ Cat's Eye Technologies SixtyPical / d1521af
Incrementing and decrementing. Cat's Eye Technologies 11 years ago
4 changed file(s) with 73 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
176176 cpy absolute
177177 X cpy #immediate
178178
179 X dec absolute
180
181 X dex
182
183 X dey
179 dec absolute
180
181 dex
182
183 dey
184184
185185 X eor #immediate
186186 X eor absolute
187187
188 X inc absolute
189
190 X inx
191
192 X iny
188 inc absolute
189
190 inx
191
192 iny
193193
194194 ! jmp
195195
266266 * External routines
267267 * Work out the analyses again and document them
268268 * parse support immediate loads, compares
269 * number ifs and repeats
270 * hello, world sort of program
269271 * Addressing modes; rename instructions to match
270272
271273 Tests
359361 | assign word screen 4000
360362 | routine main {
361363 | lda screen
364 | inc screen
362365 | tax
366 | inx
367 | dex
363368 | stx score
364369 | tay
370 | iny
371 | dey
365372 | sty score
366373 | cmp score
367374 | ldx score
371378 | cpy screen
372379 | tya
373380 | sta screen
381 | dec screen
374382 | }
375383 = .org 0
376384 = .word $0801
381389 = .alias screen 4000
382390 = main:
383391 = lda screen
392 = inc screen
384393 = tax
394 = inx
395 = dex
385396 = stx score
386397 = tay
398 = iny
399 = dey
387400 = sty score
388401 = cmp score
389402 = ldx score
393406 = cpy screen
394407 = tya
395408 = sta screen
409 = dec screen
396410 = rts
397411
398412 | assign word screen 4000
4949 emitInstr p r (CMP X (NamedLocation label)) = "cpx " ++ label
5050 emitInstr p r (CMP Y (NamedLocation label)) = "cpy " ++ label
5151
52 emitInstr p r (DELTA X 1) = "inx"
53 emitInstr p r (DELTA X (-1)) = "dex"
54 emitInstr p r (DELTA Y 1) = "iny"
55 emitInstr p r (DELTA Y (-1)) = "dey"
56 emitInstr p r (DELTA (NamedLocation label) 1) = "inc " ++ label
57 emitInstr p r (DELTA (NamedLocation label) (-1)) = "dec " ++ label
58
5259 emitInstr p r (COPY A X) = "tax"
5360 emitInstr p r (COPY A Y) = "tay"
5461 emitInstr p r (COPY X A) = "txa"
5353 | CMP StorageLocation StorageLocation
5454 | JSR RoutineName
5555 | IF Branch [Instruction] [Instruction]
56 | DELTA StorageLocation DataValue
5657 | NOP
5758 deriving (Show, Ord, Eq)
5859
2020 | "cmp" (LocationName | Immediate)
2121 | "cpx" (LocationName | Immediate)
2222 | "cpy" (LocationName | Immediate)
23 | "inx" | "iny" | "dex" | "dey"
2324 | "nop".
2425 Branch := "bcc" | "bcs" | "beq" | "bmi" | "bne" | "bpl" | "bvc" | "bvs".
2526
7980 (try sta) <|> (try stx) <|> (try sty) <|>
8081 (try txa) <|> (try tax) <|> (try tya) <|> (try tay) <|>
8182 (try cmp) <|> (try cpx) <|> (try cpy) <|>
83 (try inx) <|> (try iny) <|> (try dex) <|> (try dey) <|>
84 (try inc) <|> (try dec) <|>
8285 if_statement <|> nop
8386
8487 nop :: Parser Instruction
8689 string "nop"
8790 spaces
8891 return NOP
92
93 inx :: Parser Instruction
94 inx = do
95 string "inx"
96 spaces
97 return $ DELTA X 1
98
99 iny :: Parser Instruction
100 iny = do
101 string "iny"
102 spaces
103 return $ DELTA Y 1
104
105 dex :: Parser Instruction
106 dex = do
107 string "dex"
108 spaces
109 return $ DELTA X (-1)
110
111 dey :: Parser Instruction
112 dey = do
113 string "dey"
114 spaces
115 return $ DELTA Y (-1)
116
117 inc :: Parser Instruction
118 inc = do
119 string "inc"
120 spaces
121 l <- locationName
122 return (DELTA (NamedLocation l) 1)
123
124 dec :: Parser Instruction
125 dec = do
126 string "dec"
127 spaces
128 l <- locationName
129 return (DELTA (NamedLocation l) (-1))
89130
90131 cmp :: Parser Instruction
91132 cmp = do