Prev: A29D Up: Map Next: A2F8
A2BD: Generate Room Objects
Used by the routine at InitialisePlayer.
Fills a table of 0200 bytes at RoomObjectTable with the objects (see SetUpRoomObjects) which are to be found in the rooms. There are two bytes for each of the 0100 rooms, so each room can hold up to two objects.
A byte is taken from the ROM (starting at an address made from GameTimer and the frame counter, so it is effectively random) for each byte of the table. If the ROM byte is 80 or more then the table byte is zero, which means there is no object. Otherwise the table byte is made up from:
  • Bits 6-7: which of the room's four positions to use (taken from the byte count)
  • Bits 0-3: the type of object (taken from the random seed at RandomNumber)
This is used when a new game is started.
GenerateRoomObjects A2BD LD HL,$DDEC Point HL at the table of room objects at RoomObjectTable.
A2C0 LD A,($5C78) Fetch the low byte of FRAMES into E.
A2C3 LD E,A
A2C4 LD A,($9693) Fetch the low byte of the game timer from GameTimer.
A2C7 AND %00011111 Keep only bits 0-4.
A2C9 LD D,A Use it as the high byte of the ROM address in D, so DE points into the ROM.
A2CA LD BC,$0200 Set the number of bytes in the table in BC to 0200.
GenerateRoomObjects_Loop A2CD LD A,(DE) Fetch a (random) byte from the ROM.
A2CE INC DE Move onto the next ROM byte.
A2CF CP $80 Jump to GenerateRoomObjects_Object if the ROM byte is less than 80.
A2D1 JR C,GenerateRoomObjects_Object
A2D3 LD (HL),$00 Write 00 to the table, so there is no object here.
GenerateRoomObjects_Next A2D5 INC HL Move onto the next table byte.
GenerateRoomObjects_Count A2D6 DEC BC Decrease the byte counter by one.
A2D7 LD A,B Loop back to GenerateRoomObjects_Loop until all 0200 bytes of the table have been done.
A2D8 OR C
A2D9 JR NZ,GenerateRoomObjects_Loop
A2DB RET Return.
Make the table byte for an object.
GenerateRoomObjects_Object A2DC PUSH BC Stash the byte counter on the stack.
A2DD LD A,C Fetch the low byte of the byte counter.
A2DE RRCA Rotate the low byte of the byte counter right twice.
A2DF RRCA
A2E0 AND %11000000 Keep only bits 6-7.
A2E2 LD C,A Stash the position bits in C.
A2E3 LD A,($9695) Fetch the random seed from RandomNumber.
A2E6 AND %00001111 Keep only bits 0-3.
A2E8 OR C Combine the position and the object type.
A2E9 LD (HL),A Write the table byte for the object.
A2EA INC HL Move onto the next table byte.
Update the random seed.
A2EB LD A,R Fetch the Z80 refresh register.
A2ED LD C,A Stash it in C.
A2EE LD A,($9695) Fetch the random seed from RandomNumber.
A2F1 ADD A,C Add the refresh register value to the seed.
A2F2 LD ($9695),A Store the new random seed in RandomNumber.
A2F5 POP BC Restore the byte counter from the stack.
A2F6 JR GenerateRoomObjects_Count Jump back to GenerateRoomObjects_Count.
Prev: A29D Up: Map Next: A2F8