Skip to navigation

Revs on the BBC Micro

Screen buffer: DrawTrackView (Part 2 of 4)

Name: DrawTrackView (Part 2 of 4) [Show more] Type: Subroutine Category: Screen buffer Summary: Draw the part of the track view that fits around the dashboard Deep dive: Drawing around the dashboard Drawing the track view
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file

This routine modifes the DrawTrackBytes routine so that it draws all the remaining lines in the track view so they fit around the shape of the dashboard.
.view1 \ We get here with X = 44, as in part 1 we drew the \ lines specified by dash data offsets 79 to 44 \ \ In the following loop, we draw the lines specified by \ dash data offsets 43 to 28 LDA #&60 \ Set A to the opcode for the RTS instruction STA byte3 \ Modify the following instruction in DrawTrackBytes \ (part 3): \ \ CPX #44 -> RTS \ \ so that calls to DrawTrackLine and DrawTrackBytes from \ now on will draw individual lines rather than looping \ back to DrawTrackLine as they did for the lines above \ the dashboard .view2 DEX \ Decrement the dash data block pointer to point to \ the data for the next line LDY staDrawByte,X \ Set Y to the X-th entry in staDrawByte, which contains \ the low byte of the address of the STA (P),Y \ instruction in the DRAW_BYTE macro given in the \ table CPY view3+1 \ If the instruction at view3 has already been modified BEQ view5 \ to this address, jump to view5 to skip the following \ modifications, as they have already been done on the \ previous iteration of the loop LDA #&91 \ Set A to the opcode for the STA (P),Y instruction .view3 STA DrawTrackBytes+15 \ Modify the specified instruction back to STA (P),Y \ (the address of the modified instruction is set by the \ following, so the first time we run this line it has \ no effect) STY view4+1 \ Modify the instruction at view4 to change the low byte \ of the address to the X-th entry in staDrawByte, so \ the instruction at view4 changes the STA (P),Y \ instruction to an RTS in the DRAW_BYTE macro given \ in staDrawByte STY view3+1 \ Modify the instruction at view3 to change the low byte \ of the address to the X-th entry in staDrawByte, so \ the instruction at view3 changes the RTS instruction \ back to STA (P),Y when we loop back around LDA #&60 \ Set A to the opcode for the RTS instruction .view4 STA DrawTrackBytes \ Modify the specified instruction to an RTS so the next \ call to DrawTrackLine will return at that point (the \ address of the modified instruction is set above) LDY ldaDrawByte,X \ Set Y to the X-th entry in ldaDrawByte, which contains \ the low byte of the LDA #0 instruction in the specific \ DRAW_BYTE macro, as given in the table STY view6+1 \ Modify the instruction at view6 to change the low byte \ of the address to the X-th entry in ldaDrawByte, so \ the instruction at view6 changes so it jumps to the \ LDA #0 instruction in the DRAW_BYTE macro specified in \ the table .view5 JSR DrawTrackLine \ Draw the left portion of this track line \ \ This routine was modified above to return from the \ subroutine at the STA instruction in the DRAW_BYTE \ macro specified in the staDrawByte table, so this \ returns the last pixel byte of this portion of the \ line in A, i.e. the rightmost byte of the left portion \ of the track line, where the line meets the left \ border of the central part of the dashboard AND leftDashMask,X \ We now merge the track byte in A with the left edge ORA leftDashPixels,X \ of the dashboard, by masking out the pixels in A that STA (P),Y \ are hidden by the dashboard (with AND leftDashMask), \ and replacing them with the pixels from the left edge \ of the dashboard (with ORA leftDashPixels) LDA dashRightEdge,X \ Fetch the track pixel byte that would be shown along \ the right edge of the dashboard, i.e. the leftmost \ byte of the right portion of the track line, where the \ line meets the right border of the central part of the \ dashboard AND rightDashMask,X \ We now merge the track byte in A with the right edge ORA rightDashPixels,X \ of the dashboard, by masking out the pixels in A that \ are hidden by the dashboard (with AND rightDashMask), \ and replacing them with the pixels from the left edge \ of the dashboard (with ORA rightDashPixels) TAY \ Copy the pixel byte into Y, because the following JSR \ jumps straight to the LDA #0 instruction within the \ DRAW_BYTE macro, and at that point the macro expects \ the pixel byte to be in Y rather than A .view6 JSR byte2 \ Draw the right portion of this track line \ \ This JSR was modified above to jump to the LDA #0 \ instruction in the DRAW_BYTE macro specified in the \ ldaDrawByte table CPX #28 \ Loop back to keep drawing lines, working our way down BNE view2 \ through the dash data from entry 44 down to entry 28 JMP view7 \ Jump to part 3 to draw the rest of the track view from \ offsets 27 to 3, modifying the code so it draws the \ rest of the lines around the shape of the dashboard \ and the shape of the tyres