Skip to navigation

Revs on the BBC Micro

Dashboard: UpdateDashboard

Name: UpdateDashboard [Show more] Type: Subroutine Category: Dashboard Summary: Update the rev counter and steering wheel lines on the dashboard
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainDrivingLoop (Part 5 of 5) calls UpdateDashboard
.UpdateDashboard JSR EraseRevCounter \ Erase the dial hand on the rev counter and the line on \ the steering wheel JSR DrawRevCounter \ Redraw the dial hand on the rev counter \ We now draw the line on the steering wheel LDA steeringLo \ Set T = steeringLo STA T LSR A \ Set the C flag to bit 0 of steeringLo (the sign bit) \ which is set if we are steering left, or clear if we \ are steering right PHP \ Store the C flag on the stack LDA #2 \ Set A = 2, to use as the value of V to send to the \ DrawDashboardLine routine (shallow slope, right and \ down) BCS upda1 \ If bit 0 of steeringLo is set, skip the following \ instruction LDA #5 \ Bit 0 of steeringLo is clear, so set A = 5 to use \ as the value of V to send to the DrawDashboardLine \ routine (shallow slope, left and down) .upda1 STA V \ Set V = A, which we will pass to the DrawDashboardLine \ routine LDA steeringHi \ Set A = steeringHi, so (A T) = (steeringHi steeringLo) ASL T \ Set (A T) = (A T) << 1 ROL A \ \ setting the C flag to the top bit of (A T) BCS upda2 \ If the C flag is set, skip the following four \ instructions to set A = 60, as the wheel is turned so \ much that the indicator would be off the bottom of the \ screen CMP #38 \ If A < 38, jump to upda4 BCC upda4 CMP #61 \ If A < 61, i.e. 38 <= A <= 60, jump to upda3 to BCC upda3 \ skip the following instruction .upda2 LDA #60 \ Set A = 60, the maximum value of A, so when we fall \ through into the next calculation, with the C flag \ set, we set: \ \ Y = ~A + 76 + C \ = ~A + 76 + 1 \ = ~A + 1 + 76 \ = -A + 76 \ = -60 + 76 \ = 16 .upda3 \ If we get here then the indicator is a long way away \ from the centre of the wheel, as A >= 38 EOR #&FF \ Set Y = ~A + 76 + C ADC #76 \ = ~A + 1 + 75 + C TAY \ = 75 - A when 38 <= A <= 60 \ 16 when A > 60 \ \ so Y is in the range 37 to 16, with higher values of A \ giving lower values of A \ \ This represents the distance between this value on the \ steering wheel and the nearest quadrant STY T \ Set T = Y (in the range 37 to 16) to pass to the \ DrawDashboardLine routine as the amount of slope error \ for each step slong the main axis LDX wheelPixels,Y \ Set X to the number of pixels that would be along the \ long axis of the line if the line went all the way to \ the centre of the wheel, given the value of Y above STX SS \ Set SS = X to pass to the DrawDashboardLine routine \ as the cumulative amount of slope error that equates \ to a pixel in the shorter axis JMP upda5 \ Jump to upda5 .upda4 \ If we get here then the indicator is not far away from \ the centre of the wheel, as A < 38 TAX \ Set X = A (in the range 0 to 37) \ \ This represents the distance between this value on the \ steering wheel and the nearest quadrant STX T \ Set T = X (in the range 0 to 37) to pass to the \ DrawDashboardLine routine as the amount of slope error \ for each step slong the main axis LDA V \ Flip bit 0 of V, to flip it from the first half of the EOR #1 \ quadrant to the second half STA V \ By this point, V has the following value, which we \ pass to the DrawDashboardLine routine \ \ * 2 when sign bit of steeringLo is set and A >= 38 \ i.e. steering left a lot \ Shallow slope, right and down \ \ * 3 when sign bit of steeringLo is set and A < 38 \ i.e. steering left a little \ Steep slope, right and down \ \ * 4 when sign bit of steeringLo is clear and A < 38 \ i.e. steering right a little \ Steep slope, left and down \ \ * 5 when sign bit of steeringLo is clear and A >= 38 \ i.e. steering right a lot \ Shallow slope, left and down \ \ These are the opposite way round to the rev counter \ hand, which is also drawn by the DrawDashboardLine \ routine - this is because the rev counter hand is \ drawn from the centre outwards, while the steering \ wheel line is drawn from the outside in LDA wheelPixels,X \ Set A to the number of pixels that would be along the \ long axis of the line if the line went all the way to \ the centre of the wheel, given the value of X above STA SS \ Set SS = A to pass to the DrawDashboardLine routine \ as the cumulative amount of slope error that equates \ to a pixel in the shorter axis .upda5 ASL A \ Set A = A * 2 + 4 CLC ADC #4 EOR #&FF \ Set Y = ~A TAY TXA \ Set A = X \ \ where X is either the original value of A (0 to 37) \ or the Y-th value of wheelPixels (where Y is 16 to \ 37), which is in the range 38 to 51 \ \ In effect, this is the horizontal distance of the \ steering line from the centre point PLP \ Set the C flag to bit 0 of steeringLo (the sign bit), \ which we stored on the stack above BCC upda6 \ If bit 0 of steeringLo is clear, we are steering to \ the right, so skip the following instruction EOR #&FF \ Set A = ~A \ = -A - 1 \ \ so the following addition becomes: \ \ A = A + 80 \ = -A - 1 + 80 \ = 79 - A .upda6 CLC \ Set A = A + 80 ADC #80 \ \ which turns A into the position on the steering wheel \ where 80 is the centre point at the top middle of the \ wheel STA W \ Set W = A, so W contains the position on the steering \ wheel AND #%11111100 \ Clear bits 0 and 1 of A, to set A = A div 4 JSR GetScreenAddress \ Set (Q P) to the screen address for pixel coordinate \ (A, Y), setting Y to the pixel row within the \ character block containing the pixel (both of which we \ pass to the DrawDashboardLine routine) LDA W \ Set W = W * 2 mod 8 ASL A \ AND #%00000111 \ This takes the x-coordinate of the line on the STA W \ steering wheel, doubled so we have 160 in the centre \ of the steering wheel (so it matches the coordinates \ in mode 5), and then we look at bits 0 to 2 only to \ get the starting pixel to pass to DrawDashboardLine LDA #%100 \ Set H = %100, so the DrawDashboardLine looks up values STA H \ from the second half of the pixelByte and yLookupLo+8 \ tables (so the line is drawn on black rather than \ white) LDA #6 \ Set U = 6, so the line contains up to seven pixels STA U JSR DrawDashboardLine \ Draw the dashboard line RTS \ Return from the subroutine