Skip to navigation

Aviator on the BBC Micro

Graphics: DrawGunSights

Name: DrawGunSights [Show more] Type: Subroutine Category: Graphics Summary: Draw the canopy corners and the gun sights, if shown
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * DrawCanopyView calls DrawGunSights
.DrawGunSights JSR DrawCanopyCorners \ Draw the canopy corners LDX #&DA \ Scan the keyboard to see if "I" is being pressed JSR ScanKeyboard BNE guns1 \ If "I" is not being pressed, jump to guns1 BIT gunSights \ If bit 6 of gunSights is set, then "I" is still being BVS guns3 \ held down from a previous call to this routine, so \ jump to guns3 to move on from the subroutine LDA #%11000000 \ Set A = gunSights with bits 6 and 7 flipped, which we EOR gunSights \ will set as the new value of gunSights below BMI guns2 \ If the result has bit 7 set, that means that bit 7 of \ gunSights is currently clear, so jump to guns2 as the \ sights are not already being shown, so we don't need \ to remove them \ If we get here then bit 7 of gunSights is set, so the \ sights are already on-screen, and we aren't still \ holding down "I" from a previous call, so now we \ remove the sights PHA \ Store A on the stack so we can retrieve it below LDY #HI(row6_block1_0) \ Set (Y X) to the screen address for row 6, block 0 LDX #LO(row6_block1_0) LDA #3 \ Set R = 3, so we clear 3 character rows for the sights STA R LDA #0 \ Set X = 0 so we clear the sights to black JSR FillCanopyRows \ Fill the 3 screen rows with black, avoiding the canopy \ edges and removing the sights from the screen PLA \ Retrieve A from the stack JMP guns2 \ Jump down to guns2 to set gunSights to the value in A .guns1 \ If we get here then "I" is not being pressed LDA #%10000000 \ Extract bit 7 from gunSights into A, which clears bit AND gunSights \ 6 to indicate that "I" is not being pressed, while \ leaving the current state of bit 7 alone .guns2 STA gunSights \ Update gunSights to the new value in A .guns3 BPL ToggleJoystick \ If bit 7 of the new value of gunSights is clear, then \ the sights are no longer being shown, so jump down to \ ToggleJoystick to move on to the next routine \ If we get here, then bit 7 of gunSights is set, so we \ need to draw the sights LDY #7 \ First we draw the vertical bar in the middle of the \ sights, which runs through block 20 on rows 6 and 7, \ so we set a pixel row counter in Y to count through \ the rows in each character block .guns4 LDA #%10001000 \ Draw a vertical bar in the first pixel of the Y-th ORA row6_block20_0,Y \ pixel row in block 20 on row 6, keeping whatever is STA row6_block20_0,Y \ already on screen LDA #%10001000 \ Draw a vertical bar in the first pixel of the Y-th ORA row7_block20_0,Y \ pixel row in block 20 on row 7, keeping whatever is STA row7_block20_0,Y \ already on screen DEY \ Decrement the pixel row counter BPL guns4 \ Loop back to draw the next pixel row until we have \ drawn a vertical line through both character blocks \ Now to draw the horizontal bar of the gun sights LDA #%01110111 \ First we draw the left end of the horizontal bar, ORA row8_block11_0 \ which is starts with the three rightmost pixels in STA row8_block11_0 \ block 11 on row 8 SEC \ Set the C flag for the subtraction below LDY #136 \ The rest of the line is made up of 17 character blocks \ with four pixels in each block, so we set a counter in \ Y to work as an offset from the left end of the line, \ counting 8 bytes per character block (17 * 8 = 136), \ working from the right end of the line to the left .guns5 LDA #%11111111 \ Draw a horizontal bar of four pixels starting at the STA row8_block11_0,Y \ Y-th offset from the start of block 11 on row 8 TYA \ Set Y = Y - 8, so Y now points to the four pixels to SBC #8 \ the left, as we work or way along the line TAY BNE guns5 \ Loop back to draw the next four pixels of the line \ until we have drawn the whole horizontal line \ Fall through into ToggleJoystick to check for the \ joystick key