Prev: 49572 Up: Map Next: 49813
49639: 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 49639 LD HL,50002 Point HL at CellObjectList.
DrawObjectsInList_First 49642 LD E,(HL) Fetch the address of the next object into DE.
49643 INC HL
49644 LD D,(HL)
49645 INC HL
49646 LD A,D Return if this is the end of the list.
49647 OR E
49648 RET Z
49649 BIT 7,D Jump to DrawObjectsInList_First if it has been drawn.
49651 JR Z,DrawObjectsInList_First
Remember where the next place in the list is.
49653 LD (41546),HL Set FirstObjectPosition.
49656 PUSH DE Copy the address of the object into IX (using the stack).
49657 POP IX
Compare this object with each of the others which have not been drawn.
DrawObjectsInList_Next 49659 LD E,(HL) Fetch the address of the next object into DE.
49660 INC HL
49661 LD D,(HL)
49662 INC HL
Draw the first object if this is the end of the list.
49663 LD A,D Jump to DrawObjectsInList_Draw if it is.
49664 OR E
49665 JP Z,DrawObjectsInList_Draw
49668 BIT 7,D Jump to DrawObjectsInList_Next if it has been drawn.
49670 JR Z,DrawObjectsInList_Next
Remember where the next place in the list is.
49672 LD (41548),HL Set SecondObjectPosition.
49675 PUSH DE Copy the address of the object into IY (using the stack).
49676 POP IY
49678 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.
49680 LD A,(IY+1) Fetch the horizontal position of the second object and add its horizontal size.
49683 ADD A,(IY+8)
49686 RRA Halve it, add 64 and keep the result in B.
49687 ADD A,64
49689 LD B,A
49690 LD A,(IX+1) Fetch the horizontal position of the first object and subtract its horizontal size.
49693 SUB (IX+8)
49696 RRA Halve it and add 64.
49697 ADD A,64
49699 SUB B Jump to DrawObjectsInList_Depth if the first object starts after the second ends.
49700 JR NC,DrawObjectsInList_Depth
49702 LD A,(IX+1) Fetch the horizontal position of the first object and add its horizontal size.
49705 ADD A,(IX+8)
49708 RRA Halve it, add 64 and keep the result in B.
49709 ADD A,64
49711 LD B,A
49712 LD A,(IY+1) Fetch the horizontal position of the second object and subtract its horizontal size.
49715 SUB (IY+8)
49718 RRA Halve it and add 64.
49719 ADD A,64
49721 SUB B Jump to DrawObjectsInList_AddOne if the second object starts before the first ends.
49722 JR C,DrawObjectsInList_AddOne
49724 INC C Add one.
DrawObjectsInList_AddOne 49725 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 49726 LD A,(IY+3) Fetch the vertical position of the second object and add its vertical size.
49729 ADD A,(IY+9)
49732 RRA Halve it, add 64 and keep the result in B.
49733 ADD A,64
49735 LD B,A
49736 LD A,(IX+3) Fetch the vertical position of the first object and subtract its vertical size.
49739 SUB (IX+9)
49742 RRA Halve it and add 64.
49743 ADD A,64
49745 SUB B Subtract the end of the second object.
49746 LD A,C Fetch the number.
49747 JR NC,DrawObjectsInList_Rotated Jump to DrawObjectsInList_Rotated if the first object starts after the second ends.
49749 LD A,(IX+3) Fetch the vertical position of the first object and add its vertical size.
49752 ADD A,(IX+9)
49755 RRA Halve it, add 64 and keep the result in B.
49756 ADD A,64
49758 LD B,A
49759 LD A,(IY+3) Fetch the vertical position of the second object and subtract its vertical size.
49762 SUB (IY+9)
49765 RRA Halve it and add 64.
49766 ADD A,64
49768 SUB B Subtract the end of the first object.
49769 LD A,C Fetch the number.
49770 JR C,DrawObjectsInList_AddThree Jump to DrawObjectsInList_AddThree if the second object starts before the first ends.
49772 ADD A,3 Add three.
DrawObjectsInList_AddThree 49774 ADD A,3 Add three more.
DrawObjectsInList_Rotated 49776 LD C,A Keep the number in C.
Fetch the rotation of the view.
49777 LD A,(41576) Fetch ViewRotation.
49780 AND %00000001 Test the lowest bit.
49782 JR Z,DrawObjectsInList_Choose Jump to DrawObjectsInList_Choose if the view is not rotated.
49784 LD A,C Add 9 to the number, to use the second half of the table.
49785 ADD A,9
49787 LD C,A
DrawObjectsInList_Choose 49788 LD A,C Fetch the number.
49789 LD BC,49813 Point BC at ObjectOrderRoutines.
Run the routine for the number.
49792 CALL RunTableRoutine Call RunTableRoutine.
Fetch the place in the list after the second object.
49795 LD HL,(41548) Fetch SecondObjectPosition.
Go back to compare the next object.
49798 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 49801 LD HL,(41546) Clear bit 7 of the high byte of its address in the list.
49804 DEC HL
49805 RES 7,(HL)
Draw the object.
49807 CALL DrawScrollingObject Call DrawScrollingObject.
Go back to find the next object to draw.
49810 JP DrawObjectsInList Jump to DrawObjectsInList.
View the equivalent code in;
Prev: 49572 Up: Map Next: 49813