Prev: ACF4 Up: Map Next: AD9E
AD07: Prepare Entity Item
Used by the routine at BuildDrawList.
Converts the position of the entity with ConvertEntityPosition and adds it to the draw list. Entity types 0C and 10 are only appended with AppendEntityItem. Any other type is also given a record in the table of item records, which holds a copy of the rows of the screen buffer (which are 18 bytes wide) that lie under the entity, so that RestoreItemRows can put them back after the entity has been drawn.
Input
IX The entity
HL Pointer to the next free byte in the table of item records
Output
HL Updated pointer
PrepareEntityItem AD07 PUSH HL Save the item record pointer.
AD08 CALL ConvertEntityPosition Convert the position of the entity.
AD0B POP HL Restore the item record pointer.
AD0C LD A,(IX+$00) Fetch the type of the entity.
AD0F CP $0C Jump to AppendEntityItem if it is type 0C.
AD11 JR Z,AppendEntityItem
AD13 CP $10 Jump to AppendEntityItem if it is type 10.
AD15 JR Z,AppendEntityItem
This entry point is used by the routine at BuildDrawList.
Entry point used for the extra records, which are passed in IY.
Count the item.
PrepareEntityItem_Table AD17 LD A,($F500) Fetch the number of prepared items.
AD1A INC A Add one.
AD1B LD ($F500),A Store it again.
AD1E PUSH HL Save the item record pointer.
AD1F CALL TestRecordsAgainstEntity Check the 14-byte records for any that overlap the entity.
Check the 14-byte records for any that overlap the entity.
AD22 LD HL,($B06C) Fetch the next free item address.
Fetch the type.
AD25 LD A,(IX+$00) Fetch the type of the entity.
AD28 CP $02 Jump to PrepareEntityItem_Entity if it is not type 02.
AD2A JR NZ,PrepareEntityItem_Entity
AD2C LD (HL),A Use the type as the flag for the item.
AD2D PUSH IY IY moves into DE.
AD2F POP DE (via the stack).
AD30 INC HL Move to the address bytes.
AD31 LD (HL),E Store the low byte of the record address.
AD32 INC HL Move on.
AD33 LD (HL),D Store the high byte of the record address.
AD34 JR PrepareEntityItem_Header Jump to PrepareEntityItem_Header.
Add an entity item (flag 01) to the draw list.
PrepareEntityItem_Entity AD36 LD (HL),$01 Set the flag of the item to 01.
AD38 INC HL Move to the address bytes.
AD39 PUSH IX IX moves into DE.
AD3B POP DE (via the stack).
AD3C LD (HL),E Store the low byte of the entity address.
AD3D INC HL Move on.
AD3E LD (HL),D Store the high byte of the entity address.
PrepareEntityItem_Header AD3F INC HL Move to the next free item.
AD40 LD ($B06C),HL Store it.
AD43 POP HL Restore the item record pointer.
Fetch the address in the screen buffer.
AD44 LD E,(IX+$18) Fetch the low byte of the address in the screen buffer.
AD47 LD D,(IX+$19) Fetch the high byte of the address in the screen buffer.
Work out how many bytes wide the record is, from field 16 and field 0E.
AD4A LD A,(IX+$16) Read field 16.
AD4D AND %00001111 Keep the low nibble.
AD4F LD C,A Copy it into C.
AD50 LD A,(IX+$0E) Read field 0E.
AD53 AND %00000111 Use bits 0-2.
AD55 JR Z,PrepareEntityItem_Width Jump to PrepareEntityItem_Width if they are all zero.
AD57 INC C Otherwise add one to the width.
Patch the operand of the BC load at AD96 and write the record header: the first byte is the width plus 18 then the address in the screen buffer.
PrepareEntityItem_Width AD58 LD A,$E8 Start from E8.
AD5A SUB C Subtract the width.
AD5B LD ($AD96),A Patch the operand of the BC load at AD94 with it.
AD5E NEG Negate it to give the width plus 18.
AD60 LD (HL),A Write it as the first byte of the record.
AD61 INC HL Move on.
AD62 LD (HL),E Write the low byte of the address in the screen buffer.
AD63 INC HL Move on.
AD64 LD (HL),D Write the high byte of the address in the screen buffer.
AD65 INC HL Move on.
Patch the jump back into the unrolled copy so that only C bytes of each row are copied.
AD66 SLA C Double the width.
AD68 LD A,$F8 Start from F8.
AD6A SUB C Subtract twice the width.
AD6B LD ($AD9B),A Patch the displacement of the DJNZ at PrepareEntityItem_Loop with it (the displacement is the byte at AD9B).
AD6E SUB $02 Subtract 02.
AD70 LD (HL),A Write it as the fourth byte of the record.
AD71 INC HL Move on.
Work out the number of rows from fields 17 and 0F and write it to the header.
AD72 LD A,(IX+$17) Read field 17.
AD75 AND %00111111 Use bits 0-5.
AD77 INC A Add one.
AD78 LD B,A Copy it into B.
AD79 LD A,(IX+$0F) Read field 0F.
AD7C CP B Compare it with the value in B.
AD7D JR NC,PrepareEntityItem_Skip Jump to AD82 if it is not less.
AD7F ADD A,$02 Otherwise use field 0F plus 02.
AD81 LD B,A Copy it into B.
PrepareEntityItem_Skip AD82 LD (HL),B Write the number of rows as the fifth byte of the record.
AD83 INC HL Move on.
Swap, ready to copy the rows from the data into the table.
AD84 EX DE,HL Swap the screen buffer address into HL and the table pointer into DE.
AD85 JP PrepareEntityItem_Loop Jump into the copy loop.
PrepareEntityItem_Copy AD88 LDI Copy a byte and move on.
AD8A LDI Copy a byte and move on.
AD8C LDI Copy a byte and move on.
AD8E LDI Copy a byte and move on.
AD90 LDI Copy a byte and move on.
AD92 LDI Copy a byte and move on.
AD94 LD A,B Save the row counter.
AD95 LD BC,$FF00 Set up the step back to the start of the next row (the low byte is patched at AD96).
AD98 ADD HL,BC Move HL back to the start of the next row of the screen buffer.
AD99 LD B,A Restore the row counter.
PrepareEntityItem_Loop AD9A DJNZ PrepareEntityItem_Loop Decrease the row counter and jump back into the copy chain (the displacement is patched at AD9B) until all rows are copied.
AD9C EX DE,HL Swap the pointer to the next free byte back into HL.
AD9D RET Return.
Prev: ACF4 Up: Map Next: AD9E