test.sfc: test.o
ld65 -o $@ -m link.map -C snes.ld $<
-test.o: test.asm hwregs.inc data.inc
+test.o: test.asm hwregs.inc data.inc sintab.inc
%.o: %.asm
ca65 -o $@ --cpu 65816 $<
data.inc: logo4bpp.png img2snes/img2snes
- img2snes/img2snes -o data.inc logo4bpp.png
+ img2snes/img2snes -o $@ logo4bpp.png
+
+sintab.inc: sintab/sintab
+ sintab/sintab >$@
img2snes/img2snes:
$(MAKE) -C img2snes
+sintab/sintab:
+ $(MAKE) -C sintab
+
.PHONY: clean
clean:
rm -f test.sfc test.o
.segment "rodata"
.include "data.inc"
+ .include "sintab.inc"
.segment "code"
+ .macro A16
+ rep #$20
+ .a16
+ .endmacro
+ .macro A8
+ sep #$20
+ .a8
+ .endmacro
+
; VMEM map
; 0000: tilemap for BG1 (32x32 4bpp: 512b)
; 2048: BG3-base (h/v offsets)
; 8192: tile data (16k)
-
vmem_tiles_offs = 4096 ; 4k words
- hoffs_offs = 1024 ; 2k words
+ vmem_hoffs_offs = 1024 ; 2k words
+ vmem_voffs_offs = vmem_hoffs_offs + 32
sei
clc
.i8
jsr snes_init
+ setreg REG_SETINI, $4 ; 239 lines
setreg REG_BGMODE, $02 ; mode 2, 8x8 tiles
setreg REG_BG12NBA, $1 ; tiles at offs 8kb
setreg REG_TM, $1 ; main screen: BG1
+ setreg REG_BG3SC, (vmem_hoffs_offs / 1024) << 2
ldx #0
cmap_loop:
pea logo4bpp_tiles
pea vmem_tiles_offs
jsr copy_vmem
- rep #$20
- .a16
+ A16
pla
pla
pla
- sep #$20
- .a8
+ A8
pea logo4bpp_tilemap_rows * logo4bpp_tilemap_cols * 2
pea logo4bpp_tilemap
pea 0
jsr copy_vmem
- rep #$20
- .a16
+ A16
pla
pla
pla
- sep #$20
- .a8
+ A8
fblank 0
-halt:
- jmp halt
+ ; main loop
+ nframe = 0
+ ncol = 2
+ anim = 4
+
+ A16
+ stz nframe
+ A8
+mainloop:
+ wait_vblank
+
+ A16
+ lda nframe
+ lsr
+ lsr
+ sta anim
+ inc nframe
+ A8
+
+ lda #(vmem_voffs_offs & $ff)
+ sta REG_VMADDL
+ lda #(vmem_voffs_offs >> 8)
+ sta REG_VMADDH
+
+ stz ncol
+@cloop:
+ lda anim
+ clc
+ adc ncol
+ asl
+ tax
+ lda sintab,x
+ lsr
+ lsr
+ lsr
+
+ ldx ncol
+ bne @per_tile_offs
+ ; global scroll for the first column
+ sta REG_BG1VOFFS
+ stz REG_BG1VOFFS
+ bra @end
+
+@per_tile_offs:
+ sta REG_VMDATAL
+ lda #$20 ; enable for BG1
+ sta REG_VMDATAH
+@end:
+
+ inc ncol
+ lda ncol
+ and #$1f
+ bne @cloop
+
+ bra mainloop
; copy_vmem(vmem_offset, src, num_words)
copy_vmem: