uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

audio.tal (4295B)


      1 ( dev/audio )
      2 
      3 %GET-NOTE { #00 SWP ;melody ADD2 LDA }
      4 %GET-HEXCHAR  { #00 SWP #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2 }
      5 
      6 ( devices )
      7 
      8 |00 @System     [ &vector $2 &pad      $6 &r      $2 &g     $2 &b      $2 ]
      9 |20 @Screen     [ &vector $2 &width    $2 &height $2 &pad   $2 &x      $2 &y    $2 &addr  $2 &pixel $1 &sprite $1 ]
     10 |30 @Audio0     [ &vector $2 &position $2 &output $1 &pad   $3 &adsr   $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
     11 |80 @Controller [ &vector $2 &button $1 &key    $1 ]
     12 
     13 ( variables )
     14 
     15 |0000
     16 
     17 @timer     $1
     18 @progress  $1
     19 @selection $1
     20 @offset
     21 	&x $2 &y $2
     22 
     23 |0100 ( -> )
     24 	
     25 	( theme )
     26 	#0f8f .System/r DEO2 
     27 	#0f8f .System/g DEO2 
     28 	#0f80 .System/b DEO2 
     29 
     30 	( vectors )
     31 	;on-frame .Screen/vector DEO2
     32 	;on-button .Controller/vector DEO2
     33 
     34 	( setup synth )
     35 	#0208 .Audio0/adsr DEO2
     36 	;saw .Audio0/addr DEO2
     37 	#0100 .Audio0/length DEO2
     38 	#dd .Audio0/volume DEO ( TODO: turn ON )
     39 
     40 	( center )
     41 	.Screen/width DEI2 #01 SFT2 #0080 SUB2 .offset/x STZ2
     42 	.Screen/height DEI2 #01 SFT2 #0040 SUB2 .offset/y STZ2
     43 
     44 	;draw JSR2
     45 	#02 ;draw-selector JSR2
     46 
     47 BRK
     48 
     49 @on-button ( -> )
     50 
     51 	.Controller/button DEI #04 SFT
     52 	[ #01 ] NEQk NIP ,&no-up JCN 
     53 		.selection LDZ STHk 
     54 		#00 ;draw-note JSR2
     55 		[ STHkr GET-NOTE INC ] #00 STHkr ;melody ADD2 STA
     56 		STHr #01 ;draw-note JSR2
     57 		#02 ;draw-selector JSR2
     58 		&no-up
     59 	[ #02 ] NEQk NIP ,&no-down JCN 
     60 		.selection LDZ STHk 
     61 		#00 ;draw-note JSR2
     62 		[ STHkr GET-NOTE #01 SUB ] #00 STHkr ;melody ADD2 STA
     63 		STHr #01 ;draw-note JSR2
     64 		#02 ;draw-selector JSR2
     65 		&no-down
     66 	[ #04 ] NEQk NIP ,&no-left JCN 
     67 		#00 ;draw-selector JSR2
     68 		.selection LDZ #01 SUB #1f AND .selection STZ
     69 		#02 ;draw-selector JSR2
     70 		&no-left
     71 	[ #08 ] NEQk NIP ,&no-right JCN 
     72 		#00 ;draw-selector JSR2
     73 		.selection LDZ INC #1f AND .selection STZ
     74 		#02 ;draw-selector JSR2
     75 		&no-right
     76 	POP
     77 	
     78 BRK
     79 
     80 @on-frame ( -> )
     81 
     82 	( incr ) .timer LDZ INC .timer STZ 
     83 	( skip ) .timer LDZ #10 EQU #01 JCN [ BRK ]
     84 	.progress LDZ 
     85 	( play note )    DUP GET-NOTE .Audio0/pitch DEO
     86 	( erase last )   DUP #01 SUB #1f AND #01 ,draw-note JSR
     87 	( draw current ) #01 ,draw-note JSR
     88 	( incr ) .progress LDZ INC #1f AND .progress STZ
     89 	#00 .timer STZ
     90 
     91 BRK
     92 
     93 @draw ( -- )
     94 
     95 	#20 #00
     96 	&loop
     97 		DUP #01 ,draw-note JSR
     98 		INC GTHk ,&loop JCN
     99 	POP2
    100 
    101 JMP2r
    102 
    103 @draw-note ( id color -- )
    104 
    105 	STH STH
    106 	( set x ) [ #00 STHkr ] #30 SFT2 .offset/x LDZ2 ADD2 .Screen/x DEO2
    107 	( set y ) [ #00 #00 STHkr ;melody ADD2 LDA ] #20 SFT2 #0100 SWP2 SUB2 .offset/y LDZ2 ADD2 #0080 ADD2 .Screen/y DEO2
    108 	( set addr ) ;marker-icn [ #00 .progress LDZ STHr EQU #08 MUL ADD2 ] .Screen/addr DEO2
    109 	( draw ) STHr .Screen/sprite DEO
    110 
    111 JMP2r
    112 
    113 @draw-selector ( color -- )
    114 	
    115 	STH
    116 	[ #00 .selection LDZ ] #30 SFT2 .offset/x LDZ2 ADD2 .Screen/x DEO2
    117 	#0070 .offset/y LDZ2 ADD2 .Screen/y DEO2
    118 	;selector-icn .Screen/addr DEO2
    119 	STHkr .Screen/sprite DEO
    120 
    121 	.Screen/y DEI2k #0008 ADD2 ROT DEO2
    122 	.selection LDZ GET-NOTE STHr ,draw-byte JSR
    123 
    124 JMP2r
    125 
    126 @draw-byte ( byte color -- )
    127 	
    128 	STH 
    129 	DUP 
    130 		#04 SFT GET-HEXCHAR 
    131 		( draw ) STHkr .Screen/sprite DEO
    132 	.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
    133 		#0f AND GET-HEXCHAR 
    134 		( draw ) STHr .Screen/sprite DEO
    135 
    136 JMP2r
    137 
    138 @melody 
    139 	54 52 54 4f 4b 4f 48 ff
    140 	54 52 54 4f 4b 4f 48 ff
    141 	54 56 57 56 57 54 56 54 
    142 	56 52 54 52 54 50 54 ff 
    143 
    144 @selector-icn
    145 	0000 0010 387c 0000
    146 
    147 @marker-icn
    148 	3844 8282 8244 3800
    149 	387c fefe fe7c 3800
    150 
    151 @saw 
    152 	0003 0609 0c0f 1215 181b 1e21 2427 2a2d
    153 	3033 3639 3b3e 4143 4649 4b4e 5052 5557
    154 	595b 5e60 6264 6667 696b 6c6e 7071 7274
    155 	7576 7778 797a 7b7b 7c7d 7d7e 7e7e 7e7e
    156 	7f7e 7e7e 7e7e 7d7d 7c7b 7b7a 7978 7776
    157 	7574 7271 706e 6c6b 6967 6664 6260 5e5b
    158 	5957 5552 504e 4b49 4643 413e 3b39 3633
    159 	302d 2a27 2421 1e1b 1815 120f 0c09 0603
    160 	00fd faf7 f4f1 eeeb e8e5 e2df dcd9 d6d3
    161 	d0cd cac7 c5c2 bfbd bab7 b5b2 b0ae aba9
    162 	a7a5 a2a0 9e9c 9a99 9795 9492 908f 8e8c
    163 	8b8a 8988 8786 8585 8483 8382 8282 8282
    164 	8182 8282 8282 8383 8485 8586 8788 898a
    165 	8b8c 8e8f 9092 9495 9799 9a9c 9ea0 a2a5
    166 	a7a9 abae b0b2 b5b7 babd bfc2 c5c7 cacd
    167 	d0d3 d6d9 dcdf e2e5 e8eb eef1 f4f7 fafd 
    168 
    169 @font-hex ( 0-F )
    170 	007c 8282 8282 827c 0030 1010 1010 1010
    171 	007c 8202 7c80 80fe 007c 8202 1c02 827c
    172 	000c 1424 4484 fe04 00fe 8080 7c02 827c
    173 	007c 8280 fc82 827c 007c 8202 1e02 0202
    174 	007c 8282 7c82 827c 007c 8282 7e02 827c
    175 	007c 8202 7e82 827e 00fc 8282 fc82 82fc
    176 	007c 8280 8080 827c 00fc 8282 8282 82fc
    177 	007c 8280 f080 827c 007c 8280 f080 8080