X-Git-Url: http://4ch.mooo.com/gitweb/?p=16.git;a=blobdiff_plain;f=src%2Flib%2F16_ca.c;h=d69989c32b1102853c861a77417c2aa1cb8d262d;hp=abeffbfd76abf954c813be979346408af8b49f63;hb=050d28da3358d5c1434fda542ec11adbee182ea5;hpb=fe54ff5710fd1720312e29985ba4e67709ce48a1 diff --git a/src/lib/16_ca.c b/src/lib/16_ca.c old mode 100644 new mode 100755 index abeffbfd..d69989c3 --- a/src/lib/16_ca.c +++ b/src/lib/16_ca.c @@ -36,8 +36,9 @@ loaded into the data segment #pragma warn -pro #pragma warn -use -//#define THREEBYTEGRSTARTS - +#define THREEBYTEGRSTARTS +//https://github.com/open-watcom/open-watcom-v2/issues/279#issuecomment-244587566 for _seg +//http://www.shikadi.net/moddingwiki/GameMaps_Format for info on the code /* ============================================================================= @@ -46,10 +47,10 @@ 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 @@ -76,8 +77,7 @@ maptype _seg *mapheaderseg[NUMMAPS]; byte _seg *audiosegs[NUMSNDCHUNKS]; void _seg *grsegs[NUMCHUNKS]; -byte far grneeded[NUMCHUNKS]; -byte ca_levelbit,ca_levelnum;*/ +byte far grneeded[NUMCHUNKS];*/ void (*drawcachebox) (char *title, unsigned numcache); void (*updatecachebox) (void); @@ -98,16 +98,17 @@ extern byte EGAdict; extern byte far maphead; extern byte mapdict; extern byte far audiohead; -extern byte audiodict; +extern byte audiodict;*/ +void CA_CannotOpen(char *string, global_game_variables_t *gvar); -long _seg *grstarts; // array of offsets in egagraph, -1 for sparse +/*long _seg *grstarts; // array of offsets in egagraph, -1 for sparse long _seg *audiostarts; // array of offsets in audio / audiot #ifdef GRHEADERLINKED -huffnode *grhuffman; +huffnode *gvar->ca.grhuffman; #else -huffnode grhuffman[255]; +huffnode gvar->ca.grhuffman[255]; #endif #ifdef AUDIOHEADERLINKED @@ -120,9 +121,9 @@ huffnode audiohuffman[255]; int grhandle; // handle to EGAGRAPH int maphandle; // handle to MAPTEMP / GAMEMAPS int audiohandle; // handle to AUDIOT / AUDIO - +*/ long chunkcomplen,chunkexplen; - +/* SDMode oldsoundmode; @@ -130,20 +131,21 @@ 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_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) +CASVT GRFILEPOS(int c, global_game_variables_t *gvar) { - long value; + CASVT value; int offset; offset = c*3; - value = *(long far *)(((byte far *)grstarts)+offset); + value = *(CASVT far *)(((byte far *)gvar->ca.grstarts)+offset); value &= 0x00ffffffl; @@ -154,8 +156,12 @@ long GRFILEPOS(int c) }; #else #define FILEPOSSIZE 4 -#define GRFILEPOS(c) (grstarts[c]) -#endif*/ +//#define GRFILEPOS(c) (gvar->ca.grstarts[c]) +CASVT GRFILEPOS(int c, global_game_variables_t *gvar) +{ + return gvar->ca.grstarts[c]; +} +#endif /* ============================================================================= @@ -176,8 +182,14 @@ long GRFILEPOS(int c) */ void CA_OpenDebug(global_game_variables_t *gvar) { - unlink("debug.16"); - gvar->handle.debughandle = open("debug.16", 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(global_game_variables_t *gvar) @@ -197,13 +209,13 @@ void CA_CloseDebug(global_game_variables_t *gvar) = ============================ */ -/*++++ -void CAL_GetGrChunkLength (int chunk) + +void CAL_GetGrChunkLength (int chunk,global_game_variables_t *gvar) { - lseek(grhandle,GRFILEPOS(chunk),SEEK_SET); - read(grhandle,&chunkexplen,sizeof(chunkexplen)); - chunkcomplen = GRFILEPOS(chunk+1)-GRFILEPOS(chunk)-4; -}*/ + lseek(gvar->ca.file.grhandle,GRFILEPOS(chunk,gvar),SEEK_SET); + read(gvar->ca.file.grhandle,&gvar->ca.chunkexplen,sizeof(gvar->ca.chunkexplen)); + gvar->ca.chunkcomplen = GRFILEPOS(chunk+1,gvar)-GRFILEPOS(chunk,gvar)-4; +} /* @@ -216,65 +228,65 @@ void CAL_GetGrChunkLength (int chunk) ========================== */ -boolean CA_FarRead(int handle, byte huge *dest, dword length, mminfo_t *mm) +boolean CA_FarRead(int handle, byte far *dest, dword length, global_game_variables_t *gvar) { - boolean flag; - /*dword fat=0; - word segm=0; - //if(mm->EMSVer<0x40) + 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"); - } - - 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 + //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: #ifdef __BORLANDC__ - __asm { + __asm { #endif - cmp ax,[WORD PTR length] - je done -// errno = EINVFMT; // user manager knows this is bad read - mov flag,0 - jmp End + 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: #ifdef __BORLANDC__ - __asm { + __asm { #endif - mov flag,1 + mov flag,1 #ifdef __BORLANDC__ - } + } #endif End: #ifdef __WATCOMC__ - } + } #endif return flag; - //}else return 0;//todo: EXPAND!!! } @@ -288,65 +300,65 @@ End: ========================== */ -boolean CA_FarWrite(int handle, byte huge *source, dword length, mminfo_t *mm) +boolean CA_FarWrite(int handle, byte far *source, dword length, global_game_variables_t *gvar) { - boolean flag; - /*dword fat=0; - word segm=0; - //if(mm->EMSVer<0x40) + 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"); - } - - 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 + //segm=(length%0xfffflu)-1; + //fat=segm*0xfffflu; + //length-=fat; + printf("CA_FarWrite 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 { + __asm { #endif - cmp ax,[WORD PTR length] - je done - //errno = ENOMEM; // user manager knows this is bad write - mov flag,0 - jmp End + 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: #ifdef __BORLANDC__ - __asm { + __asm { #endif - mov flag,1 + mov flag,1 #ifdef __BORLANDC__ - } + } #endif End: #ifdef __WATCOMC__ - } + } #endif return flag; - //}else return 0; } @@ -360,17 +372,60 @@ End: ========================== */ -boolean CA_ReadFile(char *filename, memptr *ptr, mminfo_t *mm) +boolean CA_ReadFile(char *filename, memptr *ptr, global_game_variables_t *gvar) { int handle; - dword size; + sdword size; //long size; if((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1) return false; size = filelength(handle); - if(!CA_FarRead(handle,*ptr,size, mm)) +#ifdef __DEBUG_CA__ + if(dbg_debugca>0){ + printf("===============================================================================\n"); + printf(" CA_ReadFile\n"); + printf("===============================================================================\n"); + //%04x + printf(" ptr=%Fp\n", ptr); + printf(" *ptr=%Fp\n", *ptr); + printf(" &ptr=%Fp\n", &ptr); + } +#endif + if(!CA_FarRead(handle,*ptr,size, gvar)) + { + close(handle); + return false; + } + close(handle); + return true; +} + + +/* +========================== += += 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; @@ -391,18 +446,39 @@ boolean CA_ReadFile(char *filename, memptr *ptr, mminfo_t *mm) ========================== */ -boolean CA_LoadFile(char *filename, memptr *ptr, mminfo_t *mm, mminfotype *mmi) +boolean CA_LoadFile(char *filename, memptr *ptr, global_game_variables_t *gvar) { int handle; - dword size; + sdword size; //long size; if((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1) return false; - size = filelength (handle); - MM_GetPtr(ptr,size, mm, mmi); - if(!CA_FarRead(handle,*ptr,size, mm)) + size = filelength(handle); +#ifdef __DEBUG_CA__ + if(dbg_debugca>0){ + printf("===============================================================================\n"); + printf(" CA_LoadFile\n"); + printf("===============================================================================\n"); + //%04x + printf(" ptr=%Fp\n", ptr); + printf(" *ptr=%Fp\n", *ptr); + printf(" &ptr=%Fp\n", &ptr); + } +#endif + MM_GetPtr(ptr,size, gvar); +#ifdef __DEBUG_CA__ + if(dbg_debugca>0){ + //%04x + printf("---------------------------------------\n"); + printf(" ptr=%Fp\n", ptr); + printf(" *ptr=%Fp\n", *ptr); + printf(" &ptr=%Fp\n", &ptr); + printf("-------------------------------------------------------------------------------\n"); + } +#endif + if(!CA_FarRead(handle,*ptr,size, gvar)) { close(handle); return false; @@ -461,15 +537,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--; @@ -495,9 +571,8 @@ void CAL_OptimizeNodes(huffnode *table) // expand less than 64k of data //-------------------------- - __asm - { - mov bx,[headptr] + __asm { + mov bx,[word ptr headptr] mov si,[sourceoff] mov di,[destoff] @@ -508,38 +583,63 @@ void CAL_OptimizeNodes(huffnode *table) mov ch,[si] // load first byte inc si mov cl,1 - +#ifdef __BORLANDC__ + } +#endif expandshort: +#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 @@ -551,72 +651,107 @@ asm jne expandshort length--; - __asm - { -asm mov bx,[headptr] -asm mov cl,1 - -asm mov si,[sourceoff] -asm mov di,[destoff] -asm mov es,[destseg] -asm mov ds,[sourceseg] + __asm { + mov bx,[word ptr headptr] + mov cl,1 -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 - { + __asm { mov ax,ss mov ds,ax } -}*/ +} /* @@ -628,7 +763,7 @@ asm jns expand // when length = ffff ffff, done = ====================== */ -/*++++ + #define NEARTAG 0xa7 #define FARTAG 0xa8 @@ -651,13 +786,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--) @@ -669,7 +804,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 --; } @@ -689,7 +824,6 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt } } } -*/ /* @@ -699,13 +833,13 @@ 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; @@ -746,7 +880,7 @@ long CA_RLEWCompress (unsigned huge *source, long length, unsigned huge *dest, complength = 2*(dest-start); return complength; } -*/ + /* ====================== @@ -756,12 +890,12 @@ 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; @@ -807,64 +941,88 @@ 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: +#ifdef __BORLANDC__ + __asm { +#endif + cmp di,ss:endoff + jne expand + mov ax,es + cmp ax,ss:endseg + jb expand -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 - + mov ax,ss + mov ds,ax + } } -*/ /* @@ -883,23 +1041,18 @@ asm mov ds,ax ====================== */ -/*void CAL_SetupGrFile (void) +void CAL_SetupGrFile (global_game_variables_t *gvar) { + char fname[13]; int handle; memptr compseg; #ifdef GRHEADERLINKED -#if GRMODE == EGAGR - grhuffman = (huffnode *)&EGAdict; - grstarts = (long _seg *)FP_SEG(&EGAhead); -#endif -#if GRMODE == CGAGR - grhuffman = (huffnode *)&CGAdict; - grstarts = (long _seg *)FP_SEG(&CGAhead); -#endif + gvar->ca.grhuffman = (huffnode *)&VGAdict; + grstarts = (long _seg *)FP_SEG(&VGAhead); - CAL_OptimizeNodes (grhuffman); + CAL_OptimizeNodes (gvar->ca.grhuffman); #else @@ -907,23 +1060,29 @@ asm mov ds,ax // load ???dict.ext (huffman dictionary for graphics files) // - if ((handle = open(GREXT"DICT."EXT, + strcpy(fname,GDICTNAME); + strcat(fname,EXTENSION); + + if ((handle = open(fname, O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open "GREXT"DICT."EXT"!"); + CA_CannotOpen(fname,gvar); - read(handle, &grhuffman, sizeof(grhuffman)); + read(handle, &gvar->ca.grhuffman, sizeof(gvar->ca.grhuffman)); close(handle); - CAL_OptimizeNodes (grhuffman); + CAL_OptimizeNodes (gvar->ca.grhuffman); // // load the data offsets from ???head.ext // - MM_GetPtr (&(memptr)grstarts,(NUMCHUNKS+1)*FILEPOSSIZE); + MM_GetPtr (MEMPTRCONV gvar->ca.grstarts,(NUMCHUNKS+1)*FILEPOSSIZE, gvar); + + strcpy(fname,GHEADNAME); + strcat(fname,EXTENSION); - if ((handle = open(GREXT"HEAD."EXT, + if ((handle = open(fname, O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open "GREXT"HEAD."EXT"!"); + CA_CannotOpen(fname,gvar); - CA_FarRead(handle, (memptr)grstarts, (NUMCHUNKS+1)*FILEPOSSIZE); + CA_FarRead(handle, (memptr)gvar->ca.grstarts, (NUMCHUNKS+1)*FILEPOSSIZE, gvar); close(handle); @@ -933,42 +1092,48 @@ asm mov ds,ax // // Open the graphics file, leaving it open until the game is finished // - grhandle = open(GREXT"GRAPH."EXT, O_RDONLY | O_BINARY); - if (grhandle == -1) - Quit ("Cannot open "GREXT"GRAPH."EXT"!"); + strcpy(fname,GFILENAME); + strcat(fname,EXTENSION); + + gvar->ca.file.grhandle = open(fname, O_RDONLY | O_BINARY); + if (gvar->ca.file.grhandle == -1) + CA_CannotOpen(fname,gvar); // // load the pic and sprite headers into the arrays in the data segment // #if NUMPICS>0 - MM_GetPtr(&(memptr)pictable,NUMPICS*sizeof(pictabletype)); - 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); - MM_FreePtr(&compseg); + MM_GetPtr(MEMPTRCONV gvar->video.pictable,NUMPICS*sizeof(pictabletype),gvar); + CAL_GetGrChunkLength(STRUCTPIC,gvar); // position file pointer + printf("CAL_SetupGrFile:\n"); + printf(" gvar->ca.chunkcomplen size is %lu\n", gvar->ca.chunkcomplen); + MM_GetPtr(&compseg,gvar->ca.chunkcomplen,gvar); + IN_Ack(gvar); + CA_FarRead (gvar->ca.file.grhandle,compseg,gvar->ca.chunkcomplen,gvar); + CAL_HuffExpand (compseg, (byte far *)gvar->video.pictable,NUMPICS*sizeof(pictabletype),gvar->ca.grhuffman); + MM_FreePtr(&compseg,gvar); #endif #if NUMPICM>0 - MM_GetPtr(&(memptr)picmtable,NUMPICM*sizeof(pictabletype)); + MM_GetPtr(MEMPTRCONV picmtable,NUMPICM*sizeof(pictabletype)); 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); + MM_GetPtr(&compseg,gvar->ca.chunkcomplen); + CA_FarRead (gvar->ca.file.grhandle,compseg,gvar->ca.chunkcomplen); + CAL_HuffExpand (compseg, (byte far *)picmtable,NUMPICS*sizeof(pictabletype),gvar->ca.grhuffman); MM_FreePtr(&compseg); #endif #if NUMSPRITES>0 - MM_GetPtr(&(memptr)spritetable,NUMSPRITES*sizeof(spritetabletype)); + MM_GetPtr(MEMPTRCONV spritetable,NUMSPRITES*sizeof(spritetabletype)); 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); + MM_GetPtr(&compseg,gvar->ca.chunkcomplen); + CA_FarRead (gvar->ca.file.grhandle,compseg,gvar->ca.chunkcomplen); + CAL_HuffExpand (compseg, (byte far *)spritetable,NUMSPRITES*sizeof(spritetabletype),gvar->ca.grhuffman); MM_FreePtr(&compseg); #endif -}*/ +} //========================================================================== @@ -981,41 +1146,47 @@ asm mov ds,ax ====================== */ -/*void CAL_SetupMapFile (void) +void CAL_SetupMapFile (global_game_variables_t *gvar) { +#ifndef MAPHEADERLINKED int handle; long length; +#endif // // load maphead.ext (offsets and tileinfo for map file) // #ifndef MAPHEADERLINKED - if ((handle = open("MAPHEAD."EXT, + if ((handle = open("maphead.mph", O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open MAPHEAD."EXT"!"); + Quit ("Can't open maphead.mph"); length = filelength(handle); - MM_GetPtr (&(memptr)tinf,length); - CA_FarRead(handle, tinf, length); + MM_GetPtr (MEMPTRCONV gvar->ca.tinf,length,gvar); + CA_FarRead(handle, gvar->ca.tinf, length,gvar); close(handle); -#else +//#else - tinf = (byte _seg *)FP_SEG(&maphead); + gvar->ca.tinf = (byte _seg *)FP_SEG(&maphead); #endif // // open the data file // -#ifdef MAPHEADERLINKED - if ((maphandle = open("GAMEMAPS."EXT, +//TODO: multiple files + if ((gvar->ca.file.maphandle = open("data/test.map", + O_RDONLY | O_BINARY, S_IREAD)) == -1) + Quit ("Can't open data/test.map!"); +/*#ifdef MAPHEADERLINKED + if ((maphandle = open("GAMEMAPS.16"ENSION, O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open GAMEMAPS."EXT"!"); + Quit ("Can't open GAMEMAPS.16"ENSION"!"); #else - if ((maphandle = open("MAPTEMP."EXT, + if ((maphandle = open("MAPTEMP.16"ENSION, O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open MAPTEMP."EXT"!"); -#endif -}*/ + Quit ("Can't open MAPTEMP.16"ENSION"!"); +#endif*/ +} //========================================================================== @@ -1037,11 +1208,11 @@ asm mov ds,ax // load maphead.ext (offsets and tileinfo for map file) // #ifndef AUDIOHEADERLINKED - if ((handle = open("AUDIOHED."EXT, + if ((handle = open("AUDIOHED.16", O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open AUDIOHED."EXT"!"); + Quit ("Can't open AUDIOHED.16""!"); length = filelength(handle); - MM_GetPtr (&(memptr)audiostarts,length); + MM_GetPtr (MEMPTRCONV audiostarts,length); CA_FarRead(handle, (byte far *)audiostarts, length); close(handle); #else @@ -1054,13 +1225,13 @@ asm mov ds,ax // open the data file // #ifndef AUDIOHEADERLINKED - if ((audiohandle = open("AUDIOT."EXT, + if ((audiohandle = open("AUDIOT.16", O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open AUDIOT."EXT"!"); + Quit ("Can't open AUDIOT.16""!"); #else - if ((audiohandle = open("AUDIO."EXT, + if ((audiohandle = open("AUDIO.16", O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open AUDIO."EXT"!"); + Quit ("Can't open AUDIO.16""!"); #endif }*/ @@ -1080,48 +1251,41 @@ asm mov ds,ax void CA_Startup(global_game_variables_t *gvar) { #ifdef PROFILE - unlink("profile.16"); - gvar->handle.profilehandle = open("profile.16", 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 +#ifdef __WATCOMC__ + unlink("profile.16w"); + gvar->handle.profilehandle = open("profile.16w", O_CREAT | O_WRONLY | O_TEXT); +#endif +#endif//profile -#ifndef NOAUDIO - CAL_SetupAudioFile(); +#ifdef __BORLANDC__ + unlink("meminfo.16b"); + gvar->handle.showmemhandle = open("meminfo.16b", O_CREAT | O_WRONLY | O_TEXT); +#endif +#ifdef __WATCOMC__ + unlink("meminfo.16w"); + gvar->handle.showmemhandle = open("meminfo.16w", O_CREAT | O_WRONLY | O_TEXT); #endif -// MDM begin - (GAMERS EDGE) -// - if (!FindFile("GAMEMAPS."EXT,NULL,1)) - Quit("CA_Startup(): Can't find level files."); -// -// MDM end #ifndef NOMAPS - CAL_SetupMapFile (); + CAL_SetupMapFile (gvar); #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 (); + CAL_SetupGrFile (gvar); +#endif +#ifndef NOAUDIO + CAL_SetupMapFile (gvar); #endif - 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;*/ } @@ -1144,10 +1308,11 @@ void CA_Shutdown(global_game_variables_t *gvar) #ifdef PROFILE close(gvar->handle.profilehandle); #endif -/*++++ - close(maphandle); - close(grhandle); - close(audiohandle);*/ + close(gvar->handle.showmemhandle); + + close(gvar->ca.file.maphandle); + close(gvar->ca.file.grhandle); + close(gvar->ca.file.audiohandle); } //=========================================================================== @@ -1171,14 +1336,14 @@ void CA_CacheAudioChunk (int chunk) if (audiosegs[chunk]) { - MM_SetPurge (&(memptr)audiosegs[chunk],0); + MM_SetPurge (MEMPTRCONV audiosegs[chunk],0); return; // allready in memory } // MDM begin - (GAMERS EDGE) // - if (!FindFile("AUDIO."EXT,NULL,2)) - Quit("CA_CacheAudioChunk(): Can't find audio files."); + if (!FindFile("AUDIO.16",NULL,2)) + Quit ("CA_CacheAudioChunk(): Can't find audio files."); // // MDM end @@ -1193,7 +1358,7 @@ void CA_CacheAudioChunk (int chunk) #ifndef AUDIOHEADERLINKED - MM_GetPtr (&(memptr)audiosegs[chunk],compressed); + MM_GetPtr (MEMPTRCONV audiosegs[chunk],compressed); if (mmerror) return; @@ -1218,7 +1383,7 @@ void CA_CacheAudioChunk (int chunk) expanded = *(long far *)source; source += 4; // skip over length - MM_GetPtr (&(memptr)audiosegs[chunk],expanded); + MM_GetPtr (MEMPTRCONV audiosegs[chunk],expanded); if (mmerror) goto done; CAL_HuffExpand (source,audiosegs[chunk],expanded,audiohuffman); @@ -1259,7 +1424,7 @@ void CA_LoadAllSounds (void) for (i=0;idata[0],smallplane*2,grhuffman); + CAL_HuffExpand (compressed, &dest->data[0],smallplane*2,gvar->ca.grhuffman); #endif @@ -1458,7 +1646,7 @@ void CAL_CacheSprite (int chunk, byte far *compressed) // // expand the unshifted shape // - CAL_HuffExpand (compressed, &dest->data[0],smallplane*5,grhuffman); + CAL_HuffExpand (compressed, &dest->data[0],smallplane*5,gvar->ca.grhuffman); // // make the shifts! @@ -1590,7 +1778,7 @@ void CAL_ExpandGrChunk (int chunk, byte far *source) MM_GetPtr (&grsegs[chunk],expanded); if (mmerror) return; - CAL_HuffExpand (source,grsegs[chunk],expanded,grhuffman); + CAL_HuffExpand (source,grsegs[chunk],expanded,gvar->ca.grhuffman); } } */ @@ -1616,21 +1804,21 @@ void CAL_ReadGrChunk (int chunk) // load the chunk into a buffer, either the miscbuffer if it fits, or allocate // a larger buffer // - pos = GRFILEPOS(chunk); + pos = GRFILEPOS(chunk,gvar); if (pos<0) // $FFFFFFFF start is a sparse tile return; next = chunk +1; - while (GRFILEPOS(next) == -1) // skip past any sparse tiles + while (GRFILEPOS(next,gvar) == -1) // skip past any sparse tiles next++; - compressed = GRFILEPOS(next)-pos; + compressed = GRFILEPOS(next,gvar)-pos; - lseek(grhandle,pos,SEEK_SET); + lseek(gvar->ca.file.grhandle,pos,SEEK_SET); if (compressed<=BUFFERSIZE) { - CA_FarRead(grhandle,bufferseg,compressed); + CA_FarRead(gvar->ca.file.grhandle,bufferseg,compressed); source = bufferseg; } else @@ -1639,7 +1827,7 @@ void CAL_ReadGrChunk (int chunk) if (mmerror) return; MM_SetLock (&bigbufferseg,true); - CA_FarRead(grhandle,bigbufferseg,compressed); + CA_FarRead(gvar->ca.file.grhandle,bigbufferseg,compressed); source = bigbufferseg; } @@ -1666,7 +1854,7 @@ void CA_CacheGrChunk (int chunk) byte far *source; int next; - grneeded[chunk] |= ca_levelbit; // make sure it doesn't get removed + gvar->ca.grneeded[chunk] |= ca_levelbit; // make sure it doesn't get removed if (grsegs[chunk]) { MM_SetPurge (&grsegs[chunk],0); @@ -1675,8 +1863,8 @@ void CA_CacheGrChunk (int chunk) // MDM begin - (GAMERS EDGE) // - if (!FindFile("EGAGRAPH."EXT,NULL,2)) - Quit("CA_CacheGrChunk(): Can't find graphics files."); + if (!FindFile("EGAGRAPH.16",NULL,2)) + Quit ("CA_CacheGrChunk(): Can't find graphics files."); // // MDM end @@ -1684,7 +1872,7 @@ void CA_CacheGrChunk (int chunk) // load the chunk into a buffer, either the miscbuffer if it fits, or allocate // a larger buffer // - pos = GRFILEPOS(chunk); + pos = GRFILEPOS(chunk,gvar); if (pos<0) // $FFFFFFFF start is a sparse tile return; @@ -1692,20 +1880,20 @@ void CA_CacheGrChunk (int chunk) while (GRFILEPOS(next) == -1) // skip past any sparse tiles next++; - compressed = GRFILEPOS(next)-pos; + compressed = GRFILEPOS(next,gvar)-pos; - lseek(grhandle,pos,SEEK_SET); + lseek(gvar->ca.file.grhandle,pos,SEEK_SET); if (compressed<=BUFFERSIZE) { - CA_FarRead(grhandle,bufferseg,compressed); + CA_FarRead(gvar->ca.file.grhandle,bufferseg,compressed); source = bufferseg; } else { MM_GetPtr(&bigbufferseg,compressed); MM_SetLock (&bigbufferseg,true); - CA_FarRead(grhandle,bigbufferseg,compressed); + CA_FarRead(gvar->ca.file.grhandle,bigbufferseg,compressed); source = bigbufferseg; } @@ -1726,8 +1914,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; @@ -1740,42 +1928,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(MEMPTRCONV gvar->ca.camapheaderseg[mapnum],sizeof(maptype)); +// lseek(maphandle,pos,SEEK_SET); +// CA_FarRead (maphandle,(memptr)mapheaderseg[mapnum],sizeof(maptype)); +// } +// else +// MM_SetPurge (MEMPTRCONV mapheaderseg[mapnum], 0, &(gvar->mm)); // // load the planes in @@ -1787,13 +1969,13 @@ 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 - dest = &(memptr)mapsegs[plane]; + dest = MEMPTRCONV mapsegs[plane]; MM_GetPtr(dest,size); lseek(maphandle,pos,SEEK_SET); @@ -1833,7 +2015,7 @@ void CA_CacheMap (int mapnum) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } -}*/ +}//*/ //=========================================================================== @@ -1847,15 +2029,15 @@ 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++; +} //=========================================================================== @@ -1869,15 +2051,15 @@ 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); +} //=========================================================================== @@ -1890,15 +2072,14 @@ void CA_DownLevel (void) = ====================== */ -/* -void CA_ClearMarks (void) + +void CA_ClearMarks (global_game_variables_t *gvar) { int i; for (i=0;ica.grneeded[i]&=~gvar->ca.ca_levelbit; } -*/ //=========================================================================== @@ -1911,14 +2092,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->ca.grneeded,0,sizeof(gvar->ca.grneeded)); + gvar->ca.ca_levelbit = 1; + gvar->ca.ca_levelnum = 0; } -*/ //=========================================================================== @@ -1929,16 +2109,21 @@ void CA_ClearAllMarks (void) = ====================== */ -/*++++ -void CA_FreeGraphics (void) + +void CA_SetGrPurge (global_game_variables_t *gvar) { - int i; + int i; + +// +// free graphics +// + CA_ClearMarks (gvar); for (i=0;ica.grsegs[i]) + MM_SetPurge (gvar->ca.grsegs[i],3, gvar); } -*/ + /* ====================== @@ -1949,56 +2134,43 @@ void CA_FreeGraphics (void) = ====================== */ -/*++++++++ -void CA_SetAllPurge (void) + +void CA_SetAllPurge (global_game_variables_t *gvar) { int i; - CA_ClearMarks (); + CA_ClearMarks (gvar); // // free cursor sprite and background save // - VW_FreeCursor (); + //____VW_FreeCursor (); // // free map headers and map planes // - for (i=0;ica.camap.mapheaderseg[i]) +// MM_SetPurge (gvar->ca.camap.mapheaderseg[i],3, gvar); for (i=0;i<3;i++) - if (mapsegs[i]) - MM_FreePtr (&(memptr)mapsegs[i]); + if (gvar->ca.mapsegs[i]) + MM_FreePtr ((memptr *)&gvar->ca.mapsegs[i], gvar); // // free sounds // for (i=0;ica.audiosegs[i]) + MM_SetPurge ((memptr *)&gvar->ca.audiosegs[i],3, gvar); // // free graphics // - CA_FreeGraphics (); + CA_SetGrPurge (gvar); } -void CA_SetGrPurge (void) -{ - int i; - -// -// free graphics -// - for (i=0;ica.grneeded[i]&(gvar->ca.ca_levelbit))//if (grneeded[i]&ca_levelbit) { - if (grsegs[i]) // its allready in memory, make - MM_SetPurge(&grsegs[i],0); // sure it stays there! + if (gvar->ca.grsegs[i]) // its allready in memory, make + MM_SetPurge(gvar->ca.grsegs[i],0,gvar); // sure it stays there! else numcache++; } else { - if (grsegs[i]) // not needed, so make it purgeable - MM_SetPurge(&grsegs[i],3); + if (gvar->ca.grsegs[i]) // not needed, so make it purgeable + MM_SetPurge(gvar->ca.grsegs[i],3,gvar); } if (!numcache) // nothing to cache! @@ -2158,8 +2330,8 @@ void CA_CacheMarks (char *title) // MDM begin - (GAMERS EDGE) // - if (!FindFile("EGAGRAPH."EXT,NULL,2)) - Quit("CA_CacheMarks(): Can't find graphics files."); +// if (!FindFile("EGAGRAPH.16",NULL,2)) +// Quit ("CA_CacheMarks(): Can't find graphics files."); // // MDM end @@ -2179,7 +2351,7 @@ void CA_CacheMarks (char *title) bufferstart = bufferend = 0; // nothing good in buffer now for (i=0;ica.grneeded[i]&(gvar->ca.ca_levelbit)) && !gvar->ca.grsegs[i]) { // // update thermometer @@ -2187,7 +2359,7 @@ void CA_CacheMarks (char *title) if (dialog && updatecachebox) updatecachebox (); - pos = GRFILEPOS(i); + pos = GRFILEPOS(i,gvar); if (pos<0) continue; @@ -2195,7 +2367,7 @@ void CA_CacheMarks (char *title) while (GRFILEPOS(next) == -1) // skip past any sparse tiles next++; - compressed = GRFILEPOS(next)-pos; + compressed = GRFILEPOS(next,gvar)-pos; endpos = pos+compressed; if (compressed<=BUFFERSIZE) @@ -2213,15 +2385,15 @@ 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; - nextpos = GRFILEPOS(next); - while (GRFILEPOS(++next) == -1) // skip past any sparse tiles + nextpos = GRFILEPOS(next,gvar); + while (GRFILEPOS(++next,gvar) == -1) // skip past any sparse tiles ; - nextendpos = GRFILEPOS(next); + nextendpos = GRFILEPOS(next,gvar); if (nextpos - endpos <= MAXEMPTYREAD && nextendpos-pos <= BUFFERSIZE) endpos = nextendpos; @@ -2229,8 +2401,8 @@ void CA_CacheMarks (char *title) next = NUMCHUNKS; // read pos to posend } - lseek(grhandle,pos,SEEK_SET); - CA_FarRead(grhandle,bufferseg,endpos-pos); + lseek(gvar->ca.file.grhandle,pos,SEEK_SET); + CA_FarRead(gvar->ca.file.grhandle,(gvar->mm.bufferseg),endpos-pos,gvar); bufferstart = pos; bufferend = endpos; source = bufferseg; @@ -2239,12 +2411,12 @@ void CA_CacheMarks (char *title) else { // big chunk, allocate temporary buffer - MM_GetPtr(&bigbufferseg,compressed); + MM_GetPtr(&bigbufferseg,compressed,gvar); if (mmerror) return; MM_SetLock (&bigbufferseg,true); - lseek(grhandle,pos,SEEK_SET); - CA_FarRead(grhandle,bigbufferseg,compressed); + lseek(gvar->ca.file.grhandle,pos,SEEK_SET); + CA_FarRead(gvar->ca.file.grhandle,bigbufferseg,compressed,gvar); source = bigbufferseg; } @@ -2263,3 +2435,13 @@ void CA_CacheMarks (char *title) if (dialog && finishcachebox) finishcachebox(); }*/ + +void CA_CannotOpen(char *string, global_game_variables_t *gvar) +{ + char str[30]; + + strcpy(str,"Can't open "); + strcat(str,string); + strcat(str,"!\n"); + Quit (str); +}