Skip to navigation

Aviator on the BBC Micro

List of all subroutines

This index contains every subroutine and entry point that appears in the source code for Aviator, grouped by category. An entry points is a label within a subroutine that is called from outside the subroutine, which typically implements a subset or variation of the functionality of the parent subroutine.

3D geometry

AddPointToObjectAdd a point vector to an object's coordinates
AddTempToPoint (Part 1 of 2)Add the xTemp1 vector to a point, store the result in another point, and set the result to hidden if it overflows
AddTempToPoint (Part 2 of 2)Check whether the vector addition overflowed and set the point's visibility accordingly
NextObjectGroupCycle to the next object group
ProjectAxisAngleConvert the rotation angles of the plane into coordinates
ProjectPoint (Part 1 of 3)Project a point onto the screen (i.e. convert from 3D coordinates to screen coordinates)
ProjectPoint (Part 2 of 3)Calculate the screen coordinates of the projected point
ProjectPoint (Part 3 of 3)Move the projected coordinates to the centre of the screen and update the point's status byte
SetMatricesSet up matrices 1 to 4
SetMatrixEntryCalculate a matrix entry
SetMatrixEntry2Set mWrite = (S R) * mRead >> 16 and (J I) = mRead SetMatrixEntry3 Set mWrite = (J I) * -mRead >> 16 and (S R) = -mRead
SetMatrixEntry3Set mWrite = (J I) * -mRead >> 16 and (S R) = -mRead
SetObjectCoords (Part 1 of 11)Calculate the coordinates for an object's location
SetObjectCoords (Part 2 of 11)Pre-process the bullets (objects 12, 13, 14 or 15)
SetObjectCoords (Part 3 of 11)Logic for checking which objects to pre-process
SetObjectCoords (Part 4 of 11)Pre-process the object groups (objects 6, 7, 8 or 9)
SetObjectCoords (Part 5 of 11)Logic for checking which objects to pre-process
SetObjectCoords (Part 6 of 11)Pre-process dormant aliens (object group 30)
SetObjectCoords (Part 7 of 11)Pre-process feeding and flying aliens (objects 31, 32 and 33)
SetObjectCoords (Part 8 of 11)Process the object
SetObjectCoords (Part 9 of 11)Process the next object in the group, if applicable, or return from the subroutine if not
SetObjectCoords (Part 10 of 11)Process the next dormant alien (object group 30)
SetObjectCoords (Part 11 of 11)Update the object status and return from the subroutine
SetObjectToOriginSet an object's coordinates to (0, 0, 0)
SetObjPointCoords (Part 1 of 2)Calculate the coordinate for a point within an object
SetObjPointCoords (Part 2 of 2)Apply the correct scale factor to the matrix multiplication
SetPointSet a point's coordinates to the value (a, a, a)
SetPointCoordsCalculate the coordinates for a point
SetPointToOriginSet a point's coordinates to the origin at (0, 0, 0)
SetPointVisibilitySet the status byte for multiple points to indicate that their coordinates and visibility have been calculated


ArtificialHorizonVector line calculation for the artificial horizon on indicator 7
DrawFuelPixelDraw or erase a pixel on the fuel gauge on the dashboard
DrawRadarBlipDraw a blip on the radar (runway or alien)
GetHandVectorVector line calculation for a hand on indicators 0 to 6
GetRadarVectorCalculate the radar line vector for a line (the runway) or a dot (an alien)
IndicatorBUpdate the brakes indicator ("B")
IndicatorFUpdate the flaps indicator ("F") and related variables
IndicatorTUpdate the Theme indicator ("T")
IndicatorUUpdate the undercarriage indicator ("U") and related variables
ResetRadarReset the radar display
ShowUpsideDownBarShow or hide the upside down bar in the artificial horizon indicator
UpdateDash7To11Update the next indicator in the range 7 to 11
UpdateDashboardUpdate two indicators on the dashboard, one from 0-6, one from 7-11, cycling through them with each subsequent call
UpdateFuelGaugeUpdate the fuel gauge every 16 iterations of the main loop
UpdateIndicator (Part 1 of 15)Update a single indicator on the dashboard
UpdateIndicator (Part 2 of 15)Calculations for the compass (indicator 0)
UpdateIndicator (Part 3 of 15)Calculations for the airspeed indicator (indicator 1)
UpdateIndicator (Part 4 of 15)Calculations for the altimeter's small "hour" hand (indicator 2)
UpdateIndicator (Part 5 of 15)Calculations for the altimeter's "minute" hand (indicator 3)
UpdateIndicator (Part 6 of 15)Logic for checking which indicator to update
UpdateIndicator (Part 7 of 15)Calculations for the vertical speed indicator (indicator 4)
UpdateIndicator (Part 8 of 15)Logic for checking which indicator to update
UpdateIndicator (Part 9 of 15)Calculations for the turn indicator (indicator 5), the bottom part of the slip-and-turn indicator
UpdateIndicator (Part 10 of 15)Calculations for the slip indicator (indicator 6), the top part of the slip-and-turn indicator
UpdateIndicator (Part 11 of 15)Calculations for the artificial horizon (indicator 7)
UpdateIndicator (Part 12 of 15)Logic for checking which indicator to update
UpdateIndicator (Part 13 of 15)Calculations for the rudder indicator (indicator 9)
UpdateIndicator (Part 14 of 15)Calculations for the joystick position display (indicator 8 or 10)
UpdateIndicator (Part 15 of 15)Calculations for the thrust indicator (indicator 11)
UpdateRadarBlipUpdate a blip on the radar (runway or alien)

