Prev: AB33 Up: Map Next: AC3C
AB9A: Routine at AB9A
Used by the routines at main_loop, cpu_driver and escape_scene.
spawn_hazards AB9A LD A,($A254) Load another_spawning_flag
AB9D AND A Set flags
AB9E RET Z Return if zero
AB9F CPL A = ~A + 21
ABA0 ADD A,$15
ABA2 LD C,A C = A
ABA3 LD A,($A240) Load road_buffer_offset into A
ABA6 ADD A,$A0 Add 160 so it's the hazards data offset
ABA8 ADD A,C A += C
ABA9 LD L,A L = A
ABAA LD H,$EE H = $EE
ABAC LD A,(HL) A = *HL -- load the hazard byte
ABAD AND A Set flags
ABAE RET Z Return if zero
ABAF CP $04 Is it 4?
ABB1 LD DE,$0000 DE = 0
ABB4 JR C,spawn_hazards_0 Jump if < 4 -- stop spawning barriers etc? jump/split too?
ABB6 LD E,$03 E = 3
ABB8 SUB E A -= E
spawn_hazards_0 ABB9 LD B,$32 B = 50
ABBB DEC A A--
ABBC JR Z,spawn_hazards_3 Jump if zero [A == 1]
ABBE LD B,$DC B = $DC
ABC0 DEC A A--
ABC1 JR Z,spawn_hazards_3 Jump if zero [A == 2]
ABC3 INC L L += 2
ABC4 INC L
ABC5 LD (HL),D *HL = D
ABC6 INC L L += 2
ABC7 INC L
ABC8 LD (HL),D *HL = D
ABC9 LD A,E A = E
ABCA CP $03 Is it 3?
ABCC JR NZ,spawn_hazards_2 Jump if non-zero
ABCE LD A,($A221) Load inhibit_collision_detection
ABD1 AND A Set flags
ABD2 JR Z,spawn_hazards_1 Jump if zero
Flag was set.
ABD4 LD B,$20 B = 32
ABD6 CALL sh_spawn Call sh_spawn
ABD9 LD B,$56 B = 86
ABDB CALL sh_spawn Call sh_spawn
ABDE LD B,$8C B = 140
ABE0 JR spawn_hazards_3 Calls sh_spawn then returns
spawn_hazards_1 ABE2 LD B,$50 B = 80
ABE4 CALL sh_spawn Call sh_spawn
ABE7 LD B,$A0 B = 160
ABE9 JR spawn_hazards_3 Calls sh_spawn then returns
spawn_hazards_2 ABEB LD B,$46 B = 70
ABED CALL sh_spawn Call sh_spawn
ABF0 LD B,$B4 B = 180
spawn_hazards_3 ABF2 CALL sh_spawn Call sh_spawn
ABF5 RET Return
Spawns hazards in the road, like barriers and tumbleweeds.
I:B Stored at entry+5 e.g. $20/$46/$56/$50/$B4
I:C Stored at entry+1 e.g. $13
sh_spawn ABF6 EXX Bank entry registers
ABF7 LD B,$06 6 iterations
ABF9 LD HL,$A188 Point HL at hazards table
ABFC LD DE,$0014 Stride of 20 bytes
sh_loop ABFF RLC (HL) Check the flag byte to see if the entry is used (it's either $00 if empty, or $FF if used, so rotating it in place is not a problem)
AC01 JR NC,sh_found_spare Jump to sh_found_spare if it didn't carry
AC03 ADD HL,DE Move to the next entry
AC04 DJNZ sh_loop Loop while iterations remain
AC06 POP HL
AC07 RET Return
HL points to the unused entry
sh_found_spare AC08 PUSH HL IX = HL
AC09 POP IX
AC0B LD BC,$0013 Zero 20 bytes at HL
AC0E LD D,H
AC0F LD E,L
AC10 INC DE
AC11 LD (HL),$00
AC13 LDIR
AC15 EXX Restore entry registers
AC16 LD HL,$AC3C wordat(IX + 11) = Address of hazard_hit routine
AC19 LD (IX+$0C),H
AC1C LD (IX+$0B),L
AC1F LD HL,($5CF6) Point HL at the hazards data table entry (*$5CF6 -> 5E40 + 3)
AC22 ADD HL,DE
AC23 LD A,(HL) Copy flag TBD
AC24 LD (IX+$08),A
AC27 INC HL
AC28 LD A,(HL) Copy lod address (e.g. tumbleweed_lods)
AC29 LD (IX+$09),A
AC2C INC HL
AC2D LD A,(HL)
AC2E LD (IX+$0A),A
AC31 LD (IX+$05),B IX[5] = B TBD -- passed in
AC34 LD (IX+$01),C IX[1] = C TBD
AC37 LD (IX+$00),$FF Mark the entry as used
AC3B RET Return
Prev: AB33 Up: Map Next: AC3C