2017-11-20 14:10:43 +00:00
|
|
|
SixtyPical Compilation
|
2015-10-17 11:28:39 +00:00
|
|
|
======================
|
|
|
|
|
|
|
|
This is a test suite, written in [Falderal][] format, for compiling
|
2017-11-20 14:10:43 +00:00
|
|
|
SixtyPical to 6502 machine code.
|
2015-10-17 11:28:39 +00:00
|
|
|
|
|
|
|
[Falderal]: http://catseye.tc/node/Falderal
|
|
|
|
|
2017-11-20 14:10:43 +00:00
|
|
|
-> Functionality "Compile SixtyPical program" is implemented by
|
2018-04-23 12:18:01 +00:00
|
|
|
-> shell command "bin/sixtypical --output-format=c64-basic-prg --traceback %(test-body-file) >/tmp/foo && tests/appliances/bin/dcc6502-adapter </tmp/foo"
|
2015-10-17 11:28:39 +00:00
|
|
|
|
2017-11-20 14:10:43 +00:00
|
|
|
-> Tests for functionality "Compile SixtyPical program"
|
2015-10-17 11:28:39 +00:00
|
|
|
|
|
|
|
Null program.
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| {
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D RTS
|
2015-10-17 11:28:39 +00:00
|
|
|
|
2018-03-28 13:52:16 +00:00
|
|
|
`nop` program.
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| {
|
|
|
|
| nop
|
|
|
|
| }
|
|
|
|
= $080D NOP
|
|
|
|
= $080E RTS
|
|
|
|
|
2015-10-17 11:28:39 +00:00
|
|
|
Rudimentary program.
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs a
|
|
|
|
| outputs a
|
|
|
|
| trashes c, z, n, v
|
|
|
|
| {
|
|
|
|
| st off, c
|
|
|
|
| add a, 4
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D CLC
|
|
|
|
= $080E ADC #$04
|
|
|
|
= $0810 RTS
|
2015-10-17 12:50:21 +00:00
|
|
|
|
|
|
|
Call extern.
|
|
|
|
|
|
|
|
| routine chrout
|
|
|
|
| inputs a
|
|
|
|
| trashes a
|
|
|
|
| @ 65490
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs a
|
2015-10-17 13:54:28 +00:00
|
|
|
| trashes a, z, n
|
2015-10-17 12:50:21 +00:00
|
|
|
| {
|
|
|
|
| ld a, 65
|
|
|
|
| call chrout
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDA #$41
|
|
|
|
= $080F JSR $FFD2
|
|
|
|
= $0812 RTS
|
2015-10-17 14:23:00 +00:00
|
|
|
|
|
|
|
Call defined routine.
|
|
|
|
|
|
|
|
| routine foo
|
|
|
|
| outputs a, x, y
|
|
|
|
| trashes z, n
|
|
|
|
| {
|
|
|
|
| ld a, 0
|
|
|
|
| ld x, 0
|
|
|
|
| ld y, 0
|
|
|
|
| }
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| trashes a, x, y, z, n
|
|
|
|
| {
|
|
|
|
| call foo
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D JSR $0811
|
|
|
|
= $0810 RTS
|
|
|
|
= $0811 LDA #$00
|
|
|
|
= $0813 LDX #$00
|
|
|
|
= $0815 LDY #$00
|
|
|
|
= $0817 RTS
|
2015-10-17 14:46:28 +00:00
|
|
|
|
|
|
|
Access a defined memory location.
|
|
|
|
|
|
|
|
| byte foo
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| trashes a, y, z, n, foo
|
|
|
|
| {
|
|
|
|
| ld y, 0
|
|
|
|
| st y, foo
|
|
|
|
| ld a, foo
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDY #$00
|
|
|
|
= $080F STY $0816
|
|
|
|
= $0812 LDA $0816
|
|
|
|
= $0815 RTS
|
2015-10-17 15:17:35 +00:00
|
|
|
|
2016-06-16 16:03:31 +00:00
|
|
|
Memory location with explicit address.
|
|
|
|
|
2015-10-18 15:22:36 +00:00
|
|
|
| byte screen @ 1024
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| trashes a, z, n, screen
|
|
|
|
| {
|
|
|
|
| ld a, 100
|
|
|
|
| st a, screen
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDA #$64
|
|
|
|
= $080F STA $0400
|
|
|
|
= $0812 RTS
|
2015-10-18 15:22:36 +00:00
|
|
|
|
2018-04-17 16:58:26 +00:00
|
|
|
Accesses to memory locations in zero-page with `ld` and `st`
|
|
|
|
and `and`, `or`, and `xor` use zero-page addressing.
|
2018-03-29 09:31:42 +00:00
|
|
|
|
2018-03-29 10:46:56 +00:00
|
|
|
| byte zp @ $00
|
2018-03-29 09:31:42 +00:00
|
|
|
| byte screen @ 100
|
|
|
|
|
|
|
|
|
| routine main
|
2018-03-29 10:46:56 +00:00
|
|
|
| inputs screen, zp
|
|
|
|
| outputs screen, zp
|
2018-03-29 09:31:42 +00:00
|
|
|
| trashes a, z, n
|
|
|
|
| {
|
|
|
|
| ld a, screen
|
|
|
|
| st a, screen
|
2018-03-29 10:46:56 +00:00
|
|
|
| ld a, zp
|
|
|
|
| st a, zp
|
2018-04-17 16:58:26 +00:00
|
|
|
| and a, zp
|
|
|
|
| or a, zp
|
|
|
|
| xor a, zp
|
2018-03-29 09:31:42 +00:00
|
|
|
| }
|
|
|
|
= $080D LDA $64
|
|
|
|
= $080F STA $64
|
2018-03-29 10:46:56 +00:00
|
|
|
= $0811 LDA $00
|
|
|
|
= $0813 STA $00
|
2018-04-17 16:58:26 +00:00
|
|
|
= $0815 AND $00
|
|
|
|
= $0817 ORA $00
|
|
|
|
= $0819 EOR $00
|
|
|
|
= $081B RTS
|
2018-03-29 09:31:42 +00:00
|
|
|
|
2016-06-16 16:03:31 +00:00
|
|
|
Memory location with initial value.
|
|
|
|
|
|
|
|
| byte lives : 3
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs lives
|
|
|
|
| trashes a, z, n
|
|
|
|
| {
|
|
|
|
| ld a, lives
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDA $0811
|
|
|
|
= $0810 RTS
|
|
|
|
= $0811 .byte $03
|
2016-06-16 16:03:31 +00:00
|
|
|
|
2017-12-12 15:34:51 +00:00
|
|
|
Word memory locations with explicit address, initial value.
|
|
|
|
|
|
|
|
| word w1 @ 60001
|
|
|
|
| word w2 : 3003
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs w1
|
|
|
|
| outputs w2
|
|
|
|
| trashes a, z, n
|
|
|
|
| {
|
|
|
|
| copy w1, w2
|
|
|
|
| }
|
|
|
|
= $080D LDA $EA61
|
|
|
|
= $0810 STA $081A
|
|
|
|
= $0813 LDA $EA62
|
|
|
|
= $0816 STA $081B
|
|
|
|
= $0819 RTS
|
|
|
|
= $081A .byte $BB
|
|
|
|
= $081B .byte $0B
|
|
|
|
|
2018-03-29 09:45:18 +00:00
|
|
|
Initialized byte table, initialized with ASCII string. Bytes allocated, but beyond the string, are 0's.
|
2017-12-12 16:41:49 +00:00
|
|
|
|
2018-02-06 11:34:21 +00:00
|
|
|
| byte table[8] message : "WHAT?"
|
2017-12-12 16:41:49 +00:00
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs message
|
|
|
|
| outputs x, a, z, n
|
|
|
|
| {
|
|
|
|
| ld x, 0
|
|
|
|
| ld a, message + x
|
|
|
|
| }
|
|
|
|
= $080D LDX #$00
|
|
|
|
= $080F LDA $0813,X
|
|
|
|
= $0812 RTS
|
|
|
|
= $0813 .byte $57
|
|
|
|
= $0814 PHA
|
|
|
|
= $0815 EOR ($54,X)
|
|
|
|
= $0817 .byte $3F
|
|
|
|
= $0818 BRK
|
|
|
|
= $0819 BRK
|
|
|
|
= $081A BRK
|
|
|
|
|
2018-03-29 09:45:18 +00:00
|
|
|
Initialized byte table, initialized with list of byte values.
|
|
|
|
|
|
|
|
| byte table[8] message : 255, 0, 129, 128, 127
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs message
|
|
|
|
| outputs x, a, z, n
|
|
|
|
| {
|
|
|
|
| ld x, 0
|
|
|
|
| ld a, message + x
|
|
|
|
| }
|
|
|
|
= $080D LDX #$00
|
|
|
|
= $080F LDA $0813,X
|
|
|
|
= $0812 RTS
|
2018-03-29 10:09:02 +00:00
|
|
|
= $0813 .byte $FF
|
|
|
|
= $0814 BRK
|
|
|
|
= $0815 STA ($80,X)
|
|
|
|
= $0817 .byte $7F
|
2018-03-29 09:45:18 +00:00
|
|
|
= $0818 BRK
|
|
|
|
= $0819 BRK
|
|
|
|
= $081A BRK
|
|
|
|
|
2018-03-29 10:09:02 +00:00
|
|
|
Initialized word table, initialized with list of word values.
|
|
|
|
|
2018-04-18 15:32:12 +00:00
|
|
|
FIXME wait, is this not a word table[4]?
|
|
|
|
|
2018-03-29 10:09:02 +00:00
|
|
|
| word table[8] message : 65535, 0, 127
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| {
|
|
|
|
| }
|
|
|
|
= $080D RTS
|
|
|
|
= $080E .byte $FF
|
|
|
|
= $080F .byte $FF
|
|
|
|
= $0810 BRK
|
|
|
|
= $0811 BRK
|
|
|
|
= $0812 .byte $7F
|
|
|
|
= $0813 BRK
|
|
|
|
= $0814 BRK
|
|
|
|
= $0815 BRK
|
|
|
|
|
2015-10-17 15:17:35 +00:00
|
|
|
Some instructions.
|
|
|
|
|
|
|
|
| byte foo
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| trashes a, x, y, z, n, c, v, foo
|
|
|
|
| {
|
|
|
|
| ld a, 0
|
|
|
|
| ld x, 0
|
|
|
|
| ld y, 0
|
|
|
|
| st a, foo
|
|
|
|
| st x, foo
|
|
|
|
| st y, foo
|
|
|
|
| st on, c
|
|
|
|
| st off, c
|
|
|
|
| add a, 1
|
|
|
|
| add a, foo
|
|
|
|
| sub a, 1
|
|
|
|
| sub a, foo
|
|
|
|
| inc foo
|
|
|
|
| inc x
|
|
|
|
| inc y
|
|
|
|
| dec foo
|
|
|
|
| dec x
|
|
|
|
| dec y
|
|
|
|
| and a, 255
|
|
|
|
| and a, foo
|
|
|
|
| or a, 255
|
|
|
|
| or a, foo
|
|
|
|
| xor a, 255
|
|
|
|
| xor a, foo
|
|
|
|
| cmp a, 1
|
|
|
|
| cmp a, foo
|
|
|
|
| cmp x, 1
|
|
|
|
| cmp x, foo
|
|
|
|
| cmp y, 1
|
|
|
|
| cmp y, foo
|
|
|
|
| shl a
|
|
|
|
| shr a
|
2018-04-18 11:01:53 +00:00
|
|
|
| shl foo
|
|
|
|
| shr foo
|
2015-10-17 15:17:35 +00:00
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDA #$00
|
|
|
|
= $080F LDX #$00
|
|
|
|
= $0811 LDY #$00
|
2018-04-18 11:01:53 +00:00
|
|
|
= $0813 STA $0859
|
|
|
|
= $0816 STX $0859
|
|
|
|
= $0819 STY $0859
|
2017-12-11 11:16:27 +00:00
|
|
|
= $081C SEC
|
|
|
|
= $081D CLC
|
|
|
|
= $081E ADC #$01
|
2018-04-18 11:01:53 +00:00
|
|
|
= $0820 ADC $0859
|
2017-12-11 11:16:27 +00:00
|
|
|
= $0823 SBC #$01
|
2018-04-18 11:01:53 +00:00
|
|
|
= $0825 SBC $0859
|
|
|
|
= $0828 INC $0859
|
2017-12-11 11:16:27 +00:00
|
|
|
= $082B INX
|
|
|
|
= $082C INY
|
2018-04-18 11:01:53 +00:00
|
|
|
= $082D DEC $0859
|
2017-12-11 11:16:27 +00:00
|
|
|
= $0830 DEX
|
|
|
|
= $0831 DEY
|
|
|
|
= $0832 AND #$FF
|
2018-04-18 11:01:53 +00:00
|
|
|
= $0834 AND $0859
|
2017-12-11 11:16:27 +00:00
|
|
|
= $0837 ORA #$FF
|
2018-04-18 11:01:53 +00:00
|
|
|
= $0839 ORA $0859
|
2017-12-11 11:16:27 +00:00
|
|
|
= $083C EOR #$FF
|
2018-04-18 11:01:53 +00:00
|
|
|
= $083E EOR $0859
|
2017-12-11 11:16:27 +00:00
|
|
|
= $0841 CMP #$01
|
2018-04-18 11:01:53 +00:00
|
|
|
= $0843 CMP $0859
|
2017-12-11 11:16:27 +00:00
|
|
|
= $0846 CPX #$01
|
2018-04-18 11:01:53 +00:00
|
|
|
= $0848 CPX $0859
|
2017-12-11 11:16:27 +00:00
|
|
|
= $084B CPY #$01
|
2018-04-18 11:01:53 +00:00
|
|
|
= $084D CPY $0859
|
2017-12-11 11:16:27 +00:00
|
|
|
= $0850 ROL A
|
|
|
|
= $0851 ROR A
|
2018-04-18 11:01:53 +00:00
|
|
|
= $0852 ROL $0859
|
|
|
|
= $0855 ROR $0859
|
|
|
|
= $0858 RTS
|
2015-10-17 15:34:02 +00:00
|
|
|
|
2018-04-18 15:32:12 +00:00
|
|
|
Some instructions on tables. (1/3)
|
|
|
|
|
|
|
|
| byte table[256] many
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs many
|
|
|
|
| outputs many
|
|
|
|
| trashes a, x, c, n, z, v
|
|
|
|
| {
|
|
|
|
| ld x, 0
|
|
|
|
| ld a, 0
|
|
|
|
| st off, c
|
|
|
|
| add a, many + x
|
|
|
|
| sub a, many + x
|
|
|
|
| cmp a, many + x
|
|
|
|
| }
|
|
|
|
= $080D LDX #$00
|
|
|
|
= $080F LDA #$00
|
|
|
|
= $0811 CLC
|
|
|
|
= $0812 ADC $081C,X
|
|
|
|
= $0815 SBC $081C,X
|
|
|
|
= $0818 CMP $081C,X
|
|
|
|
= $081B RTS
|
|
|
|
|
|
|
|
Some instructions on tables. (2/3)
|
|
|
|
|
|
|
|
| byte table[256] many
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs many
|
|
|
|
| outputs many
|
|
|
|
| trashes a, x, c, n, z
|
|
|
|
| {
|
|
|
|
| ld x, 0
|
|
|
|
| ld a, 0
|
|
|
|
| and a, many + x
|
|
|
|
| or a, many + x
|
|
|
|
| xor a, many + x
|
|
|
|
| }
|
|
|
|
= $080D LDX #$00
|
|
|
|
= $080F LDA #$00
|
|
|
|
= $0811 AND $081B,X
|
|
|
|
= $0814 ORA $081B,X
|
|
|
|
= $0817 EOR $081B,X
|
|
|
|
= $081A RTS
|
|
|
|
|
|
|
|
Some instructions on tables. (3/3)
|
|
|
|
|
|
|
|
| byte table[256] many
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs many
|
|
|
|
| outputs many
|
|
|
|
| trashes a, x, c, n, z
|
|
|
|
| {
|
|
|
|
| ld x, 0
|
|
|
|
| ld a, 0
|
|
|
|
| st off, c
|
|
|
|
| shl many + x
|
|
|
|
| shr many + x
|
|
|
|
| inc many + x
|
|
|
|
| dec many + x
|
|
|
|
| }
|
|
|
|
= $080D LDX #$00
|
|
|
|
= $080F LDA #$00
|
|
|
|
= $0811 CLC
|
|
|
|
= $0812 ROL $081F,X
|
|
|
|
= $0815 ROR $081F,X
|
|
|
|
= $0818 INC $081F,X
|
|
|
|
= $081B DEC $081F,X
|
|
|
|
= $081E RTS
|
|
|
|
|
2015-10-17 15:34:02 +00:00
|
|
|
Compiling `if`.
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| trashes a, x, y, z, n, c, v
|
|
|
|
| {
|
|
|
|
| ld a, 0
|
|
|
|
| if z {
|
|
|
|
| ld y, 1
|
|
|
|
| } else {
|
|
|
|
| ld y, 2
|
|
|
|
| }
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDA #$00
|
|
|
|
= $080F BNE $0816
|
|
|
|
= $0811 LDY #$01
|
|
|
|
= $0813 JMP $0818
|
|
|
|
= $0816 LDY #$02
|
|
|
|
= $0818 RTS
|
2015-10-17 17:11:23 +00:00
|
|
|
|
2015-10-18 14:32:28 +00:00
|
|
|
Compiling `if not`.
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| trashes a, x, y, z, n, c, v
|
|
|
|
| {
|
|
|
|
| ld a, 0
|
|
|
|
| if not z {
|
|
|
|
| ld y, 1
|
|
|
|
| } else {
|
|
|
|
| ld y, 2
|
|
|
|
| }
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDA #$00
|
|
|
|
= $080F BEQ $0816
|
|
|
|
= $0811 LDY #$01
|
|
|
|
= $0813 JMP $0818
|
|
|
|
= $0816 LDY #$02
|
|
|
|
= $0818 RTS
|
2015-10-18 14:32:28 +00:00
|
|
|
|
2015-10-17 17:11:23 +00:00
|
|
|
Compiling `if` without `else`.
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| trashes a, x, y, z, n, c, v
|
|
|
|
| {
|
|
|
|
| ld a, 0
|
2018-02-06 16:14:44 +00:00
|
|
|
| ld y, 0
|
2015-10-17 17:11:23 +00:00
|
|
|
| if z {
|
|
|
|
| ld y, 1
|
|
|
|
| }
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDA #$00
|
2018-02-06 16:14:44 +00:00
|
|
|
= $080F LDY #$00
|
|
|
|
= $0811 BNE $0815
|
|
|
|
= $0813 LDY #$01
|
|
|
|
= $0815 RTS
|
2015-10-18 12:55:40 +00:00
|
|
|
|
2018-03-29 12:33:06 +00:00
|
|
|
Compiling `repeat ... until z`.
|
2015-10-18 12:55:40 +00:00
|
|
|
|
|
|
|
| routine main
|
|
|
|
| trashes a, y, z, n, c
|
|
|
|
| {
|
|
|
|
| ld y, 65
|
|
|
|
| repeat {
|
|
|
|
| ld a, y
|
|
|
|
| inc y
|
|
|
|
| cmp y, 91
|
|
|
|
| } until z
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDY #$41
|
|
|
|
= $080F TYA
|
|
|
|
= $0810 INY
|
|
|
|
= $0811 CPY #$5B
|
|
|
|
= $0813 BNE $080F
|
|
|
|
= $0815 RTS
|
2015-10-18 14:32:28 +00:00
|
|
|
|
2018-03-29 12:33:06 +00:00
|
|
|
Compiling `repeat ... until not z`.
|
2015-10-18 14:32:28 +00:00
|
|
|
|
|
|
|
| routine main
|
|
|
|
| trashes a, y, z, n, c
|
|
|
|
| {
|
|
|
|
| ld y, 65
|
|
|
|
| repeat {
|
|
|
|
| ld a, y
|
|
|
|
| inc y
|
|
|
|
| cmp y, 91
|
|
|
|
| } until not z
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDY #$41
|
|
|
|
= $080F TYA
|
|
|
|
= $0810 INY
|
|
|
|
= $0811 CPY #$5B
|
|
|
|
= $0813 BEQ $080F
|
|
|
|
= $0815 RTS
|
2015-10-18 14:32:28 +00:00
|
|
|
|
2018-03-29 12:33:06 +00:00
|
|
|
Compiling `repeat ... until n`.
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| trashes a, y, z, n, c
|
|
|
|
| {
|
|
|
|
| ld y, 65
|
|
|
|
| repeat {
|
|
|
|
| ld a, y
|
|
|
|
| dec y
|
|
|
|
| } until n
|
|
|
|
| }
|
|
|
|
= $080D LDY #$41
|
|
|
|
= $080F TYA
|
|
|
|
= $0810 DEY
|
|
|
|
= $0811 BPL $080F
|
|
|
|
= $0813 RTS
|
|
|
|
|
|
|
|
Compiling `repeat ... until not n`.
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| trashes a, y, z, n, c
|
|
|
|
| {
|
2018-03-29 13:45:28 +00:00
|
|
|
| ld y, 199
|
2018-03-29 12:33:06 +00:00
|
|
|
| repeat {
|
|
|
|
| ld a, y
|
|
|
|
| inc y
|
|
|
|
| } until not n
|
|
|
|
| }
|
2018-03-29 13:45:28 +00:00
|
|
|
= $080D LDY #$C7
|
2018-03-29 12:33:06 +00:00
|
|
|
= $080F TYA
|
|
|
|
= $0810 INY
|
|
|
|
= $0811 BMI $080F
|
|
|
|
= $0813 RTS
|
|
|
|
|
2015-10-18 14:32:28 +00:00
|
|
|
Compiling `repeat forever`.
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| trashes a, y, z, n, c
|
|
|
|
| {
|
|
|
|
| ld y, 65
|
|
|
|
| repeat {
|
|
|
|
| inc y
|
|
|
|
| } forever
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDY #$41
|
|
|
|
= $080F INY
|
|
|
|
= $0810 JMP $080F
|
|
|
|
= $0813 RTS
|
2015-10-18 17:32:20 +00:00
|
|
|
|
2017-12-12 15:18:59 +00:00
|
|
|
The body of `repeat forever` can be empty.
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| {
|
|
|
|
| repeat {
|
|
|
|
| } forever
|
|
|
|
| }
|
|
|
|
= $080D JMP $080D
|
|
|
|
= $0810 RTS
|
|
|
|
|
2018-03-14 15:33:11 +00:00
|
|
|
Compiling `for ... up to`.
|
|
|
|
|
|
|
|
| byte table[256] tab
|
|
|
|
|
|
|
|
|
| define main routine
|
|
|
|
| inputs tab
|
|
|
|
| trashes a, x, c, z, v, n
|
|
|
|
| {
|
|
|
|
| ld x, 0
|
|
|
|
| for x up to 15 {
|
|
|
|
| ld a, tab + x
|
|
|
|
| }
|
|
|
|
| }
|
|
|
|
= $080D LDX #$00
|
|
|
|
= $080F LDA $0818,X
|
|
|
|
= $0812 INX
|
|
|
|
= $0813 CPX #$10
|
|
|
|
= $0815 BNE $080F
|
|
|
|
= $0817 RTS
|
|
|
|
|
|
|
|
Compiling `for ... down to`.
|
|
|
|
|
|
|
|
| byte table[256] tab
|
|
|
|
|
|
|
|
|
| define main routine
|
|
|
|
| inputs tab
|
|
|
|
| trashes a, x, c, z, v, n
|
|
|
|
| {
|
|
|
|
| ld x, 15
|
|
|
|
| for x down to 0 {
|
|
|
|
| ld a, tab + x
|
|
|
|
| }
|
|
|
|
| }
|
|
|
|
= $080D LDX #$0F
|
|
|
|
= $080F LDA $0818,X
|
|
|
|
= $0812 DEX
|
|
|
|
= $0813 CPX #$FF
|
|
|
|
= $0815 BNE $080F
|
|
|
|
= $0817 RTS
|
|
|
|
|
2018-04-25 12:15:53 +00:00
|
|
|
Compiling `save`.
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs a
|
|
|
|
| outputs a
|
|
|
|
| trashes z, n
|
|
|
|
| {
|
|
|
|
| save a {
|
|
|
|
| save x {
|
|
|
|
| ld a, 0
|
|
|
|
| ld x, 1
|
|
|
|
| }
|
|
|
|
| }
|
|
|
|
| }
|
|
|
|
= $080D PHA
|
|
|
|
= $080E TXA
|
|
|
|
= $080F PHA
|
|
|
|
= $0810 LDA #$00
|
|
|
|
= $0812 LDX #$01
|
|
|
|
= $0814 PLA
|
|
|
|
= $0815 TAX
|
|
|
|
= $0816 PLA
|
|
|
|
= $0817 RTS
|
|
|
|
|
2018-04-25 12:27:47 +00:00
|
|
|
Compiling `save` on a user-defined location.
|
|
|
|
|
|
|
|
| byte foo
|
|
|
|
| routine main
|
|
|
|
| trashes a, z, n
|
|
|
|
| {
|
|
|
|
| save foo {
|
|
|
|
| ld a, 0
|
|
|
|
| st a, foo
|
|
|
|
| }
|
|
|
|
| }
|
|
|
|
= $080D LDA $081B
|
|
|
|
= $0810 PHA
|
|
|
|
= $0811 LDA #$00
|
|
|
|
= $0813 STA $081B
|
|
|
|
= $0816 PLA
|
|
|
|
= $0817 STA $081B
|
|
|
|
= $081A RTS
|
|
|
|
|
2015-10-18 17:32:20 +00:00
|
|
|
Indexed access.
|
|
|
|
|
|
|
|
| byte one
|
2018-02-06 11:34:21 +00:00
|
|
|
| byte table[256] many
|
2015-10-18 17:32:20 +00:00
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| outputs many
|
|
|
|
| trashes a, x, n, z
|
|
|
|
| {
|
|
|
|
| ld x, 0
|
|
|
|
| ld a, 0
|
|
|
|
| st a, many + x
|
|
|
|
| ld a, many + x
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDX #$00
|
|
|
|
= $080F LDA #$00
|
|
|
|
= $0811 STA $0819,X
|
|
|
|
= $0814 LDA $0819,X
|
|
|
|
= $0817 RTS
|
2015-10-19 07:55:47 +00:00
|
|
|
|
2018-04-18 15:32:12 +00:00
|
|
|
Byte tables take up, at most, 256 bytes in memory.
|
2017-12-08 16:59:31 +00:00
|
|
|
|
2018-02-06 11:34:21 +00:00
|
|
|
| byte table[256] tab1
|
|
|
|
| byte table[256] tab2
|
2017-12-08 16:59:31 +00:00
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs tab1
|
|
|
|
| outputs tab2
|
|
|
|
| trashes a, x, n, z
|
|
|
|
| {
|
|
|
|
| ld x, 0
|
|
|
|
| ld a, tab1 + x
|
|
|
|
| st a, tab2 + x
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDX #$00
|
|
|
|
= $080F LDA $0816,X
|
|
|
|
= $0812 STA $0916,X
|
|
|
|
= $0815 RTS
|
2017-12-08 16:59:31 +00:00
|
|
|
|
2017-12-11 11:16:27 +00:00
|
|
|
Byte storage locations take up only 1 byte in memory.
|
2017-12-08 16:59:31 +00:00
|
|
|
|
|
|
|
| byte one
|
|
|
|
| byte two
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| outputs one, two
|
|
|
|
| trashes a, x, n, z
|
|
|
|
| {
|
|
|
|
| ld a, 0
|
|
|
|
| st a, one
|
|
|
|
| st a, two
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDA #$00
|
|
|
|
= $080F STA $0816
|
|
|
|
= $0812 STA $0817
|
|
|
|
= $0815 RTS
|
2017-12-08 16:59:31 +00:00
|
|
|
|
2016-06-16 16:10:03 +00:00
|
|
|
Copy byte to byte.
|
|
|
|
|
|
|
|
| byte bar
|
|
|
|
| byte baz
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs baz
|
|
|
|
| outputs bar
|
|
|
|
| trashes a, n, z
|
|
|
|
| {
|
|
|
|
| copy baz, bar
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDA $0815
|
|
|
|
= $0810 STA $0814
|
|
|
|
= $0813 RTS
|
2016-06-16 16:10:03 +00:00
|
|
|
|
|
|
|
Copy word to word.
|
|
|
|
|
|
|
|
| word bar
|
|
|
|
| word baz
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs baz
|
|
|
|
| outputs bar
|
|
|
|
| trashes a, n, z
|
|
|
|
| {
|
|
|
|
| copy baz, bar
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDA $081C
|
|
|
|
= $0810 STA $081A
|
|
|
|
= $0813 LDA $081D
|
|
|
|
= $0816 STA $081B
|
|
|
|
= $0819 RTS
|
2016-06-16 16:10:03 +00:00
|
|
|
|
2017-11-20 15:53:34 +00:00
|
|
|
Copy literal word to word.
|
|
|
|
|
|
|
|
| word bar
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| outputs bar
|
|
|
|
| trashes a, n, z
|
|
|
|
| {
|
2017-12-07 16:49:43 +00:00
|
|
|
| copy 2000, bar
|
2017-11-20 15:53:34 +00:00
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDA #$D0
|
|
|
|
= $080F STA $0818
|
|
|
|
= $0812 LDA #$07
|
|
|
|
= $0814 STA $0819
|
|
|
|
= $0817 RTS
|
2017-11-20 15:53:34 +00:00
|
|
|
|
2017-12-12 16:04:59 +00:00
|
|
|
You can also copy a literal word to a word table.
|
|
|
|
|
2018-02-06 11:34:21 +00:00
|
|
|
| word table[256] many
|
2017-12-12 16:04:59 +00:00
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs many
|
|
|
|
| outputs many
|
|
|
|
| trashes a, x, n, z
|
|
|
|
| {
|
|
|
|
| ld x, 0
|
|
|
|
| copy 9999, many + x
|
|
|
|
| }
|
|
|
|
= $080D LDX #$00
|
|
|
|
= $080F LDA #$0F
|
|
|
|
= $0811 STA $081A,X
|
|
|
|
= $0814 LDA #$27
|
|
|
|
= $0816 STA $091A,X
|
|
|
|
= $0819 RTS
|
|
|
|
|
2016-06-16 16:10:03 +00:00
|
|
|
Copy vector to vector.
|
2015-10-19 07:55:47 +00:00
|
|
|
|
2018-02-05 17:01:25 +00:00
|
|
|
| vector routine bar
|
|
|
|
| vector routine baz
|
2015-10-19 07:55:47 +00:00
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs baz
|
|
|
|
| outputs bar
|
|
|
|
| trashes a, n, z
|
|
|
|
| {
|
|
|
|
| copy baz, bar
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDA $081C
|
|
|
|
= $0810 STA $081A
|
|
|
|
= $0813 LDA $081D
|
|
|
|
= $0816 STA $081B
|
|
|
|
= $0819 RTS
|
2015-10-19 07:55:47 +00:00
|
|
|
|
2017-11-20 15:53:34 +00:00
|
|
|
Copy routine to vector, inside an `interrupts off` block.
|
2015-10-19 07:55:47 +00:00
|
|
|
|
2018-02-06 16:14:44 +00:00
|
|
|
| vector routine
|
|
|
|
| inputs x
|
|
|
|
| outputs x
|
|
|
|
| trashes z, n
|
|
|
|
| bar
|
2015-10-19 07:55:47 +00:00
|
|
|
|
|
|
|
|
| routine foo
|
|
|
|
| inputs x
|
|
|
|
| outputs x
|
|
|
|
| trashes z, n
|
|
|
|
| {
|
|
|
|
| inc x
|
|
|
|
| }
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| outputs bar
|
|
|
|
| trashes a, n, z
|
|
|
|
| {
|
|
|
|
| with interrupts off {
|
|
|
|
| copy foo, bar
|
|
|
|
| }
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D SEI
|
|
|
|
= $080E LDA #$1A
|
|
|
|
= $0810 STA $081C
|
|
|
|
= $0813 LDA #$08
|
|
|
|
= $0815 STA $081D
|
|
|
|
= $0818 CLI
|
|
|
|
= $0819 RTS
|
|
|
|
= $081A INX
|
|
|
|
= $081B RTS
|
2015-10-20 12:15:21 +00:00
|
|
|
|
2018-02-12 15:59:20 +00:00
|
|
|
Copy routine (by forward reference) to vector.
|
|
|
|
|
|
|
|
| vector routine
|
|
|
|
| inputs x
|
|
|
|
| outputs x
|
|
|
|
| trashes z, n
|
|
|
|
| bar
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| outputs bar
|
|
|
|
| trashes a, n, z
|
|
|
|
| {
|
|
|
|
| copy foo, bar
|
|
|
|
| }
|
|
|
|
|
|
|
|
|
| routine foo
|
|
|
|
| inputs x
|
|
|
|
| outputs x
|
|
|
|
| trashes z, n
|
|
|
|
| {
|
|
|
|
| inc x
|
|
|
|
| }
|
|
|
|
= $080D LDA #$18
|
|
|
|
= $080F STA $081A
|
|
|
|
= $0812 LDA #$08
|
|
|
|
= $0814 STA $081B
|
|
|
|
= $0817 RTS
|
|
|
|
= $0818 INX
|
|
|
|
= $0819 RTS
|
|
|
|
|
2017-12-11 12:02:48 +00:00
|
|
|
Copy word to word table and back, with both `x` and `y` as indexes.
|
2017-12-08 15:53:18 +00:00
|
|
|
|
|
|
|
| word one
|
2018-02-06 11:34:21 +00:00
|
|
|
| word table[256] many
|
2017-12-08 15:53:18 +00:00
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs one, many
|
|
|
|
| outputs one, many
|
2017-12-11 12:02:48 +00:00
|
|
|
| trashes a, x, y, n, z
|
2017-12-08 15:53:18 +00:00
|
|
|
| {
|
|
|
|
| ld x, 0
|
2017-12-11 12:02:48 +00:00
|
|
|
| ld y, 0
|
2017-12-08 15:53:18 +00:00
|
|
|
| copy 777, one
|
|
|
|
| copy one, many + x
|
2017-12-11 12:02:48 +00:00
|
|
|
| copy one, many + y
|
|
|
|
| copy many + x, one
|
|
|
|
| copy many + y, one
|
2017-12-08 15:53:18 +00:00
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDX #$00
|
2017-12-11 12:02:48 +00:00
|
|
|
= $080F LDY #$00
|
|
|
|
= $0811 LDA #$09
|
|
|
|
= $0813 STA $084C
|
|
|
|
= $0816 LDA #$03
|
|
|
|
= $0818 STA $084D
|
|
|
|
= $081B LDA $084C
|
|
|
|
= $081E STA $084E,X
|
|
|
|
= $0821 LDA $084D
|
|
|
|
= $0824 STA $094E,X
|
|
|
|
= $0827 LDA $084C
|
|
|
|
= $082A STA $084E,Y
|
|
|
|
= $082D LDA $084D
|
|
|
|
= $0830 STA $094E,Y
|
|
|
|
= $0833 LDA $084E,X
|
|
|
|
= $0836 STA $084C
|
|
|
|
= $0839 LDA $094E,X
|
|
|
|
= $083C STA $084D
|
|
|
|
= $083F LDA $084E,Y
|
|
|
|
= $0842 STA $084C
|
|
|
|
= $0845 LDA $094E,Y
|
|
|
|
= $0848 STA $084D
|
|
|
|
= $084B RTS
|
2017-12-08 15:53:18 +00:00
|
|
|
|
2015-10-20 12:15:21 +00:00
|
|
|
Indirect call.
|
|
|
|
|
2018-02-06 16:14:44 +00:00
|
|
|
| vector routine
|
|
|
|
| outputs x
|
|
|
|
| trashes z, n
|
|
|
|
| foo
|
2015-10-20 12:15:21 +00:00
|
|
|
|
|
2018-02-06 16:14:44 +00:00
|
|
|
| routine bar
|
|
|
|
| outputs x
|
|
|
|
| trashes z, n
|
|
|
|
| {
|
2015-10-20 12:15:21 +00:00
|
|
|
| ld x, 200
|
|
|
|
| }
|
|
|
|
|
|
2018-02-06 16:14:44 +00:00
|
|
|
| routine main
|
|
|
|
| outputs x, foo
|
|
|
|
| trashes a, z, n
|
|
|
|
| {
|
2015-10-20 12:15:21 +00:00
|
|
|
| copy bar, foo
|
|
|
|
| call foo
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDA #$1B
|
2018-02-07 11:11:14 +00:00
|
|
|
= $080F STA $0822
|
2017-12-11 11:16:27 +00:00
|
|
|
= $0812 LDA #$08
|
2018-02-07 11:11:14 +00:00
|
|
|
= $0814 STA $0823
|
2017-12-11 11:16:27 +00:00
|
|
|
= $0817 JSR $081E
|
|
|
|
= $081A RTS
|
|
|
|
= $081B LDX #$C8
|
|
|
|
= $081D RTS
|
2018-02-07 11:11:14 +00:00
|
|
|
= $081E JMP ($0822)
|
2018-02-06 17:00:04 +00:00
|
|
|
= $0821 RTS
|
2015-10-21 14:51:52 +00:00
|
|
|
|
2018-04-05 13:10:04 +00:00
|
|
|
Compiling `goto`. Note that no `RTS` is emitted after the `JMP`.
|
2015-10-21 14:51:52 +00:00
|
|
|
|
2018-02-06 16:14:44 +00:00
|
|
|
| routine bar
|
|
|
|
| inputs y
|
|
|
|
| outputs x, y
|
|
|
|
| trashes z, n
|
|
|
|
| {
|
2015-10-21 14:51:52 +00:00
|
|
|
| ld x, 200
|
|
|
|
| }
|
|
|
|
|
|
2018-02-06 16:14:44 +00:00
|
|
|
| routine main
|
|
|
|
| outputs x, y
|
|
|
|
| trashes a, z, n
|
|
|
|
| {
|
2015-10-21 14:51:52 +00:00
|
|
|
| ld y, 200
|
|
|
|
| goto bar
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDY #$C8
|
2018-04-05 13:10:04 +00:00
|
|
|
= $080F JMP $0812
|
|
|
|
= $0812 LDX #$C8
|
|
|
|
= $0814 RTS
|
2017-11-24 13:09:10 +00:00
|
|
|
|
2018-02-02 17:56:50 +00:00
|
|
|
### Vector tables
|
|
|
|
|
|
|
|
Copying to and from a vector table.
|
|
|
|
|
2018-02-05 17:01:25 +00:00
|
|
|
| vector routine
|
2018-02-02 17:56:50 +00:00
|
|
|
| outputs x
|
|
|
|
| trashes a, z, n
|
2018-02-05 17:01:25 +00:00
|
|
|
| one
|
2018-02-12 14:53:49 +00:00
|
|
|
| vector routine
|
2018-02-02 17:56:50 +00:00
|
|
|
| outputs x
|
2018-02-12 14:53:49 +00:00
|
|
|
| trashes a, z, n
|
2018-02-06 11:34:21 +00:00
|
|
|
| table[256] many
|
2018-02-02 17:56:50 +00:00
|
|
|
|
|
|
|
|
| routine bar outputs x trashes a, z, n {
|
|
|
|
| ld x, 200
|
|
|
|
| }
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs one, many
|
|
|
|
| outputs one, many
|
|
|
|
| trashes a, x, n, z
|
|
|
|
| {
|
|
|
|
| ld x, 0
|
|
|
|
| copy bar, one
|
2018-02-07 13:56:17 +00:00
|
|
|
| copy bar, many + x
|
2018-02-02 17:56:50 +00:00
|
|
|
| copy one, many + x
|
|
|
|
| copy many + x, one
|
|
|
|
| call one
|
|
|
|
| }
|
|
|
|
= $080D LDX #$00
|
2018-02-07 13:56:17 +00:00
|
|
|
= $080F LDA #$3F
|
|
|
|
= $0811 STA $0846
|
2018-02-02 17:56:50 +00:00
|
|
|
= $0814 LDA #$08
|
2018-02-07 13:56:17 +00:00
|
|
|
= $0816 STA $0847
|
|
|
|
= $0819 LDA #$3F
|
|
|
|
= $081B STA $0848,X
|
|
|
|
= $081E LDA #$08
|
|
|
|
= $0820 STA $0948,X
|
|
|
|
= $0823 LDA $0846
|
|
|
|
= $0826 STA $0848,X
|
|
|
|
= $0829 LDA $0847
|
|
|
|
= $082C STA $0948,X
|
|
|
|
= $082F LDA $0848,X
|
|
|
|
= $0832 STA $0846
|
|
|
|
= $0835 LDA $0948,X
|
|
|
|
= $0838 STA $0847
|
|
|
|
= $083B JSR $0842
|
|
|
|
= $083E RTS
|
|
|
|
= $083F LDX #$C8
|
|
|
|
= $0841 RTS
|
|
|
|
= $0842 JMP ($0846)
|
|
|
|
= $0845 RTS
|
2018-02-02 17:56:50 +00:00
|
|
|
|
2017-12-07 12:48:56 +00:00
|
|
|
### word operations
|
|
|
|
|
2017-12-07 13:15:21 +00:00
|
|
|
Adding a constant word to a word memory location.
|
2017-12-07 12:48:56 +00:00
|
|
|
|
|
|
|
| word score
|
|
|
|
| routine main
|
2017-12-07 13:15:21 +00:00
|
|
|
| inputs score
|
2017-12-07 12:48:56 +00:00
|
|
|
| outputs score
|
|
|
|
| trashes a, c, z, v, n
|
|
|
|
| {
|
|
|
|
| st off, c
|
|
|
|
| add score, 1999
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D CLC
|
|
|
|
= $080E LDA $081F
|
|
|
|
= $0811 ADC #$CF
|
|
|
|
= $0813 STA $081F
|
|
|
|
= $0816 LDA $0820
|
|
|
|
= $0819 ADC #$07
|
|
|
|
= $081B STA $0820
|
|
|
|
= $081E RTS
|
2017-12-07 12:48:56 +00:00
|
|
|
|
2017-12-07 13:15:21 +00:00
|
|
|
Adding a word memory location to another word memory location.
|
|
|
|
|
|
|
|
| word score
|
|
|
|
| word delta
|
|
|
|
| routine main
|
|
|
|
| inputs score, delta
|
|
|
|
| outputs score
|
|
|
|
| trashes a, c, z, v, n
|
|
|
|
| {
|
|
|
|
| st off, c
|
|
|
|
| add score, delta
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D CLC
|
|
|
|
= $080E LDA $0821
|
|
|
|
= $0811 ADC $0823
|
|
|
|
= $0814 STA $0821
|
|
|
|
= $0817 LDA $0822
|
|
|
|
= $081A ADC $0824
|
|
|
|
= $081D STA $0822
|
|
|
|
= $0820 RTS
|
2017-12-07 13:15:21 +00:00
|
|
|
|
2017-12-13 14:07:59 +00:00
|
|
|
Subtracting a constant word from a word memory location.
|
|
|
|
|
|
|
|
| word score
|
|
|
|
| routine main
|
|
|
|
| inputs score
|
|
|
|
| outputs score
|
|
|
|
| trashes a, c, z, v, n
|
|
|
|
| {
|
|
|
|
| st on, c
|
|
|
|
| sub score, 1999
|
|
|
|
| }
|
|
|
|
= $080D SEC
|
|
|
|
= $080E LDA $081F
|
|
|
|
= $0811 SBC #$CF
|
|
|
|
= $0813 STA $081F
|
|
|
|
= $0816 LDA $0820
|
|
|
|
= $0819 SBC #$07
|
|
|
|
= $081B STA $0820
|
|
|
|
= $081E RTS
|
|
|
|
|
|
|
|
Subtracting a word memory location from another word memory location.
|
|
|
|
|
|
|
|
| word score
|
|
|
|
| word delta
|
|
|
|
| routine main
|
|
|
|
| inputs score, delta
|
|
|
|
| outputs score
|
|
|
|
| trashes a, c, z, v, n
|
|
|
|
| {
|
|
|
|
| st on, c
|
|
|
|
| sub score, delta
|
|
|
|
| }
|
|
|
|
= $080D SEC
|
|
|
|
= $080E LDA $0821
|
|
|
|
= $0811 SBC $0823
|
|
|
|
= $0814 STA $0821
|
|
|
|
= $0817 LDA $0822
|
|
|
|
= $081A SBC $0824
|
|
|
|
= $081D STA $0822
|
|
|
|
= $0820 RTS
|
|
|
|
|
2017-12-01 15:10:16 +00:00
|
|
|
### Buffers and Pointers
|
|
|
|
|
|
|
|
Load address into pointer.
|
2017-11-24 13:09:10 +00:00
|
|
|
|
2017-11-24 13:42:14 +00:00
|
|
|
| buffer[2048] buf
|
|
|
|
| pointer ptr @ 254
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs buf
|
|
|
|
| outputs buf, y
|
|
|
|
| trashes a, z, n, ptr
|
|
|
|
| {
|
|
|
|
| ld y, 0
|
2017-12-01 12:36:58 +00:00
|
|
|
| copy ^buf, ptr
|
2017-11-24 13:42:14 +00:00
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDY #$00
|
|
|
|
= $080F LDA #$18
|
|
|
|
= $0811 STA $FE
|
|
|
|
= $0813 LDA #$08
|
|
|
|
= $0815 STA $FF
|
|
|
|
= $0817 RTS
|
2017-11-24 16:56:55 +00:00
|
|
|
|
2017-12-01 15:10:16 +00:00
|
|
|
Write literal through a pointer.
|
2017-11-24 16:56:55 +00:00
|
|
|
|
|
|
|
| buffer[2048] buf
|
|
|
|
| pointer ptr @ 254
|
|
|
|
|
|
|
|
|
| routine main
|
2017-12-01 15:10:16 +00:00
|
|
|
| inputs buf
|
2017-11-24 16:56:55 +00:00
|
|
|
| outputs buf, y
|
|
|
|
| trashes a, z, n, ptr
|
|
|
|
| {
|
|
|
|
| ld y, 0
|
2017-12-01 12:36:58 +00:00
|
|
|
| copy ^buf, ptr
|
2017-11-24 16:56:55 +00:00
|
|
|
| copy 123, [ptr] + y
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDY #$00
|
|
|
|
= $080F LDA #$1C
|
|
|
|
= $0811 STA $FE
|
|
|
|
= $0813 LDA #$08
|
|
|
|
= $0815 STA $FF
|
|
|
|
= $0817 LDA #$7B
|
|
|
|
= $0819 STA ($FE),Y
|
|
|
|
= $081B RTS
|
2017-12-01 13:52:56 +00:00
|
|
|
|
|
|
|
Write stored value through a pointer.
|
|
|
|
|
|
|
|
| buffer[2048] buf
|
|
|
|
| pointer ptr @ 254
|
|
|
|
| byte foo
|
|
|
|
|
|
|
|
|
| routine main
|
2017-12-01 15:10:16 +00:00
|
|
|
| inputs foo, buf
|
|
|
|
| outputs y, buf
|
2017-12-01 13:52:56 +00:00
|
|
|
| trashes a, z, n, ptr
|
|
|
|
| {
|
|
|
|
| ld y, 0
|
|
|
|
| copy ^buf, ptr
|
|
|
|
| copy foo, [ptr] + y
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDY #$00
|
|
|
|
= $080F LDA #$1D
|
|
|
|
= $0811 STA $FE
|
|
|
|
= $0813 LDA #$08
|
|
|
|
= $0815 STA $FF
|
|
|
|
= $0817 LDA $101D
|
|
|
|
= $081A STA ($FE),Y
|
|
|
|
= $081C RTS
|
2017-12-01 13:52:56 +00:00
|
|
|
|
2017-12-13 16:11:02 +00:00
|
|
|
Read through a pointer, into a byte storage location, or the `a` register.
|
2017-12-01 13:52:56 +00:00
|
|
|
|
|
|
|
| buffer[2048] buf
|
|
|
|
| pointer ptr @ 254
|
|
|
|
| byte foo
|
|
|
|
|
|
|
|
|
| routine main
|
2017-12-01 15:10:16 +00:00
|
|
|
| inputs buf
|
2017-12-01 13:52:56 +00:00
|
|
|
| outputs y, foo
|
|
|
|
| trashes a, z, n, ptr
|
|
|
|
| {
|
|
|
|
| ld y, 0
|
|
|
|
| copy ^buf, ptr
|
|
|
|
| copy [ptr] + y, foo
|
2018-02-08 11:04:11 +00:00
|
|
|
| ld a, [ptr] + y
|
2017-12-01 13:52:56 +00:00
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDY #$00
|
2017-12-13 16:11:02 +00:00
|
|
|
= $080F LDA #$1F
|
2017-12-11 11:16:27 +00:00
|
|
|
= $0811 STA $FE
|
|
|
|
= $0813 LDA #$08
|
|
|
|
= $0815 STA $FF
|
|
|
|
= $0817 LDA ($FE),Y
|
2017-12-13 16:11:02 +00:00
|
|
|
= $0819 STA $101F
|
|
|
|
= $081C LDA ($FE),Y
|
|
|
|
= $081E RTS
|
2017-12-07 14:14:43 +00:00
|
|
|
|
2018-04-18 09:57:57 +00:00
|
|
|
Read and write through two pointers.
|
|
|
|
|
|
|
|
| buffer[2048] buf
|
|
|
|
| pointer ptra @ 252
|
|
|
|
| pointer ptrb @ 254
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs buf
|
|
|
|
| outputs buf
|
|
|
|
| trashes a, y, z, n, ptra, ptrb
|
|
|
|
| {
|
|
|
|
| ld y, 0
|
|
|
|
| copy ^buf, ptra
|
|
|
|
| copy ^buf, ptrb
|
|
|
|
| copy [ptra] + y, [ptrb] + y
|
|
|
|
| }
|
|
|
|
= $080D LDY #$00
|
|
|
|
= $080F LDA #$24
|
|
|
|
= $0811 STA $FC
|
|
|
|
= $0813 LDA #$08
|
|
|
|
= $0815 STA $FD
|
|
|
|
= $0817 LDA #$24
|
|
|
|
= $0819 STA $FE
|
|
|
|
= $081B LDA #$08
|
|
|
|
= $081D STA $FF
|
|
|
|
= $081F LDA ($FC),Y
|
|
|
|
= $0821 STA ($FE),Y
|
|
|
|
= $0823 RTS
|
|
|
|
|
2018-02-09 11:23:18 +00:00
|
|
|
Write the `a` register through a pointer.
|
|
|
|
|
|
|
|
| buffer[2048] buf
|
|
|
|
| pointer ptr @ 254
|
|
|
|
| byte foo
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs buf
|
|
|
|
| outputs buf
|
|
|
|
| trashes a, y, z, n, ptr
|
|
|
|
| {
|
|
|
|
| ld y, 0
|
|
|
|
| copy ^buf, ptr
|
|
|
|
| ld a, 255
|
|
|
|
| st a, [ptr] + y
|
|
|
|
| }
|
|
|
|
= $080D LDY #$00
|
|
|
|
= $080F LDA #$1C
|
|
|
|
= $0811 STA $FE
|
|
|
|
= $0813 LDA #$08
|
|
|
|
= $0815 STA $FF
|
|
|
|
= $0817 LDA #$FF
|
|
|
|
= $0819 STA ($FE),Y
|
|
|
|
= $081B RTS
|
|
|
|
|
2017-12-07 14:14:43 +00:00
|
|
|
Add a word memory location, and a literal word, to a pointer, and then read through it.
|
|
|
|
Note that this is *not* range-checked. (Yet.)
|
|
|
|
|
|
|
|
| buffer[2048] buf
|
|
|
|
| pointer ptr @ 254
|
|
|
|
| byte foo
|
|
|
|
| word delta
|
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs buf
|
|
|
|
| outputs y, foo, delta
|
2018-02-06 16:14:44 +00:00
|
|
|
| trashes a, c, v, z, n, ptr
|
2017-12-07 14:14:43 +00:00
|
|
|
| {
|
|
|
|
| copy 619, delta
|
|
|
|
| ld y, 0
|
2018-02-06 16:14:44 +00:00
|
|
|
| st off, c
|
2017-12-07 14:14:43 +00:00
|
|
|
| copy ^buf, ptr
|
|
|
|
| add ptr, delta
|
|
|
|
| add ptr, word 1
|
|
|
|
| copy [ptr] + y, foo
|
|
|
|
| }
|
2017-12-11 11:16:27 +00:00
|
|
|
= $080D LDA #$6B
|
2018-02-06 16:14:44 +00:00
|
|
|
= $080F STA $1043
|
2017-12-11 11:16:27 +00:00
|
|
|
= $0812 LDA #$02
|
2018-02-06 16:14:44 +00:00
|
|
|
= $0814 STA $1044
|
2017-12-11 11:16:27 +00:00
|
|
|
= $0817 LDY #$00
|
2018-02-06 16:14:44 +00:00
|
|
|
= $0819 CLC
|
|
|
|
= $081A LDA #$42
|
|
|
|
= $081C STA $FE
|
|
|
|
= $081E LDA #$08
|
|
|
|
= $0820 STA $FF
|
|
|
|
= $0822 LDA $FE
|
|
|
|
= $0824 ADC $1043
|
|
|
|
= $0827 STA $FE
|
|
|
|
= $0829 LDA $FF
|
|
|
|
= $082B ADC $1044
|
|
|
|
= $082E STA $FF
|
|
|
|
= $0830 LDA $FE
|
|
|
|
= $0832 ADC #$01
|
|
|
|
= $0834 STA $FE
|
|
|
|
= $0836 LDA $FF
|
|
|
|
= $0838 ADC #$00
|
|
|
|
= $083A STA $FF
|
|
|
|
= $083C LDA ($FE),Y
|
|
|
|
= $083E STA $1042
|
|
|
|
= $0841 RTS
|
2017-12-13 15:23:06 +00:00
|
|
|
|
|
|
|
### Trash
|
|
|
|
|
|
|
|
Trash does nothing except indicate that we do not care about the value anymore.
|
|
|
|
|
|
|
|
| routine main
|
|
|
|
| inputs a
|
|
|
|
| outputs x
|
|
|
|
| trashes a, z, n
|
|
|
|
| {
|
|
|
|
| ld x, a
|
|
|
|
| ld a, 0
|
|
|
|
| trash a
|
|
|
|
| }
|
|
|
|
= $080D TAX
|
|
|
|
= $080E LDA #$00
|
|
|
|
= $0810 RTS
|
2018-02-09 14:13:39 +00:00
|
|
|
|
|
|
|
### static ###
|
|
|
|
|
|
|
|
Memory locations defined static to a routine are allocated
|
|
|
|
just the same as initialized global storage locations are.
|
|
|
|
|
|
|
|
| define foo routine
|
|
|
|
| inputs x
|
|
|
|
| outputs x
|
|
|
|
| trashes z, n
|
2018-02-09 16:13:09 +00:00
|
|
|
| static byte t : 255
|
2018-02-09 14:13:39 +00:00
|
|
|
| {
|
|
|
|
| st x, t
|
|
|
|
| inc t
|
|
|
|
| ld x, t
|
|
|
|
| }
|
|
|
|
|
|
|
|
|
| define main routine
|
|
|
|
| trashes a, x, z, n
|
2018-02-09 16:13:09 +00:00
|
|
|
| static byte t : 7
|
2018-02-09 14:13:39 +00:00
|
|
|
| {
|
|
|
|
| ld x, t
|
|
|
|
| call foo
|
|
|
|
| }
|
2018-02-09 16:13:09 +00:00
|
|
|
= $080D LDX $081F
|
|
|
|
= $0810 JSR $0814
|
|
|
|
= $0813 RTS
|
|
|
|
= $0814 STX $081E
|
|
|
|
= $0817 INC $081E
|
|
|
|
= $081A LDX $081E
|
|
|
|
= $081D RTS
|
|
|
|
= $081E .byte $FF
|
|
|
|
= $081F .byte $07
|