From 730e29ac423291ceed573820349394ec32b53ff0 Mon Sep 17 00:00:00 2001 From: Nihilazo Date: Thu, 10 Jun 2021 18:22:06 +0100 Subject: [PATCH] make load-pattern more flexible --- main.tal | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/main.tal b/main.tal index 8f0816f..546250b 100644 --- a/main.tal +++ b/main.tal @@ -1,3 +1,4 @@ + ( a blank file ) ( macros ) @@ -41,12 +42,19 @@ |0000 -@Playback [ &position $2 &pattern-addr $2 &tick $1 &speed $1 &playing $1 &pattern-index $1 ] ( pattern-index = 0-127 which pattern is selected from the pattern table ) +@Playback [ &position $2 &tick $1 &speed $1 &playing $1 ] +( pattern-index = 0-127 which pattern is selected from the pattern table + pattern-addr = address of pattern currently loaded ) +( pattern-index and pattern-addr HAVE to stay in the same positions relative to their channel! ) +@Channel0 [ &pattern-addr $2 &pattern-index $1 ] +@Channel1 [ &pattern-addr $2 &pattern-index $1 ] +@Channel2 [ &pattern-addr $2 &pattern-index $1 ] +@Channel3 [ &pattern-addr $2 &pattern-index $1 ] @Draw [ &row $1 &col $1 &pattern-x $2 &pattern-y $2 &pattern-vspacing $2 &pattern-hspacing $2 &playhead-x $2 &playhead-y $2 ] -@Edit [ &selection-x $1 &selection-y $1 ] +@Edit [ &pattern-addr $2 &pattern-index $1 &selection-x $1 &selection-y $1 ] @Pointer [ &x $2 &y $2 ] @@ -62,9 +70,9 @@ ( speed - how many ticks we play a note every ) #10 .Playback/speed STZ -#00 .Playback/pattern-index STZ +#00 .Channel0/pattern-index STZ -.Playback/pattern-index LDZ ;alloc-load-pattern JSR2 +.Channel0/pattern-index LDZ ;alloc-load-pattern JSR2 ( display/audio init ) ;on-frame .Screen/vector DEO2 @@ -89,28 +97,31 @@ BRK @get-selected-addr ( -- addr* ) ( get the address of the current selection in the pattern ) - .Playback/pattern-addr LDZ2 #00 .Edit/selection-x LDZ ADD2 #00 .Edit/selection-y LDZ PTN_WIDTH MUL2 ADD2 + .Channel0/pattern-addr LDZ2 #00 .Edit/selection-x LDZ ADD2 #00 .Edit/selection-y LDZ PTN_WIDTH MUL2 ADD2 RTN +( TODO make these relative to the channel alloc/loading to ) + @alloc-load-pattern ( index -- ) ( alloc a pattern and load it ) STHk ( leave the index number on the stack ) #02 MUL #00 SWP ( convert index into index into the table ) ;pattern_table ADD2 ( get the address of it in the table ) LDA2 #0000 NEQ2 ,&load JCN ( if it's not 0000, load it ) - STHrk ;alloc-pattern JSR2 ( TODO write the rest of this function ) + STHrk ;alloc-pattern JSR2 &load - STHr ;load-pattern JSR2 + STHr .Channel0/pattern-addr ;load-pattern JSR2 RTN -@load-pattern ( index -- ) ( loads a pattern from the table ) +@load-pattern ( index addr -- ) ( loads a pattern from the table into zero-page address addr ) + STH ( stash address ) #02 MUL #00 SWP ( convert index to an actual index into the table ) ;pattern_table ADD2 ( add to the table ) LDA2 ( load the address ) - .Playback/pattern-addr STZ2 ( store in pattern index ) + STHr STZ2 ( store in addr ) RTN -@alloc-pattern ( index -- ) ( allocates a pattern in the table )w +@alloc-pattern ( index -- ) ( allocates a pattern in the table ) #02 MUL #00 SWP ( convert index to an index in the table ) ;pattern_table ADD2 ( get the index in the table for this pattern ) ;pattern_pointer LDA2 SWP2 STA2 ( store the current pointer in that place in the table ) @@ -212,13 +223,13 @@ RTN BRK &next POP - .Playback/pattern-index LDZ #01 ADD .Playback/pattern-index STZ - .Playback/pattern-index LDZ ;alloc-load-pattern JSR2 + .Channel0/pattern-index LDZ #01 ADD .Channel0/pattern-index STZ + .Channel0/pattern-index LDZ ;alloc-load-pattern JSR2 BRK &prev POP - .Playback/pattern-index LDZ #01 SUB .Playback/pattern-index STZ - .Playback/pattern-index LDZ ;alloc-load-pattern JSR2 + .Channel0/pattern-index LDZ #01 SUB .Channel0/pattern-index STZ + .Channel0/pattern-index LDZ ;alloc-load-pattern JSR2 BRK &pause POP @@ -362,10 +373,10 @@ RTN ;draw-playhead JSR2 #0000 .Screen/x DEO2 #0000 .Screen/y DEO2 - .Playback/pattern-index LDZ ;draw-byte JSR2 + .Channel0/pattern-index LDZ ;draw-byte JSR2 .Draw/pattern-x LDZ2 .Screen/x DEO2 .Draw/pattern-y LDZ2 .Screen/y DEO2 - .Playback/pattern-addr LDZ2 ;draw-pattern JSR2 + .Channel0/pattern-addr LDZ2 ;draw-pattern JSR2 RTN @play-line ( addr ch ) ( plays the pattern line at addr on the channel ch ) @@ -386,7 +397,7 @@ RTN PTN_LEN .Playback/position LDZ2 NEQ2 ,&continue JCN ( if we're at the end of the pattern, reset the counter ) #0000 .Playback/position STZ2 &continue - .Playback/position LDZ2 PTN_WIDTH MUL2 .Playback/pattern-addr LDZ2 ADD2 ( put pattern line address on the stack ) + .Playback/position LDZ2 PTN_WIDTH MUL2 .Channel0/pattern-addr LDZ2 ADD2 ( put pattern line address on the stack ) .Audio0 ;play-line JSR2 #0001 .Playback/position LDZ2 ADD2 .Playback/position STZ2 ;draw-playhead JSR2 ( update the playhead position )