draw pattern on screen

This commit is contained in:
Nico 2021-05-02 19:34:46 +01:00
parent 27bdb17513
commit 108d27c2b9
1 changed files with 69 additions and 12 deletions

View File

@ -2,6 +2,8 @@
( macros )
%RTN { JMP2r } ( return from a subroutine )
%LOB { SWP POP } ( get low byte of short as byte )
%HIB { POP } ( get high byte of short as byte )
( data structure access macros )
%NOTE { NOP } ( get the note of a pattern line addr )
@ -34,7 +36,8 @@
|0000
@State [ &position $2 &pattern-addr $2 &tick $1 &speed $1 ]
@Playback [ &position $2 &pattern-addr $2 &tick $1 &speed $1 ]
@Draw [ &row $1 &col $1 ]
( program )
@ -46,9 +49,9 @@
#000f .System/b DEO2
( speed - how many ticks we play a note every )
#10 .State/speed POK
#10 .Playback/speed POK
;pattern .State/pattern-addr POK2
;pattern .Playback/pattern-addr POK2
( display/audio init )
;on-frame .Screen/vector DEO2
@ -58,21 +61,64 @@
BRK
@on-frame ( -> )
.State/tick PEK .State/speed PEK NEQ ,&inc JNZ ( if the tick != speed, skip to inc )
;draw JSR2
.Playback/tick PEK .Playback/speed PEK NEQ ,&inc JNZ ( if the tick != speed, skip to inc )
;on-step JSR2 ( otherwise, run the on-step routine )
#00 .State/tick POK ( reset the tick )
#00 .Playback/tick POK ( reset the tick )
,&end JMP ( jump to end )
&inc
#01 .State/tick PEK ADD .State/tick POK ( tick up 1 )
#01 .Playback/tick PEK ADD .Playback/tick POK ( tick up 1 )
&end
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
( 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
( draw-pattern-line draws a single line in a pattern )
@draw-pattern-line ( addr )
#00 .Draw/col POK
&loop
DUP2 GET ;draw-byte JSR2
.Screen/x DEI2 #0004 ADD2 .Screen/x DEO2 ( add spacing between digits )
#0001 ADD2 ( get the next byte in the pattern )
#01 .Draw/col PEK ADD .Draw/col POK
.Draw/col PEK PTN_WIDTH LOB NEQ ,&loop JNZ
POP2 ( remove final address from stack )
RTN
( draw-pattern draws a pattern )
@draw-pattern ( addr )
#00 .Draw/row POK
&loop
#0010 .Screen/x DEO2
DUP2 ;draw-pattern-line JSR2
.Screen/y DEI2 #000b 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
@draw
#0010 .Screen/x DEO2
#0010 .Screen/y DEO2
.Playback/pattern-addr PEK2 ;draw-pattern JSR2
RTN
@on-step ( whenever a pattern step should be played )
PTN_WIDTH PTN_LEN MUL2 .State/position PEK2 NEQ2 ,&continue JNZ ( if we're at the end of the pattern, reset the counter )
#ff .Console/byte DEO
#0000 .State/position POK2
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
.State/position PEK2 .State/pattern-addr PEK2 ADD2 ( put pattern line address on the stack )
.Playback/position PEK2 .Playback/pattern-addr PEK2 ADD2 ( put pattern line address on the stack )
DUP2 VOL GET .Audio0/volume DEO ( ln -- ) ( put the address of the pattern line on the stack )
NOTE GET ( get the current note )
DUP #00 EQU ,&rest JNZ ( if the note is 00, aka empty, skip playing it )
@ -81,16 +127,27 @@ BRK
&rest POP ( if the note is a 00, jump here. POP to clean up the stack )
&end
PTN_WIDTH .State/position PEK2 ADD2 .State/position POK2
PTN_WIDTH .Playback/position PEK2 ADD2 .Playback/position POK2
RTN
@wave [ a8 58 ]
@font_hex ( 0-F )
[
003c 464a 5262 3c00 0018 0808 0808 1c00
003c 4202 3c40 7e00 003c 421c 0242 3c00
000c 1424 447e 0400 007e 407c 0242 3c00
003c 407c 4242 3c00 007e 0204 0810 1000
003c 423c 4242 3c00 003c 4242 3e02 3c00
003c 4242 7e42 4200 007c 427c 4242 7c00
003c 4240 4042 3c00 007c 4242 4242 7c00
007e 4078 4040 7e00 007e 4078 4040 4000
]
( 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) )
@pattern [
3c 00 66
ff 00 66