Incrementing and decrementing.
Cat's Eye Technologies
11 years ago
49 | 49 |
emitInstr p r (CMP X (NamedLocation label)) = "cpx " ++ label
|
50 | 50 |
emitInstr p r (CMP Y (NamedLocation label)) = "cpy " ++ label
|
51 | 51 |
|
|
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 |
|
52 | 59 |
emitInstr p r (COPY A X) = "tax"
|
53 | 60 |
emitInstr p r (COPY A Y) = "tay"
|
54 | 61 |
emitInstr p r (COPY X A) = "txa"
|
53 | 53 |
| CMP StorageLocation StorageLocation
|
54 | 54 |
| JSR RoutineName
|
55 | 55 |
| IF Branch [Instruction] [Instruction]
|
|
56 |
| DELTA StorageLocation DataValue
|
56 | 57 |
| NOP
|
57 | 58 |
deriving (Show, Ord, Eq)
|
58 | 59 |
|
20 | 20 |
| "cmp" (LocationName | Immediate)
|
21 | 21 |
| "cpx" (LocationName | Immediate)
|
22 | 22 |
| "cpy" (LocationName | Immediate)
|
|
23 |
| "inx" | "iny" | "dex" | "dey"
|
23 | 24 |
| "nop".
|
24 | 25 |
Branch := "bcc" | "bcs" | "beq" | "bmi" | "bne" | "bpl" | "bvc" | "bvs".
|
25 | 26 |
|
|
79 | 80 |
(try sta) <|> (try stx) <|> (try sty) <|>
|
80 | 81 |
(try txa) <|> (try tax) <|> (try tya) <|> (try tay) <|>
|
81 | 82 |
(try cmp) <|> (try cpx) <|> (try cpy) <|>
|
|
83 |
(try inx) <|> (try iny) <|> (try dex) <|> (try dey) <|>
|
|
84 |
(try inc) <|> (try dec) <|>
|
82 | 85 |
if_statement <|> nop
|
83 | 86 |
|
84 | 87 |
nop :: Parser Instruction
|
|
86 | 89 |
string "nop"
|
87 | 90 |
spaces
|
88 | 91 |
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))
|
89 | 130 |
|
90 | 131 |
cmp :: Parser Instruction
|
91 | 132 |
cmp = do
|