Prev: AB8F Up: Map Next: ACF4
AC40: 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 01 for an entity (see Entities), 02 for one of the 0C extra records at ExtraRecords and 03 for one of the 14-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 0C entities and their extra records.
BuildDrawList AC40 LD HL,$AFFB Make the next free item of the draw list the start of the list.
AC43 LD ($B06C),HL
AC46 XOR A Clear the count of table records that have been prepared.
AC47 LD ($F500),A
AC4A LD IX,$B540 Point IX at Entities.
AC4E LD IY,$B708 Point IY at ExtraRecords.
AC52 LD HL,$F501 Point HL at the start of the table of records.
AC55 LD B,$0C Set a counter in B for the 0C entities.
BuildDrawList_Loop AC57 PUSH BC Stash the counter on the stack.
AC58 LD A,(IX+$00) Fetch the type of the entity.
AC5B AND A Test it.
AC5C 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.
AC5E BIT 7,(IX+$01) Test bit 7 of field 01 of the entity, which is set if it is hidden.
AC62 CALL Z,PrepareEntityItem Add the entity to the draw list if it is not hidden.
AC65 BIT 7,(IY+$09) Jump to BuildDrawList_Next if the extra record is not in use.
AC69 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.
AC6B PUSH IX Stash the entity and the table pointer on the stack.
AC6D PUSH HL Stash the table pointer on the stack.
AC6E LD L,(IY+$00) Copy the screen position of the extra record into the temporary entity.
AC71 LD H,(IY+$01)
AC74 LD ($B7B2),HL
AC77 LD L,(IY+$02) Copy the x coordinate of the extra record into the temporary entity.
AC7A LD H,(IY+$03)
AC7D LD ($B7A6),HL
AC80 LD L,(IY+$04) Copy the y coordinate of the extra record into the temporary entity.
AC83 LD H,(IY+$05)
AC86 LD ($B7A9),HL
AC89 LD L,(IY+$06) Copy the z coordinate of the extra record into the temporary entity.
AC8C LD H,(IY+$07)
AC8F LD ($B7AC),HL
AC92 LD A,(IY+$0B) Copy the width of the extra record into the temporary entity.
AC95 AND $0F
AC97 LD ($B7BA),A
AC9A LD A,(IY+$0C) Copy the height of the extra record into the temporary entity.
AC9D AND $3F
AC9F LD ($B7BB),A
ACA2 LD IX,$B7A4 Point IX at TemporaryEntity.
ACA6 LD (IX+$00),$02 Make it an entity of type 02.
ACAA CALL ConvertEntityPosition Find its address in the screen buffer.
ACAD LD (IY+$08),L Store the address in the extra record.
ACB0 LD (IY+$09),H
ACB3 POP HL Restore the table pointer.
ACB4 CALL PrepareEntityItem_Table Add the temporary entity to the draw list.
ACB7 POP IX Restore the entity.
Move on to the next entity and the next extra record.
BuildDrawList_Next ACB9 LD DE,$0026 Move IX on to the next entity.
ACBC ADD IX,DE
ACBE LD E,$0D Move IY on to the next extra record.
ACC0 ADD IY,DE
ACC2 POP BC Restore the counter.
ACC3 DJNZ BuildDrawList_Loop Decrease the counter and loop back to BuildDrawList_Loop until all 0C entities have been done.
Add the records of the objects of the level that are in view to the draw list.
BuildDrawList_Records ACC5 LD HL,($B06C) Fetch the next free item of the draw list.
ACC8 LD A,($BBF6) Fetch the number of records.
ACCB AND A Test it.
ACCC JR Z,BuildDrawList_End Jump to BuildDrawList_End if there are none.
ACCE LD IY,$BBF7 Point IY at Records.
ACD2 LD BC,$0014 Set the length of a record, 14.
BuildDrawList_RecordLoop ACD5 BIT 7,(IY+$0A) Jump to BuildDrawList_RecordNext if the record is not to be drawn.
ACD9 JR Z,BuildDrawList_RecordNext
ACDB RES 7,(IY+$0A) Reset the bit so that the record is only drawn once.
ACDF LD (HL),$03 Mark the item as a record.
ACE1 PUSH IY Copy the address of the record into DE.
ACE3 POP DE
ACE4 INC HL Store the address of the record in the item.
ACE5 LD (HL),E
ACE6 INC HL
ACE7 LD (HL),D
ACE8 INC HL Move on to the next item.
BuildDrawList_RecordNext ACE9 ADD IY,BC Move IY on to the next record.
ACEB DEC A Decrease the number of records by one.
ACEC JR NZ,BuildDrawList_RecordLoop Loop back to BuildDrawList_RecordLoop until all of the records have been done.
BuildDrawList_End ACEE LD (HL),$00 Mark the end of the draw list.
ACF0 LD ($B06C),HL Store the new end of the list.
ACF3 RET Return.
Prev: AB8F Up: Map Next: ACF4