Browse code

Ported examples to new audio api

neauoire authored on 04/04/2021 03:58:42
Showing 3 changed files
... ...
@@ -28,7 +28,7 @@ else
28 28
 fi
29 29
 
30 30
 echo "Assembling.."
31
-./bin/assembler projects/examples/dev.audio.usm bin/boot.rom
31
+./bin/assembler projects/examples/dev.time.usm bin/boot.rom
32 32
 
33 33
 echo "Running.."
34 34
 if [ "${2}" = '--cli' ]; 
... ...
@@ -10,9 +10,11 @@
10 10
 ;pointer { x 2 y 2 }
11 11
 ;circle { xc 2 yc 2 x 2 y 2 r 2 d 2 }
12 12
 
13
+|0100 ;Console { pad 8 char 1 byte 1 short 2 }
13 14
 |0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
14 15
 |0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
15 16
 |0150 ;Mouse  { x 2 y 2 state 1 chord 1 }
17
+|0170 ;Audio { ch1adsr 2 ch2adsr 2 ch3adsr 2 ch4adsr 2 ch1vol 1 ch1pitch 1 ch2vol 1 ch2pitch 1 ch3vol 1 ch3pitch 1 ch4vol 1 ch4pitch 1 }
16 18
 |01F0 ;System { pad 8 r 2 g 2 b 2 }
17 19
 |0200 ^RESET JMP
18 20
 |0204 ,ERROR JMP2
... ...
@@ -20,8 +22,10 @@
20 22
 
21 23
 @RESET
22 24
 
23
-	( theme ) #13fd =System.r #1ef3 =System.g #1bf2 =System.b
25
+	( theme ) #03fd =System.r #0ef3 =System.g #0bf2 =System.b
24 26
 	
27
+	#004f =Audio.ch1adsr #33 =Audio.ch1vol
28
+
25 29
 BRK
26 30
 
27 31
 @FRAME
... ...
@@ -32,9 +36,11 @@ BRK
32 36
 	,draw-cursor JSR2
33 37
 
34 38
 	~Mouse.state #00 EQU ^$no-touch JNZ
35
-		~Mouse.x =circle.xc
36
-		~Mouse.y =circle.yc
39
+		~Mouse.x DUP2 =circle.xc
40
+		~Mouse.y DUP2 =circle.yc
37 41
 		#0000 =circle.r
42
+		( play sound ) ~Screen.width #000c DIV2 ADD2 #0002 DIV2 SWP POP =Audio.ch1pitch
43
+		( release ) #00 =Mouse.state
38 44
 	$no-touch
39 45
 
40 46
  	( draw )
... ...
@@ -17,7 +17,7 @@
17 17
 |0100 ;Console { pad 8 char 1 byte 1 short 2 }
18 18
 |0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
19 19
 |0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
20
-|0170 ;Audio { ch1adsr 2 ch2adsr 2 ch3adsr 2 ch4adsr 2 ch1pitch 1 ch1vol 1 ch2pitch 1 ch2vol 1 ch3pitch 1 ch3vol 1 ch4pitch 1 ch4vol 1 }
20
+|0170 ;Audio { ch1adsr 2 ch2adsr 2 ch3adsr 2 ch4adsr 2 ch1vol 1 ch1pitch 1 ch2vol 1 ch2pitch 1 ch3vol 1 ch3pitch 1 ch4vol 1 ch4pitch 1 }
21 21
 |0190 ;Time { year 2 month 1 day 1 hour 1 minute 1 second 1 dow 1 doy 2 isdst 1 get 1 }
22 22
 |01F0 ;System { pad 8 r 2 g 2 b 2 }
23 23
 
... ...
@@ -33,6 +33,12 @@
33 33
 	
34 34
 	( theme ) #0ff8 =System.r #0f08 =System.g #0f08 =System.b
35 35
 
36
+	#1000 =Audio.ch1adsr
37
+	#66 =Audio.ch1vol
38
+
39
+	#0003 =Audio.ch2adsr
40
+	#66 =Audio.ch2vol
41
+
36 42
 BRK
37 43
 
38 44
 @FRAME
... ...
@@ -43,9 +49,12 @@ BRK
43 49
 	~Time.second ~current.second NEQ #01 JNZ BRK
44 50
 	~Time.second =current.second
45 51
 
46
-	#1444 =Audio.ch1adsr
47
-	~Time.second #1d ADD =Audio.ch1pitch
48
-	~Time.second #03 AND #4b MUL #0f ADD =Audio.ch1vol
52
+	( play sounds )
53
+	#0d =Audio.ch1pitch
54
+
55
+	~Time.second #0f MOD #00 NEQ ^$no-tone JNZ
56
+		#0d #02 MUL =Audio.ch2pitch
57
+	$no-tone
49 58
 
50 59
 	( clear )
51 60
 	#0080 SCALEX #0080 SCALEY ~needles.sx ~needles.sy #00 ,draw-line JSR2