Prev: D0C5 Up: Map Next: D15D
D0D0: Compare Object Depths
Decides which of two objects that overlap along both axes is drawn first, by working out a value for each from the corners of the object, in units of half a cell, that measures how far it is along the diagonal of the view. The object at IX is kept if its value is not less than that of the object at IY, otherwise the object at IY is chosen. The edges which it uses are different when the view is rotated.
Input
IX The address of the first object
IY The address of the second object
Jump to CompareObjectDepths_Rotated if the view is turned round.
CompareObjectDepths D0D0 LD A,($BBBA) Fetch the rotation of the view.
D0D3 AND %00000001 Test the lowest bit.
D0D5 JR NZ,CompareObjectDepths_Rotated Jump if the view is rotated.
Find the number for the second object, in DE.
D0D7 LD A,(IY+$01) Fetch the horizontal position, add the horizontal size, halve it and add 40.
D0DA ADD A,(IY+$08)
D0DD RRA
D0DE ADD A,$40
D0E0 LD C,A Keep it in BC.
D0E1 LD B,$00
Work out the smallest Y extent of the object at IY.
D0E3 LD A,(IY+$03) Fetch the vertical position, subtract the vertical size, halve it and add 40.
D0E6 SUB (IY+$09)
D0E9 RRA
D0EA ADD A,$40
D0EC LD L,A Make the top edge a sixteen bit number in HL.
D0ED LD H,$00
D0EF AND A Subtract the X extent from the Y extent, to measure how far along the diagonal of the view the object is.
D0F0 SBC HL,BC
D0F2 LD BC,$0100 Add 0100.
D0F5 ADD HL,BC
D0F6 SRL H Divide the result by two...
D0F8 RR L
D0FA EX DE,HL Keep the result for the object at IY.
Find the number for the first object, in HL, in the same way.
D0FB LD A,(IX+$01) Fetch the horizontal position, add the horizontal size, halve it and add 40.
D0FE ADD A,(IX+$08)
D101 RRA
D102 ADD A,$40
D104 LD C,A Keep it in BC.
D105 LD B,$00
D107 LD A,(IX+$03) Fetch the smallest Y extent of the object at IX.
D10A SUB (IX+$09)
CompareObjectDepths_Second D10D RRA Halve it and add 40.
D10E ADD A,$40
D110 LD L,A Make the top edge a sixteen bit number in HL.
D111 LD H,$00
D113 AND A Subtract the horizontal edge.
D114 SBC HL,BC
D116 LD BC,$0100 Add 0100.
D119 ADD HL,BC
D11A SRL H Divide the result by two.
D11C RR L
D11E AND A Subtract the result for the object at IY.
D11F SBC HL,DE
D121 RET NC Return if the value for the object at IX is not less, which keeps it as the one to draw first.
D122 JP ChooseOtherObject Choose the object at IY instead.
Find the numbers when the view is rotated. The number for the first object goes in DE...
CompareObjectDepths_Rotated D125 LD A,(IX+$01) Fetch the horizontal position, subtract the horizontal size, halve it and add 40.
D128 SUB (IX+$08)
D12B RRA
D12C ADD A,$40
D12E LD C,A Keep it in BC.
D12F LD B,$00
Work out the largest Y extent of the object at IX.
D131 LD A,(IX+$03) Fetch the vertical position, add the vertical size, halve it and add 40.
D134 ADD A,(IX+$09)
D137 RRA
D138 ADD A,$40
D13A LD L,A Make the lower edge a sixteen bit number in HL.
D13B LD H,$00
D13D AND A Subtract the horizontal edge.
D13E SBC HL,BC
D140 LD BC,$0100 Add 0100.
D143 ADD HL,BC
D144 SRL H Divide the result by two...
D146 RR L
D148 EX DE,HL Keep the result for the object at IX.
...and the number for the second object is found in HL by the end of the routine above.
D149 LD A,(IY+$01) Fetch the horizontal position, subtract the horizontal size, halve it and add 40.
D14C SUB (IY+$08)
D14F RRA
D150 ADD A,$40
D152 LD C,A Keep it in BC.
D153 LD B,$00
D155 LD A,(IY+$03) Fetch the largest Y extent of the object at IY.
D158 ADD A,(IY+$09)
Go to find the number.
D15B JR CompareObjectDepths_Second Jump to CompareObjectDepths_Second to compare the results.
View the equivalent code in;
Prev: D0C5 Up: Map Next: D15D