Prev: 6E32 Up: Map Next: 6EC2
6E43: Handle Steering And Fuel
Used by the routine at HandlerAccelerate.
Counts down the bounce, steers the car, uses up fuel and updates the temperature and the gauges.
Count down the bounce; the sound is only made while this is not zero.
HandlerSteering 6E43 LD A,($5E45) Fetch the bounce counter (BounceCounter).
6E46 AND A Jump to HandlerSteering_Steer if the bounce is over.
6E47 JR Z,HandlerSteering_Steer
6E49 DEC A Count down the bounce.
6E4A LD ($5E45),A Write the bounce counter back to BounceCounter.
6E4D JR Z,HandlerSteering_StoreSound Jump to HandlerSteering_StoreSound if the counter is now zero.
6E4F LD A,$02 A=02.
HandlerSteering_StoreSound 6E51 LD ($5E47),A Write A to SoundStore.
Steer the car.
HandlerSteering_Steer 6E54 CALL ReadInputLR Read the steering keys using ReadInputLR.
6E57 LD HL,($5E10) Point HL at the direction (Player_Direction).
6E5A LD E,$18 Set the amount to turn by, 18.
6E5C BIT 1,A Jump to HandlerSteering_TurnLeft if left is pressed.
6E5E JP Z,HandlerSteering_TurnLeft
6E61 BIT 0,A Jump to HandlerSteering_TurnRight if right is pressed.
6E63 JP Z,HandlerSteering_TurnRight
6E66 LD E,$00 Set the amount to turn by to 00 as the car is going straight on.
6E68 JR HandlerFuel Jump to HandlerFuel.
This instruction is never used.
6E6A LD E,$18 E=18.
Turn right.
HandlerSteering_TurnRight 6E6C LD D,$00 Clear the high byte of the amount to turn by.
6E6E ADD HL,DE Add the amount to turn by to the direction.
6E6F LD ($5E10),HL Write the direction back to Player_Direction.
6E72 JR HandlerFuel Jump to HandlerFuel.
This instruction is never used.
6E74 LD E,$18 E=18.
Turn left.
HandlerSteering_TurnLeft 6E76 LD D,$00 Clear the high byte of the amount to turn by.
6E78 AND A Take the amount to turn by away from the direction.
6E79 SBC HL,DE
6E7B LD ($5E10),HL Write the direction back to Player_Direction.
Don't "use fuel" on every frame. This routine uses the last two bits of the GameTimer (i.e. a number between 0-3) to only process every fourth frame.
HandlerFuel 6E7E LD A,($5E29) Fetch the game timer (GameTimer).
6E81 AND %00000011 Keep only bits 0-1.
6E83 JR NZ,HandlerTemperatureGauge If the result is not zero then jump to HandlerTemperatureGauge.
Handles "using" fuel.
6E85 LD A,($5E0D) Fetch the speed of the car (Speed).
6E88 LD C,A Use the speed as the amount of fuel to use, in C.
6E89 LD B,$00 Clear the high byte of the amount of fuel to use.
6E8B LD HL,($5E0A) Fetch the fuel (Fuel_LSB).
A higher speed uses more fuel.
6E8E SBC HL,BC HL=HL (fuel) - BC (speed).
6E90 JR C,FuelSkipWrite If there's "carry" (i.e. if the player has run out of fuel) jump to FuelSkipWrite.
6E92 LD ($5E0A),HL Write HL to Fuel_LSB.
FuelSkipWrite 6E95 CP $B0 If the current speed is more than B0 (top speed) jump to TemperatureMaxSpeed.
6E97 JR NC,TemperatureMaxSpeed
6E99 CP $60 Compare current speed with 60.
Handle the temperature gauge.
HandlerTemperatureGauge 6E9B LD A,($5E0C) Fetch the temperature (Temperature).
6E9E JR C,TemperatureDrop If there's carry set (this could be either from 6E99 or 6E81) then jump to TemperatureDrop.
DrawTemperatureGauge 6EA0 LD HL,$5162 Set the screen location of the temperature gauge, 5162.
6EA3 CALL DrawGaugeLine Draw the temperature gauge using DrawGaugeLine.
Handle the fuel gauge.
6EA6 LD A,($5E0B) Fetch the fuel level (Fuel_MSB).
6EA9 LD HL,$5122 Set the screen location of the fuel gauge, 5122.
6EAC JP DrawGaugeLine Draw the fuel gauge using DrawGaugeLine.
Handle the temperature gauge at maximum speed.
TemperatureMaxSpeed 6EAF LD A,($5E0C) Fetch the temperature (Temperature).
Check if the temperature is already at the upper limit.
6EB2 CP $C0 If the current temperature is more than C0 jump to DrawTemperatureGauge.
6EB4 JR NC,DrawTemperatureGauge
Go ahead and increase the temperature...
6EB6 INC A Increase the temperature by one.
UpdateTemperature 6EB7 LD ($5E0C),A Write the new temperature back to Temperature.
6EBA JR DrawTemperatureGauge Jump to DrawTemperatureGauge.
Handles dropping the temperature gauge.
TemperatureDrop 6EBC AND A If the current temperature is at zero jump to DrawTemperatureGauge.
6EBD JR Z,DrawTemperatureGauge
6EBF DEC A Decrease the temperature by one.
6EC0 JR UpdateTemperature Jump to UpdateTemperature.
Prev: 6E32 Up: Map Next: 6EC2