Prev: A900 Up: Map Next: AAF4
AA97: 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 AA97 LD HL,$BAAB Store the starting room table data reference (starting at 21) to *TempTableRoomDataPointer.
AA9A LD ($BAA5),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.
AA9D LD DE,$BCCB Initialise the starting point of the room data for populating the room table data (21).
AAA0 LD HL,$ABD6 Initialise the default room data (DefaultRoomData) starting pointer in HL.
This part of the loop specifically deals with populating TableRoomData.
UnpackAllRooms_Loop AAA3 PUSH HL Stash the default room data pointer on the stack.
AAA4 LD HL,($BAA5) Write the address of where the currently in-focus room table data begins to the room table.
AAA7 LD (HL),E
AAA8 INC HL
AAA9 LD (HL),D
AAAA INC HL Store the position of the next table entry to *TempTableRoomDataPointer.
AAAB LD ($BAA5),HL
AAAE POP HL Restore the default room data pointer from the stack.
Have we finished with everything?
AAAF LD A,(HL) If the terminator character (FF) has been reached jump to SetRealStartingRoomID.
AAB0 CP $FF
AAB2 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 03 bytes of data each, so B is 03 when calling CopyRoomData. How many portholes being copied just depends on when the loop reads a termination character (FF).
AAB5 LD B,$01 Handle copying the room colour scheme.
AAB7 CALL CopyRoomData
AABA LD B,$03 Handle copying the scaffolding data.
AABC CALL CopyRoomData
AABF LD B,$04 Handle copying the doors data.
AAC1 CALL CopyRoomData
AAC4 LD B,$02 Handle copying the ladders data.
AAC6 CALL CopyRoomData
AAC9 LD B,$06 Handle copying the keys and locked doors data.
AACB CALL CopyRoomData
AACE LD B,$03 Handle copying the porthole data.
AAD0 CALL CopyRoomData
AAD3 LD B,$10 Handle copying the pirate data.
AAD5 CALL CopyRoomData
AAD8 LD B,$07 Handle copying the items data.
AADA CALL CopyRoomData
AADD LD B,$04 Handle copying the furniture data.
AADF CALL CopyRoomData
AAE2 LD B,$10 Handle copying the lifts data.
AAE4 CALL CopyRoomData
AAE7 LD B,$06 Handle copying the disappearing floors data.
AAE9 CALL CopyRoomData
AAEC 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 00 just routed the code to UnpackAllRooms, there is no room 00 - so set the "real" starting room ID.
SetRealStartingRoomID AAEE LD A,$01 Write 01 to *CurrentRoom.
AAF0 LD ($5BD3),A
AAF3 RET Return.
Prev: A900 Up: Map Next: AAF4