Prev: D56F Up: Map Next: D67C
D59F: Draw Changed Objects
Used by the routine at RunGame.
Updates the playing area for the objects that have changed. First the sprites of the objects that moved are wiped out of the screen buffer: for each object in the list at ObjectsToDrawList that is flagged to be wiped, the area covered by the old and the new position of its sprite is cleared, and the area is kept on the stack. Then the objects are drawn in order, the sun or moon is moved, and the objects the player is carrying are shown. Last, each of the areas that were kept is copied from the buffer to the screen. When the whole room has to be drawn there is nothing to wipe, and the screen is updated by the game loop.
DrawChangedObjects D59F XOR A Get a zero.
D5A0 LD ($5BA8),A Set the number of areas wiped to zero at WipedAreaCount.
D5A3 PUSH IX Stash IX on the stack.
D5A5 LD A,($5BB7) Fetch the flag that says the whole screen is to be drawn from RedrawPanelFlag.
D5A8 AND A
D5A9 JP NZ,DrawChangedObjects_Draw Jump to DrawChangedObjects_Draw if it is set.
D5AC LD HL,$CE8B Point HL at ObjectsToDrawList.
D5AF LD ($5BCB),HL Keep it as the place in the list at DrawingListPointer.
DrawChangedObjects_Wipe D5B2 LD HL,($5BCB) Fetch the place in the list from DrawingListPointer.
D5B5 LD A,(HL) Fetch the index of the object.
D5B6 INC HL Move on.
D5B7 LD ($5BCB),HL Store the place in the list at DrawingListPointer.
D5BA CP $FF Jump to DrawChangedObjects_Draw if it is the end of the list.
D5BC JP Z,DrawChangedObjects_Draw
D5BF CALL FindObjectAddress Find the address of the object.
D5C2 PUSH HL Point IX at the object (using the stack).
D5C3 POP IX
D5C5 BIT 5,(IX+$07) Jump to DrawChangedObjects_Wipe if the object is not flagged to be wiped.
D5C9 JR Z,DrawChangedObjects_Wipe
D5CB RES 5,(IX+$07) Clear the flag.
The left edge of the area is the lower of the old and the new pixel X coordinate. The width is worked out in bytes of the screen from there to the higher of the old and the new right edge.
D5CF LD A,(IX+$1A) Take the old pixel X coordinate off the new one.
D5D2 SUB (IX+$1E)
D5D5 JP C,DrawChangedObjects_Left Jump to DrawChangedObjects_Left if the new one is lower.
D5D8 LD C,(IX+$1E) Take the old pixel X coordinate as the left edge.
DrawChangedObjects_Width D5DB LD A,(IX+$1E) Fetch the old pixel X coordinate.
D5DE RRCA Divide it by eight.
D5DF RRCA
D5E0 RRCA
D5E1 AND %00011111 Keep the byte of the screen.
D5E3 ADD A,(IX+$1C) Add the old width in bytes.
D5E6 LD E,A Stash the old right edge in E.
D5E7 LD A,(IX+$1A) Fetch the new pixel X coordinate.
D5EA RRCA Divide it by eight.
D5EB RRCA
D5EC RRCA
D5ED AND %00011111 Keep the byte of the screen.
D5EF ADD A,(IX+$18) Add the new width in bytes.
D5F2 CP E Compare it with the old right edge.
D5F3 JR C,DrawChangedObjects_Width_FetchLeft Jump to DrawChangedObjects_Width_FetchLeft if the new right edge is lower.
D5F5 LD E,A Take the new right edge instead.
DrawChangedObjects_Width_FetchLeft D5F6 LD A,C Fetch the left edge.
D5F7 RRCA Divide it by eight.
D5F8 RRCA
D5F9 RRCA
D5FA AND %00011111 Keep the byte of the screen.
D5FC LD B,A Stash it in B.
D5FD LD A,E Fetch the right edge.
D5FE SUB B Take the left edge off it.
D5FF LD H,A Stash the width in bytes in H.
The bottom edge of the area is the lower of the old and the new pixel Y coordinate. The height is worked out from there to the higher of the old and the new top edge.
D600 LD A,(IX+$1B) Fetch the new pixel Y coordinate.
D603 SUB (IX+$1F) Take the old pixel Y coordinate off it.
D606 JR C,DrawChangedObjects_Bottom Jump to DrawChangedObjects_Bottom if the new one is lower.
D608 LD B,(IX+$1F) Take the old pixel Y coordinate as the bottom edge.
DrawChangedObjects_Height D60B LD A,(IX+$1F) Fetch the old pixel Y coordinate.
D60E ADD A,(IX+$1D) Add the old height in lines.
D611 LD E,A Stash the old top edge in E.
D612 LD A,(IX+$1B) Fetch the new pixel Y coordinate.
D615 ADD A,(IX+$19) Add the new height in lines.
D618 CP E Compare it with the old top edge.
D619 JR NC,DrawChangedObjects_Height_TakeBottom Jump to DrawChangedObjects_Height_TakeBottom if the new top edge is higher.
D61B LD A,E Take the old top edge instead.
DrawChangedObjects_Height_TakeBottom D61C SUB B Take the bottom edge off it.
D61D LD L,A Stash the height in lines in L.
D61E LD A,B Fetch the bottom edge.
D61F CP $C0 Jump to DrawChangedObjects_Wipe if it is off the screen.
D621 JR NC,DrawChangedObjects_Wipe
D623 ADD A,L Add the height to get the top edge.
D624 SUB $C0 Take the number of lines on the screen off it.
D626 JR C,DrawChangedObjects_Keep Jump to DrawChangedObjects_Keep if the area does not go off the top of the screen.
D628 NEG Make the number of lines that are off the screen positive.
D62A ADD A,L Take it off the height.
D62B LD L,A Stash the new height.
DrawChangedObjects_Keep D62C CALL CalculateScreenAddress Find the address of the area on the screen.
D62F CALL CalculateBufferAddress Find the address of the area in the buffer.
D632 LD A,L Swap the address of the area in the buffer with the size in HL, so that HL is the address and BC is the width and height.
D633 LD L,C
D634 LD C,A
D635 LD A,H Swap the rest.
D636 LD H,B
D637 LD B,A
D638 LD A,($5BA8) Fetch the number of areas wiped and add one to it from WipedAreaCount.
D63B INC A
D63C LD ($5BA8),A Store it at WipedAreaCount.
D63F PUSH BC Stash the width and height on the stack.
D640 PUSH DE Stash the address on the screen on the stack.
D641 PUSH HL Stash the address in the buffer on the stack.
D642 XOR A Get a zero to wipe the area with.
D643 CALL FillWindow Wipe the area.
D646 JP DrawChangedObjects_Wipe Jump to DrawChangedObjects_Wipe for the next object.
DrawChangedObjects_Left D649 LD C,(IX+$1A) Take the new pixel X coordinate as the left edge.
D64C JR DrawChangedObjects_Width Jump to DrawChangedObjects_Width.
DrawChangedObjects_Bottom D64E LD B,(IX+$1B) Take the new pixel Y coordinate as the bottom edge.
D651 JR DrawChangedObjects_Height Jump to DrawChangedObjects_Height.
Draw the objects, and then copy the areas that were wiped to the screen.
DrawChangedObjects_Draw D653 CALL DrawObjectsInOrder Draw the objects in order.
D656 CALL MoveSunMoon Move the sun or moon.
D659 CALL DisplayObjectsCarried Show the objects the player is carrying.
D65C LD HL,$5BA8 Point HL at WipedAreaCount.
D65F LD A,($5BBE) Fetch the number of objects drawn from ObjectsDrawn.
D662 ADD A,(HL) Add the number of areas wiped to it.
D663 LD ($5BBE),A Store it at ObjectsDrawn.
DrawChangedObjects_Copy D666 LD HL,$5BA8 Point HL at the number of areas wiped, WipedAreaCount.
D669 LD A,(HL) Fetch it and test whether it is zero.
D66A AND A
D66B JR Z,DrawChangedObjects_Copy_RestoreIX Jump to DrawChangedObjects_Copy_RestoreIX if it is.
D66D DEC (HL) Count it down.
D66E POP HL Restore the address in the buffer from the stack.
D66F POP DE Restore the address on the screen from the stack.
D670 POP BC Restore the width and height from the stack.
D671 LD A,B Swap the width and the height.
D672 LD B,C
D673 LD C,A
D674 CALL CopyBlockToScreen Copy the area to the screen.
D677 JR DrawChangedObjects_Copy Jump to DrawChangedObjects_Copy.
DrawChangedObjects_Copy_RestoreIX D679 POP IX Restore IX from the stack.
D67B RET Return.
View the equivalent code in;
Prev: D56F Up: Map Next: D67C