X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_ca.c;h=ce406dd50ebf6b08b481bc2a209e67e6a6fab370;hb=63a6c9058ef704a718e623a317a7626b509cdfd1;hp=008e4e84cb54949bf0b645a18a4637db04eea567;hpb=181c6beee3d42da41fc53f44f0aa3e9315016ad2;p=16.git
diff --git a/src/lib/16_ca.c b/src/lib/16_ca.c
index 008e4e84..ce406dd5 100755
--- a/src/lib/16_ca.c
+++ b/src/lib/16_ca.c
@@ -1,23 +1,19 @@
-/* Project 16 Source Code~
- * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
+/* Catacomb Apocalypse Source Code
+ * Copyright (C) 1993-2014 Flat Rock Software
*
- * This file is part of Project 16.
- *
- * Project 16 is free software; you can redistribute it and/or modify
+ * This program 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 3 of the License, or
+ * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
- * Project 16 is distributed in the hope that it will be useful,
+ * This program 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, see , or
- * 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
// ID_CA.C
@@ -167,6 +163,8 @@ CASVT GRFILEPOS(int c, global_game_variables_t *gvar)
}
#endif
+#define EXTENSION "hb1"
+
/*
=============================================================================
@@ -235,21 +233,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]
@@ -297,7 +283,7 @@ End:
/*
==========================
=
-= CA_SegWrite
+= CA_FarWrite
=
= Write from a file to a far pointer
=
@@ -307,21 +293,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]
@@ -1049,7 +1023,9 @@ void CAL_SetupGrFile (global_game_variables_t *gvar)
{
char fname[13];
int handle;
+#if NUMPICS>0
memptr compseg;
+#endif
#ifdef GRHEADERLINKED
@@ -1112,23 +1088,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);
@@ -1168,7 +1144,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);
@@ -1184,11 +1160,11 @@ void CAL_SetupMapFile (global_game_variables_t *gvar)
/*#ifdef MAPHEADERLINKED
if ((maphandle = open("GAMEMAPS.16"ENSION,
O_RDONLY | O_BINARY, S_IREAD)) == -1)
- Quit ("Can't open GAMEMAPS.16"ENSION"!");
+ Quit (gvar, "Can't open GAMEMAPS.16"ENSION"!");
#else
if ((maphandle = open("MAPTEMP.16"ENSION,
O_RDONLY | O_BINARY, S_IREAD)) == -1)
- Quit ("Can't open MAPTEMP.16"ENSION"!");
+ Quit (gvar, "Can't open MAPTEMP.16"ENSION"!");
#endif*/
}
@@ -1285,7 +1261,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;
@@ -1453,7 +1429,6 @@ cachein:
//===========================================================================
//????#if GRMODE == EGAGR
-#if 0
/*
======================
@@ -1464,12 +1439,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
@@ -1486,6 +1461,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
@@ -1583,7 +1559,7 @@ dodatabyte:
}
#endif
-
+*/
//===========================================================================
/*
@@ -1596,7 +1572,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];
@@ -1604,11 +1580,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)
@@ -1626,12 +1603,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;
@@ -1642,10 +1619,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
@@ -1679,8 +1656,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:
@@ -1691,20 +1668,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;
@@ -1712,7 +1689,7 @@ void CAL_CacheSprite (int chunk, byte far *compressed)
Quit (gvar, "CAL_CacheSprite: Bad shifts number!");
}
-#endif
+//#endif
}*/
//===========================================================================
@@ -1918,7 +1895,7 @@ void CA_CacheGrChunk (int chunk)
=
======================
*/
-/*++++ segments!
+
void CA_CacheMap (global_game_variables_t *gvar)
{
long pos,compressed;
@@ -1935,33 +1912,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
@@ -1969,30 +1956,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(&bigbufferseg,compressed, gvar);
+ MM_SetLock (&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
@@ -2002,7 +1989,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);
@@ -2013,13 +2000,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(&bigbufferseg, gvar);
}
-}//*/
+}
//===========================================================================
@@ -2153,20 +2140,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
@@ -2297,9 +2284,9 @@ void CAL_DialogFinish (void)
= CA_CacheMarks
=
======================
-*//*++++
+*/
#define MAXEMPTYREAD 1024
-
+/*++++ segments
void CAL_CacheMarks (char *title, global_game_variables_t *gvar)
{
boolean dialog;
@@ -2334,8 +2321,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
@@ -2438,7 +2425,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)
{