Prev: BE01 Up: Map Next: BFA5
BF41: Record Object
Used by the routine at AddObjectEntity.
Records an object in the table of objects at ObjectRecords. If the object is already in the copy of the table at CopiedRecords, the copy of the record is used. Otherwise a new record is made, with the position and kind of the object. The operand of the first instruction is the address of the next free record, and is updated each time.
Input
IX The object
BC The position of the object
DE The position of the object
Fetch the address of the next free record, which is patched in, and check whether there are any records in the copy of the table.
RecordObject BF41 LD HL,$0000 Set HL to the address of the next free record.
BF44 LD A,($BDBA) Fetch the number of records in the copy of the table.
BF47 AND A Test it.
BF48 JR Z,RecordObject_New Jump to RecordObject_New to make a new record if there are none.
Look for a record in the copy of the table that has the same position as the object.
BF4A PUSH DE Save the y coordinate.
BF4B PUSH BC Save the x coordinate.
BF4C LD D,C Copy the low byte of the x coordinate into D.
BF4D LD IY,$BDBB Point IY at CopiedRecords.
RecordObject_Find BF51 EX AF,AF' Keep the number of records left.
BF52 LD A,D Fetch the low byte of the x coordinate.
BF53 XOR (IY+$00) Compare it with the one in the record.
BF56 JR NZ,RecordObject_Next Jump to RecordObject_Next if it is different.
BF58 LD A,E Fetch the low byte of the y coordinate.
BF59 XOR (IY+$02) Compare it with the one in the record.
BF5C JR NZ,RecordObject_Next Jump to RecordObject_Next if it is different.
Found it, so copy the record to the next free record.
BF5E PUSH IY Put the address of the record into DE, via the stack...
BF60 POP DE ...then swap it with the address of the next free record.
BF61 EX DE,HL
BF62 LD BC,$0007 Set the size of a record, 07.
BF65 LDIR Copy the record.
BF67 EX DE,HL Put the address of the next free record in HL again.
BF68 POP BC Restore the x coordinate.
BF69 POP DE Restore the y coordinate.
BF6A JR RecordObject_Store Jump to RecordObject_Store.
RecordObject_Next BF6C LD A,B Keep B in A.
BF6D LD BC,$0007 Set the size of a record, 07.
BF70 ADD IY,BC Move on to the next record in the copy of the table.
BF72 LD B,A Bring back B.
BF73 EX AF,AF' Fetch the number of records left.
BF74 DEC A Decrease it.
BF75 JR NZ,RecordObject_Find Jump back to RecordObject_Find until all of the records have been tried.
BF77 POP BC Restore the x coordinate.
BF78 POP DE Restore the y coordinate.
Make a new record from the object, with the coordinates, the height and the kind.
RecordObject_New BF79 LD (HL),C Store the low byte of the x coordinate.
BF7A INC HL
BF7B LD (HL),B Store the high byte of the x coordinate.
BF7C INC HL
BF7D LD (HL),E Store the low byte of the y coordinate.
BF7E INC HL
BF7F LD (HL),D Store the high byte of the y coordinate.
BF80 INC HL
BF81 LD A,(IX+$01) Fetch the second byte of the object.
BF84 AND %01110000 Keep the height in bits 4-6.
BF86 LD E,A Keep it in E.
BF87 LD A,(IX+$02) Fetch the third byte of the object.
BF8A ADD A,A Move bit 6, the top bit of the height, to bit 7...
BF8B AND %10000000 ...and keep it.
BF8D ADD A,E Add the other bits of the height.
BF8E LD (HL),A Store the height in the record.
BF8F INC HL
BF90 LD (HL),$00 Set the next byte of the record to 00.
BF92 INC HL
BF93 LD A,(IX+$02) Fetch the third byte of the object.
BF96 AND %00011111 Keep the kind of the object.
BF98 LD (HL),A Store it in the record.
BF99 INC HL Move on past the record.
Store the address of the next free record, and count the record.
RecordObject_Store BF9A LD ($BF42),HL Patch the address of the next free record into the first instruction.
BF9D LD A,($BD73) Fetch the number of records.
BFA0 INC A Add one.
BFA1 LD ($BD73),A Store the number of records.
BFA4 RET Return.
Prev: BE01 Up: Map Next: BFA5