![]() |
Routines |
| Prev: 6D07 | Up: Map | Next: 6D73 |
|
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 | 6D12 | LD C,$00 | Set the miles carry to 00. | |||||||||
| 6D14 | LD A,($5E0D) | Fetch the speed of the car (Speed). | ||||||||||
| 6D17 | RLA | Rotate the top bit of A into C. | ||||||||||
| 6D18 | RL C | |||||||||||
| 6D1A | RLA | Rotate the top bit of A into C again (this multiplies the speed by 04). | ||||||||||
| 6D1B | RL C | |||||||||||
| 6D1D | LD HL,$5E30 | Point HL at the fraction of a mile (Miles_Fraction). | ||||||||||
| 6D20 | ADD A,(HL) | Add the scaled speed to the fraction of a mile. | ||||||||||
| 6D21 | LD (HL),A | Write the fraction of a mile back. | ||||||||||
| 6D22 | LD A,C | Fetch the carry from the speed. | ||||||||||
| 6D23 | LD B,$03 | Set the byte counter to 03 (the miles are stored in three bytes). | ||||||||||
|
Working backwards, add onto the odometer.
|
||||||||||||
| CalcMiles | 6D25 | DEC HL | Move back to the previous byte of the miles. | |||||||||
| 6D26 | ADC A,(HL) | Add the carry to the byte of the miles. | ||||||||||
| 6D27 | DAA | Convert the result to BCD. | ||||||||||
| 6D28 | LD (HL),A | Write the byte of the miles back. | ||||||||||
| 6D29 | LD A,$00 | Clear the carry value, keeping the carry flag. | ||||||||||
| 6D2B | 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.
|
||||||||||||
| 6D2D | LD A,($5E74) | Fetch the middle byte of the miles as it was last time (MilesCheckpoint) and keep it in L. | ||||||||||
| 6D30 | LD L,A | |||||||||||
| 6D31 | LD A,($5E2E) | Fetch the middle byte of the miles (5E2E). | ||||||||||
| 6D34 | CP L | Jump to UpdatePlayerCar_CheckFuel if the middle byte of the miles has not changed. | ||||||||||
| 6D35 | JR Z,UpdatePlayerCar_CheckFuel | |||||||||||
| 6D37 | LD ($5E74),A | Store the new middle byte of the miles in MilesCheckpoint. | ||||||||||
| 6D3A | LD BC,$0010 | Set the points to add, 0010. | ||||||||||
| 6D3D | CALL AddPointsToScore | Add the points to the score using AddPointsToScore. | ||||||||||
| UpdatePlayerCar_CheckFuel | 6D40 | LD HL,($5E05) | HL=PlayerMapPosition (the value is not used). | |||||||||
|
Check fuel.
|
||||||||||||
| 6D43 | LD A,($5E0B) | Fetch the fuel level (Fuel_MSB). | ||||||||||
|
See Infinite Fuel.
|
||||||||||||
| 6D46 | AND A | Jump to UpdatePlayerCar_CheckTemperature if there is still some fuel. | ||||||||||
| 6D47 | 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 | 6D49 | LD A,($5E0D) | Fetch the speed of the car (Speed). | |||||||||
| 6D4C | CP $33 | Jump to UpdatePlayerCar_Accelerate if the speed is below 33 so the car can be driven again. | ||||||||||
| 6D4E | JR C,UpdatePlayerCar_Accelerate | |||||||||||
| 6D50 | DEC A | Slow the car down by one. | ||||||||||
| 6D51 | LD ($5E0D),A | Write the speed back to Speed. | ||||||||||
| 6D54 | JR UpdatePlayerCar_Brake | Jump to UpdatePlayerCar_Brake. | ||||||||||
|
Check the temperature.
|
||||||||||||
| UpdatePlayerCar_CheckTemperature | 6D56 | LD A,($5E0C) | Fetch the temperature (Temperature). | |||||||||
|
See Infinite Temperature.
|
||||||||||||
| 6D59 | CP $A0 | Jump to UpdatePlayerCar_NoFuel if the temperature is A0 or more. | ||||||||||
| 6D5B | JR NC,UpdatePlayerCar_NoFuel | |||||||||||
|
Check the accelerator.
|
||||||||||||
| UpdatePlayerCar_Accelerate | 6D5D | CALL ReadInputAccelerate | Check if the accelerator is pressed using ReadInputAccelerate. | |||||||||
| 6D60 | BIT 3,A | Jump to HandlerCanAccelerate if the accelerator is pressed. | ||||||||||
| 6D62 | JR Z,HandlerCanAccelerate | |||||||||||
|
Check the brake.
|
||||||||||||
| UpdatePlayerCar_Brake | 6D64 | CALL ReadInputBrake | Check if the brake is pressed using ReadInputBrake. | |||||||||
| 6D67 | BIT 2,A | Jump to HandlerAccelerate_Gauge if the brake is not pressed. | ||||||||||
| 6D69 | JR NZ,HandlerAccelerate_Gauge | |||||||||||
| 6D6B | LD A,($5E0D) | Fetch the speed of the car (Speed). | ||||||||||
| 6D6E | SUB $10 | Subtract 10 from the speed. | ||||||||||
| 6D70 | JR NC,HandlerAccelerate | Jump to HandlerAccelerate if the speed did not go below zero. | ||||||||||
| 6D72 | XOR A | Set the speed to 00. | ||||||||||
| Prev: 6D07 | Up: Map | Next: 6D73 |