Drawing lines

AbortLineAbort drawing this line
ClipBestEndOfLineClip a line at the start or end point, depending on which is best
ClipStartOfLine (Part 1 of 5)Check whether the line is completely off-screen
ClipStartOfLine (Part 2 of 5)Work out the deltas depending on the direction of slope
ClipStartOfLine (Part 3 of 5)Work out the deltas depending on the steepness of slope
ClipStartOfLine (Part 4 of 5)Calculate where to clip the line
ClipStartOfLine (Part 5 of 5)Move the start point to the clipped position and return it
DrawCanopyLine (Part 1 of 9)Draw a line in the canopy view
DrawCanopyLine (Part 2 of 9)Modify the line drawing routine for a shallow horizontal slope
DrawCanopyLine (Part 3 of 9)Draw a line as a shallow horizontal slope
DrawCanopyLine (Part 4 of 9)Draw a part of the line, working down the screen
DrawCanopyLine (Part 5 of 9)Draw a part of the line, working up the screen
DrawCanopyLine (Part 6 of 9)Draw a part of the line, working along the screen
DrawCanopyLine (Part 7 of 9)Modify the line drawing routine for a steep vertical slope
DrawCanopyLine (Part 8 of 9)Draw a line as a steep vertical slope
DrawCanopyLine (Part 9 of 9)If the line was clipped, draw a line from the clipped coordinates to the edge of the screen
DrawClippedHorizonSet bit 1 of the line direction in V (for the horizon)
DrawClippedLine (Part 1 of 6)Clip a line to fit on-screen, starting with the line deltas
DrawClippedLine (Part 2 of 6)Work out whether the line's start point is on-screen
DrawClippedLine (Part 3 of 6)Work out whether the line's end point is on-screen
DrawClippedLine (Part 4 of 6)Calculate the starting point and direction for our clipped vector line
DrawClippedLine (Part 5 of 6)Calculate the deltas for our clipped vector line
DrawClippedLine (Part 6 of 6)Add the clipped line to the line buffer and draw it
DrawHalfHorizonDraw half of the horizon line
DrawIndicatorBarDraw a vertical bar on indicator 9 (rudder) or 11 (thrust)
DrawIndicatorHandApply min and max limits to an indicator value and draw a hand on the indicator
DrawIndicatorLineDraw a line on indicators 0 to 7, i.e. a dial hand (0-6) or an artificial horizon (7)
DrawJoystickCrossDraw a cross in the joystick position display (indicator 8 or 10)
DrawOrthoLineDraw an orthogonal line (i.e. vertical or horizontal)
DrawVectorLine (Part 1 of 3)Draw a line: set up pixel bytes and slope variables
DrawVectorLine (Part 2 of 3)Calculate the coordinates of the next pixel as we step along the line by one pixel
DrawVectorLine (Part 3 of 3)Plot a pixel at (I, J)
EraseCanopyLinesDraw all the lines from a line buffer to erase them
EraseOrthoLineUse the value of G instead of H (so the coordinate is G + W) and always use EOR Logic to draw the line (which will erase it if it is already on-screen)
ModifyDrawRoutineModify the drawing routines to draw in the correct colour for the current colour cycle
SwapLinePointsCopy an end point into a start point

Flight model

