dither4/dither4.s

184 lines
2.7 KiB
ArmAsm
Raw Normal View History

SAVMSC = $58
2022-11-25 19:51:27 +00:00
SDMCTL = $22F
SDLSTL = $230
SDLSTH = $231
COLPF0 = $D016
COLPF1 = $D017
COLPF2 = $D018
COLPF3 = $D019
COLBK = $D01A
2022-11-29 20:59:26 +00:00
DMACTL = $D400
2022-11-25 19:51:27 +00:00
WSYNC = $D40A
VCOUNT = $D40B
NMIEN = $D40E
2022-11-26 16:48:01 +00:00
framebuffer = $a000
framebuffer2 = $b000
temp1l = $80
temp1h = $81
temp1 = temp1l
temp2l = $82
temp2h = $83
temp2 = temp2l
height = 192
bytes_per_line = 40
pages_per_frame = 32
2022-11-25 19:51:27 +00:00
.data
.import palette1
.import palette2
.import palette3
2022-11-26 16:48:01 +00:00
.import bitmap
2022-11-25 19:51:27 +00:00
displaylist:
2022-11-26 03:17:34 +00:00
; @fixme resolve the line counts
2022-11-25 19:51:27 +00:00
.repeat 3
.byte $70 ; 8 blank lines
.endrep
2022-11-26 03:17:34 +00:00
; ANTIC mode e (160px 2bpp, 1 scan line per line)
.byte $4e
2022-11-25 19:51:27 +00:00
.addr framebuffer
2022-11-26 16:48:01 +00:00
.repeat height / 2 - 1
2022-11-26 03:17:34 +00:00
.byte $0e
.endrep
.byte $4e
2022-11-26 16:48:01 +00:00
.addr framebuffer2
.repeat height / 2 - 1
2022-11-25 19:51:27 +00:00
.byte $0e
.endrep
2022-11-29 14:29:56 +00:00
.repeat 3
.byte $70 ; 8 blank lines
.endrep
2022-11-25 19:51:27 +00:00
.byte $41 ; jump and blank
.addr displaylist
.code
.export start
.proc start
2022-11-26 16:48:01 +00:00
; Copy the bitmap into our framebuffer
lda #.lobyte(bitmap)
sta temp1l
lda #.hibyte(bitmap)
sta temp1h
lda #.lobyte(framebuffer)
sta temp2h
lda #.hibyte(framebuffer)
sta temp2h
jsr copy_half_frame
; Second half of bitmap has to be separately aligned
lda #.lobyte(framebuffer2)
sta temp2h
lda #.hibyte(framebuffer2)
sta temp2h
jsr copy_half_frame
2022-11-25 19:51:27 +00:00
; Disable display DMA
lda #$00
2022-11-29 20:59:26 +00:00
sta DMACTL
2022-11-26 16:48:01 +00:00
2022-11-25 19:51:27 +00:00
; Set up the display list
2022-11-26 01:35:10 +00:00
lda #.lobyte(displaylist)
2022-11-25 19:51:27 +00:00
sta SDLSTL
2022-11-26 01:35:10 +00:00
lda #.hibyte(displaylist)
2022-11-25 19:51:27 +00:00
sta SDLSTH
; Manually wait for first scan line
wait_vblank:
lda VCOUNT
2022-11-26 01:35:10 +00:00
bne wait_vblank
2022-11-25 19:51:27 +00:00
; Re-enable display DMA
lda #$22
2022-11-29 20:59:26 +00:00
sta DMACTL
; Disable VBI and DLI but allow Reset
lda #32
sta NMIEN
2022-11-25 19:51:27 +00:00
2022-11-29 19:45:29 +00:00
wait_loop:
sta WSYNC
2022-11-29 19:45:29 +00:00
wait_start:
2022-11-26 03:17:34 +00:00
lda VCOUNT
cmp #15
2022-11-29 19:45:29 +00:00
bne wait_loop
2022-11-26 03:17:34 +00:00
ldy #0
each_scanline:
tya
pha
2022-11-25 19:51:27 +00:00
2022-11-26 03:17:34 +00:00
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
pla
tay
iny
2022-11-26 16:48:01 +00:00
cpy height
2022-11-26 03:17:34 +00:00
bne each_scanline
jmp wait_start
2022-11-25 19:51:27 +00:00
.endproc
2022-11-26 03:17:34 +00:00
2022-11-26 16:48:01 +00:00
; temp1 contains source address
; temp2 contains dest address
; clobbers a/x/y
; incremepts temp1 and temp2 to the end of their regions
.proc copy_half_frame
ldx #0
copy_loop_lines:
ldy #00
copy_loop_bytes:
lda (temp1),y
sta (temp2),y
iny
cpy #bytes_per_line
bne copy_loop_bytes
clc
lda temp1l
adc #bytes_per_line
sta temp1l
lda temp1h
adc #00
sta temp1h
clc
lda temp2l
adc #bytes_per_line
sta temp2l
lda temp2h
adc #00
sta temp2h
inx
cpx #(height / 2)
bne copy_loop_lines
2022-11-26 03:17:34 +00:00
rts
.endproc