Prev: 24517 Up: Map Next: 24551
24518: Set Room Data Pointer
Used by the routine at PopulateRoomBuffer.
Sets the room data pointer for the current room.
The room data is stored as a series of blocks from Room01, separated by 0 terminators. This routine scans through the data to find the block matching the *CurrentRoom.
FindRoomData 24518 LD A,(24517) D=*CurrentRoom.
24521 LD D,A
24522 LD E,1 E=1 (start searching from room 1).
24524 CP E Return if the current room is 1 (the data pointer already defaults to the first room).
24525 RET Z
Scan through the room data blocks. Each block is terminated by 0 so count terminators to find the Nth room.
24526 LD HL,33706 HL=33706 (start of room data + 1 for no real reason).
FindRoomData_ScanLoop 24529 LD A,(HL) A=*HL.
24530 INC HL Advance the data pointer.
24531 OR A Jump to FindRoomData_FoundTerminator if a 0 terminator was found.
24532 JR Z,FindRoomData_FoundTerminator
24534 JR FindRoomData_ScanLoop Jump to FindRoomData_ScanLoop to keep scanning.
Found a block terminator so check if we've reached the target room.
FindRoomData_FoundTerminator 24536 INC E Increment the room counter in E.
24537 LD A,E Jump to Raise_Table_Error if the room counter has exceeded 17 (maximum number of rooms/room not found).
24538 CP 17
24540 JR NC,Raise_Table_Error
24542 CP D Jump to FindRoomData_Found if the room counter matches the target room number.
24543 JR Z,FindRoomData_Found
24545 JR FindRoomData_ScanLoop Otherwise, jump to FindRoomData_ScanLoop to keep scanning.
The target room was found so store the pointer to its data.
FindRoomData_Found 24547 LD (24515),HL Write HL to *PointerRoomData.
24550 RET Return.
Prev: 24517 Up: Map Next: 24551