Prev: D6CE Up: Map Next: D7A5
D6DC: Test Block Overlap
Used by the routine at TestWideOverlap.
Tests the entity against one axis of a block. TestGroupObjects patches the two edges in first. Bit 6 of the object's flags selects the x edges and the x extent; otherwise the y edges and the y extent are used. The overlap is stored for that axis, and for the player the side is mixed into the flags. No overlap on z sets the flags to FF.
Input
IX The entity
IY The object
Bit 6 of the object's flags selects the axis. The two edges loaded below are patched by TestGroupObjects.
TestBlockOverlap D6DC LD A,($5CD8) Read the object's flags.
D6DF AND %01000000 Use bit 6 of the flags.
D6E1 JR Z,TestBlockOverlap_YAxis Test the y edges when bit 6 is clear.
D6E3 LD DE,$0000 Take the patched x edges.
D6E6 LD HL,$0000
D6E9 LD A,(IY+$02) Scale the object's byte and use the x extent.
D6EC ADD A,A
D6ED ADD A,A
D6EE ADD A,A
D6EF LD B,(IX+$0B)
D6F2 JR TestBlockOverlap_Size
TestBlockOverlap_YAxis D6F4 LD DE,$0000 Take the patched y edges.
D6F7 LD HL,$0000
D6FA LD B,(IX+$0C) Use the y extent.
D6FD LD A,(IY+$02) Read the object's byte.
TestBlockOverlap_Size D700 ADD A,A Double that byte.
D701 AND %01110000 Use bits 4-6.
D703 ADD A,$10 Add 10 to make the size.
D705 LD C,A
D706 LD A,($5CD8) Read the flags again.
D709 AND %00100000 Use bit 5 of the flags.
D70B JR Z,TestBlockOverlap_Edge Measure from the far edge when bit 5 is set.
D70D EX DE,HL Subtract the near edge from the far edge plus the size.
D70E LD B,$00
D710 ADD HL,BC
D711 SBC HL,DE
D713 XOR A
D714 JR TestBlockOverlap_Mark The marker for that side is zero.
TestBlockOverlap_Edge D716 LD C,B Subtract the near edge from the far edge plus the extent.
D717 LD B,$00
D719 ADD HL,BC
D71A SBC HL,DE
D71C LD A,$04 The marker for that side is 04.
TestBlockOverlap_Mark D71E LD ($D789),A Remember the marker.
D721 LD B,$02 Start with a count of two.
D723 LD A,($5CD8) Read the flags.
D726 AND %00010000 Use bit 4 of the flags.
D728 JR NZ,TestBlockOverlap_Compare Halve the overlap when bit 4 is clear.
D72A DEC B Halve the overlap and count one.
D72B SRL H
D72D RR L
TestBlockOverlap_Compare D72F LD DE,($D6CF) Add the edge address.
D733 ADD HL,DE
D734 LD DE,($D6D6) Subtract the z coordinate.
D738 SBC HL,DE No overlap on z sets the flags to FF.
D73A JR C,FlagOverlap
D73C LD A,($DDD3) The overlap has to reach the stored z overlap.
D73F SUB L
D740 JR C,TestBlockOverlap_0
D742 SUB $02 An overlap below two clears the flags.
D744 JR C,TestBlockOverlap_0
D746 LD H,$FF Remember an overlap of FF.
D748 LD ($DDD3),HL
D74B LD A,($5CD8) Read the flags.
D74E AND %01000000 Use bit 6 of the flags.
D750 LD A,H The x test records the overlap on x.
D751 JR NZ,TestBlockOverlap_1
D753 LD ($DDD1),A Record the overlap on y.
D756 LD A,(IX+$00) Only the player records the side.
D759 DEC A
D75A RET NZ
D75B LD A,($D789) Combine the marker with the count.
D75E OR B
D75F ADD A,A Shift that side up by three.
D760 ADD A,A
D761 ADD A,A
D762 LD B,A Keep it for the flags.
D763 ADD A,A Shift it up by two more.
D764 ADD A,A
D765 AND %01100000 Use bits 5-6.
D767 LD C,A Keep them for field 21.
D768 LD A,(IX+$1E) Read the flags.
D76B AND %11000111 Use the flag bits other than 3-5.
D76D OR B Mix the side into the flags.
D76E LD (IX+$1E),A
D771 LD A,(IX+$21) Read field 21.
D774 AND %10011111 Use the bits other than 5-6.
D776 OR C Mix the side into field 21.
D777 LD (IX+$21),A
D77A RET Return.
TestBlockOverlap_0 D77B XOR A Clear the flags when the overlap is too small.
D77C LD ($5CD8),A
D77F RET
TestBlockOverlap_1 D780 LD ($DDCF),A Record the overlap on x.
D783 LD A,(IX+$00) Only the player records the side.
D786 DEC A
D787 RET NZ
D788 LD A,$00 Combine the marker with the count.
D78A OR B
D78B LD B,A Keep it.
D78C RRCA Shift the side down by three.
D78D RRCA
D78E RRCA
D78F AND %01100000 Use bits 5-6.
D791 LD C,A Keep them.
D792 LD A,(IX+$20) Read field 20.
D795 AND %10011111 Use the bits other than 5-6.
D797 OR C Mix the side into field 20.
D798 LD (IX+$20),A
D79B LD A,(IX+$1E) Read the flags.
D79E AND %11111000 Use the top five bits of the flags.
D7A0 OR B Mix the count into the low bits of the flags.
D7A1 LD (IX+$1E),A
D7A4 RET Return.
Prev: D6CE Up: Map Next: D7A5