Skip to navigation

Revs on the BBC Micro

Drawing the track: DrawSegmentEdge (Part 4 of 7)

Name: DrawSegmentEdge (Part 4 of 7) [Show more] Type: Subroutine Category: Drawing the track Summary: Set variables to use when updating the background colour Deep dive: Drawing the track verges
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file

This part sets variables for use when updating the background colour table, and clips the pitch angle in RR to fit into a track line.
LDA vergeType \ Set T = vergeType << 3 ASL A \ ASL A \ So T is as follows: ASL A \ STA T \ * %00000000 if we are drawing leftVergeStart (%00) \ \ * %00001000 if we are drawing leftTrackStart (%01) \ \ * %00010000 if we are drawing rightVergeStart (%10) \ \ * %00011000 if we are drawing rightGrassStart (%11) LDA objectPalette \ Set A to the first verge pixel mask that we stored in \ part 3, which is always a four-pixel, single colour \ pixel byte of the form %aaaabbbb, where the pixel \ colour is %ab LSR A \ Set A = A >> 3 AND %11 LSR A \ = %aaaab AND %11 LSR A \ = %ab AND #%00000011 \ \ So A contains the colour of the pixels in the first \ verge pixel mask that we stored in part 3 ORA T \ Set A = A OR T \ = %ab OR %vv000 \ = %vv0ab \ \ where %vv is the verge we are currently drawing, from \ vergeType ORA #%01000000 \ Set backgroundRight = %010vv0ab STA backgroundRight \ \ So backgroundRight contains the following data: \ \ * %vv is the verge we are currently drawing, from \ vergeType \ \ * %ab is the colour in the first verge pixel mask \ for the verge \ \ * %010xx0xx denotes that this value (if used) gets \ stored in the backgroundColour table by the \ UpdateBackground routine \ \ We use backgroundRight in the UpdateBackground routine \ when updating the background colour for the track line LDA objectPalette \ Set A to the first verge pixel mask that we stored in \ part 3, which is always a four-pixel, single colour \ pixel byte BNE dver17 \ If A is non-zero, then the colour is not black, so \ jump to dver17 LDA #&55 \ A is zero, which is a four-pixel byte in black, so STA objectPalette \ store &55 in objectPalette, as &55 in the screen \ buffer represents black .dver17 STA JJ \ Store A in JJ, so it can be used as the right pixel \ byte when drawing the edge in the screen buffer, i.e. \ the fill byte to the right of the edge LDA objectPalette+3 \ Set A to the fourth verge pixel mask that we stored in \ part 3, which is in the form %aaaxbbbx, where %a is \ the first bit of the left colour in the mask, and %b \ is the second bit \ \ This works because the fourth entry in each block in \ vergePixelMask has pixels 0 to 2 set to the left \ colour within the four-pixel block, and only pixel 3 \ set to the other colour, and the following batch of \ bit-shuffling extracts the colour of pixel 2 LSR A \ Set bit 0 of A to bit 1 of the pixel mask AND #%00000001 BIT objectPalette+3 \ If bit 7 of the pixel mask is clear, jump to dver18 to BPL dver18 \ skip the following instruction ORA #%00000010 \ Set bit 1 of A, so bit 1 of A is the same as bit 7 of \ the fourth pixel mask \ \ In other words, A = %000000ab .dver18 ORA #%10000000 \ Set A = %100000ab ORA T \ Set A = A OR T \ = %100000ab OR %vv000 \ = %100vv0ab \ \ where %vv is the verge we are currently drawing, from \ vergeType STA backgroundLeft \ Set backgroundLeft = %100vv0ab \ \ So backgroundLeft contains the following data: \ \ * %vv is the verge we are currently drawing, from \ vergeType \ \ * %ab is the colour of the first three pixels in the \ verge pixel mask for the verge in objectPalette+3 \ \ * %010xx0xx denotes that this value (if used) gets \ stored in the backgroundColour table by the \ UpdateBackground routine \ \ We use backgroundLeft in the UpdateBackground routine \ when updating the background colour for the track \ line, and in part 6 where we extract the colour bits \ in %ab LDA thisPitchIndex \ If thisPitchIndex + 1 = vergeBufferEnd, then this is CLC \ the last entry in the verge buffer, so jump to dver19 ADC #1 \ to skip the following CMP vergeBufferEnd BEQ dver19 \ We now clip the pitch angle in RR so it fits into the \ track line range of 0 to 79 LDA RR \ If RR < 80, then this is a valid track line number, so CMP #80 \ jump to dver20 to leave it alone BCC dver20 .dver19 \ If we get here then RR is outside the correct range \ for track lines of 0 to 79, so we need to clip it to \ 0 or 79, depending on which way the line is heading LDA #0 \ Set A = 0 to use as the new value of R if WW is \ negative BIT WW \ If WW is negative, then the line is heading down the BMI dver20 \ screen, so jump to dver20 to set RR = 0, which clips \ RR to the bottom of the track view LDA #79 \ WW is positive, so the line is heading up the \ screen, so set A = 79 to use as the new value of R, \ which clips RR to the top of the track view .dver20 STA RR \ Update RR to be within the range 0 to 79