1 /*
2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
4 Copyright (C) <ARembo@gmail.com> 2011
6 This file is part of the Doom2D:Rembo project.
8 Doom2D:Rembo is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 Doom2D:Rembo is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/> or
19 write to the Free Software Foundation, Inc.,
20 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include <sys/stat.h>
50 map_block_t blk;
74 }
81 }
83 }
91 }
93 // build wad directory
99 wad_t w;
104 }
109 }
115 }
127 }
133 }
135 //fclose(h);
142 }
151 }
155 }
162 }
163 }
169 }
183 }
187 }
193 }
194 }
195 }
196 }
197 }
198 }
201 }
203 // allocate resources
204 // (called from M_startup)
212 }
214 // load resource
231 }
233 /*
234 // unused
235 void F_saveres(int r, void *p, dword o, dword l) {
236 FILE* fh = wadh[wad[r].f];
237 int oo = ftell(fh);
238 if (fseek(fh, wad[r].o + o, SEEK_SET) != 0) {
239 ERR_fatal("Ошибка при чтении файла");
240 }
241 myfwrite(p, l, 1, fh);
242 fseek(fh, oo, SEEK_SET);
243 }
244 */
246 // get resource id
252 }
253 }
255 }
257 // get resource id
262 }
264 }
268 }
270 // get sprite id
283 }
285 }
286 }
287 }
290 }
294 }
309 }
311 }
318 }
319 }
321 // reads bytes from file until CR
331 }
333 i++;
334 }
336 }
338 /*
339 // unused
340 // reads bytes from file until NUL
341 void F_readstrz (FILE* h,char *s,int m) {
342 int i = 0;
343 size_t len = 0;
344 static char c = 0;
345 while (i < m) {
346 c = 0;
347 len = myfreadc(&c, 1, 1, h);
348 if (len == 0 || c == 0) {
349 break;
350 }
351 s[i] = c;
352 i++;
353 }
354 s[i] = 0;
355 }
356 */
361 map_header_t hdr;
370 }
377 }
381 }
388 }
389 }
390 }
391 }
393 }
394 }
396 /*void F_freemus(void) {
398 int i;
400 if(!pat) return;
401 S_stopmusic();
402 free(pat);free(patp);
403 for(i=0;i<inum;++i) if(dmi[i]!=NULL) free(dmi[i]);
404 free(dmi);
405 pat=NULL;
407 }
408 */
410 /*void F_loadmus(char n[8]) {
411 int r,i,j;
412 FILE *h;
413 int o;
414 struct{
415 char id[4];
416 byte ver,pat;
417 word psz;
418 }d;
419 struct{byte t;char n[13];word r;}di;
421 if((r=F_findres(n))==-1) return;
422 fseek(h=wadh[wad[r].f],wad[r].o,SEEK_SET);
423 myfread(&d,1,sizeof(d),h);
424 if(memcmp(d.id,"DMM",4)!=0) return;
425 if(!(pat=malloc(d.psz<<2))) return;
426 myfread(pat,1,d.psz<<2,h);
427 myfread(&seqn,1,1,h);if(seqn) myfread(seq,1,seqn,h);
428 inum=0;myfread(&inum,1,1,h);
429 if(!(dmi=malloc(inum*4))) {free(pat);pat=NULL;return;}
430 if(!(patp=malloc((word)d.pat*32))) {free(pat);free(dmi);pat=NULL;return;}
431 for(i=0;i<inum;++i) {
432 dmi[i]=NULL;
433 myfread(&di,1,16,h);o=ftell(h);
434 for(r=0;r<12;++r) if(di.n[r]=='.') di.n[r]=0;
435 if((r=F_findres(di.n))==-1) continue;
436 if(!(dmi[i]=malloc(wad[r].l+8))) continue;
437 memset(dmi[i],0,16);
438 F_loadres(r,dmi[i],0,2);
439 F_loadres(r,(int*)dmi[i]+1,2,2);
440 F_loadres(r,(int*)dmi[i]+2,4,2);
441 F_loadres(r,(int*)dmi[i]+3,6,2);
442 F_loadres(r,(int*)dmi[i]+4,8,wad[r].l-8);
443 fseek(h,o,SEEK_SET);
444 }
445 for(i=r=0,j=(word)d.pat<<3;i<j;++i) {
446 patp[i]=r<<2;
447 while(pat[r++].v!=0x80);
448 }
449 }
450 */