Prev: 48093 Up: Map Next: 48218
48119: Draw Room
Draws the graphics of a room. The room data is a list of graphics, each with the address of the graphic and the position to draw it at. Each graphic is drawn with DrawRoom_Process.
Input
HL The Room Data memory address (e.g. Room_Special_MainMenu, Room_00)
Before After
room-before room-after
The room data is held as:
Byte Type
1 Room Graphic Data Address
2
3 X Position
4 Y Position
And is terminated when 0000 is reached.
Fetch the room data graphic address.
DrawRoom 48119 LD E,(HL) Fetch the address of the graphic.
48120 INC HL
48121 LD D,(HL)
48122 LD A,E Return if the end of the room data has been reached (the address is zero).
48123 OR D
48124 RET Z
Fetch the X/ Y position data.
48125 INC HL Move onto the X position of the graphic.
48126 LD C,(HL) Fetch the X position into C and the Y position into B.
48127 INC HL
48128 LD B,(HL)
48129 INC HL Move onto the next graphic in the room data.
48130 PUSH HL Stash the pointer to the room data on the stack.
48131 LD H,B Copy the position into HL.
48132 LD L,C
48133 CALL DrawRoom_Process Draw the graphic.
48136 POP HL Restore the pointer to the room data from the stack.
48137 JR DrawRoom Jump back to DrawRoom to draw the next graphic.
This entry point is used by the routine at ShowAmulet.
At the point of processing; HL contains X/ Y position data, DE contains the room data graphic address (and BC is throwaway).
DrawRoom_Process 48139 PUSH HL Stash the position of the graphic on the stack.
48140 CALL ScreenAddress Convert the position into a screen address.
48143 LD A,(DE) Fetch the height of the graphic into C.
48144 LD C,A
48145 INC DE Increment DE by one.
48146 LD A,(DE) Fetch the width of the graphic into B.
48147 LD B,A
48148 INC DE Increment DE by one.
DrawRoom_Row_Loop 48149 PUSH BC Stash the counters on the stack.
DrawRoom_Write_Row 48150 LD A,(DE) Fetch a byte of the graphic.
48151 CPL Invert the bits.
48152 LD (HL),A Draw the byte on the screen.
48153 INC L Move onto the next column.
48154 INC DE Move onto the next byte of the graphic.
48155 DJNZ DrawRoom_Write_Row Decrease the width counter by one and loop back to DrawRoom_Write_Row until counter is zero.
48157 POP BC Restore the counters from the stack.
48158 LD A,L Move back to the first column.
48159 SUB B
48160 LD L,A
48161 CALL ScreenPosition1PixelBelow Move down to the next pixel line.
48164 DEC C Decrease the height counter by one and loop back to DrawRoom_Row_Loop until counter is zero.
48165 JR NZ,DrawRoom_Row_Loop
48167 POP HL Restore the position of the graphic from the stack.
48168 CALL AttributeAddress Convert the position into an attribute address.
Now set the attributes.
48171 LD A,(DE) Fetch the height of the attribute data into C.
48172 INC DE
48173 LD C,A
48174 LD A,(DE) Fetch the width of the attribute data into B.
48175 INC DE
48176 LD B,A
48177 LD A,(38578) Jump to DrawRoom_Second_Attributes if AttributeSetFlag is not zero, to use the second set of attributes.
48180 AND A
48181 JR NZ,DrawRoom_Second_Attributes
DrawRoom_Attribute_Row_Loop 48183 PUSH BC Stash the counters on the stack.
48184 PUSH HL Stash the start of the row on the stack.
DrawRoom_Attribute_Loop 48185 LD A,(DE) Fetch an attribute.
48186 INC DE Move onto the next attribute.
48187 LD (HL),A Set the attribute on the screen.
48188 INC L Move onto the next column.
48189 DJNZ DrawRoom_Attribute_Loop Decrease the width counter by one and loop back to DrawRoom_Attribute_Loop until counter is zero.
48191 POP HL Restore the start of the row from the stack.
48192 LD BC,32 BC=0032.
48195 ADD HL,BC Move down one row of attributes.
48196 POP BC Restore the counters from the stack.
48197 DEC C Decrease the row counter by one and loop back to DrawRoom_Attribute_Row_Loop until all of the rows of attributes have been set.
48198 JR NZ,DrawRoom_Attribute_Row_Loop
48200 RET Return.
Use the second set of attributes, by skipping over the first set.
DrawRoom_Second_Attributes 48201 PUSH BC Stash the counters on the stack.
48202 XOR A Start the total at zero.
48203 LD (38578),A Clear AttributeSetFlag, so the first set of attributes is used next time.
DrawRoom_Skip_Attributes 48206 ADD A,C Add the height to A, once for each column, to find the size of the first set.
48207 DJNZ DrawRoom_Skip_Attributes Decrease B by one and loop back to DrawRoom_Skip_Attributes until it is zero.
48209 LD C,A C=A.
48210 LD B,0 B=0.
48212 EX DE,HL Swap DE and HL.
48213 ADD HL,BC Move the attribute data pointer past the first set.
48214 EX DE,HL Swap DE and HL back.
48215 POP BC Restore the counters from the stack.
48216 JR DrawRoom_Attribute_Row_Loop Jump to DrawRoom_Attribute_Row_Loop.
Prev: 48093 Up: Map Next: 48218