![]() |
Routines |
| Prev: 41629 | Up: Map | Next: 41720 |
|
Used by the routine at InitialisePlayer.
Fills a table of 512 bytes at RoomObjectTable with the objects (see SetUpRoomObjects) which are to be found in the rooms. There are two bytes for each of the 256 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 128 or more then the table byte is zero, which means there is no object. Otherwise the table byte is made up from:
|
||||
| GenerateRoomObjects | 41661 | LD HL,56812 | Point HL at the table of room objects at RoomObjectTable. | |
| 41664 | LD A,(23672) | Fetch the low byte of FRAMES into E. | ||
| 41667 | LD E,A | |||
| 41668 | LD A,(38547) | Fetch the low byte of the game timer from GameTimer. | ||
| 41671 | AND %00011111 | Keep only bits 0-4. | ||
| 41673 | LD D,A | Use it as the high byte of the ROM address in D, so DE points into the ROM. | ||
| 41674 | LD BC,512 | Set the number of bytes in the table in BC to 512. | ||
| GenerateRoomObjects_Loop | 41677 | LD A,(DE) | Fetch a (random) byte from the ROM. | |
| 41678 | INC DE | Move onto the next ROM byte. | ||
| 41679 | CP 128 | Jump to GenerateRoomObjects_Object if the ROM byte is less than 128. | ||
| 41681 | JR C,GenerateRoomObjects_Object | |||
| 41683 | LD (HL),0 | Write 0 to the table, so there is no object here. | ||
| GenerateRoomObjects_Next | 41685 | INC HL | Move onto the next table byte. | |
| GenerateRoomObjects_Count | 41686 | DEC BC | Decrease the byte counter by one. | |
| 41687 | LD A,B | Loop back to GenerateRoomObjects_Loop until all 512 bytes of the table have been done. | ||
| 41688 | OR C | |||
| 41689 | JR NZ,GenerateRoomObjects_Loop | |||
| 41691 | RET | Return. | ||
|
Make the table byte for an object.
|
||||
| GenerateRoomObjects_Object | 41692 | PUSH BC | Stash the byte counter on the stack. | |
| 41693 | LD A,C | Fetch the low byte of the byte counter. | ||
| 41694 | RRCA | Rotate the low byte of the byte counter right twice. | ||
| 41695 | RRCA | |||
| 41696 | AND %11000000 | Keep only bits 6-7. | ||
| 41698 | LD C,A | Stash the position bits in C. | ||
| 41699 | LD A,(38549) | Fetch the random seed from RandomNumber. | ||
| 41702 | AND %00001111 | Keep only bits 0-3. | ||
| 41704 | OR C | Combine the position and the object type. | ||
| 41705 | LD (HL),A | Write the table byte for the object. | ||
| 41706 | INC HL | Move onto the next table byte. | ||
|
Update the random seed.
|
||||
| 41707 | LD A,R | Fetch the Z80 refresh register. | ||
| 41709 | LD C,A | Stash it in C. | ||
| 41710 | LD A,(38549) | Fetch the random seed from RandomNumber. | ||
| 41713 | ADD A,C | Add the refresh register value to the seed. | ||
| 41714 | LD (38549),A | Store the new random seed in RandomNumber. | ||
| 41717 | POP BC | Restore the byte counter from the stack. | ||
| 41718 | JR GenerateRoomObjects_Count | Jump back to GenerateRoomObjects_Count. | ||
| Prev: 41629 | Up: Map | Next: 41720 |