X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_ca.c;h=f74a5710a4349999c819f619c959e02f890c7f2d;hb=3b3f3b4bc62245426ea4dec22cbfaa7cfbf13645;hp=29df8f63d634516031dd1f9e672a7fe43912f415;hpb=61da0962e85739dc05c35eddb279d400ebbb455f;p=16.git diff --git a/src/lib/16_ca.c b/src/lib/16_ca.c index 29df8f63..f74a5710 100644 --- a/src/lib/16_ca.c +++ b/src/lib/16_ca.c @@ -30,7 +30,7 @@ loaded into the data segment ============================================================================= */ -#include "src/lib/16_head.h" +#include "src/lib/16_ca.h" //#include "ID_STRS.H" //#define THREEBYTEGRSTARTS @@ -74,9 +74,9 @@ byte _seg *audiosegs[NUMSNDCHUNKS]; void _seg *grsegs[NUMCHUNKS]; byte far grneeded[NUMCHUNKS]; -byte ca_levelbit,ca_levelnum; +byte ca_levelbit,ca_levelnum;*/ -int profilehandle,debughandle;*/ +int profilehandle,debughandle; void (*drawcachebox) (char *title, unsigned numcache); void (*updatecachebox) (void); @@ -90,7 +90,7 @@ void (*finishcachebox) (void); ============================================================================= */ -extern long far CGAhead; +/*extern long far CGAhead; extern long far EGAhead; extern byte CGAdict; extern byte EGAdict; @@ -128,12 +128,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) @@ -155,7 +154,7 @@ long GRFILEPOS(int c) #else #define FILEPOSSIZE 4 #define GRFILEPOS(c) (grstarts[c]) -#endif +#endif*/ /* ============================================================================= @@ -174,16 +173,15 @@ long GRFILEPOS(int c) = ============================ */ - -void CA_OpenDebug (void) +void CA_OpenDebug(void) { - unlink ("DEBUG.TXT"); - debughandle = open("DEBUG.TXT", O_CREAT | O_WRONLY | O_TEXT); + unlink("debug.16"); + debughandle = open("debug.16", O_CREAT | O_WRONLY | O_TEXT); } -void CA_CloseDebug (void) +void CA_CloseDebug(void) { - close (debughandle); + close(debughandle); } @@ -198,13 +196,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; -} +}*/ /* @@ -217,29 +215,49 @@ 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) - printf("CA_FarRead doesn't support 64K reads yet!\n"); - -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"); + } + + 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 good: -asm cmp ax,[WORD PTR length] -asm je done - errno = EINVFMT; // user manager knows this is bad read - return false; + cmp ax,[WORD PTR length] + je done +// errno = EINVFMT; // user manager knows this is bad read + mov flag,0 + jmp End done: - return true; + mov flag,1 +End: + } + return flag; + //}else return 0;//todo: EXPAND!!! } @@ -253,30 +271,49 @@ 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; + 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"); + } + + 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 good: -asm cmp ax,[WORD PTR length] -asm je done - errno = ENOMEM; // user manager knows this is bad write - return false; - + cmp ax,[WORD PTR length] + je done + //errno = ENOMEM; // user manager knows this is bad write + mov flag,0 + jmp End done: - return true; + mov flag,1 +End: + } + return flag; + //}else return 0; } @@ -290,21 +327,22 @@ done: ========================== */ -boolean CA_ReadFile (char *filename, memptr *ptr) +boolean CA_ReadFile(char *filename, memptr *ptr, mminfo_t *mm) { int handle; - long size; + dword 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; } @@ -320,22 +358,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; + dword 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; } @@ -389,7 +428,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; @@ -423,25 +462,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 @@ -466,6 +507,7 @@ asm mov bx,[headptr] // back to the head node for next bit asm cmp di,ax // done? asm jne expandshort + } } else { @@ -476,6 +518,8 @@ asm jne expandshort length--; + __asm + { asm mov bx,[headptr] asm mov cl,1 @@ -530,13 +574,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 -asm mov ds,ax + __asm + { + mov ax,ss + mov ds,ax + } -} +}*/ /* @@ -548,7 +595,7 @@ asm mov ds,ax = ====================== */ - +/*++++ #define NEARTAG 0xa7 #define FARTAG 0xa8 @@ -609,7 +656,7 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt } } } - +*/ /* @@ -619,7 +666,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) { @@ -666,7 +713,7 @@ long CA_RLEWCompress (unsigned huge *source, long length, unsigned huge *dest, complength = 2*(dest-start); return complength; } - +*/ /* ====================== @@ -676,7 +723,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) { @@ -784,7 +831,7 @@ asm mov ax,ss asm mov ds,ax } - +*/ /* @@ -803,7 +850,7 @@ asm mov ds,ax ====================== */ -void CAL_SetupGrFile (void) +/*void CAL_SetupGrFile (void) { int handle; memptr compseg; @@ -888,7 +935,7 @@ void CAL_SetupGrFile (void) MM_FreePtr(&compseg); #endif -} +}*/ //========================================================================== @@ -901,7 +948,7 @@ void CAL_SetupGrFile (void) ====================== */ -void CAL_SetupMapFile (void) +/*void CAL_SetupMapFile (void) { int handle; long length; @@ -935,7 +982,7 @@ void CAL_SetupMapFile (void) O_RDONLY | O_BINARY, S_IREAD)) == -1) Quit ("Can't open MAPTEMP."EXT"!"); #endif -} +}*/ //========================================================================== @@ -948,7 +995,7 @@ void CAL_SetupMapFile (void) ====================== */ -void CAL_SetupAudioFile (void) +/*void CAL_SetupAudioFile (void) { int handle; long length; @@ -982,7 +1029,7 @@ void CAL_SetupAudioFile (void) O_RDONLY | O_BINARY, S_IREAD)) == -1) Quit ("Can't open AUDIO."EXT"!"); #endif -} +}*/ //========================================================================== @@ -997,22 +1044,22 @@ void CAL_SetupAudioFile (void) ====================== */ -void CA_Startup (void) +void CA_Startup(void) { #ifdef PROFILE - unlink ("PROFILE.TXT"); - profilehandle = open("PROFILE.TXT", O_CREAT | O_WRONLY | O_TEXT); + unlink("profile.16"); + profilehandle = open("profile.16", O_CREAT | O_WRONLY | O_TEXT); #endif - +/*++++ // 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) @@ -1043,7 +1090,7 @@ void CA_Startup (void) drawcachebox = CAL_DialogDraw; updatecachebox = CAL_DialogUpdate; - finishcachebox = CAL_DialogFinish; + finishcachebox = CAL_DialogFinish;*/ } //========================================================================== @@ -1059,15 +1106,15 @@ void CA_Startup (void) ====================== */ -void CA_Shutdown (void) +void CA_Shutdown(void) { #ifdef PROFILE - close (profilehandle); + close(profilehandle); #endif - - close (maphandle); - close (grhandle); - close (audiohandle); +/*++++ + close(maphandle); + close(grhandle); + close(audiohandle);*/ } //=========================================================================== @@ -1079,7 +1126,7 @@ void CA_Shutdown (void) = ====================== */ - +/*++++ void CA_CacheAudioChunk (int chunk) { long pos,compressed; @@ -1147,7 +1194,7 @@ done: if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); #endif -} +}*/ //=========================================================================== @@ -1160,7 +1207,7 @@ done: = ====================== */ - +/*++++ void CA_LoadAllSounds (void) { unsigned start,i; @@ -1199,11 +1246,11 @@ cachein: CA_CacheAudioChunk (start); oldsoundmode = SoundMode; -} +}*/ //=========================================================================== -#if GRMODE == EGAGR +//++++#if GRMODE == EGAGR /* ====================== @@ -1214,7 +1261,7 @@ cachein: = ====================== */ - +/*++++ unsigned static sheight,swidth; boolean static dothemask; @@ -1311,7 +1358,7 @@ asm mov ds,ax } #endif - +*/ //=========================================================================== /* @@ -1323,7 +1370,7 @@ asm mov ds,ax = ====================== */ - +/*++++ void CAL_CacheSprite (int chunk, byte far *compressed) { int i; @@ -1441,7 +1488,7 @@ void CAL_CacheSprite (int chunk, byte far *compressed) } #endif -} +}*/ //=========================================================================== @@ -1455,7 +1502,7 @@ void CAL_CacheSprite (int chunk, byte far *compressed) = ====================== */ - +/*++++ void CAL_ExpandGrChunk (int chunk, byte far *source) { long expanded; @@ -1513,7 +1560,7 @@ void CAL_ExpandGrChunk (int chunk, byte far *source) CAL_HuffExpand (source,grsegs[chunk],expanded,grhuffman); } } - +*/ /* ====================== @@ -1524,7 +1571,7 @@ void CAL_ExpandGrChunk (int chunk, byte far *source) = ====================== */ - +/*++++ void CAL_ReadGrChunk (int chunk) { long pos,compressed; @@ -1568,7 +1615,7 @@ void CAL_ReadGrChunk (int chunk) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } - +*/ /* ====================== = @@ -1578,7 +1625,7 @@ void CAL_ReadGrChunk (int chunk) = ====================== */ - +/*++++ void CA_CacheGrChunk (int chunk) { long pos,compressed; @@ -1634,7 +1681,7 @@ void CA_CacheGrChunk (int chunk) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } - +*/ //========================================================================== @@ -1646,7 +1693,7 @@ void CA_CacheGrChunk (int chunk) = ====================== */ - +/*++++ void CA_CacheMap (int mapnum) { long pos,compressed; @@ -1753,7 +1800,7 @@ void CA_CacheMap (int mapnum) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } -} +}*/ //=========================================================================== @@ -1767,7 +1814,7 @@ void CA_CacheMap (int mapnum) = ====================== */ - +/*++++ void CA_UpLevel (void) { if (ca_levelnum==7) @@ -1775,7 +1822,7 @@ void CA_UpLevel (void) ca_levelbit<<=1; ca_levelnum++; -} +}*/ //=========================================================================== @@ -1789,7 +1836,7 @@ void CA_UpLevel (void) = ====================== */ - +/*++ void CA_DownLevel (void) { if (!ca_levelnum) @@ -1797,7 +1844,7 @@ void CA_DownLevel (void) ca_levelbit>>=1; ca_levelnum--; CA_CacheMarks(NULL); -} +}*/ //=========================================================================== @@ -1810,7 +1857,7 @@ void CA_DownLevel (void) = ====================== */ - +/* void CA_ClearMarks (void) { int i; @@ -1818,7 +1865,7 @@ void CA_ClearMarks (void) for (i=0;i