![]() |
Routines |
| Prev: 38109 | Up: Map | Next: 38214 |
|
Used by the routine at StartGame.
Called when a game starts. For each of the doors from RoomItemEntities onwards, a byte from the ROM (from an address that depends on FRAMES and CounterLow) is used as a random number. If it is less than 112 and the sprite ID of both halves of the door is 1 then they are both changed to 34 or if it is 2 then to 32. Both of those are doors that open and close (see HandlerDoorOpen and HandlerDoorClosed). The doorway is then closed by setting bit 3 of the attribute of both halves (see CloseDoorway).
|
||||
| RandomiseDoors | 38133 | LD A,(24082) | Fetch the counter from CounterLow and keep the low byte of the ROM address in L. | |
| 38136 | LD L,A | |||
| 38137 | LD A,(23672) | Fetch FRAMES. | ||
| 38140 | AND %00001111 | Keep only bits 0-3. | ||
| 38142 | OR %00010000 | Set bit 4. | ||
| 38144 | LD H,A | Keep the high byte of the ROM address in H. | ||
| 38145 | EXX | Switch to the shadow registers. | ||
| 38146 | LD HL,61152 | HL'=61152 (the first half of the first door). | ||
| 38149 | LD DE,61160 | Point DE' at the second half of the first door at RoomItemEntities_Door_1_Second_Half. | ||
| 38152 | LD BC,16 | BC'=0016 (the distance between the doors). | ||
| RandomiseDoors_Loop | 38155 | EXX | Switch to the main registers. | |
| 38156 | LD A,(HL) | Fetch the next random byte from the ROM. | ||
| 38157 | INC HL | Move HL on to the next byte. | ||
| 38158 | EXX | Switch to the shadow registers. | ||
| 38159 | CP 112 | Jump to RandomiseDoors_Next if the byte is 112 or more. | ||
| 38161 | JR NC,RandomiseDoors_Next | |||
| 38163 | LD A,(DE) | Fetch the sprite ID of the second half of the door. | ||
| 38164 | CP (HL) | Jump to RandomiseDoors_Next if it is different to the first half. | ||
| 38165 | JR NZ,RandomiseDoors_Next | |||
| 38167 | CP 1 | Jump to RandomiseDoors_Close if it is 1. | ||
| 38169 | JR Z,RandomiseDoors_Close | |||
| 38171 | CP 2 | Jump to RandomiseDoors_Close_Alternate if it is 2. | ||
| 38173 | JR Z,RandomiseDoors_Close_Alternate | |||
| RandomiseDoors_Next | 38175 | ADD HL,BC | Move HL on to the next door. | |
| 38176 | EX DE,HL | Switch DE and HL. | ||
| 38177 | ADD HL,BC | Move HL on to the next door. | ||
| 38178 | RET C | Return if there are no more doors. | ||
| 38179 | EX DE,HL | Switch DE and HL back again. | ||
| 38180 | JR RandomiseDoors_Loop | Jump back to RandomiseDoors_Loop to carry on with the loop through the doors. | ||
| RandomiseDoors_Close | 38182 | LD A,34 | A=34 (the new sprite ID of the closed door). | |
| RandomiseDoors_Change | 38184 | LD (DE),A | Update the sprite ID of the second half. | |
| 38185 | LD (HL),A | Update the sprite ID of the first half. | ||
| 38186 | PUSH DE | Stash DE on the stack. | ||
| 38187 | INC DE | Move DE on to the attribute of the second half. | ||
| 38188 | INC DE | |||
| 38189 | INC DE | |||
| 38190 | INC DE | |||
| 38191 | INC DE | |||
| 38192 | LD A,(DE) | Fetch the attribute. | ||
| 38193 | OR %00001000 | Set bit 3, to close the doorway. | ||
| 38195 | LD (DE),A | Write it back. | ||
| 38196 | POP DE | Restore DE from the stack. | ||
| 38197 | PUSH HL | Stash HL on the stack. | ||
| 38198 | INC HL | Move HL on to the attribute of the first half. | ||
| 38199 | INC HL | |||
| 38200 | INC HL | |||
| 38201 | INC HL | |||
| 38202 | INC HL | |||
| 38203 | LD A,(HL) | Fetch the attribute. | ||
| 38204 | OR %00001000 | Set bit 3, to close the doorway. | ||
| 38206 | LD (HL),A | Write it back. | ||
| 38207 | POP HL | Restore HL from the stack. | ||
| 38208 | JR RandomiseDoors_Next | Jump back to RandomiseDoors_Next to move on to the next door. | ||
| RandomiseDoors_Close_Alternate | 38210 | LD A,32 | A=32 (the new sprite ID of the closed door). | |
| 38212 | JR RandomiseDoors_Change | Jump to RandomiseDoors_Change to change the door. | ||
| Prev: 38109 | Up: Map | Next: 38214 |