Prev: D0C5 Up: Map Next: D15D
D0D0: Order two things whose boxes overlap on both axes
Index 4 (13 turned round) of DEPTH_TABLE. With the boxes overlapping in U and in V, neither is simply behind the other, so each is placed by its nearest corner -- in the usual view the corner at the high side of U and the low side of V -- and how far back that corner is, which is how high up the screen it is: V less U. The candidate stays if its nearest corner is as far back as the other's, or further; otherwise the other becomes the candidate (DEPTH_SWAP). Turned round, the nearest corner is at the low side of U and the high side of V, and the test the other way about.
The sides are the half-unit bytes of SORT_AND_DRAW_THINGS; each difference has 256 added and is halved, to keep it positive, which does not change the order.
Input
IX the candidate
IY the other thing
DEPTH_BY_CORNERS D0D0 LD A,(VIEW) Turned round: the other corners
D0D3 AND $01
D0D5 JR NZ,DEPTH_BY_CORNERS_1
D0D7 LD A,(IY+$01) DE = how far back the other thing's nearest corner is: its low V side less its high U side
D0DA ADD A,(IY+$08)
D0DD RRA
D0DE ADD A,$40
D0E0 LD C,A
D0E1 LD B,$00
D0E3 LD A,(IY+$03)
D0E6 SUB (IY+$09)
D0E9 RRA
D0EA ADD A,$40
D0EC LD L,A
D0ED LD H,$00
D0EF AND A
D0F0 SBC HL,BC
D0F2 LD BC,$0100
D0F5 ADD HL,BC
D0F6 SRL H
D0F8 RR L
D0FA EX DE,HL
D0FB LD A,(IX+$01) The candidate's the same...
D0FE ADD A,(IX+$08)
D101 RRA
D102 ADD A,$40
D104 LD C,A
D105 LD B,$00
D107 LD A,(IX+$03)
D10A SUB (IX+$09)
DEPTH_BY_CORNERS_0 D10D RRA ...into HL
D10E ADD A,$40
D110 LD L,A
D111 LD H,$00
D113 AND A
D114 SBC HL,BC
D116 LD BC,$0100
D119 ADD HL,BC
D11A SRL H
D11C RR L
D11E AND A The candidate's corner as far back or further: it stays
D11F SBC HL,DE
D121 RET NC
D122 JP DEPTH_SWAP Otherwise the other takes its place
DEPTH_BY_CORNERS_1 D125 LD A,(IX+$01) Turned round: DE = the candidate's high V side less its low U side
D128 SUB (IX+$08)
D12B RRA
D12C ADD A,$40
D12E LD C,A
D12F LD B,$00
D131 LD A,(IX+$03)
D134 ADD A,(IX+$09)
D137 RRA
D138 ADD A,$40
D13A LD L,A
D13B LD H,$00
D13D AND A
D13E SBC HL,BC
D140 LD BC,$0100
D143 ADD HL,BC
D144 SRL H
D146 RR L
D148 EX DE,HL
D149 LD A,(IY+$01) The other's the same, into HL; the candidate stays if the other's corner is as near as its own or nearer
D14C SUB (IY+$08)
D14F RRA
D150 ADD A,$40
D152 LD C,A
D153 LD B,$00
D155 LD A,(IY+$03)
D158 ADD A,(IY+$09)
D15B JR DEPTH_BY_CORNERS_0
Prev: D0C5 Up: Map Next: D15D