![]() |
Routines |
| Prev: 54965 | Up: Map | Next: 55064 |
|
Used by the routines at PlayMusicOnce and PlayMusic.
Plays a note of a tune, or a rest if the note number is zero. Bits 0 to 5 select the entry in NoteTable that holds the two delays of a cycle and the number of cycles. Bits 6 and 7 are the length less one, which multiplies the number of cycles, so the note is one to four times as long.
|
||||||||||||||
|
Look up the delays and the number of cycles.
|
||||||||||||||
| PlayNote | 54976 | AND %00111111 | Keep bits 0 to 5. | |||||||||||
| 54978 | JR Z,PlayNote_Rest | Jump to PlayNote_Rest if the note is a rest. | ||||||||||||
| 54980 | LD L,A | Set HL to the note number. | ||||||||||||
| 54981 | LD H,0 | |||||||||||||
| 54983 | ADD HL,HL | Double the number. | ||||||||||||
| 54984 | CALL AddAToHL | Call AddAToHL. | ||||||||||||
| 54987 | LD BC,55064 | Point BC at NoteTable. | ||||||||||||
| 54990 | ADD HL,BC | Find the entry for the note. | ||||||||||||
| 54991 | LD B,(HL) | Fetch the first delay. | ||||||||||||
| 54992 | INC HL | Move on. | ||||||||||||
| 54993 | LD C,(HL) | Fetch the second delay. | ||||||||||||
| 54994 | INC HL | Move on. | ||||||||||||
| 54995 | LD L,(HL) | Fetch the number of cycles. | ||||||||||||
| 54996 | LD H,0 | Set H to 0. | ||||||||||||
|
Bits 6 and 7 are the length, less one.
|
||||||||||||||
| 54998 | LD A,(DE) | Fetch the note again. | ||||||||||||
| 54999 | RLCA | Move bits 6 and 7 to bits 0 and 1. | ||||||||||||
| 55000 | RLCA | |||||||||||||
| 55001 | AND %00000011 | Keep bits 0 and 1. | ||||||||||||
| 55003 | INC A | Add one. | ||||||||||||
| 55004 | PUSH DE | Stash the note address on the stack. | ||||||||||||
| 55005 | LD E,L | Copy the number of cycles to DE. | ||||||||||||
| 55006 | LD D,H | |||||||||||||
|
Multiply the number of cycles by the length.
|
||||||||||||||
| PlayNote_Multiply | 55007 | DEC A | Count down the length. | |||||||||||
| 55008 | JR Z,PlayNote_Start | Jump to PlayNote_Start if the length has been used up. | ||||||||||||
| 55010 | ADD HL,DE | Add the number of cycles again. | ||||||||||||
| 55011 | JR PlayNote_Multiply | Jump to PlayNote_Multiply. | ||||||||||||
| PlayNote_Start | 55013 | POP DE | Restore the note address from the stack. | |||||||||||
|
Each pass makes one cycle of the note.
|
||||||||||||||
| PlayNote_Cycle | 55014 | PUSH BC | Stash the delays on the stack. | |||||||||||
| 55015 | XOR A | Set A to 0. | ||||||||||||
| 55016 | OUT (254),A | Turn the speaker off. | ||||||||||||
| PlayNote_LowWait | 55018 | DJNZ PlayNote_LowWait | Wait for the first half of the cycle. | |||||||||||
| 55020 | DEC C | Count down the second delay. | ||||||||||||
| 55021 | JR NZ,PlayNote_LowWait | Jump to PlayNote_LowWait until it has finished. | ||||||||||||
| 55023 | POP BC | Restore the delays from the stack. | ||||||||||||
| 55024 | PUSH BC | Stash the delays on the stack. | ||||||||||||
| 55025 | LD A,16 | Set bit 4. | ||||||||||||
| 55027 | OUT (254),A | Turn the speaker on. | ||||||||||||
| PlayNote_HighWait | 55029 | DJNZ PlayNote_HighWait | Wait for the second half of the cycle. | |||||||||||
| 55031 | DEC C | Count down the second delay. | ||||||||||||
| 55032 | JR NZ,PlayNote_HighWait | Jump to PlayNote_HighWait until it has finished. | ||||||||||||
| 55034 | POP BC | Restore the delays from the stack. | ||||||||||||
| 55035 | DEC HL | Count down the cycles. | ||||||||||||
| 55036 | LD A,H | Jump to PlayNote_Cycle until all of the cycles have been played. | ||||||||||||
| 55037 | OR L | |||||||||||||
| 55038 | JR NZ,PlayNote_Cycle | |||||||||||||
| 55040 | INC DE | Move on to the next note. | ||||||||||||
| 55041 | RET | Return. | ||||||||||||
|
A rest is a silent pause of one to four units.
|
||||||||||||||
| PlayNote_Rest | 55042 | LD A,(DE) | Fetch the length of the rest. | |||||||||||
| 55043 | INC DE | Move on to the next note. | ||||||||||||
| 55044 | RLCA | Move bits 6 and 7 to bits 0 and 1. | ||||||||||||
| 55045 | RLCA | |||||||||||||
| 55046 | AND %00000011 | Keep bits 0 and 1. | ||||||||||||
| 55048 | INC A | Add one. | ||||||||||||
| 55049 | LD L,A | Keep it in L. | ||||||||||||
| 55050 | LD BC,17163 | Set BC to 17163. | ||||||||||||
| PlayNote_RestOuter | 55053 | PUSH BC | Stash the pause length on the stack. | |||||||||||
| PlayNote_RestWait | 55054 | DEC BC | Count down the pause. | |||||||||||
| 55055 | LD A,B | Jump to PlayNote_RestWait until the delay is over. | ||||||||||||
| 55056 | OR C | |||||||||||||
| 55057 | JR NZ,PlayNote_RestWait | |||||||||||||
| 55059 | POP BC | Restore the pause length from the stack. | ||||||||||||
| 55060 | DEC L | Count down the units of the rest. | ||||||||||||
| 55061 | JR NZ,PlayNote_RestOuter | Jump to PlayNote_RestOuter until the rest is over. | ||||||||||||
| 55063 | RET | Return. | ||||||||||||
|
View the equivalent code in;
|
||||||||||||||
| Prev: 54965 | Up: Map | Next: 55064 |