X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_ca.c;h=e2803808a47389d6202f2f870c3dfbea4fb445d6;hb=f140a355c36fae1da7e962c9828983e1fa131ad1;hp=35c225102fb1fa6e9265856982d57fc1712ce75a;hpb=97b313e6e26b3fe91b40cb523a84a54dc430f704;p=16.git diff --git a/src/lib/16_ca.c b/src/lib/16_ca.c index 35c22510..e2803808 100755 --- a/src/lib/16_ca.c +++ b/src/lib/16_ca.c @@ -37,7 +37,7 @@ loaded into the data segment #pragma warn -use //#define THREEBYTEGRSTARTS - +//https://github.com/open-watcom/open-watcom-v2/issues/279#issuecomment-244587566 for _seg /* ============================================================================= @@ -48,8 +48,8 @@ loaded into the data segment /*typedef struct { - unsigned bit0,bit1; // 0-255 is a character, > is a pointer to a node -} huffnode;*/ //moved to src/lib/typdefst.h + word bit0,bit1; // 0-255 is a character, > is a pointer to a node +} 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; //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"); @@ -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; //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"); @@ -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,7 +395,7 @@ 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; @@ -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; @@ -498,7 +498,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; @@ -532,9 +532,8 @@ void CAL_OptimizeNodes(huffnode *table) // expand less than 64k of data //-------------------------- - __asm - { - mov bx,[headptr] + __asm { +//// mov bx,[headptr] mov si,[sourceoff] mov di,[destoff] @@ -545,38 +544,63 @@ void CAL_OptimizeNodes(huffnode *table) mov ch,[si] // load first byte inc si mov cl,1 - +#ifdef __BORLANDC__ + } +#endif expandshort: +#ifdef __BORLANDC__ + __asm { +#endif 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 - +#ifdef __BORLANDC__ + } +#endif bit1short: -asm mov dx,[ss:bx+2] // take bit1 path -asm shl cl,1 // advance to next bit position -asm jnc sourceupshort - +#ifdef __BORLANDC__ + __asm { +#endif + mov dx,[ss:bx+2] // take bit1 path + shl cl,1 // advance to next bit position + jnc sourceupshort +#ifdef __BORLANDC__ + } +#endif newbyteshort: -asm mov ch,[si] // load next byte -asm inc si -asm mov cl,1 // back to first bit - +#ifdef __BORLANDC__ + __asm { +#endif + mov ch,[si] // load next byte + inc si + mov cl,1 // back to first bit +#ifdef __BORLANDC__ + } +#endif sourceupshort: -asm or dh,dh // if dx<256 its a byte, else move node -asm jz storebyteshort -asm mov bx,dx // next node = (huffnode *)code -asm jmp expandshort - +#ifdef __BORLANDC__ + __asm { +#endif + or dh,dh // if dx<256 its a byte, else move node + jz storebyteshort + mov bx,dx // next node = (huffnode *)code + jmp expandshort +#ifdef __BORLANDC__ + } +#endif storebyteshort: -asm mov [es:di],dl -asm inc di // write a decopmpressed byte out -asm mov bx,[headptr] // back to the head node for next bit +#ifdef __BORLANDC__ + __asm { +#endif + mov [es:di],dl + inc di // write a decopmpressed byte out +//// mov bx,[headptr] // back to the head node for next bit -asm cmp di,ax // done? - jne expandshort + cmp di,ax // done? + jne expandshort } } else @@ -588,72 +612,107 @@ asm cmp di,ax // done? length--; - __asm - { - mov bx,[headptr] - mov cl,1 - - mov si,[sourceoff] - mov di,[destoff] - mov es,[destseg] - mov ds,[sourceseg] + __asm { +//// mov bx,[headptr] + mov cl,1 - lodsb // load first byte + mov si,[sourceoff] + mov di,[destoff] + mov es,[destseg] + mov ds,[sourceseg] + lodsb // load first byte +#ifdef __BORLANDC__ + } +#endif expand: - test al,cl // bit set? - jnz bit1 - mov dx,[ss:bx] // take bit0 path from node - jmp gotcode +#ifdef __BORLANDC__ + __asm { +#endif + test al,cl // bit set? + jnz bit1 + mov dx,[ss:bx] // take bit0 path from node + jmp gotcode +#ifdef __BORLANDC__ + } +#endif bit1: - mov dx,[ss:bx+2] // take bit1 path - +#ifdef __BORLANDC__ + __asm { +#endif + mov dx,[ss:bx+2] // take bit1 path +#ifdef __BORLANDC__ + } +#endif gotcode: - shl cl,1 // advance to next bit position - jnc sourceup - lodsb - cmp si,0x10 // normalize ds:si -asm jb sinorm - mov cx,ds - inc cx - mov ds,cx - xor si,si +#ifdef __BORLANDC__ + __asm { +#endif + shl cl,1 // advance to next bit position + jnc sourceup + lodsb + cmp si,0x10 // normalize ds:si + jb sinorm + mov cx,ds + inc cx + mov ds,cx + xor si,si +#ifdef __BORLANDC__ + } +#endif sinorm: - mov cl,1 // back to first bit - +#ifdef __BORLANDC__ + __asm { +#endif + mov cl,1 // back to first bit +#ifdef __BORLANDC__ + } +#endif sourceup: - or dh,dh // if dx<256 its a byte, else move node - jz storebyte - mov bx,dx // next node = (huffnode *)code - jmp expand - +#ifdef __BORLANDC__ + __asm { +#endif + or dh,dh // if dx<256 its a byte, else move node + jz storebyte + mov bx,dx // next node = (huffnode *)code + jmp expand +#ifdef __BORLANDC__ + } +#endif storebyte: - mov [es:di],dl - inc di // write a decopmpressed byte out - mov bx,[headptr] // back to the head node for next bit - - cmp di,0x10 // normalize es:di -asm jb dinorm - mov dx,es - inc dx - mov es,dx - xor di,di +#ifdef __BORLANDC__ + __asm { +#endif + mov [es:di],dl + inc di // write a decopmpressed byte out +//// mov bx,[headptr] // back to the head node for next bit + + cmp di,0x10 // normalize es:di + jb dinorm + mov dx,es + inc dx + mov es,dx + xor di,di +#ifdef __BORLANDC__ + } +#endif dinorm: - - sub [WORD PTR ss:length],1 - jnc expand - dec [WORD PTR ss:length+2] +#ifdef __BORLANDC__ + __asm { +#endif + sub [WORD PTR ss:length],1 + jnc expand + dec [WORD PTR ss:length+2] jns expand // when length = ffff ffff, done } } - __asm - { + __asm { mov ax,ss mov ds,ax } -}*/ +} /* @@ -665,7 +724,7 @@ dinorm: = ====================== */ -/*++++ + #define NEARTAG 0xa7 #define FARTAG 0xa8 @@ -688,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--) @@ -706,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 --; } @@ -726,7 +785,6 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt } } } -*/ /* @@ -736,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) { @@ -783,7 +841,7 @@ long CA_RLEWCompress (unsigned huge *source, long length, unsigned huge *dest, complength = 2*(dest-start); return complength; } -*/ + /* ====================== @@ -793,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) { @@ -844,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 + } } -*/ /* @@ -1018,7 +1100,7 @@ asm mov ds,ax ====================== */ -/*void CAL_SetupMapFile (void) +void CAL_SetupMapFile (global_game_variables_t *gvar) { int handle; long length; @@ -1026,33 +1108,39 @@ asm mov ds,ax // // load maphead.ext (offsets and tileinfo for map file) // -#ifndef MAPHEADERLINKED - if ((handle = open("MAPHEAD."EXT, - O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open MAPHEAD."EXT"!"); - length = filelength(handle); - MM_GetPtr (&(memptr)tinf,length); - CA_FarRead(handle, tinf, length); - close(handle); -#else - - tinf = (byte _seg *)FP_SEG(&maphead); - -#endif +// #ifndef MAPHEADERLINKED +// if ((handle = open("MAPHEAD."EXT, +// O_RDONLY | O_BINARY, S_IREAD)) == -1) +// printf("Can't open MAPHEAD."EXT"!"); +// length = filelength(handle); +// MM_GetPtr (&(memptr)tinf,length); +// CA_FarRead(handle, tinf, length); +// close(handle); +// //#else +// +// tinf = (byte _seg *)FP_SEG(&maphead); +// +// #endif // // open the data file // -#ifdef MAPHEADERLINKED - if ((maphandle = open("GAMEMAPS."EXT, - O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open GAMEMAPS."EXT"!"); -#else - if ((maphandle = open("MAPTEMP."EXT, +//TODO: multiple files + if ((gvar->ca.file.maphandle[0] = open("data/test.map", O_RDONLY | O_BINARY, S_IREAD)) == -1) - Quit ("Can't open MAPTEMP."EXT"!"); -#endif -}*/ + { + printf("Can't open data/test.map!"); + } +// #ifdef MAPHEADERLINKED +// if ((maphandle = open("GAMEMAPS."EXT, +// O_RDONLY | O_BINARY, S_IREAD)) == -1) +// Quit ("Can't open GAMEMAPS."EXT"!"); +// //#else +// if ((maphandle = open("MAPTEMP."EXT, +// O_RDONLY | O_BINARY, S_IREAD)) == -1) +// Quit ("Can't open MAPTEMP."EXT"!"); +// #endif +} //========================================================================== @@ -1125,48 +1213,26 @@ void CA_Startup(global_game_variables_t *gvar) 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)) - Quit("CA_Startup(): Can't find audio files."); -// -// MDM end +#endif//profile -#ifndef NOAUDIO - CAL_SetupAudioFile(); +#ifdef __BORLANDC__ + unlink("meminfo.16b"); + gvar->handle.showmemhandle = open("meminfo.16b", O_CREAT | O_WRONLY | O_TEXT); #endif - -// MDM begin - (GAMERS EDGE) -// - if (!FindFile("GAMEMAPS."EXT,NULL,1)) - Quit("CA_Startup(): Can't find level files."); -// -// MDM end - -#ifndef NOMAPS - CAL_SetupMapFile (); +#ifdef __WATCOMC__ + unlink("meminfo.16w"); + gvar->handle.showmemhandle = open("meminfo.16w", O_CREAT | O_WRONLY | O_TEXT); #endif - -// MDM begin - (GAMERS EDGE) -// - if (!FindFile("EGAGRAPH."EXT,NULL,2)) - Quit("CA_Startup(): Can't find graphics files."); -// -// MDM end - -#ifndef NOGRAPHICS +/* CAL_SetupGrFile (); -#endif + CAL_SetupAudioFile ();*/ + CAL_SetupMapFile (gvar); - mapon = -1; - ca_levelbit = 1; - ca_levelnum = 0; + gvar->ca.camap.mapon = -1; + gvar->ca.ca_levelbit = 1; + gvar->ca.ca_levelnum = 0; - drawcachebox = CAL_DialogDraw; +/* drawcachebox = CAL_DialogDraw; updatecachebox = CAL_DialogUpdate; finishcachebox = CAL_DialogFinish;*/ } @@ -1189,9 +1255,10 @@ void CA_Shutdown(global_game_variables_t *gvar) #ifdef PROFILE close(gvar->handle.profilehandle); #endif -// close(gvar->handle.showmemhandle); + close(gvar->handle.showmemhandle); + + close(*(gvar->ca.file.maphandle)); /*++++ - close(maphandle); close(grhandle); close(audiohandle);*/ } @@ -1772,8 +1839,8 @@ void CA_CacheGrChunk (int chunk) = ====================== */ -/*++++ -void CA_CacheMap (int mapnum) +/*++++ segments! +void CA_CacheMap (global_game_variables_t *gvar) { long pos,compressed; int plane; @@ -1786,42 +1853,35 @@ void CA_CacheMap (int mapnum) #endif -// MDM begin - (GAMERS EDGE) -// - if (!FindFile("GAMEMAPS."EXT,NULL,1)) - Quit("CA_CacheMap(): Can't find level files."); -// -// MDM end - - // // free up memory from last map // - if (mapon>-1 && mapheaderseg[mapon]) - MM_SetPurge (&(memptr)mapheaderseg[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], &(gvar->mm)); - mapon = mapnum; + gvar->ca.map.mapon = gvar->ca.map.mapnum; // // load map header // The header will be cached if it is still around // - if (!mapheaderseg[mapnum]) + if (!gvar->ca.map.mapheaderseg[gvar->ca.map.mapnum]) { - pos = ((mapfiletype _seg *)tinf)->headeroffsets[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 - Quit ("CA_CacheMap: Tried to load a non existent map!"); + printf("CA_CacheMap: Tried to load a non existent map!"); - MM_GetPtr(&(memptr)mapheaderseg[mapnum],sizeof(maptype)); + MM_GetPtr(&(memptr)gvar->ca.mapheaderseg[mapnum],sizeof(maptype)); lseek(maphandle,pos,SEEK_SET); 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 @@ -1879,7 +1939,7 @@ void CA_CacheMap (int mapnum) if (compressed>BUFFERSIZE) MM_FreePtr(&bigbufferseg); } -}*/ +}//*/ //=========================================================================== @@ -1893,15 +1953,15 @@ void CA_CacheMap (int mapnum) = ====================== */ -/*++++ -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++; +} //=========================================================================== @@ -1915,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); +} //=========================================================================== @@ -2008,7 +2068,7 @@ void CA_SetAllPurge (void) // // free cursor sprite and background save // - VW_FreeCursor (); + //VW_FreeCursor (); // // free map headers and map planes @@ -2031,20 +2091,7 @@ void CA_SetAllPurge (void) // // free graphics // - CA_FreeGraphics (); -} - - -void CA_SetGrPurge (void) -{ - int i; - -// -// free graphics -// - for (i=0;i