Prev: 52875 Up: Map Next: 53097
52923: Draw Objects In Order
Used by the routine at DrawChangedObjects.
Draws the objects in the list at ObjectsToDrawList so that the objects at the back are drawn before the objects in front of them. It takes the first object in the list that has not been drawn yet and compares it with each of the other objects that are waiting. If another object has to be drawn first, that object takes the place of the first object and is compared with the others in its turn. This carries on until an object is found that does not have to wait for any other object, and that one is drawn. This is repeated until the list is empty. The objects drawn are counted in ObjectsDrawn.
DrawObjectsInOrder 52923 XOR A Set the number of objects drawn to zero at ObjectsDrawn.
52924 LD (23486),A
52927 PUSH IX Stash IX and IY on the stack.
52929 PUSH IY
This entry point is used by the routines at CompareWithOtherObject and DrawNextObject.
DrawObjectsInOrder_First 52931 LD DE,52875 Point DE at the list, ObjectsToDrawList.
DrawObjectsInOrder_FindFirst 52934 LD A,(DE) Fetch the index of an object from the list.
52935 INC DE Move on to the next entry.
52936 CP 255 Jump to DrawNextObject_Finish if it is the end of the list.
52938 JP Z,DrawNextObject_Finish
52941 BIT 7,A Jump to DrawObjectsInOrder_FindFirst if the object has been drawn.
52943 JR NZ,DrawObjectsInOrder_FindFirst
52945 CALL FindObjectAddress Find the address of the object.
52948 LD (23501),DE Remember the place in the list at FirstListPosition.
52952 PUSH HL Point IX at the object (using the stack).
52953 POP IX
This entry point is used by the routines at ContinueComparingObjects, CompareWithOtherObject and ReplaceOverlappingSpecialObject.
DrawObjectsInOrder_FindSecond 52955 LD A,(DE) Fetch the index of another object from the list.
52956 INC DE Move on to the next entry.
52957 CP 255 Jump to DrawNextObject if it is, as nothing has to be drawn before the first object.
52959 JP Z,DrawNextObject
52962 BIT 7,A Jump to DrawObjectsInOrder_FindSecond if the object has been drawn.
52964 JR NZ,DrawObjectsInOrder_FindSecond
52966 CALL FindObjectAddress Find the address of the object.
52969 LD (23503),DE Remember the place in the list at SecondListPosition.
52973 PUSH HL Point IY at the other object (using the stack).
52974 POP IY
52976 PUSH IX Copy the address of the first object to BC (using the stack).
52978 POP BC
52979 AND A Clear the carry flag.
52980 SBC HL,BC Test whether the other object is the first object.
52982 JR Z,DrawObjectsInOrder_FindSecond Jump to DrawObjectsInOrder_FindSecond if it is.
Each of the three directions gives a number. The number in Z is 0 if the first object is above the other, 1 if the objects overlap in Z and 2 if the first object is below. The number in Y is 0 if the first object is to the north of the other, 3 if the objects overlap in Y and 6 if the first object is to the south. The number in X is 0 if the first object is to the east of the other, 9 if the objects overlap in X and 18 if the first object is to the west. The three numbers are added together in C.
52984 LD C,0 Set the number to zero.
52986 LD A,(IY+3) Work out where the top of the other object is.
52989 ADD A,(IY+6)
52992 LD L,A
52993 LD A,(IX+3) Take it off the Z coordinate of the first object.
52996 SUB L
52997 JR NC,DrawObjectsInOrder_Y Jump to DrawObjectsInOrder_Y if the first object is above the other.
52999 LD A,(IX+3) Work out where the top of the first object is.
53002 ADD A,(IX+6)
53005 LD L,A
53006 LD A,(IY+3) Take it off the Z coordinate of the other object.
53009 SUB L
53010 JR C,DrawObjectsInOrder_Overlap Jump to DrawObjectsInOrder_Overlap if the objects overlap in Z.
53012 INC C Add one to the number in Z.
DrawObjectsInOrder_Overlap 53013 INC C Add one to the number in Z.
DrawObjectsInOrder_Y 53014 LD A,(IY+2) Work out where the north edge of the other object is.
53017 ADD A,(IY+5)
53020 LD L,A
53021 LD A,(IX+2) Work out where the south edge of the first object is, and take the north edge of the other object off it.
53024 SUB (IX+5)
53027 SUB L
53028 JR NC,DrawObjectsInOrder_X Jump to DrawObjectsInOrder_X if the first object is to the north of the other.
53030 LD A,(IX+2) Work out where the north edge of the first object is.
53033 ADD A,(IX+5)
53036 LD L,A
53037 LD A,(IY+2) Work out where the south edge of the other object is, and take the north edge of the first object off it.
53040 SUB (IY+5)
53043 SUB L
53044 LD A,C Fetch the number so far.
53045 JR C,DrawObjectsInOrder_OverlapY Jump to DrawObjectsInOrder_OverlapY if the objects overlap in Y.
53047 ADD A,3 Add 3 to the number in Y.
DrawObjectsInOrder_OverlapY 53049 ADD A,3 Add 3 to the number in Y.
53051 LD C,A Store the number.
DrawObjectsInOrder_X 53052 LD A,(IY+1) Work out where the east edge of the other object is.
53055 ADD A,(IY+4)
53058 LD L,A
53059 LD A,(IX+1) Work out where the west edge of the first object is, and take the east edge of the other object off it.
53062 SUB (IX+4)
53065 SUB L
53066 JR NC,DrawObjectsInOrder_Jump Jump to DrawObjectsInOrder_Jump if the first object is to the east of the other.
53068 LD A,(IX+1) Work out where the east edge of the first object is.
53071 ADD A,(IX+4)
53074 LD L,A
53075 LD A,(IY+1) Work out where the west edge of the other object is, and take the east edge of the first object off it.
53078 SUB (IY+4)
53081 SUB L
53082 LD A,C Fetch the number so far.
53083 JR C,DrawObjectsInOrder_OverlapX Jump to DrawObjectsInOrder_OverlapX if the objects overlap in X.
53085 ADD A,9 Add 9 to the number in X.
DrawObjectsInOrder_OverlapX 53087 ADD A,9 Add 9 to the number in X.
53089 LD C,A Store the number.
DrawObjectsInOrder_Jump 53090 LD L,C Use the number as the index into the table.
53091 LD BC,53097 Point BC at DrawingOrderTable.
53094 JP RunGame_JumpToHandler Jump to the routine for the number.
View the equivalent code in;
Prev: 52875 Up: Map Next: 53097