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 /lib | |
parent | 2371bb1ad54636e4f3f8524af65f37b64ef96a2a (diff) |
Still, various fixes, changes, improvements, new bug added, etc...
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cdutils.cpp | 43 | ||||
-rw-r--r-- | lib/isobuilder.cpp | 4 | ||||
-rw-r--r-- | lib/luacd.cpp | 75 |
3 files changed, 106 insertions, 16 deletions
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; |