Files
l65/samples/l65_operator_syntax.l65

140 lines
2.4 KiB
Plaintext

-- Self-validating corpus for l65's 6502 operator syntax. The operator and
-- mnemonic sections below must generate exactly the same bytes.
cpu = require "6502"
setmetatable(_ENV, cpu)
local code = location(0x8000)
local operator_code = section("operator_code")
a := #0x12
a := 0x34
a := 0x1234
a := 0x34,x
a := 0x1234,y
a := [0x34,x]
a := [0x34],y
0x34 := a
0x1234,x := a
0x1234,y := a
[0x34,x] := a
[0x34],y := a
x := #0x23
x := 0x34
x := 0x1234,y
y := #0x45
y := 0x34
y := 0x1234,x
x := a
a := x
y := a
a := y
x := sp
sp := x
a += #1
a -= 0x34
a &= 0x1234,x
a |= 0x1234,y
a ^= [0x34,x]
a ?= #2
x ?= 0x34
y ?= 0x1234
a <<=
a >>=
0x34 <<=
0x1234,x <<=
0x1234 >>=
0x34,x >>=
0x34++
0x1234,x++
0x1234--
0x34,x--
x++
x-- -- Attached -- is decrement; spaced -- begins a comment.
y++
y--
-- Declared after both uses to validate delayed addressing-mode selection.
a := forward_value
local mnemonic_code = section("mnemonic_code")
lda #0x12
lda 0x34
lda 0x1234
lda 0x34,x
lda 0x1234,y
lda (0x34,x)
lda (0x34),y
sta 0x34
sta 0x1234,x
sta 0x1234,y
sta (0x34,x)
sta (0x34),y
ldx #0x23
ldx 0x34
ldx 0x1234,y
ldy #0x45
ldy 0x34
ldy 0x1234,x
tax
txa
tay
tya
tsx
txs
adc #1
sbc 0x34;
and 0x1234,x
ora 0x1234,y
eor (0x34,x)
cmp #2
cpx 0x34
cpy 0x1234
asl
lsr
asl 0x34
asl 0x1234,x
lsr 0x1234
lsr 0x34,x
inc 0x34
inc 0x1234,x
dec 0x1234
dec 0x34,x
inx
dex
iny
dey
lda forward_value
forward_value = 0x34
local bin = genbin()
assert(operator_code.size == mnemonic_code.size,
string.format("operator code has %d bytes; mnemonic code has %d",
operator_code.size, mnemonic_code.size))
for offset = 0, operator_code.size - 1 do
local operator_byte = bin[operator_code.org - code.start + offset + 1]
local mnemonic_byte = bin[mnemonic_code.org - code.start + offset + 1]
assert(operator_byte == mnemonic_byte,
string.format("byte %d differs: operator=%02X mnemonic=%02X",
offset, operator_byte, mnemonic_byte))
end
writebin(filename .. '.bin', bin)
print(string.format('validated %d operator-syntax bytes', operator_code.size))