![]() |
Routines |
| Prev: 27911 | Up: Map | Next: 28019 |
|
Used by the routine at HandlerPlayer.
Called once a frame for the player's car. Adds to the miles travelled, handles the accelerator and the brake, then moves the car, steers it and uses up fuel.
|
||||||||||||
|
Add the speed to the odometer.
|
||||||||||||
| UpdatePlayerCar | 27922 | LD C,0 | Set the miles carry to 0. | |||||||||
| 27924 | LD A,(24077) | Fetch the speed of the car (Speed). | ||||||||||
| 27927 | RLA | Rotate the top bit of A into C. | ||||||||||
| 27928 | RL C | |||||||||||
| 27930 | RLA | Rotate the top bit of A into C again (this multiplies the speed by 4). | ||||||||||
| 27931 | RL C | |||||||||||
| 27933 | LD HL,24112 | Point HL at the fraction of a mile (Miles_Fraction). | ||||||||||
| 27936 | ADD A,(HL) | Add the scaled speed to the fraction of a mile. | ||||||||||
| 27937 | LD (HL),A | Write the fraction of a mile back. | ||||||||||
| 27938 | LD A,C | Fetch the carry from the speed. | ||||||||||
| 27939 | LD B,3 | Set the byte counter to 3 (the miles are stored in three bytes). | ||||||||||
|
Working backwards, add onto the odometer.
|
||||||||||||
| CalcMiles | 27941 | DEC HL | Move back to the previous byte of the miles. | |||||||||
| 27942 | ADC A,(HL) | Add the carry to the byte of the miles. | ||||||||||
| 27943 | DAA | Convert the result to BCD. | ||||||||||
| 27944 | LD (HL),A | Write the byte of the miles back. | ||||||||||
| 27945 | LD A,0 | Clear the carry value, keeping the carry flag. | ||||||||||
| 27947 | DJNZ CalcMiles | Decrease the byte counter by one and loop back to CalcMiles until all three bytes of the miles have been done. | ||||||||||
|
Award some points every time the middle byte of the miles changes.
|
||||||||||||
| 27949 | LD A,(24180) | Fetch the middle byte of the miles as it was last time (MilesCheckpoint) and keep it in L. | ||||||||||
| 27952 | LD L,A | |||||||||||
| 27953 | LD A,(24110) | Fetch the middle byte of the miles (24110). | ||||||||||
| 27956 | CP L | Jump to UpdatePlayerCar_CheckFuel if the middle byte of the miles has not changed. | ||||||||||
| 27957 | JR Z,UpdatePlayerCar_CheckFuel | |||||||||||
| 27959 | LD (24180),A | Store the new middle byte of the miles in MilesCheckpoint. | ||||||||||
| 27962 | LD BC,16 | Set the points to add, 0016. | ||||||||||
| 27965 | CALL AddPointsToScore | Add the points to the score using AddPointsToScore. | ||||||||||
| UpdatePlayerCar_CheckFuel | 27968 | LD HL,(24069) | HL=PlayerMapPosition (the value is not used). | |||||||||
|
Check fuel.
|
||||||||||||
| 27971 | LD A,(24075) | Fetch the fuel level (Fuel_MSB). | ||||||||||
|
See Infinite Fuel.
|
||||||||||||
| 27974 | AND A | Jump to UpdatePlayerCar_CheckTemperature if there is still some fuel. | ||||||||||
| 27975 | JR NZ,UpdatePlayerCar_CheckTemperature | |||||||||||
|
Handle being out of fuel (or too hot): slow down gradually, but allow the car to be driven again when it is slow enough.
|
||||||||||||
| UpdatePlayerCar_NoFuel | 27977 | LD A,(24077) | Fetch the speed of the car (Speed). | |||||||||
| 27980 | CP 51 | Jump to UpdatePlayerCar_Accelerate if the speed is below 51 so the car can be driven again. | ||||||||||
| 27982 | JR C,UpdatePlayerCar_Accelerate | |||||||||||
| 27984 | DEC A | Slow the car down by one. | ||||||||||
| 27985 | LD (24077),A | Write the speed back to Speed. | ||||||||||
| 27988 | JR UpdatePlayerCar_Brake | Jump to UpdatePlayerCar_Brake. | ||||||||||
|
Check the temperature.
|
||||||||||||
| UpdatePlayerCar_CheckTemperature | 27990 | LD A,(24076) | Fetch the temperature (Temperature). | |||||||||
|
See Infinite Temperature.
|
||||||||||||
| 27993 | CP 160 | Jump to UpdatePlayerCar_NoFuel if the temperature is 160 or more. | ||||||||||
| 27995 | JR NC,UpdatePlayerCar_NoFuel | |||||||||||
|
Check the accelerator.
|
||||||||||||
| UpdatePlayerCar_Accelerate | 27997 | CALL ReadInputAccelerate | Check if the accelerator is pressed using ReadInputAccelerate. | |||||||||
| 28000 | BIT 3,A | Jump to HandlerCanAccelerate if the accelerator is pressed. | ||||||||||
| 28002 | JR Z,HandlerCanAccelerate | |||||||||||
|
Check the brake.
|
||||||||||||
| UpdatePlayerCar_Brake | 28004 | CALL ReadInputBrake | Check if the brake is pressed using ReadInputBrake. | |||||||||
| 28007 | BIT 2,A | Jump to HandlerAccelerate_Gauge if the brake is not pressed. | ||||||||||
| 28009 | JR NZ,HandlerAccelerate_Gauge | |||||||||||
| 28011 | LD A,(24077) | Fetch the speed of the car (Speed). | ||||||||||
| 28014 | SUB 16 | Subtract 16 from the speed. | ||||||||||
| 28016 | JR NC,HandlerAccelerate | Jump to HandlerAccelerate if the speed did not go below zero. | ||||||||||
| 28018 | XOR A | Set the speed to 0. | ||||||||||
| Prev: 27911 | Up: Map | Next: 28019 |