Compare commits

...

3 Commits

Author SHA1 Message Date
Nico e1f50db931 play song sequence 2022-01-10 23:41:14 +00:00
Nico 99ab8482f4 fix stack overflow, set up pallete to run debugger 2022-01-10 21:30:34 +00:00
Nico 17fa654536 put engine into seperate file 2022-01-10 08:18:54 +00:00
2 changed files with 147 additions and 130 deletions

111
engine.tal Normal file
View File

@ -0,0 +1,111 @@
( TODO
commmands
song playback
multiple channels )
@k-tick
&run
.kalama/tick LDZ #01 ADD DUP
.kalama/speed LDZ EQU ,&play JCN
.kalama/tick STZ
RTN
&play
POP
#ff .kalama/tick STZ
.kalama/line LDZ #01 ADD DUP
DUP #00 SWP #0003 MUL2
.kalama/songpos LDZ2 #0005 ADD2 .kalama/module LDZ2 ADD2 ( song position ) LDA ;k-get-pattern/run JSR2 ADD2 #00 ;k-play-line/run JSR2
#0f EQU ,&next JCN
.kalama/line STZ
RTN
&next
( TODO respect if song loops or not )
POP
#ff .kalama/line STZ .kalama/songpos LDZ2 #0004 ADD2 DUP2
.kalama/module LDZ2 #0003 ADD2 LDA2 ( song length ) EQU2 ,&reset JCN
.kalama/songpos STZ2
RTN
&reset
POP
#0000 .kalama/songpos STZ2
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
#0000 .kalama/songpos STZ2
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 instrument )
,&loop JMP
&end
POPr
RTN
@k-play-line ( *l channel -- )
&chan $1
&run
#10 MUL ,&chan STR
LDA DUP
#00 EQU ,&rest JCN
.Audio0/pitch ,&chan LDR ADD DEO ( TODO use correct channel, effects, use loop bit )
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

View File

@ -30,12 +30,12 @@
&tick $1
&line $1
&speed $1
&songpos $2 ( position in song table )
( program )
|0100 ( -> )
( theme )
#0fe5 .System/r DEO2
#0fc5 .System/g DEO2
#0f25 .System/b DEO2
@ -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,45 +84,47 @@ RTN
RTN
~engine.tal
@module
88 02 02 ( file header - speed 8, loop on, 2 patterns, 2 instruments )
8f 02 02 ( file header - speed 8, loop on, 2 patterns, 2 instruments )
0008 ( size )
00 00 ff ff
00 01 ff ff ( song table, 2 rows )
00 ff ff ff
01 ff ff ff ( song table, 2 rows )
( pattern 00 )
3c 02 00 ( C-3 I00 )
00 00 00
54 02 00 ( C-3 I00 )
52 00 00
54 00 00
4f 00 00
4b 00 00
4f 00 00
48 00 00
ff 00 00
54 02 00
52 00 00
54 00 00
4f 00 00
4b 00 00
4f 00 00
48 00 00
ff 00 00
00 00 00
3c 00 00
00 00 00
00 00 00
00 00 00
3c 00 00
00 00 00
00 00 00
00 00 00
3c 00 00
00 00 00
00 00 00
00 00 00
( pattern 01 )
54 00 00
56 02 00 ( C-3 I00 )
57 00 00
56 00 00
57 00 00
54 00 00
56 00 00
54 00 00
56 00 00
52 00 00
54 00 00
52 00 00
54 00 00
50 00 00
54 00 00
ff 00 00
3c 02 00 ( C-3 I00 )
ff 00 00
3c 00 00
ff 00 00
3c 00 00
ff 00 00
3c 00 00
ff 00 00
3c 00 00
ff 00 00
3c 00 00
ff 00 00
3c 00 00
ff 00 00
3c 00 00
( instrument 00 )
0002 ( sample length )
ff ( volume )