From 9efa35216054a134d12ae154957d59d359636691 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Fri, 11 Mar 2016 15:31:09 -0500 Subject: [PATCH] hgr-utils: shape-table: clean up whitespace, fix compiler warning --- hgr-utils/shape_table.c | 360 ++++++++++++++++++++-------------------- 1 file changed, 181 insertions(+), 179 deletions(-) diff --git a/hgr-utils/shape_table.c b/hgr-utils/shape_table.c index 5fc6506b..72ffd2c5 100644 --- a/hgr-utils/shape_table.c +++ b/hgr-utils/shape_table.c @@ -10,11 +10,11 @@ #define MAX_SIZE 8192 /* not really, but anything larger would be crazy */ static unsigned char table[MAX_SIZE]; - -void set_offset(current_shape,current_offset) { - table[2+(current_shape*2)]=current_offset&0xff; - table[2+(current_shape*2)+1]=(current_offset>>8)&0xff; +static void set_offset(int current_shape,int current_offset) { + + table[2+(current_shape*2)]=current_offset&0xff; + table[2+(current_shape*2)+1]=(current_offset>>8)&0xff; } #define LOC_A 0 @@ -23,208 +23,210 @@ void set_offset(current_shape,current_offset) { static void warn_if_zero(unsigned char byte, int line) { - /* Check to see if we're accidentally ignoring bytes */ - if (byte==0) { - fprintf(stderr,"Warning, all-0 byte will be ignored on line %d!\n", - line); - } - - if ((byte&0xf8)==0) { - fprintf(stderr,"Warning, ignoring C and B due to 0 on line %d!\n", - line); - } + /* Check to see if we're accidentally ignoring bytes */ + if (byte==0) { + fprintf(stderr, + "Warning, all-0 byte will be ignored on line %d!\n", + line); + } + if ((byte&0xf8)==0) { + fprintf(stderr, + "Warning, ignoring C and B due to 0 on line %d!\n", + line); + } } -void print_usage(char *exe) { - printf("Usage:\t%s [-h] [-a] [-b]\n\n",exe); - printf("\t-h\tprint this help message\n"); - printf("\t-a\toutput shape table in applesoft BASIC format\n"); - printf("\t-b\toutput shape table in binary format for BLOADing\n"); - printf("\n"); - exit(1); +static void print_usage(char *exe) { + + printf("Usage:\t%s [-h] [-a] [-b]\n\n",exe); + printf("\t-h\tprint this help message\n"); + printf("\t-a\toutput shape table in applesoft BASIC format\n"); + printf("\t-b\toutput shape table in binary format for BLOADing\n"); + printf("\n"); + exit(1); } int main(int argc, char **argv) { - char string[BUFSIZ]; - char *result; - int table_size=0; - int num_shapes=0; - int current_offset=0,current_shape=0; - int i,line=1; + char string[BUFSIZ]; + char *result; + int table_size=0; + int num_shapes=0; + int current_offset=0,current_shape=0; + int i,line=1; - int command=0,sub_pointer; + int command=0,sub_pointer; - int output_binary=0; + int output_binary=0; - if (argc<2) { - output_binary=0; - } - - else { - if (argv[1][0]=='-') { - - switch(argv[1][1]) { - - case 'h': print_usage(argv[0]); - case 'b': output_binary=1; - break; - case 'a': output_binary=0; - break; - default: printf("Unknown options %s\n",argv[1]); - print_usage(argv[0]); - } - } - } - - while(1) { - result=fgets(string,BUFSIZ,stdin); - if (result==NULL) break; - line++; - - /* skip comments and blank lines */ - if ((string[0]=='#') || (string[0]=='\n')) continue; - - sscanf(string,"%d",&num_shapes); - break; - - } - - //fprintf(stderr,"Num shapes: %d\n",num_shapes); - - table[0]=num_shapes; - table[1]=0; - - current_shape=0; - current_offset=2+2*(num_shapes); - - for(current_shape=0;current_shape>8)&0xff; - header[2]=table_size&0xff; - header[3]=(table_size>>8)&0xff; + current_shape=0; + current_offset=2+2*(num_shapes); - fprintf(stderr,"Be sure to POKE 232,%d : POKE 233,%d\n" - "\tto let applesoft know the location of the table\n", - offset&0xff,(offset>>8)&0xff); + for(current_shape=0;current_shape>8)&0xff); - printf("30 FOR L=%d TO %d: READ B:POKE L,B:NEXT L\n", - address,(address+table_size)-1); - printf("35 HGR:ROT=0:SCALE=2\n"); - printf("40 FOR I=1 TO %d: XDRAW I AT I*10,100:NEXT I\n", - num_shapes); - printf("90 END\n"); + /* skip comments and blank lines */ + if ((string[0]=='#') || (string[0]=='\n')) continue; - for(i=0;i>8)&0xff; + header[2]=table_size&0xff; + header[3]=(table_size>>8)&0xff; + + fprintf(stderr,"Be sure to POKE 232,%d : POKE 233,%d\n" + "\tto let applesoft know the location of the table\n", + offset&0xff,(offset>>8)&0xff); + + fwrite(header,sizeof(unsigned char),4,stdout); + + fwrite(table,sizeof(unsigned char),table_size,stdout); + } + else { + + /* put near highmem */ + int address=0x1ff0-table_size; + + printf("10 HIMEM:%d\n",address); + printf("20 POKE 232,%d:POKE 233,%d\n",(address&0xff),(address>>8)&0xff); + printf("30 FOR L=%d TO %d: READ B:POKE L,B:NEXT L\n", + address,(address+table_size)-1); + printf("35 HGR:ROT=0:SCALE=2\n"); + printf("40 FOR I=1 TO %d: XDRAW I AT I*10,100:NEXT I\n", + num_shapes); + printf("90 END\n"); + + for(i=0;i