Skip to navigation

Aviator on the BBC Micro

Dashboard: ShowUpsideDownBar

Name: ShowUpsideDownBar [Show more] Type: Subroutine Category: Dashboard Summary: Show or hide the upside down bar in the artificial horizon indicator
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyFlightModel (Part 6 of 7) calls ShowUpsideDownBar

This routine shows the upside down bar in the artificial horizon if bit 6 and bit 7 of zRotationHi are different. This is how it works. The value of zRotationHi contains the following: * 0 to 63 (bit 6 clear, bit 7 clear) * 64 to 127 (bit 6 set, bit 7 clear) * 128 to 191 (bit 6 clear, bit 7 set) * 192 to 255 (bit 6 set, bit 7 set) The zRotation angle determines how the plane is rotated around the z-axis. The z-axis points into the screen, so rotating the plane around this axis is the same as rolling the plane. A zRotation of 0 is a horizontal plane, and as the angle increases, the plane rolls to the right. If we consider the plane doing a full 360-degree roll, then for the first quarter the plane is still upright, for the second and third quarters it is upside down, and then for the final quarter it is upright again. You will notice that bits 6 and 7 differ in the second and third quarters in the list above, so if bits 6 and 7 of zRotationHi are different, then the plane is upside down, and we should show a bar at the bottom of the artificial horizon indicator.
.ShowUpsideDownBar LDA zRotationHi \ If bit 7 of zRotationHi is clear, skip the following BPL upsi1 \ instruction EOR #%11000000 \ Flip bits 6 and 7 of A, making bit 7 clear and bit 6 \ flipped .upsi1 \ When we get here, we know bit 7 of A is clear AND #%11000000 \ Extract bits 6 and 7 of A BEQ upsi2 \ If bit 6 of A is clear (we already know bit 7 is \ clear), then the plane is the correct way up, so skip \ the following instruction \ We get here if one of the following is true: \ \ * Bit 7 of zRotationHi is clear and bit 6 is set \ * Bit 7 of zRotationHi is set and bit 6 is clear \ \ either of which means the plane is upside down LDA #%00001110 \ Bit 6 is set, so set A to a three-pixel horizontal \ line to show in the indicator .upsi2 STA row25_block13_1 \ Set the line at the bottom of the artificial horizon \ indicator to the pixel pattern in A (0 if the plane is \ the right way up, %00001110 if it is upside down) RTS \ Return from the subroutine