1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-02 03:41:28 +00:00

Fix up spec, split off to 6502 opcodes doc, add some tests.

This commit is contained in:
Chris Pressey 2015-10-16 19:15:01 +01:00
parent 4fc38be387
commit 4d61f439bc
4 changed files with 260 additions and 124 deletions

View File

@ -25,14 +25,11 @@ Documentation
* [SixtyPical specification](doc/SixtyPical.md)
* [Literate test suite for SixtyPical execution](tests/SixtyPical Execution.md)
* [Literate test suite for SixtyPical analysis](tests/SixtyPical Analysis.md)
* [6502 Opcodes used/not used in SixtyPical](doc/6502 Opcodes.md)
TODO
----
For 0.2:
* write a few more tests and clean up spec a bit.
For 0.3:
* extern routines.

115
doc/6502 Opcodes.md Normal file
View File

@ -0,0 +1,115 @@
6502 Opcodes
============
As used or unused in SixtyPical.
### ld ###
ld a, 123 → LDA #123
ld a, lives → LDA LIVES
ld x, 123 → LDX #123
ld x, lives → LDX LIVES
ld y, 123 → LDY #123
ld y, lives → LDY LIVES
ld x, a → TAX
ld y, a → TAY
ld a, x → TXA
ld a, y → TYA
### st ###
st a, lives → STA LIVES
st x, lives → STX LIVES
st y, lives → STY LIVES
st on, c → SEC
st off, c → CLC
### add dest, src ###
add a, delta → ADC DELTA
add a, 1 → ADC #1
### inc ###
inc x → INX
inc y → INY
inc lives → INC LIVES
### sub ###
sub a, delta → SBC DELTA
sub a, 1 → SBC #1
### dec ###
dec x → DEX
dec y → DEY
dec lives → DEC LIVES
### cmp ###
cmp a, delta → CMP DELTA
cmp a, 1 → CMP #1
cmp x, 1 → CPX #1
cmp y, 1 → CPY #1
### and, or, xor ###
and a, 8 → AND #8
or a, 8 → ORA #8
xor a, 8 → EOR #8
### shl, shr ###
shl <dest-memory-location>
shr <dest-memory-location>
shl a → ROL A
shl lives → ROL LIVES
shr a → ROR A
shr lives → ROR LIVES
### call ###
call routine → JSR ROUTINE
### if ###
if z → BEQ LABEL
if not z → BNE LABEL
if n → BMI LABEL
if not n → BPL LABEL
if c → BCS LABEL
if not c → BCC LABEL
if v → BVS LABEL
if not v → BVC LABEL
### 6502 instructions unsupported ###
ASL Shift Left One Bit (Memory or Accumulator)
LSR Shift Right One Bit (Memory or Accumulator)
BIT Test Bits in Memory with Accumulator
BRK Force Break
CLD Clear Decimal Mode
CLI Clear interrupt Disable Bit
CLV Clear Overflow Flag
NOP No Operation
JMP Jump to New Location // but may be generated as part of `if`
PHA Push Accumulator on Stack
PHP Push Processor Status on Stack
PLA Pull Accumulator from Stack
PLP Pull Processor Status from Stack
RTI Return from Interrupt
RTS Return from Subroutine
SED Set Decimal Mode
SEI Set Interrupt Disable Status
TSX Transfer Stack Pointer to Index X
TXS Transfer Index X to Stack Pointer

View File

