.ResetVariables LDA #0 \ Set A = 0, so we can use it to reset variables to zero \ in the following loops LDX #&68 \ We start by zeroing all zero-page variables from \ playerMoving to processContact, so set up a loop \ counter in X .rese1 STA playerMoving,X \ Zero the X-th byte from playerMoving DEX \ Decrement the loop counter BPL rese1 \ Loop back until we have zeroed all variables from \ playerMoving to processContact LDX #&7F \ We now zero all variables from xPlayerCoordHi to \ zTyreForceBoth, so set up a loop counter in X .rese2 STA xPlayerCoordHi,X \ Zero the X-th byte from xPlayerCoordHi DEX \ Decrement the loop counter BPL rese2 \ Loop back until we have zeroed all variables from \ xPlayerCoordHi to zTyreForceBoth JSR DefineEnvelope \ Define the first (and only) sound envelope LDX #23 \ We now zero the 24-byte blocks at objTrackSection and \ objSectionSegmt, and initialise all 24 bytes in \ (objectSegmentHi objectSegmentLo), so set up a loop \ counter in X STX previousSignNumber \ Set previousSignNumber = 23 to set the number of the \ previous sign to the highest possible value (as the \ track sections are numbered 0 to 23), so we skip the \ part of BuildRoadSign that reuses the sign from the \ previous track section .rese3 LDA trackStartLine+1 \ Set the X-th byte of (objectSegmentHi objectSegmentLo) STA objectSegmentHi,X \ to the value of trackStartLine, which is 843 for the LDA trackStartLine \ Silverstone track and contains the segment number of STA objectSegmentLo,X \ the starting line, expressed as the number of segments \ between the starting line and the start of section 0, \ counting forwards round the track LDA #0 \ Zero the X-th byte of objTrackSection to put the STA objTrackSection,X \ object in the first track section, ready for the call \ to PlaceCarsOnTrack below STA objSectionSegmt,X \ Zero the X-th byte of objSectionSegmt to put the \ object at the first segment in the current track \ section, ready for the call to PlaceCarsOnTrack below DEX \ Decrement the loop counter BPL rese3 \ Loop back until we have zeroed or copied all 24 \ variable bytes JSR SetPlayerPositions \ Set the current player's position in currentPosition, \ plus the number of the position ahead in positionAhead \ and number of the position behind in positionBehind LDA #1 \ Set A = 1, to pass to PlaceCarsOnTrack as the spacing \ for the cars when this is a race BIT raceStarted \ If bit 7 of raceStarted is set then this is a race BMI rese4 \ rather than practice or qualifying, so jump to rese4 \ to skip the following \ This is a practice or qualifying lap, so we set the \ player's position as specified in the track data LDX trackStartPosition \ Set X to trackStartPosition, the starting position for \ practice or qualifying laps, which is 4 for the \ Silverstone track LDY currentPosition \ Set Y to the current player's position JSR SwapDriverPosition \ Swap the positions of drivers in positions X and Y in \ the driversInOrder table, so for Silverstone this sets \ the current player's position to 4 (i.e. fifth place) JSR SetPlayerPositions \ Set the current player's position in currentPosition, \ plus the number of the position ahead in positionAhead \ and number of the position behind in positionBehind LDA trackCarSpacing \ Set A to trackCarSpacing, to pass to PlaceCarsOnTrack \ as the spacing for the cars when this is a qualifying \ lap (this value is 40 for the Silverstone track) .rese4 \ By this point, A = 1 if this is a race, or the value \ of trackCarSpacing if this is practice or qualifying \ (40 for Silverstone) JSR PlaceCarsOnTrack \ Reset the cars on the track, placing them on the \ starting grid if this is a race, or spread out along \ the track if this is a qualifying lap LDX #19 \ We now zero the 20-byte blocks at driverLapNumber, \ carSteering, carProgress, (carSpeedHi carSpeedLo) and \ carStatus, and initialise the 20-byte blocks at \ objectStatus, totalRaceMinutes and carSectionSpeed, \ so set up a loop counter in X .rese5 LDA #%10000000 \ Set the X-th byte of objectStatus to %10000000, so the STA objectStatus,X \ object is hidden STA totalRaceMinutes,X \ Set the X-th byte of totalRaceMinutes to &80, which is \ 80 minutes as totalRaceMinutes is in BCD LDA #0 \ Zero the X-th byte of driverLapNumber, so each driver STA driverLapNumber,X \ starts at lap 0 STA carSteering,X \ Zero the X-th byte of carSteering to set each car's \ steering to dead ahead STA carProgress,X \ Zero the X-th byte of carProgress to reset each car's \ progress within the starting segment STA carSpeedHi,X \ Zero the X-th byte of carSpeedHi to reset each car's \ forward speed STA carStatus,X \ Zero the X-th byte of carStatus so each car is ready \ to have its status byte updated and is not braking or \ accelerating STA carSpeedLo,X \ Zero the X-th byte of carSpeedLo to reset each car's \ forward speed LDA #255 \ Set the X-th byte of carSectionSpeed to 255, so there STA carSectionSpeed,X \ is no minimum speed set for the car in the next track \ section DEX \ Decrement the loop counter BPL rese5 \ Loop back until we have zeroed or initialised all 20 \ bytes in each block LDA #1 \ Set gearNumber = 1, to set the gears to neutral STA gearNumber STA pastHalfway \ Set pastHalfway = 1, so the player is in the second \ half of the track (which is true for both practice \ and qualifying, as well as the starting grid) LDX #7 \ Set oddsOfEngineStart = 7, so the odds of the engine STX oddsOfEngineStart \ starting when revving are 1 in 7 DEX \ Set sectionListValid = 6, to denote that there are no STX sectionListValid \ valid entries in the track section list STX sectionListPointer \ Set sectionListPointer = 6, to set the current entry \ to the entry after the end of the list (as the list \ is empty) DEX \ We now zero the six bytes at mirrorContents to clear \ all six segments of the wing mirrors, so set X = 5 to \ use as a loop counter .rese6 STA mirrorContents,X \ Clear the contents of the X-th wing mirror segment DEX \ Decrement the loop counter BPL rese6 \ Loop back until we have zeroed all six mirror segments JSR PrintGearNumber \ Print the new gear number on the gear stick (neutral) LDA raceStarted \ If bit 7 of raceStarted is set then this is a race BMI rese7 \ rather than practice or qualifying, so jump to rese7 \ with bit 7 of A set and bit 6 of A clear, to print the \ race header at the top of the screen LDX #40 \ Blank out the first text line at the top of the screen JSR PrintSecondLineGap \ and print token 40 on the second line, to give: \ \ " " \ "Lap Time : Best Time " LDX #1 \ Zero the lap timer JSR ZeroTimer JSR PrintBestLapTime \ Print the best lap time and the current lap time at \ the top of the screen LDA #&DF \ Set firstLapStarted = -33, so that when we add 33 in STA firstLapStarted \ the UpdateLapTimers routine, we get a value of 0 when \ we start the first lap RTS \ Return from the subroutine .rese7 STA updateDrivingInfo \ Set bit 7 and clear bit 6 of updateDrivingInfo so the \ lap number gets printed at the top of the screen STA updateDriverInfo \ Set bit 7 of updateDriverInfo so the driver names get \ printed at the top of the screen LDX #43 \ Print token 43 on the first text line at the top of JSR PrintFirstLine \ the screen and token 44 on the second line, to give: LDX #44 \ JSR PrintSecondLine \ "Position In front: " \ "Laps to go Behind: " \ \ Token 44 includes five extra spaces at the end, though \ I'm not sure why LDA currentPosition \ Set A to the current player's position JSR ConvertNumberToBCD \ Convert the number in A into binary coded decimal \ (BCD), adding 1 in the process STA positionChangeBCD \ Set positionChangeBCD to the current player's position \ in BCD RTS \ Return from the subroutineName: ResetVariables [Show more] Type: Subroutine Category: Main Loop Summary: Reset a number of variables for driving, and print the top two text linesContext: See this subroutine in context in the source code References: This subroutine is called as follows: * MainDrivingLoop (Part 1 of 5) calls ResetVariables
[X]
Subroutine ConvertNumberToBCD (category: Maths (Arithmetic))
Convert a number into binary coded decimal (BCD), for printing
[X]
Subroutine DefineEnvelope (category: Sound)
Define a sound envelope
[X]
Subroutine PlaceCarsOnTrack (category: Car geometry)
Position the cars on the track, ready for a race or qualifying lap
[X]
Subroutine PrintBestLapTime (category: Text)
Print the best lap time and the current lap time at the top of the screen
[X]
Subroutine PrintFirstLine (category: Text)
Prints a text token on the first text line at the top of the driving screen
[X]
Subroutine PrintGearNumber (category: Text)
Print the number of the current gear in double-width characters on the gear stick
[X]
Subroutine PrintSecondLine (category: Text)
Prints a text token on the second text line at the top of the driving screen
[X]
Subroutine PrintSecondLineGap (category: Text)
Prints a text token on the second text line at the top of the driving screen, with an empty gap on the line above
[X]
Subroutine SetPlayerPositions (category: Drivers)
Set the current player's position, plus the positions behind and in front
[X]
Subroutine SwapDriverPosition (category: Drivers)
Swap the position for two drivers (i.e. overtake)
[X]
Subroutine ZeroTimer (category: Drivers)
Zero the specified timer
[X]
Variable carProgress in workspace Stack variables
Lowest byte of each car's progress through the segment it's in
[X]
Variable carSectionSpeed in workspace Stack variables
Set to the driver speed for the next track section, which is taken from the track data and used to set the section's maximum speed for non-player drivers
[X]
Variable carSpeedHi in workspace Stack variables
High byte of each car's forward speed
[X]
Variable carSpeedLo (category: Car geometry)
Low byte of each car's forward speed
[X]
Variable carStatus in workspace Stack variables
Each car's status byte
[X]
Variable carSteering in workspace Stack variables
Contains the steering to apply to each car
[X]
Variable currentPosition in workspace Zero page
The position of the current player
[X]
Variable driverLapNumber in workspace Main variable workspace
The current lap number for each driver
[X]
Variable firstLapStarted (category: Drivers)
Flag to keep track of whether we have started the first lap of practice or qualifying
[X]
Variable gearNumber in workspace Zero page
The current gear number
[X]
Variable mirrorContents (category: Dashboard)
Contains the size of the car in each mirror segment
[X]
Variable objSectionSegmt in workspace Main variable workspace
Each object's segment number within the current track section, counting from the start of the section
[X]
Variable objTrackSection in workspace Main variable workspace
The number of the track section * 8 for each object
[X]
Variable objectSegmentHi in workspace Main variable workspace
High byte of each object's segment, i.e. its position around on the track
[X]
Variable objectSegmentLo in workspace Main variable workspace
Low byte of each object's segment, i.e. its position around on the track
[X]
Variable objectStatus in workspace Stack variables
Various status flags for each object
[X]
Variable oddsOfEngineStart in workspace Zero page
The chances of the engine starting while revving the engine (the engine will start with a chance of 1 in oddsOfEngineStart)
[X]
Variable pastHalfway in workspace Zero page
Stores which half of the track the player is in
[X]
Variable playerMoving in workspace Zero page
Flag to denote whether the player's car is moving
[X]
Variable positionChangeBCD in workspace Zero page
The change in BCD for the player's race position
[X]
Variable previousSignNumber (category: Track geometry)
Stores the number of the sign from the previous call to the BuildRoadSign routine
[X]
Variable raceStarted in workspace Zero page
Flag determining whether the race has started
[X]
Label rese1 is local to this routine
[X]
Label rese2 is local to this routine
[X]
Label rese3 is local to this routine
[X]
Label rese4 is local to this routine
[X]
Label rese5 is local to this routine
[X]
Label rese6 is local to this routine
[X]
Label rese7 is local to this routine
[X]
Variable sectionListPointer in workspace Zero page
The index of the current entry in the track section list, as we only update one entry in the list on each iteration of the main driving loop
[X]
Variable sectionListValid in workspace Zero page
The index of the first valid entry in the track section list
[X]
Variable totalRaceMinutes in workspace Main variable workspace
Minutes of each driver's total race time, stored in BCD
[X]
Variable trackCarSpacing in workspace trackData
The spacing between the cars at the start of a qualifying lap, in segments
[X]
Variable trackStartLine in workspace trackData
The segment number of the starting line
[X]
Variable trackStartPosition in workspace trackData
The starting race position of the player during a practice or qualifying lap
[X]
Variable updateDriverInfo (category: Text)
Flag that controls whether the driver names are updated in the information block at the top of the screen
[X]
Variable updateDrivingInfo in workspace Zero page
Determines which parts of the driving information should be updated at the top of the screen
[X]
Variable xPlayerCoordHi (category: Car geometry)
The high byte of the x-coordinate of the player's 3D coordinates