-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsound.asm
221 lines (156 loc) · 5.44 KB
/
sound.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
; extra MACRO files need to go here
include "myMacros.inc"
.assume adl=1 ; ez80 ADL memory mode
.org $40000 ; load code here
jp start_here ; jump to start of code
.align 64 ; MOS header
.db "MOS",0,1
start_here:
push af ; store all the registers
push bc
push de
push ix
push iy
; ------------------
; This is our actual code
CLS
call loadSample
ld hl, message
call printString
WAIT_HERE:
MOSCALL $1E ; get IX pointer to keyvals
ld a, (ix + $0E)
bit 0, a ; ESC key
jp nz, EXIT_HERE ; if pressed, jump to EXIT_HERE
MOSCALL $1E ; get IX pointer to keyvals
ld a, (ix + $08)
bit 1, a ; A key
call nz, playNote
MOSCALL $1E ; get IX pointer to keyvals
ld a, (ix + $0C)
bit 4, a ; B key
call nz, playMainJet ; if pressed, start sound
MOSCALL $1E ; get IX pointer to keyvals
ld a, (ix + $0C)
bit 4, a ; B key
call z, stopMainJet ; if not pressed stop sound
MOSCALL $1E ; get IX pointer to keyvals
ld a, (ix + $0A)
bit 2, a ; C key
call nz, playSample
jr WAIT_HERE
; ------------------
; This is where we exit the program
EXIT_HERE:
ld a, 23 ; SHOW CURSOR
rst.lil $10
ld a, 1
rst.lil $10
ld a,1 ; VDU 23,1,0 = hide the text cursor
rst.lil $10 ; VDU 23,1,1 = show the text cursor
CLS
pop iy ; Pop all registers back from the stack
pop ix
pop de
pop bc
pop af
ld hl,0 ; Load the MOS API return code (0) for no errors.
ret ; Return to MOS
; ------------------
; DATA
; ------------------
message:
.db "Sound example, press A, B, or C\r\n",0
; ------------------
; SOUND ROUTINES
; ------------------
playNote:
ld hl, note
ld bc, endNote - note
rst.lil $18
call wait_for_keyup
ret
note:
.db 23,0,$85 ; do sound
.db 0 ; channel
.db 4,0 ; set waveform, waveform type
.db 23,0,$85 ; do sound
.db 0 ; channel
.db 0,63 ; code, volume
.dw 800 ; freq
.dw 1000 ; duration (milliseconds WORD)
endNote:
; ------------------
playMainJet:
ld a, (jetPlaying)
cp 1
ret z
ld hl, mainJetPlay
ld bc, endMainJet - mainJetPlay
rst.lil $18
ld a, 1
ld (jetPlaying),a
ret
mainJetPlay:
.db 23,0,$85,1,4,5 ; set waveform to VIC noise
.db 23,0,$85,1,0,127
.dw $40, -1 ; frq, duration
endMainJet:
stopMainJet:
ld hl, stopMainSnd
ld bc, endMainSnd - stopMainSnd
rst.lil $18
ld a, 0
ld (jetPlaying),a
ret
stopMainSnd:
.db 23,0,$85,1,2,0 ; set vol to 0
endMainSnd:
jetPlaying:
.db 0
; ------------------
playSample:
ld hl, startSample
ld bc, endSample - startSample
rst.lil $18
call wait_for_keyup
ret
startSample:
.db 23,0,$85 ; do sound
.db 2,4,-1 ; channel
.db 23,0,$85 ; do sound
.db 2,0, 127 ; channel, volume
.dw 125 ; freq (ignored for samples)
.dw 1000 ; duration (ignored for samples)
endSample:
; ------------------
loadSample: ; for loading audio samples
ld hl, sampleStr ; start of data to send
ld bc, endSampleStr - sampleStr ; length of data to send
rst.lil $18 ; send data
ret
sampleStr:
.db 23,0,85h ; audio command
.db -1, 5 ; sample number, sample management
.db 0 ; load
.dl 15279 ; length in bytes (LONG)
incbin "letsgo.raw"
endSampleStr:
; ------------------
; OTHER FUNCTIONS
; ------------------
wait_for_keyup: ; wait for key up state so we only do it once
MOSCALL $08 ; get IX pointer to sysvars
ld a, (ix + 18h) ; get key state
cp 0 ; are keys up, none currently pressed?
jr nz, wait_for_keyup ; loop if there is a key still pressed
ret
; ------------------
printString: ; print zero terminated string
ld a,(hl)
or a
ret z
RST.LIL 10h
inc hl
jr printString
; ------------------