summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cc5d01b)
raw | patch | inline | side by side (parent: cc5d01b)
author | Andriy Shinkarchuck <adriano32.gnu@gmail.com> | |
Sun, 24 Jul 2011 14:19:01 +0000 (17:19 +0300) | ||
committer | Andriy Shinkarchuck <adriano32.gnu@gmail.com> | |
Sun, 24 Jul 2011 14:19:01 +0000 (17:19 +0300) |
a8.c | patch | blob | history |
index fda8e6e2aae3f13b5efec7ebc19dd95d3529007f..7d521d3fdd7db6868f4d62b3917de30bd9ced510 100755 (executable)
--- a/a8.c
+++ b/a8.c
-#include "glob.h"\r
-#include <stdio.h>\r
-//#include <io.h>\r
-#include <fcntl.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include "vga.h"\r
-#include "keyb.h"\r
-#include "error.h"\r
-#include "files.h"\r
-#include "sound.h"\r
-\r
-\r
-/*\r
-#define WAIT_SZ 400000\r
-\r
-extern byte gamcor[5][64];\r
-\r
-extern char cd_path[];\r
-\r
-extern int gammaa;\r
-void setgamma(int);\r
-\r
-extern void *cd_scr;\r
-\r
-static byte skipping=0,credits=0;\r
-\r
-#define A8_ID 0xA8\r
-\r
-enum{\r
- A8C_ENDFR,A8C_PAL,A8C_CLRSCR,A8C_DRAW,\r
- A8C_FILL,A8C_DRAW2C,A8C_DRAW2\r
-};\r
-\r
-typedef struct{\r
- unsigned char id,ver;\r
- short width,height,frames;\r
- long maxfsize;\r
- long f1size;\r
-}a8_hdr_t;\r
-\r
-typedef unsigned char uchar;\r
-\r
-#define SQ 4\r
-\r
-static int sqw,sqh;\r
-\r
-static int norm_gamma;\r
-\r
-static unsigned char *frp,sqc[2][50][80];\r
-static int frame;\r
-static a8_hdr_t ah;\r
-static snd_t *strk;\r
-static int strk_ch;\r
-\r
-static signed char *unpack(char *d,signed char *p,int l) {\r
- for(;l>0;) if(*p>0) {\r
- memcpy(d,p+1,*p);d+=*p;l-=*p;p+=*p+1;\r
- }else if(*p<0) {\r
- memset(d,p[1],-*p);d+=-*p;l-=-*p;p+=2;\r
- }else return p+1;\r
- return p;\r
-}\r
-\r
-static unsigned char *draw(signed char *p) {\r
- int x,y,sy,yc,n;\r
-\r
- for(y=0;y<sqh;) if(*p>0) {\r
- for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {\r
- n=(*p++)*SQ;\r
- for(sy=0;sy<SQ;++sy) {\r
- p=unpack(scra+(y*SQ+sy)*320+x*SQ,p,n);\r
- }\r
- x+=n/SQ;\r
- }else x+=-*p++;\r
- }else y+=-*p++;\r
- return p;\r
-}\r
-\r
-static unsigned char *fill(signed char *p) {\r
- int x,y,yc,n;\r
-\r
- for(y=0;y<sqh;) if(*p>0) {\r
- for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {\r
- for(n=*p++;n;--n,++p,++x)\r
- V_clr(x*SQ,SQ,y*SQ,SQ,*p);\r
- }else x+=-*p++;\r
- }else y+=-*p++;\r
- return p;\r
-}\r
-\r
-static unsigned char *draw2c(signed char *p) {\r
- int x,y,sx,sy,yc,n;\r
- unsigned short w;\r
-\r
- for(y=0;y<sqh;) if(*p>0) {\r
- for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {\r
- for(n=*p++;n;--n,++x) {\r
- sqc[0][y][x]=*p++;\r
- sqc[1][y][x]=*p++;\r
- w=*(unsigned short*)p;p+=2;\r
- for(sy=0;sy<SQ;++sy)\r
- for(sx=0;sx<SQ;++sx,w>>=1)\r
- scra[(y*SQ+sy)*320+x*SQ+sx]=sqc[w&1][y][x];\r
- }\r
- }else x+=-*p++;\r
- }else y+=-*p++;\r
- return p;\r
-}\r
-\r
-static unsigned char *draw2(signed char *p) {\r
- int x,y,sx,sy,yc,n;\r
- unsigned short w;\r
-\r
- for(y=0;y<sqh;) if(*p>0) {\r
- for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {\r
- for(n=*p++;n;--n,++x) {\r
- w=*(unsigned short*)p;p+=2;\r
- for(sy=0;sy<SQ;++sy)\r
- for(sx=0;sx<SQ;++sx,w>>=1)\r
- scra[(y*SQ+sy)*320+x*SQ+sx]=sqc[w&1][y][x];\r
- }\r
- }else x+=-*p++;\r
- }else y+=-*p++;\r
- return p;\r
-}\r
-\r
-//---------------------------------------------------------------//\r
-\r
-static int fsz,fdptr;\r
-static FILE *fh;\r
-static char *fdata;\r
-\r
-\r
-static void f_close(void) {\r
- if(fdata) {\r
- free(fdata);fdata=NULL;\r
- }else if(fh!=NULL) {fclose(fh);fh=NULL;}\r
-}\r
-\r
-static char end_clr=1;\r
-*/\r
-\r
-void A8_close(void) {\r
-/*\r
- if(strk) if(strk_ch) S_stop(strk_ch);\r
- f_close();\r
- if(frp) {free(frp);frp=NULL;}\r
- if(strk) {free(strk);strk=NULL;}\r
- if(end_clr) {\r
- VP_fill(0,0,0);\r
- V_clr(0,320,0,200,0);V_copytoscr(0,320,0,200);\r
- setgamma(norm_gamma);\r
- }\r
-*/\r
-}\r
-\r
-int A8_nextframe(void) {\r
-/*\r
- unsigned char *p;\r
- int i,j,k;\r
- static int len;\r
-\r
- if(credits) if(keys[0x33] && keys[0x34]) skipping=1;\r
- if(frame==-1) if(strk) strk_ch=S_play(strk,-1,1024,255);\r
- if(fdata) {\r
- len=*(int*)(fdata+fdptr);fdptr+=4;\r
- }else {len=0;myfread(&len,1,4,fh);}\r
- len-=4;\r
- if(len<=0) {\r
- A8_close();\r
- return 0;\r
- }\r
- if(fdata) {\r
- p=fdata+fdptr;fdptr+=len;\r
- }else {myfread(frp,1,len,fh);p=frp;}\r
- for(;*p;) switch(*p++) {\r
- case A8C_PAL:\r
- i=*p++;j=*p++;if(!j) j=256;\r
- for(k=0;k<j*3;++k) p[k]=gamcor[3][p[k]];\r
- VP_set(p,i,j);\r
- p+=j*3;\r
- break;\r
- case A8C_CLRSCR:\r
- V_clr(0,ah.width,0,ah.height,*p++);\r
- break;\r
- case A8C_DRAW:\r
- p=draw(p);\r
- break;\r
- case A8C_FILL:\r
- p=fill(p);\r
- break;\r
- case A8C_DRAW2C:\r
- p=draw2c(p);\r
- break;\r
- case A8C_DRAW2:\r
- p=draw2(p);\r
- break;\r
- default:\r
- ERR_fatal("Плохой блок в файле A8");\r
- }\r
- ++frame;\r
- return 1;\r
- */\r
- return 0;\r
-}\r
-\r
-/*\r
-static char wscr;\r
-\r
-static void wait_scr(int s) {\r
- if(!end_clr) return;\r
- if(s<WAIT_SZ) return;\r
- F_freemus();\r
- V_setrect(0,320,0,200);\r
- V_clr(0,320,0,200,0);\r
- V_copytoscr(0,320,0,200);\r
- V_pic(0,0,(void*)((char*)cd_scr+768));\r
- VP_setall(cd_scr);\r
- V_copytoscr(0,320,0,200);\r
- wscr=1;\r
-}\r
-\r
-static void blank_scr(void) {\r
- VP_fill(0,0,0);\r
- V_setrect(0,320,0,200);\r
- V_clr(0,320,0,200,0);\r
- V_copytoscr(0,320,0,200);\r
-}\r
-*/\r
-\r
-int A8_start(char *nm) {\r
-\r
-/*\r
- static char s[40];\r
- int sz;\r
- FILE* h;\r
- unsigned char *p;\r
-\r
- end_clr=1;\r
- if(strcasecmp(nm,"FINAL")==0 || strcasecmp(nm,"CREDITS")==0) end_clr=0;\r
- else if(strcasecmp(nm,"KONEC")==0) end_clr=0;\r
- credits=(strcasecmp(nm,"FINAL")==0)?1:0;\r
- if(strcasecmp(nm,"CREDITS")==0) if(skipping) return 0;\r
- wscr=0;\r
- strk=NULL;strk_ch=0;\r
- fdata=NULL;frp=NULL;\r
- if(snd_type!=ST_NONE) {\r
- sprintf(s,"%sA8\\%s.SND",cd_path,nm);\r
- if((h=fopen(s,"rb"))!=NULL) {\r
- fseek(h,0,SEEK_END);sz=ftell(h);fseek(h,0,SEEK_SET);\r
- if((strk=malloc(sz+sizeof(snd_t)))!=NULL) {\r
- wait_scr(sz);\r
- myfread(strk+1,1,sz,h);\r
- strk->rate=11000;\r
- strk->len=sz;\r
- strk->lstart=strk->llen=0;\r
- for(p=(unsigned char *)(strk+1);sz;--sz,++p) *p^=0x80;\r
- }\r
- fclose(h);\r
- }\r
- }\r
- sprintf(s,"%sA8\\%s.A8",cd_path,nm);\r
- if((fh=fopen(s,"rb"))==NULL) {\r
- ERR_fatal("Не могу открыть файл %s",s);\r
- }\r
- myfread(&ah,1,sizeof(ah)-4,fh);\r
- if(ah.id!=A8_ID || ah.ver!=0) ERR_fatal("Испорченный файл A8 %s",s);\r
- fseek(fh,0,SEEK_END);\r
- fsz=ftell(fh)-sizeof(ah)+4;\r
- fseek(fh,sizeof(ah)-4,SEEK_SET);\r
- if((fdata=malloc(fsz))!=NULL) {\r
- wait_scr(fsz);\r
- myfread(fdata,1,fsz,fh);\r
- fdptr=0;\r
- fclose(fh);fh=NULL;\r
- }else if(!(frp=malloc(ah.maxfsize))) {\r
- if(strk) {free(strk);strk=NULL;}\r
- if(!(frp=malloc(ah.maxfsize))) {\r
- fclose(fh);fh=NULL;return 0;\r
- }\r
- }\r
- sqw=ah.width/SQ;sqh=ah.height/SQ;\r
- frame=-1;\r
- norm_gamma=gammaa;\r
- if(wscr) blank_scr();\r
-\r
-\r
- return 1;\r
-*/\r
-\r
- return 0;\r
-}\r
-\r
+/*
+ Copyright (C) Prikol Software 1996-1997
+ Copyright (C) Aleksey Volynskov 1996-1997
+ Copyright (C) <ARembo@gmail.com> 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 <http://www.gnu.org/licenses/> or
+ write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "glob.h"
+#include <stdio.h>
+//#include <io.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include "vga.h"
+#include "keyb.h"
+#include "error.h"
+#include "files.h"
+#include "sound.h"
+
+
+/*
+#define WAIT_SZ 400000
+
+extern byte gamcor[5][64];
+
+extern char cd_path[];
+
+extern int gammaa;
+void setgamma(int);
+
+extern void *cd_scr;
+
+static byte skipping=0,credits=0;
+
+#define A8_ID 0xA8
+
+enum{
+ A8C_ENDFR,A8C_PAL,A8C_CLRSCR,A8C_DRAW,
+ A8C_FILL,A8C_DRAW2C,A8C_DRAW2
+};
+
+typedef struct{
+ unsigned char id,ver;
+ short width,height,frames;
+ long maxfsize;
+ long f1size;
+}a8_hdr_t;
+
+typedef unsigned char uchar;
+
+#define SQ 4
+
+static int sqw,sqh;
+
+static int norm_gamma;
+
+static unsigned char *frp,sqc[2][50][80];
+static int frame;
+static a8_hdr_t ah;
+static snd_t *strk;
+static int strk_ch;
+
+static signed char *unpack(char *d,signed char *p,int l) {
+ for(;l>0;) if(*p>0) {
+ memcpy(d,p+1,*p);d+=*p;l-=*p;p+=*p+1;
+ }else if(*p<0) {
+ memset(d,p[1],-*p);d+=-*p;l-=-*p;p+=2;
+ }else return p+1;
+ return p;
+}
+
+static unsigned char *draw(signed char *p) {
+ int x,y,sy,yc,n;
+
+ for(y=0;y<sqh;) if(*p>0) {
+ for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {
+ n=(*p++)*SQ;
+ for(sy=0;sy<SQ;++sy) {
+ p=unpack(scra+(y*SQ+sy)*320+x*SQ,p,n);
+ }
+ x+=n/SQ;
+ }else x+=-*p++;
+ }else y+=-*p++;
+ return p;
+}
+
+static unsigned char *fill(signed char *p) {
+ int x,y,yc,n;
+
+ for(y=0;y<sqh;) if(*p>0) {
+ for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {
+ for(n=*p++;n;--n,++p,++x)
+ V_clr(x*SQ,SQ,y*SQ,SQ,*p);
+ }else x+=-*p++;
+ }else y+=-*p++;
+ return p;
+}
+
+static unsigned char *draw2c(signed char *p) {
+ int x,y,sx,sy,yc,n;
+ unsigned short w;
+
+ for(y=0;y<sqh;) if(*p>0) {
+ for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {
+ for(n=*p++;n;--n,++x) {
+ sqc[0][y][x]=*p++;
+ sqc[1][y][x]=*p++;
+ w=*(unsigned short*)p;p+=2;
+ for(sy=0;sy<SQ;++sy)
+ for(sx=0;sx<SQ;++sx,w>>=1)
+ scra[(y*SQ+sy)*320+x*SQ+sx]=sqc[w&1][y][x];
+ }
+ }else x+=-*p++;
+ }else y+=-*p++;
+ return p;
+}
+
+static unsigned char *draw2(signed char *p) {
+ int x,y,sx,sy,yc,n;
+ unsigned short w;
+
+ for(y=0;y<sqh;) if(*p>0) {
+ for(yc=*p++;yc;--yc,++y) for(x=0;x<sqw;) if(*p>0) {
+ for(n=*p++;n;--n,++x) {
+ w=*(unsigned short*)p;p+=2;
+ for(sy=0;sy<SQ;++sy)
+ for(sx=0;sx<SQ;++sx,w>>=1)
+ scra[(y*SQ+sy)*320+x*SQ+sx]=sqc[w&1][y][x];
+ }
+ }else x+=-*p++;
+ }else y+=-*p++;
+ return p;
+}
+
+//---------------------------------------------------------------//
+
+static int fsz,fdptr;
+static FILE *fh;
+static char *fdata;
+
+
+static void f_close(void) {
+ if(fdata) {
+ free(fdata);fdata=NULL;
+ }else if(fh!=NULL) {fclose(fh);fh=NULL;}
+}
+
+static char end_clr=1;
+*/
+
+void A8_close(void) {
+/*
+ if(strk) if(strk_ch) S_stop(strk_ch);
+ f_close();
+ if(frp) {free(frp);frp=NULL;}
+ if(strk) {free(strk);strk=NULL;}
+ if(end_clr) {
+ VP_fill(0,0,0);
+ V_clr(0,320,0,200,0);V_copytoscr(0,320,0,200);
+ setgamma(norm_gamma);
+ }
+*/
+}
+
+int A8_nextframe(void) {
+/*
+ unsigned char *p;
+ int i,j,k;
+ static int len;
+
+ if(credits) if(keys[0x33] && keys[0x34]) skipping=1;
+ if(frame==-1) if(strk) strk_ch=S_play(strk,-1,1024,255);
+ if(fdata) {
+ len=*(int*)(fdata+fdptr);fdptr+=4;
+ }else {len=0;myfread(&len,1,4,fh);}
+ len-=4;
+ if(len<=0) {
+ A8_close();
+ return 0;
+ }
+ if(fdata) {
+ p=fdata+fdptr;fdptr+=len;
+ }else {myfread(frp,1,len,fh);p=frp;}
+ for(;*p;) switch(*p++) {
+ case A8C_PAL:
+ i=*p++;j=*p++;if(!j) j=256;
+ for(k=0;k<j*3;++k) p[k]=gamcor[3][p[k]];
+ VP_set(p,i,j);
+ p+=j*3;
+ break;
+ case A8C_CLRSCR:
+ V_clr(0,ah.width,0,ah.height,*p++);
+ break;
+ case A8C_DRAW:
+ p=draw(p);
+ break;
+ case A8C_FILL:
+ p=fill(p);
+ break;
+ case A8C_DRAW2C:
+ p=draw2c(p);
+ break;
+ case A8C_DRAW2:
+ p=draw2(p);
+ break;
+ default:
+ ERR_fatal("Плохой блок в файле A8");
+ }
+ ++frame;
+ return 1;
+ */
+ return 0;
+}
+
+/*
+static char wscr;
+
+static void wait_scr(int s) {
+ if(!end_clr) return;
+ if(s<WAIT_SZ) return;
+ F_freemus();
+ V_setrect(0,320,0,200);
+ V_clr(0,320,0,200,0);
+ V_copytoscr(0,320,0,200);
+ V_pic(0,0,(void*)((char*)cd_scr+768));
+ VP_setall(cd_scr);
+ V_copytoscr(0,320,0,200);
+ wscr=1;
+}
+
+static void blank_scr(void) {
+ VP_fill(0,0,0);
+ V_setrect(0,320,0,200);
+ V_clr(0,320,0,200,0);
+ V_copytoscr(0,320,0,200);
+}
+*/
+
+int A8_start(char *nm) {
+
+/*
+ static char s[40];
+ int sz;
+ FILE* h;
+ unsigned char *p;
+
+ end_clr=1;
+ if(strcasecmp(nm,"FINAL")==0 || strcasecmp(nm,"CREDITS")==0) end_clr=0;
+ else if(strcasecmp(nm,"KONEC")==0) end_clr=0;
+ credits=(strcasecmp(nm,"FINAL")==0)?1:0;
+ if(strcasecmp(nm,"CREDITS")==0) if(skipping) return 0;
+ wscr=0;
+ strk=NULL;strk_ch=0;
+ fdata=NULL;frp=NULL;
+ if(snd_type!=ST_NONE) {
+ sprintf(s,"%sA8\\%s.SND",cd_path,nm);
+ if((h=fopen(s,"rb"))!=NULL) {
+ fseek(h,0,SEEK_END);sz=ftell(h);fseek(h,0,SEEK_SET);
+ if((strk=malloc(sz+sizeof(snd_t)))!=NULL) {
+ wait_scr(sz);
+ myfread(strk+1,1,sz,h);
+ strk->rate=11000;
+ strk->len=sz;
+ strk->lstart=strk->llen=0;
+ for(p=(unsigned char *)(strk+1);sz;--sz,++p) *p^=0x80;
+ }
+ fclose(h);
+ }
+ }
+ sprintf(s,"%sA8\\%s.A8",cd_path,nm);
+ if((fh=fopen(s,"rb"))==NULL) {
+ ERR_fatal("Не могу открыть файл %s",s);
+ }
+ myfread(&ah,1,sizeof(ah)-4,fh);
+ if(ah.id!=A8_ID || ah.ver!=0) ERR_fatal("Испорченный файл A8 %s",s);
+ fseek(fh,0,SEEK_END);
+ fsz=ftell(fh)-sizeof(ah)+4;
+ fseek(fh,sizeof(ah)-4,SEEK_SET);
+ if((fdata=malloc(fsz))!=NULL) {
+ wait_scr(fsz);
+ myfread(fdata,1,fsz,fh);
+ fdptr=0;
+ fclose(fh);fh=NULL;
+ }else if(!(frp=malloc(ah.maxfsize))) {
+ if(strk) {free(strk);strk=NULL;}
+ if(!(frp=malloc(ah.maxfsize))) {
+ fclose(fh);fh=NULL;return 0;
+ }
+ }
+ sqw=ah.width/SQ;sqh=ah.height/SQ;
+ frame=-1;
+ norm_gamma=gammaa;
+ if(wscr) blank_scr();
+
+
+ return 1;
+*/
+
+ return 0;
+}
+
//----------//
//----------//