Prev: 48718 Up: Map Next: 48930
48735: Add Map Cells
Used by the routine at MainLoop.
Adds the cells of the map that can be seen to the end of the draw list. They are the cells in a diamond shape around the robot: twelve rows along the map, which run from six rows further on than the robot to five rows behind it. The rows have 1, 3, 5, 7, 9, 11, 13, 11, 9, 7, 5 and 3 cells in them. Each empty cell is skipped. The position of each of the others on the screen is found from its place in the diamond, the position of the robot inside its own cell and the offsets in the template for the type of the cell, which are the same projection as AddEntity uses. Cells that are outside of the play window are not added.
AddMapCells 48735 LD IX,(38442) Fetch the address of the next free entry of the draw list.
48739 LD A,(38545) Fetch the fraction of the horizontal position of the robot, in sixteenths of a cell, in E.
48742 RRCA
48743 RRCA
48744 RRCA
48745 RRCA
48746 AND 15
48748 LD E,A
48749 LD A,(38547) Fetch the fraction of the vertical position of the robot, in sixteenths of a cell, in L.
48752 RRCA
48753 RRCA
48754 RRCA
48755 RRCA
48756 AND 15
48758 LD L,A
48759 LD A,E Store the sum of them.
48760 ADD A,L
48761 LD (38439),A
48764 LD A,E Store the difference between them.
48765 SUB L
48766 LD (38438),A
48769 LD A,(38546) Fetch the map column of the robot into E.
48772 LD E,A
48773 LD A,(38548) Fetch the map row of the robot, add six to it and keep it within the map, in D.
48776 ADD A,6
48778 AND 63
48780 LD D,A
48781 LD C,12 There are twelve rows of cells.
AddMapCells_Row 48783 LD HL,49101 Point HL at the table of half widths of the rows.
48786 LD B,0 Fetch the half width of this row into L.
48788 ADD HL,BC
48789 LD L,(HL)
48790 PUSH DE Save the position.
48791 LD A,L Find the number of the cell at the start of the row, which is six more than the half width...
48792 ADD A,6
48794 LD B,A
48795 SUB L ...and the number of the cell after the end of the row, which is six less, in H.
48796 SUB L
48797 LD H,A
48798 LD A,E Move to the right hand end of the row.
48799 ADD A,L
48800 AND 63
48802 LD E,A
AddMapCells_Cell 48803 CALL FindMapCell_ColumnRow Find the cell using FindMapCell_ColumnRow.
48806 JR Z,AddMapCells_Next Jump to move on to the next cell if it is empty.
48808 EXX Switch to the alternate registers.
48809 DEC A Find the number of the template for the type of cell...
48810 AND 15
48812 ADD A,A ...multiply it by sixteen...
48813 ADD A,A
48814 ADD A,A
48815 ADD A,A
48816 LD E,A ...and put it in DE.
48817 LD D,0
48819 LD IY,38848 Point IY at the template.
48823 ADD IY,DE
48825 EXX Switch back to the main registers.
48826 LD A,B Find the number of the column in the diamond...
48827 SUB C
48828 ADD A,6
48830 ADD A,A ...and multiply it by sixteen.
48831 ADD A,A
48832 ADD A,A
48833 ADD A,A
48834 PUSH DE Save the position.
48835 LD DE,(38438) Fetch the sum and difference of the fractions of the position of the robot.
48839 SUB E Subtract the difference, to give the horizontal position.
48840 ADD A,(IY+1) Add the first offset from the template...
48843 SUB (IY+3) ...and subtract the second one.
48846 SUB 3 Subtract three.
48848 CP 184 Jump to throw the cell away if it is further right than 183.
48850 JR NC,AddMapCells_Discard
48852 SUB 8 Take eight off. If that goes below zero then subtract 64.
48854 JR NC,AddMapCells_StoreX
48856 SUB 64
AddMapCells_StoreX 48858 LD (IX+1),A Store the horizontal position in the entry.
48861 LD A,B Find the number of the row in the diamond...
48862 ADD A,C
48863 SUB 6
48865 ADD A,A ...and multiply it by sixteen.
48866 ADD A,A
48867 ADD A,A
48868 ADD A,A
48869 SUB D Subtract the sum of the fractions, to give the height.
48870 ADD A,(IY+1) Add the first offset from the template...
48873 ADD A,(IY+3) ...and also the second one.
48876 SUB 11 Subtract 11.
48878 CP 16 Jump to throw the cell away if the height is less than 16.
48880 CCF
48881 JR NC,AddMapCells_Discard
48883 CP 160 The carry flag is set if the height is less than 160.
AddMapCells_Discard 48885 POP DE Restore the position.
48886 JR NC,AddMapCells_Next Jump to move on to the next cell if it is out of the window.
48888 LD (IX+2),A Store the height in the entry.
48891 LD A,(IY+0) Copy the sprite type from the template into the entry.
48894 LD (IX+0),A
48897 INC IX Move on to the next entry.
48899 INC IX
48901 INC IX
AddMapCells_Next 48903 LD A,B Jump if that was the last cell of the row.
48904 CP H
48905 JR Z,AddMapCells_NextRow
48907 DEC B Move on to the next cell...
48908 LD A,E ...which is one column to the left.
48909 DEC A
48910 AND 63
48912 LD E,A
48913 JR AddMapCells_Cell Loop back to deal with it.
AddMapCells_NextRow 48915 POP DE Restore the position.
48916 LD A,D Move back one row.
48917 DEC A
48918 AND 63
48920 LD D,A
48921 DEC C Loop back until all twelve rows have been done.
48922 JP NZ,AddMapCells_Row
48925 LD (IX+0),0 End the list.
48929 RET Return.
Prev: 48718 Up: Map Next: 48930