diff options
author | pixel <pixel> | 2004-05-03 12:55:04 +0000 |
---|---|---|
committer | pixel <pixel> | 2004-05-03 12:55:04 +0000 |
commit | 5b1e50428eab9ea1d141b84e4579d77ac7b8f2d9 (patch) | |
tree | d1b008ff2f7e02bcf849587842e0c9548347e530 | |
parent | 2371bb1ad54636e4f3f8524af65f37b64ef96a2a (diff) |
Still, various fixes, changes, improvements, new bug added, etc...
-rwxr-xr-x | Makefile | 3 | ||||
-rw-r--r-- | cd-tool.cpp | 4 | ||||
-rw-r--r-- | cd-tool.lua | 22 | ||||
-rw-r--r-- | includes/cdutils.h | 7 | ||||
-rw-r--r-- | lib/cdutils.cpp | 43 | ||||
-rw-r--r-- | lib/isobuilder.cpp | 4 | ||||
-rw-r--r-- | lib/luacd.cpp | 75 |
7 files changed, 132 insertions, 26 deletions
@@ -57,5 +57,4 @@ bin2c: bin2c.o Makefile clean: for d in ${SUBDIRS} ; do make -C $$d clean || exit -1 ; done - rm -f *.o ${TARGET} compil.c - + rm -f *.o ${TARGET} compil.c cd-tool-hc.h cd-tool.bin diff --git a/cd-tool.cpp b/cd-tool.cpp index d6a9b68..14f0f0b 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.29 2004-05-02 12:29:02 pixel Exp $ */ +/* $Id: cd-tool.cpp,v 1.30 2004-05-03 12:55:04 pixel Exp $ */ #define WIP @@ -69,7 +69,7 @@ enum basecdtool_t { }; struct lua_functypes_t basecdtool_functions[] = { - { BASECDTOOL_LOAD, "load", 0, 1, { LUA_ANY } }, + { BASECDTOOL_LOAD, "load", 0, 1, { LUA_STRING | LUA_OBJECT } }, { -1, 0, 0, 0, 0 } }; diff --git a/cd-tool.lua b/cd-tool.lua index 30ebd34..577b091 100644 --- a/cd-tool.lua +++ b/cd-tool.lua @@ -4,9 +4,9 @@ function extract_file(source, dest, mode) if (mode == nil) then - source = cdfile(findpath(source)) + source = cdfile(source) else - source = cdfile(findpath(source), mode) + source = cdfile(source, mode) end dest = Output(dest) source.copyto(dest) @@ -26,21 +26,28 @@ function insert_file(source, dest, mode) end end -function display(inp) +function display(inp, n) + local i if (type(inp) == "string") then inp = Input(inp) elseif (type(inp) ~= "table") then error("Display needs a string or an Input object") end + i = 0 + while(not inp:isclosed()) do + i = i + 1 print(inp:read()) + if ((n ~= nil) and (i >= n)) then + return + end end end function pchar(n) if (not ((n >= 32) and (n <= 127))) then - n = 46 -- a dot, 0x2e. + n = 46 -- aka '.' or 0x2e end return hex(n, "%c") end @@ -125,6 +132,13 @@ function cdfile(arg1, arg2, arg3, arg4) if ((type(arg1) ~= "table") or (arg1.cdfile == nil)) then check_cdutil() cdutil_implied = true + if (type(arg1) == "string") then + arg1 = findpath(arg1) + end + else + if (type(arg2) == "string") then + arg2 = findpath(arg2) + end end if ((arg2 == nil) and (arg3 == nil) and (arg4 == nil)) then diff --git a/includes/cdutils.h b/includes/cdutils.h index d21c9cf..c81c093 100644 --- a/includes/cdutils.h +++ b/includes/cdutils.h @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: cdutils.h,v 1.15 2003-12-14 22:04:34 pixel Exp $ */ +/* $Id: cdutils.h,v 1.16 2004-05-03 12:55:04 pixel Exp $ */ #ifndef __CDUTILS_H__ #define __CDUTILS_H__ @@ -83,9 +83,10 @@ class cdutils : public Base { long read_sector(Byte * buffer, int type = GUESS, int number = -1); void read_datas(Byte * buffer, long size, int type = GUESS, int number = -1); void read_file(Handle * Handle, long size, int type = GUESS, int number = -1); - void write_sector(Byte * buffer, int type = GUESS, int number = -1); + void write_sector(Byte * buffer, int type = GUESS, int number = -1) throw (GeneralException); void write_datas(Byte * buffer, long size, int type = GUESS, int number = -1); void write_file(Handle * Handle, long size = -1, int type = GUESS, int number = -1); + void create_sector(int type, int number, bool eof = false) throw (GeneralException); int get_iso_infos(); int show_iso_infos(); int get_pt_infos(); @@ -104,6 +105,8 @@ class cdutils : public Base { static bool is_valid_BCD(unsigned char x); static unsigned long from_MSF(unsigned long msf, unsigned long start = 150); static unsigned long from_MSF(unsigned char m, unsigned char s, unsigned char f, unsigned long start = 150); + static unsigned long to_MSF(int sect, unsigned long start = 150); + static void to_MSF(int sect, unsigned char & m, unsigned char & s, unsigned char & f, unsigned long start = 150); private: void write_ppf(Byte * old_sec, Byte * new_sec, int sec_num); String format_date(String input); diff --git a/lib/cdutils.cpp b/lib/cdutils.cpp index 821d51a..3ab4982 100644 --- a/lib/cdutils.cpp +++ b/lib/cdutils.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: cdutils.cpp,v 1.28 2004-05-02 21:04:45 pixel Exp $ */ +/* $Id: cdutils.cpp,v 1.29 2004-05-03 12:55:04 pixel Exp $ */ #include <stdio.h> #include <string.h> @@ -63,6 +63,20 @@ unsigned long cdutils::from_MSF(unsigned long msf, unsigned long start) { return from_MSF(m, s, f, start); } +void cdutils::to_MSF(int sect, unsigned char & m, unsigned char & s, unsigned char & f, unsigned long start) { + sect += start; + f = to_BCD(sect % 75); + sect /= 75; + s = to_BCD(sect % 60); + m = to_BCD(sect / 60); +} + +unsigned long cdutils::to_MSF(int sect, unsigned long start) { + unsigned char m, s, f; + to_MSF(sect, m, s, f, start); + return f | (s << 8) | (m << 16); +} + Handle * cdutils::open_ppf(String ppf, String comment) throw (GeneralException) { int i, l; @@ -255,7 +269,7 @@ void cdutils::read_file(Handle * file, long size, int type, int number) { } } -void cdutils::write_sector(Byte * buffer, int type, int number) { +void cdutils::write_sector(Byte * buffer, int type, int number) throw (GeneralException) { Byte old_sector[2352], new_sector[2352]; if (type == GUESS) { @@ -283,7 +297,7 @@ void cdutils::write_sector(Byte * buffer, int type, int number) { } else if (ppf_file) { write_ppf(old_sector, new_sector, number); } else { - printm(M_ERROR, "No writing method for iso file"); + throw GeneralException("No writing method for iso file"); } } @@ -339,6 +353,29 @@ void cdutils::write_file(Handle * file, long size, int type, int number) { } } +void cdutils::create_sector(int type, int number, bool eof) throw (GeneralException) { + Byte sector[2352]; + if (!f_iso_w) + throw GeneralException("Can't create sector: ISO not in write mode"); + + to_MSF(number, yazedc_o.minute, yazedc_o.second, yazedc_o.frame); + memset(sector, 0, 2352); + if ((type == MODE2_FORM1) || (type == MODE2_FORM2)) { + sector[16] = sector[20] = 0; // File Number + sector[17] = sector[21] = 0; // Channel Number + sector[18] = sector[22] = 8 | (eof ? 129 : 0) | + (type == MODE2_FORM2 ? 32 : 0); + sector[19] = sector[23] = 0; // Coding Info + } + yazedc_o.do_encode_L2(sector, type, 0); + + f_iso_w->seek(2352 * number); + + f_iso_w->write(sector, 2352); + + sector_seek(number); +} + void cdutils::show_head_entry(void) { printm(M_BARE, "Sector Size Date Time Flags Name XA flags\n"); } diff --git a/lib/isobuilder.cpp b/lib/isobuilder.cpp index 586e6f4..3f31c73 100644 --- a/lib/isobuilder.cpp +++ b/lib/isobuilder.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: isobuilder.cpp,v 1.11 2004-01-03 15:04:47 pixel Exp $ */ +/* $Id: isobuilder.cpp,v 1.12 2004-05-03 12:55:04 pixel Exp $ */ #include "isobuilder.h" @@ -543,7 +543,7 @@ int isobuilder::createsector(Byte * datas, int smode, int n) { dsector[17] = dsector[21] = 0; // Channel Number dsector[18] = dsector[22] = sub_EOR | sub_EOF | 8 | (smode == MODE2_FORM2 ? 32 : 0); - dsector[19] = dsector[23] = 0; + dsector[19] = dsector[23] = 0; // Coding Info } if (smode != MODE_RAW) { diff --git a/lib/luacd.cpp b/lib/luacd.cpp index 2c10b3f..97efe82 100644 --- a/lib/luacd.cpp +++ b/lib/luacd.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: luacd.cpp,v 1.12 2004-05-02 21:04:45 pixel Exp $ */ +/* $Id: luacd.cpp,v 1.13 2004-05-03 12:55:04 pixel Exp $ */ #include "luacd.h" @@ -48,6 +48,9 @@ enum cdutils_methods_t { CDUTILS_FINDPARENT, CDUTILS_FINDDIRENTRY, CDUTILS_NEWCDFILE, + CDUTILS_UPDATESIZE, + CDUTILS_UPDATESECTOR, + CDUTILS_CREATESECTOR, }; enum cdutils_functions_t { @@ -58,6 +61,7 @@ enum cdutils_functions_t { CDUTILS_TO_BCD, CDUTILS_IS_VALID_BCD, CDUTILS_FROM_MSF, + CDUTILS_TO_MSF, }; struct lua_functypes_t cdutils_methods[] = { @@ -76,6 +80,9 @@ struct lua_functypes_t cdutils_methods[] = { { CDUTILS_FINDPARENT, "findparent", 1, 1, {LUA_STRING} }, { CDUTILS_FINDDIRENTRY, "finddirentry", 2, 2, {LUA_OBJECT, LUA_STRING} }, { CDUTILS_NEWCDFILE, "cdfile", 1, 3, {LUA_ANY, LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_UPDATESIZE, "updatesize", 2, 2, {LUA_STRING, LUA_NUMBER} }, + { CDUTILS_UPDATESECTOR, "updatesector", 2, 2, {LUA_STRING, LUA_NUMBER} }, + { CDUTILS_CREATESECTOR, "createsector", 2, 3, {LUA_NUMBER, LUA_NUMBER, LUA_BOOLEAN} }, { -1, 0, 0, 0, 0 } }; @@ -87,6 +94,7 @@ struct lua_functypes_t cdutils_functions[] = { { CDUTILS_TO_BCD, "to_BCD", 1, 1, {LUA_NUMBER} }, { CDUTILS_IS_VALID_BCD, "is_valid_BCD", 1, 1, {LUA_NUMBER} }, { CDUTILS_FROM_MSF, "from_MSF", 1, 4, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_TO_MSF, "to_MSF", 1, 2, {LUA_NUMBER, LUA_NUMBER} }, { -1, 0, 0, 0, 0 } }; @@ -107,6 +115,9 @@ class sLua_cdutils : public Base { DECLARE_METHOD(cdutils, CDUTILS_FINDPARENT); DECLARE_METHOD(cdutils, CDUTILS_FINDDIRENTRY); DECLARE_METHOD(cdutils, CDUTILS_NEWCDFILE); + DECLARE_METHOD(cdutils, CDUTILS_UPDATESIZE); + DECLARE_METHOD(cdutils, CDUTILS_UPDATESECTOR); + DECLARE_METHOD(cdutils, CDUTILS_CREATESECTOR); DECLARE_FUNCTION(cdutils, CDUTILS_NEWCDUTILS); DECLARE_FUNCTION(cdutils, CDUTILS_SWAPWORD); @@ -115,6 +126,7 @@ class sLua_cdutils : public Base { DECLARE_FUNCTION(cdutils, CDUTILS_TO_BCD); DECLARE_FUNCTION(cdutils, CDUTILS_IS_VALID_BCD); DECLARE_FUNCTION(cdutils, CDUTILS_FROM_MSF); + DECLARE_FUNCTION(cdutils, CDUTILS_TO_MSF); private: static int cdutils_proceed(Lua * L, int n, cdutils * obj, int caller); @@ -139,6 +151,9 @@ void Luacdutils::pushmembers(Lua * L) { PUSH_METHOD(cdutils, CDUTILS_FINDPARENT); PUSH_METHOD(cdutils, CDUTILS_FINDDIRENTRY); PUSH_METHOD(cdutils, CDUTILS_NEWCDFILE); + PUSH_METHOD(cdutils, CDUTILS_UPDATESIZE); + PUSH_METHOD(cdutils, CDUTILS_UPDATESECTOR); + PUSH_METHOD(cdutils, CDUTILS_CREATESECTOR); } void Luacdutils::pushstatics(Lua * L) throw (GeneralException) { @@ -152,6 +167,7 @@ void Luacdutils::pushstatics(Lua * L) throw (GeneralException) { PUSH_FUNCTION(cdutils, CDUTILS_TO_BCD); PUSH_FUNCTION(cdutils, CDUTILS_IS_VALID_BCD); PUSH_FUNCTION(cdutils, CDUTILS_FROM_MSF); + PUSH_FUNCTION(cdutils, CDUTILS_TO_MSF); L->push("MODE0"); L->push((lua_Number) MODE0); @@ -216,8 +232,8 @@ int sLua_cdutils::cdutils_proceed(Lua * L, int n, cdutils * cd, int caller) { Handle * h; Byte sdatas[2352], * datas; String path; - cdutils::DirEntry * dir, * bdir, * adir; - bool invalid = false; + cdutils::DirEntry * dir, * bdir, * adir, pdir; + bool invalid = false, eof = false; int sector; cdfile * cdf; @@ -228,13 +244,13 @@ int sLua_cdutils::cdutils_proceed(Lua * L, int n, cdutils * cd, int caller) { break; case CDUTILS_GUESSTYPE: if (n == 1) { - sect = L->tonumber(); + sect = L->tonumber(2); } L->push((lua_Number) cd->guess_type(sect)); r = 1; break; case CDUTILS_SECTORSEEK: - sect = L->tonumber(); + sect = L->tonumber(2); cd->sector_seek(sect); break; case CDUTILS_READSECTOR: @@ -382,20 +398,20 @@ int sLua_cdutils::cdutils_proceed(Lua * L, int n, cdutils * cd, int caller) { break; case CDUTILS_NEWCDFILE: if (L->istable(2)) { - if (n <= 3) { + if (n <= 2) { dir = (cdutils::DirEntry *) LuaObject::getme(L, 2); - if (n == 3) + if (n == 2) mode = L->tonumber(3); cdf = new cdfile(cd, dir, mode); } else { invalid = true; } } else if (L->isnumber(2)) { - if (n >= 2) { + if (n >= 1) { sector = L->tonumber(2); - if (n >= 3) + if (n >= 2) size = L->tonumber(3); - if (n == 4) + if (n == 3) mode = L->tonumber(4); cdf = new cdfile(cd, sector, size, mode); } else { @@ -412,6 +428,31 @@ int sLua_cdutils::cdutils_proceed(Lua * L, int n, cdutils * cd, int caller) { r = 1; } break; + case CDUTILS_UPDATESIZE: + case CDUTILS_UPDATESECTOR: + path = L->tostring(2); + pdir = cd->find_parent(path); + dir = cd->find_path(&datas, path); + switch (caller) { + case CDUTILS_UPDATESIZE: + dir->Size = tolittle((Uint32) L->tonumber(3)); + dir->BESize = tobig((Uint32) L->tonumber(3)); + break; + case CDUTILS_UPDATESECTOR: + dir->Sector = tolittle((Uint32) L->tonumber(3)); + dir->BESector = tobig((Uint32) L->tonumber(3)); + break; + } + cd->write_datas(datas, pdir.Size, GUESS, pdir.Sector); + free(datas); + break; + case CDUTILS_CREATESECTOR: + mode = L->tonumber(2); + sect = L->tonumber(3); + if (n == 3) + eof = L->toboolean(4); + cd->create_sector(mode, sect, eof); + break; } @@ -422,7 +463,7 @@ int sLua_cdutils::cdutils_proceed_statics(Lua * L, int n, int caller) { int r = 0; Uint32 x; Handle * isor = 0, * isow = 0; - Uint32 msf, start = 150; + Uint32 sector, msf, start = 150; Byte m, s, f; switch(caller) { @@ -476,6 +517,18 @@ int sLua_cdutils::cdutils_proceed_statics(Lua * L, int n, int caller) { } r = 1; break; + case CDUTILS_TO_MSF: + sector = L->tonumber(1); + if (n == 2) + start = L->tonumber(2); + cdutils::to_MSF(sector, m, s, f, start); + msf = cdutils::to_MSF(sector, start); + L->push((lua_Number) msf); + L->push((lua_Number) m); + L->push((lua_Number) s); + L->push((lua_Number) f); + r = 4; + break; } return r; |