Prev: 6248 Up: Map Next: 626B
6251: The rooms
Every room in the castle: 128 records of varying length packed end to end, the last ending where block_type_tbl begins. There is no index and no terminator. find_screen finds a room by walking the records from the start, comparing each room number with the player's; byte 1 of a record is the distance from itself to the next record, and the walk gives up when it reaches the address of block_type_tbl.
Byte 0 is the room number. The castle is a grid of 16 by 16 squares, and the number is the square's row times 16 plus its column: walking out through the east or west side adds or subtracts 1 in the low four bits only, and north or south adds or subtracts 16 (screen_west to screen_south). Only 128 of the 256 squares are rooms. Byte 1 is the record's length less one. Byte 2 holds the room's ink colour in bits 0 to 2 -- magenta, green, cyan or yellow -- which found_screen makes into bright ink on black paper at $5BAD, and its shape in bits 3 to 7, an index into room_size_tbl.
Next come the room's backgrounds, one byte each, indexes into background_type_tbl: walls, arches, doorways and the other fixed scenery. A byte of $FF ends them. A room with nothing more in it has no $FF and simply ends; 24 rooms are like that.
After the $FF come groups of objects. A group begins with a byte whose bits 3 to 7 are an index into block_type_tbl and whose bits 0 to 2 are the number of copies less one, and carries one position byte per copy. A position byte names a cell in the room's grid of 8 by 8 cells on four levels: bits 0 to 2 the x cell, bits 3 to 5 the y cell and bits 6 and 7 the level. next_fg_obj_sprite turns it into coordinates: x is $48 plus 16 times the x cell, y likewise, and z is the floor height plus 12 times the level, to which the block type can add half a cell in x or y and extra height.
retrieve_screen builds the room as object records, 32 bytes each, from $5C88 upwards, and clears whatever is left up to font. That is room for 36 objects, and six rooms in this table need exactly 36.
location_tbl 6251 DEFB $00,$19,$03 Room $00 (row 0, column 0): square, magenta
6254 DEFB $00,$01,$0C,$FF Backgrounds: arch N, arch E, walls (square room)
6258 DEFB $07,$10,$50,$90,$11,$51,$91,$0A Block x8
6260 DEFB $4A
6261 DEFB $06,$8A,$02,$42,$82,$C8,$C1,$C0 Block x7
6269 DEFB $A8,$C9 Block (type $5B)
The comments give each record's room number, its square in the grid (row, column), its shape and colour, then what it contains. Where the listing's rows do not line up with the records, a comment covers the parts that begin in its row.
Prev: 6248 Up: Map Next: 626B