AdjustRotationMove the plane and adjust its rotation
AdjustTurnAdjust the plane's turn rate
AdjustVelocityAdjust the plane's velocity vector
ApplyAerodynamics (Part 1 of 3)Set up various variables to use in the aerodynamics calculations
ApplyAerodynamics (Part 2 of 3)Check whether the plane is stalling, and if it is, simulate one wing stalling before the other, and make the stalling sound
ApplyAerodynamics (Part 3 of 3)Calculate various aerodynamic figures
ApplyBumpyRideApply a random amount of roll or bumpiness to the plane
ApplyFlightControlCalculate the effects of the primary flight controls (elevator, rudder and ailerons), and implement the "instant centre" feature
ApplyFlightModel (Part 1 of 7)Apply the flight model to the plane, starting by calculating the effect of gravity and the undercarriage springs
ApplyFlightModel (Part 2 of 7)Convert velocity to the plane's perspective and calculate various aerodynamic forces
ApplyFlightModel (Part 3 of 7)If we are near to an exploding alien, apply turbulence
ApplyFlightModel (Part 4 of 7)Calculate the dxTurn and xLinear vectors, and the slipRate
ApplyFlightModel (Part 5 of 7)Calculate the forces for when we are on the ground
ApplyFlightModel (Part 6 of 7)Adjust the plane's velocity and turn rate, rotate the plane according to the forces on the aircraft, process landing
ApplyFlightModel (Part 7 of 7)Calculate fuel usage
ApplyTurnAndThrust (Part 1 of 2)Calculate the (dxTurn, dyTurn, dzTurn) vector
ApplyTurnAndThrust (Part 2 of 2)Calculate the (xLinear, yLinear, zLinear) vector
CheckPlaneOnRunwayCheck whether the plane is over the runway
CrashMake a crashing sound, flash the canopy and start a new game
FillUpFuelTankFill up the fuel tank by 1/65th of a full tank every four iterations of the main loop
GetMomentsCalculate the pitching, rolling and yawing moments due to the current pitch, roll and yaw rates
GetMoments-1Contains an RTS
ProcessLanding (Part 1 of 7)If this is an emergency landing, make the landing a bumpy one
ProcessLanding (Part 2 of 7)If we are too high to be touching the ground then we can't be landing, so stop the landing checks
ProcessLanding (Part 3 of 7)If we are taxiing, restrict the plane's vertical movement and roll
ProcessLanding (Part 4 of 7)If we are taxiing with the undercarriage up, restrict pitching
ProcessLanding (Part 5 of 7)If we are taxiing with the undercarriage down, restrict pitching and tilt the plane backwards
ProcessLanding (Part 6 of 7)If we are not taxiing, process the landing
ProcessLanding (Part 7 of 7)We have successfully touched down without crashing, so process the effects of landing on the plane
RetractFlapsIfFastRetract the flaps if we are going faster than 150 mph
ScaleByAltitudeMultiply the high byte of the plane's altitude by a 16-bit number
ScaleByAltitude-1Contains an RTS
ScaleFlightForcesScale the flight forces by the relevant scale factors
SetEngineSet the engine status
UpdateFlightModel (Part 1 of 4)Apply any axis control key presses to the current axis values
UpdateFlightModel (Part 2 of 4)Apply any throttle key presses to the current thrust value
UpdateFlightModel (Part 3 of 4)Process the undercarriage, brake, flaps and fire keys
UpdateFlightModel (Part 4 of 4)Set up matrices, apply the flight model and update the dashboard


ClearCanopyClear the canopy to black, leaving the canopy edges alone
ClearRowsClear the specified number of rows on-screen
DrawCanopyCornersDraw the diagonal corners at the top of the canopy
DrawCanopyViewDraw the main view out of the canopy
DrawGunSightsDraw the canopy corners and the gun sights, if shown
DrawRivetDraw a square rivet (2 pixels across, 4 pixels high)
FillCanopyFill the canopy with a specified colour, leaving the canopy edges alone
FillCanopyRowsFill multiple screen rows with a particular colour, avoiding the canopy edges
FlipColoursFlip the values of colourCycle and colourLogic to cycle to the next colour state
SetColourToBlackSet a logical colour to black
SetColourToWhiteSet a logical colour to white
SetLogicalColourSet a logical colour to a physical colour
VduDrawDraw a line using the standard VDU routines
VduMoveMove the graphics cursor using the standard VDU routines
VduPlotPerform a plot command using the standard VDU routines
VduPointDraw a point on-screen using the standard VDU routines


