.ProcessVolumeKeys LDA focusOnKeyAction \ If bit 7 of focusOnKeyAction is set then the game is BMI volk6 \ focusing effort on a key action such as a landscape \ pan, so jump to volk6 to return from the subroutine \ without checking for volume-related key presses LDA volumeLevel \ Set A to the current volume level LDX keyLogger+3 \ Set X to the key logger entry for "7", "8", COPY and \ DELETE (volume down, volume up, pause, unpause) BEQ volk1 \ If X = 0 then "7" (volume down) has been pressed, so \ jump to volk1 to process it \ If we get here then X must be 1, 2 or 3 (for "8", \ COPY and DELETE) DEX \ If X - 1 <> 0 then the original key logger entry must BNE volk6 \ be 2 or 3 (COPY or DELETE), so jump to volk6 to \ return from the subroutine \ If we get here then the key logger entry must be 1, \ so "8" (volume up) has been pressed CMP #120 \ If A >= 120 then the volume level is already at the BCS volk2 \ maximum level of 120, so jump to volk2 without \ changing it ADC #8 \ Otherwise we can turn the volume up, so add 8 to the \ volume level in A (the addition works because we know \ we just passed through a BCS, so we know the C flag is \ clear) BNE volk2 \ Jump to volk1 to update the volume level .volk1 \ If we get here then "7" (volume down) has been pressed CMP #0 \ If A = 0 then the volume level is already at the BEQ volk2 \ minimum level of 0, so jump to volk2 without changing \ it SBC #8 \ Otherwise we can turn the volume down, so subtract 8 \ from the volume level in A (the subtraction works \ because we know that A > 0, so the CMP above will have \ set the C) .volk2 LDX soundCounter \ If soundCounter >= 2 then a sound is currently being CPX #2 \ made (such as the confirmation ping we make when BCS ProcessVolumeKeys \ changing the volume level) and it hasn't finished yet, \ so loop back to the start of the routine to keep \ checking for key presses and without changing the \ volume, as we only want to change the volume when we \ can make a pinging sound so the player can hear the \ effect of the volume change STA volumeLevel \ Update the volume level in volumeLevel to the new \ value TAY \ Set Y to 0 (if the volume has been turned right down) BEQ volk3 \ or to 8 (if the volume level is non-zero) LDY #8 .volk3 STY envelopeData+42+13 \ Set parameter #13 of envelope 3 to Y, to set the ALD \ for the sound (the amplitude target level at the end \ of the decay phase) STY envelopeData+28+13 \ Set parameter #13 of envelope 2 to Y, to set the ALD \ for the sound (the amplitude target level at the end \ of the decay phase) LDY #11 \ We now work through the envelopeVolumes table, which \ contains offsets into the envelopeData table of the \ bytes that control the volume of each envelope \ \ We update each of the bytes to reflect the new volume \ level, so set a counter in Y to work through all 12 \ bytes of envelope data .volk4 LDX envelopeVolumes,Y \ Fetch the Y-th entry of the envelopeVolumes table into \ X, so it contains the offset within the envelopeData \ table that we need to update CPX #79 \ If this is not the entry at the beginning of the table BNE volk5 \ (which will be the last to be processed), jump to \ volk5 to set the envelope byte to the new volume level EOR #%11111111 \ If this is the entry at the beginning of the table, ADC #0 \ negate the volume level in A, as this entry is for the \ AD parameter (the change of amplitude per step during \ the decay phase), and we want this aspect to drop more \ quickly at higher volume levels .volk5 STA envelopeData,X \ Set the X-th byte of the envelope data to the volume \ level in A DEY \ Decrement the envelope byte counter BPL volk4 \ Loop back until we have updated all 12 bytes with the \ new volume level LDA #12 \ Set soundCounter = 12 to count down while the ping STA soundCounter \ sound is made LDA #5 \ Make sound #5 (ping) so the player can hear the new JSR MakeSound \ volume level JMP ProcessVolumeKeys \ Loop back to the start of the routine to keep checking \ for key presses .volk6 RTS \ Return from the subroutineName: ProcessVolumeKeys [Show more] Type: Subroutine Category: Sound Summary: Adjust the volume of the sound envelopes when the volume keys are pressedContext: See this subroutine in context in the source code References: This subroutine is called as follows: * ProcessGameplay calls ProcessVolumeKeys
[X]
Subroutine MakeSound (category: Sound)
Make a sound
[X]
Subroutine ProcessVolumeKeys (category: Sound)
Adjust the volume of the sound envelopes when the volume keys are pressed
[X]
Variable envelopeData (category: Sound)
Data for the six sound envelopes
[X]
Variable envelopeVolumes (category: Sound)
A table of offsets into the envelope data for bytes that control the volume of each envelope, so we can change their volume levels
[X]
Variable focusOnKeyAction in workspace Main variable workspace
A flag that determines whether the game should focus effort on implementing a key action, such as a pan of the landscape view
[X]
Variable keyLogger in workspace Main variable workspace
The four-byte key logger for logging game key presses
[X]
Variable soundCounter in workspace Main variable workspace
A counter for the sound currently being made, which counts down in the IRQHandler routine at a rate of 50 times a second
[X]
Label volk1 is local to this routine
[X]
Label volk2 is local to this routine
[X]
Label volk3 is local to this routine
[X]
Label volk4 is local to this routine
[X]
Label volk5 is local to this routine
[X]
Label volk6 is local to this routine
[X]
Variable volumeLevel (category: Sound)
The volume level, which can be changed by pressing "7" and "8"