X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_ca.c;h=2ed42cd88e713061eab42f57ad006bf47f0007f6;hb=6021fc3f27b895d382fbd30488ead35657e39196;hp=74fb0f676feae633d3e3eda60fd079cb7f5cde83;hpb=d6f4d6055ab7da24dd416e4161bef5ea5662a170;p=16.git diff --git a/src/lib/16_ca.c b/src/lib/16_ca.c index 74fb0f67..2ed42cd8 100755 --- a/src/lib/16_ca.c +++ b/src/lib/16_ca.c @@ -1,19 +1,23 @@ -/* Catacomb Apocalypse Source Code - * Copyright (C) 1993-2014 Flat Rock Software +/* Project 16 Source Code~ + * Copyright (C) 2012-2018 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover * - * This program is free software; you can redistribute it and/or modify + * This file is part of Project 16. + * + * Project 16 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * Project 16 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see , or + * write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301 USA. + * */ // ID_CA.C @@ -36,8 +40,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 /* ============================================================================= @@ -97,16 +102,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 @@ -119,9 +125,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; @@ -129,20 +135,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; @@ -153,8 +160,14 @@ 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 + +//#define EXTENSION "hb1" /* ============================================================================= @@ -202,13 +215,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; +} /* @@ -221,63 +234,51 @@ void CAL_GetGrChunkLength (int chunk) ========================== */ -boolean CA_FarRead(int handle, byte huge *dest, dword length, global_game_variables_t *gvar) +boolean CA_FarRead(int handle, byte far *dest, dword length, global_game_variables_t *gvar) { - boolean flag; - //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 + boolean flag=0; + if (length>0xfffflu) + Quit (gvar, "CA_FarRead doesn't support 64K reads yet!");//TODO: EXPAND!!! + + __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; } @@ -286,70 +287,58 @@ End: /* ========================== = -= CA_SegWrite += CA_FarWrite = = Write from a file to a far pointer = ========================== */ -boolean CA_FarWrite(int handle, byte huge *source, dword length, global_game_variables_t *gvar) +boolean CA_FarWrite(int handle, byte far *source, dword length, global_game_variables_t *gvar) { - boolean flag; - //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 + boolean flag=0; + if (length>0xfffflu) + Quit (gvar, "CA_FarWrite doesn't support 64K reads yet!");//TODO: EXPAND!!! + + __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; } @@ -375,12 +364,23 @@ boolean CA_ReadFile(char *filename, memptr *ptr, global_game_variables_t *gvar) return false; size = filelength(handle); +#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); + close(handle); return false; } - close (handle); + close(handle); return true; } @@ -398,7 +398,7 @@ boolean CA_ReadFile(char *filename, memptr *ptr, global_game_variables_t *gvar) boolean CA_WriteFile (char *filename, void far *ptr, long length, global_game_variables_t *gvar) { int handle; - sdword size; + //sdword size; //long size; handle = open(filename,O_CREAT | O_BINARY | O_WRONLY, @@ -438,7 +438,28 @@ boolean CA_LoadFile(char *filename, memptr *ptr, global_game_variables_t *gvar) return false; 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); @@ -498,15 +519,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--; @@ -533,7 +554,7 @@ void CAL_HuffExpand (byte huge *source, byte huge *dest, //-------------------------- __asm { -//// mov bx,[headptr] + mov bx,[word ptr headptr] mov si,[sourceoff] mov di,[destoff] @@ -597,7 +618,7 @@ storebyteshort: #endif mov [es:di],dl inc di // write a decopmpressed byte out -//// mov bx,[headptr] // back to the head node for next bit + mov bx,[word ptr headptr] // back to the head node for next bit cmp di,ax // done? jne expandshort @@ -613,7 +634,7 @@ storebyteshort: length--; __asm { -//// mov bx,[headptr] + mov bx,[word ptr headptr] mov cl,1 mov si,[sourceoff] @@ -685,7 +706,7 @@ storebyte: #endif mov [es:di],dl inc di // write a decopmpressed byte out -//// mov bx,[headptr] // back to the head node for next bit + mov bx,[word ptr headptr] // back to the head node for next bit cmp di,0x10 // normalize es:di jb dinorm @@ -795,12 +816,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; @@ -852,11 +873,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; @@ -1001,24 +1022,21 @@ dinorm: = ====================== */ -////++++ enable! -/*void CAL_SetupGrFile (void) + +void CAL_SetupGrFile (global_game_variables_t *gvar) { + char fname[13]; int handle; +#if NUMPICS>0 memptr compseg; +#endif #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 @@ -1026,23 +1044,29 @@ dinorm: // load ???dict.ext (huffman dictionary for graphics files) // - if ((handle = open(GREXT"DICT."EXT, + strcpy(fname,GDICTNAME); + strcat(fname,"hb1"); + + 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); - if ((handle = open(GREXT"HEAD."EXT, + strcpy(fname,GHEADNAME); + strcat(fname,"hb1"); + + 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); @@ -1052,42 +1076,48 @@ dinorm: // // 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,"hb1"); + + 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(MEMPTRANDPERCONV 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(MEMPTRANDPERCONV compseg,gvar); #endif -#if NUMPICM>0 - MM_GetPtr(&(memptr)picmtable,NUMPICM*sizeof(pictabletype)); +#if 0 + //NUMPICM>0 + 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 +//#endif -#if NUMSPRITES>0 - MM_GetPtr(&(memptr)spritetable,NUMSPRITES*sizeof(spritetabletype)); +//#if NUMSPRITES>0 + 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 -}*/ +} //========================================================================== @@ -1102,44 +1132,44 @@ dinorm: 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, -// O_RDONLY | O_BINARY, S_IREAD)) == -1) -// printf("Can't open MAPHEAD."EXT"!"); -// length = filelength(handle); -// MM_GetPtr (&(memptr)tinf,length); -// CA_FarRead(handle, tinf, length); -// close(handle); -// //#else -// -// tinf = (byte _seg *)FP_SEG(&maphead); -// -// #endif +#ifndef MAPHEADERLINKED + if ((handle = open("maphead.mph", + O_RDONLY | O_BINARY, S_IREAD)) == -1) + Quit (gvar, "Can't open maphead.mph"); + length = filelength(handle); + MM_GetPtr (MEMPTRCONV gvar->ca.tinf,length,gvar); + CA_FarRead(handle, gvar->ca.tinf, length,gvar); + close(handle); +#else + + gvar->ca.tinf = (byte _seg *)FP_SEG(&maphead); + +#endif // // open the data file // //TODO: multiple files - if ((gvar->ca.file.maphandle[0] = open("data/test.map", + if ((gvar->ca.file.maphandle = open("data/test.map", O_RDONLY | O_BINARY, S_IREAD)) == -1) - { - printf("Can't open data/test.map!"); - } -// #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, -// O_RDONLY | O_BINARY, S_IREAD)) == -1) -// Quit ("Can't open MAPTEMP."EXT"!"); -// #endif + Quit (gvar, "Can't open data/test.map!"); +/*#ifdef MAPHEADERLINKED + if ((maphandle = open("GAMEMAPS.16"ENSION, + O_RDONLY | O_BINARY, S_IREAD)) == -1) + Quit (gvar, "Can't open GAMEMAPS.16"ENSION"!"); +#else + if ((maphandle = open("MAPTEMP.16"ENSION, + O_RDONLY | O_BINARY, S_IREAD)) == -1) + Quit (gvar, "Can't open MAPTEMP.16"ENSION"!"); +#endif*/ } //========================================================================== @@ -1162,11 +1192,11 @@ void CAL_SetupMapFile (global_game_variables_t *gvar) // 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 (gvar, "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 @@ -1179,13 +1209,13 @@ void CAL_SetupMapFile (global_game_variables_t *gvar) // 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 (gvar, "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 (gvar, "Can't open AUDIO.16""!"); #endif }*/ @@ -1215,6 +1245,7 @@ void CA_Startup(global_game_variables_t *gvar) #endif #endif//profile +#ifdef SHOWMEMINFO #ifdef __BORLANDC__ unlink("meminfo.16b"); gvar->handle.showmemhandle = open("meminfo.16b", O_CREAT | O_WRONLY | O_TEXT); @@ -1223,12 +1254,20 @@ void CA_Startup(global_game_variables_t *gvar) unlink("meminfo.16w"); gvar->handle.showmemhandle = open("meminfo.16w", O_CREAT | O_WRONLY | O_TEXT); #endif -/* - CAL_SetupGrFile (); - CAL_SetupAudioFile ();*/ +#endif + + +#ifndef NOMAPS CAL_SetupMapFile (gvar); +#endif +#ifndef NOGRAPHICS + CAL_SetupGrFile (gvar); +#endif +#ifndef NOAUDIO + CAL_SetupMapFile (gvar); +#endif - gvar->ca.camap.mapon = -1; + gvar->ca.mapon = -1; gvar->ca.ca_levelbit = 1; gvar->ca.ca_levelnum = 0; @@ -1255,12 +1294,13 @@ void CA_Shutdown(global_game_variables_t *gvar) #ifdef PROFILE close(gvar->handle.profilehandle); #endif +#ifdef SHOWMEMINFO close(gvar->handle.showmemhandle); +#endif - close(*(gvar->ca.file.maphandle)); -/*++++ - close(grhandle); - close(audiohandle);*/ + close(gvar->ca.file.maphandle); + close(gvar->ca.file.grhandle); + close(gvar->ca.file.audiohandle); } //=========================================================================== @@ -1284,14 +1324,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 (gvar, "CA_CacheAudioChunk(): Can't find audio files."); // // MDM end @@ -1306,7 +1346,7 @@ void CA_CacheAudioChunk (int chunk) #ifndef AUDIOHEADERLINKED - MM_GetPtr (&(memptr)audiosegs[chunk],compressed); + MM_GetPtr (MEMPTRCONV audiosegs[chunk],compressed); if (mmerror) return; @@ -1331,7 +1371,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); @@ -1372,7 +1412,7 @@ void CA_LoadAllSounds (void) for (i=0;ivideo.shifttabletable+bp] // bp holds pointer to shift table -asm cmp [ss:dothemask],0 -asm je skipmask + cmp [ss:dothemask],0 + je skipmask // // table shift the mask // -asm mov dx,[ss:sheight] - + mov dx,[ss:sheight] +#ifdef __BORLANDC__ + } +#endif domaskrow: - -asm mov BYTE PTR [di],255 // 0xff first byte -asm mov cx,ss:[swidth] - +#ifdef __BORLANDC__ + __asm { +#endif + mov BYTE PTR [di],255 // 0xff first byte + mov cx,ss:[swidth] +#ifdef __BORLANDC__ + } +#endif domaskbyte: - -asm mov al,[bx] // source -asm not al -asm inc bx // next source byte -asm xor ah,ah -asm shl ax,1 -asm mov si,ax -asm mov ax,[bp+si] // table shift into two bytes -asm not ax -asm and [di],al // and with first byte -asm inc di -asm mov [di],ah // replace next byte - -asm loop domaskbyte - -asm inc di // the last shifted byte has 1s in it -asm dec dx -asm jnz domaskrow - +#ifdef __BORLANDC__ + __asm { +#endif + mov al,[bx] // source + not al + inc bx // next source byte + xor ah,ah + shl ax,1 + mov si,ax + mov ax,[bp+si] // table shift into two bytes + not ax + and [di],al // and with first byte + inc di + mov [di],ah // replace next byte + + loop domaskbyte + + inc di // the last shifted byte has 1s in it + dec dx + jnz domaskrow +#ifdef __BORLANDC__ + } +#endif skipmask: - +#ifdef __BORLANDC__ + __asm { +#endif // // table shift the data // -asm mov dx,ss:[sheight] -asm shl dx,1 -asm shl dx,1 // four planes of data - + mov dx,ss:[sheight] + shl dx,1 + shl dx,1 // four planes of data +#ifdef __BORLANDC__ + } +#endif dodatarow: - -asm mov BYTE PTR [di],0 // 0 first byte -asm mov cx,ss:[swidth] - +#ifdef __BORLANDC__ + __asm { +#endif + mov BYTE PTR [di],0 // 0 first byte + mov cx,ss:[swidth] +#ifdef __BORLANDC__ + } +#endif dodatabyte: +#ifdef __BORLANDC__ + __asm { +#endif + mov al,[bx] // source + inc bx // next source byte + xor ah,ah + shl ax,1 + mov si,ax + mov ax,[bp+si] // table shift into two bytes + or [di],al // or with first byte + inc di + mov [di],ah // replace next byte -asm mov al,[bx] // source -asm inc bx // next source byte -asm xor ah,ah -asm shl ax,1 -asm mov si,ax -asm mov ax,[bp+si] // table shift into two bytes -asm or [di],al // or with first byte -asm inc di -asm mov [di],ah // replace next byte - -asm loop dodatabyte + loop dodatabyte -asm inc di // the last shifted byte has 0s in it -asm dec dx -asm jnz dodatarow + inc di // the last shifted byte has 0s in it + dec dx + jnz dodatarow // // done // -asm mov ax,ss // restore data segment -asm mov ds,ax + mov ax,ss // restore data segment + mov ds,ax + } } @@ -1517,7 +1580,7 @@ asm mov ds,ax ====================== */ /*++++ -void CAL_CacheSprite (int chunk, byte far *compressed) +void CAL_CacheSprite (int chunk, byte far *compressed, global_game_variables_t *gvar) { int i; unsigned shiftstarts[5]; @@ -1525,11 +1588,12 @@ void CAL_CacheSprite (int chunk, byte far *compressed) spritetabletype far *spr; spritetype _seg *dest; -#if GRMODE == CGAGR +#if 0 +//GRMODE == CGAGR // // CGA has no pel panning, so shifts are never needed // - spr = &spritetable[chunk-STARTSPRITES]; + spr = &gvar->video.spritetable[chunk-STARTSPRITES]; smallplane = spr->width*spr->height; MM_GetPtr (&grsegs[chunk],smallplane*2+MAXSHIFTS*6); if (mmerror) @@ -1542,17 +1606,17 @@ void CAL_CacheSprite (int chunk, byte far *compressed) // // expand the unshifted shape // - CAL_HuffExpand (compressed, &dest->data[0],smallplane*2,grhuffman); + CAL_HuffExpand (compressed, &dest->data[0],smallplane*2,gvar->ca.grhuffman); #endif -#if GRMODE == EGAGR +//#if GRMODE == EGAGR // // calculate sizes // - spr = &spritetable[chunk-STARTSPRITES]; + spr = &gvar->video.spritetable[chunk-STARTSPRITES]; smallplane = spr->width*spr->height; bigplane = (spr->width+1)*spr->height; @@ -1563,15 +1627,15 @@ void CAL_CacheSprite (int chunk, byte far *compressed) shiftstarts[4] = shiftstarts[3] + bigplane*5; // nothing ever put here expanded = shiftstarts[spr->shifts]; - MM_GetPtr (&grsegs[chunk],expanded); - if (mmerror) + MM_GetPtr (MEMPTRCONV gvar->ca.grsegs[chunk],expanded, gvar); + if (gvar->mm.mmerror) return; - dest = (spritetype _seg *)grsegs[chunk]; + dest = (spritetype _seg *)gvar->ca.grsegs[chunk]; // // 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! @@ -1600,8 +1664,8 @@ void CAL_CacheSprite (int chunk, byte far *compressed) dest->planesize[i] = bigplane; dest->width[i] = spr->width+1; } - CAL_ShiftSprite ((unsigned)grsegs[chunk],dest->sourceoffset[0], - dest->sourceoffset[2],spr->width,spr->height,4,true); + CAL_ShiftSprite ((unsigned)gvar->ca.grsegs[chunk],dest->sourceoffset[0], + dest->sourceoffset[2],spr->width,spr->height,4,true,gvar); break; case 4: @@ -1612,28 +1676,28 @@ void CAL_CacheSprite (int chunk, byte far *compressed) dest->sourceoffset[1] = shiftstarts[1]; dest->planesize[1] = bigplane; dest->width[1] = spr->width+1; - CAL_ShiftSprite ((unsigned)grsegs[chunk],dest->sourceoffset[0], - dest->sourceoffset[1],spr->width,spr->height,2,true); + CAL_ShiftSprite ((unsigned)gvar->ca.grsegs[chunk],dest->sourceoffset[0], + dest->sourceoffset[1],spr->width,spr->height,2,true,gvar); dest->sourceoffset[2] = shiftstarts[2]; dest->planesize[2] = bigplane; dest->width[2] = spr->width+1; - CAL_ShiftSprite ((unsigned)grsegs[chunk],dest->sourceoffset[0], - dest->sourceoffset[2],spr->width,spr->height,4,true); + CAL_ShiftSprite ((unsigned)gvar->ca.grsegs[chunk],dest->sourceoffset[0], + dest->sourceoffset[2],spr->width,spr->height,4,true,gvar); dest->sourceoffset[3] = shiftstarts[3]; dest->planesize[3] = bigplane; dest->width[3] = spr->width+1; - CAL_ShiftSprite ((unsigned)grsegs[chunk],dest->sourceoffset[0], - dest->sourceoffset[3],spr->width,spr->height,6,true); + CAL_ShiftSprite ((unsigned)gvar->ca.grsegs[chunk],dest->sourceoffset[0], + dest->sourceoffset[3],spr->width,spr->height,6,true,gvar); break; default: - Quit ("CAL_CacheSprite: Bad shifts number!"); + Quit (gvar, "CAL_CacheSprite: Bad shifts number!"); } -#endif +//#endif }*/ //=========================================================================== @@ -1703,7 +1767,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); } } */ @@ -1729,21 +1793,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 @@ -1752,7 +1816,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; } @@ -1779,7 +1843,7 @@ void CA_CacheGrChunk (int chunk) byte far *source; int next; - gvar->video.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); @@ -1788,8 +1852,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 (gvar, "CA_CacheGrChunk(): Can't find graphics files."); // // MDM end @@ -1797,7 +1861,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; @@ -1805,27 +1869,27 @@ 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; } CAL_ExpandGrChunk (chunk,source); if (compressed>BUFFERSIZE) - MM_FreePtr(&bigbufferseg); + MM_FreePtr (MEMPTRCONV bigbufferseg); } */ @@ -1839,7 +1903,7 @@ void CA_CacheGrChunk (int chunk) = ====================== */ -/*++++ segments! + void CA_CacheMap (global_game_variables_t *gvar) { long pos,compressed; @@ -1856,32 +1920,43 @@ void CA_CacheMap (global_game_variables_t *gvar) // // free up memory from last map // - if (gvar->ca.map.mapon>-1 && gvar->ca.map.mapheaderseg[gvar->ca.map.mapon]) - MM_SetPurge (&((memptr)gvar->ca.map.mapheaderseg[(gvar->ca.map.mapon)]), 3, &(gvar->mm)); + if (gvar->ca.mapon>-1 && gvar->ca.mapheaderseg[gvar->ca.mapon]) + MM_SetPurge ((MEMPTRCONV gvar->ca.mapheaderseg[(gvar->ca.mapon)]), 3, gvar); for (plane=0;planeca.map.mapsegs[plane]) - MM_FreePtr (&(memptr)gvar->ca.map.mapsegs[plane], &(gvar->mm)); + if (gvar->ca.mapsegs[plane]) + MM_FreePtr (MEMPTRCONV gvar->ca.mapsegs[plane], gvar); - gvar->ca.map.mapon = gvar->ca.map.mapnum; + gvar->ca.mapon = gvar->ca.mapnum; // // load map header // The header will be cached if it is still around // - if (!gvar->ca.map.mapheaderseg[gvar->ca.map.mapnum]) + if (!gvar->ca.mapheaderseg[gvar->ca.mapnum]) { - //pos = ((mapfiletype _seg *)tinf)->headeroffsets[mapnum]; - pos = ((_seg *)gvar->ca.map.tinf)->headeroffsets[gvar->ca.map.mapnum]; + pos = ((mapfiletype _seg *)gvar->ca.tinf)->headeroffsets[gvar->ca.mapnum]; if (pos<0) // $FFFFFFFF start is a sparse map - printf("CA_CacheMap: Tried to load a non existent map!"); + Quit (gvar, "CA_CacheMap: Tried to load a non existent map!"); - MM_GetPtr(&(memptr)gvar->ca.mapheaderseg[mapnum],sizeof(maptype)); - lseek(maphandle,pos,SEEK_SET); - CA_FarRead (maphandle,(memptr)mapheaderseg[mapnum],sizeof(maptype)); + MM_GetPtr(MEMPTRCONV gvar->ca.mapheaderseg[gvar->ca.mapnum],sizeof(maptype), gvar); + lseek(gvar->ca.file.maphandle,pos,SEEK_SET); +#ifdef MAPHEADERLINKED +//#if BUFFERSIZE < sizeof(maptype) +//The general buffer size is too small! +//#endif + // + // load in, then unhuffman to the destination + // + CA_FarRead (gvar->ca.file.maphandle,gvar->mm.bufferseg,((mapfiletype _seg *)gvar->ca.tinf)->headersize[gvar->ca.mapnum], gvar); + CAL_HuffExpand ((byte huge *)bufferseg, + (byte huge *)gvar->ca.mapheaderseg[gvar->ca.mapnum],sizeof(maptype),maphuffman, gvar); +#else + CA_FarRead (gvar->ca.file.maphandle,(memptr)gvar->ca.mapheaderseg[gvar->ca.mapnum],sizeof(maptype), gvar); +#endif } else - MM_SetPurge (&(memptr)mapheaderseg[mapnum], 0, &(gvar->mm)); + MM_SetPurge (MEMPTRCONV gvar->ca.mapheaderseg[gvar->ca.mapnum], 0, gvar); // // load the planes in @@ -1889,30 +1964,30 @@ void CA_CacheMap (global_game_variables_t *gvar) // allways reloaded, never cached) // - size = mapheaderseg[mapnum]->width * mapheaderseg[mapnum]->height * 2; + size = gvar->ca.mapheaderseg[gvar->ca.mapnum]->width * gvar->ca.mapheaderseg[gvar->ca.mapnum]->height * 2; for (plane = 0; planeplanestart[plane]; - compressed = mapheaderseg[mapnum]->planelength[plane]; + pos = gvar->ca.mapheaderseg[gvar->ca.mapnum]->planestart[plane]; + compressed = gvar->ca.mapheaderseg[gvar->ca.mapnum]->planelength[plane]; if (!compressed) continue; // the plane is not used in this game - dest = &(memptr)mapsegs[plane]; - MM_GetPtr(dest,size); + dest = MEMPTRCONV gvar->ca.mapsegs[plane]; + MM_GetPtr(dest,size, gvar); - lseek(maphandle,pos,SEEK_SET); + lseek(gvar->ca.file.maphandle,pos,SEEK_SET); if (compressed<=BUFFERSIZE) - source = bufferseg; + source = gvar->mm.bufferseg; else { - MM_GetPtr(&bigbufferseg,compressed); - MM_SetLock (&bigbufferseg,true); + MM_GetPtr(MEMPTRCONV bigbufferseg,compressed, gvar); + MM_SetLock (MEMPTRCONV bigbufferseg,true, gvar); source = bigbufferseg; } - CA_FarRead(maphandle,(byte far *)source,compressed); + CA_FarRead(gvar->ca.file.maphandle,(byte far *)source,compressed, gvar); #ifdef MAPHEADERLINKED // // unhuffman, then unRLEW @@ -1922,7 +1997,7 @@ void CA_CacheMap (global_game_variables_t *gvar) // expanded = *source; source++; - MM_GetPtr (&buffer2seg,expanded); + MM_GetPtr (&buffer2seg,expanded, gvar); CAL_CarmackExpand (source, (unsigned far *)buffer2seg,expanded); CA_RLEWexpand (((unsigned far *)buffer2seg)+1,*dest,size, ((mapfiletype _seg *)tinf)->RLEWtag); @@ -1933,13 +2008,13 @@ void CA_CacheMap (global_game_variables_t *gvar) // unRLEW, skipping expanded length // CA_RLEWexpand (source+1, *dest,size, - ((mapfiletype _seg *)tinf)->RLEWtag); + ((mapfiletype _seg *)gvar->ca.tinf)->RLEWtag); #endif if (compressed>BUFFERSIZE) - MM_FreePtr(&bigbufferseg); + MM_FreePtr(MEMPTRCONV bigbufferseg, gvar); } -}//*/ +} //=========================================================================== @@ -2002,7 +2077,7 @@ void CA_ClearMarks (global_game_variables_t *gvar) int i; for (i=0;ivideo.grneeded[i]&=~gvar->ca.ca_levelbit; + gvar->ca.grneeded[i]&=~gvar->ca.ca_levelbit; } //=========================================================================== @@ -2019,7 +2094,7 @@ void CA_ClearMarks (global_game_variables_t *gvar) void CA_ClearAllMarks (global_game_variables_t *gvar) { - _fmemset (gvar->video.grneeded,0,sizeof(gvar->video.grneeded)); + _fmemset (gvar->ca.grneeded,0,sizeof(gvar->ca.grneeded)); gvar->ca.ca_levelbit = 1; gvar->ca.ca_levelnum = 0; } @@ -2033,21 +2108,21 @@ void CA_ClearAllMarks (global_game_variables_t *gvar) = ====================== */ -/*++++ -void CA_SetGrPurge (void) + +void CA_SetGrPurge (global_game_variables_t *gvar) { int i; // // free graphics // - CA_ClearMarks (); + CA_ClearMarks (gvar); for (i=0;ica.grsegs[i]) + MM_SetPurge (MEMPTRCONV gvar->ca.grsegs[i],3, gvar); } -*/ + /* ====================== @@ -2058,41 +2133,41 @@ void CA_SetGrPurge (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.mapheaderseg[i]) + MM_SetPurge (MEMPTRCONV gvar->ca.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 (MEMPTRCONV gvar->ca.mapsegs[i], gvar); // // free sounds // for (i=0;ica.audiosegs[i]) + MM_SetPurge (MEMPTRCONV gvar->ca.audiosegs[i],3, gvar); // // free graphics // - CA_SetGrPurge (); -}*/ + CA_SetGrPurge (gvar); +} //=========================================================================== @@ -2217,10 +2292,10 @@ void CAL_DialogFinish (void) = CA_CacheMarks = ====================== -*//* +*/ #define MAXEMPTYREAD 1024 - -void CA_CacheMarks (char *title) +/*++++ segments +void CAL_CacheMarks (char *title, global_game_variables_t *gvar) { boolean dialog; int i,next,numcache; @@ -2236,17 +2311,17 @@ void CA_CacheMarks (char *title) // go through and make everything not needed purgable // for (i=0;ivideo.grneeded[i]&ca_levelbit) + if (gvar->ca.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! @@ -2254,8 +2329,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 (gvar, "CA_CacheMarks(): Can't find graphics files."); // // MDM end @@ -2275,7 +2350,7 @@ void CA_CacheMarks (char *title) bufferstart = bufferend = 0; // nothing good in buffer now for (i=0;ivideo.grneeded[i]&ca_levelbit) && !grsegs[i]) + if ( (gvar->ca.grneeded[i]&(gvar->ca.ca_levelbit)) && !gvar->ca.grsegs[i]) { // // update thermometer @@ -2283,7 +2358,7 @@ void CA_CacheMarks (char *title) if (dialog && updatecachebox) updatecachebox (); - pos = GRFILEPOS(i); + pos = GRFILEPOS(i,gvar); if (pos<0) continue; @@ -2291,7 +2366,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) @@ -2314,10 +2389,10 @@ void CA_CacheMarks (char *title) 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; @@ -2325,8 +2400,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; @@ -2335,12 +2410,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; } @@ -2358,4 +2433,14 @@ 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 (gvar, str); +}