ProcessOtherKeysApply the undercarriage, brakes, flaps and fire keys
ReadADCChannelRead the joystick position from one of the ADC channels
ReadJoystickRead the joystick axes and fire button and update the aileron, elevator and fire key values accordingly
ScanKeyboardScan the keyboard for a specific key
ToggleJoystickToggle the joystick setting
UpdateKeyLoggerScan the keyboard for keys in the two key tables and update the key logger

Main loop

MainLoop (Part 1 of 15)Start the main loop by processing gunfire and bullets
MainLoop (Part 2 of 15)Reset object statuses and related points
MainLoop (Part 3 of 15)Make the sound of firing, if appropriate
MainLoop (Part 4 of 15)Check whether aliens have invaded Acornsville
MainLoop (Part 5 of 15)Update lines, check flying skills, increment main loop counter, update the radar
MainLoop (Part 6 of 15)Check whether any aliens have been hit
MainLoop (Part 7 of 15)Process the terminate key
MainLoop (Part 8 of 15)If we fire the guns on the runway, enable the Theme
MainLoop (Part 9 of 15)Fill up the tank if the engine is switched off, and process the volume keys
MainLoop (Part 10 of 15)Award points for a successful landing
MainLoop (Part 11 of 15)Process engine start and stop
MainLoop (Part 12 of 15)Spend at least 9 centiseconds processing lines from the linesToHide list
MainLoop (Part 13 of 15)Process more lines and update the view out of the canopy
MainLoop (Part 14 of 15)Handle the score display
MainLoop (Part 15 of 15)Update the status of any new line points


Add16x16Bit0Add two 16-bit numbers that have their signs in bit 0
AddScaledAdd or subtract a scaled amount to a variable
DivideScaledDivide a 16-bit number by a scaled 16-bit number
Multiply16x16Multiply two unsigned 16-bit numbers
Multiply16x16Bit0Multiply two 16-bit numbers that have their signs in bit 0
Multiply16x16MixMultiply two 16-bit numbers with different sign bits (one in bit 7 of the high byte, the other in bit 0 of the low byte)
Multiply4x16Multiply a 4-bit and a 16-bit number
Multiply8x16Multiply an 8-bit and a 16-bit number
Multiply8x16-2Store X in VV before doing the calculation Multiply8x16-6 Store X in VV and calculate (G W V) = (A Y) * R
Multiply8x16-6Store X in VV and calculate (G W V) = (A Y) * R
Multiply8x8Multiply two unsigned 8-bit numbers
Negate16BitNegate a 16-bit number
ScaleDown (Part 1 of 4)Scale down the results of divisions done using the ScaleUp and DivideScaled routines
ScaleDown (Part 2 of 4)Balance the scale factors for the x- and y-coordinates
ScaleDown (Part 3 of 4)Scale the x-coordinate
ScaleDown (Part 4 of 4)Scale the y-coordinate
ScaleSignedScale an indicator value by 4 or 16, retaining the sign and adding sensitivity for smaller values
ScaleUpScale up a 16-bit number until it doesn't fit into 16 bits any more
Sine16BitCalculate the sine of a 16-bit number


CheckBridgeAndTownCheck whether we are safely flying under the bridge or down the main street in Acornsville
CheckFlyingSkills (Part 1 of 2)Check whether we are performing one of the tests of flying skill
CheckFlyingSkills (Part 2 of 2)Perform finer checks to see if we are flying under the bridge or along the main street of the town
DisplayScorePrint the scores on-screen
PrintScorePrint a score
PrintScoreTextPrint text when showing the scores on-screen
RemoveScoreRemove the score display from the screen
ScoreHitPointsAward points for destroying an alien, and remove the alien from its slot and the radar, if required
ScorePointsIncrease the score and make a beep
UpdateHighScoreIf this is a high score, update the high score
UpdateScoreIncrease the score by a specified number of points


DrawCanopyMove code around, clear the edges of the canopy view, draw the canopy edges and rivets, and jump to the main code
EntryThe main entry point for the game: move code into lower memory and call it
NewGameStart a new game
ResetVariablesReset most variables to prepare for a new flight
SetupScreenSet up the screen mode and load the dashboard image
StartGameReset the high score, set up the gunfire sound envelope and start a new game
TerminateGameTerminate the current game


