Prev: C86C Up: Map Next: C8AB
C86F: The other object must be drawn first
Reached through DEPTH_ORDER. IY is behind the candidate, so it becomes the candidate instead -- unless it is already in the chain of objects that have been candidates since the last draw (CANDIDATE_CHAIN), in which case the order has gone round in a circle and IY is drawn straight away.
IY_GOES_FIRST C86F LD HL,(SORT_SECOND) C = IY's number, from its entry in the list
C872 DEC HL
C873 LD C,(HL)
C874 LD DE,CANDIDATE_CHAIN Search the chain for it
IY_GOES_FIRST_0 C877 LD A,(DE)
C878 CP $FF
C87A JR Z,IY_BECOMES_CANDIDATE
C87C CP C
C87D JR Z,BREAK_ORDER_CYCLE
C87F INC DE
C880 JR IY_GOES_FIRST_0
IY_BECOMES_CANDIDATE C882 LD A,C Not there: add it, with a new $FF after it
C883 LD (DE),A
C884 INC DE
C885 LD A,$FF
C887 LD (DE),A
C888 PUSH IY IX = IY, and SORT_FIRST = SORT_SECOND
C88A POP IX
C88C LD HL,(SORT_SECOND)
C88F LD (SORT_FIRST),HL
C892 LD DE,DRAW_LIST Compare it with the whole list from the top, since it need not be the first undrawn entry
C895 JP COMPARE_NEXT_OBJ
BREAK_ORDER_CYCLE C898 LD HL,DRAW_LIST A circle: find IY's entry in the list (its number is certain to be there, so the exit to a new pass is never taken)
IY_GOES_FIRST_1 C89B LD A,(HL)
C89C INC HL
C89D CP $FF
C89F JP Z,SORT_PASS
C8A2 CP C
C8A3 JR NZ,IY_GOES_FIRST_1
C8A5 PUSH IY IX = IY; draw it, HL just past its entry
C8A7 POP IX
C8A9 JR DRAW_AND_NEXT_PASS
Prev: C86C Up: Map Next: C8AB