single-pattern playback working

This commit is contained in:
Nico 2022-01-10 08:14:13 +00:00
parent d23350ebcb
commit d876da7e11
2 changed files with 79 additions and 45 deletions

View File

@ -47,11 +47,9 @@ a song row is 4 bytes. Each byte is a pattern number, with the first byte being
## Patterns ## Patterns
Patterns contain a short containing the size of the pattern in bytes, and 0x10 lines of note data. Patterns are ordered sequentially in the file and there can be up to 255 patterns in a file. Patterns contain 0x10 lines of note data. Patterns are ordered sequentially in the file and there can be up to 255 patterns in a file.
### Pattern lines A pattern line consists of 3 bytes. The first byte contains a note and the next two bytes contain an effect and a parameter for that effect. No note is represented by the byte 00. 0xff represents a note off/note stop. No effect is also represented by 00.
A pattern line consists of either 1 or 3 bytes, depending on if the most significant bit of the first byte is high. The 7 remaining bits of the first byte are the note value, with the MSB being set if the line contains an effect and not otherwise. If the line contains an effect, the next two bytes contain an effect and a parameter for that effect. No note is represented by the byte 00. 0x7f represents a note off/note stop.
### Effects ### Effects

View File

@ -27,6 +27,9 @@
&module $2 ( pointer to start of module file ) &module $2 ( pointer to start of module file )
&loopflags $1 ( if different channels are set to loop ) &loopflags $1 ( if different channels are set to loop )
&instruments $2 ( address that instruments start at ) &instruments $2 ( address that instruments start at )
&tick $1
&line $1
&speed $1
( program ) ( program )
@ -37,47 +40,60 @@
#0fc5 .System/g DEO2 #0fc5 .System/g DEO2
#0f25 .System/b DEO2 #0f25 .System/b DEO2
;module ;k-init-module JSR2 ;module ;k-init-module JSR2
#00 #00 ;k-load-instrument JSR2
;on-frame/run .Screen/vector DEO2 ;on-frame/run .Screen/vector DEO2
#00 #00 ;k-load-instrument/run JSR2
#3c .Audio0/pitch DEO
BRK BRK
@on-frame ( -> ) @on-frame ( -> )
&run &run
;k-tick/run JSR2
BRK 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 ) ( initialises kalama with module data )
@k-init-module ( addr* -- ) @k-init-module ( addr* -- )
&run &run
DUP2 .kalama/module STZ2 ( store module address ) DUP2 .kalama/module STZ2 ( store module address )
DUP2 LDA #0f AND .kalama/speed STZ ( set speed )
#0001 ADD2 LDA ( get pattern count byte ) #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 ) ;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 .kalama/instruments STZ2
#ff .kalama/tick STZ
#ff .kalama/line STZ
RTN RTN
( gets the memory address of the given pattern in loaded module ) ( gets the memory address of the given pattern in loaded module )
@k-get-pattern ( number -- addr* ) @k-get-pattern ( number -- addr* )
&run &run
STH ( stash pattern number to return stack for loop counter later ) #00 SWP #0030 MUL2
.kalama/module LDZ2 ( get module start address ) .kalama/module LDZ2
#0003 ADD2 ( skip header ) #0003 ADD2 ( skip header )
DUP2 LDA2 ( load pattern table length ) DUP2 LDA2 ADD2 ( skip song table body )
#0002 ADD2 ( skip pattern table length byte ) #0002 ADD2 ( skip song table size short )
ADD2 ( and skip the pattern table ) ADD2
( we are now at the size byte of pattern 00 )
&loop
STHrk #00 EQU ,&end JCN
STHr #01 SUB STH ( decrement counter )
DUP2 LDA #00 SWP ( load length byte and convert to short )
#0001 ADD2 ( jump over length byte )
ADD2 ( jump to next pattern )
,&loop JMP
&end
POPr
RTN RTN
( gets the memory address of the given instrument in loaded module ) ( gets the memory address of the given instrument in loaded module )
@ -98,6 +114,16 @@ RTN
POPr POPr
RTN 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 ) ( loads instrument with number into specified audio channel, 0-indexed )
@k-load-instrument ( number channel -- ) @k-load-instrument ( number channel -- )
&run &run
@ -155,39 +181,49 @@ RTN
RTN RTN
@module @module
88 02 02 ( file header - speed 8, loop on, 2 patterns, 2 instruments )
84 02 02 ( file header - speed 8, loop on, 2 patterns, 2 instruments )
0008 ( size ) 0008 ( size )
00 00 ff ff 00 00 ff ff
00 01 ff ff ( song table, 2 rows ) 00 01 ff ff ( song table, 2 rows )
( pattern 00 ) ( pattern 00 )
12 ( size byte )
3c 02 00 ( C-3 I00 ) 3c 02 00 ( C-3 I00 )
ff bc 00 00 00
ff bc ff 00 00
ff bc 00 00 00
ff bc 3c 00 00
ff bc 00 00 00
ff bc 00 00 00
ff bc 00 00 00
ff 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 ) ( pattern 01 )
14 ( size byte ) ff 00 00
ff
3c 02 00 ( C-3 I00 ) 3c 02 00 ( C-3 I00 )
ff be ff 00 00
ff be 3c 00 00
ff ff 00 00
3e 01 66 ( D-3 V66 ) 3c 00 00
ff be ff 00 00
ff be 3c 00 00
ff be ff 00 00
ff be 3c 00 00
ff 00 00
3c 00 00
ff 00 00
3c 00 00
ff 00 00
3c 00 00
( instrument 00 ) ( instrument 00 )
0002 ( sample length ) 0002 ( sample length )
ff ( volume ) ff ( volume )
80 ( flags - loop sample ) 80 ( flags - loop sample )
05f5 ( ADSR ) 00f0 ( ADSR )
ff 00 ( square wave sample data ) ff 00 ( square wave sample data )
( instrument 01, unused ) ( instrument 01, unused )
0008 ( sample length ) 0008 ( sample length )