.MoveSightsSideways LDX keyLogger \ Set X to the key logger entry for "S" and "D" (pan \ left, pan right), which are used to move the sights BMI sisd4 \ If there is no key press in the key logger entry, jump \ to sisd4 to return from the subroutine \ If we get here then "S" or "D" is being pressed, which \ will put 1 or 0 into the key logger respectively BNE sisd2 \ If X = 1 then "S" is being pressed, so jump to sisd2 \ to process moving the sights left \ If we get here then X = 0, so "D" is being pressed, \ which is the key for moving the sights right LDA xSights \ Increment xSights to move the sights right CLC ADC #1 CMP #144 \ If xSights < 144 then skip the following, as the BCC sisd1 \ sights have not moved off the right edge of the screen \ If we get here then the sights have just moved off the \ right edge of the screen, so we need to pan the screen \ by moving the sights back towards the centre of the \ screen and starting a pan right by "pressing" the \ relevant pan key SBC #64 \ Subtract 64 from A to move the sights to the left by \ 64, as we are about to pan the screen to the right \ (the subtraction works because we passed through a \ BCC so we know the C flag is set) STX panKeyBeingPressed \ Set panKeyBeingPressed to the key logger entry for "D" \ to pretend that the "D" key is being pressed to pan \ the screen as well as move the sights \ \ This will pan to the right by scrolling the screen to \ the left .sisd1 STA xSights \ Update the x-coordinate of the sights to the updated \ value in A AND #%00000011 \ If the x-coordinate is now a multiple of four then the BEQ SetSightsAddress \ sights just moved right into the next character block \ (as each block is four pixels wide), so jump to \ SetSightsAddress with X = 0 to update the screen \ variables for the sights JMP sisd4 \ Otherwise jump to sisd4 to return from the subroutine .sisd2 \ If we get here then X = 1, so "S" is being pressed, \ which is the key for moving the sights left LDA xSights \ Decrement xSights to move the sights left SEC SBC #1 CMP #16 \ If xSights >= 16 then skip the following, as the BCS sisd3 \ sights have not moved off the left edge of the screen \ If we get here then the sights have just moved off the \ left edge of the screen, so we need to pan the screen \ by moving the sights back towards the centre of the \ screen and starting a pan left by "pressing" the \ relevant pan key ADC #64 \ Add 64 to A to move the sights to the right by 64, as \ we are about to pan the screen to the left (the \ addition works because we passed through a BCS so we \ know the C flag is clear) STX panKeyBeingPressed \ Set panKeyBeingPressed to the key logger entry for "S" \ to pretend that the "S" key is being pressed to pan \ the screen as well as move the sights \ \ This will pan to the left by scrolling the screen to \ the right .sisd3 STA xSights \ Update the x-coordinate of the sights to the updated \ value in A AND #%00000011 \ If the x-coordinate is now one less than a multiple of CMP #%00000011 \ four then the sights just moved left into the previous BEQ SetSightsAddress \ character block (as each block is four pixels wide), \ so jump to SetSightsAddress to update the screen \ variables for the sights .sisd4 RTS \ Return from the subroutineName: MoveSightsSideways [Show more] Type: Subroutine Category: Sights Summary: Check for the left/right keys and move the sights accordingly, panning to the left or right if they go past the screen edgesContext: See this subroutine in context in the source code References: This subroutine is called as follows: * MoveSights calls MoveSightsSideways
[X]
Subroutine SetSightsAddress (category: Sights)
Update the address variables for the sights when they move into a new character block or row
[X]
Variable keyLogger in workspace Main variable workspace
The four-byte key logger for logging game key presses
[X]
Variable panKeyBeingPressed in workspace Zero page
The direction in which the player is currently panning
[X]
Label sisd1 is local to this routine
[X]
Label sisd2 is local to this routine
[X]
Label sisd3 is local to this routine
[X]
Label sisd4 is local to this routine
[X]
Variable xSights in workspace Main variable workspace
The pixel x-coordinate of the sights on-screen