Prev: 46737 Up: Map Next: 46840
46797: Place Near Sheriff
Puts an object in a cell which is a number of cells away from the sheriff, both across and up the screen. Which of the four diagonal directions is used depends on the bottom two bits of the frame counter.
Input
B The distance in cells
IY The address of the object
Output
F The zero flag is set if the cell is free
Fetch the sheriff's cell and the frame counter.
PlaceNearSheriff 46797 LD A,(41599) Fetch the horizontal cell of the sheriff and keep it in L.
46800 LD L,A
46801 LD A,(41601) Fetch the vertical cell of the sheriff and keep it in H.
46804 LD H,A
46805 LD A,(41494) Fetch the frame counter and keep it in C.
46808 LD C,A
Choose a diagonal from the bottom two bits of the frame.
46809 LD A,B Fetch the distance.
46810 BIT 0,C Jump to PlaceNearSheriff_AddHorizontal if bit 0 of the frame counter is clear.
46812 JR Z,PlaceNearSheriff_AddHorizontal
46814 NEG Go in the other direction horizontally.
PlaceNearSheriff_AddHorizontal 46816 ADD A,L Add the horizontal cell of the sheriff.
46817 AND %00001111 Wrap round the town.
46819 LD L,A Keep the wrapped horizontal cell in L.
46820 LD A,B Fetch the distance again.
46821 BIT 1,C Jump to PlaceNearSheriff_AddVertical if bit 1 of the frame counter is clear.
46823 JR Z,PlaceNearSheriff_AddVertical
46825 NEG Go in the other direction vertically.
PlaceNearSheriff_AddVertical 46827 ADD A,H Add the vertical cell of the sheriff.
46828 AND %00001111 Wrap round the town.
46830 LD H,A Keep the wrapped vertical cell in H.
Store the cell and test whether it is free.
46831 LD (IY+2),L Set the horizontal cell of the object.
46834 LD (IY+4),H Set the vertical cell of the object.
46837 JP GetMapCell Jump to GetMapCell.
Prev: 46737 Up: Map Next: 46840