Prev: C745 Up: Map Next: C833
C785: 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.
Clear the count and find the first object that is still waiting.
DrawObjectsInOrder C785 XOR A Write 00 to ObjectsDrawn.
C786 LD ($5B1E),A
C789 PUSH IX Stash IX and IY on the stack.
C78B PUSH IY
This entry point is used by the routines at CompareWithOtherObject and DrawNextObject.
DrawObjectsInOrder_First C78D LD DE,$C745 Point DE at ObjectsToDrawList.
Skip entries that have already been drawn.
DrawObjectsInOrder_FindFirst C790 LD A,(DE) Fetch an index from the list.
C791 INC DE Move on to the next entry.
C792 CP $FF Jump to DrawNextObject_Finish if it is the end of the list.
C794 JP Z,DrawNextObject_Finish
C797 BIT 7,A Jump to DrawObjectsInOrder_FindFirst if the object has been drawn.
C799 JR NZ,DrawObjectsInOrder_FindFirst
C79B CALL FindObjectAddress Find the address of the object.
C79E LD ($5B2D),DE Remember the place in the list.
C7A2 PUSH HL Point IX at the object (using the stack).
C7A3 POP IX
This entry point is used by the routines at ContinueComparingObjects, CompareWithOtherObject and ReplaceOverlappingSpecialObject.
Compare it with each later object that is still waiting.
DrawObjectsInOrder_FindSecond C7A5 LD A,(DE) Fetch an index from the list.
C7A6 INC DE Move on to the next entry.
C7A7 CP $FF Jump to DrawNextObject if it is the end of the list, as nothing has to be drawn before the first object.
C7A9 JP Z,DrawNextObject
C7AC BIT 7,A Jump to DrawObjectsInOrder_FindSecond if the object has been drawn.
C7AE JR NZ,DrawObjectsInOrder_FindSecond
C7B0 CALL FindObjectAddress Find the address of the object.
C7B3 LD ($5B2F),DE Remember the place in the list.
C7B7 PUSH HL Point IY at the other object (using the stack).
C7B8 POP IY
C7BA PUSH IX Copy IX to BC (using the stack).
C7BC POP BC
C7BD AND A Jump to DrawObjectsInOrder_FindSecond if they are the same object.
C7BE SBC HL,BC
C7C0 JR Z,DrawObjectsInOrder_FindSecond
Each of the three directions gives a number. The number along z is 00 if the first object is above the other, 01 if the objects overlap along z and 02 if the first object is below. The number along y is 00 if the first object is to the north of the other, 03 if the objects overlap along y and 06 if the first object is to the south. The number along x is 00 if the first object is to the east of the other, 09 if the objects overlap along x and 12 if the first object is to the west. The three numbers are added together in C.
C7C2 LD C,$00 Set the number to 00.
C7C4 LD A,(IY+$03) Work out where the top of the other object is.
C7C7 ADD A,(IY+$06)
C7CA LD L,A
C7CB LD A,(IX+$03) Take it off the z position of the first object.
C7CE SUB L
C7CF JR NC,DrawObjectsInOrder_Y Jump to DrawObjectsInOrder_Y if the first object is above the other.
C7D1 LD A,(IX+$03) Work out where the top of the first object is.
C7D4 ADD A,(IX+$06)
C7D7 LD L,A
C7D8 LD A,(IY+$03) Take it off the z position of the other object.
C7DB SUB L
C7DC JR C,DrawObjectsInOrder_Overlap Jump to DrawObjectsInOrder_Overlap if the objects overlap along z.
C7DE INC C Add one to the number along z.
DrawObjectsInOrder_Overlap C7DF INC C Add one to the number along z.
Add the number along y.
DrawObjectsInOrder_Y C7E0 LD A,(IY+$02) Work out where the north edge of the other object is.
C7E3 ADD A,(IY+$05)
C7E6 LD L,A
C7E7 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.
C7EA SUB (IX+$05)
C7ED SUB L
C7EE JR NC,DrawObjectsInOrder_X Jump to DrawObjectsInOrder_X if the first object is to the north of the other.
C7F0 LD A,(IX+$02) Work out where the north edge of the first object is.
C7F3 ADD A,(IX+$05)
C7F6 LD L,A
C7F7 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.
C7FA SUB (IY+$05)
C7FD SUB L
C7FE LD A,C Fetch the number so far.
C7FF JR C,DrawObjectsInOrder_OverlapY Jump to DrawObjectsInOrder_OverlapY if the objects overlap along y.
C801 ADD A,$03 Add 03 to the number along y.
DrawObjectsInOrder_OverlapY C803 ADD A,$03 Add 03 to the number along y.
C805 LD C,A Store the number.
Add the number along x.
DrawObjectsInOrder_X C806 LD A,(IY+$01) Work out where the east edge of the other object is.
C809 ADD A,(IY+$04)
C80C LD L,A
C80D 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.
C810 SUB (IX+$04)
C813 SUB L
C814 JR NC,DrawObjectsInOrder_Jump Jump to DrawObjectsInOrder_Jump if the first object is to the east of the other.
C816 LD A,(IX+$01) Work out where the east edge of the first object is.
C819 ADD A,(IX+$04)
C81C LD L,A
C81D 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.
C820 SUB (IY+$04)
C823 SUB L
C824 LD A,C Fetch the number so far.
C825 JR C,DrawObjectsInOrder_OverlapX Jump to DrawObjectsInOrder_OverlapX if the objects overlap along x.
C827 ADD A,$09 Add 09 to the number along x.
DrawObjectsInOrder_OverlapX C829 ADD A,$09 Add 09 to the number along x.
C82B LD C,A Store the number.
Jump to the routine for the number.
DrawObjectsInOrder_Jump C82C LD L,C Use the number as the index into the table.
C82D LD BC,$C833 Point BC at DrawingOrderTable.
C830 JP RunGame_JumpToHandler Jump to RunGame_JumpToHandler.
View the equivalent code in;
Prev: C745 Up: Map Next: C833