1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-07 22:29:27 +00:00

Immediate mode versions of ldx, ldy, cmp, cpx, cpy.

This commit is contained in:
Cat's Eye Technologies 2014-04-01 18:34:41 +01:00
parent 54f7fe34ef
commit 4cceb05256
5 changed files with 33 additions and 19 deletions

View File

@ -144,14 +144,14 @@ In these, `absolute` must be a `reserve`d or `locate`d address.
clv
cmp #immediate
cmp absolute
X cmp #immediate
cpx #immediate
cpx absolute
X cpx #immediate
cpy #immediate
cpy absolute
X cpy #immediate
dec absolute
@ -172,14 +172,14 @@ In these, `absolute` must be a `reserve`d or `locate`d address.
* jsr routine
lda #immediate
lda absolute
X lda #immediate
ldx #immediate
ldx absolute
X ldx #immediate
ldy #immediate
ldy absolute
X ldy #immediate
X lsr
X lsr absolute
@ -339,6 +339,8 @@ No duplicate declarations.
| assign word screen 1024
| routine main {
| lda #4
| ldx #0
| ldy #255
| lda screen
| inc screen
| tax
@ -350,11 +352,14 @@ No duplicate declarations.
| dey
| sty score
| cmp score
| cmp #30
| ldx score
| cpx screen
| cpx #31
| txa
| ldy score
| cpy screen
| cpy #32
| tya
| sta screen
| dec screen
@ -373,6 +378,8 @@ No duplicate declarations.
= .alias screen 1024
= main:
= lda #4
= ldx #0
= ldy #255
= lda screen
= inc screen
= tax
@ -384,11 +391,14 @@ No duplicate declarations.
= dey
= sty score
= cmp score
= cmp #30
= ldx score
= cpx screen
= cpx #31
= txa
= ldy score
= cpy screen
= cpy #32
= tya
= sta screen
= dec screen

View File

@ -1,11 +1,10 @@
assign byte screen 1024
reserve byte zero
routine main {
ldy zero
ldy #0
repeat bne {
inc screen
dey
cpy zero
cpy #0
}
sty screen
}

View File

@ -56,6 +56,10 @@ emitInstr p r (CMP A (NamedLocation label)) = "cmp " ++ label
emitInstr p r (CMP X (NamedLocation label)) = "cpx " ++ label
emitInstr p r (CMP Y (NamedLocation label)) = "cpy " ++ label
emitInstr p r (CMPIMM A val) = "cmp #" ++ (show val)
emitInstr p r (CMPIMM X val) = "cpx #" ++ (show val)
emitInstr p r (CMPIMM Y val) = "cpy #" ++ (show val)
emitInstr p r (DELTA X 1) = "inx"
emitInstr p r (DELTA X (-1)) = "dex"
emitInstr p r (DELTA Y 1) = "iny"

View File

@ -51,6 +51,7 @@ data Branch = BCC | BCS | BEQ | BMI | BNE | BPL | BVC | BVS
data Instruction = LOADIMM StorageLocation DataValue
| COPY StorageLocation StorageLocation
| CMPIMM StorageLocation DataValue
| CMP StorageLocation StorageLocation
| JSR RoutineName
| IF Branch [Instruction] [Instruction]

View File

@ -168,22 +168,22 @@ cmp :: Parser Instruction
cmp = do
string "cmp"
spaces
l <- locationName
return (CMP A (NamedLocation l))
(try $ immediate (\v -> CMPIMM A v) <|>
absolute (\l -> CMP A (NamedLocation l)))
cpx :: Parser Instruction
cpx = do
string "cpx"
spaces
l <- locationName
return (CMP X (NamedLocation l))
(try $ immediate (\v -> CMPIMM X v) <|>
absolute (\l -> CMP X (NamedLocation l)))
cpy :: Parser Instruction
cpy = do
string "cpy"
spaces
l <- locationName
return (CMP Y (NamedLocation l))
(try $ immediate (\v -> CMPIMM Y v) <|>
absolute (\l -> CMP Y (NamedLocation l)))
immediate :: (DataValue -> Instruction) -> Parser Instruction
immediate f = do
@ -207,15 +207,15 @@ ldx :: Parser Instruction
ldx = do
string "ldx"
spaces
l <- locationName
return (COPY (NamedLocation l) X)
(try $ immediate (\v -> LOADIMM X v) <|>
absolute (\l -> COPY (NamedLocation l) X))
ldy :: Parser Instruction
ldy = do
string "ldy"
spaces
l <- locationName
return (COPY (NamedLocation l) Y)
(try $ immediate (\v -> LOADIMM Y v) <|>
absolute (\l -> COPY (NamedLocation l) Y))
sta :: Parser Instruction
sta = do