From d12992456258d0db44f80664d687a5c74f8b8fef Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sat, 30 Sep 2023 01:03:08 -0400 Subject: [PATCH] second: clean up box_convert --- demos/second/part18_3d/auto/box_convert.c | 151 +++++++++++++--------- 1 file changed, 93 insertions(+), 58 deletions(-) diff --git a/demos/second/part18_3d/auto/box_convert.c b/demos/second/part18_3d/auto/box_convert.c index 150599f8..4dc9f224 100644 --- a/demos/second/part18_3d/auto/box_convert.c +++ b/demos/second/part18_3d/auto/box_convert.c @@ -13,6 +13,75 @@ #include "loadpng.h" + +static char color_names[16][16]={ + "BLACK", /* $00 */ + "RED", /* $01 */ + "DARK_BLUE", /* $02 */ + "MAGENTA", /* $03 */ + "GREEN", /* $04 */ + "GREY1", /* $05 */ + "MEDIUM_BLUE", /* $06 */ + "LIGHT_BLUE", /* $07 */ + "BROWN", /* $08 */ + "ORANGE", /* $09 */ + "GREY2", /* $0A */ + "PINK", /* $0B */ + "LIGHT_GREEN", /* $0C */ + "YELLOW", /* $0D */ + "AQUA", /* $0E */ + "WHITE", /* $0F */ +}; + + +/* SET_COLOR = $C0 */ + +#define ACTION_END 0x0 +#define ACTION_CLEAR 0x1 +#define ACTION_BOX 0x2 +#define ACTION_HLIN 0x3 +#define ACTION_VLIN 0x4 +#define ACTION_PLOT 0x5 +#define ACTION_HLIN_ADD 0x6 +#define ACTION_HLIN_ADD_LSAME 0x7 +#define ACTION_HLIN_ADD_RSAME 0x8 + +#if 0 +static char action_names[9][16]={ + "END","CLEAR","BOX","HLIN","VLIN","PLOT", + "HLIN_ADD","HLIN_ADD_LSAME","HLIN_ADD_RSAME" +}; +#endif + +static struct { + int type; + int color; + int x1,y1,x2,y2; +} primitive_list[4096]; + +static int framebuffer[40][48]; + + +int create_using_plots(void) { + + int current_primitive=0; + int row,col; + + /* Initial Implementation, All Plots */ + + for(row=0;row<48;row++) { + for(col=0;col<40;col++) { + primitive_list[current_primitive].color=framebuffer[col][row]; + primitive_list[current_primitive].x1=col; + primitive_list[current_primitive].y1=row; + primitive_list[current_primitive].type=ACTION_PLOT; + current_primitive++; + + } + } + return current_primitive; +} + int main(int argc, char **argv) { int row=0; @@ -52,54 +121,17 @@ int main(int argc, char **argv) { } -char color_names[16][16]={ - "BLACK", /* $00 */ - "RED", /* $01 */ - "DARK_BLUE", /* $02 */ - "MAGENTA", /* $03 */ - "GREEN", /* $04 */ - "GREY1", /* $05 */ - "MEDIUM_BLUE", /* $06 */ - "LIGHT_BLUE", /* $07 */ - "BROWN", /* $08 */ - "ORANGE", /* $09 */ - "GREY2", /* $0A */ - "PINK", /* $0B */ - "LIGHT_GREEN", /* $0C */ - "YELLOW", /* $0D */ - "AQUA", /* $0E */ - "WHITE", /* $0F */ -}; -/* SET_COLOR = $C0 */ - -#define ACTION_END 0x0 -#define ACTION_CLEAR 0x1 -#define ACTION_BOX 0x2 -#define ACTION_HLIN 0x3 -#define ACTION_VLIN 0x4 -#define ACTION_PLOT 0x5 -#define ACTION_HLIN_ADD 0x6 -#define ACTION_HLIN_ADD_LSAME 0x7 -#define ACTION_HLIN_ADD_RSAME 0x8 - -char action_names[9][16]={ - "END","CLEAR","BOX","HLIN","VLIN","PLOT", - "HLIN_ADD","HLIN_ADD_LSAME","HLIN_ADD_RSAME" -}; - int color_count[16]; - int framebuffer[40][48]; + int current_color=0; - struct { - int type; - int color; - int x1,y1,x2,y2; - } primitive_list[4096]; - int current_primitive=0; + + int max_primitive=0; + int previous_primitive=0; + int total_size=0; memset(color_count,0,16*sizeof(int)); @@ -119,27 +151,17 @@ char action_names[9][16]={ printf("; $%02X %s: %d\n",i,color_names[i],color_count[i]); } - /* Initial Implementation, All Plots */ - current_primitive=0; - for(row=0;row<48;row++) { - for(col=0;col<40;col++) { - primitive_list[current_primitive].color=framebuffer[col][row]; - primitive_list[current_primitive].x1=col; - primitive_list[current_primitive].y1=row; - primitive_list[current_primitive].type=ACTION_PLOT; - current_primitive++; - - } - } + create_using_plots(); /* Dump results */ - for(i=0;i