X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_ca.c;h=f74a5710a4349999c819f619c959e02f890c7f2d;hb=3b3f3b4bc62245426ea4dec22cbfaa7cfbf13645;hp=c5d983fcfe74663e6f3334317e992dfc21b292f0;hpb=56ee8ef55f51e619a256c01e06643a3055fde39a;p=16.git diff --git a/src/lib/16_ca.c b/src/lib/16_ca.c index c5d983fc..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); @@ -129,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_CarmackExpand (unsigned far *source, unsigned far *dest,unsigned length); -/*#ifdef THREEBYTEGRSTARTS -#define FILEPOSSIZE 3*/ +/*++++#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,35 +215,49 @@ void CAL_GetGrChunkLength (int chunk) ========================== */ -boolean CA_FarRead (int handle, byte far *dest, long length) -{ - union REGS CPURegs; - if (length>0xffffl) - printf("CA_FarRead doesn't support 64K reads yet!\n"); +boolean CA_FarRead(int handle, byte huge *dest, dword length, mminfo_t *mm) +{ + 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"); + } - __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 - } - errno = CPURegs.x.ax; - return false; - __asm - { + 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: - cmp ax,[WORD PTR length] - 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!!! } @@ -259,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; } @@ -296,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; } @@ -326,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; } @@ -395,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; @@ -429,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 @@ -472,6 +507,7 @@ asm mov bx,[headptr] // back to the head node for next bit asm cmp di,ax // done? asm jne expandshort + } } else { @@ -482,6 +518,8 @@ asm jne expandshort length--; + __asm + { asm mov bx,[headptr] asm mov cl,1 @@ -536,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 + } -} +}*/ /* @@ -554,7 +595,7 @@ asm mov ds,ax = ====================== */ - +/*++++ #define NEARTAG 0xa7 #define FARTAG 0xa8 @@ -615,7 +656,7 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt } } } - +*/ /* @@ -625,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) { @@ -672,7 +713,7 @@ long CA_RLEWCompress (unsigned huge *source, long length, unsigned huge *dest, complength = 2*(dest-start); return complength; } - +*/ /* ====================== @@ -682,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) { @@ -790,7 +831,7 @@ asm mov ax,ss asm mov ds,ax } - +*/ /* @@ -809,7 +850,7 @@ asm mov ds,ax ====================== */ -void CAL_SetupGrFile (void) +/*void CAL_SetupGrFile (void) { int handle; memptr compseg; @@ -894,7 +935,7 @@ void CAL_SetupGrFile (void) MM_FreePtr(&compseg); #endif -} +}*/ //========================================================================== @@ -907,7 +948,7 @@ void CAL_SetupGrFile (void) ====================== */ -void CAL_SetupMapFile (void) +/*void CAL_SetupMapFile (void) { int handle; long length; @@ -941,7 +982,7 @@ void CAL_SetupMapFile (void) O_RDONLY | O_BINARY, S_IREAD)) == -1) Quit ("Can't open MAPTEMP."EXT"!"); #endif -} +}*/ //========================================================================== @@ -954,7 +995,7 @@ void CAL_SetupMapFile (void) ====================== */ -void CAL_SetupAudioFile (void) +/*void CAL_SetupAudioFile (void) { int handle; long length; @@ -988,7 +1029,7 @@ void CAL_SetupAudioFile (void) O_RDONLY | O_BINARY, S_IREAD)) == -1) Quit ("Can't open AUDIO."EXT"!"); #endif -} +}*/ //========================================================================== @@ -1003,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) @@ -1049,7 +1090,7 @@ void CA_Startup (void) drawcachebox = CAL_DialogDraw; updatecachebox = CAL_DialogUpdate; - finishcachebox = CAL_DialogFinish; + finishcachebox = CAL_DialogFinish;*/ } //========================================================================== @@ -1065,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);*/ } //=========================================================================== @@ -1085,7 +1126,7 @@ void CA_Shutdown (void) = ====================== */ - +/*++++ void CA_CacheAudioChunk (int chunk) { long pos,compressed; @@ -1153,7 +1194,7 @@ done: if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); #endif -} +}*/ //=========================================================================== @@ -1166,7 +1207,7 @@ done: = ====================== */ - +/*++++ void CA_LoadAllSounds (void) { unsigned start,i; @@ -1205,11 +1246,11 @@ cachein: CA_CacheAudioChunk (start); oldsoundmode = SoundMode; -} +}*/ //=========================================================================== -#if GRMODE == EGAGR +//++++#if GRMODE == EGAGR /* ====================== @@ -1220,7 +1261,7 @@ cachein: = ====================== */ - +/*++++ unsigned static sheight,swidth; boolean static dothemask; @@ -1317,7 +1358,7 @@ asm mov ds,ax } #endif - +*/ //=========================================================================== /* @@ -1329,7 +1370,7 @@ asm mov ds,ax = ====================== */ - +/*++++ void CAL_CacheSprite (int chunk, byte far *compressed) { int i; @@ -1447,7 +1488,7 @@ void CAL_CacheSprite (int chunk, byte far *compressed) } #endif -} +}*/ //=========================================================================== @@ -1461,7 +1502,7 @@ void CAL_CacheSprite (int chunk, byte far *compressed) = ====================== */ - +/*++++ void CAL_ExpandGrChunk (int chunk, byte far *source) { long expanded; @@ -1519,7 +1560,7 @@ void CAL_ExpandGrChunk (int chunk, byte far *source) CAL_HuffExpand (source,grsegs[chunk],expanded,grhuffman); } } - +*/ /* ====================== @@ -1530,7 +1571,7 @@ void CAL_ExpandGrChunk (int chunk, byte far *source) = ====================== */ - +/*++++ void CAL_ReadGrChunk (int chunk) { long pos,compressed; @@ -1574,7 +1615,7 @@ void CAL_ReadGrChunk (int chunk) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } - +*/ /* ====================== = @@ -1584,7 +1625,7 @@ void CAL_ReadGrChunk (int chunk) = ====================== */ - +/*++++ void CA_CacheGrChunk (int chunk) { long pos,compressed; @@ -1640,7 +1681,7 @@ void CA_CacheGrChunk (int chunk) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } - +*/ //========================================================================== @@ -1652,7 +1693,7 @@ void CA_CacheGrChunk (int chunk) = ====================== */ - +/*++++ void CA_CacheMap (int mapnum) { long pos,compressed; @@ -1759,7 +1800,7 @@ void CA_CacheMap (int mapnum) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } -} +}*/ //=========================================================================== @@ -1773,7 +1814,7 @@ void CA_CacheMap (int mapnum) = ====================== */ - +/*++++ void CA_UpLevel (void) { if (ca_levelnum==7) @@ -1781,7 +1822,7 @@ void CA_UpLevel (void) ca_levelbit<<=1; ca_levelnum++; -} +}*/ //=========================================================================== @@ -1795,7 +1836,7 @@ void CA_UpLevel (void) = ====================== */ - +/*++ void CA_DownLevel (void) { if (!ca_levelnum) @@ -1803,7 +1844,7 @@ void CA_DownLevel (void) ca_levelbit>>=1; ca_levelnum--; CA_CacheMarks(NULL); -} +}*/ //=========================================================================== @@ -1816,7 +1857,7 @@ void CA_DownLevel (void) = ====================== */ - +/* void CA_ClearMarks (void) { int i; @@ -1824,7 +1865,7 @@ void CA_ClearMarks (void) for (i=0;i