Prev: B99B Up: Map Next: BA34
B9A7: Flag Overlapping Objects
Used by the routines at HandlePlayerTop and SetWipeAndDrawFlags.
Flags every object that overlaps the area of the screen covered by an object to be drawn again. The area is the one that is covered by the old and the new position of the sprite of the object together, so that the whole of it is redrawn.
Input
IX The address of the object
The left edge, in bytes, is the lower of the old and new positions. It is kept in E.
FlagOverlappingObjects B9A7 LD IY,$A76F Start with the first object record, ObjectsTable.
B9AB CALL CalculateSpriteSize Call CalculateSpriteSize to work out the size of the sprite of the object.
B9AE LD B,$36 Set a counter in B of 36 objects.
Work out the first column of the area, which is the lower of the new and the old first columns.
B9B0 LD A,(IX+$1A) Fetch the new pixel x position.
B9B3 RRCA Divide it by eight.
B9B4 RRCA
B9B5 RRCA
B9B6 AND %00011111 ...and keep only the five bits of the column.
B9B8 LD L,A Set L to the new first column.
B9B9 LD A,(IX+$1E) Fetch the old pixel x position.
B9BC RRCA Divide it by eight.
B9BD RRCA
B9BE RRCA
B9BF AND %00011111 ...and keep only the five bits of the column.
B9C1 LD H,A Set H to the old first column.
B9C2 CP L Jump to FlagOverlappingObjects_Width if the old column is lower.
B9C3 JR C,FlagOverlappingObjects_Width
B9C5 LD A,L Use the new column.
FlagOverlappingObjects_Width B9C6 LD E,A Set E to the first column of the area.
The width is the higher right edge less the left edge. It is kept in D.
B9C7 LD A,L Copy L to A.
B9C8 ADD A,(IX+$18) Add the new width.
B9CB LD L,A Copy it to L.
Add the old width to the old first column to get the old last column.
B9CC LD A,H Copy H to A.
B9CD ADD A,(IX+$1C) Add the old width.
B9D0 CP L Jump to FlagOverlappingObjects_Bottom if the old last column is higher.
B9D1 JR NC,FlagOverlappingObjects_Bottom
B9D3 LD A,L Use the new last column.
FlagOverlappingObjects_Bottom B9D4 SUB E Subtract the first column to get the width of the area.
B9D5 LD D,A Set D to the width of the area.
The bottom edge is the lower of the old and new pixel y. It is kept in L.
B9D6 LD A,(IX+$1B) Fetch the new pixel y position.
B9D9 CP (IX+$1F) Compare it with the old one.
B9DC JR C,FlagOverlappingObjects_Height Jump to FlagOverlappingObjects_Height if the new one is lower.
B9DE LD A,(IX+$1F) Fetch the old pixel y position.
FlagOverlappingObjects_Height B9E1 LD L,A Copy it to L.
The height is the higher top edge less the bottom edge. It is kept in H.
B9E2 LD A,(IX+$1B) Fetch the new pixel y position.
B9E5 ADD A,(IX+$19) Add the new height.
B9E8 LD H,A Copy it to H.
Add the old height to the old y co-ordinate to get the old top.
B9E9 LD A,(IX+$1F) Fetch the old pixel y position.
B9EC ADD A,(IX+$1D) Add the old height.
B9EF CP H Jump to FlagOverlappingObjects_Loop if the old top is higher.
B9F0 JR NC,FlagOverlappingObjects_Loop
B9F2 LD A,H Copy H to A.
FlagOverlappingObjects_Loop B9F3 SUB L Subtract the bottom to get the height of the area.
B9F4 LD H,A Set H to the height of the area.
Flag any object that overlaps the area.
FlagOverlappingObjects_Next B9F5 LD A,(IY+$00) Fetch the sprite number of the other object.
B9F8 AND A Jump to FlagOverlappingObjects_Skip if it is zero.
B9F9 JR Z,FlagOverlappingObjects_Skip
B9FB BIT 4,(IY+$07) Jump to FlagOverlappingObjects_Skip if the other object is already flagged.
B9FF JR NZ,FlagOverlappingObjects_Skip
Divide the screen x co-ordinate of the other object by eight...
BA01 LD A,(IY+$1A) Fetch the pixel x position of the other object.
BA04 RRCA Divide it by eight.
BA05 RRCA
BA06 RRCA
BA07 AND %00011111 ...and keep only the five bits of the column.
BA09 SUB E Subtract the first column of the area.
BA0A JR C,FlagOverlappingObjects_StartsBefore Jump to FlagOverlappingObjects_StartsBefore if it starts before the area.
BA0C CP D Compare the distance with the width of the area.
FlagOverlappingObjects_TestColumns BA0D JR NC,FlagOverlappingObjects_Skip Jump to FlagOverlappingObjects_Skip if it starts after the area.
Subtract the bottom of the area from the screen y co-ordinate of the other object.
BA0F LD A,(IY+$1B) Fetch the pixel y position of the other object.
BA12 SUB L Subtract L.
BA13 JR C,FlagOverlappingObjects_StartsBelow Jump to FlagOverlappingObjects_StartsBelow if it starts below the area.
BA15 CP H Compare the distance with the height of the area.
FlagOverlappingObjects_TestRows BA16 JR NC,FlagOverlappingObjects_Skip Jump to FlagOverlappingObjects_Skip if it starts above the area.
BA18 SET 4,(IY+$07) Flag the other object as needing to be drawn.
Move IY on to the next object record, using the alternate registers so that the area is kept.
FlagOverlappingObjects_Skip BA1C EXX Switch to the shadow registers.
BA1D LD DE,$0020 Set DE' to 0020.
BA20 ADD IY,DE Add DE' to IY.
BA22 EXX Switch to the main registers.
BA23 DJNZ FlagOverlappingObjects_Next Decrease the counter and loop until all the objects have been tried.
BA25 RET Return.
The object starts to the left of the area, so it overlaps only if it is wide enough to reach the area.
FlagOverlappingObjects_StartsBefore BA26 NEG Negate A.
BA28 CP (IY+$18) Compare it with the width of the other object.
BA2B JR FlagOverlappingObjects_TestColumns Jump to FlagOverlappingObjects_TestColumns to jump to the next object if it is not wide enough, or to carry on with the test if it is.
The object starts below the area, so it overlaps only if it is tall enough to reach the area.
FlagOverlappingObjects_StartsBelow BA2D NEG Negate A.
BA2F CP (IY+$19) Compare it with the height of the other object.
BA32 JR FlagOverlappingObjects_TestRows Jump to FlagOverlappingObjects_TestRows to jump to the next object if it is not tall enough, or to carry on with the test if it is.
View the equivalent code in;
Prev: B99B Up: Map Next: BA34