@@ -63,21 +63,23 @@ ENDR |
| 63 |
|
63 |
|
| 64 |
; Interrupt addresses |
64 |
; Interrupt addresses |
| 65 |
SECTION "Vblank interrupt", ROM0[$0040] |
65 |
SECTION "Vblank interrupt", ROM0[$0040] |
| 66 |
jp _dosound |
66 |
; jp _dosound |
| 67 |
reti |
67 |
reti |
| 68 |
|
68 |
|
| 69 |
SECTION "LCD controller status interrupt", ROM0[$0048] |
69 |
SECTION "LCD controller status interrupt", ROM0[$0048] |
|
|
70 |
jp _dosound |
| 70 |
reti |
71 |
reti |
| 71 |
|
72 |
|
| 72 |
SECTION "Timer overflow interrupt", ROM0[$0050] |
73 |
SECTION "Timer overflow interrupt", ROM0[$0050] |
| 73 |
jp _dosound |
74 |
; jp _dosound |
| 74 |
reti |
75 |
reti |
| 75 |
|
76 |
|
| 76 |
SECTION "Serial transfer completion interrupt", ROM0[$0058] |
77 |
SECTION "Serial transfer completion interrupt", ROM0[$0058] |
| 77 |
reti |
78 |
reti |
| 78 |
|
79 |
|
| 79 |
SECTION "P10-P13 signal low edge interrupt", ROM0[$0060] |
80 |
SECTION "P10-P13 signal low edge interrupt", ROM0[$0060] |
| 80 |
jp _dosound |
81 |
; jp _dosound |
|
|
82 |
reti |
| 81 |
|
83 |
|
| 82 |
; Reserved stack space |
84 |
; Reserved stack space |
| 83 |
SECTION "Stack", WRAM0[$d000 - STACK_SIZE] |
85 |
SECTION "Stack", WRAM0[$d000 - STACK_SIZE] |
@@ -101,16 +103,28 @@ DS 1 |
| 101 |
DB "NF" |
103 |
DB "NF" |
| 102 |
|
104 |
|
| 103 |
SECTION "Song Data", ROM0 |
105 |
SECTION "Song Data", ROM0 |
| 104 |
order_cnt: db 8 |
106 |
;; order_cnt is the number of orders times 2 |
| 105 |
order1: dw unreal, lunawaves, lunawaves, unreal |
107 |
order_cnt: db 2 |
| 106 |
order2: dw lunawaves, unreal, unreal, lunawaves |
108 |
order1: dw unreal;, lunawaves, lunawaves, unreal |
| 107 |
order3: dw unreal, lunawaves, lunawaves, unreal |
109 |
order2: dw empty, unreal, unreal, lunawaves |
| 108 |
order4: dw unreal, lunawaves, lunawaves, unreal |
110 |
order3: dw empty, lunawaves, lunawaves, unreal |
|
|
111 |
order4: dw empty, lunawaves, lunawaves, unreal |
| 109 |
|
112 |
|
| 110 |
lunawaves: |
113 |
lunawaves: |
| 111 |
include "lunawaves.inc" |
114 |
include "lunawaves.inc" |
| 112 |
unreal: |
115 |
unreal: |
| 113 |
include "unreal.inc" |
116 |
include "unreal.inc" |
|
|
117 |
empty: |
|
|
118 |
rept 64 |
|
|
119 |
db 90, 0, 0 |
|
|
120 |
endr |
|
|
121 |
drums: |
|
|
122 |
rept 16 |
|
|
123 |
db 44, 0, 0 |
|
|
124 |
db 90, 0, 0 |
|
|
125 |
db 90, 0, 0 |
|
|
126 |
db 90, 0, 0 |
|
|
127 |
endr |
| 114 |
|
128 |
|
| 115 |
SECTION "Playback variables", WRAM0 |
129 |
SECTION "Playback variables", WRAM0 |
| 116 |
pattern1: dw |
130 |
pattern1: dw |
@@ -158,7 +172,7 @@ _init: |
| 158 |
ld bc, `00000001 |
172 |
ld bc, `00000001 |
| 159 |
call _paint_tile |
173 |
call _paint_tile |
| 160 |
|
174 |
|
| 161 |
;; Load some wave data into _AUD3WAVERAM |
175 |
;; Load some wave data (or code) into _AUD3WAVERAM |
| 162 |
ld hl, $150 ;; note_table |
176 |
ld hl, $150 ;; note_table |
| 163 |
_addr = _AUD3WAVERAM |
177 |
_addr = _AUD3WAVERAM |
| 164 |
REPT 16 |
178 |
REPT 16 |
@@ -192,7 +206,14 @@ _addr = _addr + 1 |
| 192 |
ld a, TACF_START | TACF_4KHZ |
206 |
ld a, TACF_START | TACF_4KHZ |
| 193 |
ld [rTAC], a |
207 |
ld [rTAC], a |
| 194 |
|
208 |
|
| 195 |
ld a, IEF_VBLANK ; IEF_HILO | IEF_TIMER |
209 |
;; Enable the HBlank interrupt on scanline 0 |
|
|
210 |
ld a, [rSTAT] |
|
|
211 |
or a, STATF_LYC |
|
|
212 |
ld [rSTAT], a |
|
|
213 |
ld a, 0 |
|
|
214 |
ld [rLYC], a |
|
|
215 |
|
|
|
216 |
ld a, IEF_VBLANK | IEF_LCDC ; IEF_HILO | IEF_TIMER |
| 196 |
ld [rIE], a |
217 |
ld [rIE], a |
| 197 |
ei |
218 |
ei |
| 198 |
|
219 |
|
@@ -226,6 +247,10 @@ _lookup_note: |
| 226 |
|
247 |
|
| 227 |
;; Stores note value in H and L |
248 |
;; Stores note value in H and L |
| 228 |
ld a, [row] |
249 |
ld a, [row] |
|
|
250 |
ld h, a |
|
|
251 |
;; Multiply by 3 for the note value |
|
|
252 |
add h |
|
|
253 |
add h |
| 229 |
|
254 |
|
| 230 |
ld h, 0 |
255 |
ld h, 0 |
| 231 |
ld l, a |
256 |
ld l, a |
@@ -235,7 +260,7 @@ _lookup_note: |
| 235 |
cp LAST_NOTE |
260 |
cp LAST_NOTE |
| 236 |
jp c, .note_exists |
261 |
jp c, .note_exists |
| 237 |
|
262 |
|
| 238 |
;; Pop the return pointer off the stack and get the one the caller pushed |
263 |
;; Pop the return pointer off the stack and get the one the caller pushed if it's a nonexistent note |
| 239 |
pop hl |
264 |
pop hl |
| 240 |
ld hl, 0 |
265 |
ld hl, 0 |
| 241 |
ret |
266 |
ret |
@@ -259,9 +284,12 @@ _playnote1: |
| 259 |
|
284 |
|
| 260 |
;; Play a note on channel 1 (square wave) |
285 |
;; Play a note on channel 1 (square wave) |
| 261 |
|
286 |
|
|
|
287 |
; ld a, %01111001 |
|
|
288 |
; ld [rAUD1SWEEP], a |
|
|
289 |
|
| 262 |
ld a, %11111111 ; $10 |
290 |
ld a, %11111111 ; $10 |
| 263 |
ldh [rAUD1LEN], a |
291 |
ldh [rAUD1LEN], a |
| 264 |
ld a, %00110000 |
292 |
ld a, %11110000 |
| 265 |
ldh [rAUD1ENV], a |
293 |
ldh [rAUD1ENV], a |
| 266 |
|
294 |
|
| 267 |
ld a, l |
295 |
ld a, l |
@@ -307,9 +335,9 @@ _playnote4: |
| 307 |
|
335 |
|
| 308 |
;; Play a "note" on channel 4 (noise) |
336 |
;; Play a "note" on channel 4 (noise) |
| 309 |
|
337 |
|
| 310 |
ld a, 1 |
338 |
ld a, %00011111 |
| 311 |
ld [rAUD4LEN], a |
339 |
ld [rAUD4LEN], a |
| 312 |
ld a, %11110111 |
340 |
ld a, %11110001 |
| 313 |
ldh [rAUD4ENV], a |
341 |
ldh [rAUD4ENV], a |
| 314 |
ld a, l; %01000100 |
342 |
ld a, l; %01000100 |
| 315 |
ldh [rAUD4POLY], a |
343 |
ldh [rAUD4POLY], a |
@@ -327,7 +355,6 @@ ENDM |
| 327 |
|
355 |
|
| 328 |
_dosound: |
356 |
_dosound: |
| 329 |
ld a, [tick] |
357 |
ld a, [tick] |
| 330 |
ld c, a |
|
|
| 331 |
cp 0 |
358 |
cp 0 |
| 332 |
jp nz, _process_tick |
359 |
jp nz, _process_tick |
| 333 |
|
360 |
|
@@ -342,31 +369,38 @@ _dosound: |
| 342 |
push hl |
369 |
push hl |
| 343 |
loadShort pattern1, d, e |
370 |
loadShort pattern1, d, e |
| 344 |
call _lookup_note |
371 |
call _lookup_note |
|
|
372 |
pop de |
| 345 |
call _playnote1 |
373 |
call _playnote1 |
| 346 |
|
374 |
|
| 347 |
_after_note1: |
375 |
_after_note1: |
| 348 |
; ld hl, _after_note2 |
376 |
ld hl, _after_note2 |
| 349 |
; push hl |
377 |
push hl |
| 350 |
; loadShort pattern2, d, e |
378 |
loadShort pattern2, d, e |
| 351 |
; call _lookup_note |
379 |
call _lookup_note |
| 352 |
; call _playnote2 |
380 |
pop de |
|
|
381 |
call _playnote2 |
| 353 |
|
382 |
|
| 354 |
_after_note2: |
383 |
_after_note2: |
| 355 |
; ld hl, _after_note3 |
384 |
ld hl, _after_note3 |
| 356 |
; push hl |
385 |
push hl |
| 357 |
; loadShort pattern3, d, e |
386 |
loadShort pattern3, d, e |
| 358 |
; call _lookup_note |
387 |
call _lookup_note |
| 359 |
; call _playnote3 |
388 |
pop de |
|
|
389 |
call _playnote3 |
| 360 |
|
390 |
|
| 361 |
_after_note3: |
391 |
_after_note3: |
| 362 |
; ld hl, _process_tick |
392 |
ld hl, _process_tick |
| 363 |
; push hl |
393 |
push hl |
| 364 |
; loadShort pattern4, d, e |
394 |
loadShort pattern4, d, e |
| 365 |
; call _lookup_note |
395 |
call _lookup_note |
| 366 |
; call _playnote4 |
396 |
pop de |
|
|
397 |
call _playnote4 |
| 367 |
|
398 |
|
| 368 |
_process_tick: |
399 |
_process_tick: |
| 369 |
ld a, c |
400 |
;; Process effect commands |
|
|
401 |
|
|
|
402 |
|
|
|
403 |
ld a, [tick] |
| 370 |
inc a |
404 |
inc a |
| 371 |
|
405 |
|
| 372 |
cp TICKS |
406 |
cp TICKS |