Prev: 39378 Up: Map Next: 39475
39413: Draw Ceiling
Used by the routine at Draw_Room.
Draws the ceiling of the room if bit 0 of the frame flags is set, or clears its area if it is not.
The ceiling is made of thirteen tiles of two bytes by 32 lines, which are drawn from left to right starting at x position 24 and y position 16. Each tile is chosen from the table at Ceiling_Tile_Table. The first tile that is used depends on the sum of the room x and the room y, which makes the ceiling look different from room to room, and the next tiles come from the following entries of the table.
Finally the attributes of the area are set (see Set_Area_Attributes). The floor, drawn by Draw_Floor, uses this code too.
Input
DE Frame flags of the room in E
IX Object record of Sabreman
Draw_Ceiling 39413 PUSH DE Stash the frame flags on the stack.
39414 BIT 0,E Test bit 0 of the frame flags (the ceiling).
39416 LD HL,4120 Set the x position to 24 and the y position to 16 (4120).
39419 LD DE,39475 Point at the table of ceiling tiles (Ceiling_Tile_Table).
This entry point is used by the routine at Draw_Floor.
Draw_Ceiling_Check_Present 39422 JP Z,Clear_Wide_Panel Jump to Clear_Wide_Panel if there is no ceiling.
Draw the row of tiles. The same code draws the floor, which jumps to Draw_Ceiling_Check_Present.
Draw_Row_Of_Tiles 39425 LD B,13 Set the number of tiles to 13.
39427 PUSH HL Stash the screen position on the stack.
39428 CALL ScreenAddress Convert the position into a screen address.
39431 LD A,(IX+2) Fetch the room x of Sabreman.
39434 ADD A,(IX+4) Add the room y of Sabreman.
39437 RLCA Double the sum to make an offset into the table of word pointers.
Draw_Ceiling_Tile_Loop 39438 AND %00011110 Keep the offset within the table (sixteen entries).
39440 LD C,A Store the offset in C.
39441 PUSH BC Stash the tile counter and the offset on the stack.
39442 EX DE,HL Exchange the registers so that HL holds the address of the table.
39443 PUSH HL Stash the address of the table on the stack.
39444 LD B,0 Clear the high byte of the offset.
39446 ADD HL,BC Add the offset to the address of the table.
39447 LD A,(HL) Fetch the low byte of the address of the tile.
39448 INC HL Move on to the high byte.
39449 LD H,(HL) Fetch the high byte of the address of the tile.
39450 LD L,A Copy the low byte to L.
39451 EX DE,HL Exchange the registers so that DE holds the address of the tile and HL the screen address.
39452 PUSH HL Stash the screen address on the stack.
39453 CALL Draw_Tile Draw the tile.
39456 POP HL Restore the screen address from the stack.
39457 INC L Move on two cells to the right.
39458 INC L
39459 POP DE Restore the address of the table into DE.
39460 POP BC Restore the tile counter and the offset.
39461 LD A,C Copy the offset to A.
39462 ADD A,2 Move on to the next entry of the table.
39464 DJNZ Draw_Ceiling_Tile_Loop Decrease the tile counter and loop back until all of the tiles are drawn.
39466 POP HL Restore the position of the area.
39467 LD BC,6688 Set the size of the area to 6688.
39470 CALL Set_Area_Attributes Set the attributes of the area.
39473 POP DE Restore the frame flags from the stack.
39474 RET Return.
Prev: 39378 Up: Map Next: 39475