Prev: B2CC Up: Map Next: B399
B2EB: Test Record Overlap
Used by the routines at DrawItems and TestRecordsAgainstEntity.
Tests whether the entity in IX overlaps the 14-byte record in IY. If it does then bit 7 of field 0A of the record is set.
Input
IX The entity
IY The 14-byte record
The record's drawing position, plus its third size, has to meet the entity on z. The addresses in bytes 10 and 12 then have to meet it on x and y.
TestRecordOverlap B2EB LD B,$00 Start with no high byte.
B2ED LD H,(IY+$08) Read the record's drawing position.
B2F0 LD L,(IY+$09)
B2F3 LD C,(IY+$0D) Add the third size and step back one.
B2F6 ADD HL,BC
B2F7 DEC HL
B2F8 LD D,(IX+$08) Subtract the entity's z.
B2FB LD E,(IX+$09)
B2FE XOR A No overlap when the record is below the entity on z.
B2FF SBC HL,DE
B301 RET C
B302 LD A,(IX+$0D) Add the z extent to that z.
B305 ADD A,E
B306 LD E,A
B307 JR NC,TestRecordOverlap_X Count the carry in the high byte.
B309 INC D
TestRecordOverlap_X B30A LD H,(IX+$02) Subtract it from the entity's x.
B30D LD L,(IX+$03)
B310 AND A
B311 SBC HL,DE
B313 LD D,(IY+$10) Subtract the address in bytes 10 and 11.
B316 LD E,(IY+$11)
B319 XOR A The entity is on the far side of that address.
B31A SBC HL,DE
B31C JR C,TestRecordOverlap_MissX
B31E OR H No overlap when it is a byte or more past the address.
B31F RET NZ
B320 LD A,L No overlap when the gap is at least byte 4 of the record.
B321 SUB (IY+$04)
B324 RET NC
B325 JR TestRecordOverlap_Y Join the y test.
TestRecordOverlap_MissX B327 INC H No overlap when the miss is a byte or more the other way.
B328 RET NZ
B329 LD A,L The x extent reaches the address.
B32A ADD A,(IX+$0B)
B32D JR C,TestRecordOverlap_Y
B32F ADD A,(IX+$0D) The z extent reaches it too.
B332 RET NC No overlap when it still falls short.
TestRecordOverlap_Y B333 LD D,(IX+$08) Add the entity's z to its y.
B336 LD E,(IX+$09)
B339 LD H,(IX+$05)
B33C LD L,(IX+$06)
B33F ADD HL,DE
B340 LD D,(IY+$12) Subtract the address in bytes 12 and 13.
B343 LD E,(IY+$13)
B346 XOR A
B347 SBC HL,DE
B349 JR C,TestRecordOverlap_MissY The entity is on the far side of that address.
B34B OR H No overlap when it is a byte or more past the address.
B34C RET NZ
B34D LD A,L No overlap when the gap is at least byte 7 of the record.
B34E SUB (IY+$07)
B351 RET NC
B352 JR TestRecordOverlap_Range Join the column test.
TestRecordOverlap_MissY B354 INC H No overlap when the miss is a byte or more the other way.
B355 RET NZ
B356 LD A,L The y extent reaches the address.
B357 ADD A,(IX+$0C)
B35A JR C,TestRecordOverlap_Range
B35C ADD A,(IX+$0D) The z extent reaches it too.
B35F 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 20 whichever is larger.
TestRecordOverlap_Range B360 LD B,(IY+$00) Read the record's origin.
B363 LD C,(IY+$01)
B366 LD DE,($5CE7) Fetch the view origin.
B36A LD HL,($B16A) Fetch the origin kept for the items.
B36D XOR A Subtract the kept origin.
B36E SBC HL,DE
B370 ADD HL,BC Add the record's origin.
B371 LD D,$80 Measure the column from page 80.
B373 LD E,(IX+$0E)
B376 LD A,(IX+$16) Read the sprite width.
B379 AND %00001111 Use the low nibble.
B37B ADD A,A Turn the width into pixels, eight per byte.
B37C ADD A,A
B37D ADD A,A
B37E LD B,A
B37F LD A,(IY+$0B) Add the two sizes.
B382 ADD A,(IY+$0C)
B385 JR NC,TestRecordOverlap_Minimum
B387 LD A,$FF Use FF when the sizes overflow.
TestRecordOverlap_Minimum B389 CP $20 Use at least 20.
B38B JR NC,TestRecordOverlap_Column
B38D LD A,$20 The minimum size is 20.
TestRecordOverlap_Column B38F LD C,A Test the column against that range.
B390 CALL TestRange
B393 RET NZ Return when the column is outside it.
B394 SET 7,(IY+$0A) Mark the record as overlapping.
B398 RET Return.
Prev: B2CC Up: Map Next: B399