Skip to navigation


Keyboard: ProcessShiftedKeys

Name: ProcessShiftedKeys [Show more] Type: Subroutine Category: Keyboard Summary: Check for shifted keys (i.e. those that need SHIFT holding down to trigger) and process them accordingly
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * FinishRace calls ProcessShiftedKeys * MainDrivingLoop (Part 5 of 5) calls ProcessShiftedKeys

Arguments: Y Scan for the first Y + 1 keys from shiftedKeys
.ProcessShiftedKeys STY T \ Set T to the number of keys to scan LDX #&FF \ Scan the keyboard to see if SHIFT is being pressed JSR ScanKeyboard BNE shif10 \ If SHIFT is not being pressed, jump to shif10 to \ return from the subroutine LDY T \ Set Y to the number of keys to scan, to use as a loop \ counter as we work our way backwards through the \ shiftedKeys table, from entry Y to entry 0 .shif1 STY T \ Set T to the loop counter LDX shiftedKeys,Y \ Fetch the next key number from the shiftedKeys table JSR ScanKeyboard \ Scan the keyboard to see if this key is being pressed BEQ shif2 \ If this key is being pressed, jump to shif2 to update \ the relevant configuration setting LDY T \ Otherwise set Y to the value of the loop counter DEY \ Decrement the loop counter to point to the next key in \ the table (working backwards) BPL shif1 \ Loop back to check the next key in the table until we \ have checked them all BMI shif3 \ None of the keys are being pressed, so jump to shif3 \ to skip updating the configuration bytes (this BMI is \ effectively a JMP as we just passed through a BPL) .shif2 \ If we get here then the Y-th key is being pressed, \ along with SHIFT, so we now update the relevant \ configuration byte, according to the settings in the \ configKeys table LDY T \ Otherwise set Y to the value of the loop counter, \ which gives us the offset of key that is being pressed \ within the shiftedKeys table LDA configKeys,Y \ Set X to the low nibble for this key's corresponding AND #&0F \ entry in the configKeys, which contains the offset of TAX \ the configuration byte from the first configuration \ byte at configStop LDA configKeys,Y \ Set A to the high nibble for this key's corresponding AND #&F0 \ entry in the configKeys, which contains the value that \ we need for the corresponding configuration byte STA configStop,X \ Set the corresponding configuration byte to the value \ in A .shif3 LDA configPause \ If configPause = 0, then neither COPY nor DELETE are BEQ shif6 \ being, so jump to shif6 \ If we get here then one of the pause buttons is being \ pressed BPL shif5 \ If bit 7 of configPause is clear, then this means bit \ 6 must be set, which only happens when the unpause key \ (DELETE) is being pressed, so jump to shif5 to unpause \ the game \ Otherwise we need to pause the game JSR FlushSoundBuffers \ Flush all four sound channel buffers to stop the sound \ while we are paused .shif4 JSR ResetTrackLines \ Reset the blocks at leftVergeStart, leftTrackStart, \ rightVergeStart, rightGrassStart and backgroundColour LDX #&A6 \ Scan the keyboard to see if DELETE is being pressed JSR ScanKeyboard BNE shif4 \ If DELETE is not being pressed, loop back to shif4 to \ remain paused, otherwise keep going to unpause the \ game .shif5 INC soundRevCount \ Increment soundRevCount to make the engine sound jump \ a little LDA #0 \ Set configPause = 0 to clear the pause/unpause key STA configPause \ press .shif6 LDY volumeLevel \ Set Y to the volume level, which uses the operating \ system's volume scale, with -15 being full volume and \ 0 being silent LDA mainLoopCounterLo \ If bit 0 of mainLoopCounterLo is set, which it will be AND #1 \ every other iteration round the main loop, jump to BNE shif9 \ shif9 to skip the following, so the sound changes more \ slowly than it would if we did this every loop LDA configVolume \ If configVolume = 0, jump to shif10 to return from the BEQ shif10 \ subroutine BPL shif7 \ If bit 7 of configVolume is clear, then this means bit \ 6 must be set, which only happens when the volume up \ (f5) key is being pressed, so jump to shif7 \ If we get here then we need to turn the volume down INY \ Increment Y to decrease the volume BEQ shif8 \ If Y is 0 or negative, then it is still a valid volume BMI shif8 \ level, so jump to shif8 to update the volume setting BPL shif9 \ Otherwise we have already turned the volume down as \ far as it will go, so jump to shif9 to clear the key \ press and return from the subroutine (this BPL is \ effectively a JMP as we just passed through a BMI) .shif7 \ If we get here then we need to turn the volume up DEY \ Decrement Y to increase the volume CPY #241 \ If Y < -15, then we have already turned the volume up BCC shif9 \ as far as it will go, so jump to shif9 to clear the \ key press and return from the subroutine \ Otherwise fall through into shif8 to update the \ volume setting .shif8 STY volumeLevel \ Store the updated volume level in volumeLevel TYA \ Set A = -Y, negated using two's complement EOR #&FF CLC ADC #1 ASL A \ Set envelopeData+12 = A << 3 ASL A \ = -Y * 8 ASL A \ STA envelopeData+12 \ which is 0 for no volume, or 120 for full volume, so \ this sets the target level for the end of the attack \ phase to a higher figure for higher volume settings LDA #0 \ Set up the envelope for the engine sound, with the JSR DefineEnvelope \ volume changed accordingly INC soundRevCount \ Increment soundRevCount to make the engine sound jump \ a little .shif9 LDA #0 \ Set configVolume = 0 to clear the volume key press STA configVolume .shif10 RTS \ Return from the subroutine