|  | Routines | 
| Prev: C978 | Up: Map | Next: CB03 | 
| C9CA | LD A,($A045) | Return if generating train in current room | ||
| C9CD | OR A | |||
| C9CE | RET NZ | |||
| C9CF | LD A,($A043) | Decrement enemy room enter counter | ||
| C9D2 | DEC A | |||
| C9D3 | LD ($A043),A | |||
| C9D6 | OR A | Return if coutner has not reached zero | ||
| C9D7 | RET NZ | |||
| C9D8 | LD A,($A044) | Reset counter with the original value | ||
| C9DB | LD ($A043),A | |||
| C9DE | LD HL,$5E72 | Set HL to the base address for enemy status into the enemy configuration table | ||
| C9E1 | LD A,($A092) | Set B to the max number of enemies for the room | ||
| C9E4 | LD B,A | |||
| C9E5 | LD A,(HL) | Check enemy status | ||
| C9E6 | OR A | Jump forward if enemy dead/not visible | ||
| C9E7 | JP Z,$C9F1 | |||
| C9EA | LD DE,$0018 | Point to the next enemy configuration | ||
| C9ED | ADD HL,DE | |||
| C9EE | DJNZ $C9E5 | Jump back until all the enemies slots checked | ||
| C9F0 | RET | |||
| 
try to create a new enemy
 | ||||
| C9F1 | LD DE,$000C | Point HL to the base address for the current slot of enemy configuration | ||
| C9F4 | AND A | |||
| C9F5 | SBC HL,DE | |||
| C9F7 | PUSH HL | Set IX to this base address | ||
| C9F8 | POP IX | |||
| C9FA | CALL $A375 | Set A a pseudo random number | ||
| C9FD | CP $55 | is A less than 85? | ||
| C9FF | JP C,$CA0F | Jump to handle enemy enters from the left | ||
| CA02 | CP $AA | is A less than 170? | ||
| CA04 | JP C,$CA0B | Jump to handle enemy enters from the right | ||
| CA07 | CALL $CAA7 | Handle enemy enters from the top | ||
| CA0A | RET | |||
| CA0B | CALL $CA71 | Handle enemy enters from the right | ||
| CA0E | RET | |||
| CA0F | CALL $CA13 | Handle enemy enters from the left | ||
| CA12 | RET | |||
| 
Handle enemy enters from the left
 | ||||
| CA13 | LD A,($A02C) | Return if no enemies enters from the left | ||
| CA16 | OR A | |||
| CA17 | RET Z | |||
| CA18 | LD A,($A0B6) | Return if x-position of Rex less than 48 | ||
| CA1B | CP $30 | |||
| CA1D | RET C | |||
| CA1E | LD A,$00 | Set x-pixel-position of enemy | ||
| CA20 | LD ($A0AF),A | |||
| CA23 | CALL $A375 | Set A a pseudo random number | ||
| CA26 | CP $20 | Jump back until number generated is between 32 and 168 | ||
| CA28 | JP C,$CA23 | |||
| CA2B | CP $A8 | |||
| CA2D | JP NC,$CA23 | |||
| CA30 | AND $F8 | Change number to be grid 8x8 fixed | ||
| CA32 | LD ($A0B0),A | Set this number to the y-pixel-position for the enemy | ||
| CA35 | CALL $CB03 | Check if enemy can be generated | ||
| CA38 | OR A | Jump back if enemy cannot be generated | ||
| CA39 | JP Z,$CA23 | |||
| CA3C | LD A,$0F | Set x-pixel-position of enemy to 15 | ||
| CA3E | LD ($A0AF),A | |||
| CA41 | CALL $CA49 | Configure new enemy | ||
| CA44 | LD (IX+$02),$00 | Set enemy to face right | ||
| CA48 | RET | |||
| CA49 | LD A,($A088) | Set A and L the type of enemy to generate | ||
| CA4C | LD L,A | |||
| CA4D | BIT 7,A | Jump forward if generate random FOOT MAN bit is not set | ||
| CA4F | JP Z,$CA60 | |||
| 
try to generate random FOOT MAN
 | ||||
| CA52 | AND $7F | Set L the type of enemy to generate | ||
| CA54 | LD L,A | |||
| CA55 | CALL $A388 | Set A a pseudo random number between 0 an 1 | ||
| CA58 | AND $01 | |||
| CA5A | OR A | if random number is 1 then generate FOOT MAN | ||
| CA5B | JP Z,$CA60 | |||
| CA5E | LD L,$00 | Generate FOOT MAN | ||
| CA60 | LD A,L | Set A the new enemy type to create | ||
| CA61 | CALL $CB8B | Configure the new enemy | ||
| CA64 | LD A,($A0AF) | Set x-pixel-position for enemy | ||
| CA67 | LD (IX+$00),A | |||
| CA6A | LD A,($A0B0) | Set y-pixel-position for enemy | ||
| CA6D | LD (IX+$01),A | |||
| CA70 | RET | |||
| 
Handle enemy enters from the right
 | ||||
