This repository has been archived on 2021-07-08. You can view files and clone it, but cannot push or open issues or pull requests.
kalama/main.usm

194 lines
6.0 KiB
Plaintext
Raw Normal View History

2021-05-01 19:16:24 +00:00
( a blank file )
( macros )
%RTN { JMP2r } ( return from a subroutine )
2021-05-02 18:34:46 +00:00
%LOB { SWP POP } ( get low byte of short as byte )
%HIB { POP } ( get high byte of short as byte )
2021-05-01 19:16:24 +00:00
( data structure access macros )
%NOTE { NOP } ( get the note of a pattern line addr )
%INST { #0001 ADD2 } ( get the instrument of a pattern line addr )
%VOL { #0002 ADD2 } ( get the volume of a pattern line addr )
( debugging macros )
%LOG { DUP .Console/byte DEO } ( prints a byte to the console non-destructively )
( constants )
%PTN_WIDTH { #0003 } ( pattern width. a short )
%PTN_LEN { #0010 } ( pattern length. a short )
( devices )
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 ]
|10 @Console [ &pad $8 &char $1 &byte $1 &short $2 &string $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
|30 @Audio0 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|40 @Audio1 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|50 @Audio2 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|60 @Audio3 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|70 @Midi [ &vector $2 &channel $1 &note $1 &velocity $1 ]
|80 @Controller [ &vector $2 &button $1 &key $1 ]
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &chord $1 ]
|a0 @File [ &vector $2 &success $2 &offset $2 &pad $2 &name $2 &length $2 &load $2 &save $2 ]
|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ]
( variables )
|0000
2021-05-02 18:34:46 +00:00
@Playback [ &position $2 &pattern-addr $2 &tick $1 &speed $1 ]
2021-05-05 15:52:09 +00:00
@Draw [ &row $1 &col $1
&pattern-x $2 &pattern-y $2
&pattern-vspacing $2 &pattern-hspacing $2
&playhead-x $2 &playhead-y $2 ]
2021-05-01 19:16:24 +00:00
( program )
|0100 ( -> )
( set a pallete )
#0f00 .System/r DEO2
2021-05-04 19:48:12 +00:00
#0ff0 .System/g DEO2
#0f0f .System/b DEO2
2021-05-01 19:16:24 +00:00
( speed - how many ticks we play a note every )
2021-05-02 18:34:46 +00:00
#10 .Playback/speed POK
2021-05-01 19:16:24 +00:00
2021-05-02 18:34:46 +00:00
;pattern .Playback/pattern-addr POK2
2021-05-01 19:16:24 +00:00
( display/audio init )
;on-frame .Screen/vector DEO2
#0180 .Audio0/adsr DEO2
;wave .Audio0/addr DEO2
#0002 .Audio0/length DEO2
2021-05-05 15:52:09 +00:00
( 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
2021-05-01 19:16:24 +00:00
BRK
@on-frame ( -> )
2021-05-02 18:34:46 +00:00
;draw JSR2
.Playback/tick PEK .Playback/speed PEK NEQ ,&inc JNZ ( if the tick != speed, skip to inc )
2021-05-01 19:16:24 +00:00
;on-step JSR2 ( otherwise, run the on-step routine )
2021-05-02 18:34:46 +00:00
#00 .Playback/tick POK ( reset the tick )
2021-05-01 19:16:24 +00:00
,&end JMP ( jump to end )
&inc
2021-05-02 18:34:46 +00:00
#01 .Playback/tick PEK ADD .Playback/tick POK ( tick up 1 )
2021-05-01 19:16:24 +00:00
&end
2021-05-05 15:52:09 +00:00
BRK
2021-05-01 19:16:24 +00:00
2021-05-02 18:34:46 +00:00
@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 )
2021-05-05 15:52:09 +00:00
RTN
2021-05-02 18:34:46 +00:00
( 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
2021-05-05 15:52:09 +00:00
RTN
2021-05-02 18:34:46 +00:00
( draw-pattern-line draws a single line in a pattern )
@draw-pattern-line ( addr )
#00 .Draw/col POK
&loop
2021-05-04 19:44:49 +00:00
DUP2 LDA ;draw-byte JSR2
2021-05-02 18:34:46 +00:00
.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 )
2021-05-05 15:52:09 +00:00
RTN
2021-05-02 18:34:46 +00:00
( draw-pattern draws a pattern )
@draw-pattern ( addr )
#00 .Draw/row POK
&loop
2021-05-05 15:52:09 +00:00
.Draw/pattern-y PEK2 .Screen/x DEO2
2021-05-02 18:34:46 +00:00
DUP2 ;draw-pattern-line JSR2
2021-05-05 15:52:09 +00:00
.Screen/y DEI2 #0008 .Draw/pattern-vspacing PEK2 ADD2 ADD2 .Screen/y DEO2 ( add spacing between rows )
2021-05-02 18:34:46 +00:00
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 )
2021-05-05 15:52:09 +00:00
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
2021-05-02 18:34:46 +00:00
@draw
2021-05-05 15:52:09 +00:00
;draw-playhead JSR2
.Draw/pattern-x PEK2 .Screen/x DEO2
.Draw/pattern-y PEK2 .Screen/y DEO2
2021-05-02 18:34:46 +00:00
.Playback/pattern-addr PEK2 ;draw-pattern JSR2
2021-05-05 15:52:09 +00:00
RTN
2021-05-02 18:34:46 +00:00
2021-05-01 19:16:24 +00:00
@on-step ( whenever a pattern step should be played )
2021-05-05 15:52:09 +00:00
2021-05-02 18:34:46 +00:00
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
2021-05-01 19:16:24 +00:00
&continue
2021-05-02 18:34:46 +00:00
.Playback/position PEK2 .Playback/pattern-addr PEK2 ADD2 ( put pattern line address on the stack )
2021-05-04 19:44:49 +00:00
DUP2 VOL LDA .Audio0/volume DEO ( ln -- ) ( put the address of the pattern line on the stack )
NOTE LDA ( get the current note )
2021-05-01 19:16:24 +00:00
DUP #00 EQU ,&rest JNZ ( if the note is 00, aka empty, skip playing it )
.Audio0/pitch DEO ( play the note )
,&end JMP ( jump to the end )
&rest POP ( if the note is a 00, jump here. POP to clean up the stack )
&end
2021-05-05 15:52:09 +00:00
PTN_WIDTH .Playback/position PEK2 ADD2 .Playback/position POK2
;draw-playhead JSR2 ( update the playhead position )
RTN
2021-05-01 19:16:24 +00:00
2021-05-04 19:45:33 +00:00
@wave [ ff 00 ]
2021-05-01 19:16:24 +00:00
2021-05-02 18:34:46 +00:00
@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
]
2021-05-01 19:16:24 +00:00
2021-05-05 15:52:09 +00:00
@playhead_icon [ 00 60 78 7e 7e 78 60 00 ]
2021-05-01 19:16:24 +00: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) )
2021-05-02 18:34:46 +00:00
2021-05-01 19:16:24 +00:00
@pattern [
3c 00 66
ff 00 66
3e 00 22
00 00 66
3c 00 88
2021-05-05 15:52:09 +00:00
ff 00 66
2021-05-01 19:16:24 +00:00
3e 00 66
00 00 66
3c 00 22
2021-05-05 15:52:09 +00:00
ff 00 66
2021-05-01 19:16:24 +00:00
3e 00 20
00 00 66
3c 00 66
ff 00 66
3e 00 ff
40 00 66
2021-05-01 19:20:32 +00:00
]