Prev: B848 Up: Map Next: B9F4
B8D2: Routine at B8D2
Used by the routine at read_map.
sub_b8d2 B8D2 LD A,($A25A) A = var_a25a
B8D5 LD B,A BC = A
B8D6 LD C,$00
B8D8 LD A,($A258) A = var_a258
B8DB OR A Set flags
B8DC JP P,sub_b8d2_0 Jump if positive
B8DF NEG A = -A
B8E1 INC C C++
sub_b8d2_0 B8E2 SUB B B--
B8E3 JR Z,sub_b8d2_2 Jump if zero
B8E5 RR C 9-bit rotate right through carry
B8E7 LD B,$00 B = 0
B8E9 JR NC,sub_b8d2_1 Jump if no carry
B8EB NEG A = -A
B8ED DEC B B--
sub_b8d2_1 B8EE LD HL,($A171) HL = horizon_level
B8F1 LD C,A C = A
B8F2 ADD HL,BC HL += BC
B8F3 LD ($A171),HL horizon_level = HL
sub_b8d2_2 B8F6 LD A,($A240) Load road_buffer_offset into A
B8F9 ADD A,$22 Add (32+2) so it's the height data
B8FB LD H,$EE HL = $EE00 + A
B8FD LD L,A
B8FE XOR A A = 0
B8FF LD ($A25B),A var_a25b = 0
B902 LD ($A25A),A var_a25a = 0
B905 LD A,(HL) A = *HL
B906 SRA A
B908 JP P,sub_b8d2_3 Jump if positive
B90B INC A A++
sub_b8d2_3 B90C LD ($A258),A var_a258 = A
B90F DEC L L -= 2
B910 DEC L
B911 LD A,(HL) A = *HL
B912 LD C,A C = A
B913 OR A Set flags
B914 LD B,$00 B = 0
B916 JR Z,sub_b8d2_5 Jump if zero
B918 LD B,$06 B = 6
B91A JP P,sub_b8d2_4 Jump if positive
B91D NEG A = -A
B91F LD B,$03 B = 3
sub_b8d2_4 B921 CP $03 Jump if A >= 3
B923 JR NC,sub_b8d2_5
B925 LD B,$00 B = 0
sub_b8d2_5 B927 LD A,B A = B
B928 LD ($B5B0),A Self modify 'ADD A,x' @ B5AF
B92B LD HL,$A259 HL = &var_a259
B92E LD A,(HL) A = *HL
B92F AND A Set flags
B930 JP P,sub_b8d2_6 Jump if positive
B933 BIT 7,C Test bit 7
B935 JR NZ,sub_b8d2_6 Jump if non-zero
B937 NEG A = -A - 2
B939 SUB $02
B93B JR C,sub_b8d2_6 Jump if carry
B93D LD B,A B = A
B93E LD A,($B064) Load jump counter
B941 AND A Set flags
B942 JR NZ,sub_b8d2_6 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,sub_b8d2_6 Jump if <=
B957 JR Z,sub_b8d2_6
B959 PUSH HL Preserve HL
B95A RLCA HL = B057 + A*2 looks early.. might be 1-indexed? [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++ offset into B045
B963 INC HL
B964 LD A,(HL) Load new jump value [sampled: $B060]
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
B96F POP HL Restore HL
sub_b8d2_6 B970 LD (HL),C *HL = C
B971 LD A,($A25C) A = horizon_scroll
B974 EX AF,AF'
B975 LD A,($A240) Load road_buffer_offset into A
B978 LD H,$EE HL = $EE00 + A -- curvature data
B97A LD L,A
B97B LD A,($A265) A = split_road -- split road flag
B97E AND A Set flags
B97F LD A,(HL) A = *HL
B980 JR Z,sub_b8d2_7 Jump if zero
B982 LD A,($A269) A = var_a269
B985 AND A Set flags
B986 JR Z,sub_b8d2_7 Jump if zero
B988 LD A,($A249) Check fork_taken
B98B AND A
B98C LD A,(HL)
B98D JR Z,sub_b8d2_7 Jump if left fork was taken
B98F NEG A = -A
sub_b8d2_7 B991 LD ($A25C),A horizon_scroll = A
B994 AND A Set flags
B995 LD E,A E = A
B996 JR Z,sub_b8d2_9 Jump if zero
B998 LD E,$01 E = 1
B99A JP P,sub_b8d2_8 Jump if positive
B99D RL E
B99F NEG A = -A
sub_b8d2_8 B9A1 LD D,A D = A
B9A2 ADD A,A A *= 4
B9A3 ADD A,A
B9A4 LD ($A25D),A var_a25d = A
B9A7 LD B,A B = A
B9A8 LD A,($A25E) A = var_a25e
B9AB AND A Set flags
B9AC JR NZ,sub_b8d2_10 Jump if non-zero
B9AE LD HL,($A24A) Get speed value
B9B1 LD A,L A = L
B9B2 RR H A = speed / 2 (top half)
B9B4 RLA
B9B5 RLA
B9B6 RLA
B9B7 AND $06 A &= 6
B9B9 ADD A,B A = B
B9BA LD C,A BC = A
B9BB LD B,$00
B9BD LD HL,$B828 HL -> table of 16 words
B9C0 ADD HL,BC HL += BC
B9C1 LD A,(HL) A = *HL
sub_b8d2_9 B9C2 LD ($A25E),A var_a25e = A
sub_b8d2_10 B9C5 LD A,($A262) A = var_a262
B9C8 LD B,A BC = A
B9C9 LD C,$00
B9CB EX AF,AF'
B9CC AND A Set flags
B9CD JP P,sub_b8d2_11 Jump if positive
B9D0 NEG A = -A
B9D2 INC C C++
sub_b8d2_11 B9D3 SUB B A -= B
B9D4 JR C,sub_b8d2_13 Jump if <=
B9D6 JR Z,sub_b8d2_13
B9D8 LD B,A B = A
B9D9 ADD A,A A *= 4
B9DA ADD A,A
B9DB SRL B
B9DD ADD A,B A += B
B9DE RR C
B9E0 LD B,$00 B = 0
B9E2 JR NC,sub_b8d2_12 Jump if no carry
B9E4 DEC B B--
B9E5 NEG A = -A
sub_b8d2_12 B9E7 LD C,A C = A
B9E8 LD ($A25F),BC var_a25f = BC
sub_b8d2_13 B9EC XOR A A = 0
B9ED LD ($A261),A var_a261 = 0
B9F0 LD ($A262),A var_a262 = 0
B9F3 RET Return
Prev: B848 Up: Map Next: B9F4