Prev: EDC1 Up: Map Next: EE73
EDC6: Put the objects behind in drawing order, and draw them into pages $DA and $DB
Used by the routine at REDRAW_OBJECT.
Called by REDRAW_OBJECT when the list that CULL_OBJECT built at page $DA has something to draw (bit 1 of IY+$71). The list holds record numbers; IY+$7F the index of the last. Krumlinde's name for it is RTN_Sort_And_Draw_Sprites.
First the list is sorted. For each place in turn, the entries after it are tested against the one there with IS_IN_FRONT; if one of them stands in front of it, the entry is taken out, the rest close up, it goes on the end, and whatever now fills its place is tested in turn. The list is drawn from the end back, so each object is drawn before anything in front of it. An isometric scene has no single depth to sort by, and three objects can each stand in front of the next; the fifty moves allowed at each place (IY+$7E) are what stop such a ring from sorting forever.
Then the list is copied up to IY+$46, since the pages it lies in are about to be cleared -- thirty bytes whatever its length, over the printer's position and the room origin, which are wanted only while printing or drawing a room -- and drawn: each object's cover is ORed into page $DA and cleared out of page $DB (mode 4), and its image ORed into page $DB (mode 8). So page $DA ends up with where the objects behind cover the region, and page $DB with what they show, nearer over farther. In an ordinary pass the entries at the back of the list that are scenery or doors are skipped, because the clean copy the compositor starts from already shows them; from the first live object on everything is drawn, scenery included, since it has to cover that object. In the scenery pass everything is drawn.
SORT_AND_DRAW_BEHIND EDC6 LD HL,BUFFER_DA00 One entry: nothing to sort. IY+$74 counts the places still to settle
EDC9 LD A,(RIDE_DIRECTION)
EDCC AND A
EDCD LD (WORK_WEIGHT),A
EDD0 JR Z,SORT_AND_DRAW_BEHIND_5
SORT_AND_DRAW_BEHIND_0 EDD2 LD (IY+DRAW_COUNT-V),$32 At most fifty moves at this place
SORT_AND_DRAW_BEHIND_1 EDD6 LD B,(HL) The record at this place, and its far corner
EDD7 CALL RECORD_FROM_NUMBER
EDDA CALL FAR_CORNER
EDDD LD B,(IY+WORK_WEIGHT-V) Test each entry after it; none in front: the place is settled
EDE0 PUSH HL
SORT_AND_DRAW_BEHIND_2 EDE1 INC HL
EDE2 LD A,(HL)
EDE3 EXX
EDE4 LD B,A
EDE5 CALL RECORD_FROM_NUMBER
EDE8 EXX
EDE9 CALL IS_IN_FRONT
EDEC BIT 0,(IY+WORK_DIRECTION-V)
EDF0 JR NZ,SORT_AND_DRAW_BEHIND_3
EDF2 DJNZ SORT_AND_DRAW_BEHIND_2
EDF4 JR SORT_AND_DRAW_BEHIND_4
SORT_AND_DRAW_BEHIND_3 EDF6 POP HL One is in front: take this entry out and close up the list...
EDF7 PUSH HL
EDF8 LD A,(HL)
EDF9 PUSH HL
EDFA POP DE
EDFB INC HL
EDFC LD BC,$001E
EDFF LDIR
EE01 LD L,(IY+RIDE_DIRECTION-V) ...and put it on the end
EE04 LD H,$DA
EE06 LD (HL),A
EE07 DEC (IY+DRAW_COUNT-V) Test what now fills the place, unless the moves are used up
EE0A JR Z,SORT_AND_DRAW_BEHIND_4
EE0C POP HL
EE0D JR SORT_AND_DRAW_BEHIND_1
SORT_AND_DRAW_BEHIND_4 EE0F POP HL The next place
EE10 INC HL
EE11 DEC (IY+WORK_WEIGHT-V)
EE14 JR NZ,SORT_AND_DRAW_BEHIND_0
SORT_AND_DRAW_BEHIND_5 EE16 LD HL,BUFFER_DA00 Keep the list up at IY+$46, out of the pages about to be cleared
EE19 LD DE,DRAW_LIST
EE1C LD BC,$001E
EE1F LDIR
EE21 LD HL,BUFFER_DC00 Clear pages $DA and $DB (512 bytes), and start at the last entry (IY+DRAW_COUNT-V)
EE24 LD A,(RIDE_DIRECTION)
EE27 LD (IY+DRAW_COUNT-V),A
EE2A CALL CLEAR_512_BELOW
EE2D BIT 4,(IY+GAME_FLAGS-V) An ordinary pass: nothing is drawn until the first live object
EE31 JR NZ,SORT_AND_DRAW_BEHIND_6
EE33 RES 1,(IY+WORK_DIRECTION-V)
SORT_AND_DRAW_BEHIND_6 EE37 LD H,$FF The record at this index
EE39 LD A,(DRAW_COUNT)
EE3C ADD A,$C6
EE3E LD L,A
EE3F LD B,(HL)
EE40 CALL RECORD_FROM_NUMBER
EE43 BIT 1,(IY+WORK_DIRECTION-V) Until then, skip scenery and doors; draw from the first live object on
EE47 JR NZ,SORT_AND_DRAW_BEHIND_7
EE49 LD A,(IX+OBJ_KIND)
EE4C AND $0F
EE4E CP $01
EE50 JR Z,SORT_AND_DRAW_BEHIND_8
EE52 LD A,(IX+OBJ_WEIGHT)
EE55 AND $1F
EE57 JR Z,SORT_AND_DRAW_BEHIND_8
EE59 SET 1,(IY+WORK_DIRECTION-V)
SORT_AND_DRAW_BEHIND_7 EE5D LD A,$04 Its cover into page $DA, its image into page $DB
EE5F CALL DRAW_SPRITE
EE62 LD A,$08
EE64 CALL DRAW_SPRITE
SORT_AND_DRAW_BEHIND_8 EE67 LD A,(DRAW_COUNT) On to the first entry
EE6A DEC A
EE6B LD (DRAW_COUNT),A
EE6E CP $FF
EE70 JR NZ,SORT_AND_DRAW_BEHIND_6
EE72 RET
Prev: EDC1 Up: Map Next: EE73