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
40 //https://github.com/open-watcom/open-watcom-v2/issues/279#issuecomment-244587566 for _seg
\r
42 =============================================================================
\r
46 =============================================================================
\r
51 word 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
81 void (*drawcachebox) (char *title, unsigned numcache);
\r
82 void (*updatecachebox) (void);
\r
83 void (*finishcachebox) (void);
\r
86 =============================================================================
\r
90 =============================================================================
\r
93 /*extern long far CGAhead;
\r
94 extern long far EGAhead;
\r
95 extern byte CGAdict;
\r
96 extern byte EGAdict;
\r
97 extern byte far maphead;
\r
98 extern byte mapdict;
\r
99 extern byte far audiohead;
\r
100 extern byte audiodict;
\r
103 long _seg *grstarts; // array of offsets in egagraph, -1 for sparse
\r
104 long _seg *audiostarts; // array of offsets in audio / audiot
\r
106 #ifdef GRHEADERLINKED
\r
107 huffnode *grhuffman;
\r
109 huffnode grhuffman[255];
\r
112 #ifdef AUDIOHEADERLINKED
\r
113 huffnode *audiohuffman;
\r
115 huffnode audiohuffman[255];
\r
119 int grhandle; // handle to EGAGRAPH
\r
120 int maphandle; // handle to MAPTEMP / GAMEMAPS
\r
121 int audiohandle; // handle to AUDIOT / AUDIO
\r
123 long chunkcomplen,chunkexplen;
\r
125 SDMode oldsoundmode;
\r
129 void CAL_DialogDraw (char *title,unsigned numcache);
\r
130 void CAL_DialogUpdate (void);
\r
131 void CAL_DialogFinish (void);*/
\r
132 //void CAL_CarmackExpand (unsigned far *source, unsigned far *dest,unsigned length);
\r
135 /*++++#ifdef THREEBYTEGRSTARTS
\r
136 #define FILEPOSSIZE 3
\r
137 //#define GRFILEPOS(c) (*(long far *)(((byte far *)grstarts)+(c)*3)&0xffffff)
\r
138 long GRFILEPOS(int c)
\r
145 value = *(long far *)(((byte far *)grstarts)+offset);
\r
147 value &= 0x00ffffffl;
\r
149 if (value == 0xffffffl)
\r
155 #define FILEPOSSIZE 4
\r
156 #define GRFILEPOS(c) (grstarts[c])
\r
160 =============================================================================
\r
164 =============================================================================
\r
168 ============================
\r
170 = CA_OpenDebug / CA_CloseDebug
\r
172 = Opens a binary file with the handle "debughandle"
\r
174 ============================
\r
176 void CA_OpenDebug(global_game_variables_t *gvar)
\r
178 #ifdef __BORLANDC__
\r
179 unlink("debug.16b");
\r
180 gvar->handle.debughandle = open("debug.16b", O_CREAT | O_WRONLY | O_TEXT);
\r
183 unlink("debug.16w");
\r
184 gvar->handle.debughandle = open("debug.16w", O_CREAT | O_WRONLY | O_TEXT);
\r
188 void CA_CloseDebug(global_game_variables_t *gvar)
\r
190 close(gvar->handle.debughandle);
\r
196 ============================
\r
198 = CAL_GetGrChunkLength
\r
200 = Gets the length of an explicit length chunk (not tiles)
\r
201 = The file pointer is positioned so the compressed data can be read in next.
\r
203 ============================
\r
206 void CAL_GetGrChunkLength (int chunk)
\r
208 lseek(grhandle,GRFILEPOS(chunk),SEEK_SET);
\r
209 read(grhandle,&chunkexplen,sizeof(chunkexplen));
\r
210 chunkcomplen = GRFILEPOS(chunk+1)-GRFILEPOS(chunk)-4;
\r
215 ==========================
\r
219 = Read from a file to a far pointer
\r
221 ==========================
\r
224 boolean CA_FarRead(int handle, byte huge *dest, dword length, global_game_variables_t *gvar)
\r
229 if(gvar->mm.EMSVer<0x40)
\r
230 if(length>0xfffflu)
\r
232 printf("File is a fat bakapee\n");
\r
233 //segm=(length%0xfffflu)-1;
\r
234 //fat=segm*0xfffflu;
\r
236 printf("CA_FarRead doesn't support 64K reads yet!\n");
\r
237 return 0;//TODO: EXPAND!!!
\r
245 mov cx,[WORD PTR length]
\r
246 mov dx,[WORD PTR dest]
\r
247 mov ds,[WORD PTR dest+2]
\r
248 mov ah,0x3f // READ w/handle
\r
255 #ifdef __BORLANDC__
\r
259 #ifdef __BORLANDC__
\r
262 cmp ax,[WORD PTR length]
\r
264 // errno = EINVFMT; // user manager knows this is bad read
\r
267 #ifdef __BORLANDC__
\r
271 #ifdef __BORLANDC__
\r
275 #ifdef __BORLANDC__
\r
287 ==========================
\r
291 = Write from a file to a far pointer
\r
293 ==========================
\r
296 boolean CA_FarWrite(int handle, byte huge *source, dword length, global_game_variables_t *gvar)
\r
301 if(gvar->mm.EMSVer<0x40)
\r
302 if(length>0xfffflu)
\r
304 printf("File is a fat bakapee\n");
\r
305 //segm=(length%0xfffflu)-1;
\r
306 //fat=segm*0xfffflu;
\r
308 printf("CA_FarRead doesn't support 64K reads yet!\n");
\r
317 mov cx,[WORD PTR length]
\r
318 mov dx,[WORD PTR source]
\r
319 mov ds,[WORD PTR source+2]
\r
320 mov ah,0x40 // WRITE w/handle
\r
327 #ifdef __BORLANDC__
\r
331 #ifdef __BORLANDC__
\r
334 cmp ax,[WORD PTR length]
\r
336 //errno = ENOMEM; // user manager knows this is bad write
\r
339 #ifdef __BORLANDC__
\r
343 #ifdef __BORLANDC__
\r
347 #ifdef __BORLANDC__
\r
359 ==========================
\r
363 = Reads a file into an allready allocated buffer
\r
365 ==========================
\r
368 boolean CA_ReadFile(char *filename, memptr *ptr, global_game_variables_t *gvar)
\r
374 if((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
377 size = filelength(handle);
\r
378 if(!CA_FarRead(handle,*ptr,size, gvar))
\r
389 ==========================
\r
393 = Writes a file from a memory buffer
\r
395 ==========================
\r
398 boolean CA_WriteFile (char *filename, void far *ptr, long length, global_game_variables_t *gvar)
\r
404 handle = open(filename,O_CREAT | O_BINARY | O_WRONLY,
\r
405 S_IREAD | S_IWRITE | S_IFREG);
\r
410 if (!CA_FarWrite (handle,ptr,length, gvar))
\r
422 ==========================
\r
426 = Allocate space for and load a file
\r
428 ==========================
\r
431 boolean CA_LoadFile(char *filename, memptr *ptr, global_game_variables_t *gvar)
\r
437 if((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
440 size = filelength(handle);
\r
441 MM_GetPtr(ptr,size, &(gvar->mm), &(gvar->mmi)); //TODO: gvar parameters
\r
442 if(!CA_FarRead(handle,*ptr,size, gvar))
\r
452 ============================================================================
\r
454 COMPRESSION routines, see JHUFF.C for more
\r
456 ============================================================================
\r
464 = CAL_OptimizeNodes
\r
466 = Goes through a huffman table and changes the 256-511 node numbers to the
\r
467 = actular address of the node. Must be called before CAL_HuffExpand
\r
472 void CAL_OptimizeNodes(huffnode *table)
\r
479 for (i=0;i<255;i++)
\r
481 if (node->bit0 >= 256)
\r
482 node->bit0 = (unsigned)(table+(node->bit0-256));
\r
483 if (node->bit1 >= 256)
\r
484 node->bit1 = (unsigned)(table+(node->bit1-256));
\r
492 ======================
\r
496 = Length is the length of the EXPANDED data
\r
498 ======================
\r
501 void CAL_HuffExpand (byte huge *source, byte huge *dest,
\r
502 long length,huffnode *hufftable)
\r
504 // unsigned bit,byte,node,code;
\r
505 unsigned sourceseg,sourceoff,destseg,destoff,endoff;
\r
507 // huffnode *nodeon;
\r
509 headptr = hufftable+254; // head node is allways node 254
\r
511 source++; // normalize
\r
516 sourceseg = FP_SEG(source);
\r
517 sourceoff = FP_OFF(source);
\r
518 destseg = FP_SEG(dest);
\r
519 destoff = FP_OFF(dest);
\r
520 endoff = destoff+length;
\r
525 // ss:bx node pointer
\r
528 if (length <0xfff0)
\r
531 //--------------------------
\r
532 // expand less than 64k of data
\r
533 //--------------------------
\r
536 //// mov bx,[headptr]
\r
544 mov ch,[si] // load first byte
\r
547 #ifdef __BORLANDC__
\r
551 #ifdef __BORLANDC__
\r
554 test ch,cl // bit set?
\r
556 mov dx,[ss:bx] // take bit0 path from node
\r
557 shl cl,1 // advance to next bit position
\r
560 #ifdef __BORLANDC__
\r
564 #ifdef __BORLANDC__
\r
567 mov dx,[ss:bx+2] // take bit1 path
\r
568 shl cl,1 // advance to next bit position
\r
570 #ifdef __BORLANDC__
\r
574 #ifdef __BORLANDC__
\r
577 mov ch,[si] // load next byte
\r
579 mov cl,1 // back to first bit
\r
580 #ifdef __BORLANDC__
\r
584 #ifdef __BORLANDC__
\r
587 or dh,dh // if dx<256 its a byte, else move node
\r
589 mov bx,dx // next node = (huffnode *)code
\r
591 #ifdef __BORLANDC__
\r
595 #ifdef __BORLANDC__
\r
599 inc di // write a decopmpressed byte out
\r
600 //// mov bx,[headptr] // back to the head node for next bit
\r
609 //--------------------------
\r
610 // expand more than 64k of data
\r
611 //--------------------------
\r
616 //// mov bx,[headptr]
\r
624 lodsb // load first byte
\r
625 #ifdef __BORLANDC__
\r
629 #ifdef __BORLANDC__
\r
632 test al,cl // bit set?
\r
634 mov dx,[ss:bx] // take bit0 path from node
\r
636 #ifdef __BORLANDC__
\r
640 #ifdef __BORLANDC__
\r
643 mov dx,[ss:bx+2] // take bit1 path
\r
644 #ifdef __BORLANDC__
\r
648 #ifdef __BORLANDC__
\r
651 shl cl,1 // advance to next bit position
\r
654 cmp si,0x10 // normalize ds:si
\r
660 #ifdef __BORLANDC__
\r
664 #ifdef __BORLANDC__
\r
667 mov cl,1 // back to first bit
\r
668 #ifdef __BORLANDC__
\r
672 #ifdef __BORLANDC__
\r
675 or dh,dh // if dx<256 its a byte, else move node
\r
677 mov bx,dx // next node = (huffnode *)code
\r
679 #ifdef __BORLANDC__
\r
683 #ifdef __BORLANDC__
\r
687 inc di // write a decopmpressed byte out
\r
688 //// mov bx,[headptr] // back to the head node for next bit
\r
690 cmp di,0x10 // normalize es:di
\r
696 #ifdef __BORLANDC__
\r
700 #ifdef __BORLANDC__
\r
703 sub [WORD PTR ss:length],1
\r
705 dec [WORD PTR ss:length+2]
\r
706 jns expand // when length = ffff ffff, done
\r
719 ======================
\r
721 = CAL_CarmackExpand
\r
723 = Length is the length of the EXPANDED data
\r
725 ======================
\r
728 #define NEARTAG 0xa7
\r
729 #define FARTAG 0xa8
\r
731 void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned length)
\r
733 unsigned ch,chhigh,count,offset;
\r
734 unsigned far *copyptr, far *inptr, far *outptr;
\r
745 if (chhigh == NEARTAG)
\r
749 { // have to insert a word containing the tag byte
\r
750 ch |= *(/*(unsigned char far *)*/inptr)++;
\r
756 offset = *(/*(unsigned char far *)*/inptr)++;
\r
757 copyptr = outptr - offset;
\r
760 *outptr++ = *copyptr++;
\r
763 else if (chhigh == FARTAG)
\r
767 { // have to insert a word containing the tag byte
\r
768 ch |= *(/*(unsigned char far *)*/inptr)++;
\r
775 copyptr = dest + offset;
\r
778 *outptr++ = *copyptr++;
\r
791 ======================
\r
795 ======================
\r
798 long CA_RLEWCompress (unsigned huge *source, long length, unsigned huge *dest,
\r
802 unsigned value,count,i;
\r
803 unsigned huge *start,huge *end;
\r
807 end = source + (length+1)/2;
\r
816 while (*source == value && source<end)
\r
821 if (count>3 || value == rlewtag)
\r
824 // send a tag / count / value string
\r
833 // send word without compressing
\r
835 for (i=1;i<=count;i++)
\r
839 } while (source<end);
\r
841 complength = 2*(dest-start);
\r
847 ======================
\r
850 = length is EXPANDED length
\r
852 ======================
\r
855 void CA_RLEWexpand (unsigned huge *source, unsigned huge *dest,long length,
\r
858 // unsigned value,count,i;
\r
859 unsigned huge *end;
\r
860 unsigned sourceseg,sourceoff,destseg,destoff,endseg,endoff;
\r
870 if (value != rlewtag)
\r
878 // compressed string
\r
882 for (i=1;i<=count;i++)
\r
885 } while (dest<end);
\r
888 end = dest + (length)/2;
\r
889 sourceseg = FP_SEG(source);
\r
890 sourceoff = FP_OFF(source);
\r
891 destseg = FP_SEG(dest);
\r
892 destoff = FP_OFF(dest);
\r
893 endseg = FP_SEG(end);
\r
894 endoff = FP_OFF(end);
\r
898 // ax = source value
\r
900 // cx = repeat counts
\r
903 // NOTE: A repeat count that produces 0xfff0 bytes can blow this!
\r
911 #ifdef __BORLANDC__
\r
915 #ifdef __BORLANDC__
\r
923 #ifdef __BORLANDC__
\r
927 #ifdef __BORLANDC__
\r
931 mov cx,ax // repeat count
\r
932 lodsw // repeat value
\r
934 #ifdef __BORLANDC__
\r
938 #ifdef __BORLANDC__
\r
941 cmp si,0x10 // normalize ds:si
\r
952 #ifdef __BORLANDC__
\r
956 #ifdef __BORLANDC__
\r
959 cmp di,0x10 // normalize es:di
\r
970 #ifdef __BORLANDC__
\r
974 #ifdef __BORLANDC__
\r
990 =============================================================================
\r
992 CACHE MANAGER ROUTINES
\r
994 =============================================================================
\r
998 ======================
\r
1002 ======================
\r
1005 /*void CAL_SetupGrFile (void)
\r
1010 #ifdef GRHEADERLINKED
\r
1012 #if GRMODE == EGAGR
\r
1013 grhuffman = (huffnode *)&EGAdict;
\r
1014 grstarts = (long _seg *)FP_SEG(&EGAhead);
\r
1016 #if GRMODE == CGAGR
\r
1017 grhuffman = (huffnode *)&CGAdict;
\r
1018 grstarts = (long _seg *)FP_SEG(&CGAhead);
\r
1021 CAL_OptimizeNodes (grhuffman);
\r
1026 // load ???dict.ext (huffman dictionary for graphics files)
\r
1029 if ((handle = open(GREXT"DICT."EXT,
\r
1030 O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1031 Quit ("Can't open "GREXT"DICT."EXT"!");
\r
1033 read(handle, &grhuffman, sizeof(grhuffman));
\r
1035 CAL_OptimizeNodes (grhuffman);
\r
1037 // load the data offsets from ???head.ext
\r
1039 MM_GetPtr (&(memptr)grstarts,(NUMCHUNKS+1)*FILEPOSSIZE);
\r
1041 if ((handle = open(GREXT"HEAD."EXT,
\r
1042 O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1043 Quit ("Can't open "GREXT"HEAD."EXT"!");
\r
1045 CA_FarRead(handle, (memptr)grstarts, (NUMCHUNKS+1)*FILEPOSSIZE);
\r
1053 // Open the graphics file, leaving it open until the game is finished
\r
1055 grhandle = open(GREXT"GRAPH."EXT, O_RDONLY | O_BINARY);
\r
1056 if (grhandle == -1)
\r
1057 Quit ("Cannot open "GREXT"GRAPH."EXT"!");
\r
1061 // load the pic and sprite headers into the arrays in the data segment
\r
1064 MM_GetPtr(&(memptr)pictable,NUMPICS*sizeof(pictabletype));
\r
1065 CAL_GetGrChunkLength(STRUCTPIC); // position file pointer
\r
1066 MM_GetPtr(&compseg,chunkcomplen);
\r
1067 CA_FarRead (grhandle,compseg,chunkcomplen);
\r
1068 CAL_HuffExpand (compseg, (byte huge *)pictable,NUMPICS*sizeof(pictabletype),grhuffman);
\r
1069 MM_FreePtr(&compseg);
\r
1073 MM_GetPtr(&(memptr)picmtable,NUMPICM*sizeof(pictabletype));
\r
1074 CAL_GetGrChunkLength(STRUCTPICM); // position file pointer
\r
1075 MM_GetPtr(&compseg,chunkcomplen);
\r
1076 CA_FarRead (grhandle,compseg,chunkcomplen);
\r
1077 CAL_HuffExpand (compseg, (byte huge *)picmtable,NUMPICS*sizeof(pictabletype),grhuffman);
\r
1078 MM_FreePtr(&compseg);
\r
1082 MM_GetPtr(&(memptr)spritetable,NUMSPRITES*sizeof(spritetabletype));
\r
1083 CAL_GetGrChunkLength(STRUCTSPRITE); // position file pointer
\r
1084 MM_GetPtr(&compseg,chunkcomplen);
\r
1085 CA_FarRead (grhandle,compseg,chunkcomplen);
\r
1086 CAL_HuffExpand (compseg, (byte huge *)spritetable,NUMSPRITES*sizeof(spritetabletype),grhuffman);
\r
1087 MM_FreePtr(&compseg);
\r
1092 //==========================================================================
\r
1096 ======================
\r
1098 = CAL_SetupMapFile
\r
1100 ======================
\r
1103 void CAL_SetupMapFile (global_game_variables_t *gvar)
\r
1109 // load maphead.ext (offsets and tileinfo for map file)
\r
1111 // #ifndef MAPHEADERLINKED
\r
1112 // if ((handle = open("MAPHEAD."EXT,
\r
1113 // O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1114 // printf("Can't open MAPHEAD."EXT"!");
\r
1115 // length = filelength(handle);
\r
1116 // MM_GetPtr (&(memptr)tinf,length);
\r
1117 // CA_FarRead(handle, tinf, length);
\r
1121 // tinf = (byte _seg *)FP_SEG(&maphead);
\r
1126 // open the data file
\r
1128 //TODO: multiple files
\r
1129 if ((gvar->ca.file.maphandle[0] = open("data/test.map",
\r
1130 O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1132 printf("Can't open data/test.map!");
\r
1134 // #ifdef MAPHEADERLINKED
\r
1135 // if ((maphandle = open("GAMEMAPS."EXT,
\r
1136 // O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1137 // Quit ("Can't open GAMEMAPS."EXT"!");
\r
1139 // if ((maphandle = open("MAPTEMP."EXT,
\r
1140 // O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1141 // Quit ("Can't open MAPTEMP."EXT"!");
\r
1145 //==========================================================================
\r
1149 ======================
\r
1151 = CAL_SetupAudioFile
\r
1153 ======================
\r
1156 /*void CAL_SetupAudioFile (void)
\r
1162 // load maphead.ext (offsets and tileinfo for map file)
\r
1164 #ifndef AUDIOHEADERLINKED
\r
1165 if ((handle = open("AUDIOHED."EXT,
\r
1166 O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1167 Quit ("Can't open AUDIOHED."EXT"!");
\r
1168 length = filelength(handle);
\r
1169 MM_GetPtr (&(memptr)audiostarts,length);
\r
1170 CA_FarRead(handle, (byte far *)audiostarts, length);
\r
1173 audiohuffman = (huffnode *)&audiodict;
\r
1174 CAL_OptimizeNodes (audiohuffman);
\r
1175 audiostarts = (long _seg *)FP_SEG(&audiohead);
\r
1179 // open the data file
\r
1181 #ifndef AUDIOHEADERLINKED
\r
1182 if ((audiohandle = open("AUDIOT."EXT,
\r
1183 O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1184 Quit ("Can't open AUDIOT."EXT"!");
\r
1186 if ((audiohandle = open("AUDIO."EXT,
\r
1187 O_RDONLY | O_BINARY, S_IREAD)) == -1)
\r
1188 Quit ("Can't open AUDIO."EXT"!");
\r
1192 //==========================================================================
\r
1196 ======================
\r
1200 = Open all files and load in headers
\r
1202 ======================
\r
1205 void CA_Startup(global_game_variables_t *gvar)
\r
1208 #ifdef __BORLANDC__
\r
1209 unlink("profile.16b");
\r
1210 gvar->handle.profilehandle = open("profile.16b", O_CREAT | O_WRONLY | O_TEXT);
\r
1212 #ifdef __WATCOMC__
\r
1213 unlink("profile.16w");
\r
1214 gvar->handle.profilehandle = open("profile.16w", O_CREAT | O_WRONLY | O_TEXT);
\r
1218 #ifdef __BORLANDC__
\r
1219 unlink("meminfo.16b");
\r
1220 gvar->handle.showmemhandle = open("meminfo.16b", O_CREAT | O_WRONLY | O_TEXT);
\r
1222 #ifdef __WATCOMC__
\r
1223 unlink("meminfo.16w");
\r
1224 gvar->handle.showmemhandle = open("meminfo.16w", O_CREAT | O_WRONLY | O_TEXT);
\r
1227 CAL_SetupGrFile ();
\r
1228 CAL_SetupAudioFile ();*/
\r
1229 CAL_SetupMapFile (gvar);
\r
1231 gvar->ca.camap.mapon = -1;
\r
1232 gvar->ca.ca_levelbit = 1;
\r
1233 gvar->ca.ca_levelnum = 0;
\r
1235 /* drawcachebox = CAL_DialogDraw;
\r
1236 updatecachebox = CAL_DialogUpdate;
\r
1237 finishcachebox = CAL_DialogFinish;*/
\r
1240 //==========================================================================
\r
1244 ======================
\r
1248 = Closes all files
\r
1250 ======================
\r
1253 void CA_Shutdown(global_game_variables_t *gvar)
\r
1256 close(gvar->handle.profilehandle);
\r
1258 close(gvar->handle.showmemhandle);
\r
1260 close(*(gvar->ca.file.maphandle));
\r
1263 close(audiohandle);*/
\r
1266 //===========================================================================
\r
1269 ======================
\r
1271 = CA_CacheAudioChunk
\r
1273 ======================
\r
1276 void CA_CacheAudioChunk (int chunk)
\r
1278 long pos,compressed;
\r
1279 #ifdef AUDIOHEADERLINKED
\r
1281 memptr bigbufferseg;
\r
1285 if (audiosegs[chunk])
\r
1287 MM_SetPurge (&(memptr)audiosegs[chunk],0);
\r
1288 return; // allready in memory
\r
1291 // MDM begin - (GAMERS EDGE)
\r
1293 if (!FindFile("AUDIO."EXT,NULL,2))
\r
1294 Quit("CA_CacheAudioChunk(): Can't find audio files.");
\r
1299 // load the chunk into a buffer, either the miscbuffer if it fits, or allocate
\r
1300 // a larger buffer
\r
1302 pos = audiostarts[chunk];
\r
1303 compressed = audiostarts[chunk+1]-pos;
\r
1305 lseek(audiohandle,pos,SEEK_SET);
\r
1307 #ifndef AUDIOHEADERLINKED
\r
1309 MM_GetPtr (&(memptr)audiosegs[chunk],compressed);
\r
1313 CA_FarRead(audiohandle,audiosegs[chunk],compressed);
\r
1317 if (compressed<=BUFFERSIZE)
\r
1319 CA_FarRead(audiohandle,bufferseg,compressed);
\r
1320 source = bufferseg;
\r
1324 MM_GetPtr(&bigbufferseg,compressed);
\r
1327 MM_SetLock (&bigbufferseg,true);
\r
1328 CA_FarRead(audiohandle,bigbufferseg,compressed);
\r
1329 source = bigbufferseg;
\r
1332 expanded = *(long far *)source;
\r
1333 source += 4; // skip over length
\r
1334 MM_GetPtr (&(memptr)audiosegs[chunk],expanded);
\r
1337 CAL_HuffExpand (source,audiosegs[chunk],expanded,audiohuffman);
\r
1340 if (compressed>BUFFERSIZE)
\r
1341 MM_FreePtr(&bigbufferseg);
\r
1345 //===========================================================================
\r
1348 ======================
\r
1350 = CA_LoadAllSounds
\r
1352 = Purges all sounds, then loads all new ones (mode switch)
\r
1354 ======================
\r
1357 void CA_LoadAllSounds (void)
\r
1361 switch (oldsoundmode)
\r
1366 start = STARTPCSOUNDS;
\r
1369 start = STARTADLIBSOUNDS;
\r
1373 for (i=0;i<NUMSOUNDS;i++,start++)
\r
1374 if (audiosegs[start])
\r
1375 MM_SetPurge (&(memptr)audiosegs[start],3); // make purgable
\r
1379 switch (SoundMode)
\r
1384 start = STARTPCSOUNDS;
\r
1387 start = STARTADLIBSOUNDS;
\r
1391 for (i=0;i<NUMSOUNDS;i++,start++)
\r
1392 CA_CacheAudioChunk (start);
\r
1394 oldsoundmode = SoundMode;
\r
1397 //===========================================================================
\r
1399 //++++#if GRMODE == EGAGR
\r
1402 ======================
\r
1406 = Make a shifted (one byte wider) copy of a sprite into another area
\r
1408 ======================
\r
1411 unsigned static sheight,swidth;
\r
1412 boolean static dothemask;
\r
1414 void CAL_ShiftSprite (unsigned segment,unsigned source,unsigned dest,
\r
1415 unsigned width, unsigned height, unsigned pixshift, boolean domask)
\r
1418 sheight = height; // because we are going to reassign bp
\r
1420 dothemask = domask;
\r
1422 asm mov ax,[segment]
\r
1423 asm mov ds,ax // source and dest are in same segment, and all local
\r
1425 asm mov bx,[source]
\r
1428 asm mov bp,[pixshift]
\r
1430 asm mov bp,WORD PTR [shifttabletable+bp] // bp holds pointer to shift table
\r
1432 asm cmp [ss:dothemask],0
\r
1436 // table shift the mask
\r
1438 asm mov dx,[ss:sheight]
\r
1442 asm mov BYTE PTR [di],255 // 0xff first byte
\r
1443 asm mov cx,ss:[swidth]
\r
1447 asm mov al,[bx] // source
\r
1449 asm inc bx // next source byte
\r
1453 asm mov ax,[bp+si] // table shift into two bytes
\r
1455 asm and [di],al // and with first byte
\r
1457 asm mov [di],ah // replace next byte
\r
1459 asm loop domaskbyte
\r
1461 asm inc di // the last shifted byte has 1s in it
\r
1468 // table shift the data
\r
1470 asm mov dx,ss:[sheight]
\r
1472 asm shl dx,1 // four planes of data
\r
1476 asm mov BYTE PTR [di],0 // 0 first byte
\r
1477 asm mov cx,ss:[swidth]
\r
1481 asm mov al,[bx] // source
\r
1482 asm inc bx // next source byte
\r
1486 asm mov ax,[bp+si] // table shift into two bytes
\r
1487 asm or [di],al // or with first byte
\r
1489 asm mov [di],ah // replace next byte
\r
1491 asm loop dodatabyte
\r
1493 asm inc di // the last shifted byte has 0s in it
\r
1501 asm mov ax,ss // restore data segment
\r
1508 //===========================================================================
\r
1511 ======================
\r
1515 = Generate shifts and set up sprite structure for a given sprite
\r
1517 ======================
\r
1520 void CAL_CacheSprite (int chunk, byte far *compressed)
\r
1523 unsigned shiftstarts[5];
\r
1524 unsigned smallplane,bigplane,expanded;
\r
1525 spritetabletype far *spr;
\r
1526 spritetype _seg *dest;
\r
1528 #if GRMODE == CGAGR
\r
1530 // CGA has no pel panning, so shifts are never needed
\r
1532 spr = &spritetable[chunk-STARTSPRITES];
\r
1533 smallplane = spr->width*spr->height;
\r
1534 MM_GetPtr (&grsegs[chunk],smallplane*2+MAXSHIFTS*6);
\r
1537 dest = (spritetype _seg *)grsegs[chunk];
\r
1538 dest->sourceoffset[0] = MAXSHIFTS*6; // start data after 3 unsigned tables
\r
1539 dest->planesize[0] = smallplane;
\r
1540 dest->width[0] = spr->width;
\r
1543 // expand the unshifted shape
\r
1545 CAL_HuffExpand (compressed, &dest->data[0],smallplane*2,grhuffman);
\r
1550 #if GRMODE == EGAGR
\r
1553 // calculate sizes
\r
1555 spr = &spritetable[chunk-STARTSPRITES];
\r
1556 smallplane = spr->width*spr->height;
\r
1557 bigplane = (spr->width+1)*spr->height;
\r
1559 shiftstarts[0] = MAXSHIFTS*6; // start data after 3 unsigned tables
\r
1560 shiftstarts[1] = shiftstarts[0] + smallplane*5; // 5 planes in a sprite
\r
1561 shiftstarts[2] = shiftstarts[1] + bigplane*5;
\r
1562 shiftstarts[3] = shiftstarts[2] + bigplane*5;
\r
1563 shiftstarts[4] = shiftstarts[3] + bigplane*5; // nothing ever put here
\r
1565 expanded = shiftstarts[spr->shifts];
\r
1566 MM_GetPtr (&grsegs[chunk],expanded);
\r
1569 dest = (spritetype _seg *)grsegs[chunk];
\r
1572 // expand the unshifted shape
\r
1574 CAL_HuffExpand (compressed, &dest->data[0],smallplane*5,grhuffman);
\r
1577 // make the shifts!
\r
1579 switch (spr->shifts)
\r
1584 dest->sourceoffset[i] = shiftstarts[0];
\r
1585 dest->planesize[i] = smallplane;
\r
1586 dest->width[i] = spr->width;
\r
1593 dest->sourceoffset[i] = shiftstarts[0];
\r
1594 dest->planesize[i] = smallplane;
\r
1595 dest->width[i] = spr->width;
\r
1599 dest->sourceoffset[i] = shiftstarts[1];
\r
1600 dest->planesize[i] = bigplane;
\r
1601 dest->width[i] = spr->width+1;
\r
1603 CAL_ShiftSprite ((unsigned)grsegs[chunk],dest->sourceoffset[0],
\r
1604 dest->sourceoffset[2],spr->width,spr->height,4,true);
\r
1608 dest->sourceoffset[0] = shiftstarts[0];
\r
1609 dest->planesize[0] = smallplane;
\r
1610 dest->width[0] = spr->width;
\r
1612 dest->sourceoffset[1] = shiftstarts[1];
\r
1613 dest->planesize[1] = bigplane;
\r
1614 dest->width[1] = spr->width+1;
\r
1615 CAL_ShiftSprite ((unsigned)grsegs[chunk],dest->sourceoffset[0],
\r
1616 dest->sourceoffset[1],spr->width,spr->height,2,true);
\r
1618 dest->sourceoffset[2] = shiftstarts[2];
\r
1619 dest->planesize[2] = bigplane;
\r
1620 dest->width[2] = spr->width+1;
\r
1621 CAL_ShiftSprite ((unsigned)grsegs[chunk],dest->sourceoffset[0],
\r
1622 dest->sourceoffset[2],spr->width,spr->height,4,true);
\r
1624 dest->sourceoffset[3] = shiftstarts[3];
\r
1625 dest->planesize[3] = bigplane;
\r
1626 dest->width[3] = spr->width+1;
\r
1627 CAL_ShiftSprite ((unsigned)grsegs[chunk],dest->sourceoffset[0],
\r
1628 dest->sourceoffset[3],spr->width,spr->height,6,true);
\r
1633 Quit ("CAL_CacheSprite: Bad shifts number!");
\r
1639 //===========================================================================
\r
1643 ======================
\r
1645 = CAL_ExpandGrChunk
\r
1647 = Does whatever is needed with a pointer to a compressed chunk
\r
1649 ======================
\r
1652 void CAL_ExpandGrChunk (int chunk, byte far *source)
\r
1657 if (chunk >= STARTTILE8 && chunk < STARTEXTERNS)
\r
1660 // expanded sizes of tile8/16/32 are implicit
\r
1663 #if GRMODE == EGAGR
\r
1665 #define MASKBLOCK 40
\r
1668 #if GRMODE == CGAGR
\r
1670 #define MASKBLOCK 32
\r
1673 if (chunk<STARTTILE8M) // tile 8s are all in one chunk!
\r
1674 expanded = BLOCK*NUMTILE8;
\r
1675 else if (chunk<STARTTILE16)
\r
1676 expanded = MASKBLOCK*NUMTILE8M;
\r
1677 else if (chunk<STARTTILE16M) // all other tiles are one/chunk
\r
1678 expanded = BLOCK*4;
\r
1679 else if (chunk<STARTTILE32)
\r
1680 expanded = MASKBLOCK*4;
\r
1681 else if (chunk<STARTTILE32M)
\r
1682 expanded = BLOCK*16;
\r
1684 expanded = MASKBLOCK*16;
\r
1689 // everything else has an explicit size longword
\r
1691 expanded = *(long far *)source;
\r
1692 source += 4; // skip over length
\r
1696 // allocate final space, decompress it, and free bigbuffer
\r
1697 // Sprites need to have shifts made and various other junk
\r
1699 if (chunk>=STARTSPRITES && chunk< STARTTILE8)
\r
1700 CAL_CacheSprite(chunk,source);
\r
1703 MM_GetPtr (&grsegs[chunk],expanded);
\r
1706 CAL_HuffExpand (source,grsegs[chunk],expanded,grhuffman);
\r
1712 ======================
\r
1716 = Gets a chunk off disk, optimizing reads to general buffer
\r
1718 ======================
\r
1721 void CAL_ReadGrChunk (int chunk)
\r
1723 long pos,compressed;
\r
1724 memptr bigbufferseg;
\r
1729 // load the chunk into a buffer, either the miscbuffer if it fits, or allocate
\r
1730 // a larger buffer
\r
1732 pos = GRFILEPOS(chunk);
\r
1733 if (pos<0) // $FFFFFFFF start is a sparse tile
\r
1737 while (GRFILEPOS(next) == -1) // skip past any sparse tiles
\r
1740 compressed = GRFILEPOS(next)-pos;
\r
1742 lseek(grhandle,pos,SEEK_SET);
\r
1744 if (compressed<=BUFFERSIZE)
\r
1746 CA_FarRead(grhandle,bufferseg,compressed);
\r
1747 source = bufferseg;
\r
1751 MM_GetPtr(&bigbufferseg,compressed);
\r
1754 MM_SetLock (&bigbufferseg,true);
\r
1755 CA_FarRead(grhandle,bigbufferseg,compressed);
\r
1756 source = bigbufferseg;
\r
1759 CAL_ExpandGrChunk (chunk,source);
\r
1761 if (compressed>BUFFERSIZE)
\r
1762 MM_FreePtr(&bigbufferseg);
\r
1766 ======================
\r
1770 = Makes sure a given chunk is in memory, loadiing it if needed
\r
1772 ======================
\r
1775 void CA_CacheGrChunk (int chunk)
\r
1777 long pos,compressed;
\r
1778 memptr bigbufferseg;
\r
1782 gvar->video.grneeded[chunk] |= ca_levelbit; // make sure it doesn't get removed
\r
1783 if (grsegs[chunk])
\r
1785 MM_SetPurge (&grsegs[chunk],0);
\r
1786 return; // allready in memory
\r
1789 // MDM begin - (GAMERS EDGE)
\r
1791 if (!FindFile("EGAGRAPH."EXT,NULL,2))
\r
1792 Quit("CA_CacheGrChunk(): Can't find graphics files.");
\r
1797 // load the chunk into a buffer, either the miscbuffer if it fits, or allocate
\r
1798 // a larger buffer
\r
1800 pos = GRFILEPOS(chunk);
\r
1801 if (pos<0) // $FFFFFFFF start is a sparse tile
\r
1805 while (GRFILEPOS(next) == -1) // skip past any sparse tiles
\r
1808 compressed = GRFILEPOS(next)-pos;
\r
1810 lseek(grhandle,pos,SEEK_SET);
\r
1812 if (compressed<=BUFFERSIZE)
\r
1814 CA_FarRead(grhandle,bufferseg,compressed);
\r
1815 source = bufferseg;
\r
1819 MM_GetPtr(&bigbufferseg,compressed);
\r
1820 MM_SetLock (&bigbufferseg,true);
\r
1821 CA_FarRead(grhandle,bigbufferseg,compressed);
\r
1822 source = bigbufferseg;
\r
1825 CAL_ExpandGrChunk (chunk,source);
\r
1827 if (compressed>BUFFERSIZE)
\r
1828 MM_FreePtr(&bigbufferseg);
\r
1833 //==========================================================================
\r
1836 ======================
\r
1840 ======================
\r
1843 void CA_CacheMap (global_game_variables_t *gvar)
\r
1845 long pos,compressed;
\r
1847 memptr *dest,bigbufferseg;
\r
1849 unsigned far *source;
\r
1850 #ifdef MAPHEADERLINKED
\r
1851 memptr buffer2seg;
\r
1857 // free up memory from last map
\r
1859 if (gvar->ca.map.mapon>-1 && gvar->ca.map.mapheaderseg[gvar->ca.map.mapon])
\r
1860 MM_SetPurge (&((memptr)gvar->ca.map.mapheaderseg[(gvar->ca.map.mapon)]), 3, &(gvar->mm));
\r
1861 for (plane=0;plane<MAPPLANES;plane++)
\r
1862 if (gvar->ca.map.mapsegs[plane])
\r
1863 MM_FreePtr (&(memptr)gvar->ca.map.mapsegs[plane], &(gvar->mm));
\r
1865 gvar->ca.map.mapon = gvar->ca.map.mapnum;
\r
1869 // load map header
\r
1870 // The header will be cached if it is still around
\r
1872 if (!gvar->ca.map.mapheaderseg[gvar->ca.map.mapnum])
\r
1874 //pos = ((mapfiletype _seg *)tinf)->headeroffsets[mapnum];
\r
1875 pos = ((_seg *)gvar->ca.map.tinf)->headeroffsets[gvar->ca.map.mapnum];
\r
1876 if (pos<0) // $FFFFFFFF start is a sparse map
\r
1877 printf("CA_CacheMap: Tried to load a non existent map!");
\r
1879 MM_GetPtr(&(memptr)gvar->ca.mapheaderseg[mapnum],sizeof(maptype));
\r
1880 lseek(maphandle,pos,SEEK_SET);
\r
1881 CA_FarRead (maphandle,(memptr)mapheaderseg[mapnum],sizeof(maptype));
\r
1884 MM_SetPurge (&(memptr)mapheaderseg[mapnum], 0, &(gvar->mm));
\r
1887 // load the planes in
\r
1888 // If a plane's pointer still exists it will be overwritten (levels are
\r
1889 // allways reloaded, never cached)
\r
1892 size = mapheaderseg[mapnum]->width * mapheaderseg[mapnum]->height * 2;
\r
1894 for (plane = 0; plane<MAPPLANES; plane++)
\r
1896 pos = mapheaderseg[mapnum]->planestart[plane];
\r
1897 compressed = mapheaderseg[mapnum]->planelength[plane];
\r
1900 continue; // the plane is not used in this game
\r
1902 dest = &(memptr)mapsegs[plane];
\r
1903 MM_GetPtr(dest,size);
\r
1905 lseek(maphandle,pos,SEEK_SET);
\r
1906 if (compressed<=BUFFERSIZE)
\r
1907 source = bufferseg;
\r
1910 MM_GetPtr(&bigbufferseg,compressed);
\r
1911 MM_SetLock (&bigbufferseg,true);
\r
1912 source = bigbufferseg;
\r
1915 CA_FarRead(maphandle,(byte far *)source,compressed);
\r
1916 #ifdef MAPHEADERLINKED
\r
1918 // unhuffman, then unRLEW
\r
1919 // The huffman'd chunk has a two byte expanded length first
\r
1920 // The resulting RLEW chunk also does, even though it's not really
\r
1923 expanded = *source;
\r
1925 MM_GetPtr (&buffer2seg,expanded);
\r
1926 CAL_CarmackExpand (source, (unsigned far *)buffer2seg,expanded);
\r
1927 CA_RLEWexpand (((unsigned far *)buffer2seg)+1,*dest,size,
\r
1928 ((mapfiletype _seg *)tinf)->RLEWtag);
\r
1929 MM_FreePtr (&buffer2seg);
\r
1933 // unRLEW, skipping expanded length
\r
1935 CA_RLEWexpand (source+1, *dest,size,
\r
1936 ((mapfiletype _seg *)tinf)->RLEWtag);
\r
1939 if (compressed>BUFFERSIZE)
\r
1940 MM_FreePtr(&bigbufferseg);
\r
1944 //===========================================================================
\r
1947 ======================
\r
1951 = Goes up a bit level in the needed lists and clears it out.
\r
1952 = Everything is made purgable
\r
1954 ======================
\r
1957 void CA_UpLevel (global_game_variables_t *gvar)
\r
1959 if (gvar->ca.ca_levelnum==7)
\r
1960 printf("CA_UpLevel: Up past level 7!");
\r
1962 gvar->ca.ca_levelbit<<=1;
\r
1963 gvar->ca.ca_levelnum++;
\r
1966 //===========================================================================
\r
1969 ======================
\r
1973 = Goes down a bit level in the needed lists and recaches
\r
1974 = everything from the lower level
\r
1976 ======================
\r
1979 void CA_DownLevel (global_game_variables_t *gvar)
\r
1981 if (!gvar->ca.ca_levelnum)
\r
1982 printf("CA_DownLevel: Down past level 0!");
\r
1983 gvar->ca.ca_levelbit>>=1;
\r
1984 gvar->ca.ca_levelnum--;
\r
1985 ////++++++++++++++++++++++++++++++++++++++++++CA_CacheMarks(NULL);
\r
1988 //===========================================================================
\r
1991 ======================
\r
1995 = Clears out all the marks at the current level
\r
1997 ======================
\r
2000 void CA_ClearMarks (global_game_variables_t *gvar)
\r
2004 for (i=0;i<NUMCHUNKS;i++)
\r
2005 gvar->video.grneeded[i]&=~gvar->ca.ca_levelbit;
\r
2008 //===========================================================================
\r
2011 ======================
\r
2013 = CA_ClearAllMarks
\r
2015 = Clears out all the marks on all the levels
\r
2017 ======================
\r
2020 void CA_ClearAllMarks (global_game_variables_t *gvar)
\r
2022 _fmemset (gvar->video.grneeded,0,sizeof(gvar->video.grneeded));
\r
2023 gvar->ca.ca_levelbit = 1;
\r
2024 gvar->ca.ca_levelnum = 0;
\r
2027 //===========================================================================
\r
2030 ======================
\r
2034 ======================
\r
2037 void CA_SetGrPurge (void)
\r
2046 for (i=0;i<NUMCHUNKS;i++)
\r
2048 MM_SetPurge (&(memptr)grsegs[i],3);
\r
2053 ======================
\r
2057 = Make everything possible purgable
\r
2059 ======================
\r
2062 void CA_SetAllPurge (void)
\r
2069 // free cursor sprite and background save
\r
2071 //VW_FreeCursor ();
\r
2074 // free map headers and map planes
\r
2076 for (i=0;i<NUMMAPS;i++)
\r
2077 if (mapheaderseg[i])
\r
2078 MM_SetPurge (&(memptr)mapheaderseg[i],3);
\r
2082 MM_FreePtr (&(memptr)mapsegs[i]);
\r
2087 for (i=0;i<NUMSNDCHUNKS;i++)
\r
2089 MM_SetPurge (&(memptr)audiosegs[i],3);
\r
2098 //===========================================================================
\r
2102 ======================
\r
2106 ======================
\r
2109 #define NUMBARS (17l*8)
\r
2112 unsigned thx,thy,lastx;
\r
2113 long barx,barstep;
\r
2115 void CAL_DialogDraw (char *title,unsigned numcache)
\r
2117 unsigned homex,homey,x;
\r
2119 barstep = (NUMBARS<<16)/numcache;
\r
2122 // draw dialog window (masked tiles 12 - 20 are window borders)
\r
2124 US_CenterWindow (20,8);
\r
2128 US_CPrint ("Loading");
\r
2129 fontcolor = F_SECONDCOLOR;
\r
2130 US_CPrint (title);
\r
2131 fontcolor = F_BLACK;
\r
2134 // draw thermometer bar
\r
2138 VWB_DrawTile8(thx,thy,0); // CAT3D numbers
\r
2139 VWB_DrawTile8(thx,thy+8,3);
\r
2140 VWB_DrawTile8(thx,thy+16,6);
\r
2141 VWB_DrawTile8(thx+17*8,thy,2);
\r
2142 VWB_DrawTile8(thx+17*8,thy+8,5);
\r
2143 VWB_DrawTile8(thx+17*8,thy+16,8);
\r
2144 for (x=thx+8;x<thx+17*8;x+=8)
\r
2146 VWB_DrawTile8(x,thy,1);
\r
2147 VWB_DrawTile8(x,thy+8,4);
\r
2148 VWB_DrawTile8(x,thy+16,7);
\r
2151 thx += 4; // first line location
\r
2153 barx = (long)thx<<16;
\r
2156 VW_UpdateScreen();
\r
2161 ======================
\r
2163 = CAL_DialogUpdate
\r
2165 ======================
\r
2168 void CAL_DialogUpdate (void)
\r
2174 if (xh - lastx > BARSTEP)
\r
2176 for (x=lastx;x<=xh;x++)
\r
2177 #if GRMODE == EGAGR
\r
2178 VWB_Vlin (thy,thy+13,x,14);
\r
2180 #if GRMODE == CGAGR
\r
2181 VWB_Vlin (thy,thy+13,x,SECONDCOLOR);
\r
2184 VW_UpdateScreen();
\r
2189 ======================
\r
2191 = CAL_DialogFinish
\r
2193 ======================
\r
2196 void CAL_DialogFinish (void)
\r
2200 xh = thx + NUMBARS;
\r
2201 for (x=lastx;x<=xh;x++)
\r
2202 #if GRMODE == EGAGR
\r
2203 VWB_Vlin (thy,thy+13,x,14);
\r
2205 #if GRMODE == CGAGR
\r
2206 VWB_Vlin (thy,thy+13,x,SECONDCOLOR);
\r
2208 VW_UpdateScreen();
\r
2212 //===========================================================================
\r
2215 ======================
\r
2219 ======================
\r
2221 #define MAXEMPTYREAD 1024
\r
2223 void CA_CacheMarks (char *title)
\r
2226 int i,next,numcache;
\r
2227 long pos,endpos,nextpos,nextendpos,compressed;
\r
2228 long bufferstart,bufferend; // file position of general buffer
\r
2230 memptr bigbufferseg;
\r
2232 dialog = (title!=NULL);
\r
2236 // go through and make everything not needed purgable
\r
2238 for (i=0;i<NUMCHUNKS;i++)
\r
2239 if (gvar->video.grneeded[i]&ca_levelbit)
\r
2241 if (grsegs[i]) // its allready in memory, make
\r
2242 MM_SetPurge(&grsegs[i],0); // sure it stays there!
\r
2248 if (grsegs[i]) // not needed, so make it purgeable
\r
2249 MM_SetPurge(&grsegs[i],3);
\r
2252 if (!numcache) // nothing to cache!
\r
2255 // MDM begin - (GAMERS EDGE)
\r
2257 if (!FindFile("EGAGRAPH."EXT,NULL,2))
\r
2258 Quit("CA_CacheMarks(): Can't find graphics files.");
\r
2265 write(profilehandle,title,strlen(title));
\r
2266 write(profilehandle,"\n",1);
\r
2269 drawcachebox(title,numcache);
\r
2273 // go through and load in anything still needed
\r
2275 bufferstart = bufferend = 0; // nothing good in buffer now
\r
2277 for (i=0;i<NUMCHUNKS;i++)
\r
2278 if ( (gvar->video.grneeded[i]&ca_levelbit) && !grsegs[i])
\r
2281 // update thermometer
\r
2283 if (dialog && updatecachebox)
\r
2284 updatecachebox ();
\r
2286 pos = GRFILEPOS(i);
\r
2291 while (GRFILEPOS(next) == -1) // skip past any sparse tiles
\r
2294 compressed = GRFILEPOS(next)-pos;
\r
2295 endpos = pos+compressed;
\r
2297 if (compressed<=BUFFERSIZE)
\r
2299 if (bufferstart<=pos
\r
2300 && bufferend>= endpos)
\r
2302 // data is allready in buffer
\r
2303 source = (byte _seg *)bufferseg+(pos-bufferstart);
\r
2307 // load buffer with a new block from disk
\r
2308 // try to get as many of the needed blocks in as possible
\r
2309 while ( next < NUMCHUNKS )
\r
2311 while (next < NUMCHUNKS &&
\r
2312 !(gvar->video.grneeded[next]&ca_levelbit && !grsegs[next]))
\r
2314 if (next == NUMCHUNKS)
\r
2317 nextpos = GRFILEPOS(next);
\r
2318 while (GRFILEPOS(++next) == -1) // skip past any sparse tiles
\r
2320 nextendpos = GRFILEPOS(next);
\r
2321 if (nextpos - endpos <= MAXEMPTYREAD
\r
2322 && nextendpos-pos <= BUFFERSIZE)
\r
2323 endpos = nextendpos;
\r
2325 next = NUMCHUNKS; // read pos to posend
\r
2328 lseek(grhandle,pos,SEEK_SET);
\r
2329 CA_FarRead(grhandle,bufferseg,endpos-pos);
\r
2330 bufferstart = pos;
\r
2331 bufferend = endpos;
\r
2332 source = bufferseg;
\r
2337 // big chunk, allocate temporary buffer
\r
2338 MM_GetPtr(&bigbufferseg,compressed);
\r
2341 MM_SetLock (&bigbufferseg,true);
\r
2342 lseek(grhandle,pos,SEEK_SET);
\r
2343 CA_FarRead(grhandle,bigbufferseg,compressed);
\r
2344 source = bigbufferseg;
\r
2347 CAL_ExpandGrChunk (i,source);
\r
2351 if (compressed>BUFFERSIZE)
\r
2352 MM_FreePtr(&bigbufferseg);
\r
2357 // finish up any thermometer remnants
\r
2359 if (dialog && finishcachebox)
\r