Prev: D63A Up: Map Next: D67B
D651: Determine whether a warlock should materialize in the room
Used by the routine at D63A.
A warlock can appear in the room:
  • After a certain time, based on a slowly decrementing counter byte at EBB4 along with a pseudo-random adjustment
  • As long as there aren't already 3 creatures in the room
  • On levels 1-7 (based on room numbers in the table at C6A4)
No warlock appears on level 8 (Chambers of Chaos). On level 9 (High Temple of Chaos), DEMONS materialize in rooms instead of warlocks.
D651 LD A,($EAC9) Get the current level text number (1-9) - calculated from lookup table at C6A4
D654 LD B,A Store in B register
There are only 7 warlocks, so we need to do something for levels 8 and 9
D655 CP $08 Are we in the Chambers of Chaos (level 8)?
D657 JP Z,$D6CF If so there's no warlock on this level - jump to the end of this check routine
D65A CP $09 Are we in the High Temple of Chaos (level 9)?
D65C JR Z,$D6A4 If so, jump out and generate a DEMON instead of a WARLOCK
D65E LD A,($EAAA) Game cycle timer
D661 AND $3F Check bits 0-5 (values = 0-63)
D663 JP NZ,$D6CF
Every 64 game cycles, reduce the timer counter for a warlock appearing in the room
D666 LD A,($EBB4) Get warlock appearance timer
D669 DEC A Decrement it
D66A LD ($EBB4),A ...and re-store
D66D LD C,A
D66E CALL $DB06 Run pseudo-random number generator to produce a random number (returned in A register)
D671 CP C Compare it against the warlock appearance timer
D672 JR C,$D6CF If random number < warlock timer, jump out here
D674 LD A,($EBAD) Random number > warlock timer. Get byte 6 of warlock data set
D677 CP $00
D679 JR NZ,$D6CF If this byte isn't 0, there's already a warlock so we can jump out at this point
Prev: D63A Up: Map Next: D67B