← B991 Sound effect: safety net flash Map B9C2 → Effect step counters
B9B4: Emit one square-wave cycle (the sound primitive)
The one place any sound effect reaches the speaker. The SOUND FX option therefore mutes them all together.
Input
D pitch period; larger means a lower pitch
Output
D unchanged, so a caller can repeat the call to hold a tone
With SOUND FX off, the options-menu redraw patches this routine's first byte so it returns at once. With SOUND FX on, it restores that byte.
Seven effects share this counted-step shape, written here once: sfx_death_burst, sfx_spawn, sfx_chew, sfx_bomb_detonate, sfx_bat_grows, sfx_bat_shrinks and sfx_net_flash. Each is polled once a frame and returns at once while its counter reads 0. A raise of that counter arms it, and one step past the last clears it.
Every armed call bumps the counter, derives that step's pitch period and emits a short burst here. Five of the seven take the period from a table indexed by the counter, bumped before the index is taken. Those tables therefore never have their first two bytes read.
sound_blip B9B4 LD A,$10 Speaker high level
The mute is this routine's first byte. The SOUND FX handler also has a path that would disable the two speaker writes, but that branch never runs.
sound_lvl_hi B9B6 OUT ($FE),A Drive the speaker high.
Each half-cycle holds the speaker in one state for as long as the pitch period sets. A period of 0 counts as 256.
B9B8 LD B,D Load the delay count from the pitch period in D.
sound_hi_delay B9B9 DJNZ sound_hi_delay Hold the high level for D loop iterations.
B9BB XOR A Speaker low level
sound_lvl_lo B9BC OUT ($FE),A Drive the speaker low.
B9BE LD B,D Reload the delay count from D.
sound_lo_delay B9BF DJNZ sound_lo_delay Hold the low level for D iterations, then return.
B9C1 RET
← B991 Sound effect: safety net flash Map B9C2 → Effect step counters
Fork me on GitHub