Prev: CBCE Up: Map Next: CDD6
CD3A: Routine at CD3A
Used by the routines at main_loop, cpu_driver and escape_scene. Point IY at the road buffer height data.
main_loop_10 CD3A LD IYh,$EE Set IY high byte to road buffer memory region ($EExx)
CD3D LD A,($A240) Load road_buffer_offset into A
CD40 ADD A,$20 Add 32 so it's the height data offset
CD42 LD IYl,A IY is now the road buffer height data pointer
CD44 LD C,(IY+$00) Read a height byte into C
CD47 LD A,($A23F) A = fast_counter & $E0 -- top three bits
CD4A AND $E0
CD4C LD L,A L = A
CD4D LD B,A B = A
Reduces A by 31.25% ... unsure why that figure.
CD4E RRC L Divide A by 4 and subtract
CD50 RRC L
CD52 SUB L
CD53 RRC L Divide A by 16 and subtract
CD55 RRC L
CD57 SUB L
CD58 LD L,A HL = $E600 | (A + 1)
CD59 INC L
CD5A LD H,$E6
CD5C LD A,B A = B multiplicand
CD5D CALL multiply Call multiply (A = multiplier, C = multiplicand)
CD60 NEG A = -A
CD62 LD C,A C = A
CD63 EXX Bank
This builds the table at $E301.
CD64 LD B,$15 B = $15
CD66 LD DE,$E301 DE = $E301
ml10_loop CD69 EXX Unbank
CD6A LD E,(HL) E = *HL << 1
CD6B SLA E
CD6D PUSH HL Preserve HL
CD6E LD D,$00 D = 0
CD70 LD L,D L = 0
CD71 LD H,L H = 0
CD72 LD A,C A = C C is multiply result from above
CD73 ADD A,(IY+$00) A += *IY height byte
CD76 LD C,A C = A
CD77 JR Z,ml10_continue
CD79 JP P,main_loop_10_0
CD7C LD A,E A = E
CD7D DEC D E--
CD7E NEG A = -A
CD80 LD E,A E = A
CD81 LD A,C A = C
CD82 NEG A = -A
main_loop_10_0 CD84 ADD A,A A <<= 2
CD85 ADD A,A
CD86 JR NC,main_loop_10_1
CD88 LD L,E HL = DE
CD89 LD H,D
CD8A ADD HL,HL HL *= 2
main_loop_10_1 CD8B ADD A,A A <<= 1
CD8C JR NC,main_loop_10_2
CD8E ADD HL,DE HL += DE
main_loop_10_2 CD8F ADD HL,HL HL <<= 1
CD90 ADD A,A A <<= 1
CD91 JR NC,main_loop_10_3
CD93 ADD HL,DE HL += DE
main_loop_10_3 CD94 ADD HL,HL HL <<= 1
CD95 ADD A,A A <<= 1
CD96 JR NC,main_loop_10_4
CD98 ADD HL,DE HL += DE
main_loop_10_4 CD99 ADD HL,HL HL <<= 1
CD9A ADD A,A A <<= 1
CD9B JR NC,main_loop_10_5
CD9D ADD HL,DE HL += DE
main_loop_10_5 CD9E ADD HL,HL HL <<= 1
CD9F ADD A,A A <<= 1
CDA0 JR NC,main_loop_10_6
CDA2 ADD HL,DE HL += DE
main_loop_10_6 CDA3 ADD HL,HL HL <<= 1
CDA4 ADD A,A A <<= 1
CDA5 JR NC,main_loop_10_7
CDA7 ADD HL,DE HL += DE
main_loop_10_7 CDA8 ADD HL,HL HL <<= 1
CDA9 LD A,H A = H
ml10_continue CDAA POP HL Restore HL
CDAB ADD A,(HL) A += *HL
CDAC INC L L++
CDAD EXX Bank
CDAE LD (DE),A *DE = A -- writes to the table at $E3xx
CDAF INC E E++
CDB0 INC IYl IYl++
CDB2 DJNZ ml10_loop Loop to ml10_loop
CDB4 LD A,$A0 A = $A0
CDB6 LD (DE),A *DE = A
CDB7 LD HL,$E336
CDBA LD DE,$E301
CDBD LD BC,$1560
ml10_loop2 CDC0 LD A,(DE) A = *DE
CDC1 CP C
CDC2 JP P,main_loop_10_8
CDC5 LD C,A C = A
main_loop_10_8 CDC6 LD (HL),C *HL = C
CDC7 INC L L++
CDC8 INC E E++
CDC9 DJNZ ml10_loop2 Loop ml10_loop2 while B
CDCB LD A,C C = (C + 3) & $F8
CDCC ADD A,$03
CDCE AND $F8
CDD0 LD C,A
CDD1 SUB (HL) A -= *HL
CDD2 LD (HL),C *HL = C
CDD3 INC L L++
CDD4 LD (HL),A *HL = A
CDD5 RET Return
Prev: CBCE Up: Map Next: CDD6