From: sparky4 Date: Sun, 24 May 2015 05:48:12 +0000 (-0500) Subject: huge memory model fucks up everything! wwww X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=8b92f32b6e6a8ab7be52ced02208cc789364a014;p=16.git huge memory model fucks up everything! wwww modified: makefile modified: maptest.exe modified: pcxtest.exe modified: scroll.exe modified: src/lib/bitmap.c modified: src/lib/bitmap.h modified: src/lib/lib_head.c modified: src/lib/lib_head.h modified: src/lib/mapread.h modified: src/lib/modex16.h modified: src/maptest.c modified: src/pcxtest.c modified: src/test.c modified: src/test2.c modified: test.exe modified: test2.exe --- diff --git a/makefile b/makefile index cba89784..c108e708 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ OFLAGS=-ot -ox -ob -ol -oh -or -FLAGS=-0 -d2 -mh -wo $(OFLAGS) +FLAGS=-0 -d2 -wo $(OFLAGS)# -mh DIRSEP=\ SRC=src$(DIRSEP) SRCLIB=$(SRC)lib$(DIRSEP) @@ -20,8 +20,8 @@ test2.exe: test2.obj modex16.obj bitmap.obj planar.obj pcxtest.exe: pcxtest.obj modex16.obj bitmap.obj wcl $(FLAGS) pcxtest.obj modex16.obj bitmap.obj -maptest.exe: maptest.obj mapread.obj jsmn.obj modex16.obj bitmap.obj - wcl $(FLAGS) maptest.obj mapread.obj jsmn.obj modex16.obj bitmap.obj +maptest.exe: maptest.obj mapread.obj jsmn.obj modex16.obj bitmap.obj lib_head.obj + wcl $(FLAGS) maptest.obj mapread.obj jsmn.obj modex16.obj bitmap.obj lib_head.obj test.obj: $(SRC)test.c $(SRCLIB)modex16.h @@ -49,15 +49,15 @@ bitmap.obj: $(SRCLIB)bitmap.h $(SRCLIB)bitmap.c planar.obj: $(SRCLIB)planar.h $(SRCLIB)planar.c wcl $(FLAGS) -c $(SRCLIB)planar.c -mapread.obj: $(SRCLIB)mapread.h $(SRCLIB)mapread.c lib_head.obj jsmn.obj +mapread.obj: $(SRCLIB)mapread.h $(SRCLIB)mapread.c# lib_head.obj jsmn.obj wcl $(FLAGS) -c $(SRCLIB)mapread.c lib_head.obj: $(SRCLIB)lib_head.h $(SRCLIB)lib_head.c wcl $(FLAGS) -c $(SRCLIB)lib_head.c jsmn.obj: $(JSMNLIB)jsmn.h $(JSMNLIB)jsmn.c - wcl $(FLAGS) -c $(JSMNLIB)jsmn.c - + wcl $(FLAGS) -c $(JSMNLIB)jsmn.c + clean: del *.obj # del *.exe diff --git a/maptest.exe b/maptest.exe index e08e7d4e..8c75a739 100644 Binary files a/maptest.exe and b/maptest.exe differ diff --git a/pcxtest.exe b/pcxtest.exe index 2b66334a..2c9959a3 100644 Binary files a/pcxtest.exe and b/pcxtest.exe differ diff --git a/scroll.exe b/scroll.exe index f6d853d7..74b3f6c5 100644 Binary files a/scroll.exe and b/scroll.exe differ diff --git a/src/lib/bitmap.c b/src/lib/bitmap.c index a5a43944..3777c3d1 100644 --- a/src/lib/bitmap.c +++ b/src/lib/bitmap.c @@ -1,5 +1,6 @@ #include -#include +#include +#include #include "src/lib/bitmap.h" #include "src/lib/modex16.h" @@ -39,9 +40,9 @@ static void loadPcxStage1(FILE *file, bitmap_t *result) { /* make sure this is 8bpp */ if(head.bpp != 8) { - printf("I only know how to handle 8bpp pcx files!\n"); - fclose(file); - exit(-2); + printf("I only know how to handle 8bpp pcx files!\n"); + fclose(file); + exit(-2); } } @@ -73,28 +74,34 @@ bitmap_t bitmapLoadPcx(char *filename) { FILE *file; bitmap_t result; - long bufSize; + dword 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); + printf("Could not open %s for reading.\n", filename); + exit(-2); } /* load the first part of the pcx file */ loadPcxStage1(file, &result); /* allocate the buffer */ - bufSize = result.width * result.height; - result.data = malloc(bufSize); //it breaks right here~ - if(!result.data) { - printf("Could not allocate memory for bitmap data."); - fclose(file); - exit(-1); - } + bufSize = ((dword)result.width * result.height); + result.data = malloc((bufSize)); + /*0000printf("Size of block is %u bytes\n", _msize(result.data)); + printf("Size of bufSize is %lu bytes\n", bufSize); + printf("Size of result.width is %lu \n", result.width); + printf("Size of result.height is %lu \n", result.height); + printf("Dimensions of result is %lu\n", result.width*result.height);*/ + //exit(0); + if(!result.data) { + fprintf(stderr, "Could not allocate memory for bitmap data."); + fclose(file); + exit(-1); + } /* read the buffer in */ index = 0; @@ -102,16 +109,16 @@ bitmapLoadPcx(char *filename) { /* get the run length and the value */ count = fgetc(file); if(0xC0 == (count & 0xC0)) { /* this is the run count */ - count &= 0x3f; - val = fgetc(file); + count &= 0x3f; + val = fgetc(file); } else { - val = count; - count = 1; + val = count; + count = 1; } /* write the pixel the specified number of times */ for(; count && index < bufSize; count--,index++) { - result.data[index] = val; + result.data[index] = val; } } while(index < bufSize); @@ -122,7 +129,7 @@ bitmapLoadPcx(char *filename) { return result; } - +//update!! tileset_t bitmapLoadPcxTiles(char *filename, word twidth, word theight) { tileset_t ts; @@ -132,10 +139,10 @@ bitmapLoadPcxTiles(char *filename, word twidth, word theight) { /* open the PCX file for reading */ file = fopen(filename, "rb"); - if(!file) { - printf("Could not open %s for reading.\n", filename); - exit(-2); - } + if(!file) { + printf("Could not open %s for reading.\n", filename); + exit(-2); + } /* load the first part of the pcx file */ loadPcxStage1(file, &result); @@ -146,12 +153,12 @@ bitmapLoadPcxTiles(char *filename, word twidth, word 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; - } + /* 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); diff --git a/src/lib/bitmap.h b/src/lib/bitmap.h index 19ae2f04..f1b126e5 100644 --- a/src/lib/bitmap.h +++ b/src/lib/bitmap.h @@ -3,22 +3,23 @@ */ #ifndef BITMAP_H #define BITMAP_H -//#include -#include "src/lib/types.h" +#include "src/lib/types.h" +#include "src/lib/lib_head.h" + typedef struct { - byte *data; - word width; - word height; - byte *palette; - word offset; + byte *data; + word width; + word height; + byte *palette; + word offset; } bitmap_t; typedef struct { - byte **data; - word ntiles; /* the number of tiles */ - word twidth; /* width of the tiles */ - word theight; /* height of the tiles */ - byte *palette; /* palette for the tile set */ + byte **data; + word ntiles; /* the number of tiles */ + word twidth; /* width of the tiles */ + word theight; /* height of the tiles */ + byte *palette; /* palette for the tile set */ } tileset_t; bitmap_t bitmapLoadPcx(char *filename); diff --git a/src/lib/lib_head.c b/src/lib/lib_head.c index e9004d5e..0053446f 100644 --- a/src/lib/lib_head.c +++ b/src/lib/lib_head.c @@ -3,7 +3,8 @@ /* local function */ void wait(clock_t wait); void* AllocateLargestFreeBlock(size_t* Size); -size_t GetFreeSize(void); +size_t GetFreeSize(void); +long int filesize(FILE *fp); /* Function: Wait ********************************************************** * @@ -93,3 +94,15 @@ size_t GetFreeSize(void) return total; } + +long int +filesize(FILE *fp) +{ + long int save_pos, size_of_file; + + save_pos = ftell(fp); + fseek(fp, 0L, SEEK_END); + size_of_file = ftell(fp); + fseek(fp, save_pos, SEEK_SET); + return(size_of_file); +} diff --git a/src/lib/lib_head.h b/src/lib/lib_head.h index 34fcb3a0..5bc441af 100644 --- a/src/lib/lib_head.h +++ b/src/lib/lib_head.h @@ -106,6 +106,7 @@ void wait(clock_t wait); void* AllocateLargestFreeBlock(size_t* Size); size_t GetFreeSize(void); +long int filesize(FILE *fp); /* THIS FUNCTION CONVERTS A POINTER TO AN INTEL LONG */ //int long ptr2long(char *p); diff --git a/src/lib/mapread.h b/src/lib/mapread.h index 1ce7b01e..eaca2566 100644 --- a/src/lib/mapread.h +++ b/src/lib/mapread.h @@ -9,6 +9,7 @@ #include "src/lib/modex16.h" #include "src/lib/lib_head.h" +//---- temp! static char *js_sv; typedef struct { diff --git a/src/lib/modex16.h b/src/lib/modex16.h index fa9e54e0..755a11c8 100644 --- a/src/lib/modex16.h +++ b/src/lib/modex16.h @@ -3,7 +3,7 @@ */ #ifndef MODEX16_H #define MODEX16_H -#include +//#include #include "src/lib/types.h" #include "src/lib/bitmap.h" #include "src/lib/planar.h" diff --git a/src/maptest.c b/src/maptest.c index dfcd300d..48c022d1 100644 --- a/src/maptest.c +++ b/src/maptest.c @@ -4,6 +4,6 @@ void main(int argc, char *argv[]) { map_t map; - //loadmap("data/test.map", &map); + loadmap("data/test.map", &map); fprintf(stderr, "%d\n", map.data[0]); } diff --git a/src/pcxtest.c b/src/pcxtest.c index be8dcc7a..3901c238 100644 --- a/src/pcxtest.c +++ b/src/pcxtest.c @@ -5,7 +5,7 @@ #include "src/lib/bitmap.h" #include "src/lib/planar.c" -word far* clock= (word far*) 0x046C; /* 18.2hz clock */ +word far* clockw= (word far*) 0x046C; /* 18.2hz clock */ void oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite) { @@ -55,7 +55,8 @@ DrawPBuf(page_t *page, int x, int y, planar_buf_t *p, byte sprite) void main() { bitmap_t bmp; planar_buf_t *p; - int i; + //int i; + dword i; page_t page; word start; int plane; @@ -65,6 +66,8 @@ void main() { //0000 bmp = bitmapLoadPcx("data/koishi~~.pcx"); bmp = bitmapLoadPcx("data/chikyuu.pcx"); +// bmp = bitmapLoadPcx("data/koishi^^.pcx"); +// bmp = bitmapLoadPcx("16/PCX_LIB/chikyuu.pcx"); //0000 p = planar_buf_from_bitmap(&bmp); modexEnter(); @@ -75,47 +78,53 @@ void main() { modexClearRegion(&page, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 1); /* non sprite comparison */ - /*0000start = *clock; + /*0000start = *clockw; for(i=0; i<100 ;i++) { oldDrawBmp(VGA, 20, 20, &bmp, 0); } - start = *clock; + start = *clockw; for(i=0; i<100 ;i++) { //0000 modexDrawBmp(&page, 20, 20, &bmp); modexDrawBmp(&page, 0, 0, &bmp); } - t1 = (*clock-start) /18.2; + t1 = (*clockw-start) /18.2; - start = *clock; + start = *clockw; for(i=0; i<100; i++) { //0000 modexCopyPageRegion(&page, &page, 20, 20, 128, 20, 64, 64); modexCopyPageRegion(&page, &page, 0, 0, 0, 0, 320, 240); } - t2 = (*clock-start)/18.2; + t2 = (*clockw-start)/18.2; - start = *clock; + start = *clockw; for(i=0; i<100 ;i++) { oldDrawBmp(VGA, 20, 20, &bmp, 1); } - start = *clock; + start = *clockw; for(i=0; i<100 ;i++) { //0000 modexDrawSprite(&page, 20, 20, &bmp); modexDrawSprite(&page, 0, 0, &bmp); }*/ //_fmemset(MK_FP(0xA000, 0), (int)p->plane, SCREEN_WIDTH*(SCREEN_HEIGHT*2)); + modexDrawBmp(&page, 0, 0, &bmp); while(!kbhit()) { //DrawPBuf(&page, 0, 0, p, 0); - modexDrawBmp(&page, 0, 0, &bmp); } modexLeave(); printf("\n%d\n", sizeof(p->plane)); - printf("%d\n", sizeof(bmp)); + printf("%d\n", sizeof(bmp)); + + /*for(i=0; i<(320*240); i++) + { + fprintf(stdout, "%d", bmp.data[i]); + if(i%320==0) fprintf(stdout, "\n"); + }*/ //0000 printf("CPU to VGA: %f\n", t1); //0000 printf("VGA to VGA: %f\n", t2); return; diff --git a/src/test.c b/src/test.c index 24520a53..3e2b1e6f 100644 --- a/src/test.c +++ b/src/test.c @@ -1,7 +1,7 @@ #include "src/lib/modex16.h" #include -word far* clock= (word far*) 0x046C; /* 18.2hz clock */ +word far* clockw= (word far*) 0x046C; /* 18.2hz clock */ void main() { int i, j; @@ -39,7 +39,7 @@ void main() { modexFadeOn(1, pal2); - start = *clock; + start = *clockw; for(i=0; i<5; i++) { /* go right */ for(j=0; j<32; j++) { @@ -64,7 +64,7 @@ void main() { } } - end = *clock; + end = *clockw; /* fade back to text mode */ modexFadeOff(1, pal2); diff --git a/src/test2.c b/src/test2.c index 8926372d..2f76a02e 100644 --- a/src/test2.c +++ b/src/test2.c @@ -2,9 +2,9 @@ #include #include "src/lib/modex16.h" #include "src/lib/planar.h" -#include "src/lib/bitmap.h" +//#include "src/lib/bitmap.h" -word far* clock= (word far*) 0x046C; /* 18.2hz clock */ +word far* clockw= (word far*) 0x046C; /* 18.2hz clock */ void main() { FILE *file; diff --git a/test.exe b/test.exe index 38fef807..f79cea4e 100644 Binary files a/test.exe and b/test.exe differ diff --git a/test2.exe b/test2.exe index d1a35e55..a289dfd0 100644 Binary files a/test2.exe and b/test2.exe differ