Prev: 58789 Up: Map Next: 58878
58806: Play music
Used by the routines at 49345, 51043 and 55944.
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 60400.
(2) The second tune is played then the game is paused. Uses music data at 60530.
58806 CP 1 Check which tune needs to be played
58808 JR NZ,58815
58810 LD HL,60400 Point HL at first note(s) of the intro/end tune data
58813 JR 58818
58815 LD HL,60530 Point HL at first note(s) of the paused game tune data.
Play notes
58818 LD A,(HL) Get note value
58819 CP 255 255 is an end-of-music marker
58821 JR Z,58877 If so, RETurn to previous routine
58823 LD B,A Get first note of pair
58824 INC HL Get second note of pair
58825 LD A,(HL)
58826 LD C,A ...and store in C register
58827 INC HL Move note data pointer on ready for next note
58828 LD (60244),HL ...and store
58831 LD H,B H = first note of pair, e.g. 190
58832 LD A,C
58833 ADD A,32 +32 to create a phase-type effect
58835 LD L,A L = second note of pair, plus 32, e.g. 222
58836 LD DE,7168 7168 = Note duration
58839 LD A,0 Reset A to 0
58841 DEC H Decrement first note byte (for sound note loop)
58842 JR NZ,58847 Reached zero?
58844 OR 16 If zero, ensure speaker bit (4) is set to play sound
58846 LD H,B ...and restore first note of pair again
58847 DEC L Decrement second note byte (for sound note loop)
58848 JR NZ,58853 Reached zero?
58850 OR 16 If zero, ensure speaker bit (4) is set
58852 LD L,C ...and restore second note of pair again
58853 ADD A,8 'Thickens out' the sound by ensuring speaker is toggled on a bit more
58855 AND 16 Filter out other bits, only keeping bit (4) speaker toggle bit
58857 OUT (254),A ...and play sound by toggling speaker on or off accordingly
58859 SRA A Shift bits right
58861 LD (60243),A ..and store, as A register needed for next bit
58864 DEC DE Decrement note counter
58865 LD A,D And check if at zero
58866 OR E
58867 LD A,(60243) Restore A register which holds the speaker bits
58870 JR NZ,58841 If not at zero yet, continue to play note
58872 LD HL,(60244) Note played. Get data pointer
58875 JR 58818 ...and go and play next note
58877 RET Return to routine at 49345 or 51043.
Prev: 58789 Up: Map Next: 58878