Prev: B063 Up: Map Next: B4CC
B318: Routine at B318
Used by the routines at main_loop and cpu_driver.
main_loop_24 B318 LD HL,($A24A) If speed > 0 jump main_loop_24_0
B31B LD A,H
B31C OR L
B31D JR NZ,main_loop_24_0
B31F LD ($B3DC),A Self modify 'LD A' @ B3DB to load A
B322 LD ($A23E),A off_road = A
main_loop_24_0 B325 LD A,$00 [this seems to be a crashed flag]
B327 AND A Set flags
B328 JR Z,main_loop_24_7
B32A LD ($A24D),A cornering = A
B32D PUSH HL
B32E LD BC,$0000 BC = <self modified>
B331 SBC HL,BC HL -= BC
B333 POP HL
B334 JR C,main_loop_24_1 Jump to main_loop_24_1 if HL < BC
B336 LD D,H D = H
B337 LD A,L A = L
B338 SRL D D >>= 1
B33A RR A
B33C SRL A A >>= 1
B33E OR $03 OR 3
B340 LD E,A E = A
B341 SBC HL,DE HL -= DE
B343 JR Z,main_loop_24_1 equal
B345 LD A,$02 A = 2
B347 JR NC,main_loop_24_2 HL > DE
main_loop_24_1 B349 XOR A Clear crashed flag
B34A LD ($B326),A
B34D INC A A++
B34E JR main_loop_24_3
main_loop_24_2 B350 LD ($A24A),HL ($A24A) = HL
main_loop_24_3 B353 LD ($A250),A turn_speed = A
B356 LD HL,$0000 HL = $0000
B359 LD D,H D = H
B35A LD E,L E = L
B35B SRL D D >>= 1
B35D RR E RR E
B35F SRL E E >>= 1
B361 SRL E E >>= 1
B363 SRL E E >>= 1
B365 SBC HL,DE HL -= DE
B367 LD ($B357),HL Self modify 'LD HL,$xxxx' @ B356
B36A EX DE,HL
B36B LD HL,($A26C) HL = road_pos
B36E LD C,$00 C = 0
B370 LD A,C A = C
B371 AND $01 AND 1
B373 LD ($A251),A flip = A
B376 DEC C C--
B377 JR Z,main_loop_24_4
B379 DEC C C--
B37A JR Z,main_loop_24_5
B37C ADD HL,DE HL += DE
B37D JR main_loop_24_5
main_loop_24_4 B37F SBC HL,DE HL -= DE
main_loop_24_5 B381 LD ($A26C),HL road_pos = HL
B384 LD A,$00 A = $00
B386 AND A Set flags
B387 JR Z,main_loop_24_6
B389 DEC A A--
B38A LD ($B385),A *$B385 = A
B38D LD A,$00 A = $00
main_loop_24_6 B38F LD ($B3DC),A *$B3DC = A
main_loop_24_7 B392 LD HL,($A26C) HL = road_pos
B395 LD DE,$0048 DE = $0048
B398 LD A,H A = H
B399 AND A Set flags
B39A JP M,main_loop_24_9
B39D JR NZ,main_loop_24_8
B39F LD A,L A = L
B3A0 SUB E A -= E
B3A1 JR C,main_loop_24_9
main_loop_24_8 B3A3 LD DE,$01D8 DE = $01D8
B3A6 LD A,H A = H
B3A7 CP D
B3A8 JR C,main_loop_24_10
B3AA JR NZ,main_loop_24_9
B3AC LD A,L A = L
B3AD SUB E A -= E
B3AE JR C,main_loop_24_10
main_loop_24_9 B3B0 EX DE,HL
main_loop_24_10 B3B1 LD ($A26C),HL road_pos = HL
B3B4 LD A,($A24D) A = cornering | smoke
B3B7 LD HL,$A24F
B3BA OR (HL)
B3BB LD BC,$0105 Call start_sfx with cornering noise
B3BE CALL NZ,start_sfx
B3C1 LD A,($A230) Jump if perp_caught_stage > 0
B3C4 AND A
B3C5 JR Z,main_loop_24_12
B3C7 DEC A A--
B3C8 JR Z,main_loop_24_12
B3CA CP $02 CP $02
B3CC JR C,main_loop_24_11
B3CE LD A,$02 A = $02
main_loop_24_11 B3D0 LD ($A250),A turn_speed = A
B3D3 LD A,$01 flip = 1
B3D5 LD ($A251),A
main_loop_24_12 B3D8 CALL sub_b549 Draw debris?
B3DB LD A,$00 A = $00
B3DD AND A Set flags
B3DE JR Z,main_loop_24_15
B3E0 LD C,A C = A
B3E1 RLCA
B3E2 ADD A,C A += C + $18
B3E3 ADD A,$18
B3E5 LD C,A C = A
B3E6 LD A,($A250) A = turn_speed
B3E9 CP $02 CP 2
B3EB JR C,main_loop_24_14
B3ED LD A,($A251) A = flip
B3F0 AND A Set flags
B3F1 JR Z,main_loop_24_13
B3F3 INC C C++
main_loop_24_13 B3F4 INC C C++
main_loop_24_14 B3F5 EXX
B3F6 LD A,($A234) B = counter_A & 1
B3F9 AND $01
B3FB LD B,A
B3FC RLCA
B3FD LD C,A C = A
B3FE EXX
B3FF LD A,C A = C
B400 CALL sub_b67c_2
B403 XOR A off_road = 0
B404 LD ($A23E),A
main_loop_24_15 B407 CALL main_loop_24_19
B40A LD B,$00 B = $00
B40C LD A,($A23E) A = off_road
B40F DEC A A--
B410 JR NZ,main_loop_24_16
B412 LD A,($A236) B = (counter_C & 1) * 3
B415 AND $01
B417 LD B,A
B418 ADD A,A
B419 ADD A,B
B41A LD B,A
main_loop_24_16 B41B LD A,($A250) A = turn_speed
B41E CALL draw_car
B421 LD A,($A228) A = var_a228
B424 AND A Set flags
B425 JR Z,main_loop_24_17
B427 XOR A A = 0
B428 LD BC,$0102 BC = $0102
B42B CALL sub_b67c
main_loop_24_17 B42E LD A,($A234) B = counter_A
B431 LD B,A
B432 LD HL,$A24D Jump if cornering
B435 LD A,(HL)
B436 AND A
B437 JR NZ,main_loop_24_18
B439 LD A,($A236) A = counter_C
B43C LD B,A B = A
B43D INC HL HL++
B43E LD A,(HL) A = *HL++
B43F INC HL
B440 OR (HL) A |= *HL
B441 JR NZ,main_loop_24_18
B443 LD A,($A23E) A = off_road
B446 CP $02 Return if not fully off-road
B448 RET NZ
main_loop_24_18 B449 XOR A A = 0
B44A EX AF,AF'
B44B LD A,B A = B
B44C PUSH AF
B44D CALL draw_smoke Call draw_smoke (seems to be the right side)
B450 LD A,$01 A = $01
B452 EX AF,AF'
B453 POP AF
B454 JP draw_smoke Exit via draw_smoke
main_loop_24_19 B457 LD A,($A22F) A = var_a22f
B45A AND A Set flags
B45B RET Z Return if zero
B45C DEC A A--
B45D JR Z,main_loop_24_20
B45F EXX
B460 LD B,A B = A
B461 LD C,$00 C = 0
B463 EXX
B464 LD A,($A250) A = turn_speed
B467 CP $02 CP 2
B469 LD A,$24 A = $24
B46B JP NZ,sub_b67c_2
B46E LD A,($A251) A = flip + $25
B471 ADD A,$25
B473 JP sub_b67c_2 Exit via sub_b67c_2
main_loop_24_20 B476 LD C,$00 C = 0
B478 LD A,$00 A = 0
B47A DEC A A--
B47B LD ($B479),A *$B479 = A
B47E JR NZ,main_loop_24_22
B480 LD B,$02 B = 2
B482 INC C C++
B483 LD A,C A = C
B484 CP $04 CP 4
B486 JR NC,main_loop_24_21
B488 INC A A++
B489 LD C,A C = A
B48A CP $02 CP 2
B48C JR NZ,main_loop_24_21
B48E INC B B++
main_loop_24_21 B48F LD A,B A = B
B490 LD ($B479),A Self modify 'LD A' @ B478 to load A
main_loop_24_22 B493 LD A,C A = C
B494 LD ($B477),A *$B477 = A
B497 CP $07 CP 7
B499 JR C,main_loop_24_23
B49B XOR A var_a22f = 0
B49C LD ($A22F),A
B49F RET Return
main_loop_24_23 B4A0 LD A,($A250) A = turn_speed
B4A3 CP $02 CP 2
B4A5 LD A,$06 A = 6
B4A7 JR NZ,main_loop_24_24
B4A9 LD A,($A251) A = (A << 3) - flip + 13
B4AC LD B,A
B4AD RLCA
B4AE RLCA
B4AF RLCA
B4B0 SUB B
B4B1 ADD A,$0D
main_loop_24_24 B4B3 ADD A,C A += C
B4B4 PUSH AF
B4B5 CALL sub_b67c_1
B4B8 POP AF
B4B9 LD C,A C = A
B4BA LD A,($B477) A = *$B477
B4BD CP $04 Jump to main_loop_24_25 if A >= 4
B4BF JR NC,main_loop_24_25
B4C1 INC C C++
B4C2 LD A,C A = C
B4C3 JP sub_b67c_1 Exit via sub_b67c_1
main_loop_24_25 B4C6 LD A,$01 var_a228 = 1
B4C8 LD ($A228),A
B4CB RET Return
Prev: B063 Up: Map Next: B4CC