From: Andriy Shinkarchuck Date: Sun, 24 Jul 2011 16:41:07 +0000 (+0300) Subject: files.c files.h moved to repo. Added license notification X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=7f3e63f920ffc73ce5e404476ed08aaf9c305de5;p=flatwaifu.git files.c files.h moved to repo. Added license notification --- diff --git a/files.c b/files.c new file mode 100755 index 0000000..97e69eb --- /dev/null +++ b/files.c @@ -0,0 +1,463 @@ +/* + Copyright (C) Prikol Software 1996-1997 + Copyright (C) Aleksey Volynskov 1996-1997 + Copyright (C) 2011 + + This file is part of the Doom2D:Rembo project. + + Doom2D:Rembo is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + Doom2D:Rembo is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see or + write to the Free Software Foundation, Inc., + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "glob.h" +#include +//#include +#include +//#include +#include +#include +//#include +#include "vga.h" +#include "error.h" +#include "sound.h" +//#include "snddrv.h" +#include "memory.h" +#include "view.h" +#include "items.h" +#include "switch.h" +#include "files.h" +#include "map.h" + + +char *S_getinfo(void); + +extern void *snd_drv; + +typedef struct{ + byte n,i,v,d; +}dmv; + +byte seq[255],seqn; +dmv *pat=NULL; +unsigned *patp; +void **dmi; + +static int inum=0; + +void G_savegame(FILE*); +void W_savegame(FILE*); +void DOT_savegame(FILE*); +void SMK_savegame(FILE*); +void FX_savegame(FILE*); +void IT_savegame(FILE*); +void MN_savegame(FILE*); +void PL_savegame(FILE*); +void SW_savegame(FILE*); +void WP_savegame(FILE*); + +void G_loadgame(FILE*); +void W_loadgame(FILE*); +void DOT_loadgame(FILE*); +void SMK_loadgame(FILE*); +void FX_loadgame(FILE*); +void IT_loadgame(FILE*); +void MN_loadgame(FILE*); +void PL_loadgame(FILE*); +void SW_loadgame(FILE*); +void WP_loadgame(FILE*); + +byte savname[7][24],savok[7]; + +int d_start,d_end,m_start,m_end,s_start,s_end,wad_num; +mwad_t wad[MAX_WAD]; + +char wads[MAX_WADS][__MAX_PATH]; +static FILE* wadh[MAX_WADS]; + +char f_drive[__MAX_DRIVE],f_dir[__MAX_DIR],f_name[__MAX_FNAME],f_ext[__MAX_EXT], + f_path[__MAX_PATH]; + +void F_startup(void) { + logo("F_startup: настройка файловой системы\n"); + memset(wads,0,sizeof(wads)); +} + +void F_getsavnames(void) { + + int i; FILE *h; + static char n[]="SAVGAME0.DAT"; + short ver; + + for(i=0;i<7;++i) { + n[7]=i+'0';memset(savname[i],0,24);savok[i]=0; + if((h=fopen(n,"rb"))==NULL) continue; //if((h=open(n,O_RDONLY|O_BINARY))==-1) continue; + myfread(savname[i],1,24,h);ver=-1;myfread(&ver,1,2,h); + fclose(h);savname[i][23]=0;savok[i]=(ver==3)?1:0;//savok[i]=(ver==2)?1:0; + } +} + +void F_savegame(int n,char *s) { + + FILE* h; + static char fn[]="SAVGAME0.DAT"; + + fn[7]=n+'0'; + if((h=fopen(fn,"wb"))==NULL) return; + myfwrite(s,1,24,h);myfwrite("\3\0",1,2,h);//myfwrite("\2\0",1,2,h); + G_savegame(h); + W_savegame(h); + DOT_savegame(h); + SMK_savegame(h); + FX_savegame(h); + IT_savegame(h); + MN_savegame(h); + PL_savegame(h); + SW_savegame(h); + WP_savegame(h); + fclose(h); + +} + +void F_loadgame(int n) { + FILE* h; + static char fn[]="SAVGAME0.DAT"; + short ver; + + fn[7]=n+'0'; + if((h=fopen(fn,"rb"))==NULL) return;//if((h=open(fn,O_BINARY|O_RDONLY))==-1) return; + fseek(h,24,SEEK_SET);myfread(&ver,1,2,h);if(ver!=3) return;//if(ver!=2) return; + G_loadgame(h); + W_loadgame(h); + DOT_loadgame(h); + SMK_loadgame(h); + FX_loadgame(h); + IT_loadgame(h); + MN_loadgame(h); + PL_loadgame(h); + SW_loadgame(h); + WP_loadgame(h); + fclose(h); +} + +void F_addwad(char *fn) { + int i; + + for(i=0;i=MAX_WAD) ERR_failinit("Слишком много элементов WAD'а"); + memcpy(wad[p].n,w.n,8); + wad[p].o=w.o;wad[p].l=w.l;wad[p].f=0; + ++p; + } + //fclose(h); + for(i=1;i=MAX_WAD) { + if(p>=MAX_WAD) ERR_failinit("Слишком много элементов WAD'а"); + memset(wad[p].n,0,8); + strncpy(wad[p].n,f_name,8); + wad[p].o=0L;wad[p].l=myfilelength(h);wad[p].f=i; + ++p; + } + continue; + } + *s=0;myfread(s,1,4,h); + if(strncmp(s,"IWAD",4)!=0 && strncmp(s,"PWAD",4)!=0) + ERR_failinit("Нет подписи IWAD или PWAD"); + myfread(&n,1,4,h);myfread(&o,1,4,h);fseek(h,o,SEEK_SET); + for(j=0;j=MAX_WAD) { + if(p>=MAX_WAD) ERR_failinit("Слишком много элементов WAD'а"); + memcpy(wad[p].n,w.n,8); + wad[p].o=w.o;wad[p].l=w.l;wad[p].f=i; + ++p; + } + } + } + wad_num=p; + +} + +// allocate resources +// (called from M_startup) +void F_allocres(void) { + d_start=F_getresid("D_START"); + d_end=F_getresid("D_END"); + m_start=F_getresid("M_START"); + m_end=F_getresid("M_END"); + s_start=F_getresid("S_START"); + s_end=F_getresid("S_END"); +} + +// load resource +void F_loadres(int r,void *p,dword o,dword l) { + + int oo; + FILE *fh; + + + oo=ftell(fh=wadh[wad[r].f]); + + if(fseek(fh,wad[r].o+o,SEEK_SET)!=0) + ERR_fatal("Ошибка при чтении файла"); + + if((dword)myfreadc(p,1,l,fh)!=l) + ERR_fatal("Ошибка при загрузке ресурса %.8s",wad[r].n); + + fseek(fh,oo,SEEK_SET); + +} + + +void F_saveres(int r,void *p,dword o,dword l) { + + int oo; + FILE* fh; + oo=ftell(fh=wadh[wad[r].f]); + if(fseek(fh,wad[r].o+o,SEEK_SET)!=0) + ERR_fatal("Ошибка при чтении файла"); + myfwrite(p,l,1,fh); + fseek(fh,oo,SEEK_SET); + +} + +// get resource id +int F_getresid(char *n) { + int i; + + for(i=0;i=m_end) i=m_start; + for(++i;;++i) { + if(i>=m_end) i=m_start+1; + + if (strcasecmp(wad[i].n,"MENU") == 0 || + strcasecmp(wad[i].n,"INTERMUS") == 0 || + strcasecmp(wad[i].n,"\x8a\x8e\x8d\x85\x96\x0") == 0) + continue; + + if(strncasecmp(wad[i].n,"DMI",3)!=0) break; + } + memcpy(s,wad[i].n,8); +} + +void F_randmus(char *s) { + int n = myrand(10); + int i; + for (i=0; i 2011 + + This file is part of the Doom2D:Rembo project. + + Doom2D:Rembo is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + Doom2D:Rembo is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see or + write to the Free Software Foundation, Inc., + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +// File operations + +///#include +//#include +#include + +#define MAX_WADS 20 +#define MAX_WAD 2000 + +typedef char wadname[8]; + +typedef struct { + int o,l; + char n[8]; +}wad_t; + +typedef struct { + int o,l; + char n[8]; + int f; +}mwad_t; + +void F_startup(void); +void F_addwad(char *); +void F_initwads(void); +void F_allocres(void); +//void F_preload(void); +void F_readstr(FILE*,char *,int); +void F_readstrz(FILE*,char *,int); +void F_loadres(int,void *,dword,dword); +int F_getresid(char *); +void F_getresname(char *,int); +int F_findres(char *); +int F_getsprid(char[4],int,int); +int F_getreslen(int); +void F_loadmap(char[8]); +void F_loadmus(char[8]); +void F_freemus(void); +void F_nextmus(char*); + +void F_getsavnames(void); +void F_loadgame(int); +void F_savegame(int,char*); + +void F_randmus(char*);// + +extern char wads[MAX_WADS][__MAX_PATH]; +extern int wad_num;