![]() |
Routines |
| Prev: 55397 | Up: Map | Next: 55511 |
|
Used by the routine at StartGame.
Places the four items that the monsters need (type 4 to 7) in random cells of the village that are not solid, in the objects from ObjectTable_MonsterItems. The cells come from bytes of the ROM, starting from a random place.
|
||||
|
Point at the first item and a random place in the ROM.
|
||||
| PlaceItems | 55438 | CALL IncrementFrameCounter | Increase the frame counter, and update the random number generator. | |
| 55441 | LD IY,48414 | Point IY at the first object, and set a counter of four items. | ||
| 55445 | LD B,4 | |||
| 55447 | LD DE,(48042) | Make a random address in the first 4096 bytes of the ROM. | ||
| 55451 | LD A,D | |||
| 55452 | AND 15 | |||
| 55454 | LD D,A | |||
|
Place an item in a cell that is not solid.
|
||||
| PlaceItems_Cell | 55455 | LD A,(DE) | Fetch a column from the ROM. | |
| 55456 | INC DE | |||
| 55457 | AND 31 | |||
| 55459 | LD L,A | |||
| 55460 | LD A,(DE) | Fetch a row from the ROM. | ||
| 55461 | INC DE | |||
| 55462 | AND 31 | |||
| 55464 | LD H,A | |||
| 55465 | PUSH BC | Find the tile of the cell. | ||
| 55466 | PUSH HL | |||
| 55467 | CALL GetMapCell | |||
| 55470 | POP HL | |||
| 55471 | POP BC | |||
| 55472 | DEC A | Try another cell if the tile is solid (1 or 2). | ||
| 55473 | CP 2 | |||
| 55475 | JR C,PlaceItems_Cell | |||
| 55477 | PUSH BC | Keep the counter, the address in the ROM and the cell. | ||
| 55478 | PUSH DE | |||
| 55479 | PUSH HL | |||
| 55480 | LD HL,55511 | Copy the template for an item into the object, and move on to the next object. | ||
| 55483 | LD BC,16 | |||
| 55486 | PUSH IY | |||
| 55488 | POP DE | |||
| 55489 | ADD IY,BC | |||
| 55491 | LDIR | |||
| 55493 | POP HL | Restore the cell, the ROM address and the counter from the stack. | ||
| 55494 | POP DE | |||
| 55495 | POP BC | |||
| 55496 | LD A,B | Set the type of the item. | ||
| 55497 | ADD A,3 | |||
| 55499 | LD (IY-16),A | |||
| 55502 | LD (IY-14),L | Set the column and the row of the item. | ||
| 55505 | LD (IY-12),H | |||
| 55508 | DJNZ PlaceItems_Cell | Loop back until all four items have been placed. | ||
| 55510 | RET | Return. | ||
| Prev: 55397 | Up: Map | Next: 55511 |