Prev: 43671 Up: Map Next: 43844
43764: Unpack Room
This is similar to UnpackAllRooms, however instead of copying ALL the room data from the default room data into the rooms data buffer, this routine copies a single room from the room data buffers into the active room buffer. The reason for this is that 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 so when they're revisited, they can then retain those changes.
In TableRoomData the pointers to the room data are stored backwards from 22-1.
UnpackRoom 43764 LD A,(23508) Take 22-*TempCurrentRoomID then multiply by 2 (as it's an address we fetch, so is 16 bit) finally add TableRoomData to point to the correct room buffer data address in the room data table for the current room and store the pointer in HL.
43767 LD E,A
43768 LD A,22
43770 SUB E
43771 LD E,A
43772 SLA E
43774 LD D,0
43776 LD HL,47785
43779 ADD HL,DE
43780 LD E,(HL) Fetch the room buffer data address for the requested room and store it in DE.
43781 INC HL
43782 LD D,(HL)
43783 INC HL Does nothing, HL is overwritten immediately below.
Move the room buffer data address pointer to the room data itself (the first 8 bytes are colour data). There's no need to copy the colours again, as they don't vary between each game.
43784 LD HL,8 DE+=0008 (using the stack).
43787 ADD HL,DE
43788 PUSH HL
43789 POP DE
Now move onto actually copying the room data.
43790 LD HL,47831 HL=BufferCurrentRoomData.
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).
43793 LD B,3 Handle copying the scaffolding data.
43795 CALL CopyRoomData
43798 LD B,4 Handle copying the doors data.
43800 CALL CopyRoomData
43803 LD B,2 Handle copying the ladders data.
43805 CALL CopyRoomData
43808 LD B,6 Handle copying the keys and locked doors data.
43810 CALL CopyRoomData
43813 LD B,3 Handle copying the porthole data.
43815 CALL CopyRoomData
43818 LD B,16 Handle copying the pirate data.
43820 CALL CopyRoomData
43823 LD B,7 Handle copying the items data.
43825 CALL CopyRoomData
43828 LD B,4 Handle copying the furniture data.
43830 CALL CopyRoomData
43833 LD B,16 Handle copying the lifts data.
43835 CALL CopyRoomData
43838 LD B,6 Handle copying the disappearing floors data.
43840 CALL CopyRoomData
43843 RET Return.
Prev: 43671 Up: Map Next: 43844