![]() |
Routines |
| Prev: 37307 | Up: Map | Next: 37644 |
|
Drive the rover: refill the fuel gauge, read the controls and stop the rover at craters in the terrain ahead.
|
||||||||
|
Refill the tank, then steer from the controls.
|
||||||||
| Handler_MoonRover | 37346 | LD A,(24172) | Jump to Handler_MoonRover_DrawSprite if PlayerInactive is set. | |||||
| 37349 | AND A | |||||||
| 37350 | JR NZ,Handler_MoonRover_DrawSprite | |||||||
| 37352 | LD HL,36864 | Write 36864 to FuelLevel_1. | ||||||
| 37355 | LD (24718),HL | |||||||
| 37358 | LD A,H | Fetch the high fuel byte. | ||||||
| 37359 | LD HL,4160 | HL=4160 (gauge position). | ||||||
| 37362 | CALL DrawGauge | Call DrawGauge. | ||||||
|
Read the controls and speed the rover up if LEFT or RIGHT is held.
|
||||||||
| 37365 | CALL HandlerControls | Call HandlerControls. | ||||||
| 37368 | BIT 0,A | Jump to Handler_MoonRover_AccelerateRight if RIGHT is pressed. | ||||||
| 37370 | JP Z,Handler_MoonRover_AccelerateRight | |||||||
| 37373 | BIT 1,A | Jump to Handler_MoonRover_AccelerateLeft if LEFT is pressed. | ||||||
| 37375 | JP Z,Handler_MoonRover_AccelerateLeft | |||||||
|
Neither direction is held, so ease the speed back towards zero.
|
||||||||
| 37378 | LD A,(IX+5) | Jump to Handler_MoonRover_Loop if the horizontal speed is zero. | ||||||
| 37381 | AND A | |||||||
| 37382 | JR Z,Handler_MoonRover_Loop | |||||||
| 37384 | JP P,Handler_MoonRover_Decelerate | Jump to Handler_MoonRover_Decelerate if the rover is moving right. | ||||||
| 37387 | ADD A,1 | Add 1 to the speed. | ||||||
| 37389 | JR Handler_MoonRover_Loop | Jump to Handler_MoonRover_Loop. | ||||||
| Handler_MoonRover_Decelerate | 37391 | SUB 1 | Subtract 1 from the speed. | |||||
| Handler_MoonRover_Loop | 37393 | LD (IX+5),A | Write the speed to *IX+5. | |||||
|
Look ahead under the wheels for blocking terrain.
|
||||||||
| 37396 | LD HL,(24698) | Fetch Jetman_Position. | ||||||
| 37399 | BIT 7,(IX+5) | Jump to Handler_MoonRover_LookLeft if the rover is moving left. | ||||||
| 37403 | JP NZ,Handler_MoonRover_LookLeft | |||||||
| 37406 | LD DE,65528 | DE=65528. | ||||||
| Handler_MoonRover_LookAhead | 37409 | ADD HL,DE | Add the look-ahead offset. | |||||
| 37410 | SRA H | Divide the world position by 8. | ||||||
| 37412 | RR L | |||||||
| 37414 | SRA H | |||||||
| 37416 | RR L | |||||||
| 37418 | SRA H | |||||||
| 37420 | RR L | |||||||
| 37422 | LD A,H | Fetch the high byte. | ||||||
| 37423 | AND %00000011 | Keep only bits 0-1. | ||||||
| 37425 | LD H,A | Write it back to H. | ||||||
|
Scan the cells ahead of the rover and stop it at an empty cell or a crater.
|
||||||||
| 37426 | LD B,6 | Set a cell counter in B for 6 loops. | ||||||
| 37428 | EX DE,HL | Switch the index into DE. | ||||||
| Handler_MoonRover_TestTerrain | 37429 | LD HL,28672 | HL=TerrainData_Active. | |||||
| 37432 | ADD HL,DE | Point HL at that terrain cell. | ||||||
| 37433 | LD A,(HL) | Jump to Handler_MoonRover_Stop if the cell is empty. | ||||||
| 37434 | AND A | |||||||
| 37435 | JR Z,Handler_MoonRover_Stop | |||||||
| 37437 | AND %00001000 | Keep only bit 3. | ||||||
| 37439 | JR NZ,Handler_MoonRover_Stop | Jump to Handler_MoonRover_Stop if it is a crater. | ||||||
|
Step on to the next cell, wrapping the index.
|
||||||||
| 37441 | INC DE | Move onto the next cell. | ||||||
| 37442 | LD A,D | Fetch the high byte. | ||||||
| 37443 | AND %00000011 | Keep only bits 0-1. | ||||||
| 37445 | LD D,A | Write it back to D. | ||||||
| 37446 | DJNZ Handler_MoonRover_TestTerrain | Decrease the cell counter by one and loop back to Handler_MoonRover_TestTerrain until the scan is done. | ||||||
| 37448 | JR Handler_MoonRover_PickFrame | Jump to Handler_MoonRover_PickFrame. | ||||||
|
Stop the rover: it has reached an empty cell or a crater.
|
||||||||
| Handler_MoonRover_Stop | 37450 | LD (IX+5),0 | Write 0 to the horizontal speed. | |||||
| 37454 | JR Handler_MoonRover_ApplySpeed | Jump to Handler_MoonRover_ApplySpeed. | ||||||
|
Pick a facing frame from the fine X.
|
||||||||
| Handler_MoonRover_PickFrame | 37456 | LD A,(IX+5) | Jump to Handler_MoonRover_ApplySpeed if the horizontal speed is zero. | |||||
| 37459 | AND A | |||||||
| 37460 | JR Z,Handler_MoonRover_ApplySpeed | |||||||
| 37462 | JP M,Handler_MoonRover_FineX | Jump to Handler_MoonRover_FineX if the rover is moving left. | ||||||
| 37465 | LD A,(IX+2) | Fetch the low byte of the world X. | ||||||
| 37468 | RRA | Rotate it right. | ||||||
| 37469 | AND %00000011 | Keep only bits 0-1. | ||||||
|
Sprite IDs begin at 22 ("Lunar Rover: Right Frame 1").
|
||||||||
| 37471 | ADD A,22 | Add 22 for the right-facing frames. | ||||||
| 37473 | LD (IX+0),A | Write it to the actor type. | ||||||
|
Move the rover along the planet and draw its sprite.
|
||||||||
| Handler_MoonRover_ApplySpeed | 37476 | CALL ApplyJetmanSpeed | Call ApplyJetmanSpeed. | |||||
| Handler_MoonRover_DrawSprite | 37479 | CALL DrawSpritePair | Call DrawSpritePair. | |||||
|
While Jetman is inactive, step the inactive counter and hand over to Handler_RoverFrames_Tint.
|
||||||||
| 37482 | LD A,(24172) | Jump to Handler_MoonRover_ColourLights if PlayerInactive is zero. | ||||||
| 37485 | AND A | |||||||
| 37486 | JR Z,Handler_MoonRover_ColourLights | |||||||
| 37488 | INC A | Increment PlayerInactive by one. | ||||||
| 37489 | LD (24172),A | |||||||
| 37492 | JP Handler_RoverFrames_Tint | Jump to Handler_RoverFrames_Tint. | ||||||
|
Colour the rover lights, body and banner.
|
||||||||
| Handler_MoonRover_ColourLights | 37495 | CALL ColouriseRoverLights | Call ColouriseRoverLights. | |||||
| 37498 | LD DE,48286 | DE=Graphic_Moon_Rover_Attributes. | ||||||
| 37501 | CALL WriteSpriteAttributes | Call WriteSpriteAttributes. | ||||||
| 37504 | CALL ColouriseBanner | Call ColouriseBanner. | ||||||
|
Leave the rover if SPACE has just been pressed.
|
||||||||
| 37507 | CALL TestSpaceKey | Call TestSpaceKey. | ||||||
| 37510 | CALL NZ,Handler_MoonRover_Leave | Call Handler_MoonRover_Leave if SPACE is pressed. | ||||||
|
Queue a jingle only when the tune buffer has finished and the random number allows it.
|
||||||||
| 37513 | LD A,(65364) | Return if Tune_Pointer is not Tune_Buffer_End. | ||||||
| 37516 | CP 81 | |||||||
| 37518 | RET NZ | |||||||
| 37519 | LD A,(24128) | Fetch RandomNumber. | ||||||
| 37522 | AND %01111111 | Keep only bits 0-6. | ||||||
| 37524 | RET NZ | Return if the result is not zero. | ||||||
|
Choose a tune from the table using the game timer and queue it.
|
||||||||
| 37525 | LD A,(24130) | Fetch GameTimer. | ||||||
| 37528 | AND %00001110 | Keep only bits 1-3. | ||||||
| 37530 | LD C,A | Convert that index into BC. | ||||||
| 37531 | LD B,0 | |||||||
| 37533 | LD HL,40368 | Point HL at the matching entry in Jetman_Tune_Table. | ||||||
| 37536 | ADD HL,BC | |||||||
| 37537 | LD E,(HL) | Fetch the tune pointer. | ||||||
| 37538 | INC HL | |||||||
| 37539 | LD D,(HL) | |||||||
| 37540 | JP QueueTune | Jump to QueueTune. | ||||||
|
Pick a left-facing frame from the fine X.
|
||||||||
| Handler_MoonRover_FineX | 37543 | LD A,(IX+2) | Fetch the low byte of the world X. | |||||
| 37546 | RRA | Rotate it right. | ||||||
| 37547 | AND %00000011 | Keep only bits 0-1. | ||||||
|
Sprite IDs begin at 18 ("Lunar Rover: Left Frame 4").
|
||||||||
| 37549 | ADD A,18 | Add 18 for the left-facing frames. | ||||||
| 37551 | LD (IX+0),A | Write it to the actor type. | ||||||
| 37554 | JR Handler_MoonRover_ApplySpeed | Jump to Handler_MoonRover_ApplySpeed. | ||||||
|
Look further ahead when the rover is moving left.
|
||||||||
| Handler_MoonRover_LookLeft | 37556 | LD DE,65520 | DE=65520. | |||||
| 37559 | JP Handler_MoonRover_LookAhead | Jump to Handler_MoonRover_LookAhead. | ||||||
|
Accelerate left, but cap the speed at 232.
|
||||||||
| Handler_MoonRover_AccelerateLeft | 37562 | LD A,(IX+5) | Jump to Handler_MoonRover_SubtractSpeed if the horizontal speed is positive. | |||||
| 37565 | AND A | |||||||
| 37566 | JP P,Handler_MoonRover_SubtractSpeed | |||||||
| 37569 | CP 232 | Jump to Handler_MoonRover_Loop if the speed is already below 232. | ||||||
| 37571 | JP C,Handler_MoonRover_Loop | |||||||
| Handler_MoonRover_SubtractSpeed | 37574 | SUB 2 | Subtract 2 from the speed. | |||||
| 37576 | JP Handler_MoonRover_Loop | Jump to Handler_MoonRover_Loop. | ||||||
|
Accelerate right, but cap the speed at 40.
|
||||||||
| Handler_MoonRover_AccelerateRight | 37579 | LD A,(IX+5) | Jump to Handler_MoonRover_AddSpeed if the horizontal speed is negative. | |||||
| 37582 | AND A | |||||||
| 37583 | JP M,Handler_MoonRover_AddSpeed | |||||||
| 37586 | CP 40 | Jump to Handler_MoonRover_Loop if the speed is already at least 40. | ||||||
| 37588 | JP NC,Handler_MoonRover_Loop | |||||||
| Handler_MoonRover_AddSpeed | 37591 | ADD A,2 | Add 2 to the speed. | |||||
| 37593 | JP Handler_MoonRover_Loop | Jump to Handler_MoonRover_Loop. | ||||||
|
Leave the rover and restore Jetman on foot.
|
||||||||
| Handler_MoonRover_Leave | 37596 | CALL SoundsDropItem | Call SoundsDropItem. | |||||
| 37599 | LD HL,24698 | Copy the 14 bytes of rover state from Jetman_Position back out of the Jetman slot to Rover_Position. | ||||||
| 37602 | LD DE,24722 | |||||||
| 37605 | LD BC,14 | |||||||
| 37608 | LDIR | |||||||
|
Screen column 120 is standing beside the rover. Type 22 and above is facing right: walking frames 9 (left) and 13 (right), parked rover frames 26 and 34.
|
||||||||
| 37610 | LD (IX+1),120 | Write 120 to *IX+1. | ||||||
| 37614 | LD A,(IX+0) | Jump to Handler_MoonRover_StandingFrame if the actor type is at least 22. | ||||||
| 37617 | CP 22 | |||||||
| 37619 | JR NC,Handler_MoonRover_StandingFrame | |||||||
|
When facing left, walk with type 9 and park the rover as type 26.
|
||||||||
| 37621 | LD (IX+0),9 | Write 9 to the actor type. | ||||||
| 37625 | LD A,26 | A=26. | ||||||
|
Write the parked rover's type and finish by clearing the banner colour.
|
||||||||
| Handler_MoonRover_WriteType | 37627 | LD (24720),A | Write A to Rover_Slot. | |||||
| 37630 | CALL PositionAndDrawSprite | Call PositionAndDrawSprite. | ||||||
| 37633 | JP ClearBannerColour | Jump to ClearBannerColour. | ||||||
|
When facing right, walk with type 13 and park the rover as type 34.
|
||||||||
| Handler_MoonRover_StandingFrame | 37636 | LD (IX+0),13 | Write 13 to the actor type. | |||||
| 37640 | LD A,34 | A=34. | ||||||
| 37642 | JR Handler_MoonRover_WriteType | Jump to Handler_MoonRover_WriteType. | ||||||
| Prev: 37307 | Up: Map | Next: 37644 |