Prev: 54515 Up: Map Next: 54628
54536: Project Cell
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 + 240) / 2 and the vertical position is (dy - dx + 432) / 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 54536 LD A,(48053) Fetch CellRow as a position in HL.
54539 LD L,0
54541 LD H,A
54542 PUSH HL Stash it on the stack.
54543 LD A,(48052) Fetch CellColumn as a position in HL.
54546 LD L,0
54548 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 54549 LD DE,(48271) Fetch the player's horizontal position from 48271.
54553 LD A,(48058) Fetch ViewRotatedFlag.
54556 AND %00000001 Keep the lowest bit.
54558 JR Z,ProjectCell_X Jump to ProjectCell_X if the view is not rotated.
54560 LD A,E Complement E.
54561 CPL
54562 LD E,A
54563 LD A,D Complement D.
54564 CPL
54565 AND %00011111 Keep the lowest five bits.
54567 LD D,A Set D.
Find the horizontal distance.
ProjectCell_X 54568 AND A Subtract the player's position.
54569 SBC HL,DE
54571 EX DE,HL Copy the distance into DE.
54572 POP HL Restore the vertical position from the stack.
Find the vertical distance.
54573 LD BC,(48273) Fetch the player's vertical position from 48273.
54577 LD A,(48058) Fetch ViewRotatedFlag.
54580 AND %00000001 Keep the lowest bit.
54582 JR Z,ProjectCell_Y Jump to ProjectCell_Y if the view is not rotated.
54584 LD A,C Complement C.
54585 CPL
54586 LD C,A
54587 LD A,B Complement B.
54588 CPL
54589 AND %00011111 Keep the lowest five bits.
54591 LD B,A Set B.
Work out the screen position.
ProjectCell_Y 54592 AND A Subtract the player's position.
54593 SBC HL,BC
54595 PUSH HL Stash the distance on the stack.
54596 LD BC,240 Set BC to 240.
54599 ADD HL,DE Add the two distances and 240.
54600 ADD HL,BC
54601 SRA H Halve it.
54603 RR L
54605 LD (48054),HL Set ScreenXPosition.
54608 POP HL Restore the vertical distance from the stack.
54609 AND A Subtract the horizontal distance.
54610 SBC HL,DE
54612 LD BC,432 Set BC to 432.
54615 ADD HL,BC Add it.
54616 SRA H Divide it by four.
54618 RR L
54620 SRA H
54622 RR L
54624 LD (48056),HL Set ScreenYPosition and return.
54627 RET
View the equivalent code in;
Prev: 54515 Up: Map Next: 54628