Prev: CE8B Up: Map Next: CF69
CEBB: 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 CEBB XOR A Set the number of objects drawn to zero at ObjectsDrawn.
CEBC LD ($5BBE),A
CEBF PUSH IX Stash IX and IY on the stack.
CEC1 PUSH IY
This entry point is used by the routines at CompareWithOtherObject and DrawNextObject.
DrawObjectsInOrder_First CEC3 LD DE,$CE8B Point DE at the list, ObjectsToDrawList.
DrawObjectsInOrder_FindFirst CEC6 LD A,(DE) Fetch the index of an object from the list.
CEC7 INC DE Move on to the next entry.
CEC8 CP $FF Jump to DrawNextObject_Finish if it is the end of the list.
CECA JP Z,DrawNextObject_Finish
CECD BIT 7,A Jump to DrawObjectsInOrder_FindFirst if the object has been drawn.
CECF JR NZ,DrawObjectsInOrder_FindFirst
CED1 CALL FindObjectAddress Find the address of the object.
CED4 LD ($5BCD),DE Remember the place in the list at FirstListPosition.
CED8 PUSH HL Point IX at the object (using the stack).
CED9 POP IX
This entry point is used by the routines at ContinueComparingObjects, CompareWithOtherObject and ReplaceOverlappingSpecialObject.
DrawObjectsInOrder_FindSecond CEDB LD A,(DE) Fetch the index of another object from the list.
CEDC INC DE Move on to the next entry.
CEDD CP $FF Jump to DrawNextObject if it is, as nothing has to be drawn before the first object.
CEDF JP Z,DrawNextObject
CEE2 BIT 7,A Jump to DrawObjectsInOrder_FindSecond if the object has been drawn.
CEE4 JR NZ,DrawObjectsInOrder_FindSecond
CEE6 CALL FindObjectAddress Find the address of the object.
CEE9 LD ($5BCF),DE Remember the place in the list at SecondListPosition.
CEED PUSH HL Point IY at the other object (using the stack).
CEEE POP IY
CEF0 PUSH IX Copy the address of the first object to BC (using the stack).
CEF2 POP BC
CEF3 AND A Clear the carry flag.
CEF4 SBC HL,BC Test whether the other object is the first object.
CEF6 JR Z,DrawObjectsInOrder_FindSecond Jump to DrawObjectsInOrder_FindSecond if it is.
Each of the three directions gives a number. The number in Z is 00 if the first object is above the other, 01 if the objects overlap in Z and 02 if the first object is below. The number in Y is 00 if the first object is to the north of the other, 03 if the objects overlap in Y and 06 if the first object is to the south. The number in X is 00 if the first object is to the east of the other, 09 if the objects overlap in X and 12 if the first object is to the west. The three numbers are added together in C.
CEF8 LD C,$00 Set the number to zero.
CEFA LD A,(IY+$03) Work out where the top of the other object is.
CEFD ADD A,(IY+$06)
CF00 LD L,A
CF01 LD A,(IX+$03) Take it off the Z coordinate of the first object.
CF04 SUB L
CF05 JR NC,DrawObjectsInOrder_Y Jump to DrawObjectsInOrder_Y if the first object is above the other.
CF07 LD A,(IX+$03) Work out where the top of the first object is.
CF0A ADD A,(IX+$06)
CF0D LD L,A
CF0E LD A,(IY+$03) Take it off the Z coordinate of the other object.
CF11 SUB L
CF12 JR C,DrawObjectsInOrder_Overlap Jump to DrawObjectsInOrder_Overlap if the objects overlap in Z.
CF14 INC C Add one to the number in Z.
DrawObjectsInOrder_Overlap CF15 INC C Add one to the number in Z.
DrawObjectsInOrder_Y CF16 LD A,(IY+$02) Work out where the north edge of the other object is.
CF19 ADD A,(IY+$05)
CF1C LD L,A
CF1D LD A,(IX+$02) Work out where the south edge of the first object is, and take the north edge of the other object off it.
CF20 SUB (IX+$05)
CF23 SUB L
CF24 JR NC,DrawObjectsInOrder_X Jump to DrawObjectsInOrder_X if the first object is to the north of the other.
CF26 LD A,(IX+$02) Work out where the north edge of the first object is.
CF29 ADD A,(IX+$05)
CF2C LD L,A
CF2D LD A,(IY+$02) Work out where the south edge of the other object is, and take the north edge of the first object off it.
CF30 SUB (IY+$05)
CF33 SUB L
CF34 LD A,C Fetch the number so far.
CF35 JR C,DrawObjectsInOrder_OverlapY Jump to DrawObjectsInOrder_OverlapY if the objects overlap in Y.
CF37 ADD A,$03 Add 03 to the number in Y.
DrawObjectsInOrder_OverlapY CF39 ADD A,$03 Add 03 to the number in Y.
CF3B LD C,A Store the number.
DrawObjectsInOrder_X CF3C LD A,(IY+$01) Work out where the east edge of the other object is.
CF3F ADD A,(IY+$04)
CF42 LD L,A
CF43 LD A,(IX+$01) Work out where the west edge of the first object is, and take the east edge of the other object off it.
CF46 SUB (IX+$04)
CF49 SUB L
CF4A JR NC,DrawObjectsInOrder_Jump Jump to DrawObjectsInOrder_Jump if the first object is to the east of the other.
CF4C LD A,(IX+$01) Work out where the east edge of the first object is.
CF4F ADD A,(IX+$04)
CF52 LD L,A
CF53 LD A,(IY+$01) Work out where the west edge of the other object is, and take the east edge of the first object off it.
CF56 SUB (IY+$04)
CF59 SUB L
CF5A LD A,C Fetch the number so far.
CF5B JR C,DrawObjectsInOrder_OverlapX Jump to DrawObjectsInOrder_OverlapX if the objects overlap in X.
CF5D ADD A,$09 Add 09 to the number in X.
DrawObjectsInOrder_OverlapX CF5F ADD A,$09 Add 09 to the number in X.
CF61 LD C,A Store the number.
DrawObjectsInOrder_Jump CF62 LD L,C Use the number as the index into the table.
CF63 LD BC,$CF69 Point BC at DrawingOrderTable.
CF66 JP RunGame_JumpToHandler Jump to the routine for the number.
View the equivalent code in;
Prev: CE8B Up: Map Next: CF69