From: Robert Lowe Date: Wed, 1 Oct 2014 02:01:10 +0000 (-0400) Subject: Refactored out the PCX functions. X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=5c8db81871ff53318c10d77ebdd424e49c24a48a;p=16.git Refactored out the PCX functions. Started on a better tile loader --- diff --git a/16/modex16/BITMAP.C b/16/modex16/BITMAP.C index b1521526..8287e57d 100644 --- a/16/modex16/BITMAP.C +++ b/16/modex16/BITMAP.C @@ -126,6 +126,37 @@ bitmapLoadPcx(char *filename) { tileset_t bitmapLoadPcxTiles(char *filename, word twidth, word theight) { tileset_t ts; + FILE *file; + bitmap_t result; + int i; + + /* open the PCX file for reading */ + file = fopen(filename, "rb"); + if(!file) { + printf("Could not open %s for reading.\n", filename); + exit(-2); + } + + /* load the first part of the pcx file */ + loadPcxStage1(file, &result); + + /* get the number of tiles and set up the result structure */ + ts.twidth = twidth; + ts.theight = theight; + ts.ntiles = (result.width/twidth) * (result.height/theight); + ts.palette = result.palette; + + /* allocate the pixel storage for the tiles */ + ts.data = malloc(sizeof(byte*) * ts.ntiles); + ts.data[0] = malloc(sizeof(byte) * ts.ntiles * twidth * theight); + for(i=1; i < ts.ntiles; i++) { + ts.data[i] = ts.data[i-1] + twidth * theight; + } + + /* finish off the file */ + loadPcxPalette(file, &result); + + fclose(file); return ts; } diff --git a/16/modex16/modex16.c b/16/modex16/modex16.c index 71537b66..f01116b5 100644 --- a/16/modex16/modex16.c +++ b/16/modex16/modex16.c @@ -11,26 +11,6 @@ byte far* VGA=(byte far*) 0xA0000000; /* this points to video memory. */ static void fadePalette(sbyte fade, sbyte start, word iter, byte *palette); static byte tmppal[PAL_SIZE]; -static struct pcxHeader { - byte id; - byte version; - byte encoding; - byte bpp; - word xmin; - word ymin; - word xmax; - word ymax; - word hres; - word vres; - byte pal16[48]; - byte res1; - word bpplane; - word palType; - word hScreenSize; - word vScreenSize; - byte padding[54]; -}; - static void vgaSetMode(byte mode) @@ -623,82 +603,3 @@ modexWaitBorder() { /* spin */ } } - - -bitmap_t -modexLoadPcx(char *filename) { - FILE *file; - bitmap_t result; - struct pcxHeader head; - long bufSize; - int index; - byte count, val; - - /* open the PCX file for reading */ - file = fopen(filename, "rb"); - if(!file) { - printf("Could not open %s for reading.\n", filename); - exit(-2); - } - - /* read the header */ - fread(&head, sizeof(char), sizeof(struct pcxHeader), file); - - /* make sure this is 8bpp */ - if(head.bpp != 8) { - printf("I only know how to handle 8bpp pcx files!\n"); - fclose(file); - exit(-2); - } - - /* allocate the buffer */ - result.width = head.xmax - head.xmin + 1; - result.height = head.ymax - head.ymin + 1; - bufSize = result.width * result.height; - result.data = malloc(bufSize); - if(!result.data) { - printf("Could not allocate memory for bitmap data."); - fclose(file); - exit(-1); - } - - /* read the buffer in */ - index = 0; - do { - /* get the run length and the value */ - count = fgetc(file); - if(0xC0 == (count & 0xC0)) { /* this is the run count */ - count &= 0x3f; - val = fgetc(file); - } else { - val = count; - count = 1; - } - - /* write the pixel the specified number of times */ - for(; count && index < bufSize; count--,index++) { - result.data[index] = val; - } - } while(index < bufSize); - - /* handle the palette */ - fseek(file, -769, SEEK_END); - val = fgetc(file); - result.palette = modexNewPal(); - if(head.version == 5 && val == 12) { - /* use the vga palette */ - for(index=0; !feof(file) && index < PAL_SIZE; index++) { - val = fgetc(file); - result.palette[index] = val >> 2; - } - } else { - /* use the 16 color palette */ - for(index=0; index<48; index++) { - result.palette[index] = head.pal16[index]; - } - } - - fclose(file); - - return result; -} diff --git a/16/modex16/modex16.h b/16/modex16/modex16.h index f45356b5..77573105 100644 --- a/16/modex16/modex16.h +++ b/16/modex16/modex16.h @@ -55,9 +55,6 @@ void modexPalWhite(); void modexPalUpdate(byte *p); void modexWaitBorder(); -/* bitmap functions */ -bitmap_t modexLoadPcx(char *filename); - /* -======================= Constants & Vars ==========================- */ extern byte far* VGA; /* The VGA Memory */ #define SCREEN_SEG 0xa000 diff --git a/16/modex16/pcxtest.exe b/16/modex16/pcxtest.exe index 2ae847e5..20910efc 100644 Binary files a/16/modex16/pcxtest.exe and b/16/modex16/pcxtest.exe differ diff --git a/16/modex16/scroll.exe b/16/modex16/scroll.exe index 5e87bdc4..46167a51 100755 Binary files a/16/modex16/scroll.exe and b/16/modex16/scroll.exe differ diff --git a/16/modex16/test.exe b/16/modex16/test.exe index 8efde54e..63a3da16 100644 Binary files a/16/modex16/test.exe and b/16/modex16/test.exe differ diff --git a/16/modex16/test2.exe b/16/modex16/test2.exe index ab461641..d0b6755c 100644 Binary files a/16/modex16/test2.exe and b/16/modex16/test2.exe differ