Prev: E5A5 Up: Map Next: E5FE
E5B6: Play music
Used by the routines at C0C1, C763 and DA88.
Input
A Indicates which music to play (1 = intro tune, 2 = paused game tune)
"The Spectrum did not have much scope with its little beeper but I managed harmonies by counting down more than one loop at a time and reversing the pulse when each counter got to zero.
I got a phasing synthy sound by making the counters almost the same."

From interview with Steve Turner at retrovideogamer.co.uk/rvg-interviews-steve-turner
There are two tunes/melodies.
(1) The first tune is played at the end of the intro sequence when a new game is started, and also when the game is completed. Uses music data stored at EBF0.
(2) The second tune is played then the game is paused. Uses music data at EC72.
E5B6 CP $01 Check which tune needs to be played
E5B8 JR NZ,$E5BF
E5BA LD HL,$EBF0 Point HL at first note(s) of the intro/end tune data
E5BD JR $E5C2
E5BF LD HL,$EC72 Point HL at first note(s) of the paused game tune data.
Play notes
E5C2 LD A,(HL) Get note value
E5C3 CP $FF 255 is an end-of-music marker
E5C5 JR Z,$E5FD If so, RETurn to previous routine
E5C7 LD B,A Get first note of pair
E5C8 INC HL Get second note of pair
E5C9 LD A,(HL)
E5CA LD C,A ...and store in C register
E5CB INC HL Move note data pointer on ready for next note
E5CC LD ($EB54),HL ...and store
E5CF LD H,B H = first note of pair, e.g. 190
E5D0 LD A,C
E5D1 ADD A,$20 +32 to create a phase-type effect
E5D3 LD L,A L = second note of pair, plus 32, e.g. 222
E5D4 LD DE,$1C00 7168 = Note duration
E5D7 LD A,$00 Reset A to 0
E5D9 DEC H Decrement first note byte (for sound note loop)
E5DA JR NZ,$E5DF Reached zero?
E5DC OR $10 If zero, ensure speaker bit (4) is set to play sound
E5DE LD H,B ...and restore first note of pair again
E5DF DEC L Decrement second note byte (for sound note loop)
E5E0 JR NZ,$E5E5 Reached zero?
E5E2 OR $10 If zero, ensure speaker bit (4) is set
E5E4 LD L,C ...and restore second note of pair again
E5E5 ADD A,$08 'Thickens out' the sound by ensuring speaker is toggled on a bit more
E5E7 AND $10 Filter out other bits, only keeping bit (4) speaker toggle bit
E5E9 OUT ($FE),A ...and play sound by toggling speaker on or off accordingly
E5EB SRA A Shift bits right
E5ED LD ($EB53),A ..and store, as A register needed for next bit
E5F0 DEC DE Decrement note counter
E5F1 LD A,D And check if at zero
E5F2 OR E
E5F3 LD A,($EB53) Restore A register which holds the speaker bits
E5F6 JR NZ,$E5D9 If not at zero yet, continue to play note
E5F8 LD HL,($EB54) Note played. Get data pointer
E5FB JR $E5C2 ...and go and play next note
E5FD RET Return to routine at C0C1 or C763.
Prev: E5A5 Up: Map Next: E5FE