dither4/dither4.s

238 lines
4 KiB
ArmAsm
Raw Normal View History

SAVMSC = $58
2022-11-25 19:51:27 +00:00
COLPF0 = $D016
COLPF1 = $D017
COLPF2 = $D018
COLPF3 = $D019
COLBK = $D01A
2022-11-30 07:59:38 +00:00
AUDC1 = $D201
2022-11-29 20:59:26 +00:00
DMACTL = $D400
2022-11-29 22:54:02 +00:00
DLISTL = $D402
DLISTH = $D403
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
2022-11-30 07:59:38 +00:00
sample_ptrl = $84
sample_ptrh = $85
sample_ptr = sample_ptrl
2022-11-30 11:04:31 +00:00
scanline = $86
2022-11-26 16:48:01 +00:00
height = 192
bytes_per_line = 40
pages_per_frame = 32
2022-11-30 07:59:38 +00:00
lines_per_frame = 262
2022-11-30 11:04:31 +00:00
scanline_offset = 31
scanline_max = (lines_per_frame - scanline_offset) / 2
2022-11-26 16:48:01 +00:00
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-30 07:59:38 +00:00
.import audio_samples
.import audio_samples_end
2022-11-25 19:51:27 +00:00
displaylist:
; 24 lines overscan
2022-11-25 19:51:27 +00:00
.repeat 3
.byte $70 ; 8 blank lines
.endrep
; 192 lines graphics
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-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)
2022-11-30 07:59:38 +00:00
sta temp2l
2022-11-26 16:48:01 +00:00
lda #.hibyte(framebuffer)
sta temp2h
jsr copy_half_frame
; Second half of bitmap has to be separately aligned
lda #.lobyte(framebuffer2)
2022-11-30 07:59:38 +00:00
sta temp2l
2022-11-26 16:48:01 +00:00
lda #.hibyte(framebuffer2)
sta temp2h
jsr copy_half_frame
2022-11-30 07:59:38 +00:00
; Set up the audio sample buffer
lda #.lobyte(audio_samples)
sta sample_ptrl
lda #.hibyte(audio_samples)
sta sample_ptrh
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-29 22:54:02 +00:00
; Disable VBI and DLI but allow Reset
lda #32
sta NMIEN
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-29 22:54:02 +00:00
sta DLISTL
2022-11-26 01:35:10 +00:00
lda #.hibyte(displaylist)
2022-11-29 22:54:02 +00:00
sta DLISTH
2022-11-25 19:51:27 +00:00
; Manually wait for first scan line
wait_vblank:
2022-11-30 11:04:31 +00:00
sta WSYNC
2022-11-25 19:51:27 +00:00
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
2022-11-30 00:32:37 +00:00
wait_start:
2022-11-30 11:04:31 +00:00
; Wait for the vblank
; Resynchronize the scanline counter
2022-11-30 07:59:38 +00:00
wait_loop:
lda VCOUNT
2022-11-30 11:04:31 +00:00
bne wait_loop
lda #(256 - scanline_offset)
sta scanline
2022-11-26 03:17:34 +00:00
each_scanline:
2022-11-30 07:59:38 +00:00
.macro inner_scanline
2022-11-30 12:52:40 +00:00
; it'll fire on unused lines, but harmlessly
ldy scanline ; 3 cyc
inc scanline ; 5 cyc
2022-11-30 11:04:31 +00:00
2022-11-30 07:59:38 +00:00
; Leisurely memory fetches
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
.endmacro
2022-11-30 12:52:40 +00:00
.macro audio_play
ldy VCOUNT ; 4 cycles
lda (sample_ptr),y ; 5/6 cyc
sta AUDC1 ; 4 cyc
.endmacro
2022-11-30 07:59:38 +00:00
inner_scanline
2022-11-30 12:04:24 +00:00
audio_play
2022-11-30 07:59:38 +00:00
2022-11-30 11:39:23 +00:00
.macro audio_inc
; Increment sample ptr
2022-11-30 12:52:40 +00:00
clc
lda sample_ptrl
adc #130
sta sample_ptrl
2022-11-30 11:39:23 +00:00
lda sample_ptrh
2022-11-30 12:52:40 +00:00
adc #0
sta sample_ptrh
2022-11-30 11:39:23 +00:00
cmp #.hibyte(audio_samples_end)
bne audio_cont
;lda sample_ptrl
;cmp #.lobyte(audio_samples_end)
;bne audio_cont
2022-11-30 11:39:23 +00:00
lda #.lobyte(audio_samples)
sta sample_ptrl
lda #.hibyte(audio_samples)
sta sample_ptrh
2022-11-30 12:01:55 +00:00
audio_cont:
2022-11-30 11:39:23 +00:00
.endmacro
2022-11-30 11:36:25 +00:00
2022-11-30 07:59:38 +00:00
inner_scanline
2022-11-26 03:17:34 +00:00
2022-11-30 11:04:31 +00:00
lda VCOUNT
2022-11-30 11:36:25 +00:00
cmp #130 ;#130
2022-11-30 11:39:23 +00:00
bne each_scanline
2022-11-30 12:52:40 +00:00
audio_inc
2022-11-30 11:04:31 +00:00
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