Prev: C63D Up: Map Next: C6E4
C657: 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 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 C657 LD IY,$5B88 Point IY at PlayerBottomObject.
C65B CALL CalculateSpriteSize Call CalculateSpriteSize.
C65E LD B,$38 Set B to 38.
C660 LD A,(IX+$1A) Fetch the new pixel x position.
C663 RRCA Divide it by eight.
C664 RRCA
C665 RRCA
C666 AND %00011111 Keep only bits 0-4.
C668 LD L,A Copy it to L.
C669 LD A,(IX+$1E) Fetch the old pixel x position.
C66C RRCA Divide it by eight.
C66D RRCA
C66E RRCA
C66F AND %00011111 Keep only bits 0-4.
C671 LD H,A Copy it to H.
C672 CP L Jump to FlagOverlappingObjects_RightEdge if the old is lower.
C673 JR C,FlagOverlappingObjects_RightEdge
C675 LD A,L Copy L to A.
FlagOverlappingObjects_RightEdge C676 LD E,A Copy it to E.
The width is the higher right edge less the left edge. It is kept in D.
C677 LD A,L Copy L to A.
C678 ADD A,(IX+$18) Add the new width.
C67B LD L,A Copy it to L.
C67C LD A,H Copy H to A.
C67D ADD A,(IX+$1C) Add the old width.
C680 CP L Jump to FlagOverlappingObjects_AreaWidth if it is higher.
C681 JR NC,FlagOverlappingObjects_AreaWidth
C683 LD A,L Copy L to A.
FlagOverlappingObjects_AreaWidth C684 SUB E Subtract E.
C685 LD D,A Copy it to D.
The bottom edge is the lower of the old and new pixel y. It is kept in L.
C686 LD A,(IX+$1B) Fetch the new pixel y position.
C689 CP (IX+$1F) Compare it with the old one.
C68C JR C,FlagOverlappingObjects_TopEdge Jump to FlagOverlappingObjects_TopEdge if the new one is lower.
C68E LD A,(IX+$1F) Fetch the old pixel y position.
FlagOverlappingObjects_TopEdge C691 LD L,A Copy it to L.
The height is the higher top edge less the bottom edge. It is kept in H.
C692 LD A,(IX+$1B) Fetch the new pixel y position.
C695 ADD A,(IX+$19) Add the new height.
C698 LD H,A Copy it to H.
C699 LD A,(IX+$1F) Fetch the old pixel y position.
C69C ADD A,(IX+$1D) Add the old height.
C69F CP H Jump to FlagOverlappingObjects_AreaHeight if it is higher.
C6A0 JR NC,FlagOverlappingObjects_AreaHeight
C6A2 LD A,H Copy H to A.
FlagOverlappingObjects_AreaHeight C6A3 SUB L Subtract L.
C6A4 LD H,A Copy it to H.
Flag any object that overlaps the area.
FlagOverlappingObjects_Next C6A5 LD A,(IY+$00) Fetch the sprite number of the other object.
C6A8 AND A Jump to FlagOverlappingObjects_Advance if it is zero.
C6A9 JR Z,FlagOverlappingObjects_Advance
C6AB BIT 4,(IY+$07) Jump to FlagOverlappingObjects_Advance if the object is already flagged to be drawn.
C6AF JR NZ,FlagOverlappingObjects_Advance
C6B1 LD A,(IY+$1A) Fetch the pixel x position of the other object.
C6B4 RRCA Divide it by eight.
C6B5 RRCA
C6B6 RRCA
C6B7 AND %00011111 Keep only bits 0-4.
C6B9 SUB E Subtract E.
C6BA JR C,FlagOverlappingObjects_Left Jump to FlagOverlappingObjects_Left if carry is set.
C6BC CP D Compare it with D.
FlagOverlappingObjects_Right C6BD JR NC,FlagOverlappingObjects_Advance Jump to FlagOverlappingObjects_Advance if carry is not set.
C6BF LD A,(IY+$1B) Fetch the pixel y position of the other object.
C6C2 SUB L Subtract L.
C6C3 JR C,FlagOverlappingObjects_Below Jump to FlagOverlappingObjects_Below if carry is set.
C6C5 CP H Compare it with H.
FlagOverlappingObjects_Top C6C6 JR NC,FlagOverlappingObjects_Advance Jump to FlagOverlappingObjects_Advance if carry is not set.
C6C8 SET 4,(IY+$07) Set bit 4 of the flags.
FlagOverlappingObjects_Advance C6CC EXX Switch to the shadow registers.
C6CD LD DE,$0020 Set DE' to 0020.
C6D0 ADD IY,DE Add DE' to IY.
C6D2 EXX Switch to the main registers.
C6D3 DJNZ FlagOverlappingObjects_Next Jump to FlagOverlappingObjects_Next until B is zero.
C6D5 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 C6D6 NEG Negate A.
C6D8 CP (IY+$18) Compare it with the width of the other object.
C6DB JR FlagOverlappingObjects_Right Jump to FlagOverlappingObjects_Right.
The object starts below the area, so it overlaps only if it is tall enough to reach the area.
FlagOverlappingObjects_Below C6DD NEG Negate A.
C6DF CP (IY+$19) Compare it with the height of the other object.
C6E2 JR FlagOverlappingObjects_Top Jump to FlagOverlappingObjects_Top.
View the equivalent code in;
Prev: C63D Up: Map Next: C6E4