1 /* Catacomb Apocalypse Source Code
\r
2 * Copyright (C) 1993-2014 Flat Rock Software
\r
4 * This program is free software; you can redistribute it and/or modify
\r
5 * it under the terms of the GNU General Public License as published by
\r
6 * the Free Software Foundation; either version 2 of the License, or
\r
7 * (at your option) any later version.
\r
9 * This program is distributed in the hope that it will be useful,
\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 * GNU General Public License for more details.
\r
14 * You should have received a copy of the GNU General Public License along
\r
15 * with this program; if not, write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
22 =============================================================================
\r
24 Id Software Caching Manager
\r
25 ---------------------------
\r
27 Must be started BEFORE the memory manager, because it needs to get the headers
\r
28 loaded into the data segment
\r
30 =============================================================================
\r
33 #include "src/lib/16_ca.h"
\r
39 //#define THREEBYTEGRSTARTS
\r
42 =============================================================================
\r
46 =============================================================================
\r
51 unsigned bit0,bit1; // 0-255 is a character, > is a pointer to a node
\r
58 long headeroffsets[100];
\r
64 =============================================================================
\r
68 =============================================================================
\r
74 unsigned _seg *mapsegs[3];
\r
75 maptype _seg *mapheaderseg[NUMMAPS];
\r
76 byte _seg *audiosegs[NUMSNDCHUNKS];
\r
77 void _seg *grsegs[NUMCHUNKS];
\r
79 byte far grneeded[NUMCHUNKS];
\r
80 byte ca_levelbit,ca_levelnum;*/
\r
82 void (*drawcachebox) (char *title, unsigned numcache);
\r
83 void (*updatecachebox) (void);
\r
84 void (*finishcachebox) (void);
\r
87 =============================================================================
\r
91 =============================================================================
\r
94 /*extern long far CGAhead;
\r
95 extern long far EGAhead;
\r
96 extern byte CGAdict;
\r
97 extern byte EGAdict;
\r
98 extern byte far maphead;
\r
99 extern byte mapdict;
\r
100 extern byte far audiohead;
\r
101 extern byte audiodict;
\r
104 long _seg *grstarts; // array of offsets in egagraph, -1 for sparse
\r
105 long _seg *audiostarts; // array of offsets in audio / audiot
\r
107 #ifdef GRHEADERLINKED
\r
108 huffnode *grhuffman;
\r
110 huffnode grhuffman[255];
\r
113 #ifdef AUDIOHEADERLINKED
\r
114 huffnode *audiohuffman;
\r
116 huffnode audiohuffman[255];
\r
120 int grhandle; // handle to EGAGRAPH
\r
121 int maphandle; // handle to MAPTEMP / GAMEMAPS
\r
122 int audiohandle; // handle to AUDIOT / AUDIO
\r
124 long chunkcomplen,chunkexplen;
\r
126 SDMode oldsoundmode;
\r
130 void CAL_DialogDraw (char *title,unsigned numcache);
\r
131 void CAL_DialogUpdate (void);
\r
132 void CAL_DialogFinish (void);*/
\r
133 //void CAL_CarmackExpand (unsigned far *source, unsigned far *dest,unsigned length);
\r
136 /*++++#ifdef THREEBYTEGRSTARTS
\r
137 #define FILEPOSSIZE 3
\r
138 //#define GRFILEPOS(c) (*(long far *)(((byte far *)grstarts)+(c)*3)&0xffffff)
\r
139 long GRFILEPOS(int c)
\r
146 value = *(long far *)(((byte far *)grstarts)+offset);
\r
148 value &= 0x00ffffffl;
\r
150 if (value == 0xffffffl)
\r
156 #define FILEPOSSIZE 4
\r
157 #define GRFILEPOS(c) (grstarts[c])
\r
161 =============================================================================
\r
165 =============================================================================
\r
169 ============================
\r
171 = CA_OpenDebug / CA_CloseDebug
\r
173 = Opens a binary file with the handle "debughandle"
\r
175 ============================
\r
177 void CA_OpenDebug(global_game_variables_t *gvar)
\r
179 #ifdef __BORLANDC__
\r
180 unlink("debug.16b");
\r
181 gvar->handle.debughandle = open("debug.16b", O_CREAT | O_WRONLY | O_TEXT);
\r
184 unlink("debug.16w");
\r
185 gvar->handle.debughandle = open("debug.16w", O_CREAT | O_WRONLY | O_TEXT);
\r
189 void CA_CloseDebug(global_game_variables_t *gvar)
\r
191 close(gvar->handle.debughandle);
\r
197 ============================
\r
199 = CAL_GetGrChunkLength
\r
201 = Gets the length of an explicit length chunk (not tiles)
\r
202 = The file pointer is positioned so the compressed data can be read in next.
\r
204 ============================
\r
207 void CAL_GetGrChunkLength (int chunk)
\r
209 lseek(grhandle,GRFILEPOS(chunk),SEEK_SET);
\r
210 read(grhandle,&chunkexplen,sizeof(chunkexplen));
\r
211 chunkcomplen = GRFILEPOS(chunk+1)-GRFILEPOS(chunk)-4;
\r
216 ==========================
\r
220 = Read from a file to a far pointer
\r
222 ==========================
\r
225 boolean CA_FarRead(int handle, byte huge *dest, dword length, mminfo_t *mm)
\r
230 //if(mm->EMSVer<0x40)
\r
231 if(length>0xfffflu)
\r
233 printf("File is a fat bakapee\n");
\r
234 //segm=(length%0xfffflu)-1;
\r
235 //fat=segm*0xfffflu;
\r
237 // printf("CA_FarRead doesn't support 64K reads yet!\n");
\r
238 return 0;//todo: EXPAND!!!
\r
246 mov cx,[WORD PTR length]
\r
247 mov dx,[WORD PTR dest]
\r
248 mov ds,[WORD PTR dest+2]
\r
249 mov ah,0x3f // READ w/handle
\r
256 #ifdef __BORLANDC__
\r
260 #ifdef __BORLANDC__
\r
263 cmp ax,[WORD PTR length]
\r
265 // errno = EINVFMT; // user manager knows this is bad read
\r
268 #ifdef __BORLANDC__
\r
272 #ifdef __BORLANDC__
\r
276 #ifdef __BORLANDC__
\r
288 ==========================
\r
292 = Write from a file to a far pointer
\r
294 ==========================
\r
297 boolean CA_FarWrite(int handle, byte huge *source, dword length, mminfo_t *mm)
\r
302 //if(mm->EMSVer<0x40)
\r
303 if(length>0xfffflu)
\r
305 printf("File is a fat bakapee\n");
\r
306 //segm=(length%0xfffflu)-1;
\r
307 //fat=segm*0xfffflu;
\r
309 // printf("CA_FarRead doesn't support 64K reads yet!\n");
\r
318 mov cx,[WORD PTR length]
\r
319 mov dx,[WORD PTR source]
\r
320 mov ds,[WORD PTR source+2]
\r
321 mov ah,0x40 // WRITE w/handle
\r
328 #ifdef __BORLANDC__
\r
332 #ifdef __BORLANDC__
\r
335 cmp ax,[WORD PTR length]
\r
337 //errno = ENOMEM; // user manager knows this is bad write
\r
340 #ifdef __BORLANDC__
\r
344 #ifdef __BORLANDC__
\r
348 #ifdef __BORLANDC__
\r
360 ==========================
\r
364 = Reads a file into an allready allocated buffer
\r
366 ==========================
\r
369 boolean CA_ReadFile(char *filename, memptr *ptr, mminfo_t *mm)
\r
375 if((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
378 size = filelength(handle);
\r
379 if(!CA_FarRead(handle,*ptr,size, mm))
\r
391 ==========================
\r
395 = Allocate space for and load a file
\r
397 ==========================
\r
400 boolean CA_LoadFile(char *filename, memptr *ptr, mminfo_t *mm, mminfotype *mmi)
\r
406 if((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
409 size = filelength (handle);
\r
410 MM_GetPtr(ptr,size, mm, mmi);
\r
411 if(!CA_FarRead(handle,*ptr,size, mm))
\r
421 ============================================================================
\r
423 COMPRESSION routines, see JHUFF.C for more
\r
425 ============================================================================
\r
433 = CAL_OptimizeNodes
\r
435 = Goes through a huffman table and changes the 256-511 node numbers to the
\r
436 = actular address of the node. Must be called before CAL_HuffExpand
\r
441 void CAL_OptimizeNodes(huffnode *table)
\r
448 for (i=0;i<255;i++)
\r
450 if (node->bit0 >= 256)
\r
451 node->bit0 = (unsigned)(table+(node->bit0-256));
\r
452 if (node->bit1 >= 256)
\r
453 node->bit1 = (unsigned)(table+(node->bit1-256));
\r
461 ======================
\r
465 = Length is the length of the EXPANDED data
\r
467 ======================
\r
470 /*++++void CAL_HuffExpand (byte huge *source, byte huge *dest,
\r
471 long length,huffnode *hufftable)
\r
473 // unsigned bit,byte,node,code;
\r
474 unsigned sourceseg,sourceoff,destseg,destoff,endoff;
\r
476 // huffnode *nodeon;
\r
478 headptr = hufftable+254; // head node is allways node 254
\r
480 source++; // normalize
\r
485 sourceseg = FP_SEG(source);
\r
486 sourceoff = FP_OFF(source);
\r
487 destseg = FP_SEG(dest);
\r
488 destoff = FP_OFF(dest);
\r
489 endoff = destoff+length;
\r
494 // ss:bx node pointer
\r
497 if (length <0xfff0)
\r
500 //--------------------------
\r
501 // expand less than 64k of data
\r
502 //--------------------------
\r
514 mov ch,[si] // load first byte
\r
519 test ch,cl // bit set?
\r
521 mov dx,[ss:bx] // take bit0 path from node
\r
522 shl cl,1 // advance to next bit position
\r
527 asm mov dx,[ss:bx+2] // take bit1 path
\r
528 asm shl cl,1 // advance to next bit position
\r
529 asm jnc sourceupshort
\r
532 asm mov ch,[si] // load next byte
\r
534 asm mov cl,1 // back to first bit
\r
537 asm or dh,dh // if dx<256 its a byte, else move node
\r
538 asm jz storebyteshort
\r
539 asm mov bx,dx // next node = (huffnode *)code
\r
540 asm jmp expandshort
\r
544 asm inc di // write a decopmpressed byte out
\r
545 asm mov bx,[headptr] // back to the head node for next bit
\r
547 asm cmp di,ax // done?
\r
548 asm jne expandshort
\r
554 //--------------------------
\r
555 // expand more than 64k of data
\r
556 //--------------------------
\r
562 asm mov bx,[headptr]
\r
565 asm mov si,[sourceoff]
\r
566 asm mov di,[destoff]
\r
567 asm mov es,[destseg]
\r
568 asm mov ds,[sourceseg]
\r
570 asm lodsb // load first byte
\r
573 asm test al,cl // bit set?
\r
575 asm mov dx,[ss:bx] // take bit0 path from node
\r
578 asm mov dx,[ss:bx+2] // take bit1 path
\r
581 asm shl cl,1 // advance to next bit position
\r
584 asm cmp si,0x10 // normalize ds:si
\r
591 asm mov cl,1 // back to first bit
\r
594 asm or dh,dh // if dx<256 its a byte, else move node
\r
596 asm mov bx,dx // next node = (huffnode *)code
\r
601 asm inc di // write a decopmpressed byte out
\r
602 asm mov bx,[headptr] // back to the head node for next bit
\r
604 asm cmp di,0x10 // normalize es:di
\r
612 asm sub [WORD PTR ss:length],1
\r
614 asm dec [WORD PTR ss:length+2]
\r
615 asm jns expand // when length = ffff ffff, done
\r
629 ======================
\r
631 = CAL_CarmackExpand
\r
633 = Length is the length of the EXPANDED data
\r
635 ======================
\r
638 #define NEARTAG 0xa7
\r
639 #define FARTAG 0xa8
\r
641 void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned length)
\r
643 unsigned ch,chhigh,count,offset;
\r
644 unsigned far *copyptr, far *inptr, far *outptr;
\r
655 if (chhigh == NEARTAG)
\r
659 { // have to insert a word containing the tag byte
\r
660 ch |= *((unsigned char far *)inptr)++;
\r
666 offset = *((unsigned char far *)inptr)++;
\r
667 copyptr = outptr - offset;
\r
670 *outptr++ = *copyptr++;
\r
673 else if (chhigh == FARTAG)
\r
677 { // have to insert a word containing the tag byte
\r
678 ch |= *((unsigned char far *)inptr)++;
\r
685 copyptr = dest + offset;
\r
688 *outptr++ = *copyptr++;
\r
702 ======================
\r
706 ======================
\r
709 long CA_RLEWCompress (unsigned huge *source, long length, unsigned huge *dest,
\r
713 unsigned value,count,i;
\r
714 unsigned huge *start,huge *end;
\r
718 end = source + (length+1)/2;
\r
727 while (*source == value && source<end)
\r
732 if (count>3 || value == rlewtag)
\r
735 // send a tag / count / value string
\r
744 // send word without compressing
\r
746 for (i=1;i<=count;i++)
\r
750 } while (source<end);
\r
752 complength = 2*(dest-start);
\r
758 ======================
\r
761 = length is EXPANDED length
\r
763 ======================
\r
766 void CA_RLEWexpand (unsigned huge *source, unsigned huge *dest,long length,
\r
769 // unsigned value,count,i;
\r
770 unsigned huge *end;
\r
771 unsigned sourceseg,sourceoff,destseg,destoff,endseg,endoff;
\r
781 if (value != rlewtag)
\r
789 // compressed string
\r
793 for (i=1;i<=count;i++)
\r
796 } while (dest<end);
\r
799 end = dest + (length)/2;
\r
800 sourceseg = FP_SEG(source);
\r
801 sourceoff = FP_OFF(source);
\r
802 destseg = FP_SEG(dest);
\r
803 destoff = FP_OFF(dest);
\r
804 endseg = FP_SEG(end);
\r
805 endoff = FP_OFF(end);
\r
809 // ax = source value
\r
811 // cx = repeat counts
\r
814 // NOTE: A repeat count that produces 0xfff0 bytes can blow this!
\r
818 asm mov si,sourceoff
\r
821 asm mov ds,sourceseg
\r
832 asm mov cx,ax // repeat count
\r
833 asm lodsw // repeat value
\r
838 asm cmp si,0x10 // normalize ds:si
\r
850 asm cmp di,0x10 // normalize es:di
\r
863 asm cmp di,ss:endoff
\r
866 asm cmp ax,ss:endseg
\r
877 =============================================================================
\r
879 CACHE MANAGER ROUTINES
\r
881 =============================================================================
\r
885 ======================
\r
889 ======================
\r
892 /*void CAL_SetupGrFile (void)
\r
897 #ifdef GRHEADERLINKED
\r
899 #if GRMODE == EGAGR
\r
900 grhuffman = (huffnode *)&EGAdict;
\r
901 grstarts = (long _seg *)FP_SEG(&EGAhead);
\r
903 #if GRMODE == CGAGR
\r
904 grhuffman = (huffnode *)&CGAdict;
\r
905 grstarts = (long _seg *)FP_SEG(&CGAhead);
\r
908 CAL_OptimizeNodes (grhuffman);
\r
913 // load ???dict.ext (huffman dictionary for graphics files)
\r
916 if ((handle = open(GREXT"DICT."EXT,
\r
917 O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
918 Quit ("Can't open "GREXT"DICT."EXT"!");
\r
920 read(handle, &grhuffman, sizeof(grhuffman));
\r
922 CAL_OptimizeNodes (grhuffman);
\r
924 // load the data offsets from ???head.ext
\r
926 MM_GetPtr (&(memptr)grstarts,(NUMCHUNKS+1)*FILEPOSSIZE);
\r
928 if ((handle = open(GREXT"HEAD."EXT,
\r
929 O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
930 Quit ("Can't open "GREXT"HEAD."EXT"!");
\r
932 CA_FarRead(handle, (memptr)grstarts, (NUMCHUNKS+1)*FILEPOSSIZE);
\r
940 // Open the graphics file, leaving it open until the game is finished
\r
942 grhandle = open(GREXT"GRAPH."EXT, O_RDONLY | O_BINARY);
\r
943 if (grhandle == -1)
\r
944 Quit ("Cannot open "GREXT"GRAPH."EXT"!");
\r
948 // load the pic and sprite headers into the arrays in the data segment
\r
951 MM_GetPtr(&(memptr)pictable,NUMPICS*sizeof(pictabletype));
\r
952 CAL_GetGrChunkLength(STRUCTPIC); // position file pointer
\r
953 MM_GetPtr(&compseg,chunkcomplen);
\r
954 CA_FarRead (grhandle,compseg,chunkcomplen);
\r
955 CAL_HuffExpand (compseg, (byte huge *)pictable,NUMPICS*sizeof(pictabletype),grhuffman);
\r
956 MM_FreePtr(&compseg);
\r
960 MM_GetPtr(&(memptr)picmtable,NUMPICM*sizeof(pictabletype));
\r
961 CAL_GetGrChunkLength(STRUCTPICM); // position file pointer
\r
962 MM_GetPtr(&compseg,chunkcomplen);
\r
963 CA_FarRead (grhandle,compseg,chunkcomplen);
\r
964 CAL_HuffExpand (compseg, (byte huge *)picmtable,NUMPICS*sizeof(pictabletype),grhuffman);
\r
965 MM_FreePtr(&compseg);
\r
969 MM_GetPtr(&(memptr)spritetable,NUMSPRITES*sizeof(spritetabletype));
\r
970 CAL_GetGrChunkLength(STRUCTSPRITE); // position file pointer
\r
971 MM_GetPtr(&compseg,chunkcomplen);
\r
972 CA_FarRead (grhandle,compseg,chunkcomplen);
\r
973 CAL_HuffExpand (compseg, (byte huge *)spritetable,NUMSPRITES*sizeof(spritetabletype),grhuffman);
\r
974 MM_FreePtr(&compseg);
\r
979 //==========================================================================
\r
983 ======================
\r
987 ======================
\r
990 /*void CAL_SetupMapFile (void)
\r
996 // load maphead.ext (offsets and tileinfo for map file)
\r
998 #ifndef MAPHEADERLINKED
\r
999 if ((handle = open("MAPHEAD."EXT,
\r
1000 O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1001 Quit ("Can't open MAPHEAD."EXT"!");
\r
1002 length = filelength(handle);
\r
1003 MM_GetPtr (&(memptr)tinf,length);
\r
1004 CA_FarRead(handle, tinf, length);
\r
1008 tinf = (byte _seg *)FP_SEG(&maphead);
\r
1013 // open the data file
\r
1015 #ifdef MAPHEADERLINKED
\r
1016 if ((maphandle = open("GAMEMAPS."EXT,
\r
1017 O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1018 Quit ("Can't open GAMEMAPS."EXT"!");
\r
1020 if ((maphandle = open("MAPTEMP."EXT,
\r
1021 O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1022 Quit ("Can't open MAPTEMP."EXT"!");
\r
1026 //==========================================================================
\r
1030 ======================
\r
1032 = CAL_SetupAudioFile
\r
1034 ======================
\r
1037 /*void CAL_SetupAudioFile (void)
\r
1043 // load maphead.ext (offsets and tileinfo for map file)
\r
1045 #ifndef AUDIOHEADERLINKED
\r
1046 if ((handle = open("AUDIOHED."EXT,
\r
1047 O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1048 Quit ("Can't open AUDIOHED."EXT"!");
\r
1049 length = filelength(handle);
\r
1050 MM_GetPtr (&(memptr)audiostarts,length);
\r
1051 CA_FarRead(handle, (byte far *)audiostarts, length);
\r
1054 audiohuffman = (huffnode *)&audiodict;
\r
1055 CAL_OptimizeNodes (audiohuffman);
\r
1056 audiostarts = (long _seg *)FP_SEG(&audiohead);
\r
1060 // open the data file
\r
1062 #ifndef AUDIOHEADERLINKED
\r
1063 if ((audiohandle = open("AUDIOT."EXT,
\r
1064 O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1065 Quit ("Can't open AUDIOT."EXT"!");
\r
1067 if ((audiohandle = open("AUDIO."EXT,
\r
1068 O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1069 Quit ("Can't open AUDIO."EXT"!");
\r
1073 //==========================================================================
\r
1077 ======================
\r
1081 = Open all files and load in headers
\r
1083 ======================
\r
1086 void CA_Startup(global_game_variables_t *gvar)
\r
1089 #ifdef __BORLANDC__
\r
1090 unlink("profile.16b");
\r
1091 gvar->handle.profilehandle = open("profile.16b", O_CREAT | O_WRONLY | O_TEXT);
\r
1093 #ifdef __WATCOMC__
\r
1094 unlink("profile.16w");
\r
1095 gvar->handle.profilehandle = open("profile.16w", O_CREAT | O_WRONLY | O_TEXT);
\r
1098 // unlink("debug0.16");
\r
1099 // gvar->handle.showmemhandle = open("debug0.16", O_CREAT | O_WRONLY | O_TEXT);
\r
1101 // MDM begin - (GAMERS EDGE)
\r
1103 if(!FindFile("AUDIO."EXT,NULL,2))
\r
1104 Quit("CA_Startup(): Can't find audio files.");
\r
1109 CAL_SetupAudioFile();
\r
1112 // MDM begin - (GAMERS EDGE)
\r
1114 if (!FindFile("GAMEMAPS."EXT,NULL,1))
\r
1115 Quit("CA_Startup(): Can't find level files.");
\r
1120 CAL_SetupMapFile ();
\r
1123 // MDM begin - (GAMERS EDGE)
\r
1125 if (!FindFile("EGAGRAPH."EXT,NULL,2))
\r
1126 Quit("CA_Startup(): Can't find graphics files.");
\r
1130 #ifndef NOGRAPHICS
\r
1131 CAL_SetupGrFile ();
\r
1138 drawcachebox = CAL_DialogDraw;
\r
1139 updatecachebox = CAL_DialogUpdate;
\r
1140 finishcachebox = CAL_DialogFinish;*/
\r
1143 //==========================================================================
\r
1147 ======================
\r
1151 = Closes all files
\r
1153 ======================
\r
1156 void CA_Shutdown(global_game_variables_t *gvar)
\r
1159 close(gvar->handle.profilehandle);
\r
1161 // close(gvar->handle.showmemhandle);
\r
1165 close(audiohandle);*/
\r
1168 //===========================================================================
\r
1171 ======================
\r
1173 = CA_CacheAudioChunk
\r
1175 ======================
\r
1178 void CA_CacheAudioChunk (int chunk)
\r
1180 long pos,compressed;
\r
1181 #ifdef AUDIOHEADERLINKED
\r
1183 memptr bigbufferseg;
\r
1187 if (audiosegs[chunk])
\r
1189 MM_SetPurge (&(memptr)audiosegs[chunk],0);
\r
1190 return; // allready in memory
\r
1193 // MDM begin - (GAMERS EDGE)
\r
1195 if (!FindFile("AUDIO."EXT,NULL,2))
\r
1196 Quit("CA_CacheAudioChunk(): Can't find audio files.");
\r
1201 // load the chunk into a buffer, either the miscbuffer if it fits, or allocate
\r
1202 // a larger buffer
\r
1204 pos = audiostarts[chunk];
\r
1205 compressed = audiostarts[chunk+1]-pos;
\r
1207 lseek(audiohandle,pos,SEEK_SET);
\r
1209 #ifndef AUDIOHEADERLINKED
\r
1211 MM_GetPtr (&(memptr)audiosegs[chunk],compressed);
\r
1215 CA_FarRead(audiohandle,audiosegs[chunk],compressed);
\r
1219 if (compressed<=BUFFERSIZE)
\r
1221 CA_FarRead(audiohandle,bufferseg,compressed);
\r
1222 source = bufferseg;
\r
1226 MM_GetPtr(&bigbufferseg,compressed);
\r
1229 MM_SetLock (&bigbufferseg,true);
\r
1230 CA_FarRead(audiohandle,bigbufferseg,compressed);
\r
1231 source = bigbufferseg;
\r
1234 expanded = *(long far *)source;
\r
1235 source += 4; // skip over length
\r
1236 MM_GetPtr (&(memptr)audiosegs[chunk],expanded);
\r
1239 CAL_HuffExpand (source,audiosegs[chunk],expanded,audiohuffman);
\r
1242 if (compressed>BUFFERSIZE)
\r
1243 MM_FreePtr(&bigbufferseg);
\r
1247 //===========================================================================
\r
1250 ======================
\r
1252 = CA_LoadAllSounds
\r
1254 = Purges all sounds, then loads all new ones (mode switch)
\r
1256 ======================
\r
1259 void CA_LoadAllSounds (void)
\r
1263 switch (oldsoundmode)
\r
1268 start = STARTPCSOUNDS;
\r
1271 start = STARTADLIBSOUNDS;
\r
1275 for (i=0;i<NUMSOUNDS;i++,start++)
\r
1276 if (audiosegs[start])
\r
1277 MM_SetPurge (&(memptr)audiosegs[start],3); // make purgable
\r
1281 switch (SoundMode)
\r
1286 start = STARTPCSOUNDS;
\r
1289 start = STARTADLIBSOUNDS;
\r
1293 for (i=0;i<NUMSOUNDS;i++,start++)
\r
1294 CA_CacheAudioChunk (start);
\r
1296 oldsoundmode = SoundMode;
\r
1299 //===========================================================================
\r
1301 //++++#if GRMODE == EGAGR
\r
1304 ======================
\r
1308 = Make a shifted (one byte wider) copy of a sprite into another area
\r
1310 ======================
\r
1313 unsigned static sheight,swidth;
\r
1314 boolean static dothemask;
\r
1316 void CAL_ShiftSprite (unsigned segment,unsigned source,unsigned dest,
\r
1317 unsigned width, unsigned height, unsigned pixshift, boolean domask)
\r
1320 sheight = height; // because we are going to reassign bp
\r
1322 dothemask = domask;
\r
1324 asm mov ax,[segment]
\r
1325 asm mov ds,ax // source and dest are in same segment, and all local
\r
1327 asm mov bx,[source]
\r
1330 asm mov bp,[pixshift]
\r
1332 asm mov bp,WORD PTR [shifttabletable+bp] // bp holds pointer to shift table
\r
1334 asm cmp [ss:dothemask],0
\r
1338 // table shift the mask
\r
1340 asm mov dx,[ss:sheight]
\r
1344 asm mov BYTE PTR [di],255 // 0xff first byte
\r
1345 asm mov cx,ss:[swidth]
\r
1349 asm mov al,[bx] // source
\r
1351 asm inc bx // next source byte
\r
1355 asm mov ax,[bp+si] // table shift into two bytes
\r
1357 asm and [di],al // and with first byte
\r
1359 asm mov [di],ah // replace next byte
\r
1361 asm loop domaskbyte
\r
1363 asm inc di // the last shifted byte has 1s in it
\r
1370 // table shift the data
\r
1372 asm mov dx,ss:[sheight]
\r
1374 asm shl dx,1 // four planes of data
\r
1378 asm mov BYTE PTR [di],0 // 0 first byte
\r
1379 asm mov cx,ss:[swidth]
\r
1383 asm mov al,[bx] // source
\r
1384 asm inc bx // next source byte
\r
1388 asm mov ax,[bp+si] // table shift into two bytes
\r
1389 asm or [di],al // or with first byte
\r
1391 asm mov [di],ah // replace next byte
\r
1393 asm loop dodatabyte
\r
1395 asm inc di // the last shifted byte has 0s in it
\r
1403 asm mov ax,ss // restore data segment
\r
1410 //===========================================================================
\r
1413 ======================
\r
1417 = Generate shifts and set up sprite structure for a given sprite
\r
1419 ======================
\r
1422 void CAL_CacheSprite (int chunk, byte far *compressed)
\r
1425 unsigned shiftstarts[5];
\r
1426 unsigned smallplane,bigplane,expanded;
\r
1427 spritetabletype far *spr;
\r
1428 spritetype _seg *dest;
\r
1430 #if GRMODE == CGAGR
\r
1432 // CGA has no pel panning, so shifts are never needed
\r
1434 spr = &spritetable[chunk-STARTSPRITES];
\r
1435 smallplane = spr->width*spr->height;
\r
1436 MM_GetPtr (&grsegs[chunk],smallplane*2+MAXSHIFTS*6);
\r
1439 dest = (spritetype _seg *)grsegs[chunk];
\r
1440 dest->sourceoffset[0] = MAXSHIFTS*6; // start data after 3 unsigned tables
\r
1441 dest->planesize[0] = smallplane;
\r
1442 dest->width[0] = spr->width;
\r
1445 // expand the unshifted shape
\r
1447 CAL_HuffExpand (compressed, &dest->data[0],smallplane*2,grhuffman);
\r
1452 #if GRMODE == EGAGR
\r
1455 // calculate sizes
\r
1457 spr = &spritetable[chunk-STARTSPRITES];
\r
1458 smallplane = spr->width*spr->height;
\r
1459 bigplane = (spr->width+1)*spr->height;
\r
1461 shiftstarts[0] = MAXSHIFTS*6; // start data after 3 unsigned tables
\r
1462 shiftstarts[1] = shiftstarts[0] + smallplane*5; // 5 planes in a sprite
\r
1463 shiftstarts[2] = shiftstarts[1] + bigplane*5;
\r
1464 shiftstarts[3] = shiftstarts[2] + bigplane*5;
\r
1465 shiftstarts[4] = shiftstarts[3] + bigplane*5; // nothing ever put here
\r
1467 expanded = shiftstarts[spr->shifts];
\r
1468 MM_GetPtr (&grsegs[chunk],expanded);
\r
1471 dest = (spritetype _seg *)grsegs[chunk];
\r
1474 // expand the unshifted shape
\r
1476 CAL_HuffExpand (compressed, &dest->data[0],smallplane*5,grhuffman);
\r
1479 // make the shifts!
\r
1481 switch (spr->shifts)
\r
1486 dest->sourceoffset[i] = shiftstarts[0];
\r
1487 dest->planesize[i] = smallplane;
\r
1488 dest->width[i] = spr->width;
\r
1495 dest->sourceoffset[i] = shiftstarts[0];
\r
1496 dest->planesize[i] = smallplane;
\r
1497 dest->width[i] = spr->width;
\r
1501 dest->sourceoffset[i] = shiftstarts[1];
\r
1502 dest->planesize[i] = bigplane;
\r
1503 dest->width[i] = spr->width+1;
\r
1505 CAL_ShiftSprite ((unsigned)grsegs[chunk],dest->sourceoffset[0],
\r
1506 dest->sourceoffset[2],spr->width,spr->height,4,true);
\r
1510 dest->sourceoffset[0] = shiftstarts[0];
\r
1511 dest->planesize[0] = smallplane;
\r
1512 dest->width[0] = spr->width;
\r
1514 dest->sourceoffset[1] = shiftstarts[1];
\r
1515 dest->planesize[1] = bigplane;
\r
1516 dest->width[1] = spr->width+1;
\r
1517 CAL_ShiftSprite ((unsigned)grsegs[chunk],dest->sourceoffset[0],
\r
1518 dest->sourceoffset[1],spr->width,spr->height,2,true);
\r
1520 dest->sourceoffset[2] = shiftstarts[2];
\r
1521 dest->planesize[2] = bigplane;
\r
1522 dest->width[2] = spr->width+1;
\r
1523 CAL_ShiftSprite ((unsigned)grsegs[chunk],dest->sourceoffset[0],
\r
1524 dest->sourceoffset[2],spr->width,spr->height,4,true);
\r
1526 dest->sourceoffset[3] = shiftstarts[3];
\r
1527 dest->planesize[3] = bigplane;
\r
1528 dest->width[3] = spr->width+1;
\r
1529 CAL_ShiftSprite ((unsigned)grsegs[chunk],dest->sourceoffset[0],
\r
1530 dest->sourceoffset[3],spr->width,spr->height,6,true);
\r
1535 Quit ("CAL_CacheSprite: Bad shifts number!");
\r
1541 //===========================================================================
\r
1545 ======================
\r
1547 = CAL_ExpandGrChunk
\r
1549 = Does whatever is needed with a pointer to a compressed chunk
\r
1551 ======================
\r
1554 void CAL_ExpandGrChunk (int chunk, byte far *source)
\r
1559 if (chunk >= STARTTILE8 && chunk < STARTEXTERNS)
\r
1562 // expanded sizes of tile8/16/32 are implicit
\r
1565 #if GRMODE == EGAGR
\r
1567 #define MASKBLOCK 40
\r
1570 #if GRMODE == CGAGR
\r
1572 #define MASKBLOCK 32
\r
1575 if (chunk<STARTTILE8M) // tile 8s are all in one chunk!
\r
1576 expanded = BLOCK*NUMTILE8;
\r
1577 else if (chunk<STARTTILE16)
\r
1578 expanded = MASKBLOCK*NUMTILE8M;
\r
1579 else if (chunk<STARTTILE16M) // all other tiles are one/chunk
\r
1580 expanded = BLOCK*4;
\r
1581 else if (chunk<STARTTILE32)
\r
1582 expanded = MASKBLOCK*4;
\r
1583 else if (chunk<STARTTILE32M)
\r
1584 expanded = BLOCK*16;
\r
1586 expanded = MASKBLOCK*16;
\r
1591 // everything else has an explicit size longword
\r
1593 expanded = *(long far *)source;
\r
1594 source += 4; // skip over length
\r
1598 // allocate final space, decompress it, and free bigbuffer
\r
1599 // Sprites need to have shifts made and various other junk
\r
1601 if (chunk>=STARTSPRITES && chunk< STARTTILE8)
\r
1602 CAL_CacheSprite(chunk,source);
\r
1605 MM_GetPtr (&grsegs[chunk],expanded);
\r
1608 CAL_HuffExpand (source,grsegs[chunk],expanded,grhuffman);
\r
1614 ======================
\r
1618 = Gets a chunk off disk, optimizing reads to general buffer
\r
1620 ======================
\r
1623 void CAL_ReadGrChunk (int chunk)
\r
1625 long pos,compressed;
\r
1626 memptr bigbufferseg;
\r
1631 // load the chunk into a buffer, either the miscbuffer if it fits, or allocate
\r
1632 // a larger buffer
\r
1634 pos = GRFILEPOS(chunk);
\r
1635 if (pos<0) // $FFFFFFFF start is a sparse tile
\r
1639 while (GRFILEPOS(next) == -1) // skip past any sparse tiles
\r
1642 compressed = GRFILEPOS(next)-pos;
\r
1644 lseek(grhandle,pos,SEEK_SET);
\r
1646 if (compressed<=BUFFERSIZE)
\r
1648 CA_FarRead(grhandle,bufferseg,compressed);
\r
1649 source = bufferseg;
\r
1653 MM_GetPtr(&bigbufferseg,compressed);
\r
1656 MM_SetLock (&bigbufferseg,true);
\r
1657 CA_FarRead(grhandle,bigbufferseg,compressed);
\r
1658 source = bigbufferseg;
\r
1661 CAL_ExpandGrChunk (chunk,source);
\r
1663 if (compressed>BUFFERSIZE)
\r
1664 MM_FreePtr(&bigbufferseg);
\r
1668 ======================
\r
1672 = Makes sure a given chunk is in memory, loadiing it if needed
\r
1674 ======================
\r
1677 void CA_CacheGrChunk (int chunk)
\r
1679 long pos,compressed;
\r
1680 memptr bigbufferseg;
\r
1684 grneeded[chunk] |= ca_levelbit; // make sure it doesn't get removed
\r
1685 if (grsegs[chunk])
\r
1687 MM_SetPurge (&grsegs[chunk],0);
\r
1688 return; // allready in memory
\r
1691 // MDM begin - (GAMERS EDGE)
\r
1693 if (!FindFile("EGAGRAPH."EXT,NULL,2))
\r
1694 Quit("CA_CacheGrChunk(): Can't find graphics files.");
\r
1699 // load the chunk into a buffer, either the miscbuffer if it fits, or allocate
\r
1700 // a larger buffer
\r
1702 pos = GRFILEPOS(chunk);
\r
1703 if (pos<0) // $FFFFFFFF start is a sparse tile
\r
1707 while (GRFILEPOS(next) == -1) // skip past any sparse tiles
\r
1710 compressed = GRFILEPOS(next)-pos;
\r
1712 lseek(grhandle,pos,SEEK_SET);
\r
1714 if (compressed<=BUFFERSIZE)
\r
1716 CA_FarRead(grhandle,bufferseg,compressed);
\r
1717 source = bufferseg;
\r
1721 MM_GetPtr(&bigbufferseg,compressed);
\r
1722 MM_SetLock (&bigbufferseg,true);
\r
1723 CA_FarRead(grhandle,bigbufferseg,compressed);
\r
1724 source = bigbufferseg;
\r
1727 CAL_ExpandGrChunk (chunk,source);
\r
1729 if (compressed>BUFFERSIZE)
\r
1730 MM_FreePtr(&bigbufferseg);
\r
1735 //==========================================================================
\r
1738 ======================
\r
1742 ======================
\r
1745 void CA_CacheMap (int mapnum)
\r
1747 long pos,compressed;
\r
1749 memptr *dest,bigbufferseg;
\r
1751 unsigned far *source;
\r
1752 #ifdef MAPHEADERLINKED
\r
1753 memptr buffer2seg;
\r
1758 // MDM begin - (GAMERS EDGE)
\r
1760 if (!FindFile("GAMEMAPS."EXT,NULL,1))
\r
1761 Quit("CA_CacheMap(): Can't find level files.");
\r
1767 // free up memory from last map
\r
1769 if (mapon>-1 && mapheaderseg[mapon])
\r
1770 MM_SetPurge (&(memptr)mapheaderseg[mapon],3);
\r
1771 for (plane=0;plane<MAPPLANES;plane++)
\r
1772 if (mapsegs[plane])
\r
1773 MM_FreePtr (&(memptr)mapsegs[plane]);
\r
1779 // load map header
\r
1780 // The header will be cached if it is still around
\r
1782 if (!mapheaderseg[mapnum])
\r
1784 pos = ((mapfiletype _seg *)tinf)->headeroffsets[mapnum];
\r
1785 if (pos<0) // $FFFFFFFF start is a sparse map
\r
1786 Quit ("CA_CacheMap: Tried to load a non existent map!");
\r
1788 MM_GetPtr(&(memptr)mapheaderseg[mapnum],sizeof(maptype));
\r
1789 lseek(maphandle,pos,SEEK_SET);
\r
1790 CA_FarRead (maphandle,(memptr)mapheaderseg[mapnum],sizeof(maptype));
\r
1793 MM_SetPurge (&(memptr)mapheaderseg[mapnum],0);
\r
1796 // load the planes in
\r
1797 // If a plane's pointer still exists it will be overwritten (levels are
\r
1798 // allways reloaded, never cached)
\r
1801 size = mapheaderseg[mapnum]->width * mapheaderseg[mapnum]->height * 2;
\r
1803 for (plane = 0; plane<MAPPLANES; plane++)
\r
1805 pos = mapheaderseg[mapnum]->planestart[plane];
\r
1806 compressed = mapheaderseg[mapnum]->planelength[plane];
\r
1809 continue; // the plane is not used in this game
\r
1811 dest = &(memptr)mapsegs[plane];
\r
1812 MM_GetPtr(dest,size);
\r
1814 lseek(maphandle,pos,SEEK_SET);
\r
1815 if (compressed<=BUFFERSIZE)
\r
1816 source = bufferseg;
\r
1819 MM_GetPtr(&bigbufferseg,compressed);
\r
1820 MM_SetLock (&bigbufferseg,true);
\r
1821 source = bigbufferseg;
\r
1824 CA_FarRead(maphandle,(byte far *)source,compressed);
\r
1825 #ifdef MAPHEADERLINKED
\r
1827 // unhuffman, then unRLEW
\r
1828 // The huffman'd chunk has a two byte expanded length first
\r
1829 // The resulting RLEW chunk also does, even though it's not really
\r
1832 expanded = *source;
\r
1834 MM_GetPtr (&buffer2seg,expanded);
\r
1835 CAL_CarmackExpand (source, (unsigned far *)buffer2seg,expanded);
\r
1836 CA_RLEWexpand (((unsigned far *)buffer2seg)+1,*dest,size,
\r
1837 ((mapfiletype _seg *)tinf)->RLEWtag);
\r
1838 MM_FreePtr (&buffer2seg);
\r
1842 // unRLEW, skipping expanded length
\r
1844 CA_RLEWexpand (source+1, *dest,size,
\r
1845 ((mapfiletype _seg *)tinf)->RLEWtag);
\r
1848 if (compressed>BUFFERSIZE)
\r
1849 MM_FreePtr(&bigbufferseg);
\r
1853 //===========================================================================
\r
1856 ======================
\r
1860 = Goes up a bit level in the needed lists and clears it out.
\r
1861 = Everything is made purgable
\r
1863 ======================
\r
1866 void CA_UpLevel (void)
\r
1868 if (ca_levelnum==7)
\r
1869 Quit ("CA_UpLevel: Up past level 7!");
\r
1875 //===========================================================================
\r
1878 ======================
\r
1882 = Goes down a bit level in the needed lists and recaches
\r
1883 = everything from the lower level
\r
1885 ======================
\r
1888 void CA_DownLevel (void)
\r
1891 Quit ("CA_DownLevel: Down past level 0!");
\r
1894 CA_CacheMarks(NULL);
\r
1897 //===========================================================================
\r
1900 ======================
\r
1904 = Clears out all the marks at the current level
\r
1906 ======================
\r
1909 void CA_ClearMarks (void)
\r
1913 for (i=0;i<NUMCHUNKS;i++)
\r
1914 grneeded[i]&=~ca_levelbit;
\r
1918 //===========================================================================
\r
1921 ======================
\r
1923 = CA_ClearAllMarks
\r
1925 = Clears out all the marks on all the levels
\r
1927 ======================
\r
1930 void CA_ClearAllMarks (void)
\r
1932 _fmemset (grneeded,0,sizeof(grneeded));
\r
1938 //===========================================================================
\r
1941 ======================
\r
1945 ======================
\r
1948 void CA_FreeGraphics (void)
\r
1952 for (i=0;i<NUMCHUNKS;i++)
\r
1954 MM_SetPurge (&(memptr)grsegs[i],3);
\r
1959 ======================
\r
1963 = Make everything possible purgable
\r
1965 ======================
\r
1968 void CA_SetAllPurge (void)
\r
1975 // free cursor sprite and background save
\r
1980 // free map headers and map planes
\r
1982 for (i=0;i<NUMMAPS;i++)
\r
1983 if (mapheaderseg[i])
\r
1984 MM_SetPurge (&(memptr)mapheaderseg[i],3);
\r
1988 MM_FreePtr (&(memptr)mapsegs[i]);
\r
1993 for (i=0;i<NUMSNDCHUNKS;i++)
\r
1995 MM_SetPurge (&(memptr)audiosegs[i],3);
\r
2000 CA_FreeGraphics ();
\r
2004 void CA_SetGrPurge (void)
\r
2011 for (i=0;i<NUMCHUNKS;i++)
\r
2013 MM_SetPurge (&(memptr)grsegs[i],3);
\r
2017 //===========================================================================
\r
2021 ======================
\r
2025 ======================
\r
2028 #define NUMBARS (17l*8)
\r
2031 unsigned thx,thy,lastx;
\r
2032 long barx,barstep;
\r
2034 void CAL_DialogDraw (char *title,unsigned numcache)
\r
2036 unsigned homex,homey,x;
\r
2038 barstep = (NUMBARS<<16)/numcache;
\r
2041 // draw dialog window (masked tiles 12 - 20 are window borders)
\r
2043 US_CenterWindow (20,8);
\r
2047 US_CPrint ("Loading");
\r
2048 fontcolor = F_SECONDCOLOR;
\r
2049 US_CPrint (title);
\r
2050 fontcolor = F_BLACK;
\r
2053 // draw thermometer bar
\r
2057 VWB_DrawTile8(thx,thy,0); // CAT3D numbers
\r
2058 VWB_DrawTile8(thx,thy+8,3);
\r
2059 VWB_DrawTile8(thx,thy+16,6);
\r
2060 VWB_DrawTile8(thx+17*8,thy,2);
\r
2061 VWB_DrawTile8(thx+17*8,thy+8,5);
\r
2062 VWB_DrawTile8(thx+17*8,thy+16,8);
\r
2063 for (x=thx+8;x<thx+17*8;x+=8)
\r
2065 VWB_DrawTile8(x,thy,1);
\r
2066 VWB_DrawTile8(x,thy+8,4);
\r
2067 VWB_DrawTile8(x,thy+16,7);
\r
2070 thx += 4; // first line location
\r
2072 barx = (long)thx<<16;
\r
2075 VW_UpdateScreen();
\r
2080 ======================
\r
2082 = CAL_DialogUpdate
\r
2084 ======================
\r
2087 void CAL_DialogUpdate (void)
\r
2093 if (xh - lastx > BARSTEP)
\r
2095 for (x=lastx;x<=xh;x++)
\r
2096 #if GRMODE == EGAGR
\r
2097 VWB_Vlin (thy,thy+13,x,14);
\r
2099 #if GRMODE == CGAGR
\r
2100 VWB_Vlin (thy,thy+13,x,SECONDCOLOR);
\r
2103 VW_UpdateScreen();
\r
2108 ======================
\r
2110 = CAL_DialogFinish
\r
2112 ======================
\r
2115 void CAL_DialogFinish (void)
\r
2119 xh = thx + NUMBARS;
\r
2120 for (x=lastx;x<=xh;x++)
\r
2121 #if GRMODE == EGAGR
\r
2122 VWB_Vlin (thy,thy+13,x,14);
\r
2124 #if GRMODE == CGAGR
\r
2125 VWB_Vlin (thy,thy+13,x,SECONDCOLOR);
\r
2127 VW_UpdateScreen();
\r
2131 //===========================================================================
\r
2134 ======================
\r
2138 ======================
\r
2140 #define MAXEMPTYREAD 1024
\r
2142 void CA_CacheMarks (char *title)
\r
2145 int i,next,numcache;
\r
2146 long pos,endpos,nextpos,nextendpos,compressed;
\r
2147 long bufferstart,bufferend; // file position of general buffer
\r
2149 memptr bigbufferseg;
\r
2151 dialog = (title!=NULL);
\r
2155 // go through and make everything not needed purgable
\r
2157 for (i=0;i<NUMCHUNKS;i++)
\r
2158 if (grneeded[i]&ca_levelbit)
\r
2160 if (grsegs[i]) // its allready in memory, make
\r
2161 MM_SetPurge(&grsegs[i],0); // sure it stays there!
\r
2167 if (grsegs[i]) // not needed, so make it purgeable
\r
2168 MM_SetPurge(&grsegs[i],3);
\r
2171 if (!numcache) // nothing to cache!
\r
2174 // MDM begin - (GAMERS EDGE)
\r
2176 if (!FindFile("EGAGRAPH."EXT,NULL,2))
\r
2177 Quit("CA_CacheMarks(): Can't find graphics files.");
\r
2184 write(profilehandle,title,strlen(title));
\r
2185 write(profilehandle,"\n",1);
\r
2188 drawcachebox(title,numcache);
\r
2192 // go through and load in anything still needed
\r
2194 bufferstart = bufferend = 0; // nothing good in buffer now
\r
2196 for (i=0;i<NUMCHUNKS;i++)
\r
2197 if ( (grneeded[i]&ca_levelbit) && !grsegs[i])
\r
2200 // update thermometer
\r
2202 if (dialog && updatecachebox)
\r
2203 updatecachebox ();
\r
2205 pos = GRFILEPOS(i);
\r
2210 while (GRFILEPOS(next) == -1) // skip past any sparse tiles
\r
2213 compressed = GRFILEPOS(next)-pos;
\r
2214 endpos = pos+compressed;
\r
2216 if (compressed<=BUFFERSIZE)
\r
2218 if (bufferstart<=pos
\r
2219 && bufferend>= endpos)
\r
2221 // data is allready in buffer
\r
2222 source = (byte _seg *)bufferseg+(pos-bufferstart);
\r
2226 // load buffer with a new block from disk
\r
2227 // try to get as many of the needed blocks in as possible
\r
2228 while ( next < NUMCHUNKS )
\r
2230 while (next < NUMCHUNKS &&
\r
2231 !(grneeded[next]&ca_levelbit && !grsegs[next]))
\r
2233 if (next == NUMCHUNKS)
\r
2236 nextpos = GRFILEPOS(next);
\r
2237 while (GRFILEPOS(++next) == -1) // skip past any sparse tiles
\r
2239 nextendpos = GRFILEPOS(next);
\r
2240 if (nextpos - endpos <= MAXEMPTYREAD
\r
2241 && nextendpos-pos <= BUFFERSIZE)
\r
2242 endpos = nextendpos;
\r
2244 next = NUMCHUNKS; // read pos to posend
\r
2247 lseek(grhandle,pos,SEEK_SET);
\r
2248 CA_FarRead(grhandle,bufferseg,endpos-pos);
\r
2249 bufferstart = pos;
\r
2250 bufferend = endpos;
\r
2251 source = bufferseg;
\r
2256 // big chunk, allocate temporary buffer
\r
2257 MM_GetPtr(&bigbufferseg,compressed);
\r
2260 MM_SetLock (&bigbufferseg,true);
\r
2261 lseek(grhandle,pos,SEEK_SET);
\r
2262 CA_FarRead(grhandle,bigbufferseg,compressed);
\r
2263 source = bigbufferseg;
\r
2266 CAL_ExpandGrChunk (i,source);
\r
2270 if (compressed>BUFFERSIZE)
\r
2271 MM_FreePtr(&bigbufferseg);
\r
2276 // finish up any thermometer remnants
\r
2278 if (dialog && finishcachebox)
\r