Prev: 47515 Up: Map Next: 47668
47527: 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 47527 LD IY,42863 Start with the first object record, ObjectsTable.
47531 CALL CalculateSpriteSize Call CalculateSpriteSize to work out the size of the sprite of the object.
47534 LD B,54 Set a counter in B of 54 objects.
Work out the first column of the area, which is the lower of the new and the old first columns.
47536 LD A,(IX+26) Fetch the new pixel x position.
47539 RRCA Divide it by eight.
47540 RRCA
47541 RRCA
47542 AND %00011111 ...and keep only the five bits of the column.
47544 LD L,A Set L to the new first column.
47545 LD A,(IX+30) Fetch the old pixel x position.
47548 RRCA Divide it by eight.
47549 RRCA
47550 RRCA
47551 AND %00011111 ...and keep only the five bits of the column.
47553 LD H,A Set H to the old first column.
47554 CP L Jump to FlagOverlappingObjects_Width if the old column is lower.
47555 JR C,FlagOverlappingObjects_Width
47557 LD A,L Use the new column.
FlagOverlappingObjects_Width 47558 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.
47559 LD A,L Copy L to A.
47560 ADD A,(IX+24) Add the new width.
47563 LD L,A Copy it to L.
Add the old width to the old first column to get the old last column.
47564 LD A,H Copy H to A.
47565 ADD A,(IX+28) Add the old width.
47568 CP L Jump to FlagOverlappingObjects_Bottom if the old last column is higher.
47569 JR NC,FlagOverlappingObjects_Bottom
47571 LD A,L Use the new last column.
FlagOverlappingObjects_Bottom 47572 SUB E Subtract the first column to get the width of the area.
47573 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.
47574 LD A,(IX+27) Fetch the new pixel y position.
47577 CP (IX+31) Compare it with the old one.
47580 JR C,FlagOverlappingObjects_Height Jump to FlagOverlappingObjects_Height if the new one is lower.
47582 LD A,(IX+31) Fetch the old pixel y position.
FlagOverlappingObjects_Height 47585 LD L,A Copy it to L.
The height is the higher top edge less the bottom edge. It is kept in H.
47586 LD A,(IX+27) Fetch the new pixel y position.
47589 ADD A,(IX+25) Add the new height.
47592 LD H,A Copy it to H.
Add the old height to the old y co-ordinate to get the old top.
47593 LD A,(IX+31) Fetch the old pixel y position.
47596 ADD A,(IX+29) Add the old height.
47599 CP H Jump to FlagOverlappingObjects_Loop if the old top is higher.
47600 JR NC,FlagOverlappingObjects_Loop
47602 LD A,H Copy H to A.
FlagOverlappingObjects_Loop 47603 SUB L Subtract the bottom to get the height of the area.
47604 LD H,A Set H to the height of the area.
Flag any object that overlaps the area.
FlagOverlappingObjects_Next 47605 LD A,(IY+0) Fetch the sprite number of the other object.
47608 AND A Jump to FlagOverlappingObjects_Skip if it is zero.
47609 JR Z,FlagOverlappingObjects_Skip
47611 BIT 4,(IY+7) Jump to FlagOverlappingObjects_Skip if the other object is already flagged.
47615 JR NZ,FlagOverlappingObjects_Skip
Divide the screen x co-ordinate of the other object by eight...
47617 LD A,(IY+26) Fetch the pixel x position of the other object.
47620 RRCA Divide it by eight.
47621 RRCA
47622 RRCA
47623 AND %00011111 ...and keep only the five bits of the column.
47625 SUB E Subtract the first column of the area.
47626 JR C,FlagOverlappingObjects_StartsBefore Jump to FlagOverlappingObjects_StartsBefore if it starts before the area.
47628 CP D Compare the distance with the width of the area.
FlagOverlappingObjects_TestColumns 47629 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.
47631 LD A,(IY+27) Fetch the pixel y position of the other object.
47634 SUB L Subtract L.
47635 JR C,FlagOverlappingObjects_StartsBelow Jump to FlagOverlappingObjects_StartsBelow if it starts below the area.
47637 CP H Compare the distance with the height of the area.
FlagOverlappingObjects_TestRows 47638 JR NC,FlagOverlappingObjects_Skip Jump to FlagOverlappingObjects_Skip if it starts above the area.
47640 SET 4,(IY+7) 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 47644 EXX Switch to the shadow registers.
47645 LD DE,32 Set DE' to 0032.
47648 ADD IY,DE Add DE' to IY.
47650 EXX Switch to the main registers.
47651 DJNZ FlagOverlappingObjects_Next Decrease the counter and loop until all the objects have been tried.
47653 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 47654 NEG Negate A.
47656 CP (IY+24) Compare it with the width of the other object.
47659 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 47661 NEG Negate A.
47663 CP (IY+25) Compare it with the height of the other object.
47666 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: 47515 Up: Map Next: 47668