![]() |
Routines |
| Prev: 46266 | Up: Map | Next: 46365 |
|
Used by the routines at PlayMusic_WaitKey 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 MusicNotes 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 | 46277 | AND %00111111 | Keep bits 0 to 5. | |||||||||||
| 46279 | JR Z,PlayNote_Rest | Jump to PlayNote_Rest if the note is a rest. | ||||||||||||
| 46281 | LD L,A | Set HL to the note number. | ||||||||||||
| 46282 | LD H,0 | |||||||||||||
| 46284 | ADD HL,HL | Double the number. | ||||||||||||
| 46285 | CALL AddAToHL | Call AddAToHL. | ||||||||||||
| 46288 | LD BC,46365 | Point BC at MusicNotes. | ||||||||||||
| 46291 | ADD HL,BC | Find the entry for the note. | ||||||||||||
| 46292 | LD B,(HL) | Fetch the first delay. | ||||||||||||
| 46293 | INC HL | Move on. | ||||||||||||
| 46294 | LD C,(HL) | Fetch the second delay. | ||||||||||||
| 46295 | INC HL | Move on. | ||||||||||||
| 46296 | LD L,(HL) | Fetch the number of cycles. | ||||||||||||
| 46297 | LD H,0 | Set H to 0. | ||||||||||||
|
Bits 6 and 7 are the length, less one.
|
||||||||||||||
| 46299 | LD A,(DE) | Fetch the note again. | ||||||||||||
| 46300 | RLCA | Move bits 6 and 7 to bits 0 and 1. | ||||||||||||
| 46301 | RLCA | |||||||||||||
| 46302 | AND %00000011 | Keep bits 0 and 1. | ||||||||||||
| 46304 | INC A | Add one. | ||||||||||||
| 46305 | PUSH DE | Stash the note address on the stack. | ||||||||||||
| 46306 | LD E,L | Copy the number of cycles to DE. | ||||||||||||
| 46307 | LD D,H | |||||||||||||
|
Multiply the number of cycles by the length.
|
||||||||||||||
| PlayNote_MultiplyLength | 46308 | DEC A | Count down the length. | |||||||||||
| 46309 | JR Z,PlayNote_PlayCycle | Jump to PlayNote_PlayCycle if the length has been used up. | ||||||||||||
| 46311 | ADD HL,DE | Add the number of cycles again. | ||||||||||||
| 46312 | JR PlayNote_MultiplyLength | Jump to PlayNote_MultiplyLength. | ||||||||||||
| PlayNote_PlayCycle | 46314 | POP DE | Restore the note address from the stack. | |||||||||||
|
Each pass makes one cycle of the note.
|
||||||||||||||
| PlayNote_Cycle | 46315 | PUSH BC | Stash the delays on the stack. | |||||||||||
| 46316 | XOR A | Set A to 0. | ||||||||||||
| 46317 | OUT (254),A | Turn the speaker off. | ||||||||||||
| PlayNote_FirstDelay | 46319 | DJNZ PlayNote_FirstDelay | Wait for the first half of the cycle. | |||||||||||
| 46321 | DEC C | Count down the second delay. | ||||||||||||
| 46322 | JR NZ,PlayNote_FirstDelay | Jump to PlayNote_FirstDelay until it has finished. | ||||||||||||
| 46324 | POP BC | Restore the delays from the stack. | ||||||||||||
| 46325 | PUSH BC | Stash the delays on the stack. | ||||||||||||
| 46326 | LD A,16 | Set bit 4. | ||||||||||||
| 46328 | OUT (254),A | Turn the speaker on. | ||||||||||||
| PlayNote_SecondDelay | 46330 | DJNZ PlayNote_SecondDelay | Wait for the second half of the cycle. | |||||||||||
| 46332 | DEC C | Count down the second delay. | ||||||||||||
| 46333 | JR NZ,PlayNote_SecondDelay | Jump to PlayNote_SecondDelay until it has finished. | ||||||||||||
| 46335 | POP BC | Restore the delays from the stack. | ||||||||||||
| 46336 | DEC HL | Count down the cycles. | ||||||||||||
| 46337 | LD A,H | Jump to PlayNote_Cycle until all of the cycles have been played. | ||||||||||||
| 46338 | OR L | |||||||||||||
| 46339 | JR NZ,PlayNote_Cycle | |||||||||||||
| 46341 | INC DE | Move on to the next note. | ||||||||||||
| 46342 | RET | Return. | ||||||||||||
|
A rest is a silent pause of one to four units.
|
||||||||||||||
| PlayNote_Rest | 46343 | LD A,(DE) | Fetch the length of the rest. | |||||||||||
| 46344 | INC DE | Move on to the next note. | ||||||||||||
| 46345 | RLCA | Move bits 6 and 7 to bits 0 and 1. | ||||||||||||
| 46346 | RLCA | |||||||||||||
| 46347 | AND %00000011 | Keep bits 0 and 1. | ||||||||||||
| 46349 | INC A | Add one. | ||||||||||||
| 46350 | LD L,A | Keep it in L. | ||||||||||||
| 46351 | LD BC,17163 | Set BC to 17163. | ||||||||||||
| PlayNote_RestUnit | 46354 | PUSH BC | Stash the pause length on the stack. | |||||||||||
| PlayNote_Pause | 46355 | DEC BC | Count down the pause. | |||||||||||
| 46356 | LD A,B | Jump to PlayNote_Pause until it has finished. | ||||||||||||
| 46357 | OR C | |||||||||||||
| 46358 | JR NZ,PlayNote_Pause | |||||||||||||
| 46360 | POP BC | Restore the pause length from the stack. | ||||||||||||
| 46361 | DEC L | Count down the units of the rest. | ||||||||||||
| 46362 | JR NZ,PlayNote_RestUnit | Jump to PlayNote_RestUnit until the rest has finished. | ||||||||||||
| 46364 | RET | Return. | ||||||||||||
|
View the equivalent code in;
|
||||||||||||||
| Prev: 46266 | Up: Map | Next: 46365 |