Prev: B178 Up: Map Next: B278
B19E: 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 DrawList 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 and the objects that the player is carrying are shown. Last, each of the areas that were kept is copied from the buffer to the screen. When the panel is to be drawn again, the whole screen is going to be drawn, so none of the areas are wiped.
Start with no rectangles queued, unless the whole room needs drawing.
Wipe each flagged sprite, unless the panel is to be drawn again.
DrawChangedObjects B19E XOR A Write 00 to WipedAreaCount.
B19F LD ($A710),A
B1A2 PUSH IX Stash IX on the stack.
Jump to DrawChangedObjects_Draw if the room has just been built.
B1A4 LD A,($A711) Fetch RoomRedrawFlag.
B1A7 AND A Jump to DrawChangedObjects_Draw if it is not zero.
B1A8 JP NZ,DrawChangedObjects_Draw
Point DrawingListPointer at the start of the list of objects to draw, DrawList.
B1AB LD HL,$B55A Point HL at DrawList.
B1AE LD ($A712),HL Set DrawingListPointer.
Take the next object from the list and skip it if it has not moved.
DrawChangedObjects_NextEntry B1B1 LD HL,($A712) Fetch the list pointer from DrawingListPointer.
Fetch the object number and move on the list pointer.
B1B4 LD A,(HL) Fetch the index of the object.
B1B5 INC HL Increment the list pointer.
B1B6 LD ($A712),HL Update DrawingListPointer.
B1B9 CP $FF Jump to DrawChangedObjects_Draw if the end of the list has been reached.
B1BB JP Z,DrawChangedObjects_Draw
Get the address of the object record.
B1BE CALL FindObjectAddress Call FindObjectAddress to get the address of the object record.
B1C1 PUSH HL Copy the address of the object record to IX (using the stack).
B1C2 POP IX
B1C4 BIT 5,(IX+$07) Jump to DrawChangedObjects_NextEntry if the object has not moved.
B1C8 JR Z,DrawChangedObjects_NextEntry
B1CA RES 5,(IX+$07) Clear the flag that says it has moved.
The left edge of the area is the lower of the old and the new pixel x position. The width is worked out in bytes of the screen from there to the higher of the old and the new right edge.
B1CE LD A,(IX+$1A) Subtract the old pixel x from the new.
B1D1 SUB (IX+$1E)
B1D4 JP C,DrawChangedObjects_NewLeft Jump to DrawChangedObjects_NewLeft if carry is set.
B1D7 LD C,(IX+$1E) Use the previous x position as the left edge.
Find the right edge, in bytes: the larger of the old and new right edges.
DrawChangedObjects_RightEdge B1DA LD A,(IX+$1E) Fetch the old pixel x position.
B1DD RRCA Divide it by eight.
B1DE RRCA
B1DF RRCA
B1E0 AND %00011111 Keep only the five bits of the column.
Add the previous width to get the old right edge.
B1E2 ADD A,(IX+$1C) Add the old width in bytes.
B1E5 LD E,A Copy it to E.
Divide the new x position by eight, to get its byte column.
B1E6 LD A,(IX+$1A) Fetch the new pixel x position.
B1E9 RRCA Divide it by eight to get the byte column.
B1EA RRCA
B1EB RRCA
B1EC AND %00011111 Keep only the five bits of the column.
B1EE ADD A,(IX+$18) Add the new width to get the new right edge.
Compare it with the old right edge.
B1F1 CP E Jump to DrawChangedObjects_Width if the new right edge is lower.
B1F2 JR C,DrawChangedObjects_Width
B1F4 LD E,A Use the new right edge.
Divide the left edge by eight to get its byte column.
DrawChangedObjects_Width B1F5 LD A,C Fetch C.
B1F6 RRCA Divide it by eight.
B1F7 RRCA
B1F8 RRCA
B1F9 AND %00011111 Keep only the five bits of the column.
B1FB LD B,A Stash the left column in B.
Subtract it from the right edge to get the width of the rectangle in bytes, in H.
B1FC LD A,E Fetch E.
B1FD SUB B Subtract B.
B1FE LD H,A Copy it to H.
The bottom edge of the area is the lower of the old and the new pixel y position. The height is worked out from there to the higher of the old and the new top edge.
B1FF LD A,(IX+$1B) Fetch the new pixel y position.
B202 SUB (IX+$1F) Subtract the old pixel y.
B205 JR C,DrawChangedObjects_NewBottom Jump to DrawChangedObjects_NewBottom if carry is set.
B207 LD B,(IX+$1F) Use the previous y position as the bottom edge.
Find the top edge: the higher of the old and new tops, and so the height.
DrawChangedObjects_TopEdge B20A LD A,(IX+$1F) Fetch the old pixel y position.
B20D ADD A,(IX+$1D) Add the old height in lines.
B210 LD E,A Copy it to E.
Add the new height to the new y position to get the new top.
B211 LD A,(IX+$1B) Fetch the new pixel y position.
B214 ADD A,(IX+$19) Add the new height in lines.
B217 CP E Compare it with the old top.
B218 JR NC,DrawChangedObjects_Height Jump to DrawChangedObjects_Height if the new top is higher or the same.
B21A LD A,E Use the old top.
DrawChangedObjects_Height B21B SUB B Subtract the bottom edge to get the height of the rectangle.
B21C LD L,A Set the height in L.
Clip the rectangle to the top of the screen, and ignore it when it is wholly off the screen.
B21D LD A,B Fetch the bottom edge.
B21E CP $C0 Jump to DrawChangedObjects_NextEntry if the rectangle is below the screen and so not visible.
B220 JR NC,DrawChangedObjects_NextEntry
B222 ADD A,L Add the height to get the top edge.
B223 SUB $C0 Subtract C0 to see how far it is above the screen.
B225 JR C,DrawChangedObjects_Queue Jump to DrawChangedObjects_Queue if it is not above the screen.
Reduce the height by that amount, so the rectangle ends at the top of the screen.
B227 NEG Negate A.
B229 ADD A,L Add L.
B22A LD L,A Copy it to L.
Wipe the area and keep it on the stack.
DrawChangedObjects_Queue B22B CALL CalculateScreenAddress Call CalculateScreenAddress to get the screen address of the rectangle in DE.
B22E CALL CalculateBufferAddress Call CalculateBufferAddress to get the buffer address in BC.
Swap so that HL is the buffer address, B the width and C the height.
B231 LD A,L Exchange L and C.
B232 LD L,C
B233 LD C,A
B234 LD A,H Exchange H and B.
B235 LD H,B
B236 LD B,A
Count the rectangle in WipedAreaCount.
B237 LD A,($A710) Fetch WipedAreaCount.
B23A INC A Increment A.
B23B LD ($A710),A Set WipedAreaCount.
B23E PUSH BC Stash the width and height, the screen address and the buffer address on the stack.
B23F PUSH DE
B240 PUSH HL
B241 XOR A Set A to 00.
B242 CALL FillWindow Call FillWindow to clear the rectangle in the buffer.
B245 JP DrawChangedObjects_NextEntry Jump to DrawChangedObjects_NextEntry to look at the next object.
Use the new x position as the left edge, and carry on at DrawChangedObjects_RightEdge.
DrawChangedObjects_NewLeft B248 LD C,(IX+$1A) Copy the new pixel x to C.
B24B JR DrawChangedObjects_RightEdge Jump to DrawChangedObjects_RightEdge.
Use the new y position as the bottom edge, and carry on at DrawChangedObjects_TopEdge.
DrawChangedObjects_NewBottom B24D LD B,(IX+$1B) Copy the new pixel y to B.
B250 JR DrawChangedObjects_TopEdge Jump to DrawChangedObjects_TopEdge.
Draw the objects, then copy the wiped areas to the screen.
DrawChangedObjects_Draw B252 CALL DrawObjectsInOrder Call DrawObjectsInOrder to sort the objects and draw them into the buffer.
B255 CALL CheckInventory Call CheckInventory to redraw the inventory if it has changed.
Add the number of rectangles queued to the count of objects drawn in DrawingWorkCount.
B258 LD HL,$A710 Point HL at WipedAreaCount.
B25B LD A,($A714) Fetch DrawingWorkCount.
B25E ADD A,(HL) Add WipedAreaCount.
B25F LD ($A714),A Set DrawingWorkCount.
Jump to DrawChangedObjects_Done if there are no rectangles left on the stack.
DrawChangedObjects_Copy B262 LD HL,$A710 Point HL at WipedAreaCount.
B265 LD A,(HL) Jump to DrawChangedObjects_Done if it is zero.
B266 AND A
B267 JR Z,DrawChangedObjects_Done
B269 DEC (HL) Count the rectangle off.
B26A POP HL Fetch the buffer address, the screen address and the width and height from the stack.
B26B POP DE
B26C POP BC
B26D LD A,B Swap B and C, so that B is the number of lines and C the width.
B26E LD B,C
B26F LD C,A
B270 CALL CopyBlockToScreen Call CopyBlockToScreen to copy the rectangle to the screen.
B273 JR DrawChangedObjects_Copy Jump to DrawChangedObjects_Copy for the next rectangle.
DrawChangedObjects_Done B275 POP IX Restore IX from the stack.
B277 RET Return.
View the equivalent code in;
Prev: B178 Up: Map Next: B278