Prev: 45772 Up: Map Next: 45977
45803: Test Record Overlap
Used by the routines at DrawItems and TestRecordsAgainstEntity.
Tests whether the entity in IX overlaps the 20-byte record in IY. If it does then bit 7 of field 10 of the record is set.
Input
IX The entity
IY The 20-byte record
The record's drawing position, plus its third size, has to meet the entity on z. The addresses in bytes 16 and 18 then have to meet it on x and y.
TestRecordOverlap 45803 LD B,0 Start with no high byte.
45805 LD H,(IY+8) Read the record's drawing position.
45808 LD L,(IY+9)
45811 LD C,(IY+13) Add the third size and step back one.
45814 ADD HL,BC
45815 DEC HL
45816 LD D,(IX+8) Subtract the entity's z.
45819 LD E,(IX+9)
45822 XOR A No overlap when the record is below the entity on z.
45823 SBC HL,DE
45825 RET C
45826 LD A,(IX+13) Add the z extent to that z.
45829 ADD A,E
45830 LD E,A
45831 JR NC,TestRecordOverlap_X Count the carry in the high byte.
45833 INC D
TestRecordOverlap_X 45834 LD H,(IX+2) Subtract it from the entity's x.
45837 LD L,(IX+3)
45840 AND A
45841 SBC HL,DE
45843 LD D,(IY+16) Subtract the address in bytes 16 and 17.
45846 LD E,(IY+17)
45849 XOR A The entity is on the far side of that address.
45850 SBC HL,DE
45852 JR C,TestRecordOverlap_MissX
45854 OR H No overlap when it is a byte or more past the address.
45855 RET NZ
45856 LD A,L No overlap when the gap is at least byte 4 of the record.
45857 SUB (IY+4)
45860 RET NC
45861 JR TestRecordOverlap_Y Join the y test.
TestRecordOverlap_MissX 45863 INC H No overlap when the miss is a byte or more the other way.
45864 RET NZ
45865 LD A,L The x extent reaches the address.
45866 ADD A,(IX+11)
45869 JR C,TestRecordOverlap_Y
45871 ADD A,(IX+13) The z extent reaches it too.
45874 RET NC No overlap when it still falls short.
TestRecordOverlap_Y 45875 LD D,(IX+8) Add the entity's z to its y.
45878 LD E,(IX+9)
45881 LD H,(IX+5)
45884 LD L,(IX+6)
45887 ADD HL,DE
45888 LD D,(IY+18) Subtract the address in bytes 18 and 19.
45891 LD E,(IY+19)
45894 XOR A
45895 SBC HL,DE
45897 JR C,TestRecordOverlap_MissY The entity is on the far side of that address.
45899 OR H No overlap when it is a byte or more past the address.
45900 RET NZ
45901 LD A,L No overlap when the gap is at least byte 7 of the record.
45902 SUB (IY+7)
45905 RET NC
45906 JR TestRecordOverlap_Range Join the column test.
TestRecordOverlap_MissY 45908 INC H No overlap when the miss is a byte or more the other way.
45909 RET NZ
45910 LD A,L The y extent reaches the address.
45911 ADD A,(IX+12)
45914 JR C,TestRecordOverlap_Range
45916 ADD A,(IX+13) The z extent reaches it too.
45919 RET NC No overlap when it still falls short.
The column is tested against the record's origin, shifted by how far the view origin has moved. The width is the sprite width in bytes times eight, and the range is the two sizes or 32 whichever is larger.
TestRecordOverlap_Range 45920 LD B,(IY+0) Read the record's origin.
45923 LD C,(IY+1)
45926 LD DE,(23783) Fetch the view origin.
45930 LD HL,(45418) Fetch the origin kept for the items.
45933 XOR A Subtract the kept origin.
45934 SBC HL,DE
45936 ADD HL,BC Add the record's origin.
45937 LD D,128 Measure the column from page 128.
45939 LD E,(IX+14)
45942 LD A,(IX+22) Read the sprite width.
45945 AND %00001111 Use the low nibble.
45947 ADD A,A Turn the width into pixels, eight per byte.
45948 ADD A,A
45949 ADD A,A
45950 LD B,A
45951 LD A,(IY+11) Add the two sizes.
45954 ADD A,(IY+12)
45957 JR NC,TestRecordOverlap_Minimum
45959 LD A,255 Use 255 when the sizes overflow.
TestRecordOverlap_Minimum 45961 CP 32 Use at least 32.
45963 JR NC,TestRecordOverlap_Column
45965 LD A,32 The minimum size is 32.
TestRecordOverlap_Column 45967 LD C,A Test the column against that range.
45968 CALL TestRange
45971 RET NZ Return when the column is outside it.
45972 SET 7,(IY+10) Mark the record as overlapping.
45976 RET Return.
Prev: 45772 Up: Map Next: 45977