| ← 9B23 | Map | 9B67 → |
9B28: Compute the tile-map probe origin for a ball
|
Finds the tile-map cell under a ball, shifted back against the ball's direction of travel.
|
|||||||||||||
|
|||||||||||||
|
The result is the cell where the probe starts. The ball's move pass probes the cell just ahead of the ball in its direction of travel, from this origin.
The ball's position is moved back against its direction of travel before it is converted to a tile-map cell. The direction signs in the ball state record say which way back is.
The ball bitmap does not fill its sprite square. The cell blocks a ball that moves right or down one pixel before the ball's edge reaches the cell. It blocks a ball that moves left or up only once the ball's edge pixel lies inside the cell.
|
|||||||||||||
| ball_tile_cell | 9B28 | PUSH IX | Save IX/BC/DE; the routine returns only HL. | ||||||||||
| 9B2A | PUSH BC | ||||||||||||
| 9B2B | PUSH DE | ||||||||||||
| 9B2C | LD A,B | Point IX at the sprite record of pool slot B. Its first two bytes are the object's pixel X and Y. | |||||||||||
| 9B2D | CALL object_slot_ptr | ||||||||||||
| 9B30 | LD A,(IX+$00) | Read the object's pixel X. | |||||||||||
| 9B33 | BIT 0,(IY+$04) | Nudge X against travel: a clear X direction sign means leftward, so add. | |||||||||||
| 9B37 | JR NZ,ball_tile_cell_x_right | ||||||||||||
| 9B39 | ADD A,$03 | ||||||||||||
| 9B3B | JR ball_tile_cell_x_col | ||||||||||||
| ball_tile_cell_x_right | 9B3D | SUB $03 | A set sign means rightward, so subtract instead. | ||||||||||
| ball_tile_cell_x_col | 9B3F | RRCA | Turn the nudged X into its tile column, in C. | ||||||||||
| 9B40 | RRCA | ||||||||||||
| 9B41 | RRCA | ||||||||||||
| 9B42 | AND $1F | ||||||||||||
| 9B44 | LD C,A | ||||||||||||
| 9B45 | LD A,(IX+$01) | Read the object's pixel Y. | |||||||||||
| 9B48 | BIT 0,(IY+$05) | Nudge Y against travel: a clear Y direction sign means upward, so add. | |||||||||||
| 9B4C | JR NZ,ball_tile_cell_y_down | ||||||||||||
| 9B4E | ADD A,$03 | ||||||||||||
| 9B50 | JR ball_tile_cell_y_row | ||||||||||||
| ball_tile_cell_y_down | 9B52 | SUB $03 | A set sign means downward, so subtract instead. | ||||||||||
| ball_tile_cell_y_row | 9B54 | AND $F8 | Align Y to the top of its character row. | ||||||||||
| 9B56 | LD L,A | Scale it to the row's offset in the 32-wide tile map. | |||||||||||
| 9B57 | LD H,$00 | ||||||||||||
| 9B59 | ADD HL,HL | ||||||||||||
| 9B5A | ADD HL,HL | ||||||||||||
| 9B5B | LD A,L | Merge the column into the low bits, which the row offset leaves clear. | |||||||||||
| 9B5C | OR C | ||||||||||||
| 9B5D | LD L,A | ||||||||||||
| 9B5E | LD BC,tilemap | Add the tile-map base. HL now points at the object's tile-map cell. | |||||||||||
| 9B61 | ADD HL,BC | ||||||||||||
| 9B62 | POP DE | ||||||||||||
| 9B63 | POP BC | ||||||||||||
| 9B64 | POP IX | ||||||||||||
| 9B66 | RET | ||||||||||||
| ← 9B23 | Map | 9B67 → |
