diff --git a/006.simple_blit/blit.s b/006.simple_blit/blit.s index ac75d9a..0704843 100644 --- a/006.simple_blit/blit.s +++ b/006.simple_blit/blit.s @@ -101,7 +101,13 @@ blitWait: btst #6,DMACONR(a6) bne.s .waitblit rts - + +TC_WIDTH equ 64 +TC_HEIGHT equ 64 +TC_WIDTH_BYTES equ TC_WIDTH/8 +TC_WIDTH_WORDS equ TC_WIDTH/16 +TC_XPOS equ 16 +TC_YPOS equ 16 doblit: movem.l d0-a6,-(sp) lea $dff000,a6 @@ -109,10 +115,10 @@ doblit: move.l #$09f00000,BLTCON0(a6) ;A->D copy, no shifts, ascending mode move.l #$ffffffff,BLTAFWM(a6) ;no masking of first/last word move.w #0,BLTAMOD(a6) ;A modulo=bytes to skip between lines - move.w #0,BLTDMOD(a6) ;D modulo - move.l #bitplanes,BLTAPTH(a6) ;source graphic top left corner - move.l #bitplanes+(SCREEN_WIDTH_BYTES*SCREEN_BIT_DEPTH*SCREEN_HEIGHT/2),BLTDPTH(a6) ;destination top left corner - move.w #SCREEN_WIDTH_BYTES*SCREEN_BIT_DEPTH*SCREEN_HEIGHT/4,BLTSIZE(a6) ;rectangle size, starts blit + move.w #SCREEN_WIDTH_BYTES-TC_WIDTH_BYTES,BLTDMOD(a6) ;D modulo + move.l #tc,BLTAPTH(a6) ;source graphic top left corner + move.l #bitplanes+(TC_XPOS)/8+(SCREEN_WIDTH_BYTES*SCREEN_BIT_DEPTH*TC_YPOS),BLTDPTH(a6) ;destination top left corner + move.w #(TC_HEIGHT*SCREEN_BIT_DEPTH)<<6|(TC_WIDTH_WORDS),BLTSIZE(a6) ;rectangle size, starts blit movem.l (sp)+,d0-a6 rts diff --git a/assets/tc.png b/assets/tc.png new file mode 100644 index 0000000..8da4c9d Binary files /dev/null and b/assets/tc.png differ diff --git a/base.mk b/base.mk index de641d9..0ea646f 100644 --- a/base.mk +++ b/base.mk @@ -41,10 +41,14 @@ out/bootblock.o: ../shared/bootblock.s out/main.bin vc -c $< -o $@ out/main.o: $(MODULE) $(EXTRA) - vc -c $< -o $@ + @# -v + @#vc -c $< -o $@ + @#-showopt -no-opt + vasmm68k_mot -Fhunk -phxass -opt-fconst -nowarn=62 -quiet $< -o $@ -I/usr/local/amiga/os-include -out/main.bin: out/main.o - vlink -brawbin1 $< -o $@ +out/main.bin: out/main.o $(EXTRAOBJS) + @#-T ../link.script + vlink -Ttext 0x70000 -brawbin1 $< $(EXTRAOBJS) -o $@ clean: rm -rf out bin *~ diff --git a/tools/imagecon/imagecon.c b/tools/imagecon/imagecon.c index 3ddf3f9..c87a81d 100644 --- a/tools/imagecon/imagecon.c +++ b/tools/imagecon/imagecon.c @@ -17,6 +17,7 @@ imagecon_config_t config = { .maxColors = MAX_PALETTE, .outputPalette = 0, + .outputMask = 0, .quantize = 0, .overridePalette = 0 }; @@ -25,13 +26,14 @@ typedef struct { unsigned char r; unsigned char g; unsigned char b; + unsigned char a; } amiga_color_t; void usage() { - fprintf(stderr, "%s: --input [options]\nOptions:\n --output \n --colors \n --quantize\n --output-palette\n --override-palette \n --verbose\n", config.argv[0]); + fprintf(stderr, "%s: --input [options]\nOptions:\n --output \n --colors \n --quantize\n --output-mask\n --output-palette\n --override-palette \n --verbose\n", config.argv[0]); exit(1); } @@ -58,6 +60,10 @@ openFileWrite(const char * s, ...) vsprintf(buffer, s, args); va_end(args); + if (config.verbose) { + printf("Opening %s for writing\n", buffer); + } + FILE* fp = fopen(buffer, "w+"); if (!fp) { abort_("Failed to open %s for writing\n", buffer); @@ -86,6 +92,10 @@ openFileRead(const char * s, ...) void outputPalette(char* outFilename, amiga_color_t* palette, int numColors) { + if (config.verbose) { + printf("outputPalette...\n"); + } + FILE* fp = openFileWrite("%s-copper-list.s", outFilename); FILE* paletteFP = 0; if (config.outputPalette) { @@ -98,7 +108,7 @@ outputPalette(char* outFilename, amiga_color_t* palette, int numColors) for (int i = 0; i < numColors; i++) { if (config.verbose) { - printf("%d: %x %d %d %d\n", i , palette[i].r << 8 | palette[i].g << 4 | palette[i].b, palette[i].r, palette[i].g, palette[i].b); + printf("%02d: hex=%03x r=%03d g=%03d b=%03d a=%03d\n", i , palette[i].r << 8 | palette[i].g << 4 | palette[i].b, palette[i].r, palette[i].g, palette[i].b, palette[i].a); } if (paletteFP) { fprintf(paletteFP, "%03x\n", palette[i].r << 8 | palette[i].g << 4 | palette[i].b); @@ -110,12 +120,20 @@ outputPalette(char* outFilename, amiga_color_t* palette, int numColors) } fclose(fp); + + if (config.verbose) { + printf("done\n\n"); + } } int generateQuantizedPalette(unsigned char* amigaImage, png_bytep* rowPointers, amiga_color_t* palette) { + if (config.verbose) { + printf("generateQuantizedPalette...\n"); + } + liq_attr *attr = liq_attr_create(); liq_image *image = liq_image_create_rgba_rows(attr, (void**)rowPointers, config.width, config.height, 0); @@ -160,11 +178,16 @@ generateQuantizedPalette(unsigned char* amigaImage, png_bytep* rowPointers, amig for (unsigned i = 0; i < pal->count; i++) { if (config.verbose) { - printf("%d %d %d %d\n", i, pal->entries[i].r, pal->entries[i].g, pal->entries[i].b); + printf("%02d: r=%03d g=%03d b=%03d a=%03d\n", i, pal->entries[i].r, pal->entries[i].g, pal->entries[i].b, pal->entries[i].a); } palette[i].r = pal->entries[i].r >> 4; palette[i].g = pal->entries[i].g >> 4; palette[i].b = pal->entries[i].b >> 4; + palette[i].a = pal->entries[i].a >> 4; + } + + if (config.verbose) { + printf("done\n\n"); } return pal->count; @@ -174,6 +197,10 @@ generateQuantizedPalette(unsigned char* amigaImage, png_bytep* rowPointers, amig int generatePalette(unsigned char* amigaImage, png_bytep* rowPointers, amiga_color_t* palette) { + if (config.verbose) { + printf("generatePalette...\n"); + } + int paletteIndex = 0; for (int y=0; y> 4; color.g = ptr[1] >> 4; color.b = ptr[2] >> 4; + color.a = ptr[3] >> 4; int index = -1; for (int i = 0; i < paletteIndex; i++) { @@ -205,28 +233,37 @@ generatePalette(unsigned char* amigaImage, png_bytep* rowPointers, amiga_color_t amigaImage[(config.width*y)+x] = index; } } - + + if (config.verbose) { + printf("done\n\n"); + } + return paletteIndex; } void outputBitplanes(char* outFilename, unsigned char* amigaImage, int numColors) { + + + if (config.verbose) { + printf("outputBitplanes...\n"); + } int numBitPlanes = (int)(log(numColors-1) / log(2))+1; if (config.verbose) { printf("number of colors = %d\n", numColors); printf("number of bitplanes = %d\n", numBitPlanes); } + int byteWidth = (config.width + 7) / 8; - char** bitplanes = malloc(sizeof(void*)+numBitPlanes); + char** bitplanes = malloc(sizeof(void*)*numBitPlanes); for (int i = 0; i < numBitPlanes; i++) { bitplanes[i] = calloc(byteWidth*config.height, 1); } - for (int y = 0, writeIndex = 0; y < config.height; y++) { for (int byte = 0;byte < byteWidth; byte++) { for (int bit = 0; bit < 8; bit++) { @@ -241,6 +278,7 @@ outputBitplanes(char* outFilename, unsigned char* amigaImage, int numColors) } } + FILE* fp = openFileWrite("%s.bin", outFilename); for (int y = 0; y < config.height; y++) { @@ -250,11 +288,64 @@ outputBitplanes(char* outFilename, unsigned char* amigaImage, int numColors) } } fclose(fp); + if (config.verbose) { + printf("done\n\n"); + } +} + +void +outputMask(char* outFilename, unsigned char* amigaImage, amiga_color_t* palette, int numColors) +{ + if (config.verbose) { + printf("outputMask...\n"); + } + int numBitPlanes = (int)(log(numColors-1) / log(2))+1; + + int byteWidth = (config.width + 7) / 8; + + char** bitplanes = malloc(sizeof(void*)*numBitPlanes); + for (int i = 0; i < numBitPlanes; i++) { + bitplanes[i] = calloc(byteWidth*config.height, 1); + } + + + for (int y = 0, writeIndex = 0; y < config.height; y++) { + for (int byte = 0;byte < byteWidth; byte++) { + for (int bit = 0; bit < 8; bit++) { + int x = byte * 8 + 7 - bit; + int paletteIndex = amigaImage[(config.width*y)+x]; + int bitmask = palette[paletteIndex].a > 0 ? 0xFF : 0; + for (int plane_index = 0; plane_index < numBitPlanes; plane_index++) { + char* plane = bitplanes[plane_index]; + plane[writeIndex] |= ((bitmask >> plane_index) & 1) << bit; + } + } + writeIndex++; + } + } + + FILE* fp = openFileWrite("%s-mask.bin", outFilename); + + for (int y = 0; y < config.height; y++) { + for (int plane_index = 0; plane_index < numBitPlanes; plane_index++) { + char* plane = bitplanes[plane_index]; + fwrite(&plane[y*byteWidth], byteWidth, 1, fp); + } + } + fclose(fp); + + if (config.verbose) { + printf("done\n\n"); + } } void processFile(char* outFilename, png_bytep* rowPointers) { + if (config.verbose) { + printf("processFile...\n"); + } + int numColors; amiga_color_t palette[MAX_PALETTE]; @@ -268,8 +359,16 @@ processFile(char* outFilename, png_bytep* rowPointers) numColors = generatePalette(amigaImage, rowPointers, palette); } - outputBitplanes(outFilename, amigaImage, numColors); + outputBitplanes(outFilename, amigaImage, numColors); + + if (config.outputMask) { + outputMask(outFilename, amigaImage, palette, numColors); + } outputPalette(outFilename, palette, numColors); + + if (config.verbose) { + printf("done\n\n"); + } } @@ -286,6 +385,7 @@ main(int argc, char **argv) {"verbose", no_argument, &config.verbose, 1}, {"quantize", no_argument, &config.quantize, 1}, {"output-palette", no_argument, &config.outputPalette, 1}, + {"output-mask", no_argument, &config.outputMask, 1}, {"override-palette", required_argument, 0, 'p'}, {"output", required_argument, 0, 'o'}, {"colors", required_argument, 0, 'c'}, @@ -345,7 +445,7 @@ main(int argc, char **argv) } if (config.verbose) { - printf("Options:\verbose = %d\ninputFile = %s\noutputFile = %s\nmaxColors = %d\n\n", config.verbose, inputFile, outputFile, config.maxColors); + printf("Options:\nverbose = %d\ninputFile = %s\noutputFile = %s\nmaxColors = %d\noutputPalette = %d\noutputMask = %d\n\n", config.verbose, inputFile, outputFile, config.maxColors, config.outputPalette, config.outputMask); } processFile(outputFile, png_read(inputFile)); diff --git a/tools/imagecon/imagecon.h b/tools/imagecon/imagecon.h index 338cde8..3fdeeda 100644 --- a/tools/imagecon/imagecon.h +++ b/tools/imagecon/imagecon.h @@ -7,6 +7,7 @@ typedef struct { int height; int maxColors; int outputPalette; + int outputMask; char* overridePalette; int quantize; int verbose; diff --git a/tools/imagecon/rgba8.png b/tools/imagecon/rgba8.png new file mode 100644 index 0000000..495d8c3 Binary files /dev/null and b/tools/imagecon/rgba8.png differ