From cdcd274923495e552ee4699c43d5e0fb60c6c909 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Thu, 27 Sep 2018 20:43:47 -0400 Subject: [PATCH] png2gr: fix to work again hopefully I didn't break anything that depended on the old behavior --- gr-utils/loadpng.c | 5 +++++ gr-utils/png2gr.c | 38 ++++++++++++-------------------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/gr-utils/loadpng.c b/gr-utils/loadpng.c index ec00786f..12a20b7c 100644 --- a/gr-utils/loadpng.c +++ b/gr-utils/loadpng.c @@ -1,3 +1,8 @@ +/* Loads a 80x48 PNG image into a 40x48 Apple II layout */ +/* It's not interleaved like an actual Apple II */ +/* But the top/bottom are pre-packed into a naive 40x24 array */ + + #include #include diff --git a/gr-utils/png2gr.c b/gr-utils/png2gr.c index e074677c..2248dc89 100644 --- a/gr-utils/png2gr.c +++ b/gr-utils/png2gr.c @@ -19,6 +19,7 @@ int main(int argc, char **argv) { int col=0; int enough=0; int x; + unsigned char out_buffer[1024]; unsigned char *image; int xsize,ysize; @@ -42,36 +43,21 @@ int main(int argc, char **argv) { printf("Loaded image %d by %d\n",xsize,ysize); - x=0; - while(1) { - fputc( image[col+(row*xsize)] | - (image[col+(row+1)*xsize]<<4),outfile); - x++; - if (x>0x3f8) break; - enough++; - if (enough>119) { - /* screen hole */ - /* We should never BLOAD this image */ - /* as we can corrupt important state here */ - fputc(0,outfile); - fputc(0,outfile); - fputc(0,outfile); - fputc(0,outfile); - fputc(0,outfile); - fputc(0,outfile); - fputc(0,outfile); - fputc(0,outfile); - enough=0; - } + short gr_offsets[]={ + 0x400,0x480,0x500,0x580,0x600,0x680,0x700,0x780, + 0x428,0x4a8,0x528,0x5a8,0x628,0x6a8,0x728,0x7a8, + 0x450,0x4d0,0x550,0x5d0,0x650,0x6d0,0x750,0x7d0, + }; - col++; - if (col>39) { - col=0; - row+=16; - if (row>47) row-=46; + memset(out_buffer,0,1024); + for(row=0;row<24;row++) { + for(col=0;col<40;col++) { + out_buffer[(gr_offsets[row]-0x400)+col]=image[row*xsize+col]; } } + for(x=0;x<1024;x++) fputc( out_buffer[x],outfile); + fclose(outfile); return 0;