6502 command stream player, part 19

move example command table to stream_example.i
prepare for dispatch building blocks (pitch calculation in particular)
This commit is contained in:
tildearrow 2025-04-23 19:25:41 -05:00
parent 823488b6d1
commit 3baaf05647
3 changed files with 140 additions and 44 deletions

View file

@ -8,6 +8,10 @@ curChan=$401
joyInput=$402 joyInput=$402
joyPrev=$403 joyPrev=$403
tempNote=$0a
tempOctave=$0b
temp16=$0c
; program ROM ; program ROM
.BANK 1 SLOT 1 .BANK 1 SLOT 1
.ORGA $8000 .ORGA $8000
@ -278,9 +282,97 @@ fcsGlobalStack=$200
fcsPtr=cmdStream fcsPtr=cmdStream
fcsVolMax=volMaxArray fcsVolMax=volMaxArray
exampleNoteTable:
.dw $06ad*2, $064d*2, $05f3*2, $059d*2, $054c*2, $0500*2, $04b8*2, $0474*2, $0434*2, $03f8*2, $03bf*2, $0389*2
; >>2
noteSubTable:
.db 0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180
; >>2
octaveTable:
.db 0, 0, 0
.db 1, 1, 1
.db 2, 2, 2
.db 3, 3, 3
.db 4, 4, 4
.db 5, 5, 5
.db 6, 6, 6
.db 7, 7, 7
.db 8, 8, 8
.db 9, 9, 9
.db 10, 10, 10
.db 11, 11, 11
.db 12, 12, 12
.db 13, 13, 13
.db 14, 14, 14
.db 15, 15, 15
; command call table ; command call table
fcsCmdTableLow=fcsCmdTableExample fcsCmdTableLow=cmdTableLow
fcsCmdTableHigh=fcsCmdTableExample fcsCmdTableHigh=cmdTableHigh
; calculate note_and octave from single-byte note_
; a: note_from 0-180
; set a to note_, and y to octave
calcNoteOctave:
; push a for later use
pha
; divide by 4 for indexing in the octave table
lsr
lsr
tay
; get the octave and put it into y
lda octaveTable,y
tay
; pull a (contains note_from 0-180)
pla
; subtract it with the note_sub table to clamp note_to 0-12
sec
sbc noteSubTable,y
; end
rts
noteOnHandler:
txa
lsr
cmp curChan
beq +
rts
; note_on handler
+ lda fcsArg0
sec
sbc #72
jsr calcNoteOctave
clc
rol
tay
lda exampleNoteTable+1,y
pha
lda exampleNoteTable,y
pha
; make a sound
lda #$01
sta $4015
lda #$04
sta $4000
lda #$08
sta $4001
pla
sta $4002
pla
ora #$08
sta $4003
rts
cmdTableLow:
.db <noteOnHandler
.dsb 255, 0
cmdTableHigh:
.db >noteOnHandler
.dsb 255, 0
.include "../stream.s" .include "../stream.s"

View file

@ -74,6 +74,12 @@ fcsDriverInfo:
+ +
.ENDM .ENDM
; same as fcsReadNext, but don't change PC
.MACRO fcsPeekNext
; a=chanPC[x]
lda (chanPC,x)
.ENDM
; note on null ; note on null
fcsNoteOnNull: fcsNoteOnNull:
lda #0 lda #0
@ -272,7 +278,16 @@ fcsCallI:
; ignore next two bytes ; ignore next two bytes
jsr fcsIgnoreNext jsr fcsIgnoreNext
jsr fcsIgnoreNext jsr fcsIgnoreNext
jsr fcsPushCall ; fcsPushCall BEGIN
ldy chanStackPtr,x
lda chanPC,x
sta fcsGlobalStack,y
iny
lda chanPC+1,x
sta fcsGlobalStack,y
iny
sty chanStackPtr,x
; fcsPushCall END
pla pla
sta chanPC+1,x sta chanPC+1,x
pla pla
@ -322,39 +337,33 @@ fcsCall:
fcsReadNext fcsReadNext
adc #>fcsPtr adc #>fcsPtr
pha pha
jsr fcsPushCall ; fcsPushCall BEGIN
pla ; push channel PC to stack
sta chanPC+1,x ldy chanStackPtr,x
pla
sta chanPC,x
rts
; push channel PC to stack
fcsPushCall:
lda chanStackPtr,x
tay
lda chanPC,x lda chanPC,x
sta fcsGlobalStack,y sta fcsGlobalStack,y
iny iny
lda chanPC+1,x lda chanPC+1,x
sta fcsGlobalStack,y sta fcsGlobalStack,y
iny iny
tya sty chanStackPtr,x
sta chanStackPtr,x ; fcsPushCall END
pla
sta chanPC+1,x
pla
sta chanPC,x
rts rts
; retrieve channel PC from stack ; retrieve channel PC from stack
fcsRet: fcsRet:
lda chanStackPtr,x ldy chanStackPtr,x
tay
dey dey
lda fcsGlobalStack,y lda fcsGlobalStack,y
sta chanPC+1,x sta chanPC+1,x
dey dey
lda fcsGlobalStack,y lda fcsGlobalStack,y
sta chanPC,x sta chanPC,x
tya sty chanStackPtr,x
sta chanStackPtr,x
rts rts
fcsJump: fcsJump:
@ -363,13 +372,8 @@ fcsJump:
clc clc
adc #<fcsPtr adc #<fcsPtr
pha pha
fcsReadNext fcsPeekNext
adc #>fcsPtr adc #>fcsPtr
pha
; ignore next two bytes
jsr fcsIgnoreNext
jsr fcsIgnoreNext
pla
sta chanPC+1,x sta chanPC+1,x
pla pla
sta chanPC,x sta chanPC,x
@ -1198,21 +1202,3 @@ fcsFullCmdTable:
.db 1 .db 1
; WonderSwan speaker vol ; WonderSwan speaker vol
.db 1 .db 1
; "dummy" implementation - example only!
fcsDummyFunc:
rts
fcsVolMaxExample:
.db $7f, $00
.db $7f, $00
.db $7f, $00
.db $7f, $00
.db $7f, $00
.db $7f, $00
.db $7f, $00
.db $7f, $00
fcsCmdTableExample:
.dsb 256, 0

View file

@ -18,3 +18,21 @@ fcsVolMax=fcsVolMaxExample ; pointer to max channel volume array
; - a zero pointer means "don't handle" ; - a zero pointer means "don't handle"
fcsCmdTableLow=fcsCmdTableExample fcsCmdTableLow=fcsCmdTableExample
fcsCmdTableHigh=fcsCmdTableExample fcsCmdTableHigh=fcsCmdTableExample
; "dummy" implementation - example only!
fcsDummyFunc:
rts
fcsVolMaxExample:
.db $7f, $00
.db $7f, $00
.db $7f, $00
.db $7f, $00
.db $7f, $00
.db $7f, $00
.db $7f, $00
.db $7f, $00
fcsCmdTableExample:
.dsb 256, 0