DefineEnvelopeDefine a sound envelope
MakeEngineSoundMake the engine sound, with the choppiness and pitch affected by thrust and airspeed
MakeSoundMake a sound
MakeSoundEnvelopeEither make a sound or set up an envelope
ProcessVolumeKeysAdjust the volume when the volume keys are pressed
ResetEngineSoundReset the pitch of the engine sound
ToggleEngineSoundTurn the engine sound on or off

The Theme

AlienInAcornsvilleMove an alien towards Acornsville and check whether it has reached it yet (and if so, end the game)
CheckAlienWeakSpotCheck whether an object is close enough to an alien's weak spot to be hitting it
CheckIfAlienIsHit (Part 1 of 2)Extract the alien's feeding stage, ready for the hit calculations in part 2
CheckIfAlienIsHit (Part 2 of 2)Check to see whether the alien has been hit, and if so, initiate the explosion
ExplodeAlienExplode an alien, making the alien split apart
FireGunsCreate the bullet objects and send them on their way
FireGuns-1Contains an RTS
GetAlienWeakSpotCalculate the coordinates of an alien's weak spot
GetTrailVectorStepCalculate 1/32 of the vector for a bullet trail
PrintTooLatePrint the "TOO LATE!" message at column 6, row 7 on-screen
ResizeFeedingAlienChange the size of an alien so it grows bigger as it feeds
SpawnAlienIf the Theme is enabled and the current wave does not yet have eight aliens in it, spawn a new alien
UpdateAliens (Part 1 of 5)Update the aliens so they progress through their feeding or attack cycles
UpdateAliens (Part 2 of 5)Manage alien slots 31 and 32, and if there's a vacancy, wake up a dormant alien, move it into the slot and start its feeding cycle
UpdateAliens (Part 3 of 5)If alien slot 33 is free and there's an alien waiting to take off, promote it into slot 33
UpdateAliens (Part 4 of 5)When an alien reaches the next feeding stage, double its size
UpdateAliens (Part 5 of 5)Check whether the whole wave has been destroyed, and award points accordingly
UpdateBulletsMove the bullets through the air

Utility routines

CheckTimePassedFlag whether 9 centiseconds have passed since the last call
CopyPointToWorkCopy a point from the point tables to the variable workspace
CopyTempToPointSet a specified point to (xTemp1, yTemp1, zTemp1)
CopyWorkToPointCopy a point from the variable workspace to the point tables
DelayDelay for a specified number of loops
NextRandomNumberPoint to the next item in the randomNumbers list
ResetVariableSet a 16-bit in the variable workspace to 0
SetRandomNumberSet the next item in the randomNumbers list to a new random number and update the pointer to point to it


CheckLineDistanceCheck whether a point on a line is within the visible distance for the line
CheckObjDistanceCheck whether an object is within the visible distance for that object, along just one axis
ProcessHorizonLineCalculate coordinates for the horizon's start and end points
ProcessLine (Part 1 of 7)Process a line, rotating and transforming it to the correct coordinates and calculating its visibility
ProcessLine (Part 2 of 7)Process runway lines
ProcessLine (Part 3 of 7)If a line is part of a multi-point object, extract the other points in the line so we can check them all
ProcessLine (Part 4 of 7)Process bullet lines
ProcessLine (Part 5 of 7)Calculate the object's coordinates and visibility
ProcessLine (Part 6 of 7)Check the visibility of all the object's points on the stack
ProcessLine (Part 7 of 7)Check distance and z-coordinates and return the final result
ProcessLine-1Contains an RTS
ProcessLinesToHideProcess an unprocessed line from the linesToHide list
ProcessLinesToShowProcess the linesToShow list, projecting all the lines onto the screen and moving any that aren't visible to the linesToHide list
ProcessRunwayLine (Part 1 of 5)Calculate coordinates and visibility for a runway line
ProcessRunwayLine (Part 2 of 5)Calculate coordinates and visibility for the runway outline
ProcessRunwayLine (Part 3 of 5)Calculate visibility for the runway dashes
ProcessRunwayLine (Part 4 of 5)Construct the dashes down the middle of the runway
ProcessRunwayLine (Part 5 of 5)Clip any portion of the runway outline that's behind us
ResetLineListsReset the line lists at linesToShow and linesToHide
ShowOrHideLineProcess a line, working out its visibility and adding it to the linesToShow or linesToHide list
UpdateLinesToShowUpdate the linesToShow list, moving any lines that aren't visible into the linesToHide list