![]() |
Routines |
| Prev: D4F3 | Up: Map | Next: D564 |
|
Used by the routines at DrawCell and DrawCellWithWalls.
Works out where the corner of the cell last set by GetMapCell is on the screen. With the distances from the player as dx and dy, the horizontal position is (dx + dy + F0) / 2 and the vertical position is (dy - dx + 01B0) / 4. They are put in ScreenXPosition and ScreenYPosition. When bit 0 of ViewRotatedFlag is set, the player's position is turned round.
|
||||
|
Set the position of the corner of the cell.
|
||||
| ProjectCell | D508 | LD A,($BBB5) | Fetch CellRow as a position in HL. | |
| D50B | LD L,$00 | |||
| D50D | LD H,A | |||
| D50E | PUSH HL | Stash it on the stack. | ||
| D50F | LD A,($BBB4) | Fetch CellColumn as a position in HL. | ||
| D512 | LD L,$00 | |||
| D514 | LD H,A | |||
|
This entry point is used by the routine at ProjectObject.
Find the position on the screen. HL is the horizontal position, and the vertical position is on the stack.
|
||||
| ProjectCell_Position | D515 | LD DE,($BC8F) | Fetch the player's horizontal position from BC8F. | |
| D519 | LD A,($BBBA) | Fetch ViewRotatedFlag. | ||
| D51C | AND %00000001 | Keep the lowest bit. | ||
| D51E | JR Z,ProjectCell_X | Jump to ProjectCell_X if the view is not rotated. | ||
| D520 | LD A,E | Complement E. | ||
| D521 | CPL | |||
| D522 | LD E,A | |||
| D523 | LD A,D | Complement D. | ||
| D524 | CPL | |||
| D525 | AND %00011111 | Keep the lowest five bits. | ||
| D527 | LD D,A | Set D. | ||
|
Find the horizontal distance.
|
||||
| ProjectCell_X | D528 | AND A | Subtract the player's position. | |
| D529 | SBC HL,DE | |||
| D52B | EX DE,HL | Copy the distance into DE. | ||
| D52C | POP HL | Restore the vertical position from the stack. | ||
|
Find the vertical distance.
|
||||
| D52D | LD BC,($BC91) | Fetch the player's vertical position from BC91. | ||
| D531 | LD A,($BBBA) | Fetch ViewRotatedFlag. | ||
| D534 | AND %00000001 | Keep the lowest bit. | ||
| D536 | JR Z,ProjectCell_Y | Jump to ProjectCell_Y if the view is not rotated. | ||
| D538 | LD A,C | Complement C. | ||
| D539 | CPL | |||
| D53A | LD C,A | |||
| D53B | LD A,B | Complement B. | ||
| D53C | CPL | |||
| D53D | AND %00011111 | Keep the lowest five bits. | ||
| D53F | LD B,A | Set B. | ||
|
Work out the screen position.
|
||||
| ProjectCell_Y | D540 | AND A | Subtract the player's position. | |
| D541 | SBC HL,BC | |||
| D543 | PUSH HL | Stash the distance on the stack. | ||
| D544 | LD BC,$00F0 | Set BC to F0. | ||
| D547 | ADD HL,DE | Add the two distances and F0. | ||
| D548 | ADD HL,BC | |||
| D549 | SRA H | Halve it. | ||
| D54B | RR L | |||
| D54D | LD ($BBB6),HL | Set ScreenXPosition. | ||
| D550 | POP HL | Restore the vertical distance from the stack. | ||
| D551 | AND A | Subtract the horizontal distance. | ||
| D552 | SBC HL,DE | |||
| D554 | LD BC,$01B0 | Set BC to 01B0. | ||
| D557 | ADD HL,BC | Add it. | ||
| D558 | SRA H | Divide it by four. | ||
| D55A | RR L | |||
| D55C | SRA H | |||
| D55E | RR L | |||
| D560 | LD ($BBB8),HL | Set ScreenYPosition and return. | ||
| D563 | RET | |||
|
View the equivalent code in;
|
||||
| Prev: D4F3 | Up: Map | Next: D564 |