Prev: E16A Up: Map Next: E207
E1D7: Play (generic) sound effect
Used by the routines at C07A, D325 and DA88.
Generic white noise sound effects, crunching, stepping sounds - e.g. doors opening/closing, creature footsteps. Also used to generate the thunder sound in the intro lightning routine.
  • The byte at EB56 determines length/frequency of the sound effect.
  • The address pointer stored at EB59, and initialised at address 0000 (ROM) provides random values for the sound.
E1D7 LD ($EB57),HL Preserve HL for this routine
E1DA LD A,($EB56) Counter/frequency for sound effect
E1DD LD B,A Store in B register
E1DE CP $00
E1E0 JR Z,$E203
E1E2 DEC A Decrement counter and store
E1E3 LD ($EB56),A
E1E6 LD A,B Retrieve (pre-decremented) counter
E1E7 AND $07 Check bits 0-2 to cause an occasional change of address for the base address pointer
E1E9 LD HL,($EB59) Get byte from address pointer in readiness
E1EC LD A,(HL)
E1ED JR NZ,$E1FA
Every 8 loops, move to a different address for the byte value to base the effect on:
E1EF INC HL Skip to the next address
E1F0 LD ($EB59),HL ..and store address pointer
E1F3 LD A,(HL)
E1F4 JR NZ,$E1FA Repeat of condition that was checked at E1ED
E1F6 INC HL Skip another address
E1F7 LD ($EB59),HL ...and re-store counter
Use pseudo-random byte to generate sound:
E1FA INC B Shift sound byte based on counter - randomize speaker bit
E1FB RLA
E1FC DJNZ $E1FB
E1FE SBC A,A Based on the (randomized) carry flag the subtraction will cause the speaker bit to be either on or off (50/50)
E1FF AND $10 Filter out everything except speaker bit (bit 4)
E201 OUT ($FE),A Output value to speaker (1 or 0)
E203 LD HL,($EB57) Retrieve HL register pair value preserved at the start of the routine
E206 RET
Prev: E16A Up: Map Next: E207