Prev: 9BD2 Up: Map Next: 9C61
9BEA: Draw Room Frame
Used by the routine at EnterRoom.
Clears GameFlags (so the next pass of MainLoop draws the items in the room), reads the room's attribute from RoomAttributes and draws the frame. The entry point at DrawRoomFrame_Room draws the frame of the room in A, which is how FallThroughTrapdoor draws the frame of room 96. The entry for the shape of the room in RoomShapeTable gives the width and height of the floor (written to CurrentRoom_Width and CurrentRoom_Height), the coordinates of the corners of the frame and the lists of the lines to draw between them (see TunnelFrameCoordinates and TunnelFrameLines for the frame of room 96). Each list has a corner to start from, followed by the corners to draw lines to, ending with FF. The list of lists ends with FF.
Input
A The room (at the entry point DrawRoomFrame_Room)
Before After
room-frame-before room-frame-after
The frame of a cave room (room 30):
room-frame-cave
DrawRoomFrame 9BEA XOR A Reset A.
9BEB LD ($5E14),A Update the game flags in GameFlags.
9BEE LD A,($EA91) Fetch the room of the player from PlayerRoom.
This entry point is used by the routine at FallThroughTrapdoor.
DrawRoomFrame_Room 9BF1 LD BC,$A854 Point BC at the room attribute table at RoomAttributes.
9BF4 LD L,A Keep the room in L.
9BF5 LD H,$00 Clear the high byte of the room.
9BF7 ADD HL,HL Multiply HL by 02.
9BF8 ADD HL,BC Add BC to HL to get the entry for the room.
9BF9 LD A,(HL) Fetch the attribute of the room.
9BFA INC HL Move on to the shape of the room.
9BFB LD ($5E1A),A Update the room attribute in CurrentRoom_Attribute.
9BFE EXX Switch to the shadow registers.
9BFF LD HL,$5800 HL'=5800 (the attribute buffer).
9C02 LD BC,$1818 BC'=1818 (the size of the play area).
9C05 LD A,($5E1A) Fetch the room attribute from CurrentRoom_Attribute.
9C08 CALL ClearPlayArea_Row Call ClearPlayArea_Row to fill the play area with the attribute.
9C0B EXX Switch back to the main registers.
9C0C LD L,(HL) Fetch the shape of the room.
9C0D LD H,$00 Clear the high byte of the shape.
9C0F ADD HL,HL Multiply HL by 02.
9C10 LD C,L Keep the shape multiplied by two in BC.
9C11 LD B,H
9C12 ADD HL,HL Multiply HL by 02.
9C13 ADD HL,BC Add BC to HL, to multiply the shape by 06.
9C14 LD BC,$A982 Point BC at the room shape table at RoomShapeTable.
9C17 ADD HL,BC Add BC to HL to get the entry for the shape.
9C18 LD A,(HL) Fetch the width.
9C19 INC HL Move on to the next byte.
9C1A LD ($5E1D),A Update the room width in CurrentRoom_Width.
9C1D LD A,(HL) Fetch the height.
9C1E INC HL Move on to the next byte.
9C1F LD ($5E1E),A Update the room height in CurrentRoom_Height.
9C22 LD E,(HL) Fetch the low byte of the address of the coordinates.
9C23 INC HL Move on to the next byte.
9C24 LD D,(HL) Fetch the high byte of the address of the coordinates.
9C25 INC HL Move on to the next byte.
9C26 LD A,(HL) Fetch the low byte of the address of the lists of lines.
9C27 INC HL Move on to the next byte.
9C28 LD H,(HL) Fetch the high byte of the address of the lists of lines.
9C29 LD L,A Keep the low byte of the address of the lists of lines in L.
9C2A PUSH DE Copy DE into IX, as the address of the coordinates.
9C2B POP IX
Start a list. The corner to start from is found by changing the offsets in the instructions at 9C3D and 9C40.
9C2D PUSH BC Stash BC on the stack.
DrawRoomFrame_List 9C2E POP BC Restore BC from the stack.
9C2F LD A,(HL) Fetch the corner to start from.
9C30 INC HL Move HL on to the next byte.
9C31 CP $FF Return if there are no more lists.
9C33 RET Z
9C34 SLA A Multiply the corner by 02.
9C36 LD ($9C3F),A Write it as the offset in the instruction at 9C3D.
9C39 INC A Increment it.
9C3A LD ($9C42),A Write it as the offset in the instruction at 9C40.
9C3D LD C,(IX+$00) Fetch the X coordinate of the corner.
9C40 LD B,(IX+$00) Fetch the Y coordinate of the corner.
DrawRoomFrame_Line 9C43 PUSH BC Stash the coordinates of the corner on the stack.
9C44 LD A,(HL) Fetch the corner to draw a line to.
9C45 INC HL Move HL on to the next byte.
9C46 CP $FF Jump to DrawRoomFrame_List if this is the end of the list.
9C48 JR Z,DrawRoomFrame_List
9C4A SLA A Multiply the corner by 02.
9C4C LD ($9C55),A Write it as the offset in the instruction at 9C53.
9C4F INC A Increment it.
9C50 LD ($9C58),A Write it as the offset in the instruction at 9C56.
9C53 LD E,(IX+$00) Fetch the X coordinate of the corner.
9C56 LD D,(IX+$00) Fetch the Y coordinate of the corner.
9C59 PUSH HL Stash HL on the stack.
9C5A CALL DrawLine Call DrawLine to draw the line.
9C5D POP HL Restore HL from the stack.
9C5E POP BC Restore the coordinates of the first corner from the stack.
9C5F JR DrawRoomFrame_Line Jump back to DrawRoomFrame_Line to draw the next line of the frame.
Prev: 9BD2 Up: Map Next: 9C61