![]() |
Routines |
| Prev: BA0B | Up: Map | Next: BDF1 |
|
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 FF for the ship, 80 when the object should stop, and zero otherwise. The ship also plays the crash or bump sound and changes the scroll speed.
|
||||||||||||||||
| CheckTerrainCollision | BA21 | XOR A | Clear the hit flag. | |||||||||||||
| BA22 | LD ($5C1C),A | The hit flag at ScratchValue starts clear. | ||||||||||||||
| BA25 | LD ($BA09),IX | Keep the address of the object. | ||||||||||||||
| BA29 | CALL StartTerrainCheck | Find the tiles the object overlaps. | ||||||||||||||
| BA2C | JR CheckTerrainCollision_Tile | Test the first of those tiles. | ||||||||||||||
| CheckTerrainCollision_NextTiles | BA2E | CALL SelectNextTile | The next overlapping tile. | |||||||||||||
| CheckTerrainCollision_Tile | BA31 | LD A,(IX+$00) | The number of boxes in this tile. | |||||||||||||
| BA34 | AND A | None: on to the next tile. | ||||||||||||||
| BA35 | JR Z,CheckTerrainCollision_Done | |||||||||||||||
| BA37 | INC IX | The first box of the tile. | ||||||||||||||
| CheckTerrainCollision_Box | BA39 | PUSH IX | Keep the address of this box. | |||||||||||||
| BA3B | EX AF,AF' | The box count is in the alternate accumulator. | ||||||||||||||
| BA3C | XOR A | Clear the hit flag for this box. | ||||||||||||||
| BA3D | LD ($5C1C),A | The hit flag starts clear. | ||||||||||||||
| BA40 | LD A,(IX+$04) | The flags of this box. | ||||||||||||||
| BA43 | LD ($5C20),A | Keep the flags. | ||||||||||||||
| BA46 | AND %00111100 | Bits 2 to 5 mark a rectangle. | ||||||||||||||
| BA48 | JR NZ,CheckTerrainCollision_Rectangle | A rectangle is tested below. | ||||||||||||||
| BA4A | JP CheckTerrainCollision_Slope | Otherwise the box is a slope. | ||||||||||||||
| CheckTerrainCollision_Check | BA4D | LD A,($5C35) | The collision status. | |||||||||||||
| BA50 | BIT 6,A | Jump to CheckTerrainCollision_Stop if bit 6 of A is set. | ||||||||||||||
| BA52 | JR NZ,CheckTerrainCollision_Stop | |||||||||||||||
| CheckTerrainCollision_NextBox | BA54 | POP IX | Back to this box. | |||||||||||||
| BA56 | LD DE,$0005 | A box is five bytes. | ||||||||||||||
| BA59 | ADD IX,DE | The next box. | ||||||||||||||
| BA5B | EX AF,AF' | Back to the box count. | ||||||||||||||
| BA5C | DEC A | One box has been tested. | ||||||||||||||
| BA5D | JR NZ,CheckTerrainCollision_Box | Repeat while boxes remain. | ||||||||||||||
| CheckTerrainCollision_Done | BA5F | LD A,($5C1D) | The tiles still to test. | |||||||||||||
| BA62 | DEC A | One tile has been tested. | ||||||||||||||
| BA63 | LD ($5C1D),A | Remember how many tiles remain. | ||||||||||||||
| BA66 | JP NZ,CheckTerrainCollision_NextTiles | Jump to CheckTerrainCollision_NextTiles if the zero flag is clear. | ||||||||||||||
| BA69 | LD IX,($BA09) | Fetch the word at BA09 into IX. | ||||||||||||||
| BA6D | LD A,($5C25) | The collision mode. | ||||||||||||||
| BA70 | INC A | The ship is mode FF which becomes zero here. | ||||||||||||||
| BA71 | RET NZ | Return if the zero flag is clear. | ||||||||||||||
| BA72 | LD ($BC12),A | The ship has finished this check. | ||||||||||||||
| BA75 | RET | Return. | ||||||||||||||
| CheckTerrainCollision_Stop | BA76 | LD A,($8F53) | The ship state. | |||||||||||||
| BA79 | CP $0A | Jump to CheckTerrainCollision_Return if A is less than 0A. | ||||||||||||||
| BA7B | JR C,CheckTerrainCollision_Return | |||||||||||||||
| BA7D | LD A,($5C25) | The collision mode. | ||||||||||||||
| BA80 | AND A | Jump to CheckTerrainCollision_Return if A is not zero. | ||||||||||||||
| BA81 | JR NZ,CheckTerrainCollision_Return | |||||||||||||||
| BA83 | JP CheckTerrainCollision_NextBox | Jump to CheckTerrainCollision_NextBox. | ||||||||||||||
| CheckTerrainCollision_Return | BA86 | POP IX | Discard the box address. | |||||||||||||
| BA88 | LD IX,($BA09) | Fetch the word at BA09 into IX. | ||||||||||||||
| BA8C | RET | Return. | ||||||||||||||
| BA8D | NOP | Do nothing. | ||||||||||||||
| BA8E | NOP | Do nothing. | ||||||||||||||
| CheckTerrainCollision_Rectangle | BA8F | LD A,($5C35) | The collision status. | |||||||||||||
| BA92 | BIT 7,A | Jump to CheckTerrainCollision_Check if bit 7 of A is set. | ||||||||||||||
| BA94 | JP NZ,CheckTerrainCollision_Check | |||||||||||||||
| BA97 | LD HL,($CE3A) | Fetch the word at ScratchValues into HL. | ||||||||||||||
| BA9A | LD A,($5C25) | The collision mode. | ||||||||||||||
| BA9D | CP $80 | Jump to CheckTerrainCollision_Test if A is 80. | ||||||||||||||
| BA9F | JR Z,CheckTerrainCollision_Test | |||||||||||||||
| BAA1 | LD A,($5C25) | The collision mode again. | ||||||||||||||
| BAA4 | INC A | The ship is the only object tested here. | ||||||||||||||
| BAA5 | JP NZ,CheckTerrainCollision_Flags | Jump to CheckTerrainCollision_Flags if the zero flag is clear. | ||||||||||||||
| BAA8 | LD A,L | The low byte of the position in the tile. | ||||||||||||||
| BAA9 | ADD A,$04 | Add 04 to A. | ||||||||||||||
| BAAB | CP $E8 | Jump to CheckTerrainCollision_Limit if A is less than E8. | ||||||||||||||
| BAAD | JR C,CheckTerrainCollision_Limit | |||||||||||||||
| BAAF | LD A,$E8 | Do not test past column E8. | ||||||||||||||
| CheckTerrainCollision_Limit | BAB1 | LD D,A | The near edge of the test. | |||||||||||||
| BAB2 | ADD A,$24 | Add 24 to A. | ||||||||||||||
| BAB4 | JR NC,CheckTerrainCollision_Lower | Jump to CheckTerrainCollision_Lower if the carry flag is clear. | ||||||||||||||
| BAB6 | LD A,$F8 | Do not test past column F8. | ||||||||||||||
| CheckTerrainCollision_Lower | BAB8 | LD E,A | The far edge of the test. | |||||||||||||
| BAB9 | BIT 2,(IX+$04) | Jump to CheckTerrainCollision_Flags if bit 2 of offset 04 of IX is clear. | ||||||||||||||
| BABD | JR Z,CheckTerrainCollision_Flags | |||||||||||||||
| BABF | LD A,($F5EF) | The second part flag. | ||||||||||||||
| BAC2 | AND A | Jump to CheckTerrainCollision_Flags if A is not zero. | ||||||||||||||
| BAC3 | JR NZ,CheckTerrainCollision_Flags | |||||||||||||||
| BAC5 | LD A,(IX+$01) | The box's other coordinate. | ||||||||||||||
| BAC8 | SUB H | Subtract H from A. | ||||||||||||||
| BAC9 | JR C,CheckTerrainCollision_Flags | Jump to CheckTerrainCollision_Flags if the carry flag is set. | ||||||||||||||
| BACB | CP $29 | Jump to CheckTerrainCollision_Flags if A is 29 or more. | ||||||||||||||
| BACD | JR NC,CheckTerrainCollision_Flags | |||||||||||||||
| BACF | LD A,(IX+$00) | The box's first coordinate. | ||||||||||||||
| BAD2 | CP E | Jump to CheckTerrainCollision_Flags if A is E or more. | ||||||||||||||
| BAD3 | JR NC,CheckTerrainCollision_Flags | |||||||||||||||
| BAD5 | ADD A,(IX+$02) | Add the byte at offset 02 of IX to A. | ||||||||||||||
| BAD8 | CP D | Jump to CheckTerrainCollision_Flags if A is less than D. | ||||||||||||||
| BAD9 | JR C,CheckTerrainCollision_Flags | |||||||||||||||
| BADB | LD ($C6D0),A | The ship has landed on this box. | ||||||||||||||
| CheckTerrainCollision_Flags | BADE | LD A,(IX+$04) | The box flags. | |||||||||||||
| BAE1 | AND %00110000 | Bits 4 and 5 select a sideways face. | ||||||||||||||
| BAE3 | JR NZ,CheckTerrainCollision_Test2 | Jump to CheckTerrainCollision_Test2 if the zero flag is clear. | ||||||||||||||
| BAE5 | LD A,($BE8E) | The saved vertical speed. | ||||||||||||||
| BAE8 | AND A | Jump to CheckTerrainCollision_Test if A is zero. | ||||||||||||||
| BAE9 | JR Z,CheckTerrainCollision_Test | |||||||||||||||
| BAEB | BIT 2,(IX+$04) | Jump to CheckTerrainCollision_Skip if bit 2 of offset 04 of IX is set. | ||||||||||||||
| BAEF | JR NZ,CheckTerrainCollision_Skip | |||||||||||||||
| BAF1 | NEG | Negate A. | ||||||||||||||
| CheckTerrainCollision_Skip | BAF3 | BIT 7,A | Jump to CheckTerrainCollision_Check if bit 7 of A is set. | |||||||||||||
| BAF5 | JP NZ,CheckTerrainCollision_Check | |||||||||||||||
| BAF8 | JR CheckTerrainCollision_Test | Jump to CheckTerrainCollision_Test. | ||||||||||||||
| CheckTerrainCollision_Test2 | BAFA | BIT 4,A | Test bit 4 of A. | |||||||||||||
| BAFC | LD A,($BE8D) | The saved horizontal speed. | ||||||||||||||
| BAFF | JR NZ,CheckTerrainCollision_Check2 | Jump to CheckTerrainCollision_Check2 if the zero flag is clear. | ||||||||||||||
| BB01 | NEG | Negate A. | ||||||||||||||
| CheckTerrainCollision_Check2 | BB03 | AND A | Jump to CheckTerrainCollision_Test if A is zero. | |||||||||||||
| BB04 | JR Z,CheckTerrainCollision_Test | |||||||||||||||
| BB06 | BIT 7,A | Jump to CheckTerrainCollision_Check if bit 7 of A is clear. | ||||||||||||||
| BB08 | JP Z,CheckTerrainCollision_Check | |||||||||||||||
| BB0B | JR CheckTerrainCollision_Test | Jump to CheckTerrainCollision_Test. | ||||||||||||||
| CheckTerrainCollision_Test | BB0D | LD DE,($CE3C) | Fetch the word at CE3C into DE. | |||||||||||||
| BB11 | CALL TestBoxesOverlap | Call TestBoxesOverlap. | ||||||||||||||
| BB14 | LD A,($5C1C) | The hit flag from the rectangle test. | ||||||||||||||
| BB17 | AND A | Jump to CheckTerrainCollision_Check if A is zero. | ||||||||||||||
| BB18 | JP Z,CheckTerrainCollision_Check | |||||||||||||||
| BB1B | LD A,($5C25) | The collision mode. | ||||||||||||||
| BB1E | CP $80 | Jump to CheckTerrainCollision_Stop if A is 80. | ||||||||||||||
| BB20 | JP Z,CheckTerrainCollision_Stop | |||||||||||||||
| BB23 | LD A,$80 | A rectangle hit is marked with 80. | ||||||||||||||
| BB25 | LD ($5C35),A | Remember that hit in the collision status. | ||||||||||||||
| BB28 | LD A,(IX+$01) | The box's second coordinate. | ||||||||||||||
| BB2B | SUB $14 | Subtract 14 from A. | ||||||||||||||
| BB2D | LD ($DEDC),A | Keep that coordinate. | ||||||||||||||
| BB30 | LD A,(IX+$04) | The box flags again. | ||||||||||||||
| BB33 | LD ($DEDD),A | Keep the box flags. | ||||||||||||||
| BB36 | LD B,A | The flags, kept for the bounce. | ||||||||||||||
| BB37 | AND %00110000 | Bits 4 and 5 mean the face is sideways. | ||||||||||||||
| BB39 | LD IX,($BA09) | Fetch the word at BA09 into IX. | ||||||||||||||
| BB3D | JP NZ,CheckTerrainCollision_Wall | Jump to CheckTerrainCollision_Wall if the zero flag is clear. | ||||||||||||||
| BB40 | LD A,($5C25) | The collision mode. | ||||||||||||||
| BB43 | AND A | Jump to CheckTerrainCollision_Free if A is zero. | ||||||||||||||
| BB44 | JR Z,CheckTerrainCollision_Free | |||||||||||||||
| BB46 | BIT 3,B | Jump to CheckTerrainCollision_Vertical if bit 3 of B is clear. | ||||||||||||||
| BB48 | JR Z,CheckTerrainCollision_Vertical | |||||||||||||||
| BB4A | LD A,($F5F6) | The ninth part flag. | ||||||||||||||
| BB4D | AND A | Jump to CheckTerrainCollision_Vertical if A is not zero. | ||||||||||||||
| BB4E | JR NZ,CheckTerrainCollision_Vertical | |||||||||||||||
| BB50 | LD A,$04 | Four frames of the hit flash. | ||||||||||||||
| BB52 | LD ($C7C1),A | Start the hit flash. | ||||||||||||||
| BB55 | JR CheckTerrainCollision_Vertical | Jump to CheckTerrainCollision_Vertical. | ||||||||||||||
| CheckTerrainCollision_Free | BB57 | CALL ClearShot | Call ClearShot. | |||||||||||||
| BB5A | BIT 3,B | Jump to CheckTerrainCollision_Vertical if bit 3 of B is set. | ||||||||||||||
| BB5C | JR NZ,CheckTerrainCollision_Vertical | |||||||||||||||
| BB5E | LD A,($DEDC) | The coordinate the object should stand on. | ||||||||||||||
| BB61 | LD (IX+$05),A | Put the object on that row. | ||||||||||||||
| CheckTerrainCollision_Vertical | BB64 | LD H,(IX+$09) | The high byte of the vertical speed. | |||||||||||||
| BB67 | LD L,(IX+$0A) | The low byte of the vertical speed. | ||||||||||||||
| BB6A | CALL NegateNumber | Call NegateNumber. | ||||||||||||||
| BB6D | CALL HalveNumber | Call HalveNumber. | ||||||||||||||
| BB70 | CALL LimitSpeed | Call LimitSpeed. | ||||||||||||||
| BB73 | CALL ZeroSmallSpeed | Call ZeroSmallSpeed. | ||||||||||||||
| CheckTerrainCollision_StoreVertical | BB76 | LD (IX+$09),H | The bounced vertical speed. | |||||||||||||
| BB79 | LD (IX+$0A),L | The low byte of the bounced vertical speed. | ||||||||||||||
| BB7C | LD A,H | The high byte of that speed. | ||||||||||||||
| BB7D | LD ($BE8E),A | Keep it for the next box. | ||||||||||||||
| BB80 | OR L | Set the bits of A that are set in L. | ||||||||||||||
| BB81 | JR Z,CheckTerrainCollision_Still | Jump to CheckTerrainCollision_Still if the zero flag is set. | ||||||||||||||
| BB83 | LD A,($5C35) | The collision status. | ||||||||||||||
| BB86 | OR %01000000 | Set the bits of A that are set in 40. | ||||||||||||||
| BB88 | LD ($5C35),A | Note that the object is still moving vertically. | ||||||||||||||
| BB8B | JR CheckTerrainCollision_Ship | Jump to CheckTerrainCollision_Ship. | ||||||||||||||
| CheckTerrainCollision_Still | BB8D | LD A,($5C25) | The collision mode. | |||||||||||||
| BB90 | INC A | See whether this is the ship. | ||||||||||||||
| BB91 | JR Z,CheckTerrainCollision_Ship | Jump to CheckTerrainCollision_Ship if the zero flag is set. | ||||||||||||||
| BB93 | BIT 3,B | Jump to CheckTerrainCollision_Check if bit 3 of B is clear. | ||||||||||||||
| BB95 | JP Z,CheckTerrainCollision_Check | |||||||||||||||
| BB98 | LD (IX+$09),$FE | Store FE at offset 09 of IX. | ||||||||||||||
| CheckTerrainCollision_Ship | BB9C | LD A,($5C25) | The collision mode. | |||||||||||||
| BB9F | INC A | The ship is mode FF. | ||||||||||||||
| BBA0 | JP NZ,CheckTerrainCollision_Check | Jump to CheckTerrainCollision_Check if the zero flag is clear. | ||||||||||||||
| BBA3 | LD A,L | The low byte of the bounced speed. | ||||||||||||||
| BBA4 | OR H | Set the bits of A that are set in H. | ||||||||||||||
| BBA5 | CALL NZ,PlayCrashSound | Call PlayCrashSound if the zero flag is clear. | ||||||||||||||
| BBA8 | LD DE,$0000 | No fractional vertical scroll. | ||||||||||||||
| BBAB | LD ($B320),DE | Clear the vertical scroll fraction. | ||||||||||||||
| BBAF | CALL UpdateVerticalScrollSpeed | Call UpdateVerticalScrollSpeed. | ||||||||||||||
| BBB2 | LD A,($DEDD) | The box flags that were hit. | ||||||||||||||
| BBB5 | CP $04 | Jump to CheckTerrainCollision_Check if A is not 04. | ||||||||||||||
| BBB7 | JP NZ,CheckTerrainCollision_Check | |||||||||||||||
| BBBA | LD A,($C8EA) | The ship's map zone. | ||||||||||||||
| BBBD | LD B,A | Keep the map zone. | ||||||||||||||
| BBBE | LD A,($DEDC) | The box coordinate. | ||||||||||||||
| BBC1 | CP B | Jump to CheckTerrainCollision_Check if A is B or more. | ||||||||||||||
| BBC2 | JP NC,CheckTerrainCollision_Check | |||||||||||||||
| BBC5 | LD A,$02 | A small downward scroll. | ||||||||||||||
| BBC7 | LD ($CCBA),A | Scroll the world down by two. | ||||||||||||||
| BBCA | JP CheckTerrainCollision_Check | Jump to CheckTerrainCollision_Check. | ||||||||||||||
| CheckTerrainCollision_Wall | BBCD | LD H,(IX+$07) | The high byte of the horizontal speed. | |||||||||||||
| BBD0 | LD L,(IX+$08) | The low byte of the horizontal speed. | ||||||||||||||
| BBD3 | CALL NegateNumber | Call NegateNumber. | ||||||||||||||
| BBD6 | LD A,($5C25) | The collision mode. | ||||||||||||||
| BBD9 | AND A | Jump to CheckTerrainCollision_Update if A is not zero. | ||||||||||||||
| BBDA | JR NZ,CheckTerrainCollision_Update | |||||||||||||||
| BBDC | CALL ClearShot | Call ClearShot. | ||||||||||||||
| BBDF | JR CheckTerrainCollision_StoreHorizontal | Jump to CheckTerrainCollision_StoreHorizontal. | ||||||||||||||
| CheckTerrainCollision_Update | BBE1 | CALL HalveNumber | Call HalveNumber. | |||||||||||||
| BBE4 | CALL LimitSpeed | Call LimitSpeed. | ||||||||||||||
| BBE7 | CALL ZeroSmallSpeed | Call ZeroSmallSpeed. | ||||||||||||||
| CheckTerrainCollision_StoreHorizontal | BBEA | LD (IX+$07),H | The bounced horizontal speed. | |||||||||||||
| BBED | LD (IX+$08),L | The low byte of the bounced horizontal speed. | ||||||||||||||
| BBF0 | LD A,H | The high byte of that speed. | ||||||||||||||
| BBF1 | LD ($BE8D),A | Keep it for the next box. | ||||||||||||||
| BBF4 | LD A,($5C25) | The collision mode. | ||||||||||||||
| BBF7 | INC A | The ship is mode FF. | ||||||||||||||
| BBF8 | JP NZ,CheckTerrainCollision_Check | Jump to CheckTerrainCollision_Check if the zero flag is clear. | ||||||||||||||
| BBFB | LD A,L | The low byte of the bounced speed. | ||||||||||||||
| BBFC | OR H | Set the bits of A that are set in H. | ||||||||||||||
| BBFD | CALL NZ,PlayBumpSound | Call PlayBumpSound if the zero flag is clear. | ||||||||||||||
| BC00 | LD DE,$0000 | No fractional horizontal scroll. | ||||||||||||||
| BC03 | LD ($C7FA),DE | Clear the horizontal scroll fraction. | ||||||||||||||
| BC07 | CALL UpdateHorizontalScrollSpeed | Call UpdateHorizontalScrollSpeed. | ||||||||||||||
| BC0A | LD A,$01 | The ship has hit a wall. | ||||||||||||||
| BC0C | LD ($D0BC),A | The collision kind is the terrain. | ||||||||||||||
| BC0F | JP CheckTerrainCollision_Check | Jump to CheckTerrainCollision_Check. | ||||||||||||||
| BC12 | NOP | Do nothing. | ||||||||||||||
| CheckTerrainCollision_Slope | BC13 | LD A,($5C35) | The collision status. | |||||||||||||
| BC16 | BIT 4,A | Jump to CheckTerrainCollision_Check if bit 4 of A is set. | ||||||||||||||
| BC18 | JP NZ,CheckTerrainCollision_Check | |||||||||||||||
| BC1B | CALL TestSlopeCollision | Call TestSlopeCollision. | ||||||||||||||
| BC1E | LD A,($5C1C) | The hit flag from the slope test. | ||||||||||||||
| BC21 | AND A | Jump to CheckTerrainCollision_Check if A is zero. | ||||||||||||||
| BC22 | JP Z,CheckTerrainCollision_Check | |||||||||||||||
| BC25 | LD A,($5C35) | The collision status. | ||||||||||||||
| BC28 | OR %00010000 | Set the bits of A that are set in 10. | ||||||||||||||
| BC2A | LD ($5C35),A | Note that a slope has been hit. | ||||||||||||||
| BC2D | LD A,($5C25) | The collision mode. | ||||||||||||||
| BC30 | CP $80 | Jump to CheckTerrainCollision_Stop if A is 80. | ||||||||||||||
| BC32 | JP Z,CheckTerrainCollision_Stop | |||||||||||||||
| BC35 | AND A | Jump to CheckTerrainCollision_Kind if A is zero. | ||||||||||||||
| BC36 | JR Z,CheckTerrainCollision_Kind | |||||||||||||||
| BC38 | DEC A | One less than the mode. | ||||||||||||||
| BC39 | LD ($D0BC),A | The collision kind follows the mode. | ||||||||||||||
| CheckTerrainCollision_Kind | BC3C | LD A,(IX+$04) | The slope flags. | |||||||||||||
| BC3F | LD ($5C20),A | Keep the slope flags. | ||||||||||||||
| BC42 | AND %01111111 | The steepness and the facing, without bit 7. | ||||||||||||||
| BC44 | CP $02 | Jump to CheckTerrainCollision_Reflect if A is 02. | ||||||||||||||
| BC46 | JP Z,CheckTerrainCollision_Reflect | |||||||||||||||
| BC49 | AND %00000111 | The steepness. | ||||||||||||||
| BC4B | CP $02 | Jump to CheckTerrainCollision_Three if A is 02. | ||||||||||||||
| BC4D | JP Z,CheckTerrainCollision_Three | |||||||||||||||
| BC50 | LD A,(IX+$04) | The slope flags again. | ||||||||||||||
| BC53 | BIT 6,A | Jump to CheckTerrainCollision_Rebound if bit 6 of A is clear. | ||||||||||||||
| BC55 | JP Z,CheckTerrainCollision_Rebound | |||||||||||||||
| BC58 | JP CheckTerrainCollision_ReboundBoth | Jump to CheckTerrainCollision_ReboundBoth. | ||||||||||||||
| CheckTerrainCollision_Bounce | BC5B | LD IX,($BA09) | Fetch the word at BA09 into IX. | |||||||||||||
| BC5F | LD A,($5C25) | The collision mode. | ||||||||||||||
| BC62 | INC A | See whether this is the ship. | ||||||||||||||
| BC63 | JR Z,CheckTerrainCollision_Clear | Jump to CheckTerrainCollision_Clear if the zero flag is set. | ||||||||||||||
| BC65 | LD L,(IX+$07) | The high byte of the horizontal speed, kept in L. | ||||||||||||||
| BC68 | LD H,(IX+$08) | The low byte of the horizontal speed, kept in H. | ||||||||||||||
| BC6B | LD ($BA8D),HL | Keep the old horizontal speed. | ||||||||||||||
| BC6E | LD A,($5C1A) | How far the object went into the slope. | ||||||||||||||
| BC71 | NEG | Negate A. | ||||||||||||||
| BC73 | LD (IX+$07),A | The horizontal speed becomes that depth, reversed. | ||||||||||||||
| BC76 | BIT 7,A | Jump to CheckTerrainCollision_Speed if bit 7 of A is clear. | ||||||||||||||
| BC78 | JR Z,CheckTerrainCollision_Speed | |||||||||||||||
| BC7A | NEG | Negate A. | ||||||||||||||
| CheckTerrainCollision_Speed | BC7C | CP $10 | Jump to CheckTerrainCollision_Position if A is less than 10. | |||||||||||||
| BC7E | JR C,CheckTerrainCollision_Position | |||||||||||||||
| BC80 | SET 3,(IX+$10) | Set bit 3 of offset 10 of IX. | ||||||||||||||
| CheckTerrainCollision_Position | BC84 | LD (IX+$08),$00 | Store 00 at offset 08 of IX. | |||||||||||||
| BC88 | CALL FindHorizontalMove | Call FindHorizontalMove. | ||||||||||||||
| BC8B | LD (IX+$01),H | The map column after the bounce. | ||||||||||||||
| BC8E | LD (IX+$02),L | The horizontal position after the bounce. | ||||||||||||||
| BC91 | LD HL,($BA8D) | Fetch the word at BA8D into HL. | ||||||||||||||
| BC94 | LD (IX+$07),L | Restore the high byte of the old horizontal speed. | ||||||||||||||
| BC97 | LD (IX+$08),H | Restore the low byte of the old horizontal speed. | ||||||||||||||
| CheckTerrainCollision_Clear | BC9A | CALL ClearShot | Call ClearShot. | |||||||||||||
| BC9D | LD H,(IX+$09) | The high byte of the vertical speed. | ||||||||||||||
| BCA0 | LD L,(IX+$0A) | The low byte of the vertical speed. | ||||||||||||||
| BCA3 | CALL ZeroSmallSpeed | Call ZeroSmallSpeed. | ||||||||||||||
| BCA6 | LD A,L | The low byte of the vertical speed. | ||||||||||||||
| BCA7 | OR H | Set the bits of A that are set in H. | ||||||||||||||
| BCA8 | JR NZ,CheckTerrainCollision_Finish | Jump to CheckTerrainCollision_Finish if the zero flag is clear. | ||||||||||||||
| BCAA | LD H,(IX+$07) | The high byte of the horizontal speed. | ||||||||||||||
| BCAD | LD L,(IX+$08) | The low byte of the horizontal speed. | ||||||||||||||
| BCB0 | CALL ZeroSmallSpeed | Call ZeroSmallSpeed. | ||||||||||||||
| BCB3 | LD (IX+$08),L | The low byte, once a tiny speed has been dropped. | ||||||||||||||
| BCB6 | LD A,H | The high byte of the horizontal speed. | ||||||||||||||
| BCB7 | OR L | Set the bits of A that are set in L. | ||||||||||||||
| BCB8 | JR NZ,CheckTerrainCollision_Finish | Jump to CheckTerrainCollision_Finish if the zero flag is clear. | ||||||||||||||
| BCBA | CALL CheckTerrainCollision_Flags2 | Call CheckTerrainCollision_Flags2. | ||||||||||||||
| BCBD | JR CheckTerrainCollision_Finish | Jump to CheckTerrainCollision_Finish. | ||||||||||||||
| CheckTerrainCollision_Flags2 | BCBF | LD A,($5C20) | The slope flags. | |||||||||||||
| BCC2 | LD (IX+$07),$01 | Store 01 at offset 07 of IX. | ||||||||||||||
| BCC6 | AND %11000000 | The two facing bits. | ||||||||||||||
| BCC8 | RET Z | Return if the zero flag is set. | ||||||||||||||
| BCC9 | XOR %11000000 | Flip the bits of A that are set in C0. | ||||||||||||||
| BCCB | RET Z | Return if the zero flag is set. | ||||||||||||||
| BCCC | LD (IX+$07),$FF | Store FF at offset 07 of IX. | ||||||||||||||
| BCD0 | RET | Return. | ||||||||||||||
| CheckTerrainCollision_Finish | BCD1 | LD A,($5C25) | The collision mode. | |||||||||||||
| BCD4 | AND A | Jump to CheckTerrainCollision_Stop if A is zero. | ||||||||||||||
| BCD5 | JP Z,CheckTerrainCollision_Stop | |||||||||||||||
| BCD8 | XOR A | Clear A. | ||||||||||||||
| BCD9 | LD ($CCBB),A | Stop the horizontal scroll. | ||||||||||||||
| BCDC | LD ($CCBA),A | Stop the vertical scroll. | ||||||||||||||
| BCDF | LD A,($5C40) | The ship was just hit. | ||||||||||||||
| BCE2 | AND A | Jump to CheckTerrainCollision_Pending if A is not zero. | ||||||||||||||
| BCE3 | JR NZ,CheckTerrainCollision_Pending | |||||||||||||||
| BCE5 | LD A,($BC12) | The terrain-check flag. | ||||||||||||||
| BCE8 | AND A | Call PlayBumpSound if A is zero. | ||||||||||||||
| BCE9 | CALL Z,PlayBumpSound | |||||||||||||||
| CheckTerrainCollision_Pending | BCEC | LD A,($BC12) | The terrain-check flag. | |||||||||||||
| BCEF | AND A | Jump to CheckTerrainCollision_Set if A is zero. | ||||||||||||||
| BCF0 | JR Z,CheckTerrainCollision_Set | |||||||||||||||
| BCF2 | CALL CheckTerrainCollision_Flags2 | Call CheckTerrainCollision_Flags2. | ||||||||||||||
| BCF5 | LD A,(IX+$07) | The high byte of the horizontal speed. | ||||||||||||||
| BCF8 | ADD A,A | Twice that speed. | ||||||||||||||
| BCF9 | LD ($CCBB),A | The scroll follows the bounce. | ||||||||||||||
| CheckTerrainCollision_Set | BCFC | LD A,$80 | The check is finished. | |||||||||||||
| BCFE | LD ($BC12),A | Mark the check as finished. | ||||||||||||||
| BD01 | JP CheckTerrainCollision_Stop | Jump to CheckTerrainCollision_Stop. | ||||||||||||||
| CheckTerrainCollision_Reflect | BD04 | XOR A | Clear A. | |||||||||||||
| CheckTerrainCollision_Patch | BD05 | LD ($BD16),A | Choose whether the first speed is reversed. | |||||||||||||
| BD08 | LD ($BD2B),A | Choose whether the second speed is reversed. | ||||||||||||||
| BD0B | LD IX,($BA09) | Fetch the word at BA09 into IX. | ||||||||||||||
| BD0F | LD H,(IX+$07) | The high byte of the horizontal speed. | ||||||||||||||
| BD12 | LD L,(IX+$08) | The low byte of the horizontal speed. | ||||||||||||||
| CheckTerrainCollision_PatchFirst | BD15 | JR CheckTerrainCollision_PatchFirst | Jump to CheckTerrainCollision_PatchFirst. | |||||||||||||
| BD17 | CALL CheckTerrainCollision_Negate | Call CheckTerrainCollision_Negate. | ||||||||||||||
| BD1A | CALL LimitSpeed | Call LimitSpeed. | ||||||||||||||
| BD1D | EX DE,HL | Swap DE and HL. | ||||||||||||||
| BD1E | LD H,(IX+$09) | The high byte of the vertical speed. | ||||||||||||||
| BD21 | LD L,(IX+$0A) | The low byte of the vertical speed. | ||||||||||||||
| BD24 | LD (IX+$09),D | The vertical speed takes the adjusted horizontal speed. | ||||||||||||||
| BD27 | LD (IX+$0A),E | The low byte of that new vertical speed. | ||||||||||||||
| CheckTerrainCollision_PatchSecond | BD2A | JR CheckTerrainCollision_PatchSecond | Jump to CheckTerrainCollision_PatchSecond. | |||||||||||||
| BD2C | CALL CheckTerrainCollision_Negate | Call CheckTerrainCollision_Negate. | ||||||||||||||
| CheckTerrainCollision_Horizontal | BD2F | CALL LimitSpeed | Call LimitSpeed. | |||||||||||||
| BD32 | LD (IX+$07),H | The horizontal speed takes the adjusted vertical speed. | ||||||||||||||
| BD35 | LD (IX+$08),L | The low byte of that new horizontal speed. | ||||||||||||||
| BD38 | JP CheckTerrainCollision_Bounce | Jump to CheckTerrainCollision_Bounce. | ||||||||||||||
| CheckTerrainCollision_Three | BD3B | LD A,$03 | Steepness two does not reverse the speeds. | |||||||||||||
| BD3D | JR CheckTerrainCollision_Patch | Jump to CheckTerrainCollision_Patch. | ||||||||||||||
| CheckTerrainCollision_Negate | BD3F | LD A,H | The high byte of the speed. | |||||||||||||
| BD40 | NEG | Negate A. | ||||||||||||||
| BD42 | LD H,A | The speed is reversed. | ||||||||||||||
| BD43 | RET | Return. | ||||||||||||||
| CheckTerrainCollision_Rebound | BD44 | XOR A | Clear A. | |||||||||||||
| BD45 | LD ($BD85),A | Choose whether this speed is reversed. | ||||||||||||||
| BD48 | LD ($BD74),A | Choose whether the other speed is reversed. | ||||||||||||||
| CheckTerrainCollision_ReboundStart | BD4B | LD A,(IX+$04) | The slope flags. | |||||||||||||
| BD4E | LD C,A | Keep the slope flags. | ||||||||||||||
| BD4F | AND %00000111 | The steepness. | ||||||||||||||
| BD51 | PUSH AF | Keep the steepness. | ||||||||||||||
| BD52 | LD IX,($BA09) | Fetch the word at BA09 into IX. | ||||||||||||||
| BD56 | CP $03 | Call SwapSpeeds if A is 03. | ||||||||||||||
| BD58 | CALL Z,SwapSpeeds | |||||||||||||||
| BD5B | LD H,(IX+$07) | The high byte of the horizontal speed. | ||||||||||||||
| BD5E | LD L,(IX+$08) | The low byte of the horizontal speed. | ||||||||||||||
| BD61 | CALL TakeThreeEighths | Call TakeThreeEighths. | ||||||||||||||
| BD64 | LD ($5C15),HL | Three eighths of the horizontal speed. | ||||||||||||||
| BD67 | LD H,(IX+$07) | The horizontal speed again. | ||||||||||||||
| BD6A | LD L,(IX+$08) | The low byte again. | ||||||||||||||
| BD6D | CALL DoubleNumber | Call DoubleNumber. | ||||||||||||||
| BD70 | CALL TakeThreeEighths | Call TakeThreeEighths. | ||||||||||||||
| CheckTerrainCollision_PatchThird | BD73 | JR CheckTerrainCollision_PatchThird | Jump to CheckTerrainCollision_PatchThird. | |||||||||||||
| BD75 | CALL CheckTerrainCollision_ReboundNegate | Call CheckTerrainCollision_ReboundNegate. | ||||||||||||||
| BD78 | LD ($5C17),HL | The adjusted fraction of the doubled horizontal speed. | ||||||||||||||
| BD7B | LD H,(IX+$09) | The high byte of the vertical speed. | ||||||||||||||
| BD7E | LD L,(IX+$0A) | The low byte of the vertical speed. | ||||||||||||||
| BD81 | CALL TakeThreeEighths | Call TakeThreeEighths. | ||||||||||||||
| CheckTerrainCollision_PatchFourth | BD84 | JR CheckTerrainCollision_PatchFourth | Jump to CheckTerrainCollision_PatchFourth. | |||||||||||||
| BD86 | CALL CheckTerrainCollision_ReboundNegate | Call CheckTerrainCollision_ReboundNegate. | ||||||||||||||
| BD89 | LD DE,($5C15) | Fetch the word at 5C15 into DE. | ||||||||||||||
| BD8D | ADD HL,DE | Add the saved fraction of the horizontal speed. | ||||||||||||||
| BD8E | CALL LimitSpeed | Call LimitSpeed. | ||||||||||||||
| BD91 | LD (IX+$07),H | The new horizontal speed. | ||||||||||||||
| BD94 | LD (IX+$08),L | The low byte of the new horizontal speed. | ||||||||||||||
| BD97 | LD H,(IX+$09) | The vertical speed. | ||||||||||||||
| BD9A | LD L,(IX+$0A) | The low byte of the vertical speed. | ||||||||||||||
| BD9D | CALL DoubleNumber | Call DoubleNumber. | ||||||||||||||
| BDA0 | CALL TakeThreeEighths | Call TakeThreeEighths. | ||||||||||||||
| BDA3 | CALL CheckTerrainCollision_ReboundNegate | Call CheckTerrainCollision_ReboundNegate. | ||||||||||||||
| BDA6 | LD DE,($5C17) | Fetch the word at 5C17 into DE. | ||||||||||||||
| BDAA | ADD HL,DE | Add the saved fraction of the doubled horizontal speed. | ||||||||||||||
| BDAB | CALL LimitSpeed | Call LimitSpeed. | ||||||||||||||
| BDAE | LD (IX+$09),H | The new vertical speed. | ||||||||||||||
| BDB1 | LD (IX+$0A),L | The low byte of the new vertical speed. | ||||||||||||||
| BDB4 | POP AF | Back to the steepness. | ||||||||||||||
| BDB5 | CP $03 | Call SwapSpeeds if A is 03. | ||||||||||||||
| BDB7 | CALL Z,SwapSpeeds | |||||||||||||||
| BDBA | JP CheckTerrainCollision_Bounce | Jump to CheckTerrainCollision_Bounce. | ||||||||||||||
| CheckTerrainCollision_ReboundBoth | BDBD | LD A,$03 | This facing does not reverse the speeds. | |||||||||||||
| BDBF | LD ($BD85),A | This facing skips the first reverse. | ||||||||||||||
| BDC2 | LD ($BD74),A | This facing skips the second reverse. | ||||||||||||||
| BDC5 | JP CheckTerrainCollision_ReboundStart | Jump to CheckTerrainCollision_ReboundStart. | ||||||||||||||
| CheckTerrainCollision_ReboundNegate | BDC8 | BIT 7,C | Jump to NegateNumber if bit 7 of C is set. | |||||||||||||
| BDCA | JP NZ,NegateNumber | |||||||||||||||
| BDCD | LD A,C | The slope flags. | ||||||||||||||
| BDCE | AND %00000111 | The steepness. | ||||||||||||||
| BDD0 | CP $03 | Jump to NegateNumber if A is 03. | ||||||||||||||
| BDD2 | JP Z,NegateNumber | |||||||||||||||
| BDD5 | JP CheckTerrainCollision_Negate | Jump to CheckTerrainCollision_Negate. | ||||||||||||||
| SwapSpeeds | BDD8 | LD H,(IX+$07) | The high byte of the horizontal speed. | |||||||||||||
| BDDB | LD L,(IX+$08) | The low byte of the horizontal speed. | ||||||||||||||
| BDDE | LD D,(IX+$09) | The high byte of the vertical speed. | ||||||||||||||
| BDE1 | LD E,(IX+$0A) | The low byte of the vertical speed. | ||||||||||||||
| BDE4 | LD (IX+$07),D | Swap the speeds: horizontal takes the vertical. | ||||||||||||||
| BDE7 | LD (IX+$08),E | The low byte of the new horizontal speed. | ||||||||||||||
| BDEA | LD (IX+$09),H | Vertical takes the old horizontal speed. | ||||||||||||||
| BDED | LD (IX+$0A),L | The low byte of the new vertical speed. | ||||||||||||||
| BDF0 | RET | Return. | ||||||||||||||
| Prev: BA0B | Up: Map | Next: BDF1 |