Prev: C1A4 Up: Map Next: C295
C1E7: Draw Objects In List
Used by the routine at DrawCellObjects.
Draws the objects in the list at CellObjectList, 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 C1E7 LD HL,$C352 Point HL at CellObjectList.
DrawObjectsInList_First C1EA LD E,(HL) Fetch the address of the next object into DE.
C1EB INC HL
C1EC LD D,(HL)
C1ED INC HL
C1EE LD A,D Return if this is the end of the list.
C1EF OR E
C1F0 RET Z
C1F1 BIT 7,D Jump to DrawObjectsInList_First if it has been drawn.
C1F3 JR Z,DrawObjectsInList_First
Remember where the next place in the list is.
C1F5 LD ($A24A),HL Set FirstObjectPosition.
C1F8 PUSH DE Copy the address of the object into IX (using the stack).
C1F9 POP IX
Compare this object with each of the others which have not been drawn.
DrawObjectsInList_Next C1FB LD E,(HL) Fetch the address of the next object into DE.
C1FC INC HL
C1FD LD D,(HL)
C1FE INC HL
Draw the first object if this is the end of the list.
C1FF LD A,D Jump to DrawObjectsInList_Draw if it is.
C200 OR E
C201 JP Z,DrawObjectsInList_Draw
C204 BIT 7,D Jump to DrawObjectsInList_Next if it has been drawn.
C206 JR Z,DrawObjectsInList_Next
Remember where the next place in the list is.
C208 LD ($A24C),HL Set SecondObjectPosition.
C20B PUSH DE Copy the address of the object into IY (using the stack).
C20C POP IY
C20E 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.
C210 LD A,(IY+$01) Fetch the horizontal position of the second object and add its horizontal size.
C213 ADD A,(IY+$08)
C216 RRA Halve it, add 40 and keep the result in B.
C217 ADD A,$40
C219 LD B,A
C21A LD A,(IX+$01) Fetch the horizontal position of the first object and subtract its horizontal size.
C21D SUB (IX+$08)
C220 RRA Halve it and add 40.
C221 ADD A,$40
C223 SUB B Jump to DrawObjectsInList_Depth if the first object starts after the second ends.
C224 JR NC,DrawObjectsInList_Depth
C226 LD A,(IX+$01) Fetch the horizontal position of the first object and add its horizontal size.
C229 ADD A,(IX+$08)
C22C RRA Halve it, add 40 and keep the result in B.
C22D ADD A,$40
C22F LD B,A
C230 LD A,(IY+$01) Fetch the horizontal position of the second object and subtract its horizontal size.
C233 SUB (IY+$08)
C236 RRA Halve it and add 40.
C237 ADD A,$40
C239 SUB B Jump to DrawObjectsInList_AddOne if the second object starts before the first ends.
C23A JR C,DrawObjectsInList_AddOne
C23C INC C Add one.
DrawObjectsInList_AddOne C23D 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_Depth C23E LD A,(IY+$03) Fetch the vertical position of the second object and add its vertical size.
C241 ADD A,(IY+$09)
C244 RRA Halve it, add 40 and keep the result in B.
C245 ADD A,$40
C247 LD B,A
C248 LD A,(IX+$03) Fetch the vertical position of the first object and subtract its vertical size.
C24B SUB (IX+$09)
C24E RRA Halve it and add 40.
C24F ADD A,$40
C251 SUB B Subtract the end of the second object.
C252 LD A,C Fetch the number.
C253 JR NC,DrawObjectsInList_Rotated Jump to DrawObjectsInList_Rotated if the first object starts after the second ends.
C255 LD A,(IX+$03) Fetch the vertical position of the first object and add its vertical size.
C258 ADD A,(IX+$09)
C25B RRA Halve it, add 40 and keep the result in B.
C25C ADD A,$40
C25E LD B,A
C25F LD A,(IY+$03) Fetch the vertical position of the second object and subtract its vertical size.
C262 SUB (IY+$09)
C265 RRA Halve it and add 40.
C266 ADD A,$40
C268 SUB B Subtract the end of the first object.
C269 LD A,C Fetch the number.
C26A JR C,DrawObjectsInList_AddThree Jump to DrawObjectsInList_AddThree if the second object starts before the first ends.
C26C ADD A,$03 Add three.
DrawObjectsInList_AddThree C26E ADD A,$03 Add three more.
DrawObjectsInList_Rotated C270 LD C,A Keep the number in C.
Fetch the rotation of the view.
C271 LD A,($A268) Fetch ViewRotation.
C274 AND %00000001 Test the lowest bit.
C276 JR Z,DrawObjectsInList_Choose Jump to DrawObjectsInList_Choose if the view is not rotated.
C278 LD A,C Add 09 to the number, to use the second half of the table.
C279 ADD A,$09
C27B LD C,A
DrawObjectsInList_Choose C27C LD A,C Fetch the number.
C27D LD BC,$C295 Point BC at ObjectOrderRoutines.
Run the routine for the number.
C280 CALL RunTableRoutine Call RunTableRoutine.
Fetch the place in the list after the second object.
C283 LD HL,($A24C) Fetch SecondObjectPosition.
Go back to compare the next object.
C286 JP DrawObjectsInList_Next Jump to DrawObjectsInList_Next.
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 FirstObjectPosition.
DrawObjectsInList_Draw C289 LD HL,($A24A) Clear bit 7 of the high byte of its address in the list.
C28C DEC HL
C28D RES 7,(HL)
Draw the object.
C28F CALL DrawScrollingObject Call DrawScrollingObject.
Go back to find the next object to draw.
C292 JP DrawObjectsInList Jump to DrawObjectsInList.
View the equivalent code in;
Prev: C1A4 Up: Map Next: C295