138 lines
4.5 KiB
Tal
138 lines
4.5 KiB
Tal
|
( drums2.tal )
|
||
|
( )
|
||
|
( very very simple drum machine )
|
||
|
|
||
|
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $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 ]
|
||
|
|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ]
|
||
|
|
||
|
|0000
|
||
|
@timer $2
|
||
|
@rng [ &x $2 &y $2 ]
|
||
|
|
||
|
|0100
|
||
|
( bass )
|
||
|
;noise .Audio0/addr DEO2 ( sample )
|
||
|
#0100 .Audio0/length DEO2 ( length )
|
||
|
#0100 .Audio0/adsr DEO2 ( envelope )
|
||
|
#99 .Audio0/volume DEO ( volume )
|
||
|
|
||
|
( snare )
|
||
|
;noise .Audio1/addr DEO2 ( sample )
|
||
|
#0100 .Audio1/length DEO2 ( length )
|
||
|
#0102 .Audio1/adsr DEO2 ( envelope )
|
||
|
#df .Audio1/volume DEO ( volume )
|
||
|
|
||
|
( hi-hat )
|
||
|
;noise .Audio2/addr DEO2 ( sample )
|
||
|
#0100 .Audio2/length DEO2 ( length )
|
||
|
#0001 .Audio2/adsr DEO2 ( envelope )
|
||
|
#fb .Audio2/volume DEO ( volume )
|
||
|
|
||
|
( cymbal )
|
||
|
;noise .Audio3/addr DEO2 ( sample )
|
||
|
#0100 .Audio3/length DEO2 ( length )
|
||
|
#0035 .Audio3/adsr DEO2 ( envelope )
|
||
|
#af .Audio3/volume DEO ( volume )
|
||
|
|
||
|
( set up clock timer, each tick is 1/60 second )
|
||
|
#0000 .timer STZ2
|
||
|
|
||
|
( we use an rng to add extra hits sometimes )
|
||
|
;init-rng JSR2
|
||
|
|
||
|
( this callback updates tick 60x a second )
|
||
|
;tick .Screen/vector DEO2
|
||
|
BRK
|
||
|
|
||
|
%MOD2 { DIV2k MUL2 SUB2 }
|
||
|
%PULSE { #0006 }
|
||
|
%LOOPLEN { #0010 }
|
||
|
|
||
|
@tick
|
||
|
( this div/mod defines the tempo )
|
||
|
( each sixteenth note is 8/60 seconds, i.e. 133ms )
|
||
|
( this makes the tempo 128 bpm )
|
||
|
.timer LDZ2 PULSE MOD2 ORA ,&done JCN ( done if t%pulse!=0 )
|
||
|
.timer LDZ2 PULSE DIV2 LOOPLEN MOD2 ( beat=(t/pulse)%looplen )
|
||
|
STH2k ;bass ;play-beat JSR2
|
||
|
STH2kr ;snare ;play-beat JSR2
|
||
|
STH2kr ;hi-hat ;play-beat JSR2
|
||
|
( STH2r ;cymbal ;play-beat JSR2 )
|
||
|
POP2r
|
||
|
&done .timer LDZ2 INC2 .timer STZ2 ( t += 1 ) BRK
|
||
|
|
||
|
@play-beat ( beat* addr* -- )
|
||
|
STH2k ADD2 LDA ,&on JCN
|
||
|
;random-byte JSR2 #07 AND #00 EQU ,&on JCN ( 1-in-8 chance of activating )
|
||
|
POP2r JMP2r
|
||
|
&on STH2r #0010 ADD2 LDA2 DEO JMP2r
|
||
|
|
||
|
( each track has 16 notes )
|
||
|
( followed by 2 bytes describing pitch/channel to use )
|
||
|
|
||
|
@bass
|
||
|
01 00 00 01 00 00 00 00 00 00 01 00 00 00 00 00
|
||
|
00 3f ( #00 Audio0/pitch DEO )
|
||
|
|
||
|
@snare
|
||
|
00 00 00 00 01 00 00 00 00 00 00 00 01 01 00 01
|
||
|
0c 4f ( #0c Audio1/pitch DEO )
|
||
|
|
||
|
@hi-hat
|
||
|
01 00 01 00 01 00 01 01 01 01 01 00 01 00 01 00
|
||
|
3c 5f ( #3c Audio2/pitch DEO )
|
||
|
|
||
|
@cymbal
|
||
|
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||
|
48 6f ( #4a Audio3/pitch DEO )
|
||
|
|
||
|
( 256 random bytes to create noise )
|
||
|
@noise
|
||
|
c1 be 88 3c e5 55 c0 a1 3a b8 8c e7 a3 40 b4 b7
|
||
|
fa 20 52 fd 39 88 ef 3d d0 d2 37 12 81 56 40 1e
|
||
|
f1 de 86 9d 2a cd ba 2c 8c b2 a3 e5 17 2a bf a3
|
||
|
33 e9 ab f3 3d 7c ac 00 a3 77 a7 a9 d8 10 2f af
|
||
|
b1 ba 68 0f 12 d3 7b e0 62 68 ef 0f 8a ea 7f b5
|
||
|
ad 5c 43 c6 f0 f6 29 33 9b c6 2f 24 34 41 d2 3d
|
||
|
16 53 27 ae b7 ba f4 53 0e 78 bf b9 16 7d 18 56
|
||
|
4e 95 8a e4 10 08 6c 9d bc 99 f7 ad d4 5b db f4
|
||
|
17 ea e3 c8 e6 67 8f 66 29 48 13 1c 9c ed 6f 26
|
||
|
1a 55 77 6d ee 8a d1 63 f2 88 92 17 7c fc d8 55
|
||
|
11 20 a8 6b 9e 48 d2 97 a2 6c dc 73 3a 82 13 f7
|
||
|
03 9c 25 5f 01 62 c1 f0 6e 71 aa 41 2f a7 a0 e1
|
||
|
78 07 c9 e5 0b 31 0c 23 00 0a c9 86 fe 2d 60 97
|
||
|
8b df 01 dd fe 68 5b 7e e6 28 a5 a2 5f 96 57 36
|
||
|
0a b4 b5 fd 21 4e ff 50 fb 00 c8 ae 25 ca 02 c9
|
||
|
5f b4 4b 5b f7 59 0b 08 98 52 29 81 97 85 1c 6d
|
||
|
|
||
|
@random-byte ( -> val^ )
|
||
|
;random-short JSR2 POP JMP2r
|
||
|
|
||
|
%<<5 { #50 SFT2 }
|
||
|
%>>1 { #01 SFT2 }
|
||
|
%>>3 { #03 SFT2 }
|
||
|
|
||
|
@random-short ( -> val* )
|
||
|
.rng/x LDZ2 DUP2 <<5 EOR2 ( tmp: x^[x<<5] )
|
||
|
.rng/y LDZ2 DUP2 .rng/x STZ2 ( tmp y )
|
||
|
DUP2 >>1 EOR2 ( tmp y^[y>>1] )
|
||
|
SWP2 DUP2 >>3 EOR2 ( y^[y>>1] tmp^[tmp>>3] )
|
||
|
EOR2 DUP2 .rng/y STZ2 ( y^[y>>1] ^ tmp^[tmp>>3] )
|
||
|
JMP2r
|
||
|
|
||
|
@init-rng ( -> )
|
||
|
( seed .rng/x in seconds )
|
||
|
#00 .DateTime/minute DEI #003c MUL2
|
||
|
#00 .DateTime/second DEI ADD2
|
||
|
#0001 ORA2 .rng/x STZ2 ( x <- min*60+sec|1 )
|
||
|
|
||
|
( seed .rng/y in hours )
|
||
|
#00 .DateTime/day DEI #0018 MUL2
|
||
|
#00 .DateTime/hour DEI ADD2
|
||
|
#0001 ORA2 .rng/y STZ2 ( y <- day*24+hour|1 )
|
||
|
JMP2r
|