git @ Cat's Eye Technologies SixtyPical / 4cceb05
Immediate mode versions of ldx, ldy, cmp, cpx, cpy. Cat's Eye Technologies 8 years ago
5 changed file(s) with 37 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
143143
144144 clv
145145
146 cmp #immediate
146147 cmp absolute
147 X cmp #immediate
148
148
149 cpx #immediate
149150 cpx absolute
150 X cpx #immediate
151
151
152 cpy #immediate
152153 cpy absolute
153 X cpy #immediate
154154
155155 dec absolute
156156
171171
172172 * jsr routine
173173
174 lda #immediate
174175 lda absolute
175 X lda #immediate
176
176
177 ldx #immediate
177178 ldx absolute
178 X ldx #immediate
179
179
180 ldy #immediate
180181 ldy absolute
181 X ldy #immediate
182182
183183 X lsr
184184 X lsr absolute
338338 | assign word screen 1024
339339 | routine main {
340340 | lda #4
341 | ldx #0
342 | ldy #255
341343 | lda screen
342344 | inc screen
343345 | tax
349351 | dey
350352 | sty score
351353 | cmp score
354 | cmp #30
352355 | ldx score
353356 | cpx screen
357 | cpx #31
354358 | txa
355359 | ldy score
356360 | cpy screen
361 | cpy #32
357362 | tya
358363 | sta screen
359364 | dec screen
372377 = .alias screen 1024
373378 = main:
374379 = lda #4
380 = ldx #0
381 = ldy #255
375382 = lda screen
376383 = inc screen
377384 = tax
383390 = dey
384391 = sty score
385392 = cmp score
393 = cmp #30
386394 = ldx score
387395 = cpx screen
396 = cpx #31
388397 = txa
389398 = ldy score
390399 = cpy screen
400 = cpy #32
391401 = tya
392402 = sta screen
393403 = dec screen
00 assign byte screen 1024
1 reserve byte zero
21 routine main {
3 ldy zero
2 ldy #0
43 repeat bne {
54 inc screen
65 dey
7 cpy zero
6 cpy #0
87 }
98 sty screen
109 }
5555 emitInstr p r (CMP X (NamedLocation label)) = "cpx " ++ label
5656 emitInstr p r (CMP Y (NamedLocation label)) = "cpy " ++ label
5757
58 emitInstr p r (CMPIMM A val) = "cmp #" ++ (show val)
59 emitInstr p r (CMPIMM X val) = "cpx #" ++ (show val)
60 emitInstr p r (CMPIMM Y val) = "cpy #" ++ (show val)
61
5862 emitInstr p r (DELTA X 1) = "inx"
5963 emitInstr p r (DELTA X (-1)) = "dex"
6064 emitInstr p r (DELTA Y 1) = "iny"
5050
5151 data Instruction = LOADIMM StorageLocation DataValue
5252 | COPY StorageLocation StorageLocation
53 | CMPIMM StorageLocation DataValue
5354 | CMP StorageLocation StorageLocation
5455 | JSR RoutineName
5556 | IF Branch [Instruction] [Instruction]
167167 cmp = do
168168 string "cmp"
169169 spaces
170 l <- locationName
171 return (CMP A (NamedLocation l))
170 (try $ immediate (\v -> CMPIMM A v) <|>
171 absolute (\l -> CMP A (NamedLocation l)))
172172
173173 cpx :: Parser Instruction
174174 cpx = do
175175 string "cpx"
176176 spaces
177 l <- locationName
178 return (CMP X (NamedLocation l))
177 (try $ immediate (\v -> CMPIMM X v) <|>
178 absolute (\l -> CMP X (NamedLocation l)))
179179
180180 cpy :: Parser Instruction
181181 cpy = do
182182 string "cpy"
183183 spaces
184 l <- locationName
185 return (CMP Y (NamedLocation l))
184 (try $ immediate (\v -> CMPIMM Y v) <|>
185 absolute (\l -> CMP Y (NamedLocation l)))
186186
187187 immediate :: (DataValue -> Instruction) -> Parser Instruction
188188 immediate f = do
206206 ldx = do
207207 string "ldx"
208208 spaces
209 l <- locationName
210 return (COPY (NamedLocation l) X)
209 (try $ immediate (\v -> LOADIMM X v) <|>
210 absolute (\l -> COPY (NamedLocation l) X))
211211
212212 ldy :: Parser Instruction
213213 ldy = do
214214 string "ldy"
215215 spaces
216 l <- locationName
217 return (COPY (NamedLocation l) Y)
216 (try $ immediate (\v -> LOADIMM Y v) <|>
217 absolute (\l -> COPY (NamedLocation l) Y))
218218
219219 sta :: Parser Instruction
220220 sta = do