Prev: 45432 Up: Map Next: 45688
45470: 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 45470 XOR A Write 0 to WipedAreaCount.
45471 LD (42768),A
45474 PUSH IX Stash IX on the stack.
Jump to DrawChangedObjects_Draw if the room has just been built.
45476 LD A,(42769) Fetch RoomRedrawFlag.
45479 AND A Jump to DrawChangedObjects_Draw if it is not zero.
45480 JP NZ,DrawChangedObjects_Draw
Point DrawingListPointer at the start of the list of objects to draw, DrawList.
45483 LD HL,46426 Point HL at DrawList.
45486 LD (42770),HL Set DrawingListPointer.
Take the next object from the list and skip it if it has not moved.
DrawChangedObjects_NextEntry 45489 LD HL,(42770) Fetch the list pointer from DrawingListPointer.
Fetch the object number and move on the list pointer.
45492 LD A,(HL) Fetch the index of the object.
45493 INC HL Increment the list pointer.
45494 LD (42770),HL Update DrawingListPointer.
45497 CP 255 Jump to DrawChangedObjects_Draw if the end of the list has been reached.
45499 JP Z,DrawChangedObjects_Draw
Get the address of the object record.
45502 CALL FindObjectAddress Call FindObjectAddress to get the address of the object record.
45505 PUSH HL Copy the address of the object record to IX (using the stack).
45506 POP IX
45508 BIT 5,(IX+7) Jump to DrawChangedObjects_NextEntry if the object has not moved.
45512 JR Z,DrawChangedObjects_NextEntry
45514 RES 5,(IX+7) 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.
45518 LD A,(IX+26) Subtract the old pixel x from the new.
45521 SUB (IX+30)
45524 JP C,DrawChangedObjects_NewLeft Jump to DrawChangedObjects_NewLeft if carry is set.
45527 LD C,(IX+30) 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 45530 LD A,(IX+30) Fetch the old pixel x position.
45533 RRCA Divide it by eight.
45534 RRCA
45535 RRCA
45536 AND %00011111 Keep only the five bits of the column.
Add the previous width to get the old right edge.
45538 ADD A,(IX+28) Add the old width in bytes.
45541 LD E,A Copy it to E.
Divide the new x position by eight, to get its byte column.
45542 LD A,(IX+26) Fetch the new pixel x position.
45545 RRCA Divide it by eight to get the byte column.
45546 RRCA
45547 RRCA
45548 AND %00011111 Keep only the five bits of the column.
45550 ADD A,(IX+24) Add the new width to get the new right edge.
Compare it with the old right edge.
45553 CP E Jump to DrawChangedObjects_Width if the new right edge is lower.
45554 JR C,DrawChangedObjects_Width
45556 LD E,A Use the new right edge.
Divide the left edge by eight to get its byte column.
DrawChangedObjects_Width 45557 LD A,C Fetch C.
45558 RRCA Divide it by eight.
45559 RRCA
45560 RRCA
45561 AND %00011111 Keep only the five bits of the column.
45563 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.
45564 LD A,E Fetch E.
45565 SUB B Subtract B.
45566 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.
45567 LD A,(IX+27) Fetch the new pixel y position.
45570 SUB (IX+31) Subtract the old pixel y.
45573 JR C,DrawChangedObjects_NewBottom Jump to DrawChangedObjects_NewBottom if carry is set.
45575 LD B,(IX+31) 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 45578 LD A,(IX+31) Fetch the old pixel y position.
45581 ADD A,(IX+29) Add the old height in lines.
45584 LD E,A Copy it to E.
Add the new height to the new y position to get the new top.
45585 LD A,(IX+27) Fetch the new pixel y position.
45588 ADD A,(IX+25) Add the new height in lines.
45591 CP E Compare it with the old top.
45592 JR NC,DrawChangedObjects_Height Jump to DrawChangedObjects_Height if the new top is higher or the same.
45594 LD A,E Use the old top.
DrawChangedObjects_Height 45595 SUB B Subtract the bottom edge to get the height of the rectangle.
45596 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.
45597 LD A,B Fetch the bottom edge.
45598 CP 192 Jump to DrawChangedObjects_NextEntry if the rectangle is below the screen and so not visible.
45600 JR NC,DrawChangedObjects_NextEntry
45602 ADD A,L Add the height to get the top edge.
45603 SUB 192 Subtract 192 to see how far it is above the screen.
45605 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.
45607 NEG Negate A.
45609 ADD A,L Add L.
45610 LD L,A Copy it to L.
Wipe the area and keep it on the stack.
DrawChangedObjects_Queue 45611 CALL CalculateScreenAddress Call CalculateScreenAddress to get the screen address of the rectangle in DE.
45614 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.
45617 LD A,L Exchange L and C.
45618 LD L,C
45619 LD C,A
45620 LD A,H Exchange H and B.
45621 LD H,B
45622 LD B,A
Count the rectangle in WipedAreaCount.
45623 LD A,(42768) Fetch WipedAreaCount.
45626 INC A Increment A.
45627 LD (42768),A Set WipedAreaCount.
45630 PUSH BC Stash the width and height, the screen address and the buffer address on the stack.
45631 PUSH DE
45632 PUSH HL
45633 XOR A Set A to 0.
45634 CALL FillWindow Call FillWindow to clear the rectangle in the buffer.
45637 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 45640 LD C,(IX+26) Copy the new pixel x to C.
45643 JR DrawChangedObjects_RightEdge Jump to DrawChangedObjects_RightEdge.
Use the new y position as the bottom edge, and carry on at DrawChangedObjects_TopEdge.
DrawChangedObjects_NewBottom 45645 LD B,(IX+27) Copy the new pixel y to B.
45648 JR DrawChangedObjects_TopEdge Jump to DrawChangedObjects_TopEdge.
Draw the objects, then copy the wiped areas to the screen.
DrawChangedObjects_Draw 45650 CALL DrawObjectsInOrder Call DrawObjectsInOrder to sort the objects and draw them into the buffer.
45653 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.
45656 LD HL,42768 Point HL at WipedAreaCount.
45659 LD A,(42772) Fetch DrawingWorkCount.
45662 ADD A,(HL) Add WipedAreaCount.
45663 LD (42772),A Set DrawingWorkCount.
Jump to DrawChangedObjects_Done if there are no rectangles left on the stack.
DrawChangedObjects_Copy 45666 LD HL,42768 Point HL at WipedAreaCount.
45669 LD A,(HL) Jump to DrawChangedObjects_Done if it is zero.
45670 AND A
45671 JR Z,DrawChangedObjects_Done
45673 DEC (HL) Count the rectangle off.
45674 POP HL Fetch the buffer address, the screen address and the width and height from the stack.
45675 POP DE
45676 POP BC
45677 LD A,B Swap B and C, so that B is the number of lines and C the width.
45678 LD B,C
45679 LD C,A
45680 CALL CopyBlockToScreen Call CopyBlockToScreen to copy the rectangle to the screen.
45683 JR DrawChangedObjects_Copy Jump to DrawChangedObjects_Copy for the next rectangle.
DrawChangedObjects_Done 45685 POP IX Restore IX from the stack.
45687 RET Return.
View the equivalent code in;
Prev: 45432 Up: Map Next: 45688