second: clean up box_convert

This commit is contained in:
Vince Weaver 2023-09-30 01:03:08 -04:00
parent cfe857dff1
commit d129924562
1 changed files with 93 additions and 58 deletions

View File

@ -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<current_primitive;i++) {
for(i=0;i<max_primitive;i++) {
if (primitive_list[i].color==0) continue;
if (current_color!=primitive_list[i].color) {
printf("\t.byte SET_COLOR | %s\n",
color_names[primitive_list[i].color]);
current_color=primitive_list[i].color;
total_size+=1;
}
switch(primitive_list[i].type) {
@ -154,9 +176,20 @@ char action_names[9][16]={
case ACTION_VLIN:
break;
case ACTION_PLOT:
printf("\t.byte PLOT,%d,%d\n",
primitive_list[i].x1,
primitive_list[i].y1);
if (primitive_list[i].type==previous_primitive) {
printf("\t.byte %d,%d\n",
primitive_list[i].x1,
primitive_list[i].y1);
total_size+=2;
}
else {
printf("\t.byte PLOT,%d,%d\n",
primitive_list[i].x1,
primitive_list[i].y1);
total_size+=3;
previous_primitive=ACTION_PLOT;
}
break;
case ACTION_HLIN_ADD:
break;
@ -174,6 +207,8 @@ char action_names[9][16]={
}
printf("\t.byte END\n");
total_size++;
printf("; total size = %d\n",total_size);
return 0;
}