dither4/dither4.s

91 lines
1.4 KiB
ArmAsm

SAVMSC = $58
SDMCTL = $22F
SDLSTL = $230
SDLSTH = $231
COLPF0 = $D016
COLPF1 = $D017
COLPF2 = $D018
COLPF3 = $D019
COLBK = $D01A
WSYNC = $D40A
VCOUNT = $D40B
NMIEN = $D40E
.data
.import palette1
.import palette2
.import palette3
.import framebuffer
displaylist:
.repeat 3
.byte $70 ; 8 blank lines
.endrep
.byte $4e ; ANTIC mode e (160px 2bpp, 1 scan line per line)
.addr framebuffer
.repeat 191
.byte $0e
.endrep
.byte $41 ; jump and blank
.addr displaylist
.code
.export start
; Loop through scan lines updating the palette
.proc update_palette
lda palette1,y
pha
ldx palette2,y
lda palette3,y
tay
pla
; Wait for horizontal blank
sta WSYNC
; Update color registers as fast as possible
sta COLPF0
stx COLPF1
sty COLPF2
rts
.endproc
.proc start
; Disable display DMA
lda #$00
sta SDMCTL
; Set up the display list
lda #.lobyte(displaylist)
sta SDLSTL
lda #.hibyte(displaylist)
sta SDLSTH
; Turn off interrupts except reset button
lda #$20
sta NMIEN
; Manually wait for first scan line
wait_vblank:
lda VCOUNT
bne wait_vblank
; Re-enable display DMA
lda #$22
sta SDMCTL
even_scanline:
ldy VCOUNT
jsr update_palette
odd_scanline:
ldy VCOUNT
iny
jsr update_palette
jmp even_scanline
.endproc