X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_ca.c;h=4373ad005ad93b3df9ab4c51fa82ee6817296d99;hb=a565be31ce92d6168ae6983042da75b0b683e52b;hp=ccab39ba8c97e10a7b11703e903d5522ac6f207e;hpb=3e49e24d51e5a253c8bd3caaa447150d009ea85d;p=16.git diff --git a/src/lib/16_ca.c b/src/lib/16_ca.c index ccab39ba..4373ad00 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-2019 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 @@ -163,6 +167,8 @@ CASVT GRFILEPOS(int c, global_game_variables_t *gvar) } #endif +//#define EXTENSION "hp1" + /* ============================================================================= @@ -231,21 +237,9 @@ void CAL_GetGrChunkLength (int chunk,global_game_variables_t *gvar) boolean CA_FarRead(int handle, byte far *dest, dword length, global_game_variables_t *gvar) { 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 (length>0xfffflu) + Quit (gvar, "CA_FarRead doesn't support 64K reads yet!");//TODO: EXPAND!!! - //if(!fat&&!segm) - //{ __asm { push ds mov bx,[handle] @@ -293,7 +287,7 @@ End: /* ========================== = -= CA_SegWrite += CA_FarWrite = = Write from a file to a far pointer = @@ -303,21 +297,9 @@ End: boolean CA_FarWrite(int handle, byte far *source, dword length, global_game_variables_t *gvar) { 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_FarWrite doesn't support 64K reads yet!\n"); - return 0; - } + if (length>0xfffflu) + Quit (gvar, "CA_FarWrite doesn't support 64K reads yet!");//TODO: EXPAND!!! - //if(!fat&&!segm) - //{ __asm { push ds mov bx,[handle] @@ -1063,7 +1045,7 @@ void CAL_SetupGrFile (global_game_variables_t *gvar) // strcpy(fname,GDICTNAME); - strcat(fname,EXTENSION); + strcat(fname,"hp1"); if ((handle = open(fname, O_RDONLY | O_BINARY, S_IREAD)) == -1) @@ -1078,7 +1060,7 @@ void CAL_SetupGrFile (global_game_variables_t *gvar) MM_GetPtr (MEMPTRCONV gvar->ca.grstarts,(NUMCHUNKS+1)*FILEPOSSIZE, gvar); strcpy(fname,GHEADNAME); - strcat(fname,EXTENSION); + strcat(fname,"hp1"); if ((handle = open(fname, O_RDONLY | O_BINARY, S_IREAD)) == -1) @@ -1095,7 +1077,7 @@ void CAL_SetupGrFile (global_game_variables_t *gvar) // Open the graphics file, leaving it open until the game is finished // strcpy(fname,GFILENAME); - strcat(fname,EXTENSION); + strcat(fname,"hp1"); gvar->ca.file.grhandle = open(fname, O_RDONLY | O_BINARY); if (gvar->ca.file.grhandle == -1) @@ -1110,23 +1092,23 @@ void CAL_SetupGrFile (global_game_variables_t *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); + 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(&compseg,gvar); + MM_FreePtr(MEMPTRANDPERCONV compseg,gvar); #endif -#if NUMPICM>0 +#if 0 + //NUMPICM>0 MM_GetPtr(MEMPTRCONV picmtable,NUMPICM*sizeof(pictabletype)); CAL_GetGrChunkLength(STRUCTPICM); // position file pointer 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 +//#if NUMSPRITES>0 MM_GetPtr(MEMPTRCONV spritetable,NUMSPRITES*sizeof(spritetabletype)); CAL_GetGrChunkLength(STRUCTSPRITE); // position file pointer MM_GetPtr(&compseg,gvar->ca.chunkcomplen); @@ -1166,7 +1148,7 @@ void CAL_SetupMapFile (global_game_variables_t *gvar) MM_GetPtr (MEMPTRCONV gvar->ca.tinf,length,gvar); CA_FarRead(handle, gvar->ca.tinf, length,gvar); close(handle); -//#else +#else gvar->ca.tinf = (byte _seg *)FP_SEG(&maphead); @@ -1263,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); @@ -1271,6 +1254,7 @@ void CA_Startup(global_game_variables_t *gvar) unlink("meminfo.16w"); gvar->handle.showmemhandle = open("meminfo.16w", O_CREAT | O_WRONLY | O_TEXT); #endif +#endif #ifndef NOMAPS @@ -1283,7 +1267,7 @@ void CA_Startup(global_game_variables_t *gvar) CAL_SetupMapFile (gvar); #endif - gvar->ca.camap.mapon = -1; + gvar->ca.mapon = -1; gvar->ca.ca_levelbit = 1; gvar->ca.ca_levelnum = 0; @@ -1310,7 +1294,9 @@ 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(gvar->ca.file.grhandle); @@ -1451,7 +1437,6 @@ cachein: //=========================================================================== //????#if GRMODE == EGAGR -#if 0 /* ====================== @@ -1462,12 +1447,12 @@ cachein: = ====================== */ - +/*++++ unsigned static sheight,swidth; boolean static dothemask; void CAL_ShiftSprite (unsigned segment,unsigned source,unsigned dest, - unsigned width, unsigned height, unsigned pixshift, boolean domask) + unsigned width, unsigned height, unsigned pixshift, boolean domask, global_game_variables_t *gvar) { sheight = height; // because we are going to reassign bp @@ -1484,6 +1469,7 @@ void CAL_ShiftSprite (unsigned segment,unsigned source,unsigned dest, mov bp,[pixshift] shl bp,1 mov bp,WORD PTR [shifttabletable+bp] // bp holds pointer to shift table +// mov bp,WORD PTR [gvar->video.shifttabletable+bp] // bp holds pointer to shift table cmp [ss:dothemask],0 je skipmask @@ -1581,7 +1567,7 @@ dodatabyte: } #endif - +*/ //=========================================================================== /* @@ -1594,7 +1580,7 @@ dodatabyte: ====================== */ /*++++ -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]; @@ -1602,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) @@ -1624,12 +1611,12 @@ void CAL_CacheSprite (int chunk, byte far *compressed) #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; @@ -1640,10 +1627,10 @@ 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 @@ -1677,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: @@ -1689,20 +1676,20 @@ 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; @@ -1710,7 +1697,7 @@ void CAL_CacheSprite (int chunk, byte far *compressed) Quit (gvar, "CAL_CacheSprite: Bad shifts number!"); } -#endif +//#endif }*/ //=========================================================================== @@ -1902,7 +1889,7 @@ void CA_CacheGrChunk (int chunk) CAL_ExpandGrChunk (chunk,source); if (compressed>BUFFERSIZE) - MM_FreePtr(&bigbufferseg); + MM_FreePtr (MEMPTRCONV bigbufferseg); } */ @@ -1916,7 +1903,7 @@ void CA_CacheGrChunk (int chunk) = ====================== */ -/*++++ segments! + void CA_CacheMap (global_game_variables_t *gvar) { long pos,compressed; @@ -1933,33 +1920,43 @@ void CA_CacheMap (global_game_variables_t *gvar) // // free up memory from last map // - 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); + 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.camap.mapsegs[plane]) - MM_FreePtr ((memptr)gvar->ca.camap.mapsegs[plane], gvar); + if (gvar->ca.mapsegs[plane]) + MM_FreePtr (MEMPTRCONV gvar->ca.mapsegs[plane], gvar); - gvar->ca.camap.mapon = gvar->ca.camap.mapnum; + gvar->ca.mapon = gvar->ca.mapnum; // // load map header // The header will be cached if it is still around // -// 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!"); + if (!gvar->ca.mapheaderseg[gvar->ca.mapnum]) + { + pos = ((mapfiletype _seg *)gvar->ca.tinf)->headeroffsets[gvar->ca.mapnum]; + if (pos<0) // $FFFFFFFF start is a sparse map + Quit (gvar, "CA_CacheMap: Tried to load a non existent map!"); -// 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)); + 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 (MEMPTRCONV gvar->ca.mapheaderseg[gvar->ca.mapnum], 0, gvar); // // load the planes in @@ -1967,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 = MEMPTRCONV 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 @@ -2000,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); @@ -2011,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); } -}//*/ +} //=========================================================================== @@ -2123,7 +2120,7 @@ void CA_SetGrPurge (global_game_variables_t *gvar) for (i=0;ica.grsegs[i]) - MM_SetPurge (gvar->ca.grsegs[i],3, gvar); + MM_SetPurge (MEMPTRCONV gvar->ca.grsegs[i],3, gvar); } @@ -2151,20 +2148,20 @@ void CA_SetAllPurge (global_game_variables_t *gvar) // // 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;ica.mapheaderseg[i]) + MM_SetPurge (MEMPTRCONV gvar->ca.mapheaderseg[i],3, gvar); for (i=0;i<3;i++) if (gvar->ca.mapsegs[i]) - MM_FreePtr ((memptr *)&gvar->ca.mapsegs[i], gvar); + MM_FreePtr (MEMPTRCONV gvar->ca.mapsegs[i], gvar); // // free sounds // for (i=0;ica.audiosegs[i]) - MM_SetPurge ((memptr *)&gvar->ca.audiosegs[i],3, gvar); + MM_SetPurge (MEMPTRCONV gvar->ca.audiosegs[i],3, gvar); // // free graphics @@ -2295,9 +2292,9 @@ void CAL_DialogFinish (void) = CA_CacheMarks = ====================== -*//*++++ +*/ #define MAXEMPTYREAD 1024 - +/*++++ segments void CAL_CacheMarks (char *title, global_game_variables_t *gvar) { boolean dialog; @@ -2332,8 +2329,8 @@ void CAL_CacheMarks (char *title, global_game_variables_t *gvar) // MDM begin - (GAMERS EDGE) // -// if (!FindFile("EGAGRAPH.16",NULL,2)) -// Quit (gvar, "CA_CacheMarks(): Can't find graphics files."); +//???? if (!FindFile("EGAGRAPH.16",NULL,2)) +//???? Quit (gvar, "CA_CacheMarks(): Can't find graphics files."); // // MDM end @@ -2436,7 +2433,7 @@ void CAL_CacheMarks (char *title, global_game_variables_t *gvar) // if (dialog && finishcachebox) finishcachebox(); -}*/ +}//*/ void CA_CannotOpen(char *string, global_game_variables_t *gvar) {