Prev: 50887 Up: Map Next: 51000
50908: Project Cell
Used by the routines at DrawScenery, DrawCell and DrawCellWithWalls.
Works out where the corner of the cell last set by GetMapCell is on the screen. With the distances from the sheriff 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 ScreenHorizontalPosition and ScreenVerticalPosition. When bit 0 of ViewRotation is set, the sheriff's position is turned round.
Set the position of the corner of the cell.
ProjectCell 50908 LD A,(41557) Fetch CellRow as a position in HL.
50911 LD L,0
50913 LD H,A
50914 PUSH HL Stash it on the stack.
50915 LD A,(41556) Fetch CellColumn as a position in HL.
50918 LD L,0
50920 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 50921 LD DE,(41598) Fetch the sheriff's horizontal position from 41598.
50925 LD A,(41576) Fetch ViewRotation.
50928 AND %00000001 Keep the lowest bit.
50930 JR Z,ProjectCell_X Jump to ProjectCell_X if the view is not rotated.
50932 LD A,E Complement E.
50933 CPL
50934 LD E,A
50935 LD A,D Complement D.
50936 CPL
50937 AND %00001111 Keep the lowest four bits.
50939 LD D,A Set D.
Find the horizontal distance.
ProjectCell_X 50940 AND A Subtract the sheriff's position.
50941 SBC HL,DE
50943 EX DE,HL Copy the distance into DE.
50944 POP HL Restore the vertical position from the stack.
Find the vertical distance.
50945 LD BC,(41600) Fetch the sheriff's vertical position from 41600.
50949 LD A,(41576) Fetch ViewRotation.
50952 AND %00000001 Keep the lowest bit.
50954 JR Z,ProjectCell_Y Jump to ProjectCell_Y if the view is not rotated.
50956 LD A,C Complement C.
50957 CPL
50958 LD C,A
50959 LD A,B Complement B.
50960 CPL
50961 AND %00001111 Keep the lowest four bits.
50963 LD B,A Set B.
Work out the screen position.
ProjectCell_Y 50964 AND A Subtract the sheriff's position.
50965 SBC HL,BC
50967 PUSH HL Stash the distance on the stack.
50968 LD BC,240 Set BC to 240.
50971 ADD HL,DE Add the two distances and 240.
50972 ADD HL,BC
50973 SRA H Halve it.
50975 RR L
50977 LD (41550),HL Set ScreenHorizontalPosition.
50980 POP HL Restore the vertical distance from the stack.
50981 AND A Subtract the horizontal distance.
50982 SBC HL,DE
50984 LD BC,432 Set BC to 432.
50987 ADD HL,BC Add it.
50988 SRA H Divide it by four.
50990 RR L
50992 SRA H
50994 RR L
50996 LD (41552),HL Set ScreenVerticalPosition and return.
50999 RET
View the equivalent code in;
Prev: 50887 Up: Map Next: 51000