summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: eef55d4)
raw | patch | inline | side by side (parent: eef55d4)
author | ARembo <ARembo@gmail.com> | |
Sat, 23 Jul 2011 17:24:09 +0000 (20:24 +0300) | ||
committer | ARembo <ARembo@gmail.com> | |
Sat, 23 Jul 2011 17:24:09 +0000 (20:24 +0300) |
a8.c | [new file with mode: 0755] | patch | blob |
diff --git a/a8.c b/a8.c
--- /dev/null
+++ b/a8.c
@@ -0,0 +1,294 @@
+#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