Prev: 54639 Up: Map Next: 54908
54687: 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 54687 XOR A Get a zero.
54688 LD (23464),A Set the number of areas wiped to zero at WipedAreaCount.
54691 PUSH IX Stash IX on the stack.
54693 LD A,(23479) Fetch the flag that says the whole screen is to be drawn from RedrawPanelFlag.
54696 AND A
54697 JP NZ,DrawChangedObjects_Draw Jump to DrawChangedObjects_Draw if it is set.
54700 LD HL,52875 Point HL at ObjectsToDrawList.
54703 LD (23499),HL Keep it as the place in the list at DrawingListPointer.
DrawChangedObjects_Wipe 54706 LD HL,(23499) Fetch the place in the list from DrawingListPointer.
54709 LD A,(HL) Fetch the index of the object.
54710 INC HL Move on.
54711 LD (23499),HL Store the place in the list at DrawingListPointer.
54714 CP 255 Jump to DrawChangedObjects_Draw if it is the end of the list.
54716 JP Z,DrawChangedObjects_Draw
54719 CALL FindObjectAddress Find the address of the object.
54722 PUSH HL Point IX at the object (using the stack).
54723 POP IX
54725 BIT 5,(IX+7) Jump to DrawChangedObjects_Wipe if the object is not flagged to be wiped.
54729 JR Z,DrawChangedObjects_Wipe
54731 RES 5,(IX+7) 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.
54735 LD A,(IX+26) Take the old pixel X coordinate off the new one.
54738 SUB (IX+30)
54741 JP C,DrawChangedObjects_Left Jump to DrawChangedObjects_Left if the new one is lower.
54744 LD C,(IX+30) Take the old pixel X coordinate as the left edge.
DrawChangedObjects_Width 54747 LD A,(IX+30) Fetch the old pixel X coordinate.
54750 RRCA Divide it by eight.
54751 RRCA
54752 RRCA
54753 AND %00011111 Keep the byte of the screen.
54755 ADD A,(IX+28) Add the old width in bytes.
54758 LD E,A Stash the old right edge in E.
54759 LD A,(IX+26) Fetch the new pixel X coordinate.
54762 RRCA Divide it by eight.
54763 RRCA
54764 RRCA
54765 AND %00011111 Keep the byte of the screen.
54767 ADD A,(IX+24) Add the new width in bytes.
54770 CP E Compare it with the old right edge.
54771 JR C,DrawChangedObjects_Width_FetchLeft Jump to DrawChangedObjects_Width_FetchLeft if the new right edge is lower.
54773 LD E,A Take the new right edge instead.
DrawChangedObjects_Width_FetchLeft 54774 LD A,C Fetch the left edge.
54775 RRCA Divide it by eight.
54776 RRCA
54777 RRCA
54778 AND %00011111 Keep the byte of the screen.
54780 LD B,A Stash it in B.
54781 LD A,E Fetch the right edge.
54782 SUB B Take the left edge off it.
54783 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.
54784 LD A,(IX+27) Fetch the new pixel Y coordinate.
54787 SUB (IX+31) Take the old pixel Y coordinate off it.
54790 JR C,DrawChangedObjects_Bottom Jump to DrawChangedObjects_Bottom if the new one is lower.
54792 LD B,(IX+31) Take the old pixel Y coordinate as the bottom edge.
DrawChangedObjects_Height 54795 LD A,(IX+31) Fetch the old pixel Y coordinate.
54798 ADD A,(IX+29) Add the old height in lines.
54801 LD E,A Stash the old top edge in E.
54802 LD A,(IX+27) Fetch the new pixel Y coordinate.
54805 ADD A,(IX+25) Add the new height in lines.
54808 CP E Compare it with the old top edge.
54809 JR NC,DrawChangedObjects_Height_TakeBottom Jump to DrawChangedObjects_Height_TakeBottom if the new top edge is higher.
54811 LD A,E Take the old top edge instead.
DrawChangedObjects_Height_TakeBottom 54812 SUB B Take the bottom edge off it.
54813 LD L,A Stash the height in lines in L.
54814 LD A,B Fetch the bottom edge.
54815 CP 192 Jump to DrawChangedObjects_Wipe if it is off the screen.
54817 JR NC,DrawChangedObjects_Wipe
54819 ADD A,L Add the height to get the top edge.
54820 SUB 192 Take the number of lines on the screen off it.
54822 JR C,DrawChangedObjects_Keep Jump to DrawChangedObjects_Keep if the area does not go off the top of the screen.
54824 NEG Make the number of lines that are off the screen positive.
54826 ADD A,L Take it off the height.
54827 LD L,A Stash the new height.
DrawChangedObjects_Keep 54828 CALL CalculateScreenAddress Find the address of the area on the screen.
54831 CALL CalculateBufferAddress Find the address of the area in the buffer.
54834 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.
54835 LD L,C
54836 LD C,A
54837 LD A,H Swap the rest.
54838 LD H,B
54839 LD B,A
54840 LD A,(23464) Fetch the number of areas wiped and add one to it from WipedAreaCount.
54843 INC A
54844 LD (23464),A Store it at WipedAreaCount.
54847 PUSH BC Stash the width and height on the stack.
54848 PUSH DE Stash the address on the screen on the stack.
54849 PUSH HL Stash the address in the buffer on the stack.
54850 XOR A Get a zero to wipe the area with.
54851 CALL FillWindow Wipe the area.
54854 JP DrawChangedObjects_Wipe Jump to DrawChangedObjects_Wipe for the next object.
DrawChangedObjects_Left 54857 LD C,(IX+26) Take the new pixel X coordinate as the left edge.
54860 JR DrawChangedObjects_Width Jump to DrawChangedObjects_Width.
DrawChangedObjects_Bottom 54862 LD B,(IX+27) Take the new pixel Y coordinate as the bottom edge.
54865 JR DrawChangedObjects_Height Jump to DrawChangedObjects_Height.
Draw the objects, and then copy the areas that were wiped to the screen.
DrawChangedObjects_Draw 54867 CALL DrawObjectsInOrder Draw the objects in order.
54870 CALL MoveSunMoon Move the sun or moon.
54873 CALL DisplayObjectsCarried Show the objects the player is carrying.
54876 LD HL,23464 Point HL at WipedAreaCount.
54879 LD A,(23486) Fetch the number of objects drawn from ObjectsDrawn.
54882 ADD A,(HL) Add the number of areas wiped to it.
54883 LD (23486),A Store it at ObjectsDrawn.
DrawChangedObjects_Copy 54886 LD HL,23464 Point HL at the number of areas wiped, WipedAreaCount.
54889 LD A,(HL) Fetch it and test whether it is zero.
54890 AND A
54891 JR Z,DrawChangedObjects_Copy_RestoreIX Jump to DrawChangedObjects_Copy_RestoreIX if it is.
54893 DEC (HL) Count it down.
54894 POP HL Restore the address in the buffer from the stack.
54895 POP DE Restore the address on the screen from the stack.
54896 POP BC Restore the width and height from the stack.
54897 LD A,B Swap the width and the height.
54898 LD B,C
54899 LD C,A
54900 CALL CopyBlockToScreen Copy the area to the screen.
54903 JR DrawChangedObjects_Copy Jump to DrawChangedObjects_Copy.
DrawChangedObjects_Copy_RestoreIX 54905 POP IX Restore IX from the stack.
54907 RET Return.
View the equivalent code in;
Prev: 54639 Up: Map Next: 54908