Prev: 30267 Up: Map Next: 30419
30268: Handler: Fuel
Used by the routine at Game_Loop.
Handler_Fuel 30268 CALL 29728 Call 29728.
30271 LD HL,(30780) HL=*Fuel.
30274 LD A,H Jump to ProcessFuelConsumption if H is lower than 128.
30275 CP 128
30277 JR C,ProcessFuelConsumption
30279 LD HL,(30766) HL=*LevelProgressPointer.
30282 LD A,(HL) A=*HL.
30283 DEC A Decrease A by one.
30284 JR Z,TriggerOutOfFuel Jump to TriggerOutOfFuel if A is zero.
30286 CP 49 Call 60403 if A is higher than 49.
30288 CALL NC,60403
30291 CP 45 Call 60403 if A is lower than 45.
30293 CALL C,60403
30296 NOP No operation.
30297 NOP
30298 NOP
30299 NOP
Start the "Out Of Fuel" sequence.
TriggerOutOfFuel 30300 CALL RemoveSprites Call RemoveSprites.
30303 LD A,(30754) A=*Speed.
30306 BIT 7,A Check the direction bit.
30308 LD A,135 Load the base player sprite into A (135).
30310 JR NZ,SetWheelieSprite Jump to SetWheelieSprite if the player is moving left.
30312 ADD A,64 Modify the player sprite ID for the player moving right (199).
SetWheelieSprite 30314 LD (30772),A Write the player sprite ID to *PlayerSpriteID.
30317 CALL Handler: PlayerSprite Call Handler: PlayerSprite.
Print the "OUT OF FUEL" messaging in the footer.
out-of-fuel
30320 LD A,169 A=169 (INK: BLUE, PAPER: CYAN FLASH: ON).
30322 LD HL,47750 HL=Messaging_OutOfFuel.
30325 CALL PrintFooterColourString Call PrintFooterColourString.
Play the "out of fuel" audio.
30328 LD D,16 Set an outer loop count in D for 16 iterations.
30330 LD C,1 Set the initial tone value in C to 1.
PlayFuelSound_OuterLoop 30332 LD HL,7680 Set the tone duration counter in HL to 7680.
30335 LD A,C Get current tone value.
PlayFuelSound_ToneLoop 30336 LD B,C Set inner delay counter.
30337 OUT (254),A Send to the speaker.
30339 XOR %00010000 Flip the speaker bit.
PlayFuelSound_InnerDelayLoop 30341 DJNZ PlayFuelSound_InnerDelayLoop Decrease the inner delay counter by one and loop back to PlayFuelSound_InnerDelayLoop until the counter is zero.
30343 DEC L Decrease the tone duration low byte by one.
30344 JR NZ,PlayFuelSound_ToneLoop Jump back to PlayFuelSound_ToneLoop until the tone duration low byte is zero.
30346 DEC H Decrease the tone duration high byte by one.
30347 JR NZ,PlayFuelSound_ToneLoop Jump back to PlayFuelSound_ToneLoop until the tone duration high byte is zero.
30349 INC C Increase the tone frequency by one (higher pitch).
30350 DEC D Decrease the outer loop counter by one.
30351 JR NZ,PlayFuelSound_OuterLoop Jump back to PlayFuelSound_OuterLoop until the outer loop counter is zero.
Reset the players fuel and restart the game.
30353 LD HL,13312 Write 13312 to *Fuel.
30356 LD (30780),HL
30359 JP 29025 Jump to 29025.
Normal fuel consumption processing.
ProcessFuelConsumption 30362 LD A,(30754) A=*Speed.
30365 BIT 7,A Check the direction bit.
30367 JR NZ,CalculateFuelConsumption Jump to CalculateFuelConsumption if the player is moving backwards.
The player is moving forwards.
30369 CPL Invert the speed for forward movement calculation.
CalculateFuelConsumption 30370 SUB 126 Calculate the fuel consumption rate in DE; (speed-126)/2.
30372 SRL A
30374 LD E,A
30375 LD D,0
30377 AND A Subtract the consumption from the players fuel level.
30378 SBC HL,DE
30380 LD (30780),HL Write the updated fuel value back to *Fuel.
30383 JR C,Handler_Fuel_0 Jump to Handler_Fuel_0 if the fuel value is negative.
Update the fuel gauge display.
30385 LD A,H Get the fuel high byte.
30386 SRL A Divide it by 4.
30388 SRL A
30390 CPL Invert the byte for the gauge display.
30391 SUB 12 Abjust by an offset of 12 bytes for where the gauge displays.
30393 LD L,A Set this value in L.
30394 LD H,186 Load the high byte in H with 186.
30396 LD DE,23141 Point DE to the gauge position 23141 (attribute buffer location).
30399 CALL CopyTwelveBytes Call CopyTwelveBytes.
Handle fuel-related audio effects during gameplay.
30402 LD HL,(30780) HL=*Fuel.
30405 LD A,H Call 27984 if the fuel level is 1024 or higher, or for every 64 fuel units (which creates pulses as the fuel decreases).
30406 CP 4
30408 CALL NC,27984
30411 BIT 6,L
30413 CALL NZ,27984
Handler_Fuel_0 30416 JP 60403 Jump to 60403.
Prev: 30267 Up: Map Next: 30419