@@ -34,7 +34,7 @@ ENDM |
| 34 |
ret_dont_call_playnote: MACRO |
34 |
ret_dont_call_playnote: MACRO |
| 35 |
pop hl |
35 |
pop hl |
| 36 |
pop af |
36 |
pop af |
| 37 |
ld a, 6 |
37 |
ld a, 6 ; How many bytes until the next channel's code |
| 38 |
add_a_to_hl |
38 |
add_a_to_hl |
| 39 |
jp hl |
39 |
jp hl |
| 40 |
ENDM |
40 |
ENDM |
@@ -135,8 +135,8 @@ ENDM |
| 135 |
|
135 |
|
| 136 |
SECTION "Song Data", ROM0 |
136 |
SECTION "Song Data", ROM0 |
| 137 |
;; order_cnt is the number of orders times 2 |
137 |
;; order_cnt is the number of orders times 2 |
| 138 |
order_cnt: db 6 |
138 |
order_cnt: db 4 |
| 139 |
order1: dw unreal, unreal, unreal_arps |
139 |
order1: dw unreal, tfau_bass, empty |
| 140 |
order2: dw empty, empty, empty |
140 |
order2: dw empty, empty, empty |
| 141 |
order3: dw empty, empty, empty |
141 |
order3: dw empty, empty, empty |
| 142 |
order4: dw empty, empty, empty |
142 |
order4: dw empty, empty, empty |
@@ -253,23 +253,17 @@ instruments: |
| 253 |
|
253 |
|
| 254 |
square_instrument: |
254 |
square_instrument: |
| 255 |
.sweep: db ; unused for channel 2 |
255 |
.sweep: db ; unused for channel 2 |
| 256 |
.length_and_duty: db %00000000 |
256 |
.length_and_duty: db %10000001 |
| 257 |
.envelope: db %11110000 |
257 |
.envelope: db %11110000 |
| 258 |
.unused: db |
258 |
.highmask: db %11000000 |
| 259 |
|
|
|
| 260 |
square_instrument2: |
|
|
| 261 |
.sweep: db ; unused for channel 2 |
|
|
| 262 |
.length_and_duty: db %10000000 |
|
|
| 263 |
.envelope: db %11110000 |
|
|
| 264 |
.unused: db |
|
|
| 265 |
|
259 |
|
| 266 |
;; Format for channel 3: |
260 |
;; Format for channel 3: |
| 267 |
|
261 |
|
| 268 |
voice_instrument: |
262 |
voice_instrument: |
| 269 |
.length: db 0 |
263 |
.length: db 0 |
| 270 |
.volume: db %00100000 |
264 |
.volume: db %00100000 |
| 271 |
.wave: db 0 |
265 |
.wave: db 0 |
| 272 |
.unused: db 0 |
266 |
.highmask: db %10000000 |
| 273 |
|
267 |
|
| 274 |
;; Format for channel 4: |
268 |
;; Format for channel 4: |
| 275 |
|
269 |
|
@@ -277,8 +271,7 @@ noise_instrument: |
| 277 |
.length: db 0 |
271 |
.length: db 0 |
| 278 |
.envelope: db %10100001 |
272 |
.envelope: db %10100001 |
| 279 |
.step_and_ratio: db 0 |
273 |
.step_and_ratio: db 0 |
| 280 |
.unused: db |
274 |
.highmask: db %10000000 |
| 281 |
|
|
|
| 282 |
|
275 |
|
| 283 |
routines: |
276 |
routines: |
| 284 |
|
277 |
|
@@ -314,7 +307,7 @@ toneporta_target1: dw |
| 314 |
channel_note1: db |
307 |
channel_note1: db |
| 315 |
vibrato_tremolo_phase1: db |
308 |
vibrato_tremolo_phase1: db |
| 316 |
envelope1: db |
309 |
envelope1: db |
| 317 |
ds 1 |
310 |
highmask1: db |
| 318 |
|
311 |
|
| 319 |
;;;;;;;;;;; |
312 |
;;;;;;;;;;; |
| 320 |
;;Channel 2 |
313 |
;;Channel 2 |
@@ -325,7 +318,7 @@ toneporta_target2: dw |
| 325 |
channel_note2: db |
318 |
channel_note2: db |
| 326 |
vibrato_tremolo_phase2: db |
319 |
vibrato_tremolo_phase2: db |
| 327 |
envelope2: db |
320 |
envelope2: db |
| 328 |
ds 1 |
321 |
highmask2: db |
| 329 |
|
322 |
|
| 330 |
;;;;;;;;;;; |
323 |
;;;;;;;;;;; |
| 331 |
;;Channel 3 |
324 |
;;Channel 3 |
@@ -336,7 +329,7 @@ toneporta_target3: dw |
| 336 |
channel_note3: db |
329 |
channel_note3: db |
| 337 |
vibrato_tremolo_phase3: db |
330 |
vibrato_tremolo_phase3: db |
| 338 |
envelope3: db |
331 |
envelope3: db |
| 339 |
ds 1 |
332 |
highmask3: db |
| 340 |
|
333 |
|
| 341 |
;;;;;;;;;;; |
334 |
;;;;;;;;;;; |
| 342 |
;;Channel 4 |
335 |
;;Channel 4 |
@@ -347,7 +340,7 @@ toneporta_target4: dw |
| 347 |
channel_note4: db |
340 |
channel_note4: db |
| 348 |
vibrato_tremolo_phase4: db |
341 |
vibrato_tremolo_phase4: db |
| 349 |
envelope4: db |
342 |
envelope4: db |
| 350 |
ds 1 |
343 |
highmask4: db |
| 351 |
|
344 |
|
| 352 |
row: ds 1 |
345 |
row: ds 1 |
| 353 |
tick: ds 1 |
346 |
tick: ds 1 |
@@ -539,14 +532,14 @@ _update_channel: |
| 539 |
;; TODO: Turn this into a jump table? Or find some other way to optimize |
532 |
;; TODO: Turn this into a jump table? Or find some other way to optimize |
| 540 |
ld a, b |
533 |
ld a, b |
| 541 |
|
534 |
|
| 542 |
cp 0 |
|
|
| 543 |
jp z, _update_channel1 |
|
|
| 544 |
cp 1 |
|
|
| 545 |
jp z, _update_channel2 |
|
|
| 546 |
cp 2 |
|
|
| 547 |
jp z, _update_channel3 |
|
|
| 548 |
cp 3 |
535 |
cp 3 |
| 549 |
jp z, _update_channel4 |
536 |
jp z, _update_channel4 |
|
|
537 |
cp 2 |
|
|
538 |
jp z, _update_channel3 |
|
|
539 |
cp 1 |
|
|
540 |
jp z, _update_channel2 |
|
|
541 |
; cp 0 |
|
|
542 |
; jp z, _update_channel1 |
| 550 |
|
543 |
|
| 551 |
_update_channel1: |
544 |
_update_channel1: |
| 552 |
ld a, e |
545 |
ld a, e |
@@ -573,12 +566,15 @@ _update_channel4: |
| 573 |
ld [rAUD4GO], a |
566 |
ld [rAUD4GO], a |
| 574 |
ret |
567 |
ret |
| 575 |
|
568 |
|
| 576 |
;;;;;;; |
569 |
;;;;;;; |
| 577 |
;; Note playing routines. Need to either consolidate these or find some |
570 |
;; Note playing routines. Need to either consolidate these or find some |
| 578 |
;; better way of doing effects that happen on the first tick. |
571 |
;; better way of doing effects that happen on the first tick. |
| 579 |
;;;;;;; |
572 |
;;;;;;; |
| 580 |
|
573 |
|
| 581 |
_playnote1: |
574 |
_playnote1: |
|
|
575 |
;; Call with: |
|
|
576 |
;; Location of highmask on the stack |
|
|
577 |
|
| 582 |
;; Play a note on channel 1 (square wave) |
578 |
;; Play a note on channel 1 (square wave) |
| 583 |
ld a, [temp_note_value+1] |
579 |
ld a, [temp_note_value+1] |
| 584 |
ld [channel_period1], a |
580 |
ld [channel_period1], a |
@@ -587,7 +583,14 @@ _playnote1: |
| 587 |
ld a, [temp_note_value] |
583 |
ld a, [temp_note_value] |
| 588 |
ld [channel_period1+1], a |
584 |
ld [channel_period1+1], a |
| 589 |
|
585 |
|
| 590 |
or %10000000 |
586 |
;; IN PROGRESS: |
|
|
587 |
|
|
|
588 |
;; Trying to figure out how the highmask and len works, and debugging |
|
|
589 |
;; it with this. |
|
|
590 |
|
|
|
591 |
;; Get the highmask and apply it. |
|
|
592 |
; ld hl, highmask1 |
|
|
593 |
or %11000000; [hl] |
| 591 |
ld [rAUD1HIGH], a |
594 |
ld [rAUD1HIGH], a |
| 592 |
|
595 |
|
| 593 |
ret |
596 |
ret |
@@ -1156,7 +1159,6 @@ fx_porta_down: |
| 1156 |
|
1159 |
|
| 1157 |
jp _update_channel |
1160 |
jp _update_channel |
| 1158 |
|
1161 |
|
| 1159 |
;; TODO: Figure out why this is not toneporta-ing as much as it used to. so bizarre... |
|
|
| 1160 |
fx_toneporta: |
1162 |
fx_toneporta: |
| 1161 |
jr nz, .do_toneporta |
1163 |
jr nz, .do_toneporta |
| 1162 |
|
1164 |
|
@@ -1272,6 +1274,9 @@ _setup_instrument_pointer: |
| 1272 |
ld a, b |
1274 |
ld a, b |
| 1273 |
and %11110000 |
1275 |
and %11110000 |
| 1274 |
swap a |
1276 |
swap a |
|
|
1277 |
ret z ; If there's no instrument, then return early. |
|
|
1278 |
|
|
|
1279 |
dec a ; Instrument 0 is "no instrument" |
| 1275 |
|
1280 |
|
| 1276 |
;; Shift left twice to multiply by 4 |
1281 |
;; Shift left twice to multiply by 4 |
| 1277 |
sla a |
1282 |
sla a |
@@ -1279,6 +1284,7 @@ _setup_instrument_pointer: |
| 1279 |
|
1284 |
|
| 1280 |
ld de, instruments |
1285 |
ld de, instruments |
| 1281 |
add_a_to_de |
1286 |
add_a_to_de |
|
|
1287 |
rla ; reset the Z flag |
| 1282 |
ret |
1288 |
ret |
| 1283 |
|
1289 |
|
| 1284 |
_dosound: |
1290 |
_dosound: |
@@ -1303,6 +1309,13 @@ _dosound: |
| 1303 |
ld [rAUD1LEN], a |
1309 |
ld [rAUD1LEN], a |
| 1304 |
ld a, [de] |
1310 |
ld a, [de] |
| 1305 |
ld [rAUD1ENV], a |
1311 |
ld [rAUD1ENV], a |
|
|
1312 |
inc de |
|
|
1313 |
ld a, [de] |
|
|
1314 |
|
|
|
1315 |
jr nz, .use_instr_mask1 ; if there's a real instrument, use its highmask |
|
|
1316 |
ld a, 0 ; if not, then use zero. |
|
|
1317 |
.use_instr_mask1: |
|
|
1318 |
ld [highmask1], a |
| 1306 |
|
1319 |
|
| 1307 |
.do_setvol1: |
1320 |
.do_setvol1: |
| 1308 |
ld a, h |
1321 |
ld a, h |
@@ -1333,6 +1346,13 @@ _dosound: |
| 1333 |
ld [rAUD2LEN], a |
1346 |
ld [rAUD2LEN], a |
| 1334 |
ld a, [de] |
1347 |
ld a, [de] |
| 1335 |
ld [rAUD2ENV], a |
1348 |
ld [rAUD2ENV], a |
|
|
1349 |
inc de |
|
|
1350 |
ld a, [de] |
|
|
1351 |
|
|
|
1352 |
jr nz, .use_instr_mask2 ; if there's a real instrument, use its highmask |
|
|
1353 |
ld a, 0 ; if not, then use zero. |
|
|
1354 |
.use_instr_mask2: |
|
|
1355 |
ld [highmask2], a |
| 1336 |
|
1356 |
|
| 1337 |
.do_setvol2: |
1357 |
.do_setvol2: |
| 1338 |
ld a, h |
1358 |
ld a, h |
@@ -1367,6 +1387,14 @@ _dosound: |
| 1367 |
;; TODO: Write to _AUD3WAVERAM |
1387 |
;; TODO: Write to _AUD3WAVERAM |
| 1368 |
; ld a, [de] |
1388 |
; ld a, [de] |
| 1369 |
; ld [rAUD3ENV], a |
1389 |
; ld [rAUD3ENV], a |
|
|
1390 |
inc de |
|
|
1391 |
inc de |
|
|
1392 |
ld a, [de] |
|
|
1393 |
|
|
|
1394 |
jr nz, .use_instr_mask3 ; if there's a real instrument, use its highmask |
|
|
1395 |
ld a, 0 ; if not, then use zero. |
|
|
1396 |
.use_instr_mask3: |
|
|
1397 |
ld [highmask3], a |
| 1370 |
|
1398 |
|
| 1371 |
.do_setvol3: |
1399 |
.do_setvol3: |
| 1372 |
ld a, h |
1400 |
ld a, h |
@@ -1401,6 +1429,13 @@ _dosound: |
| 1401 |
ld [rAUD4ENV], a |
1429 |
ld [rAUD4ENV], a |
| 1402 |
ld a, [de] |
1430 |
ld a, [de] |
| 1403 |
ld [rAUD4POLY], a |
1431 |
ld [rAUD4POLY], a |
|
|
1432 |
inc de |
|
|
1433 |
ld a, [de] |
|
|
1434 |
|
|
|
1435 |
jr nz, .use_instr_mask4 ; if there's a real instrument, use its highmask |
|
|
1436 |
ld a, 0 ; if not, then use zero. |
|
|
1437 |
.use_instr_mask4: |
|
|
1438 |
ld [highmask4], a |
| 1404 |
|
1439 |
|
| 1405 |
.do_setvol4: |
1440 |
.do_setvol4: |
| 1406 |
ld a, h |
1441 |
ld a, h |
@@ -1552,6 +1587,11 @@ _noreset: |
| 1552 |
_halt: |
1587 |
_halt: |
| 1553 |
; Do nothing, forever |
1588 |
; Do nothing, forever |
| 1554 |
halt |
1589 |
halt |
|
|
1590 |
_nop: |
|
|
1591 |
;; This NOP needs to be here due to a gameboy hardware bug |
|
|
1592 |
;; where an instruction after a HALT will be skipped. We label |
|
|
1593 |
;; it because it's also used in _dosound as a "blank" highmask. |
|
|
1594 |
;; Pretty clever, huh? |
| 1555 |
nop |
1595 |
nop |
| 1556 |
jr _halt |
1596 |
jr _halt |
| 1557 |
|
1597 |
|