Prev: 5DC0 Up: Map Next: 5E72
5E24: Populate Room Buffer
Fetch the current room number and set up the default tile and attribute data pointers.
PopulateRoomBuffer 5E24 LD A,($5FC5) Load A with *CurrentRoom.
Initialise the room pointer/ default tile set.
5E27 LD HL,$83A9 Write Room01 to *PointerRoomData.
5E2A LD ($5FC3),HL
5E2D LD HL,$9BAA Write TileSet_Default to *PointerActiveTileSet.
5E30 LD ($5FC1),HL
If this is not room 00 look up the correct room data pointer.
5E33 OR A Call FindRoomData if this is not room 00.
5E34 CALL NZ,FindRoomData
Clear the screen buffer at RoomBuffer.
5E37 LD HL,$C000 Clear 17FF bytes from RoomBuffer onwards.
5E3A LD DE,$C001
5E3D LD (HL),$00
5E3F LD BC,$17FF
5E42 LDIR
Initialise drawing state variables.
5E44 LD A,$FF Write FF to *RespawnFlag.
5E46 LD ($5FBB),A
5E49 LD HL,$00FF Write 00FF to *RoomDrawPosition.
5E4C LD ($5FB9),HL
5E4F LD DE,$02C1 DE=02C1.
The main room data parsing loop. Reads a command byte from the room data and dispatches to the appropriate handler based on its value.
5E52 LD HL,($5FC3) Fetch the *PointerRoomData and store it in HL.
PopulateRoomBuffer_ParseByte 5E55 LD A,(HL) Fetch the room data byte from the pointer.
5E56 OR A Jump to Command00_Skip if the room data byte is 00.
5E57 JR Z,Command00_Skip
5E59 CP $01 Jump to Command01_SkipTiles if the room data byte is 01.
5E5B JR Z,Command01_SkipTiles
5E5D CP $02 Jump to Command02_RepeatedTile if the room data byte is 02.
5E5F JR Z,Command02_RepeatedTile
5E61 CP $03 Jump to Command03_FillAttributes if the room data byte is 03.
5E63 JR Z,Command03_FillAttributes
5E65 CP $04 Jump to Command04_SwitchTileSet if the room data byte is 04.
5E67 JR Z,Command04_SwitchTileSet
5E69 CP $08 Jump to Command08Plus_SingleTile if the room data byte is 08 or higher.
5E6B JR NC,Command08Plus_SingleTile
If none of the above matched, trigger an error (with an arbitrary error code).
PopulateRoomBuffer_Error 5E6D RST $08 Run the ERROR_1 routine: RST 08.
5E6E DEFB $04 Error code: 04 ("Out of memory").
Command 00: no-op. Skip this byte and continue parsing.
Command00_Skip 5E6F INC HL Increment the room data pointer by one.
5E70 JR PopulateRoomBuffer_ParseByte Jump to PopulateRoomBuffer_ParseByte.
Prev: 5DC0 Up: Map Next: 5E72