← BB11 Compute an object's back-buffer address from its pixel position Map BBA4 → Blit dirty cells to the display and age their counters
BB38: Recompose flagged cells into the back buffer
Recomposes every flagged work-buffer cell into the back buffer. The scan skips the top three character rows, which are static, as the blit does.
recompose_cells BB38 LD HL,WORKBUF_FB+$5F Start one cell before the first scanned playfield cell; the loop's INC HL lands on it.
BB3B XOR A Clear the accumulator for the flag test.
recompose_next_cell BB3C INC HL Advance to the next cell; a zero flag is a clean cell – skip it.
BB3D OR (HL)
BB3E JP Z,recompose_next_cell
BB41 INC A The $FF terminator wraps to 0 here, and the scan ends
BB42 RET Z
BB43 PUSH HL Save the work-buffer pointer.
BB44 DEC H Drop 3 pages to the same cell in the tile map.
BB45 DEC H
BB46 DEC H
BB47 LD A,(HL) Read the cell's tile code.
BB48 CP $20 The empty tile erases the cell – take the clear path.
BB4A JP Z,erase_cell
BB4D PUSH HL Save the tile pointer.
BB4E LD L,A Point HL at the tile's glyph in the tile set, 8 bytes per tile.
BB4F LD H,$00
BB51 ADD HL,HL
BB52 ADD HL,HL
BB53 ADD HL,HL
BB54 LD DE,sprite_mirror_lut
BB57 ADD HL,DE
BB58 LD B,H Move the glyph source into BC.
BB59 LD C,L
BB5A POP HL Restore the tile pointer.
BB5B LD A,H Turn the tile page into the back-buffer page of the cell's top pixel row. The low byte keeps the column.
BB5C AND $03
BB5E RLCA
BB5F RLCA
BB60 RLCA
BB61 ADD A,BACKBUF_BASE/$100
BB63 LD H,A
BB64 LD A,(BC) Copy the 8 glyph rows into the back buffer.
BB65 LD (HL),A
BB66 INC BC
BB67 INC H
BB68 LD A,(BC)
BB69 LD (HL),A
BB6A INC BC
BB6B INC H
BB6C LD A,(BC)
BB6D LD (HL),A
BB6E INC BC
BB6F INC H
BB70 LD A,(BC)
BB71 LD (HL),A
BB72 INC BC
BB73 INC H
BB74 LD A,(BC)
BB75 LD (HL),A
BB76 INC BC
BB77 INC H
BB78 LD A,(BC)
BB79 LD (HL),A
BB7A INC BC
BB7B INC H
BB7C LD A,(BC)
BB7D LD (HL),A
BB7E INC BC
BB7F INC H
BB80 LD A,(BC)
BB81 LD (HL),A
BB82 POP HL Restore the work-buffer pointer.
BB83 XOR A Resume the scan with the flag accumulator cleared. The flag stays set for the blit to age by one.
BB84 JP recompose_next_cell
erase_cell BB87 LD A,H Build the same back-buffer page from the tile pointer.
BB88 AND $03
BB8A RLCA
BB8B RLCA
BB8C RLCA
BB8D ADD A,BACKBUF_BASE/$100
BB8F LD H,A
BB90 XOR A Zero fill value
BB91 LD (HL),A Erase the cell: zero its 8 back-buffer rows.
BB92 INC H
BB93 LD (HL),A
BB94 INC H
BB95 LD (HL),A
BB96 INC H
BB97 LD (HL),A
BB98 INC H
BB99 LD (HL),A
BB9A INC H
BB9B LD (HL),A
BB9C INC H
BB9D LD (HL),A
BB9E INC H
BB9F LD (HL),A
BBA0 POP HL Restore the work-buffer pointer.
BBA1 JP recompose_next_cell
← BB11 Compute an object's back-buffer address from its pixel position Map BBA4 → Blit dirty cells to the display and age their counters
Fork me on GitHub