From da00cf317f450a2b0e0312daa11001118181a49a Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 25 Nov 2022 17:54:58 -0800 Subject: [PATCH] ... --- Makefile | 25 +++++++++++++++---------- dither-image.js | 31 ++++++++++++++----------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 21397f3..22e9f2b 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,27 @@ -.PHONY : all clean - -all : dither4.xex +all : sample0.xex sample1.xex sample2.xex sample3.xex sample4.xex sample5.xex sample6.xex # sample5.s from sample5.jpg # reminder: $< is input # $@ is output -%.o : %.s - ca65 -v -t atari -o $@ $< %.s : %.jpg node dither-image.js $< $@ $@.png +%.o : %.s + ca65 -v -t atari -o $@ $< + +%.xex : %.o dither4.o + ld65 -v -C atari-asm-xex.cfg -o $@ $< + dither4.xex : dither4.o sample6.o ld65 -v -C atari-asm-xex.cfg -o $@ $< -clean : - rm -f sample5.s - rm -f sample5.o - rm -f dither4.o - rm -f dither4.xex + +#clean : +# rm -f dither4.o +# rm -f dither4.xex +# rm -f sample[0-6].o +# rm -f sample[0-6].s +# rm -f sample[0-6].xex +# rm -f sample[0-6].png diff --git a/dither-image.js b/dither-image.js index fc26fed..46b9216 100644 --- a/dither-image.js +++ b/dither-image.js @@ -626,10 +626,8 @@ async function convert(source, nbits) { for (let y = 0; y < height; y++) { let error = lines[y - 1]?.error; let inputLine = input.slice(y * width, (y + 1) * width); - console.log(`DOING LINE ${y}; have ${inputLine.length} pixels`); let line = decimate(inputLine, allColors, 4, error); lines.push(line); - console.log(`DID LINE ${y}; have ${line.output.length} pixels`); } return { width, @@ -640,12 +638,13 @@ async function convert(source, nbits) { function indexedToBitmap(width, nbits, src, dest) { - let nbytes = width >> nbits; + let nbytes = width * nbits / 8; + let x = 0; for (let i = 0; i < nbytes; i++) { let a = 0; for (let b = 0; b < 8; b += nbits) { a <<= nbits; - a |= src[i]; + a |= src[x++]; } dest[i] = a; } @@ -654,7 +653,7 @@ function indexedToBitmap(width, nbits, src, dest) { function byte2byte(arr) { let lines = []; for (let i=0; i < arr.length; i++) { - lines.push(`.byte ${lines[i]}`); + lines.push(`.byte ${arr[i]}`); } return lines.join('\n'); } @@ -669,24 +668,22 @@ function genAssembly(width, height, nbits, lines) { palette1[y] = lines[y].palette[1]; palette2[y] = lines[y].palette[2]; palette3[y] = lines[y].palette[3]; - indexedToBitmap(width, nbits, lines[y].output, framebuffer.slice(y * stride)); + indexedToBitmap(width, nbits, lines[y].output, framebuffer.slice(y * stride, (y + 1) * stride)); } - return ` -.data + return `.data -.export palette1: - ${byte2byte(palette1)} +.export far palette1: +${byte2byte(palette1)} -.export palette2: - ${byte2byte(palette2)} +.export far palette2: +${byte2byte(palette2)} -.export palette3: - ${byte2byte(palette3)} - -.export framebuffer: - ${byte2byte(framebuffer)} +.export far palette3: +${byte2byte(palette3)} +.export far framebuffer: +${byte2byte(framebuffer)} `; }