From: sparky4 Date: Sat, 13 May 2017 19:41:36 +0000 (-0500) Subject: 16_ca needs huge amounts of work and I should remember what needs to be done soon... X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=b71a38de9e2c9e603ae664d9dceed0cdd64042f5;p=16.git 16_ca needs huge amounts of work and I should remember what needs to be done soon[going to port rest of code to borland c some time so we can use the core components of id engine here ][going to add 16_us.c eventually but the debug system and CA_ PM_ and MM_ usage is priority now]older zcroll renamed to xcroll][zcroll is now the pre menu game loop system with PROPER data usage with CAMMPM] added 1st scroll back [i work on CA] palette debug show values added wwww and i need to know how to see vrs/vrl imaage data palette index numbers [i am trying to find out how the hell you get the index number values of VRL/VRS] boom has been fixed ^^[CA_CacheMap added seems to be used in start a new game] what is mapsegs? --- diff --git a/src/lib/16_ca.c b/src/lib/16_ca.c index 1d9b7f0b..ce406dd5 100755 --- a/src/lib/16_ca.c +++ b/src/lib/16_ca.c @@ -1088,23 +1088,23 @@ void CAL_SetupGrFile (global_game_variables_t *gvar) CAL_GetGrChunkLength(STRUCTPIC,gvar); // position file pointer printf("CAL_SetupGrFile:\n"); printf(" gvar->ca.chunkcomplen size is %lu\n", gvar->ca.chunkcomplen); - MM_GetPtr(&compseg,gvar->ca.chunkcomplen,gvar); - IN_Ack(gvar); + MM_GetPtr(MEMPTRANDPERCONV compseg,gvar->ca.chunkcomplen,gvar); IN_Ack(gvar); CA_FarRead (gvar->ca.file.grhandle,compseg,gvar->ca.chunkcomplen,gvar); CAL_HuffExpand (compseg, (byte far *)gvar->video.pictable,NUMPICS*sizeof(pictabletype),gvar->ca.grhuffman); - MM_FreePtr(&compseg,gvar); + MM_FreePtr(MEMPTRANDPERCONV compseg,gvar); #endif -#if NUMPICM>0 +#if 0 + //NUMPICM>0 MM_GetPtr(MEMPTRCONV picmtable,NUMPICM*sizeof(pictabletype)); CAL_GetGrChunkLength(STRUCTPICM); // position file pointer MM_GetPtr(&compseg,gvar->ca.chunkcomplen); CA_FarRead (gvar->ca.file.grhandle,compseg,gvar->ca.chunkcomplen); CAL_HuffExpand (compseg, (byte far *)picmtable,NUMPICS*sizeof(pictabletype),gvar->ca.grhuffman); MM_FreePtr(&compseg); -#endif +//#endif -#if NUMSPRITES>0 +//#if NUMSPRITES>0 MM_GetPtr(MEMPTRCONV spritetable,NUMSPRITES*sizeof(spritetabletype)); CAL_GetGrChunkLength(STRUCTSPRITE); // position file pointer MM_GetPtr(&compseg,gvar->ca.chunkcomplen); diff --git a/src/lib/16_map.c b/src/lib/16_map.c index 88110d5e..ad846e81 100755 --- a/src/lib/16_map.c +++ b/src/lib/16_map.c @@ -216,7 +216,6 @@ int newloadmap(char *mn, map_t *map) { //====== -#define MAPBUFINLM (gvar->ca.mapsegs[0]) int CA_loadmap(char *mn, map_t *map, global_game_variables_t *gvar) { jsmn_parser p; @@ -230,18 +229,18 @@ int CA_loadmap(char *mn, map_t *map, global_game_variables_t *gvar) jsmn_init(&p); file_s = filesize(fh); - CA_LoadFile(mn, (memptr *)&MAPBUFINLM, gvar); - tokcount = jsmn_parse(&p, (char const *)MAPBUFINLM, file_s, NULL, 0); + CA_LoadFile(mn, MEMPTRCONV MAPSEGINLM, gvar); + tokcount = jsmn_parse(&p, (char const *)MAPSEGINLM, file_s, NULL, 0); tok = malloc(tokcount*sizeof(jsmntok_t));//TODO: USE MM_ CA_ AND PM_ // printf("Allocated %d tokens", tokcount); jsmn_init(&p); - if((status = jsmn_parse(&p, (char const *)MAPBUFINLM, file_s, tok, tokcount)) < 0) + if((status = jsmn_parse(&p, (char const *)MAPSEGINLM, file_s, tok, tokcount)) < 0) { printf("Error: %d\n", status); return status; } else if(status != tokcount) { printf("Warning: used %d tok\n", status);} - extract_map((char const *)MAPBUFINLM, tok, tokcount, map); + extract_map((char const *)MAPSEGINLM, tok, tokcount, map); free(tok); //TODO: USE MM_ CA_ AND PM_ fclose(fh); //TODO: USE MM_ CA_ AND PM_ diff --git a/src/lib/16_rf.c b/src/lib/16_rf.c index bc0afca6..86f40456 100755 --- a/src/lib/16_rf.c +++ b/src/lib/16_rf.c @@ -919,7 +919,8 @@ void RFL_CalcOriginStuff (long x, long y) gvar->video.ofs.pan.panx = (originxglobal>>G_P_SHIFT) & 15; gvar->video.ofs.pan.pansx = gvar->video.ofs.pan.panx & 8; gvar->video.ofs.pan.pany = gvar->video.ofs.pan.pansy = (originyglobal>>G_P_SHIFT) & 15; - gvar->video.ofs.pan.panadjust = gvar->video.ofs.pan.panx/8 + gvar->video.ofs.ylookup[gvar->video.ofs.pan.pany]; +// gvar->video.ofs.pan.panadjust = gvar->video.ofs.pan.panx/8 + gvar->video.ofs.ylookup[gvar->video.ofs.pan.pany]; + gvar->video.ofs.pan.panadjust = gvar->video.ofs.pan.panx/8 + (gvar->video.ofs.pan.pany*gvar->video.page[0].stridew); /*#endif #if GRMODE == CGAGR @@ -1368,7 +1369,7 @@ void RFL_BoundNewOrigin (unsigned orgx,unsigned orgy) void RF_ClearBlock (int x, int y, int width, int height) { - eraseblocktype block; +// eraseblocktype block; #if GRMODE == EGAGR block.screenx = x/8+originxscreen; @@ -1429,7 +1430,7 @@ void RF_RedrawBlock (int x, int y, int width, int height) void RF_CalcTics (void) { - long newtime,oldtimecount; + long newtime;//,oldtimecount; word TimeCount = *clockw; // @@ -2678,7 +2679,8 @@ void RFL_EraseBlocks (void) // // erase the block by copying from the master screen // - pos = gvar->video.ofs.ylookup[block->screeny]+block->screenx; +//---- pos = gvar->video.ofs.ylookup[block->screeny]+block->screenx; + pos = (block->screeny*gvar->video.page[0].stridew)+block->screenx; block->width = (block->width + (pos&1) + 1)& ~1; pos &= ~1; // make sure a word copy gets used //++++ VW_ScreenToScreen (masterofs+pos,bufferofs+pos, diff --git a/src/lib/16_rf.h b/src/lib/16_rf.h index e70fb104..fe16b89c 100755 --- a/src/lib/16_rf.h +++ b/src/lib/16_rf.h @@ -81,12 +81,12 @@ #define MSPEED (INTILE+NUMTILE16M) #define CGAGR 1 #define EGAGR 2 -#define MAXSHIFTS 1 +//#define MAXSHIFTS 1 #define TILEWIDTH TILEWH typedef enum {NOcard,MDAcard,CGAcard,EGAcard,MCGAcard,VGAcard, HGCcard=0x80,HGCPcard,HICcard} cardtype; typedef enum {CGAgr,EGAgr,VGAgr} grtype; -typedef struct +/*typedef struct { int width, height, @@ -101,7 +101,7 @@ typedef struct unsigned planesize[MAXSHIFTS]; unsigned width[MAXSHIFTS]; byte data[]; -} spritetype; // the memptr for each sprite points to this +} spritetype; // the memptr for each sprite points to this*/ // //=========================================================================== diff --git a/src/lib/16_t.h b/src/lib/16_t.h index ff738657..db1871f7 100755 --- a/src/lib/16_t.h +++ b/src/lib/16_t.h @@ -49,19 +49,16 @@ typedef enum {ichi,ni,san,yon,go,roku,shichi,hachi,kyu,ju,juichi,juni,jusan,juyo /*typedef unsigned memseg; memptr should be replaced by memseg in code. - on usage where you need pointer convert memseg type (segment) to far pointer by MK_FP(segment value, 0)*/ -#ifdef __WATCOMC__ + #ifdef __WATCOMC__ //typedef void __based( void ) * memptr; ////old //----typedef void __based(__self) * memptr; //typedef unsigned short _seg; // it will contains segment value (as Borland _seg) #define _seg __based( void ) -// #define __SEGA __segment -#endif -#ifdef __BORLANDC__ + #endif + #ifdef __BORLANDC__ #define _memavl() coreleft() -// #define __SEGA _seg -#endif + #endif typedef void _seg * memptr; diff --git a/src/lib/16_tdef.h b/src/lib/16_tdef.h index c1f2db84..b3fc892d 100755 --- a/src/lib/16_tdef.h +++ b/src/lib/16_tdef.h @@ -694,6 +694,10 @@ typedef struct #define GFILENAME DATADIR"vgagraph." +#define MAPSEGBUF mapsegs +#define MAPSEGPTR MAPSEGBUF[0] +#define MAPSEGINLM (gvar->ca.MAPSEGPTR) + typedef struct { word bit0,bit1; // 0-255 is a character, > is a pointer to a node diff --git a/src/lib/id_ca.c b/src/lib/id_ca.c new file mode 100755 index 00000000..0cf682eb --- /dev/null +++ b/src/lib/id_ca.c @@ -0,0 +1,1914 @@ +// ID_CA.C + +// this has been customized for WOLF + +/* +============================================================================= + +Id Software Caching Manager +--------------------------- + +Must be started BEFORE the memory manager, because it needs to get the headers +loaded into the data segment + +============================================================================= +*/ + +#include "ID_HEADS.H" +#pragma hdrstop + +#pragma warn -pro +#pragma warn -use + +#define THREEBYTEGRSTARTS + +/* +============================================================================= + + LOCAL CONSTANTS + +============================================================================= +*/ + +typedef struct +{ + unsigned bit0,bit1; // 0-255 is a character, > is a pointer to a node +} huffnode; + + +typedef struct +{ + unsigned RLEWtag; + long headeroffsets[100]; + byte tileinfo[]; +} mapfiletype; + + +/* +============================================================================= + + GLOBAL VARIABLES + +============================================================================= +*/ + +byte _seg *tinf; +int mapon; + +unsigned _seg *mapsegs[MAPPLANES]; +maptype _seg *mapheaderseg[NUMMAPS]; +byte _seg *audiosegs[NUMSNDCHUNKS]; +void _seg *grsegs[NUMCHUNKS]; + +byte far grneeded[NUMCHUNKS]; +byte ca_levelbit,ca_levelnum; + +int profilehandle,debughandle; + +char audioname[13]="AUDIO."; + +/* +============================================================================= + + LOCAL VARIABLES + +============================================================================= +*/ + +extern long far CGAhead; +extern long far EGAhead; +extern byte CGAdict; +extern byte EGAdict; +extern byte far maphead; +extern byte mapdict; +extern byte far audiohead; +extern byte audiodict; + + +char extension[5], // Need a string, not constant to change cache files + gheadname[10]=GREXT"HEAD.", + gfilename[10]=GREXT"GRAPH.", + gdictname[10]=GREXT"DICT.", + mheadname[10]="MAPHEAD.", + mfilename[10]="MAPTEMP.", + aheadname[10]="AUDIOHED.", + afilename[10]="AUDIOT."; + +void CA_CannotOpen(char *string); + +long _seg *grstarts; // array of offsets in egagraph, -1 for sparse +long _seg *audiostarts; // array of offsets in audio / audiot + +#ifdef GRHEADERLINKED +huffnode *grhuffman; +#else +huffnode grhuffman[255]; +#endif + +#ifdef AUDIOHEADERLINKED +huffnode *audiohuffman; +#else +huffnode audiohuffman[255]; +#endif + + +int grhandle; // handle to EGAGRAPH +int maphandle; // handle to MAPTEMP / GAMEMAPS +int audiohandle; // handle to AUDIOT / AUDIO + +long chunkcomplen,chunkexplen; + +SDMode oldsoundmode; + + + +void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, + unsigned length); + + +#ifdef THREEBYTEGRSTARTS +#define FILEPOSSIZE 3 +//#define GRFILEPOS(c) (*(long far *)(((byte far *)grstarts)+(c)*3)&0xffffff) +long GRFILEPOS(int c) +{ + long value; + int offset; + + offset = c*3; + + value = *(long far *)(((byte far *)grstarts)+offset); + + value &= 0x00ffffffl; + + if (value == 0xffffffl) + value = -1; + + return value; +}; +#else +#define FILEPOSSIZE 4 +#define GRFILEPOS(c) (grstarts[c]) +#endif + +/* +============================================================================= + + LOW LEVEL ROUTINES + +============================================================================= +*/ + +/* +============================ += += CA_OpenDebug / CA_CloseDebug += += Opens a binary file with the handle "debughandle" += +============================ +*/ + +void CA_OpenDebug (void) +{ + unlink ("DEBUG.TXT"); + debughandle = open("DEBUG.TXT", O_CREAT | O_WRONLY | O_TEXT); +} + +void CA_CloseDebug (void) +{ + close (debughandle); +} + + + +/* +============================ += += CAL_GetGrChunkLength += += Gets the length of an explicit length chunk (not tiles) += The file pointer is positioned so the compressed data can be read in next. += +============================ +*/ + +void CAL_GetGrChunkLength (int chunk) +{ + lseek(grhandle,GRFILEPOS(chunk),SEEK_SET); + read(grhandle,&chunkexplen,sizeof(chunkexplen)); + chunkcomplen = GRFILEPOS(chunk+1)-GRFILEPOS(chunk)-4; +} + + +/* +========================== += += CA_FarRead += += Read from a file to a far pointer += +========================== +*/ + +boolean CA_FarRead (int handle, byte far *dest, long length) +{ + boolean flag=false; + if (length>0xffffl) + Quit ("CA_FarRead doesn't support 64K reads yet!"); + + __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 { +#endif + 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 { +#endif + mov flag,1 +#ifdef __BORLANDC__ + } +#endif +End: +#ifdef __WATCOMC__ + } +#endif + return flag; +} + + +/* +========================== += += CA_SegWrite += += Write from a file to a far pointer += +========================== +*/ + +boolean CA_FarWrite (int handle, byte far *source, long length) +{ + boolean flag=false; + if (length>0xffffl) + Quit ("CA_FarWrite doesn't support 64K reads yet!"); + + __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 { +#endif + 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 { +#endif + mov flag,1 +#ifdef __BORLANDC__ + } +#endif +End: +#ifdef __WATCOMC__ + } +#endif + return flag; +} + + +/* +========================== += += CA_ReadFile += += Reads a file into an allready allocated buffer += +========================== +*/ + +boolean CA_ReadFile (char *filename, memptr *ptr) +{ + int handle; + long size; + + if ((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1) + return false; + + size = filelength (handle); + if (!CA_FarRead (handle,*ptr,size)) + { + 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) +{ + int handle; + 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)) + { + close (handle); + return false; + } + close (handle); + return true; +} + + + +/* +========================== += += CA_LoadFile += += Allocate space for and load a file += +========================== +*/ + +boolean CA_LoadFile (char *filename, memptr *ptr) +{ + int handle; + long size; + + 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)) + { + close (handle); + return false; + } + close (handle); + return true; +} + +/* +============================================================================ + + COMPRESSION routines, see JHUFF.C for more + +============================================================================ +*/ + + + +/* +=============== += += CAL_OptimizeNodes += += Goes through a huffman table and changes the 256-511 node numbers to the += actular address of the node. Must be called before CAL_HuffExpand += +=============== +*/ + +void CAL_OptimizeNodes (huffnode *table) +{ + huffnode *node; + int i; + + node = table; + + for (i=0;i<255;i++) + { + if (node->bit0 >= 256) + node->bit0 = (unsigned)(table+(node->bit0-256)); + if (node->bit1 >= 256) + node->bit1 = (unsigned)(table+(node->bit1-256)); + node++; + } +} + + + +/* +====================== += += CAL_HuffExpand += += Length is the length of the EXPANDED data += If screenhack, the data is decompressed in four planes directly += to the screen += +====================== +*/ + +void CAL_HuffExpand (byte huge *source, byte huge *dest, + long length,huffnode *hufftable, boolean screenhack) +{ +// unsigned bit,byte,node,code; + unsigned sourceseg,sourceoff,destseg,destoff,endoff; + huffnode *headptr; + byte mapmask; +// huffnode *nodeon; + + headptr = hufftable+254; // head node is allways node 254 + + source++; // normalize + source--; + dest++; + dest--; + + if (screenhack) + { + mapmask = 1; +asm mov dx,SC_INDEX +asm mov ax,SC_MAPMASK + 256 +asm out dx,ax + length >>= 2; + } + + sourceseg = FP_SEG(source); + sourceoff = FP_OFF(source); + destseg = FP_SEG(dest); + destoff = FP_OFF(dest); + endoff = destoff+length; + +// +// ds:si source +// es:di dest +// ss:bx node pointer +// + + if (length <0xfff0) + { + +//-------------------------- +// expand less than 64k of data +//-------------------------- + + __asm { + mov bx,[word ptr headptr] + + mov si,[sourceoff] + mov di,[destoff] + mov es,[destseg] + mov ds,[sourceseg] + mov ax,[endoff] + + 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: +#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: +#ifdef __BORLANDC__ + __asm { +#endif + mov ch,[si] // load next byte + inc si + mov cl,1 // back to first bit +#ifdef __BORLANDC__ + } +#endif +sourceupshort: +#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: +#ifdef __BORLANDC__ + __asm { +#endif + mov [es:di],dl + inc di // write a decopmpressed byte out + mov bx,[word ptr headptr] // back to the head node for next bit + + cmp di,ax // done? + jne expandshort +// +// perform screenhack if needed +// + test [screenhack],1 + jz notscreen + shl [mapmask],1 + mov ah,[mapmask] + cmp ah,16 + je notscreen // all four planes done + mov dx,SC_INDEX + mov al,SC_MAPMASK + out dx,ax + mov di,[destoff] + mov ax,[endoff] + jmp expandshort +#ifdef __BORLANDC__ + } +#endif +notscreen: +#ifdef __WATCOMC__ + } +#endif + } + else + { + +//-------------------------- +// expand more than 64k of data +//-------------------------- + + length--; + + __asm { + mov bx,[word ptr headptr] + mov cl,1 + + mov si,[sourceoff] + mov di,[destoff] + mov es,[destseg] + mov ds,[sourceseg] + + lodsb // load first byte +#ifdef __BORLANDC__ + } +#endif +expand: +#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: +#ifdef __BORLANDC__ + __asm { +#endif + mov dx,[ss:bx+2] // take bit1 path +#ifdef __BORLANDC__ + } +#endif +gotcode: +#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: +#ifdef __BORLANDC__ + __asm { +#endif + mov cl,1 // back to first bit +#ifdef __BORLANDC__ + } +#endif +sourceup: +#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: +#ifdef __BORLANDC__ + __asm { +#endif + mov [es:di],dl + inc di // write a decopmpressed byte out + mov bx,[word ptr 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: +#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 { + mov ax,ss + mov ds,ax + } + +} + + +/* +====================== += += CAL_CarmackExpand += += Length is the length of the EXPANDED data += +====================== +*/ + +#define NEARTAG 0xa7 +#define FARTAG 0xa8 + +void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned length) +{ + unsigned ch,chhigh,count,offset; + unsigned far *copyptr, far *inptr, far *outptr; + + length/=2; + + inptr = source; + outptr = dest; + + while (length) + { + ch = *inptr++; + chhigh = ch>>8; + if (chhigh == NEARTAG) + { + count = ch&0xff; + if (!count) + { // have to insert a word containing the tag byte + ch |= *(BYTEFARPTRCONV inptr)++; + *outptr++ = ch; + length--; + } + else + { + offset = *(BYTEFARPTRCONV inptr)++; + copyptr = outptr - offset; + length -= count; + while (count--) + *outptr++ = *copyptr++; + } + } + else if (chhigh == FARTAG) + { + count = ch&0xff; + if (!count) + { // have to insert a word containing the tag byte + ch |= *(BYTEFARPTRCONV inptr)++; + *outptr++ = ch; + length --; + } + else + { + offset = *inptr++; + copyptr = dest + offset; + length -= count; + while (count--) + *outptr++ = *copyptr++; + } + } + else + { + *outptr++ = ch; + length --; + } + } +} + + + +/* +====================== += += CA_RLEWcompress += +====================== +*/ + +long CA_RLEWCompress (unsigned huge *source, long length, unsigned huge *dest, + unsigned rlewtag) +{ + long complength; + unsigned value,count,i; + unsigned huge *start,huge *end; + + start = dest; + + end = source + (length+1)/2; + +// +// compress it +// + do + { + count = 1; + value = *source++; + while (*source == value && source3 || value == rlewtag) + { + // + // send a tag / count / value string + // + *dest++ = rlewtag; + *dest++ = count; + *dest++ = value; + } + else + { + // + // send word without compressing + // + for (i=1;i<=count;i++) + *dest++ = value; + } + + } while (sourceheaderoffsets[i]; + if (pos<0) // $FFFFFFFF start is a sparse map + continue; + + MM_GetPtr(MEMPTRCONV mapheaderseg[i],sizeof(maptype)); + MM_SetLock(MEMPTRCONV mapheaderseg[i],true); + lseek(maphandle,pos,SEEK_SET); + CA_FarRead (maphandle,(memptr)mapheaderseg[i],sizeof(maptype)); + } + +// +// allocate space for 3 64*64 planes +// + for (i=0;iBUFFERSIZE) + MM_FreePtr(MEMPTRANDPERCONV bigbufferseg); +#endif +} + +//=========================================================================== + +/* +====================== += += CA_LoadAllSounds += += Purges all sounds, then loads all new ones (mode switch) += +====================== +*/ + +void CA_LoadAllSounds (void) +{ + unsigned start,i; + + switch (oldsoundmode) + { + case sdm_Off: + goto cachein; + case sdm_PC: + start = STARTPCSOUNDS; + break; + case sdm_AdLib: + start = STARTADLIBSOUNDS; + break; + } + + for (i=0;i= STARTTILE8 && chunk < STARTEXTERNS) + { + // + // expanded sizes of tile8/16/32 are implicit + // + +#define BLOCK 64 +#define MASKBLOCK 128 + + if (chunkBUFFERSIZE) + MM_FreePtr(MEMPTRANDPERCONV bigbufferseg); +} + + + +//========================================================================== + +/* +====================== += += CA_CacheScreen += += Decompresses a chunk from disk straight onto the screen += +====================== +*/ + +void CA_CacheScreen (int chunk) +{ + long pos,compressed,expanded; + memptr bigbufferseg; + byte far *source; + int next; + +// +// load the chunk into a buffer +// + pos = GRFILEPOS(chunk); + next = chunk +1; + while (GRFILEPOS(next) == -1) // skip past any sparse tiles + next++; + compressed = GRFILEPOS(next)-pos; + + lseek(grhandle,pos,SEEK_SET); + + MM_GetPtr(MEMPTRANDPERCONV bigbufferseg,compressed); + MM_SetLock (MEMPTRANDPERCONV bigbufferseg,true); + CA_FarRead(grhandle,bigbufferseg,compressed); + source = bigbufferseg; + + expanded = *(long far *)source; + source += 4; // skip over length + +// +// allocate final space, decompress it, and free bigbuffer +// Sprites need to have shifts made and various other junk +// + CAL_HuffExpand (source,MK_FP(SCREENSEG,bufferofs),expanded,grhuffman,true); + VW_MarkUpdateBlock (0,0,319,199); + MM_FreePtr(MEMPTRANDPERCONV bigbufferseg); +} + +//========================================================================== + +/* +====================== += += CA_CacheMap += += WOLF: This is specialized for a 64*64 map size += +====================== +*/ + +void CA_CacheMap (int mapnum) +{ + long pos,compressed; + int plane; + memptr *dest,bigbufferseg; + unsigned size; + unsigned far *source; +#ifdef CARMACIZED + memptr buffer2seg; + long expanded; +#endif + + mapon = mapnum; + +// +// load the planes into the allready allocated buffers +// + size = 64*64*2; + + for (plane = 0; planeplanestart[plane]; + compressed = mapheaderseg[mapnum]->planelength[plane]; + + dest = MEMPTRCONV mapsegs[plane]; + + lseek(maphandle,pos,SEEK_SET); + if (compressed<=BUFFERSIZE) + source = bufferseg; + else + { + MM_GetPtr(MEMPTRANDPERCONV bigbufferseg,compressed); + MM_SetLock (MEMPTRANDPERCONV bigbufferseg,true); + source = bigbufferseg; + } + + CA_FarRead(maphandle,(byte far *)source,compressed); +#ifdef CARMACIZED + // + // unhuffman, then unRLEW + // The huffman'd chunk has a two byte expanded length first + // The resulting RLEW chunk also does, even though it's not really + // needed + // + expanded = *source; + source++; + MM_GetPtr (MEMPTRANDPERCONV buffer2seg,expanded); + CAL_CarmackExpand (source, (unsigned far *)buffer2seg,expanded); + CA_RLEWexpand (((unsigned far *)buffer2seg)+1,*dest,size, + ((mapfiletype _seg *)tinf)->RLEWtag); + MM_FreePtr (MEMPTRANDPERCONV buffer2seg); + +#else + // + // unRLEW, skipping expanded length + // + CA_RLEWexpand (source+1, *dest,size, + ((mapfiletype _seg *)tinf)->RLEWtag); +#endif + + if (compressed>BUFFERSIZE) + MM_FreePtr(MEMPTRANDPERCONV bigbufferseg); + } +} + +//=========================================================================== + +/* +====================== += += CA_UpLevel += += Goes up a bit level in the needed lists and clears it out. += Everything is made purgable += +====================== +*/ + +void CA_UpLevel (void) +{ + int i; + + if (ca_levelnum==7) + Quit ("CA_UpLevel: Up past level 7!"); + + for (i=0;i>=1; + ca_levelnum--; + CA_CacheMarks(); +} + +//=========================================================================== + +/* +====================== += += CA_ClearMarks += += Clears out all the marks at the current level += +====================== +*/ + +void CA_ClearMarks (void) +{ + int i; + + for (i=0;i= endpos) + { + // data is allready in buffer + source = (byte _seg *)bufferseg+(pos-bufferstart); + } + else + { + // load buffer with a new block from disk + // try to get as many of the needed blocks in as possible + while ( next < NUMCHUNKS ) + { + while (next < NUMCHUNKS && + !(grneeded[next]&ca_levelbit && !grsegs[next])) + next++; + if (next == NUMCHUNKS) + continue; + + nextpos = GRFILEPOS(next); + while (GRFILEPOS(++next) == -1) // skip past any sparse tiles + ; + nextendpos = GRFILEPOS(next); + if (nextpos - endpos <= MAXEMPTYREAD + && nextendpos-pos <= BUFFERSIZE) + endpos = nextendpos; + else + next = NUMCHUNKS; // read pos to posend + } + + lseek(grhandle,pos,SEEK_SET); + CA_FarRead(grhandle,bufferseg,endpos-pos); + bufferstart = pos; + bufferend = endpos; + source = bufferseg; + } + } + else + { + // big chunk, allocate temporary buffer + MM_GetPtr(MEMPTRANDPERCONV bigbufferseg,compressed); + if (mmerror) + return; + MM_SetLock (MEMPTRANDPERCONV bigbufferseg,true); + lseek(grhandle,pos,SEEK_SET); + CA_FarRead(grhandle,bigbufferseg,compressed); + source = bigbufferseg; + } + + CAL_ExpandGrChunk (i,source); + if (mmerror) + return; + + if (compressed>BUFFERSIZE) + MM_FreePtr(MEMPTRANDPERCONV bigbufferseg); + + } +} + +void CA_CannotOpen(char *string) +{ + char str[30]; + + strcpy(str,"Can't open "); + strcat(str,string); + strcat(str,"!\n"); + Quit (str); +} diff --git a/src/maptest.c b/src/maptest.c index 143a5f4d..33c5dcc7 100755 --- a/src/maptest.c +++ b/src/maptest.c @@ -23,7 +23,7 @@ #include #define DUMP -#define DUMP_MAP +//#define DUMP_MAP void main(int argc, char *argv[]) @@ -48,7 +48,7 @@ main(int argc, char *argv[]) fprintf(stderr, fmt, _memavl()); fprintf(stderr, fmt0, _memmax()); - fprintf(stderr, "Size of map var = %u\n", _msize(&(gvar.ca.mapsegs))); + fprintf(stderr, "Size of map var = %u\n", _msize(&(gvar.ca.MAPSEGPTR))); CA_loadmap("data/test.map", &map, &gvar); #ifdef DUMP @@ -72,7 +72,7 @@ main(int argc, char *argv[]) getch(); } #else - //fprintf(stderr, "contents of the buffer\n[\n%s\n]\n", (gvar.ca.mapsegs)); + fprintf(stderr, "contents of the buffer\n[\n%s\n]\n", (gvar.ca.MAPSEGPTR)); #endif /*fprintf(stdout, "&main()=%Fp\n", *argv[0]); fprintf(stdout, "&map==%Fp\n", &map); @@ -82,7 +82,7 @@ main(int argc, char *argv[]) fprintf(stdout, "&map.data==%Fp\n", map.data);*/ #endif //fprintf(stderr, "here comes dat boi!\n"); getch(); fprintf(stderr, "%s", datboi); - MM_FreePtr((memptr *)&(gvar.ca.mapsegs), &gvar); + MM_FreePtr(MEMPTRCONV (gvar.ca.MAPSEGPTR), &gvar); PM_Shutdown(&gvar); CA_Shutdown(&gvar); MM_Shutdown(&gvar);