Prev: A7F3 Up: Map Next: A8CD
A89C: Returns the range of lanes that cars or hazards should spawn within
Returning (1,1) means that cars will only spawn in the leftmost lane; returning (3,4) makes them spawn in the third or fourth lane; and so on.
The lanes byte at the given road buffer offset decides. (1,4) is a four lane road, a dirt track or a fork; (1,3) a three lane road or a tunnel; (2,4) a three lane road biased right; (1,2) a two lane road biased left; and (3,4) a two lane road biased right.
Input
C Additional lanes buffer offset (e.g. 20)
Output
B Lowest lane
C Highest lane
get_spawn_lanes A89C LD A,($A240) Calculate [current buffer offset] + [lanes offset of 64] + 2 bytes + [additional buffer offset] (wrapping around)
A89F ADD A,$42
A8A1 ADD A,C
A8A2 LD L,A Point DE at road buffer lane data as calculated
A8A3 LD H,$EE
A8A5 LD A,(HL) Read lanes_byte
A8A6 AND A Set flags
A8A7 LD BC,$0104 Set lowest lane = 1, highest lane = 4
A8AA RET Z Return if lanes_byte was zero (4 lanes)
A8AB LD E,A Preserve lanes_byte
A8AC AND $C1 Return if ((lanes_byte & $C1) == $C1) (4 lane dirt track) [would also choose 2 lane dirt track but that's nonstandard]
A8AE CP $C1
A8B0 RET Z
A8B1 CP $41 Test for tunnel (three lanes)
A8B3 LD BC,$0103 Set lowest = 1, highest = 3
A8B6 RET Z Return if tunnel
A8B7 LD A,E Compute (lanes_byte & $82)
A8B8 AND $82
A8BA ADD A,A Set carry from top bit while discarding it
A8BB JR NC,gsl_two_lanes Jump to gsl_two_lanes if top bit not set
gsl_three_lanes A8BD LD BC,$0204 Set lowest = 2, highest = 4
A8C0 RET NZ Return if non-zero (3 lanes right aligned)
A8C1 LD BC,$0103 Set lowest = 1, highest = 3
A8C4 RET Return (3 lanes left aligned)
gsl_two_lanes A8C5 LD BC,$0102 Set lowest = 1, highest = 2
A8C8 RET Z Return if zero (2 lanes left aligned)
A8C9 LD BC,$0304 Set lowest = 3, highest = 4
A8CC RET Return
Prev: A7F3 Up: Map Next: A8CD