--- /dev/null
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include "bitmap.h"\r
+#include "modex16.h"\r
+\r
+static struct pcxHeader {\r
+ byte id;\r
+ byte version;\r
+ byte encoding;\r
+ byte bpp;\r
+ word xmin;\r
+ word ymin;\r
+ word xmax;\r
+ word ymax;\r
+ word hres;\r
+ word vres;\r
+ byte pal16[48];\r
+ byte res1;\r
+ word bpplane;\r
+ word palType;\r
+ word hScreenSize;\r
+ word vScreenSize;\r
+ byte padding[54];\r
+};\r
+\r
+\r
+static void loadPcxStage1(FILE *file, bitmap_t *result) {\r
+ struct pcxHeader head;\r
+ long bufSize;\r
+ int index;\r
+ byte count, val;\r
+ long int pos;\r
+\r
+ /* read the header */\r
+ fread(&head, sizeof(char), sizeof(struct pcxHeader), file);\r
+\r
+ /* make sure this is 8bpp */\r
+ if(head.bpp != 8) {\r
+ printf("I only know how to handle 8bpp pcx files!\n");\r
+ fclose(file);\r
+ exit(-2);\r
+ }\r
+\r
+ /* allocate the buffer */\r
+ result->width = head.xmax - head.xmin + 1;\r
+ result->height = head.ymax - head.ymin + 1;\r
+ bufSize = result->width * result->height;\r
+ result->data = malloc(bufSize);\r
+ if(!result->data) {\r
+ printf("Could not allocate memory for bitmap data.");\r
+ fclose(file);\r
+ exit(-1);\r
+ }\r
+\r
+ /* save the position of the pixel data */\r
+ pos = ftell(file);\r
+\r
+ /* handle the palette */\r
+ fseek(file, -769, SEEK_END);\r
+ val = fgetc(file);\r
+ result->palette = modexNewPal();\r
+ if(head.version == 5 && val == 12) {\r
+ /* use the vga palette */\r
+ for(index=0; !feof(file) && index < PAL_SIZE; index++) {\r
+ val = fgetc(file);\r
+ result->palette[index] = val >> 2;\r
+ }\r
+ } else {\r
+ /* use the 16 color palette */\r
+ for(index=0; index<48; index++) {\r
+ result->palette[index] = head.pal16[index];\r
+ }\r
+ }\r
+\r
+ /* go back to the pixel data */\r
+ fseek(file, -pos, SEEK_END);\r
+}\r
+\r
+\r
+bitmap_t\r
+bitmapLoadPcx(char *filename) {\r
+ FILE *file;\r
+ bitmap_t result;\r
+ struct pcxHeader head;\r
+ long bufSize;\r
+ int index;\r
+ byte count, val;\r
+\r
+ /* open the PCX file for reading */\r
+ file = fopen(filename, "rb");\r
+ if(!file) {\r
+ printf("Could not open %s for reading.\n", filename);\r
+ exit(-2);\r
+ }\r
+\r
+ /* load the first part of the pcx file */\r
+ loadPcxStage1(file, &result);\r
+\r
+ /* read the buffer in */\r
+ index = 0;\r
+ do {\r
+ /* get the run length and the value */\r
+ count = fgetc(file);\r
+ if(0xC0 == (count & 0xC0)) { /* this is the run count */\r
+ count &= 0x3f;\r
+ val = fgetc(file);\r
+ } else {\r
+ val = count;\r
+ count = 1;\r
+ }\r
+\r
+ /* write the pixel the specified number of times */\r
+ for(; count && index < bufSize; count--,index++) {\r
+ result.data[index] = val;\r
+ }\r
+ } while(index < bufSize);\r
+\r
+\r
+ fclose(file);\r
+\r
+ return result;\r
+}\r
+\r
+\r
+tileset_t\r
+bitmapLoadPcxTiles(char *filename, word twidth, word theight) {\r
+ tileset_t ts;\r
+\r
+ return ts;\r
+}\r
--- /dev/null
+/*\r
+ * Functions and types for loading and manipulating bitmaps.\r
+ */\r
+#ifndef BITMAP_H\r
+#define BITMAP_H\r
+#include "types.h"\r
+typedef struct {\r
+ byte *data;\r
+ word width;\r
+ word height;\r
+ byte *palette;\r
+} bitmap_t;\r
+\r
+typedef struct {\r
+ byte **data;\r
+ word ntiles; /* the number of tiles */\r
+ word twidth; /* width of the tiles */\r
+ word theight; /* height of the tiles */\r
+ byte *palette; /* palette for the tile set */\r
+} tileset_t;\r
+\r
+bitmap_t bitmapLoadPcx(char *filename);\r
+tileset_t bitmapLoadPcxTiles(char *filename, word twidth, word theight);\r
+#endif\r
FLAGS=-0 \r
all: test.exe pcxtest.exe test2.exe scroll.exe\r
\r
-scroll.exe: scroll.obj modex16.obj dos_kb.obj\r
- wcl $(FLAGS) scroll.obj modex16.obj dos_kb.obj\r
+scroll.exe: scroll.obj modex16.obj dos_kb.obj bitmap.obj\r
+ wcl $(FLAGS) scroll.obj modex16.obj dos_kb.obj bitmap.obj\r
scroll.obj: scroll.c\r
wcl $(FLAGS) -c scroll.c\r
-test.exe: test.obj modex16.obj\r
- wcl $(FLAGS) test.obj modex16.obj\r
+test.exe: test.obj modex16.obj bitmap.obj\r
+ wcl $(FLAGS) test.obj modex16.obj bitmap.obj\r
\r
-test2.exe: test2.obj modex16.obj\r
- wcl $(FLAGS) test2.obj modex16.obj\r
+test2.exe: test2.obj modex16.obj bitmap.obj\r
+ wcl $(FLAGS) test2.obj modex16.obj bitmap.obj\r
\r
-pcxtest.exe: pcxtest.obj modex16.obj\r
- wcl $(FLAGS) pcxtest.obj modex16.obj\r
+pcxtest.exe: pcxtest.obj modex16.obj bitmap.obj\r
+ wcl $(FLAGS) pcxtest.obj modex16.obj bitmap.obj\r
\r
test.obj: test.c modex16.h\r
wcl $(FLAGS) -c test.c\r
\r
modex16.obj: modex16.h modex16.c\r
wcl $(FLAGS) -c modex16.c\r
-
+\r
dos_kb.obj: dos_kb.h dos_kb.c\r
- wcl $(FLAGS) -c dos_kb.c
+ wcl $(FLAGS) -c dos_kb.c\r
\r
+bitmap.obj: bitmap.h bitmap.c\r
+ wcl $(FLAGS) -c bitmap.c\r
+ \r
clean: \r
del *.obj\r
del *.exe\r