Prev: 47627 Up: Map Next: 48625
47649: Check Terrain Collision
Used by the routines at NudgeObject and RunFrame.
Checks whether an object has run into the terrain and bounces it when it has. The tiles come from StartTerrainCheck and SelectNextTile. A tile record starts with the number of boxes, and each box is five bytes: its position, its width, its height and its flags. Bits 2 to 5 clear means a slope (TestSlopeCollision); otherwise the box is a rectangle (TestBoxesOverlap). A rectangle with bits 4 and 5 clear reverses, halves and limits the vertical speed. Any other rectangle does the same to the horizontal speed, and skips the halving when the collision mode is zero. The mode in HorizontalStepSize is 255 for the ship, 128 when the object should stop, and zero otherwise. The ship also plays the crash or bump sound and changes the scroll speed.
Input
B Height of the object
C Width of the object
IX Address of the object
Output
$5C1C Non-zero if the object hit something
CheckTerrainCollision 47649 XOR A Clear the hit flag.
47650 LD (23580),A The hit flag at ScratchValue starts clear.
47653 LD (47625),IX Keep the address of the object.
47657 CALL StartTerrainCheck Find the tiles the object overlaps.
47660 JR CheckTerrainCollision_Tile Test the first of those tiles.
CheckTerrainCollision_NextTiles 47662 CALL SelectNextTile The next overlapping tile.
CheckTerrainCollision_Tile 47665 LD A,(IX+0) The number of boxes in this tile.
47668 AND A None: on to the next tile.
47669 JR Z,CheckTerrainCollision_Done
47671 INC IX The first box of the tile.
CheckTerrainCollision_Box 47673 PUSH IX Keep the address of this box.
47675 EX AF,AF' The box count is in the alternate accumulator.
47676 XOR A Clear the hit flag for this box.
47677 LD (23580),A The hit flag starts clear.
47680 LD A,(IX+4) The flags of this box.
47683 LD (23584),A Keep the flags.
47686 AND %00111100 Bits 2 to 5 mark a rectangle.
47688 JR NZ,CheckTerrainCollision_Rectangle A rectangle is tested below.
47690 JP CheckTerrainCollision_Slope Otherwise the box is a slope.
CheckTerrainCollision_Check 47693 LD A,(23605) The collision status.
47696 BIT 6,A Jump to CheckTerrainCollision_Stop if bit 6 of A is set.
47698 JR NZ,CheckTerrainCollision_Stop
CheckTerrainCollision_NextBox 47700 POP IX Back to this box.
47702 LD DE,5 A box is five bytes.
47705 ADD IX,DE The next box.
47707 EX AF,AF' Back to the box count.
47708 DEC A One box has been tested.
47709 JR NZ,CheckTerrainCollision_Box Repeat while boxes remain.
CheckTerrainCollision_Done 47711 LD A,(23581) The tiles still to test.
47714 DEC A One tile has been tested.
47715 LD (23581),A Remember how many tiles remain.
47718 JP NZ,CheckTerrainCollision_NextTiles Jump to CheckTerrainCollision_NextTiles if the zero flag is clear.
47721 LD IX,(47625) Fetch the word at 47625 into IX.
47725 LD A,(23589) The collision mode.
47728 INC A The ship is mode 255 which becomes zero here.
47729 RET NZ Return if the zero flag is clear.
47730 LD (48146),A The ship has finished this check.
47733 RET Return.
CheckTerrainCollision_Stop 47734 LD A,(36691) The ship state.
47737 CP 10 Jump to CheckTerrainCollision_Return if A is less than 10.
47739 JR C,CheckTerrainCollision_Return
47741 LD A,(23589) The collision mode.
47744 AND A Jump to CheckTerrainCollision_Return if A is not zero.
47745 JR NZ,CheckTerrainCollision_Return
47747 JP CheckTerrainCollision_NextBox Jump to CheckTerrainCollision_NextBox.
CheckTerrainCollision_Return 47750 POP IX Discard the box address.
47752 LD IX,(47625) Fetch the word at 47625 into IX.
47756 RET Return.
47757 NOP Do nothing.
47758 NOP Do nothing.
CheckTerrainCollision_Rectangle 47759 LD A,(23605) The collision status.
47762 BIT 7,A Jump to CheckTerrainCollision_Check if bit 7 of A is set.
47764 JP NZ,CheckTerrainCollision_Check
47767 LD HL,(52794) Fetch the word at ScratchValues into HL.
47770 LD A,(23589) The collision mode.
47773 CP 128 Jump to CheckTerrainCollision_Test if A is 128.
47775 JR Z,CheckTerrainCollision_Test
47777 LD A,(23589) The collision mode again.
47780 INC A The ship is the only object tested here.
47781 JP NZ,CheckTerrainCollision_Flags Jump to CheckTerrainCollision_Flags if the zero flag is clear.
47784 LD A,L The low byte of the position in the tile.
47785 ADD A,4 Add 4 to A.
47787 CP 232 Jump to CheckTerrainCollision_Limit if A is less than 232.
47789 JR C,CheckTerrainCollision_Limit
47791 LD A,232 Do not test past column 232.
CheckTerrainCollision_Limit 47793 LD D,A The near edge of the test.
47794 ADD A,36 Add 36 to A.
47796 JR NC,CheckTerrainCollision_Lower Jump to CheckTerrainCollision_Lower if the carry flag is clear.
47798 LD A,248 Do not test past column 248.
CheckTerrainCollision_Lower 47800 LD E,A The far edge of the test.
47801 BIT 2,(IX+4) Jump to CheckTerrainCollision_Flags if bit 2 of offset 4 of IX is clear.
47805 JR Z,CheckTerrainCollision_Flags
47807 LD A,(62959) The second part flag.
47810 AND A Jump to CheckTerrainCollision_Flags if A is not zero.
47811 JR NZ,CheckTerrainCollision_Flags
47813 LD A,(IX+1) The box's other coordinate.
47816 SUB H Subtract H from A.
47817 JR C,CheckTerrainCollision_Flags Jump to CheckTerrainCollision_Flags if the carry flag is set.
47819 CP 41 Jump to CheckTerrainCollision_Flags if A is 41 or more.
47821 JR NC,CheckTerrainCollision_Flags
47823 LD A,(IX+0) The box's first coordinate.
47826 CP E Jump to CheckTerrainCollision_Flags if A is E or more.
47827 JR NC,CheckTerrainCollision_Flags
47829 ADD A,(IX+2) Add the byte at offset 2 of IX to A.
47832 CP D Jump to CheckTerrainCollision_Flags if A is less than D.
47833 JR C,CheckTerrainCollision_Flags
47835 LD (50896),A The ship has landed on this box.
CheckTerrainCollision_Flags 47838 LD A,(IX+4) The box flags.
47841 AND %00110000 Bits 4 and 5 select a sideways face.
47843 JR NZ,CheckTerrainCollision_Test2 Jump to CheckTerrainCollision_Test2 if the zero flag is clear.
47845 LD A,(48782) The saved vertical speed.
47848 AND A Jump to CheckTerrainCollision_Test if A is zero.
47849 JR Z,CheckTerrainCollision_Test
47851 BIT 2,(IX+4) Jump to CheckTerrainCollision_Skip if bit 2 of offset 4 of IX is set.
47855 JR NZ,CheckTerrainCollision_Skip
47857 NEG Negate A.
CheckTerrainCollision_Skip 47859 BIT 7,A Jump to CheckTerrainCollision_Check if bit 7 of A is set.
47861 JP NZ,CheckTerrainCollision_Check
47864 JR CheckTerrainCollision_Test Jump to CheckTerrainCollision_Test.
CheckTerrainCollision_Test2 47866 BIT 4,A Test bit 4 of A.
47868 LD A,(48781) The saved horizontal speed.
47871 JR NZ,CheckTerrainCollision_Check2 Jump to CheckTerrainCollision_Check2 if the zero flag is clear.
47873 NEG Negate A.
CheckTerrainCollision_Check2 47875 AND A Jump to CheckTerrainCollision_Test if A is zero.
47876 JR Z,CheckTerrainCollision_Test
47878 BIT 7,A Jump to CheckTerrainCollision_Check if bit 7 of A is clear.
47880 JP Z,CheckTerrainCollision_Check
47883 JR CheckTerrainCollision_Test Jump to CheckTerrainCollision_Test.
CheckTerrainCollision_Test 47885 LD DE,(52796) Fetch the word at 52796 into DE.
47889 CALL TestBoxesOverlap Call TestBoxesOverlap.
47892 LD A,(23580) The hit flag from the rectangle test.
47895 AND A Jump to CheckTerrainCollision_Check if A is zero.
47896 JP Z,CheckTerrainCollision_Check
47899 LD A,(23589) The collision mode.
47902 CP 128 Jump to CheckTerrainCollision_Stop if A is 128.
47904 JP Z,CheckTerrainCollision_Stop
47907 LD A,128 A rectangle hit is marked with 128.
47909 LD (23605),A Remember that hit in the collision status.
47912 LD A,(IX+1) The box's second coordinate.
47915 SUB 20 Subtract 20 from A.
47917 LD (57052),A Keep that coordinate.
47920 LD A,(IX+4) The box flags again.
47923 LD (57053),A Keep the box flags.
47926 LD B,A The flags, kept for the bounce.
47927 AND %00110000 Bits 4 and 5 mean the face is sideways.
47929 LD IX,(47625) Fetch the word at 47625 into IX.
47933 JP NZ,CheckTerrainCollision_Wall Jump to CheckTerrainCollision_Wall if the zero flag is clear.
47936 LD A,(23589) The collision mode.
47939 AND A Jump to CheckTerrainCollision_Free if A is zero.
47940 JR Z,CheckTerrainCollision_Free
47942 BIT 3,B Jump to CheckTerrainCollision_Vertical if bit 3 of B is clear.
47944 JR Z,CheckTerrainCollision_Vertical
47946 LD A,(62966) The ninth part flag.
47949 AND A Jump to CheckTerrainCollision_Vertical if A is not zero.
47950 JR NZ,CheckTerrainCollision_Vertical
47952 LD A,4 Four frames of the hit flash.
47954 LD (51137),A Start the hit flash.
47957 JR CheckTerrainCollision_Vertical Jump to CheckTerrainCollision_Vertical.
CheckTerrainCollision_Free 47959 CALL ClearShot Call ClearShot.
47962 BIT 3,B Jump to CheckTerrainCollision_Vertical if bit 3 of B is set.
47964 JR NZ,CheckTerrainCollision_Vertical
47966 LD A,(57052) The coordinate the object should stand on.
47969 LD (IX+5),A Put the object on that row.
CheckTerrainCollision_Vertical 47972 LD H,(IX+9) The high byte of the vertical speed.
47975 LD L,(IX+10) The low byte of the vertical speed.
47978 CALL NegateNumber Call NegateNumber.
47981 CALL HalveNumber Call HalveNumber.
47984 CALL LimitSpeed Call LimitSpeed.
47987 CALL ZeroSmallSpeed Call ZeroSmallSpeed.
CheckTerrainCollision_StoreVertical 47990 LD (IX+9),H The bounced vertical speed.
47993 LD (IX+10),L The low byte of the bounced vertical speed.
47996 LD A,H The high byte of that speed.
47997 LD (48782),A Keep it for the next box.
48000 OR L Set the bits of A that are set in L.
48001 JR Z,CheckTerrainCollision_Still Jump to CheckTerrainCollision_Still if the zero flag is set.
48003 LD A,(23605) The collision status.
48006 OR %01000000 Set the bits of A that are set in 64.
48008 LD (23605),A Note that the object is still moving vertically.
48011 JR CheckTerrainCollision_Ship Jump to CheckTerrainCollision_Ship.
CheckTerrainCollision_Still 48013 LD A,(23589) The collision mode.
48016 INC A See whether this is the ship.
48017 JR Z,CheckTerrainCollision_Ship Jump to CheckTerrainCollision_Ship if the zero flag is set.
48019 BIT 3,B Jump to CheckTerrainCollision_Check if bit 3 of B is clear.
48021 JP Z,CheckTerrainCollision_Check
48024 LD (IX+9),254 Store 254 at offset 9 of IX.
CheckTerrainCollision_Ship 48028 LD A,(23589) The collision mode.
48031 INC A The ship is mode 255.
48032 JP NZ,CheckTerrainCollision_Check Jump to CheckTerrainCollision_Check if the zero flag is clear.
48035 LD A,L The low byte of the bounced speed.
48036 OR H Set the bits of A that are set in H.
48037 CALL NZ,PlayCrashSound Call PlayCrashSound if the zero flag is clear.
48040 LD DE,0 No fractional vertical scroll.
48043 LD (45856),DE Clear the vertical scroll fraction.
48047 CALL UpdateVerticalScrollSpeed Call UpdateVerticalScrollSpeed.
48050 LD A,(57053) The box flags that were hit.
48053 CP 4 Jump to CheckTerrainCollision_Check if A is not 4.
48055 JP NZ,CheckTerrainCollision_Check
48058 LD A,(51434) The ship's map zone.
48061 LD B,A Keep the map zone.
48062 LD A,(57052) The box coordinate.
48065 CP B Jump to CheckTerrainCollision_Check if A is B or more.
48066 JP NC,CheckTerrainCollision_Check
48069 LD A,2 A small downward scroll.
48071 LD (52410),A Scroll the world down by two.
48074 JP CheckTerrainCollision_Check Jump to CheckTerrainCollision_Check.
CheckTerrainCollision_Wall 48077 LD H,(IX+7) The high byte of the horizontal speed.
48080 LD L,(IX+8) The low byte of the horizontal speed.
48083 CALL NegateNumber Call NegateNumber.
48086 LD A,(23589) The collision mode.
48089 AND A Jump to CheckTerrainCollision_Update if A is not zero.
48090 JR NZ,CheckTerrainCollision_Update
48092 CALL ClearShot Call ClearShot.
48095 JR CheckTerrainCollision_StoreHorizontal Jump to CheckTerrainCollision_StoreHorizontal.
CheckTerrainCollision_Update 48097 CALL HalveNumber Call HalveNumber.
48100 CALL LimitSpeed Call LimitSpeed.
48103 CALL ZeroSmallSpeed Call ZeroSmallSpeed.
CheckTerrainCollision_StoreHorizontal 48106 LD (IX+7),H The bounced horizontal speed.
48109 LD (IX+8),L The low byte of the bounced horizontal speed.
48112 LD A,H The high byte of that speed.
48113 LD (48781),A Keep it for the next box.
48116 LD A,(23589) The collision mode.
48119 INC A The ship is mode 255.
48120 JP NZ,CheckTerrainCollision_Check Jump to CheckTerrainCollision_Check if the zero flag is clear.
48123 LD A,L The low byte of the bounced speed.
48124 OR H Set the bits of A that are set in H.
48125 CALL NZ,PlayBumpSound Call PlayBumpSound if the zero flag is clear.
48128 LD DE,0 No fractional horizontal scroll.
48131 LD (51194),DE Clear the horizontal scroll fraction.
48135 CALL UpdateHorizontalScrollSpeed Call UpdateHorizontalScrollSpeed.
48138 LD A,1 The ship has hit a wall.
48140 LD (53436),A The collision kind is the terrain.
48143 JP CheckTerrainCollision_Check Jump to CheckTerrainCollision_Check.
48146 NOP Do nothing.
CheckTerrainCollision_Slope 48147 LD A,(23605) The collision status.
48150 BIT 4,A Jump to CheckTerrainCollision_Check if bit 4 of A is set.
48152 JP NZ,CheckTerrainCollision_Check
48155 CALL TestSlopeCollision Call TestSlopeCollision.
48158 LD A,(23580) The hit flag from the slope test.
48161 AND A Jump to CheckTerrainCollision_Check if A is zero.
48162 JP Z,CheckTerrainCollision_Check
48165 LD A,(23605) The collision status.
48168 OR %00010000 Set the bits of A that are set in 16.
48170 LD (23605),A Note that a slope has been hit.
48173 LD A,(23589) The collision mode.
48176 CP 128 Jump to CheckTerrainCollision_Stop if A is 128.
48178 JP Z,CheckTerrainCollision_Stop
48181 AND A Jump to CheckTerrainCollision_Kind if A is zero.
48182 JR Z,CheckTerrainCollision_Kind
48184 DEC A One less than the mode.
48185 LD (53436),A The collision kind follows the mode.
CheckTerrainCollision_Kind 48188 LD A,(IX+4) The slope flags.
48191 LD (23584),A Keep the slope flags.
48194 AND %01111111 The steepness and the facing, without bit 7.
48196 CP 2 Jump to CheckTerrainCollision_Reflect if A is 2.
48198 JP Z,CheckTerrainCollision_Reflect
48201 AND %00000111 The steepness.
48203 CP 2 Jump to CheckTerrainCollision_Three if A is 2.
48205 JP Z,CheckTerrainCollision_Three
48208 LD A,(IX+4) The slope flags again.
48211 BIT 6,A Jump to CheckTerrainCollision_Rebound if bit 6 of A is clear.
48213 JP Z,CheckTerrainCollision_Rebound
48216 JP CheckTerrainCollision_ReboundBoth Jump to CheckTerrainCollision_ReboundBoth.
CheckTerrainCollision_Bounce 48219 LD IX,(47625) Fetch the word at 47625 into IX.
48223 LD A,(23589) The collision mode.
48226 INC A See whether this is the ship.
48227 JR Z,CheckTerrainCollision_Clear Jump to CheckTerrainCollision_Clear if the zero flag is set.
48229 LD L,(IX+7) The high byte of the horizontal speed, kept in L.
48232 LD H,(IX+8) The low byte of the horizontal speed, kept in H.
48235 LD (47757),HL Keep the old horizontal speed.
48238 LD A,(23578) How far the object went into the slope.
48241 NEG Negate A.
48243 LD (IX+7),A The horizontal speed becomes that depth, reversed.
48246 BIT 7,A Jump to CheckTerrainCollision_Speed if bit 7 of A is clear.
48248 JR Z,CheckTerrainCollision_Speed
48250 NEG Negate A.
CheckTerrainCollision_Speed 48252 CP 16 Jump to CheckTerrainCollision_Position if A is less than 16.
48254 JR C,CheckTerrainCollision_Position
48256 SET 3,(IX+16) Set bit 3 of offset 16 of IX.
CheckTerrainCollision_Position 48260 LD (IX+8),0 Store 0 at offset 8 of IX.
48264 CALL FindHorizontalMove Call FindHorizontalMove.
48267 LD (IX+1),H The map column after the bounce.
48270 LD (IX+2),L The horizontal position after the bounce.
48273 LD HL,(47757) Fetch the word at 47757 into HL.
48276 LD (IX+7),L Restore the high byte of the old horizontal speed.
48279 LD (IX+8),H Restore the low byte of the old horizontal speed.
CheckTerrainCollision_Clear 48282 CALL ClearShot Call ClearShot.
48285 LD H,(IX+9) The high byte of the vertical speed.
48288 LD L,(IX+10) The low byte of the vertical speed.
48291 CALL ZeroSmallSpeed Call ZeroSmallSpeed.
48294 LD A,L The low byte of the vertical speed.
48295 OR H Set the bits of A that are set in H.
48296 JR NZ,CheckTerrainCollision_Finish Jump to CheckTerrainCollision_Finish if the zero flag is clear.
48298 LD H,(IX+7) The high byte of the horizontal speed.
48301 LD L,(IX+8) The low byte of the horizontal speed.
48304 CALL ZeroSmallSpeed Call ZeroSmallSpeed.
48307 LD (IX+8),L The low byte, once a tiny speed has been dropped.
48310 LD A,H The high byte of the horizontal speed.
48311 OR L Set the bits of A that are set in L.
48312 JR NZ,CheckTerrainCollision_Finish Jump to CheckTerrainCollision_Finish if the zero flag is clear.
48314 CALL CheckTerrainCollision_Flags2 Call CheckTerrainCollision_Flags2.
48317 JR CheckTerrainCollision_Finish Jump to CheckTerrainCollision_Finish.
CheckTerrainCollision_Flags2 48319 LD A,(23584) The slope flags.
48322 LD (IX+7),1 Store 1 at offset 7 of IX.
48326 AND %11000000 The two facing bits.
48328 RET Z Return if the zero flag is set.
48329 XOR %11000000 Flip the bits of A that are set in 192.
48331 RET Z Return if the zero flag is set.
48332 LD (IX+7),255 Store 255 at offset 7 of IX.
48336 RET Return.
CheckTerrainCollision_Finish 48337 LD A,(23589) The collision mode.
48340 AND A Jump to CheckTerrainCollision_Stop if A is zero.
48341 JP Z,CheckTerrainCollision_Stop
48344 XOR A Clear A.
48345 LD (52411),A Stop the horizontal scroll.
48348 LD (52410),A Stop the vertical scroll.
48351 LD A,(23616) The ship was just hit.
48354 AND A Jump to CheckTerrainCollision_Pending if A is not zero.
48355 JR NZ,CheckTerrainCollision_Pending
48357 LD A,(48146) The terrain-check flag.
48360 AND A Call PlayBumpSound if A is zero.
48361 CALL Z,PlayBumpSound
CheckTerrainCollision_Pending 48364 LD A,(48146) The terrain-check flag.
48367 AND A Jump to CheckTerrainCollision_Set if A is zero.
48368 JR Z,CheckTerrainCollision_Set
48370 CALL CheckTerrainCollision_Flags2 Call CheckTerrainCollision_Flags2.
48373 LD A,(IX+7) The high byte of the horizontal speed.
48376 ADD A,A Twice that speed.
48377 LD (52411),A The scroll follows the bounce.
CheckTerrainCollision_Set 48380 LD A,128 The check is finished.
48382 LD (48146),A Mark the check as finished.
48385 JP CheckTerrainCollision_Stop Jump to CheckTerrainCollision_Stop.
CheckTerrainCollision_Reflect 48388 XOR A Clear A.
CheckTerrainCollision_Patch 48389 LD (48406),A Choose whether the first speed is reversed.
48392 LD (48427),A Choose whether the second speed is reversed.
48395 LD IX,(47625) Fetch the word at 47625 into IX.
48399 LD H,(IX+7) The high byte of the horizontal speed.
48402 LD L,(IX+8) The low byte of the horizontal speed.
CheckTerrainCollision_PatchFirst 48405 JR CheckTerrainCollision_PatchFirst Jump to CheckTerrainCollision_PatchFirst.
48407 CALL CheckTerrainCollision_Negate Call CheckTerrainCollision_Negate.
48410 CALL LimitSpeed Call LimitSpeed.
48413 EX DE,HL Swap DE and HL.
48414 LD H,(IX+9) The high byte of the vertical speed.
48417 LD L,(IX+10) The low byte of the vertical speed.
48420 LD (IX+9),D The vertical speed takes the adjusted horizontal speed.
48423 LD (IX+10),E The low byte of that new vertical speed.
CheckTerrainCollision_PatchSecond 48426 JR CheckTerrainCollision_PatchSecond Jump to CheckTerrainCollision_PatchSecond.
48428 CALL CheckTerrainCollision_Negate Call CheckTerrainCollision_Negate.
CheckTerrainCollision_Horizontal 48431 CALL LimitSpeed Call LimitSpeed.
48434 LD (IX+7),H The horizontal speed takes the adjusted vertical speed.
48437 LD (IX+8),L The low byte of that new horizontal speed.
48440 JP CheckTerrainCollision_Bounce Jump to CheckTerrainCollision_Bounce.
CheckTerrainCollision_Three 48443 LD A,3 Steepness two does not reverse the speeds.
48445 JR CheckTerrainCollision_Patch Jump to CheckTerrainCollision_Patch.
CheckTerrainCollision_Negate 48447 LD A,H The high byte of the speed.
48448 NEG Negate A.
48450 LD H,A The speed is reversed.
48451 RET Return.
CheckTerrainCollision_Rebound 48452 XOR A Clear A.
48453 LD (48517),A Choose whether this speed is reversed.
48456 LD (48500),A Choose whether the other speed is reversed.
CheckTerrainCollision_ReboundStart 48459 LD A,(IX+4) The slope flags.
48462 LD C,A Keep the slope flags.
48463 AND %00000111 The steepness.
48465 PUSH AF Keep the steepness.
48466 LD IX,(47625) Fetch the word at 47625 into IX.
48470 CP 3 Call SwapSpeeds if A is 3.
48472 CALL Z,SwapSpeeds
48475 LD H,(IX+7) The high byte of the horizontal speed.
48478 LD L,(IX+8) The low byte of the horizontal speed.
48481 CALL TakeThreeEighths Call TakeThreeEighths.
48484 LD (23573),HL Three eighths of the horizontal speed.
48487 LD H,(IX+7) The horizontal speed again.
48490 LD L,(IX+8) The low byte again.
48493 CALL DoubleNumber Call DoubleNumber.
48496 CALL TakeThreeEighths Call TakeThreeEighths.
CheckTerrainCollision_PatchThird 48499 JR CheckTerrainCollision_PatchThird Jump to CheckTerrainCollision_PatchThird.
48501 CALL CheckTerrainCollision_ReboundNegate Call CheckTerrainCollision_ReboundNegate.
48504 LD (23575),HL The adjusted fraction of the doubled horizontal speed.
48507 LD H,(IX+9) The high byte of the vertical speed.
48510 LD L,(IX+10) The low byte of the vertical speed.
48513 CALL TakeThreeEighths Call TakeThreeEighths.
CheckTerrainCollision_PatchFourth 48516 JR CheckTerrainCollision_PatchFourth Jump to CheckTerrainCollision_PatchFourth.
48518 CALL CheckTerrainCollision_ReboundNegate Call CheckTerrainCollision_ReboundNegate.
48521 LD DE,(23573) Fetch the word at 23573 into DE.
48525 ADD HL,DE Add the saved fraction of the horizontal speed.
48526 CALL LimitSpeed Call LimitSpeed.
48529 LD (IX+7),H The new horizontal speed.
48532 LD (IX+8),L The low byte of the new horizontal speed.
48535 LD H,(IX+9) The vertical speed.
48538 LD L,(IX+10) The low byte of the vertical speed.
48541 CALL DoubleNumber Call DoubleNumber.
48544 CALL TakeThreeEighths Call TakeThreeEighths.
48547 CALL CheckTerrainCollision_ReboundNegate Call CheckTerrainCollision_ReboundNegate.
48550 LD DE,(23575) Fetch the word at 23575 into DE.
48554 ADD HL,DE Add the saved fraction of the doubled horizontal speed.
48555 CALL LimitSpeed Call LimitSpeed.
48558 LD (IX+9),H The new vertical speed.
48561 LD (IX+10),L The low byte of the new vertical speed.
48564 POP AF Back to the steepness.
48565 CP 3 Call SwapSpeeds if A is 3.
48567 CALL Z,SwapSpeeds
48570 JP CheckTerrainCollision_Bounce Jump to CheckTerrainCollision_Bounce.
CheckTerrainCollision_ReboundBoth 48573 LD A,3 This facing does not reverse the speeds.
48575 LD (48517),A This facing skips the first reverse.
48578 LD (48500),A This facing skips the second reverse.
48581 JP CheckTerrainCollision_ReboundStart Jump to CheckTerrainCollision_ReboundStart.
CheckTerrainCollision_ReboundNegate 48584 BIT 7,C Jump to NegateNumber if bit 7 of C is set.
48586 JP NZ,NegateNumber
48589 LD A,C The slope flags.
48590 AND %00000111 The steepness.
48592 CP 3 Jump to NegateNumber if A is 3.
48594 JP Z,NegateNumber
48597 JP CheckTerrainCollision_Negate Jump to CheckTerrainCollision_Negate.
SwapSpeeds 48600 LD H,(IX+7) The high byte of the horizontal speed.
48603 LD L,(IX+8) The low byte of the horizontal speed.
48606 LD D,(IX+9) The high byte of the vertical speed.
48609 LD E,(IX+10) The low byte of the vertical speed.
48612 LD (IX+7),D Swap the speeds: horizontal takes the vertical.
48615 LD (IX+8),E The low byte of the new horizontal speed.
48618 LD (IX+9),H Vertical takes the old horizontal speed.
48621 LD (IX+10),L The low byte of the new vertical speed.
48624 RET Return.
Prev: 47627 Up: Map Next: 48625