Prev: CD33 Up: Map Next: CDDA
CD4D: Flag Overlapping Objects
Used by the routines at SetWipeAndDrawFlags and HandlePlayerTop.
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 Address of the object
FlagOverlappingObjects CD4D LD IY,$5C08 Point IY at the first object in the table, ObjectsTable.
CD51 CALL CalculateSpriteSize Work out where the object is on the screen, and how big it is.
CD54 LD B,$28 Set the number of objects to 28.
The left edge of the area, in bytes of the screen, is the lower of the byte of the old and of the new position. It is kept in E.
CD56 LD A,(IX+$1A) Fetch the new pixel X coordinate of the object.
CD59 RRCA Divide it by eight.
CD5A RRCA
CD5B RRCA
CD5C AND %00011111 Keep the byte of the screen.
CD5E LD L,A Stash it in L.
CD5F LD A,(IX+$1E) Fetch the old pixel X coordinate of the object.
CD62 RRCA Divide it by eight.
CD63 RRCA
CD64 RRCA
CD65 AND %00011111 Keep the byte of the screen.
CD67 LD H,A Stash it in H.
CD68 CP L Compare the old with the new.
CD69 JR C,FlagOverlappingObjects_RightEdge Jump to FlagOverlappingObjects_RightEdge if the old is lower.
CD6B LD A,L Take the new one instead.
FlagOverlappingObjects_RightEdge CD6C LD E,A Stash the left edge in E.
The width of the area is the higher of the right edge of the old and of the new position, less the left edge. It is kept in D.
CD6D LD A,L Fetch the new byte of the screen.
CD6E ADD A,(IX+$18) Add the width of the new position.
CD71 LD L,A Stash the right edge in L.
CD72 LD A,H Fetch the old byte of the screen.
CD73 ADD A,(IX+$1C) Add the width of the old position.
CD76 CP L Compare it with the new right edge.
CD77 JR NC,FlagOverlappingObjects_AreaWidth Jump to FlagOverlappingObjects_AreaWidth if it is higher.
CD79 LD A,L Take the new one instead.
FlagOverlappingObjects_AreaWidth CD7A SUB E Take the left edge off it.
CD7B LD D,A Stash the width of the area in D.
The bottom edge of the area is the lower of the old and the new pixel Y coordinate. It is kept in L.
CD7C LD A,(IX+$1B) Fetch the new pixel Y coordinate.
CD7F CP (IX+$1F) Compare it with the old one.
CD82 JR C,FlagOverlappingObjects_TopEdge Jump to FlagOverlappingObjects_TopEdge if the new one is lower.
CD84 LD A,(IX+$1F) Take the old one instead.
FlagOverlappingObjects_TopEdge CD87 LD L,A Stash the bottom edge in L.
The height of the area is the higher of the top edge of the old and of the new position, less the bottom edge. It is kept in H.
CD88 LD A,(IX+$1B) Fetch the new pixel Y coordinate.
CD8B ADD A,(IX+$19) Add the height of the new position.
CD8E LD H,A Stash the top edge in H.
CD8F LD A,(IX+$1F) Fetch the old pixel Y coordinate.
CD92 ADD A,(IX+$1D) Add the height of the old position.
CD95 CP H Compare it with the new top edge.
CD96 JR NC,FlagOverlappingObjects_AreaHeight Jump to FlagOverlappingObjects_AreaHeight if it is higher.
CD98 LD A,H Take the new one instead.
FlagOverlappingObjects_AreaHeight CD99 SUB L Take the bottom edge off it.
CD9A LD H,A Stash the height of the area in H.
FlagOverlappingObjects_Next CD9B LD A,(IY+$00) Fetch the graphic number of the other object.
CD9E AND A Test whether it is null.
CD9F JR Z,FlagOverlappingObjects_Advance Jump to FlagOverlappingObjects_Advance if it is.
CDA1 BIT 4,(IY+$07) Jump to FlagOverlappingObjects_Advance if the other object is already flagged to be drawn.
CDA5 JR NZ,FlagOverlappingObjects_Advance
CDA7 LD A,(IY+$1A) Fetch the pixel X coordinate of the other object.
CDAA RRCA Divide it by eight.
CDAB RRCA
CDAC RRCA
CDAD AND %00011111 Keep the byte of the screen.
CDAF SUB E Take the left edge of the area off it.
CDB0 JR C,FlagOverlappingObjects_Left Jump to FlagOverlappingObjects_Left if the object starts to the left of the area.
FlagOverlappingObjects_Right CDB2 CP D Compare it with the width of the area.
FlagOverlappingObjects_Right_Test CDB3 JR NC,FlagOverlappingObjects_Advance Jump to FlagOverlappingObjects_Advance if the object starts to the right of the area.
CDB5 LD A,(IY+$1B) Fetch the pixel Y coordinate of the other object.
CDB8 SUB L Take the bottom edge of the area off it.
CDB9 JR C,FlagOverlappingObjects_Below Jump to FlagOverlappingObjects_Below if the object starts below the area.
FlagOverlappingObjects_Top CDBB CP H Compare it with the height of the area.
FlagOverlappingObjects_Top_Test CDBC JR NC,FlagOverlappingObjects_Advance Jump to FlagOverlappingObjects_Advance if the object starts above the area.
CDBE SET 4,(IY+$07) Flag the other object to be drawn.
FlagOverlappingObjects_Advance CDC2 EXX Switch to the alternate registers.
CDC3 LD DE,$0020 Set DE to the size of an object.
CDC6 ADD IY,DE Point IY at the next object.
CDC8 EXX Switch back to the main registers.
CDC9 DJNZ FlagOverlappingObjects_Next Jump to FlagOverlappingObjects_Next until all of the objects have been tested.
CDCB 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_Left CDCC NEG Make the distance positive.
CDCE CP (IY+$18) Compare it with the width of the sprite of the other object.
CDD1 JR FlagOverlappingObjects_Right_Test Jump to FlagOverlappingObjects_Right_Test.
The object starts below the area, so it overlaps only if it is tall enough to reach the area.
FlagOverlappingObjects_Below CDD3 NEG Make the distance positive.
CDD5 CP (IY+$19) Compare it with the height of the sprite of the other object.
CDD8 JR FlagOverlappingObjects_Top_Test Jump to FlagOverlappingObjects_Top_Test.
View the equivalent code in;
Prev: CD33 Up: Map Next: CDDA