diff --git a/main.usm b/main.usm index 9e6bcb3..8132044 100644 --- a/main.usm +++ b/main.usm @@ -37,7 +37,10 @@ |0000 @Playback [ &position $2 &pattern-addr $2 &tick $1 &speed $1 ] -@Draw [ &row $1 &col $1 ] +@Draw [ &row $1 &col $1 + &pattern-x $2 &pattern-y $2 + &pattern-vspacing $2 &pattern-hspacing $2 + &playhead-x $2 &playhead-y $2 ] ( program ) @@ -58,6 +61,13 @@ #0180 .Audio0/adsr DEO2 ;wave .Audio0/addr DEO2 #0002 .Audio0/length DEO2 + +( drawing properties ) +#0010 .Draw/pattern-x POK2 +#0010 .Draw/pattern-y POK2 +#0004 .Draw/pattern-vspacing POK2 +#0007 .Draw/playhead-x POK2 +#0004 .Draw/pattern-hspacing POK2 BRK @on-frame ( -> ) @@ -69,19 +79,19 @@ BRK &inc #01 .Playback/tick PEK ADD .Playback/tick POK ( tick up 1 ) &end - BRK +BRK @draw-nibble ( nibble ) #08 MUL #00 SWP ;font_hex ADD2 .Screen/addr DEO2 ( locate nibble in the hex font ) #21 .Screen/color DEO ( display it ) .Screen/x DEI2 #0008 ADD2 .Screen/x DEO2 ( move right a sprite ) - RTN +RTN ( draw-byte draws a byte as hex on the screen ) @draw-byte ( byte ) DUP #04 SFT ( high digit ) ;draw-nibble JSR2 #0f AND ( low digit ) ;draw-nibble JSR2 - RTN +RTN ( draw-pattern-line draws a single line in a pattern ) @draw-pattern-line ( addr ) @@ -93,28 +103,42 @@ BRK #01 .Draw/col PEK ADD .Draw/col POK .Draw/col PEK PTN_WIDTH LOB NEQ ,&loop JNZ POP2 ( remove final address from stack ) - RTN +RTN ( draw-pattern draws a pattern ) @draw-pattern ( addr ) #00 .Draw/row POK &loop - #0010 .Screen/x DEO2 + .Draw/pattern-y PEK2 .Screen/x DEO2 DUP2 ;draw-pattern-line JSR2 - .Screen/y DEI2 #000b ADD2 .Screen/y DEO2 ( add spacing between rows ) + .Screen/y DEI2 #0008 .Draw/pattern-vspacing PEK2 ADD2 ADD2 .Screen/y DEO2 ( add spacing between rows ) PTN_WIDTH ADD2 ( get the next byte in the pattern ) #01 .Draw/row PEK ADD .Draw/row POK .Draw/row PEK PTN_LEN LOB NEQ ,&loop JNZ POP2 ( remove final address from stack ) - RTN - +RTN + +@draw-playhead + ( clear previous playhead ) + .Draw/playhead-y PEK2 .Screen/y DEO2 + .Draw/playhead-x PEK2 .Screen/x DEO2 + #20 .Screen/color DEO + ( draw new playhead ) + .Draw/pattern-y PEK2 .Playback/position PEK2 #0001 SUB2 #0004 MUL2 ADD2 #0008 SUB2 DUP2 .Draw/playhead-y POK2 + .Screen/y DEO2 + ;playhead_icon .Screen/addr DEO2 + #21 .Screen/color DEO +RTN + @draw - #0010 .Screen/x DEO2 - #0010 .Screen/y DEO2 + ;draw-playhead JSR2 + .Draw/pattern-x PEK2 .Screen/x DEO2 + .Draw/pattern-y PEK2 .Screen/y DEO2 .Playback/pattern-addr PEK2 ;draw-pattern JSR2 - RTN +RTN @on-step ( whenever a pattern step should be played ) + PTN_WIDTH PTN_LEN MUL2 .Playback/position PEK2 NEQ2 ,&continue JNZ ( if we're at the end of the pattern, reset the counter ) #0000 .Playback/position POK2 &continue @@ -127,9 +151,9 @@ BRK &rest POP ( if the note is a 00, jump here. POP to clean up the stack ) &end - PTN_WIDTH .Playback/position PEK2 ADD2 .Playback/position POK2 - - RTN + PTN_WIDTH .Playback/position PEK2 ADD2 .Playback/position POK2 + ;draw-playhead JSR2 ( update the playhead position ) +RTN @wave [ ff 00 ] @@ -145,6 +169,7 @@ BRK 007e 4078 4040 7e00 007e 4078 4040 4000 ] +@playhead_icon [ 00 60 78 7e 7e 78 60 00 ] ( pattern format - each note has 3 bytes. Pitch, instrument, volume. patterns are 0x10 long. an ff in the note column of the pattern will kill the existing note without starting a new one (this is the tracker "box" note) ) @@ -154,11 +179,11 @@ BRK 3e 00 22 00 00 66 3c 00 88 - 00 00 66 + ff 00 66 3e 00 66 00 00 66 3c 00 22 - 00 00 66 + ff 00 66 3e 00 20 00 00 66 3c 00 66