1 /* coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://sam.zoy.org/wtfpl/COPYING for more details. */
13 writeln("ERROR: ", msg);
26 \["GVAR", "findGVarIndex"],
27 \["TVAR", "findTVarIndex"],
28 \["SVAR", "findSVarIndex"],
30 \["CONST", "findConst"]
37 fl = new File("awish.vmd", "rb");
38 if (!fl) abort("no code file");
40 if (sign != "AVM0") abort("invalid code file");
45 //writeln(csz, " ", lcnt);
46 for (local f = 0; f < lcnt; ++f) {
47 local type = fl.getc(), value, name, nlen, vname, v;
49 if (type == LB_GVAR || type == LB_TVAR) {
51 } else if (type == LB_CODE) {
52 value = fl.readWord();
53 } else if (type == LB_CONST) {
54 value = fl.readWord();
55 if (value >= 32768) value -= 65536;
57 abort("invalid code file");
60 name = fl.readBuf(nlen);
61 for (local f = 0; f < name.length; ++f) name[f] ^= 0xa5;
63 for (local f = 0; f < vname.length; ++f) {
67 if (ch < '0' || (ch > '9' && ch < 'A') || (ch > 'Z' && ch < 'a')) ch = '_';
71 vname = types[type][0]+"_"+vname.toUpper();
72 v = \[type, name, vname];
79 fo = new File("vm_gamelabels.h", "w");
80 foreach (local v with list.items()) {
81 fo.writeln("extern int %s;".format(v[2]));
85 fo = new File("vm_gamelabelsdef.c", "w");
86 foreach (local v with list.items()) {
87 fo.writeln("int %s;".format(v[2]));
91 fo = new File("vm_gamelabelsinit.c", "w");
92 foreach (local v with list.items()) {
93 fo.writeln(" %s = %s(\"%s\");".format(v[2], types[v[0]][1], v[1]));