Prev: 53445 Up: Map Next: 53597
53456: 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 53456 LD A,(48058) Fetch the rotation of the view.
53459 AND %00000001 Test the lowest bit.
53461 JR NZ,CompareObjectDepths_Rotated Jump if the view is rotated.
Find the number for the second object, in DE.
53463 LD A,(IY+1) Fetch the horizontal position, add the horizontal size, halve it and add 64.
53466 ADD A,(IY+8)
53469 RRA
53470 ADD A,64
53472 LD C,A Keep it in BC.
53473 LD B,0
Work out the smallest Y extent of the object at IY.
53475 LD A,(IY+3) Fetch the vertical position, subtract the vertical size, halve it and add 64.
53478 SUB (IY+9)
53481 RRA
53482 ADD A,64
53484 LD L,A Make the top edge a sixteen bit number in HL.
53485 LD H,0
53487 AND A Subtract the X extent from the Y extent, to measure how far along the diagonal of the view the object is.
53488 SBC HL,BC
53490 LD BC,256 Add 256.
53493 ADD HL,BC
53494 SRL H Divide the result by two...
53496 RR L
53498 EX DE,HL Keep the result for the object at IY.
Find the number for the first object, in HL, in the same way.
53499 LD A,(IX+1) Fetch the horizontal position, add the horizontal size, halve it and add 64.
53502 ADD A,(IX+8)
53505 RRA
53506 ADD A,64
53508 LD C,A Keep it in BC.
53509 LD B,0
53511 LD A,(IX+3) Fetch the smallest Y extent of the object at IX.
53514 SUB (IX+9)
CompareObjectDepths_Second 53517 RRA Halve it and add 64.
53518 ADD A,64
53520 LD L,A Make the top edge a sixteen bit number in HL.
53521 LD H,0
53523 AND A Subtract the horizontal edge.
53524 SBC HL,BC
53526 LD BC,256 Add 256.
53529 ADD HL,BC
53530 SRL H Divide the result by two.
53532 RR L
53534 AND A Subtract the result for the object at IY.
53535 SBC HL,DE
53537 RET NC Return if the value for the object at IX is not less, which keeps it as the one to draw first.
53538 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 53541 LD A,(IX+1) Fetch the horizontal position, subtract the horizontal size, halve it and add 64.
53544 SUB (IX+8)
53547 RRA
53548 ADD A,64
53550 LD C,A Keep it in BC.
53551 LD B,0
Work out the largest Y extent of the object at IX.
53553 LD A,(IX+3) Fetch the vertical position, add the vertical size, halve it and add 64.
53556 ADD A,(IX+9)
53559 RRA
53560 ADD A,64
53562 LD L,A Make the lower edge a sixteen bit number in HL.
53563 LD H,0
53565 AND A Subtract the horizontal edge.
53566 SBC HL,BC
53568 LD BC,256 Add 256.
53571 ADD HL,BC
53572 SRL H Divide the result by two...
53574 RR L
53576 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.
53577 LD A,(IY+1) Fetch the horizontal position, subtract the horizontal size, halve it and add 64.
53580 SUB (IY+8)
53583 RRA
53584 ADD A,64
53586 LD C,A Keep it in BC.
53587 LD B,0
53589 LD A,(IY+3) Fetch the largest Y extent of the object at IY.
53592 ADD A,(IY+9)
Go to find the number.
53595 JR CompareObjectDepths_Second Jump to CompareObjectDepths_Second to compare the results.
View the equivalent code in;
Prev: 53445 Up: Map Next: 53597