Prev: B848 Up: Map Next: B9F4
B8D2: Updates the per-frame road level state
Called once a frame from read_map. It touches six things in order:
The horizon level moves by the accumulated incline step, then the accumulator is reset. The next height byte is read from the road buffer and halved to give the new incline. The frontmost height byte gives the pitch used to animate the car. A crest in the road launches the car into a jump, with the jump parameters chosen from a table. The new curvature byte, negated when the other fork is being taken, gives the horizon curve index and moves the horizon x scroll. Last, the difference between the old and the new curvature becomes this frame's steering correction and the curvature counters are reset.
Used by the routine at read_map.
update_road_level B8D2 LD A,($A25A) B = horizon_y_accum -- set by scroll_horizon
B8D5 LD B,A
B8D6 LD C,$00 C = 0 -- records the sign of the incline, so that url_incline_was_nonzero can restore it after the arithmetic below
B8D8 LD A,($A258) Load incline ($FD..$03 = climbing..descending)
B8DB OR A Set flags
B8DC JP P,url_incline_set Jump if road descending (positive value)
Otherwise road climbing (negative value).
B8DF NEG A = -A -- make positive $FD..$FF => 3..1
B8E1 INC C C++ -- set flag to 1
url_incline_set B8E2 SUB B A -= B (B is copy of horizon_y_accum, not used again)
B8E3 JR Z,url_read_road_height Jump if zero
url_incline_was_nonzero B8E5 RR C C is 0 or 1, so put into carry
B8E7 LD B,$00 BC = C
B8E9 JR NC,url_alter_horizon_level Jump if no carry (positive value)
Otherwise negative value.
B8EB NEG A = -A -- invert incline again?
B8ED DEC B B = $FF
url_alter_horizon_level B8EE LD HL,($A171) Load HL from horizon_level
B8F1 LD C,A C = A
B8F2 ADD HL,BC HL += BC
B8F3 LD ($A171),HL Store horizon_level
url_read_road_height B8F6 LD A,($A240) Load road_buffer_offset.lo into A
B8F9 ADD A,$22 Add (32+2) so it's the height data
B8FB LD H,$EE Point HL at road buffer height data
B8FD LD L,A
B8FE XOR A Zero horizon_y_step and horizon_y_accum
B8FF LD ($A25B),A
B902 LD ($A25A),A
B905 LD A,(HL) A = (height byte) >> 1
B906 SRA A
B908 JP P,url_positive Jump if positive (or zero?)
B90B INC A A++
url_positive B90C LD ($A258),A incline = A
B90F DEC L Step back 2 in the height data (frontmost height byte?)
B910 DEC L
B911 LD A,(HL) Read height byte
B912 LD C,A Copy to C
B913 OR A Set flags
B914 LD B,$00 B = 0
B916 JR Z,url_ge_3 Jump if height was zero
B918 LD B,$06 B = 6
B91A JP P,url_another_positive Jump if positive
Else negative.
B91D NEG A = -A
B91F LD B,$03 B = 3
url_another_positive B921 CP $03 Jump if A >= 3
B923 JR NC,url_ge_3
B925 LD B,$00 B = 0
url_ge_3 B927 LD A,B A = B
B928 LD ($B5B0),A Self modify 'ADD A,x' @ B5AF
B92B LD HL,$A259 Load address of prev_road_height
B92E LD A,(HL) Read prev_road_height
B92F AND A Set flags
B930 JP P,url_potato Jump if positive (or zero)
Else negative.
B933 BIT 7,C Test bit 7
B935 JR NZ,url_potato Jump if non-zero
Else unset.
B937 NEG A = -A - 2
B939 SUB $02
B93B JR C,url_potato Jump if carry (-A < 2)
Else ?
B93D LD B,A B = A
B93E LD A,($B064) Load jump counter
B941 AND A Set flags
B942 JR NZ,url_potato Jump if non-zero
B944 LD DE,($A24A) DE = speed
B948 RR D 9-bit rotate right via carry
B94A LD A,E A = E
B94B RLA 9-bit rotate left via carry
B94C RLA
B94D AND $03 D = ~(A & 3) + 4
B94F CPL
B950 ADD A,$04
B952 LD D,A
B953 LD A,B A = B - D
B954 SUB D
B955 JR C,url_potato Jump if <=
B957 JR Z,url_potato
B959 PUSH HL Preserve HL
B95A RLCA HL = B057 + A*2 -- 1-indexed pointer into table_b059 [sampled A: 3,2,4]
B95B LD E,A
B95C LD D,$00
B95E LD HL,$B057
B961 ADD HL,DE
B962 LD E,(HL) E = *HL++ (loads one of 2/4/6/8/10)
B963 INC HL
B964 LD A,(HL) Load new jump value [sampled: $B060] (loads one of 8/6/4/2/0)
B965 LD ($B064),A Set jump counter
B968 LD HL,$B045 HL = hero_car_jump_table + E -- points into jump values table
B96B ADD HL,DE
B96C LD ($B07A),HL Self modify mhc_midair (mhc_midair)
B96F POP HL Restore HL (which is what?)
url_potato B970 LD (HL),C *HL = C
B971 LD A,($A25C) Load current_curvature into A
B974 EX AF,AF' Preserve it
B975 LD A,($A240) Load road_buffer_offset.lo into A
B978 LD H,$EE Point HL at road buffer curvature data
B97A LD L,A
B97B LD A,($A265) Test fork_visible
B97E AND A
B97F LD A,(HL) Load a curvature byte
B980 JR Z,url_fork_not_visible Jump if fork_visible was zero
Forked road is visible.
url_fork_visible B982 LD A,($A269) Jump if fork_in_progress is zero [set while the road forks]
B985 AND A
B986 JR Z,url_fork_not_visible
B988 LD A,($A249) Check fork_taken
B98B AND A
B98C LD A,(HL) Load a curvature byte again
B98D JR Z,url_fork_not_visible Jump if left fork was taken
B98F NEG Negate if right fork was taken
url_fork_not_visible B991 LD ($A25C),A Store new curvature value to current_curvature
B994 AND A Set flags
B995 LD E,A E = A
B996 JR Z,url_set_x_scroll Jump if curvature byte was zero
B998 LD E,$01 E = 1
B99A JP P,url_b9a1 Jump if positive
Otherwise negative
B99D RL E
B99F NEG A = -A -- make positive
url_b9a1 B9A1 LD D,A D = A -- this doesn't appear to be used
B9A2 ADD A,A A *= 4
B9A3 ADD A,A
B9A4 LD ($A25D),A horizon_curve_index = A
B9A7 LD B,A B = A
B9A8 LD A,($A25E) Jump if horizon_x_scroll is non-zero
B9AB AND A
B9AC JR NZ,url_b9c5
B9AE LD HL,($A24A) Load speed into HL
B9B1 LD A,L Speed low byte
B9B2 RR H Bottom bit of H moves to carry (H now unused)
B9B4 RLA A = (A << 3) & 6
B9B5 RLA
B9B6 RLA
B9B7 AND $06
B9B9 ADD A,B A += B
B9BA LD C,A BC = A
B9BB LD B,$00
B9BD LD HL,$B828 HL = horizon_table + BC
B9C0 ADD HL,BC
B9C1 LD A,(HL) A = *HL
url_set_x_scroll B9C2 LD ($A25E),A horizon_x_scroll = A
url_b9c5 B9C5 LD A,($A262) A = curvature_ticks
B9C8 LD B,A BC = A
B9C9 LD C,$00
B9CB EX AF,AF' Unbank current curvature
B9CC AND A Set flags
B9CD JP P,url_b9d3 Jump if positive
Otherwise negative
B9D0 NEG A = -A -- make positive
B9D2 INC C C++
url_b9d3 B9D3 SUB B A -= B
B9D4 JR C,url_b9ec Jump if <=
B9D6 JR Z,url_b9ec
B9D8 LD B,A B = A
B9D9 ADD A,A A = A * 4
B9DA ADD A,A
B9DB SRL B B >>= 1
B9DD ADD A,B A += B
B9DE RR C
B9E0 LD B,$00 B = 0
B9E2 JR NC,url_set_hz_adjust Jump if no carry
url_b9e4 B9E4 DEC B B--
B9E5 NEG A = -A
url_set_hz_adjust B9E7 LD C,A C = A
B9E8 LD ($A25F),BC Set horizontal_adjust to BC (this shifts the car left/right if +ve/-ve)
url_b9ec B9EC XOR A A = 0
B9ED LD ($A261),A horizon_scroll_sub = 0
B9F0 LD ($A262),A curvature_ticks = 0
B9F3 RET Return
Prev: B848 Up: Map Next: B9F4