Prev: 83CA Up: Map Next: 845F
83EA: Put a new monster into the room
Used by the routine at UPDATE_KNIGHT.
Monsters are not placed once and left. Called once a frame from PLAYER_TICK: entering a room names it in $5E26 and starts a 32-frame countdown at $5E27; when that expires a creature is dropped into the room, and after that one more on any frame the refresh register's low nibble is zero -- which is why standing still in one place does not make you safe.
It looks for a free slot among only the first three of the eight monster records, and gives up if all three are taken. Those three are also the ones INERT_SPRITE bothers to burn time for, so the spawning slots and the timed slots are the same three.
A new monster is a straight sixteen-byte copy of a template at MONSTER_TEMPLATE -- one LDIR, and the record is complete.
SPAWN_MONSTER_INTO_ROOM 83EA LD A,($5E26) Only in the room the spawner is watching.
83ED LD C,A
83EE LD A,($EA91)
83F1 CP C
83F2 JR NZ,SPAWN_MONSTER_INTO_ROOM_3 Wrong room: nothing to do.
83F4 LD HL,$5E27 The countdown to the next one.
83F7 LD A,(HL)
83F8 AND A
83F9 JR Z,SPAWN_MONSTER_INTO_ROOM_4
83FB DEC (HL) Not yet.
83FC RET NZ
SPAWN_MONSTER_INTO_ROOM_0 83FD LD HL,$EE60 Three slots, sixteen bytes apart.
8400 LD DE,$0010
8403 LD B,$03
SPAWN_MONSTER_INTO_ROOM_1 8405 LD A,(HL) A zero sprite means the slot is free.
8406 AND A
8407 JR Z,SPAWN_MONSTER_INTO_ROOM_2
8409 ADD HL,DE
840A DJNZ SPAWN_MONSTER_INTO_ROOM_1
840C RET
SPAWN_MONSTER_INTO_ROOM_2 840D EX DE,HL
840E LD HL,MONSTER_TEMPLATE The template.
8411 LD BC,$0010
8414 PUSH DE
8415 LDIR Sixteen bytes, and the monster exists.
8417 POP HL
8418 PUSH HL
8419 INC HL
841A LD A,($EA91)
841D LD (HL),A
841E INC HL
841F PUSH HL
8420 LD HL,SPAWN_TYPES
8423 LD A,($5C78)
8426 AND $0F
8428 LD E,A
8429 LD D,$00
842B ADD HL,DE
842C LD A,(HL)
842D POP HL
842E LD (HL),A
842F LD DE,($5E1D)
8433 LD B,E
8434 CALL RANDOM_POSITION
8437 LD (HL),A
8438 LD B,D
8439 CALL RANDOM_POSITION
843C LD (HL),A
843D POP DE
843E PUSH IX
8440 LD IX,$0000
8444 ADD IX,DE
8446 CALL RANDOM_VELOCITY
8449 CALL DRAW_THING
844C POP IX
844E RET
SPAWN_MONSTER_INTO_ROOM_3 844F LD ($5E26),A
8452 LD A,$20
8454 LD ($5E27),A
8457 RET
SPAWN_MONSTER_INTO_ROOM_4 8458 LD A,R
845A AND $0F
845C RET NZ
845D JR SPAWN_MONSTER_INTO_ROOM_0
Prev: 83CA Up: Map Next: 845F