Skip to navigation


Sound: FlushSoundBuffer

Name: FlushSoundBuffer [Show more] Type: Subroutine Category: Sound Summary: Flush the specified sound buffer Deep dive: The engine sounds
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyTyresAndSkids calls FlushSoundBuffer * FlushSoundBuffers calls FlushSoundBuffer * MakeDrivingSounds calls FlushSoundBuffer

This routine flushes the specified sound channel buffer, but only if that channel's soundBuffer value is non-zero.
Arguments: X The number of the sound channel buffer to flush (0 to 3)
Returns: X X is unchanged A A is unchanged
.FlushSoundBuffer PHA \ Store the value of A on the stack so we can retrieve \ it before returning from the routine LDA soundBuffer,X \ If this buffer's soundBuffer value is zero, then there BEQ flus1 \ is nothing to flush, so jump to flus1 to return from \ the subroutine LDA #0 \ Set this buffer's soundBuffer value for this buffer to STA soundBuffer,X \ 0 to indicate that it has been flushed TXA \ Set bit 2 of X ORA #%00000100 \ TAX \ This changes X from the original range of 0 to 3, into \ the range 4 to 7, so it now matches the relevant sound \ buffer number (as buffers 4 to 7 are the buffers for \ sound channels 0 to 3) LDA #21 \ Call OSBYTE with A = 21 to flush buffer X, which JSR OSBYTE \ flushes the relevant sound channel buffer TXA \ Clear bit 2 of X, to reverse the X OR 4 above AND #%11111011 TAX .flus1 PLA \ Retrieve the value of A that we stored on the stack \ above, so it remains unchanged by the routine RTS \ Return from the subroutine