ref: 71a278603d4fd68c33ec60e65730611c437b9888
author: qwx <qwx@sciops.net>
date: Sat Apr 24 05:54:44 EDT 2021
shim fs.c
--- /dev/null
+++ b/README
@@ -1,0 +1,4 @@
+Based on 1.0.92 file format specs graciously provided by:
+
+- https://soulsphere.org/random/doom-rpg-bnf.txt
+- http://www.neocomputer.org/projects/doomrpg
--- /dev/null
+++ b/dat.h
@@ -1,0 +1,1 @@
+extern char *prefix;
--- /dev/null
+++ b/dporg.c
@@ -1,0 +1,50 @@
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include <draw.h>
+#include <mouse.h>
+#include <keyboard.h>
+#include "dat.h"
+#include "fns.h"
+
+char *prefix = "/sys/games/lib/dporg";
+
+void *
+erealloc(void *p, ulong n, ulong oldn)
+{
+ if((p = realloc(p, n)) == nil)
+ sysfatal("realloc: %r");
+ setrealloctag(p, getcallerpc(&p));
+ if(n > oldn)
+ memset((uchar *)p + oldn, 0, n - oldn);
+ return p;
+}
+
+void *
+emalloc(ulong n)
+{
+ void *p;
+
+ if((p = mallocz(n, 1)) == nil)
+ sysfatal("emalloc: %r");
+ setmalloctag(p, getcallerpc(&n));
+ return p;
+}
+
+static void
+usage(void)
+{
+ fprint(2, "usage: %s [-d datadir]\n", argv0);
+ threadexits("usage");
+}
+
+void
+threadmain(int argc, char **argv)
+{
+ ARGBEGIN{
+ case 'd': prefix = EARGF(usage()); break;
+ default: usage();
+ }ARGEND
+ initfs();
+ threadexits(nil);
+}
--- /dev/null
+++ b/fns.h
@@ -1,0 +1,3 @@
+void initfs(void);
+void* erealloc(void*, ulong, ulong);
+void* emalloc(ulong);
--- /dev/null
+++ b/fs.c
@@ -1,0 +1,123 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+#include "dat.h"
+#include "fns.h"
+
+s32int sintab[256];
+int npal;
+u32int *pal;
+
+static Biobuf *
+eopen(char *s, int mode)
+{
+ Biobuf *bf;
+
+ if((bf = Bopen(s, mode)) == nil)
+ sysfatal("Bopen: %r");
+ Blethal(bf, nil);
+ return bf;
+}
+
+static long
+eread(Biobuf *bf, void *buf, long n)
+{
+ if(Bread(bf, buf, n) != n)
+ sysfatal("ebread: short read: %r");
+ return n;
+}
+
+static u8int
+get8(Biobuf *bf)
+{
+ u8int v;
+
+ eread(bf, &v, 1);
+ return v;
+}
+
+static u16int
+get16(Biobuf *bf)
+{
+ u16int v;
+
+ v = get8(bf);
+ return v | get8(bf) << 8;
+}
+
+static u32int
+get24(Biobuf *bf)
+{
+ u32int v;
+
+ v = get16(bf);
+ return v | get8(bf) << 16;
+}
+
+static u32int
+get32(Biobuf *bf)
+{
+ u32int v;
+
+ v = get16(bf);
+ return v | get16(bf) << 16;
+}
+
+static void
+readpal(void)
+{
+ int n;
+ u8int r, g, b;
+ u32int *p;
+ Biobuf *bf;
+
+ bf = eopen("palettes.bin", OREAD);
+ npal = get32(bf) / 2;
+ pal = emalloc(npal * sizeof *pal);
+ for(p=pal; p<pal+npal; p++){
+ n = get16(bf);
+ r = n & 0x1f;
+ r = r << 3 | r >> 2;
+ g = n >> 5 & 0x3f;
+ g = g << 2 | g >> 4;
+ b = n >> 11 & 0x1f;
+ b = b << 3 | b >> 2;
+ *p = r << 16 | g << 8 | b;
+ }
+ Bterm(bf);
+}
+
+static void
+readsintab(void)
+{
+ Biobuf *bf;
+ s32int *s;
+
+ bf = eopen("sintable.bin", OREAD);
+ for(s=sintab; s<sintab+nelem(sintab); s++)
+ *s = get32(bf);
+ Bterm(bf);
+}
+
+void
+initfs(void)
+{
+ rfork(RFNAMEG);
+ if(bind(".", prefix, MBEFORE|MCREATE) == -1 || chdir(prefix) < 0)
+ fprint(2, "initfs: %r\n");
+ readsintab();
+ readpal();
+}
+
+// grids: 32/256/2048
+// wtexels.bin
+// stexels.bin
+// bitshapes.bin
+// entities.db
+// entities.str
+// mappings.bin
+// map bsp + str (on demand, with shim load gauge)
+// a.map
+// base.str
+// .bit (r8g8b8a8)
+// + old project code
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,9 @@
+</$objtype/mkfile
+BIN=$home/bin/$objtype
+TARG=dporg
+OFILES=\
+ fs.$O\
+ dporg.$O\
+
+HFILES= dat.h fns.h
+</sys/src/cmd/mkone