| CA71 | LD A,($A02D) | Return if enemies doesn't enters from the right | ||
| CA74 | OR A | |||
| CA75 | RET Z | |||
| CA76 | LD A,($A0B6) | Return if x-position of Rex greater than 200 | ||
| CA79 | CP $C8 | |||
| CA7B | RET NC | |||
| CA7C | LD A,$E0 | Set x-position of enemy at A0AF | ||
| CA7E | LD ($A0AF),A | |||
| CA81 | CALL $A375 | Set A a pseudo random number | ||
| CA84 | CP $20 | Jump back until number generated is between 32 and 168 | ||
| CA86 | JP C,$CA81 | |||
| CA89 | CP $A8 | |||
| CA8B | JP NC,$CA81 | |||
| CA8E | AND $F8 | Change number to be grid 8x8 fixed | ||
| CA90 | LD ($A0B0),A | Set this number to the y-pixel-position for the enemy | ||
| CA93 | CALL $CB03 | Check if enemy can be generated | ||
| CA96 | OR A | Jump back if enemy cannot be generated | ||
| CA97 | JP Z,$CA81 | |||
| CA9A | LD A,$E8 | Set x-position of enemy at A0AF | ||
| CA9C | LD ($A0AF),A | |||
| CA9F | CALL $CA49 | Configure the new enemy | ||
| CAA2 | LD (IX+$02),$01 | Set enemy to face left | ||
| CAA6 | RET | |||
| 
Handle enemy enters from the top
 | ||||
| CAA7 | LD A,($A02E) | Return if enemies doesn't enters from the top | ||
| CAAA | OR A | |||
| CAAB | RET Z | |||
| CAAC | LD A,($A0B7) | Return if y-position of Rex is less than 56 | ||
| CAAF | CP $38 | |||
| CAB1 | RET C | |||
| CAB2 | LD A,$18 | Set y-position of enemy | ||
| CAB4 | LD ($A0B0),A | |||
| CAB7 | CALL $A375 | Set A a pseudo random number | ||
| CABA | CP $20 | Jump back until number generated is between 32 and 224 | ||
| CABC | JP C,$CAB7 | |||
| CABF | CP $E0 | |||
| CAC1 | JP NC,$CAB7 | |||
| CAC4 | AND $F8 | Change number to be grid 8x8 fixed | ||
| CAC6 | LD ($A0AF),A | Set this number to the x-pixel-position for the enemy | ||
| CAC9 | CALL $A503 | Computes into HL the address into tile type buffer for the enemy position | ||
| CACC | LD A,(HL) | Set A to the tile type | ||
| CACD | OR A | Jump back and computes another position if tile type is not background | ||
| CACE | JP NZ,$CAB7 | |||
| CAD1 | INC HL | Increase address into tile type buffer | ||
| CAD2 | LD A,(HL) | Set A to the tile type | ||
| CAD3 | OR A | Jump back and computes another position if tile type is not background | ||
| CAD4 | JP NZ,$CAB7 | |||
| CAD7 | INC HL | Increase address into tile type buffer | ||
| CAD8 | LD A,(HL) | Set A to the tile type | ||
| CAD9 | OR A | Jump back and computes another position if tile type is not background | ||
| CADA | JP NZ,$CAB7 | |||
| CADD | LD DE,$001E | Point HL to the next row | ||
| CAE0 | ADD HL,DE | |||
| CAE1 | LD A,(HL) | Set A to the tile type | ||
| CAE2 | OR A | Jump back and computes another position if tile type is not background | ||
| CAE3 | JP NZ,$CAB7 | |||
| CAE6 | INC HL | Increase address into tile type buffer | ||
| CAE7 | LD A,(HL) | Set A to the tile type | ||
| CAE8 | OR A | Jump back and computes another position if tile type is not background | ||
| CAE9 | JP NZ,$CAB7 | |||
| CAEC | LD A,($A0AF) | Set the new x-position for enemy | ||
| CAEF | ADD A,$10 | |||
| CAF1 | LD ($A0AF),A | |||
| CAF4 | XOR A | Set y-position to 0 | ||
| CAF5 | LD ($A0B0),A | |||
| CAF8 | CALL $CA49 | Configure the enemy | ||
| CAFB | LD A,R | Set random facing direction for enemy | ||
| CAFD | AND $FF | |||
| CAFF | LD (IX+$02),A | |||
| CB02 | RET | |||
| Prev: C978 | Up: Map | Next: CB03 |