summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2cd3d04)
raw | patch | inline | side by side (parent: 2cd3d04)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 7 Apr 2021 05:57:00 +0000 (08:57 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 7 Apr 2021 05:57:00 +0000 (08:57 +0300) |
src/common/streams.h | patch | blob | history | |
src/common/wadres.c | [new file with mode: 0644] | patch | blob |
src/common/wadres.h | [new file with mode: 0644] | patch | blob |
src/files.c | patch | blob | history | |
src/files.h | patch | blob | history | |
src/map.c | patch | blob | history | |
src/map.h | patch | blob | history | |
src/memory.c | patch | blob | history | |
src/sdl/main.c | patch | blob | history |
diff --git a/src/common/streams.h b/src/common/streams.h
index 8952e24dac7ce5717329534e0860998f6419f07a..d82b51af477658e54029da426619cb8019b9445d 100644 (file)
--- a/src/common/streams.h
+++ b/src/common/streams.h
typedef struct Reader Reader;
typedef struct Writer Writer;
+typedef struct Handle Handle;
struct Reader {
long (*getpos)(Reader *r);
diff --git a/src/common/wadres.c b/src/common/wadres.c
--- /dev/null
+++ b/src/common/wadres.c
@@ -0,0 +1,120 @@
+#include <stdint.h>
+#include <string.h>
+#include <assert.h>
+
+#include "common/wadres.h"
+#include "common/streams.h"
+#include "cp866.h"
+
+typedef struct Entry {
+ long offset, size;
+ char name[8];
+ int f;
+} Entry;
+
+static int n_wads;
+static int n_resources;
+static Reader *wads[MAX_WADS];
+static Entry resources[MAX_RESOURCES];
+
+static int check_header (Reader *r) {
+ assert(r != NULL);
+ char ident[4];
+ r->setpos(r, 0);
+ stream_read(ident, 4, 1, r);
+ return (memcmp(ident, "IWAD", 4) == 0) || (memcmp(ident, "PWAD", 4) == 0);
+}
+
+int WADRES_addwad (Reader *r) {
+ assert(r != NULL);
+ if (n_wads < MAX_WADS && check_header(r)) {
+ wads[n_wads] = r;
+ n_wads += 1;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+static int WADRES_addresource (const Entry *e) {
+ assert(e != NULL);
+ for (int i = 0; i < n_resources; ++i) {
+ if (cp866_strncasecmp(resources[i].name, e->name, 8) == 0) {
+ memcpy(&resources[i], e, sizeof(Entry));
+ return i;
+ }
+ }
+ if (n_resources < MAX_RESOURCES) {
+ memcpy(&resources[n_resources], e, sizeof(Entry));
+ n_resources += 1;
+ return n_resources - 1;
+ }
+ return -1;
+}
+
+static int WADRES_read (Reader *r) {
+ r->setpos(r, 4); // skip magic
+ int32_t n = stream_read32(r);
+ int32_t dir = stream_read32(r);
+ r->setpos(r, dir);
+ int ok = 1;
+ for (int32_t i = 0; ok && i < n; ++i) {
+ Entry e;
+ e.offset = stream_read32(r);
+ e.size = stream_read32(r);
+ stream_read(e.name, 8, 1, r);
+ ok = WADRES_addresource(&e) != -1;
+ }
+ return ok;
+}
+
+int WADRES_rehash (void) {
+ int ok = 1;
+ for (int i = 0; i < n_wads; ++i) {
+ if (!WADRES_read(wads[i])) {
+ ok = 0;
+ }
+ }
+ return ok;
+}
+
+int WADRES_find (const char name[8]) {
+ int i = n_resources - 1;
+ while (i >= 0 && cp866_strncasecmp(name, resources[i].name, 8) != 0) {
+ i -= 1;
+ }
+ return i;
+}
+
+int WADRES_maxids (void) {
+ return n_resources;
+}
+
+Reader *WADRES_getbasereader (int id) {
+ assert(id >= 0 && id < n_resources);
+ return wads[resources[id].f];
+}
+
+long WADRES_getoffset (int id) {
+ assert(id >= 0 && id < n_resources);
+ return resources[id].offset;
+}
+
+long WADRES_getsize (int id) {
+ assert(id >= 0 && id < n_resources);
+ return resources[id].size;
+}
+
+void WADRES_getname (int id, char *name) {
+ assert(id >= 0 && id < n_resources);
+ strncpy(name, resources[id].name, 8);
+}
+
+void WADRES_getdata (int id, void *data) {
+ assert(id >= 0 && id < n_resources);
+ Reader *r = wads[resources[id].f];
+ long pos = r->getpos(r);
+ r->setpos(r, resources[id].offset);
+ stream_read(data, resources[id].size, 1, r);
+ r->setpos(r, pos);
+}
diff --git a/src/common/wadres.h b/src/common/wadres.h
--- /dev/null
+++ b/src/common/wadres.h
@@ -0,0 +1,21 @@
+#ifndef COMMON_WADRES_H_INCLUDED
+#define COMMON_WADRES_H_INCLUDED
+
+#include "common/streams.h"
+
+#define MAX_WADS 20
+#define MAX_RESOURCES 2000
+
+int WADRES_addwad (Reader *r);
+int WADRES_rehash (void);
+
+int WADRES_find (const char name[8]);
+int WADRES_maxids (void);
+
+Reader *WADRES_getbasereader (int id);
+long WADRES_getoffset (int id);
+long WADRES_getsize (int id);
+void WADRES_getname (int id, char *name);
+void WADRES_getdata (int id, void *data);
+
+#endif /* COMMON_WADRES_H_INCLUDED */
\ No newline at end of file
diff --git a/src/files.c b/src/files.c
index e470830be662a62216d3daac74cda57eec157d4a..704ca271b9f3c40f6fae889dec624f7ad6533f64 100644 (file)
--- a/src/files.c
+++ b/src/files.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <assert.h>
#ifdef UNIX
# include <sys/stat.h>
#endif
#include "error.h"
#include "cp866.h"
-typedef struct {
- byte n, i, v, d;
-} dmv;
+#include "common/streams.h"
+#include "common/files.h"
+#include "common/wadres.h"
int d_start, d_end;
-mwad_t wad[MAX_WAD];
-char wads[MAX_WADS][__MAX_PATH];
-FILE* wadh[MAX_WADS];
-
-static byte seq[255];
-static byte seqn;
-static int inum=0;
-static dmv *pat=NULL;
-static unsigned *patp;
-static void **dmi;
-
static int m_start, m_end;
static int s_start, s_end;
-static int wad_num;
-
-static char f_drive[__MAX_DRIVE];
-static char f_dir[__MAX_DIR];
-static char f_name[__MAX_FNAME];
-static char f_ext[__MAX_EXT];
void F_startup (void) {
logo("F_startup: setup file system\n");
- memset(wads,0,sizeof(wads));
}
void F_addwad (const char *fn) {
- int i;
-
- for(i=0;i<MAX_WADS;++i) if(wads[i][0]==0) {
- strcpy(wads[i],fn);return;
+ static int i = 0;
+ static FILE_Reader wadh[MAX_WADS];
+ if (i < MAX_WADS) {
+ if (FILE_OpenReader(&wadh[i], fn)) {
+ if (WADRES_addwad(&wadh[i].base)) {
+ i += 1;
+ } else {
+ ERR_failinit("Invalid WAD %s", fn);
+ }
+ } else {
+ ERR_failinit("Unable to add WAD %s", fn);
+ }
+ } else {
+ ERR_failinit("Too many wads");
}
- ERR_failinit("Unable to add WAD %s",fn);
-}
-
-static int myfilelength (FILE *h) {
- int pos = ftell(h);
- fseek (h, 0, SEEK_END);
- int len = ftell(h);
- fseek (h, pos, SEEK_SET);
- return len;
}
-// build wad directory
void F_initwads (void) {
- int i, j, k, p;
- FILE *h;
- char s[4];
- int n, o;
- wad_t w;
-
- logo("F_initwads: use WAD-files\n");
- for (i = 0; i < MAX_WAD; ++i) {
- wad[i].n[0] = 0;
- }
-
- logo(" add %s\n", wads[0]);
- if ((wadh[0] = h = fopen(wads[0], "rb")) == NULL) {
- ERR_failinit("Unable to open file: %s", wads[0]);
- }
-
- s[0] = '\0';
- myfread(s, 1, 4, h);
- if (strncmp(s, "IWAD", 4) != 0 && strncmp(s, "PWAD", 4) != 0) {
- ERR_failinit("Not IWAD or PWAD (1)");
- }
-
- p = 0; // wad number
- n = myfread32(h); // num
- o = myfread32(h); // offset
- fseek(h, o, SEEK_SET);
- for (j = 0; j < n; ++j) {
- w.o = myfread32(h); // offset
- w.l = myfread32(h); // len
- myfread(w.n, 1, 8, h); // name
- if (p >= MAX_WAD) {
- ERR_failinit("Too many entries in the WAD");
- }
- wad[p].o = w.o;
- wad[p].l = w.l;
- memcpy(wad[p].n, w.n, 8);
- wad[p].f = 0;
- ++p;
+ if (!WADRES_rehash()) {
+ ERR_failinit("F_initwads: failed rehash");
}
-
- //fclose(h);
-
- for (i = 1; i < MAX_WADS; ++i) {
- if (wads[i][0] != 0) {
- logo(" add %s\n", wads[i]);
- if ((wadh[i] = h = fopen(wads[i], "rb")) == NULL) {
- ERR_failinit("Unable to open file (2): %s", wads[i]);
- }
- mysplitpath(wads[i], f_drive, f_dir, f_name, f_ext);
- if (cp866_strcasecmp(f_ext, ".lmp") == 0) {
- for (k = 0; k < MAX_WAD; ++k) {
- if (cp866_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("Too many entries in the 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("Not IWAD or PWAD (2)");
- }
- n = myfread32(h); // num
- o = myfread32(h); // offset
- fseek(h, o, SEEK_SET);
- for (j = 0; j < n; ++j) {
- w.o = myfread32(h); // offset
- w.o = myfread32(h); // len
- myfread(w.n, 1, 8, h); // name
- for (k = 0; k < MAX_WAD; ++k) {
- if (cp866_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("Too many entries in the 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("Error while file reading");
-
- if((dword)myfreadc(p,1,l,fh)!=l)
- ERR_fatal("Error while loading resource %.8s", wad[r].n);
-
- fseek(fh,oo,SEEK_SET);
-
+ 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");
}
-/*
-// unused
-void F_saveres(int r, void *p, dword o, dword l) {
- FILE* fh = wadh[wad[r].f];
- int oo = ftell(fh);
- if (fseek(fh, wad[r].o + o, SEEK_SET) != 0) {
- ERR_fatal("Error while reading file");
- }
- myfwrite(p, l, 1, fh);
- fseek(fh, oo, SEEK_SET);
+void F_loadres (int r, void *p) {
+ WADRES_getdata(r, p);
}
-*/
-// get resource id
int F_findres (const char n[8]) {
- int i;
- for (i = 0; i < wad_num; i++) {
- if (cp866_strncasecmp(wad[i].n, n, 8) == 0) {
- return i;
- }
- }
- return -1;
+ return WADRES_find(n);
}
-// get resource id
int F_getresid (const char n[8]) {
int i = F_findres(n);
if (i == -1) {
}
void F_getresname (char n[8], int r) {
- memcpy(n, wad[r].n, 8);
+ WADRES_getname(r, n);
}
-// get sprite id
int F_getsprid (const char n[4], int s, int d, char *dir) {
- int i;
- byte a, b;
s += 'A';
d += '0';
- for (i = s_start + 1; i < s_end; i++) {
- if (cp866_strncasecmp(wad[i].n, n, 4) == 0 && (wad[i].n[4] == s || wad[i].n[6] == s)) {
- a = wad[i].n[4] == s ? wad[i].n[5] : 0;
- b = wad[i].n[6] == s ? wad[i].n[7] : 0;
+ for (int i = s_start + 1; i < s_end; i++) {
+ char wn[8];
+ byte a, b;
+ WADRES_getname(i, wn);
+ if (cp866_strncasecmp(wn, n, 4) == 0 && (wn[4] == s || wn[6] == s)) {
+ a = wn[4] == s ? wn[5] : 0;
+ b = wn[6] == s ? wn[7] : 0;
if (a == '0' || b == '0' || a == d || b == d) {
if (dir != NULL) {
- *dir = a != '0' && b == '0' || a != d && b == d;
+ *dir = (a != '0' && b == '0') || (a != d && b == d);
}
return i;
}
}
int F_getreslen (int r) {
- return wad[r].l;
+ return WADRES_getsize(r);
}
void F_nextmus (char *s) {
- int i;
- i=F_findres(s);
- if(i<=m_start || i>=m_end) i=m_start;
- for(++i;;++i) {
- if(i>=m_end) i=m_start+1;
-
- if (cp866_strcasecmp(wad[i].n,"MENU") == 0 ||
- cp866_strcasecmp(wad[i].n,"INTERMUS") == 0 ||
- cp866_strcasecmp(wad[i].n,"\x8a\x8e\x8d\x85\x96\x0") == 0)
- continue;
-
- if(cp866_strncasecmp(wad[i].n,"DMI",3)!=0) break;
+ int i = F_findres(s);
+ if (i <= m_start || i >= m_end) {
+ i = m_start;
+ }
+ for (++i; ; ++i) {
+ if (i >= m_end) {
+ i = m_start + 1;
+ }
+ WADRES_getname(i, s);
+ if (cp866_strcasecmp(s, "MENU") == 0 ||
+ cp866_strcasecmp(s, "INTERMUS") == 0 ||
+ cp866_strcasecmp(s, "\x8a\x8e\x8d\x85\x96\x0") == 0) {
+ continue;
+ }
+ if (cp866_strncasecmp(s, "DMI", 3) != 0) {
+ break;
+ }
}
- memcpy(s,wad[i].n,8);
}
void F_randmus (char *s) {
s[i] = 0;
}
-/*
-// unused
-// reads bytes from file until NUL
-void F_readstrz (FILE* h,char *s,int m) {
- 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;
+void F_loadmap (char n[8]) {
+ int id = F_getresid(n);
+ if (id != -1) {
+ Reader *r = WADRES_getbasereader(id);
+ long offset = WADRES_getoffset(id);
+ r->setpos(r, offset);
+ if (!MAP_load(r)) {
+ ERR_fatal("Failed to load map");
}
- s[i] = c;
- i++;
+ } else {
+ ERR_fatal("Failed to load map: resource %.8s not found", n);
}
- s[i] = 0;
-}
-*/
-
-/*void F_freemus(void) {
-
- int i;
-
- if(!pat) return;
- S_stopmusic();
- free(pat);free(patp);
- for(i=0;i<inum;++i) if(dmi[i]!=NULL) free(dmi[i]);
- free(dmi);
- pat=NULL;
-
}
-*/
-
-/*void F_loadmus(char n[8]) {
- int r,i,j;
- FILE *h;
- int o;
- struct{
- char id[4];
- byte ver,pat;
- word psz;
- }d;
- struct{byte t;char n[13];word r;}di;
-
- if((r=F_findres(n))==-1) return;
- fseek(h=wadh[wad[r].f],wad[r].o,SEEK_SET);
- myfread(&d,1,sizeof(d),h);
- if(memcmp(d.id,"DMM",4)!=0) return;
- if(!(pat=malloc(d.psz<<2))) return;
- myfread(pat,1,d.psz<<2,h);
- myfread(&seqn,1,1,h);if(seqn) myfread(seq,1,seqn,h);
- inum=0;myfread(&inum,1,1,h);
- if(!(dmi=malloc(inum*4))) {free(pat);pat=NULL;return;}
- if(!(patp=malloc((word)d.pat*32))) {free(pat);free(dmi);pat=NULL;return;}
- for(i=0;i<inum;++i) {
- dmi[i]=NULL;
- myfread(&di,1,16,h);o=ftell(h);
- for(r=0;r<12;++r) if(di.n[r]=='.') di.n[r]=0;
- if((r=F_findres(di.n))==-1) continue;
- if(!(dmi[i]=malloc(wad[r].l+8))) continue;
- memset(dmi[i],0,16);
- F_loadres(r,dmi[i],0,2);
- F_loadres(r,(int*)dmi[i]+1,2,2);
- F_loadres(r,(int*)dmi[i]+2,4,2);
- F_loadres(r,(int*)dmi[i]+3,6,2);
- F_loadres(r,(int*)dmi[i]+4,8,wad[r].l-8);
- fseek(h,o,SEEK_SET);
- }
- for(i=r=0,j=(word)d.pat<<3;i<j;++i) {
- patp[i]=r<<2;
- while(pat[r++].v!=0x80);
- }
- }
-*/
-
diff --git a/src/files.h b/src/files.h
index 5433bfc15b16acb69580b2b73aa0a0822b18fe07..1dfd0cb2a902dcaa7ac86c674a1fa5668f67d044 100644 (file)
--- a/src/files.h
+++ b/src/files.h
#include <stdio.h> // FILE
#include "map.h" // map_block_t
-#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;
-
extern int d_start, d_end;
-extern mwad_t wad[MAX_WAD];
-extern char wads[MAX_WADS][__MAX_PATH];
-extern FILE* wadh[MAX_WADS];
void F_startup (void);
void F_addwad (const char *fn);
void F_initwads (void);
void F_allocres (void);
-void F_loadres (int r, void *p, dword o, dword l);
+void F_loadres (int r, void *p);
int F_findres (const char n[8]);
int F_getresid (const char n[8]);
void F_getresname (char n[8], int r);
void F_randmus (char *s);
void F_readstr (FILE* h, char *s, int m);
+void F_loadmap (char n[8]);
+
#endif /* FILES_H_INCLUDED */
diff --git a/src/map.c b/src/map.c
index 1bdb4d3c145c643f19ac9ca207b9012c6fe95230..dc65f0c2491e0952de1a089e0ee7118f02d7eec6 100644 (file)
--- a/src/map.c
+++ b/src/map.c
#include "view.h"
#include "music.h"
-#include "files.h"
#include "render.h"
-#include <stdio.h>
#include <string.h>
#include <assert.h>
-#include "my.h"
#include "error.h"
#include "cp866.h"
}
} else {
logo("Invalid map header\n");
+ abort();
ok = 0;
}
return ok;
}
-
-void F_loadmap (char n[8]) {
- FILE_Reader rd;
- int r = F_getresid(n);
- FILE *h = wadh[wad[r].f];
- fseek(h, wad[r].o, SEEK_SET);
- FILE_AssignReader(&rd, h);
- if (!MAP_load(&rd.base)) {
- ERR_fatal("Failed to load map");
- }
-}
diff --git a/src/map.h b/src/map.h
index d661b366ae639002e8b7cd97f51508f89deffe49..4e1470652445a3e5c886266d994ab88bb3c57c6c 100644 (file)
--- a/src/map.h
+++ b/src/map.h
#include "common/streams.h"
int MAP_load (Reader *r);
-void F_loadmap (char n[8]);
#endif /* MAP_H_INCLUDED */
diff --git a/src/memory.c b/src/memory.c
index f1187462d2a047ffe760ae283ee3d33bc634ad36..404bbc481b36a967e5fa04c94c406842afd14a0c 100644 (file)
--- a/src/memory.c
+++ b/src/memory.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "error.h"
#include "files.h"
#include "memory.h"
-static byte m_active;
-static void *resp[MAX_WAD];
-static short resl[MAX_WAD];
+#include "common/wadres.h"
+#include "common/streams.h"
+
+typedef struct Block {
+ int id;
+ int ref;
+ char data[];
+} Block;
+
+static Block *blocks[MAX_RESOURCES];
void M_startup (void) {
- if(m_active) return;
- logo("M_startup: setup memory\n");
- memset(resp,0,sizeof(resp));
- memset(resl,0,sizeof(resl));
- // logo(" free DPMI-memory: %uK\n",dpmi_memavl()>>10);
- m_active=TRUE;
+ memset(blocks, 0, sizeof(blocks));
}
void M_shutdown (void) {
- if(!m_active) return;
- m_active=FALSE;
-}
-
-static void allocres (int h) {
- int *p,s;
-
- if(h>d_start && h<d_end) s=1; else s=0;
- if(!(p=malloc(wad[h].l+4+s*8)))
- ERR_fatal("M_lock: out of memory");
- *p=h;
- ++p;
- resp[h]=p;
- if(s) {
- p[0]=p[1]=p[2]=p[3]=0;
- F_loadres(h,p,0,2);
- F_loadres(h,p+1,2,2);
- F_loadres(h,p+2,4,2);
- F_loadres(h,p+3,6,2);
- F_loadres(h,p+4,8,wad[h].l-8);
- }else F_loadres(h,p,0,wad[h].l);
+ // stub
}
-void *M_lock (int h) {
- if(h==-1 || h==0xFFFF) return NULL;
- if(h>=MAX_WAD) ERR_fatal("M_lock: invalid resource id");
- if(!resl[h]) if(!resp[h]) allocres(h);
- ++resl[h];
- return resp[h];
+void *M_lock (int id) {
+ assert(id >= -1 && id < MAX_RESOURCES);
+ if (id >= 0) {
+ Block *x = blocks[id];
+ if (x) {
+ x->ref += 1;
+ return x->data;
+ } else {
+ x = malloc(sizeof(Block) + WADRES_getsize(id));
+ if (x) {
+ x->id = id;
+ x->ref = 1;
+ WADRES_getdata(id, x->data);
+ blocks[id] = x;
+ return x->data;
+ }
+ }
+ }
+ return NULL;
}
void M_unlock (void *p) {
- int h;
-
- if(!p) return;
- h=((int*)p)[-1];
- if(h>=MAX_WAD) ERR_fatal("M_unlock: invalid resource id");
- if(!resl[h]) return;
- --resl[h];
+ if (p) {
+ Block *x = p - sizeof(Block);
+ int id = x->id;
+ assert(id >= 0 && id < MAX_RESOURCES);
+ x->ref -= 1;
+ assert(x->ref >= 0);
+#if 0
+ if (x->ref == 0) {
+ blocks[id] = NULL;
+ free(x);
+ }
+#endif
+ }
}
-int M_locked (int h) {
- return (h != -1) && (h != 0xFFFF) && (resl[h] != 0);
+int M_locked (int id) {
+ assert(id >= -1 && id < MAX_RESOURCES);
+ return (id >= 0) && (blocks[id] != NULL) && (blocks[id]->ref >= 1);
}
-int M_was_locked (int h) {
- return (h != -1) && (h != 0xFFFF) && (resp[h] != NULL);
+int M_was_locked (int id) {
+ assert(id >= -1 && id < MAX_RESOURCES);
+ return (id >= 0) && (blocks[id] != NULL) && (blocks[id]->ref >= 0);
}
diff --git a/src/sdl/main.c b/src/sdl/main.c
index 217890a0425ece6750a72a493ab714a3fdb1463c..2c229fb3c77942ba0c9e055821ee1ff8ccb05dfb 100644 (file)
--- a/src/sdl/main.c
+++ b/src/sdl/main.c
vprintf(s, ap);
va_end(ap);
puts("");
- exit(1);
+ abort();
}
void ERR_fatal (char *s, ...) {
vprintf(s, ap);
va_end(ap);
puts("");
- exit(1);
+ abort();
}
void ERR_quit (void) {