Prev: BE4E Up: Map Next: BF22
BE5F: 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 01, 03, 05, 07, 09, 0B, 0D, 0B, 09, 07, 05 and 03 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 BE5F LD IX,($962A) Fetch the address of the next free entry of the draw list.
BE63 LD A,($9691) Fetch the fraction of the horizontal position of the robot, in sixteenths of a cell, in E.
BE66 RRCA
BE67 RRCA
BE68 RRCA
BE69 RRCA
BE6A AND $0F
BE6C LD E,A
BE6D LD A,($9693) Fetch the fraction of the vertical position of the robot, in sixteenths of a cell, in L.
BE70 RRCA
BE71 RRCA
BE72 RRCA
BE73 RRCA
BE74 AND $0F
BE76 LD L,A
BE77 LD A,E Store the sum of them.
BE78 ADD A,L
BE79 LD ($9627),A
BE7C LD A,E Store the difference between them.
BE7D SUB L
BE7E LD ($9626),A
BE81 LD A,($9692) Fetch the map column of the robot into E.
BE84 LD E,A
BE85 LD A,($9694) Fetch the map row of the robot, add six to it and keep it within the map, in D.
BE88 ADD A,$06
BE8A AND $3F
BE8C LD D,A
BE8D LD C,$0C There are twelve rows of cells.
AddMapCells_Row BE8F LD HL,$BFCD Point HL at the table of half widths of the rows.
BE92 LD B,$00 Fetch the half width of this row into L.
BE94 ADD HL,BC
BE95 LD L,(HL)
BE96 PUSH DE Save the position.
BE97 LD A,L Find the number of the cell at the start of the row, which is six more than the half width...
BE98 ADD A,$06
BE9A LD B,A
BE9B SUB L ...and the number of the cell after the end of the row, which is six less, in H.
BE9C SUB L
BE9D LD H,A
BE9E LD A,E Move to the right hand end of the row.
BE9F ADD A,L
BEA0 AND $3F
BEA2 LD E,A
AddMapCells_Cell BEA3 CALL FindMapCell_ColumnRow Find the cell using FindMapCell_ColumnRow.
BEA6 JR Z,AddMapCells_Next Jump to move on to the next cell if it is empty.
BEA8 EXX Switch to the alternate registers.
BEA9 DEC A Find the number of the template for the type of cell...
BEAA AND $0F
BEAC ADD A,A ...multiply it by sixteen...
BEAD ADD A,A
BEAE ADD A,A
BEAF ADD A,A
BEB0 LD E,A ...and put it in DE.
BEB1 LD D,$00
BEB3 LD IY,$97C0 Point IY at the template.
BEB7 ADD IY,DE
BEB9 EXX Switch back to the main registers.
BEBA LD A,B Find the number of the column in the diamond...
BEBB SUB C
BEBC ADD A,$06
BEBE ADD A,A ...and multiply it by sixteen.
BEBF ADD A,A
BEC0 ADD A,A
BEC1 ADD A,A
BEC2 PUSH DE Save the position.
BEC3 LD DE,($9626) Fetch the sum and difference of the fractions of the position of the robot.
BEC7 SUB E Subtract the difference, to give the horizontal position.
BEC8 ADD A,(IY+$01) Add the first offset from the template...
BECB SUB (IY+$03) ...and subtract the second one.
BECE SUB $03 Subtract three.
BED0 CP $B8 Jump to throw the cell away if it is further right than B7.
BED2 JR NC,AddMapCells_Discard
BED4 SUB $08 Take eight off. If that goes below zero then subtract 40.
BED6 JR NC,AddMapCells_StoreX
BED8 SUB $40
AddMapCells_StoreX BEDA LD (IX+$01),A Store the horizontal position in the entry.
BEDD LD A,B Find the number of the row in the diamond...
BEDE ADD A,C
BEDF SUB $06
BEE1 ADD A,A ...and multiply it by sixteen.
BEE2 ADD A,A
BEE3 ADD A,A
BEE4 ADD A,A
BEE5 SUB D Subtract the sum of the fractions, to give the height.
BEE6 ADD A,(IY+$01) Add the first offset from the template...
BEE9 ADD A,(IY+$03) ...and also the second one.
BEEC SUB $0B Subtract 0B.
BEEE CP $10 Jump to throw the cell away if the height is less than 10.
BEF0 CCF
BEF1 JR NC,AddMapCells_Discard
BEF3 CP $A0 The carry flag is set if the height is less than A0.
AddMapCells_Discard BEF5 POP DE Restore the position.
BEF6 JR NC,AddMapCells_Next Jump to move on to the next cell if it is out of the window.
BEF8 LD (IX+$02),A Store the height in the entry.
BEFB LD A,(IY+$00) Copy the sprite type from the template into the entry.
BEFE LD (IX+$00),A
BF01 INC IX Move on to the next entry.
BF03 INC IX
BF05 INC IX
AddMapCells_Next BF07 LD A,B Jump if that was the last cell of the row.
BF08 CP H
BF09 JR Z,AddMapCells_NextRow
BF0B DEC B Move on to the next cell...
BF0C LD A,E ...which is one column to the left.
BF0D DEC A
BF0E AND $3F
BF10 LD E,A
BF11 JR AddMapCells_Cell Loop back to deal with it.
AddMapCells_NextRow BF13 POP DE Restore the position.
BF14 LD A,D Move back one row.
BF15 DEC A
BF16 AND $3F
BF18 LD D,A
BF19 DEC C Loop back until all twelve rows have been done.
BF1A JP NZ,AddMapCells_Row
BF1D LD (IX+$00),$00 End the list.
BF21 RET Return.
Prev: BE4E Up: Map Next: BF22