X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_ca.c;h=e1555f2f4566e11090f186df3242573f09ef3e1d;hb=5d8d1deb6c3520abadbad86d202ea453df77bfc2;hp=bacb7181c155ae93232dfda2c69423aa478553bd;hpb=c4ea89ef8cb104fb6f9f9edd4f4bf55e7984a51f;p=16.git diff --git a/src/lib/16_ca.c b/src/lib/16_ca.c old mode 100644 new mode 100755 index bacb7181..e1555f2f --- a/src/lib/16_ca.c +++ b/src/lib/16_ca.c @@ -30,14 +30,13 @@ loaded into the data segment ============================================================================= */ -#include "ID_HEADS.H" +#include "src/lib/16_ca.h" #pragma hdrstop -#include "ID_STRS.H" #pragma warn -pro #pragma warn -use -#define THREEBYTEGRSTARTS +//#define THREEBYTEGRSTARTS /* ============================================================================= @@ -53,12 +52,12 @@ typedef struct } huffnode; -typedef struct +/*typedef struct { unsigned RLEWtag; long headeroffsets[100]; byte tileinfo[]; -} mapfiletype; +} mapfiletype;*/ /* @@ -69,7 +68,7 @@ typedef struct ============================================================================= */ -byte _seg *tinf; +/*byte _seg *tinf; int mapon; unsigned _seg *mapsegs[3]; @@ -78,9 +77,7 @@ byte _seg *audiosegs[NUMSNDCHUNKS]; void _seg *grsegs[NUMCHUNKS]; byte far grneeded[NUMCHUNKS]; -byte ca_levelbit,ca_levelnum; - -int profilehandle,debughandle; +byte ca_levelbit,ca_levelnum;*/ void (*drawcachebox) (char *title, unsigned numcache); void (*updatecachebox) (void); @@ -94,7 +91,7 @@ void (*finishcachebox) (void); ============================================================================= */ -extern long far CGAhead; +/*extern long far CGAhead; extern long far EGAhead; extern byte CGAdict; extern byte EGAdict; @@ -132,12 +129,11 @@ SDMode oldsoundmode; void CAL_DialogDraw (char *title,unsigned numcache); void CAL_DialogUpdate (void); -void CAL_DialogFinish (void); -void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, - unsigned length); +void CAL_DialogFinish (void);*/ +//void CAL_CarmackExpand (unsigned far *source, unsigned far *dest,unsigned length); -#ifdef THREEBYTEGRSTARTS +/*++++#ifdef THREEBYTEGRSTARTS #define FILEPOSSIZE 3 //#define GRFILEPOS(c) (*(long far *)(((byte far *)grstarts)+(c)*3)&0xffffff) long GRFILEPOS(int c) @@ -159,7 +155,7 @@ long GRFILEPOS(int c) #else #define FILEPOSSIZE 4 #define GRFILEPOS(c) (grstarts[c]) -#endif +#endif*/ /* ============================================================================= @@ -178,16 +174,21 @@ long GRFILEPOS(int c) = ============================ */ - -void CA_OpenDebug (void) +void CA_OpenDebug(global_game_variables_t *gvar) { - unlink ("DEBUG.TXT"); - debughandle = open("DEBUG.TXT", O_CREAT | O_WRONLY | O_TEXT); +#ifdef __BORLANDC__ + unlink("debug.16b"); + gvar->handle.debughandle = open("debug.16b", O_CREAT | O_WRONLY | O_TEXT); +#endif +#ifdef __WATCOMC__ + unlink("debug.16w"); + gvar->handle.debughandle = open("debug.16w", O_CREAT | O_WRONLY | O_TEXT); +#endif } -void CA_CloseDebug (void) +void CA_CloseDebug(global_game_variables_t *gvar) { - close (debughandle); + close(gvar->handle.debughandle); } @@ -202,13 +203,13 @@ void CA_CloseDebug (void) = ============================ */ - +/*++++ void CAL_GetGrChunkLength (int chunk) { lseek(grhandle,GRFILEPOS(chunk),SEEK_SET); read(grhandle,&chunkexplen,sizeof(chunkexplen)); chunkcomplen = GRFILEPOS(chunk+1)-GRFILEPOS(chunk)-4; -} +}*/ /* @@ -221,29 +222,65 @@ void CAL_GetGrChunkLength (int chunk) ========================== */ -boolean CA_FarRead (int handle, byte far *dest, long length) +boolean CA_FarRead(int handle, byte huge *dest, dword length, mminfo_t *mm) { - if (length>0xffffl) - Quit ("CA_FarRead doesn't support 64K reads yet!"); - -asm push ds -asm mov bx,[handle] -asm mov cx,[WORD PTR length] -asm mov dx,[WORD PTR dest] -asm mov ds,[WORD PTR dest+2] -asm mov ah,0x3f // READ w/handle -asm int 21h -asm pop ds -asm jnc good - errno = _AX; - return false; + boolean flag; + //dword fat=0; + //word segm=0; + //if(mm->EMSVer<0x40) + if(length>0xfffflu) + { + printf("File is a fat bakapee\n"); + //segm=(length%0xfffflu)-1; + //fat=segm*0xfffflu; + //length-=fat; +// printf("CA_FarRead doesn't support 64K reads yet!\n"); + return 0;//todo: EXPAND!!! + } + + //if(!fat&&!segm) + //{ + __asm { + push ds + mov bx,[handle] + mov cx,[WORD PTR length] + mov dx,[WORD PTR dest] + mov ds,[WORD PTR dest+2] + mov ah,0x3f // READ w/handle + int 21h + pop ds + jnc good + mov errno,ax + mov flag,0 + jmp End +#ifdef __BORLANDC__ + } +#endif good: -asm cmp ax,[WORD PTR length] -asm je done - errno = EINVFMT; // user manager knows this is bad read - return false; +#ifdef __BORLANDC__ + __asm { +#endif + cmp ax,[WORD PTR length] + je done +// errno = EINVFMT; // user manager knows this is bad read + mov flag,0 + jmp End +#ifdef __BORLANDC__ + } +#endif done: - return true; +#ifdef __BORLANDC__ + __asm { +#endif + mov flag,1 +#ifdef __BORLANDC__ + } +#endif +End: +#ifdef __WATCOMC__ + } +#endif + return flag; } @@ -257,30 +294,65 @@ done: ========================== */ -boolean CA_FarWrite (int handle, byte far *source, long length) +boolean CA_FarWrite(int handle, byte huge *source, dword length, mminfo_t *mm) { - if (length>0xffffl) - Quit ("CA_FarWrite doesn't support 64K reads yet!"); - -asm push ds -asm mov bx,[handle] -asm mov cx,[WORD PTR length] -asm mov dx,[WORD PTR source] -asm mov ds,[WORD PTR source+2] -asm mov ah,0x40 // WRITE w/handle -asm int 21h -asm pop ds -asm jnc good - errno = _AX; - return false; -good: -asm cmp ax,[WORD PTR length] -asm je done - errno = ENOMEM; // user manager knows this is bad write - return false; + boolean flag; + //dword fat=0; + //word segm=0; + //if(mm->EMSVer<0x40) + if(length>0xfffflu) + { + printf("File is a fat bakapee\n"); + //segm=(length%0xfffflu)-1; + //fat=segm*0xfffflu; + //length-=fat; +// printf("CA_FarRead doesn't support 64K reads yet!\n"); + return 0; + } + //if(!fat&&!segm) + //{ + __asm { + push ds + mov bx,[handle] + mov cx,[WORD PTR length] + mov dx,[WORD PTR source] + mov ds,[WORD PTR source+2] + mov ah,0x40 // WRITE w/handle + int 21h + pop ds + jnc good + mov errno,ax + mov flag,0 + jmp End +#ifdef __BORLANDC__ + } +#endif +good: +#ifdef __BORLANDC__ + __asm { +#endif + cmp ax,[WORD PTR length] + je done + //errno = ENOMEM; // user manager knows this is bad write + mov flag,0 + jmp End +#ifdef __BORLANDC__ + } +#endif done: - return true; +#ifdef __BORLANDC__ + __asm { +#endif + mov flag,1 +#ifdef __BORLANDC__ + } +#endif +End: +#ifdef __WATCOMC__ + } +#endif + return flag; } @@ -294,21 +366,22 @@ done: ========================== */ -boolean CA_ReadFile (char *filename, memptr *ptr) +boolean CA_ReadFile(char *filename, memptr *ptr, mminfo_t *mm) { int handle; - long size; + sdword size; + //long size; - if ((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1) + if((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1) return false; - size = filelength (handle); - if (!CA_FarRead (handle,*ptr,size)) + size = filelength(handle); + if(!CA_FarRead(handle,*ptr,size, mm)) { - close (handle); + close(handle); return false; } - close (handle); + close(handle); return true; } @@ -324,22 +397,23 @@ boolean CA_ReadFile (char *filename, memptr *ptr) ========================== */ -boolean CA_LoadFile (char *filename, memptr *ptr) +boolean CA_LoadFile(char *filename, memptr *ptr, mminfo_t *mm, mminfotype *mmi) { int handle; - long size; + sdword size; + //long size; - if ((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1) + if((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1) return false; size = filelength (handle); - MM_GetPtr (ptr,size); - if (!CA_FarRead (handle,*ptr,size)) + MM_GetPtr(ptr,size, mm, mmi); + if(!CA_FarRead(handle,*ptr,size, mm)) { - close (handle); + close(handle); return false; } - close (handle); + close(handle); return true; } @@ -364,7 +438,7 @@ boolean CA_LoadFile (char *filename, memptr *ptr) =============== */ -void CAL_OptimizeNodes (huffnode *table) +void CAL_OptimizeNodes(huffnode *table) { huffnode *node; int i; @@ -393,7 +467,7 @@ void CAL_OptimizeNodes (huffnode *table) ====================== */ -void CAL_HuffExpand (byte huge *source, byte huge *dest, +/*++++void CAL_HuffExpand (byte huge *source, byte huge *dest, long length,huffnode *hufftable) { // unsigned bit,byte,node,code; @@ -427,25 +501,27 @@ void CAL_HuffExpand (byte huge *source, byte huge *dest, // expand less than 64k of data //-------------------------- -asm mov bx,[headptr] + __asm + { + mov bx,[headptr] -asm mov si,[sourceoff] -asm mov di,[destoff] -asm mov es,[destseg] -asm mov ds,[sourceseg] -asm mov ax,[endoff] + mov si,[sourceoff] + mov di,[destoff] + mov es,[destseg] + mov ds,[sourceseg] + mov ax,[endoff] -asm mov ch,[si] // load first byte -asm inc si -asm mov cl,1 + mov ch,[si] // load first byte + inc si + mov cl,1 expandshort: -asm test ch,cl // bit set? -asm jnz bit1short -asm mov dx,[ss:bx] // take bit0 path from node -asm shl cl,1 // advance to next bit position -asm jc newbyteshort -asm jnc sourceupshort + 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 bit1short: asm mov dx,[ss:bx+2] // take bit1 path @@ -470,6 +546,7 @@ asm mov bx,[headptr] // back to the head node for next bit asm cmp di,ax // done? asm jne expandshort + } } else { @@ -480,6 +557,8 @@ asm jne expandshort length--; + __asm + { asm mov bx,[headptr] asm mov cl,1 @@ -534,13 +613,16 @@ 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 + } + } + __asm + { + mov ax,ss + mov ds,ax } -asm mov ax,ss -asm mov ds,ax - -} +}*/ /* @@ -552,7 +634,7 @@ asm mov ds,ax = ====================== */ - +/*++++ #define NEARTAG 0xa7 #define FARTAG 0xa8 @@ -613,7 +695,7 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt } } } - +*/ /* @@ -623,7 +705,7 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt = ====================== */ - +/*++++ long CA_RLEWCompress (unsigned huge *source, long length, unsigned huge *dest, unsigned rlewtag) { @@ -670,7 +752,7 @@ long CA_RLEWCompress (unsigned huge *source, long length, unsigned huge *dest, complength = 2*(dest-start); return complength; } - +*/ /* ====================== @@ -680,7 +762,7 @@ long CA_RLEWCompress (unsigned huge *source, long length, unsigned huge *dest, = ====================== */ - +/*++++ void CA_RLEWexpand (unsigned huge *source, unsigned huge *dest,long length, unsigned rlewtag) { @@ -788,7 +870,7 @@ asm mov ax,ss asm mov ds,ax } - +*/ /* @@ -807,7 +889,7 @@ asm mov ds,ax ====================== */ -void CAL_SetupGrFile (void) +/*void CAL_SetupGrFile (void) { int handle; memptr compseg; @@ -892,7 +974,7 @@ void CAL_SetupGrFile (void) MM_FreePtr(&compseg); #endif -} +}*/ //========================================================================== @@ -905,7 +987,7 @@ void CAL_SetupGrFile (void) ====================== */ -void CAL_SetupMapFile (void) +/*void CAL_SetupMapFile (void) { int handle; long length; @@ -939,7 +1021,7 @@ void CAL_SetupMapFile (void) O_RDONLY | O_BINARY, S_IREAD)) == -1) Quit ("Can't open MAPTEMP."EXT"!"); #endif -} +}*/ //========================================================================== @@ -952,7 +1034,7 @@ void CAL_SetupMapFile (void) ====================== */ -void CAL_SetupAudioFile (void) +/*void CAL_SetupAudioFile (void) { int handle; long length; @@ -986,7 +1068,7 @@ void CAL_SetupAudioFile (void) O_RDONLY | O_BINARY, S_IREAD)) == -1) Quit ("Can't open AUDIO."EXT"!"); #endif -} +}*/ //========================================================================== @@ -1001,22 +1083,30 @@ void CAL_SetupAudioFile (void) ====================== */ -void CA_Startup (void) +void CA_Startup(global_game_variables_t *gvar) { #ifdef PROFILE - unlink ("PROFILE.TXT"); - profilehandle = open("PROFILE.TXT", O_CREAT | O_WRONLY | O_TEXT); +#ifdef __BORLANDC__ + unlink("profile.16b"); + gvar->handle.profilehandle = open("profile.16b", O_CREAT | O_WRONLY | O_TEXT); #endif - +#ifdef __WATCOMC__ + unlink("profile.16w"); + gvar->handle.profilehandle = open("profile.16w", O_CREAT | O_WRONLY | O_TEXT); +#endif +#endif +// unlink("debug0.16"); +// gvar->handle.showmemhandle = open("debug0.16", O_CREAT | O_WRONLY | O_TEXT); +/*++++ // MDM begin - (GAMERS EDGE) // - if (!FindFile("AUDIO."EXT,NULL,2)) + if(!FindFile("AUDIO."EXT,NULL,2)) Quit("CA_Startup(): Can't find audio files."); // // MDM end #ifndef NOAUDIO - CAL_SetupAudioFile (); + CAL_SetupAudioFile(); #endif // MDM begin - (GAMERS EDGE) @@ -1047,7 +1137,7 @@ void CA_Startup (void) drawcachebox = CAL_DialogDraw; updatecachebox = CAL_DialogUpdate; - finishcachebox = CAL_DialogFinish; + finishcachebox = CAL_DialogFinish;*/ } //========================================================================== @@ -1063,15 +1153,16 @@ void CA_Startup (void) ====================== */ -void CA_Shutdown (void) +void CA_Shutdown(global_game_variables_t *gvar) { #ifdef PROFILE - close (profilehandle); + close(gvar->handle.profilehandle); #endif - - close (maphandle); - close (grhandle); - close (audiohandle); +// close(gvar->handle.showmemhandle); +/*++++ + close(maphandle); + close(grhandle); + close(audiohandle);*/ } //=========================================================================== @@ -1083,7 +1174,7 @@ void CA_Shutdown (void) = ====================== */ - +/*++++ void CA_CacheAudioChunk (int chunk) { long pos,compressed; @@ -1151,7 +1242,7 @@ done: if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); #endif -} +}*/ //=========================================================================== @@ -1164,7 +1255,7 @@ done: = ====================== */ - +/*++++ void CA_LoadAllSounds (void) { unsigned start,i; @@ -1203,11 +1294,11 @@ cachein: CA_CacheAudioChunk (start); oldsoundmode = SoundMode; -} +}*/ //=========================================================================== -#if GRMODE == EGAGR +//++++#if GRMODE == EGAGR /* ====================== @@ -1218,7 +1309,7 @@ cachein: = ====================== */ - +/*++++ unsigned static sheight,swidth; boolean static dothemask; @@ -1315,7 +1406,7 @@ asm mov ds,ax } #endif - +*/ //=========================================================================== /* @@ -1327,7 +1418,7 @@ asm mov ds,ax = ====================== */ - +/*++++ void CAL_CacheSprite (int chunk, byte far *compressed) { int i; @@ -1445,7 +1536,7 @@ void CAL_CacheSprite (int chunk, byte far *compressed) } #endif -} +}*/ //=========================================================================== @@ -1459,7 +1550,7 @@ void CAL_CacheSprite (int chunk, byte far *compressed) = ====================== */ - +/*++++ void CAL_ExpandGrChunk (int chunk, byte far *source) { long expanded; @@ -1517,7 +1608,7 @@ void CAL_ExpandGrChunk (int chunk, byte far *source) CAL_HuffExpand (source,grsegs[chunk],expanded,grhuffman); } } - +*/ /* ====================== @@ -1528,7 +1619,7 @@ void CAL_ExpandGrChunk (int chunk, byte far *source) = ====================== */ - +/*++++ void CAL_ReadGrChunk (int chunk) { long pos,compressed; @@ -1572,7 +1663,7 @@ void CAL_ReadGrChunk (int chunk) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } - +*/ /* ====================== = @@ -1582,7 +1673,7 @@ void CAL_ReadGrChunk (int chunk) = ====================== */ - +/*++++ void CA_CacheGrChunk (int chunk) { long pos,compressed; @@ -1638,7 +1729,7 @@ void CA_CacheGrChunk (int chunk) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } - +*/ //========================================================================== @@ -1650,7 +1741,7 @@ void CA_CacheGrChunk (int chunk) = ====================== */ - +/*++++ void CA_CacheMap (int mapnum) { long pos,compressed; @@ -1757,7 +1848,7 @@ void CA_CacheMap (int mapnum) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } -} +}*/ //=========================================================================== @@ -1771,7 +1862,7 @@ void CA_CacheMap (int mapnum) = ====================== */ - +/*++++ void CA_UpLevel (void) { if (ca_levelnum==7) @@ -1779,7 +1870,7 @@ void CA_UpLevel (void) ca_levelbit<<=1; ca_levelnum++; -} +}*/ //=========================================================================== @@ -1793,7 +1884,7 @@ void CA_UpLevel (void) = ====================== */ - +/*++ void CA_DownLevel (void) { if (!ca_levelnum) @@ -1801,7 +1892,7 @@ void CA_DownLevel (void) ca_levelbit>>=1; ca_levelnum--; CA_CacheMarks(NULL); -} +}*/ //=========================================================================== @@ -1814,7 +1905,7 @@ void CA_DownLevel (void) = ====================== */ - +/* void CA_ClearMarks (void) { int i; @@ -1822,7 +1913,7 @@ void CA_ClearMarks (void) for (i=0;i