diff --git a/src/asm/6502/nes/test.s b/src/asm/6502/nes/test.s index df9d09000..a77511523 100644 --- a/src/asm/6502/nes/test.s +++ b/src/asm/6502/nes/test.s @@ -8,6 +8,10 @@ curChan=$401 joyInput=$402 joyPrev=$403 +tempNote=$0a +tempOctave=$0b +temp16=$0c + ; program ROM .BANK 1 SLOT 1 .ORGA $8000 @@ -278,9 +282,97 @@ fcsGlobalStack=$200 fcsPtr=cmdStream 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 -fcsCmdTableLow=fcsCmdTableExample -fcsCmdTableHigh=fcsCmdTableExample +fcsCmdTableLow=cmdTableLow +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 .include "../stream.s" diff --git a/src/asm/6502/stream.s b/src/asm/6502/stream.s index bd98270c9..d2347a5ba 100644 --- a/src/asm/6502/stream.s +++ b/src/asm/6502/stream.s @@ -74,6 +74,12 @@ fcsDriverInfo: + .ENDM +; same as fcsReadNext, but don't change PC +.MACRO fcsPeekNext + ; a=chanPC[x] + lda (chanPC,x) +.ENDM + ; note on null fcsNoteOnNull: lda #0 @@ -272,7 +278,16 @@ fcsCallI: ; ignore next two bytes 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 sta chanPC+1,x pla @@ -322,39 +337,33 @@ fcsCall: fcsReadNext adc #>fcsPtr pha - jsr fcsPushCall - pla - sta chanPC+1,x - pla - sta chanPC,x - rts - -; push channel PC to stack -fcsPushCall: - lda chanStackPtr,x - tay + ; fcsPushCall BEGIN + ; push channel PC to stack + ldy chanStackPtr,x lda chanPC,x sta fcsGlobalStack,y iny lda chanPC+1,x sta fcsGlobalStack,y iny - tya - sta chanStackPtr,x + sty chanStackPtr,x + ; fcsPushCall END + pla + sta chanPC+1,x + pla + sta chanPC,x rts ; retrieve channel PC from stack fcsRet: - lda chanStackPtr,x - tay + ldy chanStackPtr,x dey lda fcsGlobalStack,y sta chanPC+1,x dey lda fcsGlobalStack,y sta chanPC,x - tya - sta chanStackPtr,x + sty chanStackPtr,x rts fcsJump: @@ -363,13 +372,8 @@ fcsJump: clc adc #fcsPtr - pha - ; ignore next two bytes - jsr fcsIgnoreNext - jsr fcsIgnoreNext - pla sta chanPC+1,x pla sta chanPC,x @@ -1198,21 +1202,3 @@ fcsFullCmdTable: .db 1 ; WonderSwan speaker vol .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 diff --git a/src/asm/6502/stream_example.i b/src/asm/6502/stream_example.i index 950fd71eb..658902a34 100644 --- a/src/asm/6502/stream_example.i +++ b/src/asm/6502/stream_example.i @@ -18,3 +18,21 @@ fcsVolMax=fcsVolMaxExample ; pointer to max channel volume array ; - a zero pointer means "don't handle" fcsCmdTableLow=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