X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_ca.c;h=dcdcaa1c3bc65b262a78fc6439bcd36eacc7f9ad;hb=29204d5f82b02c730907d7cdf6760f291ae8e93e;hp=bacb7181c155ae93232dfda2c69423aa478553bd;hpb=c4ea89ef8cb104fb6f9f9edd4f4bf55e7984a51f;p=16.git diff --git a/src/lib/16_ca.c b/src/lib/16_ca.c old mode 100644 new mode 100755 index bacb7181..dcdcaa1c --- a/src/lib/16_ca.c +++ b/src/lib/16_ca.c @@ -30,15 +30,14 @@ loaded into the data segment ============================================================================= */ -#include "ID_HEADS.H" +#include "src/lib/16_ca.h" #pragma hdrstop -#include "ID_STRS.H" #pragma warn -pro #pragma warn -use -#define THREEBYTEGRSTARTS - +//#define THREEBYTEGRSTARTS +//https://github.com/open-watcom/open-watcom-v2/issues/279#issuecomment-244587566 for _seg /* ============================================================================= @@ -47,18 +46,18 @@ loaded into the data segment ============================================================================= */ -typedef struct +/*typedef struct { - unsigned bit0,bit1; // 0-255 is a character, > is a pointer to a node -} huffnode; + word bit0,bit1; // 0-255 is a character, > is a pointer to a node +} huffnode;*/ -typedef struct +/*typedef struct { unsigned RLEWtag; long headeroffsets[100]; byte tileinfo[]; -} mapfiletype; +} mapfiletype;*/ /* @@ -69,7 +68,7 @@ typedef struct ============================================================================= */ -byte _seg *tinf; +/*byte _seg *tinf; int mapon; unsigned _seg *mapsegs[3]; @@ -77,10 +76,7 @@ maptype _seg *mapheaderseg[NUMMAPS]; byte _seg *audiosegs[NUMSNDCHUNKS]; void _seg *grsegs[NUMCHUNKS]; -byte far grneeded[NUMCHUNKS]; -byte ca_levelbit,ca_levelnum; - -int profilehandle,debughandle; +byte far grneeded[NUMCHUNKS];*/ void (*drawcachebox) (char *title, unsigned numcache); void (*updatecachebox) (void); @@ -94,7 +90,7 @@ void (*finishcachebox) (void); ============================================================================= */ -extern long far CGAhead; +/*extern long far CGAhead; extern long far EGAhead; extern byte CGAdict; extern byte EGAdict; @@ -132,12 +128,11 @@ SDMode oldsoundmode; void CAL_DialogDraw (char *title,unsigned numcache); void CAL_DialogUpdate (void); -void CAL_DialogFinish (void); -void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, - unsigned length); +void CAL_DialogFinish (void);*/ +//void CAL_CarmackExpand (unsigned far *source, unsigned far *dest,unsigned length); -#ifdef THREEBYTEGRSTARTS +/*++++#ifdef THREEBYTEGRSTARTS #define FILEPOSSIZE 3 //#define GRFILEPOS(c) (*(long far *)(((byte far *)grstarts)+(c)*3)&0xffffff) long GRFILEPOS(int c) @@ -159,7 +154,7 @@ long GRFILEPOS(int c) #else #define FILEPOSSIZE 4 #define GRFILEPOS(c) (grstarts[c]) -#endif +#endif*/ /* ============================================================================= @@ -178,16 +173,21 @@ long GRFILEPOS(int c) = ============================ */ - -void CA_OpenDebug (void) +void CA_OpenDebug(global_game_variables_t *gvar) { - unlink ("DEBUG.TXT"); - debughandle = open("DEBUG.TXT", O_CREAT | O_WRONLY | O_TEXT); +#ifdef __BORLANDC__ + unlink("debug.16b"); + gvar->handle.debughandle = open("debug.16b", O_CREAT | O_WRONLY | O_TEXT); +#endif +#ifdef __WATCOMC__ + unlink("debug.16w"); + gvar->handle.debughandle = open("debug.16w", O_CREAT | O_WRONLY | O_TEXT); +#endif } -void CA_CloseDebug (void) +void CA_CloseDebug(global_game_variables_t *gvar) { - close (debughandle); + close(gvar->handle.debughandle); } @@ -202,13 +202,13 @@ void CA_CloseDebug (void) = ============================ */ - +/*++++ void CAL_GetGrChunkLength (int chunk) { lseek(grhandle,GRFILEPOS(chunk),SEEK_SET); read(grhandle,&chunkexplen,sizeof(chunkexplen)); chunkcomplen = GRFILEPOS(chunk+1)-GRFILEPOS(chunk)-4; -} +}*/ /* @@ -221,29 +221,65 @@ void CAL_GetGrChunkLength (int chunk) ========================== */ -boolean CA_FarRead (int handle, byte far *dest, long length) +boolean CA_FarRead(int handle, byte far *dest, dword length, global_game_variables_t *gvar) { - if (length>0xffffl) - Quit ("CA_FarRead doesn't support 64K reads yet!"); - -asm push ds -asm mov bx,[handle] -asm mov cx,[WORD PTR length] -asm mov dx,[WORD PTR dest] -asm mov ds,[WORD PTR dest+2] -asm mov ah,0x3f // READ w/handle -asm int 21h -asm pop ds -asm jnc good - errno = _AX; - return false; + boolean flag=0; + //dword fat=0; + //word segm=0; + if(gvar->pm.emm.EMSVer<0x40) + if(length>0xfffflu) + { + printf("File is a fat bakapee\n"); + //segm=(length%0xfffflu)-1; + //fat=segm*0xfffflu; + //length-=fat; + printf("CA_FarRead doesn't support 64K reads yet!\n"); + return 0;//TODO: EXPAND!!! + } + + //if(!fat&&!segm) + //{ + __asm { + push ds + mov bx,[handle] + mov cx,[WORD PTR length] + mov dx,[WORD PTR dest] + mov ds,[WORD PTR dest+2] + mov ah,0x3f // READ w/handle + int 21h + pop ds + jnc good + mov errno,ax + mov flag,0 + jmp End +#ifdef __BORLANDC__ + } +#endif good: -asm cmp ax,[WORD PTR length] -asm je done - errno = EINVFMT; // user manager knows this is bad read - return false; +#ifdef __BORLANDC__ + __asm { +#endif + cmp ax,[WORD PTR length] + je done +// errno = EINVFMT; // user manager knows this is bad read + mov flag,0 + jmp End +#ifdef __BORLANDC__ + } +#endif done: - return true; +#ifdef __BORLANDC__ + __asm { +#endif + mov flag,1 +#ifdef __BORLANDC__ + } +#endif +End: +#ifdef __WATCOMC__ + } +#endif + return flag; } @@ -257,30 +293,65 @@ done: ========================== */ -boolean CA_FarWrite (int handle, byte far *source, long length) +boolean CA_FarWrite(int handle, byte far *source, dword length, global_game_variables_t *gvar) { - if (length>0xffffl) - Quit ("CA_FarWrite doesn't support 64K reads yet!"); - -asm push ds -asm mov bx,[handle] -asm mov cx,[WORD PTR length] -asm mov dx,[WORD PTR source] -asm mov ds,[WORD PTR source+2] -asm mov ah,0x40 // WRITE w/handle -asm int 21h -asm pop ds -asm jnc good - errno = _AX; - return false; -good: -asm cmp ax,[WORD PTR length] -asm je done - errno = ENOMEM; // user manager knows this is bad write - return false; + boolean flag=0; + //dword fat=0; + //word segm=0; + if(gvar->pm.emm.EMSVer<0x40) + if(length>0xfffflu) + { + printf("File is a fat bakapee\n"); + //segm=(length%0xfffflu)-1; + //fat=segm*0xfffflu; + //length-=fat; + printf("CA_FarRead doesn't support 64K reads yet!\n"); + return 0; + } + //if(!fat&&!segm) + //{ + __asm { + push ds + mov bx,[handle] + mov cx,[WORD PTR length] + mov dx,[WORD PTR source] + mov ds,[WORD PTR source+2] + mov ah,0x40 // WRITE w/handle + int 21h + pop ds + jnc good + mov errno,ax + mov flag,0 + jmp End +#ifdef __BORLANDC__ + } +#endif +good: +#ifdef __BORLANDC__ + __asm { +#endif + cmp ax,[WORD PTR length] + je done +// errno = ENOMEM; // user manager knows this is bad write + mov flag,0 + jmp End +#ifdef __BORLANDC__ + } +#endif done: - return true; +#ifdef __BORLANDC__ + __asm { +#endif + mov flag,1 +#ifdef __BORLANDC__ + } +#endif +End: +#ifdef __WATCOMC__ + } +#endif + return flag; } @@ -294,16 +365,17 @@ done: ========================== */ -boolean CA_ReadFile (char *filename, memptr *ptr) +boolean CA_ReadFile(char *filename, memptr *ptr, global_game_variables_t *gvar) { int handle; - long size; + sdword size; + //long size; - if ((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1) + if((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1) return false; - size = filelength (handle); - if (!CA_FarRead (handle,*ptr,size)) + size = filelength(handle); + if(!CA_FarRead(handle,*ptr,size, gvar)) { close (handle); return false; @@ -313,6 +385,38 @@ boolean CA_ReadFile (char *filename, memptr *ptr) } +/* +========================== += += CA_WriteFile += += Writes a file from a memory buffer += +========================== +*/ + +boolean CA_WriteFile (char *filename, void far *ptr, long length, global_game_variables_t *gvar) +{ + int handle; + //sdword size; + //long size; + + handle = open(filename,O_CREAT | O_BINARY | O_WRONLY, + S_IREAD | S_IWRITE | S_IFREG); + + if (handle == -1) + return false; + + if (!CA_FarWrite (handle,ptr,length, gvar)) + { + close(handle); + return false; + } + close(handle); + return true; +} + + /* ========================== @@ -324,22 +428,23 @@ boolean CA_ReadFile (char *filename, memptr *ptr) ========================== */ -boolean CA_LoadFile (char *filename, memptr *ptr) +boolean CA_LoadFile(char *filename, memptr *ptr, global_game_variables_t *gvar) { int handle; - long size; + sdword size; + //long size; - if ((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1) + if((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1) return false; - size = filelength (handle); - MM_GetPtr (ptr,size); - if (!CA_FarRead (handle,*ptr,size)) + size = filelength(handle); + MM_GetPtr(ptr,size, gvar); + if(!CA_FarRead(handle,*ptr,size, gvar)) { - close (handle); + close(handle); return false; } - close (handle); + close(handle); return true; } @@ -364,7 +469,7 @@ boolean CA_LoadFile (char *filename, memptr *ptr) =============== */ -void CAL_OptimizeNodes (huffnode *table) +void CAL_OptimizeNodes(huffnode *table) { huffnode *node; int i; @@ -393,15 +498,15 @@ void CAL_OptimizeNodes (huffnode *table) ====================== */ -void CAL_HuffExpand (byte huge *source, byte huge *dest, +void CAL_HuffExpand (byte far *source, byte far *dest, long length,huffnode *hufftable) { // unsigned bit,byte,node,code; unsigned sourceseg,sourceoff,destseg,destoff,endoff; - huffnode *headptr; + huffnode *headptr; // huffnode *nodeon; - headptr = hufftable+254; // head node is allways node 254 + headptr = hufftable+254; // head node is allways node 254 source++; // normalize source--; @@ -427,49 +532,76 @@ void CAL_HuffExpand (byte huge *source, byte huge *dest, // expand less than 64k of data //-------------------------- -asm mov bx,[headptr] - -asm mov si,[sourceoff] -asm mov di,[destoff] -asm mov es,[destseg] -asm mov ds,[sourceseg] -asm mov ax,[endoff] + __asm { + mov bx,[word ptr headptr] -asm mov ch,[si] // load first byte -asm inc si -asm mov cl,1 + mov si,[sourceoff] + mov di,[destoff] + mov es,[destseg] + mov ds,[sourceseg] + mov ax,[endoff] + mov ch,[si] // load first byte + inc si + mov cl,1 +#ifdef __BORLANDC__ + } +#endif expandshort: -asm test ch,cl // bit set? -asm jnz bit1short -asm mov dx,[ss:bx] // take bit0 path from node -asm shl cl,1 // advance to next bit position -asm jc newbyteshort -asm jnc sourceupshort - +#ifdef __BORLANDC__ + __asm { +#endif + test ch,cl // bit set? + jnz bit1short + mov dx,[ss:bx] // take bit0 path from node + shl cl,1 // advance to next bit position + jc newbyteshort + jnc sourceupshort +#ifdef __BORLANDC__ + } +#endif bit1short: -asm mov dx,[ss:bx+2] // take bit1 path -asm shl cl,1 // advance to next bit position -asm jnc sourceupshort - +#ifdef __BORLANDC__ + __asm { +#endif + mov dx,[ss:bx+2] // take bit1 path + shl cl,1 // advance to next bit position + jnc sourceupshort +#ifdef __BORLANDC__ + } +#endif newbyteshort: -asm mov ch,[si] // load next byte -asm inc si -asm mov cl,1 // back to first bit - +#ifdef __BORLANDC__ + __asm { +#endif + mov ch,[si] // load next byte + inc si + mov cl,1 // back to first bit +#ifdef __BORLANDC__ + } +#endif sourceupshort: -asm or dh,dh // if dx<256 its a byte, else move node -asm jz storebyteshort -asm mov bx,dx // next node = (huffnode *)code -asm jmp expandshort - +#ifdef __BORLANDC__ + __asm { +#endif + or dh,dh // if dx<256 its a byte, else move node + jz storebyteshort + mov bx,dx // next node = (huffnode *)code + jmp expandshort +#ifdef __BORLANDC__ + } +#endif storebyteshort: -asm mov [es:di],dl -asm inc di // write a decopmpressed byte out -asm mov bx,[headptr] // back to the head node for next bit +#ifdef __BORLANDC__ + __asm { +#endif + mov [es:di],dl + inc di // write a decopmpressed byte out + mov bx,[word ptr headptr] // back to the head node for next bit -asm cmp di,ax // done? -asm jne expandshort + cmp di,ax // done? + jne expandshort + } } else { @@ -480,65 +612,105 @@ asm jne expandshort length--; -asm mov bx,[headptr] -asm mov cl,1 + __asm { + mov bx,[word ptr headptr] + mov cl,1 -asm mov si,[sourceoff] -asm mov di,[destoff] -asm mov es,[destseg] -asm mov ds,[sourceseg] - -asm lodsb // load first byte + mov si,[sourceoff] + mov di,[destoff] + mov es,[destseg] + mov ds,[sourceseg] + lodsb // load first byte +#ifdef __BORLANDC__ + } +#endif expand: -asm test al,cl // bit set? -asm jnz bit1 -asm mov dx,[ss:bx] // take bit0 path from node -asm jmp gotcode +#ifdef __BORLANDC__ + __asm { +#endif + test al,cl // bit set? + jnz bit1 + mov dx,[ss:bx] // take bit0 path from node + jmp gotcode +#ifdef __BORLANDC__ + } +#endif bit1: -asm mov dx,[ss:bx+2] // take bit1 path - +#ifdef __BORLANDC__ + __asm { +#endif + mov dx,[ss:bx+2] // take bit1 path +#ifdef __BORLANDC__ + } +#endif gotcode: -asm shl cl,1 // advance to next bit position -asm jnc sourceup -asm lodsb -asm cmp si,0x10 // normalize ds:si -asm jb sinorm -asm mov cx,ds -asm inc cx -asm mov ds,cx -asm xor si,si +#ifdef __BORLANDC__ + __asm { +#endif + shl cl,1 // advance to next bit position + jnc sourceup + lodsb + cmp si,0x10 // normalize ds:si + jb sinorm + mov cx,ds + inc cx + mov ds,cx + xor si,si +#ifdef __BORLANDC__ + } +#endif sinorm: -asm mov cl,1 // back to first bit - +#ifdef __BORLANDC__ + __asm { +#endif + mov cl,1 // back to first bit +#ifdef __BORLANDC__ + } +#endif sourceup: -asm or dh,dh // if dx<256 its a byte, else move node -asm jz storebyte -asm mov bx,dx // next node = (huffnode *)code -asm jmp expand - +#ifdef __BORLANDC__ + __asm { +#endif + or dh,dh // if dx<256 its a byte, else move node + jz storebyte + mov bx,dx // next node = (huffnode *)code + jmp expand +#ifdef __BORLANDC__ + } +#endif storebyte: -asm mov [es:di],dl -asm inc di // write a decopmpressed byte out -asm mov bx,[headptr] // back to the head node for next bit - -asm cmp di,0x10 // normalize es:di -asm jb dinorm -asm mov dx,es -asm inc dx -asm mov es,dx -asm xor di,di +#ifdef __BORLANDC__ + __asm { +#endif + mov [es:di],dl + inc di // write a decopmpressed byte out + mov bx,[word ptr headptr] // back to the head node for next bit + + cmp di,0x10 // normalize es:di + jb dinorm + mov dx,es + inc dx + mov es,dx + xor di,di +#ifdef __BORLANDC__ + } +#endif dinorm: - -asm sub [WORD PTR ss:length],1 -asm jnc expand -asm dec [WORD PTR ss:length+2] -asm jns expand // when length = ffff ffff, done - +#ifdef __BORLANDC__ + __asm { +#endif + sub [WORD PTR ss:length],1 + jnc expand + dec [WORD PTR ss:length+2] + jns expand // when length = ffff ffff, done + } } -asm mov ax,ss -asm mov ds,ax + __asm { + mov ax,ss + mov ds,ax + } } @@ -575,13 +747,13 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt count = ch&0xff; if (!count) { // have to insert a word containing the tag byte - ch |= *((unsigned char far *)inptr)++; + ch |= *(/*(unsigned char far *)*/inptr)++; *outptr++ = ch; length--; } else { - offset = *((unsigned char far *)inptr)++; + offset = *(/*(unsigned char far *)*/inptr)++; copyptr = outptr - offset; length -= count; while (count--) @@ -593,7 +765,7 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt count = ch&0xff; if (!count) { // have to insert a word containing the tag byte - ch |= *((unsigned char far *)inptr)++; + ch |= *(/*(unsigned char far *)*/inptr)++; *outptr++ = ch; length --; } @@ -615,7 +787,6 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt } - /* ====================== = @@ -624,12 +795,12 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt ====================== */ -long CA_RLEWCompress (unsigned huge *source, long length, unsigned huge *dest, +long CA_RLEWCompress (unsigned far *source, long length, unsigned far *dest, unsigned rlewtag) { long complength; unsigned value,count,i; - unsigned huge *start,huge *end; + unsigned far *start,far *end; start = dest; @@ -681,11 +852,11 @@ long CA_RLEWCompress (unsigned huge *source, long length, unsigned huge *dest, ====================== */ -void CA_RLEWexpand (unsigned huge *source, unsigned huge *dest,long length, +void CA_RLEWexpand (unsigned far *source, unsigned far *dest,long length, unsigned rlewtag) { // unsigned value,count,i; - unsigned huge *end; + unsigned far *end; unsigned sourceseg,sourceoff,destseg,destoff,endseg,endoff; @@ -731,66 +902,90 @@ void CA_RLEWexpand (unsigned huge *source, unsigned huge *dest,long length, // // NOTE: A repeat count that produces 0xfff0 bytes can blow this! // - -asm mov bx,rlewtag -asm mov si,sourceoff -asm mov di,destoff -asm mov es,destseg -asm mov ds,sourceseg - + __asm { + mov bx,rlewtag + mov si,sourceoff + mov di,destoff + mov es,destseg + mov ds,sourceseg +#ifdef __BORLANDC__ + } +#endif expand: -asm lodsw -asm cmp ax,bx -asm je repeat -asm stosw -asm jmp next - +#ifdef __BORLANDC__ + __asm { +#endif + lodsw + cmp ax,bx + je repeat + stosw + jmp next +#ifdef __BORLANDC__ + } +#endif repeat: -asm lodsw -asm mov cx,ax // repeat count -asm lodsw // repeat value -asm rep stosw - +#ifdef __BORLANDC__ + __asm { +#endif + lodsw + mov cx,ax // repeat count + lodsw // repeat value + rep stosw +#ifdef __BORLANDC__ + } +#endif next: - -asm cmp si,0x10 // normalize ds:si -asm jb sinorm -asm mov ax,si -asm shr ax,1 -asm shr ax,1 -asm shr ax,1 -asm shr ax,1 -asm mov dx,ds -asm add dx,ax -asm mov ds,dx -asm and si,0xf +#ifdef __BORLANDC__ + __asm { +#endif + cmp si,0x10 // normalize ds:si + jb sinorm + mov ax,si + shr ax,1 + shr ax,1 + shr ax,1 + shr ax,1 + mov dx,ds + add dx,ax + mov ds,dx + and si,0xf +#ifdef __BORLANDC__ + } +#endif sinorm: -asm cmp di,0x10 // normalize es:di -asm jb dinorm -asm mov ax,di -asm shr ax,1 -asm shr ax,1 -asm shr ax,1 -asm shr ax,1 -asm mov dx,es -asm add dx,ax -asm mov es,dx -asm and di,0xf +#ifdef __BORLANDC__ + __asm { +#endif + cmp di,0x10 // normalize es:di + jb dinorm + mov ax,di + shr ax,1 + shr ax,1 + shr ax,1 + shr ax,1 + mov dx,es + add dx,ax + mov es,dx + and di,0xf +#ifdef __BORLANDC__ + } +#endif dinorm: - -asm cmp di,ss:endoff -asm jne expand -asm mov ax,es -asm cmp ax,ss:endseg -asm jb expand - -asm mov ax,ss -asm mov ds,ax - +#ifdef __BORLANDC__ + __asm { +#endif + cmp di,ss:endoff + jne expand + mov ax,es + cmp ax,ss:endseg + jb expand + + mov ax,ss + mov ds,ax + } } - /* ============================================================================= @@ -806,8 +1001,8 @@ asm mov ds,ax = ====================== */ - -void CAL_SetupGrFile (void) +////++++ enable! +/*void CAL_SetupGrFile (void) { int handle; memptr compseg; @@ -833,7 +1028,7 @@ void CAL_SetupGrFile (void) if ((handle = open(GREXT"DICT."EXT, O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open "GREXT"DICT."EXT"!"); + Quit (gvar, "Can't open "GREXT"DICT."EXT"!"); read(handle, &grhuffman, sizeof(grhuffman)); close(handle); @@ -845,7 +1040,7 @@ void CAL_SetupGrFile (void) if ((handle = open(GREXT"HEAD."EXT, O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open "GREXT"HEAD."EXT"!"); + Quit (gvar, "Can't open "GREXT"HEAD."EXT"!"); CA_FarRead(handle, (memptr)grstarts, (NUMCHUNKS+1)*FILEPOSSIZE); @@ -859,7 +1054,7 @@ void CAL_SetupGrFile (void) // grhandle = open(GREXT"GRAPH."EXT, O_RDONLY | O_BINARY); if (grhandle == -1) - Quit ("Cannot open "GREXT"GRAPH."EXT"!"); + Quit (gvar, "Cannot open "GREXT"GRAPH."EXT"!"); // @@ -870,7 +1065,7 @@ void CAL_SetupGrFile (void) CAL_GetGrChunkLength(STRUCTPIC); // position file pointer MM_GetPtr(&compseg,chunkcomplen); CA_FarRead (grhandle,compseg,chunkcomplen); - CAL_HuffExpand (compseg, (byte huge *)pictable,NUMPICS*sizeof(pictabletype),grhuffman); + CAL_HuffExpand (compseg, (byte far *)pictable,NUMPICS*sizeof(pictabletype),grhuffman); MM_FreePtr(&compseg); #endif @@ -879,7 +1074,7 @@ void CAL_SetupGrFile (void) CAL_GetGrChunkLength(STRUCTPICM); // position file pointer MM_GetPtr(&compseg,chunkcomplen); CA_FarRead (grhandle,compseg,chunkcomplen); - CAL_HuffExpand (compseg, (byte huge *)picmtable,NUMPICS*sizeof(pictabletype),grhuffman); + CAL_HuffExpand (compseg, (byte far *)picmtable,NUMPICS*sizeof(pictabletype),grhuffman); MM_FreePtr(&compseg); #endif @@ -888,11 +1083,11 @@ void CAL_SetupGrFile (void) CAL_GetGrChunkLength(STRUCTSPRITE); // position file pointer MM_GetPtr(&compseg,chunkcomplen); CA_FarRead (grhandle,compseg,chunkcomplen); - CAL_HuffExpand (compseg, (byte huge *)spritetable,NUMSPRITES*sizeof(spritetabletype),grhuffman); + CAL_HuffExpand (compseg, (byte far *)spritetable,NUMSPRITES*sizeof(spritetabletype),grhuffman); MM_FreePtr(&compseg); #endif -} +}*/ //========================================================================== @@ -905,9 +1100,9 @@ void CAL_SetupGrFile (void) ====================== */ -void CAL_SetupMapFile (void) +void CAL_SetupMapFile (global_game_variables_t *gvar) { - int handle; +/* int handle; long length; // @@ -916,29 +1111,35 @@ void CAL_SetupMapFile (void) #ifndef MAPHEADERLINKED if ((handle = open("MAPHEAD."EXT, O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open MAPHEAD."EXT"!"); + printf("Can't open MAPHEAD."EXT"!"); length = filelength(handle); MM_GetPtr (&(memptr)tinf,length); CA_FarRead(handle, tinf, length); close(handle); -#else +//#else tinf = (byte _seg *)FP_SEG(&maphead); -#endif +#endif*/ // // open the data file // -#ifdef MAPHEADERLINKED - if ((maphandle = open("GAMEMAPS."EXT, - O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open GAMEMAPS."EXT"!"); -#else - if ((maphandle = open("MAPTEMP."EXT, +//TODO: multiple files + if ((gvar->ca.file.maphandle[0] = open("data/test.map", O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open MAPTEMP."EXT"!"); -#endif + { + printf("Can't open data/test.map!"); + } +// #ifdef MAPHEADERLINKED +// if ((maphandle = open("GAMEMAPS."EXT, +// O_RDONLY | O_BINARY, S_IREAD)) == -1) +// Quit (gvar, "Can't open GAMEMAPS."EXT"!"); +// //#else +// if ((maphandle = open("MAPTEMP."EXT, +// O_RDONLY | O_BINARY, S_IREAD)) == -1) +// Quit (gvar, "Can't open MAPTEMP."EXT"!"); +// #endif } //========================================================================== @@ -952,7 +1153,7 @@ void CAL_SetupMapFile (void) ====================== */ -void CAL_SetupAudioFile (void) +/*void CAL_SetupAudioFile (void) { int handle; long length; @@ -963,7 +1164,7 @@ void CAL_SetupAudioFile (void) #ifndef AUDIOHEADERLINKED if ((handle = open("AUDIOHED."EXT, O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open AUDIOHED."EXT"!"); + Quit (gvar, "Can't open AUDIOHED."EXT"!"); length = filelength(handle); MM_GetPtr (&(memptr)audiostarts,length); CA_FarRead(handle, (byte far *)audiostarts, length); @@ -980,13 +1181,13 @@ void CAL_SetupAudioFile (void) #ifndef AUDIOHEADERLINKED if ((audiohandle = open("AUDIOT."EXT, O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open AUDIOT."EXT"!"); + Quit (gvar, "Can't open AUDIOT."EXT"!"); #else if ((audiohandle = open("AUDIO."EXT, O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open AUDIO."EXT"!"); + Quit (gvar, "Can't open AUDIO."EXT"!"); #endif -} +}*/ //========================================================================== @@ -1001,53 +1202,39 @@ void CAL_SetupAudioFile (void) ====================== */ -void CA_Startup (void) +void CA_Startup(global_game_variables_t *gvar) { #ifdef PROFILE - unlink ("PROFILE.TXT"); - profilehandle = open("PROFILE.TXT", O_CREAT | O_WRONLY | O_TEXT); +#ifdef __BORLANDC__ + unlink("profile.16b"); + gvar->handle.profilehandle = open("profile.16b", O_CREAT | O_WRONLY | O_TEXT); #endif - -// MDM begin - (GAMERS EDGE) -// - if (!FindFile("AUDIO."EXT,NULL,2)) - Quit("CA_Startup(): Can't find audio files."); -// -// MDM end - -#ifndef NOAUDIO - CAL_SetupAudioFile (); +#ifdef __WATCOMC__ + unlink("profile.16w"); + gvar->handle.profilehandle = open("profile.16w", O_CREAT | O_WRONLY | O_TEXT); #endif +#endif//profile -// MDM begin - (GAMERS EDGE) -// - if (!FindFile("GAMEMAPS."EXT,NULL,1)) - Quit("CA_Startup(): Can't find level files."); -// -// MDM end - -#ifndef NOMAPS - CAL_SetupMapFile (); +#ifdef __BORLANDC__ + unlink("meminfo.16b"); + gvar->handle.showmemhandle = open("meminfo.16b", O_CREAT | O_WRONLY | O_TEXT); #endif - -// MDM begin - (GAMERS EDGE) -// - if (!FindFile("EGAGRAPH."EXT,NULL,2)) - Quit("CA_Startup(): Can't find graphics files."); -// -// MDM end - -#ifndef NOGRAPHICS - CAL_SetupGrFile (); +#ifdef __WATCOMC__ + unlink("meminfo.16w"); + gvar->handle.showmemhandle = open("meminfo.16w", O_CREAT | O_WRONLY | O_TEXT); #endif +/* + CAL_SetupGrFile (); + CAL_SetupAudioFile ();*/ + CAL_SetupMapFile (gvar); - mapon = -1; - ca_levelbit = 1; - ca_levelnum = 0; + gvar->ca.camap.mapon = -1; + gvar->ca.ca_levelbit = 1; + gvar->ca.ca_levelnum = 0; - drawcachebox = CAL_DialogDraw; +/* drawcachebox = CAL_DialogDraw; updatecachebox = CAL_DialogUpdate; - finishcachebox = CAL_DialogFinish; + finishcachebox = CAL_DialogFinish;*/ } //========================================================================== @@ -1063,15 +1250,17 @@ void CA_Startup (void) ====================== */ -void CA_Shutdown (void) +void CA_Shutdown(global_game_variables_t *gvar) { #ifdef PROFILE - close (profilehandle); + close(gvar->handle.profilehandle); #endif + close(gvar->handle.showmemhandle); - close (maphandle); - close (grhandle); - close (audiohandle); + close(*(gvar->ca.file.maphandle)); +/*++++ + close(grhandle); + close(audiohandle);*/ } //=========================================================================== @@ -1083,7 +1272,7 @@ void CA_Shutdown (void) = ====================== */ - +/*++++ void CA_CacheAudioChunk (int chunk) { long pos,compressed; @@ -1102,7 +1291,7 @@ void CA_CacheAudioChunk (int chunk) // MDM begin - (GAMERS EDGE) // if (!FindFile("AUDIO."EXT,NULL,2)) - Quit("CA_CacheAudioChunk(): Can't find audio files."); + Quit (gvar, "CA_CacheAudioChunk(): Can't find audio files."); // // MDM end @@ -1151,7 +1340,7 @@ done: if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); #endif -} +}*/ //=========================================================================== @@ -1164,7 +1353,7 @@ done: = ====================== */ - +/*++++ void CA_LoadAllSounds (void) { unsigned start,i; @@ -1203,11 +1392,11 @@ cachein: CA_CacheAudioChunk (start); oldsoundmode = SoundMode; -} +}*/ //=========================================================================== -#if GRMODE == EGAGR +//++++#if GRMODE == EGAGR /* ====================== @@ -1218,7 +1407,7 @@ cachein: = ====================== */ - +/*++++ unsigned static sheight,swidth; boolean static dothemask; @@ -1315,7 +1504,7 @@ asm mov ds,ax } #endif - +*/ //=========================================================================== /* @@ -1327,7 +1516,7 @@ asm mov ds,ax = ====================== */ - +/*++++ void CAL_CacheSprite (int chunk, byte far *compressed) { int i; @@ -1441,11 +1630,11 @@ void CAL_CacheSprite (int chunk, byte far *compressed) break; default: - Quit ("CAL_CacheSprite: Bad shifts number!"); + Quit (gvar, "CAL_CacheSprite: Bad shifts number!"); } #endif -} +}*/ //=========================================================================== @@ -1459,7 +1648,7 @@ void CAL_CacheSprite (int chunk, byte far *compressed) = ====================== */ - +/*++++ void CAL_ExpandGrChunk (int chunk, byte far *source) { long expanded; @@ -1517,7 +1706,7 @@ void CAL_ExpandGrChunk (int chunk, byte far *source) CAL_HuffExpand (source,grsegs[chunk],expanded,grhuffman); } } - +*/ /* ====================== @@ -1528,7 +1717,7 @@ void CAL_ExpandGrChunk (int chunk, byte far *source) = ====================== */ - +/*++++ void CAL_ReadGrChunk (int chunk) { long pos,compressed; @@ -1572,7 +1761,7 @@ void CAL_ReadGrChunk (int chunk) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } - +*/ /* ====================== = @@ -1582,7 +1771,7 @@ void CAL_ReadGrChunk (int chunk) = ====================== */ - +/*++++ void CA_CacheGrChunk (int chunk) { long pos,compressed; @@ -1590,7 +1779,7 @@ void CA_CacheGrChunk (int chunk) byte far *source; int next; - grneeded[chunk] |= ca_levelbit; // make sure it doesn't get removed + gvar->video.grneeded[chunk] |= ca_levelbit; // make sure it doesn't get removed if (grsegs[chunk]) { MM_SetPurge (&grsegs[chunk],0); @@ -1600,7 +1789,7 @@ void CA_CacheGrChunk (int chunk) // MDM begin - (GAMERS EDGE) // if (!FindFile("EGAGRAPH."EXT,NULL,2)) - Quit("CA_CacheGrChunk(): Can't find graphics files."); + Quit (gvar, "CA_CacheGrChunk(): Can't find graphics files."); // // MDM end @@ -1638,7 +1827,7 @@ void CA_CacheGrChunk (int chunk) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } - +*/ //========================================================================== @@ -1650,8 +1839,8 @@ void CA_CacheGrChunk (int chunk) = ====================== */ - -void CA_CacheMap (int mapnum) +/*++++ segments! +void CA_CacheMap (global_game_variables_t *gvar) { long pos,compressed; int plane; @@ -1664,42 +1853,36 @@ void CA_CacheMap (int mapnum) #endif -// MDM begin - (GAMERS EDGE) -// - if (!FindFile("GAMEMAPS."EXT,NULL,1)) - Quit("CA_CacheMap(): Can't find level files."); -// -// MDM end - - // // free up memory from last map // - if (mapon>-1 && mapheaderseg[mapon]) - MM_SetPurge (&(memptr)mapheaderseg[mapon],3); + if (gvar->ca.camap.mapon>-1 && gvar->ca.camap.mapheaderseg[gvar->ca.camap.mapon]) + MM_SetPurge (((memptr)gvar->ca.camap.mapheaderseg[(gvar->ca.camap.mapon)]), 3, gvar); for (plane=0;planeca.camap.mapsegs[plane]) + MM_FreePtr ((memptr)gvar->ca.camap.mapsegs[plane], gvar); - mapon = mapnum; + gvar->ca.camap.mapon = gvar->ca.camap.mapnum; // // load map header // The header will be cached if it is still around // - if (!mapheaderseg[mapnum]) - { - pos = ((mapfiletype _seg *)tinf)->headeroffsets[mapnum]; - if (pos<0) // $FFFFFFFF start is a sparse map - Quit ("CA_CacheMap: Tried to load a non existent map!"); +// if (!gvar->ca.camap.mapheaderseg[gvar->ca.camap.mapnum]) +// { +// //pos = ((mapfiletype _seg *)tinf)->headeroffsets[mapnum]; +// //pos = ((_seg *)gvar->ca.camap.tinf)->headeroffsets[gvar->ca.camap.mapnum]; +// pos = ((memptr)gvar->ca.camap.tinf)->headeroffsets[gvar->ca.camap.mapnum]; +// if (pos<0) // $FFFFFFFF start is a sparse map +// printf("CA_CacheMap: Tried to load a non existent map!"); - MM_GetPtr(&(memptr)mapheaderseg[mapnum],sizeof(maptype)); - lseek(maphandle,pos,SEEK_SET); - CA_FarRead (maphandle,(memptr)mapheaderseg[mapnum],sizeof(maptype)); - } - else - MM_SetPurge (&(memptr)mapheaderseg[mapnum],0); +// MM_GetPtr(&(memptr)gvar->ca.camapheaderseg[mapnum],sizeof(maptype)); +// lseek(maphandle,pos,SEEK_SET); +// CA_FarRead (maphandle,(memptr)mapheaderseg[mapnum],sizeof(maptype)); +// } +// else +// MM_SetPurge (&(memptr)mapheaderseg[mapnum], 0, &(gvar->mm)); // // load the planes in @@ -1711,8 +1894,8 @@ void CA_CacheMap (int mapnum) for (plane = 0; planeplanestart[plane]; - compressed = mapheaderseg[mapnum]->planelength[plane]; + //pos = mapheaderseg[mapnum]->planestart[plane]; + //compressed = mapheaderseg[mapnum]->planelength[plane]; if (!compressed) continue; // the plane is not used in this game @@ -1757,7 +1940,7 @@ void CA_CacheMap (int mapnum) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } -} +}//*/ //=========================================================================== @@ -1772,13 +1955,13 @@ void CA_CacheMap (int mapnum) ====================== */ -void CA_UpLevel (void) +void CA_UpLevel (global_game_variables_t *gvar) { - if (ca_levelnum==7) - Quit ("CA_UpLevel: Up past level 7!"); + if (gvar->ca.ca_levelnum==7) + printf("CA_UpLevel: Up past level 7!"); - ca_levelbit<<=1; - ca_levelnum++; + gvar->ca.ca_levelbit<<=1; + gvar->ca.ca_levelnum++; } //=========================================================================== @@ -1794,13 +1977,13 @@ void CA_UpLevel (void) ====================== */ -void CA_DownLevel (void) +void CA_DownLevel (global_game_variables_t *gvar) { - if (!ca_levelnum) - Quit ("CA_DownLevel: Down past level 0!"); - ca_levelbit>>=1; - ca_levelnum--; - CA_CacheMarks(NULL); + if (!gvar->ca.ca_levelnum) + printf("CA_DownLevel: Down past level 0!"); + gvar->ca.ca_levelbit>>=1; + gvar->ca.ca_levelnum--; + ////++++++++++++++++++++++++++++++++++++++++++CA_CacheMarks(NULL); } //=========================================================================== @@ -1815,15 +1998,14 @@ void CA_DownLevel (void) ====================== */ -void CA_ClearMarks (void) +void CA_ClearMarks (global_game_variables_t *gvar) { int i; for (i=0;ivideo.grneeded[i]&=~gvar->ca.ca_levelbit; } - //=========================================================================== /* @@ -1836,14 +2018,13 @@ void CA_ClearMarks (void) ====================== */ -void CA_ClearAllMarks (void) +void CA_ClearAllMarks (global_game_variables_t *gvar) { - _fmemset (grneeded,0,sizeof(grneeded)); - ca_levelbit = 1; - ca_levelnum = 0; + _fmemset (gvar->video.grneeded,0,sizeof(gvar->video.grneeded)); + gvar->ca.ca_levelbit = 1; + gvar->ca.ca_levelnum = 0; } - //=========================================================================== /* @@ -1853,16 +2034,21 @@ void CA_ClearAllMarks (void) = ====================== */ - -void CA_FreeGraphics (void) +/*++++ +void CA_SetGrPurge (void) { - int i; + int i; + +// +// free graphics +// + CA_ClearMarks (); for (i=0;ivideo.grneeded[i]&ca_levelbit) { if (grsegs[i]) // its allready in memory, make MM_SetPurge(&grsegs[i],0); // sure it stays there! @@ -2083,7 +2256,7 @@ void CA_CacheMarks (char *title) // MDM begin - (GAMERS EDGE) // if (!FindFile("EGAGRAPH."EXT,NULL,2)) - Quit("CA_CacheMarks(): Can't find graphics files."); + Quit (gvar, "CA_CacheMarks(): Can't find graphics files."); // // MDM end @@ -2103,7 +2276,7 @@ void CA_CacheMarks (char *title) bufferstart = bufferend = 0; // nothing good in buffer now for (i=0;ivideo.grneeded[i]&ca_levelbit) && !grsegs[i]) { // // update thermometer @@ -2137,7 +2310,7 @@ void CA_CacheMarks (char *title) while ( next < NUMCHUNKS ) { while (next < NUMCHUNKS && - !(grneeded[next]&ca_levelbit && !grsegs[next])) + !(gvar->video.grneeded[next]&ca_levelbit && !grsegs[next])) next++; if (next == NUMCHUNKS) continue; @@ -2186,5 +2359,4 @@ void CA_CacheMarks (char *title) // if (dialog && finishcachebox) finishcachebox(); -} - +}*/