diff options
author | pixel <pixel> | 2004-05-02 12:29:02 +0000 |
---|---|---|
committer | pixel <pixel> | 2004-05-02 12:29:02 +0000 |
commit | b0ecd395ad3f7ae5d782713dd610a056b1b33c31 (patch) | |
tree | 8e3641d1721a12540170301f84697050b9fad425 | |
parent | 6fe28e64b960b2a58ef0cff94898f6958467927c (diff) |
Added a built-in cd-tool.lua feature.
-rwxr-xr-x | Makefile | 17 | ||||
-rw-r--r-- | bin2c.cpp | 40 | ||||
-rw-r--r-- | cd-tool.cpp | 51 | ||||
-rw-r--r-- | cd-tool.lua | 537 |
4 files changed, 371 insertions, 274 deletions
@@ -1,13 +1,13 @@ #!/usr/bin/make -f CPPFLAGS=-Wall -g -O3 -mcpu=i686 -Iincludes `sdl-config --cflags` -DHAVE_ZLIB `baltisot-config --cflags` `lua-config --include` -DCHATTING -LDFLAGS=-lz `sdl-config --libs` `baltisot-config --libs` -lefence +LDFLAGS=-lz `sdl-config --libs` `baltisot-config --libs` CDTOOL_LDFLAGS=`baltisot-config --libs` -lreadline CXX=g++ #SUBDIRS = psxdev lib Xenogears VP MegamanX5 SUBDIRS = psxdev lib PE Xenogears -TARGET = lzss dlzss cd-tool str-player crypto-search bgrep tile-convert mipspoke +TARGET = lzss dlzss cd-tool str-player crypto-search bgrep tile-convert mipspoke bin2c all: subdirs ${TARGET} @@ -23,7 +23,15 @@ dlzss: lzss Makefile yazedc: yazedc-main.o lib/lib.a Makefile ${CXX} yazedc-main.o lib/lib.a -DYAZEDC_MAIN -o yazedc ${LDFLAGS} -cd-tool: includes/cdutils.h includes/yazedc.h cd-tool.o lib/lib.a psxdev/psxdev.a Makefile +cd-tool.o: cd-tool.cpp cd-tool-hc.h + +cd-tool-hc.h: bin2c cd-tool.bin + ./bin2c cd-tool.bin cd-tool-hc.h cd_tool_lua + +cd-tool.bin: cd-tool.lua + luac -s -o cd-tool.bin cd-tool.lua + +cd-tool: includes/cdutils.h includes/yazedc.h cd-tool.o lib/lib.a psxdev/psxdev.a Makefile ${CXX} cd-tool.o lib/lib.a psxdev/psxdev.a -o cd-tool ${CDTOOL_LDFLAGS} dte-tool: includes/dte.h dtemain.o lib/lib.a Makefile @@ -44,6 +52,9 @@ bgrep: bgrep.o Makefile tile-convert: tile-convert.o Makefile ${CXX} tile-convert.o -o tile-convert ${LDFLAGS} +bin2c: bin2c.o Makefile + ${CXX} bin2c.o -o bin2c ${LDFLAGS} + clean: for d in ${SUBDIRS} ; do make -C $$d clean || exit -1 ; done rm -f *.o ${TARGET} compil.c diff --git a/bin2c.cpp b/bin2c.cpp new file mode 100644 index 0000000..69561a1 --- /dev/null +++ b/bin2c.cpp @@ -0,0 +1,40 @@ +#include <Input.h> +#include <Output.h> +#include <Main.h> + +CODE_BEGINS +virtual int startup() throw (GeneralException) { + int i; + + if (argc != 4) { + printm(M_BARE, "Usage: %s <bin file> <c file> <symbol>\n", argv[0]); + exit(-1); + } + + printm(M_BARE, "Starting converting %s to %s:\n", argv[1], argv[2]); + + Input binfile(argv[1]); + Output cfile(argv[2]); + + unsigned char * map = (unsigned char *) binfile.mmap(); + + cfile << "int " << argv[3] << "_size = " << binfile.GetSize() << ";\n"; + cfile << "unsigned char " << argv[3] << "[] = {"; + + for (i = 0; i < binfile.GetSize(); i++) { + String s; + + s.set("0x%02x, ", map[i]); + if (!(i % 16)) { + cfile << "\n\t"; + printm(M_BARE, "%5.2f%%\r", i * 100.0 / binfile.GetSize()); + } + cfile << s; + } + + cfile << "\n};\n"; + printm(M_BARE, "Done! \n"); + + return 0; +} +CODE_ENDS diff --git a/cd-tool.cpp b/cd-tool.cpp index 9737647..d6a9b68 100644 --- a/cd-tool.cpp +++ b/cd-tool.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: cd-tool.cpp,v 1.28 2004-05-02 02:29:23 pixel Exp $ */ +/* $Id: cd-tool.cpp,v 1.29 2004-05-02 12:29:02 pixel Exp $ */ #define WIP @@ -39,6 +39,8 @@ #include <readline/readline.h> #include <readline/history.h> +#include "cd-tool-hc.h" + bool interactive = false; cdutils * cdutil = 0; isobuilder * build = 0; @@ -90,7 +92,7 @@ int sLua_basecdtool::basecdtool_proceed_statics(Lua * L, int n, int caller) { switch (caller) { case BASECDTOOL_LOAD: if (!n) { - L->load(&Input("cd-tool.lua")); + L->load(&Input("cd-tool.lua")); } else { if (L->isstring(1)) { L->load(&Input(L->tostring(1))); @@ -231,6 +233,7 @@ struct option long_options[] = { {"interactive", 0, NULL, 'i'}, {"line", 0, NULL, 'l'}, {"exec", 1, NULL, 'e'}, + {"built-in", 0, NULL, 'b'}, {"probe", 0, NULL, 'p'}, {0, 0, NULL, 0 } }; @@ -298,6 +301,8 @@ void showhelp(bool longhelp = false) { " -i to start interactive mode.\n" " -l to turn off the exec on end line.\n" " -e <cmd> to execute this single command in LUA.\n" +" -b to force the use of the built-in cd-tool.lua\n" +" -p to run a CD device probe.\n" " -h for a help page.\n" , argv[0]); @@ -336,7 +341,7 @@ void probe(void) { virtual int startup() throw (GeneralException) { char c; - bool auto_exec = true, strip = true, todo = false, runit, write = false; + bool auto_exec = true, strip = true, todo = false, runit, write = false, builtin = false; char * file = 0, * output = 0, * compile = 0, * exec = 0, * line_read = 0; char prompt[10]; Lua * L = 0; @@ -346,13 +351,13 @@ virtual int startup() throw (GeneralException) { String line, endline; int pos; - verbosity = M_STATUS; + verbosity = M_WARNING; showbanner(); /* Let's start parsing options */ - while ((c = getopt_long(argc, argv, "Hhvf:wo:a:c:dile:pm:", long_options, NULL)) != EOF) { + while ((c = getopt_long(argc, argv, "Hhvf:wo:a:c:dile:pb", long_options, NULL)) != EOF) { switch (c) { case 'h': case 'H': @@ -394,6 +399,9 @@ virtual int startup() throw (GeneralException) { case 'p': probe(); throw Exit(0); + case 'b': + builtin = true; + break; default: showhelp(); throw Exit(-1); @@ -406,8 +414,31 @@ virtual int startup() throw (GeneralException) { L = start_basic_lua(); /* Loading cd-tool.lua (only when not compiling) */ - if (!compile) - L->load(&Input("cd-tool.lua")); + if (!compile && !builtin) { + try { + L->load(&Input("cd-tool.lua")); + } + catch (GeneralException e) { + printm(M_WARNING, "There was an error loading cd-tool.lua, using built-in: %s\n", e.GetMsg()); + builtin = true; + } + } + + if (!compile && builtin) { + Buffer built; + int i; + + for (i = 0; i < cd_tool_lua_size; i++) { + built.writeU8(cd_tool_lua[i]); + } + try { + L->load(&built); + } + catch (GeneralException e) { + printm(M_WARNING, "There was an error loading built-in cd-tool.lua: %s\n", e.GetMsg()); + builtin = true; + } + } /* Loading all the scripts */ while (optind < argc) { @@ -512,6 +543,12 @@ virtual int startup() throw (GeneralException) { while(L->gettop()) L->pop(); } + catch (GeneralException e) { + /* A more severe exception... */ + while(L->gettop()) + L->pop(); + printm(M_ERROR, "Aborted. LUA caused the following exception: %s\n", e.GetMsg()); + } strcpy(prompt, "> "); } else { strcpy(prompt, "- "); diff --git a/cd-tool.lua b/cd-tool.lua index 4e0f0d0..7b37d0f 100644 --- a/cd-tool.lua +++ b/cd-tool.lua @@ -1,176 +1,181 @@ - ------------------
--- misc functions --
- ------------------
-
-function display(inp)
- if (type(inp) == "string") then
- inp = Input(inp)
- elseif (type(inp) ~= "table") then
- error("Display needs a string or an Input object")
- end
-
- while(not inp:isclosed()) do
- print(inp:read())
- end
-end
-
-function pchar(n)
- if (not ((n >= 32) and (n <= 127))) then
- n = 0x2e
- end
- return hex(n, "%c")
-end
-
-function hexdump(inp, from, to, width)
- local size, nlines, remaining, data_array, line, byte, outstring
-
- if (type(inp) == "string") then
- inp = Input(inp)
- elseif (type(inp) ~= "table") then
- error("Hexdump needs a string or an Input object")
- end
-
- size = inp:getsize()
-
- if (from == nil) then
- from = 0
- end
-
- if (to == nil) then
- to = size
- end
-
- if (to > size) then
- to = size
- end
-
- size = to - from
-
- if (width == nil) then
- width = 16
- end
-
- nlines = math.floor(size / width)
- remaining = math.mod(size, width)
- inp:seek(from)
- data_array = inp:read(size)
-
- for line = 0, nlines - 1, 1 do
- outstring = hex(line * width + from, "%08x ")
- for byte = 0, width - 1, 1 do
- outstring = outstring .. hex(data_array[line * 16 + byte]) .. " "
- end
- outstring = outstring .. " "
- for byte = 0, width - 1, 1 do
- outstring = outstring .. pchar(data_array[line * 16 + byte])
- end
- print(outstring)
- end
-
- if (remaining == 0) then
- return
- end
-
- outstring = hex(nlines * width + from, "%08x ");
- for byte = 0, remaining - 1, 1 do
- outstring = outstring .. hex(data_array[nlines * 16 + byte]) .. " "
- end
- for byte = remaining + 1, width - 1, 1 do
- outstring = outstring .. " "
- end
- outstring = outstring .. " "
- for byte = 0, remaining - 1, 1 do
- outstring = outstring .. pchar(data_array[nlines * 16 + byte])
- end
-
- print(outstring)
-end
-
-
- --------------------------
--- cdutil object wrappers --
- --------------------------
-
-function cdfile(arg1, arg2, arg3, arg4)
- local cdutil_implied = false
-
- if ((type(arg1) ~= "table") or (arg1.cdfile == nil)) then
- cdutil_implied = true
- end
-
- if ((arg2 == nil) and (arg3 == nil) and (arg4 == nil)) then
- return cdutil:cdfile(arg1)
- elseif ((arg3 == nil) and (arg4 == nil)) then
- if (cdutil_implied) then
- return cdutil:cdfile(arg1, arg2)
- else
- return arg1:cdfile(arg2)
- end
- elseif (arg4 == nil) then
- if (cdutil_implied) then
- return cdutil:cdfile(arg1, arg2, arg3)
- else
- return arg1:cdfile(arg2, arg3)
- end
- else
- return arg1:cdfile(arg2, arg3, arg4)
- end
-end
-
-function setisow(iso_w)
- if (cdutil == nil) then error "cdutil object non existant" end
- return cdutil:setisow(iso_w)
-end
-
-function guessmode(sect)
- if (cdutil == nil) then error "cdutil object non existant" end
- if (sect == nil) then
- return cdutil:guessmode()
- else
- return cdutil:guessmode(sect)
- end
-end
-
-function sectorseek(sect)
- if (cdutil == nil) then error "cdutil object non existant" end
- return cdutil:sectorseek(sect)
-end
-
-function readsector(sect, mode)
- if (cdutil == nil) then error "cdutil object non existant" end
- if (sect == nil) then
- return cdutil:readsector()
- elseif (mode == nil) then
- return cdutil:readsector(sect)
- else
- return cdutil:readsector(sect, mode)
- end
-end
+ ------------------ +-- misc functions -- + ------------------ + +function display(inp) + if (type(inp) == "string") then + inp = Input(inp) + elseif (type(inp) ~= "table") then + error("Display needs a string or an Input object") + end + + while(not inp:isclosed()) do + print(inp:read()) + end +end + +function pchar(n) + if (not ((n >= 32) and (n <= 127))) then + n = 46 + end + return hex(n, "%c") +end + +function hexdump(inp, from, to, width) + local size, nlines, remaining, data_array, line, byte, outstring + + if (type(inp) == "string") then + inp = Input(inp) + elseif (type(inp) ~= "table") then + error("Hexdump needs a string or an Input object") + end + + size = inp:getsize() + + if (from == nil) then + from = 0 + end + + if (to == nil) then + to = size + end + + if (to > size) then + to = size + end + + size = to - from + + if (width == nil) then + width = 16 + end + + nlines = math.floor(size / width) + remaining = math.mod(size, width) + inp:seek(from) + data_array = inp:read(size) + + for line = 0, nlines - 1, 1 do + outstring = hex(line * width + from, "%08x ") + for byte = 0, width - 1, 1 do + outstring = outstring .. hex(data_array[line * 16 + byte]) .. " " + end + outstring = outstring .. " " + for byte = 0, width - 1, 1 do + outstring = outstring .. pchar(data_array[line * 16 + byte]) + end + print(outstring) + end + + if (remaining == 0) then + return + end + + outstring = hex(nlines * width + from, "%08x "); + for byte = 0, remaining - 1, 1 do + outstring = outstring .. hex(data_array[nlines * 16 + byte]) .. " " + end + for byte = remaining + 1, width - 1, 1 do + outstring = outstring .. " " + end + outstring = outstring .. " " + for byte = 0, remaining - 1, 1 do + outstring = outstring .. pchar(data_array[nlines * 16 + byte]) + end + + print(outstring) +end + + + -------------------------- +-- cdutil object wrappers -- + -------------------------- + +function check_cdutil() + if (cdutil == nil) then error "cdutil object non existant" end +end + +function cdfile(arg1, arg2, arg3, arg4) + local cdutil_implied = false + + if ((type(arg1) ~= "table") or (arg1.cdfile == nil)) then + check_cdutil() + cdutil_implied = true + end + + if ((arg2 == nil) and (arg3 == nil) and (arg4 == nil)) then + return cdutil:cdfile(arg1) + elseif ((arg3 == nil) and (arg4 == nil)) then + if (cdutil_implied) then + return cdutil:cdfile(arg1, arg2) + else + return arg1:cdfile(arg2) + end + elseif (arg4 == nil) then + if (cdutil_implied) then + return cdutil:cdfile(arg1, arg2, arg3) + else + return arg1:cdfile(arg2, arg3) + end + else + return arg1:cdfile(arg2, arg3, arg4) + end +end + +function setisow(iso_w) + check_cdutil() + return cdutil:setisow(iso_w) +end + +function guessmode(sect) + check_cdutil() + if (sect == nil) then + return cdutil:guessmode() + else + return cdutil:guessmode(sect) + end +end + +function sectorseek(sect) + check_cdutil() + return cdutil:sectorseek(sect) +end + +function readsector(sect, mode) + check_cdutil() + if (sect == nil) then + return cdutil:readsector() + elseif (mode == nil) then + return cdutil:readsector(sect) + else + return cdutil:readsector(sect, mode) + end +end function readdatas(size, sector, mode) - if (cdutil == nil) then error "cdutil object non existant" end
- if (sect == nil) then
- return cdutil:readdatas(size)
- elseif (mode == nil) then
- return cdutil:readdatas(size, sect)
- else
- return cdutil:readdatas(size, sect, mode)
- end
+ check_cdutil() + if (sect == nil) then + return cdutil:readdatas(size) + elseif (mode == nil) then + return cdutil:readdatas(size, sect) + else + return cdutil:readdatas(size, sect, mode) + end end function readfile(handle, size, sector, mode) - if (cdutil == nil) then error "cdutil object non existant" end
- if (sect == nil) then
- return cdutil:readfile(handle, size)
- elseif (mode == nil) then
- return cdutil:readfile(handle, size, sect)
- else
- return cdutil:readfile(handle, size, sect, mode)
- end
+ check_cdutil() + if (sect == nil) then + return cdutil:readfile(handle, size) + elseif (mode == nil) then + return cdutil:readfile(handle, size, sect) + else + return cdutil:readfile(handle, size, sect, mode) + end end function writesector(array, sector, mode) - if (cdutil == nil) then error "cdutil object non existant" end + check_cdutil() if (sector == nil) then return cdutil:writesector(array, sector) elseif (mode == nil) then @@ -179,7 +184,7 @@ function writesector(array, sector, mode) end function writedatas(array, size, sector, mode) - if (cdutil == nil) then error "cdutil object non existant" end + check_cdutil() if (sector == nil) then return cdutil:writedatas(array, size) elseif (mode == nil) then @@ -190,7 +195,7 @@ function writedatas(array, size, sector, mode) end function writefile(handle, size, sector, mode) - if (cdutil == nil) then error "cdutil object non existant" end + check_cdutil() if (size == nil) then return cdutil:writefile(handle) elseif (sector == nil) then @@ -203,71 +208,75 @@ function writefile(handle, size, sector, mode) end function findpath(path) - if (cdutil == nil) then error "cdutil object non existant" end + check_cdutil() return cdutil:findpath(path) end function findparent(path) - if (cdutil == nil) then error "cdutil object non existant" end + check_cdutil() return cdutil:findparent(path) end function finddirectory(dir, path) - if (cdutil == nil) then error "cdutil object non existant" end + check_cdutil() return cdutil:finddirectory(dir, path) end -
-
- -----------------------
--- iso object wrappers --
- -----------------------
-
-function foreword(lcdutil)
- if (iso == nil) then error "iso object non existant" end
- if ((lcdutil == nil) and (cdutil == nil)) then error "cdutil object non existant" end
- if (lcdutil == nil) then
- return iso:foreword(cdutil)
- else
- return iso:foreword(lcdutil)
- end
-end
-
-function foreword_handle(handle, mode)
- if (iso == nil) then error "iso object non existant" end
- if (mode == nil) then
- return iso:foreword_handle(handle)
- else
- return iso:foreword_handle(handle, mode)
- end
-end
-
-function foreword_array(array, mode)
- if (iso == nil) then error "iso object non existant" end
- if (mode == nil) then
- return iso:foreword_array(array)
- else
- return iso:foreword_array(array, mode)
- end
-end
-
-function getdispsect()
- if (iso == nil) then error "iso object non existant" end
- return iso:getdispsect()
-end
-
-function putfile(handle, mode, sector)
- if (iso == nil) then error "iso object non existant" end
- if (mode == nil) then
- iso:putfile(handle)
- elseif (sector == nil) then
- iso:putfile(handle, mode)
- else
- iso:putfile(handle, mode, sector)
- end
-end
+ + + ----------------------- +-- iso object wrappers -- + ----------------------- + +function check_iso() + if (iso == nil) then error "iso object non existant" end +end + +function foreword(lcdutil) + check_iso() + if ((lcdutil == nil) and (cdutil == nil)) then error "cdutil object non existant" end + if (lcdutil == nil) then + return iso:foreword(cdutil) + else + return iso:foreword(lcdutil) + end +end + +function foreword_handle(handle, mode) + check_iso() + if (mode == nil) then + return iso:foreword_handle(handle) + else + return iso:foreword_handle(handle, mode) + end +end + +function foreword_array(array, mode) + check_iso() + if (mode == nil) then + return iso:foreword_array(array) + else + return iso:foreword_array(array, mode) + end +end + +function getdispsect() + check_iso() + return iso:getdispsect() +end + +function putfile(handle, mode, sector) + check_iso() + if (mode == nil) then + iso:putfile(handle) + elseif (sector == nil) then + iso:putfile(handle, mode) + else + iso:putfile(handle, mode, sector) + end +end function putdatas(array, size, mode, sector) - if (iso == nil) then error "iso object non existant" end
+ check_iso() if (mode == nil) then iso:putdatas(array, size) elseif (sector == nil) then @@ -278,7 +287,7 @@ function putdatas(array, size, mode, sector) end function createsector(array, mode, sector) - if (iso == nil) then error "iso object non existant" end
+ check_iso() if (mode == nil) then iso:createsector(array) elseif (sector == nil) then @@ -289,43 +298,43 @@ function createsector(array, mode, sector) end function setEOF() - if (iso == nil) then error "iso object non existant" end
- iso:setEOF()
-end
-
-function clearEOF()
- if (iso == nil) then error "iso object non existant" end
- iso:clearEOF()
-end
+ check_iso() + iso:setEOF() +end + +function clearEOF() + check_iso() + iso:clearEOF() +end function setbasics(pvd, rootsize, ptsize, nvd, rootsect) - if (iso == nil) then error "iso object non existant" end
- if (rootsize == nil) then
- iso:setbasics(pvd)
- elseif (ptsize == nil) then
- iso:setbasics(pvd, rootsize)
- elseif (nvd == nil) then
- iso:setbasics(pvd, rootsize, ptsize)
- elseif (rootsect) then
- iso:setbasics(pvd, rootsize, ptsize, nvd)
- else
- iso:setbasics(pvd, rootsize, ptsize, nvd, rootsect)
- end
-end
+ check_iso() + if (rootsize == nil) then + iso:setbasics(pvd) + elseif (ptsize == nil) then + iso:setbasics(pvd, rootsize) + elseif (nvd == nil) then + iso:setbasics(pvd, rootsize, ptsize) + elseif (rootsect) then + iso:setbasics(pvd, rootsize, ptsize, nvd) + else + iso:setbasics(pvd, rootsize, ptsize, nvd, rootsect) + end +end function createdir(dirtree, name, size, direntry, mode) - if (iso == nil) then error "iso object non existant" end
- if (size == nil) then
- iso:createdir(dirtree, name)
- elseif (mode == nil) then
- iso:createdir(dirtree, name, size, direntry)
- else
- iso:createdir(dirtree, name, size, direntry, mode)
- end
-end
+ check_iso() + if (size == nil) then + iso:createdir(dirtree, name) + elseif (mode == nil) then + iso:createdir(dirtree, name, size, direntry) + else + iso:createdir(dirtree, name, size, direntry, mode) + end +end function createfile(dirtree, name, size, direntry, mode) - if (iso == nil) then error "iso object non existant" end
+ check_iso() if (mode == nil) then iso:createfile(dirtree, name, size, direntry) else @@ -334,7 +343,7 @@ function createfile(dirtree, name, size, direntry, mode) end function copydir(dirtree, cdutils, direntry, mode) - if (iso == nil) then error "iso object non existant" end
+ check_iso() if (mode == nil) then iso:copydir(dirtree, cdutils, direntry) else @@ -343,14 +352,14 @@ function copydir(dirtree, cdutils, direntry, mode) end function close(cuefile, mode, nsectors) - if (iso == nil) then error "iso object non existant" end
- if (cuefile == nil) then
- iso:close()
- elseif (mode == nil) then
- iso:close(cuefile)
- elseif (nsectors == nil) then
- iso:close(cuefile, mode)
- else
- iso:close(cuefile, mode, nsectors)
- end
-end
+ check_iso() + if (cuefile == nil) then + iso:close() + elseif (mode == nil) then + iso:close(cuefile) + elseif (nsectors == nil) then + iso:close(cuefile, mode) + else + iso:close(cuefile, mode, nsectors) + end +end |