Prev: CE8B Up: Map Next: CEC3
CEBB: Draw the listed objects, back to front
Used by the routine at draw_and_copy_rects.
This is where Knight Lore decides what is in front of what. Every listed object is an axis-aligned box in the room: centre X and Y with half-sizes at +$04 and +$05, and a base Z with a height at +$06. On the screen +X runs down and to the right and +Y up and to the right, so the far side of anything is towards smaller X, larger Y and smaller Z.
It repeatedly takes the first object in objects_to_draw not yet drawn as the candidate (IX) and compares it with every other undrawn one (IY). If some IY has to be drawn before the candidate, IY becomes the candidate and the comparison starts again from the top of the list; when a candidate survives a full pass it is drawn, marked done, and the whole thing starts over. So each draw is of an object with nothing undrawn behind it.
The comparison classifies the two boxes on each axis into IX clear on the near side, overlapping, or IY clear on the near side, and combines the three into an index 0 to 26 into depth_order_tbl. The rule the table encodes: IY must go first when, on every axis, IY is either further back than IX or overlapping it, and is further back on at least one. Any other arrangement places no constraint on the pair.
The order found need not be consistent -- three boxes can each be behind the next -- so the chain of candidates is recorded in candidate_chain, and meeting an object already in it breaks the cycle by drawing that object at once (break_order_cycle).
$5BBE counts the objects drawn; end_of_frame uses it to pace the frame.
calc_display_order_and_render CEBB XOR A no objects drawn yet
CEBC LD ($5BBE),A
CEBF PUSH IX
CEC1 PUSH IY
Prev: CE8B Up: Map Next: CEC3