mirror of
https://github.com/catseye/SixtyPical.git
synced 2024-11-22 01:32:13 +00:00
Parse more instructions.
This commit is contained in:
parent
b15411c677
commit
4cef193da9
@ -70,11 +70,13 @@ An address knows if it is an address of a byte, of a word, or of a table.
|
|||||||
|
|
||||||
### Blocks ###
|
### Blocks ###
|
||||||
|
|
||||||
Each routine is a block. It may be composed of inner blocks.
|
Each routine is a block. It may be composed of inner blocks, attached to
|
||||||
|
some instructions.
|
||||||
|
|
||||||
SixtyPical does not have instructions that map literally to the 6502 branch
|
SixtyPical does not have instructions that map literally to the 6502 branch
|
||||||
instructions. Instead, each branch instruction has a corresponding
|
instructions. Instead, each branch instruction has a corresponding
|
||||||
"if-then-else"-like construct with the same name as the branch.
|
"if-then-else"-like construct with the same name as the branch instruction.
|
||||||
|
These _test_ instructions each have two blocks, for the then and the else.
|
||||||
|
|
||||||
The abstract states of the machine at each of the different block exits are
|
The abstract states of the machine at each of the different block exits are
|
||||||
merged during analysis. If any register or memory location is treated
|
merged during analysis. If any register or memory location is treated
|
||||||
@ -82,6 +84,23 @@ inconsistently (e.g. updated in one branch of the test, but not the other,)
|
|||||||
that register cannot subsequently be used without a declaration to the effect
|
that register cannot subsequently be used without a declaration to the effect
|
||||||
that we know what's going on. (This is all a bit fuzzy right now.)
|
that we know what's going on. (This is all a bit fuzzy right now.)
|
||||||
|
|
||||||
|
There is also no `rts` instruction. It is included at the end of a routine,
|
||||||
|
but only when the routine is used as a subroutine.
|
||||||
|
|
||||||
|
There are also _with_ instructions, which are associated with an opcode
|
||||||
|
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.
|
||||||
|
|
||||||
|
TODO
|
||||||
|
----
|
||||||
|
|
||||||
|
* Parse HEX values like $40A3
|
||||||
|
* Full machine model
|
||||||
|
* Check before analyzing
|
||||||
|
* Check, analyze, generate
|
||||||
|
* Addressing modes; rename instructions to match
|
||||||
|
|
||||||
Tests
|
Tests
|
||||||
-----
|
-----
|
||||||
|
|
||||||
@ -113,7 +132,13 @@ A program may reserve and assign.
|
|||||||
| assign word screen 4000
|
| assign word screen 4000
|
||||||
| routine main {
|
| routine main {
|
||||||
| lda screen
|
| lda screen
|
||||||
|
| tax
|
||||||
|
| tay
|
||||||
| cmp score
|
| cmp score
|
||||||
|
| ldx score
|
||||||
|
| txa
|
||||||
|
| ldy score
|
||||||
|
| tya
|
||||||
| }
|
| }
|
||||||
= True
|
= True
|
||||||
|
|
||||||
|
@ -15,8 +15,11 @@ Routine := "routine" RoutineName Block.
|
|||||||
Block := "{" {Command} "}".
|
Block := "{" {Command} "}".
|
||||||
Command := "beq" Block "else" Block
|
Command := "beq" Block "else" Block
|
||||||
| "lda" (LocationName | Immediate)
|
| "lda" (LocationName | Immediate)
|
||||||
|
| "ldx" (LocationName | Immediate)
|
||||||
|
| "ldy" (LocationName | Immediate)
|
||||||
| "txa" | "tax" | "tya" | "tay"
|
| "txa" | "tax" | "tya" | "tay"
|
||||||
| "cmp" (LocationName | Immediate)
|
| "cmp" (LocationName | Immediate)
|
||||||
|
| "nop".
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
@ -70,7 +73,9 @@ block = do
|
|||||||
return cs
|
return cs
|
||||||
|
|
||||||
command :: Parser Instruction
|
command :: Parser Instruction
|
||||||
command = cmp <|> lda <|> beq <|> nop
|
command = cmp <|> (try lda) <|> (try ldx) <|> (try ldy) <|>
|
||||||
|
(try txa) <|> (try tax) <|> (try tya) <|> (try tay) <|>
|
||||||
|
beq <|> nop
|
||||||
|
|
||||||
nop :: Parser Instruction
|
nop :: Parser Instruction
|
||||||
nop = do
|
nop = do
|
||||||
@ -92,6 +97,44 @@ lda = do
|
|||||||
l <- locationName
|
l <- locationName
|
||||||
return (LOAD A l)
|
return (LOAD A l)
|
||||||
|
|
||||||
|
ldx :: Parser Instruction
|
||||||
|
ldx = do
|
||||||
|
string "ldx"
|
||||||
|
spaces
|
||||||
|
l <- locationName
|
||||||
|
return (LOAD X l)
|
||||||
|
|
||||||
|
ldy :: Parser Instruction
|
||||||
|
ldy = do
|
||||||
|
string "ldy"
|
||||||
|
spaces
|
||||||
|
l <- locationName
|
||||||
|
return (LOAD Y l)
|
||||||
|
|
||||||
|
txa :: Parser Instruction
|
||||||
|
txa = do
|
||||||
|
string "txa"
|
||||||
|
spaces
|
||||||
|
return (COPY X A)
|
||||||
|
|
||||||
|
tax :: Parser Instruction
|
||||||
|
tax = do
|
||||||
|
string "tax"
|
||||||
|
spaces
|
||||||
|
return (COPY A X)
|
||||||
|
|
||||||
|
tya :: Parser Instruction
|
||||||
|
tya = do
|
||||||
|
string "tya"
|
||||||
|
spaces
|
||||||
|
return (COPY Y A)
|
||||||
|
|
||||||
|
tay :: Parser Instruction
|
||||||
|
tay = do
|
||||||
|
string "tay"
|
||||||
|
spaces
|
||||||
|
return (COPY A Y)
|
||||||
|
|
||||||
beq :: Parser Instruction
|
beq :: Parser Instruction
|
||||||
beq = do
|
beq = do
|
||||||
string "beq"
|
string "beq"
|
||||||
|
Loading…
Reference in New Issue
Block a user