![]() |
Routines |
| Prev: B55A | Up: Map | Next: B638 |
|
Used by the routine at RENDER_DYNAMIC_OBJECTS.
Called by RENDER_DYNAMIC_OBJECTS. This is where the game decides what is in front of what; the code is Knight Lore's. Every listed object is a box in the room: centre U and V with half-sizes at +$04 and +$05, a base Z with its whole height at +$06. The far side of anything is towards smaller U, larger V and lower Z (measured in the simulator with pairs of boxes: the one with smaller U, larger V or lower base was drawn first).
It takes the first object in DRAW_LIST 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; a candidate that survives a whole pass is drawn, marked done, and the whole thing starts over. So each object drawn has nothing undrawn behind it.
The comparison classifies the two boxes on each axis -- IX clear on one side, overlapping, IY clear on one side -- and adds the three into an index 0-26 into DEPTH_ORDER. The order found need not be consistent (three boxes can each be behind the next), so the chain of candidates is kept in CANDIDATE_CHAIN, and meeting an object already in it breaks the circle by drawing that object at once.
DRAW_WORK counts the objects drawn; RENDER_DYNAMIC_OBJECTS adds the rectangles it wiped, and the main loop waits less the more work a turn has done. SORT_FIRST and SORT_SECOND point just past the candidate's entry and the compared object's.
|
||||||||||
| SORT_AND_DRAW | B58A | XOR A | no objects drawn yet | |||||||
| B58B | LD (DRAW_WORK),A | |||||||||
| B58E | PUSH IX | |||||||||
| B590 | PUSH IY | |||||||||
|
This entry point is used by the routines at IY_GOES_FIRST and DRAW_CANDIDATE.
|
||||||||||
| SORT_PASS | B592 | LD DE,DRAW_LIST | a pass: from the top of the list | |||||||
| SORT_AND_DRAW_0 | B595 | LD A,(DE) | the end of the list: everything is drawn | |||||||
| B596 | INC DE | |||||||||
| B597 | CP $FF | |||||||||
| B599 | JP Z,ALL_DRAWN | |||||||||
| B59C | BIT 7,A | bit 7: already drawn | ||||||||
| B59E | JR NZ,SORT_AND_DRAW_0 | |||||||||
| B5A0 | CALL RECORD_OF | IX = the candidate; SORT_FIRST just past its entry | ||||||||
| B5A3 | LD (SORT_FIRST),DE | |||||||||
| B5A7 | PUSH HL | |||||||||
| B5A8 | POP IX | |||||||||
|
This entry point is used by the routines at ORDER_UNCONSTRAINED, CANDIDATE_ALREADY_FIRST, IY_GOES_FIRST and BOXES_INTERSECT.
|
||||||||||
| COMPARE_NEXT_OBJ | B5AA | LD A,(DE) | the end of the list: nothing is behind the candidate, so draw it | |||||||
| B5AB | INC DE | |||||||||
| B5AC | CP $FF | |||||||||
| B5AE | JP Z,DRAW_CANDIDATE | |||||||||
| B5B1 | BIT 7,A | already drawn: skip | ||||||||
| B5B3 | JR NZ,COMPARE_NEXT_OBJ | |||||||||
| B5B5 | CALL RECORD_OF | IY = this object; SORT_SECOND just past its entry | ||||||||
| B5B8 | LD (SORT_SECOND),DE | |||||||||
| B5BC | PUSH HL | |||||||||
| B5BD | POP IY | |||||||||
| B5BF | PUSH IX | the candidate itself: skip | ||||||||
| B5C1 | POP BC | |||||||||
| B5C2 | AND A | |||||||||
| B5C3 | SBC HL,BC | |||||||||
| B5C5 | JR Z,COMPARE_NEXT_OBJ | |||||||||
| B5C7 | LD C,$00 | Z: code 0 if the candidate's base is at or above IY's top | ||||||||
| B5C9 | LD A,(IY+$03) | |||||||||
| B5CC | ADD A,(IY+$06) | |||||||||
| B5CF | LD L,A | |||||||||
| B5D0 | LD A,(IX+$03) | |||||||||
| B5D3 | SUB L | |||||||||
| B5D4 | JR NC,COMPARE_ALONG_V | |||||||||
| B5D6 | LD A,(IX+$03) | code 2 if IY's base is at or above the candidate's top, 1 if they overlap | ||||||||
| B5D9 | ADD A,(IX+$06) | |||||||||
| B5DC | LD L,A | |||||||||
| B5DD | LD A,(IY+$03) | |||||||||
| B5E0 | SUB L | |||||||||
| B5E1 | JR C,SORT_AND_DRAW_1 | |||||||||
| B5E3 | INC C | |||||||||
| SORT_AND_DRAW_1 | B5E4 | INC C | ||||||||
| COMPARE_ALONG_V | B5E5 | LD A,(IY+$02) | V: add 0 if the candidate's low-V edge is at or beyond IY's high-V edge, the candidate lying wholly further back | |||||||
| B5E8 | ADD A,(IY+$05) | |||||||||
| B5EB | LD L,A | |||||||||
| B5EC | LD A,(IX+$02) | |||||||||
| B5EF | SUB (IX+$05) | |||||||||
| B5F2 | SUB L | |||||||||
| B5F3 | JR NC,COMPARE_ALONG_U | |||||||||
| B5F5 | LD A,(IX+$02) | add 6 if IY lies wholly further back, 3 if they overlap | ||||||||
| B5F8 | ADD A,(IX+$05) | |||||||||
| B5FB | LD L,A | |||||||||
| B5FC | LD A,(IY+$02) | |||||||||
| B5FF | SUB (IY+$05) | |||||||||
| B602 | SUB L | |||||||||
| B603 | LD A,C | |||||||||
| B604 | JR C,SORT_AND_DRAW_2 | |||||||||
| B606 | ADD A,$03 | |||||||||
| SORT_AND_DRAW_2 | B608 | ADD A,$03 | ||||||||
| B60A | LD C,A | |||||||||
| COMPARE_ALONG_U | B60B | LD A,(IY+$01) | U: add 0 if the candidate's low-U edge is at or beyond IY's high-U edge, IY lying wholly further back | |||||||
| B60E | ADD A,(IY+$04) | |||||||||
| B611 | LD L,A | |||||||||
| B612 | LD A,(IX+$01) | |||||||||
| B615 | SUB (IX+$04) | |||||||||
| B618 | SUB L | |||||||||
| B619 | JR NC,ACT_ON_COMPARISON | |||||||||
| B61B | LD A,(IX+$01) | add 18 if the candidate lies wholly further back, 9 if they overlap | ||||||||
| B61E | ADD A,(IX+$04) | |||||||||
| B621 | LD L,A | |||||||||
| B622 | LD A,(IY+$01) | |||||||||
| B625 | SUB (IY+$04) | |||||||||
| B628 | SUB L | |||||||||
| B629 | LD A,C | |||||||||
| B62A | JR C,SORT_AND_DRAW_3 | |||||||||
| B62C | ADD A,$09 | |||||||||
| SORT_AND_DRAW_3 | B62E | ADD A,$09 | ||||||||
| B630 | LD C,A | |||||||||
| ACT_ON_COMPARISON | B631 | LD L,C | jump through DEPTH_ORDER, as the main loop jumps through the update table | |||||||
| B632 | LD BC,DEPTH_ORDER | |||||||||
| B635 | JP JUMP_TO_TBL_ENTRY | |||||||||
| Prev: B55A | Up: Map | Next: B638 |