diff --git a/main.usm b/main.usm index 3f80347..92755d4 100644 --- a/main.usm +++ b/main.usm @@ -60,7 +60,7 @@ #10 .Playback/speed STZ #00 .Playback/pattern-index STZ -;update-pattern-addr JSR2 +;load-pattern JSR2 ( display/audio init ) ;on-frame .Screen/vector DEO2 @@ -81,11 +81,25 @@ BRK +( TODO either alloc or get-selected-addr is breaking things. Fix tomorrow. ) + +@alloc-pattern ( number -- ) ( allocates pattern n in the pattern table in a new area of memory. WILL OVERWRITE! ) + #02 MUL #00 SWP ;pattern-table ADD2 ;pattern-pointer LDA2 SWP2 STA2 ( store current position of pattern pointer in pattern table for this pattern ) + PTN_LEN PTN_WIDTH MUL2 ;pattern-pointer LDA2 ADD2 ;pattern-pointer STA2 + +RTN + @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 RTN -@update-pattern-addr ( -- ) +( loads the pattern pointed to by Playback/pattern-index. Allocs it if it doesn't exist. ) +@load-pattern ( number -- ) + .Playback/pattern-index LDZ #02 MUL #00 SWP ;pattern-table ADD2 LDA2 ( get current pattern address ) + DUP2 #0000 NEQ ,&exists JCN ( if the pattern exists, don't alloc a new one ) + .Playback/pattern-index LDZ ;alloc-pattern JSR2 + &exists + POP2 .Playback/pattern-index LDZ #02 MUL #00 SWP ;pattern-table ADD2 LDA2 .Playback/pattern-addr STZ2 RTN @@ -137,9 +151,25 @@ RTN .Controller/key DEI DUP ;handle-editing JSR2 ( play/pause ) - #70 NEQ ,&end JCN + DUP #70 EQU ,&pause JCN + DUP #3e EQU ,&next-pattern JCN + #3c EQU ,&prev-pattern JCN + .Playback/pattern-addr LDZ2 .Console/short DEO2 + BRK + &pause + POP .Playback/playing LDZ #00 EQU .Playback/playing STZ - &end + BRK + &next-pattern ( TODO bounds checking to 127 ) + POP + .Playback/pattern-index LDZ #01 ADD .Playback/pattern-index STZ + ;load-pattern JSR2 + BRK + &prev-pattern ( TODO bounds checking to 127 ) + POP + .Playback/pattern-index LDZ #01 SUB .Playback/pattern-index STZ + ;load-pattern JSR2 + BRK BRK @on-frame ( -> )