From 77db999e7dbbb14c11cf6b0294d2b88cd8a78e70 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Fri, 4 May 2012 15:33:00 -0400 Subject: [PATCH] pcx2hgr now works it generates color images that can be loaded with BLOAD IMAGE,A$2000 --- asoft_presenter/Makefile | 6 +- asoft_presenter/hgr.pal | 10 ++ pcx2hgr.c | 262 ++++++++++++++++++++++++++------------- 3 files changed, 189 insertions(+), 89 deletions(-) create mode 100644 asoft_presenter/hgr.pal diff --git a/asoft_presenter/Makefile b/asoft_presenter/Makefile index 5295c65f..5485fe55 100644 --- a/asoft_presenter/Makefile +++ b/asoft_presenter/Makefile @@ -5,10 +5,14 @@ LFLAGS = all: test.dsk -test.dsk: TEST +test.dsk: TEST VINCE.IMG ../dos33 test.dsk SAVE A TEST + ../dos33 test.dsk SAVE B VINCE.IMG +VINCE.IMG: vince.pcx ../pcx2hgr + ../pcx2hgr vince.pcx > VINCE.IMG + TEST: test.bas ../tokenize_asoft < test.bas > TEST diff --git a/asoft_presenter/hgr.pal b/asoft_presenter/hgr.pal new file mode 100644 index 00000000..1579ecac --- /dev/null +++ b/asoft_presenter/hgr.pal @@ -0,0 +1,10 @@ +GIMP Palette +Name: Apple II HGR +Columns: 0 +# + 0 0 0 Black + 27 203 1 Green +228 52 254 Purple +255 255 255 White +205 91 1 Orange + 27 154 254 Blue diff --git a/pcx2hgr.c b/pcx2hgr.c index ad644ec6..a409556d 100644 --- a/pcx2hgr.c +++ b/pcx2hgr.c @@ -1,22 +1,22 @@ -/* Converts 280x160 8-bit PCX file with correct palette to Apple II HGR */ +/* Converts 140x192 8-bit PCX file with correct palette to Apple II HGR */ #include /* For FILE I/O */ #include /* For strncmp */ #include /* for open() */ #include /* for lseek() */ #include /* for file modes */ - +#include /* free() */ #define PCX_UNKNOWN 0 #define PCX_8BIT 1 #define PCX_24BIT 2 -int debug=1; +static int debug=0; static int vmwGetPCXInfo(char *filename, int *xsize, int *ysize, int *type) { unsigned char pcx_header[128]; - int xmin,ymin,xmax,ymax,version=PCX_UNKNOWN,bpp,debug=1,pcx_fd; + int xmin,ymin,xmax,ymax,version=PCX_UNKNOWN,bpp,pcx_fd; int result; /* Open the file */ @@ -90,16 +90,18 @@ static int vmwGetPCXInfo(char *filename, int *xsize, int *ysize, int *type) { return 0; } +unsigned char colors[256]; + static int vmwLoadPCX(char *filename, unsigned char *framebuffer) { int pcx_fd; - /* int x,y,i,numacross,xsize,ysize,xmin,ymin; unsigned int r,g,b; - int bpp,planes,bpl,xmax,ymax,version; + int xmax,ymax; unsigned char pcx_header[128]; unsigned char temp_byte; - */ + int result; + unsigned char *pointer=framebuffer; /* Open the file */ pcx_fd=open(filename,O_RDONLY); @@ -109,102 +111,93 @@ static int vmwLoadPCX(char *filename, unsigned char *framebuffer) { return -1; } -#if 0 - /*************** DECODE THE HEADER *************************/ - read(pcx_fd,&pcx_header,128); - + result=read(pcx_fd,&pcx_header,128); + if (result<0) { + fprintf(stderr,"ERROR opening header of file %s\n",filename); + } + xmin=(pcx_header[5]<<8)+pcx_header[4]; ymin=(pcx_header[7]<<8)+pcx_header[6]; xmax=(pcx_header[9]<<8)+pcx_header[8]; ymax=(pcx_header[11]<<8)+pcx_header[10]; - version=pcx_header[1]; - bpp=pcx_header[3]; - planes=pcx_header[65]; - bpl=(pcx_header[67]<<8)+pcx_header[66]; - xsize=((xmax-xmin)+1); ysize=((ymax-ymin)+1); - /* Possibly add some sanity checking in the header at some point... */ - /* Or actually even get the proper VALUES from the header. Some day... */ - - if (LoadPic) { - - - unsigned char *pointer=target->memory; - - x=0; y=0; + x=0; y=0; - while (x 0xc0, then it's a RLE byte */ + if (0xc0 == (temp_byte&0xc0)) { + numacross=temp_byte&0x3f; + result=read(pcx_fd,&temp_byte,1); + for(i=0;i0)<<7); + byte2=((fourteen_bits>>7)&0x7f)|((pal[1]>0)<<7); + + page=(y%8); + block=((y/8)%8); + leaf=(y/64); + + yoffset=(page*1024) + (block*128) + (leaf*40); + /* + printf("%d %d = %x %x %x\n",x,y,fourteen_bits,yoffset, + yoffset+(x*2)); + */ + hgr=out_framebuffer+yoffset+(x*2); + + *hgr=byte1; + *(hgr+1)=byte2; + } + } + + unsigned char header[4]; + + + /* assume HGR page 1 */ + int offset=8192; + int file_size=8184; + + header[0]=offset&0xff; + header[1]=(offset>>8)&0xff; + header[2]=file_size&0xff; + header[3]=(file_size>>8)&0xff; + + fwrite(header,sizeof(unsigned char),4,stdout); + + /* Don't need the last 8 bytes; makes it fit in one fewer disk sectors */ + fwrite(out_framebuffer,sizeof(unsigned char),8184,stdout); + + free(out_framebuffer); + free(in_framebuffer); + return 0;