From f5f2c5dbbf7c72b14c25640743aa15c4ffdd3470 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 25 Nov 2022 11:51:27 -0800 Subject: [PATCH] work in progress --- .gitignore | 5 +++ dither4.js | 11 ++++-- dither4.s | 98 +++++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 97 insertions(+), 17 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..010428c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +*.o +*.xex +*.pxd +canvas*.png diff --git a/dither4.js b/dither4.js index 2654599..cb9aa83 100644 --- a/dither4.js +++ b/dither4.js @@ -530,9 +530,12 @@ function decimate(input, palette, n) { let least = Infinity; let pick = -1; for (let i = 1; i < decimated.length; i++) { - if (i == 0) { + if (decimated[i] === palette256[0]) { continue; // keep black always } + if (decimated[i] === palette256[0x0f]) { + continue; // keep white always + } //let coolFactor = popularity[i]; @@ -552,11 +555,15 @@ function decimate(input, palette, n) { } } let old = decimated.length; + //decimated.splice(pick, 1); decimated = decimated.filter((rgb, i) => { if (i == pick) { return false; } - if (i > 0 && popularity[i] == 0) { + if (rgb !== palette256[0] && popularity[i] == 0) { + return false; + } + if (rgb !== palette256[0x0f] && popularity[i] == 0) { return false; } return true; diff --git a/dither4.s b/dither4.s index 5c467f8..1e8d81d 100644 --- a/dither4.s +++ b/dither4.s @@ -1,23 +1,91 @@ SAVMSC = $58 +SDMCTL = $22F +SDLSTL = $230 +SDLSTH = $231 +COLPF0 = $D016 +COLPF1 = $D017 +COLPF2 = $D018 +COLPF3 = $D019 +COLBK = $D01A + +WSYNC = $D40A +VCOUNT = $D40B +NMIEN = $D40E + +.data + +.import palette1 +.import palette2 +.import palette3 +.import framebuffer + +displaylist: + .repeat 3 + .byte $70 ; 8 blank lines + .endrep + .byte $4e ; ANTIC mode e (160px 2bpp, 1 scan line per line) + .addr framebuffer + .repeat 191 + .byte $0e + .endrep + .byte $41 ; jump and blank + .addr displaylist + .code .export start -.proc start - ; Get the framebuffer address and just write new fun values into it - ; x: byte to write in - ; y: index into the first 256 bytes of buffer +; Loop through scan lines updating the palette +.proc update_palette + 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 + rst +.endproc + +.proc start + ; Disable display DMA + lda #$00 + sta SDMCTL + ; Set up the display list + lda .low displaylist + sta SDLSTL + lda .high displaylist + sta SDLSTH + + ; Turn off interrupts except reset button + lda #$20 + sta NMIEN + + ; Manually wait for first scan line +wait_vblank: + lda VCOUNT + bnz wait_vblank + + ; Re-enable display DMA + lda #$22 + sta SDMCTL + +even_scanline: + ldy VCOUNT + jsr update_palette + +odd_scanline: + ldy VCOUNT + iny + jsr update_palette + jmp even_scanline - ldx #00 -outer_loop: - txa - ldy #00 -inner_loop: - sta (SAVMSC),y - iny - bne inner_loop - inx - jmp outer_loop - ; infinite loop .endproc