![]() |
Routines |
| Prev: D6B5 | Up: Map | Next: D718 |
|
Used by the routines at PLAY_TUNE_ONCE and PLAY_TUNE.
A note byte's low six bits index NOTES, with 0 a rest; its top two bits are its length less one, one to four units. The note's three bytes are two loop counts that time each half of a wave and how many waves make one unit, and the wave count rises with the pitch, which keeps every unit close to 0.155 seconds whatever the note. The speaker is driven directly, off for one half-wave and on for the other, with the border black.
The routine and NOTES are byte for byte Knight Lore's (play_note there), at other addresses.
|
||||||||||
| PLAY_NOTE | D6C0 | AND $3F | index 0 is a rest | |||||||
| D6C2 | JR Z,PLAY_NOTE_5 | |||||||||
| D6C4 | LD L,A | HL = NOTES + 3 * index | ||||||||
| D6C5 | LD H,$00 | |||||||||
| D6C7 | ADD HL,HL | |||||||||
| D6C8 | CALL ADD_HL_A | |||||||||
| D6CB | LD BC,NOTES | |||||||||
| D6CE | ADD HL,BC | |||||||||
| D6CF | LD B,(HL) | B and C time the half-wave; HL = the number of waves in one unit | ||||||||
| D6D0 | INC HL | |||||||||
| D6D1 | LD C,(HL) | |||||||||
| D6D2 | INC HL | |||||||||
| D6D3 | LD L,(HL) | |||||||||
| D6D4 | LD H,$00 | |||||||||
| D6D6 | LD A,(DE) | the top two bits: the length, one to four units | ||||||||
| D6D7 | RLCA | |||||||||
| D6D8 | RLCA | |||||||||
| D6D9 | AND $03 | |||||||||
| D6DB | INC A | |||||||||
| D6DC | PUSH DE | HL = the waves in one unit times the length | ||||||||
| D6DD | LD E,L | |||||||||
| D6DE | LD D,H | |||||||||
| PLAY_NOTE_0 | D6DF | DEC A | ||||||||
| D6E0 | JR Z,PLAY_NOTE_1 | |||||||||
| D6E2 | ADD HL,DE | |||||||||
| D6E3 | JR PLAY_NOTE_0 | |||||||||
| PLAY_NOTE_1 | D6E5 | POP DE | the tune pointer back in DE | |||||||
| PLAY_NOTE_2 | D6E6 | PUSH BC | speaker off, border black; wait | |||||||
| D6E7 | XOR A | |||||||||
| D6E8 | OUT ($FE),A | |||||||||
| PLAY_NOTE_3 | D6EA | DJNZ PLAY_NOTE_3 | ||||||||
| D6EC | DEC C | |||||||||
| D6ED | JR NZ,PLAY_NOTE_3 | |||||||||
| D6EF | POP BC | |||||||||
| D6F0 | PUSH BC | speaker on; wait | ||||||||
| D6F1 | LD A,$10 | |||||||||
| D6F3 | OUT ($FE),A | |||||||||
| PLAY_NOTE_4 | D6F5 | DJNZ PLAY_NOTE_4 | ||||||||
| D6F7 | DEC C | |||||||||
| D6F8 | JR NZ,PLAY_NOTE_4 | |||||||||
| D6FA | POP BC | |||||||||
| D6FB | DEC HL | until all the waves are done | ||||||||
| D6FC | LD A,H | |||||||||
| D6FD | OR L | |||||||||
| D6FE | JR NZ,PLAY_NOTE_2 | |||||||||
| D700 | INC DE | on to the next note byte | ||||||||
| D701 | RET | |||||||||
| PLAY_NOTE_5 | D702 | LD A,(DE) | a rest: one to four units... | |||||||
| D703 | INC DE | |||||||||
| D704 | RLCA | |||||||||
| D705 | RLCA | |||||||||
| D706 | AND $03 | |||||||||
| D708 | INC A | |||||||||
| D709 | LD L,A | |||||||||
| D70A | LD BC,$430B | ...each 17163 turns of a 26 T-state loop, about 0.127 seconds (no tune has a rest) | ||||||||
| PLAY_NOTE_6 | D70D | PUSH BC | ||||||||
| PLAY_NOTE_7 | D70E | DEC BC | ||||||||
| D70F | LD A,B | |||||||||
| D710 | OR C | |||||||||
| D711 | JR NZ,PLAY_NOTE_7 | |||||||||
| D713 | POP BC | |||||||||
| D714 | DEC L | |||||||||
| D715 | JR NZ,PLAY_NOTE_6 | |||||||||
| D717 | RET | |||||||||
| Prev: D6B5 | Up: Map | Next: D718 |