Prev: 43264 Up: Map Next: 43764
43671: Unpack All Rooms
This is similar to UnpackRoom except that instead of copying a single rooms data from the room data buffers, this routine loops through ALL the rooms - copying the default room data into the room data buffers. Also, at the start of every loop - it writes the room data buffer address which is about to be processed to the room data table as both the table and the room data buffers are completely blank after the game first loads.
Note; this always occurs at the start of every game regardless, the game opens with the default positions for everything held by the defaults but as the player moves around the game and interacts with doors/ keys/ items/ etc, the buffers keep track of what's been collected, and where the pirates were when the player left the room.
When a new game begins, all the rooms are reset to their default states.
UnpackAllRooms 43671 LD HL,47787 Store the starting room table data reference (starting at 21) to *TempTableRoomDataPointer.
43674 LD (47781),HL
The idea here is to point to the room data, store this in the table. Then populate this current room, and then we know what the next address value will be for the following rooms starting point.
43677 LD DE,48331 Initialise the starting point of the room data for populating the room table data (21).
43680 LD HL,43990 Initialise the default room data (DefaultRoomData) starting pointer in HL.
This part of the loop specifically deals with populating TableRoomData.
UnpackAllRooms_Loop 43683 PUSH HL Stash the default room data pointer on the stack.
43684 LD HL,(47781) Write the address of where the currently in-focus room table data begins to the room table.
43687 LD (HL),E
43688 INC HL
43689 LD (HL),D
43690 INC HL Store the position of the next table entry to *TempTableRoomDataPointer.
43691 LD (47781),HL
43694 POP HL Restore the default room data pointer from the stack.
Have we finished with everything?
43695 LD A,(HL) If the terminator character (255) has been reached jump to SetRealStartingRoomID.
43696 CP 255
43698 JP Z,SetRealStartingRoomID
Now move onto actually copying the room data.
Set up counters for copying data from the default state to the room buffer. The counter length relates to the length of the data for each instance of the "thing" being copied (NOT the length of the data being copied). For an example; portholes are 3 bytes of data each, so B is 3 when calling CopyRoomData. How many portholes being copied just depends on when the loop reads a termination character (255).
43701 LD B,1 Handle copying the room colour scheme.
43703 CALL CopyRoomData
43706 LD B,3 Handle copying the scaffolding data.
43708 CALL CopyRoomData
43711 LD B,4 Handle copying the doors data.
43713 CALL CopyRoomData
43716 LD B,2 Handle copying the ladders data.
43718 CALL CopyRoomData
43721 LD B,6 Handle copying the keys and locked doors data.
43723 CALL CopyRoomData
43726 LD B,3 Handle copying the porthole data.
43728 CALL CopyRoomData
43731 LD B,16 Handle copying the pirate data.
43733 CALL CopyRoomData
43736 LD B,7 Handle copying the items data.
43738 CALL CopyRoomData
43741 LD B,4 Handle copying the furniture data.
43743 CALL CopyRoomData
43746 LD B,16 Handle copying the lifts data.
43748 CALL CopyRoomData
43751 LD B,6 Handle copying the disappearing floors data.
43753 CALL CopyRoomData
43756 JR UnpackAllRooms_Loop Loop back around to UnpackAllRooms_Loop, the unpacking is only finished when the terminator character is read at the start.
The room ID of 0 just routed the code to UnpackAllRooms, there is no room 0 - so set the "real" starting room ID.
SetRealStartingRoomID 43758 LD A,1 Write 1 to *CurrentRoom.
43760 LD (23507),A
43763 RET Return.
Prev: 43264 Up: Map Next: 43764