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>
72 }
79 }
81 }
89 }
91 // build wad directory
97 wad_t w;
102 }
107 }
113 }
125 }
131 }
133 //fclose(h);
140 }
149 }
153 }
160 }
161 }
167 }
181 }
185 }
191 }
192 }
193 }
194 }
195 }
196 }
199 }
201 // allocate resources
202 // (called from M_startup)
210 }
212 // load resource
229 }
231 /*
232 // unused
233 void F_saveres(int r, void *p, dword o, dword l) {
234 FILE* fh = wadh[wad[r].f];
235 int oo = ftell(fh);
236 if (fseek(fh, wad[r].o + o, SEEK_SET) != 0) {
237 ERR_fatal("Ошибка при чтении файла");
238 }
239 myfwrite(p, l, 1, fh);
240 fseek(fh, oo, SEEK_SET);
241 }
242 */
244 // get resource id
250 }
251 }
253 }
255 // get resource id
260 }
262 }
266 }
268 // get sprite id
281 }
283 }
284 }
285 }
288 }
292 }
307 }
309 }
316 }
317 }
319 // reads bytes from file until CR
329 }
331 i++;
332 }
334 }
336 /*
337 // unused
338 // reads bytes from file until NUL
339 void F_readstrz (FILE* h,char *s,int m) {
340 int i = 0;
341 size_t len = 0;
342 static char c = 0;
343 while (i < m) {
344 c = 0;
345 len = myfreadc(&c, 1, 1, h);
346 if (len == 0 || c == 0) {
347 break;
348 }
349 s[i] = c;
350 i++;
351 }
352 s[i] = 0;
353 }
354 */
356 /*void F_freemus(void) {
358 int i;
360 if(!pat) return;
361 S_stopmusic();
362 free(pat);free(patp);
363 for(i=0;i<inum;++i) if(dmi[i]!=NULL) free(dmi[i]);
364 free(dmi);
365 pat=NULL;
367 }
368 */
370 /*void F_loadmus(char n[8]) {
371 int r,i,j;
372 FILE *h;
373 int o;
374 struct{
375 char id[4];
376 byte ver,pat;
377 word psz;
378 }d;
379 struct{byte t;char n[13];word r;}di;
381 if((r=F_findres(n))==-1) return;
382 fseek(h=wadh[wad[r].f],wad[r].o,SEEK_SET);
383 myfread(&d,1,sizeof(d),h);
384 if(memcmp(d.id,"DMM",4)!=0) return;
385 if(!(pat=malloc(d.psz<<2))) return;
386 myfread(pat,1,d.psz<<2,h);
387 myfread(&seqn,1,1,h);if(seqn) myfread(seq,1,seqn,h);
388 inum=0;myfread(&inum,1,1,h);
389 if(!(dmi=malloc(inum*4))) {free(pat);pat=NULL;return;}
390 if(!(patp=malloc((word)d.pat*32))) {free(pat);free(dmi);pat=NULL;return;}
391 for(i=0;i<inum;++i) {
392 dmi[i]=NULL;
393 myfread(&di,1,16,h);o=ftell(h);
394 for(r=0;r<12;++r) if(di.n[r]=='.') di.n[r]=0;
395 if((r=F_findres(di.n))==-1) continue;
396 if(!(dmi[i]=malloc(wad[r].l+8))) continue;
397 memset(dmi[i],0,16);
398 F_loadres(r,dmi[i],0,2);
399 F_loadres(r,(int*)dmi[i]+1,2,2);
400 F_loadres(r,(int*)dmi[i]+2,4,2);
401 F_loadres(r,(int*)dmi[i]+3,6,2);
402 F_loadres(r,(int*)dmi[i]+4,8,wad[r].l-8);
403 fseek(h,o,SEEK_SET);
404 }
405 for(i=r=0,j=(word)d.pat<<3;i<j;++i) {
406 patp[i]=r<<2;
407 while(pat[r++].v!=0x80);
408 }
409 }
410 */