; 04-tiles.s - a scrolling tile layer: two register writes a frame, no copying ; ; cl65 -t c64 -C c64-asm.cfg -u __EXEHDR__ --asm-include-dir ../include -o 04-tiles.prg 04-tiles.s .include "vicx.inc" .include "vicxlib.inc" MAP = $0000 ; 32 x 32 entries x 2 bytes = 2 KB of VRAM TILES = $4000 ; 8-bit 8x8 tiles, 64 bytes each CLRSCR = $E544 ; KERNAL: clear the text screen sx = $FB ; two free zero-page bytes row = $FD .code jsr CLRSCR ; start with an empty text screen sei VICX_UNLOCK_SEQ lda VICX_ID0 cmp #$56 beq found cli rts found: SET_PAL 16, 30, 40, 110 SET_PAL 17, 70, 90, 190 SET_PAL 18, 250, 212, 64 ; Tile 0 stays empty (color 0 is transparent). Tile 1 is a framed ; block, tile 2 a plain one. VICX_P0_SET TILES + 64, VICX_STEP_1 ldx #0 t1: cpx #8 ; top row? bcc edge txa and #7 ; left column? beq edge lda #17 bne put edge: lda #18 put: sta VICX_P0_DATA inx cpx #64 bne t1 lda #16 ; tile 2: 64 bytes of color 16 P0_FILL 64 ; The map: a chequerboard of tiles 1 and 2. Entries are 16 bits. VICX_P0_SET MAP, VICX_STEP_1 lda #0 sta row mrow: ldx #0 mcol: txa eor row and #1 clc adc #1 ; tile 1 or 2 sta VICX_P0_DATA lda #0 ; no flips, bank 0 sta VICX_P0_DATA inx cpx #32 bne mcol inc row lda row cmp #32 bne mrow LAYER_SET VICX_LAYER0, VICX_LMODE_TILE8, VICX_MAP_W32 | VICX_MAP_H32, MAP, TILES, 0, 0, 0, 0 lda #VICX_CTRL_L0 | VICX_CTRL_BGTRANS sta VICX_CTRL lda #0 sta sx sta sx+1 loop: lda VICX_FRAME ; wait for the next frame wait: cmp VICX_FRAME beq wait inc sx bne :+ inc sx+1 : VICX_P0_SET VICX_LAYER0 + VICX_L_SCROLLX, VICX_STEP_1 lda sx ; scroll X, 12 bits, wraps round the map sta VICX_P0_DATA lda sx+1 sta VICX_P0_DATA lda sx+1 ; scroll Y at half the speed lsr tax lda sx ror sta VICX_P0_DATA stx VICX_P0_DATA jmp loop ; runs until reset