dos33fsprogs/graphics/dgr_viewer/make_dgr_viewer.c
Vince Weaver 30825d0fdf dgr_viewer: double lo-res is a pain
did finally figure out what was going on

the aux pages are rotated by nybble
2023-05-07 14:55:55 -04:00

284 lines
7.9 KiB
C

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#define MAX_FILES 1024
static char *png_filenames[MAX_FILES];
static char *zx02_aux_filenames[MAX_FILES];
static char *zx02_main_filenames[MAX_FILES];
static char *labels[MAX_FILES];
/* Format:
file_label FILE.ZX02 file.png
*/
int main(int argc, char **argv) {
char *result;
char string[BUFSIZ];
int num_files=0;
int i,j,count,line=0;
char temp_png[BUFSIZ];
char temp_zx02[BUFSIZ];
char temp_label[BUFSIZ];
char s_filename[BUFSIZ];
char filename_base[BUFSIZ];
char temp[BUFSIZ];
FILE *sss;
/******************************************/
/* parse command line */
/******************************************/
if (argc>1) {
strcpy(filename_base,argv[1]);
}
else {
strcpy(filename_base,"dlores_plain");
}
sprintf(s_filename,"%s.s",filename_base);
/******************************************/
/* scan in data */
/******************************************/
while(1) {
line++;
result=fgets(string,BUFSIZ,stdin);
if (result==NULL) {
break;
}
if (result[0]=='#') continue;
count=sscanf(string,"%s %s %s",temp_label,temp_zx02,temp_png);
if (count!=3) {
fprintf(stderr,"WARNING! weird input line %d (%d)\n",line,count);
fprintf(stderr,"\t%s",string);
}
else {
labels[num_files]=strdup(temp_label);
png_filenames[num_files]=strdup(temp_png);
sprintf(temp,"%s.AUX.ZX02",temp_zx02);
zx02_aux_filenames[num_files]=strdup(temp);
sprintf(temp,"%s.MAIN.ZX02",temp_zx02);
zx02_main_filenames[num_files]=strdup(temp);
num_files++;
if (num_files>=MAX_FILES) {
fprintf(stderr,"ERROR! Too many files!\n");
exit(-1);
}
}
}
if (num_files==0) {
fprintf(stderr,"ERROR! No files found!\n");
exit(-1);
}
/******************************************/
/* generate S file */
/******************************************/
sss=fopen(s_filename,"w");
if (sss==NULL) {
fprintf(stderr,"ERRROR opening %s\n",s_filename);
exit(-1);
}
fprintf(sss,"; Some nice double lores images\n\n");
fprintf(sss,".include \"../dlores_main.s\"\n\n");
fprintf(sss,"MAX_FILES = %d\n\n",num_files);
fprintf(sss,"main_filenames_low:\n");
for(i=0;i<num_files;i++) {
fprintf(sss,"\t.byte <%s_filename_main\n",labels[i]);
}
fprintf(sss,"\n");
fprintf(sss,"main_filenames_high:\n");
for(i=0;i<num_files;i++) {
fprintf(sss,"\t.byte >%s_filename_main\n",labels[i]);
}
fprintf(sss,"\n");
fprintf(sss,"aux_filenames_low:\n");
for(i=0;i<num_files;i++) {
fprintf(sss,"\t.byte <%s_filename_aux\n",labels[i]);
}
fprintf(sss,"\n");
fprintf(sss,"aux_filenames_high:\n");
for(i=0;i<num_files;i++) {
fprintf(sss,"\t.byte >%s_filename_aux\n",labels[i]);
}
fprintf(sss,"\n");
fprintf(sss,"; filename to open is 30-character Apple text:\n");
for(i=0;i<num_files;i++) {
fprintf(sss,"%s_filename_main:\t; %s\n",labels[i],zx02_main_filenames[i]);
fprintf(sss,"\t.byte ");
for(j=0;j<strlen(zx02_main_filenames[i]);j++) {
if (j!=0) fprintf(sss,",");
fprintf(sss,"\'%c\'|$80",zx02_main_filenames[i][j]);
}
fprintf(sss,",$00\n\n");
fprintf(sss,"%s_filename_aux:\t; %s\n",labels[i],zx02_aux_filenames[i]);
fprintf(sss,"\t.byte ");
for(j=0;j<strlen(zx02_aux_filenames[i]);j++) {
if (j!=0) fprintf(sss,",");
fprintf(sss,"\'%c\'|$80",zx02_aux_filenames[i][j]);
}
fprintf(sss,",$00\n\n");
}
fclose(sss);
/******************************************/
/* generate Makefile */
/******************************************/
/* don't over-write as a precaution */
if (access("Makefile", F_OK) == 0) {
fprintf(stderr,"Makefile already exists! Out of caution giving up.\n");
exit(-1);
}
sss=fopen("Makefile","w");
if (sss==NULL) {
fprintf(stderr,"ERRROR opening Makefile\n");
exit(-1);
}
fprintf(sss,"include ../../../Makefile.inc\n\n");
fprintf(sss,"ZX02 = ~/research/6502_compression/zx02.git/build/zx02\n");
fprintf(sss,"PNG_TO_DGR = ../../../utils/gr-utils/png2dgr\n");
fprintf(sss,"LINKER_SCRIPTS = ../../../linker_scripts\n");
fprintf(sss,"DOS33 = ../../../utils/dos33fs-utils/dos33\n");
fprintf(sss,"EMPTY_DISK = ../../../empty_disk/empty.dsk\n");
fprintf(sss,"TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft\n");
fprintf(sss,"\n");
fprintf(sss,"all:\t%s.dsk\n\n",filename_base);
fprintf(sss,"####\n\n");
fprintf(sss,"DLORES:\t%s.o\n",filename_base);
fprintf(sss,"\tld65 -o DLORES %s.o -C $(LINKER_SCRIPTS)/apple2_1000.inc\n\n",filename_base);
fprintf(sss,"%s.o:\t%s.s ../dlores_main.s ../zx02_optim.s \\\n",filename_base,filename_base);
fprintf(sss,"\t\t../zp.inc ../hardware.inc\n");
fprintf(sss,"\tca65 -o %s.o %s.s -l %s.lst\n",filename_base,filename_base,filename_base);
fprintf(sss,"####\n\n");
fprintf(sss,"HELLO:\t../hello.bas\n");
fprintf(sss,"\t$(TOKENIZE) < ../hello.bas > HELLO\n\n");
fprintf(sss,"####\n\n");
fprintf(sss,"%s.dsk:\tHELLO DLORES\\\n",filename_base);
for(i=0;i<num_files;i++) {
fprintf(sss,"\t\t%s.gr.main.zx02 %s.gr.aux.zx02",
png_filenames[i],png_filenames[i]);
if (i!=(num_files-1)) {
fprintf(sss,"\\");
}
fprintf(sss,"\n");
}
fprintf(sss,"\tcp $(EMPTY_DISK) %s.dsk\n",filename_base);
fprintf(sss,"\t$(DOS33) -y %s.dsk SAVE A HELLO\n",filename_base);
fprintf(sss,"\t$(DOS33) -y %s.dsk BSAVE -a 0x1000 DLORES\n",filename_base);
for(i=0;i<num_files;i++) {
fprintf(sss,"\t$(DOS33) -y %s.dsk BSAVE -a 0xa000 %s.gr.main.zx02 %s\n",
filename_base,
png_filenames[i],zx02_main_filenames[i]);
fprintf(sss,"\t$(DOS33) -y %s.dsk BSAVE -a 0xa000 %s.gr.aux.zx02 %s\n",
filename_base,
png_filenames[i],zx02_aux_filenames[i]);
}
fprintf(sss,"####\n\n");
fprintf(sss,"clean:\n");
fprintf(sss,"\trm -f *~ *.o *.lst\n\n");
fclose(sss);
/******************************************/
/* generate Makefile.graphics */
/******************************************/
sss=fopen("Makefile.graphics","w");
if (sss==NULL) {
fprintf(stderr,"ERRROR opening Makefile\n");
exit(-1);
}
fprintf(sss,"include ../../../Makefile.inc\n\n");
fprintf(sss,"ZX02 = ~/research/6502_compression/zx02.git/build/zx02\n");
fprintf(sss,"PNG_TO_DGR = ../../../utils/gr-utils/png2dgr\n");
fprintf(sss,"LINKER_SCRIPTS = ../../../linker_scripts\n");
fprintf(sss,"DOS33 = ../../../utils/dos33fs-utils/dos33\n");
fprintf(sss,"EMPTY_DISK = ../../../empty_disk/empty.dsk\n");
fprintf(sss,"TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft\n");
fprintf(sss,"\n");
fprintf(sss,"all:\\\n");
for(i=0;i<num_files;i++) {
fprintf(sss,"\t\t%s.gr.main.zx02 %s.gr.aux.zx02 ",
png_filenames[i],png_filenames[i]);
if (i!=(num_files-1)) {
fprintf(sss,"\\");
}
fprintf(sss,"\n");
}
// fprintf(sss,"\tcp $(EMPTY_DISK) %s.dsk\n",filename_base);
// fprintf(sss,"\t$(DOS33) -y %s.dsk SAVE A HELLO\n",filename_base);
// fprintf(sss,"\t$(DOS33) -y %s.dsk BSAVE -a 0x0c00 LORES\n",filename_base);
// for(i=0;i<num_files;i++) {
// fprintf(sss,"\t$(DOS33) -y %s.dsk BSAVE -a 0xa000 %s.gr.zx02 %s\n",
// filename_base,
// png_filenames[i],zx02_filenames[i]);
// }
for(i=0;i<num_files;i++) {
fprintf(sss,"\n####\n\n");
fprintf(sss,"%s.gr.main.zx02:\t%s.gr.main\n",png_filenames[i],png_filenames[i]);
fprintf(sss,"\t$(ZX02) %s.gr.main %s.gr.main.zx02\n",png_filenames[i],png_filenames[i]);
fprintf(sss,"\n");
fprintf(sss,"%s.gr.aux.zx02:\t%s.gr.aux\n",png_filenames[i],png_filenames[i]);
fprintf(sss,"\t$(ZX02) %s.gr.aux %s.gr.aux.zx02\n",png_filenames[i],png_filenames[i]);
fprintf(sss,"\n");
fprintf(sss,"%s.gr.main:\t%s.png\n",png_filenames[i],png_filenames[i]);
fprintf(sss,"\t$(PNG_TO_DGR) %s.png %s.gr\n",png_filenames[i],png_filenames[i]);
fprintf(sss,"\n");
fprintf(sss,"%s.gr.aux:\t%s.png\n",png_filenames[i],png_filenames[i]);
fprintf(sss,"\t$(PNG_TO_DGR) %s.png %s.gr\n",png_filenames[i],png_filenames[i]);
fprintf(sss,"\n");
}
fprintf(sss,"####\n\n");
fprintf(sss,"clean:\n");
fprintf(sss,"\trm -f *~ *.o *.lst\n\n");
fclose(sss);
return 0;
}