2022-11-20 23:43:34 +00:00
|
|
|
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
|
|
|
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-12-08 00:35:07 +00:00
|
|
|
audiotemp = $87
|
2022-11-26 16:48:01 +00:00
|
|
|
|
2022-11-30 16:53:47 +00:00
|
|
|
height = 160
|
2022-11-26 16:48:01 +00:00
|
|
|
bytes_per_line = 40
|
|
|
|
pages_per_frame = 32
|
2022-11-30 07:59:38 +00:00
|
|
|
lines_per_frame = 262
|
2022-11-30 16:53:47 +00:00
|
|
|
;scanline_offset = 31 + (40 - 24) / 2
|
|
|
|
scanline_offset = 47
|
2022-11-30 11:04:31 +00:00
|
|
|
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
|
|
|
|
|
2022-11-30 07:59:38 +00:00
|
|
|
.import audio_samples
|
|
|
|
.import audio_samples_end
|
2022-11-25 19:51:27 +00:00
|
|
|
|
2022-12-08 02:20:24 +00:00
|
|
|
.import frame1_top
|
|
|
|
.import frame1_bottom
|
|
|
|
.import frame1_palette1
|
|
|
|
.import frame1_palette2
|
|
|
|
.import frame1_palette3
|
|
|
|
.import frame2_top
|
|
|
|
.import frame2_bottom
|
|
|
|
.import frame2_palette1
|
|
|
|
.import frame2_palette2
|
|
|
|
.import frame2_palette3
|
|
|
|
|
2022-11-25 19:51:27 +00:00
|
|
|
displaylist:
|
2022-11-30 16:53:47 +00:00
|
|
|
; 40 lines overscan
|
|
|
|
.repeat 5
|
2022-11-25 19:51:27 +00:00
|
|
|
.byte $70 ; 8 blank lines
|
|
|
|
.endrep
|
2022-11-29 23:10:56 +00:00
|
|
|
|
2022-11-30 16:53:47 +00:00
|
|
|
; 160 lines graphics
|
2022-11-26 03:17:34 +00:00
|
|
|
; ANTIC mode e (160px 2bpp, 1 scan line per line)
|
|
|
|
.byte $4e
|
2022-12-08 02:20:24 +00:00
|
|
|
.addr frame1_top
|
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-12-08 02:20:24 +00:00
|
|
|
.addr frame1_bottom
|
2022-11-26 16:48:01 +00:00
|
|
|
.repeat height / 2 - 1
|
2022-11-25 19:51:27 +00:00
|
|
|
.byte $0e
|
|
|
|
.endrep
|
2022-11-29 23:10:56 +00:00
|
|
|
|
2022-12-08 01:11:22 +00:00
|
|
|
.byte $41 ; jump and blank
|
2022-12-08 02:25:27 +00:00
|
|
|
.addr displaylist
|
2022-12-08 01:11:22 +00:00
|
|
|
|
2022-12-08 02:25:27 +00:00
|
|
|
;fixme use
|
2022-12-08 01:11:22 +00:00
|
|
|
displaylist_part2:
|
|
|
|
; 40 lines overscan
|
|
|
|
.repeat 5
|
|
|
|
.byte $70 ; 8 blank lines
|
|
|
|
.endrep
|
|
|
|
|
|
|
|
; 160 lines graphics
|
|
|
|
; ANTIC mode e (160px 2bpp, 1 scan line per line)
|
|
|
|
.byte $4e
|
2022-12-08 02:20:24 +00:00
|
|
|
.addr frame2_top
|
2022-12-08 01:11:22 +00:00
|
|
|
.repeat height / 2 - 1
|
|
|
|
.byte $0e
|
|
|
|
.endrep
|
|
|
|
.byte $4e
|
2022-12-08 02:20:24 +00:00
|
|
|
.addr frame2_bottom
|
2022-12-08 01:11:22 +00:00
|
|
|
.repeat height / 2 - 1
|
|
|
|
.byte $0e
|
|
|
|
.endrep
|
|
|
|
|
2022-11-25 19:51:27 +00:00
|
|
|
.byte $41 ; jump and blank
|
|
|
|
.addr displaylist
|
|
|
|
|
2022-12-08 01:11:22 +00:00
|
|
|
|
2022-12-08 00:35:07 +00:00
|
|
|
audio_high_byte:
|
|
|
|
.scope
|
|
|
|
.macro byteseq val
|
|
|
|
.repeat 16
|
|
|
|
.byte val | $10
|
|
|
|
.endrep
|
|
|
|
.endmacro
|
|
|
|
byteseq $0
|
|
|
|
byteseq $1
|
|
|
|
byteseq $2
|
|
|
|
byteseq $3
|
|
|
|
byteseq $4
|
|
|
|
byteseq $5
|
|
|
|
byteseq $7
|
|
|
|
byteseq $8
|
|
|
|
byteseq $9
|
|
|
|
byteseq $a
|
|
|
|
byteseq $b
|
|
|
|
byteseq $c
|
|
|
|
byteseq $d
|
|
|
|
byteseq $e
|
|
|
|
byteseq $f
|
|
|
|
.endscope
|
2022-11-20 23:43:34 +00:00
|
|
|
|
|
|
|
.code
|
|
|
|
|
|
|
|
.export start
|
|
|
|
|
|
|
|
.proc start
|
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
|
2022-12-08 02:20:24 +00:00
|
|
|
lda #$20
|
2022-11-29 22:54:02 +00:00
|
|
|
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-12-08 00:35:07 +00:00
|
|
|
tay ; save for audio lookup
|
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-12-08 00:35:07 +00:00
|
|
|
.macro audio_prep
|
2022-12-08 00:43:45 +00:00
|
|
|
; Y is VCOUNT at entry
|
2022-12-08 00:35:07 +00:00
|
|
|
lda (sample_ptr),y ; 5/6 cyc
|
|
|
|
sta audiotemp ; 3 cyc
|
|
|
|
.endmacro
|
|
|
|
|
2022-12-08 02:20:24 +00:00
|
|
|
.macro inner_scanline frame_base
|
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
|
2022-12-08 02:20:24 +00:00
|
|
|
lda frame1_palette1,y ; 5 @FIXME alternate
|
|
|
|
pha ; ...3?
|
|
|
|
ldx frame1_palette2,y ; 5
|
|
|
|
lda frame1_palette3,y ; 5
|
2022-11-30 07:59:38 +00:00
|
|
|
tay
|
|
|
|
pla
|
|
|
|
|
|
|
|
; Wait for horizontal blank
|
|
|
|
sta WSYNC
|
|
|
|
|
|
|
|
; Update color registers as fast as possible
|
|
|
|
sta COLPF0
|
|
|
|
stx COLPF1
|
|
|
|
sty COLPF2
|
|
|
|
.endmacro
|
|
|
|
|
2022-12-08 00:35:07 +00:00
|
|
|
.macro audio_play_lo ; 11 cycles
|
|
|
|
lda audiotemp ; 3 cyc
|
2022-12-08 02:20:24 +00:00
|
|
|
and #$0f ; 2 cyc
|
|
|
|
ora #$10 ; 2 cyc
|
2022-11-30 12:52:40 +00:00
|
|
|
sta AUDC1 ; 4 cyc
|
|
|
|
.endmacro
|
|
|
|
|
2022-12-08 00:35:07 +00:00
|
|
|
.macro audio_play_hi ; 12 cycles
|
|
|
|
ldy audiotemp ; 3 cyc
|
|
|
|
lda audio_high_byte,y ; 5 cyc
|
|
|
|
sta AUDC1 ; 4 cyc
|
|
|
|
.endmacro
|
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
|
|
|
|
|
2022-11-30 12:30:46 +00:00
|
|
|
;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-12-08 01:11:22 +00:00
|
|
|
;audio_prep
|
2022-12-08 00:35:07 +00:00
|
|
|
inner_scanline
|
2022-12-08 01:11:22 +00:00
|
|
|
;audio_play_lo
|
2022-11-30 07:59:38 +00:00
|
|
|
inner_scanline
|
2022-12-08 00:43:45 +00:00
|
|
|
;audio_play_hi
|
2022-11-26 03:17:34 +00:00
|
|
|
|
2022-11-30 11:04:31 +00:00
|
|
|
lda VCOUNT
|
2022-12-08 00:43:45 +00:00
|
|
|
tay ; save for audio lookup
|
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
|
|
|
|
2022-11-20 23:43:34 +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
|