Prev: 54990 Up: Map Next: 55205
55004: 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 255.
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 55004 LD A,(23768) Read the object's flags.
55007 AND %01000000 Use bit 6 of the flags.
55009 JR Z,TestBlockOverlap_YAxis Test the y edges when bit 6 is clear.
55011 LD DE,0 Take the patched x edges.
55014 LD HL,0
55017 LD A,(IY+2) Scale the object's byte and use the x extent.
55020 ADD A,A
55021 ADD A,A
55022 ADD A,A
55023 LD B,(IX+11)
55026 JR TestBlockOverlap_Size
TestBlockOverlap_YAxis 55028 LD DE,0 Take the patched y edges.
55031 LD HL,0
55034 LD B,(IX+12) Use the y extent.
55037 LD A,(IY+2) Read the object's byte.
TestBlockOverlap_Size 55040 ADD A,A Double that byte.
55041 AND %01110000 Use bits 4-6.
55043 ADD A,16 Add 16 to make the size.
55045 LD C,A
55046 LD A,(23768) Read the flags again.
55049 AND %00100000 Use bit 5 of the flags.
55051 JR Z,TestBlockOverlap_Edge Measure from the far edge when bit 5 is set.
55053 EX DE,HL Subtract the near edge from the far edge plus the size.
55054 LD B,0
55056 ADD HL,BC
55057 SBC HL,DE
55059 XOR A
55060 JR TestBlockOverlap_Mark The marker for that side is zero.
TestBlockOverlap_Edge 55062 LD C,B Subtract the near edge from the far edge plus the extent.
55063 LD B,0
55065 ADD HL,BC
55066 SBC HL,DE
55068 LD A,4 The marker for that side is 4.
TestBlockOverlap_Mark 55070 LD (55177),A Remember the marker.
55073 LD B,2 Start with a count of two.
55075 LD A,(23768) Read the flags.
55078 AND %00010000 Use bit 4 of the flags.
55080 JR NZ,TestBlockOverlap_Compare Halve the overlap when bit 4 is clear.
55082 DEC B Halve the overlap and count one.
55083 SRL H
55085 RR L
TestBlockOverlap_Compare 55087 LD DE,(54991) Add the edge address.
55091 ADD HL,DE
55092 LD DE,(54998) Subtract the z coordinate.
55096 SBC HL,DE No overlap on z sets the flags to 255.
55098 JR C,FlagOverlap
55100 LD A,(56787) The overlap has to reach the stored z overlap.
55103 SUB L
55104 JR C,TestBlockOverlap_0
55106 SUB 2 An overlap below two clears the flags.
55108 JR C,TestBlockOverlap_0
55110 LD H,255 Remember an overlap of 255.
55112 LD (56787),HL
55115 LD A,(23768) Read the flags.
55118 AND %01000000 Use bit 6 of the flags.
55120 LD A,H The x test records the overlap on x.
55121 JR NZ,TestBlockOverlap_1
55123 LD (56785),A Record the overlap on y.
55126 LD A,(IX+0) Only the player records the side.
55129 DEC A
55130 RET NZ
55131 LD A,(55177) Combine the marker with the count.
55134 OR B
55135 ADD A,A Shift that side up by three.
55136 ADD A,A
55137 ADD A,A
55138 LD B,A Keep it for the flags.
55139 ADD A,A Shift it up by two more.
55140 ADD A,A
55141 AND %01100000 Use bits 5-6.
55143 LD C,A Keep them for field 33.
55144 LD A,(IX+30) Read the flags.
55147 AND %11000111 Use the flag bits other than 3-5.
55149 OR B Mix the side into the flags.
55150 LD (IX+30),A
55153 LD A,(IX+33) Read field 33.
55156 AND %10011111 Use the bits other than 5-6.
55158 OR C Mix the side into field 33.
55159 LD (IX+33),A
55162 RET Return.
TestBlockOverlap_0 55163 XOR A Clear the flags when the overlap is too small.
55164 LD (23768),A
55167 RET
TestBlockOverlap_1 55168 LD (56783),A Record the overlap on x.
55171 LD A,(IX+0) Only the player records the side.
55174 DEC A
55175 RET NZ
55176 LD A,0 Combine the marker with the count.
55178 OR B
55179 LD B,A Keep it.
55180 RRCA Shift the side down by three.
55181 RRCA
55182 RRCA
55183 AND %01100000 Use bits 5-6.
55185 LD C,A Keep them.
55186 LD A,(IX+32) Read field 32.
55189 AND %10011111 Use the bits other than 5-6.
55191 OR C Mix the side into field 32.
55192 LD (IX+32),A
55195 LD A,(IX+30) Read the flags.
55198 AND %11111000 Use the top five bits of the flags.
55200 OR B Mix the count into the low bits of the flags.
55201 LD (IX+30),A
55204 RET Return.
Prev: 54990 Up: Map Next: 55205