summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8fb3d3f)
raw | patch | inline | side by side (parent: 8fb3d3f)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Tue, 10 Mar 2020 10:02:45 +0000 (13:02 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Tue, 10 Mar 2020 10:02:45 +0000 (13:02 +0300) |
14 files changed:
src/config.c | patch | blob | history | |
src/files.c | patch | blob | history | |
src/game.c | patch | blob | history | |
src/items.c | patch | blob | history | |
src/memory.c | patch | blob | history | |
src/memory.h | patch | blob | history | |
src/menu.c | patch | blob | history | |
src/misc.h | patch | blob | history | |
src/miscc.c | patch | blob | history | |
src/my.c | patch | blob | history | |
src/switch.c | patch | blob | history | |
src/vga.c | patch | blob | history | |
src/vga.h | patch | blob | history | |
src/view.c | patch | blob | history |
diff --git a/src/config.c b/src/config.c
index d0c4a9f1322545d2e9b87591a195d8ac6c82bdd0..2bf7f731dfac80c223640c4cbb8faa794be4ba6d 100644 (file)
--- a/src/config.c
+++ b/src/config.c
}
while(!feof(h)) {
F_readstr(h,s,127);
- if(*s==';' || s[1]==';') continue; // comment
- if(!(p1=strtok(s,"\r\n\t=;"))) continue;//if(!(p1=strtok(s,"\r\n\t =;"))) continue;
- if(!(p2=strtok(NULL,"\r\n\t=;"))) continue;//if(!(p2=strtok(NULL,"\r\n\t =;"))) continue;
- for(j=0;cfg[j].t;++j) if(cfg[j].cfg && !cfg[j].o)
- if(strcasecmp(p1,cfg[j].cfg)==0) {
- switch(cfg[j].t) {
- case BYTE:
- n=strtol(p2,NULL,0);
- *((byte *)cfg[j].p)=(byte)n;
- break;
- case WORD:
- n=strtol(p2,NULL,0);
- *((word *)cfg[j].p)=(word)n;
- break;
- case DWORD:
- n=strtol(p2,NULL,0);
- *((dword *)cfg[j].p)=n;
- break;
- case STRING:
- strcpy((char *)cfg[j].p,p2);
- break;
- case SW_ON:
- case SW_OFF:
- if(strcasecmp(p2,"ON")==0) {*((byte *)cfg[j].p)=ON;break;}
- if(strcasecmp(p2,"OFF")==0) {*((byte *)cfg[j].p)=OFF;break;}
- *((byte *)cfg[j].p)=strtol(p2,NULL,0);
- break;
- case FILES:
- break;
-
- case KEY:
- {
- int k = get_key(p2);
- if (k) {
- *((int *)cfg[j].p)=k;
- }
- else {
+ if(*s==';' || s[1]==';')
+ continue; // comment
+ if(!(p1=strtok(s,"\r\n\t=;")))
+ continue; //if(!(p1=strtok(s,"\r\n\t =;"))) continue;
+ if(!(p2=strtok(NULL,"\r\n\t=;")))
+ continue;//if(!(p2=strtok(NULL,"\r\n\t =;"))) continue;
+ for(j=0;cfg[j].t;++j) {
+ if(cfg[j].cfg && !cfg[j].o) {
+ if(strcasecmp(p1,cfg[j].cfg)==0) {
+ switch(cfg[j].t) {
+ case BYTE:
+ n=strtol(p2,NULL,0);
+ *((byte *)cfg[j].p)=(byte)n;
+ break;
+ case WORD:
+ n=strtol(p2,NULL,0);
+ *((word *)cfg[j].p)=(word)n;
+ break;
+ case DWORD:
+ n=strtol(p2,NULL,0);
+ *((dword *)cfg[j].p)=n;
+ break;
+ case STRING:
+ strcpy((char *)cfg[j].p,p2);
+ break;
+ case SW_ON:
+ case SW_OFF:
+ if(strcasecmp(p2,"ON")==0) {
+ *((byte *)cfg[j].p)=ON;
+ break;
+ }
+ if(strcasecmp(p2,"OFF")==0) {
+ *((byte *)cfg[j].p)=OFF;
+ break;
+ }
+ *((byte *)cfg[j].p)=strtol(p2,NULL,0);
+ break;
+ case FILES:
+ break;
+ case KEY:
+ {
+ int k = get_key(p2);
+ if (k) {
+ *((int *)cfg[j].p)=k;
+ } else {
logo("Unknown key in cfg: %s=%s\n",p1,p2);
logo("List available key names:\n");
int i;
logo("%s\n", s);
}
}
- }
- }
- break;
-
- default:
- ERR_failinit("!!! Неизвестный тип в cfg !!!");
- }
- break;
- }
- }
+ }
+ }
+ break;
+ default:
+ ERR_failinit("!!! Неизвестный тип в cfg !!!");
+ } // switch
+ break;
+ } // if
+ } // if
+ } // for
+ } // while
fclose(h);
}
diff --git a/src/files.c b/src/files.c
index 220d72cd254e4e9957ef83d5ff325aad2c4b4a83..eb6d36e943bbbda1b55d1082d79d7b04c473aade 100644 (file)
--- a/src/files.c
+++ b/src/files.c
extern void mysplitpath(const char* path, char* drv, char* dir, char* name, char* ext);
+static int myread_int32 (FILE *f) {
+ int x;
+ myfread(&x, 4, 1, f);
+ return int2host(x);
+}
+
// build wad directory
-void F_initwads(void) {
- int i,j,k,p;
+void F_initwads (void) {
+ int i, j, k, p;
FILE *h;
char s[4];
- int n,o;
+ int n, o;
wad_t w;
logo("F_initwads: подключение WAD-файлов\n");
- for(i=0;i<MAX_WAD;++i) wad[i].n[0]=0;
- logo(" подключается %s\n",wads[0]);
- if((wadh[0]=h=fopen(wads[0],"rb"))==NULL)//if((wadh[0]=h=open(wads[0],O_RDWR|O_BINARY))==-1)
- ERR_failinit("Не могу открыть файл: %s",wads[0]);//sys_errlist[errno]);
- *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,p=0;j<n;++j) {
- myfread(&w,1,16,h);
- 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=0;
- ++p;
+ for (i = 0; i < MAX_WAD; ++i) {
+ wad[i].n[0] = 0;
+ }
+
+ logo(" подключается %s\n", wads[0]);
+ if ((wadh[0] = h = fopen(wads[0], "rb")) == NULL) {
+ ERR_failinit("Не могу открыть файл: %s", wads[0]);
+ }
+
+ s[0] = '\0';
+ myfread(s, 1, 4, h);
+ if (strncmp(s, "IWAD", 4) != 0 && strncmp(s, "PWAD", 4) != 0) {
+ ERR_failinit("Нет подписи IWAD или PWAD (1)");
}
+
+ p = 0; // wad number
+ n = myread_int32(h); // num
+ o = myread_int32(h); // offset
+ fseek(h, o, SEEK_SET);
+ for (j = 0; j < n; ++j) {
+ w.o = myread_int32(h); // offset
+ w.l = myread_int32(h); // len
+ myfread(w.n, 1, 8, h); // name
+ if (p >= MAX_WAD) {
+ ERR_failinit("Слишком много элементов WAD'а");
+ }
+ wad[p].o = w.o;
+ wad[p].l = w.l;
+ memcpy(wad[p].n, w.n, 8);
+ wad[p].f = 0;
+ ++p;
+ }
+
//fclose(h);
- for(i=1;i<MAX_WADS;++i) if(wads[i][0]!=0) {
-
- logo(" подключается %s\n",wads[i]);
- if((wadh[i]=h=fopen(wads[i], "rb"))==NULL) //if((wadh[i]=h=open(wads[i],O_RDONLY|O_BINARY))==-1)
- ERR_failinit("Не могу открыть файл2: %s",wads[i]);//sys_errlist[errno]);
- mysplitpath(wads[i],f_drive,f_dir,f_name,f_ext);
- if(strcasecmp(f_ext,".lmp")==0) {
- for(k=0;k<MAX_WAD;++k) if(strncasecmp(wad[k].n,f_name,8)==0)
- {wad[k].o=0L;wad[k].l=myfilelength(h);wad[k].f=i;break;}
- if(k>=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<n;++j) {
- myfread(&w,1,16,h);
- for(k=0;k<MAX_WAD;++k) if(strncasecmp(wad[k].n,w.n,8)==0)
- {wad[k].o=w.o;wad[k].l=w.l;wad[k].f=i;break;}
- if(k>=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;
+
+ for (i = 1; i < MAX_WADS; ++i) {
+ if (wads[i][0] != 0) {
+ logo(" подключается %s\n", wads[i]);
+ if ((wadh[i] = h = fopen(wads[i], "rb")) == NULL) {
+ ERR_failinit("Не могу открыть файл2: %s", wads[i]);
+ }
+ mysplitpath(wads[i], f_drive, f_dir, f_name, f_ext);
+ if (strcasecmp(f_ext, ".lmp") == 0) {
+ for (k = 0; k < MAX_WAD; ++k) {
+ if (strncasecmp(wad[k].n, f_name, 8) == 0) {
+ wad[k].o = 0;
+ wad[k].l = myfilelength(h);
+ wad[k].f = i;
+ break;
+ }
+ if (k >= 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 = 0;
+ wad[p].l = myfilelength(h);
+ wad[p].f = i;
+ ++p;
+ }
+ }
+
+ s[0] = '\0';
+ myfread(s, 1, 4, h);
+ if (strncmp(s, "IWAD", 4) != 0 && strncmp(s, "PWAD", 4) != 0) {
+ ERR_failinit("Нет подписи IWAD или PWAD (2)");
+ }
+ n = myread_int32(h); // num
+ o = myread_int32(h); // offset
+ fseek(h, o, SEEK_SET);
+ for (j = 0; j < n; ++j) {
+ w.o = myread_int32(h); // offset
+ w.l = myread_int32(h); // len
+ myfread(w.n, 1, 8, h); // name
+ for (k = 0; k < MAX_WAD; ++k) {
+ if (strncasecmp(wad[k].n, w.n, 8) == 0) {
+ wad[k].o = w.o;
+ wad[k].l = w.l;
+ wad[k].f = i;
+ break;
+ }
+ if (k >= 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;
-
+ }
+
+ wad_num = p;
}
// allocate resources
}
// reads bytes from file until CR
-void F_readstr(FILE* h,char *s,int m) {
- int i;
- static char c;
-
- for(i=0;;) {
- c=13;
- myfreadc(&c,1,1,h);
- if(c==13) break;
- if(i<m) s[i++]=c;
+void F_readstr(FILE* h, char *s, int m) {
+ int i = 0;
+ size_t len = 0;
+ static char c = 0;
+ while (i < m) {
+ c = 13;
+ len = myfreadc(&c, 1, 1, h);
+ if (len == 0 || c == 13 || c == 10) {
+ break;
+ }
+ s[i] = c;
+ i++;
}
- s[i]=0;
+ s[i] = 0;
}
// reads bytes from file until NUL
void F_readstrz(FILE* h,char *s,int m) {
- int i;
- static char c;
-
- for(i=0;;) {
- c=0;
- myfreadc(&c,1,1,h);
- if(c==0) break;
- if(i<m) s[i++]=c;
+ int i = 0;
+ size_t len = 0;
+ static char c = 0;
+ while (i < m) {
+ c = 0;
+ len = myfreadc(&c, 1, 1, h);
+ if (len == 0 || c == 0) {
+ break;
+ }
+ s[i] = c;
+ i++;
}
- s[i]=0;
+ s[i] = 0;
}
map_block_t blk;
r=F_getresid(n);
fseek(h=wadh[wad[r].f],wad[r].o,SEEK_SET);
myfread(&hdr,1,sizeof(hdr),h);
+ hdr.ver = short2host(hdr.ver);
if(memcmp(hdr.id,"Doom2D\x1A",8)!=0)
ERR_fatal("%.8s не является уровнем",n);
for(;;) {
myfread(&blk,1,sizeof(blk),h);
+ blk.t = short2host(blk.t);
+ blk.st = short2host(blk.st);
+ blk.sz = int2host(blk.sz);
if(blk.t==MB_END) break;
if(blk.t==MB_COMMENT)
{fseek(h,blk.sz,SEEK_CUR);continue;}
diff --git a/src/game.c b/src/game.c
index f2f346304fc0193487d953b2f553e0a53f636fd9..1b35f7eb5469c3ed164c92c607d13602fbe1e77e 100644 (file)
--- a/src/game.c
+++ b/src/game.c
logo("G_init: настройка ресурсов игры ");
logo_gas(5,GGAS_TOTAL);
telepsnd=Z_getsnd("TELEPT");
- scrnh[0]=M_lock(F_getresid("TITLEPIC"));
- scrnh[1]=M_lock(F_getresid("INTERPIC"));
- scrnh[2]=M_lock(F_getresid("ENDPIC"));
- cd_scr=M_lock(F_getresid("CD1PIC"));
+ scrnh[0]=V_loadvgaimg("TITLEPIC");
+ scrnh[1]=V_loadvgaimg("INTERPIC");
+ scrnh[2]=V_loadvgaimg("ENDPIC");
+ cd_scr=V_loadvgaimg("CD1PIC");
for(i=0;i<2;++i) {
sprintf(s,"LTN%c",i+'1');
for(j=0;j<2;++j)
diff --git a/src/items.c b/src/items.c
index 06230c9c7f949bf83952a3697da60fbd654351a0..126fd5ce4e24e5f80fbc1e39895917cb3dc8fb75 100644 (file)
--- a/src/items.c
+++ b/src/items.c
case MB_THING:
for(i=0;blk.sz>0;++i,blk.sz-=8) {
myfread(&t,1,sizeof(t),h);
+ t.x = short2host(t.x);
+ t.y = short2host(t.y);
+ t.t = short2host(t.t);
+ t.f = short2host(t.f);
it[i].o.x=t.x;it[i].o.y=t.y;
it[i].t=t.t;it[i].s=t.f;
if(!it[i].t) break;
diff --git a/src/memory.c b/src/memory.c
index 5c7953cc813ee93a99753ff327c2618352bd54da..af93fa6f7b00a2af6d1a9d5bacd6d0a028e3ee00 100644 (file)
--- a/src/memory.c
+++ b/src/memory.c
if(!resl[h]) return;
--resl[h];
}
+
+int M_locked (int h) {
+ h&=-1-0x8000;
+ return (h != -1) && (h != 0xFFFF) && (resl[h] != 0);
+}
+
+int M_was_locked (int h) {
+ h&=-1-0x8000;
+ return (h != -1) && (h != 0xFFFF) && (resp[h] != NULL);
+}
diff --git a/src/memory.h b/src/memory.h
index b63501604ea96fcf2553db2e53198525912de15c..84ca70f31e317f67299b6a520873b388615eb58d 100644 (file)
--- a/src/memory.h
+++ b/src/memory.h
void M_shutdown(void);
void *M_lock(int);
void M_unlock(void *);
+int M_locked(int);
+int M_was_locked(int);
diff --git a/src/menu.c b/src/menu.c
index ff6932df60e4741b38dab3450fb49940762fe20c..aca7cd43d0c407057c0d632d4ebd93ad1e788c1b 100644 (file)
--- a/src/menu.c
+++ b/src/menu.c
msnd4=Z_getsnd("SWTCHX");
msnd5=Z_getsnd("SUDI");
msnd6=Z_getsnd("TUDI");
- msklh[0]=M_lock(F_getresid("M_SKULL1"));
+ msklh[0]=V_loadvgaimg("M_SKULL1");
// msklh[0]=load_vga("vga\\spr.vga","M_SKULL1");
- msklh[1]=M_lock(F_getresid("M_SKULL2"));
- mbarl=M_lock(F_getresid("M_THERML"));
- mbarm=M_lock(F_getresid("M_THERMM"));
- mbarr=M_lock(F_getresid("M_THERMR"));
- mbaro=M_lock(F_getresid("M_THERMO"));
- mslotl=M_lock(F_getresid("M_LSLEFT"));
- mslotm=M_lock(F_getresid("M_LSCNTR"));
- mslotr=M_lock(F_getresid("M_LSRGHT"));
+ msklh[1]=V_loadvgaimg("M_SKULL2");
+ mbarl=V_loadvgaimg("M_THERML");
+ mbarm=V_loadvgaimg("M_THERMM");
+ mbarr=V_loadvgaimg("M_THERMR");
+ mbaro=V_loadvgaimg("M_THERMO");
+ mslotl=V_loadvgaimg("M_LSLEFT");
+ mslotm=V_loadvgaimg("M_LSCNTR");
+ mslotr=V_loadvgaimg("M_LSRGHT");
K_setkeyproc(G_keyf);
}
diff --git a/src/misc.h b/src/misc.h
index 6d4ac768d65b83fa4df470667244eee256a62b8f..60eaee5bf5ec9ce7ea63f24d91ef3c1aea4047c1 100644 (file)
--- a/src/misc.h
+++ b/src/misc.h
int Z_getacid(int x,int y,int r,int h);
void Z_clrst();
+
+unsigned short int short2host (unsigned short int x);
+unsigned int int2host (unsigned int x);
diff --git a/src/miscc.c b/src/miscc.c
index 4fd6353f0c4feadb1d101572052e082b8850346c..7123938b16356714846b4fed3ba705b5ab6c4c19 100644 (file)
--- a/src/miscc.c
+++ b/src/miscc.c
h=F_getsprid(n,s,d);
if(dir) *dir=(h&0x8000)?1:0;
- return M_lock(h);
+ //return M_lock(h);
+ return V_getvgaimg(h);
}
void *Z_getsnd(char n[6]) {
//if(snd_type==-1) return NULL;
strncpy(s+2,n,6);s[0]='D';
s[1]='S';
- return M_lock(F_getresid(s));
+
+ int id = F_getresid(s);
+ int loaded = M_was_locked(id);
+ snd_t *snd = M_lock(id);
+ if (snd != NULL && !loaded) {
+ snd->len = int2host(snd->len);
+ snd->rate = int2host(snd->rate);
+ snd->lstart = int2host(snd->lstart);
+ snd->llen = int2host(snd->llen);
+ }
+ return snd;
}
int Z_sound(void *s,int v) {
"PLASA0","BFUGA0","GUN2A0"
};
- stone=M_lock(F_getresid("STONE"));
- stone2=M_lock(F_getresid("STONE2"));
- keys[0]=M_lock(F_getresid("KEYRA0"));
- keys[1]=M_lock(F_getresid("KEYGA0"));
- keys[2]=M_lock(F_getresid("KEYBA0"));
+ stone=V_loadvgaimg("STONE");
+ stone2=V_loadvgaimg("STONE2");
+ keys[0]=V_loadvgaimg("KEYRA0");
+ keys[1]=V_loadvgaimg("KEYGA0");
+ keys[2]=V_loadvgaimg("KEYBA0");
for(i=0;i<22;++i)
- sth[i]=M_lock(F_getresid(nm[i]));
+ sth[i]=V_loadvgaimg(nm[i]);
strcpy(s,"STBF_*");
for(i='!';i<160;++i) {
s[5]=i;
- bfh[i-'!']=M_lock(F_findres(s));
+ bfh[i-'!']=V_getvgaimg(F_findres(s));
if(!(i&15)) logo_gas(GAS_START+((i-'!')>>4),GAS_TOTAL);
}
for(i='!';i<160;++i) {
sprintf(s,"STCFN%03d",i);
- sfh[i-'!']=M_lock(F_findres(s));
+ sfh[i-'!']=V_getvgaimg(F_findres(s));
if(!(i&15)) logo_gas(GAS_START+8+((i-'!')>>4),GAS_TOTAL);
}
strcpy(s,"WINUM*");
for(i='0';i<='9';++i) {
s[5]=i;
- bfh[i-'!']=M_lock(F_getresid(s));
+ bfh[i-'!']=V_loadvgaimg(s);
}
- bfh[':'-'!']=M_lock(F_getresid("WICOLON"));
+ bfh[':'-'!']=V_loadvgaimg("WICOLON");
bulsnd[0]=Z_getsnd("BUL1");
bulsnd[1]=Z_getsnd("BUL2");
}
t = t / 60;
*h = t;
}
+
+unsigned short int short2host (unsigned short int x) {
+#if __BIG_ENDIAN__
+ union {
+ unsigned char a[2];
+ unsigned short int x;
+ } y;
+ y.x = x;
+ unsigned char t = y.a[0]; y.a[0] = y.a[1]; y.a[1] = t;
+ return y.x;
+#else
+ return x;
+#endif
+}
+
+unsigned int int2host (unsigned int x) {
+#if __BIG_ENDIAN__
+ union {
+ unsigned char a[4];
+ unsigned int x;
+ } y;
+ y.x = x;
+ #define SWAP_VAR(a, b) do { unsigned char t = a; a = b; b = t; } while(0)
+ SWAP_VAR(y.a[0], y.a[3]);
+ SWAP_VAR(y.a[1], y.a[2]);
+ #undef SWAP_VAR
+ return y.x;
+#else
+ return x;
+#endif
+}
diff --git a/src/my.c b/src/my.c
index c7fe41cc48e123680241b4f7015448e83dd90134..0a7fcbcd6ce4a20958b2d915e730c2ee9fb89a81 100644 (file)
--- a/src/my.c
+++ b/src/my.c
}
}
-void myfread(void *ptr, size_t n, size_t size, FILE *f) {
- if (fread(ptr,n,size,f) != size) ERR_fatal("File reading error\n");
+size_t myfreadc(void *ptr, size_t size, size_t n, FILE *f) {
+ return fread(ptr, size, n, f);
}
-size_t myfreadc(void *ptr, size_t n, size_t size, FILE *f) {
- return fread(ptr,n,size,f);
+void myfread(void *ptr, size_t size, size_t n, FILE *f) {
+ if (myfreadc(ptr, size, n, f) != n) {
+ ERR_fatal("File reading error\n");
+ }
}
void myfwrite(void *ptr, size_t n, size_t size, FILE *f) {
diff --git a/src/switch.c b/src/switch.c
index cc418b8bc5287bf7291fe8612e680fe2ff9e6e83..980955dee5f54ad7ebb42b5be4c9b00f806fe2b0 100644 (file)
--- a/src/switch.c
+++ b/src/switch.c
sw_secrets=0;
for(i=0;i<MAXSW && blk.sz>0;++i,blk.sz-=sizeof(sw_t)) {
myfread(sw+i,1,sizeof(sw_t),h);
+ sw[i].c = short2host(sw[i].c);
sw[i].tm=0;sw[i].d=0;
sw[i].f|=0x80;
if(sw[i].t==SW_SECRET) ++sw_secrets;
diff --git a/src/vga.c b/src/vga.c
index e06baf482dd3ed2a891a5e154a5ce38f434b54ac..5db6b53cf0c7cf457785348c5c8bace494811406 100644 (file)
--- a/src/vga.c
+++ b/src/vga.c
#include <SDL.h>
#include "error.h"
#include "view.h"
+#include "memory.h"
+
+#include <assert.h>
// адрес экранного буфера
#define HQ 2
+vgaimg *V_getvgaimg (int id) {
+ int loaded = M_was_locked(id);
+ vgaimg *v = M_lock(id);
+ if (v != NULL && !loaded) {
+ v->w = short2host(v->w);
+ v->h = short2host(v->h);
+ v->sx = short2host(v->sx);
+ v->sy = short2host(v->sy);
+ }
+ return v;
+}
+
+vgaimg *V_loadvgaimg (char *name) {
+ return V_getvgaimg(F_getresid(name));
+}
+
short V_init(void)
{
Uint32 flags = SDL_SWSURFACE|SDL_DOUBLEBUF|SDL_HWPALETTE;
diff --git a/src/vga.h b/src/vga.h
index 132af8cbd210247ef2c16757c030d0edd0f10755..cc90ca5493d08c60b2ab73a60c6ee30f4d97daa5 100644 (file)
--- a/src/vga.h
+++ b/src/vga.h
typedef void spr_f(int, int, unsigned char);//typedef void spr_f(void);
+vgaimg *V_getvgaimg (int id);
+vgaimg *V_loadvgaimg (char *name);
+
// переключение в режим VGA 320x200,256 цветов
// возвращает 0, если все о'кей
short V_init(void);
diff --git a/src/view.c b/src/view.c
index 0d19be0e66e0fc562a7e1ce294c2763d7de937c0..3bf36772cd60cec019f9d89528746c84613d03c6 100644 (file)
--- a/src/view.c
+++ b/src/view.c
walani[i]=getani(s);
if(strncasecmp(s,"_WATER_",7)==0) { //if(memicmp(s,"_WATER_",7)==0) {
walh[i]=-2;walp[i]=(void*)(s[7]-'0'+1);
- }else walp[i]=M_lock(walh[i]=F_getresid(s));
+ } else {
+ walh[i]=F_getresid(s);
+ walp[i]=V_getvgaimg(walh[i]);
+ }
}
myfread(walf,1,sizeof(walf),h);
for(i=1;i<256;++i) if(walf[i]&1) walh[i]|=0x8000;
myfread(fldf,1,FLDW*FLDH,h);
strcpy(s,"RSKY1");s[4]=sky_type+'0';
M_unlock(horiz);
- horiz=M_lock(F_getresid(s));
+ horiz=V_loadvgaimg(s);
}
void W_adjust(void) {
PL_init();
MN_init();
M_unlock(horiz);
- horiz=M_lock(F_getresid("RSKY1"));
+ horiz=V_loadvgaimg("RSKY1");
free_chunks();
}
if(g_time%3!=0) return;
for(i=1;i<256;++i) if((a=walani[i])!=0) {
if(anih[a][++anic[a]]==-1) anic[a]=0;
- walp[i]=M_lock(anih[a][anic[a]]);
+ walp[i]=V_getvgaimg(anih[a][anic[a]]);
}
}
+/*
static void unpack(void *buf,int len,void *obuf) {
byte *p,*o;
int l,n;
n=*((word*)(++p));memset(o,*(p+=2),n);o+=n;l-=3;
}else *(o++)=*p;
}
+*/
+
+static void unpack(void *buf, int len, void *obuf) {
+ int i = 0;
+ int j = 0;
+ unsigned char *p = buf;
+ unsigned char *q = obuf;
+ while (i < len) {
+ int id = p[i];
+ int step = 1;
+ i += 1;
+ if (id == 0xff) {
+ step = p[i] | p[i + 1] << 8;
+ id = p[i + 2];
+ i += 3;
+ }
+ memset(&q[j], id, step);
+ j += step;
+ }
+}
int W_load(FILE* h) {
int i,j,k,g;
if(strncasecmp(w.n,"_WATER_",7)==0) //if(memicmp(w.n,"_WATER_",7)==0)
{walp[i]=(void*)(w.n[7]-'0'+1);walh[i]=-2;continue;}
- walp[i]=M_lock(walh[i]=F_getresid(w.n));
+
+ walh[i]=F_getresid(w.n);
+ walp[i]=V_getvgaimg(walh[i]);
if(w.n[0]=='S' && w.n[1]=='W' && w.n[4]=='_') walswp[i]=0;
walf[i]=(w.t)?1:0;if(w.t) walh[i]|=0x8000;
g=F_getresid(w.n)|(walh[i]&0x8000);
for(k=1;k<256;++k) if(walh[k]==g) break;
if(k>=256) {
- walh[k=j++]=g;walp[k]=M_lock(g);
+ walh[k=j++]=g;walp[k]=V_getvgaimg(g);
walf[k]=(g&0x8000)?1:0;
}
walswp[i]=k;walswp[k]=i;
default: return 0;
}return 1;
case MB_SKY:
- sky_type=0;myfread(&sky_type,1,2,h);
+ sky_type=0;myfread(&sky_type,2,1,h);
+ sky_type = short2host(sky_type);
strcpy(w.n,"RSKY1");w.n[4]=sky_type+'0';
M_unlock(horiz);
- horiz=M_lock(F_getresid(w.n));
+ horiz=V_loadvgaimg(w.n);
return 1;
}return 0;
}