Prev: 43919 Up: Map Next: 44276
44096: Build Draw List
Used by the routines at RunFrame and RunGame.
Builds the list of items to be drawn for the current frame, at DrawList. Each item is three bytes: a flag byte followed by the address of the record to draw. The flag is 1 for an entity (see Entities), 2 for one of the 12 extra records at ExtraRecords and 3 for one of the 20-byte records at Records. The list ends with a zero byte, and DrawListPointer holds the address of the next free item.
Every entity that is in use and not hidden is prepared with PrepareEntityItem. The matching extra record is then prepared as well, if it has been flagged as visible.
Start with an empty list and with no table records, and go through the 12 entities and their extra records.
BuildDrawList 44096 LD HL,45051 Make the next free item of the draw list the start of the list.
44099 LD (45164),HL
44102 XOR A Clear the count of table records that have been prepared.
44103 LD (62720),A
44106 LD IX,46400 Point IX at Entities.
44110 LD IY,46856 Point IY at ExtraRecords.
44114 LD HL,62721 Point HL at the start of the table of records.
44117 LD B,12 Set a counter in B for the 12 entities.
BuildDrawList_Loop 44119 PUSH BC Stash the counter on the stack.
44120 LD A,(IX+0) Fetch the type of the entity.
44123 AND A Test it.
44124 JR Z,BuildDrawList_Next Jump to BuildDrawList_Next if the entity is not in use.
Add the entity to the draw list, unless it is hidden.
44126 BIT 7,(IX+1) Test bit 7 of field 1 of the entity, which is set if it is hidden.
44130 CALL Z,PrepareEntityItem Add the entity to the draw list if it is not hidden.
44133 BIT 7,(IY+9) Jump to BuildDrawList_Next if the extra record is not in use.
44137 JR Z,BuildDrawList_Next
Build the temporary entity from the extra record, so that the extra record can be drawn in the same way as an entity.
44139 PUSH IX Stash the entity and the table pointer on the stack.
44141 PUSH HL Stash the table pointer on the stack.
44142 LD L,(IY+0) Copy the screen position of the extra record into the temporary entity.
44145 LD H,(IY+1)
44148 LD (47026),HL
44151 LD L,(IY+2) Copy the x coordinate of the extra record into the temporary entity.
44154 LD H,(IY+3)
44157 LD (47014),HL
44160 LD L,(IY+4) Copy the y coordinate of the extra record into the temporary entity.
44163 LD H,(IY+5)
44166 LD (47017),HL
44169 LD L,(IY+6) Copy the z coordinate of the extra record into the temporary entity.
44172 LD H,(IY+7)
44175 LD (47020),HL
44178 LD A,(IY+11) Copy the width of the extra record into the temporary entity.
44181 AND 15
44183 LD (47034),A
44186 LD A,(IY+12) Copy the height of the extra record into the temporary entity.
44189 AND 63
44191 LD (47035),A
44194 LD IX,47012 Point IX at TemporaryEntity.
44198 LD (IX+0),2 Make it an entity of type 2.
44202 CALL ConvertEntityPosition Find its address in the screen buffer.
44205 LD (IY+8),L Store the address in the extra record.
44208 LD (IY+9),H
44211 POP HL Restore the table pointer.
44212 CALL PrepareEntityItem_Table Add the temporary entity to the draw list.
44215 POP IX Restore the entity.
Move on to the next entity and the next extra record.
BuildDrawList_Next 44217 LD DE,38 Move IX on to the next entity.
44220 ADD IX,DE
44222 LD E,13 Move IY on to the next extra record.
44224 ADD IY,DE
44226 POP BC Restore the counter.
44227 DJNZ BuildDrawList_Loop Decrease the counter and loop back to BuildDrawList_Loop until all 12 entities have been done.
Add the records of the objects of the level that are in view to the draw list.
BuildDrawList_Records 44229 LD HL,(45164) Fetch the next free item of the draw list.
44232 LD A,(48118) Fetch the number of records.
44235 AND A Test it.
44236 JR Z,BuildDrawList_End Jump to BuildDrawList_End if there are none.
44238 LD IY,48119 Point IY at Records.
44242 LD BC,20 Set the length of a record, 20.
BuildDrawList_RecordLoop 44245 BIT 7,(IY+10) Jump to BuildDrawList_RecordNext if the record is not to be drawn.
44249 JR Z,BuildDrawList_RecordNext
44251 RES 7,(IY+10) Reset the bit so that the record is only drawn once.
44255 LD (HL),3 Mark the item as a record.
44257 PUSH IY Copy the address of the record into DE.
44259 POP DE
44260 INC HL Store the address of the record in the item.
44261 LD (HL),E
44262 INC HL
44263 LD (HL),D
44264 INC HL Move on to the next item.
BuildDrawList_RecordNext 44265 ADD IY,BC Move IY on to the next record.
44267 DEC A Decrease the number of records by one.
44268 JR NZ,BuildDrawList_RecordLoop Loop back to BuildDrawList_RecordLoop until all of the records have been done.
BuildDrawList_End 44270 LD (HL),0 Mark the end of the draw list.
44272 LD (45164),HL Store the new end of the list.
44275 RET Return.
Prev: 43919 Up: Map Next: 44276