Prev: 49359 Up: Map Next: 49436
49370: Play Note
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 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.
Input
A The note
DE Address of the note
Output
DE Address of the next note
PlayNote 49370 AND %00111111 Keep the note number.
49372 JR Z,PlayRest Jump to make a rest if the note number is zero.
Look up the delays and the number of cycles.
49374 LD L,A Set HL to the note number.
49375 LD H,0
49377 ADD HL,HL Double the number.
49378 CALL AddAToHL ...and add the note number to give three times it, using AddAToHL.
49381 LD BC,49458 Add the address of the table of notes.
49384 ADD HL,BC
49385 LD B,(HL) Fetch the first delay.
49386 INC HL Move on.
49387 LD C,(HL) Fetch the second delay.
49388 INC HL Move on.
49389 LD L,(HL) Fetch the number of cycles of the shortest note.
49390 LD H,0 Set H to 0.
Bits 6 and 7 are the length, less one.
49392 LD A,(DE) Fetch the note again.
49393 RLCA Move bits 6 and 7 to bits 0 and 1.
49394 RLCA
49395 AND %00000011 Keep bits 0 and 1.
49397 INC A Add one.
49398 PUSH DE Save the address of the note.
49399 LD E,L Copy the number of cycles of the shortest note into DE.
49400 LD D,H
Multiply the number of cycles by the length.
PlayMusic_Process_Multiply 49401 DEC A Count down the length.
49402 JR Z,PlayMusic_Process_Finished Jump to PlayMusic_Process_Finished if the length has been used up.
49404 ADD HL,DE Otherwise add on the number of cycles of the shortest note again...
49405 JR PlayMusic_Process_Multiply Jump to PlayMusic_Process_Multiply.
PlayMusic_Process_Finished 49407 POP DE Restore the note address from the stack.
Each pass makes one cycle of the note.
PlayMusic_Process_Cycle 49408 PUSH BC Stash the delays on the stack.
49409 XOR A Set A to 0.
49410 OUT (254),A Turn the speaker off.
PlayMusic_Process_LowWait 49412 DJNZ PlayMusic_Process_LowWait Wait for the time of the low half of a cycle...
Count down the rest of the delay.
49414 DEC C Count down the second delay.
49415 JR NZ,PlayMusic_Process_LowWait Jump to PlayMusic_Process_LowWait until it has finished.
49417 POP BC Restore the delays from the stack.
49418 PUSH BC Stash the delays on the stack.
49419 LD A,16 Set bit 4.
49421 OUT (254),A Turn the speaker on.
PlayMusic_Process_HighWait 49423 DJNZ PlayMusic_Process_HighWait Wait for the time of the high half of a cycle...
Count down the rest of the delay.
49425 DEC C Count down the second delay.
49426 JR NZ,PlayMusic_Process_HighWait Jump to PlayMusic_Process_HighWait until it has finished.
49428 POP BC Restore the delays from the stack.
Count down the number of cycles, and loop back until it reaches zero.
49429 DEC HL Count down the cycles.
49430 LD A,H Jump to PlayMusic_Process_Cycle until all of the cycles have been played.
49431 OR L
49432 JR NZ,PlayMusic_Process_Cycle
49434 INC DE Move on to the next note.
49435 RET Return.
View the equivalent code in;
Prev: 49359 Up: Map Next: 49436