Prev: 55511 Up: Map Next: 55602
55527: Place Monsters
Used by the routine at StartGame.
Places the four monsters (type 96, 100, 104 and 108) in random cells of the village that are not solid, in the objects from ObjectTable_Monsters. The cells come from bytes of the ROM, starting from a random place.
Point at the first monster and a random place in the ROM.
PlaceMonsters 55527 CALL IncrementFrameCounter Increase the frame counter, and update the random number generator.
55530 LD IY,48478 Point IY at the first object, and set a counter of four monsters.
55534 LD B,4
55536 LD DE,(48042) Make a random address in the first 4096 bytes of the ROM.
55540 LD A,D
55541 AND 15
55543 LD D,A
Place a monster in a cell that is not solid.
PlaceMonsters_Cell 55544 LD A,(DE) Fetch a column from the ROM.
55545 INC DE
55546 AND 31
55548 LD L,A
55549 LD A,(DE) Fetch a row from the ROM.
55550 INC DE
55551 AND 31
55553 LD H,A
55554 PUSH BC Find the tile of the cell.
55555 PUSH HL
55556 CALL GetMapCell
55559 POP HL
55560 POP BC
55561 DEC A Try another cell if the tile is solid (1 or 2).
55562 CP 2
55564 JR C,PlaceMonsters_Cell
55566 PUSH BC Keep the counter, the address in the ROM and the cell.
55567 PUSH DE
55568 PUSH HL
55569 LD HL,55602 Copy the template for a monster into the object, and move on to the next object.
55572 LD BC,16
55575 PUSH IY
55577 POP DE
55578 ADD IY,BC
55580 LDIR
55582 POP HL Restore the cell, the ROM address and the counter from the stack.
55583 POP DE
55584 POP BC
55585 LD A,B Set the type of the monster from the counter.
55586 ADD A,A
55587 ADD A,A
55588 ADD A,92
55590 LD (IY-16),A
55593 LD (IY-14),L Set the column and the row of the monster.
55596 LD (IY-12),H
55599 DJNZ PlaceMonsters_Cell Loop back until all four monsters have been placed.
55601 RET Return.
Prev: 55511 Up: Map Next: 55602