summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--VP-map.lua16
-rw-r--r--VP-miscwork.lua185
-rw-r--r--VP-process.lua12
-rw-r--r--VP-roomwork.lua104
-rw-r--r--VP-textwork.lua65
-rw-r--r--compil.lex308
6 files changed, 566 insertions, 124 deletions
diff --git a/VP-map.lua b/VP-map.lua
index df096b9..54a382e 100644
--- a/VP-map.lua
+++ b/VP-map.lua
@@ -4,6 +4,7 @@ VP_maintypes = {
"GFX",
"MAIN",
"GAME",
+ "MISC",
}
VP_map = { }
@@ -49,6 +50,9 @@ VP_map_spans = {
{ idx_s = 2096, idx_e = 2097, data = { dir = "SOUNDS/UNKNOWN03", ext = "wag", }, },
{ idx_s = 2098, idx_e = 2172, data = { dir = "SOUNDS/VICTORY", ext = "wag", }, },
+
+ { idx_s = 2175, idx_e = 2186, data = { dir = "MISC/MENUS", ext = "sarc", ftype = "arcroom", }, },
+
{ idx_s = 2187, idx_e = 2211, data = { dir = "GFX/STATUSPIC" }, },
{ idx_s = 2296, idx_e = 2319, data = { dir = "GFX/UNKNOWN06" }, },
{ idx_s = 3299, idx_e = 3505, data = { dir = "GFX/FACE" }, },
@@ -66,6 +70,7 @@ VP_map = {
[ 3] = { dir = "MISC", ext = "txt" },
[ 4] = { dir = "MAIN/SOUNDS", ext = "wag" },
[ 5] = { dir = "MAIN/GFX" },
+ [ 6] = { dir = "MAIN/MISC", ext = "sarc", ftype = "arcroom" },
[ 618] = { dir = "SOUNDS/MISC", ext = "wag" },
[1021] = { dir = "SOUNDS/MISC", ext = "wag" },
@@ -87,6 +92,17 @@ VP_map = {
[1983] = { dir = "GFX/MAGIC12", ext = "agx", ftype = "arcgfx", },
[1986] = { dir = "GFX/MAGIC13", ext = "agx", ftype = "arcgfx", },
+ [2173] = { dir = "MISC/GFX", ext = "agx", ftype = "arcgfx", },
+
+ [2294] = { dir = "MISC/SCRIPT", ext = "script", ftype = "cscript", },
+
+ [4734] = { dir = "MISC/SCRIPT", ext = "sarc", ftype = "arcroom", },
+
+ [4797] = { dir = "MISC/UNKNOWN", ext = "carc", ftype = "carc", },
+ [4798] = { dir = "MISC/UNKNOWN", ext = "carc", ftype = "carc", },
+ [4799] = { dir = "MISC/UNKNOWN", ext = "carc", ftype = "carc", },
+ [4807] = { dir = "MISC/UNKNOWN", ext = "carc", ftype = "carc", },
+
--
-- Videos
--
diff --git a/VP-miscwork.lua b/VP-miscwork.lua
index 31f7e92..1a5bc14 100644
--- a/VP-miscwork.lua
+++ b/VP-miscwork.lua
@@ -31,11 +31,54 @@ function process_arcgfx(fname, h, size, ext)
index[i].size = h:readU32()
end
- local tell
local outfile = {}
+ local script = nil
+ local font = nil
for i = 1, nfiles do
- tell = h:tell()
- outfile[i] = process_single_file(fname .. string.format("/%04i-%08X", i, index[i].extra), h, index[i].size, ext)
+ local tell = h:tell()
+ local handler = nil
+ local counter = 1
+ local f1 = andB(index[i].extra, 0xffffff00)
+ if dump_mode and f1 == 0x00300900 then
+ if script then error "Can't have two scripts" end
+ handler = function(fname, h, size, ext)
+ if counter == 1 then
+ log "taking script"
+ script = Buffer(true)
+ script:copyfrom(h)
+ else
+ error "Too many files"
+ end
+ counter = counter + 1
+ end
+ elseif dump_mode and f1 == 0x00300800 then
+ if font then error "Can't have two fonts" end
+ handler = function(fname, h, size, ext)
+ if counter == 1 then
+ log "taking font"
+ font = Buffer(true)
+ font:copyfrom(h)
+ else
+ error "Too many files"
+ end
+ counter = counter + 1
+ end
+ elseif not dump_mode and f1 == 0x00300900 then
+ error "Not written yet"
+ elseif not dump_mode and f1 == 0x00300800 then
+ error "Not written yet"
+ end
+ outfile[i] = process_single_file(fname .. string.format("/%04i-%08X", i, index[i].extra), h, index[i].size, ext, handler)
+
+ if handler and script and font then
+ if dump_mode then
+ extract_simple_script(fname .. string.format("/%04i", i), script, font)
+ end
+ script:destroy()
+ font:destroy()
+ script = nil
+ font = nil
+ end
h:seek(tell + index[i].size)
end
@@ -57,3 +100,139 @@ function process_arcgfx(fname, h, size, ext)
-- return ret
end
+function process_cscript(fname, h, size, ext)
+ log("Processing " .. fname .. ".slz")
+ log("Extracting " .. fname .. " - format 'cscript'")
+ local counter = 1
+ local script
+ local font
+ local handler = function(fname, h, size, ext)
+ if counter == 1 then
+ log "taking script"
+ script = Buffer(true)
+ script:copyfrom(h)
+ elseif counter == 2 then
+ log "taking font"
+ font = Buffer(true)
+ font:copyfrom(h)
+ else
+ error "Too many files"
+ end
+ counter = counter + 1
+ end
+
+ process_single_file(fname, h, h:getsize(), ext, handler)
+
+ if not script or not font then error "Not enough files" end
+ if dump_mode then
+ extract_simple_script(fname, script, font)
+ end
+ script:destroy()
+ font:destroy()
+end
+
+function process_carc(fname, h, size, ext)
+ log("Processing " .. fname .. "." .. ext)
+ if dump_mode then
+ o = Output(fname .. "." .. ext)
+ o:copyfrom(h, size)
+ o:destroy()
+ h:seek(-size, SEEK_CUR)
+ end
+ log("Extracting " .. fname .. " - format 'carc'")
+ dump_mkdir(fname)
+ local nfiles = h:readU32()
+ local ret
+ if not dump_mode then
+ ret = Buffer(true)
+ ret:writeU32(nfiles)
+ end
+
+ local index = {}
+ for i = 1, nfiles do
+ index[i] = {}
+ local offset = h:readU32()
+ index[i].extra = shr(offset, 24)
+ index[i].offset = andB(offset, 0xffffff)
+ end
+
+ index[nfiles + 1] = {}
+ index[nfiles + 1].extra = 0
+ index[nfiles + 1].offset = size
+
+ local outfile = {}
+ local script = nil
+ local font = nil
+ for i = 1, nfiles do
+ local tell = h:tell()
+ local handler = nil
+ local counter = 1
+ if index[i].extra == 3 then
+ handler = function(fname, h, size, ext)
+ if counter ~= 1 then error "Too many files" end
+ counter = counter + 1
+ return process_carc(fname, h, size, ext)
+ end
+ elseif dump_mode and index[i].extra == 2 then
+ if script then error "Can't have two scripts" end
+ handler = function(fname, h, size, ext)
+ if counter == 1 then
+ log "taking script"
+ script = Buffer(true)
+ script:copyfrom(h)
+ else
+ error "Too many files"
+ end
+ counter = counter + 1
+ end
+ elseif dump_mode and index[i].extra == 1 then
+ if font then error "Can't have two fonts" end
+ handler = function(fname, h, size, ext)
+ if counter == 1 then
+ log "taking font"
+ font = Buffer(true)
+ font:copyfrom(h)
+ else
+ error "Too many files"
+ end
+ counter = counter + 1
+ end
+ elseif not dump_mode and index[i].extra == 2 then
+ error "Not written yet"
+ elseif not dump_mode and index[i].extra == 1 then
+ error "Not written yet"
+ end
+ local fsize = index[i + 1].offset - index[i].offset
+ outfile[i] = process_single_file(fname .. string.format("/%04i-%08X", i, index[i].extra), h, fsize, ext, handler)
+
+ if handler and script and font then
+ if dump_mode then
+ second_style_script = true
+ extract_simple_script(fname .. string.format("/%04i", i), script, font)
+ second_style_script = false
+ end
+ script:destroy()
+ font:destroy()
+ script = nil
+ font = nil
+ end
+ h:seek(tell + fsize)
+ end
+
+ if not dump_mode then
+ for i = 1, nfiles do
+ local alignment_bytes = alignment(outfile[i]:getsize(), 4)
+ for j = 1, alignment_bytes do
+ outfile[i]:writeU8(0)
+ end
+ ret:writeU32(index[i].extra)
+ ret:writeU32(outfile[i]:getsize())
+ end
+ for i = 1, nfiles do
+ ret:copyfrom(outfile[i])
+ outfile[i]:destroy()
+ end
+ end
+
+-- return ret
+end
diff --git a/VP-process.lua b/VP-process.lua
index 82d0815..0eb1cb9 100644
--- a/VP-process.lua
+++ b/VP-process.lua
@@ -239,14 +239,12 @@ function process_files(index, map, iso, iso_full, cindex, index_add, jp_in_us)
log("JP-in-US: replacing file " .. i .. " by file " .. lookup)
file_out = index_add[lookup].cd:cdfile(index_add[lookup].sector, index_add[lookup].size * sec_sizes[mode])
end
- elseif not ftype then
- file_out = process_single_file("DUMP/" .. dir .. string.format("/%04i", i), file_in, file_in:getsize(), ext)
- elseif ftype == "arcgfx" then
- file_out = process_arcgfx("DUMP/" .. dir .. string.format("/%04i", i), file_in, file_in:getsize(), ext)
- elseif ftype == "arcroom" then
- file_out = process_arcroom("DUMP/" .. dir .. string.format("/%04i", i), file_in, file_in:getsize(), ext)
+ elseif ftype then
+ local handler = _G["process_" .. ftype]
+ if not handler then error("Unknown ftype: " .. ftype) end
+ file_out = handler("DUMP/" .. dir .. string.format("/%04i", i), file_in, file_in:getsize(), ext)
else
- error("Unknow ftype: " .. ftype)
+ file_out = process_single_file("DUMP/" .. dir .. string.format("/%04i", i), file_in, file_in:getsize(), ext)
end
if not file_out then file_out = file_in end
file_in:seek(0)
diff --git a/VP-roomwork.lua b/VP-roomwork.lua
index d1eabfe..9bb590b 100644
--- a/VP-roomwork.lua
+++ b/VP-roomwork.lua
@@ -120,7 +120,7 @@ function process_arcroom(fname, h, size, ext)
o:destroy()
h:seek(-size, SEEK_CUR)
end
- log("Processing " .. fname .. " - format 'arcroom'")
+ log("Processing " .. fname .. " - format 'arcroom' - " .. ext)
dump_mkdir(fname)
local nfiles = h:readU32()
@@ -157,23 +157,23 @@ function process_arcroom(fname, h, size, ext)
tell = h:tell()
local handler = nil
local counter = 1
- if dump_mode and index[i].ftype == 4 then
+ if dump_mode and ext == "arm" and index[i].ftype == 4 then
log("Preparing to dump script...")
- script = Buffer(true)
- font = Buffer(true)
handler = function(fname, h, size, ext)
if counter == 1 then
log("Taking script...")
+ script = Buffer(true)
script:copyfrom(h)
elseif counter == 2 then
log("Taking font...")
+ font = Buffer(true)
font:copyfrom(h)
else
error("Too many files.")
end
counter = counter + 1
end
- elseif index[i].ftype == 4 and script and font then
+ elseif not dump_mode and ext == "arm" and index[i].ftype == 4 and script and font then
old_script = Buffer(true)
handler = function(fname, h, size, ext)
local ret
@@ -190,15 +190,51 @@ function process_arcroom(fname, h, size, ext)
counter = counter + 1
return ret
end
+ elseif dump_mode and ext == "sarc" and index[i].ftype == 4 then
+ handler = function(fname, h, size, ext)
+ if counter == 1 then
+ if script then error "Can't have two scripts in these..." end
+ log("Taking text...")
+ script = Buffer(true)
+ script:copyfrom(h)
+ elseif counter == 2 then
+ if font then error "Can't have two fonts in these..." end
+ log("Taking font...")
+ font = Buffer(true)
+ font:copyfrom(h)
+ else
+ error("Too many files")
+ end
+ counter = counter + 1
+ end
+ elseif dump_mode and ext == "sarc" and index[i].ftype == 7 then
+ if font then error "Can't have two fonts in these..." end
+ handler = function(fname, h, size, ext)
+ if counter == 1 then
+ log("Taking font...")
+ font = Buffer(true)
+ font:copyfrom(h)
+ else
+ error("Too many files")
+ end
+ counter = counter + 1
+ end
+ elseif not dump_mode and ext == "sarc" and index[i].ftype == 4 then
+ error "Not written yet"
+ elseif not dump_mode and ext == "sarc" and index[i].ftype == 7 then
+ error "Not written yet"
end
outfile[i] = process_single_file(fname .. string.format("/%04i-%08X", i, index[i].ftype), h, index[i].size, "room", handler)
- if handler then
- if counter ~= 3 then error("Didn't get enough files; got " .. (counter - 1) .. " instead of 2.") end
- if dump_mode then
+ if handler and script and font then
+ if dump_mode and ext == "arm" then
extract_room_script(fname .. string.format("/%04i", i), script, font)
+ elseif dump_mode then
+ extract_simple_script(fname .. string.format("/%04i", i), script, font)
end
script:destroy()
font:destroy()
+ script = nil
+ font = nil
end
h:seek(tell + index[i].size)
end
@@ -497,3 +533,55 @@ function extract_room_script(fname, script, font)
o:destroy()
end
+
+function extract_simple_script(fname, script, font)
+ log("Processing script " .. fname)
+ dump_mkdir(fname)
+ local font = extract_font(fname .. "/FONT", font)
+ local lookup = resolve_font(font)
+ local n_ptrs = 1
+ local script_begin = script:readU32()
+
+ local ptrs = {}
+ local unks = {}
+ local ptr_start = 1
+ local tell = script:tell()
+
+ while tell < script_begin do
+ unks[n_ptrs] = script:readU32()
+ ptrs[n_ptrs] = script:readU32()
+ tell = script:tell()
+ n_ptrs = n_ptrs + 1
+ end
+ ptrs[n_ptrs] = script:getsize() - script_begin
+ n_ptrs = n_ptrs - 1
+
+ local ptrs_contents, ptrs_raws = {}, {}
+ ptr_start = 1
+ for i = ptr_start, n_ptrs do
+ ptrs_contents[i] = ""
+ ptrs_raws[i] = ""
+
+-- if tell + ptrs[i] ~= script:tell() then print("Script consistancy failure for pointer " .. i .. " - we're at " .. script:tell() .. " and " .. (tell + ptrs[i]) .. " was expected.") end
+
+ script:seek(script_begin + ptrs[i])
+ while script:tell() ~= (script_begin + ptrs[i + 1]) do
+ local r, rr = extract_char(script, lookup)
+ if r then
+ ptrs_contents[i] = ptrs_contents[i] .. r
+ ptrs_raws[i] = ptrs_raws[i] .. rr
+ elseif script:tell() ~= (script_begin + ptrs[i + 1]) then
+ ptrs_contents[i] = ptrs_contents[i] .. "<ZERO>"
+ end
+ end
+ end
+
+ local o = Output(fname .. "-script.txt")
+ for i = ptr_start, n_ptrs do
+ o:write("<ptr " .. i .. " - " .. unks[i] .. ">\n")
+ o:write(ptrs_contents[i])
+ o:write("\n")
+ end
+
+ o:destroy()
+end
diff --git a/VP-textwork.lua b/VP-textwork.lua
index 2d3f56c..c3312f7 100644
--- a/VP-textwork.lua
+++ b/VP-textwork.lua
@@ -1,3 +1,9 @@
+function get_next_char(script)
+ local c = script:readU8()
+ if c >= 0x80 then c = (c - 0x80) + (script:readU8() * 128) end
+ return c
+end
+
function get_next_utf8(str)
local ret = ""
local n
@@ -34,6 +40,8 @@ function dump_special(script, code)
return "\n", "\n"
elseif code == 1 then
return "\n<new/>\n", "\n"
+ elseif code == 2 then
+ return "<pause>", ""
elseif code == 3 then
local speed = script:readU8()
if speed == 255 then
@@ -41,6 +49,8 @@ function dump_special(script, code)
else
return '<st spd="' .. speed .. '"/>', ""
end
+ elseif code == 4 then
+ return '<st clr="' .. script:readU8() .. '"/>', ""
elseif code == 5 then
return '<start/>', ""
elseif code == 7 then
@@ -57,6 +67,21 @@ function dump_special(script, code)
else
return '<st siz="' .. siz ..'"/>', ""
end
+ elseif code == 14 then
+ return '<var n="' .. script:readU8() .. '"/>', ""
+ elseif code == 17 then
+ local t, u
+ t = script:readU8()
+ u = script:readU8()
+ if u == 0 then
+ return '<delay0 t="' .. t .. '"/>', ""
+ elseif u == 1 then
+ return '<delay1 t="' .. t .. '"/>', ""
+ else
+ return '<delay t="' .. t .. '" u="' .. u .. '"/>', ""
+ end
+ elseif code == 18 then
+ return "<ssync/>", ""
elseif code == 19 then
local arg1, arg2
arg1 = script:readU8()
@@ -66,16 +91,35 @@ function dump_special(script, code)
else
return '<port a1="' .. arg1 .. '" a2="' .. arg2 .. '"/>', ""
end
- elseif code == 14 then
- return '<var n="' .. script:readU8() .. '"/>', ""
- elseif code == 4 then
- return '<st clr="' .. script:readU8() .. '"/>', ""
else
local a1, a2
if code == 3 or code == 4 or code == 7 or code == 8 or code == 14 then
a1 = script:readU8()
return '<u1 c="' .. code .. '" a="' .. a1 .. '"/>', ""
- elseif code == 6 or code == 12 or code == 17 or code == 19 then
+ elseif code == 6 or code == 12 or code == 19 then
+ a1 = script:readU8()
+ a2 = script:readU8()
+ return '<u2 c="' .. code .. '" a1="' .. a1 .. '" a2="' .. a2 .. '"/>', ""
+ else
+ return '<uk c="' .. code .. '"/>', ""
+ end
+ end
+ error "Should not end up there"
+end
+
+function dump_special2(script, code)
+ if code == 0 then
+ return "\n", "\n"
+ elseif code == 1 then
+ return "\n<new/>\n", "\n"
+ elseif code == 2 then
+ return "<pause>", ""
+ else
+ local a1, a2
+ if code == 3 or code == 5 or code == 7 or code == 8 or code == 9 or code == 12 or code == 13 or code == 14 or code == 15 or code == 21 then
+ a1 = script:readU8()
+ return '<u1 c="' .. code .. '" a="' .. a1 .. '"/>', ""
+ elseif code == 20 then
a1 = script:readU8()
a2 = script:readU8()
return '<u2 c="' .. code .. '" a1="' .. a1 .. '" a2="' .. a2 .. '"/>', ""
@@ -87,13 +131,16 @@ function dump_special(script, code)
end
function extract_char(script, lookup)
- local
- c = script:readU8()
+ local c = get_next_char(script)
if c == 0 then return nil end
- if c >= 0x80 then c = (c - 0x80) + (script:readU8() * 128) end
if c >= 0x4000 then
- return dump_special(script, c - 0x4000)
+ local code = c - 0x4000
+ if second_style_script then
+ return dump_special2(script, code)
+ else
+ return dump_special(script, code)
+ end
else
local l = lookup[c]
if not l and not sloppy_extract then error("Lookup failed for character " .. c) end
diff --git a/compil.lex b/compil.lex
index ad24a2c..36db5c5 100644
--- a/compil.lex
+++ b/compil.lex
@@ -1,8 +1,18 @@
#include <string.h>
+ /* Waiting for Window */
+%s WW
+ /* Waiting for Window Y */
+%s WWY
+ /* Waiting for Window W */
+%s WWW
+ /* Waiting for Window H */
+%s WWH
/* In text block */
%s I
/* In port block */
%s P
+ /* In delay block */
+%s D
/* In unknown 1 block */
%s U1
/* In unknown 2 block, arg1 */
@@ -19,185 +29,289 @@
int arg1 = 0;
int errstate = 0;
int got_ptr = 0;
+ int current_ptr = 0;
+
+ const int max_tagsize = 64;
+
+ char unknown_tag[65];
+ char * unknown_tag_ptr = unknown_tag;
+
+ int in_unknown_tag = 0;
+
+ struct window {
+ int t, x, y, w, h;
+ };
+
+ struct window windows[8192];
%%
<INITIAL>"<roomscripts>" {
- fprintf(yyout, "rooms_txts = {\n");
- BEGIN(I);
+ fprintf(yyout, "rooms_txts = {\n");
+ BEGIN(I);
}
-<INITIAL>.* {
- fprintf(stderr, "Invalid file, must begin with <roomscripts>\n");
- errstate = 1;
+<INITIAL>.* {
+ fprintf(stderr, "Invalid file, must begin with <roomscripts>\n");
+ errstate = 1;
}
-<I>"\n\n<ptr n=\""[[:digit:]]+"\" room=\""[^\"]*"\"/>\n" {
- int d = atoi(yytext + 10);
- if (got_ptr) {
- fprintf(yyout, "\x5d\x5d },\n");
- }
- fprintf(yyout, " [%i] = { \x5b\x5b", d);
- got_ptr = 1;
+<I>"\n\n<ptr n=\""[[:digit:]]+"\" room=\""[^\"]*"\"/>\n" {
+ current_ptr = atoi(yytext + 10);
+ if (got_ptr) {
+ fprintf(yyout, "\x5d\x5d },\n");
+ }
+ fprintf(yyout, " [%i] = { \x5b\x5b", current_ptr);
+ got_ptr = 1;
+ BEGIN(WW);
}
-<I>"\n<new/>\n" {
- putcode(1);
+<WW>"<nowindowdetected/>\n" {
+ BEGIN(I);
}
-<I>"<rspd/>" {
- putcode1(3, 255);
+<WW>"<window type=\"fixed\"/>\n" {
+ windows[current_ptr].t = 3;
+ BEGIN(I);
}
-<I>"<st spd=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 9);
- putcode1(3, d);
+<WW>"<window x=\""[[:digit:]]+"\" " {
+ int d = atoi(yytext + 11);
+ windows[current_ptr].t = 1;
+ windows[current_ptr].x = d;
+ BEGIN(WWY);
}
-<I>"<st clr=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 9);
- putcode1(4, d);
+<WW>"<window x=\"var\" y=\""[[:digit:]]+"\" " {
+ int d = atoi(yytext + 19);
+ windows[current_ptr].t = 2;
+ windows[current_ptr].y = d;
+ BEGIN(WWW);
}
-<I>"<start/>" {
- putcode(5);
+<WWY>"y=\""[[:digit:]]+"\" " {
+ int d = atoi(yytext + 3);
+ windows[current_ptr].y = d;
+ BEGIN(WWW);
}
-<I>"<rrep/>" {
- putcode1(7, 1);
+<WWW>"width=\""[[:digit:]]+"\" " {
+ int d = atoi(yytext + 7);
+ windows[current_ptr].w = d;
+ BEGIN(WWH);
}
-<I>"<st rep=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 9);
- putcode1(7, d);
+<WWH>"height=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 8);
+ windows[current_ptr].h = d;
+ BEGIN(I);
}
-<I>"<rsiz/>" {
- putcode1(8, 1);
+<I>"\n<new/>\n" {
+ putcode(1);
}
-<I>"<st siz=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 9);
- putcode1(8, d);
+<I>"<rspd/>" {
+ putcode1(3, 255);
}
-<I>"<dport/>" {
- putcode2(19, 255, 255);
+<I>"<st spd=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 9);
+ putcode1(3, d);
}
-<I>"<port a1=\""[[:digit:]]+"\" " {
- arg1 = atoi(yytext + 10);
- BEGIN(P);
+<I>"<st clr=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 9);
+ putcode1(4, d);
}
-<P>"a2=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 4);
- putcode2(19, arg1, d);
- BEGIN(I);
+<I>"<start/>" {
+ putcode(5);
}
-<I>"<var n=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 8);
- putcode1(14, d);
+<I>"<rrep/>" {
+ putcode1(7, 1);
}
-<I>"<uk c=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 7);
- putcode(d);
+<I>"<st rep=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 9);
+ putcode1(7, d);
}
-<I>"<u1 c=\""[[:digit:]]+"\" " {
- cmd = atoi(yytext + 7);
- BEGIN(U1);
-}
+<I>"<rsiz/>" {
+ putcode1(8, 1);
+ }
+
+<I>"<st siz=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 9);
+ putcode1(8, d);
+ }
+
+<I>"<dport/>" {
+ putcode2(19, 255, 255);
+ }
+
+<I>"<port a1=\""[[:digit:]]+"\" " {
+ arg1 = atoi(yytext + 10);
+ BEGIN(P);
+ }
+
+<I>"<ssync/>" {
+ putcode(18);
+ }
+
+<I>"<delay t=\""[[:digit:]]+"\" " {
+ arg1 = atoi(yytext + 10);
+ BEGIN(D);
+ }
+
+<D>"u=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 3);
+ putcode2(17, d, arg1);
+ BEGIN(I);
+ }
+
+<I>"<delay0 t=\""[[:digit:]]+"\"/>" {
+ int t = atoi(yytext + 11);
+ putcode2(17, t, 0);
+ }
+
+<I>"<delay1 t=\""[[:digit:]]+"\"/>" {
+ int t = atoi(yytext + 11);
+ putcode2(17, t, 1);
+ }
+
+<P>"a2=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 4);
+ putcode2(19, arg1, d);
+ BEGIN(I);
+ }
+
+<I>"<var n=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 8);
+ putcode1(14, d);
+ }
+
+<I>"<uk c=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 7);
+ putcode(d);
+ }
-<U1>"a1=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 4);
- putcode1(cmd, d);
- BEGIN(I);
+<I>"<u1 c=\""[[:digit:]]+"\" " {
+ cmd = atoi(yytext + 7);
+ BEGIN(U1);
}
-<I>"<u2 c=\""[[:digit:]]+"\" " {
- cmd = atoi(yytext + 7);
- BEGIN(U21);
+<U1>"a1=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 4);
+ putcode1(cmd, d);
+ BEGIN(I);
}
-<U21>"a1=\""[[:digit:]]+"\" " {
- arg1 = atoi(yytext + 4);
- BEGIN(U22);
+<I>"<u2 c=\""[[:digit:]]+"\" " {
+ cmd = atoi(yytext + 7);
+ BEGIN(U21);
}
-<U22>"a2=\""[[:digit:]]+"\"/>" {
- int d = atoi(yytext + 4);
- putcode2(cmd, arg1, d);
- BEGIN(I);
+<U21>"a1=\""[[:digit:]]+"\" " {
+ arg1 = atoi(yytext + 4);
+ BEGIN(U22);
}
-<I>"\n" {
- putcode(0);
- }
+<U22>"a2=\""[[:digit:]]+"\"/>" {
+ int d = atoi(yytext + 4);
+ putcode2(cmd, arg1, d);
+ BEGIN(I);
+}
-<I>"</roomscripts>\n" {
- fprintf(yyout, "\x5d\x5d}\n}\n");
- BEGIN(E);
+<I>"\n" {
+ putcode(0);
}
-<I>"abcdef<"[^\>\n]*"/>" {
- yytext[strlen(yytext) - 2] = 0;
- fprintf(stderr, "Error: Invalid command: '%s'\n", yytext + 1);
- errstate = 1;
+<I>"</roomscripts>\n" {
+ int i;
+ fprintf(yyout, "\x5d\x5d}\n}\n\nwindows_data = {\n");
+ for (i = 0; i < 8192; i++) {
+ switch (windows[i].t) {
+ case 1:
+ fprintf(yyout, " [%i] = { x = \"%i\", y = \"%i\", width = \"%i\", height = \"%i\" },\n", i, windows[i].x, windows[i].y, windows[i].w, windows[i].h);
+ break;
+ case 2:
+ fprintf(yyout, " [%i] = { x = \"var\", y = \"%i\", width = \"%i\", height = \"%i\" },\n", i, windows[i].y, windows[i].w, windows[i].h);
+ break;
+ case 3:
+ fprintf(yyout, " [%i] = { wtype = \"fixed\" },\n", i);
+ break;
+ }
+ }
+ fprintf(yyout, "}\n");
+ BEGIN(E);
}
-<I>. {
- fputc(*yytext, yyout);
+<I>. {
+ if (*yytext == '<') {
+ in_unknown_tag = 1;
+ unknown_tag_ptr = unknown_tag;
+ } else if ((*yytext == '>') && in_unknown_tag) {
+ *unknown_tag_ptr = 0;
+ fprintf(stderr, "Got an unknown tag: %s\n", unknown_tag);
+ in_unknown_tag = 0;
+ } else if (in_unknown_tag) {
+ *unknown_tag_ptr++ = *yytext;
+ if ((unknown_tag_ptr - unknown_tag) == max_tagsize) {
+ in_unknown_tag = 0;
+ }
+ }
+ fputc(*yytext, yyout);
}
-. {
- fprintf(stderr, "Hu uh, something's wrong...\n");
+. {
+ fprintf(stderr, "Hu uh, something's wrong... unexpected %s\n", yytext);
}
%%
-int yywrap(void) {
+int yywrap(void) {
exit(errstate ? -1 : 0);
}
-int main(int argc, char ** argv) {
+int main(int argc, char ** argv) {
if ((argc < 2) || (argc > 3)) {
- fprintf(stderr, "Usage: %s <output> [input]\n", argv[0]);
- exit(-1);
+ fprintf(stderr, "Usage: %s <output> [input]\n", argv[0]);
+ exit(-1);
}
if (!(yyout = fopen(argv[1], "wb"))) {
- fprintf(stderr, "Error: can't open file %s\n", argv[1]);
- exit(-1);
+ fprintf(stderr, "Error: can't open file %s\n", argv[1]);
+ exit(-1);
}
if (argc == 3) {
- if (!(yyin = fopen(argv[2], "rb"))) {
- fprintf(stderr, "Error: can't open file %s\n", argv[2]);
- exit(-1);
- }
+ if (!(yyin = fopen(argv[2], "rb"))) {
+ fprintf(stderr, "Error: can't open file %s\n", argv[2]);
+ exit(-1);
+ }
}
+ memset(windows, 0, sizeof(windows));
fprintf(stderr, "Creating file %s\n", argv[1]);
yylex();
exit(errstate ? -1 : 0);
}
-void unputs(char * s) {
+void unputs(char * s) {
int l = strlen(s), i;
-
+
for (i = l - 1; i >= 0; i--) {
- unput(s[i]);
+ unput(s[i]);
}
}
-void putcode(int code) {
+void putcode(int code) {
fprintf(yyout, "\x5d\x5d, { %i }, \x5b\x5b", code);
}
-void putcode1(int code, int arg) {
+void putcode1(int code, int arg) {
fprintf(yyout, "\x5d\x5d, { %i, %i }, \x5b\x5b", code, arg);
}
-void putcode2(int code, int arg1, int arg2) {
+void putcode2(int code, int arg1, int arg2) {
fprintf(yyout, "\x5d\x5d, { %i, %i, %i }, \x5b\x5b", code, arg1, arg2);
}