; Furnace Command Stream player for 6502 architecture ; written by tildearrow ; usage: ; call fcsInit - this sets A to 0 on success or 1 on failure ; call fcsTick on every frame/tick/whatever ; - call your dispatch implementation's tick function afterwards ; notes: ; - short pointers only ; - little-endian only! .include "6502base.i" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; constants FCS_MAX_CHAN=8 ; maximum number of channels (up to 127, but see below!) FCS_MAX_STACK=16 ; stack depth per channel (FCS_MAX_STACK*FCS_MAX_CHAN<256) ; player constants - change if necessary fcsAddrBase=$20 ; player state address base fcsZeroPage=$10 ; player state address base for zero-page-mandatory variables fcsGlobalStack=$200 ; player stack (best placed in a page) fcsPtr=$8000 ; pointer to command stream fcsVolMax=fcsVolMaxExample ; pointer to max channel volume array ; calculated from player constants fcsDelays=fcsPtr+8 fcsSpeedDial=fcsPtr+24 ; command call table ; - see src/engine/dispatch.h for a list of commands to be potentially handled ; - do not implement HINT commands - the player will never send these ; - no need to implement commands not pertaining to the target system ; - a zero pointer means "don't handle" fcsCmdTableLow=fcsCmdTableExample fcsCmdTableHigh=fcsCmdTableExample ; variables ; these may be read by your command handling routines fcsArg0=fcsAddrBase ; int fcsArg1=fcsAddrBase+4 ; int ; something else fcsTicks=fcsAddrBase+8 ; short ; temporary variables fcsSendVolume=fcsAddrBase+10 ; char fcsSendPitch=fcsAddrBase+11 ; char fcsCmd=fcsAddrBase+16 ; char[8] fcsTempPtr=fcsZeroPage ; short ; channel state chanPC=fcsZeroPage+2 ; short chanTicks=fcsAddrBase+24 ; short chanStackPtr=fcsAddrBase+24+(FCS_MAX_CHAN*2) ; char chanNote=fcsAddrBase+24+(FCS_MAX_CHAN*2)+1 ; char chanVibratoPos=fcsAddrBase+24+(FCS_MAX_CHAN*4) ; char ; may be used for driver detection fcsDriverInfo: .db "Furnace" .db 0 ; note on null fcsNoteOnNull: lda #0 sta chanVibratoPos,x jsr fcsDispatchCmd rts ; note off, note off env, env release fcsNoArgDispatch: jsr fcsDispatchCmd rts fcsOneByteDispatch: tya pha jsr fcsReadNext sta fcsArg0 pla tay jsr fcsDispatchCmd rts fcsNoOp: rts ; x: channel*2 ; y: command fcsDispatchCmd: ; read command call table lda fcsCmdTableLow,y sta fcsTempPtr lda fcsCmdTableHigh,y sta fcsTempPtr+1 ; check for zero lda fcsTempPtr ora fcsTempPtr beq + ; get out ; handle command in dispatch code jmp (fcsTempPtr) ; only if pointer is zero + rts ; x: channel*2 ; a is set to next byte fcsReadNext: ; a=chanPC[x]+fcsPtr clc lda chanPC,x adc #>fcsPtr sta fcsTempPtr lda chanPC+1,x adc #