From 53026bbfdd588db67e595ec10ed3a3cde30898a9 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 10 Dec 2022 13:01:29 -0800 Subject: [PATCH] WIP refactoring --- dither-image.js | 86 +++++++++++++++++++++++++++++++++++-------------- dither4.s | 48 ++++++++++++++++----------- 2 files changed, 91 insertions(+), 43 deletions(-) diff --git a/dither-image.js b/dither-image.js index 66fa869..1241eb8 100644 --- a/dither-image.js +++ b/dither-image.js @@ -654,6 +654,14 @@ function byte2byte(arr) { 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) { let linesEach = height / reps; let stride = width * nbits / 8; @@ -684,14 +692,20 @@ function genAssembly(width, height, nbits, lines, reps) { return `.data .export frame1_top .export frame1_bottom -.export frame1_palette1 -.export frame1_palette2 -.export frame1_palette3 +.export frame1_palette1_even +.export frame1_palette1_odd +.export frame1_palette2_even +.export frame1_palette2_odd +.export frame1_palette3_even +.export frame1_palette3_odd .export frame2_top .export frame2_bottom -.export frame2_palette1 -.export frame2_palette2 -.export frame2_palette3 +.export frame2_palette1_even +.export frame2_palette1_odd +.export frame2_palette2_even +.export frame2_palette2_odd +.export frame2_palette3_even +.export frame2_palette3_odd .export displaylist .segment "BUFFERS" @@ -700,17 +714,29 @@ function genAssembly(width, height, nbits, lines, reps) { frame1_top: ${byte2byte(frames[0].bitmap.slice(0, half))} -.align 256 -frame1_palette1: -${byte2byte(frames[0].palette1)} +.align 128 +frame1_palette1_even: +${byte2byte(even(frames[0].palette1))} -.align 256 -frame1_palette2: -${byte2byte(frames[0].palette2)} +.align 128 +frame1_palette1_odd: +${byte2byte(odd(frames[0].palette1))} -.align 256 -frame1_palette3: -${byte2byte(frames[0].palette3)} +.align 128 +frame1_palette2_even: +${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 frame1_bottom: @@ -722,17 +748,29 @@ ${byte2byte(frames[0].bitmap.slice(half))} frame2_top: ${byte2byte(frames[1].bitmap.slice(0, half))} -.align 256 -frame2_palette1: -${byte2byte(frames[1].palette1)} +.align 128 +frame2_palette1_even: +${byte2byte(even(frames[1].palette1))} -.align 256 -frame2_palette2: -${byte2byte(frames[1].palette2)} +.align 128 +frame2_palette1_odd: +${byte2byte(odd(frames[1].palette1))} -.align 256 -frame2_palette3: -${byte2byte(frames[1].palette3)} +.align 128 +frame2_palette2_even: +${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 frame2_bottom: diff --git a/dither4.s b/dither4.s index c9f886c..9b8bb23 100644 --- a/dither4.s +++ b/dither4.s @@ -34,7 +34,7 @@ bytes_per_line = 40 pages_per_frame = 32 lines_per_frame = 262 ;scanline_offset = 31 + (40 - 24) / 2 -scanline_offset = 48 +scanline_offset = 40 scanline_max = (lines_per_frame - scanline_offset) / 2 .data @@ -44,14 +44,20 @@ scanline_max = (lines_per_frame - scanline_offset) / 2 .import frame1_top .import frame1_bottom -.import frame1_palette1 -.import frame1_palette2 -.import frame1_palette3 +.import frame1_palette1_even +.import frame1_palette1_odd +.import frame1_palette2_even +.import frame1_palette2_odd +.import frame1_palette3_even +.import frame1_palette3_odd .import frame2_top .import frame2_bottom -.import frame2_palette1 -.import frame2_palette2 -.import frame2_palette3 +.import frame2_palette1_even +.import frame2_palette1_odd +.import frame2_palette2_even +.import frame2_palette2_odd +.import frame2_palette3_even +.import frame2_palette3_odd .import displaylist audio_high_byte: @@ -136,16 +142,17 @@ wait_loop: sta audiotemp ; 3 cyc .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 - ldy scanline ; 3 cyc - inc scanline ; 5 cyc + ;ldy scanline ; 3 cyc + ;inc scanline ; 5 cyc ; 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? - ldx palette2,y ; 5 - lda palette3,y ; 5 + ldx frame1_palette2_even + frame_offset + line_offset - scanline_offset / 2,y ; 5 + lda frame1_palette3_even + frame_offset + line_offset - scanline_offset / 2,y ; 5 tay pla @@ -159,7 +166,7 @@ wait_loop: .endmacro .macro audio_play_raw - ldy VCOUNT + ;ldy VCOUNT ; set on entry lda (sample_ptr),y ; 5/6 cyc sta AUDC1 ; 4 cyc .endmacro @@ -202,14 +209,17 @@ wait_loop: audio_cont: .endmacro - .macro run_frame palette1, palette2, palette3 + .macro run_frame frame_offset .scope each_scanline_pair: ;audio_prep - inner_scanline palette1, palette2, palette3 + sty scanline + inner_scanline frame_offset, 0 + + ldy scanline audio_play_raw ;audio_play_lo - inner_scanline palette1, palette2, palette3 + inner_scanline frame_offset, 128 ;audio_play_raw ;audio_play_hi ; too slow @@ -232,9 +242,9 @@ wait_loop: beq run_frame1 jmp run_frame2 run_frame1: - run_frame frame1_palette1, frame1_palette2, frame1_palette3 + run_frame 0 run_frame2: - run_frame frame2_palette1, frame2_palette2, frame2_palette3 + run_frame 8192 .endproc