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

Support most of the rest of the instructions.

This commit is contained in:
Cat's Eye Technologies 2014-04-03 17:57:30 +01:00
parent de414ee714
commit 55a5ee85e3
6 changed files with 84 additions and 291 deletions

View File

@ -172,147 +172,6 @@ that has a natural symmetrical opcode (e.g. `pha`, `sei`). These instructions
take a block. The natural symmetrical opcode is inserted at the end of the
block.
Unsupported Opcodes
-------------------
6502 opcodes with no language-level equivalent instructions in SixtyPical
are `brk`, `cli`, `pla`, `plp`, `rti`, `rts`, `tsx`, `txs`. These may be
inserted into the output program as a SixtyPical → 6502 compiler sees fit,
however.
Note to self, the `pl` opcodes *do* change flags.
Instruction Support so far
--------------------------
A `X` indicates unsupported.
Funny syntax indicates use of a special form.
In these, `absolute` must be a `reserve`d or `locate`d address.
`immediate` must be a literal decimal or hexadecimal number
(or in future, a declared constant.)
.
adc #immediate
adc absolute
and #immediate
and absolute
X asl
X asl absolute
if bcc { block } else { block }
if bcs { block } else { block }
if beq { block } else { block }
X bit absolute
if bmi { block } else { block }
if bne { block } else { block }
if bpl { block } else { block }
if bvc { block } else { block }
if bvs { block } else { block }
clc
cld
clv
cmp #immediate
cmp absolute
cpx #immediate
cpx absolute
cpy #immediate
cpy absolute
dec absolute
dex
dey
X eor #immediate
X eor absolute
inc absolute
inx
iny
* jsr routine
X jsr vector
X jmp routine
* jmp vector
lda #immediate
lda absolute
lda absolute, x
lda absolute, y
lda (absolute), y
ldx #immediate
ldx absolute
ldy #immediate
ldy absolute
X lsr
X lsr absolute
nop
ora #immediate
ora absolute
X pha { block }
X php { block }
X rol
X rol absolute
X ror
X ror absolute
sbc #immediate
sbc absolute
sec
sed
sei { block }
sta absolute
sta absolute, x
sta absolute, y
sta (absolute), y
stx absolute
sty absolute
tax
tay
txa
tya
TODO
----

View File

@ -6,154 +6,6 @@ Emitting Ophis from SixtyPical Programs
-> Functionality "Emit ASM for SixtyPical program" is implemented by
-> shell command "bin/sixtypical emit %(test-file)"
Big test for parsing and emitting instructions.
| reserve word vword
| reserve byte vbyte
| assign byte table table 1024
| routine main {
| lda #4
| ldx #0
| ldy #$FF
| lda vbyte
| lda table, x
| lda table, y
| lda (vword), y
| lda <vword
| lda >vword
| inc vbyte
| tax
| inx
| dex
| stx vbyte
| tay
| iny
| dey
| sty vbyte
| cmp vbyte
| cmp #30
| cmp <vword
| cmp >vword
| ldx vbyte
| cpx vbyte
| cpx #31
| txa
| ldy vbyte
| cpy vbyte
| cpy #32
| tya
| sta vbyte
| sta table, x
| sta table, y
| sta (vword), y
| sta <vword
| sta >vword
| dec vbyte
| clc
| cld
| clv
| sec
| sed
| adc #8
| adc vbyte
| and #8
| and vbyte
| sbc #8
| sbc vbyte
| ora #8
| ora vbyte
| }
= main:
= lda #4
= ldx #0
= ldy #255
= lda vbyte
= lda table, x
= lda table, y
= lda (vword), y
= lda vword
= lda vword+1
= inc vbyte
= tax
= inx
= dex
= stx vbyte
= tay
= iny
= dey
= sty vbyte
= cmp vbyte
= cmp #30
= cmp vword
= cmp vword+1
= ldx vbyte
= cpx vbyte
= cpx #31
= txa
= ldy vbyte
= cpy vbyte
= cpy #32
= tya
= sta vbyte
= sta table, x
= sta table, y
= sta (vword), y
= sta vword
= sta vword+1
= dec vbyte
= clc
= cld
= clv
= sec
= sed
= adc #8
= adc vbyte
= and #8
= and vbyte
= sbc #8
= sbc vbyte
= ora #8
= ora vbyte
= rts
=
= vword: .word 0
= vbyte: .byte 0
= .alias table 1024
| reserve word vword
| reserve byte vbyte
| assign byte table table 1024
| routine main {
| asl
| asl vbyte
| lsr
| lsr vbyte
| rol
| rol vbyte
| ror
| ror vbyte
| bit vbyte
| eor #5
| eor vbyte
| }
= main:
= asl
= asl vbyte
= lsr
= lsr vbyte
= rol
= rol vbyte
= ror
= ror vbyte
= bit vbyte
= eor #5
= eor vbyte
= rts
=
= vword: .word 0
= vbyte: .byte 0
= .alias table 1024
Emitting an `if`.
| assign byte screen $0400

View File

