Prev: B063 Up: Map Next: B4CC
B318: Animates the hero car.
Used by the routines at main_loop and cpu_driver.
animate_hero_car B318 LD HL,($A24A) Jump to ahc_check_crashed if speed > 0
B31B LD A,H
B31C OR L
B31D JR NZ,ahc_check_crashed
A is zero here.
B31F LD ($B3DC),A Self modify 'LD A' @ B3DB (below) to load zero
B322 LD ($A23E),A off_road = 0
ahc_check_crashed B325 LD A,$00 A = <self modified> -- crashed flag set by cc_new_crash
B327 AND A Jump if not crashed
B328 JR Z,ahc_not_crashed
Crashed. A is non-zero here.
ahc_crashed B32A LD ($A24D),A cornering = A (which is non-zero here)
B32D PUSH HL Preserve speed
B32E LD BC,$0000 BC = <self modified> -- set when crashed by cc_a4f2
B331 SBC HL,BC Speed minus whatever BC holds?
B333 POP HL Restore speed
B334 JR C,ahc_speed_less_or_eq Jump to ahc_speed_less_or_eq if speed < ?
ahc_speed_greater B336 LD D,H Divide speed by four (D becomes zero since game max speed is 511)
B337 LD A,L
B338 SRL D
B33A RR A
B33C SRL A
B33E OR $03 A |= 3 -- perhaps rounding up
B340 LD E,A E = A
B341 SBC HL,DE HL -= DE -- overall expr is new_speed = (speed - ((speed / 4) | 3))
B343 JR Z,ahc_speed_less_or_eq Jump to ahc_speed_less_or_eq if equal (to zero?)
B345 LD A,$02 Turn speed = 2 (fastest)
B347 JR NC,ahc_assign_speed Jump to ahc_assign_speed if HL > DE
Otherwise HL < DE.
ahc_speed_less_or_eq B349 XOR A Clear crashed flag
B34A LD ($B326),A
B34D INC A Turn speed = 1 (middle)
B34E JR ahc_assign_turn_speed Jump to set turn speed
ahc_assign_speed B350 LD ($A24A),HL Set speed to HL
ahc_assign_turn_speed B353 LD ($A250),A Set turn_speed to A -- could be 0, 1 or 2
This value is set by cc_a4e3, then decremented by 1/16 each time we pass here.
B356 LD HL,$0000 HL = <self modified below>
Divide HL by 16.
B359 LD D,H DE = HL
B35A LD E,L
B35B SRL D DE / 2 -- after this it all fits into E
B35D RR E
B35F SRL E Divide E by 8
B361 SRL E
B363 SRL E
B365 SBC HL,DE HL -= DE -- i.e. original HL minus HL/16
B367 LD ($B357),HL Self modify 'LD HL,$xxxx' @ B356 above
B36A EX DE,HL
B36B LD HL,($A26C) Load road_pos
B36E LD C,$00 Load flip_flag, self modified by A4C0 in check_collisions
B370 LD A,C flip_car = (flip_flag & 1)
B371 AND $01
B373 LD ($A251),A
B376 DEC C Jump if flip_flag is 1
B377 JR Z,ahc_reduce_road_pos
B379 DEC C Jump if flip_flag is 2 -- is this ever taken?
B37A JR Z,ahc_assign_road_pos
Flip flag was zero?
ahc_increase_road_pos B37C ADD HL,DE Increment road position by DE
B37D JR ahc_assign_road_pos Jump to set road_pos
ahc_reduce_road_pos B37F SBC HL,DE Decrement road position by DE
ahc_assign_road_pos B381 LD ($A26C),HL Set road_pos to HL
Decrement this counter.
B384 LD A,$00 Set to 5 on collisions (by A4C7, and decremented below)
B386 AND A Jump if zero
B387 JR Z,animate_hero_car_0
B389 DEC A Decrement
B38A LD ($B385),A Self modify 'LD A,x' @ B384 (above) to x = A
B38D LD A,$00 A = <self modified> -- gets set to (flip flag + 1)
animate_hero_car_0 B38F LD ($B3DC),A *$B3DC = A (below)
Arrive here if not crashed.
ahc_not_crashed B392 LD HL,($A26C) Load road_pos
B395 LD DE,$0048 DE = 72
B398 LD A,H A = H
B399 AND A Set flags
B39A JP M,animate_hero_car_2 Jump if top bit is set?
B39D JR NZ,animate_hero_car_1 Jump if non-zero
Otherwise it was zero.
B39F LD A,L A = L
B3A0 SUB E A -= E
B3A1 JR C,animate_hero_car_2 Jump if E > L
animate_hero_car_1 B3A3 LD DE,$01D8 DE = $01D8
B3A6 LD A,H A = H
B3A7 CP D
B3A8 JR C,ahc_assign_road_pos_2 Jump if D > H
B3AA JR NZ,animate_hero_car_2
B3AC LD A,L A = L
B3AD SUB E A -= E
B3AE JR C,ahc_assign_road_pos_2 Jump if E > L
animate_hero_car_2 B3B0 EX DE,HL
ahc_assign_road_pos_2 B3B1 LD ($A26C),HL Set road_pos to HL
B3B4 LD A,($A24D) A = cornering | smoke
B3B7 LD HL,$A24F
B3BA OR (HL)
B3BB LD BC,$0105 Effect 1 (cornering squeal), Priority 5
B3BE CALL NZ,start_sfx Call start_sfx if cornering or smoke
B3C1 LD A,($A230) Jump if perp_caught_phase == 0
B3C4 AND A
B3C5 JR Z,ahc_debris
B3C7 DEC A Jump if perp_caught_phase is 1 (starts the pull over sequence)
B3C8 JR Z,ahc_debris
New turn speed = MIN(A,2)
B3CA CP $02 Jump if A < 2
B3CC JR C,animate_hero_car_3
B3CE LD A,$02 Else A = 2
animate_hero_car_3 B3D0 LD ($A250),A turn_speed = A
B3D3 LD A,$01 flip_car = 1
B3D5 LD ($A251),A
ahc_debris B3D8 CALL draw_debris Draw debris
B3DB LD A,$00 A = <self modified> -- flip flag + 1
B3DD AND A Jump if zero (not flipped?)
B3DE JR Z,animate_hero_car_6
B3E0 LD C,A C = A
B3E1 RLCA
B3E2 ADD A,C A += C + 24
B3E3 ADD A,$18
B3E5 LD C,A C = A
B3E6 LD A,($A250) Load turn_speed
B3E9 CP $02 Jump if < 2
B3EB JR C,animate_hero_car_5
turn_speed is 2.
B3ED LD A,($A251) Load flip_car
B3F0 AND A Jump if zero
B3F1 JR Z,animate_hero_car_4
B3F3 INC C 2 -> 3
animate_hero_car_4 B3F4 INC C 2/3 -> 3/4
animate_hero_car_5 B3F5 EXX Bank/unbank
B3F6 LD A,($A234) B = counter_A & 1 -- animation counter
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 draw_crash Draw crash
B403 XOR A off_road = 0
B404 LD ($A23E),A
animate_hero_car_6 B407 CALL ahc_check_hand_flag Call ahc_check_hand_flag
Make the car bounce up and down when it goes off-road.
B40A LD B,$00 Default bounce of zero to pass to draw_car. It should be either 0 or 3.
B40C LD A,($A23E) Add the bounce only when one wheel is off-road (if off_road == 1)
B40F DEC A
B410 JR NZ,ahc_draw_car
B412 LD A,($A236) New bounce = (counter_C & 1) * 3 -- half rate counter 0/1/2/3
B415 AND $01
B417 LD B,A
B418 ADD A,A
B419 ADD A,B
B41A LD B,A
ahc_draw_car B41B LD A,($A250) Load turn_speed
B41E CALL draw_car Call draw_car
B421 LD A,($A228) Jump if cherry_light is zero
B424 AND A
B425 JR Z,ahc_draw_smoke
Draw the cherry light.
B427 XOR A A = 0
B428 LD BC,$0102 BC = $0102 -- size?
B42B CALL draw_cherry Call draw_cherry
Check to see if smoke needs drawing.
ahc_draw_smoke B42E LD A,($A234) B = counter_A (0/1/2/3)
B431 LD B,A
B432 LD HL,$A24D Jump if cornering
B435 LD A,(HL)
B436 AND A
B437 JR NZ,ahc_do_draw_smoke
B439 LD A,($A236) A = counter_C -- half rate counter 0/1/2/3
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,ahc_do_draw_smoke
B443 LD A,($A23E) Load off_road
B446 CP $02 Return if not fully off-road
B448 RET NZ
Draw the smoke.
ahc_do_draw_smoke B449 XOR A A' = 0
B44A EX AF,AF'
B44B LD A,B A = B -- smoke anim index
B44C PUSH AF preserve
B44D CALL draw_smoke Call draw_smoke - for the right hand side
B450 LD A,$01 A' = 1
B452 EX AF,AF'
B453 POP AF restore smoke anim index
B454 JP draw_smoke Exit via draw_smoke - for the left hand side
ahc_check_hand_flag B457 LD A,($A22F) Return if hand_flag is zero
B45A AND A
B45B RET Z
Start the animation.
ahc_hand_flag_non_zero B45C DEC A Jump if hand_flag is one
B45D JR Z,ahc_hand_flag_one
Show the "stop" hand.
ahc_hand_flag_gt_one B45F EXX Bank
B460 LD B,A BC = A
B461 LD C,$00
B463 EXX Unbank
Avoid the hand animation if turning hard?
B464 LD A,($A250) Is turn_speed 2? (turn hard)
B467 CP $02
B469 LD A,$24 A = 36
B46B JP NZ,draw_crash Exit via draw_crash if turn_speed != 2
Otherwise turn_speed is 2 (turn hard).
B46E LD A,($A251) A = flip_car + 37
B471 ADD A,$25
B473 JP draw_crash Exit via draw_crash
Start the animation.
ahc_hand_flag_one B476 LD C,$00 C = <self modified>
B478 LD A,$00 A = <self modified> [could be animation frame?] -- gets set to 2
B47A DEC A A--
B47B LD ($B479),A Self modify 'LD A' @ B478 (above) to load A
B47E JR NZ,ahc_b493
B480 LD B,$02 B = 2
B482 INC C C++
B483 LD A,C A = C
B484 CP $04 Jump if >= 4
B486 JR NC,ahc_b48f
B488 INC A A++
B489 LD C,A C = A
B48A CP $02 Jump if != 2
B48C JR NZ,ahc_b48f
B48E INC B B++
ahc_b48f B48F LD A,B A = B
B490 LD ($B479),A Self modify 'LD A' @ B478 (above) to load A
ahc_b493 B493 LD A,C A = C
B494 LD ($B477),A Self modify 'LD C' @ ahc_hand_flag_one (above) to load A
B497 CP $07 Jump if >= 7
B499 JR C,animate_hero_car_7
B49B XOR A hand_flag = 0
B49C LD ($A22F),A
B49F RET Return
animate_hero_car_7 B4A0 LD A,($A250) A = turn_speed
B4A3 CP $02 CP 2
B4A5 LD A,$06 A = 6
B4A7 JR NZ,animate_hero_car_8
B4A9 LD A,($A251) A = (A << 3) - flip_car + 13
B4AC LD B,A
B4AD RLCA
B4AE RLCA
B4AF RLCA
B4B0 SUB B
B4B1 ADD A,$0D
animate_hero_car_8 B4B3 ADD A,C A += C
B4B4 PUSH AF
B4B5 CALL draw_cherry_b699
B4B8 POP AF
B4B9 LD C,A C = A
B4BA LD A,($B477) Read from 'LD C' @ ahc_hand_flag_one (above) to load A
B4BD CP $04 Jump to ahc_enable_cherry_light if A >= 4
B4BF JR NC,ahc_enable_cherry_light
B4C1 INC C C++
B4C2 LD A,C A = C
B4C3 JP draw_cherry_b699 Exit via draw_cherry_b699
ahc_enable_cherry_light B4C6 LD A,$01 Enable the cherry_light
B4C8 LD ($A228),A
B4CB RET Return
Prev: B063 Up: Map Next: B4CC