Prev: D0BC Up: Map Next: D292
D0BD: Draw the landscape
Used by the routine at scroll_landscape.
Called each pass by scroll_landscape, when the view is below the sky (map row 3 or more). The screen shows at most four map tiles, each the size of the play area: the view's page, the one below, the one to the right and the one below that. load_map_window has listed their tile records' addresses after map_window_pointer, which points into the list, and their collision-box lists (37 bytes each) are at loader_entry, ground_cell_bottom_left, ground_cell_top_right and ground_cell_bottom_right; ground_cell says which of the four is being drawn (0 the view's page, 1 below, 2 right, 3 below right). Nothing is scrolled: every piece that can be seen is drawn again, straight onto the screen, from a copy of its graphic pre-shifted for this pass's fine scroll.
First the shift table: the fine scroll (origin_x AND 7) picks one of four tables (at 0, 2, 4 or 6 pixels; shift_table), and the graphic-offset table's start (graphic_offsets, or one byte on when shifted). Then, for each tile: the page-to-screen offsets origin_x and origin_y are moved on to that tile ($E0 to the right, $A0 down, as 8-bit sums) and put back at the end (in after_step_drawn).
A tile record (the tables from tile_records): first byte 0, an empty tile. Otherwise, optionally $99 (the tile is turned upside down: floors become ceilings), optionally $FF (mirrored left-right), optionally a byte of $95 or more (skipped: padding, so a mirrored or upside-down tile can point a few bytes before a plain record and share it), then the number of pieces. Each piece: x and y in the page (pixels; y counts down from the top of the page, and the piece's line rises from there), then a byte whose high nibble is its direction (load_piece_steps) and whose low nibble its number of steps (0 meaning 16), and, only for a flat direction (0 or 7), the codes of its two end pieces (piece_ends). So a tile's ground is a chain of pieces, each a line of steps of one shape: a flat run of 24-pixel steps, a slope up or down, a wall.
Each collision-box list: +0 the number of pieces, then up to seven 5-byte boxes, one per piece: +0 +1 x and y, +2 +3 for a flat piece its width (24 a step) and $14, for a wall $18 and its height (16 a step), for a slope its far end's x and y; +4 its class (piece_classes). These are refilled only while record_ground is set: when the view has moved into a new page this pass (scroll_landscape) or the screen is being built after a restart (map_rebuild); otherwise only the piece count is rewritten.
Each piece is then tested against the view: a piece wholly outside it across (view_x, piece_off_left_edge for the left-hand tiles, piece_off_right_edge for the right) or up and down (view_y, piece_off_top_edge for the upper tiles, piece_off_bottom_edge for the lower) is not drawn. One that may be seen is drawn by the column loop at landscape_step_loop, its attributes coloured by colour_piece, and the next piece taken from next_piece. The renderer uses SP for its POP blitter and reloads it from the fixed address stack_top between pieces.
draw_landscape D0BD LD A,(map_rebuild) Building after a restart: refill the collision records too.
D0C0 AND A
D0C1 JR Z,draw_landscape_0
D0C3 LD (record_ground),A
draw_landscape_0 D0C6 LD A,(origin_y) The vertical offset for the first tile.
D0C9 ADD A,$60
D0CB LD (origin_y),A
D0CE LD DE,graphic_offsets Start of the graphic-offset table for an unshifted scroll.
D0D1 LD (offsets_start),DE
D0D5 EXX The fine scroll picks the shift table (and the shifted half of the offsets) for 0, 2, 4 or 6 pixels.
D0D6 LD HL,piece_blitters_shift0
D0D9 LD A,(origin_x)
D0DC AND $07
D0DE JR Z,draw_landscape_1
D0E0 EXX
D0E1 INC DE
D0E2 LD (offsets_start),DE
D0E6 EXX
D0E7 LD HL,piece_blitters_shift2
D0EA CP $02
D0EC JR Z,draw_landscape_1
D0EE LD HL,piece_blitters_shift4
D0F1 CP $04
D0F3 JR Z,draw_landscape_1
D0F5 LD HL,piece_blitters_shift6
draw_landscape_1 D0F8 LD (shift_table),HL
D0FB XOR A The first tile.
D0FC LD (ground_cell),A
This entry point is used by the routine at after_step_drawn.
draw_landscape_2 D0FF LD IX,loader_entry Each tile: its box list.
D103 LD A,(ground_cell)
D106 AND A
D107 JR Z,draw_landscape_3
D109 LD IX,ground_cell_bottom_left
D10D CP $01
D10F JR Z,draw_landscape_3
D111 LD IX,ground_cell_top_right
D115 CP $02
D117 JR Z,draw_landscape_3
D119 LD IX,ground_cell_bottom_right
draw_landscape_3 D11D LD HL,(map_window_pointer) The next tile record's address from the list.
D120 LD E,(HL)
D121 INC HL
D122 LD D,(HL)
D123 INC HL
D124 LD (map_window_pointer),HL
D127 EX DE,HL
D128 XOR A Not mirrored, not upside down, no pieces yet.
D129 LD (tile_mirrored_left_right),A
D12C LD (tile_upside_down),A
D12F LD (IX+$00),A
D132 LD A,(HL) An empty tile: on to the next.
D133 AND A
D134 JP Z,after_step_drawn_17
D137 CP $99 $99: upside down.
D139 JR NZ,draw_landscape_4
D13B LD (tile_upside_down),A
D13E INC HL
draw_landscape_4 D13F LD A,(HL) $FF: mirrored left-right.
D140 CP $FF
D142 JR NZ,draw_landscape_5
D144 LD (tile_mirrored_left_right),A
D147 INC HL
draw_landscape_5 D148 LD A,(HL) A byte from $95 up is skipped.
D149 CP $95
D14B JR C,draw_landscape_6
D14D INC HL
D14E LD A,(HL)
draw_landscape_6 D14F LD (pieces_left),A The number of pieces, to pieces_left and the box list; its first box kept at collision_object.
D152 LD (IX+$00),A
D155 INC IX
D157 INC HL
D158 LD (collision_object),IX
This entry point is used by the routine at after_step_drawn.
draw_landscape_7 D15C LD IX,current_piece Each piece: its state at current_piece, and the per-piece flags cleared.
D160 XOR A
D161 LD (piece_steps_done),A
D164 LD (clipped_columns),A
D167 LD (piece_clip),A
D16A LD (piece_kept),A
D16D LD (piece_extra_b),A
D170 LD (piece_extra_a),A
D173 LD (piece_ceiling),A
D176 LD (piece_rows),A
D179 LD (last_step_in_border),A
D17C LD (IX+$01),A
D17F LD A,(HL) Its x and y in the page (the y kept unchanged in box_height too).
D180 LD (piece_page_x),A
D183 INC HL
D184 LD A,(HL)
D185 LD (piece_page_y),A
D188 LD (box_height),A
D18B INC HL
D18C LD A,(HL) Its direction (high nibble) and its steps (load_piece_steps).
D18D RRCA
D18E RRCA
D18F RRCA
D190 RRCA
D191 AND $0F
D193 LD (IX+$03),A
D196 EXX
D197 CALL load_piece_steps
D19A EXX
D19B LD A,(HL) The number of steps; 0 means 16.
D19C AND $0F
D19E JR NZ,draw_landscape_8
D1A0 LD A,$10
draw_landscape_8 D1A2 LD (piece_steps),A
D1A5 LD C,A
D1A6 INC HL The end pieces, and a mirrored tile's changes (piece_ends).
D1A7 CALL piece_ends
D1AA LD HL,column_varieties The column-variety sequence in HL; the direction kept in B.
D1AD LD B,(IX+$03)
D1B0 EXX The box, filled only while building (record_ground).
D1B1 LD IX,(collision_object)
D1B5 LD A,(record_ground)
D1B8 AND A
D1B9 JP Z,draw_landscape_15
D1BC LD A,($DEDF) Its class, steps, x and y.
D1BF LD E,A
D1C0 LD D,$00
D1C2 LD HL,piece_classes
D1C5 ADD HL,DE
D1C6 LD A,(HL)
D1C7 LD (IX+$04),A
D1CA LD A,(piece_steps)
D1CD LD (IX+$02),A
D1D0 LD A,(piece_page_x)
D1D3 LD (IX+$00),A
D1D6 LD A,(piece_page_y)
D1D9 LD (IX+$01),A
D1DC LD A,(piece_rise) A flat piece:
D1DF AND A
D1E0 JR NZ,draw_landscape_10
D1E2 LD B,(IX+$02) width 24 pixels a step, height $14,
D1E5 XOR A
draw_landscape_9 D1E6 ADD A,$18
D1E8 DJNZ draw_landscape_9
D1EA LD (IX+$02),A
D1ED LD A,($DEDF)
D1F0 CP $07
D1F2 LD (IX+$03),$14
D1F6 JP Z,draw_landscape_15
D1F9 LD A,(IX+$01) and its y $10 lower unless it is upside down.
D1FC ADD A,$10
D1FE LD (IX+$01),A
D201 JP draw_landscape_15
draw_landscape_10 D204 LD A,(piece_dx_copy) A wall:
D207 AND A
D208 JR NZ,draw_landscape_12
D20A LD B,(IX+$02) width $18, height 16 a step, and the left-going wall $10 to the left.
D20D XOR A
draw_landscape_11 D20E ADD A,$10
D210 DJNZ draw_landscape_11
D212 LD B,A
D213 LD (IX+$02),$18
D217 LD A,($DEDF)
D21A LD (IX+$03),B
D21D CP $0F
D21F JP NZ,draw_landscape_15
D222 LD A,(IX+$00)
D225 SUB $10
D227 LD (IX+$00),A
D22A JP draw_landscape_15
draw_landscape_12 D22D LD A,(direction_flag) A slope going left starts one x step further right.
D230 CP $FF
D232 JR Z,draw_landscape_13
D234 LD A,(piece_step_x)
D237 ADD A,(IX+$00)
D23A LD (IX+$00),A
draw_landscape_13 D23D LD B,(IX+$02) Its far end: the x and y after all its steps.
D240 LD D,(IX+$00)
D243 LD E,(IX+$01)
draw_landscape_14 D246 LD A,(piece_dx)
D249 ADD A,D
D24A LD D,A
D24B LD A,(piece_rise)
D24E NEG
D250 ADD A,E
D251 LD E,A
D252 DJNZ draw_landscape_14
D254 LD (IX+$03),E
D257 LD (IX+$02),D
draw_landscape_15 D25A LD A,(view_x) Wholly to the left or right of the view?
D25D LD B,A
D25E LD A,(ground_cell)
D261 BIT 1,A
D263 JR Z,draw_landscape_16
D265 CALL piece_off_right_edge
D268 JR draw_landscape_17
draw_landscape_16 D26A CALL piece_off_left_edge
draw_landscape_17 D26D JP NZ,draw_landscape_20
D270 LD A,(view_y) Wholly above or below it?
D273 LD B,A
D274 LD A,(ground_cell)
D277 BIT 0,A
D279 JR Z,draw_landscape_18
D27B CALL piece_off_bottom_edge
D27E JR draw_landscape_19
draw_landscape_18 D280 CALL piece_off_top_edge
draw_landscape_19 D283 JP NZ,draw_landscape_20
D286 CALL next_piece_box It can be seen: on to the next collision record, and draw it.
D289 JP landscape_step_loop_0
draw_landscape_20 D28C CALL next_piece_box It cannot: on to the next collision record and the next piece.
D28F JP after_step_drawn_16
Prev: D0BC Up: Map Next: D292