@ -95,6 +95,20 @@ emitInstr p r (SUB A (Immediate val)) = "sbc #" ++ (show val)
emitInstr p r (OR A (NamedLocation st label)) = "ora " ++ label
emitInstr p r (OR A (Immediate val)) = "ora #" ++ (show val)
emitInstr p r (XOR A (NamedLocation st label)) = "eor " ++ label
emitInstr p r (XOR A (Immediate val)) = "eor #" ++ (show val)
emitInstr p r (SHL A (Immediate 0)) = "asl"
emitInstr p r (SHL (NamedLocation st label) (Immediate 0)) = "asl " ++ label
emitInstr p r (SHR A (Immediate 0)) = "lsr"
emitInstr p r (SHR (NamedLocation st label) (Immediate 0)) = "lsr " ++ label
emitInstr p r (SHL A FlagC) = "rol"
emitInstr p r (SHL (NamedLocation st label) FlagC) = "rol " ++ label
emitInstr p r (SHR A FlagC) = "ror"
emitInstr p r (SHR (NamedLocation st label) FlagC) = "ror " ++ label
emitInstr p r (BIT (NamedLocation st label)) = "bit " ++ label
emitInstr p r (DELTA X 1) = "inx"
emitInstr p r (DELTA X (-1)) = "dex"
emitInstr p r (DELTA Y 1) = "iny"

View File

@ -66,6 +66,10 @@ data Instruction = COPY StorageLocation StorageLocation
| AND StorageLocation StorageLocation
| SUB StorageLocation StorageLocation
| OR StorageLocation StorageLocation
| XOR StorageLocation StorageLocation
| SHL StorageLocation StorageLocation
| SHR StorageLocation StorageLocation
| BIT StorageLocation
| JSR RoutineName
-- | JSRVECTOR StorageLocation
| JMPVECTOR StorageLocation

View File

@ -126,6 +126,7 @@ data AddressingModality = Directly LocationName
| LowBytely LocationName
| Indirectly LocationName
| Immediately DataValue
| Implicitly StorageLocation
deriving (Ord, Show, Eq)
low_byte_of_absolute :: Parser AddressingModality
@ -154,6 +155,12 @@ direct_location = do
l <- locationName
return $ Directly l
register_location :: Parser AddressingModality
register_location = do
string "@" --- ARGH
spaces
return $ Implicitly A
immediate :: Parser AddressingModality
immediate = do
string "#"
@ -164,7 +171,7 @@ addressing_mode :: (AddressingModality -> [StorageLocation] -> Instruction) -> P
addressing_mode f = do
d <- ((try immediate) <|> (try high_byte_of_absolute) <|>
(try low_byte_of_absolute) <|> (try indirect_location) <|>
direct_location)
(try register_location) <|> (try direct_location))
indexes <- many index
return $ f d indexes
@ -172,6 +179,8 @@ commented_command :: Parser Instruction
commented_command = do
c <- command
optional comment
-- string "\n" -- not yet...
-- spaces
return c
command :: Parser Instruction
@ -185,6 +194,8 @@ command = (try lda) <|>
(try clc) <|> (try cld) <|> (try clv) <|> (try sec) <|> (try sed) <|>
(try adc) <|> (try SixtyPical.Parser.and) <|>
(try sbc) <|> (try ora) <|>
(try asl) <|> (try bit) <|> (try eor) <|> (try lsr) <|>
(try rol) <|> (try ror) <|>
(try sei) <|>
(try jmp) <|> (try jsr) <|>
(try copy_vector_statement) <|>
@ -197,6 +208,42 @@ nop = do
spaces
return NOP
asl :: Parser Instruction
asl = do
string "asl"
spaces
addressing_mode gen
where
gen (Implicitly A) [] = SHL A (Immediate 0)
gen (Directly l) [] = SHL (NamedLocation Nothing l) (Immediate 0)
lsr :: Parser Instruction
lsr = do
string "lsr"
spaces
addressing_mode gen
where
gen (Implicitly A) [] = SHR A (Immediate 0)
gen (Directly l) [] = SHR (NamedLocation Nothing l) (Immediate 0)
rol :: Parser Instruction
rol = do
string "rol"
spaces
addressing_mode gen
where
gen (Implicitly A) [] = SHL A FlagC
gen (Directly l) [] = SHL (NamedLocation Nothing l) FlagC
ror :: Parser Instruction
ror = do
string "ror"
spaces
addressing_mode gen
where
gen (Implicitly A) [] = SHR A FlagC
gen (Directly l) [] = SHR (NamedLocation Nothing l) FlagC
clc :: Parser Instruction
clc = do
string "clc"
@ -334,6 +381,23 @@ ora = do
gen (Immediately v) [] = OR A (Immediate v)
gen (Directly l) [] = OR A (NamedLocation Nothing l)
eor :: Parser Instruction
eor = do
string "eor"
spaces
addressing_mode gen
where
gen (Immediately v) [] = XOR A (Immediate v)
gen (Directly l) [] = XOR A (NamedLocation Nothing l)
bit :: Parser Instruction
bit = do
string "bit"
spaces
addressing_mode gen
where
gen (Directly l) [] = BIT (NamedLocation Nothing l)
lda :: Parser Instruction
lda = do
string "lda"

View File

@ -1,4 +1,4 @@
#!/bin/sh
FILES="doc/Checking.markdown doc/Emitting.markdown"
FILES="doc/Checking.markdown doc/Emitting.markdown doc/Instruction_Support.markdown"
./build.sh && falderal --substring-error ${FILES}