X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_ca.c;h=7298ca3f6639ae93daa497da0a3419d8dbe68b25;hb=8e974b9ed72a1521714ea3cf96a9b87c68db8025;hp=6511ef176ab649739d61e14ed50b1645c4c27108;hpb=2f9b9da25eb21b1945419758cff38824ed63e49b;p=16.git diff --git a/src/lib/16_ca.c b/src/lib/16_ca.c index 6511ef17..7298ca3f 100755 --- a/src/lib/16_ca.c +++ b/src/lib/16_ca.c @@ -46,10 +46,10 @@ loaded into the data segment ============================================================================= */ -typedef struct +/*typedef struct { word bit0,bit1; // 0-255 is a character, > is a pointer to a node -} huffnode; +} huffnode;*/ /*typedef struct @@ -221,12 +221,12 @@ void CAL_GetGrChunkLength (int chunk) ========================== */ -boolean CA_FarRead(int handle, byte huge *dest, dword length, mminfo_t *mm) +boolean CA_FarRead(int handle, byte huge *dest, dword length, global_game_variables_t *gvar) { - boolean flag; + boolean flag=0; //dword fat=0; //word segm=0; - if(mm->EMSVer<0x40) + if(gvar->pm.emm.EMSVer<0x40) if(length>0xfffflu) { printf("File is a fat bakapee\n"); @@ -239,45 +239,45 @@ boolean CA_FarRead(int handle, byte huge *dest, dword length, mminfo_t *mm) //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 + __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: #ifdef __BORLANDC__ - __asm { + __asm { #endif - cmp ax,[WORD PTR length] - je done -// errno = EINVFMT; // user manager knows this is bad read - mov flag,0 - jmp End + 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: #ifdef __BORLANDC__ - __asm { + __asm { #endif - mov flag,1 + mov flag,1 #ifdef __BORLANDC__ - } + } #endif End: #ifdef __WATCOMC__ - } + } #endif return flag; } @@ -293,12 +293,12 @@ End: ========================== */ -boolean CA_FarWrite(int handle, byte huge *source, dword length, mminfo_t *mm) +boolean CA_FarWrite(int handle, byte huge *source, dword length, global_game_variables_t *gvar) { - boolean flag; + boolean flag=0; //dword fat=0; //word segm=0; - if(mm->EMSVer<0x40) + if(gvar->pm.emm.EMSVer<0x40) if(length>0xfffflu) { printf("File is a fat bakapee\n"); @@ -311,45 +311,45 @@ boolean CA_FarWrite(int handle, byte huge *source, dword length, mminfo_t *mm) //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 + __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 { + __asm { #endif - cmp ax,[WORD PTR length] - je done - //errno = ENOMEM; // user manager knows this is bad write - mov flag,0 - jmp End + 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: #ifdef __BORLANDC__ - __asm { + __asm { #endif - mov flag,1 + mov flag,1 #ifdef __BORLANDC__ - } + } #endif End: #ifdef __WATCOMC__ - } + } #endif return flag; } @@ -365,7 +365,7 @@ End: ========================== */ -boolean CA_ReadFile(char *filename, memptr *ptr, mminfo_t *mm) +boolean CA_ReadFile(char *filename, memptr *ptr, global_game_variables_t *gvar) { int handle; sdword size; @@ -375,7 +375,7 @@ boolean CA_ReadFile(char *filename, memptr *ptr, mminfo_t *mm) return false; size = filelength(handle); - if(!CA_FarRead(handle,*ptr,size, mm)) + if(!CA_FarRead(handle,*ptr,size, gvar)) { close (handle); return false; @@ -395,10 +395,10 @@ boolean CA_ReadFile(char *filename, memptr *ptr, mminfo_t *mm) ========================== */ -boolean CA_WriteFile (char *filename, void far *ptr, long length, mminfo_t *mm) +boolean CA_WriteFile (char *filename, void far *ptr, long length, global_game_variables_t *gvar) { int handle; - sdword size; + //sdword size; //long size; handle = open(filename,O_CREAT | O_BINARY | O_WRONLY, @@ -407,7 +407,7 @@ boolean CA_WriteFile (char *filename, void far *ptr, long length, mminfo_t *mm) if (handle == -1) return false; - if (!CA_FarWrite (handle,ptr,length, mm)) + if (!CA_FarWrite (handle,ptr,length, gvar)) { close(handle); return false; @@ -428,7 +428,7 @@ boolean CA_WriteFile (char *filename, void far *ptr, long length, mminfo_t *mm) ========================== */ -boolean CA_LoadFile(char *filename, memptr *ptr, mminfo_t *mm, mminfotype *mmi) +boolean CA_LoadFile(char *filename, memptr *ptr, global_game_variables_t *gvar) { int handle; sdword size; @@ -437,9 +437,9 @@ boolean CA_LoadFile(char *filename, memptr *ptr, mminfo_t *mm, mminfotype *mmi) if((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1) return false; - size = filelength (handle); - MM_GetPtr(ptr,size, mm, mmi); - if(!CA_FarRead(handle,*ptr,size, mm)) + size = filelength(handle); + MM_GetPtr(ptr,size, gvar); + if(!CA_FarRead(handle,*ptr,size, gvar)) { close(handle); return false; @@ -503,10 +503,10 @@ void CAL_HuffExpand (byte huge *source, byte huge *dest, { // unsigned bit,byte,node,code; unsigned sourceseg,sourceoff,destseg,destoff,endoff; - huffnode *headptr; + huffnode *headptr; // huffnode *nodeon; - headptr = hufftable+254; // head node is allways node 254 + headptr = hufftable+254; // head node is allways node 254 source++; // normalize source--; @@ -533,7 +533,7 @@ void CAL_HuffExpand (byte huge *source, byte huge *dest, //-------------------------- __asm { -//// mov bx,[headptr] + mov bx,[word ptr headptr] mov si,[sourceoff] mov di,[destoff] @@ -597,7 +597,7 @@ storebyteshort: #endif mov [es:di],dl inc di // write a decopmpressed byte out -//// mov bx,[headptr] // back to the head node for next bit + mov bx,[word ptr headptr] // back to the head node for next bit cmp di,ax // done? jne expandshort @@ -613,7 +613,7 @@ storebyteshort: length--; __asm { -//// mov bx,[headptr] + mov bx,[word ptr headptr] mov cl,1 mov si,[sourceoff] @@ -685,7 +685,7 @@ storebyte: #endif mov [es:di],dl inc di // write a decopmpressed byte out -//// mov bx,[headptr] // back to the head node for next bit + mov bx,[word ptr headptr] // back to the head node for next bit cmp di,0x10 // normalize es:di jb dinorm @@ -724,7 +724,7 @@ dinorm: = ====================== */ -/*++++ + #define NEARTAG 0xa7 #define FARTAG 0xa8 @@ -747,13 +747,13 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt count = ch&0xff; if (!count) { // have to insert a word containing the tag byte - ch |= *((unsigned char far *)inptr)++; + ch |= *(/*(unsigned char far *)*/inptr)++; *outptr++ = ch; length--; } else { - offset = *((unsigned char far *)inptr)++; + offset = *(/*(unsigned char far *)*/inptr)++; copyptr = outptr - offset; length -= count; while (count--) @@ -765,7 +765,7 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt count = ch&0xff; if (!count) { // have to insert a word containing the tag byte - ch |= *((unsigned char far *)inptr)++; + ch |= *(/*(unsigned char far *)*/inptr)++; *outptr++ = ch; length --; } @@ -785,7 +785,6 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt } } } -*/ /* @@ -795,7 +794,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) { @@ -842,7 +841,7 @@ long CA_RLEWCompress (unsigned huge *source, long length, unsigned huge *dest, complength = 2*(dest-start); return complength; } -*/ + /* ====================== @@ -852,7 +851,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) { @@ -903,64 +902,88 @@ void CA_RLEWexpand (unsigned huge *source, unsigned huge *dest,long length, // // NOTE: A repeat count that produces 0xfff0 bytes can blow this! // - -asm mov bx,rlewtag -asm mov si,sourceoff -asm mov di,destoff -asm mov es,destseg -asm mov ds,sourceseg - + __asm { + mov bx,rlewtag + mov si,sourceoff + mov di,destoff + mov es,destseg + mov ds,sourceseg +#ifdef __BORLANDC__ + } +#endif expand: -asm lodsw -asm cmp ax,bx -asm je repeat -asm stosw -asm jmp next - +#ifdef __BORLANDC__ + __asm { +#endif + lodsw + cmp ax,bx + je repeat + stosw + jmp next +#ifdef __BORLANDC__ + } +#endif repeat: -asm lodsw -asm mov cx,ax // repeat count -asm lodsw // repeat value -asm rep stosw - +#ifdef __BORLANDC__ + __asm { +#endif + lodsw + mov cx,ax // repeat count + lodsw // repeat value + rep stosw +#ifdef __BORLANDC__ + } +#endif next: - -asm cmp si,0x10 // normalize ds:si -asm jb sinorm -asm mov ax,si -asm shr ax,1 -asm shr ax,1 -asm shr ax,1 -asm shr ax,1 -asm mov dx,ds -asm add dx,ax -asm mov ds,dx -asm and si,0xf +#ifdef __BORLANDC__ + __asm { +#endif + cmp si,0x10 // normalize ds:si + jb sinorm + mov ax,si + shr ax,1 + shr ax,1 + shr ax,1 + shr ax,1 + mov dx,ds + add dx,ax + mov ds,dx + and si,0xf +#ifdef __BORLANDC__ + } +#endif sinorm: -asm cmp di,0x10 // normalize es:di -asm jb dinorm -asm mov ax,di -asm shr ax,1 -asm shr ax,1 -asm shr ax,1 -asm shr ax,1 -asm mov dx,es -asm add dx,ax -asm mov es,dx -asm and di,0xf +#ifdef __BORLANDC__ + __asm { +#endif + cmp di,0x10 // normalize es:di + jb dinorm + mov ax,di + shr ax,1 + shr ax,1 + shr ax,1 + shr ax,1 + mov dx,es + add dx,ax + mov es,dx + and di,0xf +#ifdef __BORLANDC__ + } +#endif dinorm: +#ifdef __BORLANDC__ + __asm { +#endif + cmp di,ss:endoff + jne expand + mov ax,es + cmp ax,ss:endseg + jb expand -asm cmp di,ss:endoff -asm jne expand -asm mov ax,es -asm cmp ax,ss:endseg -asm jb expand - -asm mov ax,ss -asm mov ds,ax - + mov ax,ss + mov ds,ax + } } -*/ /* @@ -1079,8 +1102,8 @@ asm mov ds,ax void CAL_SetupMapFile (global_game_variables_t *gvar) { - int handle; - long length; +// int handle; +// long length; // // load maphead.ext (offsets and tileinfo for map file) @@ -1088,7 +1111,7 @@ void CAL_SetupMapFile (global_game_variables_t *gvar) // #ifndef MAPHEADERLINKED // if ((handle = open("MAPHEAD."EXT, // O_RDONLY | O_BINARY, S_IREAD)) == -1) -// Quit ("Can't open MAPHEAD."EXT"!"); +// printf("Can't open MAPHEAD."EXT"!"); // length = filelength(handle); // MM_GetPtr (&(memptr)tinf,length); // CA_FarRead(handle, tinf, length); @@ -1203,10 +1226,9 @@ void CA_Startup(global_game_variables_t *gvar) /* CAL_SetupGrFile (); CAL_SetupAudioFile ();*/ - CAL_SetupMapFile (gvar); - gvar->ca.mapon = -1; + gvar->ca.camap.mapon = -1; gvar->ca.ca_levelbit = 1; gvar->ca.ca_levelnum = 0; @@ -1817,7 +1839,7 @@ void CA_CacheGrChunk (int chunk) = ====================== */ -/*++++ fuckin segments! +/*++++ segments! void CA_CacheMap (global_game_variables_t *gvar) { long pos,compressed; @@ -1834,11 +1856,11 @@ void CA_CacheMap (global_game_variables_t *gvar) // // free up memory from last map // -// if (gvar->ca.map.mapon>-1 && gvar->ca.map.mapheaderseg[gvar->ca.map.mapon]) -// MM_SetPurge (&(memptr)gvar->ca.map.mapheaderseg[gvar-ca.map.mapon],3); + if (gvar->ca.map.mapon>-1 && gvar->ca.map.mapheaderseg[gvar->ca.map.mapon]) + MM_SetPurge (&((memptr)gvar->ca.map.mapheaderseg[(gvar->ca.map.mapon)]), 3, &(gvar->mm)); for (plane=0;planeca.map.mapsegs[plane]) - MM_FreePtr (&(memptr)gvar->ca.map.mapsegs[plane]); + MM_FreePtr (&(memptr)gvar->ca.map.mapsegs[plane], &(gvar->mm)); gvar->ca.map.mapon = gvar->ca.map.mapnum; @@ -1849,7 +1871,8 @@ void CA_CacheMap (global_game_variables_t *gvar) // if (!gvar->ca.map.mapheaderseg[gvar->ca.map.mapnum]) { - pos = ((__segmement *)tinf)->headeroffsets[gvar->ca.mapnum]; + //pos = ((mapfiletype _seg *)tinf)->headeroffsets[mapnum]; + pos = ((_seg *)gvar->ca.map.tinf)->headeroffsets[gvar->ca.map.mapnum]; if (pos<0) // $FFFFFFFF start is a sparse map printf("CA_CacheMap: Tried to load a non existent map!"); @@ -1858,7 +1881,7 @@ void CA_CacheMap (global_game_variables_t *gvar) CA_FarRead (maphandle,(memptr)mapheaderseg[mapnum],sizeof(maptype)); } else - MM_SetPurge (&(memptr)mapheaderseg[mapnum],0); + MM_SetPurge (&(memptr)mapheaderseg[mapnum], 0, &(gvar->mm)); // // load the planes in @@ -1916,7 +1939,7 @@ void CA_CacheMap (global_game_variables_t *gvar) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } -}*/ +}//*/ //=========================================================================== @@ -1930,15 +1953,15 @@ void CA_CacheMap (global_game_variables_t *gvar) = ====================== */ -/*++++ -void CA_UpLevel (void) + +void CA_UpLevel (global_game_variables_t *gvar) { - if (ca_levelnum==7) - Quit ("CA_UpLevel: Up past level 7!"); + if (gvar->ca.ca_levelnum==7) + printf("CA_UpLevel: Up past level 7!"); - ca_levelbit<<=1; - ca_levelnum++; -}*/ + gvar->ca.ca_levelbit<<=1; + gvar->ca.ca_levelnum++; +} //=========================================================================== @@ -1952,15 +1975,15 @@ void CA_UpLevel (void) = ====================== */ -/*++ -void CA_DownLevel (void) + +void CA_DownLevel (global_game_variables_t *gvar) { - if (!ca_levelnum) - Quit ("CA_DownLevel: Down past level 0!"); - ca_levelbit>>=1; - ca_levelnum--; - CA_CacheMarks(NULL); -}*/ + if (!gvar->ca.ca_levelnum) + printf("CA_DownLevel: Down past level 0!"); + gvar->ca.ca_levelbit>>=1; + gvar->ca.ca_levelnum--; + ////++++++++++++++++++++++++++++++++++++++++++CA_CacheMarks(NULL); +} //=========================================================================== @@ -2045,7 +2068,7 @@ void CA_SetAllPurge (void) // // free cursor sprite and background save // - VW_FreeCursor (); + //VW_FreeCursor (); // // free map headers and map planes