Prev: 696B Up: Map Next: 6A3F
6990: Render one line of island terrain
Renders the left and right edges of an island on the current screen line. Islands are rendered as two diagonal edges (left and right) with solid terrain ($FF) filling the space from screen edge to each diagonal edge.
The left edge X position is calculated as: state_island_byte_2 + profile_value + $80. The $80 centers the coordinate system (screen center). The profile_value comes from data_terrain_profiles indexed by state_island_profile_idx and state_terrain_position.
The right edge position depends on state_island_byte_3: 0=use byte_3 directly, 1=mirror around center (2*$3C - left), 2=offset from left ($3C + left). $3C (60) is the default river half-width.
render_island_line 6990 LD HL,$5EFD Increment island line counter.
6993 INC (HL)
6994 LD A,($5EFA) Set up lookup: HL=data_terrain_profiles, DE=TERRAIN_PROFILE_SIZE.
6997 LD HL,$8063
699A LD DE,$0010
699D OR A
699E SBC HL,DE
locate_island_profile 69A0 ADD HL,DE Locate 16-byte profile entry by state_island_profile_idx.
69A1 DEC A
69A2 JR NZ,locate_island_profile
69A4 LD A,($5F7D) Index into profile by (state_terrain_position AND $0F) to get edge offset byte.
69A7 AND $0F
69A9 LD D,$00
69AB LD E,A
69AC ADD HL,DE
69AD LD A,($5EFB) Left edge X = state_island_byte_2 + profile_byte + $80. Save X on stack.
69B0 ADD A,(HL)
69B1 PUSH AF
69B2 LD B,$00
69B4 ADD A,$80
69B6 LD D,A
69B7 LD HL,$89F2
69BA LD A,D Look up 2-byte edge sprite from terrain_edge_left using (X AND $06) as sprite index.
69BB AND $07
69BD SRL A
69BF LD C,A
69C0 SLA C
69C2 LD A,D
69C3 ADD HL,BC
69C4 EX DE,HL
69C5 LD C,A Calculate screen address = screen_ptr + (X >> 3). Copy 2-byte edge sprite via LDIR.
69C6 LD HL,($5F7B)
69C9 LD B,$00
69CB SRL C
69CD SRL C
69CF SRL C
69D1 ADD HL,BC
69D2 EX DE,HL
69D3 LD BC,$0002
69D6 LDIR
69D8 DEC DE Calculate fill count = (X >> 3) - 16. This is number of solid tiles left of edge.
69D9 DEC DE
69DA SRL A
69DC SRL A
69DE SRL A
69E0 SUB $10
69E2 AND $0F
69E4 LD B,A
69E5 CP $00
69E7 JP Z,prepare_right_edge
69EA LD A,$FF Fill leftward with $FF bytes (solid terrain) for fill count iterations.
fill_island_left_loop 69EC DEC DE
69ED LD (DE),A
69EE DJNZ fill_island_left_loop
prepare_right_edge 69F0 POP AF Restore left X from stack. Set D=left X, C=$3C (river half-width), B=state_island_byte_2.
69F1 LD B,$00
69F3 LD D,A
69F4 LD C,$3C
69F6 LD A,($5EFB)
69F9 LD B,A
69FA LD A,($5EFC) Dispatch based on state_island_byte_3: 1=calc_mirrored_edge, 2=calc_offset_edge, else use byte_3 as right X.
69FD CP $01
69FF JP Z,calc_mirrored_edge
6A02 LD A,($5EFC)
6A05 CP $02
6A07 JP Z,calc_offset_edge
This entry point is used by the routines at calc_mirrored_edge and calc_offset_edge.
draw_right_edge 6A0A LD D,A Look up 2-byte edge sprite from terrain_edge_right using (right X AND $06) as index.
6A0B LD HL,$89FA
6A0E LD A,D
6A0F AND $06
6A11 LD C,A
6A12 LD B,$00
6A14 LD A,D
6A15 ADD HL,BC
6A16 EX DE,HL
6A17 LD C,A
6A18 LD HL,($5F7B) Calculate screen address = screen_ptr + (right X >> 3). Copy 2-byte edge sprite via LDIR.
6A1B SRL C
6A1D SRL C
6A1F SRL C
6A21 ADD HL,BC
6A22 EX DE,HL
6A23 LD BC,$0002
6A26 LDIR Calculate fill count = 15 - (right X >> 3). This is number of solid tiles right of edge.
6A28 LD B,A
6A29 SRL B
6A2B SRL B
6A2D SRL B
6A2F LD A,$0F
6A31 SUB B
6A32 LD B,A
6A33 AND $0F
6A35 CP $00
6A37 RET Z
6A38 LD A,$FF Load $FF (solid terrain byte) into A.
fill_island_right_loop 6A3A LD (DE),A Write A to (DE), increment DE, loop B times to fill rightward.
6A3B INC DE
6A3C DJNZ fill_island_right_loop
6A3E RET Return after filling right terrain.
Prev: 696B Up: Map Next: 6A3F