Prev: 48641 Up: Map Next: 49061
48961: 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 48961 LD HL,0 Set HL to the address of the next free record.
48964 LD A,(48570) Fetch the number of records in the copy of the table.
48967 AND A Test it.
48968 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.
48970 PUSH DE Save the y coordinate.
48971 PUSH BC Save the x coordinate.
48972 LD D,C Copy the low byte of the x coordinate into D.
48973 LD IY,48571 Point IY at CopiedRecords.
RecordObject_Find 48977 EX AF,AF' Keep the number of records left.
48978 LD A,D Fetch the low byte of the x coordinate.
48979 XOR (IY+0) Compare it with the one in the record.
48982 JR NZ,RecordObject_Next Jump to RecordObject_Next if it is different.
48984 LD A,E Fetch the low byte of the y coordinate.
48985 XOR (IY+2) Compare it with the one in the record.
48988 JR NZ,RecordObject_Next Jump to RecordObject_Next if it is different.
Found it, so copy the record to the next free record.
48990 PUSH IY Put the address of the record into DE, via the stack...
48992 POP DE ...then swap it with the address of the next free record.
48993 EX DE,HL
48994 LD BC,7 Set the size of a record, 7.
48997 LDIR Copy the record.
48999 EX DE,HL Put the address of the next free record in HL again.
49000 POP BC Restore the x coordinate.
49001 POP DE Restore the y coordinate.
49002 JR RecordObject_Store Jump to RecordObject_Store.
RecordObject_Next 49004 LD A,B Keep B in A.
49005 LD BC,7 Set the size of a record, 7.
49008 ADD IY,BC Move on to the next record in the copy of the table.
49010 LD B,A Bring back B.
49011 EX AF,AF' Fetch the number of records left.
49012 DEC A Decrease it.
49013 JR NZ,RecordObject_Find Jump back to RecordObject_Find until all of the records have been tried.
49015 POP BC Restore the x coordinate.
49016 POP DE Restore the y coordinate.
Make a new record from the object, with the coordinates, the height and the kind.
RecordObject_New 49017 LD (HL),C Store the low byte of the x coordinate.
49018 INC HL
49019 LD (HL),B Store the high byte of the x coordinate.
49020 INC HL
49021 LD (HL),E Store the low byte of the y coordinate.
49022 INC HL
49023 LD (HL),D Store the high byte of the y coordinate.
49024 INC HL
49025 LD A,(IX+1) Fetch the second byte of the object.
49028 AND %01110000 Keep the height in bits 4-6.
49030 LD E,A Keep it in E.
49031 LD A,(IX+2) Fetch the third byte of the object.
49034 ADD A,A Move bit 6, the top bit of the height, to bit 7...
49035 AND %10000000 ...and keep it.
49037 ADD A,E Add the other bits of the height.
49038 LD (HL),A Store the height in the record.
49039 INC HL
49040 LD (HL),0 Set the next byte of the record to 0.
49042 INC HL
49043 LD A,(IX+2) Fetch the third byte of the object.
49046 AND %00011111 Keep the kind of the object.
49048 LD (HL),A Store it in the record.
49049 INC HL Move on past the record.
Store the address of the next free record, and count the record.
RecordObject_Store 49050 LD (48962),HL Patch the address of the next free record into the first instruction.
49053 LD A,(48499) Fetch the number of records.
49056 INC A Add one.
49057 LD (48499),A Store the number of records.
49060 RET Return.
Prev: 48641 Up: Map Next: 49061