Prev: CFAF Up: Map Next: D0A0
CFF2: Draw Objects In List
Used by the routine at DrawCellAndObjects.
Draws the objects in the list at ObjectList, which are the objects in one cell. The objects are drawn so that the ones further from the viewer come first. Each time it takes the first object in the list which has not been drawn, compares it with each of the rest, and swaps it for any object which should be drawn before it. It then draws the object it is left with, and marks it as drawn by clearing bit 7 of the high byte of its address in the list.
Find the first object in the list which has not been drawn.
DrawObjectsInList CFF2 LD HL,$D15D Point HL at ObjectList.
DrawObjectsInList_Next CFF5 LD E,(HL) Fetch the address of the next object into DE.
CFF6 INC HL
CFF7 LD D,(HL)
CFF8 INC HL
CFF9 LD A,D Return if this is the end of the list.
CFFA OR E
CFFB RET Z
CFFC BIT 7,D Skip the entry if the object has been drawn already.
CFFE JR Z,DrawObjectsInList_Next
Remember where the next place in the list is.
D000 LD ($BBC4),HL Set ChosenObjectPosition.
D003 PUSH DE Copy the address of the object into IX (using the stack).
D004 POP IX
Compare this object with each of the others which have not been drawn.
DrawObjectsInList_Compare D006 LD E,(HL) Fetch the address of the next object into DE.
D007 INC HL
D008 LD D,(HL)
D009 INC HL
Draw the first object if this is the end of the list.
D00A LD A,D Jump to DrawObjectsInList_Draw to draw the object if it is the zero word that marks the end of the list.
D00B OR E
D00C JP Z,DrawObjectsInList_Draw
D00F BIT 7,D Skip the entry if the object has been drawn already.
D011 JR Z,DrawObjectsInList_Compare
Remember where the next place in the list is.
D013 LD ($BBC6),HL Set ComparedObjectPosition.
D016 PUSH DE Copy the address of the object into IY (using the stack).
D017 POP IY
D019 LD C,$00 Clear the number which says how the objects compare.
Compare the objects from side to side. The number in C stays at zero if the first object starts after the second ends, becomes two if the second starts after the first ends, and becomes one if they overlap.
D01B LD A,(IY+$01) Fetch the horizontal position of the second object and add its horizontal size.
D01E ADD A,(IY+$08)
D021 RRA Halve it, add 40 and keep the result in B.
D022 ADD A,$40
D024 LD B,A
Work out the smallest extent of the object at IX, and subtract the largest extent of the object at IY.
D025 LD A,(IX+$01) Fetch the horizontal position of the first object and subtract its horizontal size.
D028 SUB (IX+$08)
D02B RRA Halve it and add 40.
D02C ADD A,$40
D02E SUB B Jump to DrawObjectsInList_Y if the first object starts after the second ends.
D02F JR NC,DrawObjectsInList_Y
Work out the largest extent of the object at IX.
D031 LD A,(IX+$01) Fetch the horizontal position of the first object and add its horizontal size.
D034 ADD A,(IX+$08)
D037 RRA Halve it, add 40 and keep the result in B.
D038 ADD A,$40
D03A LD B,A
Work out the smallest extent of the object at IY, and subtract the largest extent of the object at IX.
D03B LD A,(IY+$01) Fetch the horizontal position of the second object and subtract its horizontal size.
D03E SUB (IY+$08)
D041 RRA Halve it and add 40.
D042 ADD A,$40
D044 SUB B Jump to DrawObjectsInList_Overlap if the second object starts before the first ends.
D045 JR C,DrawObjectsInList_Overlap
D047 INC C Add one.
DrawObjectsInList_Overlap D048 INC C Add one more.
Compare the objects from front to back in the same way. This time the number in C has zero, three or six added to it.
DrawObjectsInList_Y D049 LD A,(IY+$03) Fetch the vertical position of the second object and add its vertical size.
D04C ADD A,(IY+$09)
D04F RRA Halve it, add 40 and keep the result in B.
D050 ADD A,$40
D052 LD B,A
Work out the smallest extent of the object at IX, and subtract the largest extent of the object at IY.
D053 LD A,(IX+$03) Fetch the vertical position of the first object and subtract its vertical size.
D056 SUB (IX+$09)
D059 RRA Halve it and add 40.
D05A ADD A,$40
D05C SUB B Subtract the end of the second object.
D05D LD A,C Fetch the number.
D05E JR NC,DrawObjectsInList_Relation Jump to DrawObjectsInList_Relation if the object at IX is wholly beyond it.
Work out the largest extent of the object at IX.
D060 LD A,(IX+$03) Fetch the vertical position of the first object and add its vertical size.
D063 ADD A,(IX+$09)
D066 RRA Halve it, add 40 and keep the result in B.
D067 ADD A,$40
D069 LD B,A
Work out the smallest extent of the object at IY, and subtract the largest extent of the object at IX.
D06A LD A,(IY+$03) Fetch the vertical position of the second object and subtract its vertical size.
D06D SUB (IY+$09)
D070 RRA Halve it and add 40.
D071 ADD A,$40
D073 SUB B Subtract the end of the first object.
D074 LD A,C Fetch the number.
D075 JR C,DrawObjectsInList_YOverlap Jump to DrawObjectsInList_YOverlap if they overlap.
D077 ADD A,$03 Add three.
DrawObjectsInList_YOverlap D079 ADD A,$03 Add three more.
DrawObjectsInList_Relation D07B LD C,A Keep the number in C.
Fetch the rotation of the view.
D07C LD A,($BBBA) Fetch ViewRotatedFlag.
D07F AND %00000001 Test the lowest bit.
D081 JR Z,DrawObjectsInList_Choose Jump to DrawObjectsInList_Choose if the view is not rotated.
D083 LD A,C Add 09 to the number, to use the second half of the table.
D084 ADD A,$09
D086 LD C,A
Run the routine in the table at ObjectOrderTable for the relation, which does nothing if the object at IX is to be drawn first, and otherwise makes the object at IY the object at IX (see ChooseOtherObject), or compares them further.
DrawObjectsInList_Choose D087 LD A,C Fetch the number.
D088 LD BC,$D0A0 Point BC at ObjectOrderTable.
Run the routine for the number.
D08B CALL JumpToTableRoutine Call JumpToTableRoutine.
Fetch the place in the list after the second object.
D08E LD HL,($BBC6) Fetch ComparedObjectPosition.
Go back to compare the next object.
D091 JP DrawObjectsInList_Compare Jump to DrawObjectsInList_Compare.
There are no more objects to compare with, so the first object is the one to draw. Mark it as drawn, using the place kept at ChosenObjectPosition.
DrawObjectsInList_Draw D094 LD HL,($BBC4) Mark the entry for the object at IX as drawn.
D097 DEC HL
D098 RES 7,(HL)
Draw the object.
D09A CALL DrawObject Draw the object.
Go back to find the next object to draw.
D09D JP DrawObjectsInList Go back to draw the objects that are left in the list.
View the equivalent code in;
Prev: CFAF Up: Map Next: D0A0