put engine into seperate file
This commit is contained in:
parent
d876da7e11
commit
17fa654536
|
@ -0,0 +1,96 @@
|
|||
@k-tick
|
||||
&run
|
||||
.kalama/tick LDZ #01 ADD DUP
|
||||
.kalama/speed LDZ EQU ,&play JCN
|
||||
.kalama/tick STZ
|
||||
RTN
|
||||
&play
|
||||
#ff .kalama/tick STZ
|
||||
.kalama/line LDZ #01 ADD DUP
|
||||
DUP #00 SWP #0003 MUL2
|
||||
#00 ;k-get-pattern/run JSR2 ADD2 ;k-play-line/run JSR2
|
||||
#0f EQU ,&next JCN
|
||||
.kalama/line STZ
|
||||
RTN
|
||||
&next
|
||||
( TODO next pattern )
|
||||
#ff .kalama/line STZ
|
||||
RTN
|
||||
|
||||
( initialises kalama with module data )
|
||||
@k-init-module ( addr* -- )
|
||||
&run
|
||||
DUP2 .kalama/module STZ2 ( store module address )
|
||||
DUP2 LDA #0f AND .kalama/speed STZ ( set speed )
|
||||
#0001 ADD2 LDA ( get pattern count byte )
|
||||
;k-get-pattern/run JSR2 ( get the "pattern" that is 1 over the pattern index numbers. This is the first byte of the instruments )
|
||||
.kalama/instruments STZ2
|
||||
#ff .kalama/tick STZ
|
||||
#ff .kalama/line STZ
|
||||
|
||||
RTN
|
||||
|
||||
( gets the memory address of the given pattern in loaded module )
|
||||
@k-get-pattern ( number -- addr* )
|
||||
&run
|
||||
#00 SWP #0030 MUL2
|
||||
.kalama/module LDZ2
|
||||
#0003 ADD2 ( skip header )
|
||||
DUP2 LDA2 ADD2 ( skip song table body )
|
||||
#0002 ADD2 ( skip song table size short )
|
||||
ADD2
|
||||
|
||||
RTN
|
||||
|
||||
( gets the memory address of the given instrument in loaded module )
|
||||
@k-get-instrument ( number -- addr* )
|
||||
&run
|
||||
STH ( store instrument number for later )
|
||||
.kalama/instruments LDZ2
|
||||
( we are now at the size byte of instrument 00, the start of instrument memory )
|
||||
&loop
|
||||
STHrk #00 EQU ,&end JCN
|
||||
STHr #01 SUB STH ( decrement counter )
|
||||
DUP2 LDA2 ( load length byte and convert to short )
|
||||
#0006 ADD2 ( jump over length short, vol, flags, ADSR )
|
||||
ADD2 ( jump to next pattern )
|
||||
,&loop JMP
|
||||
|
||||
&end
|
||||
POPr
|
||||
RTN
|
||||
|
||||
@k-play-line ( *l -- )
|
||||
&run
|
||||
LDA DUP
|
||||
#00 EQU ,&rest JCN
|
||||
.Audio0/pitch DEO ( TODO use correct channel, effects )
|
||||
RTN
|
||||
&rest
|
||||
POP
|
||||
RTN
|
||||
|
||||
( loads instrument with number into specified audio channel, 0-indexed )
|
||||
@k-load-instrument ( number channel -- )
|
||||
&run
|
||||
#10 MUL STH ( stash channel * 0x10, offset for that channel's data relative to Audio0 )
|
||||
|
||||
;k-get-instrument JSR2 ( get instrument location )
|
||||
DUP2 LDA2 STHrk .Audio0/length ADD DEO2 ( copy ADSR value )
|
||||
#0002 ADD2 ( move to volume value )
|
||||
DUP2 LDA STHrk .Audio0/volume ADD DEO ( copy volume value )
|
||||
#0001 ADD2 DUP2 ( move to flags value )
|
||||
LDA #07 SFT ( MSB is set for looping sample, turn it into 0/1 )
|
||||
|
||||
DUP ( set or clear loop bit )
|
||||
#00 EQU ,&clear JCN
|
||||
STHrk SFT .kalama/loopflags LDZ ORA .kalama/loopflags STZ ( set bit on )
|
||||
,&end JMP
|
||||
&clear
|
||||
STHrk SFT #ff EOR .kalama/loopflags LDZ AND .kalama/loopflags STZ ( set bit off )
|
||||
&end
|
||||
|
||||
#0001 ADD2 LDA2 STHrk .Audio0/adsr DEO2 ( copy ADSR value )
|
||||
|
||||
POPr
|
||||
RTN
|
98
player.tal
98
player.tal
|
@ -52,102 +52,6 @@ BRK
|
|||
;k-tick/run JSR2
|
||||
BRK
|
||||
|
||||
@k-tick
|
||||
&run
|
||||
.kalama/tick LDZ #01 ADD DUP
|
||||
.kalama/speed LDZ EQU ,&play JCN
|
||||
.kalama/tick STZ
|
||||
RTN
|
||||
&play
|
||||
#ff .kalama/tick STZ
|
||||
.kalama/line LDZ #01 ADD DUP
|
||||
DUP #00 SWP #0003 MUL2
|
||||
#00 ;k-get-pattern/run JSR2 ADD2 ;k-play-line/run JSR2
|
||||
#0f EQU ,&next JCN
|
||||
.kalama/line STZ
|
||||
RTN
|
||||
&next
|
||||
( TODO next pattern )
|
||||
#ff .kalama/line STZ
|
||||
RTN
|
||||
|
||||
( initialises kalama with module data )
|
||||
@k-init-module ( addr* -- )
|
||||
&run
|
||||
DUP2 .kalama/module STZ2 ( store module address )
|
||||
DUP2 LDA #0f AND .kalama/speed STZ ( set speed )
|
||||
#0001 ADD2 LDA ( get pattern count byte )
|
||||
;k-get-pattern/run JSR2 ( get the "pattern" that is 1 over the pattern index numbers. This is the first byte of the instruments )
|
||||
.kalama/instruments STZ2
|
||||
#ff .kalama/tick STZ
|
||||
#ff .kalama/line STZ
|
||||
|
||||
RTN
|
||||
|
||||
( gets the memory address of the given pattern in loaded module )
|
||||
@k-get-pattern ( number -- addr* )
|
||||
&run
|
||||
#00 SWP #0030 MUL2
|
||||
.kalama/module LDZ2
|
||||
#0003 ADD2 ( skip header )
|
||||
DUP2 LDA2 ADD2 ( skip song table body )
|
||||
#0002 ADD2 ( skip song table size short )
|
||||
ADD2
|
||||
|
||||
RTN
|
||||
|
||||
( gets the memory address of the given instrument in loaded module )
|
||||
@k-get-instrument ( number -- addr* )
|
||||
&run
|
||||
STH ( store instrument number for later )
|
||||
.kalama/instruments LDZ2
|
||||
( we are now at the size byte of instrument 00, the start of instrument memory )
|
||||
&loop
|
||||
STHrk #00 EQU ,&end JCN
|
||||
STHr #01 SUB STH ( decrement counter )
|
||||
DUP2 LDA2 ( load length byte and convert to short )
|
||||
#0006 ADD2 ( jump over length short, vol, flags, ADSR )
|
||||
ADD2 ( jump to next pattern )
|
||||
,&loop JMP
|
||||
|
||||
&end
|
||||
POPr
|
||||
RTN
|
||||
|
||||
@k-play-line ( *l -- )
|
||||
&run
|
||||
LDA DUP
|
||||
#00 EQU ,&rest JCN
|
||||
.Audio0/pitch DEO ( TODO use correct channel, effects )
|
||||
RTN
|
||||
&rest
|
||||
POP
|
||||
RTN
|
||||
|
||||
( loads instrument with number into specified audio channel, 0-indexed )
|
||||
@k-load-instrument ( number channel -- )
|
||||
&run
|
||||
#10 MUL STH ( stash channel * 0x10, offset for that channel's data relative to Audio0 )
|
||||
|
||||
;k-get-instrument JSR2 ( get instrument location )
|
||||
DUP2 LDA2 STHrk .Audio0/length ADD DEO2 ( copy ADSR value )
|
||||
#0002 ADD2 ( move to volume value )
|
||||
DUP2 LDA STHrk .Audio0/volume ADD DEO ( copy volume value )
|
||||
#0001 ADD2 DUP2 ( move to flags value )
|
||||
LDA #07 SFT ( MSB is set for looping sample, turn it into 0/1 )
|
||||
|
||||
DUP ( set or clear loop bit )
|
||||
#00 EQU ,&clear JCN
|
||||
STHrk SFT .kalama/loopflags LDZ ORA .kalama/loopflags STZ ( set bit on )
|
||||
,&end JMP
|
||||
&clear
|
||||
STHrk SFT #ff EOR .kalama/loopflags LDZ AND .kalama/loopflags STZ ( set bit off )
|
||||
&end
|
||||
|
||||
#0001 ADD2 LDA2 STHrk .Audio0/adsr DEO2 ( copy ADSR value )
|
||||
|
||||
POPr
|
||||
RTN
|
||||
|
||||
@print-hex ( value* -- )
|
||||
|
||||
|
@ -180,6 +84,8 @@ RTN
|
|||
|
||||
RTN
|
||||
|
||||
~engine.tal
|
||||
|
||||
@module
|
||||
88 02 02 ( file header - speed 8, loop on, 2 patterns, 2 instruments )
|
||||
0008 ( size )
|
||||
|
|
Reference in New Issue