From b287da0ae1bc24ab3b05d627bd0064bc09e39952 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sun, 1 Oct 2023 00:03:47 -0400 Subject: [PATCH] second: work on automated conversion --- demos/second/part18_3d/auto/Makefile | 17 +- demos/second/part18_3d/auto/NOTES | 17 + demos/second/part18_3d/auto/box_convert.c | 191 +- demos/second/part18_3d/auto/box_sizes.c | 1926 +++++++++++++++++++++ demos/second/part18_3d/auto/make_sizes.c | 16 + 5 files changed, 2157 insertions(+), 10 deletions(-) create mode 100644 demos/second/part18_3d/auto/box_sizes.c create mode 100644 demos/second/part18_3d/auto/make_sizes.c diff --git a/demos/second/part18_3d/auto/Makefile b/demos/second/part18_3d/auto/Makefile index ac268c36..d52e2bbb 100644 --- a/demos/second/part18_3d/auto/Makefile +++ b/demos/second/part18_3d/auto/Makefile @@ -1,7 +1,7 @@ CC = gcc CFLAGS = -g -Wall -O2 -all: box_convert +all: box_convert make_sizes ### @@ -14,11 +14,20 @@ loadpng.o: loadpng.c loadpng.h box_convert: box_convert.o loadpng.o $(CC) $(LFLAGS) -o box_convert box_convert.o loadpng.o -lpng -box_convert.o: box_convert.c loadpng.h +box_convert.o: box_convert.c loadpng.h box_sizes.c $(CC) $(CFLAGS) -c box_convert.c ### -clean: - rm -f *~ *.o box_convert +make_sizes: make_sizes.o + $(CC) $(LFLAGS) -o make_sizes make_sizes.o + +make_sizes.o: make_sizes.c loadpng.h + $(CC) $(CFLAGS) -c make_sizes.c + + +### + +clean: + rm -f *~ *.o box_convert make_sizes diff --git a/demos/second/part18_3d/auto/NOTES b/demos/second/part18_3d/auto/NOTES index fb4b4350..71dac46a 100644 --- a/demos/second/part18_3d/auto/NOTES +++ b/demos/second/part18_3d/auto/NOTES @@ -14,3 +14,20 @@ todo, compressed: 2568 bytes: try4: use compact form (only change type if changed) 1194 bytes: try5: use hlin (essentially RLE) 906 bytes: try6: sort by color first + 628 bytes: try7: initial use boxes + 526 bytes: try8: boxes that optimize to HLIN/VLIN/PLOT + +TODO: + If HLIN and previous same x1/x2 do box + If HLIN only one wide, switch to VLIN? + IF HLIN and next line HLIN at +1, use HLIN_ADD + If HLIN and next line HLIN at +1 and R same, HLIN_ADD_RSAME + If HLIN and next line HLIN at +1 and R same, HLIN_ADD_LSAME + + MOVE PLOTS one line before HLIN + +Possible size boxes + 48x40,39,38....1 + + + diff --git a/demos/second/part18_3d/auto/box_convert.c b/demos/second/part18_3d/auto/box_convert.c index 36378d17..e522f9c8 100644 --- a/demos/second/part18_3d/auto/box_convert.c +++ b/demos/second/part18_3d/auto/box_convert.c @@ -13,6 +13,8 @@ #include "loadpng.h" +#include "box_sizes.c" + static char color_names[16][16]={ "BLACK", /* $00 */ @@ -53,11 +55,12 @@ static char action_names[9][16]={ }; #endif +#define MAX_PRIMITIVES 4096 static struct { int type; int color; int x1,y1,x2,y2; -} primitive_list[4096]; +} primitive_list[MAX_PRIMITIVES]; static int framebuffer[40][48]; static int background_color=0; @@ -87,11 +90,9 @@ int create_using_hlins(void) { int current_primitive=0; int row,col,start_x; - int current_color,prev_color; + int prev_color; int len; - /* Initial Implementation, All Plots */ - for(row=0;row<48;row++) { prev_color=framebuffer[0][row]; len=0; start_x=0; for(col=0;col<40;col++) { @@ -123,7 +124,6 @@ int create_using_hlins_by_color(void) { int current_color,prev_color; int len; - /* Initial Implementation, All Plots */ for(current_color=0;current_color<16;current_color++) { if (current_color==background_color) continue; @@ -156,6 +156,67 @@ int create_using_hlins_by_color(void) { } +int create_using_boxes(void) { + + int current_primitive=0; + int row,col,box; + int current_color; + + for(current_color=0;current_color<16;current_color++) { + + if (current_color==background_color) continue; + + for(box=0;box=MAX_PRIMITIVES) { + fprintf(stderr,"Error! Too many primitives: %d\n",current_primitive); + exit(1); + } + for(yy=0;yy + +// ./make_sizes | sort -k 7 -n -r + +int main(int argc, char **argv) { + + int x,y; + + for(x=40;x>0;x--) { + for(y=48;y>0;y--) { + printf("{ %d , %d },\t// %d\n",x,y,x*y); + } + } + + return 0; +}