Skip to navigation

Aviator on the BBC Micro

Setup: DrawCanopy

Name: DrawCanopy [Show more] Type: Subroutine Category: Setup Summary: Move code around, clear the edges of the canopy view, draw the canopy edges and rivets, and jump to the main code
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * SetupScreen calls DrawCanopy
.DrawCanopy LDA #140 \ Call OSBYTE with A = 140 to select the tape filing JSR OSBYTE \ system (i.e. do a *TAPE command) LDY #0 \ We now copy the following block in memory: \ \ * &0400-&07FF is copied to &0D00-&10FF \ \ so we set up a byte counter in Y \ \ Note that this is the same block that was copied from \ &5800-&5BFF by the Entry routine, so in all we end up \ moving code as follows: \ \ * &5800-&5BFF is copied to &0400-&07FF \ then to &0D00-&10FF \ * &5C00-&5DFF is copied to &0B00-&0CFF \ \ As the rest of the main code file runs from &1100 to \ &57FF, this gives us a continuous block of code from \ &0B00 to &57FF, followed by screen memory at &5800 to \ &7FFF .dcan1 LDA &0400,Y \ Copy the Y-th byte of &0400 to the Y-th byte of &0D00 STA &0D00,Y LDA &0500,Y \ Copy the Y-th byte of &0500 to the Y-th byte of &0E00 STA &0E00,Y LDA &0600,Y \ Copy the Y-th byte of &0600 to the Y-th byte of &0F00 STA &0F00,Y LDA &0700,Y \ Copy the Y-th byte of &0700 to the Y-th byte of &1000 STA &1000,Y DEY \ Decrement the loop counter BNE dcan1 \ Loop back until we have copied a whole page of bytes NOP \ Presumably this contained some kind of copy protection NOP \ or decryption code that has been replaced by NOPs in NOP \ this unprotected version of the game NOP \ The following two calls to ClearRows clear the first \ two character rows on-screen LDA #&58 \ Set (Q P) = &5800, so the call to ClearRows starts STA Q \ clearing from the start of the first character row LDA #0 \ (i.e. row 0) STA P LDA #2 \ Set R = 2, so we clear 2 character rows STA R LDY #0 \ Set Y = 0, so we clear 256 bytes per row, or 32 of the \ 40 character blocks in each screen row (128 pixels) JSR ClearRows \ Call ClearRows to clear the first 256 bytes of the \ first two character rows on-screen, which blanks out \ the first 32 character blocks (blocks 0 to 31) of the \ top two character rows (rows 0 and 1) LDA #&58 \ Set (Q P) = &58FF, so the call to ClearRows starts STA Q \ clearingfrom character block 32 in the first character LDA #&FF \ row on-screen STA P LDA #2 \ Set R = 2, so we clear 2 character rows STA R LDY #64 \ Set Y = 64, so we clear 64 bytes per row, or 8 of the \ 40 character blocks in each screen row (32 pixels) JSR ClearRows \ Call ClearRows to clear the last 64 bytes of the first \ two character rows on-screen, which blanks out the \ last 8 character blocks (blocks 32 to 39) of the top \ two character rows (rows 0 and 1) \ The following two calls to ClearRows clear a \ 4-pixel-wide column on the left and right edges of the \ screen LDA #&5A \ Set (Q P) = &5A7F, so the call to ClearRows starts STA Q \ clearing from the start of the third character row LDA #&7F \ (i.e. row 2) STA P LDA #18 \ Set R = 18, so we clear 18 character rows STA R LDY #8 \ Set Y = 8, so we clear 8 bytes per row, or 1 of the \ 40 character blocks in each screen row (4 pixels) JSR ClearRows \ Call ClearRows to clear the first byte of character \ rows 2 to 20, which blanks out the first character \ block (block 0) on all 18 rows, i.e. the first four \ pixels LDA #&5B \ Set (Q P) = &5BB7, so the call to ClearRows starts STA Q \ clearing from the start of the last character block LDA #&B7 \ on the third character row (i.e. row 2) STA P LDA #18 \ Set R = 18, so we clear 18 character rows STA R LDY #8 \ Set Y = 8, so we clear 8 bytes per row, or 1 of the \ 40 character blocks in each screen row (4 pixels) JSR ClearRows \ Call ClearRows to clear the last byte of character \ rows 2 to 20, which blanks out the last character \ block (block 39) on all 18 rows, i.e. the last four \ pixels \ We now draw the edges of the canopy view, starting \ with the left edge, then the right edge, and then the \ horizontal line along the top (so this does not \ include the bottom edge, which has already been \ displayed as part of the dashboard image, and it also \ doesn't include the diagonal top corners, which are \ drawn by the main game code) LDX #3 \ Move the graphics cursor to (3, 96) LDY #96 JSR VduMove LDX #3 \ Draw a line to (3, 239) LDY #239 JSR VduDraw LDX #156 \ Move the graphics cursor to (156, 96) LDY #96 JSR VduMove LDX #156 \ Draw a line to (156, 239) LDY #239 JSR VduDraw LDX #8 \ Move the graphics cursor to (8, 248) LDY #248 JSR VduMove LDX #151 \ Draw a line to (151, 248) LDY #248 JSR VduDraw \ We now draw the square rivets around the edge of the \ canopy view, starting with the three rivets up each \ side of the screen LDY #121 \ Set Y = 121 so the first rivets are drawn at height \ 121, i.e. at (0, 121) and (158, 121) .dcan2 LDX #0 \ Draw a square rivet at (0, Y) JSR DrawRivet LDX #158 \ Draw a square rivet at (158, Y) JSR DrawRivet TYA \ Set Y = Y + 48 CLC \ ADC #48 \ so the next rivet we draw will be 48 pixels higher TAY CPY #9 \ Loop back to draw the next rivet until Y = 9, at which BNE dcan2 \ point Y has wrapped round off the top of the screen \ back to the bottom and we will have drawn three rivets \ up each side of the canopy view \ Finally, we draw the six square rivets along the top \ of the canopy view LDY #255 \ Set X and Y so the first rivet is at (19, 255) LDX #19 .dcan3 JSR DrawRivet \ Draw a square rivet at (X, Y) TXA \ Set X = X + 24 CLC \ ADC #24 \ so the next rivet we draw will be 24 pixels to the TAX \ right CPX #163 \ Loop back to draw the next rivet until X = 163, at BNE dcan3 \ which point we will have drawn six rivets along the \ top of the canopy view JMP StartGame \ Jump to StartGame to start the game