X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_ca.c;h=96bb4b4849b5d215497c000733bdae8feb2bb465;hb=e24f44d22bf10e9d0d8da54d469cd19eb460b8a1;hp=7eb30d8763baf8254a65f84514baeeb0bdbed3f1;hpb=ea5bcfc4dfd9567bcb6c13aca55680da7873c758;p=16.git diff --git a/src/lib/16_ca.c b/src/lib/16_ca.c index 7eb30d87..96bb4b48 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,7 +48,7 @@ loaded into the data segment typedef struct { - unsigned bit0,bit1; // 0-255 is a character, > is a pointer to a node + word bit0,bit1; // 0-255 is a character, > is a pointer to a node } huffnode; @@ -76,8 +76,7 @@ maptype _seg *mapheaderseg[NUMMAPS]; byte _seg *audiosegs[NUMSNDCHUNKS]; void _seg *grsegs[NUMCHUNKS]; -byte far grneeded[NUMCHUNKS]; -byte ca_levelbit,ca_levelnum;*/ +byte far grneeded[NUMCHUNKS];*/ void (*drawcachebox) (char *title, unsigned numcache); void (*updatecachebox) (void); @@ -227,14 +226,14 @@ 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(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"); + printf("CA_FarRead doesn't support 64K reads yet!\n"); return 0;//TODO: EXPAND!!! } @@ -299,14 +298,14 @@ boolean CA_FarWrite(int handle, byte huge *source, dword length, mminfo_t *mm) boolean flag; //dword fat=0; //word segm=0; - //if(mm->EMSVer<0x40) + 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"); + printf("CA_FarRead doesn't support 64K reads yet!\n"); return 0; } @@ -377,6 +376,38 @@ boolean CA_ReadFile(char *filename, memptr *ptr, mminfo_t *mm) size = filelength(handle); if(!CA_FarRead(handle,*ptr,size, mm)) + { + close (handle); + return false; + } + close (handle); + return true; +} + + +/* +========================== += += CA_WriteFile += += Writes a file from a memory buffer += +========================== +*/ + +boolean CA_WriteFile (char *filename, void far *ptr, long length, mminfo_t *mm) +{ + int handle; + sdword size; + //long size; + + handle = open(filename,O_CREAT | O_BINARY | O_WRONLY, + S_IREAD | S_IWRITE | S_IFREG); + + if (handle == -1) + return false; + + if (!CA_FarWrite (handle,ptr,length, mm)) { close(handle); return false; @@ -467,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; @@ -501,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] @@ -514,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? -asm jne expandshort + cmp di,ax // done? + jne expandshort } } else @@ -557,72 +612,107 @@ asm jne expandshort length--; - __asm - { -asm mov bx,[headptr] -asm mov cl,1 - -asm mov si,[sourceoff] -asm mov di,[destoff] -asm mov es,[destseg] -asm mov ds,[sourceseg] + __asm { +//// mov bx,[headptr] + mov cl,1 -asm lodsb // load first byte + mov si,[sourceoff] + mov di,[destoff] + mov es,[destseg] + mov ds,[sourceseg] + lodsb // load first byte +#ifdef __BORLANDC__ + } +#endif expand: -asm test al,cl // bit set? -asm jnz bit1 -asm mov dx,[ss:bx] // take bit0 path from node -asm 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: -asm mov dx,[ss:bx+2] // take bit1 path - +#ifdef __BORLANDC__ + __asm { +#endif + mov dx,[ss:bx+2] // take bit1 path +#ifdef __BORLANDC__ + } +#endif gotcode: -asm shl cl,1 // advance to next bit position -asm jnc sourceup -asm lodsb -asm cmp si,0x10 // normalize ds:si -asm jb sinorm -asm mov cx,ds -asm inc cx -asm mov ds,cx -asm 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: -asm mov cl,1 // back to first bit - +#ifdef __BORLANDC__ + __asm { +#endif + mov cl,1 // back to first bit +#ifdef __BORLANDC__ + } +#endif sourceup: -asm or dh,dh // if dx<256 its a byte, else move node -asm jz storebyte -asm mov bx,dx // next node = (huffnode *)code -asm 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: -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 - -asm cmp di,0x10 // normalize es:di -asm jb dinorm -asm mov dx,es -asm inc dx -asm mov es,dx -asm 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: - -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 +#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 } -}*/ +} /* @@ -888,7 +978,7 @@ asm mov ds,ax = ====================== */ - +////++++ enable! /*void CAL_SetupGrFile (void) { int handle; @@ -987,7 +1077,7 @@ asm mov ds,ax ====================== */ -/*void CAL_SetupMapFile (void) +void CAL_SetupMapFile (global_game_variables_t *gvar) { int handle; long length; @@ -995,33 +1085,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) +// 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 // // 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 +} //========================================================================== @@ -1094,48 +1190,27 @@ 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 ();*/ - mapon = -1; - ca_levelbit = 1; - ca_levelnum = 0; + CAL_SetupMapFile (gvar); - drawcachebox = CAL_DialogDraw; + gvar->ca.mapon = -1; + gvar->ca.ca_levelbit = 1; + gvar->ca.ca_levelnum = 0; + +/* drawcachebox = CAL_DialogDraw; updatecachebox = CAL_DialogUpdate; finishcachebox = CAL_DialogFinish;*/ } @@ -1158,9 +1233,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);*/ } @@ -1681,7 +1757,7 @@ void CA_CacheGrChunk (int chunk) byte far *source; int next; - grneeded[chunk] |= ca_levelbit; // make sure it doesn't get removed + gvar->video.grneeded[chunk] |= ca_levelbit; // make sure it doesn't get removed if (grsegs[chunk]) { MM_SetPurge (&grsegs[chunk],0); @@ -1905,15 +1981,14 @@ void CA_DownLevel (void) = ====================== */ -/* -void CA_ClearMarks (void) + +void CA_ClearMarks (global_game_variables_t *gvar) { int i; for (i=0;ivideo.grneeded[i]&=~gvar->ca.ca_levelbit; } -*/ //=========================================================================== @@ -1926,14 +2001,13 @@ void CA_ClearMarks (void) = ====================== */ -/* -void CA_ClearAllMarks (void) + +void CA_ClearAllMarks (global_game_variables_t *gvar) { - _fmemset (grneeded,0,sizeof(grneeded)); - ca_levelbit = 1; - ca_levelnum = 0; + _fmemset (gvar->video.grneeded,0,sizeof(gvar->video.grneeded)); + gvar->ca.ca_levelbit = 1; + gvar->ca.ca_levelnum = 0; } -*/ //=========================================================================== @@ -1945,9 +2019,14 @@ void CA_ClearAllMarks (void) ====================== */ /*++++ -void CA_FreeGraphics (void) +void CA_SetGrPurge (void) { - int i; + int i; + +// +// free graphics +// + CA_ClearMarks (); for (i=0;ivideo.grneeded[i]&ca_levelbit) { if (grsegs[i]) // its allready in memory, make MM_SetPurge(&grsegs[i],0); // sure it stays there! @@ -2194,7 +2260,7 @@ void CA_CacheMarks (char *title) bufferstart = bufferend = 0; // nothing good in buffer now for (i=0;ivideo.grneeded[i]&ca_levelbit) && !grsegs[i]) { // // update thermometer @@ -2228,7 +2294,7 @@ void CA_CacheMarks (char *title) while ( next < NUMCHUNKS ) { while (next < NUMCHUNKS && - !(grneeded[next]&ca_levelbit && !grsegs[next])) + !(gvar->video.grneeded[next]&ca_levelbit && !grsegs[next])) next++; if (next == NUMCHUNKS) continue;