mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-02-16 15:30:26 +00:00
Immediate and absolute parser helper parser combinators.
This commit is contained in:
parent
e268c550b5
commit
54f7fe34ef
@ -246,6 +246,7 @@ TODO
|
|||||||
* number ifs and repeats
|
* number ifs and repeats
|
||||||
* `repeat jmp`
|
* `repeat jmp`
|
||||||
* Addressing modes; rename instructions to match
|
* Addressing modes; rename instructions to match
|
||||||
|
* no two routines with same name
|
||||||
|
|
||||||
Tests
|
Tests
|
||||||
-----
|
-----
|
||||||
@ -275,7 +276,7 @@ Tests
|
|||||||
A program may reserve and assign.
|
A program may reserve and assign.
|
||||||
|
|
||||||
| reserve word score
|
| reserve word score
|
||||||
| assign word screen 4000
|
| assign word screen 1024
|
||||||
| routine main {
|
| routine main {
|
||||||
| lda screen
|
| lda screen
|
||||||
| tax
|
| tax
|
||||||
@ -308,7 +309,7 @@ All locations used in all routines must be declared first.
|
|||||||
Even in inner blocks.
|
Even in inner blocks.
|
||||||
|
|
||||||
| reserve word score
|
| reserve word score
|
||||||
| assign word screen 4000
|
| assign word screen 1024
|
||||||
| routine main {
|
| routine main {
|
||||||
| lda score
|
| lda score
|
||||||
| cmp screen
|
| cmp screen
|
||||||
@ -335,8 +336,9 @@ No duplicate declarations.
|
|||||||
-> shell command "bin/sixtypical emit %(test-file)"
|
-> shell command "bin/sixtypical emit %(test-file)"
|
||||||
|
|
||||||
| reserve word score
|
| reserve word score
|
||||||
| assign word screen 4000
|
| assign word screen 1024
|
||||||
| routine main {
|
| routine main {
|
||||||
|
| lda #4
|
||||||
| lda screen
|
| lda screen
|
||||||
| inc screen
|
| inc screen
|
||||||
| tax
|
| tax
|
||||||
@ -368,8 +370,9 @@ No duplicate declarations.
|
|||||||
= .byte $10, $08, $c9, $07, $9e, $32, $30, $36, $31, $00, $00, $00
|
= .byte $10, $08, $c9, $07, $9e, $32, $30, $36, $31, $00, $00, $00
|
||||||
= jmp main
|
= jmp main
|
||||||
= score: .word 0
|
= score: .word 0
|
||||||
= .alias screen 4000
|
= .alias screen 1024
|
||||||
= main:
|
= main:
|
||||||
|
= lda #4
|
||||||
= lda screen
|
= lda screen
|
||||||
= inc screen
|
= inc screen
|
||||||
= tax
|
= tax
|
||||||
@ -396,7 +399,7 @@ No duplicate declarations.
|
|||||||
= sed
|
= sed
|
||||||
= rts
|
= rts
|
||||||
|
|
||||||
| assign word screen 4000
|
| assign word screen 1024
|
||||||
| routine main {
|
| routine main {
|
||||||
| lda screen
|
| lda screen
|
||||||
| cmp screen
|
| cmp screen
|
||||||
@ -412,7 +415,7 @@ No duplicate declarations.
|
|||||||
= .org $0801
|
= .org $0801
|
||||||
= .byte $10, $08, $c9, $07, $9e, $32, $30, $36, $31, $00, $00, $00
|
= .byte $10, $08, $c9, $07, $9e, $32, $30, $36, $31, $00, $00, $00
|
||||||
= jmp main
|
= jmp main
|
||||||
= .alias screen 4000
|
= .alias screen 1024
|
||||||
= main:
|
= main:
|
||||||
= lda screen
|
= lda screen
|
||||||
= cmp screen
|
= cmp screen
|
||||||
@ -425,7 +428,7 @@ No duplicate declarations.
|
|||||||
= sta screen
|
= sta screen
|
||||||
= rts
|
= rts
|
||||||
|
|
||||||
| assign byte screen 4000
|
| assign byte screen 1024
|
||||||
| reserve byte zero
|
| reserve byte zero
|
||||||
| routine main {
|
| routine main {
|
||||||
| ldy zero
|
| ldy zero
|
||||||
@ -441,7 +444,7 @@ No duplicate declarations.
|
|||||||
= .org $0801
|
= .org $0801
|
||||||
= .byte $10, $08, $c9, $07, $9e, $32, $30, $36, $31, $00, $00, $00
|
= .byte $10, $08, $c9, $07, $9e, $32, $30, $36, $31, $00, $00, $00
|
||||||
= jmp main
|
= jmp main
|
||||||
= .alias screen 4000
|
= .alias screen 1024
|
||||||
= zero: .byte 0
|
= zero: .byte 0
|
||||||
= main:
|
= main:
|
||||||
= ldy zero
|
= ldy zero
|
||||||
|
@ -77,8 +77,11 @@ block = do
|
|||||||
spaces
|
spaces
|
||||||
return cs
|
return cs
|
||||||
|
|
||||||
|
--command = (try lda_imm) <|> (try lda) <|>
|
||||||
|
|
||||||
command :: Parser Instruction
|
command :: Parser Instruction
|
||||||
command = (try lda) <|> (try ldx) <|> (try ldy) <|>
|
command = (try lda) <|>
|
||||||
|
(try ldx) <|> (try ldy) <|>
|
||||||
(try sta) <|> (try stx) <|> (try sty) <|>
|
(try sta) <|> (try stx) <|> (try sty) <|>
|
||||||
(try txa) <|> (try tax) <|> (try tya) <|> (try tay) <|>
|
(try txa) <|> (try tax) <|> (try tya) <|> (try tay) <|>
|
||||||
(try cmp) <|> (try cpx) <|> (try cpy) <|>
|
(try cmp) <|> (try cpx) <|> (try cpy) <|>
|
||||||
@ -182,12 +185,23 @@ cpy = do
|
|||||||
l <- locationName
|
l <- locationName
|
||||||
return (CMP Y (NamedLocation l))
|
return (CMP Y (NamedLocation l))
|
||||||
|
|
||||||
|
immediate :: (DataValue -> Instruction) -> Parser Instruction
|
||||||
|
immediate f = do
|
||||||
|
string "#"
|
||||||
|
v <- data_value
|
||||||
|
return $ f v
|
||||||
|
|
||||||
|
absolute :: (LocationName -> Instruction) -> Parser Instruction
|
||||||
|
absolute f = do
|
||||||
|
l <- locationName
|
||||||
|
return $ f l
|
||||||
|
|
||||||
lda :: Parser Instruction
|
lda :: Parser Instruction
|
||||||
lda = do
|
lda = do
|
||||||
string "lda"
|
string "lda"
|
||||||
spaces
|
spaces
|
||||||
l <- locationName
|
(try $ immediate (\v -> LOADIMM A v) <|>
|
||||||
return (COPY (NamedLocation l) A)
|
absolute (\l -> COPY (NamedLocation l) A))
|
||||||
|
|
||||||
ldx :: Parser Instruction
|
ldx :: Parser Instruction
|
||||||
ldx = do
|
ldx = do
|
||||||
@ -298,6 +312,12 @@ address = do
|
|||||||
spaces
|
spaces
|
||||||
return (read digits :: Address)
|
return (read digits :: Address)
|
||||||
|
|
||||||
|
data_value :: Parser DataValue
|
||||||
|
data_value = do
|
||||||
|
digits <- many digit
|
||||||
|
spaces
|
||||||
|
return (read digits :: DataValue)
|
||||||
|
|
||||||
-- -- -- driver -- -- --
|
-- -- -- driver -- -- --
|
||||||
|
|
||||||
parseProgram = parse toplevel ""
|
parseProgram = parse toplevel ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user