Prev: 52531 Up: Map Next: 52698
52557: 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 52557 LD IY,23560 Point IY at the first object in the table, ObjectsTable.
52561 CALL CalculateSpriteSize Work out where the object is on the screen, and how big it is.
52564 LD B,40 Set the number of objects to 40.
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.
52566 LD A,(IX+26) Fetch the new pixel X coordinate of the object.
52569 RRCA Divide it by eight.
52570 RRCA
52571 RRCA
52572 AND %00011111 Keep the byte of the screen.
52574 LD L,A Stash it in L.
52575 LD A,(IX+30) Fetch the old pixel X coordinate of the object.
52578 RRCA Divide it by eight.
52579 RRCA
52580 RRCA
52581 AND %00011111 Keep the byte of the screen.
52583 LD H,A Stash it in H.
52584 CP L Compare the old with the new.
52585 JR C,FlagOverlappingObjects_RightEdge Jump to FlagOverlappingObjects_RightEdge if the old is lower.
52587 LD A,L Take the new one instead.
FlagOverlappingObjects_RightEdge 52588 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.
52589 LD A,L Fetch the new byte of the screen.
52590 ADD A,(IX+24) Add the width of the new position.
52593 LD L,A Stash the right edge in L.
52594 LD A,H Fetch the old byte of the screen.
52595 ADD A,(IX+28) Add the width of the old position.
52598 CP L Compare it with the new right edge.
52599 JR NC,FlagOverlappingObjects_AreaWidth Jump to FlagOverlappingObjects_AreaWidth if it is higher.
52601 LD A,L Take the new one instead.
FlagOverlappingObjects_AreaWidth 52602 SUB E Take the left edge off it.
52603 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.
52604 LD A,(IX+27) Fetch the new pixel Y coordinate.
52607 CP (IX+31) Compare it with the old one.
52610 JR C,FlagOverlappingObjects_TopEdge Jump to FlagOverlappingObjects_TopEdge if the new one is lower.
52612 LD A,(IX+31) Take the old one instead.
FlagOverlappingObjects_TopEdge 52615 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.
52616 LD A,(IX+27) Fetch the new pixel Y coordinate.
52619 ADD A,(IX+25) Add the height of the new position.
52622 LD H,A Stash the top edge in H.
52623 LD A,(IX+31) Fetch the old pixel Y coordinate.
52626 ADD A,(IX+29) Add the height of the old position.
52629 CP H Compare it with the new top edge.
52630 JR NC,FlagOverlappingObjects_AreaHeight Jump to FlagOverlappingObjects_AreaHeight if it is higher.
52632 LD A,H Take the new one instead.
FlagOverlappingObjects_AreaHeight 52633 SUB L Take the bottom edge off it.
52634 LD H,A Stash the height of the area in H.
FlagOverlappingObjects_Next 52635 LD A,(IY+0) Fetch the graphic number of the other object.
52638 AND A Test whether it is null.
52639 JR Z,FlagOverlappingObjects_Advance Jump to FlagOverlappingObjects_Advance if it is.
52641 BIT 4,(IY+7) Jump to FlagOverlappingObjects_Advance if the other object is already flagged to be drawn.
52645 JR NZ,FlagOverlappingObjects_Advance
52647 LD A,(IY+26) Fetch the pixel X coordinate of the other object.
52650 RRCA Divide it by eight.
52651 RRCA
52652 RRCA
52653 AND %00011111 Keep the byte of the screen.
52655 SUB E Take the left edge of the area off it.
52656 JR C,FlagOverlappingObjects_Left Jump to FlagOverlappingObjects_Left if the object starts to the left of the area.
FlagOverlappingObjects_Right 52658 CP D Compare it with the width of the area.
FlagOverlappingObjects_Right_Test 52659 JR NC,FlagOverlappingObjects_Advance Jump to FlagOverlappingObjects_Advance if the object starts to the right of the area.
52661 LD A,(IY+27) Fetch the pixel Y coordinate of the other object.
52664 SUB L Take the bottom edge of the area off it.
52665 JR C,FlagOverlappingObjects_Below Jump to FlagOverlappingObjects_Below if the object starts below the area.
FlagOverlappingObjects_Top 52667 CP H Compare it with the height of the area.
FlagOverlappingObjects_Top_Test 52668 JR NC,FlagOverlappingObjects_Advance Jump to FlagOverlappingObjects_Advance if the object starts above the area.
52670 SET 4,(IY+7) Flag the other object to be drawn.
FlagOverlappingObjects_Advance 52674 EXX Switch to the alternate registers.
52675 LD DE,32 Set DE to the size of an object.
52678 ADD IY,DE Point IY at the next object.
52680 EXX Switch back to the main registers.
52681 DJNZ FlagOverlappingObjects_Next Jump to FlagOverlappingObjects_Next until all of the objects have been tested.
52683 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 52684 NEG Make the distance positive.
52686 CP (IY+24) Compare it with the width of the sprite of the other object.
52689 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 52691 NEG Make the distance positive.
52693 CP (IY+25) Compare it with the height of the sprite of the other object.
52696 JR FlagOverlappingObjects_Top_Test Jump to FlagOverlappingObjects_Top_Test.
View the equivalent code in;
Prev: 52531 Up: Map Next: 52698