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 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 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.
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.
### Effects

View File

@ -27,6 +27,9 @@
&module $2 ( pointer to start of module file )
&loopflags $1 ( if different channels are set to loop )
&instruments $2 ( address that instruments start at )
&tick $1
&line $1
&speed $1
( program )
@ -37,47 +40,60 @@
#0fc5 .System/g 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
#00 #00 ;k-load-instrument/run JSR2
#3c .Audio0/pitch DEO
BRK
@on-frame ( -> )
&run
;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
STH ( stash pattern number to return stack for loop counter later )
.kalama/module LDZ2 ( get module start address )
#00 SWP #0030 MUL2
.kalama/module LDZ2
#0003 ADD2 ( skip header )
DUP2 LDA2 ( load pattern table length )
#0002 ADD2 ( skip pattern table length byte )
ADD2 ( and skip the pattern table )
( 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
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 )
@ -98,6 +114,16 @@ RTN
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
@ -155,39 +181,49 @@ RTN
RTN
@module
84 02 02 ( file header - speed 8, loop on, 2 patterns, 2 instruments )
88 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 )
( pattern 00 )
12 ( size byte )
3c 02 00 ( C-3 I00 )
ff bc
ff bc
ff bc
ff bc
ff bc
ff bc
ff bc
ff
00 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 )
14 ( size byte )
ff
ff 00 00
3c 02 00 ( C-3 I00 )
ff be
ff be
ff
3e 01 66 ( D-3 V66 )
ff be
ff be
ff be
ff be
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 )
80 ( flags - loop sample )
05f5 ( ADSR )
00f0 ( ADSR )
ff 00 ( square wave sample data )
( instrument 01, unused )
0008 ( sample length )