![]() |
Routines |
| Prev: D303 | Up: Map | Next: D464 |
|
Used by the routine at after_step_drawn.
The per-step loop of the landscape renderer. A piece is a straight run of identical steps; each step moves the drawing position on by its direction's advance (piece_dx pixels across, piece_dcolumn bytes across, piece_rise pixels up, from the table at piece_shapes by set_piece_shape). Directions 0-6 are floors -- flat, three slopes rising to the right, three rising to the left -- and 7-13 the same shapes as ceilings (rock above, sky below; set_piece_shape sets piece_ceiling to $80 for them); 14 and 15 are vertical walls. For each step this routine:
1. Advances the in-cell position (piece_page_x, piece_page_y) and the screen position (piece_x, piece_y). A piece's first step is entered further down, without moving. 2. Culls it against the play area. Vertically: in an upper map cell a step whose base is above the top edge is skipped; in a lower one, a step whose top is below the bottom edge; a step exactly on the edge sets a flag in edge_flags (column_at_view_top, column_at_view_bottom). Horizontally the same against view_x, with flags set by column_at_view_left and column_at_view_right. Skipped steps go to the step counter in after_step_drawn without drawing. 3. With an edge flag set, goes to edge_column or column_clipped (the edge-exact cases). 4. Otherwise reads the step's variant (0-2, from the repeating sequence at column_varieties) and, for the piece's first drawn step, looks its direction up in the fine-scroll table at shift_table (16 entries of four bytes: a blitter address into IY, a graphic address into piece_graphic), works out the screen address (step_screen_address) and finds this direction's row of variant offsets (piece_offsets). 5. Chooses how to draw: a flat step goes to flat_step_clip; a sloped step near the right edge (screen x from $D1) through the patched JR at the end of this routine to slope_step_at_right_edge; others to slope_step_at_left_edge, which clips at the left edge or draws whole. All of them end at draw_step, which draws the step.
Interrupts are off for the whole game, which is what makes it safe for the blitters to borrow SP.
|
||||||||||||
| landscape_step_loop | D319 | LD A,(piece_rise) | Move to this step: up by the direction's rise, across by its run. | |||||||||
| D31C | LD B,A | |||||||||||
| D31D | LD A,(piece_page_y) | |||||||||||
| D320 | SUB B | |||||||||||
| D321 | LD (piece_page_y),A | |||||||||||
| D324 | LD A,(piece_y) | |||||||||||
| D327 | SUB B | |||||||||||
| D328 | LD (piece_y),A | |||||||||||
| D32B | LD A,(piece_dx) | |||||||||||
| D32E | LD B,A | |||||||||||
| D32F | LD A,(piece_x) | |||||||||||
| D332 | ADD A,B | |||||||||||
| D333 | LD (piece_x),A | |||||||||||
| D336 | LD A,(piece_page_x) | |||||||||||
| D339 | ADD A,B | |||||||||||
| D33A | LD (piece_page_x),A | |||||||||||
|
This entry point is used by the routine at draw_landscape.
|
||||||||||||
| landscape_step_loop_0 | D33D | XOR A | A piece's first step enters here (from draw_landscape): no edge flags yet. | |||||||||
| D33E | LD (edge_flags),A | |||||||||||
| D341 | LD A,(ground_cell) | Upper map cell: skip if the step's base is above the top edge; exactly on it, flag it (column_at_view_top). | ||||||||||
| D344 | BIT 0,A | |||||||||||
| D346 | JR NZ,landscape_step_loop_1 | |||||||||||
| D348 | LD A,(piece_page_y) | |||||||||||
| D34B | LD B,A | |||||||||||
| D34C | LD A,(view_y) | |||||||||||
| D34F | CP B | |||||||||||
| D350 | JP Z,column_at_view_top | |||||||||||
| D353 | JP NC,after_step_drawn_2 | |||||||||||
| D356 | JP landscape_step_loop_2 | |||||||||||
| landscape_step_loop_1 | D359 | LD A,(piece_rows) | Lower map cell: skip if the step's top is below the bottom edge; exactly on it, flag it (column_at_view_bottom). | |||||||||
| D35C | LD B,A | |||||||||||
| D35D | LD A,(piece_page_y) | |||||||||||
| D360 | SUB B | |||||||||||
| D361 | LD B,A | |||||||||||
| D362 | LD A,(view_y) | |||||||||||
| D365 | CP B | |||||||||||
| D366 | JP C,after_step_drawn_2 | |||||||||||
| D369 | JP Z,column_at_view_bottom | |||||||||||
|
This entry point is used by the routines at column_at_view_bottom and column_at_view_top.
|
||||||||||||
| landscape_step_loop_2 | D36C | LD A,(piece_page_x) | Horizontal cull; the right-hand map cells are tested further on. | |||||||||
| D36F | LD B,A | |||||||||||
| D370 | LD A,(ground_cell) | |||||||||||
| D373 | BIT 1,A | |||||||||||
| D375 | JR NZ,landscape_step_loop_4 | |||||||||||
| D377 | LD A,(piece_rise) | A flat step of a left-hand cell whose screen x falls in $F1-$F6 (hanging off the left edge into the border) is drawn only if it is the piece's last, and then the flag last_step_in_border is set to $FF. Exactly $F0 is an edge case (column_at_view_left). | ||||||||||
| D37A | AND A | |||||||||||
| D37B | JR NZ,landscape_step_loop_3 | |||||||||||
| D37D | LD A,(origin_x) | |||||||||||
| D380 | ADD A,B | |||||||||||
| D381 | CP $F0 | |||||||||||
| D383 | JR C,landscape_step_loop_3 | |||||||||||
| D385 | JP Z,column_at_view_left | |||||||||||
| D388 | CP $F7 | |||||||||||
| D38A | JR NC,landscape_step_loop_3 | |||||||||||
| D38C | LD A,C | |||||||||||
| D38D | DEC A | |||||||||||
| D38E | JP NZ,after_step_drawn_2 | |||||||||||
| D391 | DEC A | |||||||||||
| D392 | LD (last_step_in_border),A | |||||||||||
| landscape_step_loop_3 | D395 | LD A,(piece_step_x) | Skip the step if it ends left of the left edge; exactly on it, column_at_view_left. | |||||||||
| D398 | ADD A,B | |||||||||||
| D399 | LD B,A | |||||||||||
| D39A | LD A,(view_x) | |||||||||||
| D39D | CP B | |||||||||||
| D39E | JP Z,column_at_view_left | |||||||||||
| D3A1 | JP NC,after_step_drawn_2 | |||||||||||
| D3A4 | JR landscape_step_loop_5 | |||||||||||
| landscape_step_loop_4 | D3A6 | LD A,(view_x) | Right-hand map cell: skip the step if it starts right of the right edge; exactly on it, column_at_view_right. | |||||||||
| D3A9 | CP B | |||||||||||
| D3AA | JP Z,column_at_view_right | |||||||||||
| D3AD | JP C,after_step_drawn_2 | |||||||||||
|
This entry point is used by the routines at column_at_view_left and column_at_view_right.
|
||||||||||||
| landscape_step_loop_5 | D3B0 | LD A,(edge_flags) | An edge flag set: off to the edge-case handlers. | |||||||||
| D3B3 | AND A | |||||||||||
| D3B4 | JR Z,landscape_step_loop_6 | |||||||||||
| D3B6 | CP $08 | |||||||||||
| D3B8 | JP Z,edge_column | |||||||||||
| D3BB | CP $04 | |||||||||||
| D3BD | JP Z,edge_column | |||||||||||
| D3C0 | CP $01 | |||||||||||
| D3C2 | JP Z,column_clipped | |||||||||||
| D3C5 | CP $02 | |||||||||||
| D3C7 | JP Z,column_clipped | |||||||||||
| D3CA | AND $0F | |||||||||||
| D3CC | JP NZ,column_clipped | |||||||||||
| D3CF | JP after_step_drawn_2 | |||||||||||
| landscape_step_loop_6 | D3D2 | LD E,(HL) | E = this step's variant (0, 1 or 2). | |||||||||
| D3D3 | LD A,(IX+$01) | Steps after the piece's first drawn one carry on from where the last blitter left HL. | ||||||||||
| D3D6 | AND A | |||||||||||
| D3D7 | JP NZ,landscape_step_loop_8 | |||||||||||
| D3DA | EXX | First drawn step: from the fine-scroll table (shift_table + 4 * direction) the blitter address into IY and the graphic address into piece_graphic. | ||||||||||
| D3DB | LD HL,(shift_table) | |||||||||||
| D3DE | LD E,(IX+$03) | |||||||||||
| D3E1 | LD D,$00 | |||||||||||
| D3E3 | SLA E | |||||||||||
| D3E5 | SLA E | |||||||||||
| D3E7 | ADD HL,DE | |||||||||||
| D3E8 | LD C,(HL) | |||||||||||
| D3E9 | INC HL | |||||||||||
| D3EA | LD B,(HL) | |||||||||||
| D3EB | INC HL | |||||||||||
| D3EC | PUSH BC | |||||||||||
| D3ED | POP IY | |||||||||||
| D3EF | LD C,(HL) | |||||||||||
| D3F0 | INC HL | |||||||||||
| D3F1 | LD B,(HL) | |||||||||||
| D3F2 | LD (piece_graphic),BC | |||||||||||
| D3F6 | LD A,(piece_rows) | Row pairs to draw = the step's height (piece_rows) / 2. | ||||||||||
| D3F9 | SRL A | |||||||||||
| D3FB | LD (half_rows),A | |||||||||||
| D3FE | CALL step_screen_address | Screen address of the step (step_screen_address), less the byte advance, into column_address. | ||||||||||
| D401 | LD A,(piece_dcolumn) | |||||||||||
| D404 | LD B,A | |||||||||||
| D405 | LD A,L | |||||||||||
| D406 | SUB B | |||||||||||
| D407 | LD L,A | |||||||||||
| D408 | LD (column_address),HL | |||||||||||
| D40B | LD DE,(offsets_start) | piece_offsets = this direction's row of variant offsets: offsets_start (graphic_offsets on a byte boundary, one byte on off it) + 6 * (direction mod 7). | ||||||||||
| D40F | LD A,(IX+$03) | |||||||||||
| D412 | CP $07 | |||||||||||
| D414 | JR C,landscape_step_loop_7 | |||||||||||
| D416 | SUB $07 | |||||||||||
| landscape_step_loop_7 | D418 | ADD A,A | ||||||||||
| D419 | LD H,A | |||||||||||
| D41A | ADD A,A | |||||||||||
| D41B | ADD A,H | |||||||||||
| D41C | LD L,A | |||||||||||
| D41D | LD H,$00 | |||||||||||
| D41F | ADD HL,DE | |||||||||||
| D420 | LD (piece_offsets),HL | |||||||||||
| D423 | EXX | D' = 0 steps drawn; the displacement of the JR at the end of slope_step_at_right_edge = 1 if the step is on a byte boundary, else 0 (mirrored_slope_far_right copies it too). | ||||||||||
| D424 | XOR A | |||||||||||
| D425 | LD D,A | |||||||||||
| D426 | LD ($D480),A | |||||||||||
| D429 | LD A,(IX+$00) | |||||||||||
| D42C | AND $07 | |||||||||||
| D42E | JR NZ,landscape_step_loop_8 | |||||||||||
| D430 | LD A,$01 | |||||||||||
| D432 | LD ($D480),A | |||||||||||
| landscape_step_loop_8 | D435 | LD A,(piece_dx_copy) | A vertical wall: once a step is drawn the rest go straight to the draw; before that piece_dx = -8 * direction. | |||||||||
| D438 | AND A | |||||||||||
| D439 | JR NZ,landscape_step_loop_9 | |||||||||||
| D43B | LD A,D | |||||||||||
| D43C | AND A | |||||||||||
| D43D | JP NZ,draw_step | |||||||||||
| D440 | LD A,(direction_flag) | |||||||||||
| D443 | NEG | |||||||||||
| D445 | ADD A,A | |||||||||||
| D446 | ADD A,A | |||||||||||
| D447 | ADD A,A | |||||||||||
| D448 | LD (piece_dx),A | |||||||||||
| landscape_step_loop_9 | D44B | XOR A | Default dispatch (the dispatch JR in draw_step): the step's own blitter. Flat steps: flat_step_clip. | |||||||||
| D44C | LD ($D702),A | |||||||||||
| D44F | LD A,(piece_rise) | |||||||||||
| D452 | AND A | |||||||||||
| D453 | JP Z,flat_step_clip | |||||||||||
| D456 | LD A,(piece_x) | A sloped step: near the right edge (screen x $D1 or more)? | ||||||||||
| D459 | CP $D1 | |||||||||||
| D45B | JP C,slope_step_at_left_edge | |||||||||||
| D45E | LD B,A | B = screen x, A = run in pixels. | ||||||||||
| D45F | LD A,(piece_dx) | |||||||||||
| landscape_step_loop_10 | D462 | JR landscape_step_loop_10 | Patched by set_piece_shape: displacement 0 for a piece running left, into slope_step_at_right_edge to negate the run first; 2 for one running right, past the NEG. | |||||||||
| Prev: D303 | Up: Map | Next: D464 |