| Chase H.Q. | Routines |
| Prev: BDFB | Up: Map | Next: C15B |
|
Three cases, chosen by the tunnel visible flag and the in-tunnel flag.
Neither set: no tunnel yet, so the tunnel sound effect is cleared, the two CALLs into draw_tunnel are NOPped out and the routine returns.
In a tunnel but not yet marked visible: adjacent pairs of the centre x-position table are scanned inwards from the near rows, counting the steps until the values converge. That count becomes the tunnel distance, the tunnel visible flag is set to 2 and the code falls through to arm the hooks.
Already visible: the scan is skipped and the hooks are armed straight away.
Arming the hooks means patching a CALL opcode back over the two NOPs, and the far wall mode is set to the in-tunnel flag inverted.
|
||||
| prepare_tunnel | C0E1 | LD A,($C161) | Read 'LD A,x' @ C160 (in draw_tunnel) | |
| C0E4 | AND A | Set flags | ||
| C0E5 | LD A,($C890) | Read 'LD A,x' @ C88F (tunnel related) | ||
| C0E8 | JR NZ,pt_c144 | Jump if tunnel has appeared | ||
|
Tunnel hasn't appeared.
|
||||
| pt_no_tunnel | C0EA | AND A | Set flags | |
| C0EB | JR NZ,pt_yes_a_tunnel | Jump if non-zero | ||
| C0ED | XOR A | Zero tunnel_sfx | ||
| C0EE | LD ($A23B),A | |||
| C0F1 | LD H,A | HL = 0 | ||
| C0F2 | LD L,A | |||
|
Remove draw_tunnel calls.
|
||||
| C0F3 | LD ($8F82),A | 8F82 = NOP (instruction) | ||
| C0F6 | LD ($8F83),HL | 8F83 & 8F84 = NOP (instruction) | ||
| C0F9 | LD ($8FA7),A | 8FA7 = NOP (instruction) | ||
| C0FC | LD ($8FA8),HL | 8FA8 & 8FA9 = NOP (instruction) | ||
| C0FF | RET | Return | ||
|
Tunnel has appeared.
|
||||
| pt_yes_a_tunnel | C100 | LD A,$05 | Set tunnel_sfx to 5. This quietens effects when in the tunnel | |
| C102 | LD ($A23B),A | |||
| C105 | LD HL,$EAF3 | -- somewhere in road height data table | ||
| C108 | LD B,(HL) | BC = wordat(HL); HL -= 4 | ||
| C109 | DEC L | |||
| C10A | LD C,(HL) | |||
| C10B | DEC L | |||
| C10C | DEC L | |||
| C10D | DEC L | |||
| C10E | EXX | Bank | ||
| C10F | LD HL,$EAF1 | -- somewhere in road height data table | ||
| C112 | LD D,(HL) | DE = wordat(HL); HL -= 4 | ||
| C113 | DEC L | |||
| C114 | LD E,(HL) | |||
| C115 | DEC L | |||
| C116 | DEC L | |||
| C117 | DEC L | |||
| pt_tunnel_loop | C118 | EXX | Bank | |
| C119 | LD D,(HL) | DE = wordat(HL); HL-- | ||
| C11A | DEC L | |||
| C11B | LD E,(HL) | |||
| C11C | PUSH DE | Stack DE | ||
| C11D | DEC L | HL -= 3 | ||
| C11E | DEC L | |||
| C11F | DEC L | |||
| C120 | EX DE,HL | |||
| C121 | SBC HL,BC | HL -= BC | ||
| C123 | POP BC | Unstack | ||
| C124 | JR C,pt_c139 | Jump if HL < BC | ||
| C126 | EX DE,HL | |||
| C127 | EXX | Bank | ||
| C128 | LD B,(HL) | BC = wordat(HL); HL -= 4 | ||
| C129 | DEC L | |||
| C12A | LD C,(HL) | |||
| C12B | DEC L | |||
| C12C | DEC L | |||
| C12D | DEC L | |||
| C12E | EX DE,HL | Swap | ||
| C12F | SBC HL,BC | HL -= BC | ||
| C131 | JR C,pt_c139 | Jump if HL < BC | ||
| C133 | EX DE,HL | Swap | ||
| C134 | LD D,B | DE = BC | ||
| C135 | LD E,C | |||
| C136 | DEC A | A-- | ||
| C137 | JR NZ,pt_tunnel_loop | Loop to tunnel_loop | ||
| pt_c139 | C139 | CPL | A = 9 - A | |
| C13A | ADD A,$0A | |||
| C13C | LD ($C15E),A | Self modify 'CP x' @ C15D [15 when tunnel is small, 6 when fills screen] | ||
| C13F | LD A,$02 | A = 2 | ||
| C141 | LD ($C161),A | Self modify 'LD A,x' @ C160 (in draw_tunnel below) | ||
| pt_c144 | C144 | XOR $01 | A = 3 | |
| C146 | LD ($C2B9),A | Self modify 'LD A,x' @ C2B8 | ||
| C149 | LD HL,$C15B | Load address of draw_tunnel | ||
| C14C | LD A,$CD | Load opcode of 'CALL' | ||
| C14E | LD ($8F82),A | Write CALL draw_tunnel to 8F82 | ||
| C151 | LD ($8F83),HL | |||
| C154 | LD ($8FA7),A | Write CALL draw_tunnel to 8FA7 | ||
| C157 | LD ($8FA8),HL | |||
| C15A | RET | Return | ||
| Prev: BDFB | Up: Map | Next: C15B |