Prev: 53167 Up: Map Next: 53408
53234: 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 53234 LD HL,53597 Point HL at ObjectList.
DrawObjectsInList_Next 53237 LD E,(HL) Fetch the address of the next object into DE.
53238 INC HL
53239 LD D,(HL)
53240 INC HL
53241 LD A,D Return if this is the end of the list.
53242 OR E
53243 RET Z
53244 BIT 7,D Skip the entry if the object has been drawn already.
53246 JR Z,DrawObjectsInList_Next
Remember where the next place in the list is.
53248 LD (48068),HL Set ChosenObjectPosition.
53251 PUSH DE Copy the address of the object into IX (using the stack).
53252 POP IX
Compare this object with each of the others which have not been drawn.
DrawObjectsInList_Compare 53254 LD E,(HL) Fetch the address of the next object into DE.
53255 INC HL
53256 LD D,(HL)
53257 INC HL
Draw the first object if this is the end of the list.
53258 LD A,D Jump to DrawObjectsInList_Draw to draw the object if it is the zero word that marks the end of the list.
53259 OR E
53260 JP Z,DrawObjectsInList_Draw
53263 BIT 7,D Skip the entry if the object has been drawn already.
53265 JR Z,DrawObjectsInList_Compare
Remember where the next place in the list is.
53267 LD (48070),HL Set ComparedObjectPosition.
53270 PUSH DE Copy the address of the object into IY (using the stack).
53271 POP IY
53273 LD C,0 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.
53275 LD A,(IY+1) Fetch the horizontal position of the second object and add its horizontal size.
53278 ADD A,(IY+8)
53281 RRA Halve it, add 64 and keep the result in B.
53282 ADD A,64
53284 LD B,A
Work out the smallest extent of the object at IX, and subtract the largest extent of the object at IY.
53285 LD A,(IX+1) Fetch the horizontal position of the first object and subtract its horizontal size.
53288 SUB (IX+8)
53291 RRA Halve it and add 64.
53292 ADD A,64
53294 SUB B Jump to DrawObjectsInList_Y if the first object starts after the second ends.
53295 JR NC,DrawObjectsInList_Y
Work out the largest extent of the object at IX.
53297 LD A,(IX+1) Fetch the horizontal position of the first object and add its horizontal size.
53300 ADD A,(IX+8)
53303 RRA Halve it, add 64 and keep the result in B.
53304 ADD A,64
53306 LD B,A
Work out the smallest extent of the object at IY, and subtract the largest extent of the object at IX.
53307 LD A,(IY+1) Fetch the horizontal position of the second object and subtract its horizontal size.
53310 SUB (IY+8)
53313 RRA Halve it and add 64.
53314 ADD A,64
53316 SUB B Jump to DrawObjectsInList_Overlap if the second object starts before the first ends.
53317 JR C,DrawObjectsInList_Overlap
53319 INC C Add one.
DrawObjectsInList_Overlap 53320 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 53321 LD A,(IY+3) Fetch the vertical position of the second object and add its vertical size.
53324 ADD A,(IY+9)
53327 RRA Halve it, add 64 and keep the result in B.
53328 ADD A,64
53330 LD B,A
Work out the smallest extent of the object at IX, and subtract the largest extent of the object at IY.
53331 LD A,(IX+3) Fetch the vertical position of the first object and subtract its vertical size.
53334 SUB (IX+9)
53337 RRA Halve it and add 64.
53338 ADD A,64
53340 SUB B Subtract the end of the second object.
53341 LD A,C Fetch the number.
53342 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.
53344 LD A,(IX+3) Fetch the vertical position of the first object and add its vertical size.
53347 ADD A,(IX+9)
53350 RRA Halve it, add 64 and keep the result in B.
53351 ADD A,64
53353 LD B,A
Work out the smallest extent of the object at IY, and subtract the largest extent of the object at IX.
53354 LD A,(IY+3) Fetch the vertical position of the second object and subtract its vertical size.
53357 SUB (IY+9)
53360 RRA Halve it and add 64.
53361 ADD A,64
53363 SUB B Subtract the end of the first object.
53364 LD A,C Fetch the number.
53365 JR C,DrawObjectsInList_YOverlap Jump to DrawObjectsInList_YOverlap if they overlap.
53367 ADD A,3 Add three.
DrawObjectsInList_YOverlap 53369 ADD A,3 Add three more.
DrawObjectsInList_Relation 53371 LD C,A Keep the number in C.
Fetch the rotation of the view.
53372 LD A,(48058) Fetch ViewRotatedFlag.
53375 AND %00000001 Test the lowest bit.
53377 JR Z,DrawObjectsInList_Choose Jump to DrawObjectsInList_Choose if the view is not rotated.
53379 LD A,C Add 9 to the number, to use the second half of the table.
53380 ADD A,9
53382 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 53383 LD A,C Fetch the number.
53384 LD BC,53408 Point BC at ObjectOrderTable.
Run the routine for the number.
53387 CALL JumpToTableRoutine Call JumpToTableRoutine.
Fetch the place in the list after the second object.
53390 LD HL,(48070) Fetch ComparedObjectPosition.
Go back to compare the next object.
53393 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 53396 LD HL,(48068) Mark the entry for the object at IX as drawn.
53399 DEC HL
53400 RES 7,(HL)
Draw the object.
53402 CALL DrawObject Draw the object.
Go back to find the next object to draw.
53405 JP DrawObjectsInList Go back to draw the objects that are left in the list.
View the equivalent code in;
Prev: 53167 Up: Map Next: 53408