2014-04-03 12:32:06 +00:00
|
|
|
Emitting Ophis from SixtyPical Programs
|
|
|
|
=======================================
|
|
|
|
|
|
|
|
-> Tests for functionality "Emit ASM for SixtyPical program"
|
|
|
|
|
|
|
|
-> Functionality "Emit ASM for SixtyPical program" is implemented by
|
|
|
|
-> shell command "bin/sixtypical emit %(test-file)"
|
|
|
|
|
2014-04-03 13:30:27 +00:00
|
|
|
Emitting an `if`.
|
|
|
|
|
2014-04-03 12:32:06 +00:00
|
|
|
| assign byte screen $0400
|
|
|
|
| routine main {
|
|
|
|
| lda screen
|
|
|
|
| cmp screen
|
|
|
|
| if beq {
|
|
|
|
| tax
|
|
|
|
| } else {
|
|
|
|
| tay
|
|
|
|
| }
|
|
|
|
| sta screen
|
|
|
|
| }
|
|
|
|
= main:
|
|
|
|
= lda screen
|
|
|
|
= cmp screen
|
|
|
|
= BEQ _label_1
|
|
|
|
= tay
|
|
|
|
= jmp _past_1
|
|
|
|
= _label_1:
|
|
|
|
= tax
|
|
|
|
= _past_1:
|
|
|
|
= sta screen
|
|
|
|
= rts
|
|
|
|
=
|
2014-04-11 20:05:00 +00:00
|
|
|
= .data
|
2014-04-03 12:32:06 +00:00
|
|
|
= .alias screen 1024
|
|
|
|
|
2014-04-03 13:30:27 +00:00
|
|
|
Emitting a `repeat`.
|
|
|
|
|
2014-04-03 12:32:06 +00:00
|
|
|
| assign byte screen 1024
|
2014-04-11 19:35:45 +00:00
|
|
|
| reserve byte four : $04
|
2014-04-03 12:32:06 +00:00
|
|
|
| routine main {
|
2014-04-11 19:35:45 +00:00
|
|
|
| ldy four
|
2014-04-03 12:32:06 +00:00
|
|
|
| repeat bne {
|
|
|
|
| inc screen
|
|
|
|
| dey
|
2014-04-11 19:35:45 +00:00
|
|
|
| cpy four
|
2014-04-03 12:32:06 +00:00
|
|
|
| }
|
|
|
|
| sty screen
|
|
|
|
| }
|
|
|
|
= main:
|
2014-04-11 19:35:45 +00:00
|
|
|
= ldy four
|
2014-04-03 12:32:06 +00:00
|
|
|
=
|
|
|
|
= _repeat_1:
|
|
|
|
= inc screen
|
|
|
|
= dey
|
2014-04-11 19:35:45 +00:00
|
|
|
= cpy four
|
2014-04-03 12:32:06 +00:00
|
|
|
= BNE _repeat_1
|
|
|
|
= sty screen
|
|
|
|
= rts
|
|
|
|
=
|
2014-04-11 19:35:45 +00:00
|
|
|
= four: .byte 4
|
2014-04-11 20:05:00 +00:00
|
|
|
= .data
|
|
|
|
= .alias screen 1024
|
2014-04-03 12:32:06 +00:00
|
|
|
|
|
|
|
Nested ifs.
|
|
|
|
|
|
|
|
| routine main {
|
|
|
|
| if beq {
|
|
|
|
| if bcc {
|
|
|
|
| lda #0
|
|
|
|
| } else {
|
|
|
|
| if bvs {
|
|
|
|
| lda #1
|
|
|
|
| } else {
|
|
|
|
| lda #2
|
|
|
|
| }
|
|
|
|
| }
|
|
|
|
| } else {
|
|
|
|
| lda #3
|
|
|
|
| }
|
|
|
|
| }
|
|
|
|
= main:
|
|
|
|
= BEQ _label_3
|
|
|
|
= lda #3
|
|
|
|
= jmp _past_3
|
|
|
|
= _label_3:
|
|
|
|
= BCC _label_2
|
|
|
|
= BVS _label_1
|
|
|
|
= lda #2
|
|
|
|
= jmp _past_1
|
|
|
|
= _label_1:
|
|
|
|
= lda #1
|
|
|
|
= _past_1:
|
|
|
|
= jmp _past_2
|
|
|
|
= _label_2:
|
|
|
|
= lda #0
|
|
|
|
= _past_2:
|
|
|
|
= _past_3:
|
|
|
|
= rts
|
|
|
|
|
|
|
|
Installing an interrupt handler (at the Kernal level, i.e. with CINV)
|
|
|
|
|
|
|
|
| assign byte screen 1024
|
|
|
|
| assign vector cinv 788
|
|
|
|
| reserve vector save_cinv
|
|
|
|
|
|
|
|
|
| routine main {
|
2014-04-11 20:26:27 +00:00
|
|
|
| with sei {
|
2014-04-03 21:07:19 +00:00
|
|
|
| copy cinv save_cinv
|
2014-04-03 12:32:06 +00:00
|
|
|
| copy routine our_cinv to cinv
|
|
|
|
| }
|
|
|
|
| }
|
|
|
|
|
|
|
|
|
| routine our_cinv {
|
|
|
|
| inc screen
|
2014-04-03 17:52:58 +00:00
|
|
|
| jmp (save_cinv)
|
2014-04-03 12:32:06 +00:00
|
|
|
| }
|
|
|
|
= main:
|
|
|
|
= sei
|
|
|
|
= lda cinv
|
|
|
|
= sta save_cinv
|
|
|
|
= lda cinv+1
|
|
|
|
= sta save_cinv+1
|
|
|
|
= lda #<our_cinv
|
|
|
|
= sta cinv
|
|
|
|
= lda #>our_cinv
|
|
|
|
= sta cinv+1
|
|
|
|
= cli
|
|
|
|
= rts
|
|
|
|
=
|
|
|
|
= our_cinv:
|
|
|
|
= inc screen
|
|
|
|
= jmp (save_cinv)
|
|
|
|
= rts
|
|
|
|
=
|
2014-04-11 20:05:00 +00:00
|
|
|
= .data
|
2014-04-03 12:32:06 +00:00
|
|
|
= .alias screen 1024
|
|
|
|
= .alias cinv 788
|
2014-04-11 20:05:00 +00:00
|
|
|
= .space save_cinv 2
|
2014-04-03 21:07:19 +00:00
|
|
|
|
|
|
|
Copy command: immediate -> byte
|
|
|
|
|
|
|
|
| reserve byte position
|
|
|
|
| routine main {
|
|
|
|
| copy #23 position
|
|
|
|
| }
|
|
|
|
= main:
|
|
|
|
= lda #23
|
|
|
|
= sta position
|
|
|
|
= rts
|
|
|
|
=
|
2014-04-11 20:05:00 +00:00
|
|
|
= .data
|
|
|
|
= .space position 1
|
2014-04-03 21:07:19 +00:00
|
|
|
|
|
|
|
Copy command: immediate -> word
|
|
|
|
|
|
|
|
| reserve word position
|
|
|
|
| routine main {
|
|
|
|
| copy #$0400 position
|
|
|
|
| }
|
|
|
|
= main:
|
|
|
|
= lda #0
|
|
|
|
= sta position
|
|
|
|
= lda #4
|
|
|
|
= sta position+1
|
|
|
|
= rts
|
|
|
|
=
|
2014-04-11 20:05:00 +00:00
|
|
|
= .data
|
|
|
|
= .space position 2
|
2014-04-04 15:54:25 +00:00
|
|
|
|
|
|
|
`main` is always emitted first.
|
|
|
|
|
|
|
|
| reserve word position
|
|
|
|
| routine foo {
|
|
|
|
| inx
|
|
|
|
| }
|
|
|
|
| routine main {
|
|
|
|
| jsr foo
|
|
|
|
| jsr foo
|
|
|
|
| }
|
|
|
|
= main:
|
|
|
|
= jsr foo
|
|
|
|
= jsr foo
|
|
|
|
= rts
|
|
|
|
=
|
|
|
|
= foo:
|
|
|
|
= inx
|
|
|
|
= rts
|
|
|
|
=
|
2014-04-11 20:05:00 +00:00
|
|
|
= .data
|
|
|
|
= .space position 2
|
2014-04-11 20:47:18 +00:00
|
|
|
|
|
|
|
Reserving and assigning byte tables.
|
|
|
|
|
|
|
|
| reserve byte[16] frequencies
|
|
|
|
| assign byte[256] screen $0400
|
|
|
|
| routine main {
|
|
|
|
| lda #0
|
|
|
|
| ldy #0
|
|
|
|
| sta frequencies, y
|
|
|
|
| sta screen, y
|
|
|
|
| }
|
|
|
|
= main:
|
|
|
|
= lda #0
|
|
|
|
= ldy #0
|
|
|
|
= sta frequencies, y
|
|
|
|
= sta screen, y
|
|
|
|
= rts
|
|
|
|
=
|
|
|
|
= .data
|
|
|
|
= .space frequencies 16
|
|
|
|
= .alias screen 1024
|
|
|
|
|
2014-04-12 12:55:08 +00:00
|
|
|
Reserving things with initial values.
|
|
|
|
|
|
|
|
| reserve byte lives : 3
|
|
|
|
| reserve word screen : $0400
|
|
|
|
| reserve byte[8] frequencies : (0 1 2 4 5 8 9 10)
|
|
|
|
| reserve byte[13] message : "Hello, world!"
|
|
|
|
| routine main {
|
|
|
|
| }
|
|
|
|
= main:
|
|
|
|
= rts
|
|
|
|
=
|
|
|
|
= lives: .byte 3
|
|
|
|
= screen: .word 1024
|
|
|
|
= frequencies: .byte 0, 1, 2, 4, 5, 8, 9, 10
|
|
|
|
= message: .byte 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33
|
|
|
|
|
2014-04-11 21:50:03 +00:00
|
|
|
Temporary storage, in the form of block-local declarations. Note that these
|
|
|
|
temporaries are not unioned yet, but they could be.
|
|
|
|
|
|
|
|
| routine a {
|
|
|
|
| reserve byte foo
|
|
|
|
| reserve word bar
|
|
|
|
| lda foo
|
|
|
|
| sta >bar
|
|
|
|
| }
|
|
|
|
| routine b {
|
|
|
|
| reserve byte baz
|
|
|
|
| reserve word quuz
|
|
|
|
| lda baz
|
|
|
|
| sta <quuz
|
|
|
|
| }
|
|
|
|
| routine main {
|
|
|
|
| jsr a
|
|
|
|
| jsr b
|
|
|
|
| }
|
|
|
|
= main:
|
|
|
|
= jsr a
|
|
|
|
= jsr b
|
|
|
|
= rts
|
2014-04-12 11:16:09 +00:00
|
|
|
=
|
2014-04-11 21:50:03 +00:00
|
|
|
= a:
|
|
|
|
= lda _temp_1
|
|
|
|
= sta _temp_2+1
|
|
|
|
= rts
|
2014-04-12 11:16:09 +00:00
|
|
|
=
|
2014-04-11 21:50:03 +00:00
|
|
|
= b:
|
|
|
|
= lda _temp_3
|
|
|
|
= sta _temp_4
|
|
|
|
= rts
|
|
|
|
=
|
|
|
|
= .data
|
2014-04-12 11:16:09 +00:00
|
|
|
= .space _temp_3 1
|
|
|
|
= .space _temp_4 2
|
2014-04-11 21:50:03 +00:00
|
|
|
= .space _temp_1 1
|
|
|
|
= .space _temp_2 2
|