@ -8,6 +8,9 @@ these are, technically speaking, separate concepts.)
This document is nominally normative, but the tests in the `tests` directory
are even more normative.
Refer to the bottom of this document for an EBNF grammar of the syntax of
the language.
Types
-----
@ -122,19 +125,6 @@ are considered initialized after it has executed.
Some combinations, such as `ld x, y`, are illegal because they do not map to
underlying opcodes.
Notes:
ld a, 123 → LDA #123
ld a, lives → LDA LIVES
ld x, 123 → LDX #123
ld x, lives → LDX LIVES
ld y, 123 → LDY #123
ld y, lives → LDY LIVES
ld x, a → TAX
ld y, a → TAY
ld a, x → TXA
ld a, y → TYA
### st ###
st <src-memory-location>, <dest-memory-location>
@ -150,14 +140,6 @@ Reads from src and writes to dest.
After execution, dest is considered initialized. No flags are
changed by this instruction (unless of course dest is a flag.)
Notes:
st a, lives → STA LIVES
st x, lives → STX LIVES
st y, lives → STY LIVES
st on, c → SEC
st off, c → CLC
### add dest, src ###
add <dest-memory-location>, <src-memory-location>
@ -174,11 +156,6 @@ and initializing them afterwards.
dest and src continue to be initialized afterwards.
Notes:
add a, delta → ADC DELTA
add a, 1 → ADC #1
### inc ###
inc <dest-memory-location>
@ -193,12 +170,6 @@ Increments the value in dest. Does not honour carry.
Affects n and z flags, requiring that they be in the WRITES lists,
and initializing them afterwards.
Notes:
inc x → INX
inc y → INY
inc lives → INC LIVES
### sub ###
sub <dest-memory-location>, <src-memory-location>
@ -215,14 +186,9 @@ and initializing them afterwards.
dest and src continue to be initialized afterwards.
Notes:
sub a, delta → SBC DELTA
sub a, 1 → SBC #1
### dec ###
inc <dest-memory-location>
dec <dest-memory-location>
Decrements the value in dest. Does not honour carry.
@ -234,30 +200,18 @@ Decrements the value in dest. Does not honour carry.
Affects n and z flags, requiring that they be in the WRITES lists,
and initializing them afterwards.
Notes:
dec x → DEX
dec y → DEY
dec lives → DEC LIVES
### cmp ###
cmp <dest-memory-location>, <src-memory-location>
Subtracts the contents of src from dest, but does not store the result.
Subtracts the contents of src from dest (without considering carry) but
does not store the result anywhere, only sets the resulting flags.
* It is illegal if src OR dest is uninitialized.
Affects n, z, and c flags, requiring that they be in the WRITES lists,
and initializing them afterwards.
Notes:
cmp a, delta → CMP DELTA
cmp a, 1 → CMP #1
cmp x, 1 → CPX #1
cmp y, 1 → CPY #1
### and, or, xor ###
and <dest-memory-location>, <src-memory-location>
@ -277,12 +231,6 @@ current routine, and sets them as initialized afterwards.
dest and src continue to be initialized afterwards.
Notes:
and a, 8 → AND #8
or a, 8 → ORA #8
xor a, 8 → EOR #8
### shl, shr ###
shl <dest-memory-location>
@ -303,13 +251,6 @@ and `c` becomes the bit that was shifted off the right.
Affects the c flag, requiring that it be in the WRITES lists of the
current routine, and it continues to be initialized afterwards.
Notes:
shl a → ROL A
shl lives → ROL LIVES
shr a → ROR A
shr lives → ROR LIVES
### call ###
call <routine-name>
@ -326,35 +267,22 @@ Just after the call,
* All memory locations listed as TRASHED in the called routine's OUTPUTS
list are considered initialized.
Notes:
call routine → JSR ROUTINE
- - - -
### if ###
if (bit) {
true-branch
if <src-memory-location> {
<true-branch>
} else {
false-branch
<false-branch>
}
_bit_ is usually one of the flags, z or c.
Executes the true-branch if the value in src is nonzero, otherwise executes
the false-branch. The false-branch is optional may be omitted; in this case
it is treated like an empty block.
Notes:
BEQ Branch on Result Zero
BMI Branch on Result Minus
BNE Branch on Result not Zero
BPL Branch on Result Plus
BCC Branch on Carry Clear
BCS Branch on Carry Set
BVC Branch on Overflow Clear
BVS Branch on Overflow Set
- - - -
* It is illegal if src is not z, c, n, or v.
* It is illegal if src is not initialized.
* It is illegal if any location initialized at the end of the true-branch
is not initialized at the end of the false-branch, and vice versa.
Grammar
-------
@ -384,34 +312,3 @@ Grammar
| "dec" LocExpr
| "call" RoutineIdent
| "if" LocExpr Block ["else" Block].
### 6502 instructions unsupported ###
ASL Shift Left One Bit (Memory or Accumulator)
LSR Shift Right One Bit (Memory or Accumulator)
BIT Test Bits in Memory with Accumulator
BRK Force Break
CLD Clear Decimal Mode
CLI Clear interrupt Disable Bit
CLV Clear Overflow Flag
NOP No Operation
JMP Jump to New Location // but may be generated as part of `if`
PHA Push Accumulator on Stack
PHP Push Processor Status on Stack
PLA Pull Accumulator from Stack
PLP Pull Processor Status from Stack
RTI Return from Interrupt
RTS Return from Subroutine
SED Set Decimal Mode
SEI Set Interrupt Disable Status
TSX Transfer Stack Pointer to Index X
TXS Transfer Index X to Stack Pointer

View File

@ -242,7 +242,134 @@ Can't `add` to a memory location that isn't writeable.
| }
? IllegalWriteError: a
### ... many missing tests ... ###
### sub ###
Can't `sub` from or to a memory location that isn't initialized.
| routine main
| inputs a
| outputs a
| trashes c, z, v, n
| {
| st off, c
| sub a, 0
| }
= ok
| byte lives
| routine main
| inputs a
| outputs a
| trashes c, z, v, n
| {
| st off, c
| sub a, lives
| }
? UninitializedAccessError: lives
| byte lives
| routine main
| inputs lives
| outputs a
| trashes c, z, v, n
| {
| st off, c
| sub a, lives
| }
? UninitializedAccessError: a
Can't `sub` to a memory location that isn't writeable.
| routine main
| inputs a
| trashes c
| {
| st off, c
| sub a, 0
| }
? IllegalWriteError: a
### inc ###
Location must be initialized and writeable.
| routine main
| outputs x
| trashes z, n
| {
| inc x
| }
? UninitializedAccessError: x
| routine main
| inputs x
| trashes z, n
| {
| inc x
| }
? IllegalWriteError: x
| routine main
| inputs x
| outputs x
| trashes z, n
| {
| inc x
| }
= ok
### dec ###
Location must be initialized and writeable.
| routine main
| outputs x
| trashes z, n
| {
| dec x
| }
? UninitializedAccessError: x
| routine main
| inputs x
| trashes z, n
| {
| dec x
| }
? IllegalWriteError: x
| routine main
| inputs x
| outputs x
| trashes z, n
| {
| dec x
| }
= ok
### cmp ###
TODO: write some tests
### and ###
TODO: write some tests
### or ###
TODO: write some tests
### xor ###
TODO: write some tests
### shl ###
TODO: write some tests
### shr ###
TODO: write some tests
### call ###