| Prev: 6A4F | Up: Map | Next: 6B58 |
6AA3: Render one pixel line of terrain
|
Renders a single pixel line of the current terrain fragment. Called 16 times per fragment (lines 0-15). Draws left edge sprite, fills left terrain, draws right edge sprite, fills right terrain. Handles special fragments (bridges/roads) separately.
|
||||
|
Left edge X = profile_byte + row_offset - 16. The profile_byte comes from data_terrain_profiles[profile_number][line]. The -16 adjusts for the edge sprite width. Right edge depends on state_terrain_extras mode.
|
||||
| render_terrain_fragment | 6AA3 | LD A,($5F77) | Set up profile lookup: HL = data_terrain_profiles, DE = TERRAIN_PROFILE_SIZE. | |
| 6AA6 | LD HL,$8063 | |||
| 6AA9 | LD DE,$0010 | |||
| 6AAC | OR A | |||
| 6AAD | SBC HL,DE | |||
| locate_terrain_profile | 6AAF | ADD HL,DE | Locate profile: data_terrain_profiles[state_terrain_profile_number]. | |
| 6AB0 | DEC A | |||
| 6AB1 | JR NZ,locate_terrain_profile | |||
| 6AB3 | LD A,($5F7D) | Increment state_terrain_position (line 0-15). | ||
| 6AB6 | INC A | |||
| 6AB7 | LD ($5F7D),A | |||
| 6ABA | CP $10 | If line reached TERRAIN_PROFILE_SIZE, jump to render_terrain_row to load next fragment. | ||
| 6ABC | JP Z,render_terrain_row | |||
| 6ABF | AND $0F | Index into profile: HL = profile_base + (line mod TERRAIN_PROFILE_SIZE). | ||
| 6AC1 | LD D,$00 | |||
| 6AC3 | LD E,A | |||
| 6AC4 | ADD HL,DE | |||
| 6AC5 | LD BC,($5F78) | Load row offset (B) from state_terrain_element_23 and profile byte (A). | ||
| 6AC9 | LD A,(HL) | |||
| 6ACA | BIT 7,A | If bit 7 of profile byte set, jump to handle_special_terrain_fragment (special fragment). | ||
| 6ACC | JP NZ,handle_special_terrain_fragment | |||
| 6ACF | ADD A,B | Left edge X = profile_byte + row_offset - 16. Save original X, work with adjusted X. | ||
| 6AD0 | PUSH AF | |||
| 6AD1 | LD B,$00 | |||
| 6AD3 | SUB $10 | |||
| 6AD5 | LD D,A | Increment terrain_edge_counter. Set up sprite lookup from terrain_edge_left. | ||
| 6AD6 | LD HL,$693B | |||
| 6AD9 | INC (HL) | |||
| 6ADA | LD HL,$89F2 | Sprite index = (X AND $06). Look up 2-byte edge sprite from terrain_edge_left. | ||
| 6ADD | LD A,D | |||
| 6ADE | AND $07 | |||
| 6AE0 | SRL A | |||
| 6AE2 | LD C,A | |||
| 6AE3 | SLA C | |||
| 6AE5 | LD A,D | Screen address = screen_ptr + (X >> 3). Copy 2-byte sprite via LDIR. | ||
| 6AE6 | ADD HL,BC | |||
| 6AE7 | EX DE,HL | |||
| 6AE8 | LD C,A | |||
| 6AE9 | LD HL,($5F7B) | |||
| 6AEC | LD B,$00 | |||
| 6AEE | SRL C | |||
| 6AF0 | SRL C | |||
| 6AF2 | SRL C | |||
| 6AF4 | ADD HL,BC | Fill count = X >> 3. Fill leftward with $FF (solid terrain). | ||
| 6AF5 | EX DE,HL | |||
| 6AF6 | LD BC,$0002 | |||
| 6AF9 | LDIR | |||
| 6AFB | DEC DE | Restore original X. Dispatch based on state_terrain_extras: 1=calc_terrain_right_mirrored, 2=calc_terrain_right_offset. | ||
| 6AFC | DEC DE | |||
| 6AFD | LD B,A | |||
| 6AFE | SRL B | |||
| 6B00 | SRL B | |||
| 6B02 | SRL B | |||
| 6B04 | LD A,$FF | |||
| fill_terrain_left_loop | 6B06 | DEC DE | ||
| 6B07 | LD (DE),A | |||
| 6B08 | DJNZ fill_terrain_left_loop | |||
| 6B0A | POP AF | |||
| 6B0B | LD D,A | |||
| 6B0C | LD BC,($5F78) | |||
| 6B10 | LD A,($5F7A) | Right sprite index = (right_X AND $06). Look up from terrain_edge_right. | ||
| 6B13 | CP $01 | |||
| 6B15 | JP Z,calc_terrain_right_mirrored | |||
| 6B18 | LD A,($5F7A) | |||
| 6B1B | CP $02 | |||
| 6B1D | JP Z,calc_terrain_right_offset | |||
|
This entry point is used by the routines at calc_terrain_right_mirrored and calc_terrain_right_offset.
|
||||
| draw_terrain_right_edge | 6B20 | LD D,A | } | |
| 6B21 | LD B,$00 | Screen address = screen_ptr + (right_X >> 3). Copy 2-byte sprite via LDIR. | ||
| 6B23 | LD HL,$89FA | |||
| 6B26 | LD A,D | |||
| 6B27 | AND $06 | |||
| 6B29 | LD C,A | |||
| 6B2A | LD A,D | |||
| 6B2B | ADD HL,BC | |||
| 6B2C | EX DE,HL | |||
| 6B2D | LD C,A | |||
| 6B2E | LD HL,($5F7B) | |||
| 6B31 | SRL C | Fill count = 30 - (right_X >> 3). Fill rightward with $FF. | ||
| 6B33 | SRL C | |||
| 6B35 | SRL C | |||
| 6B37 | ADD HL,BC | |||
| 6B38 | EX DE,HL | |||
| 6B39 | LD BC,$0002 | |||
| 6B3C | LDIR | |||
| 6B3E | LD B,A | |||
| 6B3F | SRL B | |||
| 6B41 | SRL B | |||
| 6B43 | SRL B | |||
| 6B45 | LD A,$1E | If island active (state_island_line_idx != 16), call render_island_line. | ||
| 6B47 | SUB B | |||
| 6B48 | LD B,A | |||
| 6B49 | LD A,$FF | |||
| fill_terrain_right_loop | 6B4B | LD (DE),A | ||
| 6B4C | INC DE | |||
| 6B4D | DJNZ fill_terrain_right_loop | |||
| 6B4F | LD A,($5EFD) | |||
| 6B52 | CP $10 | |||
| 6B54 | CALL NZ,render_island_line | |||
| 6B57 | RET | |||
| Prev: 6A4F | Up: Map | Next: 6B58 |