Prev: E020 Up: Map Next: E063
E028: Look up a cell of the town, and where the object is in it
Used by the routines at HIT_BOXES_U and HIT_BOXES_V.
Takes the cell at column D and row H -- the high bytes of any U and V in it -- and returns its type from the map (TOWN), and the object's position in that cell's own frame, in the units its boxes are measured in: the object's U and V less the cell's corner, halved, plus 64. A cell is 256 units a side, so it runs from 64 to 191 in these half units, and a position half a cell beyond it either way still fits in a byte; only the low byte of the halved difference is kept, which is right for anything within that distance.
The entry point TOWN_CELL does only the look-up, for a column in L and a row in H; the finds (SPAWN_FIND), the visited cells (VISIT_CELL), the monsters (SPAWN_MONSTER) and the bonus (PLACE_BONUS) use it. The map is 32 cells a row, and nothing here checks that the column or the row is less than 32.
Input
D The column (the high byte of a U)
H The row (the high byte of a V)
IX The object
Output
A The cell's type, with Z set if it is 0 (nothing there)
HL The cell's address in the map
E The object's U in the cell, in half units from 64
D The object's V in the cell, likewise
PLACE_IN_CELL E028 LD B,H Keep the row and the column
E029 LD C,D
E02A PUSH BC
E02B LD C,$00 E = (U less the cell's first U) halved, plus 64
E02D LD E,C
E02E LD L,(IX+$01)
E031 LD H,(IX+$02)
E034 AND A
E035 SBC HL,DE
E037 SRL H
E039 RR L
E03B LD A,L
E03C ADD A,$40
E03E LD E,A
E03F LD L,(IX+$03) D = (V less the cell's first V) halved, plus 64
E042 LD H,(IX+$04)
E045 AND A
E046 SBC HL,BC
E048 SRL H
E04A RR L
E04C LD A,L
E04D ADD A,$40
E04F LD D,A
E050 POP HL H = the row, L = the column
This entry point is used by the routines at VISIT_CELL, SPAWN_FIND, SPAWN_MONSTER and PLACE_BONUS.
TOWN_CELL E051 LD A,L TOWN_CELL: HL = the row times 32, plus the column
E052 LD L,H
E053 LD H,$00
E055 ADD HL,HL
E056 ADD HL,HL
E057 ADD HL,HL
E058 ADD HL,HL
E059 ADD HL,HL
E05A OR L
E05B LD L,A
E05C LD BC,TOWN A = the cell's type from the map, Z set if the cell is empty
E05F ADD HL,BC
E060 LD A,(HL)
E061 AND A
E062 RET
Prev: E020 Up: Map Next: E063