![]() |
Routines |
| Prev: D865 | Up: Map | Next: D8D7 |
|
Used by the routine at StartGame.
Places the four items that the monsters need (type 04 to 07) 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 | D88E | CALL IncrementFrameCounter | Increase the frame counter, and update the random number generator. | |
| D891 | LD IY,$BD1E | Point IY at the first object, and set a counter of four items. | ||
| D895 | LD B,$04 | |||
| D897 | LD DE,($BBAA) | Make a random address in the first 1000 bytes of the ROM. | ||
| D89B | LD A,D | |||
| D89C | AND $0F | |||
| D89E | LD D,A | |||
|
Place an item in a cell that is not solid.
|
||||
| PlaceItems_Cell | D89F | LD A,(DE) | Fetch a column from the ROM. | |
| D8A0 | INC DE | |||
| D8A1 | AND $1F | |||
| D8A3 | LD L,A | |||
| D8A4 | LD A,(DE) | Fetch a row from the ROM. | ||
| D8A5 | INC DE | |||
| D8A6 | AND $1F | |||
| D8A8 | LD H,A | |||
| D8A9 | PUSH BC | Find the tile of the cell. | ||
| D8AA | PUSH HL | |||
| D8AB | CALL GetMapCell | |||
| D8AE | POP HL | |||
| D8AF | POP BC | |||
| D8B0 | DEC A | Try another cell if the tile is solid (01 or 02). | ||
| D8B1 | CP $02 | |||
| D8B3 | JR C,PlaceItems_Cell | |||
| D8B5 | PUSH BC | Keep the counter, the address in the ROM and the cell. | ||
| D8B6 | PUSH DE | |||
| D8B7 | PUSH HL | |||
| D8B8 | LD HL,$D8D7 | Copy the template for an item into the object, and move on to the next object. | ||
| D8BB | LD BC,$0010 | |||
| D8BE | PUSH IY | |||
| D8C0 | POP DE | |||
| D8C1 | ADD IY,BC | |||
| D8C3 | LDIR | |||
| D8C5 | POP HL | Restore the cell, the ROM address and the counter from the stack. | ||
| D8C6 | POP DE | |||
| D8C7 | POP BC | |||
| D8C8 | LD A,B | Set the type of the item. | ||
| D8C9 | ADD A,$03 | |||
| D8CB | LD (IY-$10),A | |||
| D8CE | LD (IY-$0E),L | Set the column and the row of the item. | ||
| D8D1 | LD (IY-$0C),H | |||
| D8D4 | DJNZ PlaceItems_Cell | Loop back until all four items have been placed. | ||
| D8D6 | RET | Return. | ||
| Prev: D865 | Up: Map | Next: D8D7 |