WIP refactoring

This commit is contained in:
Brooke Vibber 2022-12-10 13:01:29 -08:00
parent 60ceb48ec6
commit 53026bbfdd
2 changed files with 91 additions and 43 deletions

View file

@ -654,6 +654,14 @@ function byte2byte(arr) {
return lines.join('\n'); return lines.join('\n');
} }
//let [even, odd] = [0, 1].map((bit) => (arr) => arr.filter((_item, index) => (index & 1) === bit));
function even(arr) {
return arr.filter((_item, index) => !(index & 1));
}
function odd(arr) {
return arr.filter((_item, index) => (index & 1));
}
function genAssembly(width, height, nbits, lines, reps) { function genAssembly(width, height, nbits, lines, reps) {
let linesEach = height / reps; let linesEach = height / reps;
let stride = width * nbits / 8; let stride = width * nbits / 8;
@ -684,14 +692,20 @@ function genAssembly(width, height, nbits, lines, reps) {
return `.data return `.data
.export frame1_top .export frame1_top
.export frame1_bottom .export frame1_bottom
.export frame1_palette1 .export frame1_palette1_even
.export frame1_palette2 .export frame1_palette1_odd
.export frame1_palette3 .export frame1_palette2_even
.export frame1_palette2_odd
.export frame1_palette3_even
.export frame1_palette3_odd
.export frame2_top .export frame2_top
.export frame2_bottom .export frame2_bottom
.export frame2_palette1 .export frame2_palette1_even
.export frame2_palette2 .export frame2_palette1_odd
.export frame2_palette3 .export frame2_palette2_even
.export frame2_palette2_odd
.export frame2_palette3_even
.export frame2_palette3_odd
.export displaylist .export displaylist
.segment "BUFFERS" .segment "BUFFERS"
@ -700,17 +714,29 @@ function genAssembly(width, height, nbits, lines, reps) {
frame1_top: frame1_top:
${byte2byte(frames[0].bitmap.slice(0, half))} ${byte2byte(frames[0].bitmap.slice(0, half))}
.align 256 .align 128
frame1_palette1: frame1_palette1_even:
${byte2byte(frames[0].palette1)} ${byte2byte(even(frames[0].palette1))}
.align 256 .align 128
frame1_palette2: frame1_palette1_odd:
${byte2byte(frames[0].palette2)} ${byte2byte(odd(frames[0].palette1))}
.align 256 .align 128
frame1_palette3: frame1_palette2_even:
${byte2byte(frames[0].palette3)} ${byte2byte(even(frames[0].palette2))}
.align 128
frame1_palette2_odd:
${byte2byte(odd(frames[0].palette2))}
.align 128
frame1_palette3_even:
${byte2byte(even(frames[0].palette3))}
.align 128
frame1_palette3_odd:
${byte2byte(odd(frames[0].palette3))}
.align 4096 .align 4096
frame1_bottom: frame1_bottom:
@ -722,17 +748,29 @@ ${byte2byte(frames[0].bitmap.slice(half))}
frame2_top: frame2_top:
${byte2byte(frames[1].bitmap.slice(0, half))} ${byte2byte(frames[1].bitmap.slice(0, half))}
.align 256 .align 128
frame2_palette1: frame2_palette1_even:
${byte2byte(frames[1].palette1)} ${byte2byte(even(frames[1].palette1))}
.align 256 .align 128
frame2_palette2: frame2_palette1_odd:
${byte2byte(frames[1].palette2)} ${byte2byte(odd(frames[1].palette1))}
.align 256 .align 128
frame2_palette3: frame2_palette2_even:
${byte2byte(frames[1].palette3)} ${byte2byte(even(frames[1].palette2))}
.align 128
frame2_palette2_odd:
${byte2byte(odd(frames[1].palette2))}
.align 128
frame2_palette3_even:
${byte2byte(even(frames[1].palette3))}
.align 128
frame2_palette3_odd:
${byte2byte(odd(frames[1].palette3))}
.align 4096 .align 4096
frame2_bottom: frame2_bottom:

View file

@ -34,7 +34,7 @@ bytes_per_line = 40
pages_per_frame = 32 pages_per_frame = 32
lines_per_frame = 262 lines_per_frame = 262
;scanline_offset = 31 + (40 - 24) / 2 ;scanline_offset = 31 + (40 - 24) / 2
scanline_offset = 48 scanline_offset = 40
scanline_max = (lines_per_frame - scanline_offset) / 2 scanline_max = (lines_per_frame - scanline_offset) / 2
.data .data
@ -44,14 +44,20 @@ scanline_max = (lines_per_frame - scanline_offset) / 2
.import frame1_top .import frame1_top
.import frame1_bottom .import frame1_bottom
.import frame1_palette1 .import frame1_palette1_even
.import frame1_palette2 .import frame1_palette1_odd
.import frame1_palette3 .import frame1_palette2_even
.import frame1_palette2_odd
.import frame1_palette3_even
.import frame1_palette3_odd
.import frame2_top .import frame2_top
.import frame2_bottom .import frame2_bottom
.import frame2_palette1 .import frame2_palette1_even
.import frame2_palette2 .import frame2_palette1_odd
.import frame2_palette3 .import frame2_palette2_even
.import frame2_palette2_odd
.import frame2_palette3_even
.import frame2_palette3_odd
.import displaylist .import displaylist
audio_high_byte: audio_high_byte:
@ -136,16 +142,17 @@ wait_loop:
sta audiotemp ; 3 cyc sta audiotemp ; 3 cyc
.endmacro .endmacro
.macro inner_scanline palette1, palette2, palette3 .macro inner_scanline frame_offset, line_offset
; Y should be VCOUNT at entry
; it'll fire on unused lines, but harmlessly ; it'll fire on unused lines, but harmlessly
ldy scanline ; 3 cyc ;ldy scanline ; 3 cyc
inc scanline ; 5 cyc ;inc scanline ; 5 cyc
; Leisurely memory fetches ; Leisurely memory fetches
lda palette1,y ; 5 @FIXME alternate lda frame1_palette1_even + frame_offset + line_offset - scanline_offset / 2,y ; 5 @FIXME alternate
pha ; ...3? pha ; ...3?
ldx palette2,y ; 5 ldx frame1_palette2_even + frame_offset + line_offset - scanline_offset / 2,y ; 5
lda palette3,y ; 5 lda frame1_palette3_even + frame_offset + line_offset - scanline_offset / 2,y ; 5
tay tay
pla pla
@ -159,7 +166,7 @@ wait_loop:
.endmacro .endmacro
.macro audio_play_raw .macro audio_play_raw
ldy VCOUNT ;ldy VCOUNT ; set on entry
lda (sample_ptr),y ; 5/6 cyc lda (sample_ptr),y ; 5/6 cyc
sta AUDC1 ; 4 cyc sta AUDC1 ; 4 cyc
.endmacro .endmacro
@ -202,14 +209,17 @@ wait_loop:
audio_cont: audio_cont:
.endmacro .endmacro
.macro run_frame palette1, palette2, palette3 .macro run_frame frame_offset
.scope .scope
each_scanline_pair: each_scanline_pair:
;audio_prep ;audio_prep
inner_scanline palette1, palette2, palette3 sty scanline
inner_scanline frame_offset, 0
ldy scanline
audio_play_raw audio_play_raw
;audio_play_lo ;audio_play_lo
inner_scanline palette1, palette2, palette3 inner_scanline frame_offset, 128
;audio_play_raw ;audio_play_raw
;audio_play_hi ; too slow ;audio_play_hi ; too slow
@ -232,9 +242,9 @@ wait_loop:
beq run_frame1 beq run_frame1
jmp run_frame2 jmp run_frame2
run_frame1: run_frame1:
run_frame frame1_palette1, frame1_palette2, frame1_palette3 run_frame 0
run_frame2: run_frame2:
run_frame frame2_palette1, frame2_palette2, frame2_palette3 run_frame 8192
.endproc .endproc