← 96EB Blank the safety net band Map 97BD → Side-wall tile pattern
9731: Compose the level's brick field into the tile map
Composes the current level's brick field into the tile map, once at level start.
Each slot code becomes a 2×2 group of tile codes and one attribute byte.
The bricks reach the screen only through the tile-map render.
The grid is 9×9 slots, each 2×2 characters. It spans the playfield's full height, rows 4 to 21, and 18 of its columns.
The field sits against the wall opposite the bat.
compose_brick_field 9731 LD A,(bat_side) Read the bat side: 0 for the right, non-zero for the left.
9734 OR A
9735 JR Z,bat_on_right
9737 LD HL,TILEMAP_BASE+$9C Bat on the left: anchor the grid at tile-map row 4, column 28.
973A LD (compose_grid+$2),HL Store the anchor as the grid's start cell, in the operand of the LD HL below.
973D LD HL,$2D2D Patch the per-cell column step to DEC L,DEC L: cells advance 2 columns leftward.
9740 LD (smc_grid_col_step),HL
9743 JR seek_layout
bat_on_right 9745 LD HL,TILEMAP_BASE+$82 Bat on the right: anchor the grid at tile-map row 4, column 2.
9748 LD (compose_grid+$2),HL Store the anchor as the grid's start cell.
974B LD HL,$2C2C Patch the per-cell column step to INC L,INC L: cells advance 2 columns rightward.
974E LD (smc_grid_col_step),HL
seek_layout 9751 LD A,(level) Index this level's slot layout by the level index.
9754 LD HL,level_layouts Base of the slot-layout table.
9757 OR A Level 0 uses the table base unchanged.
9758 JR Z,compose_grid
975A LD B,A Layouts are 81 bytes each (a 9×9 grid of slot codes); skip the layouts of earlier levels.
975B LD DE,$0051
seek_layout_loop 975E ADD HL,DE Step past one layout per earlier level. HL then points at this level's layout.
975F DJNZ seek_layout_loop
compose_grid 9761 EX DE,HL Point DE at the first slot code of this level's layout.
9762 LD HL,$0000 Point HL at the anchor cell. The bat-side setup above patches the operand.
9765 LD B,$09 Walk the grid's rows of bricks.
next_brick_row 9767 PUSH BC Save the row counter and this row's start cell.
9768 PUSH HL
9769 LD B,$09 Walk this row's bricks.
next_brick_cell 976B PUSH BC Save the slot counter, the layout pointer, and this cell's tile-map address.
976C PUSH DE
976D PUSH HL
976E LD A,(DE) Read this cell's code; keep a copy in A' for the attribute lookup.
976F EX AF,AF'
9770 LD A,(DE) Look up the slot code's four tile codes in the brick tile-glyph groups, 4 bytes per code, and point DE at them. They are the slot's tiles in row order.
9771 LD L,A
9772 LD H,$00
9774 ADD HL,HL
9775 ADD HL,HL
9776 LD DE,brick_tile_groups
9779 ADD HL,DE
977A EX DE,HL
977B POP HL Recover this cell's address (the top-left character of the 2×2 block).
977C PUSH HL
977D LD A,(DE) Write the cell's top row: the top-left tile, then the top-right one in the next column. Then step down one tile-map row.
977E LD (HL),A
977F INC L
9780 INC DE
9781 LD A,(DE)
9782 LD (HL),A
9783 INC DE
9784 DEC L
9785 CALL advance_buffer_row
9788 LD A,(DE) Write the bottom row: the bottom-left tile, then the bottom-right one in the next column.
9789 LD (HL),A
978A INC L
978B INC DE
978C LD A,(DE)
978D LD (HL),A
978E POP HL Recover the cell address for the attribute pass.
978F PUSH HL
9790 LD A,H Map the tile-map page to the attribute page of the same cell; the shared low byte keeps the same cell.
9791 AND $03
9793 ADD A,$58
9795 LD H,A
9796 PUSH HL Look up the cell's attribute by code in the brick attributes, into C.
9797 EX AF,AF'
9798 LD E,A
9799 LD D,$00
979B LD HL,brick_attrs
979E ADD HL,DE
979F LD C,(HL)
97A0 POP HL
97A1 LD (HL),C Paint all four attribute cells of the 2×2 block with C.
97A2 INC L
97A3 LD (HL),C
97A4 CALL advance_buffer_row
97A7 LD (HL),C
97A8 DEC L
97A9 LD (HL),C
97AA POP HL Recover the cell address.
smc_grid_col_step 97AB INC L Self-modified per-cell column step, this byte and the next, patched by the bat-side setup. Both are INC L to advance 2 columns right, or both DEC L to advance left.
97AC INC L
97AD POP DE Restore the layout pointer and step to the next slot code.
97AE INC DE
97AF POP BC Loop for the 9 cells across this row.
97B0 DJNZ next_brick_cell
97B2 POP HL Recover this row's start cell.
97B3 CALL advance_buffer_row Step down 2 tile-map rows to the next cell row (each cell is 2 rows tall).
97B6 CALL advance_buffer_row
97B9 POP BC Loop for the 9 cell rows.
97BA DJNZ next_brick_row
97BC RET
← 96EB Blank the safety net band Map 97BD → Side-wall tile pattern
Fork me on GitHub