diff options
85 files changed, 14460 insertions, 14985 deletions
diff --git a/Dalos/Dalos.cc b/Dalos/Dalos.cc index 7e49660..b2f4212 100644 --- a/Dalos/Dalos.cc +++ b/Dalos/Dalos.cc @@ -1,526 +1 @@ -/*
- * Dalos
- * Copyright (C) 2004 Nicolas "Pixel" Noble
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/* $Id: Dalos.cc,v 1.7 2004-10-19 01:27:27 pixel Exp $ */
-
-#include <SDL.h>
-#include <SDL_thread.h>
-
-#include <vector>
-
-#include <Main.h>
-#include <Handle.h>
-#include <Input.h>
-#include <Buffer.h>
-#include <BLua.h>
-#include <LuaHandle.h>
-
-#include <engine.h>
-#include <glbase.h>
-#include <glshape.h>
-#include <font.h>
-
-#include <luacd.h>
-#include <luapsx.h>
-
-#include <Console.h>
-
-#include "cd-tool-hc.h"
-
-#ifdef __MINGW32__
-#define main SDL_main
-#endif
-
-bool auto_exec = true;
-bool lua_started = false;
-bool do_lua_break = false;
-
-CODE_BEGINS
-
-class hexview;
-
-hexview * hexviewer;
-
-mogltk::widgets::Root * Root;
-mogltk::widget * Frame, * MainPanel;
-mogltk::widgets::Menu * MainMenu;
-
-class threaded_Lua : public Lua {
- public:
- threaded_Lua() : mutex(SDL_CreateMutex()) { }
- virtual ~threaded_Lua() { SDL_DestroyMutex(mutex); }
- virtual void lock() {
- SDL_mutexP(mutex);
- }
- virtual void unlock() {
- SDL_mutexV(mutex);
- }
- private:
- SDL_mutex * mutex;
-};
-
-class threaded_locker : public locker_t {
- public:
- threaded_locker() : mutex(SDL_CreateMutex()) { }
- virtual ~threaded_locker() { SDL_DestroyMutex(mutex); }
- virtual void lock() {
- SDL_mutexP(mutex);
- }
- virtual void unlock() {
- SDL_mutexV(mutex);
- }
- private:
- SDL_mutex * mutex;
-};
-
-static int lua_print(lua_State * _L) {
- Lua * L = Lua::find(_L);
- String t = L->tostring() + "\n";
- char * tc = t.strdup();
-
- printm(M_STATUS, "%s", tc);
-
- free(tc);
-
- return 0;
-}
-
-static void lua_hook(lua_State * _L, lua_Debug * ar) {
- if (!lua_started)
- return;
- Lua * L = Lua::find(_L);
-
- if (do_lua_break) {
- L->do_break();
- do_lua_break = false;
- }
-}
-
-void start_lua() {
- Lua * L = new threaded_Lua();
- Buffer built;
- bool use_builtin_cdtool = false;
- int i;
-
- L->open_base();
- L->open_math();
- L->open_string();
- L->open_table();
-
- LuaInput::pushconstruct(L);
- LuaOutput::pushconstruct(L);
- LuaBuffer::pushconstruct(L);
-
- CD_PUSHSTATICS(L);
- Luapsx::pushstatics(L);
-
- L->push("print");
- L->push(lua_print);
- L->setvar();
-
- L->sethook(lua_hook, LUA_MASKLINE, 0);
-
- console_lock = SDL_CreateMutex();
- console_sem = SDL_CreateSemaphore(0);
-
- try {
- L->load(&Input("cd-tool.lua"));
- } catch (GeneralException e) {
- printm(M_WARNING, "There was an error loading cd-tool.lua: %s, using built-in.\n", e.GetMsg());
- use_builtin_cdtool = true;
- }
-
- if (use_builtin_cdtool) {
- 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());
- }
- }
-
- SDL_CreateThread(LuaThread, L);
-}
-
-static int LuaThread(void * d) {
- Lua * L = (Lua *) d;
- while (true) {
- SDL_SemWait(console_sem);
- lua_started = true;
- SDL_mutexP(console_lock);
- try {
- L->load(&console_buffer);
- }
- catch (LuaException e) {
- /* If there was an error, ignore it, and free the stack */
- 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());
- }
- SDL_mutexV(console_lock);
- lua_started = false;
- }
-}
-
-class hexview_keyevent : public mogltk::engine::keyevent {
- public:
- virtual void down(SDL_keysym k) {
- if (!Application->hexviewer || !Application->hexviewer->GetVisible()) {
- if (old_handler)
- old_handler->down(k);
- return;
- }
- switch (k.sym) {
- case SDLK_DOWN:
- Application->hexviewer->change_offset(Application->hexviewer->get_offset() + Application->hexviewer->get_width());
- break;
- case SDLK_UP:
- Application->hexviewer->change_offset(Application->hexviewer->get_offset() - Application->hexviewer->get_width());
- break;
- case SDLK_RIGHT:
- if (KMOD_ALT & k.mod) {
- Application->hexviewer->change_width(Application->hexviewer->get_width() + 1);
- } else if (KMOD_CTRL & k.mod) {
- Application->hexviewer->change_shift(Application->hexviewer->get_shift() - 1);
- } else {
- Application->hexviewer->change_offset(Application->hexviewer->get_offset() + 1);
- }
- break;
- case SDLK_LEFT:
- if (KMOD_ALT & k.mod) {
- Application->hexviewer->change_width(Application->hexviewer->get_width() - 1);
- } else if (KMOD_CTRL & k.mod) {
- Application->hexviewer->change_shift(Application->hexviewer->get_shift() + 1);
- } else {
- Application->hexviewer->change_offset(Application->hexviewer->get_offset() - 1);
- }
- break;
- case SDLK_PAGEDOWN:
- Application->hexviewer->change_offset(Application->hexviewer->get_offset() + Application->hexviewer->get_width() * Application->hexviewer->get_nlines());
- break;
- case SDLK_PAGEUP:
- Application->hexviewer->change_offset(Application->hexviewer->get_offset() - Application->hexviewer->get_width() * Application->hexviewer->get_nlines());
- break;
- case SDLK_HOME:
- Application->hexviewer->change_offset(0);
- break;
- case SDLK_END:
- Application->hexviewer->change_offset(Application->hexviewer->get_size() - 1);
- break;
- default:
- if (old_handler)
- old_handler->down(k);
- return;
- }
- }
- virtual void up(SDL_keysym k) {
- if (old_handler)
- old_handler->up(k);
- }
-};
-
-class myprinter : public printer_t {
- public:
- myprinter() : lock(SDL_CreateMutex()) { }
- virtual ~myprinter() { SDL_DestroyMutex(lock); }
- virtual bool printm(int level, const char * m, va_list ap) {
- static String heads[] = {"EE", "--", "WW", "II"};
- static char buffer[20480];
-
- if (level >= M_INFO)
- return true;
-
- SDL_mutexP(lock);
-
- vsprintf(buffer, m, ap);
- if (level >= 0)
- CurrentConsole->add_line("(" + heads[level] + ") " + buffer);
- else
- CurrentConsole->add_line(buffer);
-
- SDL_mutexV(lock);
-
- return true;
- }
- private:
- SDL_mutex * lock;
-};
-
-class hexview : public mogltk::widget {
- public:
- hexview(mogltk::shape * sh, mogltk::widget * father) :
- widget(father, 0, 0, father->GetW(), father->GetH(), 0, "hexview", sh), h(0), width(16), offset(0), offset_loaded(-1), size_loaded(0), data(0), virtual_base(0), shift(0)
- { nlines = GetH() / 13; Application->hexviewer = this; }
- virtual ~hexview() { free(data); Application->hexviewer = 0; }
- void set_virtual_base(int _virtual_base) {
- virtual_base = _virtual_base;
- }
- int get_nlines() {
- return nlines;
- }
- int get_size() {
- if (!h)
- return 0;
- return h->GetSize();
- }
- void change_width(int _width) {
- if (_width <= 0)
- _width = 1;
- if (width != _width) {
- free(data);
- width = _width;
- }
- }
- int get_width() {
- return width;
- }
- void change_offset(int _offset) {
- if ((_offset < 0) || !h)
- _offset = 0;
- if (h && (_offset >= h->GetSize()))
- _offset = h->GetSize() - 1;
- offset = _offset;
- }
- int get_offset() {
- return offset;
- }
- void change_shift(int _shift) {
- if (_shift < 0)
- _shift = 0;
- shift = _shift;
- }
- int get_shift() {
- return shift;
- }
- void bind_handle(Handle * _h) {
- h = _h;
- }
- Uint8 * get_data() {
- if (!data) {
- data = (Uint8 *) malloc(nlines * width);
- }
-
- if ((offset_loaded == offset) && (size_loaded == (nlines * width)))
- return data;
-
- h->seek(offset);
- h->read(data, nlines * width);
-
- offset_loaded = offset;
- size_loaded = nlines * width;
-
- return data;
- }
- virtual void draw() {
- int i, max_o, j, k, start_o, l, c;
-
- if (!h)
- return;
-
- get_data();
-
- mogltk::FixedFont->setcolor(WHITE);
- mogltk::FixedFont->putcursor(GetAX() - shift * 6, GetAY());
-
- max_o = min(h->GetSize(), offset + nlines * width);
-
- for (i = start_o = offset, j = 0, l = 0; i < max_o; i++) {
- if ((j % width) == 0) {
- mogltk::FixedFont->printf("%08X ", i + virtual_base);
- }
- mogltk::FixedFont->printf("%02X ", data[j]);
- j++;
- if ((j % width) == 0) {
- for (k = start_o, c = 0; k < start_o + width; k++, c++) {
- mogltk::FixedFont->putcursor(GetAX() + (c + width * 3 + 14 - shift) * 6, GetAY() + l * 13);
- if (data[j - width + c] >= 0x20)
- // Have better font support here...
- mogltk::FixedFont->putentry(data[j - width + c] - 0x20);
- }
- l++;
- mogltk::FixedFont->putcursor(GetAX() - shift * 6, GetAY() + l * 13);
- start_o = i;
- }
- }
- }
- protected:
- virtual void resize_notify() {
- nlines = Father()->GetH() / 13;
- resize(Father()->GetW(), Father()->GetH());
- }
- private:
- Handle * h;
- int width, offset, nlines;
- int offset_loaded, size_loaded, virtual_base;
- int shift;
- Uint8 * data;
-};
-
-class frame : public mogltk::widget {
- public:
- frame(mogltk::shape * sh, mogltk::widget * father) :
- widget(father, 2, 2, father->GetW() - 4, father->GetH() - 4, 0, "MyFrame", sh) { }
- protected:
- virtual void draw() {
- }
- virtual mogltk::rect GetDrawRect() {
- mogltk::rect r;
-
- r.x = GetX() + 2;
- r.y = GetY() + 2;
- r.w = GetW() - 4;
- r.h = GetH() - 4;
-
- return r;
- }
- virtual bool process_event(int mx, int my, mogltk::event_t event) {
- mx -= GetAX();
- my -= GetAY();
- return false;
- }
- virtual void resize_notify() {
- resize(Father()->GetW() - 4, Father()->GetH() - 4);
- }
-};
-
-class timer : public mogltk::widget {
- public:
- timer() :
- widget(Application->Root, 0, 0, 0, 0, 0, "Timer", 0), tick(0)
- { set_timed_event(100); }
- protected:
- virtual bool process_event(int, int, mogltk::event_t event) {
- if (event == mogltk::E_TIMER) {
- set_timed_event(100);
- tick = (tick + 1) % 4;
- switch (tick) {
- case 0:
- Application->MainMenu->SetCaption(0, "/");
- break;
- case 1:
- Application->MainMenu->SetCaption(0, "-");
- break;
- case 2:
- Application->MainMenu->SetCaption(0, "\\");
- break;
- case 3:
- Application->MainMenu->SetCaption(0, "I");
- break;
- }
- Application->MainMenu->SetCaption(3, String("FPS: ") + mogltk::engine::FPS());
- return true;
- }
- return false;
- }
- private:
- int tick;
-};
-
-class quit : public mogltk::widgets::action {
- public:
- virtual void do_action(mogltk::widget * w) {
- mogltk::engine::quit();
- }
-} action_quit;
-
-class about : public mogltk::widgets::action {
- public:
- virtual void do_action(mogltk::widget * w) {
- new mogltk::widgets::MsgBox(w->Shaper(), w->Father(), "About...",
- "Dalos version 0.1 - OpenGL version\n"
- "Copyright (C) 2004 Nicolas \"Pixel\" Noble\n"
- "\n"
- "Thanks and greetings fly to (no particular order)\n"
- "GreatSkaori, Orphis, Ti Dragon, Yaz0r, S-O-R,\n"
- "Meradrin, SkeuD, Moogle, InVerse, LavosSpawn\n"
- "\n"
- "And to all I forgot!\n"
- );
- }
-} about_dialog;
-
-virtual int startup() throw (GeneralException) {
- verbosity = M_INFO;
- try {
- new Archive(argv[0], ARCHIVE_EXECUTABLE);
- }
- catch (...) {
- new Archive("Dalos.paq");
- }
-
- mogltk::widgets::ContextMenu * c;
- mogltk::base * gl = new mogltk::glbase();
- mogltk::shape * sh = new mogltk::glshape();
-
- SDL_EnableKeyRepeat(250, 40);
-
- mogltk::engine::setcursorvisible(true);
- mogltk::engine::setappactive(true);
-
- Root = new mogltk::widgets::Root(sh);
- MainPanel = Root->InnerPanel();
- MainMenu = new mogltk::widgets::Menu(sh, MainPanel);
- Frame = new frame(sh, new mogltk::widgets::Frame(sh, MainPanel, 0, MainMenu->GetH(), Root->GetW() - 1, Root->GetH() - MainMenu->GetH() - 1));
-
- mogltk::widget * box = new mogltk::widgets::SmartBox(sh, MainPanel, 50, 50, 500, 400, "Hexview");
- (new hexview(sh, box->InnerPanel()))->bind_handle(new Input(argv[0]));
-
- CurrentConsole = new console(sh, Root, 0, 8);
- CurrentConsole->move(0, Root->GetH() - CurrentConsole->GetH());
- CurrentConsole->add_line("Dalos v0.1 - LUA console");
-
- printer = new myprinter();
- locker = new threaded_locker();
-
- start_lua();
-
- // Filling menu.
- MainMenu->addnode("/", 0);
-
- c = MainMenu->createsub("File");
- c->addnode("Quit", &action_quit);
-
- c = MainMenu->createsub("Help");
- c->addnode("About", &about_dialog);
-
- MainMenu->addnode("FPS:", 0);
-
- new timer();
-
- // Setting up the key event handlers
- new hexview_keyevent;
- new console_keyevent; // Should be one of the last
-
- // And launching the main loop
- Root->mainloop();
-
- // Should cleanup here... nevermind ;)
-
- return 0;
-}
-
-CODE_ENDS
+int main(void) { return 0; }
diff --git a/MegamanX5/unarc.cpp b/MegamanX5/unarc.cpp index ea5e498..098af51 100644 --- a/MegamanX5/unarc.cpp +++ b/MegamanX5/unarc.cpp @@ -1,40 +1,40 @@ -#include <stdlib.h> -#include "generic.h" -#include "Input.h" -#include "Output.h" -#include "Main.h" - -CODE_BEGINS -virtual int startup() throw (GeneralException) { - Handle * f, * o; - - int i = 0; - - f = new Input(argv[1]); - - int offset = 0; - while (1) { - int sector, size; - f->seek(offset, SEEK_SET); - f->read(§or, 4); - f->read(&size, 4); - offset += 8; - - if (!sector) - break; - - f->seek(sector <<= 9, SEEK_SET); - - String fname; - fname.set("unarc-%03i.out", i); - o = new Output(fname); - copy(f, o, size); - delete o; - i++; - } - - delete f; - - return -1; -} -CODE_ENDS +#include <stdlib.h>
+#include "generic.h"
+#include "Input.h"
+#include "Output.h"
+#include "Main.h"
+
+CODE_BEGINS
+virtual int startup() throw (GeneralException) {
+ Handle * f, * o;
+
+ int i = 0;
+
+ f = new Input(argv[1]);
+
+ int offset = 0;
+ while (1) {
+ int sector, size;
+ f->seek(offset, SEEK_SET);
+ f->read(§or, 4);
+ f->read(&size, 4);
+ offset += 8;
+
+ if (!sector)
+ break;
+
+ f->seek(sector <<= 9, SEEK_SET);
+
+ String fname;
+ fname.set("unarc-%03i.out", i);
+ o = new Output(fname);
+ copy(f, o, size);
+ delete o;
+ i++;
+ }
+
+ delete f;
+
+ return -1;
+}
+CODE_ENDS
diff --git a/PE/extract-rooms.cpp b/PE/extract-rooms.cpp index a23026f..f2e2e31 100644 --- a/PE/extract-rooms.cpp +++ b/PE/extract-rooms.cpp @@ -1,142 +1,142 @@ -#include "Main.h" -#include "Input.h" -#include "Output.h" -#include "table.h" - -struct tentry { - int sector; - unsigned char u[4]; -}; - -struct entry { - int sector; - int sizes[3]; -}; - -#define fullsize 206213120 -#define offset 0x83b78 -#define N 438 - -CODE_BEGINS -struct entry tab[N]; - -virtual int startup() throw (GeneralException) { - int i, j, s, dcount = 1; - Input * f; - Output * t; - int alreadycounted = 0; - String fn; - char buff[2048]; - unsigned char b, a1, a2; - struct tentry te; - unsigned long orig, pos, truesize, ptr, sig, size; - int found, empty; - - verbosity = M_INFO; - - f = new Input("slus_006.62"); - f->seek(offset); - - for (i = 0; i < N; i++) { - f->read(&te, sizeof(struct tentry)); - tab[i].sector = te.sector; - tab[i].sizes[0] = te.u[0]; - tab[i].sizes[1] = te.u[1] | ((te.u[2] & 0xf) << 8); - tab[i].sizes[2] = (te.u[2] >> 4) | (te.u[3] << 4); - printm(M_INFO, "entry %3i - offset: %9i, sizes = %4i %4i %4i (%02x %02x %02x %02x)\n", i, tab[i].sector * 2048, - tab[i].sizes[0], tab[i].sizes[1], tab[i].sizes[2], te.u[0], te.u[1], te.u[2], te.u[3]); - } - - delete f; - - f = new Input("pe.img"); - - for (i = 0; i < N; i++) { - printm(M_INFO, "Dumping room %i\n", i + 1); - - if (!tab[i].sizes[0]) - continue; - - f->seek(tab[i].sector * 2048); - for (j = 0; j < 3; j++) { - fn.set("rooms/room-%04i-%02i.out", i + 1, j); - - t = new Output(fn); - - for (s = 0; s < tab[i].sizes[j]; s++) { - f->read(buff, 2048); - t->write(buff, 2048); - } - delete t; - } - } - - for (i = 0; i < N; i++) { - printm(M_INFO, "Dumping script %i\n", i + 1); - - found = empty = 0; - - if (!tab[i].sizes[0]) - continue; - - f->seek((tab[i].sector + tab[i].sizes[0] + tab[i].sizes[1]) * 2048); - orig = f->tell(); - - fn.set("scripts/room-%04i.txt", i); - t = new Output(fn); - -#if 0 - f->read(&truesize, 4); - f->seek(truesize - 4, SEEK_CUR); - - while (!found) { - f->read(&ptr, 4); - f->seek(-8, SEEK_CUR); - pos = f->tell(); - if ((ptr >> 24) == 1) { - ptr &= 0x00ffffff; - f->seek(orig + ptr); - f->read(&sig, 4); - if ((sig & 0xffff) == 0xfe) { - f->seek(pos); - f->read(&size, 4); - pos = ptr + orig; - found = 1; - } else if (sig != 0x4f414b41) { /* AKAO */ - delete t; - empty = 1; - break; - } - } - f->seek(pos); - } - - if (empty) - continue; -#else - truesize = f->readU32(); - ptr = f->readU32(); - f->seek(orig + ptr + 32, SEEK_SET); - ptr = f->readU32(); - - if (!(ptr & 0xfff00000)) - continue; - - f->seek(orig + (ptr & 0xfffff) + 8); - size = f->readU32(); - ptr = f->readU32(); - pos = orig + (ptr & 0xfffff); - f->seek(pos); -#endif - - printm(M_INFO, "Found %i bytes of text at %i\n", size, pos); - - extracttext(f, t, size); - - delete t; - } - - delete f; - return 0; -} -CODE_ENDS +#include "Main.h"
+#include "Input.h"
+#include "Output.h"
+#include "table.h"
+
+struct tentry {
+ int sector;
+ unsigned char u[4];
+};
+
+struct entry {
+ int sector;
+ int sizes[3];
+};
+
+#define fullsize 206213120
+#define offset 0x83b78
+#define N 438
+
+CODE_BEGINS
+struct entry tab[N];
+
+virtual int startup() throw (GeneralException) {
+ int i, j, s, dcount = 1;
+ Input * f;
+ Output * t;
+ int alreadycounted = 0;
+ String fn;
+ char buff[2048];
+ unsigned char b, a1, a2;
+ struct tentry te;
+ unsigned long orig, pos, truesize, ptr, sig, size;
+ int found, empty;
+
+ verbosity = M_INFO;
+
+ f = new Input("slus_006.62");
+ f->seek(offset);
+
+ for (i = 0; i < N; i++) {
+ f->read(&te, sizeof(struct tentry));
+ tab[i].sector = te.sector;
+ tab[i].sizes[0] = te.u[0];
+ tab[i].sizes[1] = te.u[1] | ((te.u[2] & 0xf) << 8);
+ tab[i].sizes[2] = (te.u[2] >> 4) | (te.u[3] << 4);
+ printm(M_INFO, "entry %3i - offset: %9i, sizes = %4i %4i %4i (%02x %02x %02x %02x)\n", i, tab[i].sector * 2048,
+ tab[i].sizes[0], tab[i].sizes[1], tab[i].sizes[2], te.u[0], te.u[1], te.u[2], te.u[3]);
+ }
+
+ delete f;
+
+ f = new Input("pe.img");
+
+ for (i = 0; i < N; i++) {
+ printm(M_INFO, "Dumping room %i\n", i + 1);
+
+ if (!tab[i].sizes[0])
+ continue;
+
+ f->seek(tab[i].sector * 2048);
+ for (j = 0; j < 3; j++) {
+ fn.set("rooms/room-%04i-%02i.out", i + 1, j);
+
+ t = new Output(fn);
+
+ for (s = 0; s < tab[i].sizes[j]; s++) {
+ f->read(buff, 2048);
+ t->write(buff, 2048);
+ }
+ delete t;
+ }
+ }
+
+ for (i = 0; i < N; i++) {
+ printm(M_INFO, "Dumping script %i\n", i + 1);
+
+ found = empty = 0;
+
+ if (!tab[i].sizes[0])
+ continue;
+
+ f->seek((tab[i].sector + tab[i].sizes[0] + tab[i].sizes[1]) * 2048);
+ orig = f->tell();
+
+ fn.set("scripts/room-%04i.txt", i);
+ t = new Output(fn);
+
+#if 0
+ f->read(&truesize, 4);
+ f->seek(truesize - 4, SEEK_CUR);
+
+ while (!found) {
+ f->read(&ptr, 4);
+ f->seek(-8, SEEK_CUR);
+ pos = f->tell();
+ if ((ptr >> 24) == 1) {
+ ptr &= 0x00ffffff;
+ f->seek(orig + ptr);
+ f->read(&sig, 4);
+ if ((sig & 0xffff) == 0xfe) {
+ f->seek(pos);
+ f->read(&size, 4);
+ pos = ptr + orig;
+ found = 1;
+ } else if (sig != 0x4f414b41) { /* AKAO */
+ delete t;
+ empty = 1;
+ break;
+ }
+ }
+ f->seek(pos);
+ }
+
+ if (empty)
+ continue;
+#else
+ truesize = f->readU32();
+ ptr = f->readU32();
+ f->seek(orig + ptr + 32, SEEK_SET);
+ ptr = f->readU32();
+
+ if (!(ptr & 0xfff00000))
+ continue;
+
+ f->seek(orig + (ptr & 0xfffff) + 8);
+ size = f->readU32();
+ ptr = f->readU32();
+ pos = orig + (ptr & 0xfffff);
+ f->seek(pos);
+#endif
+
+ printm(M_INFO, "Found %i bytes of text at %i\n", size, pos);
+
+ extracttext(f, t, size);
+
+ delete t;
+ }
+
+ delete f;
+ return 0;
+}
+CODE_ENDS
diff --git a/PE/extract-various.cpp b/PE/extract-various.cpp index 6f02fba..cd0d8e1 100644 --- a/PE/extract-various.cpp +++ b/PE/extract-various.cpp @@ -1,165 +1,165 @@ -#include <Main.h> -#include <Input.h> -#include <Output.h> -#include "table.h" - -CODE_BEGINS -int pos[50]; - -virtual int startup() throw (GeneralException) { - Input * f = new Input("dump/0000.out"); - Output * s = new Output("various/various.txt"); - unsigned int c, b, i, j, size, changed; - unsigned short p, t; - String fn; - - verbosity = M_INFO; - - for (c = 0; c < 6;) { - b = f->readU8(); - if (b <= MAXCHAR) { - s->writeU8(table[b]); - } else { - switch(b) { - case 0xfe: - b = f->readU8(); - (*s) << "<PT" << b << ">\n"; - break; - case 0xff: - (*s) << "\n<CLOSE>\n"; - c++; - break; - default: - (*s) << String().set("<UNK %02X>", b); - } - } - } - - delete f; - delete s; - - f = new Input("dump/0001.out"); - - c = f->readU32(); - - for (i = 0; i < c; i++) { - pos[i] = f->readU32(); - } - pos[c] = f->GetSize(); - - for (i = 0; i < c; i++) { - f->seek(pos[i]); - size = pos[i + 1] - pos[i]; - fn.set("various/0001/%02i.out", i); - s = new Output(fn); - for (j = 0; j < size; j++) { - b = f->readU8(); - s->writeU8(b); - } - delete s; - } - - delete f; - - - f = new Input("various/0001/00.out"); - - c = f->readU32(); - - for (i = 0; i < c; i++) { - pos[i] = f->readU32(); - } - pos[c] = f->GetSize(); - - for (i = 0; i < c; i++) { - f->seek(pos[i]); - size = pos[i + 1] - pos[i]; - fn.set("various/0001/00/%01i.out", i); - s = new Output(fn); - for (j = 0; j < size; j++) { - b = f->readU8(); - s->writeU8(b); - } - delete s; - } - - delete f; - - for (i = 0; i < 4; i++) { - fn.set("various/0001/00/%i.out", i); - f = new Input(fn); - fn.set("various/menus%i.txt", i); - s = new Output(fn); - - p = f->readU16(); - f->seek(p * 2, SEEK_CUR); - (*s) << "<NBPTS " << p << ">\n"; - - changed = 1; - - for (c = 0; c < p;) { - if (changed) { - f->seek(c * 2 + 2); - t = f->readU16(); - f->seek(t); - } - if (!(b = f->readU8()) && changed) - break; - - changed = 0; - - if (b <= MAXCHAR) { - s->writeU8(table[b]); - } else { - switch(b) { - case 0xff: - (*s) << "\n<CLOSE>\n"; - c++; - changed = 1; - break; - default: - (*s) << String().set("<UNK %02X>", b); - } - } - } - - delete f; - delete s; - } - - f = new Input("dump/0075.out"); - - for (i = 0; i < 4; i++) { - Uint32 pos, pos2, size; - - f->seek(i * 4); - pos = f->readU32(); - pos2 = f->readU32(); - f->seek(pos); - - if (i == 3) { - size = f->readU32(); - f->seek(pos); - } else { - size = pos2 - pos; - } - - s = new Output(String().set("75/%i.out", i)); - - copy(f, s, size); - - delete s; - - if (i == 1) { - s = new Output("75/text.txt"); - f->seek(pos); - extracttext(f, s, size); - delete s; - } - } - - delete f; - - return 0; -} -CODE_ENDS +#include <Main.h>
+#include <Input.h>
+#include <Output.h>
+#include "table.h"
+
+CODE_BEGINS
+int pos[50];
+
+virtual int startup() throw (GeneralException) {
+ Input * f = new Input("dump/0000.out");
+ Output * s = new Output("various/various.txt");
+ unsigned int c, b, i, j, size, changed;
+ unsigned short p, t;
+ String fn;
+
+ verbosity = M_INFO;
+
+ for (c = 0; c < 6;) {
+ b = f->readU8();
+ if (b <= MAXCHAR) {
+ s->writeU8(table[b]);
+ } else {
+ switch(b) {
+ case 0xfe:
+ b = f->readU8();
+ (*s) << "<PT" << b << ">\n";
+ break;
+ case 0xff:
+ (*s) << "\n<CLOSE>\n";
+ c++;
+ break;
+ default:
+ (*s) << String().set("<UNK %02X>", b);
+ }
+ }
+ }
+
+ delete f;
+ delete s;
+
+ f = new Input("dump/0001.out");
+
+ c = f->readU32();
+
+ for (i = 0; i < c; i++) {
+ pos[i] = f->readU32();
+ }
+ pos[c] = f->GetSize();
+
+ for (i = 0; i < c; i++) {
+ f->seek(pos[i]);
+ size = pos[i + 1] - pos[i];
+ fn.set("various/0001/%02i.out", i);
+ s = new Output(fn);
+ for (j = 0; j < size; j++) {
+ b = f->readU8();
+ s->writeU8(b);
+ }
+ delete s;
+ }
+
+ delete f;
+
+
+ f = new Input("various/0001/00.out");
+
+ c = f->readU32();
+
+ for (i = 0; i < c; i++) {
+ pos[i] = f->readU32();
+ }
+ pos[c] = f->GetSize();
+
+ for (i = 0; i < c; i++) {
+ f->seek(pos[i]);
+ size = pos[i + 1] - pos[i];
+ fn.set("various/0001/00/%01i.out", i);
+ s = new Output(fn);
+ for (j = 0; j < size; j++) {
+ b = f->readU8();
+ s->writeU8(b);
+ }
+ delete s;
+ }
+
+ delete f;
+
+ for (i = 0; i < 4; i++) {
+ fn.set("various/0001/00/%i.out", i);
+ f = new Input(fn);
+ fn.set("various/menus%i.txt", i);
+ s = new Output(fn);
+
+ p = f->readU16();
+ f->seek(p * 2, SEEK_CUR);
+ (*s) << "<NBPTS " << p << ">\n";
+
+ changed = 1;
+
+ for (c = 0; c < p;) {
+ if (changed) {
+ f->seek(c * 2 + 2);
+ t = f->readU16();
+ f->seek(t);
+ }
+ if (!(b = f->readU8()) && changed)
+ break;
+
+ changed = 0;
+
+ if (b <= MAXCHAR) {
+ s->writeU8(table[b]);
+ } else {
+ switch(b) {
+ case 0xff:
+ (*s) << "\n<CLOSE>\n";
+ c++;
+ changed = 1;
+ break;
+ default:
+ (*s) << String().set("<UNK %02X>", b);
+ }
+ }
+ }
+
+ delete f;
+ delete s;
+ }
+
+ f = new Input("dump/0075.out");
+
+ for (i = 0; i < 4; i++) {
+ Uint32 pos, pos2, size;
+
+ f->seek(i * 4);
+ pos = f->readU32();
+ pos2 = f->readU32();
+ f->seek(pos);
+
+ if (i == 3) {
+ size = f->readU32();
+ f->seek(pos);
+ } else {
+ size = pos2 - pos;
+ }
+
+ s = new Output(String().set("75/%i.out", i));
+
+ copy(f, s, size);
+
+ delete s;
+
+ if (i == 1) {
+ s = new Output("75/text.txt");
+ f->seek(pos);
+ extracttext(f, s, size);
+ delete s;
+ }
+ }
+
+ delete f;
+
+ return 0;
+}
+CODE_ENDS
diff --git a/PE/extract.cpp b/PE/extract.cpp index 4fa8b2f..4418fb9 100644 --- a/PE/extract.cpp +++ b/PE/extract.cpp @@ -1,83 +1,83 @@ -#include <Main.h> -#include <Input.h> -#include <Output.h> - -#define INDEX 0x838da - -#define N1 100 -#define N2 600 - -CODE_BEGINS -int index1[N1]; -int index2[N2]; - -virtual int startup() throw (GeneralException) { - Input * s; - Output * f; - short int t, b; - int n1 = 0, n2 = 0, i, j, size; - String fn; - char buff[2048]; - - verbosity = M_INFO; - - s = new Input("slus_006.62"); - - s->seek(INDEX); - - while (1) { - t = s->readU16(); - if (!t) - break; - index1[n1++] = t; - printm(M_INFO, "I1 - %3i - %4i\n", n1, t); - } - - b = index1[n1 - 1]; - - s->seek(6, SEEK_CUR); - - while (1) { - s->read(&t, 2); - if (!t) - break; - index2[n2++] = t + b; - printm(M_INFO, "I2 - %3i - %4i\n", n2, t); - } - - delete s; - - s = new Input("pe.img"); - - for (i = 0; i < (n1 - 1); i++) { - fn.set("dump/%04i.out", i); - if (!(index1[i + 1] - index1[i])) - continue; - f = new Output(fn); - printm(M_INFO, "Dumping %3i sectors at %4i (%8i) into " + fn + "\n", index1[i + 1] - index1[i], index1[i], index1[i] * 2048); - s->seek(index1[i] * 2048); - for (j = index1[i]; j < index1[i + 1]; j++) { - s->read(buff, 2048); - f->write(buff, 2048); - } - delete f; - } - - for (i = 0; i < (n2 - 1); i++) { - fn.set("musics/song-%04i.out", i); - if (!(index2[i + 1] - index2[i])) - continue; - f = new Output(fn); - printm(M_INFO, "Music - Dumping %3i sectors at %4i into " + fn + "\n", index2[i + 1] - index2[i], index2[i]); - s->seek(index2[i] * 2048); - for (j = index2[i]; j < index2[i + 1]; j++) { - s->read(buff, 2048); - f->write(buff, 2048); - } - delete f; - } - delete s; - - return 0; -} -CODE_ENDS +#include <Main.h>
+#include <Input.h>
+#include <Output.h>
+
+#define INDEX 0x838da
+
+#define N1 100
+#define N2 600
+
+CODE_BEGINS
+int index1[N1];
+int index2[N2];
+
+virtual int startup() throw (GeneralException) {
+ Input * s;
+ Output * f;
+ short int t, b;
+ int n1 = 0, n2 = 0, i, j, size;
+ String fn;
+ char buff[2048];
+
+ verbosity = M_INFO;
+
+ s = new Input("slus_006.62");
+
+ s->seek(INDEX);
+
+ while (1) {
+ t = s->readU16();
+ if (!t)
+ break;
+ index1[n1++] = t;
+ printm(M_INFO, "I1 - %3i - %4i\n", n1, t);
+ }
+
+ b = index1[n1 - 1];
+
+ s->seek(6, SEEK_CUR);
+
+ while (1) {
+ s->read(&t, 2);
+ if (!t)
+ break;
+ index2[n2++] = t + b;
+ printm(M_INFO, "I2 - %3i - %4i\n", n2, t);
+ }
+
+ delete s;
+
+ s = new Input("pe.img");
+
+ for (i = 0; i < (n1 - 1); i++) {
+ fn.set("dump/%04i.out", i);
+ if (!(index1[i + 1] - index1[i]))
+ continue;
+ f = new Output(fn);
+ printm(M_INFO, "Dumping %3i sectors at %4i (%8i) into " + fn + "\n", index1[i + 1] - index1[i], index1[i], index1[i] * 2048);
+ s->seek(index1[i] * 2048);
+ for (j = index1[i]; j < index1[i + 1]; j++) {
+ s->read(buff, 2048);
+ f->write(buff, 2048);
+ }
+ delete f;
+ }
+
+ for (i = 0; i < (n2 - 1); i++) {
+ fn.set("musics/song-%04i.out", i);
+ if (!(index2[i + 1] - index2[i]))
+ continue;
+ f = new Output(fn);
+ printm(M_INFO, "Music - Dumping %3i sectors at %4i into " + fn + "\n", index2[i + 1] - index2[i], index2[i]);
+ s->seek(index2[i] * 2048);
+ for (j = index2[i]; j < index2[i + 1]; j++) {
+ s->read(buff, 2048);
+ f->write(buff, 2048);
+ }
+ delete f;
+ }
+ delete s;
+
+ return 0;
+}
+CODE_ENDS
diff --git a/PE/pepatch.cpp b/PE/pepatch.cpp index 80e6154..18e11dd 100644 --- a/PE/pepatch.cpp +++ b/PE/pepatch.cpp @@ -24,23 +24,23 @@ virtual int startup() throw (GeneralException) { DialogBox(0, MAKEINTRESOURCE(IDD_ABOUT),
GetActiveWindow(), 0);
-// ShowWindow(CreateDialog(0, MAKEINTRESOURCE(IDD_ABOUT), GetActiveWindow(), AboutDlgProc), SW_SHOWDEFAULT); +// ShowWindow(CreateDialog(0, MAKEINTRESOURCE(IDD_ABOUT), GetActiveWindow(), AboutDlgProc), SW_SHOWDEFAULT);
bmp = LoadBitmap(0, MAKEINTRESOURCE(IDB_AYA));
do {
if (!ReadFile(bmp, buffer, 2048, &readed, 0)) {
- DWORD dwErrCode = GetLastError(); - LPVOID lpMsgBuf; - if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpMsgBuf, 0, NULL )) - throw GeneralException("Gave up on reading CD: unknown error"); - String errmsg = (LPCTSTR) lpMsgBuf; - LocalFree(lpMsgBuf); - throw GeneralException("Got error " + errmsg); + DWORD dwErrCode = GetLastError();
+ LPVOID lpMsgBuf;
+ if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPTSTR) &lpMsgBuf, 0, NULL ))
+ throw GeneralException("Gave up on reading CD: unknown error");
+ String errmsg = (LPCTSTR) lpMsgBuf;
+ LocalFree(lpMsgBuf);
+ throw GeneralException("Got error " + errmsg);
}
printm(M_INFO, "Read %i bytes\n", readed);
out->write(buffer, readed);
diff --git a/PE/rebuildmenus.cpp b/PE/rebuildmenus.cpp index 681e909..bfbda61 100644 --- a/PE/rebuildmenus.cpp +++ b/PE/rebuildmenus.cpp @@ -1,76 +1,76 @@ -#include <Main.h> -#include <Input.h> -#include <Output.h> - -CODE_BEGINS -virtual int startup(void) throw (GeneralException) { - int i, j, p, s; - Handle * inter = new Output("concat.out"); - Handle * f, * out; - String fname; - - inter->writeU32(4); - - for (i = 0; i < 4; i++) { - inter->writeU32(0); - } - - for (i = 0; i < 4; i++) { - fname = "menus" + String(i) + ".out"; - f = new Input(fname); - s = f->GetSize(); - - p = inter->tell(); - - inter->seek(i * 4 + 4); - inter->writeU32(p); - inter->seek(0, SEEK_END); - - copy(f, inter); - - s &= 3; - - if (s) { - s = 4 - s; - for (j = 0; j < s; j++) - inter->writeU8(0); - } - - delete f; - } - - delete inter; - - out = new Output("menus.bin"); - out->writeU32(11); - - for (i = 0; i < 11; i++) { - out->writeU32(0); - } - - for (i = 0; i < 11; i++) { - if (i == 0) { - fname = "concat.out"; - } else if (i < 10) { - fname = "../../various/0001/0" + String(i) + ".out"; - } else { - fname = "../../various/0001/10.out"; - } - f = new Input(fname); - - p = out->tell(); - - out->seek(i * 4 + 4); - out->writeU32(p); - out->seek(0, SEEK_END); - - copy(f, out); - - delete f; - } - - delete out; - - return 0; -} -CODE_ENDS +#include <Main.h>
+#include <Input.h>
+#include <Output.h>
+
+CODE_BEGINS
+virtual int startup(void) throw (GeneralException) {
+ int i, j, p, s;
+ Handle * inter = new Output("concat.out");
+ Handle * f, * out;
+ String fname;
+
+ inter->writeU32(4);
+
+ for (i = 0; i < 4; i++) {
+ inter->writeU32(0);
+ }
+
+ for (i = 0; i < 4; i++) {
+ fname = "menus" + String(i) + ".out";
+ f = new Input(fname);
+ s = f->GetSize();
+
+ p = inter->tell();
+
+ inter->seek(i * 4 + 4);
+ inter->writeU32(p);
+ inter->seek(0, SEEK_END);
+
+ copy(f, inter);
+
+ s &= 3;
+
+ if (s) {
+ s = 4 - s;
+ for (j = 0; j < s; j++)
+ inter->writeU8(0);
+ }
+
+ delete f;
+ }
+
+ delete inter;
+
+ out = new Output("menus.bin");
+ out->writeU32(11);
+
+ for (i = 0; i < 11; i++) {
+ out->writeU32(0);
+ }
+
+ for (i = 0; i < 11; i++) {
+ if (i == 0) {
+ fname = "concat.out";
+ } else if (i < 10) {
+ fname = "../../various/0001/0" + String(i) + ".out";
+ } else {
+ fname = "../../various/0001/10.out";
+ }
+ f = new Input(fname);
+
+ p = out->tell();
+
+ out->seek(i * 4 + 4);
+ out->writeU32(p);
+ out->seek(0, SEEK_END);
+
+ copy(f, out);
+
+ delete f;
+ }
+
+ delete out;
+
+ return 0;
+}
+CODE_ENDS
diff --git a/PE/reinsert.cpp b/PE/reinsert.cpp index 28b7c75..1ad4441 100644 --- a/PE/reinsert.cpp +++ b/PE/reinsert.cpp @@ -1,16 +1,16 @@ -#include <Exceptions.h> -#include <Input.h> -#include <Output.h> -#include <Main.h> -#include "cdutils.h" - -#include "reinsert-res.h" -#include <windowsx.h> - -#define index 0x838da - -#define offset 0x83b78 - +#include <Exceptions.h>
+#include <Input.h>
+#include <Output.h>
+#include <Main.h>
+#include "cdutils.h"
+
+#include "reinsert-res.h"
+#include <windowsx.h>
+
+#define index 0x838da
+
+#define offset 0x83b78
+
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
Base::printm(M_STATUS, "AboutDlgProc: uMsg = %i (0x%x)\n", uMsg, uMsg);
switch (uMsg) {
@@ -56,189 +56,189 @@ void UpdateProgress(HWND Dlg, float percent) { InvalidateRect(ctrl, NULL, TRUE);
UpdateWindow(Dlg);
}
- -CODE_BEGINS -HWND Dlg; - -virtual int startup() throw (GeneralException) { - Handle * ir; - Handle * iw; - cdutils * cd; - -// new Archive(*argv, ARCHIVE_EXECUTABLE); - - verbosity = M_INFO; - - ShowWindow(Dlg = CreateDialog(0, MAKEINTRESOURCE(IDD_ABOUT), GetActiveWindow(), AboutDlgProc), SW_SHOWDEFAULT); - UpdateProgress(Dlg, 0); - - ir = new Input("PE1.bin"); - iw = new Output("PE1.bin", 0, 0); - cd = new cdutils(ir, iw); - - printm(M_INFO, "Patch du CD1\n"); - patch_img(cd); - - delete cd; - delete iw; - delete ir; - - return 0; - - ir = new Input("PE2.bin"); - iw = new Output("PE2.bin", 0, 0); - cd = new cdutils(ir, iw); - printm(M_INFO, "Patch du CD2\n"); - patch_img(cd); - - delete cd; - delete iw; - delete ir; -} - -int patch_img(cdutils * cd) { - struct cdutils::DirEntry d_slus, d_pe1; - unsigned char * slus; - int i, c; - String s; - int groupes[100][20]; - int counts[20]; - - verbosity = M_STATUS; - - d_slus = cd->find_path("/SLUS_006.62;1"); - - if (!d_slus.Sector) - d_slus = cd->find_path("/SLUS_006.68;1"); - - d_pe1 = cd->find_path("/PE.IMG;1"); - - slus = (unsigned char *) malloc(d_slus.Size); - - cd->read_datas(slus, GUESS, d_slus.Sector, d_slus.Size); - - int fontei = *((short *)(slus + index + 9 * 2)); - Handle * fonte = new Input("fonte.tim"); - printm(M_INFO, "Ecriture de la fonte...\n"); - cd->write_file(fonte, GUESS, fontei + d_pe1.Sector); - delete fonte; - - Handle * pslus = new Input("PE-SLUS00662-patched.exe"); - printm(M_INFO, "Ecriture du SLUS...\n"); - cd->write_file(pslus, GUESS, d_slus.Sector); - delete pslus; - - int menui = *((short *)(slus + index + 69 * 2)); - Handle * menu = new Input("69/0069.out"); - printm(M_INFO, "Ecriture du menu...\n"); - cd->write_file(menu, GUESS, menui + d_pe1.Sector); - delete menu; - - int mapi = *((short *)(slus + index + 71 * 2)); - int smap = *((short *)(slus + index + 72 * 2)) - mapi; - smap *= 2048; - Byte * map = (Byte *) malloc(smap); - printm(M_INFO, "Ecriture de la carte...\n"); - cd->read_datas(map, GUESS, mapi + d_pe1.Sector, smap); - fonte = new Input("fonte.tim"); - fonte->read(map + 8, fonte->GetSize()); - delete fonte; - cd->write_datas(map, GUESS, mapi + d_pe1.Sector, smap); - free(map); - -#if 1 - int jour1i = *((short *)(slus + index + 75 * 2)); - int sjour1 = *((short *)(slus + index + 76 * 2)) - jour1i; - sjour1 *= 2048; - Byte * jour1 = (Byte *) malloc(sjour1); - printm(M_INFO, "Ecriture de la fin du jour 1...\n"); - cd->read_datas(jour1, GUESS, jour1i + d_pe1.Sector, sjour1); - Handle * jour1text = new Input("scripts/c/map.out"); - int sjour1text = jour1text->GetSize(); - if (sjour1text & 3) sjour1text = (sjour1text & (~3)) + 4; - int pjour1text = *((Uint32 *)(jour1 + 8)) - sjour1text; - if (pjour1text < 0) throw GeneralException("Texte trop grand!\n"); - *((Uint32 *)(jour1 + 4)) = pjour1text; - jour1text->read(jour1 + pjour1text, jour1text->GetSize()); - delete jour1text; - cd->write_datas(jour1, GUESS, jour1i + d_pe1.Sector, sjour1); - free(jour1); -#else - int jour1i = *((short *)(slus + index + 75 * 2)); - Handle * jour1 = new Input("75/0075.out"); - printm(M_INFO, "Ecriture de la fin du jour 1...\n"); - cd->write_file(jour1, GUESS, jour1i + d_pe1.Sector); - delete jour1; -#endif - - for (i = 1; i <= 20; i++) { - Input groupe(String().set("groupe-%02i.txt", i)); - c = 0; - while (1) { - groupe >> s; - if (!s.strlen()) - break; - groupes[c++][i] = s.to_int(); - } - counts[i] = c; - } - - for (i = 1; i <= 20; i++) { - Handle * f = new Input(String().set("scripts/c/%02i.out", i)); - unsigned char * script = (unsigned char *) malloc(f->GetSize()); - f->read(script, f->GetSize()); - printm(M_INFO, "Groupe %i...\n", i); - for (c = 0; c < counts[i]; c++) { - UpdateProgress(Dlg, i * 5.0); - LaisserSouffler(Dlg); - int sector, s1, s2, s3, r, size, size2, sizes[2], tptr, uptr, aptr, asiz, maxsize; - r = groupes[c][i] - 1; - unsigned char * room; - - sector = *((int *) (slus + offset + r * 8)); - s1 = *(slus + offset + r * 8 + 4); - s2 = *(slus + offset + r * 8 + 5) | ((*(slus + offset + r * 8 + 6) & 0x0f) << 8); - s3 = ((*(slus + offset + r * 8 + 6) & 0xf0) >> 4) | (*(slus + offset + r * 8 + 7) << 4); - - cd->read_datas((unsigned char *) sizes, GUESS, d_pe1.Sector + sector + s1 + s2, 8); - size = sizes[0]; - size2 = sizes[1]; - - room = (unsigned char *) malloc(size); - cd->read_datas(room, GUESS, d_pe1.Sector + sector + s1 + s2, size); - - printm(M_INFO, " Room %i\n", r + 1); - - tptr = *((int *) (room + size2 + 32)) & 0xfffff; - uptr = *((int *) (room + tptr + 4)); - aptr = *((int *) (room + tptr + 12)) & 0xfffff; - asiz = *((int *) (room + tptr + 8)); - maxsize = aptr - uptr + (asiz | 3); -// printm(M_INFO, "size2 = 0x%08x\ntptr = 0x%08x\nuptr = 0x%08x\naptr = 0x%08x\nasiz = 0x%08x\nmaxsize = 0x%08x\nsize = 0x%08x\n", size2, tptr, uptr, aptr, asiz, maxsize, f->GetSize()); - if (f->GetSize() > maxsize) { - printm(M_WARNING, "Script trop grand (%i octets et %i libres)\n", f->GetSize(), maxsize); - free(room); - continue; - } - - uptr = (uptr + maxsize - f->GetSize()) & (~3); - - memcpy(room + uptr, script, f->GetSize()); - - *((int *) (room + tptr + 12)) = uptr | 0x01000000; - *((int *) (room + tptr + 8)) = f->GetSize(); - - cd->write_datas(room, GUESS, d_pe1.Sector + sector + s1 + s2, size); - - free(room); - } - delete f; - free(script); - } - - free(slus); - - return 0; -} - -CODE_ENDS +
+CODE_BEGINS
+HWND Dlg;
+
+virtual int startup() throw (GeneralException) {
+ Handle * ir;
+ Handle * iw;
+ cdutils * cd;
+
+// new Archive(*argv, ARCHIVE_EXECUTABLE);
+
+ verbosity = M_INFO;
+
+ ShowWindow(Dlg = CreateDialog(0, MAKEINTRESOURCE(IDD_ABOUT), GetActiveWindow(), AboutDlgProc), SW_SHOWDEFAULT);
+ UpdateProgress(Dlg, 0);
+
+ ir = new Input("PE1.bin");
+ iw = new Output("PE1.bin", 0, 0);
+ cd = new cdutils(ir, iw);
+
+ printm(M_INFO, "Patch du CD1\n");
+ patch_img(cd);
+
+ delete cd;
+ delete iw;
+ delete ir;
+
+ return 0;
+
+ ir = new Input("PE2.bin");
+ iw = new Output("PE2.bin", 0, 0);
+ cd = new cdutils(ir, iw);
+ printm(M_INFO, "Patch du CD2\n");
+ patch_img(cd);
+
+ delete cd;
+ delete iw;
+ delete ir;
+}
+
+int patch_img(cdutils * cd) {
+ struct cdutils::DirEntry d_slus, d_pe1;
+ unsigned char * slus;
+ int i, c;
+ String s;
+ int groupes[100][20];
+ int counts[20];
+
+ verbosity = M_STATUS;
+
+ d_slus = cd->find_path("/SLUS_006.62;1");
+
+ if (!d_slus.Sector)
+ d_slus = cd->find_path("/SLUS_006.68;1");
+
+ d_pe1 = cd->find_path("/PE.IMG;1");
+
+ slus = (unsigned char *) malloc(d_slus.Size);
+
+ cd->read_datas(slus, GUESS, d_slus.Sector, d_slus.Size);
+
+ int fontei = *((short *)(slus + index + 9 * 2));
+ Handle * fonte = new Input("fonte.tim");
+ printm(M_INFO, "Ecriture de la fonte...\n");
+ cd->write_file(fonte, GUESS, fontei + d_pe1.Sector);
+ delete fonte;
+
+ Handle * pslus = new Input("PE-SLUS00662-patched.exe");
+ printm(M_INFO, "Ecriture du SLUS...\n");
+ cd->write_file(pslus, GUESS, d_slus.Sector);
+ delete pslus;
+
+ int menui = *((short *)(slus + index + 69 * 2));
+ Handle * menu = new Input("69/0069.out");
+ printm(M_INFO, "Ecriture du menu...\n");
+ cd->write_file(menu, GUESS, menui + d_pe1.Sector);
+ delete menu;
+
+ int mapi = *((short *)(slus + index + 71 * 2));
+ int smap = *((short *)(slus + index + 72 * 2)) - mapi;
+ smap *= 2048;
+ Byte * map = (Byte *) malloc(smap);
+ printm(M_INFO, "Ecriture de la carte...\n");
+ cd->read_datas(map, GUESS, mapi + d_pe1.Sector, smap);
+ fonte = new Input("fonte.tim");
+ fonte->read(map + 8, fonte->GetSize());
+ delete fonte;
+ cd->write_datas(map, GUESS, mapi + d_pe1.Sector, smap);
+ free(map);
+
+#if 1
+ int jour1i = *((short *)(slus + index + 75 * 2));
+ int sjour1 = *((short *)(slus + index + 76 * 2)) - jour1i;
+ sjour1 *= 2048;
+ Byte * jour1 = (Byte *) malloc(sjour1);
+ printm(M_INFO, "Ecriture de la fin du jour 1...\n");
+ cd->read_datas(jour1, GUESS, jour1i + d_pe1.Sector, sjour1);
+ Handle * jour1text = new Input("scripts/c/map.out");
+ int sjour1text = jour1text->GetSize();
+ if (sjour1text & 3) sjour1text = (sjour1text & (~3)) + 4;
+ int pjour1text = *((Uint32 *)(jour1 + 8)) - sjour1text;
+ if (pjour1text < 0) throw GeneralException("Texte trop grand!\n");
+ *((Uint32 *)(jour1 + 4)) = pjour1text;
+ jour1text->read(jour1 + pjour1text, jour1text->GetSize());
+ delete jour1text;
+ cd->write_datas(jour1, GUESS, jour1i + d_pe1.Sector, sjour1);
+ free(jour1);
+#else
+ int jour1i = *((short *)(slus + index + 75 * 2));
+ Handle * jour1 = new Input("75/0075.out");
+ printm(M_INFO, "Ecriture de la fin du jour 1...\n");
+ cd->write_file(jour1, GUESS, jour1i + d_pe1.Sector);
+ delete jour1;
+#endif
+
+ for (i = 1; i <= 20; i++) {
+ Input groupe(String().set("groupe-%02i.txt", i));
+ c = 0;
+ while (1) {
+ groupe >> s;
+ if (!s.strlen())
+ break;
+ groupes[c++][i] = s.to_int();
+ }
+ counts[i] = c;
+ }
+
+ for (i = 1; i <= 20; i++) {
+ Handle * f = new Input(String().set("scripts/c/%02i.out", i));
+ unsigned char * script = (unsigned char *) malloc(f->GetSize());
+ f->read(script, f->GetSize());
+ printm(M_INFO, "Groupe %i...\n", i);
+ for (c = 0; c < counts[i]; c++) {
+ UpdateProgress(Dlg, i * 5.0);
+ LaisserSouffler(Dlg);
+ int sector, s1, s2, s3, r, size, size2, sizes[2], tptr, uptr, aptr, asiz, maxsize;
+ r = groupes[c][i] - 1;
+ unsigned char * room;
+
+ sector = *((int *) (slus + offset + r * 8));
+ s1 = *(slus + offset + r * 8 + 4);
+ s2 = *(slus + offset + r * 8 + 5) | ((*(slus + offset + r * 8 + 6) & 0x0f) << 8);
+ s3 = ((*(slus + offset + r * 8 + 6) & 0xf0) >> 4) | (*(slus + offset + r * 8 + 7) << 4);
+
+ cd->read_datas((unsigned char *) sizes, GUESS, d_pe1.Sector + sector + s1 + s2, 8);
+ size = sizes[0];
+ size2 = sizes[1];
+
+ room = (unsigned char *) malloc(size);
+ cd->read_datas(room, GUESS, d_pe1.Sector + sector + s1 + s2, size);
+
+ printm(M_INFO, " Room %i\n", r + 1);
+
+ tptr = *((int *) (room + size2 + 32)) & 0xfffff;
+ uptr = *((int *) (room + tptr + 4));
+ aptr = *((int *) (room + tptr + 12)) & 0xfffff;
+ asiz = *((int *) (room + tptr + 8));
+ maxsize = aptr - uptr + (asiz | 3);
+// printm(M_INFO, "size2 = 0x%08x\ntptr = 0x%08x\nuptr = 0x%08x\naptr = 0x%08x\nasiz = 0x%08x\nmaxsize = 0x%08x\nsize = 0x%08x\n", size2, tptr, uptr, aptr, asiz, maxsize, f->GetSize());
+ if (f->GetSize() > maxsize) {
+ printm(M_WARNING, "Script trop grand (%i octets et %i libres)\n", f->GetSize(), maxsize);
+ free(room);
+ continue;
+ }
+
+ uptr = (uptr + maxsize - f->GetSize()) & (~3);
+
+ memcpy(room + uptr, script, f->GetSize());
+
+ *((int *) (room + tptr + 12)) = uptr | 0x01000000;
+ *((int *) (room + tptr + 8)) = f->GetSize();
+
+ cd->write_datas(room, GUESS, d_pe1.Sector + sector + s1 + s2, size);
+
+ free(room);
+ }
+ delete f;
+ free(script);
+ }
+
+ free(slus);
+
+ return 0;
+}
+
+CODE_ENDS
@@ -1,67 +1,67 @@ -char table[256] = "0123456789+-=*% ABCDEFGHIJKLMNOPQRSTUVWXYZ&!?\"'.abcdefghijklmnopqrstuvwxyz:,/éèêëàâäîïôöùûüç..()#"; - -#define MAXCHAR 0x60 - -#ifdef __HANDLE_H__ -void extracttext(Handle * f, Handle * t, int size) { - int j; - Uint8 b, a1, a2; - - for (j = 0; j < size; j++) { - b = f->readU8(); - - if (b <= MAXCHAR) { - t->writeU8(table[b]); - } else { - switch(b) { - case 0xf7: - t->writeU8('\n'); - break; - case 0xf8: - (*t) << "<PAUSE>\n"; - break; - case 0xf9: - (*t) << "\n<TCLOSE>\n"; - break; - case 0xfa: - (*t) << "<AYA>"; - break; - case 0xfb: - j++; - j++; - a1 = f->readU8(); - switch(a1) { - case 0: - (*t) << "<TAG0>"; - break; - case 1: - (*t) << "<TAG1>"; - break; - case 9: - a2 = f->readU8(); - (*t) << "<CHOICES " << a2 << ">\n"; - break; - case 7: - a2 = f->readU8(); - (*t) << "<TIMER " << a2 << ">"; - break; - default: - (*t) << "<UNKCMD " << a1 << ">"; - break; - } - break; - case 0xfe: - j++; - b = f->readU8(); - (*t) << "<PT" << b << ">\n"; - break; - case 0xff: - (*t) << "\n<CLOSE>\n"; - break; - default: - (*t) << String().set("<UNK %02X>", b); - } - } - } -} -#endif +char table[256] = "0123456789+-=*% ABCDEFGHIJKLMNOPQRSTUVWXYZ&!?\"'.abcdefghijklmnopqrstuvwxyz:,/éèêëàâäîïôöùûüç..()#";
+
+#define MAXCHAR 0x60
+
+#ifdef __HANDLE_H__
+void extracttext(Handle * f, Handle * t, int size) {
+ int j;
+ Uint8 b, a1, a2;
+
+ for (j = 0; j < size; j++) {
+ b = f->readU8();
+
+ if (b <= MAXCHAR) {
+ t->writeU8(table[b]);
+ } else {
+ switch(b) {
+ case 0xf7:
+ t->writeU8('\n');
+ break;
+ case 0xf8:
+ (*t) << "<PAUSE>\n";
+ break;
+ case 0xf9:
+ (*t) << "\n<TCLOSE>\n";
+ break;
+ case 0xfa:
+ (*t) << "<AYA>";
+ break;
+ case 0xfb:
+ j++;
+ j++;
+ a1 = f->readU8();
+ switch(a1) {
+ case 0:
+ (*t) << "<TAG0>";
+ break;
+ case 1:
+ (*t) << "<TAG1>";
+ break;
+ case 9:
+ a2 = f->readU8();
+ (*t) << "<CHOICES " << a2 << ">\n";
+ break;
+ case 7:
+ a2 = f->readU8();
+ (*t) << "<TIMER " << a2 << ">";
+ break;
+ default:
+ (*t) << "<UNKCMD " << a1 << ">";
+ break;
+ }
+ break;
+ case 0xfe:
+ j++;
+ b = f->readU8();
+ (*t) << "<PT" << b << ">\n";
+ break;
+ case 0xff:
+ (*t) << "\n<CLOSE>\n";
+ break;
+ default:
+ (*t) << String().set("<UNK %02X>", b);
+ }
+ }
+ }
+}
+#endif
diff --git a/PcsxSrc/Linux/GladeCalls.c b/PcsxSrc/Linux/GladeCalls.c index 809309a..938a8e3 100644 --- a/PcsxSrc/Linux/GladeCalls.c +++ b/PcsxSrc/Linux/GladeCalls.c @@ -475,37 +475,37 @@ OnMcd_Delete1 (GtkButton *button, }
- -void -OnDebug (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnDbg_Ok (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnDebug_Ok (GtkButton *button, - gpointer user_data) -{ - -} - - -gboolean -OnConfConf_Cancel (GtkWidget *widget, - GdkEvent *event, - gpointer user_data) -{ - - return FALSE; -} - +
+void
+OnDebug (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+
+}
+
+
+void
+OnDbg_Ok (GtkButton *button,
+ gpointer user_data)
+{
+
+}
+
+
+void
+OnDebug_Ok (GtkButton *button,
+ gpointer user_data)
+{
+
+}
+
+
+gboolean
+OnConfConf_Cancel (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+
+ return FALSE;
+}
+
diff --git a/PcsxSrc/Linux/GladeCalls.h b/PcsxSrc/Linux/GladeCalls.h index f6e7a9b..0eb216d 100644 --- a/PcsxSrc/Linux/GladeCalls.h +++ b/PcsxSrc/Linux/GladeCalls.h @@ -237,15 +237,15 @@ OnMcd_Delete2 (GtkButton *button, void
OnMcd_Delete1 (GtkButton *button,
gpointer user_data);
- -void -OnDebug (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnDbg_Ok (GtkButton *button, - gpointer user_data); - -void -OnDebug_Ok (GtkButton *button, - gpointer user_data); +
+void
+OnDebug (GtkMenuItem *menuitem,
+ gpointer user_data);
+
+void
+OnDbg_Ok (GtkButton *button,
+ gpointer user_data);
+
+void
+OnDebug_Ok (GtkButton *button,
+ gpointer user_data);
diff --git a/PcsxSrc/Linux/GladeFuncs.c b/PcsxSrc/Linux/GladeFuncs.c index f20a9a2..47dbfc3 100644 --- a/PcsxSrc/Linux/GladeFuncs.c +++ b/PcsxSrc/Linux/GladeFuncs.c @@ -1,162 +1,162 @@ -/* - * DO NOT EDIT THIS FILE - it is generated by Glade. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <string.h> - -#include <gtk/gtk.h> - -#include "GladeFuncs.h" - -/* This is an internally used function to check if a pixmap file exists. */ -static gchar* check_file_exists (const gchar *directory, - const gchar *filename); - -/* This is an internally used function to create pixmaps. */ -static GtkWidget* create_dummy_pixmap (GtkWidget *widget); - -GtkWidget* -lookup_widget (GtkWidget *widget, - const gchar *widget_name) -{ - GtkWidget *parent, *found_widget; - - for (;;) - { - if (GTK_IS_MENU (widget)) - parent = gtk_menu_get_attach_widget (GTK_MENU (widget)); - else - parent = widget->parent; - if (parent == NULL) - break; - widget = parent; - } - - found_widget = (GtkWidget*) gtk_object_get_data (GTK_OBJECT (widget), - widget_name); - if (!found_widget) - g_warning ("Widget not found: %s", widget_name); - return found_widget; -} - -/* This is a dummy pixmap we use when a pixmap can't be found. */ -static char *dummy_pixmap_xpm[] = { -/* columns rows colors chars-per-pixel */ -"1 1 1 1", -" c None", -/* pixels */ -" " -}; - -/* This is an internally used function to create pixmaps. */ -static GtkWidget* -create_dummy_pixmap (GtkWidget *widget) -{ - GdkColormap *colormap; - GdkPixmap *gdkpixmap; - GdkBitmap *mask; - GtkWidget *pixmap; - - colormap = gtk_widget_get_colormap (widget); - gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask, - NULL, dummy_pixmap_xpm); - if (gdkpixmap == NULL) - g_error ("Couldn't create replacement pixmap."); - pixmap = gtk_pixmap_new (gdkpixmap, mask); - gdk_pixmap_unref (gdkpixmap); - gdk_bitmap_unref (mask); - return pixmap; -} - -static GList *pixmaps_directories = NULL; - -/* Use this function to set the directory containing installed pixmaps. */ -void -add_pixmap_directory (const gchar *directory) -{ - pixmaps_directories = g_list_prepend (pixmaps_directories, - g_strdup (directory)); -} - -/* This is an internally used function to create pixmaps. */ -GtkWidget* -create_pixmap (GtkWidget *widget, - const gchar *filename) -{ - gchar *found_filename = NULL; - GdkColormap *colormap; - GdkPixmap *gdkpixmap; - GdkBitmap *mask; - GtkWidget *pixmap; - GList *elem; - - if (!filename || !filename[0]) - return create_dummy_pixmap (widget); - - /* We first try any pixmaps directories set by the application. */ - elem = pixmaps_directories; - while (elem) - { - found_filename = check_file_exists ((gchar*)elem->data, filename); - if (found_filename) - break; - elem = elem->next; - } - - /* If we haven't found the pixmap, try the source directory. */ - if (!found_filename) - { - found_filename = check_file_exists (".pixmaps", filename); - } - - if (!found_filename) - { - g_warning ("Couldn't find pixmap file: %s", filename); - return create_dummy_pixmap (widget); - } - - colormap = gtk_widget_get_colormap (widget); - gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL, colormap, &mask, - NULL, found_filename); - if (gdkpixmap == NULL) - { - g_warning ("Error loading pixmap file: %s", found_filename); - g_free (found_filename); - return create_dummy_pixmap (widget); - } - g_free (found_filename); - pixmap = gtk_pixmap_new (gdkpixmap, mask); - gdk_pixmap_unref (gdkpixmap); - gdk_bitmap_unref (mask); - return pixmap; -} - -/* This is an internally used function to check if a pixmap file exists. */ -gchar* -check_file_exists (const gchar *directory, - const gchar *filename) -{ - gchar *full_filename; - struct stat s; - gint status; - - full_filename = (gchar*) g_malloc (strlen (directory) + 1 - + strlen (filename) + 1); - strcpy (full_filename, directory); - strcat (full_filename, G_DIR_SEPARATOR_S); - strcat (full_filename, filename); - - status = stat (full_filename, &s); - if (status == 0 && S_ISREG (s.st_mode)) - return full_filename; - g_free (full_filename); - return NULL; -} - +/*
+ * DO NOT EDIT THIS FILE - it is generated by Glade.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <gtk/gtk.h>
+
+#include "GladeFuncs.h"
+
+/* This is an internally used function to check if a pixmap file exists. */
+static gchar* check_file_exists (const gchar *directory,
+ const gchar *filename);
+
+/* This is an internally used function to create pixmaps. */
+static GtkWidget* create_dummy_pixmap (GtkWidget *widget);
+
+GtkWidget*
+lookup_widget (GtkWidget *widget,
+ const gchar *widget_name)
+{
+ GtkWidget *parent, *found_widget;
+
+ for (;;)
+ {
+ if (GTK_IS_MENU (widget))
+ parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
+ else
+ parent = widget->parent;
+ if (parent == NULL)
+ break;
+ widget = parent;
+ }
+
+ found_widget = (GtkWidget*) gtk_object_get_data (GTK_OBJECT (widget),
+ widget_name);
+ if (!found_widget)
+ g_warning ("Widget not found: %s", widget_name);
+ return found_widget;
+}
+
+/* This is a dummy pixmap we use when a pixmap can't be found. */
+static char *dummy_pixmap_xpm[] = {
+/* columns rows colors chars-per-pixel */
+"1 1 1 1",
+" c None",
+/* pixels */
+" "
+};
+
+/* This is an internally used function to create pixmaps. */
+static GtkWidget*
+create_dummy_pixmap (GtkWidget *widget)
+{
+ GdkColormap *colormap;
+ GdkPixmap *gdkpixmap;
+ GdkBitmap *mask;
+ GtkWidget *pixmap;
+
+ colormap = gtk_widget_get_colormap (widget);
+ gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask,
+ NULL, dummy_pixmap_xpm);
+ if (gdkpixmap == NULL)
+ g_error ("Couldn't create replacement pixmap.");
+ pixmap = gtk_pixmap_new (gdkpixmap, mask);
+ gdk_pixmap_unref (gdkpixmap);
+ gdk_bitmap_unref (mask);
+ return pixmap;
+}
+
+static GList *pixmaps_directories = NULL;
+
+/* Use this function to set the directory containing installed pixmaps. */
+void
+add_pixmap_directory (const gchar *directory)
+{
+ pixmaps_directories = g_list_prepend (pixmaps_directories,
+ g_strdup (directory));
+}
+
+/* This is an internally used function to create pixmaps. */
+GtkWidget*
+create_pixmap (GtkWidget *widget,
+ const gchar *filename)
+{
+ gchar *found_filename = NULL;
+ GdkColormap *colormap;
+ GdkPixmap *gdkpixmap;
+ GdkBitmap *mask;
+ GtkWidget *pixmap;
+ GList *elem;
+
+ if (!filename || !filename[0])
+ return create_dummy_pixmap (widget);
+
+ /* We first try any pixmaps directories set by the application. */
+ elem = pixmaps_directories;
+ while (elem)
+ {
+ found_filename = check_file_exists ((gchar*)elem->data, filename);
+ if (found_filename)
+ break;
+ elem = elem->next;
+ }
+
+ /* If we haven't found the pixmap, try the source directory. */
+ if (!found_filename)
+ {
+ found_filename = check_file_exists (".pixmaps", filename);
+ }
+
+ if (!found_filename)
+ {
+ g_warning ("Couldn't find pixmap file: %s", filename);
+ return create_dummy_pixmap (widget);
+ }
+
+ colormap = gtk_widget_get_colormap (widget);
+ gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL, colormap, &mask,
+ NULL, found_filename);
+ if (gdkpixmap == NULL)
+ {
+ g_warning ("Error loading pixmap file: %s", found_filename);
+ g_free (found_filename);
+ return create_dummy_pixmap (widget);
+ }
+ g_free (found_filename);
+ pixmap = gtk_pixmap_new (gdkpixmap, mask);
+ gdk_pixmap_unref (gdkpixmap);
+ gdk_bitmap_unref (mask);
+ return pixmap;
+}
+
+/* This is an internally used function to check if a pixmap file exists. */
+gchar*
+check_file_exists (const gchar *directory,
+ const gchar *filename)
+{
+ gchar *full_filename;
+ struct stat s;
+ gint status;
+
+ full_filename = (gchar*) g_malloc (strlen (directory) + 1
+ + strlen (filename) + 1);
+ strcpy (full_filename, directory);
+ strcat (full_filename, G_DIR_SEPARATOR_S);
+ strcat (full_filename, filename);
+
+ status = stat (full_filename, &s);
+ if (status == 0 && S_ISREG (s.st_mode))
+ return full_filename;
+ g_free (full_filename);
+ return NULL;
+}
+
diff --git a/PcsxSrc/Linux/GladeFuncs.h b/PcsxSrc/Linux/GladeFuncs.h index aee31f9..8866159 100644 --- a/PcsxSrc/Linux/GladeFuncs.h +++ b/PcsxSrc/Linux/GladeFuncs.h @@ -1,38 +1,38 @@ -/* - * DO NOT EDIT THIS FILE - it is generated by Glade. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <gtk/gtk.h> - -/* - * Public Functions. - */ - -/* - * This function returns a widget in a component created by Glade. - * Call it with the toplevel widget in the component (i.e. a window/dialog), - * or alternatively any widget in the component, and the name of the widget - * you want returned. - */ -GtkWidget* lookup_widget (GtkWidget *widget, - const gchar *widget_name); - -/* get_widget() is deprecated. Use lookup_widget instead. */ -#define get_widget lookup_widget - -/* Use this function to set the directory containing installed pixmaps. */ -void add_pixmap_directory (const gchar *directory); - - -/* - * Private Functions. - */ - -/* This is used to create the pixmaps in the interface. */ -GtkWidget* create_pixmap (GtkWidget *widget, - const gchar *filename); - +/*
+ * DO NOT EDIT THIS FILE - it is generated by Glade.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+
+/*
+ * Public Functions.
+ */
+
+/*
+ * This function returns a widget in a component created by Glade.
+ * Call it with the toplevel widget in the component (i.e. a window/dialog),
+ * or alternatively any widget in the component, and the name of the widget
+ * you want returned.
+ */
+GtkWidget* lookup_widget (GtkWidget *widget,
+ const gchar *widget_name);
+
+/* get_widget() is deprecated. Use lookup_widget instead. */
+#define get_widget lookup_widget
+
+/* Use this function to set the directory containing installed pixmaps. */
+void add_pixmap_directory (const gchar *directory);
+
+
+/*
+ * Private Functions.
+ */
+
+/* This is used to create the pixmaps in the interface. */
+GtkWidget* create_pixmap (GtkWidget *widget,
+ const gchar *filename);
+
diff --git a/PcsxSrc/Linux/GladeGui.c b/PcsxSrc/Linux/GladeGui.c index 0af25dc..44ec6c8 100644 --- a/PcsxSrc/Linux/GladeGui.c +++ b/PcsxSrc/Linux/GladeGui.c @@ -1,1644 +1,1644 @@ -/* - * DO NOT EDIT THIS FILE - it is generated by Glade. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <string.h> - -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include "GladeCalls.h" -#include "GladeGui.h" -#include "GladeFuncs.h" - -GtkWidget* -create_MainWindow (void) -{ - GtkWidget *MainWindow; - GtkWidget *vbox1; - GtkWidget *menubar1; - GtkWidget *item1; - GtkWidget *item1_menu; - GtkAccelGroup *item1_menu_accels; - GtkWidget *RunCd; - GtkWidget *RunCdBiois; - GtkWidget *Run_Exe; - GtkWidget *separator2; - GtkWidget *exit2; - GtkWidget *emulator1; - GtkWidget *emulator1_menu; - GtkAccelGroup *emulator1_menu_accels; - GtkWidget *run1; - GtkWidget *reset1; - GtkWidget *configuration1; - GtkWidget *configuration1_menu; - GtkAccelGroup *configuration1_menu_accels; - GtkWidget *plugins___bios1; - GtkWidget *separator3; - GtkWidget *graphics1; - GtkWidget *sound1; - GtkWidget *cd_rom1; - GtkWidget *controllers1; - GtkWidget *separator4; - GtkWidget *cpu1; - GtkWidget *memory_cards1; - GtkWidget *debug1; - GtkWidget *help1; - GtkWidget *help1_menu; - GtkAccelGroup *help1_menu_accels; - GtkWidget *about_pcsx1; - - MainWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_object_set_data (GTK_OBJECT (MainWindow), "MainWindow", MainWindow); - gtk_widget_set_usize (MainWindow, 350, 200); - gtk_window_set_title (GTK_WINDOW (MainWindow), "PCSX"); - gtk_window_set_position (GTK_WINDOW (MainWindow), GTK_WIN_POS_CENTER); - gtk_window_set_policy (GTK_WINDOW (MainWindow), FALSE, FALSE, FALSE); - - vbox1 = gtk_vbox_new (FALSE, 0); - gtk_widget_ref (vbox1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "vbox1", vbox1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (vbox1); - gtk_container_add (GTK_CONTAINER (MainWindow), vbox1); - - menubar1 = gtk_menu_bar_new (); - gtk_widget_ref (menubar1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "menubar1", menubar1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (menubar1); - gtk_box_pack_start (GTK_BOX (vbox1), menubar1, FALSE, FALSE, 0); - - item1 = gtk_menu_item_new_with_label ("File"); - gtk_widget_ref (item1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "item1", item1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (item1); - gtk_container_add (GTK_CONTAINER (menubar1), item1); - - item1_menu = gtk_menu_new (); - gtk_widget_ref (item1_menu); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "item1_menu", item1_menu, - (GtkDestroyNotify) gtk_widget_unref); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (item1), item1_menu); - item1_menu_accels = gtk_menu_ensure_uline_accel_group (GTK_MENU (item1_menu)); - - RunCd = gtk_menu_item_new_with_label ("Run Cd"); - gtk_widget_ref (RunCd); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "RunCd", RunCd, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (RunCd); - gtk_container_add (GTK_CONTAINER (item1_menu), RunCd); - - RunCdBiois = gtk_menu_item_new_with_label ("Run Cd Through Bios"); - gtk_widget_ref (RunCdBiois); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "RunCdBiois", RunCdBiois, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (RunCdBiois); - gtk_container_add (GTK_CONTAINER (item1_menu), RunCdBiois); - - Run_Exe = gtk_menu_item_new_with_label ("Run Exe"); - gtk_widget_ref (Run_Exe); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "Run_Exe", Run_Exe, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (Run_Exe); - gtk_container_add (GTK_CONTAINER (item1_menu), Run_Exe); - - separator2 = gtk_menu_item_new (); - gtk_widget_ref (separator2); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "separator2", separator2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (separator2); - gtk_container_add (GTK_CONTAINER (item1_menu), separator2); - gtk_widget_set_sensitive (separator2, FALSE); - - exit2 = gtk_menu_item_new_with_label ("Exit"); - gtk_widget_ref (exit2); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "exit2", exit2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (exit2); - gtk_container_add (GTK_CONTAINER (item1_menu), exit2); - - emulator1 = gtk_menu_item_new_with_label ("Emulator"); - gtk_widget_ref (emulator1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "emulator1", emulator1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (emulator1); - gtk_container_add (GTK_CONTAINER (menubar1), emulator1); - - emulator1_menu = gtk_menu_new (); - gtk_widget_ref (emulator1_menu); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "emulator1_menu", emulator1_menu, - (GtkDestroyNotify) gtk_widget_unref); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (emulator1), emulator1_menu); - emulator1_menu_accels = gtk_menu_ensure_uline_accel_group (GTK_MENU (emulator1_menu)); - - run1 = gtk_menu_item_new_with_label ("Run"); - gtk_widget_ref (run1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "run1", run1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (run1); - gtk_container_add (GTK_CONTAINER (emulator1_menu), run1); - - reset1 = gtk_menu_item_new_with_label ("Reset"); - gtk_widget_ref (reset1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "reset1", reset1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (reset1); - gtk_container_add (GTK_CONTAINER (emulator1_menu), reset1); - - configuration1 = gtk_menu_item_new_with_label ("Configuration"); - gtk_widget_ref (configuration1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "configuration1", configuration1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (configuration1); - gtk_container_add (GTK_CONTAINER (menubar1), configuration1); - - configuration1_menu = gtk_menu_new (); - gtk_widget_ref (configuration1_menu); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "configuration1_menu", configuration1_menu, - (GtkDestroyNotify) gtk_widget_unref); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (configuration1), configuration1_menu); - configuration1_menu_accels = gtk_menu_ensure_uline_accel_group (GTK_MENU (configuration1_menu)); - - plugins___bios1 = gtk_menu_item_new_with_label ("Plugins & Bios"); - gtk_widget_ref (plugins___bios1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "plugins___bios1", plugins___bios1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (plugins___bios1); - gtk_container_add (GTK_CONTAINER (configuration1_menu), plugins___bios1); - - separator3 = gtk_menu_item_new (); - gtk_widget_ref (separator3); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "separator3", separator3, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (separator3); - gtk_container_add (GTK_CONTAINER (configuration1_menu), separator3); - gtk_widget_set_sensitive (separator3, FALSE); - - graphics1 = gtk_menu_item_new_with_label ("Graphics"); - gtk_widget_ref (graphics1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "graphics1", graphics1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (graphics1); - gtk_container_add (GTK_CONTAINER (configuration1_menu), graphics1); - - sound1 = gtk_menu_item_new_with_label ("Sound"); - gtk_widget_ref (sound1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "sound1", sound1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (sound1); - gtk_container_add (GTK_CONTAINER (configuration1_menu), sound1); - - cd_rom1 = gtk_menu_item_new_with_label ("CD-ROM"); - gtk_widget_ref (cd_rom1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "cd_rom1", cd_rom1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (cd_rom1); - gtk_container_add (GTK_CONTAINER (configuration1_menu), cd_rom1); - - controllers1 = gtk_menu_item_new_with_label ("Controllers"); - gtk_widget_ref (controllers1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "controllers1", controllers1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (controllers1); - gtk_container_add (GTK_CONTAINER (configuration1_menu), controllers1); - - separator4 = gtk_menu_item_new (); - gtk_widget_ref (separator4); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "separator4", separator4, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (separator4); - gtk_container_add (GTK_CONTAINER (configuration1_menu), separator4); - gtk_widget_set_sensitive (separator4, FALSE); - - cpu1 = gtk_menu_item_new_with_label ("Cpu"); - gtk_widget_ref (cpu1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "cpu1", cpu1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (cpu1); - gtk_container_add (GTK_CONTAINER (configuration1_menu), cpu1); - - memory_cards1 = gtk_menu_item_new_with_label ("Memory Cards"); - gtk_widget_ref (memory_cards1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "memory_cards1", memory_cards1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (memory_cards1); - gtk_container_add (GTK_CONTAINER (configuration1_menu), memory_cards1); - - debug1 = gtk_menu_item_new_with_label ("Debug"); - gtk_widget_ref (debug1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "debug1", debug1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (debug1); - gtk_container_add (GTK_CONTAINER (menubar1), debug1); - - help1 = gtk_menu_item_new_with_label ("Help"); - gtk_widget_ref (help1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "help1", help1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (help1); - gtk_container_add (GTK_CONTAINER (menubar1), help1); - - help1_menu = gtk_menu_new (); - gtk_widget_ref (help1_menu); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "help1_menu", help1_menu, - (GtkDestroyNotify) gtk_widget_unref); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (help1), help1_menu); - help1_menu_accels = gtk_menu_ensure_uline_accel_group (GTK_MENU (help1_menu)); - - about_pcsx1 = gtk_menu_item_new_with_label ("About P\251SX"); - gtk_widget_ref (about_pcsx1); - gtk_object_set_data_full (GTK_OBJECT (MainWindow), "about_pcsx1", about_pcsx1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (about_pcsx1); - gtk_container_add (GTK_CONTAINER (help1_menu), about_pcsx1); - - gtk_signal_connect (GTK_OBJECT (MainWindow), "destroy", - GTK_SIGNAL_FUNC (OnDestroy), - NULL); - gtk_signal_connect (GTK_OBJECT (RunCd), "activate", - GTK_SIGNAL_FUNC (OnFile_RunCd), - NULL); - gtk_signal_connect (GTK_OBJECT (RunCdBiois), "activate", - GTK_SIGNAL_FUNC (OnFile_RunCdBios), - NULL); - gtk_signal_connect (GTK_OBJECT (Run_Exe), "activate", - GTK_SIGNAL_FUNC (OnFile_RunExe), - NULL); - gtk_signal_connect (GTK_OBJECT (exit2), "activate", - GTK_SIGNAL_FUNC (OnFile_Exit), - NULL); - gtk_signal_connect (GTK_OBJECT (run1), "activate", - GTK_SIGNAL_FUNC (OnEmu_Run), - NULL); - gtk_signal_connect (GTK_OBJECT (reset1), "activate", - GTK_SIGNAL_FUNC (OnEmu_Reset), - NULL); - gtk_signal_connect (GTK_OBJECT (plugins___bios1), "activate", - GTK_SIGNAL_FUNC (OnConf_Conf), - NULL); - gtk_signal_connect (GTK_OBJECT (graphics1), "activate", - GTK_SIGNAL_FUNC (OnConf_Gpu), - NULL); - gtk_signal_connect (GTK_OBJECT (sound1), "activate", - GTK_SIGNAL_FUNC (OnConf_Spu), - NULL); - gtk_signal_connect (GTK_OBJECT (cd_rom1), "activate", - GTK_SIGNAL_FUNC (OnConf_Cdr), - NULL); - gtk_signal_connect (GTK_OBJECT (controllers1), "activate", - GTK_SIGNAL_FUNC (OnConf_Pads), - NULL); - gtk_signal_connect (GTK_OBJECT (cpu1), "activate", - GTK_SIGNAL_FUNC (OnConf_Cpu), - NULL); - gtk_signal_connect (GTK_OBJECT (memory_cards1), "activate", - GTK_SIGNAL_FUNC (OnConf_Mcds), - NULL); - gtk_signal_connect (GTK_OBJECT (debug1), "activate", - GTK_SIGNAL_FUNC (OnDebug), - NULL); - gtk_signal_connect (GTK_OBJECT (about_pcsx1), "activate", - GTK_SIGNAL_FUNC (OnHelp_About), - NULL); - - return MainWindow; -} - -GtkWidget* -create_AboutDlg (void) -{ - GtkWidget *AboutDlg; - GtkWidget *vbox2; - GtkWidget *packer1; - GtkWidget *hbox1; - GtkWidget *vbox4; - GtkWidget *GtkAbout_LabelVersion; - GtkWidget *frame1; - GtkWidget *vbox6; - GtkWidget *GtkAbout_LabelAuthors; - GtkWidget *pixmap1; - GtkWidget *frame2; - GtkWidget *vbox5; - GtkWidget *GtkAbout_LabelGreets; - GtkWidget *hbuttonbox1; - GtkWidget *button1; - - AboutDlg = gtk_window_new (GTK_WINDOW_DIALOG); - gtk_object_set_data (GTK_OBJECT (AboutDlg), "AboutDlg", AboutDlg); - gtk_container_set_border_width (GTK_CONTAINER (AboutDlg), 10); - gtk_window_set_title (GTK_WINDOW (AboutDlg), "Pcsx About"); - gtk_window_set_position (GTK_WINDOW (AboutDlg), GTK_WIN_POS_CENTER); - - vbox2 = gtk_vbox_new (FALSE, 0); - gtk_widget_ref (vbox2); - gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "vbox2", vbox2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (vbox2); - gtk_container_add (GTK_CONTAINER (AboutDlg), vbox2); - - packer1 = gtk_packer_new (); - gtk_widget_ref (packer1); - gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "packer1", packer1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (packer1); - gtk_box_pack_start (GTK_BOX (vbox2), packer1, FALSE, FALSE, 0); - - hbox1 = gtk_hbox_new (FALSE, 0); - gtk_widget_ref (hbox1); - gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "hbox1", hbox1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbox1); - gtk_box_pack_start (GTK_BOX (vbox2), hbox1, TRUE, TRUE, 0); - - vbox4 = gtk_vbox_new (FALSE, 0); - gtk_widget_ref (vbox4); - gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "vbox4", vbox4, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (vbox4); - gtk_box_pack_start (GTK_BOX (hbox1), vbox4, TRUE, TRUE, 0); - - GtkAbout_LabelVersion = gtk_label_new ("PCSX\r\r\nVersion x.x"); - gtk_widget_ref (GtkAbout_LabelVersion); - gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "GtkAbout_LabelVersion", GtkAbout_LabelVersion, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkAbout_LabelVersion); - gtk_box_pack_start (GTK_BOX (vbox4), GtkAbout_LabelVersion, FALSE, FALSE, 0); - - frame1 = gtk_frame_new (NULL); - gtk_widget_ref (frame1); - gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "frame1", frame1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (frame1); - gtk_box_pack_start (GTK_BOX (vbox4), frame1, FALSE, FALSE, 0); - gtk_container_set_border_width (GTK_CONTAINER (frame1), 5); - - vbox6 = gtk_vbox_new (FALSE, 0); - gtk_widget_ref (vbox6); - gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "vbox6", vbox6, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (vbox6); - gtk_container_add (GTK_CONTAINER (frame1), vbox6); - gtk_container_set_border_width (GTK_CONTAINER (vbox6), 5); - - GtkAbout_LabelAuthors = gtk_label_new ("written by..."); - gtk_widget_ref (GtkAbout_LabelAuthors); - gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "GtkAbout_LabelAuthors", GtkAbout_LabelAuthors, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkAbout_LabelAuthors); - gtk_box_pack_start (GTK_BOX (vbox6), GtkAbout_LabelAuthors, FALSE, FALSE, 0); - - pixmap1 = create_pixmap (AboutDlg, "pcsxAbout.xpm"); - gtk_widget_ref (pixmap1); - gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "pixmap1", pixmap1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (pixmap1); - gtk_box_pack_start (GTK_BOX (hbox1), pixmap1, TRUE, TRUE, 0); - - frame2 = gtk_frame_new (NULL); - gtk_widget_ref (frame2); - gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "frame2", frame2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (frame2); - gtk_box_pack_start (GTK_BOX (vbox2), frame2, FALSE, FALSE, 0); - gtk_container_set_border_width (GTK_CONTAINER (frame2), 5); - - vbox5 = gtk_vbox_new (FALSE, 0); - gtk_widget_ref (vbox5); - gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "vbox5", vbox5, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (vbox5); - gtk_container_add (GTK_CONTAINER (frame2), vbox5); - gtk_container_set_border_width (GTK_CONTAINER (vbox5), 5); - - GtkAbout_LabelGreets = gtk_label_new ("greets to..."); - gtk_widget_ref (GtkAbout_LabelGreets); - gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "GtkAbout_LabelGreets", GtkAbout_LabelGreets, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkAbout_LabelGreets); - gtk_box_pack_start (GTK_BOX (vbox5), GtkAbout_LabelGreets, FALSE, FALSE, 0); - - hbuttonbox1 = gtk_hbutton_box_new (); - gtk_widget_ref (hbuttonbox1); - gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "hbuttonbox1", hbuttonbox1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbuttonbox1); - gtk_box_pack_start (GTK_BOX (vbox2), hbuttonbox1, TRUE, TRUE, 0); - - button1 = gtk_button_new_with_label ("Ok"); - gtk_widget_ref (button1); - gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "button1", button1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button1); - gtk_container_add (GTK_CONTAINER (hbuttonbox1), button1); - GTK_WIDGET_SET_FLAGS (button1, GTK_CAN_DEFAULT); - - gtk_signal_connect (GTK_OBJECT (button1), "clicked", - GTK_SIGNAL_FUNC (OnHelpAbout_Ok), - NULL); - - return AboutDlg; -} - -GtkWidget* -create_ConfDlg (void) -{ - GtkWidget *ConfDlg; - GtkWidget *vbox12; - GtkWidget *table2; - GtkWidget *GtkCombo_Pad1; - GtkWidget *combo_entry4; - GtkWidget *GtkCombo_Pad2; - GtkWidget *combo_entry5; - GtkWidget *GtkCombo_Cdr; - GtkWidget *combo_entry6; - GtkWidget *GtkCombo_Bios; - GtkWidget *combo_entry7; - GtkWidget *hbuttonbox5; - GtkWidget *button6; - GtkWidget *button7; - GtkWidget *button8; - GtkWidget *hbuttonbox6; - GtkWidget *button9; - GtkWidget *button10; - GtkWidget *button11; - GtkWidget *hbuttonbox7; - GtkWidget *button12; - GtkWidget *button13; - GtkWidget *button14; - GtkWidget *hbuttonbox8; - GtkWidget *button15; - GtkWidget *button16; - GtkWidget *button17; - GtkWidget *hbuttonbox9; - GtkWidget *button18; - GtkWidget *button19; - GtkWidget *button20; - GtkWidget *label2; - GtkWidget *label1; - GtkWidget *label3; - GtkWidget *label5; - GtkWidget *label6; - GtkWidget *label4; - GtkWidget *GtkCombo_Gpu; - GtkWidget *combo_entry2; - GtkWidget *GtkCombo_Spu; - GtkWidget *combo_entry3; - GtkWidget *hbox5; - GtkWidget *hbuttonbox11; - GtkWidget *button22; - GtkWidget *button23; - GtkWidget *hbuttonbox10; - GtkWidget *button4; - GtkWidget *button25; - - ConfDlg = gtk_window_new (GTK_WINDOW_DIALOG); - gtk_object_set_data (GTK_OBJECT (ConfDlg), "ConfDlg", ConfDlg); - gtk_container_set_border_width (GTK_CONTAINER (ConfDlg), 10); - gtk_window_set_title (GTK_WINDOW (ConfDlg), "Conf"); - gtk_window_set_position (GTK_WINDOW (ConfDlg), GTK_WIN_POS_CENTER); - - vbox12 = gtk_vbox_new (FALSE, 0); - gtk_widget_ref (vbox12); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "vbox12", vbox12, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (vbox12); - gtk_container_add (GTK_CONTAINER (ConfDlg), vbox12); - - table2 = gtk_table_new (9, 2, FALSE); - gtk_widget_ref (table2); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "table2", table2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (table2); - gtk_box_pack_start (GTK_BOX (vbox12), table2, TRUE, TRUE, 0); - gtk_table_set_col_spacings (GTK_TABLE (table2), 15); - - GtkCombo_Pad1 = gtk_combo_new (); - gtk_widget_ref (GtkCombo_Pad1); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "GtkCombo_Pad1", GtkCombo_Pad1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCombo_Pad1); - gtk_table_attach (GTK_TABLE (table2), GtkCombo_Pad1, 0, 1, 4, 5, - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - combo_entry4 = GTK_COMBO (GtkCombo_Pad1)->entry; - gtk_widget_ref (combo_entry4); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "combo_entry4", combo_entry4, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (combo_entry4); - - GtkCombo_Pad2 = gtk_combo_new (); - gtk_widget_ref (GtkCombo_Pad2); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "GtkCombo_Pad2", GtkCombo_Pad2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCombo_Pad2); - gtk_table_attach (GTK_TABLE (table2), GtkCombo_Pad2, 1, 2, 4, 5, - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - combo_entry5 = GTK_COMBO (GtkCombo_Pad2)->entry; - gtk_widget_ref (combo_entry5); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "combo_entry5", combo_entry5, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (combo_entry5); - - GtkCombo_Cdr = gtk_combo_new (); - gtk_widget_ref (GtkCombo_Cdr); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "GtkCombo_Cdr", GtkCombo_Cdr, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCombo_Cdr); - gtk_table_attach (GTK_TABLE (table2), GtkCombo_Cdr, 0, 1, 7, 8, - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - combo_entry6 = GTK_COMBO (GtkCombo_Cdr)->entry; - gtk_widget_ref (combo_entry6); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "combo_entry6", combo_entry6, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (combo_entry6); - - GtkCombo_Bios = gtk_combo_new (); - gtk_widget_ref (GtkCombo_Bios); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "GtkCombo_Bios", GtkCombo_Bios, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCombo_Bios); - gtk_table_attach (GTK_TABLE (table2), GtkCombo_Bios, 1, 2, 7, 8, - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - combo_entry7 = GTK_COMBO (GtkCombo_Bios)->entry; - gtk_widget_ref (combo_entry7); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "combo_entry7", combo_entry7, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (combo_entry7); - - hbuttonbox5 = gtk_hbutton_box_new (); - gtk_widget_ref (hbuttonbox5); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbuttonbox5", hbuttonbox5, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbuttonbox5); - gtk_table_attach (GTK_TABLE (table2), hbuttonbox5, 0, 1, 8, 9, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0); - gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox5), 0); - - button6 = gtk_button_new_with_label ("Configure"); - gtk_widget_ref (button6); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button6", button6, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button6); - gtk_container_add (GTK_CONTAINER (hbuttonbox5), button6); - GTK_WIDGET_SET_FLAGS (button6, GTK_CAN_DEFAULT); - - button7 = gtk_button_new_with_label ("Test"); - gtk_widget_ref (button7); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button7", button7, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button7); - gtk_container_add (GTK_CONTAINER (hbuttonbox5), button7); - GTK_WIDGET_SET_FLAGS (button7, GTK_CAN_DEFAULT); - - button8 = gtk_button_new_with_label ("About"); - gtk_widget_ref (button8); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button8", button8, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button8); - gtk_container_add (GTK_CONTAINER (hbuttonbox5), button8); - GTK_WIDGET_SET_FLAGS (button8, GTK_CAN_DEFAULT); - - hbuttonbox6 = gtk_hbutton_box_new (); - gtk_widget_ref (hbuttonbox6); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbuttonbox6", hbuttonbox6, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbuttonbox6); - gtk_table_attach (GTK_TABLE (table2), hbuttonbox6, 1, 2, 5, 6, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0); - gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox6), 0); - - button9 = gtk_button_new_with_label ("Configure"); - gtk_widget_ref (button9); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button9", button9, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button9); - gtk_container_add (GTK_CONTAINER (hbuttonbox6), button9); - GTK_WIDGET_SET_FLAGS (button9, GTK_CAN_DEFAULT); - - button10 = gtk_button_new_with_label ("Test"); - gtk_widget_ref (button10); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button10", button10, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button10); - gtk_container_add (GTK_CONTAINER (hbuttonbox6), button10); - GTK_WIDGET_SET_FLAGS (button10, GTK_CAN_DEFAULT); - - button11 = gtk_button_new_with_label ("About"); - gtk_widget_ref (button11); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button11", button11, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button11); - gtk_container_add (GTK_CONTAINER (hbuttonbox6), button11); - GTK_WIDGET_SET_FLAGS (button11, GTK_CAN_DEFAULT); - - hbuttonbox7 = gtk_hbutton_box_new (); - gtk_widget_ref (hbuttonbox7); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbuttonbox7", hbuttonbox7, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbuttonbox7); - gtk_table_attach (GTK_TABLE (table2), hbuttonbox7, 0, 1, 5, 6, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 0, 0); - gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox7), 0); - - button12 = gtk_button_new_with_label ("Configure"); - gtk_widget_ref (button12); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button12", button12, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button12); - gtk_container_add (GTK_CONTAINER (hbuttonbox7), button12); - GTK_WIDGET_SET_FLAGS (button12, GTK_CAN_DEFAULT); - - button13 = gtk_button_new_with_label ("Test"); - gtk_widget_ref (button13); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button13", button13, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button13); - gtk_container_add (GTK_CONTAINER (hbuttonbox7), button13); - GTK_WIDGET_SET_FLAGS (button13, GTK_CAN_DEFAULT); - - button14 = gtk_button_new_with_label ("About"); - gtk_widget_ref (button14); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button14", button14, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button14); - gtk_container_add (GTK_CONTAINER (hbuttonbox7), button14); - GTK_WIDGET_SET_FLAGS (button14, GTK_CAN_DEFAULT); - - hbuttonbox8 = gtk_hbutton_box_new (); - gtk_widget_ref (hbuttonbox8); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbuttonbox8", hbuttonbox8, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbuttonbox8); - gtk_table_attach (GTK_TABLE (table2), hbuttonbox8, 0, 1, 2, 3, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0); - gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox8), 0); - - button15 = gtk_button_new_with_label ("Configure"); - gtk_widget_ref (button15); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button15", button15, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button15); - gtk_container_add (GTK_CONTAINER (hbuttonbox8), button15); - GTK_WIDGET_SET_FLAGS (button15, GTK_CAN_DEFAULT); - - button16 = gtk_button_new_with_label ("Test"); - gtk_widget_ref (button16); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button16", button16, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button16); - gtk_container_add (GTK_CONTAINER (hbuttonbox8), button16); - GTK_WIDGET_SET_FLAGS (button16, GTK_CAN_DEFAULT); - - button17 = gtk_button_new_with_label ("About"); - gtk_widget_ref (button17); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button17", button17, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button17); - gtk_container_add (GTK_CONTAINER (hbuttonbox8), button17); - GTK_WIDGET_SET_FLAGS (button17, GTK_CAN_DEFAULT); - - hbuttonbox9 = gtk_hbutton_box_new (); - gtk_widget_ref (hbuttonbox9); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbuttonbox9", hbuttonbox9, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbuttonbox9); - gtk_table_attach (GTK_TABLE (table2), hbuttonbox9, 1, 2, 2, 3, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_FILL), 0, 0); - gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox9), 0); - - button18 = gtk_button_new_with_label ("Configure"); - gtk_widget_ref (button18); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button18", button18, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button18); - gtk_container_add (GTK_CONTAINER (hbuttonbox9), button18); - GTK_WIDGET_SET_FLAGS (button18, GTK_CAN_DEFAULT); - - button19 = gtk_button_new_with_label ("Test"); - gtk_widget_ref (button19); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button19", button19, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button19); - gtk_container_add (GTK_CONTAINER (hbuttonbox9), button19); - GTK_WIDGET_SET_FLAGS (button19, GTK_CAN_DEFAULT); - - button20 = gtk_button_new_with_label ("About"); - gtk_widget_ref (button20); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button20", button20, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button20); - gtk_container_add (GTK_CONTAINER (hbuttonbox9), button20); - GTK_WIDGET_SET_FLAGS (button20, GTK_CAN_DEFAULT); - - label2 = gtk_label_new ("Sound"); - gtk_widget_ref (label2); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "label2", label2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label2); - gtk_table_attach (GTK_TABLE (table2), label2, 1, 2, 0, 1, - (GtkAttachOptions) (0), - (GtkAttachOptions) (0), 0, 0); - gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5); - - label1 = gtk_label_new ("Graphics"); - gtk_widget_ref (label1); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "label1", label1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label1); - gtk_table_attach (GTK_TABLE (table2), label1, 0, 1, 0, 1, - (GtkAttachOptions) (0), - (GtkAttachOptions) (0), 0, 0); - gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5); - - label3 = gtk_label_new ("First Controller"); - gtk_widget_ref (label3); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "label3", label3, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label3); - gtk_table_attach (GTK_TABLE (table2), label3, 0, 1, 3, 4, - (GtkAttachOptions) (0), - (GtkAttachOptions) (0), 0, 0); - gtk_misc_set_alignment (GTK_MISC (label3), 0, 0.5); - - label5 = gtk_label_new ("Cdrom"); - gtk_widget_ref (label5); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "label5", label5, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label5); - gtk_table_attach (GTK_TABLE (table2), label5, 0, 1, 6, 7, - (GtkAttachOptions) (0), - (GtkAttachOptions) (0), 0, 0); - gtk_misc_set_alignment (GTK_MISC (label5), 0, 0.5); - - label6 = gtk_label_new ("Bios"); - gtk_widget_ref (label6); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "label6", label6, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label6); - gtk_table_attach (GTK_TABLE (table2), label6, 1, 2, 6, 7, - (GtkAttachOptions) (0), - (GtkAttachOptions) (0), 0, 0); - gtk_misc_set_alignment (GTK_MISC (label6), 0, 0.5); - - label4 = gtk_label_new ("Second Controller"); - gtk_widget_ref (label4); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "label4", label4, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label4); - gtk_table_attach (GTK_TABLE (table2), label4, 1, 2, 3, 4, - (GtkAttachOptions) (0), - (GtkAttachOptions) (0), 0, 0); - gtk_misc_set_alignment (GTK_MISC (label4), 0, 0.5); - - GtkCombo_Gpu = gtk_combo_new (); - gtk_widget_ref (GtkCombo_Gpu); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "GtkCombo_Gpu", GtkCombo_Gpu, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCombo_Gpu); - gtk_table_attach (GTK_TABLE (table2), GtkCombo_Gpu, 0, 1, 1, 2, - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - combo_entry2 = GTK_COMBO (GtkCombo_Gpu)->entry; - gtk_widget_ref (combo_entry2); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "combo_entry2", combo_entry2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (combo_entry2); - - GtkCombo_Spu = gtk_combo_new (); - gtk_widget_ref (GtkCombo_Spu); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "GtkCombo_Spu", GtkCombo_Spu, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCombo_Spu); - gtk_table_attach (GTK_TABLE (table2), GtkCombo_Spu, 1, 2, 1, 2, - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - combo_entry3 = GTK_COMBO (GtkCombo_Spu)->entry; - gtk_widget_ref (combo_entry3); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "combo_entry3", combo_entry3, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (combo_entry3); - - hbox5 = gtk_hbox_new (FALSE, 14); - gtk_widget_ref (hbox5); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbox5", hbox5, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbox5); - gtk_box_pack_start (GTK_BOX (vbox12), hbox5, TRUE, TRUE, 0); - - hbuttonbox11 = gtk_hbutton_box_new (); - gtk_widget_ref (hbuttonbox11); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbuttonbox11", hbuttonbox11, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbuttonbox11); - gtk_box_pack_start (GTK_BOX (hbox5), hbuttonbox11, TRUE, TRUE, 0); - gtk_widget_set_usize (hbuttonbox11, 169, -2); - gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox11), 0); - - button22 = gtk_button_new_with_label ("Select Plugins Dir"); - gtk_widget_ref (button22); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button22", button22, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button22); - gtk_container_add (GTK_CONTAINER (hbuttonbox11), button22); - gtk_widget_set_usize (button22, 109, -2); - GTK_WIDGET_SET_FLAGS (button22, GTK_CAN_DEFAULT); - - button23 = gtk_button_new_with_label ("Select Bios Dir"); - gtk_widget_ref (button23); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button23", button23, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button23); - gtk_container_add (GTK_CONTAINER (hbuttonbox11), button23); - GTK_WIDGET_SET_FLAGS (button23, GTK_CAN_DEFAULT); - - hbuttonbox10 = gtk_hbutton_box_new (); - gtk_widget_ref (hbuttonbox10); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbuttonbox10", hbuttonbox10, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbuttonbox10); - gtk_box_pack_start (GTK_BOX (hbox5), hbuttonbox10, TRUE, TRUE, 0); - gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox10), 0); - - button4 = gtk_button_new_with_label ("Ok"); - gtk_widget_ref (button4); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button4", button4, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button4); - gtk_container_add (GTK_CONTAINER (hbuttonbox10), button4); - GTK_WIDGET_SET_FLAGS (button4, GTK_CAN_DEFAULT); - - button25 = gtk_button_new_with_label ("Cancel"); - gtk_widget_ref (button25); - gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button25", button25, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button25); - gtk_container_add (GTK_CONTAINER (hbuttonbox10), button25); - GTK_WIDGET_SET_FLAGS (button25, GTK_CAN_DEFAULT); - - gtk_signal_connect (GTK_OBJECT (button6), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_CdrConf), - NULL); - gtk_signal_connect (GTK_OBJECT (button7), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_CdrTest), - NULL); - gtk_signal_connect (GTK_OBJECT (button8), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_CdrAbout), - NULL); - gtk_signal_connect (GTK_OBJECT (button9), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_Pad2Conf), - NULL); - gtk_signal_connect (GTK_OBJECT (button10), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_Pad2Test), - NULL); - gtk_signal_connect (GTK_OBJECT (button11), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_Pad2About), - NULL); - gtk_signal_connect (GTK_OBJECT (button12), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_Pad1Conf), - NULL); - gtk_signal_connect (GTK_OBJECT (button13), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_Pad1Test), - NULL); - gtk_signal_connect (GTK_OBJECT (button14), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_Pad1About), - NULL); - gtk_signal_connect (GTK_OBJECT (button15), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_GpuConf), - NULL); - gtk_signal_connect (GTK_OBJECT (button16), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_GpuTest), - NULL); - gtk_signal_connect (GTK_OBJECT (button17), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_GpuAbout), - NULL); - gtk_signal_connect (GTK_OBJECT (button18), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_SpuConf), - NULL); - gtk_signal_connect (GTK_OBJECT (button19), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_SpuTest), - NULL); - gtk_signal_connect (GTK_OBJECT (button20), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_SpuAbout), - NULL); - gtk_signal_connect (GTK_OBJECT (button22), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_PluginsPath), - NULL); - gtk_signal_connect (GTK_OBJECT (button23), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_BiosPath), - NULL); - gtk_signal_connect (GTK_OBJECT (button4), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_Ok), - NULL); - gtk_signal_connect (GTK_OBJECT (button25), "clicked", - GTK_SIGNAL_FUNC (OnConfConf_Cancel), - NULL); - - return ConfDlg; -} - -GtkWidget* -create_CpuDlg (void) -{ - GtkWidget *CpuDlg; - GtkWidget *vbox8; - GtkWidget *frame3; - GtkWidget *vbox15; - GtkWidget *table1; - GtkWidget *GtkCheckButton_Xa; - GtkWidget *GtkCheckButton_Cdda; - GtkWidget *GtkCheckButton_Sio; - GtkWidget *GtkCheckButton_Cpu; - GtkWidget *GtkCheckButton_PsxOut; - GtkWidget *GtkCheckButton_Mdec; - GtkWidget *GtkCheckButton_SpuIrq; - GtkWidget *GtkCheckButton_CpuLog; - GtkWidget *GtkCheckButton_CdTiming; - GtkWidget *frame6; - GtkWidget *hbox4; - GtkWidget *GtkCheckButton_PsxAuto; - GtkWidget *GtkCombo_PsxType; - GtkWidget *combo_entry1; - GtkWidget *hbuttonbox3; - GtkWidget *button2; - GtkWidget *button3; - - CpuDlg = gtk_window_new (GTK_WINDOW_DIALOG); - gtk_object_set_data (GTK_OBJECT (CpuDlg), "CpuDlg", CpuDlg); - gtk_container_set_border_width (GTK_CONTAINER (CpuDlg), 5); - gtk_window_set_title (GTK_WINDOW (CpuDlg), "Cpu"); - gtk_window_set_position (GTK_WINDOW (CpuDlg), GTK_WIN_POS_CENTER); - - vbox8 = gtk_vbox_new (FALSE, 0); - gtk_widget_ref (vbox8); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "vbox8", vbox8, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (vbox8); - gtk_container_add (GTK_CONTAINER (CpuDlg), vbox8); - - frame3 = gtk_frame_new ("Options"); - gtk_widget_ref (frame3); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "frame3", frame3, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (frame3); - gtk_box_pack_start (GTK_BOX (vbox8), frame3, TRUE, TRUE, 0); - gtk_container_set_border_width (GTK_CONTAINER (frame3), 5); - - vbox15 = gtk_vbox_new (FALSE, 0); - gtk_widget_ref (vbox15); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "vbox15", vbox15, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (vbox15); - gtk_container_add (GTK_CONTAINER (frame3), vbox15); - gtk_container_set_border_width (GTK_CONTAINER (vbox15), 5); - - table1 = gtk_table_new (4, 2, FALSE); - gtk_widget_ref (table1); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "table1", table1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (table1); - gtk_box_pack_start (GTK_BOX (vbox15), table1, TRUE, TRUE, 0); - - GtkCheckButton_Xa = gtk_check_button_new_with_label ("Disable Xa Decoding"); - gtk_widget_ref (GtkCheckButton_Xa); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_Xa", GtkCheckButton_Xa, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCheckButton_Xa); - gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_Xa, 0, 1, 0, 1, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - GtkCheckButton_Cdda = gtk_check_button_new_with_label ("Disable Cd Audio"); - gtk_widget_ref (GtkCheckButton_Cdda); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_Cdda", GtkCheckButton_Cdda, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCheckButton_Cdda); - gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_Cdda, 1, 2, 0, 1, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - GtkCheckButton_Sio = gtk_check_button_new_with_label ("Sio Irq Always Enabled"); - gtk_widget_ref (GtkCheckButton_Sio); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_Sio", GtkCheckButton_Sio, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCheckButton_Sio); - gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_Sio, 0, 1, 1, 2, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - GtkCheckButton_Cpu = gtk_check_button_new_with_label ("Enable Interpreter Cpu"); - gtk_widget_ref (GtkCheckButton_Cpu); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_Cpu", GtkCheckButton_Cpu, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCheckButton_Cpu); - gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_Cpu, 1, 2, 1, 2, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - GtkCheckButton_PsxOut = gtk_check_button_new_with_label ("Enable Console Output"); - gtk_widget_ref (GtkCheckButton_PsxOut); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_PsxOut", GtkCheckButton_PsxOut, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCheckButton_PsxOut); - gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_PsxOut, 1, 2, 2, 3, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - GtkCheckButton_Mdec = gtk_check_button_new_with_label ("Black & White Movies"); - gtk_widget_ref (GtkCheckButton_Mdec); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_Mdec", GtkCheckButton_Mdec, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCheckButton_Mdec); - gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_Mdec, 0, 1, 3, 4, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - GtkCheckButton_SpuIrq = gtk_check_button_new_with_label ("Spu Irq Always Enabled"); - gtk_widget_ref (GtkCheckButton_SpuIrq); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_SpuIrq", GtkCheckButton_SpuIrq, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCheckButton_SpuIrq); - gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_SpuIrq, 0, 1, 2, 3, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - GtkCheckButton_CpuLog = gtk_check_button_new_with_label ("Enable CPU Log"); - gtk_widget_ref (GtkCheckButton_CpuLog); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_CpuLog", GtkCheckButton_CpuLog, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCheckButton_CpuLog); - gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_CpuLog, 1, 2, 3, 4, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - GtkCheckButton_CdTiming = gtk_check_button_new_with_label ("Old Cdrom Timing (Gran Turismo...)"); - gtk_widget_ref (GtkCheckButton_CdTiming); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_CdTiming", GtkCheckButton_CdTiming, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCheckButton_CdTiming); - gtk_box_pack_start (GTK_BOX (vbox15), GtkCheckButton_CdTiming, FALSE, FALSE, 0); - - frame6 = gtk_frame_new ("Psx System Type"); - gtk_widget_ref (frame6); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "frame6", frame6, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (frame6); - gtk_box_pack_start (GTK_BOX (vbox8), frame6, TRUE, TRUE, 0); - gtk_container_set_border_width (GTK_CONTAINER (frame6), 5); - - hbox4 = gtk_hbox_new (FALSE, 0); - gtk_widget_ref (hbox4); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "hbox4", hbox4, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbox4); - gtk_container_add (GTK_CONTAINER (frame6), hbox4); - gtk_container_set_border_width (GTK_CONTAINER (hbox4), 5); - - GtkCheckButton_PsxAuto = gtk_check_button_new_with_label ("Autodetect"); - gtk_widget_ref (GtkCheckButton_PsxAuto); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_PsxAuto", GtkCheckButton_PsxAuto, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCheckButton_PsxAuto); - gtk_box_pack_start (GTK_BOX (hbox4), GtkCheckButton_PsxAuto, FALSE, FALSE, 0); - gtk_widget_set_usize (GtkCheckButton_PsxAuto, 159, -2); - - GtkCombo_PsxType = gtk_combo_new (); - gtk_widget_ref (GtkCombo_PsxType); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCombo_PsxType", GtkCombo_PsxType, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCombo_PsxType); - gtk_box_pack_start (GTK_BOX (hbox4), GtkCombo_PsxType, FALSE, FALSE, 0); - gtk_widget_set_usize (GtkCombo_PsxType, 154, -2); - - combo_entry1 = GTK_COMBO (GtkCombo_PsxType)->entry; - gtk_widget_ref (combo_entry1); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "combo_entry1", combo_entry1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (combo_entry1); - gtk_entry_set_editable (GTK_ENTRY (combo_entry1), FALSE); - - hbuttonbox3 = gtk_hbutton_box_new (); - gtk_widget_ref (hbuttonbox3); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "hbuttonbox3", hbuttonbox3, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbuttonbox3); - gtk_box_pack_start (GTK_BOX (vbox8), hbuttonbox3, TRUE, TRUE, 0); - - button2 = gtk_button_new_with_label ("Ok"); - gtk_widget_ref (button2); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "button2", button2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button2); - gtk_container_add (GTK_CONTAINER (hbuttonbox3), button2); - GTK_WIDGET_SET_FLAGS (button2, GTK_CAN_DEFAULT); - - button3 = gtk_button_new_with_label ("Cancel"); - gtk_widget_ref (button3); - gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "button3", button3, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button3); - gtk_container_add (GTK_CONTAINER (hbuttonbox3), button3); - GTK_WIDGET_SET_FLAGS (button3, GTK_CAN_DEFAULT); - - gtk_signal_connect (GTK_OBJECT (button2), "clicked", - GTK_SIGNAL_FUNC (OnCpu_Ok), - NULL); - gtk_signal_connect (GTK_OBJECT (button3), "clicked", - GTK_SIGNAL_FUNC (OnCpu_Cancel), - NULL); - - return CpuDlg; -} - -GtkWidget* -create_McdsDlg (void) -{ - GtkWidget *McdsDlg; - GtkWidget *vbox10; - GtkWidget *hbox6; - GtkWidget *frame7; - GtkWidget *vbox13; - GtkWidget *scrolledwindow1; - GtkWidget *GtkCList_McdList1; - GtkWidget *label9; - GtkWidget *label10; - GtkWidget *label11; - GtkWidget *label15; - GtkWidget *label16; - GtkWidget *hbuttonbox12; - GtkWidget *GtkButton_SelMcd1; - GtkWidget *GtkButton_Format1; - GtkWidget *GtkButton_Reload1; - GtkWidget *GtkEntry_Mcd1; - GtkWidget *vbuttonbox1; - GtkWidget *button26; - GtkWidget *button28; - GtkWidget *GtkButton_McdPaste; - GtkWidget *button29; - GtkWidget *button30; - GtkWidget *frame8; - GtkWidget *vbox14; - GtkWidget *scrolledwindow2; - GtkWidget *GtkCList_McdList2; - GtkWidget *label12; - GtkWidget *label13; - GtkWidget *label14; - GtkWidget *label17; - GtkWidget *label18; - GtkWidget *hbuttonbox13; - GtkWidget *GtkButton_SelMcd2; - GtkWidget *GtkButton_Format2; - GtkWidget *GtkButton_Reload2; - GtkWidget *GtkEntry_Mcd2; - GtkWidget *hbuttonbox2; - GtkWidget *GtkMcds_Ok; - GtkWidget *GtkMcds_Cancel; - - McdsDlg = gtk_window_new (GTK_WINDOW_DIALOG); - gtk_object_set_data (GTK_OBJECT (McdsDlg), "McdsDlg", McdsDlg); - gtk_container_set_border_width (GTK_CONTAINER (McdsDlg), 5); - gtk_window_set_title (GTK_WINDOW (McdsDlg), "Mcds"); - gtk_window_set_position (GTK_WINDOW (McdsDlg), GTK_WIN_POS_CENTER); - - vbox10 = gtk_vbox_new (FALSE, 5); - gtk_widget_ref (vbox10); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "vbox10", vbox10, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (vbox10); - gtk_container_add (GTK_CONTAINER (McdsDlg), vbox10); - - hbox6 = gtk_hbox_new (FALSE, 0); - gtk_widget_ref (hbox6); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "hbox6", hbox6, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbox6); - gtk_box_pack_start (GTK_BOX (vbox10), hbox6, TRUE, TRUE, 0); - - frame7 = gtk_frame_new ("Memory Card 1"); - gtk_widget_ref (frame7); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "frame7", frame7, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (frame7); - gtk_box_pack_start (GTK_BOX (hbox6), frame7, TRUE, TRUE, 0); - gtk_container_set_border_width (GTK_CONTAINER (frame7), 5); - - vbox13 = gtk_vbox_new (FALSE, 0); - gtk_widget_ref (vbox13); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "vbox13", vbox13, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (vbox13); - gtk_container_add (GTK_CONTAINER (frame7), vbox13); - gtk_container_set_border_width (GTK_CONTAINER (vbox13), 5); - - scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_ref (scrolledwindow1); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "scrolledwindow1", scrolledwindow1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (scrolledwindow1); - gtk_box_pack_start (GTK_BOX (vbox13), scrolledwindow1, TRUE, TRUE, 0); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - - GtkCList_McdList1 = gtk_clist_new (5); - gtk_widget_ref (GtkCList_McdList1); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkCList_McdList1", GtkCList_McdList1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCList_McdList1); - gtk_container_add (GTK_CONTAINER (scrolledwindow1), GtkCList_McdList1); - gtk_widget_set_usize (GtkCList_McdList1, -2, 180); - gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList1), 0, 25); - gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList1), 1, 180); - gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList1), 2, 50); - gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList1), 3, 80); - gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList1), 4, 80); - gtk_clist_column_titles_show (GTK_CLIST (GtkCList_McdList1)); - - label9 = gtk_label_new ("Icon"); - gtk_widget_ref (label9); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label9", label9, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label9); - gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList1), 0, label9); - - label10 = gtk_label_new ("Title"); - gtk_widget_ref (label10); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label10", label10, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label10); - gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList1), 1, label10); - - label11 = gtk_label_new ("Status"); - gtk_widget_ref (label11); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label11", label11, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label11); - gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList1), 2, label11); - - label15 = gtk_label_new ("Game ID"); - gtk_widget_ref (label15); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label15", label15, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label15); - gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList1), 3, label15); - - label16 = gtk_label_new ("Game"); - gtk_widget_ref (label16); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label16", label16, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label16); - gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList1), 4, label16); - - hbuttonbox12 = gtk_hbutton_box_new (); - gtk_widget_ref (hbuttonbox12); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "hbuttonbox12", hbuttonbox12, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbuttonbox12); - gtk_box_pack_start (GTK_BOX (vbox13), hbuttonbox12, TRUE, TRUE, 0); - gtk_widget_set_usize (hbuttonbox12, 240, -2); - gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox12), 0); - gtk_button_box_set_child_size (GTK_BUTTON_BOX (hbuttonbox12), 70, 27); - - GtkButton_SelMcd1 = gtk_button_new_with_label ("Select"); - gtk_widget_ref (GtkButton_SelMcd1); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkButton_SelMcd1", GtkButton_SelMcd1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkButton_SelMcd1); - gtk_container_add (GTK_CONTAINER (hbuttonbox12), GtkButton_SelMcd1); - GTK_WIDGET_SET_FLAGS (GtkButton_SelMcd1, GTK_CAN_DEFAULT); - - GtkButton_Format1 = gtk_button_new_with_label ("Format"); - gtk_widget_ref (GtkButton_Format1); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkButton_Format1", GtkButton_Format1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkButton_Format1); - gtk_container_add (GTK_CONTAINER (hbuttonbox12), GtkButton_Format1); - GTK_WIDGET_SET_FLAGS (GtkButton_Format1, GTK_CAN_DEFAULT); - - GtkButton_Reload1 = gtk_button_new_with_label ("Reload"); - gtk_widget_ref (GtkButton_Reload1); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkButton_Reload1", GtkButton_Reload1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkButton_Reload1); - gtk_container_add (GTK_CONTAINER (hbuttonbox12), GtkButton_Reload1); - GTK_WIDGET_SET_FLAGS (GtkButton_Reload1, GTK_CAN_DEFAULT); - - GtkEntry_Mcd1 = gtk_entry_new (); - gtk_widget_ref (GtkEntry_Mcd1); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkEntry_Mcd1", GtkEntry_Mcd1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkEntry_Mcd1); - gtk_box_pack_start (GTK_BOX (vbox13), GtkEntry_Mcd1, FALSE, FALSE, 0); - - vbuttonbox1 = gtk_vbutton_box_new (); - gtk_widget_ref (vbuttonbox1); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "vbuttonbox1", vbuttonbox1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (vbuttonbox1); - gtk_box_pack_start (GTK_BOX (hbox6), vbuttonbox1, TRUE, FALSE, 0); - gtk_button_box_set_layout (GTK_BUTTON_BOX (vbuttonbox1), GTK_BUTTONBOX_SPREAD); - gtk_button_box_set_spacing (GTK_BUTTON_BOX (vbuttonbox1), 0); - gtk_button_box_set_child_size (GTK_BUTTON_BOX (vbuttonbox1), 64, 27); - gtk_button_box_set_child_ipadding (GTK_BUTTON_BOX (vbuttonbox1), 0, 0); - - button26 = gtk_button_new_with_label ("-> Copy ->"); - gtk_widget_ref (button26); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "button26", button26, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button26); - gtk_container_add (GTK_CONTAINER (vbuttonbox1), button26); - GTK_WIDGET_SET_FLAGS (button26, GTK_CAN_DEFAULT); - - button28 = gtk_button_new_with_label ("<- Copy <-"); - gtk_widget_ref (button28); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "button28", button28, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button28); - gtk_container_add (GTK_CONTAINER (vbuttonbox1), button28); - GTK_WIDGET_SET_FLAGS (button28, GTK_CAN_DEFAULT); - - GtkButton_McdPaste = gtk_button_new_with_label ("Paste"); - gtk_widget_ref (GtkButton_McdPaste); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkButton_McdPaste", GtkButton_McdPaste, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkButton_McdPaste); - gtk_container_add (GTK_CONTAINER (vbuttonbox1), GtkButton_McdPaste); - GTK_WIDGET_SET_FLAGS (GtkButton_McdPaste, GTK_CAN_DEFAULT); - - button29 = gtk_button_new_with_label ("Un/Delete ->"); - gtk_widget_ref (button29); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "button29", button29, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button29); - gtk_container_add (GTK_CONTAINER (vbuttonbox1), button29); - GTK_WIDGET_SET_FLAGS (button29, GTK_CAN_DEFAULT); - - button30 = gtk_button_new_with_label ("<- Un/Delete"); - gtk_widget_ref (button30); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "button30", button30, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (button30); - gtk_container_add (GTK_CONTAINER (vbuttonbox1), button30); - GTK_WIDGET_SET_FLAGS (button30, GTK_CAN_DEFAULT); - - frame8 = gtk_frame_new ("Memory Card 2"); - gtk_widget_ref (frame8); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "frame8", frame8, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (frame8); - gtk_box_pack_start (GTK_BOX (hbox6), frame8, TRUE, TRUE, 0); - gtk_container_set_border_width (GTK_CONTAINER (frame8), 5); - - vbox14 = gtk_vbox_new (FALSE, 0); - gtk_widget_ref (vbox14); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "vbox14", vbox14, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (vbox14); - gtk_container_add (GTK_CONTAINER (frame8), vbox14); - gtk_container_set_border_width (GTK_CONTAINER (vbox14), 5); - - scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_ref (scrolledwindow2); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "scrolledwindow2", scrolledwindow2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (scrolledwindow2); - gtk_box_pack_start (GTK_BOX (vbox14), scrolledwindow2, TRUE, TRUE, 0); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow2), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - - GtkCList_McdList2 = gtk_clist_new (5); - gtk_widget_ref (GtkCList_McdList2); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkCList_McdList2", GtkCList_McdList2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkCList_McdList2); - gtk_container_add (GTK_CONTAINER (scrolledwindow2), GtkCList_McdList2); - gtk_widget_set_usize (GtkCList_McdList2, -2, 180); - gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList2), 0, 25); - gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList2), 1, 180); - gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList2), 2, 50); - gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList2), 3, 80); - gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList2), 4, 80); - gtk_clist_column_titles_show (GTK_CLIST (GtkCList_McdList2)); - - label12 = gtk_label_new ("Icon"); - gtk_widget_ref (label12); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label12", label12, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label12); - gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList2), 0, label12); - - label13 = gtk_label_new ("Title"); - gtk_widget_ref (label13); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label13", label13, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label13); - gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList2), 1, label13); - - label14 = gtk_label_new ("Status"); - gtk_widget_ref (label14); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label14", label14, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label14); - gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList2), 2, label14); - - label17 = gtk_label_new ("Game ID"); - gtk_widget_ref (label17); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label17", label17, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label17); - gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList2), 3, label17); - - label18 = gtk_label_new ("Game"); - gtk_widget_ref (label18); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label18", label18, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (label18); - gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList2), 4, label18); - - hbuttonbox13 = gtk_hbutton_box_new (); - gtk_widget_ref (hbuttonbox13); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "hbuttonbox13", hbuttonbox13, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbuttonbox13); - gtk_box_pack_start (GTK_BOX (vbox14), hbuttonbox13, TRUE, TRUE, 0); - gtk_widget_set_usize (hbuttonbox13, 240, -2); - gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox13), 0); - gtk_button_box_set_child_size (GTK_BUTTON_BOX (hbuttonbox13), 70, 27); - - GtkButton_SelMcd2 = gtk_button_new_with_label ("Select"); - gtk_widget_ref (GtkButton_SelMcd2); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkButton_SelMcd2", GtkButton_SelMcd2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkButton_SelMcd2); - gtk_container_add (GTK_CONTAINER (hbuttonbox13), GtkButton_SelMcd2); - GTK_WIDGET_SET_FLAGS (GtkButton_SelMcd2, GTK_CAN_DEFAULT); - - GtkButton_Format2 = gtk_button_new_with_label ("Format"); - gtk_widget_ref (GtkButton_Format2); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkButton_Format2", GtkButton_Format2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkButton_Format2); - gtk_container_add (GTK_CONTAINER (hbuttonbox13), GtkButton_Format2); - GTK_WIDGET_SET_FLAGS (GtkButton_Format2, GTK_CAN_DEFAULT); - - GtkButton_Reload2 = gtk_button_new_with_label ("Reload"); - gtk_widget_ref (GtkButton_Reload2); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkButton_Reload2", GtkButton_Reload2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkButton_Reload2); - gtk_container_add (GTK_CONTAINER (hbuttonbox13), GtkButton_Reload2); - GTK_WIDGET_SET_FLAGS (GtkButton_Reload2, GTK_CAN_DEFAULT); - - GtkEntry_Mcd2 = gtk_entry_new (); - gtk_widget_ref (GtkEntry_Mcd2); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkEntry_Mcd2", GtkEntry_Mcd2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkEntry_Mcd2); - gtk_box_pack_start (GTK_BOX (vbox14), GtkEntry_Mcd2, FALSE, FALSE, 0); - - hbuttonbox2 = gtk_hbutton_box_new (); - gtk_widget_ref (hbuttonbox2); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "hbuttonbox2", hbuttonbox2, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbuttonbox2); - gtk_box_pack_start (GTK_BOX (vbox10), hbuttonbox2, TRUE, TRUE, 0); - - GtkMcds_Ok = gtk_button_new_with_label ("Ok"); - gtk_widget_ref (GtkMcds_Ok); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkMcds_Ok", GtkMcds_Ok, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkMcds_Ok); - gtk_container_add (GTK_CONTAINER (hbuttonbox2), GtkMcds_Ok); - GTK_WIDGET_SET_FLAGS (GtkMcds_Ok, GTK_CAN_DEFAULT); - - GtkMcds_Cancel = gtk_button_new_with_label ("Cancel"); - gtk_widget_ref (GtkMcds_Cancel); - gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkMcds_Cancel", GtkMcds_Cancel, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkMcds_Cancel); - gtk_container_add (GTK_CONTAINER (hbuttonbox2), GtkMcds_Cancel); - GTK_WIDGET_SET_FLAGS (GtkMcds_Cancel, GTK_CAN_DEFAULT); - - gtk_signal_connect (GTK_OBJECT (GtkButton_SelMcd1), "clicked", - GTK_SIGNAL_FUNC (OnMcd_FS1), - NULL); - gtk_signal_connect (GTK_OBJECT (GtkButton_Format1), "clicked", - GTK_SIGNAL_FUNC (OnMcd_Format1), - NULL); - gtk_signal_connect (GTK_OBJECT (GtkButton_Reload1), "clicked", - GTK_SIGNAL_FUNC (OnMcd_Reload1), - NULL); - gtk_signal_connect (GTK_OBJECT (button26), "clicked", - GTK_SIGNAL_FUNC (OnMcd_CopyTo2), - NULL); - gtk_signal_connect (GTK_OBJECT (button28), "clicked", - GTK_SIGNAL_FUNC (OnMcd_CopyTo1), - NULL); - gtk_signal_connect (GTK_OBJECT (GtkButton_McdPaste), "clicked", - GTK_SIGNAL_FUNC (OnMcd_Paste), - NULL); - gtk_signal_connect (GTK_OBJECT (button29), "clicked", - GTK_SIGNAL_FUNC (OnMcd_Delete2), - NULL); - gtk_signal_connect (GTK_OBJECT (button30), "clicked", - GTK_SIGNAL_FUNC (OnMcd_Delete1), - NULL); - gtk_signal_connect (GTK_OBJECT (GtkButton_SelMcd2), "clicked", - GTK_SIGNAL_FUNC (OnMcd_FS2), - NULL); - gtk_signal_connect (GTK_OBJECT (GtkButton_Format2), "clicked", - GTK_SIGNAL_FUNC (OnMcd_Format2), - NULL); - gtk_signal_connect (GTK_OBJECT (GtkButton_Reload2), "clicked", - GTK_SIGNAL_FUNC (OnMcd_Reload2), - NULL); - gtk_signal_connect (GTK_OBJECT (GtkMcds_Ok), "clicked", - GTK_SIGNAL_FUNC (OnMcd_Ok), - NULL); - gtk_signal_connect (GTK_OBJECT (GtkMcds_Cancel), "clicked", - GTK_SIGNAL_FUNC (OnMcd_Cancel), - NULL); - - return McdsDlg; -} - -GtkWidget* -create_DebugDlg (void) -{ - GtkWidget *DebugDlg; - GtkWidget *vbox17; - GtkWidget *scrolledwindow3; - GtkWidget *text1; - GtkWidget *hbuttonbox14; - GtkWidget *GtkButton_DbgOk; - - DebugDlg = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_object_set_data (GTK_OBJECT (DebugDlg), "DebugDlg", DebugDlg); - gtk_container_set_border_width (GTK_CONTAINER (DebugDlg), 5); - gtk_window_set_title (GTK_WINDOW (DebugDlg), "Debug"); - - vbox17 = gtk_vbox_new (FALSE, 0); - gtk_widget_ref (vbox17); - gtk_object_set_data_full (GTK_OBJECT (DebugDlg), "vbox17", vbox17, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (vbox17); - gtk_container_add (GTK_CONTAINER (DebugDlg), vbox17); - - scrolledwindow3 = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_ref (scrolledwindow3); - gtk_object_set_data_full (GTK_OBJECT (DebugDlg), "scrolledwindow3", scrolledwindow3, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (scrolledwindow3); - gtk_box_pack_start (GTK_BOX (vbox17), scrolledwindow3, TRUE, TRUE, 0); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow3), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); - - text1 = gtk_text_new (NULL, NULL); - gtk_widget_ref (text1); - gtk_object_set_data_full (GTK_OBJECT (DebugDlg), "text1", text1, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (text1); - gtk_container_add (GTK_CONTAINER (scrolledwindow3), text1); - gtk_text_insert (GTK_TEXT (text1), NULL, NULL, NULL, - "Test", 4); - - hbuttonbox14 = gtk_hbutton_box_new (); - gtk_widget_ref (hbuttonbox14); - gtk_object_set_data_full (GTK_OBJECT (DebugDlg), "hbuttonbox14", hbuttonbox14, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (hbuttonbox14); - gtk_box_pack_start (GTK_BOX (vbox17), hbuttonbox14, TRUE, TRUE, 0); - - GtkButton_DbgOk = gtk_button_new_with_label ("Ok"); - gtk_widget_ref (GtkButton_DbgOk); - gtk_object_set_data_full (GTK_OBJECT (DebugDlg), "GtkButton_DbgOk", GtkButton_DbgOk, - (GtkDestroyNotify) gtk_widget_unref); - gtk_widget_show (GtkButton_DbgOk); - gtk_container_add (GTK_CONTAINER (hbuttonbox14), GtkButton_DbgOk); - GTK_WIDGET_SET_FLAGS (GtkButton_DbgOk, GTK_CAN_DEFAULT); - - gtk_signal_connect (GTK_OBJECT (GtkButton_DbgOk), "clicked", - GTK_SIGNAL_FUNC (OnDebug_Ok), - NULL); - - return DebugDlg; -} - +/*
+ * DO NOT EDIT THIS FILE - it is generated by Glade.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <gdk/gdkkeysyms.h>
+#include <gtk/gtk.h>
+
+#include "GladeCalls.h"
+#include "GladeGui.h"
+#include "GladeFuncs.h"
+
+GtkWidget*
+create_MainWindow (void)
+{
+ GtkWidget *MainWindow;
+ GtkWidget *vbox1;
+ GtkWidget *menubar1;
+ GtkWidget *item1;
+ GtkWidget *item1_menu;
+ GtkAccelGroup *item1_menu_accels;
+ GtkWidget *RunCd;
+ GtkWidget *RunCdBiois;
+ GtkWidget *Run_Exe;
+ GtkWidget *separator2;
+ GtkWidget *exit2;
+ GtkWidget *emulator1;
+ GtkWidget *emulator1_menu;
+ GtkAccelGroup *emulator1_menu_accels;
+ GtkWidget *run1;
+ GtkWidget *reset1;
+ GtkWidget *configuration1;
+ GtkWidget *configuration1_menu;
+ GtkAccelGroup *configuration1_menu_accels;
+ GtkWidget *plugins___bios1;
+ GtkWidget *separator3;
+ GtkWidget *graphics1;
+ GtkWidget *sound1;
+ GtkWidget *cd_rom1;
+ GtkWidget *controllers1;
+ GtkWidget *separator4;
+ GtkWidget *cpu1;
+ GtkWidget *memory_cards1;
+ GtkWidget *debug1;
+ GtkWidget *help1;
+ GtkWidget *help1_menu;
+ GtkAccelGroup *help1_menu_accels;
+ GtkWidget *about_pcsx1;
+
+ MainWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_object_set_data (GTK_OBJECT (MainWindow), "MainWindow", MainWindow);
+ gtk_widget_set_usize (MainWindow, 350, 200);
+ gtk_window_set_title (GTK_WINDOW (MainWindow), "PCSX");
+ gtk_window_set_position (GTK_WINDOW (MainWindow), GTK_WIN_POS_CENTER);
+ gtk_window_set_policy (GTK_WINDOW (MainWindow), FALSE, FALSE, FALSE);
+
+ vbox1 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_ref (vbox1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "vbox1", vbox1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (vbox1);
+ gtk_container_add (GTK_CONTAINER (MainWindow), vbox1);
+
+ menubar1 = gtk_menu_bar_new ();
+ gtk_widget_ref (menubar1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "menubar1", menubar1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (menubar1);
+ gtk_box_pack_start (GTK_BOX (vbox1), menubar1, FALSE, FALSE, 0);
+
+ item1 = gtk_menu_item_new_with_label ("File");
+ gtk_widget_ref (item1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "item1", item1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (item1);
+ gtk_container_add (GTK_CONTAINER (menubar1), item1);
+
+ item1_menu = gtk_menu_new ();
+ gtk_widget_ref (item1_menu);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "item1_menu", item1_menu,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (item1), item1_menu);
+ item1_menu_accels = gtk_menu_ensure_uline_accel_group (GTK_MENU (item1_menu));
+
+ RunCd = gtk_menu_item_new_with_label ("Run Cd");
+ gtk_widget_ref (RunCd);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "RunCd", RunCd,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (RunCd);
+ gtk_container_add (GTK_CONTAINER (item1_menu), RunCd);
+
+ RunCdBiois = gtk_menu_item_new_with_label ("Run Cd Through Bios");
+ gtk_widget_ref (RunCdBiois);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "RunCdBiois", RunCdBiois,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (RunCdBiois);
+ gtk_container_add (GTK_CONTAINER (item1_menu), RunCdBiois);
+
+ Run_Exe = gtk_menu_item_new_with_label ("Run Exe");
+ gtk_widget_ref (Run_Exe);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "Run_Exe", Run_Exe,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (Run_Exe);
+ gtk_container_add (GTK_CONTAINER (item1_menu), Run_Exe);
+
+ separator2 = gtk_menu_item_new ();
+ gtk_widget_ref (separator2);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "separator2", separator2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (separator2);
+ gtk_container_add (GTK_CONTAINER (item1_menu), separator2);
+ gtk_widget_set_sensitive (separator2, FALSE);
+
+ exit2 = gtk_menu_item_new_with_label ("Exit");
+ gtk_widget_ref (exit2);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "exit2", exit2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (exit2);
+ gtk_container_add (GTK_CONTAINER (item1_menu), exit2);
+
+ emulator1 = gtk_menu_item_new_with_label ("Emulator");
+ gtk_widget_ref (emulator1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "emulator1", emulator1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (emulator1);
+ gtk_container_add (GTK_CONTAINER (menubar1), emulator1);
+
+ emulator1_menu = gtk_menu_new ();
+ gtk_widget_ref (emulator1_menu);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "emulator1_menu", emulator1_menu,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (emulator1), emulator1_menu);
+ emulator1_menu_accels = gtk_menu_ensure_uline_accel_group (GTK_MENU (emulator1_menu));
+
+ run1 = gtk_menu_item_new_with_label ("Run");
+ gtk_widget_ref (run1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "run1", run1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (run1);
+ gtk_container_add (GTK_CONTAINER (emulator1_menu), run1);
+
+ reset1 = gtk_menu_item_new_with_label ("Reset");
+ gtk_widget_ref (reset1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "reset1", reset1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (reset1);
+ gtk_container_add (GTK_CONTAINER (emulator1_menu), reset1);
+
+ configuration1 = gtk_menu_item_new_with_label ("Configuration");
+ gtk_widget_ref (configuration1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "configuration1", configuration1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (configuration1);
+ gtk_container_add (GTK_CONTAINER (menubar1), configuration1);
+
+ configuration1_menu = gtk_menu_new ();
+ gtk_widget_ref (configuration1_menu);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "configuration1_menu", configuration1_menu,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (configuration1), configuration1_menu);
+ configuration1_menu_accels = gtk_menu_ensure_uline_accel_group (GTK_MENU (configuration1_menu));
+
+ plugins___bios1 = gtk_menu_item_new_with_label ("Plugins & Bios");
+ gtk_widget_ref (plugins___bios1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "plugins___bios1", plugins___bios1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (plugins___bios1);
+ gtk_container_add (GTK_CONTAINER (configuration1_menu), plugins___bios1);
+
+ separator3 = gtk_menu_item_new ();
+ gtk_widget_ref (separator3);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "separator3", separator3,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (separator3);
+ gtk_container_add (GTK_CONTAINER (configuration1_menu), separator3);
+ gtk_widget_set_sensitive (separator3, FALSE);
+
+ graphics1 = gtk_menu_item_new_with_label ("Graphics");
+ gtk_widget_ref (graphics1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "graphics1", graphics1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (graphics1);
+ gtk_container_add (GTK_CONTAINER (configuration1_menu), graphics1);
+
+ sound1 = gtk_menu_item_new_with_label ("Sound");
+ gtk_widget_ref (sound1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "sound1", sound1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (sound1);
+ gtk_container_add (GTK_CONTAINER (configuration1_menu), sound1);
+
+ cd_rom1 = gtk_menu_item_new_with_label ("CD-ROM");
+ gtk_widget_ref (cd_rom1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "cd_rom1", cd_rom1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (cd_rom1);
+ gtk_container_add (GTK_CONTAINER (configuration1_menu), cd_rom1);
+
+ controllers1 = gtk_menu_item_new_with_label ("Controllers");
+ gtk_widget_ref (controllers1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "controllers1", controllers1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (controllers1);
+ gtk_container_add (GTK_CONTAINER (configuration1_menu), controllers1);
+
+ separator4 = gtk_menu_item_new ();
+ gtk_widget_ref (separator4);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "separator4", separator4,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (separator4);
+ gtk_container_add (GTK_CONTAINER (configuration1_menu), separator4);
+ gtk_widget_set_sensitive (separator4, FALSE);
+
+ cpu1 = gtk_menu_item_new_with_label ("Cpu");
+ gtk_widget_ref (cpu1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "cpu1", cpu1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (cpu1);
+ gtk_container_add (GTK_CONTAINER (configuration1_menu), cpu1);
+
+ memory_cards1 = gtk_menu_item_new_with_label ("Memory Cards");
+ gtk_widget_ref (memory_cards1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "memory_cards1", memory_cards1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (memory_cards1);
+ gtk_container_add (GTK_CONTAINER (configuration1_menu), memory_cards1);
+
+ debug1 = gtk_menu_item_new_with_label ("Debug");
+ gtk_widget_ref (debug1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "debug1", debug1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (debug1);
+ gtk_container_add (GTK_CONTAINER (menubar1), debug1);
+
+ help1 = gtk_menu_item_new_with_label ("Help");
+ gtk_widget_ref (help1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "help1", help1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (help1);
+ gtk_container_add (GTK_CONTAINER (menubar1), help1);
+
+ help1_menu = gtk_menu_new ();
+ gtk_widget_ref (help1_menu);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "help1_menu", help1_menu,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (help1), help1_menu);
+ help1_menu_accels = gtk_menu_ensure_uline_accel_group (GTK_MENU (help1_menu));
+
+ about_pcsx1 = gtk_menu_item_new_with_label ("About P\251SX");
+ gtk_widget_ref (about_pcsx1);
+ gtk_object_set_data_full (GTK_OBJECT (MainWindow), "about_pcsx1", about_pcsx1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (about_pcsx1);
+ gtk_container_add (GTK_CONTAINER (help1_menu), about_pcsx1);
+
+ gtk_signal_connect (GTK_OBJECT (MainWindow), "destroy",
+ GTK_SIGNAL_FUNC (OnDestroy),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (RunCd), "activate",
+ GTK_SIGNAL_FUNC (OnFile_RunCd),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (RunCdBiois), "activate",
+ GTK_SIGNAL_FUNC (OnFile_RunCdBios),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (Run_Exe), "activate",
+ GTK_SIGNAL_FUNC (OnFile_RunExe),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (exit2), "activate",
+ GTK_SIGNAL_FUNC (OnFile_Exit),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (run1), "activate",
+ GTK_SIGNAL_FUNC (OnEmu_Run),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (reset1), "activate",
+ GTK_SIGNAL_FUNC (OnEmu_Reset),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (plugins___bios1), "activate",
+ GTK_SIGNAL_FUNC (OnConf_Conf),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (graphics1), "activate",
+ GTK_SIGNAL_FUNC (OnConf_Gpu),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (sound1), "activate",
+ GTK_SIGNAL_FUNC (OnConf_Spu),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (cd_rom1), "activate",
+ GTK_SIGNAL_FUNC (OnConf_Cdr),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (controllers1), "activate",
+ GTK_SIGNAL_FUNC (OnConf_Pads),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (cpu1), "activate",
+ GTK_SIGNAL_FUNC (OnConf_Cpu),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (memory_cards1), "activate",
+ GTK_SIGNAL_FUNC (OnConf_Mcds),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (debug1), "activate",
+ GTK_SIGNAL_FUNC (OnDebug),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (about_pcsx1), "activate",
+ GTK_SIGNAL_FUNC (OnHelp_About),
+ NULL);
+
+ return MainWindow;
+}
+
+GtkWidget*
+create_AboutDlg (void)
+{
+ GtkWidget *AboutDlg;
+ GtkWidget *vbox2;
+ GtkWidget *packer1;
+ GtkWidget *hbox1;
+ GtkWidget *vbox4;
+ GtkWidget *GtkAbout_LabelVersion;
+ GtkWidget *frame1;
+ GtkWidget *vbox6;
+ GtkWidget *GtkAbout_LabelAuthors;
+ GtkWidget *pixmap1;
+ GtkWidget *frame2;
+ GtkWidget *vbox5;
+ GtkWidget *GtkAbout_LabelGreets;
+ GtkWidget *hbuttonbox1;
+ GtkWidget *button1;
+
+ AboutDlg = gtk_window_new (GTK_WINDOW_DIALOG);
+ gtk_object_set_data (GTK_OBJECT (AboutDlg), "AboutDlg", AboutDlg);
+ gtk_container_set_border_width (GTK_CONTAINER (AboutDlg), 10);
+ gtk_window_set_title (GTK_WINDOW (AboutDlg), "Pcsx About");
+ gtk_window_set_position (GTK_WINDOW (AboutDlg), GTK_WIN_POS_CENTER);
+
+ vbox2 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_ref (vbox2);
+ gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "vbox2", vbox2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (vbox2);
+ gtk_container_add (GTK_CONTAINER (AboutDlg), vbox2);
+
+ packer1 = gtk_packer_new ();
+ gtk_widget_ref (packer1);
+ gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "packer1", packer1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (packer1);
+ gtk_box_pack_start (GTK_BOX (vbox2), packer1, FALSE, FALSE, 0);
+
+ hbox1 = gtk_hbox_new (FALSE, 0);
+ gtk_widget_ref (hbox1);
+ gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "hbox1", hbox1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbox1);
+ gtk_box_pack_start (GTK_BOX (vbox2), hbox1, TRUE, TRUE, 0);
+
+ vbox4 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_ref (vbox4);
+ gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "vbox4", vbox4,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (vbox4);
+ gtk_box_pack_start (GTK_BOX (hbox1), vbox4, TRUE, TRUE, 0);
+
+ GtkAbout_LabelVersion = gtk_label_new ("PCSX\r\r\nVersion x.x");
+ gtk_widget_ref (GtkAbout_LabelVersion);
+ gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "GtkAbout_LabelVersion", GtkAbout_LabelVersion,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkAbout_LabelVersion);
+ gtk_box_pack_start (GTK_BOX (vbox4), GtkAbout_LabelVersion, FALSE, FALSE, 0);
+
+ frame1 = gtk_frame_new (NULL);
+ gtk_widget_ref (frame1);
+ gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "frame1", frame1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (frame1);
+ gtk_box_pack_start (GTK_BOX (vbox4), frame1, FALSE, FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (frame1), 5);
+
+ vbox6 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_ref (vbox6);
+ gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "vbox6", vbox6,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (vbox6);
+ gtk_container_add (GTK_CONTAINER (frame1), vbox6);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox6), 5);
+
+ GtkAbout_LabelAuthors = gtk_label_new ("written by...");
+ gtk_widget_ref (GtkAbout_LabelAuthors);
+ gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "GtkAbout_LabelAuthors", GtkAbout_LabelAuthors,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkAbout_LabelAuthors);
+ gtk_box_pack_start (GTK_BOX (vbox6), GtkAbout_LabelAuthors, FALSE, FALSE, 0);
+
+ pixmap1 = create_pixmap (AboutDlg, "pcsxAbout.xpm");
+ gtk_widget_ref (pixmap1);
+ gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "pixmap1", pixmap1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (pixmap1);
+ gtk_box_pack_start (GTK_BOX (hbox1), pixmap1, TRUE, TRUE, 0);
+
+ frame2 = gtk_frame_new (NULL);
+ gtk_widget_ref (frame2);
+ gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "frame2", frame2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (frame2);
+ gtk_box_pack_start (GTK_BOX (vbox2), frame2, FALSE, FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (frame2), 5);
+
+ vbox5 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_ref (vbox5);
+ gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "vbox5", vbox5,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (vbox5);
+ gtk_container_add (GTK_CONTAINER (frame2), vbox5);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox5), 5);
+
+ GtkAbout_LabelGreets = gtk_label_new ("greets to...");
+ gtk_widget_ref (GtkAbout_LabelGreets);
+ gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "GtkAbout_LabelGreets", GtkAbout_LabelGreets,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkAbout_LabelGreets);
+ gtk_box_pack_start (GTK_BOX (vbox5), GtkAbout_LabelGreets, FALSE, FALSE, 0);
+
+ hbuttonbox1 = gtk_hbutton_box_new ();
+ gtk_widget_ref (hbuttonbox1);
+ gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "hbuttonbox1", hbuttonbox1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbuttonbox1);
+ gtk_box_pack_start (GTK_BOX (vbox2), hbuttonbox1, TRUE, TRUE, 0);
+
+ button1 = gtk_button_new_with_label ("Ok");
+ gtk_widget_ref (button1);
+ gtk_object_set_data_full (GTK_OBJECT (AboutDlg), "button1", button1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button1);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox1), button1);
+ GTK_WIDGET_SET_FLAGS (button1, GTK_CAN_DEFAULT);
+
+ gtk_signal_connect (GTK_OBJECT (button1), "clicked",
+ GTK_SIGNAL_FUNC (OnHelpAbout_Ok),
+ NULL);
+
+ return AboutDlg;
+}
+
+GtkWidget*
+create_ConfDlg (void)
+{
+ GtkWidget *ConfDlg;
+ GtkWidget *vbox12;
+ GtkWidget *table2;
+ GtkWidget *GtkCombo_Pad1;
+ GtkWidget *combo_entry4;
+ GtkWidget *GtkCombo_Pad2;
+ GtkWidget *combo_entry5;
+ GtkWidget *GtkCombo_Cdr;
+ GtkWidget *combo_entry6;
+ GtkWidget *GtkCombo_Bios;
+ GtkWidget *combo_entry7;
+ GtkWidget *hbuttonbox5;
+ GtkWidget *button6;
+ GtkWidget *button7;
+ GtkWidget *button8;
+ GtkWidget *hbuttonbox6;
+ GtkWidget *button9;
+ GtkWidget *button10;
+ GtkWidget *button11;
+ GtkWidget *hbuttonbox7;
+ GtkWidget *button12;
+ GtkWidget *button13;
+ GtkWidget *button14;
+ GtkWidget *hbuttonbox8;
+ GtkWidget *button15;
+ GtkWidget *button16;
+ GtkWidget *button17;
+ GtkWidget *hbuttonbox9;
+ GtkWidget *button18;
+ GtkWidget *button19;
+ GtkWidget *button20;
+ GtkWidget *label2;
+ GtkWidget *label1;
+ GtkWidget *label3;
+ GtkWidget *label5;
+ GtkWidget *label6;
+ GtkWidget *label4;
+ GtkWidget *GtkCombo_Gpu;
+ GtkWidget *combo_entry2;
+ GtkWidget *GtkCombo_Spu;
+ GtkWidget *combo_entry3;
+ GtkWidget *hbox5;
+ GtkWidget *hbuttonbox11;
+ GtkWidget *button22;
+ GtkWidget *button23;
+ GtkWidget *hbuttonbox10;
+ GtkWidget *button4;
+ GtkWidget *button25;
+
+ ConfDlg = gtk_window_new (GTK_WINDOW_DIALOG);
+ gtk_object_set_data (GTK_OBJECT (ConfDlg), "ConfDlg", ConfDlg);
+ gtk_container_set_border_width (GTK_CONTAINER (ConfDlg), 10);
+ gtk_window_set_title (GTK_WINDOW (ConfDlg), "Conf");
+ gtk_window_set_position (GTK_WINDOW (ConfDlg), GTK_WIN_POS_CENTER);
+
+ vbox12 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_ref (vbox12);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "vbox12", vbox12,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (vbox12);
+ gtk_container_add (GTK_CONTAINER (ConfDlg), vbox12);
+
+ table2 = gtk_table_new (9, 2, FALSE);
+ gtk_widget_ref (table2);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "table2", table2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (table2);
+ gtk_box_pack_start (GTK_BOX (vbox12), table2, TRUE, TRUE, 0);
+ gtk_table_set_col_spacings (GTK_TABLE (table2), 15);
+
+ GtkCombo_Pad1 = gtk_combo_new ();
+ gtk_widget_ref (GtkCombo_Pad1);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "GtkCombo_Pad1", GtkCombo_Pad1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCombo_Pad1);
+ gtk_table_attach (GTK_TABLE (table2), GtkCombo_Pad1, 0, 1, 4, 5,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ combo_entry4 = GTK_COMBO (GtkCombo_Pad1)->entry;
+ gtk_widget_ref (combo_entry4);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "combo_entry4", combo_entry4,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (combo_entry4);
+
+ GtkCombo_Pad2 = gtk_combo_new ();
+ gtk_widget_ref (GtkCombo_Pad2);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "GtkCombo_Pad2", GtkCombo_Pad2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCombo_Pad2);
+ gtk_table_attach (GTK_TABLE (table2), GtkCombo_Pad2, 1, 2, 4, 5,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ combo_entry5 = GTK_COMBO (GtkCombo_Pad2)->entry;
+ gtk_widget_ref (combo_entry5);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "combo_entry5", combo_entry5,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (combo_entry5);
+
+ GtkCombo_Cdr = gtk_combo_new ();
+ gtk_widget_ref (GtkCombo_Cdr);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "GtkCombo_Cdr", GtkCombo_Cdr,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCombo_Cdr);
+ gtk_table_attach (GTK_TABLE (table2), GtkCombo_Cdr, 0, 1, 7, 8,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ combo_entry6 = GTK_COMBO (GtkCombo_Cdr)->entry;
+ gtk_widget_ref (combo_entry6);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "combo_entry6", combo_entry6,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (combo_entry6);
+
+ GtkCombo_Bios = gtk_combo_new ();
+ gtk_widget_ref (GtkCombo_Bios);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "GtkCombo_Bios", GtkCombo_Bios,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCombo_Bios);
+ gtk_table_attach (GTK_TABLE (table2), GtkCombo_Bios, 1, 2, 7, 8,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ combo_entry7 = GTK_COMBO (GtkCombo_Bios)->entry;
+ gtk_widget_ref (combo_entry7);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "combo_entry7", combo_entry7,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (combo_entry7);
+
+ hbuttonbox5 = gtk_hbutton_box_new ();
+ gtk_widget_ref (hbuttonbox5);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbuttonbox5", hbuttonbox5,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbuttonbox5);
+ gtk_table_attach (GTK_TABLE (table2), hbuttonbox5, 0, 1, 8, 9,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
+ gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox5), 0);
+
+ button6 = gtk_button_new_with_label ("Configure");
+ gtk_widget_ref (button6);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button6", button6,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button6);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox5), button6);
+ GTK_WIDGET_SET_FLAGS (button6, GTK_CAN_DEFAULT);
+
+ button7 = gtk_button_new_with_label ("Test");
+ gtk_widget_ref (button7);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button7", button7,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button7);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox5), button7);
+ GTK_WIDGET_SET_FLAGS (button7, GTK_CAN_DEFAULT);
+
+ button8 = gtk_button_new_with_label ("About");
+ gtk_widget_ref (button8);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button8", button8,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button8);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox5), button8);
+ GTK_WIDGET_SET_FLAGS (button8, GTK_CAN_DEFAULT);
+
+ hbuttonbox6 = gtk_hbutton_box_new ();
+ gtk_widget_ref (hbuttonbox6);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbuttonbox6", hbuttonbox6,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbuttonbox6);
+ gtk_table_attach (GTK_TABLE (table2), hbuttonbox6, 1, 2, 5, 6,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
+ gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox6), 0);
+
+ button9 = gtk_button_new_with_label ("Configure");
+ gtk_widget_ref (button9);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button9", button9,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button9);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox6), button9);
+ GTK_WIDGET_SET_FLAGS (button9, GTK_CAN_DEFAULT);
+
+ button10 = gtk_button_new_with_label ("Test");
+ gtk_widget_ref (button10);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button10", button10,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button10);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox6), button10);
+ GTK_WIDGET_SET_FLAGS (button10, GTK_CAN_DEFAULT);
+
+ button11 = gtk_button_new_with_label ("About");
+ gtk_widget_ref (button11);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button11", button11,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button11);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox6), button11);
+ GTK_WIDGET_SET_FLAGS (button11, GTK_CAN_DEFAULT);
+
+ hbuttonbox7 = gtk_hbutton_box_new ();
+ gtk_widget_ref (hbuttonbox7);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbuttonbox7", hbuttonbox7,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbuttonbox7);
+ gtk_table_attach (GTK_TABLE (table2), hbuttonbox7, 0, 1, 5, 6,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (GTK_FILL), 0, 0);
+ gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox7), 0);
+
+ button12 = gtk_button_new_with_label ("Configure");
+ gtk_widget_ref (button12);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button12", button12,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button12);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox7), button12);
+ GTK_WIDGET_SET_FLAGS (button12, GTK_CAN_DEFAULT);
+
+ button13 = gtk_button_new_with_label ("Test");
+ gtk_widget_ref (button13);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button13", button13,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button13);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox7), button13);
+ GTK_WIDGET_SET_FLAGS (button13, GTK_CAN_DEFAULT);
+
+ button14 = gtk_button_new_with_label ("About");
+ gtk_widget_ref (button14);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button14", button14,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button14);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox7), button14);
+ GTK_WIDGET_SET_FLAGS (button14, GTK_CAN_DEFAULT);
+
+ hbuttonbox8 = gtk_hbutton_box_new ();
+ gtk_widget_ref (hbuttonbox8);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbuttonbox8", hbuttonbox8,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbuttonbox8);
+ gtk_table_attach (GTK_TABLE (table2), hbuttonbox8, 0, 1, 2, 3,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
+ gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox8), 0);
+
+ button15 = gtk_button_new_with_label ("Configure");
+ gtk_widget_ref (button15);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button15", button15,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button15);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox8), button15);
+ GTK_WIDGET_SET_FLAGS (button15, GTK_CAN_DEFAULT);
+
+ button16 = gtk_button_new_with_label ("Test");
+ gtk_widget_ref (button16);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button16", button16,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button16);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox8), button16);
+ GTK_WIDGET_SET_FLAGS (button16, GTK_CAN_DEFAULT);
+
+ button17 = gtk_button_new_with_label ("About");
+ gtk_widget_ref (button17);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button17", button17,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button17);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox8), button17);
+ GTK_WIDGET_SET_FLAGS (button17, GTK_CAN_DEFAULT);
+
+ hbuttonbox9 = gtk_hbutton_box_new ();
+ gtk_widget_ref (hbuttonbox9);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbuttonbox9", hbuttonbox9,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbuttonbox9);
+ gtk_table_attach (GTK_TABLE (table2), hbuttonbox9, 1, 2, 2, 3,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (GTK_FILL), 0, 0);
+ gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox9), 0);
+
+ button18 = gtk_button_new_with_label ("Configure");
+ gtk_widget_ref (button18);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button18", button18,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button18);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox9), button18);
+ GTK_WIDGET_SET_FLAGS (button18, GTK_CAN_DEFAULT);
+
+ button19 = gtk_button_new_with_label ("Test");
+ gtk_widget_ref (button19);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button19", button19,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button19);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox9), button19);
+ GTK_WIDGET_SET_FLAGS (button19, GTK_CAN_DEFAULT);
+
+ button20 = gtk_button_new_with_label ("About");
+ gtk_widget_ref (button20);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button20", button20,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button20);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox9), button20);
+ GTK_WIDGET_SET_FLAGS (button20, GTK_CAN_DEFAULT);
+
+ label2 = gtk_label_new ("Sound");
+ gtk_widget_ref (label2);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "label2", label2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label2);
+ gtk_table_attach (GTK_TABLE (table2), label2, 1, 2, 0, 1,
+ (GtkAttachOptions) (0),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5);
+
+ label1 = gtk_label_new ("Graphics");
+ gtk_widget_ref (label1);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "label1", label1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label1);
+ gtk_table_attach (GTK_TABLE (table2), label1, 0, 1, 0, 1,
+ (GtkAttachOptions) (0),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5);
+
+ label3 = gtk_label_new ("First Controller");
+ gtk_widget_ref (label3);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "label3", label3,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label3);
+ gtk_table_attach (GTK_TABLE (table2), label3, 0, 1, 3, 4,
+ (GtkAttachOptions) (0),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label3), 0, 0.5);
+
+ label5 = gtk_label_new ("Cdrom");
+ gtk_widget_ref (label5);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "label5", label5,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label5);
+ gtk_table_attach (GTK_TABLE (table2), label5, 0, 1, 6, 7,
+ (GtkAttachOptions) (0),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label5), 0, 0.5);
+
+ label6 = gtk_label_new ("Bios");
+ gtk_widget_ref (label6);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "label6", label6,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label6);
+ gtk_table_attach (GTK_TABLE (table2), label6, 1, 2, 6, 7,
+ (GtkAttachOptions) (0),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label6), 0, 0.5);
+
+ label4 = gtk_label_new ("Second Controller");
+ gtk_widget_ref (label4);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "label4", label4,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label4);
+ gtk_table_attach (GTK_TABLE (table2), label4, 1, 2, 3, 4,
+ (GtkAttachOptions) (0),
+ (GtkAttachOptions) (0), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (label4), 0, 0.5);
+
+ GtkCombo_Gpu = gtk_combo_new ();
+ gtk_widget_ref (GtkCombo_Gpu);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "GtkCombo_Gpu", GtkCombo_Gpu,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCombo_Gpu);
+ gtk_table_attach (GTK_TABLE (table2), GtkCombo_Gpu, 0, 1, 1, 2,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ combo_entry2 = GTK_COMBO (GtkCombo_Gpu)->entry;
+ gtk_widget_ref (combo_entry2);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "combo_entry2", combo_entry2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (combo_entry2);
+
+ GtkCombo_Spu = gtk_combo_new ();
+ gtk_widget_ref (GtkCombo_Spu);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "GtkCombo_Spu", GtkCombo_Spu,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCombo_Spu);
+ gtk_table_attach (GTK_TABLE (table2), GtkCombo_Spu, 1, 2, 1, 2,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ combo_entry3 = GTK_COMBO (GtkCombo_Spu)->entry;
+ gtk_widget_ref (combo_entry3);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "combo_entry3", combo_entry3,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (combo_entry3);
+
+ hbox5 = gtk_hbox_new (FALSE, 14);
+ gtk_widget_ref (hbox5);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbox5", hbox5,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbox5);
+ gtk_box_pack_start (GTK_BOX (vbox12), hbox5, TRUE, TRUE, 0);
+
+ hbuttonbox11 = gtk_hbutton_box_new ();
+ gtk_widget_ref (hbuttonbox11);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbuttonbox11", hbuttonbox11,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbuttonbox11);
+ gtk_box_pack_start (GTK_BOX (hbox5), hbuttonbox11, TRUE, TRUE, 0);
+ gtk_widget_set_usize (hbuttonbox11, 169, -2);
+ gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox11), 0);
+
+ button22 = gtk_button_new_with_label ("Select Plugins Dir");
+ gtk_widget_ref (button22);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button22", button22,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button22);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox11), button22);
+ gtk_widget_set_usize (button22, 109, -2);
+ GTK_WIDGET_SET_FLAGS (button22, GTK_CAN_DEFAULT);
+
+ button23 = gtk_button_new_with_label ("Select Bios Dir");
+ gtk_widget_ref (button23);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button23", button23,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button23);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox11), button23);
+ GTK_WIDGET_SET_FLAGS (button23, GTK_CAN_DEFAULT);
+
+ hbuttonbox10 = gtk_hbutton_box_new ();
+ gtk_widget_ref (hbuttonbox10);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "hbuttonbox10", hbuttonbox10,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbuttonbox10);
+ gtk_box_pack_start (GTK_BOX (hbox5), hbuttonbox10, TRUE, TRUE, 0);
+ gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox10), 0);
+
+ button4 = gtk_button_new_with_label ("Ok");
+ gtk_widget_ref (button4);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button4", button4,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button4);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox10), button4);
+ GTK_WIDGET_SET_FLAGS (button4, GTK_CAN_DEFAULT);
+
+ button25 = gtk_button_new_with_label ("Cancel");
+ gtk_widget_ref (button25);
+ gtk_object_set_data_full (GTK_OBJECT (ConfDlg), "button25", button25,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button25);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox10), button25);
+ GTK_WIDGET_SET_FLAGS (button25, GTK_CAN_DEFAULT);
+
+ gtk_signal_connect (GTK_OBJECT (button6), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_CdrConf),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button7), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_CdrTest),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button8), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_CdrAbout),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button9), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_Pad2Conf),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button10), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_Pad2Test),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button11), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_Pad2About),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button12), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_Pad1Conf),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button13), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_Pad1Test),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button14), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_Pad1About),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button15), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_GpuConf),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button16), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_GpuTest),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button17), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_GpuAbout),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button18), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_SpuConf),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button19), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_SpuTest),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button20), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_SpuAbout),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button22), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_PluginsPath),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button23), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_BiosPath),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button4), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_Ok),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button25), "clicked",
+ GTK_SIGNAL_FUNC (OnConfConf_Cancel),
+ NULL);
+
+ return ConfDlg;
+}
+
+GtkWidget*
+create_CpuDlg (void)
+{
+ GtkWidget *CpuDlg;
+ GtkWidget *vbox8;
+ GtkWidget *frame3;
+ GtkWidget *vbox15;
+ GtkWidget *table1;
+ GtkWidget *GtkCheckButton_Xa;
+ GtkWidget *GtkCheckButton_Cdda;
+ GtkWidget *GtkCheckButton_Sio;
+ GtkWidget *GtkCheckButton_Cpu;
+ GtkWidget *GtkCheckButton_PsxOut;
+ GtkWidget *GtkCheckButton_Mdec;
+ GtkWidget *GtkCheckButton_SpuIrq;
+ GtkWidget *GtkCheckButton_CpuLog;
+ GtkWidget *GtkCheckButton_CdTiming;
+ GtkWidget *frame6;
+ GtkWidget *hbox4;
+ GtkWidget *GtkCheckButton_PsxAuto;
+ GtkWidget *GtkCombo_PsxType;
+ GtkWidget *combo_entry1;
+ GtkWidget *hbuttonbox3;
+ GtkWidget *button2;
+ GtkWidget *button3;
+
+ CpuDlg = gtk_window_new (GTK_WINDOW_DIALOG);
+ gtk_object_set_data (GTK_OBJECT (CpuDlg), "CpuDlg", CpuDlg);
+ gtk_container_set_border_width (GTK_CONTAINER (CpuDlg), 5);
+ gtk_window_set_title (GTK_WINDOW (CpuDlg), "Cpu");
+ gtk_window_set_position (GTK_WINDOW (CpuDlg), GTK_WIN_POS_CENTER);
+
+ vbox8 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_ref (vbox8);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "vbox8", vbox8,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (vbox8);
+ gtk_container_add (GTK_CONTAINER (CpuDlg), vbox8);
+
+ frame3 = gtk_frame_new ("Options");
+ gtk_widget_ref (frame3);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "frame3", frame3,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (frame3);
+ gtk_box_pack_start (GTK_BOX (vbox8), frame3, TRUE, TRUE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (frame3), 5);
+
+ vbox15 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_ref (vbox15);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "vbox15", vbox15,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (vbox15);
+ gtk_container_add (GTK_CONTAINER (frame3), vbox15);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox15), 5);
+
+ table1 = gtk_table_new (4, 2, FALSE);
+ gtk_widget_ref (table1);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "table1", table1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (table1);
+ gtk_box_pack_start (GTK_BOX (vbox15), table1, TRUE, TRUE, 0);
+
+ GtkCheckButton_Xa = gtk_check_button_new_with_label ("Disable Xa Decoding");
+ gtk_widget_ref (GtkCheckButton_Xa);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_Xa", GtkCheckButton_Xa,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCheckButton_Xa);
+ gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_Xa, 0, 1, 0, 1,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ GtkCheckButton_Cdda = gtk_check_button_new_with_label ("Disable Cd Audio");
+ gtk_widget_ref (GtkCheckButton_Cdda);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_Cdda", GtkCheckButton_Cdda,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCheckButton_Cdda);
+ gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_Cdda, 1, 2, 0, 1,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ GtkCheckButton_Sio = gtk_check_button_new_with_label ("Sio Irq Always Enabled");
+ gtk_widget_ref (GtkCheckButton_Sio);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_Sio", GtkCheckButton_Sio,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCheckButton_Sio);
+ gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_Sio, 0, 1, 1, 2,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ GtkCheckButton_Cpu = gtk_check_button_new_with_label ("Enable Interpreter Cpu");
+ gtk_widget_ref (GtkCheckButton_Cpu);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_Cpu", GtkCheckButton_Cpu,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCheckButton_Cpu);
+ gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_Cpu, 1, 2, 1, 2,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ GtkCheckButton_PsxOut = gtk_check_button_new_with_label ("Enable Console Output");
+ gtk_widget_ref (GtkCheckButton_PsxOut);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_PsxOut", GtkCheckButton_PsxOut,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCheckButton_PsxOut);
+ gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_PsxOut, 1, 2, 2, 3,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ GtkCheckButton_Mdec = gtk_check_button_new_with_label ("Black & White Movies");
+ gtk_widget_ref (GtkCheckButton_Mdec);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_Mdec", GtkCheckButton_Mdec,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCheckButton_Mdec);
+ gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_Mdec, 0, 1, 3, 4,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ GtkCheckButton_SpuIrq = gtk_check_button_new_with_label ("Spu Irq Always Enabled");
+ gtk_widget_ref (GtkCheckButton_SpuIrq);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_SpuIrq", GtkCheckButton_SpuIrq,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCheckButton_SpuIrq);
+ gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_SpuIrq, 0, 1, 2, 3,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ GtkCheckButton_CpuLog = gtk_check_button_new_with_label ("Enable CPU Log");
+ gtk_widget_ref (GtkCheckButton_CpuLog);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_CpuLog", GtkCheckButton_CpuLog,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCheckButton_CpuLog);
+ gtk_table_attach (GTK_TABLE (table1), GtkCheckButton_CpuLog, 1, 2, 3, 4,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
+ GtkCheckButton_CdTiming = gtk_check_button_new_with_label ("Old Cdrom Timing (Gran Turismo...)");
+ gtk_widget_ref (GtkCheckButton_CdTiming);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_CdTiming", GtkCheckButton_CdTiming,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCheckButton_CdTiming);
+ gtk_box_pack_start (GTK_BOX (vbox15), GtkCheckButton_CdTiming, FALSE, FALSE, 0);
+
+ frame6 = gtk_frame_new ("Psx System Type");
+ gtk_widget_ref (frame6);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "frame6", frame6,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (frame6);
+ gtk_box_pack_start (GTK_BOX (vbox8), frame6, TRUE, TRUE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (frame6), 5);
+
+ hbox4 = gtk_hbox_new (FALSE, 0);
+ gtk_widget_ref (hbox4);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "hbox4", hbox4,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbox4);
+ gtk_container_add (GTK_CONTAINER (frame6), hbox4);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox4), 5);
+
+ GtkCheckButton_PsxAuto = gtk_check_button_new_with_label ("Autodetect");
+ gtk_widget_ref (GtkCheckButton_PsxAuto);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCheckButton_PsxAuto", GtkCheckButton_PsxAuto,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCheckButton_PsxAuto);
+ gtk_box_pack_start (GTK_BOX (hbox4), GtkCheckButton_PsxAuto, FALSE, FALSE, 0);
+ gtk_widget_set_usize (GtkCheckButton_PsxAuto, 159, -2);
+
+ GtkCombo_PsxType = gtk_combo_new ();
+ gtk_widget_ref (GtkCombo_PsxType);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "GtkCombo_PsxType", GtkCombo_PsxType,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCombo_PsxType);
+ gtk_box_pack_start (GTK_BOX (hbox4), GtkCombo_PsxType, FALSE, FALSE, 0);
+ gtk_widget_set_usize (GtkCombo_PsxType, 154, -2);
+
+ combo_entry1 = GTK_COMBO (GtkCombo_PsxType)->entry;
+ gtk_widget_ref (combo_entry1);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "combo_entry1", combo_entry1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (combo_entry1);
+ gtk_entry_set_editable (GTK_ENTRY (combo_entry1), FALSE);
+
+ hbuttonbox3 = gtk_hbutton_box_new ();
+ gtk_widget_ref (hbuttonbox3);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "hbuttonbox3", hbuttonbox3,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbuttonbox3);
+ gtk_box_pack_start (GTK_BOX (vbox8), hbuttonbox3, TRUE, TRUE, 0);
+
+ button2 = gtk_button_new_with_label ("Ok");
+ gtk_widget_ref (button2);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "button2", button2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button2);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox3), button2);
+ GTK_WIDGET_SET_FLAGS (button2, GTK_CAN_DEFAULT);
+
+ button3 = gtk_button_new_with_label ("Cancel");
+ gtk_widget_ref (button3);
+ gtk_object_set_data_full (GTK_OBJECT (CpuDlg), "button3", button3,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button3);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox3), button3);
+ GTK_WIDGET_SET_FLAGS (button3, GTK_CAN_DEFAULT);
+
+ gtk_signal_connect (GTK_OBJECT (button2), "clicked",
+ GTK_SIGNAL_FUNC (OnCpu_Ok),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button3), "clicked",
+ GTK_SIGNAL_FUNC (OnCpu_Cancel),
+ NULL);
+
+ return CpuDlg;
+}
+
+GtkWidget*
+create_McdsDlg (void)
+{
+ GtkWidget *McdsDlg;
+ GtkWidget *vbox10;
+ GtkWidget *hbox6;
+ GtkWidget *frame7;
+ GtkWidget *vbox13;
+ GtkWidget *scrolledwindow1;
+ GtkWidget *GtkCList_McdList1;
+ GtkWidget *label9;
+ GtkWidget *label10;
+ GtkWidget *label11;
+ GtkWidget *label15;
+ GtkWidget *label16;
+ GtkWidget *hbuttonbox12;
+ GtkWidget *GtkButton_SelMcd1;
+ GtkWidget *GtkButton_Format1;
+ GtkWidget *GtkButton_Reload1;
+ GtkWidget *GtkEntry_Mcd1;
+ GtkWidget *vbuttonbox1;
+ GtkWidget *button26;
+ GtkWidget *button28;
+ GtkWidget *GtkButton_McdPaste;
+ GtkWidget *button29;
+ GtkWidget *button30;
+ GtkWidget *frame8;
+ GtkWidget *vbox14;
+ GtkWidget *scrolledwindow2;
+ GtkWidget *GtkCList_McdList2;
+ GtkWidget *label12;
+ GtkWidget *label13;
+ GtkWidget *label14;
+ GtkWidget *label17;
+ GtkWidget *label18;
+ GtkWidget *hbuttonbox13;
+ GtkWidget *GtkButton_SelMcd2;
+ GtkWidget *GtkButton_Format2;
+ GtkWidget *GtkButton_Reload2;
+ GtkWidget *GtkEntry_Mcd2;
+ GtkWidget *hbuttonbox2;
+ GtkWidget *GtkMcds_Ok;
+ GtkWidget *GtkMcds_Cancel;
+
+ McdsDlg = gtk_window_new (GTK_WINDOW_DIALOG);
+ gtk_object_set_data (GTK_OBJECT (McdsDlg), "McdsDlg", McdsDlg);
+ gtk_container_set_border_width (GTK_CONTAINER (McdsDlg), 5);
+ gtk_window_set_title (GTK_WINDOW (McdsDlg), "Mcds");
+ gtk_window_set_position (GTK_WINDOW (McdsDlg), GTK_WIN_POS_CENTER);
+
+ vbox10 = gtk_vbox_new (FALSE, 5);
+ gtk_widget_ref (vbox10);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "vbox10", vbox10,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (vbox10);
+ gtk_container_add (GTK_CONTAINER (McdsDlg), vbox10);
+
+ hbox6 = gtk_hbox_new (FALSE, 0);
+ gtk_widget_ref (hbox6);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "hbox6", hbox6,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbox6);
+ gtk_box_pack_start (GTK_BOX (vbox10), hbox6, TRUE, TRUE, 0);
+
+ frame7 = gtk_frame_new ("Memory Card 1");
+ gtk_widget_ref (frame7);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "frame7", frame7,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (frame7);
+ gtk_box_pack_start (GTK_BOX (hbox6), frame7, TRUE, TRUE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (frame7), 5);
+
+ vbox13 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_ref (vbox13);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "vbox13", vbox13,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (vbox13);
+ gtk_container_add (GTK_CONTAINER (frame7), vbox13);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox13), 5);
+
+ scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_ref (scrolledwindow1);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "scrolledwindow1", scrolledwindow1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (scrolledwindow1);
+ gtk_box_pack_start (GTK_BOX (vbox13), scrolledwindow1, TRUE, TRUE, 0);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+ GtkCList_McdList1 = gtk_clist_new (5);
+ gtk_widget_ref (GtkCList_McdList1);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkCList_McdList1", GtkCList_McdList1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCList_McdList1);
+ gtk_container_add (GTK_CONTAINER (scrolledwindow1), GtkCList_McdList1);
+ gtk_widget_set_usize (GtkCList_McdList1, -2, 180);
+ gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList1), 0, 25);
+ gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList1), 1, 180);
+ gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList1), 2, 50);
+ gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList1), 3, 80);
+ gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList1), 4, 80);
+ gtk_clist_column_titles_show (GTK_CLIST (GtkCList_McdList1));
+
+ label9 = gtk_label_new ("Icon");
+ gtk_widget_ref (label9);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label9", label9,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label9);
+ gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList1), 0, label9);
+
+ label10 = gtk_label_new ("Title");
+ gtk_widget_ref (label10);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label10", label10,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label10);
+ gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList1), 1, label10);
+
+ label11 = gtk_label_new ("Status");
+ gtk_widget_ref (label11);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label11", label11,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label11);
+ gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList1), 2, label11);
+
+ label15 = gtk_label_new ("Game ID");
+ gtk_widget_ref (label15);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label15", label15,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label15);
+ gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList1), 3, label15);
+
+ label16 = gtk_label_new ("Game");
+ gtk_widget_ref (label16);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label16", label16,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label16);
+ gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList1), 4, label16);
+
+ hbuttonbox12 = gtk_hbutton_box_new ();
+ gtk_widget_ref (hbuttonbox12);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "hbuttonbox12", hbuttonbox12,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbuttonbox12);
+ gtk_box_pack_start (GTK_BOX (vbox13), hbuttonbox12, TRUE, TRUE, 0);
+ gtk_widget_set_usize (hbuttonbox12, 240, -2);
+ gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox12), 0);
+ gtk_button_box_set_child_size (GTK_BUTTON_BOX (hbuttonbox12), 70, 27);
+
+ GtkButton_SelMcd1 = gtk_button_new_with_label ("Select");
+ gtk_widget_ref (GtkButton_SelMcd1);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkButton_SelMcd1", GtkButton_SelMcd1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkButton_SelMcd1);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox12), GtkButton_SelMcd1);
+ GTK_WIDGET_SET_FLAGS (GtkButton_SelMcd1, GTK_CAN_DEFAULT);
+
+ GtkButton_Format1 = gtk_button_new_with_label ("Format");
+ gtk_widget_ref (GtkButton_Format1);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkButton_Format1", GtkButton_Format1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkButton_Format1);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox12), GtkButton_Format1);
+ GTK_WIDGET_SET_FLAGS (GtkButton_Format1, GTK_CAN_DEFAULT);
+
+ GtkButton_Reload1 = gtk_button_new_with_label ("Reload");
+ gtk_widget_ref (GtkButton_Reload1);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkButton_Reload1", GtkButton_Reload1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkButton_Reload1);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox12), GtkButton_Reload1);
+ GTK_WIDGET_SET_FLAGS (GtkButton_Reload1, GTK_CAN_DEFAULT);
+
+ GtkEntry_Mcd1 = gtk_entry_new ();
+ gtk_widget_ref (GtkEntry_Mcd1);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkEntry_Mcd1", GtkEntry_Mcd1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkEntry_Mcd1);
+ gtk_box_pack_start (GTK_BOX (vbox13), GtkEntry_Mcd1, FALSE, FALSE, 0);
+
+ vbuttonbox1 = gtk_vbutton_box_new ();
+ gtk_widget_ref (vbuttonbox1);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "vbuttonbox1", vbuttonbox1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (vbuttonbox1);
+ gtk_box_pack_start (GTK_BOX (hbox6), vbuttonbox1, TRUE, FALSE, 0);
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (vbuttonbox1), GTK_BUTTONBOX_SPREAD);
+ gtk_button_box_set_spacing (GTK_BUTTON_BOX (vbuttonbox1), 0);
+ gtk_button_box_set_child_size (GTK_BUTTON_BOX (vbuttonbox1), 64, 27);
+ gtk_button_box_set_child_ipadding (GTK_BUTTON_BOX (vbuttonbox1), 0, 0);
+
+ button26 = gtk_button_new_with_label ("-> Copy ->");
+ gtk_widget_ref (button26);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "button26", button26,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button26);
+ gtk_container_add (GTK_CONTAINER (vbuttonbox1), button26);
+ GTK_WIDGET_SET_FLAGS (button26, GTK_CAN_DEFAULT);
+
+ button28 = gtk_button_new_with_label ("<- Copy <-");
+ gtk_widget_ref (button28);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "button28", button28,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button28);
+ gtk_container_add (GTK_CONTAINER (vbuttonbox1), button28);
+ GTK_WIDGET_SET_FLAGS (button28, GTK_CAN_DEFAULT);
+
+ GtkButton_McdPaste = gtk_button_new_with_label ("Paste");
+ gtk_widget_ref (GtkButton_McdPaste);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkButton_McdPaste", GtkButton_McdPaste,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkButton_McdPaste);
+ gtk_container_add (GTK_CONTAINER (vbuttonbox1), GtkButton_McdPaste);
+ GTK_WIDGET_SET_FLAGS (GtkButton_McdPaste, GTK_CAN_DEFAULT);
+
+ button29 = gtk_button_new_with_label ("Un/Delete ->");
+ gtk_widget_ref (button29);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "button29", button29,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button29);
+ gtk_container_add (GTK_CONTAINER (vbuttonbox1), button29);
+ GTK_WIDGET_SET_FLAGS (button29, GTK_CAN_DEFAULT);
+
+ button30 = gtk_button_new_with_label ("<- Un/Delete");
+ gtk_widget_ref (button30);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "button30", button30,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (button30);
+ gtk_container_add (GTK_CONTAINER (vbuttonbox1), button30);
+ GTK_WIDGET_SET_FLAGS (button30, GTK_CAN_DEFAULT);
+
+ frame8 = gtk_frame_new ("Memory Card 2");
+ gtk_widget_ref (frame8);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "frame8", frame8,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (frame8);
+ gtk_box_pack_start (GTK_BOX (hbox6), frame8, TRUE, TRUE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (frame8), 5);
+
+ vbox14 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_ref (vbox14);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "vbox14", vbox14,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (vbox14);
+ gtk_container_add (GTK_CONTAINER (frame8), vbox14);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox14), 5);
+
+ scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_ref (scrolledwindow2);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "scrolledwindow2", scrolledwindow2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (scrolledwindow2);
+ gtk_box_pack_start (GTK_BOX (vbox14), scrolledwindow2, TRUE, TRUE, 0);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow2), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+ GtkCList_McdList2 = gtk_clist_new (5);
+ gtk_widget_ref (GtkCList_McdList2);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkCList_McdList2", GtkCList_McdList2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkCList_McdList2);
+ gtk_container_add (GTK_CONTAINER (scrolledwindow2), GtkCList_McdList2);
+ gtk_widget_set_usize (GtkCList_McdList2, -2, 180);
+ gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList2), 0, 25);
+ gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList2), 1, 180);
+ gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList2), 2, 50);
+ gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList2), 3, 80);
+ gtk_clist_set_column_width (GTK_CLIST (GtkCList_McdList2), 4, 80);
+ gtk_clist_column_titles_show (GTK_CLIST (GtkCList_McdList2));
+
+ label12 = gtk_label_new ("Icon");
+ gtk_widget_ref (label12);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label12", label12,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label12);
+ gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList2), 0, label12);
+
+ label13 = gtk_label_new ("Title");
+ gtk_widget_ref (label13);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label13", label13,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label13);
+ gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList2), 1, label13);
+
+ label14 = gtk_label_new ("Status");
+ gtk_widget_ref (label14);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label14", label14,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label14);
+ gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList2), 2, label14);
+
+ label17 = gtk_label_new ("Game ID");
+ gtk_widget_ref (label17);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label17", label17,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label17);
+ gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList2), 3, label17);
+
+ label18 = gtk_label_new ("Game");
+ gtk_widget_ref (label18);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "label18", label18,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label18);
+ gtk_clist_set_column_widget (GTK_CLIST (GtkCList_McdList2), 4, label18);
+
+ hbuttonbox13 = gtk_hbutton_box_new ();
+ gtk_widget_ref (hbuttonbox13);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "hbuttonbox13", hbuttonbox13,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbuttonbox13);
+ gtk_box_pack_start (GTK_BOX (vbox14), hbuttonbox13, TRUE, TRUE, 0);
+ gtk_widget_set_usize (hbuttonbox13, 240, -2);
+ gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox13), 0);
+ gtk_button_box_set_child_size (GTK_BUTTON_BOX (hbuttonbox13), 70, 27);
+
+ GtkButton_SelMcd2 = gtk_button_new_with_label ("Select");
+ gtk_widget_ref (GtkButton_SelMcd2);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkButton_SelMcd2", GtkButton_SelMcd2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkButton_SelMcd2);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox13), GtkButton_SelMcd2);
+ GTK_WIDGET_SET_FLAGS (GtkButton_SelMcd2, GTK_CAN_DEFAULT);
+
+ GtkButton_Format2 = gtk_button_new_with_label ("Format");
+ gtk_widget_ref (GtkButton_Format2);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkButton_Format2", GtkButton_Format2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkButton_Format2);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox13), GtkButton_Format2);
+ GTK_WIDGET_SET_FLAGS (GtkButton_Format2, GTK_CAN_DEFAULT);
+
+ GtkButton_Reload2 = gtk_button_new_with_label ("Reload");
+ gtk_widget_ref (GtkButton_Reload2);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkButton_Reload2", GtkButton_Reload2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkButton_Reload2);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox13), GtkButton_Reload2);
+ GTK_WIDGET_SET_FLAGS (GtkButton_Reload2, GTK_CAN_DEFAULT);
+
+ GtkEntry_Mcd2 = gtk_entry_new ();
+ gtk_widget_ref (GtkEntry_Mcd2);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkEntry_Mcd2", GtkEntry_Mcd2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkEntry_Mcd2);
+ gtk_box_pack_start (GTK_BOX (vbox14), GtkEntry_Mcd2, FALSE, FALSE, 0);
+
+ hbuttonbox2 = gtk_hbutton_box_new ();
+ gtk_widget_ref (hbuttonbox2);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "hbuttonbox2", hbuttonbox2,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbuttonbox2);
+ gtk_box_pack_start (GTK_BOX (vbox10), hbuttonbox2, TRUE, TRUE, 0);
+
+ GtkMcds_Ok = gtk_button_new_with_label ("Ok");
+ gtk_widget_ref (GtkMcds_Ok);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkMcds_Ok", GtkMcds_Ok,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkMcds_Ok);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox2), GtkMcds_Ok);
+ GTK_WIDGET_SET_FLAGS (GtkMcds_Ok, GTK_CAN_DEFAULT);
+
+ GtkMcds_Cancel = gtk_button_new_with_label ("Cancel");
+ gtk_widget_ref (GtkMcds_Cancel);
+ gtk_object_set_data_full (GTK_OBJECT (McdsDlg), "GtkMcds_Cancel", GtkMcds_Cancel,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkMcds_Cancel);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox2), GtkMcds_Cancel);
+ GTK_WIDGET_SET_FLAGS (GtkMcds_Cancel, GTK_CAN_DEFAULT);
+
+ gtk_signal_connect (GTK_OBJECT (GtkButton_SelMcd1), "clicked",
+ GTK_SIGNAL_FUNC (OnMcd_FS1),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (GtkButton_Format1), "clicked",
+ GTK_SIGNAL_FUNC (OnMcd_Format1),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (GtkButton_Reload1), "clicked",
+ GTK_SIGNAL_FUNC (OnMcd_Reload1),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button26), "clicked",
+ GTK_SIGNAL_FUNC (OnMcd_CopyTo2),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button28), "clicked",
+ GTK_SIGNAL_FUNC (OnMcd_CopyTo1),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (GtkButton_McdPaste), "clicked",
+ GTK_SIGNAL_FUNC (OnMcd_Paste),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button29), "clicked",
+ GTK_SIGNAL_FUNC (OnMcd_Delete2),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (button30), "clicked",
+ GTK_SIGNAL_FUNC (OnMcd_Delete1),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (GtkButton_SelMcd2), "clicked",
+ GTK_SIGNAL_FUNC (OnMcd_FS2),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (GtkButton_Format2), "clicked",
+ GTK_SIGNAL_FUNC (OnMcd_Format2),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (GtkButton_Reload2), "clicked",
+ GTK_SIGNAL_FUNC (OnMcd_Reload2),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (GtkMcds_Ok), "clicked",
+ GTK_SIGNAL_FUNC (OnMcd_Ok),
+ NULL);
+ gtk_signal_connect (GTK_OBJECT (GtkMcds_Cancel), "clicked",
+ GTK_SIGNAL_FUNC (OnMcd_Cancel),
+ NULL);
+
+ return McdsDlg;
+}
+
+GtkWidget*
+create_DebugDlg (void)
+{
+ GtkWidget *DebugDlg;
+ GtkWidget *vbox17;
+ GtkWidget *scrolledwindow3;
+ GtkWidget *text1;
+ GtkWidget *hbuttonbox14;
+ GtkWidget *GtkButton_DbgOk;
+
+ DebugDlg = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_object_set_data (GTK_OBJECT (DebugDlg), "DebugDlg", DebugDlg);
+ gtk_container_set_border_width (GTK_CONTAINER (DebugDlg), 5);
+ gtk_window_set_title (GTK_WINDOW (DebugDlg), "Debug");
+
+ vbox17 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_ref (vbox17);
+ gtk_object_set_data_full (GTK_OBJECT (DebugDlg), "vbox17", vbox17,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (vbox17);
+ gtk_container_add (GTK_CONTAINER (DebugDlg), vbox17);
+
+ scrolledwindow3 = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_ref (scrolledwindow3);
+ gtk_object_set_data_full (GTK_OBJECT (DebugDlg), "scrolledwindow3", scrolledwindow3,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (scrolledwindow3);
+ gtk_box_pack_start (GTK_BOX (vbox17), scrolledwindow3, TRUE, TRUE, 0);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow3), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
+
+ text1 = gtk_text_new (NULL, NULL);
+ gtk_widget_ref (text1);
+ gtk_object_set_data_full (GTK_OBJECT (DebugDlg), "text1", text1,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (text1);
+ gtk_container_add (GTK_CONTAINER (scrolledwindow3), text1);
+ gtk_text_insert (GTK_TEXT (text1), NULL, NULL, NULL,
+ "Test", 4);
+
+ hbuttonbox14 = gtk_hbutton_box_new ();
+ gtk_widget_ref (hbuttonbox14);
+ gtk_object_set_data_full (GTK_OBJECT (DebugDlg), "hbuttonbox14", hbuttonbox14,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (hbuttonbox14);
+ gtk_box_pack_start (GTK_BOX (vbox17), hbuttonbox14, TRUE, TRUE, 0);
+
+ GtkButton_DbgOk = gtk_button_new_with_label ("Ok");
+ gtk_widget_ref (GtkButton_DbgOk);
+ gtk_object_set_data_full (GTK_OBJECT (DebugDlg), "GtkButton_DbgOk", GtkButton_DbgOk,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (GtkButton_DbgOk);
+ gtk_container_add (GTK_CONTAINER (hbuttonbox14), GtkButton_DbgOk);
+ GTK_WIDGET_SET_FLAGS (GtkButton_DbgOk, GTK_CAN_DEFAULT);
+
+ gtk_signal_connect (GTK_OBJECT (GtkButton_DbgOk), "clicked",
+ GTK_SIGNAL_FUNC (OnDebug_Ok),
+ NULL);
+
+ return DebugDlg;
+}
+
diff --git a/PcsxSrc/Linux/GladeGui.h b/PcsxSrc/Linux/GladeGui.h index ff8d9f9..ca46235 100644 --- a/PcsxSrc/Linux/GladeGui.h +++ b/PcsxSrc/Linux/GladeGui.h @@ -1,10 +1,10 @@ -/* - * DO NOT EDIT THIS FILE - it is generated by Glade. - */ - -GtkWidget* create_MainWindow (void); -GtkWidget* create_AboutDlg (void); -GtkWidget* create_ConfDlg (void); -GtkWidget* create_CpuDlg (void); -GtkWidget* create_McdsDlg (void); -GtkWidget* create_DebugDlg (void); +/*
+ * DO NOT EDIT THIS FILE - it is generated by Glade.
+ */
+
+GtkWidget* create_MainWindow (void);
+GtkWidget* create_AboutDlg (void);
+GtkWidget* create_ConfDlg (void);
+GtkWidget* create_CpuDlg (void);
+GtkWidget* create_McdsDlg (void);
+GtkWidget* create_DebugDlg (void);
diff --git a/PcsxSrc/Linux/GtkGui.c b/PcsxSrc/Linux/GtkGui.c index 03ab7a1..7ac46d4 100644 --- a/PcsxSrc/Linux/GtkGui.c +++ b/PcsxSrc/Linux/GtkGui.c @@ -64,7 +64,7 @@ void OnHelp_About(); GtkWidget *Window = NULL;
GtkWidget *ConfDlg;
-GtkWidget *DebugDlg; +GtkWidget *DebugDlg;
GtkWidget *AboutDlg;
GtkWidget *FileSel;
@@ -804,9 +804,9 @@ void OnCpu_Ok() { psxCpu->Reset();
}
- Btn = lookup_widget(CpuDlg, "GtkCheckButton_CpuLog"); - Config.Log = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); - + Btn = lookup_widget(CpuDlg, "GtkCheckButton_CpuLog");
+ Config.Log = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn));
+
Btn = lookup_widget(CpuDlg, "GtkCheckButton_PsxOut");
Config.PsxOut = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn));
@@ -1100,20 +1100,20 @@ void OnConf_Conf() { if (Window != NULL) gtk_widget_set_sensitive(Window, FALSE);
gtk_main();
}
- -void OnDebug() { - DebugDlg = create_DebugDlg(); - gtk_widget_show_all(DebugDlg); - - if (Window != NULL) gtk_widget_set_sensitive(Window, FALSE); - gtk_main(); -} - -void OnDebug_Ok() { +
+void OnDebug() {
+ DebugDlg = create_DebugDlg();
+ gtk_widget_show_all(DebugDlg);
+
+ if (Window != NULL) gtk_widget_set_sensitive(Window, FALSE);
+ gtk_main();
+}
+
+void OnDebug_Ok() {
gtk_widget_destroy(DebugDlg);
if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE);
- gtk_main_quit();
-} + gtk_main_quit();
+}
void OnHelp_Help() {
}
diff --git a/PcsxSrc/Sio.c b/PcsxSrc/Sio.c index 263e556..b7cb516 100644 --- a/PcsxSrc/Sio.c +++ b/PcsxSrc/Sio.c @@ -46,18 +46,18 @@ static unsigned char adrH,adrL; static unsigned long padst;
PadDataS pad;
- -#ifndef strlwr -#include <ctype.h> -char * strlwr(char * string) { - char * r; - for (r = string; *r; r++) { - *r = tolower(*r); - } - return string; -} +
+#ifndef strlwr
+#include <ctype.h>
+char * strlwr(char * string) {
+ char * r;
+ for (r = string; *r; r++) {
+ *r = tolower(*r);
+ }
+ return string;
+}
#endif
- +
char Mcd1Data[MCD_SIZE], Mcd2Data[MCD_SIZE];
// clk cycle byte
diff --git a/PcsxSrc/Win32/plugin.c b/PcsxSrc/Win32/plugin.c index 0edabbe..018257e 100644 --- a/PcsxSrc/Win32/plugin.c +++ b/PcsxSrc/Win32/plugin.c @@ -118,16 +118,16 @@ void PADhandleKey(int key) { cdOpenCase = 0;
return;
- case VK_F11: - GPU_displayText("*PCSX*: Begin CPU Log"); - Log = 1; - return; - - case VK_F12: - GPU_displayText("*PCSX*: Ending CPU Log"); - Log = 0; - return; - + case VK_F11:
+ GPU_displayText("*PCSX*: Begin CPU Log");
+ Log = 1;
+ return;
+
+ case VK_F12:
+ GPU_displayText("*PCSX*: Ending CPU Log");
+ Log = 0;
+ return;
+
case VK_ESCAPE:
Running = 0;
ClosePlugins();
diff --git a/PcsxSrc/ix86/iR3000A.c b/PcsxSrc/ix86/iR3000A.c index 7acf24e..c6ff128 100644 --- a/PcsxSrc/ix86/iR3000A.c +++ b/PcsxSrc/ix86/iR3000A.c @@ -111,7 +111,7 @@ static int recInit() { memcpy(recLUT + 0xa000, recLUT, 0x80 * 4);
for (i=0; i<0x08; i++) recLUT[i + 0xbfc0] = (u32)&recROM[i << 16];
- +
return 0;
}
diff --git a/ToD/ExtracteurIdiot.cpp b/ToD/ExtracteurIdiot.cpp index fde5134..8825d97 100644 --- a/ToD/ExtracteurIdiot.cpp +++ b/ToD/ExtracteurIdiot.cpp @@ -1,96 +1,96 @@ -#include <iostream> -#include <iomanip> -#include <fstream> -#include <vector> - -using namespace std; - -int main(int, char **) -{ - int iPosPointeur, iPosTexte; - char szPath[2][256]; - vector<unsigned char> vFichier; - - cout << "Entrez le nom du fichier :"; - cin >> szPath[0]; - cout << "Entrez le nom du fichier texte :"; - cin >> szPath[1]; - - cout << "Entrez la position du pointeur (Hexadeciaml) :"; - cin >> hex >> iPosPointeur; - cout << "Entrez la position du texte (Hexadeciaml) :"; - cin >> hex >> iPosTexte; - - ifstream ifFichier(szPath[0], ios::binary); - - if(ifFichier) - { - ifFichier.seekg(0, ios::end); - vFichier.resize(ifFichier.tellg()); - - ifFichier.seekg(0, ios::beg); - ifFichier.read((char *) vFichier.begin(), vFichier.size()); - } - - ofstream ofTexte(szPath[1], ios::binary | ios::trunc); - - for(int i = 0; i < (iPosTexte - iPosPointeur) / 2; i++) - { - ofTexte << "<PT" << setw(4) << setfill('0') << i << ">\n"; - - for(int j = iPosPointeur + vFichier[iPosPointeur + i * 2] + - (vFichier[iPosPointeur + i * 2 + 1] * 256); vFichier[j] != 0; j++) - switch(vFichier[j]) - { - case 0x01: - ofTexte << "<NOM:" << (int) vFichier[++j] << ">"; - break; - case 0x02: - ofTexte << "<02>"; - break; - case 0x03: - ofTexte << "<03>"; - break; - case 0x04: - switch (vFichier[++j]) - { - case 0x02: - ofTexte << "<VIOLET>"; - break; - case 0x04: - ofTexte << "<VERT>"; - break; - case 0x05: - ofTexte << "<BLEU>"; - break; - case 0x06: - ofTexte << "<JAUNE>"; - break; - case 0x0F: - ofText << "<FINCOULEUR>"; - break; - default: - ofTexte << setw(2) << << setfill('0') << hex << vFichier[j]; - } - break; - case 0x05: - ofTexte << "<05>"; - break; - case 0x06: - ofTexte << "<06>"; - break; - case 0x0c: - ofTexte << "<NP>\n"; - break; - case 0x0a: - ofTexte.put('\n'); - break; - default: - ofTexte.put(vFichier[j]); - } - - ofTexte << "<FIN>\n\n"; - } - - return 0; +#include <iostream>
+#include <iomanip>
+#include <fstream>
+#include <vector>
+
+using namespace std;
+
+int main(int, char **)
+{
+ int iPosPointeur, iPosTexte;
+ char szPath[2][256];
+ vector<unsigned char> vFichier;
+
+ cout << "Entrez le nom du fichier :";
+ cin >> szPath[0];
+ cout << "Entrez le nom du fichier texte :";
+ cin >> szPath[1];
+
+ cout << "Entrez la position du pointeur (Hexadeciaml) :";
+ cin >> hex >> iPosPointeur;
+ cout << "Entrez la position du texte (Hexadeciaml) :";
+ cin >> hex >> iPosTexte;
+
+ ifstream ifFichier(szPath[0], ios::binary);
+
+ if(ifFichier)
+ {
+ ifFichier.seekg(0, ios::end);
+ vFichier.resize(ifFichier.tellg());
+
+ ifFichier.seekg(0, ios::beg);
+ ifFichier.read((char *) vFichier.begin(), vFichier.size());
+ }
+
+ ofstream ofTexte(szPath[1], ios::binary | ios::trunc);
+
+ for(int i = 0; i < (iPosTexte - iPosPointeur) / 2; i++)
+ {
+ ofTexte << "<PT" << setw(4) << setfill('0') << i << ">\n";
+
+ for(int j = iPosPointeur + vFichier[iPosPointeur + i * 2] +
+ (vFichier[iPosPointeur + i * 2 + 1] * 256); vFichier[j] != 0; j++)
+ switch(vFichier[j])
+ {
+ case 0x01:
+ ofTexte << "<NOM:" << (int) vFichier[++j] << ">";
+ break;
+ case 0x02:
+ ofTexte << "<02>";
+ break;
+ case 0x03:
+ ofTexte << "<03>";
+ break;
+ case 0x04:
+ switch (vFichier[++j])
+ {
+ case 0x02:
+ ofTexte << "<VIOLET>";
+ break;
+ case 0x04:
+ ofTexte << "<VERT>";
+ break;
+ case 0x05:
+ ofTexte << "<BLEU>";
+ break;
+ case 0x06:
+ ofTexte << "<JAUNE>";
+ break;
+ case 0x0F:
+ ofText << "<FINCOULEUR>";
+ break;
+ default:
+ ofTexte << setw(2) << << setfill('0') << hex << vFichier[j];
+ }
+ break;
+ case 0x05:
+ ofTexte << "<05>";
+ break;
+ case 0x06:
+ ofTexte << "<06>";
+ break;
+ case 0x0c:
+ ofTexte << "<NP>\n";
+ break;
+ case 0x0a:
+ ofTexte.put('\n');
+ break;
+ default:
+ ofTexte.put(vFichier[j]);
+ }
+
+ ofTexte << "<FIN>\n\n";
+ }
+
+ return 0;
}
\ No newline at end of file diff --git a/ToD/c_dumper.cpp b/ToD/c_dumper.cpp index edbd8df..669a564 100644 --- a/ToD/c_dumper.cpp +++ b/ToD/c_dumper.cpp @@ -1,140 +1,140 @@ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include "generic.h" -#include "Main.h" -#include "Input.h" -#include "Output.h" - -CODE_BEGINS -int startup() throw (GeneralException) -{ - long valpos = 0; - long valpos2 = 0; - long valposnext = 0; - long valtaille = 0; - char doublon[8]; - char doublon2[8]; - unsigned char pos[3]; - unsigned char taille[3]; - int index = 0; - - Byte segment[257]; - - Input * handleindex = new Input("M.B"); - Input * handlearchi = new Input("M.DAT"); - - while(index!=1315) { - Output * outfile; - String nom_fichier; - - valposnext = valpos + valtaille; - - handleindex->seek(1, SEEK_CUR); // on saute le premier octet - handleindex->read(pos, 3); - valpos = pos[0] + (pos[1] << 8) + (pos[2] << 16); - - handleindex->seek(1, SEEK_CUR); // on saute le premier octet - handleindex->read(taille, 3); - valtaille = taille[0] + (taille[1] << 8) + (taille[2] << 16); - - valpos2 = handleindex->tell(); // sauve la position - doublon[0] = 0; - doublon[1] = pos[0]; - doublon[2] = pos[1]; - doublon[3] = pos[2]; - doublon[4] = 0; - doublon[5] = taille[0]; - doublon[6] = taille[1]; - doublon[7] = taille[2]; // on construit la chaine contenant le pointeur - handleindex->seek(0); - for(int i = 0; i < (valpos2 - 8); i += 8) { - handleindex->read(doublon2, 8); - if(memcmp(doublon, doublon2, 8) == 0) { - printm(M_BARE, "\nIgnore fichier d'index %d\n", index); - index++; - break; - } - } - handleindex->seek(valpos2); // on remet la position au bon endroit - - if (memcmp(doublon, doublon2, 8) == 0) { - continue; - } - - handlearchi->seek(valpos << 8); - - nom_fichier.set("extract\\tod_%04d.out", index); - - ///////////////////// - // A decommenter si les fichiers sont déjà extrait du .DAT - ///////////////////// - - // outfile = fopen(nom_fichier,"rb"); // unarc - - //////////////////// - // Commenter à partir de là jusqu'à la fin du FOR si on a déjà extrait les fichiers du .DAT - //////////////////// - - outfile = new Output(nom_fichier); - - for (int i = 0; i < valtaille; i++) { - handlearchi->read(segment, 256); - outfile->write(segment, 256); - } - //////////////////// - - printm(M_BARE, "\rFichier dumpé : %d",index); - //unarc(outfile,index); - delete outfile; - index++; - - } - delete handleindex; - delete handlearchi; - - printm(M_BARE, "\nNombre de fichiers dumpés : %d",index - 1); - return 0; -} - -void unarc(Input * fichier, int num) -{ - int quantite; - int *pos; - long taille; - char *buf; - String nomarchive; - String nomfichier; - Output *fichierout; - - taille = fichier->GetSize(); - - fichier->read(&quantite, 4); - pos = (int *) malloc(4 * quantite); - fichier->read(pos, 4 * quantite); - nomarchive.set("%04d", num); - MKDIR(nomarchive.to_charp()); - - for (int i = 0; i < quantite - 1; i++) { - buf=(char *) malloc(pos[i+1]-pos[i]); - fichier->read(buf, pos[i + 1] - pos[i]); - nomarchive.set("%04d", i); - - fichierout = new Output(nomarchive + nomfichier); - fichierout->write(buf, pos[i + 1] - pos[i]); - delete fichierout; - } - - buf = (char *) malloc(taille - pos[quantite - 1]); - fichier->read(buf, taille - pos[quantite - 1]); - nomfichier.set("%04d", quantite - 1); - - fichierout = new Output(nomarchive + nomfichier); - fichierout->write(buf, taille - pos[quantite - 1]); - delete fichierout; -} - -int Analyse_table() { - return 1; -} -CODE_ENDS +#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "generic.h"
+#include "Main.h"
+#include "Input.h"
+#include "Output.h"
+
+CODE_BEGINS
+int startup() throw (GeneralException)
+{
+ long valpos = 0;
+ long valpos2 = 0;
+ long valposnext = 0;
+ long valtaille = 0;
+ char doublon[8];
+ char doublon2[8];
+ unsigned char pos[3];
+ unsigned char taille[3];
+ int index = 0;
+
+ Byte segment[257];
+
+ Input * handleindex = new Input("M.B");
+ Input * handlearchi = new Input("M.DAT");
+
+ while(index!=1315) {
+ Output * outfile;
+ String nom_fichier;
+
+ valposnext = valpos + valtaille;
+
+ handleindex->seek(1, SEEK_CUR); // on saute le premier octet
+ handleindex->read(pos, 3);
+ valpos = pos[0] + (pos[1] << 8) + (pos[2] << 16);
+
+ handleindex->seek(1, SEEK_CUR); // on saute le premier octet
+ handleindex->read(taille, 3);
+ valtaille = taille[0] + (taille[1] << 8) + (taille[2] << 16);
+
+ valpos2 = handleindex->tell(); // sauve la position
+ doublon[0] = 0;
+ doublon[1] = pos[0];
+ doublon[2] = pos[1];
+ doublon[3] = pos[2];
+ doublon[4] = 0;
+ doublon[5] = taille[0];
+ doublon[6] = taille[1];
+ doublon[7] = taille[2]; // on construit la chaine contenant le pointeur
+ handleindex->seek(0);
+ for(int i = 0; i < (valpos2 - 8); i += 8) {
+ handleindex->read(doublon2, 8);
+ if(memcmp(doublon, doublon2, 8) == 0) {
+ printm(M_BARE, "\nIgnore fichier d'index %d\n", index);
+ index++;
+ break;
+ }
+ }
+ handleindex->seek(valpos2); // on remet la position au bon endroit
+
+ if (memcmp(doublon, doublon2, 8) == 0) {
+ continue;
+ }
+
+ handlearchi->seek(valpos << 8);
+
+ nom_fichier.set("extract\\tod_%04d.out", index);
+
+ /////////////////////
+ // A decommenter si les fichiers sont déjà extrait du .DAT
+ /////////////////////
+
+ // outfile = fopen(nom_fichier,"rb"); // unarc
+
+ ////////////////////
+ // Commenter à partir de là jusqu'à la fin du FOR si on a déjà extrait les fichiers du .DAT
+ ////////////////////
+
+ outfile = new Output(nom_fichier);
+
+ for (int i = 0; i < valtaille; i++) {
+ handlearchi->read(segment, 256);
+ outfile->write(segment, 256);
+ }
+ ////////////////////
+
+ printm(M_BARE, "\rFichier dumpé : %d",index);
+ //unarc(outfile,index);
+ delete outfile;
+ index++;
+
+ }
+ delete handleindex;
+ delete handlearchi;
+
+ printm(M_BARE, "\nNombre de fichiers dumpés : %d",index - 1);
+ return 0;
+}
+
+void unarc(Input * fichier, int num)
+{
+ int quantite;
+ int *pos;
+ long taille;
+ char *buf;
+ String nomarchive;
+ String nomfichier;
+ Output *fichierout;
+
+ taille = fichier->GetSize();
+
+ fichier->read(&quantite, 4);
+ pos = (int *) malloc(4 * quantite);
+ fichier->read(pos, 4 * quantite);
+ nomarchive.set("%04d", num);
+ MKDIR(nomarchive.to_charp());
+
+ for (int i = 0; i < quantite - 1; i++) {
+ buf=(char *) malloc(pos[i+1]-pos[i]);
+ fichier->read(buf, pos[i + 1] - pos[i]);
+ nomarchive.set("%04d", i);
+
+ fichierout = new Output(nomarchive + nomfichier);
+ fichierout->write(buf, pos[i + 1] - pos[i]);
+ delete fichierout;
+ }
+
+ buf = (char *) malloc(taille - pos[quantite - 1]);
+ fichier->read(buf, taille - pos[quantite - 1]);
+ nomfichier.set("%04d", quantite - 1);
+
+ fichierout = new Output(nomarchive + nomfichier);
+ fichierout->write(buf, taille - pos[quantite - 1]);
+ delete fichierout;
+}
+
+int Analyse_table() {
+ return 1;
+}
+CODE_ENDS
diff --git a/ToF/main_dump.cpp b/ToF/main_dump.cpp index 8c7c5f1..f8af1ea 100644 --- a/ToF/main_dump.cpp +++ b/ToF/main_dump.cpp @@ -1,275 +1,275 @@ -/* - * Threads of Fate extractor by Nicolas "Pixel" Noble (nicolas@nobis-crew.org) - * Highly based upon Yazoo's Chrono Cross CD extractor - * - * ******** Original disclaimer by Yazoo ******** - * - * Chrono Cross CD extractor Copyright 2000-2001 by Yazoo (hamm@efrei.fr) Revision 0.1b ANSI C - * - * - * Features: - * - * Dump the complete content of Chrono Chross CD1/CD2 US and Japanese version It requires a iso - * named Chrono1.iso in the same directory - * - * Todo list: - * - * Find a way to locate end of the last file Better support for CD2 Dump in subdirectory according - * to CD1/CD2 repartition Recompilation in Visual C++ 6 for disk speed optimisation Source comment - * and reorganisation Log feature (Optional since you can redirect output with > ) Progression - * indicator Better detection of the ISO with error control Major code optimisation Integration in - * main Chrono Cross Hacking tool - * - * ******** End of original disclaimer by Yazoo ******** - * - */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include "cdutils.h" -#include "generic.h" -#include "Input.h" -#include "Output.h" -#include "String.h" -#include "Main.h" -#include "cdabstract.h" - -CODE_BEGINS -public: -Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso(0), f_out(0), cdutil(0) {} -virtual ~Appli() { - delete cdutil; - delete f_def; - delete f_iso; - delete f_out; -} -private: - -unsigned int tourne; - -struct t_index_tab { - unsigned long address; - unsigned char flags; - long pad; - long index; - long type; -}; - -struct t_sequence { - unsigned int n; - unsigned int sum; - String prefix; - String name; - int type; -}; - -String title, iso_filename, prefix; -unsigned long iso_size; -unsigned int nb_records, nb_seqs; -struct t_sequence sequences[1000]; -Handle * f_def, * f_iso, * f_out; -cdutils * cdutil; - -unsigned char user_data[2352]; - -virtual int startup() throw (GeneralException) -{ - verbosity = M_INFO; - - fprintf(stderr, -"Threads of Fate File Extractor by Nicolas \"Pixel\" Noble\n" -"Highly based upon the Chrono Cross File Extractor By Yazoo\n\n"); - - if (argc != 3) { - fprintf(stderr, "Usage: %s <definition_file.sqr> <iso_file_name>\nSee readme.txt for details\n", - argv[0]); - throw Exit(-1); - } - - printm(M_STATUS, "Processing file %s...\n", argv[1]); - - f_def = new Input(argv[1]); - - if (process_def_file()) { - printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]); - throw Exit(-1); - } - - iso_filename = argv[2]; - - printm(M_STATUS, "Begin processing iso file.\n"); - f_iso = open_iso(iso_filename); - - if (check_iso()) { - printm(M_ERROR, "Invalid iso file for " + title + "\n"); - printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n"); - } else { - printm(M_INFO, "Genuine " + title + " iso detected.\n"); - } - - cdutil = new cdutils(f_iso); - - printm(M_STATUS, "Entering files read sequence\n"); - read_files(); - throw Exit(0); -} - -/* - * Ugly but working... for now - */ -int process_def_file() -{ - String t; - unsigned int n, sum = 0; - - *f_def >> title; - printm(M_INFO, "Read title: " + title + "\n"); - - *f_def >> t; - iso_size = t.to_int(); - printm(M_INFO, "Read iso size: %lu bytes\n", iso_size); - - *f_def >> prefix; - printm(M_INFO, "Read global directory prefix: " + prefix + "\n"); - - *f_def >> t; - nb_records = t.to_int(); - printm(M_INFO, "Read total of records: %u\n", nb_records); - - while (1) { - *f_def >> t; - n = t.to_int(); - if (!n) { - if (sum == nb_records) { - printm(M_INFO, "Definition file seems coherent\n"); - return 0; - } else { - printm(M_ERROR, "Definition file incoherent\n"); - return 1; - } - } - sum += n; - sequences[nb_seqs].n = n; - sequences[nb_seqs].sum = sum; - *f_def >> sequences[nb_seqs].prefix; - *f_def >> t; - sequences[nb_seqs].type = t.to_int(); - *f_def >> sequences[nb_seqs].name; - printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of " + sequences[nb_seqs].name + " (" + sequences[nb_seqs].prefix + ")\n", - nb_seqs, n, sum); - nb_seqs++; - } -} - -long check_iso() -{ - unsigned long length; - - length = f_iso->GetSize(); - if (length < 0) { - printm(M_INFO, "Can not get file size, assuming reading from cd.\n"); - } else { - printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length); - if (length != iso_size) { - return 1; - } - } - return 0; -} - -void read_files() -{ - t_index_tab index_tab[10000]; - unsigned long i; - unsigned long j; - unsigned int seq = 0; - unsigned long indexer; - - unsigned char fat[24576]; - -#define INDEXPOS 24 - - cdutil->sector_seek(INDEXPOS); - for (i = INDEXPOS; i < (INDEXPOS + 12); i++) { - printm(M_INFO, "Reading fat sector %lu\n", i); - cdutil->read_sector(&fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); - } - - indexer = 0; - for (j = 0; j < 24576; j += 4) { - unsigned char c1, c2, c3; - c1 = fat[j]; - c2 = fat[j + 1]; - c3 = fat[j + 2] & 0x7f; - index_tab[indexer].address = c1 + c2 * 256 + c3 * 65536; - index_tab[indexer].index = j / 4; - index_tab[indexer].flags = fat[j + 2] & 0x80; - index_tab[indexer].pad = fat[j + 3]; - printm(M_INFO, "Found a quite valid index: number %4lu, address %6lu - flags = %02x - pad = %i\n", - indexer, index_tab[indexer].address, fat[j + 3] & 0x80, fat[j + 3] & 0x7f); - indexer++; - if (indexer == nb_records) - break; - } - printm(M_STATUS, "Index file generation complete.\n\n"); - index_tab[indexer].address = f_iso->GetSize() / 2352; - - for (i = 0; i < nb_records; i++) { - if (sequences[seq].sum == i) - seq++; - index_tab[i].type = sequences[seq].type; - if (sequences[seq].type == 0) { - printm(M_INFO, "%6lu - %02x: ignored\n", index_tab[i].address, index_tab[i].flags); - } else { - int size; - printm(M_INFO, "%6lu - %02x: ", index_tab[i].address, index_tab[i].flags); - size = index_tab[i + 1].address - index_tab[i].address; - size *= sec_sizes[index_tab[i].type]; - size -= index_tab[i].pad * 8; - file_dump(index_tab[i].address, size, i, seq); - if (verbosity >= M_INFO) { - fprintf(stderr, "\n"); - } - } - } - fprintf(stderr, "\n"); -} - -void file_dump(unsigned long debut, unsigned long taille, long num, int seq) -{ - long i; - long nbsects; - String nom; - char type = sequences[seq].type; - char ptitbidule[] = "-\\|/"; - - nom = "./" + prefix + "/"; - MKDIR(nom.to_charp()); - - nom += sequences[seq].prefix + "/"; - MKDIR(nom.to_charp()); - - nom += String().set("%04ld.out", num); - - f_out = new Output(nom); - nbsects = taille / sec_sizes[type]; - if (taille % sec_sizes[type]) - nbsects++; - cdutil->sector_seek(debut); - for (i = 0; i < nbsects; i++) { - if (verbosity < M_INFO) - fprintf(stderr, " (%c)\010\010\010\010\010", ptitbidule[((tourne++) >> 8) % 4]); - cdutil->read_sector(user_data, type); - if (i != (nbsects - 1)) { - f_out->write(user_data, sec_sizes[type]); - } else { - f_out->write(user_data, taille % sec_sizes[type] ? taille % sec_sizes[type] : sec_sizes[type]); - } - } - delete f_out; - f_out = 0; - printm(M_BARE, " (*) Dumped file number %4ld - type \"" + sequences[seq].name + "\" \r", num); -} -CODE_ENDS +/*
+ * Threads of Fate extractor by Nicolas "Pixel" Noble (nicolas@nobis-crew.org)
+ * Highly based upon Yazoo's Chrono Cross CD extractor
+ *
+ * ******** Original disclaimer by Yazoo ********
+ *
+ * Chrono Cross CD extractor Copyright 2000-2001 by Yazoo (hamm@efrei.fr) Revision 0.1b ANSI C
+ *
+ *
+ * Features:
+ *
+ * Dump the complete content of Chrono Chross CD1/CD2 US and Japanese version It requires a iso
+ * named Chrono1.iso in the same directory
+ *
+ * Todo list:
+ *
+ * Find a way to locate end of the last file Better support for CD2 Dump in subdirectory according
+ * to CD1/CD2 repartition Recompilation in Visual C++ 6 for disk speed optimisation Source comment
+ * and reorganisation Log feature (Optional since you can redirect output with > ) Progression
+ * indicator Better detection of the ISO with error control Major code optimisation Integration in
+ * main Chrono Cross Hacking tool
+ *
+ * ******** End of original disclaimer by Yazoo ********
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "cdutils.h"
+#include "generic.h"
+#include "Input.h"
+#include "Output.h"
+#include "String.h"
+#include "Main.h"
+#include "cdabstract.h"
+
+CODE_BEGINS
+public:
+Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso(0), f_out(0), cdutil(0) {}
+virtual ~Appli() {
+ delete cdutil;
+ delete f_def;
+ delete f_iso;
+ delete f_out;
+}
+private:
+
+unsigned int tourne;
+
+struct t_index_tab {
+ unsigned long address;
+ unsigned char flags;
+ long pad;
+ long index;
+ long type;
+};
+
+struct t_sequence {
+ unsigned int n;
+ unsigned int sum;
+ String prefix;
+ String name;
+ int type;
+};
+
+String title, iso_filename, prefix;
+unsigned long iso_size;
+unsigned int nb_records, nb_seqs;
+struct t_sequence sequences[1000];
+Handle * f_def, * f_iso, * f_out;
+cdutils * cdutil;
+
+unsigned char user_data[2352];
+
+virtual int startup() throw (GeneralException)
+{
+ verbosity = M_INFO;
+
+ fprintf(stderr,
+"Threads of Fate File Extractor by Nicolas \"Pixel\" Noble\n"
+"Highly based upon the Chrono Cross File Extractor By Yazoo\n\n");
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s <definition_file.sqr> <iso_file_name>\nSee readme.txt for details\n",
+ argv[0]);
+ throw Exit(-1);
+ }
+
+ printm(M_STATUS, "Processing file %s...\n", argv[1]);
+
+ f_def = new Input(argv[1]);
+
+ if (process_def_file()) {
+ printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]);
+ throw Exit(-1);
+ }
+
+ iso_filename = argv[2];
+
+ printm(M_STATUS, "Begin processing iso file.\n");
+ f_iso = open_iso(iso_filename);
+
+ if (check_iso()) {
+ printm(M_ERROR, "Invalid iso file for " + title + "\n");
+ printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n");
+ } else {
+ printm(M_INFO, "Genuine " + title + " iso detected.\n");
+ }
+
+ cdutil = new cdutils(f_iso);
+
+ printm(M_STATUS, "Entering files read sequence\n");
+ read_files();
+ throw Exit(0);
+}
+
+/*
+ * Ugly but working... for now
+ */
+int process_def_file()
+{
+ String t;
+ unsigned int n, sum = 0;
+
+ *f_def >> title;
+ printm(M_INFO, "Read title: " + title + "\n");
+
+ *f_def >> t;
+ iso_size = t.to_int();
+ printm(M_INFO, "Read iso size: %lu bytes\n", iso_size);
+
+ *f_def >> prefix;
+ printm(M_INFO, "Read global directory prefix: " + prefix + "\n");
+
+ *f_def >> t;
+ nb_records = t.to_int();
+ printm(M_INFO, "Read total of records: %u\n", nb_records);
+
+ while (1) {
+ *f_def >> t;
+ n = t.to_int();
+ if (!n) {
+ if (sum == nb_records) {
+ printm(M_INFO, "Definition file seems coherent\n");
+ return 0;
+ } else {
+ printm(M_ERROR, "Definition file incoherent\n");
+ return 1;
+ }
+ }
+ sum += n;
+ sequences[nb_seqs].n = n;
+ sequences[nb_seqs].sum = sum;
+ *f_def >> sequences[nb_seqs].prefix;
+ *f_def >> t;
+ sequences[nb_seqs].type = t.to_int();
+ *f_def >> sequences[nb_seqs].name;
+ printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of " + sequences[nb_seqs].name + " (" + sequences[nb_seqs].prefix + ")\n",
+ nb_seqs, n, sum);
+ nb_seqs++;
+ }
+}
+
+long check_iso()
+{
+ unsigned long length;
+
+ length = f_iso->GetSize();
+ if (length < 0) {
+ printm(M_INFO, "Can not get file size, assuming reading from cd.\n");
+ } else {
+ printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length);
+ if (length != iso_size) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+void read_files()
+{
+ t_index_tab index_tab[10000];
+ unsigned long i;
+ unsigned long j;
+ unsigned int seq = 0;
+ unsigned long indexer;
+
+ unsigned char fat[24576];
+
+#define INDEXPOS 24
+
+ cdutil->sector_seek(INDEXPOS);
+ for (i = INDEXPOS; i < (INDEXPOS + 12); i++) {
+ printm(M_INFO, "Reading fat sector %lu\n", i);
+ cdutil->read_sector(&fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
+ }
+
+ indexer = 0;
+ for (j = 0; j < 24576; j += 4) {
+ unsigned char c1, c2, c3;
+ c1 = fat[j];
+ c2 = fat[j + 1];
+ c3 = fat[j + 2] & 0x7f;
+ index_tab[indexer].address = c1 + c2 * 256 + c3 * 65536;
+ index_tab[indexer].index = j / 4;
+ index_tab[indexer].flags = fat[j + 2] & 0x80;
+ index_tab[indexer].pad = fat[j + 3];
+ printm(M_INFO, "Found a quite valid index: number %4lu, address %6lu - flags = %02x - pad = %i\n",
+ indexer, index_tab[indexer].address, fat[j + 3] & 0x80, fat[j + 3] & 0x7f);
+ indexer++;
+ if (indexer == nb_records)
+ break;
+ }
+ printm(M_STATUS, "Index file generation complete.\n\n");
+ index_tab[indexer].address = f_iso->GetSize() / 2352;
+
+ for (i = 0; i < nb_records; i++) {
+ if (sequences[seq].sum == i)
+ seq++;
+ index_tab[i].type = sequences[seq].type;
+ if (sequences[seq].type == 0) {
+ printm(M_INFO, "%6lu - %02x: ignored\n", index_tab[i].address, index_tab[i].flags);
+ } else {
+ int size;
+ printm(M_INFO, "%6lu - %02x: ", index_tab[i].address, index_tab[i].flags);
+ size = index_tab[i + 1].address - index_tab[i].address;
+ size *= sec_sizes[index_tab[i].type];
+ size -= index_tab[i].pad * 8;
+ file_dump(index_tab[i].address, size, i, seq);
+ if (verbosity >= M_INFO) {
+ fprintf(stderr, "\n");
+ }
+ }
+ }
+ fprintf(stderr, "\n");
+}
+
+void file_dump(unsigned long debut, unsigned long taille, long num, int seq)
+{
+ long i;
+ long nbsects;
+ String nom;
+ char type = sequences[seq].type;
+ char ptitbidule[] = "-\\|/";
+
+ nom = "./" + prefix + "/";
+ MKDIR(nom.to_charp());
+
+ nom += sequences[seq].prefix + "/";
+ MKDIR(nom.to_charp());
+
+ nom += String().set("%04ld.out", num);
+
+ f_out = new Output(nom);
+ nbsects = taille / sec_sizes[type];
+ if (taille % sec_sizes[type])
+ nbsects++;
+ cdutil->sector_seek(debut);
+ for (i = 0; i < nbsects; i++) {
+ if (verbosity < M_INFO)
+ fprintf(stderr, " (%c)\010\010\010\010\010", ptitbidule[((tourne++) >> 8) % 4]);
+ cdutil->read_sector(user_data, type);
+ if (i != (nbsects - 1)) {
+ f_out->write(user_data, sec_sizes[type]);
+ } else {
+ f_out->write(user_data, taille % sec_sizes[type] ? taille % sec_sizes[type] : sec_sizes[type]);
+ }
+ }
+ delete f_out;
+ f_out = 0;
+ printm(M_BARE, " (*) Dumped file number %4ld - type \"" + sequences[seq].name + "\" \r", num);
+}
+CODE_ENDS
diff --git a/VP/decomp-slz.cpp b/VP/decomp-slz.cpp index 076d3bd..a3ff9a1 100644 --- a/VP/decomp-slz.cpp +++ b/VP/decomp-slz.cpp @@ -1,63 +1,63 @@ -#include <stdio.h> -#include <stdlib.h> - -#include "lzss.h" -#include "Input.h" -#include "Output.h" -#include "Main.h" - -CODE_BEGINS -public: -Appli() : lzss_o(new lzss) {} -virtual ~Appli() { - delete lzss_o; -} -private: - -lzss * lzss_o; - -virtual int startup() throw (GeneralException) { - int sig, l, d, v; - Handle * fin = &Stdin, * fout = &Stdout; - - switch (argc) { - case 3: - fout = new Output(argv[2]); - case 2: - fin = new Input(argv[1]); - break; - case 1: - break; - default: - printm(M_BARE, "Usage: %s [filein] [fileout]\n", argv[0]); - return -1; - } - - verbosity = M_STATUS; - - fin->read(&sig, 4); - fin->read(&d, 4); - fin->read(&l, 4); - switch (sig) { - case 0x05a4c53: - printm(M_STATUS, "Detected a SLZ-type 0 file.\n"); - fin->read(&v, 4); - copy(fin, fout, d); - return 0; - case 0x15a4c53: - lzss_o->change_scheme(lzss_o->schemes[lzss_o->VP_1]); - printm(M_STATUS, "Detected a SLZ-type 1 file.\n"); - break; - case 0x25a4c53: - lzss_o->change_scheme(lzss_o->schemes[lzss_o->VP_2]); - printm(M_STATUS, "Detected a SLZ-type 2 file.\n"); - break; - default: - printm(M_ERROR, "Not a SLZ file.\n"); - return -1; - } - - lzss_o->lzss_decomp(fin, fout, l); - return 0; -} -CODE_ENDS +#include <stdio.h>
+#include <stdlib.h>
+
+#include "lzss.h"
+#include "Input.h"
+#include "Output.h"
+#include "Main.h"
+
+CODE_BEGINS
+public:
+Appli() : lzss_o(new lzss) {}
+virtual ~Appli() {
+ delete lzss_o;
+}
+private:
+
+lzss * lzss_o;
+
+virtual int startup() throw (GeneralException) {
+ int sig, l, d, v;
+ Handle * fin = &Stdin, * fout = &Stdout;
+
+ switch (argc) {
+ case 3:
+ fout = new Output(argv[2]);
+ case 2:
+ fin = new Input(argv[1]);
+ break;
+ case 1:
+ break;
+ default:
+ printm(M_BARE, "Usage: %s [filein] [fileout]\n", argv[0]);
+ return -1;
+ }
+
+ verbosity = M_STATUS;
+
+ fin->read(&sig, 4);
+ fin->read(&d, 4);
+ fin->read(&l, 4);
+ switch (sig) {
+ case 0x05a4c53:
+ printm(M_STATUS, "Detected a SLZ-type 0 file.\n");
+ fin->read(&v, 4);
+ copy(fin, fout, d);
+ return 0;
+ case 0x15a4c53:
+ lzss_o->change_scheme(lzss_o->schemes[lzss_o->VP_1]);
+ printm(M_STATUS, "Detected a SLZ-type 1 file.\n");
+ break;
+ case 0x25a4c53:
+ lzss_o->change_scheme(lzss_o->schemes[lzss_o->VP_2]);
+ printm(M_STATUS, "Detected a SLZ-type 2 file.\n");
+ break;
+ default:
+ printm(M_ERROR, "Not a SLZ file.\n");
+ return -1;
+ }
+
+ lzss_o->lzss_decomp(fin, fout, l);
+ return 0;
+}
+CODE_ENDS
diff --git a/VP/main_dump.cpp b/VP/main_dump.cpp index 9fa4dfa..5add9b3 100644 --- a/VP/main_dump.cpp +++ b/VP/main_dump.cpp @@ -1,284 +1,284 @@ -/* - * Valkyrie Profile extractor by Nicolas "Pixel" Noble (nicolas@nobis-crew.org) - * Highly based upon Yazoo's Chrono Cross CD extractor - * - * ******** Original disclaimer by Yazoo ******** - * - * Chrono Cross CD extractor Copyright 2000-2001 by Yazoo (hamm@efrei.fr) Revision 0.1b ANSI C - * - * - * Features: - * - * Dump the complete content of Chrono Chross CD1/CD2 US and Japanese version It requires a iso - * named Chrono1.iso in the same directory - * - * Todo list: - * - * Find a way to locate end of the last file Better support for CD2 Dump in subdirectory according - * to CD1/CD2 repartition Recompilation in Visual C++ 6 for disk speed optimisation Source comment - * and reorganisation Log feature (Optional since you can redirect output with > ) Progression - * indicator Better detection of the ISO with error control Major code optimisation Integration in - * main Chrono Cross Hacking tool - * - * ******** End of original disclaimer by Yazoo ******** - * - */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include "cdutils.h" -#include "generic.h" -#include "Input.h" -#include "Output.h" -#include "BString.h" -#include "Main.h" -#include "cdabstract.h" - -CODE_BEGINS -public: -Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso(0), f_out(0), cdutil(0) {} -virtual ~Appli() { - delete cdutil; - delete f_def; - delete f_iso; - delete f_out; -} -private: - -unsigned int tourne; - -struct t_index_tab { - unsigned long address; - unsigned char flags; - long type; - long index; -}; - -struct t_sequence { - unsigned int n; - unsigned int sum; - String prefix; - String name; - int type; -}; - -String title, iso_filename, prefix; -unsigned long iso_size; -unsigned int nb_records, nb_seqs; -struct t_sequence sequences[1000]; -Handle * f_def, * f_iso, * f_out; -cdutils * cdutil; - -unsigned char user_data[2352]; - -virtual int startup() throw (GeneralException) -{ - verbosity = M_STATUS; - - fprintf(stderr, -"Valkyrie Profile File Extractor by Nicolas \"Pixel\" Noble\n" -"Highly based upon the Chrono Cross File Extractor By Yazoo\n\n"); - - if (argc != 3) { - fprintf(stderr, "Usage: %s <definition_file.sqr> <iso_file_name>\nSee readme.txt for details\n", - argv[0]); - throw Exit(-1); - } - - printm(M_STATUS, "Processing file %s...\n", argv[1]); - - f_def = new Input(argv[1]); - - if (process_def_file()) { - printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]); - throw Exit(-1); - } - - iso_filename = argv[2]; - - printm(M_STATUS, "Begin processing iso file.\n"); - f_iso = open_iso(iso_filename); - - if (check_iso()) { - printm(M_ERROR, "Invalid iso file for " + title + "\n"); - printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n"); - } else { - printm(M_INFO, "Genuine " + title + " iso detected.\n"); - } - - cdutil = new cdutils(f_iso); - - printm(M_STATUS, "Entering files read sequence\n"); - read_files(); - throw Exit(0); -} - -/* - * Ugly but working... for now - */ -int process_def_file() -{ - String t; - unsigned int n, sum = 0; - - *f_def >> title; - printm(M_INFO, "Read title: " + title + "\n"); - - *f_def >> t; - iso_size = t.to_int(); - printm(M_INFO, "Read iso size: %lu bytes\n", iso_size); - - *f_def >> prefix; - printm(M_INFO, "Read global directory prefix: " + prefix + "\n"); - - *f_def >> t; - nb_records = t.to_int(); - printm(M_INFO, "Read total of records: %u\n", nb_records); - - while (1) { - *f_def >> t; - n = t.to_int(); - if (!n) { - if (sum == nb_records) { - printm(M_INFO, "Definition file seems coherent\n"); - return 0; - } else { - printm(M_ERROR, "Definition file incoherent\n"); - return 1; - } - } - sum += n; - sequences[nb_seqs].n = n; - sequences[nb_seqs].sum = sum; - *f_def >> sequences[nb_seqs].prefix; - *f_def >> t; - sequences[nb_seqs].type = t.to_int(); - *f_def >> sequences[nb_seqs].name; - printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of " + sequences[nb_seqs].name + " (" + sequences[nb_seqs].prefix + ")\n", - nb_seqs, n, sum); - nb_seqs++; - } -} - -long check_iso() -{ - unsigned long length; - - length = f_iso->GetSize(); - if (length < 0) { - printm(M_INFO, "Can not get file size, assuming reading from cd.\n"); - } else { - printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length); - if (length != iso_size) { - return 1; - } - } - return 0; -} - -void read_files() -{ - t_index_tab index_tab[10000]; - unsigned long i; - unsigned long j; - unsigned int seq = 0; - unsigned long indexer; - - unsigned char fat[20480]; - unsigned char key[256]; - -#define INDEXPOS 150 - - cdutil->sector_seek(INDEXPOS); - for (i = INDEXPOS; i < (INDEXPOS + 10); i++) { - printm(M_INFO, "Reading fat sector %lu\n", i); - cdutil->read_sector(&fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); - } - - memcpy(key, fat + 0x4f00, 256); - - printm(M_INFO, "Decrypting.\n"); - for (i = 0; i < 20480; i++) { - fat[i] ^= key[i % 256]; - } - - indexer = 0; - for (j = 4; j < 20480; j += 4) { - unsigned char m, s, f; - m = fat[j]; - s = fat[j + 1]; - f = fat[j + 2]; - index_tab[indexer].address = cdutil->from_MSF(m, s, f); - if (m || s || f) { - index_tab[indexer].index = j / 4; - index_tab[indexer].flags = fat[j + 3]; - printm(M_INFO, "Found a quite valid index: number %4lu, address %6lu - flags = %02x\n", - indexer, index_tab[indexer].address, fat[j + 3]); - indexer++; - if (indexer == nb_records) - break; - } else { - printm(M_WARNING, "Ignored invalid index chunk number %4lu\n", j / 4); - } - } - printm(M_STATUS, "Index file generation complete.\n\n"); - index_tab[indexer].address = f_iso->GetSize() / 2352; - - for (i = 0; i < nb_records; i++) { - if (sequences[seq].sum == i) - seq++; - index_tab[i].type = sequences[seq].type; - if (sequences[seq].type == 0) { - printm(M_INFO, "%6lu - %02x: ignored\n", index_tab[i].address, index_tab[i].flags); - } else { - int size; - printm(M_INFO, "%6lu - %02x: ", index_tab[i].address, index_tab[i].flags); - size = index_tab[i + 1].address - index_tab[i].address; - size *= sec_sizes[index_tab[i].type]; - file_dump(index_tab[i].address, size, i, seq); - if (verbosity >= M_INFO) { - fprintf(stderr, "\n"); - } - } - } - fprintf(stderr, "\n"); -} - -void file_dump(unsigned long debut, unsigned long taille, long num, int seq) -{ - long i; - long nbsects; - String nom; - char type = sequences[seq].type; - char ptitbidule[] = "-\\|/"; - - nom = "./" + prefix + "/"; - MKDIR(nom.to_charp()); - - nom += sequences[seq].prefix + "/"; - MKDIR(nom.to_charp()); - - nom += String().set("%04ld.out", num); - - f_out = new Output(nom); - nbsects = taille / sec_sizes[type]; - if (taille % sec_sizes[type]) - nbsects++; - cdutil->sector_seek(debut); - for (i = 0; i < nbsects; i++) { - if (verbosity < M_INFO) - fprintf(stderr, " (%c)\010\010\010\010\010", ptitbidule[((tourne++) >> 8) % 4]); - cdutil->read_sector(user_data, type); - if (i != (nbsects - 1)) { - f_out->write(user_data, sec_sizes[type]); - } else { - f_out->write(user_data, taille % sec_sizes[type] ? taille % sec_sizes[type] : sec_sizes[type]); - } - } - delete f_out; - f_out = 0; - printm(M_BARE, " (*) Dumped file number %4ld - type \"" + sequences[seq].name + "\" \r", num); -} -CODE_ENDS +/*
+ * Valkyrie Profile extractor by Nicolas "Pixel" Noble (nicolas@nobis-crew.org)
+ * Highly based upon Yazoo's Chrono Cross CD extractor
+ *
+ * ******** Original disclaimer by Yazoo ********
+ *
+ * Chrono Cross CD extractor Copyright 2000-2001 by Yazoo (hamm@efrei.fr) Revision 0.1b ANSI C
+ *
+ *
+ * Features:
+ *
+ * Dump the complete content of Chrono Chross CD1/CD2 US and Japanese version It requires a iso
+ * named Chrono1.iso in the same directory
+ *
+ * Todo list:
+ *
+ * Find a way to locate end of the last file Better support for CD2 Dump in subdirectory according
+ * to CD1/CD2 repartition Recompilation in Visual C++ 6 for disk speed optimisation Source comment
+ * and reorganisation Log feature (Optional since you can redirect output with > ) Progression
+ * indicator Better detection of the ISO with error control Major code optimisation Integration in
+ * main Chrono Cross Hacking tool
+ *
+ * ******** End of original disclaimer by Yazoo ********
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "cdutils.h"
+#include "generic.h"
+#include "Input.h"
+#include "Output.h"
+#include "BString.h"
+#include "Main.h"
+#include "cdabstract.h"
+
+CODE_BEGINS
+public:
+Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso(0), f_out(0), cdutil(0) {}
+virtual ~Appli() {
+ delete cdutil;
+ delete f_def;
+ delete f_iso;
+ delete f_out;
+}
+private:
+
+unsigned int tourne;
+
+struct t_index_tab {
+ unsigned long address;
+ unsigned char flags;
+ long type;
+ long index;
+};
+
+struct t_sequence {
+ unsigned int n;
+ unsigned int sum;
+ String prefix;
+ String name;
+ int type;
+};
+
+String title, iso_filename, prefix;
+unsigned long iso_size;
+unsigned int nb_records, nb_seqs;
+struct t_sequence sequences[1000];
+Handle * f_def, * f_iso, * f_out;
+cdutils * cdutil;
+
+unsigned char user_data[2352];
+
+virtual int startup() throw (GeneralException)
+{
+ verbosity = M_STATUS;
+
+ fprintf(stderr,
+"Valkyrie Profile File Extractor by Nicolas \"Pixel\" Noble\n"
+"Highly based upon the Chrono Cross File Extractor By Yazoo\n\n");
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s <definition_file.sqr> <iso_file_name>\nSee readme.txt for details\n",
+ argv[0]);
+ throw Exit(-1);
+ }
+
+ printm(M_STATUS, "Processing file %s...\n", argv[1]);
+
+ f_def = new Input(argv[1]);
+
+ if (process_def_file()) {
+ printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]);
+ throw Exit(-1);
+ }
+
+ iso_filename = argv[2];
+
+ printm(M_STATUS, "Begin processing iso file.\n");
+ f_iso = open_iso(iso_filename);
+
+ if (check_iso()) {
+ printm(M_ERROR, "Invalid iso file for " + title + "\n");
+ printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n");
+ } else {
+ printm(M_INFO, "Genuine " + title + " iso detected.\n");
+ }
+
+ cdutil = new cdutils(f_iso);
+
+ printm(M_STATUS, "Entering files read sequence\n");
+ read_files();
+ throw Exit(0);
+}
+
+/*
+ * Ugly but working... for now
+ */
+int process_def_file()
+{
+ String t;
+ unsigned int n, sum = 0;
+
+ *f_def >> title;
+ printm(M_INFO, "Read title: " + title + "\n");
+
+ *f_def >> t;
+ iso_size = t.to_int();
+ printm(M_INFO, "Read iso size: %lu bytes\n", iso_size);
+
+ *f_def >> prefix;
+ printm(M_INFO, "Read global directory prefix: " + prefix + "\n");
+
+ *f_def >> t;
+ nb_records = t.to_int();
+ printm(M_INFO, "Read total of records: %u\n", nb_records);
+
+ while (1) {
+ *f_def >> t;
+ n = t.to_int();
+ if (!n) {
+ if (sum == nb_records) {
+ printm(M_INFO, "Definition file seems coherent\n");
+ return 0;
+ } else {
+ printm(M_ERROR, "Definition file incoherent\n");
+ return 1;
+ }
+ }
+ sum += n;
+ sequences[nb_seqs].n = n;
+ sequences[nb_seqs].sum = sum;
+ *f_def >> sequences[nb_seqs].prefix;
+ *f_def >> t;
+ sequences[nb_seqs].type = t.to_int();
+ *f_def >> sequences[nb_seqs].name;
+ printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of " + sequences[nb_seqs].name + " (" + sequences[nb_seqs].prefix + ")\n",
+ nb_seqs, n, sum);
+ nb_seqs++;
+ }
+}
+
+long check_iso()
+{
+ unsigned long length;
+
+ length = f_iso->GetSize();
+ if (length < 0) {
+ printm(M_INFO, "Can not get file size, assuming reading from cd.\n");
+ } else {
+ printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length);
+ if (length != iso_size) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+void read_files()
+{
+ t_index_tab index_tab[10000];
+ unsigned long i;
+ unsigned long j;
+ unsigned int seq = 0;
+ unsigned long indexer;
+
+ unsigned char fat[20480];
+ unsigned char key[256];
+
+#define INDEXPOS 150
+
+ cdutil->sector_seek(INDEXPOS);
+ for (i = INDEXPOS; i < (INDEXPOS + 10); i++) {
+ printm(M_INFO, "Reading fat sector %lu\n", i);
+ cdutil->read_sector(&fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
+ }
+
+ memcpy(key, fat + 0x4f00, 256);
+
+ printm(M_INFO, "Decrypting.\n");
+ for (i = 0; i < 20480; i++) {
+ fat[i] ^= key[i % 256];
+ }
+
+ indexer = 0;
+ for (j = 4; j < 20480; j += 4) {
+ unsigned char m, s, f;
+ m = fat[j];
+ s = fat[j + 1];
+ f = fat[j + 2];
+ index_tab[indexer].address = cdutil->from_MSF(m, s, f);
+ if (m || s || f) {
+ index_tab[indexer].index = j / 4;
+ index_tab[indexer].flags = fat[j + 3];
+ printm(M_INFO, "Found a quite valid index: number %4lu, address %6lu - flags = %02x\n",
+ indexer, index_tab[indexer].address, fat[j + 3]);
+ indexer++;
+ if (indexer == nb_records)
+ break;
+ } else {
+ printm(M_WARNING, "Ignored invalid index chunk number %4lu\n", j / 4);
+ }
+ }
+ printm(M_STATUS, "Index file generation complete.\n\n");
+ index_tab[indexer].address = f_iso->GetSize() / 2352;
+
+ for (i = 0; i < nb_records; i++) {
+ if (sequences[seq].sum == i)
+ seq++;
+ index_tab[i].type = sequences[seq].type;
+ if (sequences[seq].type == 0) {
+ printm(M_INFO, "%6lu - %02x: ignored\n", index_tab[i].address, index_tab[i].flags);
+ } else {
+ int size;
+ printm(M_INFO, "%6lu - %02x: ", index_tab[i].address, index_tab[i].flags);
+ size = index_tab[i + 1].address - index_tab[i].address;
+ size *= sec_sizes[index_tab[i].type];
+ file_dump(index_tab[i].address, size, i, seq);
+ if (verbosity >= M_INFO) {
+ fprintf(stderr, "\n");
+ }
+ }
+ }
+ fprintf(stderr, "\n");
+}
+
+void file_dump(unsigned long debut, unsigned long taille, long num, int seq)
+{
+ long i;
+ long nbsects;
+ String nom;
+ char type = sequences[seq].type;
+ char ptitbidule[] = "-\\|/";
+
+ nom = "./" + prefix + "/";
+ MKDIR(nom.to_charp());
+
+ nom += sequences[seq].prefix + "/";
+ MKDIR(nom.to_charp());
+
+ nom += String().set("%04ld.out", num);
+
+ f_out = new Output(nom);
+ nbsects = taille / sec_sizes[type];
+ if (taille % sec_sizes[type])
+ nbsects++;
+ cdutil->sector_seek(debut);
+ for (i = 0; i < nbsects; i++) {
+ if (verbosity < M_INFO)
+ fprintf(stderr, " (%c)\010\010\010\010\010", ptitbidule[((tourne++) >> 8) % 4]);
+ cdutil->read_sector(user_data, type);
+ if (i != (nbsects - 1)) {
+ f_out->write(user_data, sec_sizes[type]);
+ } else {
+ f_out->write(user_data, taille % sec_sizes[type] ? taille % sec_sizes[type] : sec_sizes[type]);
+ }
+ }
+ delete f_out;
+ f_out = 0;
+ printm(M_BARE, " (*) Dumped file number %4ld - type \"" + sequences[seq].name + "\" \r", num);
+}
+CODE_ENDS
diff --git a/VP/search-script.cpp b/VP/search-script.cpp index ebbf214..d68149f 100644 --- a/VP/search-script.cpp +++ b/VP/search-script.cpp @@ -1,73 +1,73 @@ -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include "fileutils.h" -#include "generic.h" - -#define THRESHOLD 2000 - -int main(int argc, char ** argv) { - int h, n, o, i, p, c, pp, b; - - verbosity = M_INFO; - - if (argc != 2) { - printm(M_BARE, "Usage: search-script <file>\n"); - exit(-1); - } - - if ((h = open(argv[1], O_RDONLY)) < 0) { - printm(M_ERROR, "Error opening file %s\n", argv[1]); - exit(-1); - } - - printm(M_STATUS, "Reading informations from %s...\n", argv[1]); - - read(h, &n, 4); - - o = n; - - n -= 4; - n /= 8; - - printm(M_INFO, "Script claims to have %i texts.\n", n); - - if (n > THRESHOLD) { - printm(M_ERROR, "Too much texts to make sense.\n"); - exit(-1); - } - - printm(M_STATUS, "Reading index.\n"); - - pp = -1; - for (i = 0; i < n; i++) { - lseek(h, i * 8 + 4, SEEK_SET); - read(h, &c, 4); - read(h, &p, 4); - printm(M_INFO, "Index #%i has pointer %i and counter %i\n", i, p, c); - if (pp > p) { - printm(M_ERROR, "Script's text overlapping.\n"); - exit(-1); - } - - if (((unsigned int)(p + o)) > filesize(h)) { - printm(M_ERROR, "Text bigger than script.\n"); - exit(-1); - } - - lseek(h, p + o - 1, SEEK_SET); - b = 0; - read(h, &b, 1); - - if (b) { - printm(M_ERROR, "Byte before the pointer is not 0 (%i = 0x%02x)\n", b, b); - exit(-1); - } - - pp = p; - } - - printm(M_STATUS, "Script seems ok to me.\n"); - - exit(0); -} +#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "fileutils.h"
+#include "generic.h"
+
+#define THRESHOLD 2000
+
+int main(int argc, char ** argv) {
+ int h, n, o, i, p, c, pp, b;
+
+ verbosity = M_INFO;
+
+ if (argc != 2) {
+ printm(M_BARE, "Usage: search-script <file>\n");
+ exit(-1);
+ }
+
+ if ((h = open(argv[1], O_RDONLY)) < 0) {
+ printm(M_ERROR, "Error opening file %s\n", argv[1]);
+ exit(-1);
+ }
+
+ printm(M_STATUS, "Reading informations from %s...\n", argv[1]);
+
+ read(h, &n, 4);
+
+ o = n;
+
+ n -= 4;
+ n /= 8;
+
+ printm(M_INFO, "Script claims to have %i texts.\n", n);
+
+ if (n > THRESHOLD) {
+ printm(M_ERROR, "Too much texts to make sense.\n");
+ exit(-1);
+ }
+
+ printm(M_STATUS, "Reading index.\n");
+
+ pp = -1;
+ for (i = 0; i < n; i++) {
+ lseek(h, i * 8 + 4, SEEK_SET);
+ read(h, &c, 4);
+ read(h, &p, 4);
+ printm(M_INFO, "Index #%i has pointer %i and counter %i\n", i, p, c);
+ if (pp > p) {
+ printm(M_ERROR, "Script's text overlapping.\n");
+ exit(-1);
+ }
+
+ if (((unsigned int)(p + o)) > filesize(h)) {
+ printm(M_ERROR, "Text bigger than script.\n");
+ exit(-1);
+ }
+
+ lseek(h, p + o - 1, SEEK_SET);
+ b = 0;
+ read(h, &b, 1);
+
+ if (b) {
+ printm(M_ERROR, "Byte before the pointer is not 0 (%i = 0x%02x)\n", b, b);
+ exit(-1);
+ }
+
+ pp = p;
+ }
+
+ printm(M_STATUS, "Script seems ok to me.\n");
+
+ exit(0);
+}
diff --git a/VP/unarc.cpp b/VP/unarc.cpp index 36a258a..1584041 100644 --- a/VP/unarc.cpp +++ b/VP/unarc.cpp @@ -1,79 +1,79 @@ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include "Input.h" -#include "Output.h" -#include "generic.h" -#include "Main.h" - -#define THRESHOLD 2000 - -CODE_BEGINS -virtual int startup() throw(GeneralException) { - int n, * index, * sizes, i, d; - String temp; - Handle * h, * o; - - verbosity = M_INFO; - - if (argc != 2) { - printm(M_BARE, "Usage: unarc <archive>\n"); - exit(-1); - } - - h = new Input(argv[1]); - - h->read(&n, 4); - - printm(M_STATUS, "Archive claims to have %i files, checking integrity.\n", n); - - if (n > THRESHOLD) { - printm(M_ERROR, "Archive has more than %i files, that doesn't make sense to me.\n", THRESHOLD); - exit(-1); - } - - index = (int *) malloc(n * sizeof(int)); - sizes = (int *) malloc(n * sizeof(int)); - - for (i = 0; i < n; i++) { - h->seek((i + 1) * 8 + 4, SEEK_SET); - h->read(&(sizes[i]), 4); - printm(M_INFO, "File #%i size = %i = 0x%08x\n", i, sizes[i], sizes[i]); - } - - index[0] = (n + 1) * 8; - i = 0; - printm(M_INFO, "Index #%i = %i = 0x%08x\n", i, index[i], index[i]); - - for (i = 1; i < n; i++) { - index[i] = index[i - 1] + sizes[i - 1]; - printm(M_INFO, "Index #%i = %i = 0x%08x\n", i, index[i], index[i]); - } - - d = h->GetSize() - index[n - 1] - sizes[n - 1]; - - printm(M_INFO, "Archive size: %i, last index: %i, last file size: %i, difference = %i\n", h->GetSize(), index[n - 1], sizes[n - 1], d); - - if ((d < 0) || (d > 2048)) { - printm(M_ERROR, "Archive incoherent.\n"); - exit(-1); - } - - printm(M_STATUS, "Archive seems to be ok, extracting.\n"); - - for (i = 0; i < n; i++) { - temp.set("%04i.out", i); - o = new Output(temp); - - printm(M_INFO, "Extracting " + temp + "\n"); - - h->seek(index[i], SEEK_SET); - copy(h, o, sizes[i]); - delete o; - } - - delete h; - return 0; -} -CODE_ENDS +#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "Input.h"
+#include "Output.h"
+#include "generic.h"
+#include "Main.h"
+
+#define THRESHOLD 2000
+
+CODE_BEGINS
+virtual int startup() throw(GeneralException) {
+ int n, * index, * sizes, i, d;
+ String temp;
+ Handle * h, * o;
+
+ verbosity = M_INFO;
+
+ if (argc != 2) {
+ printm(M_BARE, "Usage: unarc <archive>\n");
+ exit(-1);
+ }
+
+ h = new Input(argv[1]);
+
+ h->read(&n, 4);
+
+ printm(M_STATUS, "Archive claims to have %i files, checking integrity.\n", n);
+
+ if (n > THRESHOLD) {
+ printm(M_ERROR, "Archive has more than %i files, that doesn't make sense to me.\n", THRESHOLD);
+ exit(-1);
+ }
+
+ index = (int *) malloc(n * sizeof(int));
+ sizes = (int *) malloc(n * sizeof(int));
+
+ for (i = 0; i < n; i++) {
+ h->seek((i + 1) * 8 + 4, SEEK_SET);
+ h->read(&(sizes[i]), 4);
+ printm(M_INFO, "File #%i size = %i = 0x%08x\n", i, sizes[i], sizes[i]);
+ }
+
+ index[0] = (n + 1) * 8;
+ i = 0;
+ printm(M_INFO, "Index #%i = %i = 0x%08x\n", i, index[i], index[i]);
+
+ for (i = 1; i < n; i++) {
+ index[i] = index[i - 1] + sizes[i - 1];
+ printm(M_INFO, "Index #%i = %i = 0x%08x\n", i, index[i], index[i]);
+ }
+
+ d = h->GetSize() - index[n - 1] - sizes[n - 1];
+
+ printm(M_INFO, "Archive size: %i, last index: %i, last file size: %i, difference = %i\n", h->GetSize(), index[n - 1], sizes[n - 1], d);
+
+ if ((d < 0) || (d > 2048)) {
+ printm(M_ERROR, "Archive incoherent.\n");
+ exit(-1);
+ }
+
+ printm(M_STATUS, "Archive seems to be ok, extracting.\n");
+
+ for (i = 0; i < n; i++) {
+ temp.set("%04i.out", i);
+ o = new Output(temp);
+
+ printm(M_INFO, "Extracting " + temp + "\n");
+
+ h->seek(index[i], SEEK_SET);
+ copy(h, o, sizes[i]);
+ delete o;
+ }
+
+ delete h;
+ return 0;
+}
+CODE_ENDS
diff --git a/Xenogears/Decrypt.cpp b/Xenogears/Decrypt.cpp index 0683078..7cdb1aa 100644 --- a/Xenogears/Decrypt.cpp +++ b/Xenogears/Decrypt.cpp @@ -1,513 +1,513 @@ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include "generic.h" -#include "Input.h" -#include "Output.h" -#include "Main.h" - -CODE_BEGINS -void init_table(long table[5000]) -{ - long i; - - for (i = 0; i < 5000; i++) { - table[i] = 0; - } -} - -char found_position(long table[5000], int number, FILE * f_source) -{ - long position; - long i; - - position = ftell(f_source); - - for (i = 0; i < number; i++) { - if (table[i] <= position) - return (1); - } - return (0); -} - -long found_next(long table[5000], long script_number, long max_script) -{ - long i; - long next = 0xFFFF; - long actual = table[script_number]; - - for (i = 0; i < script_number; i++) { - if (table[i] > actual) { - if (table[i] < next) - next = table[i]; - } - } - - for (i = script_number + 1; i < max_script; i++) { - if (table[i] > actual) { - if (table[i] < next) - next = table[i]; - } - } - - return (next); -} - -void dump_text(FILE * f_source, FILE * f_cible, long table[5000], long script_number, - long max_script, unsigned char *length_table, unsigned char *line_table) -{ - long next; - unsigned char val; - char temp_string[2] = {0, 0}; - long position; - unsigned char temp1 = 0; - unsigned char temp2 = 0; - - next = found_next(table, script_number, max_script); - - fseek(f_source, table[script_number], SEEK_SET); - - fprintf(f_cible, "<Text_block lines:%d width:%d>\n", - line_table[script_number], length_table[script_number]); - - position = ftell(f_source); - - while (position < next) { - val = 0; - - fread((unsigned char *) &val, 1, 1, f_source); - - if (val == 0x00) // "<Close>" - { - break; - } else if (val == 0x01) // "\n" - { - fprintf(f_cible, "\n"); - } else if (val == 0x02) // "<New>" - { - fprintf(f_cible, "<New>\n"); - } else if (val == 0x03) // "<Wait>" - { - fprintf(f_cible, "<Wait>"); - } else if (val == 0x0F) // Extended opcode. Reads two more bytes. - { - fread((unsigned char *) &temp1, 1, 1, f_source); - fread((unsigned char *) &temp2, 1, 1, f_source); - if (temp1 == 0) { - fprintf(f_cible, "<Delay %d>", temp2); - } else if (temp1 == 5) { - switch (temp2) { - case 0: - fprintf(f_cible, "<Fei>"); - break; - case 1: - fprintf(f_cible, "<Elly>"); - break; - case 2: - fprintf(f_cible, "<Citan>"); - break; - case 3: - fprintf(f_cible, "<Bart>"); - break; - case 4: - fprintf(f_cible, "<Billy>"); - break; - case 5: - fprintf(f_cible, "<Rico>"); - break; - case 6: - fprintf(f_cible, "<Emeralda>"); - break; - case 7: - fprintf(f_cible, "<Chu-Chu>"); - break; - case 8: - fprintf(f_cible, "<Maria>"); - break; - case 9: - fprintf(f_cible, "<Citan2>"); - break; - case 10: - fprintf(f_cible, "<Emeralda2>"); - break; - case 11: - fprintf(f_cible, "<Weltall>"); - break; - case 12: - fprintf(f_cible, "<Weltall-2>"); - break; - case 13: - fprintf(f_cible, "<Vierge>"); - break; - case 14: - fprintf(f_cible, "<Heimdal>"); - break; - case 15: - fprintf(f_cible, "<Brigandier>"); - break; - case 16: - fprintf(f_cible, "<Renmazuo>"); - break; - case 17: - fprintf(f_cible, "<Stier>"); - break; - case 18: - fprintf(f_cible, "<BigChu-chu>"); - break; - case 19: - fprintf(f_cible, "<Seibzehn>"); - break; - case 20: - fprintf(f_cible, "<Crescens>"); - break; - case 21: - fprintf(f_cible, "<Regurus>"); - break; - case 22: - fprintf(f_cible, "<Fenrir>"); - break; - case 23: - fprintf(f_cible, "<Andvari>"); - break; - case 24: - fprintf(f_cible, "<Renmazuo>"); - break; - case 25: - fprintf(f_cible, "<Stier-2>"); - break; - case 26: - fprintf(f_cible, "<Xenogears>"); - break; - case 27: - fprintf(f_cible, "<BARTHOS>"); - break; - case 28: - fprintf(f_cible, "<Yggdra>"); - break; - case 128: - fprintf(f_cible, "<Perso1>"); - break; - case 129: - fprintf(f_cible, "<Perso2>"); - break; - case 130: - fprintf(f_cible, "<Perso3>"); - break; - default: - fprintf(f_cible, "<Gear %d>", temp2); - } - } else { - fprintf(f_cible, "<Opcode %d %d>", temp1, temp2); - } - } else if (val == 0x10) // " " - { - fprintf(f_cible, " "); - } else if (val == 0x11) // "+" - { - fprintf(f_cible, "+"); - } else if (val == 0x12) // "," - { - fprintf(f_cible, ","); - } else if (val == 0x13) // "-" - { - fprintf(f_cible, "-"); - } else if (val == 0x14) // "." - { - fprintf(f_cible, "."); - } else if (val == 0x15) // "/" - { - fprintf(f_cible, "/"); - } else if ((val >= 0x16) && (val <= 0x1F)) // "0-9" - { - temp_string[0] = val + 0x1A; - fprintf(f_cible, temp_string); - } else if ((val >= 0x20) && (val <= 0x39)) // "A-Z" - { - temp_string[0] = val + 0x21; - fprintf(f_cible, temp_string); - } else if (val == 0x3A) // "[" - { - fprintf(f_cible, "["); - } else if (val == 0x3B) // "]" - { - fprintf(f_cible, "]"); - } else if (val == 0x3C) // "=" - { - fprintf(f_cible, "="); - } else if ((val >= 0x3D) && (val <= 0x56)) // "a-z" - { - temp_string[0] = val + 0x24; - fprintf(f_cible, temp_string); - } else if (val == 0x57) // "!" - { - fprintf(f_cible, "!"); - } else if (val == 0x58) // "\"" - { - fprintf(f_cible, "\""); - } else if (val == 0x59) // "#" - { - fprintf(f_cible, "#"); - } else if (val == 0x5A) // "%" - { - fprintf(f_cible, "%%"); - } else if (val == 0x5B) // "&" - { - fprintf(f_cible, "&"); - } else if (val == 0x5C) // "'" - { - fprintf(f_cible, "'"); - } else if (val == 0x5D) // "(" - { - fprintf(f_cible, "("); - } else if (val == 0x5E) // ")" - { - fprintf(f_cible, ")"); - } else if (val == 0x5F) // ":" - { - fprintf(f_cible, ":"); - } else if (val == 0x60) // "?" - { - fprintf(f_cible, "?"); - } else if (val == 0x61) // "<0>" - { - fprintf(f_cible, "<0>"); - } else if (val == 0x62) // "<1>" - { - fprintf(f_cible, "<1>"); - } else if (val == 0x63) // "<2>" - { - fprintf(f_cible, "<2>"); - } else if (val == 0x64) // "<3>" - { - fprintf(f_cible, "<3>"); - } else if (val == 0x65) // "<4>" - { - fprintf(f_cible, "<4>"); - } else if (val == 0x66) // "<5>" - { - fprintf(f_cible, "<5>"); - } else if (val == 0x67) // "<6>" - { - fprintf(f_cible, "<6>"); - } else if (val == 0x68) // "<7>" - { - fprintf(f_cible, "<7>"); - } else if (val == 0x69) // "<8>" - { - fprintf(f_cible, "<8>"); - } else if (val == 0x6A) // "<9>" - { - fprintf(f_cible, "<9>"); - } else if (val == 0x6B) // "<%>" - { - fprintf(f_cible, "<%%>"); - } else if (val == 0x6C) // "<&>" - { - fprintf(f_cible, "<&>"); - } else if (val == 0x6D) // "*" - { - fprintf(f_cible, "*"); - } else if (val == 0x6E) // "<C>" - { - fprintf(f_cible, "<C>"); - } else if (val == 0x6F) // "<S>" - { - fprintf(f_cible, "<S>"); - } else if (val == 0x70) // "<T>" - { - fprintf(f_cible, "<T>"); - } else if (val == 0x71) // "<*>" - { - fprintf(f_cible, "<*>"); - } else if (val == 0x72) // "<R>" - { - fprintf(f_cible, "<R>"); - } else if (val == 0x73) // "<L>" - { - fprintf(f_cible, "<L>"); - } else if (val == 0x74) // "<U>" - { - fprintf(f_cible, "<U>"); - } else if (val == 0x75) // "<U>" - { - fprintf(f_cible, "<D>"); - } else if (val == 0x76) // "<.>" - { - fprintf(f_cible, "<.>"); - } else if (val == 0x77) // "<:>" - { - fprintf(f_cible, "<:>"); - } else if (val == 0x79) // "</>" - { - fprintf(f_cible, "</>"); - } else if (val == 0x7A) // "<..>" - { - fprintf(f_cible, "<..>"); - } else if (val == 0x7B) // "<`>" - { - fprintf(f_cible, "<`>"); - } else if (val == 0x7D) // "<+>" - { - fprintf(f_cible, "<+>"); - } else if (val == 0x7E) // "<->" - { - fprintf(f_cible, "<->"); - } else if (val == 0x7F) // "<X>" - { - fprintf(f_cible, "<X>"); - } else if (val == 0x80) // "<[>" - { - fprintf(f_cible, "<[>"); - } else if (val == 0x81) // "<]>" - { - fprintf(f_cible, "<]>"); - } else if (val == 0x82) // "<%>" - { - fprintf(f_cible, "<%%>"); - } else if (val == 0x83) // "<&>" - { - fprintf(f_cible, "<&>"); - } else if (val == 0x84) // "<(>" - { - fprintf(f_cible, "<(>"); - } else if (val == 0x85) // "<)>" - { - fprintf(f_cible, "<)>"); - } else if (val == 0x86) // "<#>" - { - fprintf(f_cible, "<#>"); - } else if (val == 0x87) // "`" - { - fprintf(f_cible, "`"); - } else if (val == 0x88) // "°" - { - fprintf(f_cible, "°"); - } else if (val == 0x89) // "<=>" - { - fprintf(f_cible, "<=>"); - } else if (val == 0x8A) // "<?>" - { - fprintf(f_cible, "<?>"); - } else if (val == 0x8B) // "<!>" - { - fprintf(f_cible, "<!>"); - } else if (val == 0x8C) // "_" - { - fprintf(f_cible, "_"); - } else if (val == 0x8D) // "~" - { - fprintf(f_cible, "~"); - } else if (val == 0x8E) // "<...>" - { - fprintf(f_cible, "<...>"); - } else if (val == 0x8F) // "<'>" - { - fprintf(f_cible, "<'>"); - } else if (val == 0xFE) // "<Extra1 X> - { - fread((unsigned char *) &temp1, 1, 1, f_source); - fprintf(f_cible, "<Extra1 %d>", temp1); - } else if (val == 0xFF) // "<Extra2 X> - { - fread((unsigned char *) &temp1, 1, 1, f_source); - fprintf(f_cible, "<Extra2 %d>", temp1); - } else { - fprintf(f_cible, "<Bare %X>", val); - } - - position = ftell(f_source); - } - fprintf(f_cible, "\n<End_of_block>\n\n"); -} - -int decrypt(FILE * f_source, FILE * f_cible, int room_number) -{ - long i, j; - long table[5000]; - unsigned char line_table[5000]; - unsigned char length_table[5000]; - long script_number = 0; - long temp = 0; - char temp_char; - int counter = 0; - - fread((long *) &script_number, 4, 1, f_source); - - if (script_number == 0x0000FFFF) - return (1); - - script_number = (script_number++); - - fprintf(f_cible, "<Blocks:%li>\n", script_number); - init_table(table); - - i = j = 0; - - while (i < script_number) { - fread((long *) &temp, 2, 1, f_source); - if (table[j - 1] != temp) - table[j++] = temp; - i++; - } - - script_number = j; - - for (i = 0; i < script_number; i++) { - fread((unsigned char *) &length_table[i], 1, 1, f_source); - fread((unsigned char *) &line_table[i], 1, 1, f_source); - } - - fseek(f_source, table[script_number - 1], SEEK_SET); - - do { - fread((char *) &temp_char, 1, 1, f_source); - counter++; - } while (temp_char != 0); - - table[script_number] = ftell(f_source); - - for (i = 0; i < script_number; i++) { - dump_text(f_source, f_cible, table, i, script_number, length_table, line_table); - } - - return (0); -} - -int startup(void) throw (GeneralException) -{ - int i; - char file_name[100]; - FILE *f_source, *f_cible; - - for (i = 0; i < 730; i++) { - printf("%d\n", i); - sprintf(file_name, "xeno_d1/ROOMS/%04d/script.comp", i); - f_source = fopen(file_name, "rb"); - - sprintf(file_name, "xeno_d1/ROOMS/%04d/script.txt", i); - - if (f_source != NULL) { - f_cible = fopen(file_name, "w"); - decrypt(f_source, f_cible, 5); - fclose(f_source); - fclose(f_cible); - } - } - for (i = 0; i < 730; i++) { - printf("%d\n", i); - sprintf(file_name, "xeno_d2/ROOMS/%04d/script.comp", i); - f_source = fopen(file_name, "rb"); - - sprintf(file_name, "xeno_d2/ROOMS/%04d/script.txt", i); - - if (f_source != NULL) { - f_cible = fopen(file_name, "w"); - decrypt(f_source, f_cible, 5); - fclose(f_source); - fclose(f_cible); - } - } - - return 0; -} -CODE_ENDS +#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "generic.h"
+#include "Input.h"
+#include "Output.h"
+#include "Main.h"
+
+CODE_BEGINS
+void init_table(long table[5000])
+{
+ long i;
+
+ for (i = 0; i < 5000; i++) {
+ table[i] = 0;
+ }
+}
+
+char found_position(long table[5000], int number, FILE * f_source)
+{
+ long position;
+ long i;
+
+ position = ftell(f_source);
+
+ for (i = 0; i < number; i++) {
+ if (table[i] <= position)
+ return (1);
+ }
+ return (0);
+}
+
+long found_next(long table[5000], long script_number, long max_script)
+{
+ long i;
+ long next = 0xFFFF;
+ long actual = table[script_number];
+
+ for (i = 0; i < script_number; i++) {
+ if (table[i] > actual) {
+ if (table[i] < next)
+ next = table[i];
+ }
+ }
+
+ for (i = script_number + 1; i < max_script; i++) {
+ if (table[i] > actual) {
+ if (table[i] < next)
+ next = table[i];
+ }
+ }
+
+ return (next);
+}
+
+void dump_text(FILE * f_source, FILE * f_cible, long table[5000], long script_number,
+ long max_script, unsigned char *length_table, unsigned char *line_table)
+{
+ long next;
+ unsigned char val;
+ char temp_string[2] = {0, 0};
+ long position;
+ unsigned char temp1 = 0;
+ unsigned char temp2 = 0;
+
+ next = found_next(table, script_number, max_script);
+
+ fseek(f_source, table[script_number], SEEK_SET);
+
+ fprintf(f_cible, "<Text_block lines:%d width:%d>\n",
+ line_table[script_number], length_table[script_number]);
+
+ position = ftell(f_source);
+
+ while (position < next) {
+ val = 0;
+
+ fread((unsigned char *) &val, 1, 1, f_source);
+
+ if (val == 0x00) // "<Close>"
+ {
+ break;
+ } else if (val == 0x01) // "\n"
+ {
+ fprintf(f_cible, "\n");
+ } else if (val == 0x02) // "<New>"
+ {
+ fprintf(f_cible, "<New>\n");
+ } else if (val == 0x03) // "<Wait>"
+ {
+ fprintf(f_cible, "<Wait>");
+ } else if (val == 0x0F) // Extended opcode. Reads two more bytes.
+ {
+ fread((unsigned char *) &temp1, 1, 1, f_source);
+ fread((unsigned char *) &temp2, 1, 1, f_source);
+ if (temp1 == 0) {
+ fprintf(f_cible, "<Delay %d>", temp2);
+ } else if (temp1 == 5) {
+ switch (temp2) {
+ case 0:
+ fprintf(f_cible, "<Fei>");
+ break;
+ case 1:
+ fprintf(f_cible, "<Elly>");
+ break;
+ case 2:
+ fprintf(f_cible, "<Citan>");
+ break;
+ case 3:
+ fprintf(f_cible, "<Bart>");
+ break;
+ case 4:
+ fprintf(f_cible, "<Billy>");
+ break;
+ case 5:
+ fprintf(f_cible, "<Rico>");
+ break;
+ case 6:
+ fprintf(f_cible, "<Emeralda>");
+ break;
+ case 7:
+ fprintf(f_cible, "<Chu-Chu>");
+ break;
+ case 8:
+ fprintf(f_cible, "<Maria>");
+ break;
+ case 9:
+ fprintf(f_cible, "<Citan2>");
+ break;
+ case 10:
+ fprintf(f_cible, "<Emeralda2>");
+ break;
+ case 11:
+ fprintf(f_cible, "<Weltall>");
+ break;
+ case 12:
+ fprintf(f_cible, "<Weltall-2>");
+ break;
+ case 13:
+ fprintf(f_cible, "<Vierge>");
+ break;
+ case 14:
+ fprintf(f_cible, "<Heimdal>");
+ break;
+ case 15:
+ fprintf(f_cible, "<Brigandier>");
+ break;
+ case 16:
+ fprintf(f_cible, "<Renmazuo>");
+ break;
+ case 17:
+ fprintf(f_cible, "<Stier>");
+ break;
+ case 18:
+ fprintf(f_cible, "<BigChu-chu>");
+ break;
+ case 19:
+ fprintf(f_cible, "<Seibzehn>");
+ break;
+ case 20:
+ fprintf(f_cible, "<Crescens>");
+ break;
+ case 21:
+ fprintf(f_cible, "<Regurus>");
+ break;
+ case 22:
+ fprintf(f_cible, "<Fenrir>");
+ break;
+ case 23:
+ fprintf(f_cible, "<Andvari>");
+ break;
+ case 24:
+ fprintf(f_cible, "<Renmazuo>");
+ break;
+ case 25:
+ fprintf(f_cible, "<Stier-2>");
+ break;
+ case 26:
+ fprintf(f_cible, "<Xenogears>");
+ break;
+ case 27:
+ fprintf(f_cible, "<BARTHOS>");
+ break;
+ case 28:
+ fprintf(f_cible, "<Yggdra>");
+ break;
+ case 128:
+ fprintf(f_cible, "<Perso1>");
+ break;
+ case 129:
+ fprintf(f_cible, "<Perso2>");
+ break;
+ case 130:
+ fprintf(f_cible, "<Perso3>");
+ break;
+ default:
+ fprintf(f_cible, "<Gear %d>", temp2);
+ }
+ } else {
+ fprintf(f_cible, "<Opcode %d %d>", temp1, temp2);
+ }
+ } else if (val == 0x10) // " "
+ {
+ fprintf(f_cible, " ");
+ } else if (val == 0x11) // "+"
+ {
+ fprintf(f_cible, "+");
+ } else if (val == 0x12) // ","
+ {
+ fprintf(f_cible, ",");
+ } else if (val == 0x13) // "-"
+ {
+ fprintf(f_cible, "-");
+ } else if (val == 0x14) // "."
+ {
+ fprintf(f_cible, ".");
+ } else if (val == 0x15) // "/"
+ {
+ fprintf(f_cible, "/");
+ } else if ((val >= 0x16) && (val <= 0x1F)) // "0-9"
+ {
+ temp_string[0] = val + 0x1A;
+ fprintf(f_cible, temp_string);
+ } else if ((val >= 0x20) && (val <= 0x39)) // "A-Z"
+ {
+ temp_string[0] = val + 0x21;
+ fprintf(f_cible, temp_string);
+ } else if (val == 0x3A) // "["
+ {
+ fprintf(f_cible, "[");
+ } else if (val == 0x3B) // "]"
+ {
+ fprintf(f_cible, "]");
+ } else if (val == 0x3C) // "="
+ {
+ fprintf(f_cible, "=");
+ } else if ((val >= 0x3D) && (val <= 0x56)) // "a-z"
+ {
+ temp_string[0] = val + 0x24;
+ fprintf(f_cible, temp_string);
+ } else if (val == 0x57) // "!"
+ {
+ fprintf(f_cible, "!");
+ } else if (val == 0x58) // "\""
+ {
+ fprintf(f_cible, "\"");
+ } else if (val == 0x59) // "#"
+ {
+ fprintf(f_cible, "#");
+ } else if (val == 0x5A) // "%"
+ {
+ fprintf(f_cible, "%%");
+ } else if (val == 0x5B) // "&"
+ {
+ fprintf(f_cible, "&");
+ } else if (val == 0x5C) // "'"
+ {
+ fprintf(f_cible, "'");
+ } else if (val == 0x5D) // "("
+ {
+ fprintf(f_cible, "(");
+ } else if (val == 0x5E) // ")"
+ {
+ fprintf(f_cible, ")");
+ } else if (val == 0x5F) // ":"
+ {
+ fprintf(f_cible, ":");
+ } else if (val == 0x60) // "?"
+ {
+ fprintf(f_cible, "?");
+ } else if (val == 0x61) // "<0>"
+ {
+ fprintf(f_cible, "<0>");
+ } else if (val == 0x62) // "<1>"
+ {
+ fprintf(f_cible, "<1>");
+ } else if (val == 0x63) // "<2>"
+ {
+ fprintf(f_cible, "<2>");
+ } else if (val == 0x64) // "<3>"
+ {
+ fprintf(f_cible, "<3>");
+ } else if (val == 0x65) // "<4>"
+ {
+ fprintf(f_cible, "<4>");
+ } else if (val == 0x66) // "<5>"
+ {
+ fprintf(f_cible, "<5>");
+ } else if (val == 0x67) // "<6>"
+ {
+ fprintf(f_cible, "<6>");
+ } else if (val == 0x68) // "<7>"
+ {
+ fprintf(f_cible, "<7>");
+ } else if (val == 0x69) // "<8>"
+ {
+ fprintf(f_cible, "<8>");
+ } else if (val == 0x6A) // "<9>"
+ {
+ fprintf(f_cible, "<9>");
+ } else if (val == 0x6B) // "<%>"
+ {
+ fprintf(f_cible, "<%%>");
+ } else if (val == 0x6C) // "<&>"
+ {
+ fprintf(f_cible, "<&>");
+ } else if (val == 0x6D) // "*"
+ {
+ fprintf(f_cible, "*");
+ } else if (val == 0x6E) // "<C>"
+ {
+ fprintf(f_cible, "<C>");
+ } else if (val == 0x6F) // "<S>"
+ {
+ fprintf(f_cible, "<S>");
+ } else if (val == 0x70) // "<T>"
+ {
+ fprintf(f_cible, "<T>");
+ } else if (val == 0x71) // "<*>"
+ {
+ fprintf(f_cible, "<*>");
+ } else if (val == 0x72) // "<R>"
+ {
+ fprintf(f_cible, "<R>");
+ } else if (val == 0x73) // "<L>"
+ {
+ fprintf(f_cible, "<L>");
+ } else if (val == 0x74) // "<U>"
+ {
+ fprintf(f_cible, "<U>");
+ } else if (val == 0x75) // "<U>"
+ {
+ fprintf(f_cible, "<D>");
+ } else if (val == 0x76) // "<.>"
+ {
+ fprintf(f_cible, "<.>");
+ } else if (val == 0x77) // "<:>"
+ {
+ fprintf(f_cible, "<:>");
+ } else if (val == 0x79) // "</>"
+ {
+ fprintf(f_cible, "</>");
+ } else if (val == 0x7A) // "<..>"
+ {
+ fprintf(f_cible, "<..>");
+ } else if (val == 0x7B) // "<`>"
+ {
+ fprintf(f_cible, "<`>");
+ } else if (val == 0x7D) // "<+>"
+ {
+ fprintf(f_cible, "<+>");
+ } else if (val == 0x7E) // "<->"
+ {
+ fprintf(f_cible, "<->");
+ } else if (val == 0x7F) // "<X>"
+ {
+ fprintf(f_cible, "<X>");
+ } else if (val == 0x80) // "<[>"
+ {
+ fprintf(f_cible, "<[>");
+ } else if (val == 0x81) // "<]>"
+ {
+ fprintf(f_cible, "<]>");
+ } else if (val == 0x82) // "<%>"
+ {
+ fprintf(f_cible, "<%%>");
+ } else if (val == 0x83) // "<&>"
+ {
+ fprintf(f_cible, "<&>");
+ } else if (val == 0x84) // "<(>"
+ {
+ fprintf(f_cible, "<(>");
+ } else if (val == 0x85) // "<)>"
+ {
+ fprintf(f_cible, "<)>");
+ } else if (val == 0x86) // "<#>"
+ {
+ fprintf(f_cible, "<#>");
+ } else if (val == 0x87) // "`"
+ {
+ fprintf(f_cible, "`");
+ } else if (val == 0x88) // "°"
+ {
+ fprintf(f_cible, "°");
+ } else if (val == 0x89) // "<=>"
+ {
+ fprintf(f_cible, "<=>");
+ } else if (val == 0x8A) // "<?>"
+ {
+ fprintf(f_cible, "<?>");
+ } else if (val == 0x8B) // "<!>"
+ {
+ fprintf(f_cible, "<!>");
+ } else if (val == 0x8C) // "_"
+ {
+ fprintf(f_cible, "_");
+ } else if (val == 0x8D) // "~"
+ {
+ fprintf(f_cible, "~");
+ } else if (val == 0x8E) // "<...>"
+ {
+ fprintf(f_cible, "<...>");
+ } else if (val == 0x8F) // "<'>"
+ {
+ fprintf(f_cible, "<'>");
+ } else if (val == 0xFE) // "<Extra1 X>
+ {
+ fread((unsigned char *) &temp1, 1, 1, f_source);
+ fprintf(f_cible, "<Extra1 %d>", temp1);
+ } else if (val == 0xFF) // "<Extra2 X>
+ {
+ fread((unsigned char *) &temp1, 1, 1, f_source);
+ fprintf(f_cible, "<Extra2 %d>", temp1);
+ } else {
+ fprintf(f_cible, "<Bare %X>", val);
+ }
+
+ position = ftell(f_source);
+ }
+ fprintf(f_cible, "\n<End_of_block>\n\n");
+}
+
+int decrypt(FILE * f_source, FILE * f_cible, int room_number)
+{
+ long i, j;
+ long table[5000];
+ unsigned char line_table[5000];
+ unsigned char length_table[5000];
+ long script_number = 0;
+ long temp = 0;
+ char temp_char;
+ int counter = 0;
+
+ fread((long *) &script_number, 4, 1, f_source);
+
+ if (script_number == 0x0000FFFF)
+ return (1);
+
+ script_number = (script_number++);
+
+ fprintf(f_cible, "<Blocks:%li>\n", script_number);
+ init_table(table);
+
+ i = j = 0;
+
+ while (i < script_number) {
+ fread((long *) &temp, 2, 1, f_source);
+ if (table[j - 1] != temp)
+ table[j++] = temp;
+ i++;
+ }
+
+ script_number = j;
+
+ for (i = 0; i < script_number; i++) {
+ fread((unsigned char *) &length_table[i], 1, 1, f_source);
+ fread((unsigned char *) &line_table[i], 1, 1, f_source);
+ }
+
+ fseek(f_source, table[script_number - 1], SEEK_SET);
+
+ do {
+ fread((char *) &temp_char, 1, 1, f_source);
+ counter++;
+ } while (temp_char != 0);
+
+ table[script_number] = ftell(f_source);
+
+ for (i = 0; i < script_number; i++) {
+ dump_text(f_source, f_cible, table, i, script_number, length_table, line_table);
+ }
+
+ return (0);
+}
+
+int startup(void) throw (GeneralException)
+{
+ int i;
+ char file_name[100];
+ FILE *f_source, *f_cible;
+
+ for (i = 0; i < 730; i++) {
+ printf("%d\n", i);
+ sprintf(file_name, "xeno_d1/ROOMS/%04d/script.comp", i);
+ f_source = fopen(file_name, "rb");
+
+ sprintf(file_name, "xeno_d1/ROOMS/%04d/script.txt", i);
+
+ if (f_source != NULL) {
+ f_cible = fopen(file_name, "w");
+ decrypt(f_source, f_cible, 5);
+ fclose(f_source);
+ fclose(f_cible);
+ }
+ }
+ for (i = 0; i < 730; i++) {
+ printf("%d\n", i);
+ sprintf(file_name, "xeno_d2/ROOMS/%04d/script.comp", i);
+ f_source = fopen(file_name, "rb");
+
+ sprintf(file_name, "xeno_d2/ROOMS/%04d/script.txt", i);
+
+ if (f_source != NULL) {
+ f_cible = fopen(file_name, "w");
+ decrypt(f_source, f_cible, 5);
+ fclose(f_source);
+ fclose(f_cible);
+ }
+ }
+
+ return 0;
+}
+CODE_ENDS
diff --git a/Xenogears/Translate.cpp b/Xenogears/Translate.cpp index 3f85437..1edef8b 100644 --- a/Xenogears/Translate.cpp +++ b/Xenogears/Translate.cpp @@ -1,256 +1,256 @@ -#include <stdio.h> -#include <string.h> - -void dump_text(FILE * f_source, FILE * f_cible) -{ - unsigned char val; - unsigned char temp1 = 0; - unsigned char temp2 = 0; - - while (!feof(f_source)) { - val = 0; - - fread((unsigned char *) &val, 1, 1, f_source); - - if (val == 0x00) // "<Close>" - { -// break; - fprintf(f_cible, "<EOF>\n"); - } else if (val == 0x01) // "\n" - { - fprintf(f_cible, "\n"); - } else if (val == 0x02) // "<New>" - { - fprintf(f_cible, "<New>\n"); - } else if (val == 0x03) // "<Wait>" - { - fprintf(f_cible, "<Wait>"); - } else if (val == 0x0F) // "<Delay X> - { - fread((unsigned char *) &temp1, 1, 1, f_source); - fread((unsigned char *) &temp2, 1, 1, f_source); - if (temp1 == 0) { - fprintf(f_cible, "<Delay %d>", temp2); - } else if (temp1 == 5) { - fprintf(f_cible, "<Gear %d>", temp2); - } else { - fprintf(f_cible, "<Opcode %d %d>", temp1, temp2); - } - } else if (val == 0x10) // " " - { - fprintf(f_cible, " "); - } else if (val == 0x11) // "+" - { - fprintf(f_cible, "+"); - } else if (val == 0x12) // "," - { - fprintf(f_cible, ","); - } else if (val == 0x13) // "-" - { - fprintf(f_cible, "-"); - } else if (val == 0x14) // "." - { - fprintf(f_cible, "."); - } else if (val == 0x15) // "/" - { - fprintf(f_cible, "/"); - } else if ((val >= 0x16) && (val <= 0x1F)) // "0-9" - { - fprintf(f_cible, "%c", val + 0x1a); - } else if ((val >= 0x20) && (val <= 0x39)) // "A-Z" - { - fprintf(f_cible, "%c", val + 0x21); - } else if (val == 0x3A) // "[" - { - fprintf(f_cible, "["); - } else if (val == 0x3B) // "]" - { - fprintf(f_cible, "]"); - } else if (val == 0x3C) // "=" - { - fprintf(f_cible, "="); - } else if ((val >= 0x3D) && (val <= 0x56)) // "a-z" - { - fprintf(f_cible, "%c", val + 0x24); - } else if (val == 0x57) // "!" - { - fprintf(f_cible, "!"); - } else if (val == 0x58) // "\"" - { - fprintf(f_cible, "\""); - } else if (val == 0x59) // "#" - { - fprintf(f_cible, "#"); - } else if (val == 0x5A) // "%" - { - fprintf(f_cible, "%%"); - } else if (val == 0x5B) // "&" - { - fprintf(f_cible, "&"); - } else if (val == 0x5C) // "'" - { - fprintf(f_cible, "'"); - } else if (val == 0x5D) // "(" - { - fprintf(f_cible, "("); - } else if (val == 0x5E) // ")" - { - fprintf(f_cible, ")"); - } else if (val == 0x5F) // ":" - { - fprintf(f_cible, ":"); - } else if (val == 0x60) // "?" - { - fprintf(f_cible, "?"); - } else if (val == 0x61) // "<0>" - { - fprintf(f_cible, "<0>"); - } else if (val == 0x62) // "<1>" - { - fprintf(f_cible, "<1>"); - } else if (val == 0x63) // "<2>" - { - fprintf(f_cible, "<2>"); - } else if (val == 0x64) // "<3>" - { - fprintf(f_cible, "<3>"); - } else if (val == 0x65) // "<4>" - { - fprintf(f_cible, "<4>"); - } else if (val == 0x66) // "<5>" - { - fprintf(f_cible, "<5>"); - } else if (val == 0x67) // "<6>" - { - fprintf(f_cible, "<6>"); - } else if (val == 0x68) // "<7>" - { - fprintf(f_cible, "<7>"); - } else if (val == 0x69) // "<8>" - { - fprintf(f_cible, "<8>"); - } else if (val == 0x6A) // "<9>" - { - fprintf(f_cible, "<9>"); - } else if (val == 0x6B) // "<%>" - { - fprintf(f_cible, "<%%>"); - } else if (val == 0x6C) // "<&>" - { - fprintf(f_cible, "<&>"); - } else if (val == 0x6D) // "*" - { - fprintf(f_cible, "*"); - } else if (val == 0x6E) // "<C>" - { - fprintf(f_cible, "<C>"); - } else if (val == 0x6F) // "<S>" - { - fprintf(f_cible, "<S>"); - } else if (val == 0x70) // "<T>" - { - fprintf(f_cible, "<T>"); - } else if (val == 0x71) // "<*>" - { - fprintf(f_cible, "<*>"); - } else if (val == 0x72) // "<R>" - { - fprintf(f_cible, "<R>"); - } else if (val == 0x73) // "<L>" - { - fprintf(f_cible, "<L>"); - } else if (val == 0x74) // "<U>" - { - fprintf(f_cible, "<U>"); - } else if (val == 0x75) // "<U>" - { - fprintf(f_cible, "<D>"); - } else if (val == 0x76) // "<.>" - { - fprintf(f_cible, "<.>"); - } else if (val == 0x77) // "<:>" - { - fprintf(f_cible, "<:>"); - } else if (val == 0x79) // "</>" - { - fprintf(f_cible, "</>"); - } else if (val == 0x7A) // "<..>" - { - fprintf(f_cible, "<..>"); - } else if (val == 0x7B) // "<`>" - { - fprintf(f_cible, "<`>"); - } else if (val == 0x7D) // "<+>" - { - fprintf(f_cible, "<+>"); - } else if (val == 0x7E) // "<->" - { - fprintf(f_cible, "<->"); - } else if (val == 0x7F) // "<X>" - { - fprintf(f_cible, "<X>"); - } else if (val == 0x80) // "<[>" - { - fprintf(f_cible, "<[>"); - } else if (val == 0x81) // "<]>" - { - fprintf(f_cible, "<]>"); - } else if (val == 0x82) // "<%>" - { - fprintf(f_cible, "<%%>"); - } else if (val == 0x83) // "<&>" - { - fprintf(f_cible, "<&>"); - } else if (val == 0x84) // "<(>" - { - fprintf(f_cible, "<(>"); - } else if (val == 0x85) // "<)>" - { - fprintf(f_cible, "<)>"); - } else if (val == 0x86) // "<#>" - { - fprintf(f_cible, "<#>"); - } else if (val == 0x87) // "`" - { - fprintf(f_cible, "`"); - } else if (val == 0x88) // "°" - { - fprintf(f_cible, "°"); - } else if (val == 0x89) // "<=>" - { - fprintf(f_cible, "<=>"); - } else if (val == 0x8A) // "<?>" - { - fprintf(f_cible, "<?>"); - } else if (val == 0x8B) // "<!>" - { - fprintf(f_cible, "<!>"); - } else if (val == 0x8C) // "_" - { - fprintf(f_cible, "_"); - } else if (val == 0x8D) // "~" - { - fprintf(f_cible, "~"); - } else if (val == 0x8E) // "<...>" - { - fprintf(f_cible, "<...>"); - } else if (val == 0x8F) // "<'>" - { - fprintf(f_cible, "<'>"); - } else if (val == 0xFE) // "<Extra1 X> - { - fread((unsigned char *) &temp1, 1, 1, f_source); - fprintf(f_cible, "<Extra1 %d>", temp1); - } else if (val == 0xFF) // "<Extra2 X> - { - fread((unsigned char *) &temp1, 1, 1, f_source); - fprintf(f_cible, "<Extra2 %d>", temp1); - } else { - fprintf(f_cible, "<Bare %X>", val); - } - } -} - -int main(void) { - dump_text(stdin, stdout); -} +#include <stdio.h>
+#include <string.h>
+
+void dump_text(FILE * f_source, FILE * f_cible)
+{
+ unsigned char val;
+ unsigned char temp1 = 0;
+ unsigned char temp2 = 0;
+
+ while (!feof(f_source)) {
+ val = 0;
+
+ fread((unsigned char *) &val, 1, 1, f_source);
+
+ if (val == 0x00) // "<Close>"
+ {
+// break;
+ fprintf(f_cible, "<EOF>\n");
+ } else if (val == 0x01) // "\n"
+ {
+ fprintf(f_cible, "\n");
+ } else if (val == 0x02) // "<New>"
+ {
+ fprintf(f_cible, "<New>\n");
+ } else if (val == 0x03) // "<Wait>"
+ {
+ fprintf(f_cible, "<Wait>");
+ } else if (val == 0x0F) // "<Delay X>
+ {
+ fread((unsigned char *) &temp1, 1, 1, f_source);
+ fread((unsigned char *) &temp2, 1, 1, f_source);
+ if (temp1 == 0) {
+ fprintf(f_cible, "<Delay %d>", temp2);
+ } else if (temp1 == 5) {
+ fprintf(f_cible, "<Gear %d>", temp2);
+ } else {
+ fprintf(f_cible, "<Opcode %d %d>", temp1, temp2);
+ }
+ } else if (val == 0x10) // " "
+ {
+ fprintf(f_cible, " ");
+ } else if (val == 0x11) // "+"
+ {
+ fprintf(f_cible, "+");
+ } else if (val == 0x12) // ","
+ {
+ fprintf(f_cible, ",");
+ } else if (val == 0x13) // "-"
+ {
+ fprintf(f_cible, "-");
+ } else if (val == 0x14) // "."
+ {
+ fprintf(f_cible, ".");
+ } else if (val == 0x15) // "/"
+ {
+ fprintf(f_cible, "/");
+ } else if ((val >= 0x16) && (val <= 0x1F)) // "0-9"
+ {
+ fprintf(f_cible, "%c", val + 0x1a);
+ } else if ((val >= 0x20) && (val <= 0x39)) // "A-Z"
+ {
+ fprintf(f_cible, "%c", val + 0x21);
+ } else if (val == 0x3A) // "["
+ {
+ fprintf(f_cible, "[");
+ } else if (val == 0x3B) // "]"
+ {
+ fprintf(f_cible, "]");
+ } else if (val == 0x3C) // "="
+ {
+ fprintf(f_cible, "=");
+ } else if ((val >= 0x3D) && (val <= 0x56)) // "a-z"
+ {
+ fprintf(f_cible, "%c", val + 0x24);
+ } else if (val == 0x57) // "!"
+ {
+ fprintf(f_cible, "!");
+ } else if (val == 0x58) // "\""
+ {
+ fprintf(f_cible, "\"");
+ } else if (val == 0x59) // "#"
+ {
+ fprintf(f_cible, "#");
+ } else if (val == 0x5A) // "%"
+ {
+ fprintf(f_cible, "%%");
+ } else if (val == 0x5B) // "&"
+ {
+ fprintf(f_cible, "&");
+ } else if (val == 0x5C) // "'"
+ {
+ fprintf(f_cible, "'");
+ } else if (val == 0x5D) // "("
+ {
+ fprintf(f_cible, "(");
+ } else if (val == 0x5E) // ")"
+ {
+ fprintf(f_cible, ")");
+ } else if (val == 0x5F) // ":"
+ {
+ fprintf(f_cible, ":");
+ } else if (val == 0x60) // "?"
+ {
+ fprintf(f_cible, "?");
+ } else if (val == 0x61) // "<0>"
+ {
+ fprintf(f_cible, "<0>");
+ } else if (val == 0x62) // "<1>"
+ {
+ fprintf(f_cible, "<1>");
+ } else if (val == 0x63) // "<2>"
+ {
+ fprintf(f_cible, "<2>");
+ } else if (val == 0x64) // "<3>"
+ {
+ fprintf(f_cible, "<3>");
+ } else if (val == 0x65) // "<4>"
+ {
+ fprintf(f_cible, "<4>");
+ } else if (val == 0x66) // "<5>"
+ {
+ fprintf(f_cible, "<5>");
+ } else if (val == 0x67) // "<6>"
+ {
+ fprintf(f_cible, "<6>");
+ } else if (val == 0x68) // "<7>"
+ {
+ fprintf(f_cible, "<7>");
+ } else if (val == 0x69) // "<8>"
+ {
+ fprintf(f_cible, "<8>");
+ } else if (val == 0x6A) // "<9>"
+ {
+ fprintf(f_cible, "<9>");
+ } else if (val == 0x6B) // "<%>"
+ {
+ fprintf(f_cible, "<%%>");
+ } else if (val == 0x6C) // "<&>"
+ {
+ fprintf(f_cible, "<&>");
+ } else if (val == 0x6D) // "*"
+ {
+ fprintf(f_cible, "*");
+ } else if (val == 0x6E) // "<C>"
+ {
+ fprintf(f_cible, "<C>");
+ } else if (val == 0x6F) // "<S>"
+ {
+ fprintf(f_cible, "<S>");
+ } else if (val == 0x70) // "<T>"
+ {
+ fprintf(f_cible, "<T>");
+ } else if (val == 0x71) // "<*>"
+ {
+ fprintf(f_cible, "<*>");
+ } else if (val == 0x72) // "<R>"
+ {
+ fprintf(f_cible, "<R>");
+ } else if (val == 0x73) // "<L>"
+ {
+ fprintf(f_cible, "<L>");
+ } else if (val == 0x74) // "<U>"
+ {
+ fprintf(f_cible, "<U>");
+ } else if (val == 0x75) // "<U>"
+ {
+ fprintf(f_cible, "<D>");
+ } else if (val == 0x76) // "<.>"
+ {
+ fprintf(f_cible, "<.>");
+ } else if (val == 0x77) // "<:>"
+ {
+ fprintf(f_cible, "<:>");
+ } else if (val == 0x79) // "</>"
+ {
+ fprintf(f_cible, "</>");
+ } else if (val == 0x7A) // "<..>"
+ {
+ fprintf(f_cible, "<..>");
+ } else if (val == 0x7B) // "<`>"
+ {
+ fprintf(f_cible, "<`>");
+ } else if (val == 0x7D) // "<+>"
+ {
+ fprintf(f_cible, "<+>");
+ } else if (val == 0x7E) // "<->"
+ {
+ fprintf(f_cible, "<->");
+ } else if (val == 0x7F) // "<X>"
+ {
+ fprintf(f_cible, "<X>");
+ } else if (val == 0x80) // "<[>"
+ {
+ fprintf(f_cible, "<[>");
+ } else if (val == 0x81) // "<]>"
+ {
+ fprintf(f_cible, "<]>");
+ } else if (val == 0x82) // "<%>"
+ {
+ fprintf(f_cible, "<%%>");
+ } else if (val == 0x83) // "<&>"
+ {
+ fprintf(f_cible, "<&>");
+ } else if (val == 0x84) // "<(>"
+ {
+ fprintf(f_cible, "<(>");
+ } else if (val == 0x85) // "<)>"
+ {
+ fprintf(f_cible, "<)>");
+ } else if (val == 0x86) // "<#>"
+ {
+ fprintf(f_cible, "<#>");
+ } else if (val == 0x87) // "`"
+ {
+ fprintf(f_cible, "`");
+ } else if (val == 0x88) // "°"
+ {
+ fprintf(f_cible, "°");
+ } else if (val == 0x89) // "<=>"
+ {
+ fprintf(f_cible, "<=>");
+ } else if (val == 0x8A) // "<?>"
+ {
+ fprintf(f_cible, "<?>");
+ } else if (val == 0x8B) // "<!>"
+ {
+ fprintf(f_cible, "<!>");
+ } else if (val == 0x8C) // "_"
+ {
+ fprintf(f_cible, "_");
+ } else if (val == 0x8D) // "~"
+ {
+ fprintf(f_cible, "~");
+ } else if (val == 0x8E) // "<...>"
+ {
+ fprintf(f_cible, "<...>");
+ } else if (val == 0x8F) // "<'>"
+ {
+ fprintf(f_cible, "<'>");
+ } else if (val == 0xFE) // "<Extra1 X>
+ {
+ fread((unsigned char *) &temp1, 1, 1, f_source);
+ fprintf(f_cible, "<Extra1 %d>", temp1);
+ } else if (val == 0xFF) // "<Extra2 X>
+ {
+ fread((unsigned char *) &temp1, 1, 1, f_source);
+ fprintf(f_cible, "<Extra2 %d>", temp1);
+ } else {
+ fprintf(f_cible, "<Bare %X>", val);
+ }
+ }
+}
+
+int main(void) {
+ dump_text(stdin, stdout);
+}
diff --git a/Xenogears/archive.cpp b/Xenogears/archive.cpp index 6701c2c..286fa43 100644 --- a/Xenogears/archive.cpp +++ b/Xenogears/archive.cpp @@ -1,37 +1,37 @@ -#include <stdio.h> -#include <values.h> -#include <stdlib.h> -#include "fileutils.h" - -void dearchive(FILE * f) { - long nb; - long * address; - char fname[100]; - int i; - FILE * f_out; - - fread(&nb, 4, 1, f); - nb++; - fprintf(stderr, "Reading index... (%li elements)\n", nb); - - address = (long *) malloc(nb * sizeof(long) + 1); - - for (i = 0; i < nb; i++) { - fread(address + i, 4, 1, f); - } - address[nb] = MAXINT; - - for (i = 0; i < nb; i++) { - fprintf(stderr, "Dumping file %i\n", i); - sprintf(fname, "part-%i.lz", i); - f_out = fopen(fname, "wb"); - copy(fileno(f), fileno(f_out), address[i + 1] - address[i]); - fclose(f_out); - } - - free(address); -} - -int main(void) { - dearchive(stdin); -} +#include <stdio.h>
+#include <values.h>
+#include <stdlib.h>
+#include "fileutils.h"
+
+void dearchive(FILE * f) {
+ long nb;
+ long * address;
+ char fname[100];
+ int i;
+ FILE * f_out;
+
+ fread(&nb, 4, 1, f);
+ nb++;
+ fprintf(stderr, "Reading index... (%li elements)\n", nb);
+
+ address = (long *) malloc(nb * sizeof(long) + 1);
+
+ for (i = 0; i < nb; i++) {
+ fread(address + i, 4, 1, f);
+ }
+ address[nb] = MAXINT;
+
+ for (i = 0; i < nb; i++) {
+ fprintf(stderr, "Dumping file %i\n", i);
+ sprintf(fname, "part-%i.lz", i);
+ f_out = fopen(fname, "wb");
+ copy(fileno(f), fileno(f_out), address[i + 1] - address[i]);
+ fclose(f_out);
+ }
+
+ free(address);
+}
+
+int main(void) {
+ dearchive(stdin);
+}
diff --git a/Xenogears/build-sector-2.cpp b/Xenogears/build-sector-2.cpp index 6ab7835..1b1be62 100644 --- a/Xenogears/build-sector-2.cpp +++ b/Xenogears/build-sector-2.cpp @@ -1,14 +1,14 @@ -#include <stdio.h> -#include "yazedc.h" - -int main(void) { - unsigned char datas[2352]; - - fread(datas, 2352, 1, stdin); - minute = datas[12]; - second = datas[13]; - frame = datas[14]; - fprintf(stderr, "Sector info: %2i:%02i:%04i\n", minute, second, frame); - do_encode_L2(datas, MODE_2, 0); - fwrite(datas, 2352, 1, stdout); -} +#include <stdio.h>
+#include "yazedc.h"
+
+int main(void) {
+ unsigned char datas[2352];
+
+ fread(datas, 2352, 1, stdin);
+ minute = datas[12];
+ second = datas[13];
+ frame = datas[14];
+ fprintf(stderr, "Sector info: %2i:%02i:%04i\n", minute, second, frame);
+ do_encode_L2(datas, MODE_2, 0);
+ fwrite(datas, 2352, 1, stdout);
+}
diff --git a/Xenogears/build-sector.cpp b/Xenogears/build-sector.cpp index 3effc35..744a087 100644 --- a/Xenogears/build-sector.cpp +++ b/Xenogears/build-sector.cpp @@ -1,14 +1,14 @@ -#include <stdio.h> -#include "yazedc.h" - -int main(void) { - unsigned char datas[2352]; - - fread(datas, 2352, 1, stdin); - minute = datas[12]; - second = datas[13]; - frame = datas[14]; - fprintf(stderr, "Sector info: %2i:%02i:%04i\n", minute, second, frame); - do_encode_L2(datas, MODE_2_FORM_1, 0); - fwrite(datas, 2352, 1, stdout); -} +#include <stdio.h>
+#include "yazedc.h"
+
+int main(void) {
+ unsigned char datas[2352];
+
+ fread(datas, 2352, 1, stdin);
+ minute = datas[12];
+ second = datas[13];
+ frame = datas[14];
+ fprintf(stderr, "Sector info: %2i:%02i:%04i\n", minute, second, frame);
+ do_encode_L2(datas, MODE_2_FORM_1, 0);
+ fwrite(datas, 2352, 1, stdout);
+}
diff --git a/Xenogears/main_dump.cpp b/Xenogears/main_dump.cpp index 1610ec1..e2f5058 100644 --- a/Xenogears/main_dump.cpp +++ b/Xenogears/main_dump.cpp @@ -1,283 +1,283 @@ -/* - * Xenogears extractor by Nicolas "Pixel" Noble (nicolas@nobis-crew.org) - * Highly based upon Yazoo's Chrono Cross CD extractor - * - * ******** Original disclaimer by Yazoo ******** - * - * Chrono Cross CD extractor Copyright 2000-2001 by Yazoo (hamm@efrei.fr) Revision 0.1b ANSI C - * - * - * Features: - * - * Dump the complete content of Chrono Chross CD1/CD2 US and Japanese version It requires a iso - * named Chrono1.iso in the same directory - * - * Todo list: - * - * Find a way to locate end of the last file Better support for CD2 Dump in subdirectory according - * to CD1/CD2 repartition Recompilation in Visual C++ 6 for disk speed optimisation Source comment - * and reorganisation Log feature (Optional since you can redirect output with > ) Progression - * indicator Better detection of the ISO with error control Major code optimisation Integration in - * main Chrono Cross Hacking tool - * - * ******** End of original disclaimer by Yazoo ******** - * - */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include "cdutils.h" -#include "generic.h" -#include "Input.h" -#include "Output.h" -#include "Main.h" -#include "cdabstract.h" - -CODE_BEGINS -public: -Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso(0), cdutil(0) {} -virtual ~Appli() { - delete cdutil; - delete f_def; - delete f_iso; - delete f_out; -} -private: - -unsigned int tourne; - -struct t_index_tab { - unsigned long address; - long size; - long type; - long index; -}; - -struct t_sequence { - unsigned int n; - unsigned int sum; - String prefix; - String name; - int type; -}; - -String title, iso_filename, prefix; -unsigned long iso_size; -unsigned int nb_records, nb_seqs; -struct t_sequence sequences[100]; -Handle * f_def, * f_iso, * f_out; - -cdutils * cdutil; - -Byte user_data[2352]; - -virtual int startup() throw (GeneralException) -{ - - verbosity = 3; - - printm(M_BARE, -"Xenogears File Extractor by Nicolas \"Pixel\" Noble\n" -"Highly based upon the Chrono Cross File Extractor By Yazoo\n\n"); - - if (argc != 3) { - printm(M_BARE, "Usage: %s <definition_file.sqr> <iso_file_name>\nSee readme.txt for details\n", - argv[0]); - exit(-1); - } - - printm(M_STATUS, "Processing file %s...\n", argv[1]); - - f_def = new Input(argv[1]); - - if (process_def_file()) { - printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]); - exit(-1); - } - - iso_filename = argv[2]; - - printm(M_STATUS, "Begin processing iso file.\n"); - f_iso = cdabstract::open_cd(iso_filename); - - if (check_iso()) { - printm(M_ERROR, "Invalid iso file for " + title + "\n"); - printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n"); - } else { - printm(M_INFO, "Genuine " + title + " iso detected.\n"); - } - - cdutil = new cdutils(f_iso); - - printm(M_STATUS, "Entering files read sequence\n"); - read_files(); - return 0; -} - -/* - * Ugly but working... for now - */ -int process_def_file() -{ - String t; - unsigned int n, sum = 0; - - *f_def >> t; - printm(M_INFO, "Read title: " + t + "\n"); - title = t; - - *f_def >> t; - iso_size = t.to_int(); - printm(M_INFO, "Read iso size: %lu bytes\n", iso_size); - - *f_def >> t; - printm(M_INFO, "Read global directory prefix: " + t + "\n"); - prefix = t; - - *f_def >> t; - nb_records = t.to_int(); - printm(M_INFO, "Read total of records: %u\n", nb_records); - - while (1) { - *f_def >> t; - n = t.to_int(); - if (!n) { - if (sum == nb_records) { - printm(M_INFO, "Definition file seems coherent\n"); - return 0; - } else { - printm(M_ERROR, "Definition file incoherent\n"); - return 1; - } - } - sum += n; - sequences[nb_seqs].n = n; - sequences[nb_seqs].sum = sum; - *f_def >> t; - sequences[nb_seqs].prefix = t; - *f_def >> t; - n = t.to_int(); - sequences[nb_seqs].type = n; - *f_def >> t; - sequences[nb_seqs].name = t; - printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of " + t + - " (" + sequences[nb_seqs].prefix + ")\n", nb_seqs, n, sum); - nb_seqs++; - } -} - -long check_iso() -{ - unsigned long length; - - length = f_iso->GetSize(); - if (length < 0) { - printm(M_INFO, "Can not get file size, assuming reading from CD.\n"); - } else { - printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length); - if (length != iso_size) { - return 1; - } - } - return 0; -} - -void read_files() -{ - t_index_tab index_tab[10000]; - unsigned char t[8]; - unsigned long i; - unsigned long j; - unsigned int seq = 0; - unsigned long indexer; - struct t_index_tab *p = (struct t_index_tab *) t; - - Byte fat[32768]; - -#define INDEXPOS 24 - - cdutil->sector_seek(INDEXPOS); - for (i = INDEXPOS; i < (INDEXPOS + 16); i++) { - printm(M_INFO, "Reading fat sector %lu\n", i); - cdutil->read_sector(&fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); - } - - indexer = 0; - for (j = 0; j < 32768; j = j + 7) { - t[0] = 0; - bcopy((char *) &fat[j], (char *) t + 1, 7); - p->address >>= 8; - index_tab[indexer] = *p; - if (p->size > 0 && p->address != 0) { - index_tab[indexer].index = j / 7; - printm(M_INFO, "Found a quite valid index: number %4lu, address %6lu, size %3li\n", - indexer, index_tab[indexer].address, index_tab[indexer].size); - indexer++; - if (indexer == nb_records) - break; - } else { - printm(M_WARNING, "Ignored invalid index chunk number %4lu (size = %lu) (%02x %02x %02x %02x %02x %02x %02x)\n", - j / 7, -index_tab[indexer].size, t[0], t[1], t[2], t[4], t[5], t[6], t[7]); - } - } - printm(M_STATUS, "Index file generation complete.\n\n"); - - for (i = 0; i < nb_records; i++) { - if (sequences[seq].sum == i) - seq++; - index_tab[i].type = sequences[seq].type; - if (sequences[seq].type == 0) { - printm(M_INFO, "%6lu (%10lu): ignored\n", index_tab[i].address, index_tab[i].size); - } else { - printm(M_INFO, "%6lu (%10lu): ", index_tab[i].address, index_tab[i].size); - file_dump(index_tab[i].address, index_tab[i].size, i, seq); - if (verbosity >= M_INFO) { - fprintf(stderr, "\n"); - } - } - } - fprintf(stderr, "\n"); -} - -void file_dump(unsigned long debut, unsigned long taille, long num, int seq) -{ - long i; - long nbsects; - String nom; - String extension = ".out"; - String nom_t; - char type = sequences[seq].type; - char ptitbidule[] = "-\\|/"; - - nom_t.set("%04ld", num); - - nom = "./" + prefix + "/"; - - MKDIR(nom.to_charp()); - - nom += sequences[seq].prefix + "/"; - MKDIR(nom.to_charp()); - - nom += nom_t + extension;; - - f_out = new Output(nom); - nbsects = taille / sec_sizes[type]; - if (taille % sec_sizes[type]) - nbsects++; - cdutil->sector_seek(debut); - for (i = 0; i < nbsects; i++) { - if (verbosity < M_INFO) - fprintf(stderr, " (%c)\010\010\010\010\010", ptitbidule[((tourne++) >> 8) % 4]); - cdutil->read_sector(user_data, type); - if (i != (nbsects - 1)) { - f_out->write(user_data, sec_sizes[type]); - } else { - f_out->write(user_data, taille % sec_sizes[type] ? taille % sec_sizes[type] : sec_sizes[type]); - } - } - delete f_out; - f_out = 0; - printm(M_BARE, " (*) Dumped file number %4ld - type \"" + sequences[seq].name + "\" \r", num); -} -CODE_ENDS +/*
+ * Xenogears extractor by Nicolas "Pixel" Noble (nicolas@nobis-crew.org)
+ * Highly based upon Yazoo's Chrono Cross CD extractor
+ *
+ * ******** Original disclaimer by Yazoo ********
+ *
+ * Chrono Cross CD extractor Copyright 2000-2001 by Yazoo (hamm@efrei.fr) Revision 0.1b ANSI C
+ *
+ *
+ * Features:
+ *
+ * Dump the complete content of Chrono Chross CD1/CD2 US and Japanese version It requires a iso
+ * named Chrono1.iso in the same directory
+ *
+ * Todo list:
+ *
+ * Find a way to locate end of the last file Better support for CD2 Dump in subdirectory according
+ * to CD1/CD2 repartition Recompilation in Visual C++ 6 for disk speed optimisation Source comment
+ * and reorganisation Log feature (Optional since you can redirect output with > ) Progression
+ * indicator Better detection of the ISO with error control Major code optimisation Integration in
+ * main Chrono Cross Hacking tool
+ *
+ * ******** End of original disclaimer by Yazoo ********
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "cdutils.h"
+#include "generic.h"
+#include "Input.h"
+#include "Output.h"
+#include "Main.h"
+#include "cdabstract.h"
+
+CODE_BEGINS
+public:
+Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso(0), cdutil(0) {}
+virtual ~Appli() {
+ delete cdutil;
+ delete f_def;
+ delete f_iso;
+ delete f_out;
+}
+private:
+
+unsigned int tourne;
+
+struct t_index_tab {
+ unsigned long address;
+ long size;
+ long type;
+ long index;
+};
+
+struct t_sequence {
+ unsigned int n;
+ unsigned int sum;
+ String prefix;
+ String name;
+ int type;
+};
+
+String title, iso_filename, prefix;
+unsigned long iso_size;
+unsigned int nb_records, nb_seqs;
+struct t_sequence sequences[100];
+Handle * f_def, * f_iso, * f_out;
+
+cdutils * cdutil;
+
+Byte user_data[2352];
+
+virtual int startup() throw (GeneralException)
+{
+
+ verbosity = 3;
+
+ printm(M_BARE,
+"Xenogears File Extractor by Nicolas \"Pixel\" Noble\n"
+"Highly based upon the Chrono Cross File Extractor By Yazoo\n\n");
+
+ if (argc != 3) {
+ printm(M_BARE, "Usage: %s <definition_file.sqr> <iso_file_name>\nSee readme.txt for details\n",
+ argv[0]);
+ exit(-1);
+ }
+
+ printm(M_STATUS, "Processing file %s...\n", argv[1]);
+
+ f_def = new Input(argv[1]);
+
+ if (process_def_file()) {
+ printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]);
+ exit(-1);
+ }
+
+ iso_filename = argv[2];
+
+ printm(M_STATUS, "Begin processing iso file.\n");
+ f_iso = cdabstract::open_cd(iso_filename);
+
+ if (check_iso()) {
+ printm(M_ERROR, "Invalid iso file for " + title + "\n");
+ printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n");
+ } else {
+ printm(M_INFO, "Genuine " + title + " iso detected.\n");
+ }
+
+ cdutil = new cdutils(f_iso);
+
+ printm(M_STATUS, "Entering files read sequence\n");
+ read_files();
+ return 0;
+}
+
+/*
+ * Ugly but working... for now
+ */
+int process_def_file()
+{
+ String t;
+ unsigned int n, sum = 0;
+
+ *f_def >> t;
+ printm(M_INFO, "Read title: " + t + "\n");
+ title = t;
+
+ *f_def >> t;
+ iso_size = t.to_int();
+ printm(M_INFO, "Read iso size: %lu bytes\n", iso_size);
+
+ *f_def >> t;
+ printm(M_INFO, "Read global directory prefix: " + t + "\n");
+ prefix = t;
+
+ *f_def >> t;
+ nb_records = t.to_int();
+ printm(M_INFO, "Read total of records: %u\n", nb_records);
+
+ while (1) {
+ *f_def >> t;
+ n = t.to_int();
+ if (!n) {
+ if (sum == nb_records) {
+ printm(M_INFO, "Definition file seems coherent\n");
+ return 0;
+ } else {
+ printm(M_ERROR, "Definition file incoherent\n");
+ return 1;
+ }
+ }
+ sum += n;
+ sequences[nb_seqs].n = n;
+ sequences[nb_seqs].sum = sum;
+ *f_def >> t;
+ sequences[nb_seqs].prefix = t;
+ *f_def >> t;
+ n = t.to_int();
+ sequences[nb_seqs].type = n;
+ *f_def >> t;
+ sequences[nb_seqs].name = t;
+ printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of " + t +
+ " (" + sequences[nb_seqs].prefix + ")\n", nb_seqs, n, sum);
+ nb_seqs++;
+ }
+}
+
+long check_iso()
+{
+ unsigned long length;
+
+ length = f_iso->GetSize();
+ if (length < 0) {
+ printm(M_INFO, "Can not get file size, assuming reading from CD.\n");
+ } else {
+ printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length);
+ if (length != iso_size) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+void read_files()
+{
+ t_index_tab index_tab[10000];
+ unsigned char t[8];
+ unsigned long i;
+ unsigned long j;
+ unsigned int seq = 0;
+ unsigned long indexer;
+ struct t_index_tab *p = (struct t_index_tab *) t;
+
+ Byte fat[32768];
+
+#define INDEXPOS 24
+
+ cdutil->sector_seek(INDEXPOS);
+ for (i = INDEXPOS; i < (INDEXPOS + 16); i++) {
+ printm(M_INFO, "Reading fat sector %lu\n", i);
+ cdutil->read_sector(&fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
+ }
+
+ indexer = 0;
+ for (j = 0; j < 32768; j = j + 7) {
+ t[0] = 0;
+ bcopy((char *) &fat[j], (char *) t + 1, 7);
+ p->address >>= 8;
+ index_tab[indexer] = *p;
+ if (p->size > 0 && p->address != 0) {
+ index_tab[indexer].index = j / 7;
+ printm(M_INFO, "Found a quite valid index: number %4lu, address %6lu, size %3li\n",
+ indexer, index_tab[indexer].address, index_tab[indexer].size);
+ indexer++;
+ if (indexer == nb_records)
+ break;
+ } else {
+ printm(M_WARNING, "Ignored invalid index chunk number %4lu (size = %lu) (%02x %02x %02x %02x %02x %02x %02x)\n",
+ j / 7, -index_tab[indexer].size, t[0], t[1], t[2], t[4], t[5], t[6], t[7]);
+ }
+ }
+ printm(M_STATUS, "Index file generation complete.\n\n");
+
+ for (i = 0; i < nb_records; i++) {
+ if (sequences[seq].sum == i)
+ seq++;
+ index_tab[i].type = sequences[seq].type;
+ if (sequences[seq].type == 0) {
+ printm(M_INFO, "%6lu (%10lu): ignored\n", index_tab[i].address, index_tab[i].size);
+ } else {
+ printm(M_INFO, "%6lu (%10lu): ", index_tab[i].address, index_tab[i].size);
+ file_dump(index_tab[i].address, index_tab[i].size, i, seq);
+ if (verbosity >= M_INFO) {
+ fprintf(stderr, "\n");
+ }
+ }
+ }
+ fprintf(stderr, "\n");
+}
+
+void file_dump(unsigned long debut, unsigned long taille, long num, int seq)
+{
+ long i;
+ long nbsects;
+ String nom;
+ String extension = ".out";
+ String nom_t;
+ char type = sequences[seq].type;
+ char ptitbidule[] = "-\\|/";
+
+ nom_t.set("%04ld", num);
+
+ nom = "./" + prefix + "/";
+
+ MKDIR(nom.to_charp());
+
+ nom += sequences[seq].prefix + "/";
+ MKDIR(nom.to_charp());
+
+ nom += nom_t + extension;;
+
+ f_out = new Output(nom);
+ nbsects = taille / sec_sizes[type];
+ if (taille % sec_sizes[type])
+ nbsects++;
+ cdutil->sector_seek(debut);
+ for (i = 0; i < nbsects; i++) {
+ if (verbosity < M_INFO)
+ fprintf(stderr, " (%c)\010\010\010\010\010", ptitbidule[((tourne++) >> 8) % 4]);
+ cdutil->read_sector(user_data, type);
+ if (i != (nbsects - 1)) {
+ f_out->write(user_data, sec_sizes[type]);
+ } else {
+ f_out->write(user_data, taille % sec_sizes[type] ? taille % sec_sizes[type] : sec_sizes[type]);
+ }
+ }
+ delete f_out;
+ f_out = 0;
+ printm(M_BARE, " (*) Dumped file number %4ld - type \"" + sequences[seq].name + "\" \r", num);
+}
+CODE_ENDS
diff --git a/Xenogears/reinsert.cpp b/Xenogears/reinsert.cpp index bf60cb4..fb7460e 100644 --- a/Xenogears/reinsert.cpp +++ b/Xenogears/reinsert.cpp @@ -1,290 +1,290 @@ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include "cdutils.h" -#include "generic.h" -#include "Input.h" -#include "Output.h" -#include "Main.h" - -CODE_BEGINS -public: -Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso_r(0), f_iso_w(0), f_in(0), cdutil(0), slus_index(-1), force(0) {} -virtual ~Appli() { - delete cdutil; - delete f_def; - delete f_iso_r; - delete f_iso_w; - delete f_in; -} -private: - -unsigned int tourne; - -struct t_index_tab { - unsigned long address; - long size; - long type; - long index; -}; - -struct t_sequence { - unsigned int n; - unsigned int sum; - String prefix; - String name; - int type; -}; - -String title, iso_filename, prefix, in_filename; -unsigned long iso_size; -unsigned int nb_records, nb_seqs; -struct t_sequence sequences[1000]; -Handle * f_def, * f_iso_r, * f_iso_w, * f_in; -cdutils * cdutil; - -int slus_index, force; - -unsigned char user_data[2352]; - -void usage() throw (GeneralException) { - printm(M_BARE, "Usage: %s <definition_file.sqr> <iso_file_name> <file_index> <filename> [-f]\nSee readme.txt for details\n", - argv[0]); - throw Exit(-1); -} - -virtual int startup() throw (GeneralException) -{ - int fileindex; - - verbosity = 1; - - printm(M_BARE, "Xenogears File Insertor by Nicolas \"Pixel\" Noble\n\n"); - - if ((argc != 5) && (argc != 6)) { - usage(); - } - - if (argc == 6) { - if (strcmp(argv[5], "-f")) { - usage(); - } else { - force = 1; - } - } - - printm(M_STATUS, "Processing file %s...\n", argv[1]); - - f_def = new Input(argv[1]); - - if (process_def_file(f_def)) { - printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]); - throw Exit(-1); - } - - iso_filename = argv[2]; - - printm(M_STATUS, "Begin processing iso file.\n"); - f_iso_r = new Input(iso_filename); - f_iso_w = new Output(iso_filename, 0, 0); - f_iso_w->seek(0, SEEK_SET); - - cdutil = new cdutils(f_iso_r, f_iso_w); - - if (check_iso()) { - printm(M_ERROR, "Invalid iso file for " + title + "\n"); - printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n"); - throw Exit(-1); - } else { - printm(M_INFO, "Genuine " + title + " iso detected.\n"); - } - - fileindex = atoi(argv[3]); - in_filename = argv[4]; - f_in = new Input(in_filename); - - printm(M_STATUS, "Entering files write sequence\n"); - write_files(fileindex); - return 0; -} - -/* - * Ugly but working... for now - */ -int process_def_file(Handle * f_def) -{ - unsigned int n, sum = 0; - String t; - - *f_def >> t; - printm(M_INFO, "Read title: " + t + "\n"); - title = t; - - *f_def >> t; - iso_size = t.to_int(); - printm(M_INFO, "Read iso size: %lu bytes\n", iso_size); - - *f_def >> t; - printm(M_INFO, "Read global directory prefix: " + t + "\n"); - prefix = t; - - *f_def >> t; - nb_records = t.to_int(); - printm(M_INFO, "Read total of records: %u\n", nb_records); - - while (1) { - *f_def >> t; - n = t.to_int(); - if (!n) { - if (sum == nb_records) { - printm(M_INFO, "Definition file seems coherent\n"); - return 0; - } else { - printm(M_ERROR, "Definition file incoherent\n"); - return 1; - } - } - sum += n; - sequences[nb_seqs].n = n; - sequences[nb_seqs].sum = sum; - *f_def >> t; - sequences[nb_seqs].prefix = t; - *f_def >> t; - n = t.to_int(); - sequences[nb_seqs].type = n; - *f_def >> t; - sequences[nb_seqs].name = t; - printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of " + t + - " (" + sequences[nb_seqs].prefix + ")\n", nb_seqs, n, sum); - nb_seqs++; - } -} - -long check_iso() -{ - unsigned long length; - - length = f_iso_r->GetSize(); - printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length); - if (length != iso_size) { - return 1; - } - return 0; -} - -#define INDEXPOS 24 - -void rewrite_fat(Byte * new_fat) { - unsigned char old_fat[34816]; - int i; - - cdutil->sector_seek(INDEXPOS); - for (i = INDEXPOS; i < (INDEXPOS + 16); i++) { - printm(M_INFO, "Writing fat sector %lu\n", i); - cdutil->write_sector(&new_fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); - } - - cdutil->sector_seek(slus_index + 1); - for (i = slus_index + 1; i < (slus_index + 18); i++) { - printm(M_INFO, "Reading SLUS sector %lu\n", i); - cdutil->read_sector(&old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1); - } - - bcopy((char *) new_fat, (char *) old_fat + 4, 32768); - cdutil->sector_seek(slus_index + 1); - for (i = slus_index + 1; i < (slus_index + 18); i++) { - printm(M_INFO, "Writing SLUS sector %lu\n", i); - cdutil->write_sector(&old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1); - } -} - -void write_files(int fileindex) throw (GeneralException) -{ - t_index_tab index_tab[10000]; - unsigned char t[8]; - unsigned long i; - unsigned long j; - unsigned int seq = 0; - unsigned long indexer; - struct t_index_tab *p = (struct t_index_tab *) t; - - long old_file_size, new_file_size, old_nb_sects, new_nb_sects; - unsigned char fat[32768]; - - cdutil->sector_seek(INDEXPOS); - for (i = INDEXPOS; i < (INDEXPOS + 16); i++) { - printm(M_INFO, "Reading fat sector %lu\n", i); - cdutil->read_sector(&fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1); - } - - indexer = 0; - for (j = 0; j < 32768; j = j + 7) { - t[0] = 0; - bcopy((char *) &fat[j], (char *) t + 1, 7); - p->address >>= 8; - index_tab[indexer] = *p; - if (p->size > 0 && p->address != 0) { - index_tab[indexer].index = j / 7; - printm(M_INFO, "Found a quite valid index: number %4lu, address %6lu, size %3li\n", - indexer, index_tab[indexer].address, index_tab[indexer].size); - indexer++; - if (indexer == nb_records) - break; - } else { - printm(M_WARNING, "Ignored invalid index chunk number %4lu (size = %lu) (%02x %02x %02x %02x %02x %02x %02x)\n", - j / 7, -index_tab[indexer].size, t[0], t[1], t[2], t[4], t[5], t[6], t[7]); - } - } - printm(M_STATUS, "Index file generation complete.\n\n"); - - for (i = 0; i < nb_records; i++) { - if (sequences[seq].sum == i) - seq++; - index_tab[i].type = sequences[seq].type; - if (sequences[seq].prefix == "SLUS") { - if (slus_index >= 0) { - printm(M_ERROR, "Two SLUS files defined\n"); - throw Exit(-1); - } - slus_index = index_tab[i].address; - } - } - - if (slus_index < 0) { - printm(M_ERROR, "No SLUS file defined\n"); - throw Exit(-1); - } - - printm(M_INFO, "SLUS file found at sector %6i\n", slus_index); - - new_file_size = f_in->GetSize(); - old_file_size = index_tab[fileindex].size; - - new_nb_sects = new_file_size / sec_sizes[index_tab[fileindex].type]; - old_nb_sects = old_file_size / sec_sizes[index_tab[fileindex].type]; - - if (new_file_size % sec_sizes[index_tab[fileindex].type]) { - new_nb_sects++; - } - - if (old_file_size % sec_sizes[index_tab[fileindex].type]) { - old_nb_sects++; - } - - if (new_nb_sects > old_nb_sects) { - printm(M_ERROR, "New file too big.\n"); - if (!force) { - throw Exit(-1); - } - } - - printm(M_INFO, "New file size: %12li, old file size: %12li\n", new_file_size, old_file_size); - printm(M_INFO, "New file ssize: %12li, old file ssize: %12li\n", new_nb_sects, old_nb_sects); - - printm(M_INFO, "File address: %6i\n", index_tab[fileindex].address); - - cdutil->write_file(f_in, index_tab[fileindex].type, index_tab[fileindex].address); - *((long *)(&fat[index_tab[fileindex].index * 7 + 3])) = new_file_size; - rewrite_fat(fat); -} -CODE_ENDS +#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "cdutils.h"
+#include "generic.h"
+#include "Input.h"
+#include "Output.h"
+#include "Main.h"
+
+CODE_BEGINS
+public:
+Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso_r(0), f_iso_w(0), f_in(0), cdutil(0), slus_index(-1), force(0) {}
+virtual ~Appli() {
+ delete cdutil;
+ delete f_def;
+ delete f_iso_r;
+ delete f_iso_w;
+ delete f_in;
+}
+private:
+
+unsigned int tourne;
+
+struct t_index_tab {
+ unsigned long address;
+ long size;
+ long type;
+ long index;
+};
+
+struct t_sequence {
+ unsigned int n;
+ unsigned int sum;
+ String prefix;
+ String name;
+ int type;
+};
+
+String title, iso_filename, prefix, in_filename;
+unsigned long iso_size;
+unsigned int nb_records, nb_seqs;
+struct t_sequence sequences[1000];
+Handle * f_def, * f_iso_r, * f_iso_w, * f_in;
+cdutils * cdutil;
+
+int slus_index, force;
+
+unsigned char user_data[2352];
+
+void usage() throw (GeneralException) {
+ printm(M_BARE, "Usage: %s <definition_file.sqr> <iso_file_name> <file_index> <filename> [-f]\nSee readme.txt for details\n",
+ argv[0]);
+ throw Exit(-1);
+}
+
+virtual int startup() throw (GeneralException)
+{
+ int fileindex;
+
+ verbosity = 1;
+
+ printm(M_BARE, "Xenogears File Insertor by Nicolas \"Pixel\" Noble\n\n");
+
+ if ((argc != 5) && (argc != 6)) {
+ usage();
+ }
+
+ if (argc == 6) {
+ if (strcmp(argv[5], "-f")) {
+ usage();
+ } else {
+ force = 1;
+ }
+ }
+
+ printm(M_STATUS, "Processing file %s...\n", argv[1]);
+
+ f_def = new Input(argv[1]);
+
+ if (process_def_file(f_def)) {
+ printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]);
+ throw Exit(-1);
+ }
+
+ iso_filename = argv[2];
+
+ printm(M_STATUS, "Begin processing iso file.\n");
+ f_iso_r = new Input(iso_filename);
+ f_iso_w = new Output(iso_filename, 0, 0);
+ f_iso_w->seek(0, SEEK_SET);
+
+ cdutil = new cdutils(f_iso_r, f_iso_w);
+
+ if (check_iso()) {
+ printm(M_ERROR, "Invalid iso file for " + title + "\n");
+ printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n");
+ throw Exit(-1);
+ } else {
+ printm(M_INFO, "Genuine " + title + " iso detected.\n");
+ }
+
+ fileindex = atoi(argv[3]);
+ in_filename = argv[4];
+ f_in = new Input(in_filename);
+
+ printm(M_STATUS, "Entering files write sequence\n");
+ write_files(fileindex);
+ return 0;
+}
+
+/*
+ * Ugly but working... for now
+ */
+int process_def_file(Handle * f_def)
+{
+ unsigned int n, sum = 0;
+ String t;
+
+ *f_def >> t;
+ printm(M_INFO, "Read title: " + t + "\n");
+ title = t;
+
+ *f_def >> t;
+ iso_size = t.to_int();
+ printm(M_INFO, "Read iso size: %lu bytes\n", iso_size);
+
+ *f_def >> t;
+ printm(M_INFO, "Read global directory prefix: " + t + "\n");
+ prefix = t;
+
+ *f_def >> t;
+ nb_records = t.to_int();
+ printm(M_INFO, "Read total of records: %u\n", nb_records);
+
+ while (1) {
+ *f_def >> t;
+ n = t.to_int();
+ if (!n) {
+ if (sum == nb_records) {
+ printm(M_INFO, "Definition file seems coherent\n");
+ return 0;
+ } else {
+ printm(M_ERROR, "Definition file incoherent\n");
+ return 1;
+ }
+ }
+ sum += n;
+ sequences[nb_seqs].n = n;
+ sequences[nb_seqs].sum = sum;
+ *f_def >> t;
+ sequences[nb_seqs].prefix = t;
+ *f_def >> t;
+ n = t.to_int();
+ sequences[nb_seqs].type = n;
+ *f_def >> t;
+ sequences[nb_seqs].name = t;
+ printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of " + t +
+ " (" + sequences[nb_seqs].prefix + ")\n", nb_seqs, n, sum);
+ nb_seqs++;
+ }
+}
+
+long check_iso()
+{
+ unsigned long length;
+
+ length = f_iso_r->GetSize();
+ printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length);
+ if (length != iso_size) {
+ return 1;
+ }
+ return 0;
+}
+
+#define INDEXPOS 24
+
+void rewrite_fat(Byte * new_fat) {
+ unsigned char old_fat[34816];
+ int i;
+
+ cdutil->sector_seek(INDEXPOS);
+ for (i = INDEXPOS; i < (INDEXPOS + 16); i++) {
+ printm(M_INFO, "Writing fat sector %lu\n", i);
+ cdutil->write_sector(&new_fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
+ }
+
+ cdutil->sector_seek(slus_index + 1);
+ for (i = slus_index + 1; i < (slus_index + 18); i++) {
+ printm(M_INFO, "Reading SLUS sector %lu\n", i);
+ cdutil->read_sector(&old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1);
+ }
+
+ bcopy((char *) new_fat, (char *) old_fat + 4, 32768);
+ cdutil->sector_seek(slus_index + 1);
+ for (i = slus_index + 1; i < (slus_index + 18); i++) {
+ printm(M_INFO, "Writing SLUS sector %lu\n", i);
+ cdutil->write_sector(&old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1);
+ }
+}
+
+void write_files(int fileindex) throw (GeneralException)
+{
+ t_index_tab index_tab[10000];
+ unsigned char t[8];
+ unsigned long i;
+ unsigned long j;
+ unsigned int seq = 0;
+ unsigned long indexer;
+ struct t_index_tab *p = (struct t_index_tab *) t;
+
+ long old_file_size, new_file_size, old_nb_sects, new_nb_sects;
+ unsigned char fat[32768];
+
+ cdutil->sector_seek(INDEXPOS);
+ for (i = INDEXPOS; i < (INDEXPOS + 16); i++) {
+ printm(M_INFO, "Reading fat sector %lu\n", i);
+ cdutil->read_sector(&fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
+ }
+
+ indexer = 0;
+ for (j = 0; j < 32768; j = j + 7) {
+ t[0] = 0;
+ bcopy((char *) &fat[j], (char *) t + 1, 7);
+ p->address >>= 8;
+ index_tab[indexer] = *p;
+ if (p->size > 0 && p->address != 0) {
+ index_tab[indexer].index = j / 7;
+ printm(M_INFO, "Found a quite valid index: number %4lu, address %6lu, size %3li\n",
+ indexer, index_tab[indexer].address, index_tab[indexer].size);
+ indexer++;
+ if (indexer == nb_records)
+ break;
+ } else {
+ printm(M_WARNING, "Ignored invalid index chunk number %4lu (size = %lu) (%02x %02x %02x %02x %02x %02x %02x)\n",
+ j / 7, -index_tab[indexer].size, t[0], t[1], t[2], t[4], t[5], t[6], t[7]);
+ }
+ }
+ printm(M_STATUS, "Index file generation complete.\n\n");
+
+ for (i = 0; i < nb_records; i++) {
+ if (sequences[seq].sum == i)
+ seq++;
+ index_tab[i].type = sequences[seq].type;
+ if (sequences[seq].prefix == "SLUS") {
+ if (slus_index >= 0) {
+ printm(M_ERROR, "Two SLUS files defined\n");
+ throw Exit(-1);
+ }
+ slus_index = index_tab[i].address;
+ }
+ }
+
+ if (slus_index < 0) {
+ printm(M_ERROR, "No SLUS file defined\n");
+ throw Exit(-1);
+ }
+
+ printm(M_INFO, "SLUS file found at sector %6i\n", slus_index);
+
+ new_file_size = f_in->GetSize();
+ old_file_size = index_tab[fileindex].size;
+
+ new_nb_sects = new_file_size / sec_sizes[index_tab[fileindex].type];
+ old_nb_sects = old_file_size / sec_sizes[index_tab[fileindex].type];
+
+ if (new_file_size % sec_sizes[index_tab[fileindex].type]) {
+ new_nb_sects++;
+ }
+
+ if (old_file_size % sec_sizes[index_tab[fileindex].type]) {
+ old_nb_sects++;
+ }
+
+ if (new_nb_sects > old_nb_sects) {
+ printm(M_ERROR, "New file too big.\n");
+ if (!force) {
+ throw Exit(-1);
+ }
+ }
+
+ printm(M_INFO, "New file size: %12li, old file size: %12li\n", new_file_size, old_file_size);
+ printm(M_INFO, "New file ssize: %12li, old file ssize: %12li\n", new_nb_sects, old_nb_sects);
+
+ printm(M_INFO, "File address: %6i\n", index_tab[fileindex].address);
+
+ cdutil->write_file(f_in, index_tab[fileindex].type, index_tab[fileindex].address);
+ *((long *)(&fat[index_tab[fileindex].index * 7 + 3])) = new_file_size;
+ rewrite_fat(fat);
+}
+CODE_ENDS
diff --git a/Xenogears/script-comp.cpp b/Xenogears/script-comp.cpp index 964b350..01f6bdd 100644 --- a/Xenogears/script-comp.cpp +++ b/Xenogears/script-comp.cpp @@ -1,109 +1,109 @@ -#include "lzss.h" -#include "Input.h" -#include "Output.h" -#include "generic.h" -#include "Main.h" - -CODE_BEGINS -public: -Appli() : lzss_o(new lzss()) {} -virtual ~Appli() { delete lzss_o; } -private: - -lzss * lzss_o; - -void process_one_file(Handle * f, Handle * d, Handle * f_part, int n) { - String nom_du_fichier; - char zeros[4] = {0, 0, 0, 0}, * datas; - int script_position, true_length, delta, data_length; - printm(M_BARE, " Copying header\n"); - - f->seek(0x14c); - f->read(&script_position, 4); - f->seek(0); - copy(f, d, script_position); - - f->seek(0x150); - f->read(&script_position, 4); - f->seek(script_position); - - data_length = f->GetSize() - script_position; - - datas = (char *) malloc(data_length); - f->read(datas, data_length); - +#include "lzss.h"
+#include "Input.h"
+#include "Output.h"
+#include "generic.h"
+#include "Main.h"
+
+CODE_BEGINS
+public:
+Appli() : lzss_o(new lzss()) {}
+virtual ~Appli() { delete lzss_o; }
+private:
+
+lzss * lzss_o;
+
+void process_one_file(Handle * f, Handle * d, Handle * f_part, int n) {
+ String nom_du_fichier;
+ char zeros[4] = {0, 0, 0, 0}, * datas;
+ int script_position, true_length, delta, data_length;
+ printm(M_BARE, " Copying header\n");
+
+ f->seek(0x14c);
+ f->read(&script_position, 4);
+ f->seek(0);
+ copy(f, d, script_position);
+
+ f->seek(0x150);
+ f->read(&script_position, 4);
+ f->seek(script_position);
+
+ data_length = f->GetSize() - script_position;
+
+ datas = (char *) malloc(data_length);
+ f->read(datas, data_length);
+
printm(M_BARE, " Processing script\n");
- - true_length = f_part->GetSize(); - +
+ true_length = f_part->GetSize();
+
script_position = d->tell();
- d->seek(0x14c); - d->write(&script_position, 4); - d->seek(0x128); - d->write(&true_length, 4); - d->seek(0, SEEK_END); - - lzss_o->lzss_comp(f_part, d, &delta); - - script_position = d->tell(); - if ((true_length = (script_position & 3))) { - d->write(zeros, 4 - true_length); - } - - printm(M_BARE, " Processing extra datas\n"); - script_position = d->tell(); - d->seek(0x150); + d->seek(0x14c);
d->write(&script_position, 4);
+ d->seek(0x128);
+ d->write(&true_length, 4);
+ d->seek(0, SEEK_END);
- d->seek(0,SEEK_END); - d->write(datas, data_length); - - free(datas); -} - -virtual int startup() throw (GeneralException) -{ - Handle * f_script_comp, * f_old_script, * f_new_script; - int i; - int num = 0; - String nom_du_fichier; - + lzss_o->lzss_comp(f_part, d, &delta);
+
+ script_position = d->tell();
+ if ((true_length = (script_position & 3))) {
+ d->write(zeros, 4 - true_length);
+ }
+
+ printm(M_BARE, " Processing extra datas\n");
+ script_position = d->tell();
+ d->seek(0x150);
+ d->write(&script_position, 4);
+
+ d->seek(0,SEEK_END);
+ d->write(datas, data_length);
+
+ free(datas);
+}
+
+virtual int startup() throw (GeneralException)
+{
+ Handle * f_script_comp, * f_old_script, * f_new_script;
+ int i;
+ int num = 0;
+ String nom_du_fichier;
+
for (i = 384; i < 1844; i = i + 2) {
- printm(M_BARE, "CD1 - File %d -> Script %d\n", i, num); - nom_du_fichier.set("xeno_d1/ROOMS/%04d.out", i); - f_old_script = new Input(nom_du_fichier); - nom_du_fichier.set("xeno_d1/ROOMS/%04d.out-new", i); - f_new_script = new Output(nom_du_fichier); - nom_du_fichier.set("xeno_d1/ROOMS/%04d/script.comp", num); - f_script_comp = new Input(nom_du_fichier); - - process_one_file(f_old_script, f_new_script, f_script_comp, num); - - delete f_script_comp; - delete f_new_script; - delete f_old_script; - num++; - } - num = 0; - - for (i = 379; i < 1838; i = i + 2) { - printm(M_BARE, "CD2 - File %d -> Script %d\n", i, num); - nom_du_fichier.set("xeno_d2/ROOMS/%04d.out", i); - f_old_script = new Input(nom_du_fichier); - nom_du_fichier.set("xeno_d2/ROOMS/%04d.out-new", i); - f_new_script = new Output(nom_du_fichier); - nom_du_fichier.set("xeno_d2/ROOMS/%04d/script.comp", num); - f_script_comp = new Input(nom_du_fichier); - - process_one_file(f_old_script, f_new_script, f_script_comp, num); - - delete f_script_comp; - delete f_new_script; - delete f_old_script; - num++; - } - printm(M_BARE, "Done !\n"); - - return 0; -} -CODE_ENDS + printm(M_BARE, "CD1 - File %d -> Script %d\n", i, num);
+ nom_du_fichier.set("xeno_d1/ROOMS/%04d.out", i);
+ f_old_script = new Input(nom_du_fichier);
+ nom_du_fichier.set("xeno_d1/ROOMS/%04d.out-new", i);
+ f_new_script = new Output(nom_du_fichier);
+ nom_du_fichier.set("xeno_d1/ROOMS/%04d/script.comp", num);
+ f_script_comp = new Input(nom_du_fichier);
+
+ process_one_file(f_old_script, f_new_script, f_script_comp, num);
+
+ delete f_script_comp;
+ delete f_new_script;
+ delete f_old_script;
+ num++;
+ }
+ num = 0;
+
+ for (i = 379; i < 1838; i = i + 2) {
+ printm(M_BARE, "CD2 - File %d -> Script %d\n", i, num);
+ nom_du_fichier.set("xeno_d2/ROOMS/%04d.out", i);
+ f_old_script = new Input(nom_du_fichier);
+ nom_du_fichier.set("xeno_d2/ROOMS/%04d.out-new", i);
+ f_new_script = new Output(nom_du_fichier);
+ nom_du_fichier.set("xeno_d2/ROOMS/%04d/script.comp", num);
+ f_script_comp = new Input(nom_du_fichier);
+
+ process_one_file(f_old_script, f_new_script, f_script_comp, num);
+
+ delete f_script_comp;
+ delete f_new_script;
+ delete f_old_script;
+ num++;
+ }
+ printm(M_BARE, "Done !\n");
+
+ return 0;
+}
+CODE_ENDS
diff --git a/Xenogears/script-dec.cpp b/Xenogears/script-dec.cpp index 55edb31..0285013 100644 --- a/Xenogears/script-dec.cpp +++ b/Xenogears/script-dec.cpp @@ -1,82 +1,82 @@ -#include <stdio.h> -#include <stdlib.h> -#include "lzss.h" -#include "BString.h" -#include "Input.h" -#include "Output.h" -#include "Main.h" - -CODE_BEGINS -public: -Appli() : lzss_o(new lzss()) {} -virtual ~Appli() { delete lzss_o; } -private: - -lzss * lzss_o; - -void process_one_file(Handle * f, int d, int n) { - String nom_du_fichier; - long script_position, true_length; - int i; - Handle * f_out; - - if (f->GetSize() == 24) return; - - nom_du_fichier.set("xeno_d%d/ROOMS/%04i", d, n); - MKDIR(nom_du_fichier.to_charp()); - - i = 7; -// for (i = 0; i < 9; i++) { -// printm(M_BARE, " Processing part %i\n", i); - nom_du_fichier.set("xeno_d%d/ROOMS/%04i/script.comp", d, n); -// sprintf(nom_du_fichier, "xeno_d%d/ROOMS/%04i/part-%i", d, n, i); - f_out = new Output(nom_du_fichier); - f->seek(0x130 + i * 4); - f->read(&script_position, 4); - f->seek(0x10c + i * 4); - f->read(&true_length, 4); - f->seek(script_position); - lzss_o->lzss_decomp(f, f_out, true_length); -// if (i == 7) { -// fseek(f_out, 0, SEEK_SET); -// fread(&true_length, 4, 1, f_out); -// printm(M_BARE, " (seems to be the script number %i)\n", true_length); -// } - delete f_out; -// } -} - -virtual int startup() throw (GeneralException) -{ - Handle * f_script_comp; - int i; - int num = 0; - char nom_du_fichier[100]; - - for (i = 384; i < 1844; i = i + 2) { - printm(M_BARE, "CD 1 - File %d -> Script %d\n", i, num); - sprintf(nom_du_fichier, "xeno_d1/ROOMS/%04d.out", i); - f_script_comp = new Input(nom_du_fichier); - - process_one_file(f_script_comp, 1, num); - - delete f_script_comp; - num++; - } - - num = 0; - - for (i = 379; i < 1838; i = i + 2) { - printm(M_BARE, "CD 2 - File %d -> Script %d\n", i, num); - sprintf(nom_du_fichier, "xeno_d2/ROOMS/%04d.out", i); - f_script_comp = new Input(nom_du_fichier); - - process_one_file(f_script_comp, 2, num); - - delete f_script_comp; - num++; - } - printm(M_BARE, "Done !\n"); - return 0; -} -CODE_ENDS +#include <stdio.h>
+#include <stdlib.h>
+#include "lzss.h"
+#include "BString.h"
+#include "Input.h"
+#include "Output.h"
+#include "Main.h"
+
+CODE_BEGINS
+public:
+Appli() : lzss_o(new lzss()) {}
+virtual ~Appli() { delete lzss_o; }
+private:
+
+lzss * lzss_o;
+
+void process_one_file(Handle * f, int d, int n) {
+ String nom_du_fichier;
+ long script_position, true_length;
+ int i;
+ Handle * f_out;
+
+ if (f->GetSize() == 24) return;
+
+ nom_du_fichier.set("xeno_d%d/ROOMS/%04i", d, n);
+ MKDIR(nom_du_fichier.to_charp());
+
+ i = 7;
+// for (i = 0; i < 9; i++) {
+// printm(M_BARE, " Processing part %i\n", i);
+ nom_du_fichier.set("xeno_d%d/ROOMS/%04i/script.comp", d, n);
+// sprintf(nom_du_fichier, "xeno_d%d/ROOMS/%04i/part-%i", d, n, i);
+ f_out = new Output(nom_du_fichier);
+ f->seek(0x130 + i * 4);
+ f->read(&script_position, 4);
+ f->seek(0x10c + i * 4);
+ f->read(&true_length, 4);
+ f->seek(script_position);
+ lzss_o->lzss_decomp(f, f_out, true_length);
+// if (i == 7) {
+// fseek(f_out, 0, SEEK_SET);
+// fread(&true_length, 4, 1, f_out);
+// printm(M_BARE, " (seems to be the script number %i)\n", true_length);
+// }
+ delete f_out;
+// }
+}
+
+virtual int startup() throw (GeneralException)
+{
+ Handle * f_script_comp;
+ int i;
+ int num = 0;
+ char nom_du_fichier[100];
+
+ for (i = 384; i < 1844; i = i + 2) {
+ printm(M_BARE, "CD 1 - File %d -> Script %d\n", i, num);
+ sprintf(nom_du_fichier, "xeno_d1/ROOMS/%04d.out", i);
+ f_script_comp = new Input(nom_du_fichier);
+
+ process_one_file(f_script_comp, 1, num);
+
+ delete f_script_comp;
+ num++;
+ }
+
+ num = 0;
+
+ for (i = 379; i < 1838; i = i + 2) {
+ printm(M_BARE, "CD 2 - File %d -> Script %d\n", i, num);
+ sprintf(nom_du_fichier, "xeno_d2/ROOMS/%04d.out", i);
+ f_script_comp = new Input(nom_du_fichier);
+
+ process_one_file(f_script_comp, 2, num);
+
+ delete f_script_comp;
+ num++;
+ }
+ printm(M_BARE, "Done !\n");
+ return 0;
+}
+CODE_ENDS
diff --git a/Xenogears/test-dlzss.cpp b/Xenogears/test-dlzss.cpp index ecd0f7e..4591b9d 100644 --- a/Xenogears/test-dlzss.cpp +++ b/Xenogears/test-dlzss.cpp @@ -1,7 +1,7 @@ -#include <stdio.h> -#include "lzss.h" - -int main(void) { - lzss_decomp(0, 1); - return 0; -} +#include <stdio.h>
+#include "lzss.h"
+
+int main(void) {
+ lzss_decomp(0, 1);
+ return 0;
+}
diff --git a/Xenogears/test-lzss.cpp b/Xenogears/test-lzss.cpp index 0257e99..b92808c 100644 --- a/Xenogears/test-lzss.cpp +++ b/Xenogears/test-lzss.cpp @@ -1,7 +1,7 @@ -#include <stdio.h> -#include "lzss.h" - -int main(void) { - lzss_comp(0, 1); - return 0; -} +#include <stdio.h>
+#include "lzss.h"
+
+int main(void) {
+ lzss_comp(0, 1);
+ return 0;
+}
@@ -1,34 +1,34 @@ -#include <stdio.h> -#include <stdlib.h> -#include "Input.h" -#include "Main.h" - -#define THRESHOLD 20480 - -CODE_BEGINS -virtual int startup() throw (GeneralException) { - unsigned int p = strtol(argv[1], 0, 0); - char * fn = argv[2]; - Handle * f = new Input(fn); - - if (!f) { - printf("Bleeh.\n"); - exit(-1); - } - int l = f->GetSize(), i; - char * b = (char *) malloc(l); - - f->read(b, l); - - for (i = 0; i < l - 3; i++) { - unsigned int r = *((unsigned int *) &(b[i])); - if (r == p) { - printf("Found 0x%08x at %i = 0x%08x in %s\n", p, i, i, fn); - } - } - - delete f; - - return 0; -} +#include <stdio.h>
+#include <stdlib.h>
+#include "Input.h"
+#include "Main.h"
+
+#define THRESHOLD 20480
+
+CODE_BEGINS
+virtual int startup() throw (GeneralException) {
+ unsigned int p = strtol(argv[1], 0, 0);
+ char * fn = argv[2];
+ Handle * f = new Input(fn);
+
+ if (!f) {
+ printf("Bleeh.\n");
+ exit(-1);
+ }
+ int l = f->GetSize(), i;
+ char * b = (char *) malloc(l);
+
+ f->read(b, l);
+
+ for (i = 0; i < l - 3; i++) {
+ unsigned int r = *((unsigned int *) &(b[i]));
+ if (r == p) {
+ printf("Found 0x%08x at %i = 0x%08x in %s\n", p, i, i, fn);
+ }
+ }
+
+ delete f;
+
+ return 0;
+}
CODE_ENDS
\ No newline at end of file @@ -1,40 +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 +#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/crypto-search.cpp b/crypto-search.cpp index 164c001..c5cb785 100644 --- a/crypto-search.cpp +++ b/crypto-search.cpp @@ -1,106 +1,106 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <stdio.h> -#include <stdlib.h> -#ifdef __linux__ -#include <values.h> -#else -#define MAXINT INT_MAX -#define MININT INT_MIN -#endif -#include <string.h> -#include "generic.h" -#include "Input.h" -#include "Main.h" - -CODE_BEGINS -int startup(void) throw (GeneralException) { - int size, mind, maxd, delta, len, i, j; - char * buffer, * str; - Handle * h; - - if (argc != 3) { - printm(M_BARE, "Usage: %s <inputfile> <needle>\n", argv[0]); - exit(-1); - } - - verbosity = M_INFO; - - h = new Input(argv[1]); - - str = argv[2]; - size = h->GetSize(); - -#if 0 - printm(M_STATUS, "Requesting memory (%i bytes)\n", size); - - if (!(buffer = (char *) malloc(size))) { - printm(M_ERROR, "Not enough memory.\n"); - delete h; - exit(-1); - } - - printm(M_STATUS, "Loading file...\n"); - h->read(buffer, size); -#else - printm(M_STATUS, "Mapping file\n"); - - buffer = (char *) h->mmap(); -#endif - printm(M_STATUS, "Done, initialising the search.\n"); - len = strlen(argv[2]); - - mind = MININT; - maxd = MAXINT; - - for (i = 0; i < len; i++) { - mind = (mind < (-str[i])) ? -str[i] : mind; - maxd = (maxd > (255 - str[i])) ? 255 - str[i] : maxd; - } - - printm(M_STATUS, "Min Delta = %i, Max Delta = %i\n", mind, maxd); - - printm(M_STATUS, "Beginning searching...\n"); - - for (i = 0; i < (size - len); i++) { - delta = buffer[i] - str[0]; - if ((delta >= mind) && (delta <= maxd)) { - int good = 1; - for (j = 1; j < len; j++) { - if (((delta + str[j]) != buffer[i + j]) && (str[j] != '.')) { - good = 0; - break; - } - } - if (good) { - printm(M_STATUS, "Found a needle at %i = 0x%08x with delta %i:", i, i, delta); - for (j = 0; j < len; j++) { - printm(M_BARE, "%c", buffer[j + i]); - } - printm(M_BARE, "\n"); - } - } - } - - delete h; - - return 0; -} -CODE_ENDS +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef __linux__
+#include <values.h>
+#else
+#define MAXINT INT_MAX
+#define MININT INT_MIN
+#endif
+#include <string.h>
+#include "generic.h"
+#include "Input.h"
+#include "Main.h"
+
+CODE_BEGINS
+int startup(void) throw (GeneralException) {
+ int size, mind, maxd, delta, len, i, j;
+ char * buffer, * str;
+ Handle * h;
+
+ if (argc != 3) {
+ printm(M_BARE, "Usage: %s <inputfile> <needle>\n", argv[0]);
+ exit(-1);
+ }
+
+ verbosity = M_INFO;
+
+ h = new Input(argv[1]);
+
+ str = argv[2];
+ size = h->GetSize();
+
+#if 0
+ printm(M_STATUS, "Requesting memory (%i bytes)\n", size);
+
+ if (!(buffer = (char *) malloc(size))) {
+ printm(M_ERROR, "Not enough memory.\n");
+ delete h;
+ exit(-1);
+ }
+
+ printm(M_STATUS, "Loading file...\n");
+ h->read(buffer, size);
+#else
+ printm(M_STATUS, "Mapping file\n");
+
+ buffer = (char *) h->mmap();
+#endif
+ printm(M_STATUS, "Done, initialising the search.\n");
+ len = strlen(argv[2]);
+
+ mind = MININT;
+ maxd = MAXINT;
+
+ for (i = 0; i < len; i++) {
+ mind = (mind < (-str[i])) ? -str[i] : mind;
+ maxd = (maxd > (255 - str[i])) ? 255 - str[i] : maxd;
+ }
+
+ printm(M_STATUS, "Min Delta = %i, Max Delta = %i\n", mind, maxd);
+
+ printm(M_STATUS, "Beginning searching...\n");
+
+ for (i = 0; i < (size - len); i++) {
+ delta = buffer[i] - str[0];
+ if ((delta >= mind) && (delta <= maxd)) {
+ int good = 1;
+ for (j = 1; j < len; j++) {
+ if (((delta + str[j]) != buffer[i + j]) && (str[j] != '.')) {
+ good = 0;
+ break;
+ }
+ }
+ if (good) {
+ printm(M_STATUS, "Found a needle at %i = 0x%08x with delta %i:", i, i, delta);
+ for (j = 0; j < len; j++) {
+ printm(M_BARE, "%c", buffer[j + i]);
+ }
+ printm(M_BARE, "\n");
+ }
+ }
+ }
+
+ delete h;
+
+ return 0;
+}
+CODE_ENDS
diff --git a/dtemain.cpp b/dtemain.cpp index ec60509..a9047b0 100644 --- a/dtemain.cpp +++ b/dtemain.cpp @@ -1,69 +1,69 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include "Input.h" -#include "generic.h" -#include "dte.h" - -int main(int argc, char ** argv) { - Handle * f, * t; - long old_size; - int i; - - verbosity = M_INFO; - - printm(M_STATUS, "Reading thingy table\n"); - t = new Input(argv[2]); - read_thingy(t); - delete t; - - f = new Input(argv[1]); - dte_text_size = f->GetSize(); - dte_text = (char *) calloc(dte_text_size + 4, 1); - printm(M_STATUS, "Reading file, size = %li\n", dte_text_size); - read_thingy_file(f); - delete f; - - printm(M_STATUS, "True size = %li\n", old_size = dte_text_size); - - printm(M_STATUS, "Compressing file.\n"); - dte_compress(); - - printm(M_STATUS, "Rereading file.\n"); - f = new Input(argv[1]); - dte_text_size = f->GetSize(); - dte_text = (char *) calloc(dte_text_size + 4, 1); - read_thingy_file(f); - delete f; - - printm(M_STATUS, "True size = %li, real gain = %li\n", dte_text_size, old_size - dte_text_size); - - printm(M_INFO, "DTE Usage:\n"); - for (i = 0; i < 256; i++) { - printm(M_INFO, "Entry %i ('%s') used at %i\n", i, things[i], dte_usage[i]); - } - - printm(M_INFO, "Number of couples: %i\n", tnb_dte); - - free(dte_text); -} +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include "Input.h"
+#include "generic.h"
+#include "dte.h"
+
+int main(int argc, char ** argv) {
+ Handle * f, * t;
+ long old_size;
+ int i;
+
+ verbosity = M_INFO;
+
+ printm(M_STATUS, "Reading thingy table\n");
+ t = new Input(argv[2]);
+ read_thingy(t);
+ delete t;
+
+ f = new Input(argv[1]);
+ dte_text_size = f->GetSize();
+ dte_text = (char *) calloc(dte_text_size + 4, 1);
+ printm(M_STATUS, "Reading file, size = %li\n", dte_text_size);
+ read_thingy_file(f);
+ delete f;
+
+ printm(M_STATUS, "True size = %li\n", old_size = dte_text_size);
+
+ printm(M_STATUS, "Compressing file.\n");
+ dte_compress();
+
+ printm(M_STATUS, "Rereading file.\n");
+ f = new Input(argv[1]);
+ dte_text_size = f->GetSize();
+ dte_text = (char *) calloc(dte_text_size + 4, 1);
+ read_thingy_file(f);
+ delete f;
+
+ printm(M_STATUS, "True size = %li, real gain = %li\n", dte_text_size, old_size - dte_text_size);
+
+ printm(M_INFO, "DTE Usage:\n");
+ for (i = 0; i < 256; i++) {
+ printm(M_INFO, "Entry %i ('%s') used at %i\n", i, things[i], dte_usage[i]);
+ }
+
+ printm(M_INFO, "Number of couples: %i\n", tnb_dte);
+
+ free(dte_text);
+}
@@ -1,81 +1,81 @@ -#include <SDL.h> -#include "generic.h" -#include "Main.h" -#include "glbase.h" -#include "gltexture.h" - -CODE_BEGINS -virtual int startup() throw (GeneralException) { - Uint8 * texture; - verbosity = M_INFO; - mogltk::glbase::setup(); - - mogltk::texture * mytex = new mogltk::texture(256, 256); - - texture = (Uint8 *) mytex->GetSurface()->pixels; - - for (int y = 0; y < 256; y++) { - for (int x = 0; x < 256; x++) { - int r = random() % 256; - texture[(x + y * 256) * 4 + 0] = r; - texture[(x + y * 256) * 4 + 1] = r; - texture[(x + y * 256) * 4 + 2] = r; - texture[(x + y * 256) * 4 + 3] = 255; - } - } - - SDL_Surface * s = SDL_LoadBMP("pattern6.bmp"); - SDL_BlitSurface(s, NULL, mytex->GetSurface(), NULL); -/* - for (int y = 0; y < 256; y += 2) { - for (int x = 0; x < 256; x += 2) { - texture[(x + y * 256) * 4 + 0] = 255; - texture[(x + y * 256) * 4 + 1] = 255; - texture[(x + y * 256) * 4 + 2] = 255; - texture[(x + y * 256) * 4 + 3] = 255; - } - } -*/ - mytex->Generate(); - - mogltk::glbase::Enter2DMode(); - - mytex->Bind(); - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2i(0, 0); - glVertex2f(50, 50); - glTexCoord2i(511, 0); - glVertex2f(561, 50); - glTexCoord2i(0, 511); - glVertex2f(50, 561); - glTexCoord2i(511, 511); - glVertex2f(561, 561); - glEnd(); - - mogltk::texture::Unbind(); - glBegin(GL_TRIANGLE_STRIP); -// glTexCoord2i(0, 0); - glColor3d(0, 0, 0); - glVertex2i(400, 100); -// glTexCoord2i(256, 0); - glColor3d(1, 0, 0); - glVertex2i(450, 100); -// glTexCoord2i(0, 256); - glColor3d(0, 1, 0); - glVertex2i(400, 150); -// glTexCoord2i(256, 256); - glColor3d(0, 0, 1); - glVertex2i(450, 150); - glEnd(); - mogltk::glbase::Leave2DMode(); - - mogltk::glbase::Flip(); - -// sleep(15); - getchar(); - - delete mytex; - - return 0; -} -CODE_ENDS +#include <SDL.h>
+#include "generic.h"
+#include "Main.h"
+#include "glbase.h"
+#include "gltexture.h"
+
+CODE_BEGINS
+virtual int startup() throw (GeneralException) {
+ Uint8 * texture;
+ verbosity = M_INFO;
+ mogltk::glbase::setup();
+
+ mogltk::texture * mytex = new mogltk::texture(256, 256);
+
+ texture = (Uint8 *) mytex->GetSurface()->pixels;
+
+ for (int y = 0; y < 256; y++) {
+ for (int x = 0; x < 256; x++) {
+ int r = random() % 256;
+ texture[(x + y * 256) * 4 + 0] = r;
+ texture[(x + y * 256) * 4 + 1] = r;
+ texture[(x + y * 256) * 4 + 2] = r;
+ texture[(x + y * 256) * 4 + 3] = 255;
+ }
+ }
+
+ SDL_Surface * s = SDL_LoadBMP("pattern6.bmp");
+ SDL_BlitSurface(s, NULL, mytex->GetSurface(), NULL);
+/*
+ for (int y = 0; y < 256; y += 2) {
+ for (int x = 0; x < 256; x += 2) {
+ texture[(x + y * 256) * 4 + 0] = 255;
+ texture[(x + y * 256) * 4 + 1] = 255;
+ texture[(x + y * 256) * 4 + 2] = 255;
+ texture[(x + y * 256) * 4 + 3] = 255;
+ }
+ }
+*/
+ mytex->Generate();
+
+ mogltk::glbase::Enter2DMode();
+
+ mytex->Bind();
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2i(0, 0);
+ glVertex2f(50, 50);
+ glTexCoord2i(511, 0);
+ glVertex2f(561, 50);
+ glTexCoord2i(0, 511);
+ glVertex2f(50, 561);
+ glTexCoord2i(511, 511);
+ glVertex2f(561, 561);
+ glEnd();
+
+ mogltk::texture::Unbind();
+ glBegin(GL_TRIANGLE_STRIP);
+// glTexCoord2i(0, 0);
+ glColor3d(0, 0, 0);
+ glVertex2i(400, 100);
+// glTexCoord2i(256, 0);
+ glColor3d(1, 0, 0);
+ glVertex2i(450, 100);
+// glTexCoord2i(0, 256);
+ glColor3d(0, 1, 0);
+ glVertex2i(400, 150);
+// glTexCoord2i(256, 256);
+ glColor3d(0, 0, 1);
+ glVertex2i(450, 150);
+ glEnd();
+ mogltk::glbase::Leave2DMode();
+
+ mogltk::glbase::Flip();
+
+// sleep(15);
+ getchar();
+
+ delete mytex;
+
+ return 0;
+}
+CODE_ENDS
diff --git a/includes/cdabstract.h b/includes/cdabstract.h index 9a728ec..a5dcd0e 100644 --- a/includes/cdabstract.h +++ b/includes/cdabstract.h @@ -1,65 +1,65 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002-2003 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: cdabstract.h,v 1.5 2003-12-11 16:53:42 pixel Exp $ */ - -#ifndef __CD_ABSTRACT_H__ -#define __CD_ABSTRACT_H__ - -#if defined (_MSC_VER) || defined (__MINGW32__) -#include <windowsx.h> - -#define IOCTL_SCSI_BASE 0x00000004 - -#define METHOD_BUFFERED 0 -#define METHOD_OUT_DIRECT 2 - -#define FILE_ANY_ACCESS 0 -#define FILE_READ_ACCESS 0x0001 - -#define CTL_CODE( DevType, Function, Method, Access ) ( \ - ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \ -) -#define IOCTL_SCSI_GET_ADDRESS CTL_CODE( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS ) -#define FILE_DEVICE_CD_ROM 0x00000002 -#define IOCTL_CDROM_BASE FILE_DEVICE_CD_ROM -#define IOCTL_CDROM_RAW_READ CTL_CODE(IOCTL_CDROM_BASE, 0x000F, METHOD_OUT_DIRECT, FILE_READ_ACCESS) - -#endif - -#include <vector> -#include <Exceptions.h> -#include <Handle.h> - -class cdabstract : public Base { - public: - static Handle * open_cd(const String &); - static bool canprobe(); - static std::vector<String> probe() throw (GeneralException); -#ifdef _WIN32 - protected: - static HANDLE OpenIOCTLFile(char cLetter); - static void GetIOCTLAdapter(HANDLE hF, int * iDA, int * iDT, int * iDL); -#endif - private: - static bool subprobe(String &); - friend class cdreader; -}; - -#endif +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: cdabstract.h,v 1.6 2004-11-27 21:44:46 pixel Exp $ */
+
+#ifndef __CD_ABSTRACT_H__
+#define __CD_ABSTRACT_H__
+
+#if defined (_MSC_VER) || defined (__MINGW32__)
+#include <windowsx.h>
+
+#define IOCTL_SCSI_BASE 0x00000004
+
+#define METHOD_BUFFERED 0
+#define METHOD_OUT_DIRECT 2
+
+#define FILE_ANY_ACCESS 0
+#define FILE_READ_ACCESS 0x0001
+
+#define CTL_CODE( DevType, Function, Method, Access ) ( \
+ ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
+)
+#define IOCTL_SCSI_GET_ADDRESS CTL_CODE( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
+#define FILE_DEVICE_CD_ROM 0x00000002
+#define IOCTL_CDROM_BASE FILE_DEVICE_CD_ROM
+#define IOCTL_CDROM_RAW_READ CTL_CODE(IOCTL_CDROM_BASE, 0x000F, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
+
+#endif
+
+#include <vector>
+#include <Exceptions.h>
+#include <Handle.h>
+
+class cdabstract : public Base {
+ public:
+ static Handle * open_cd(const String &);
+ static bool canprobe();
+ static std::vector<String> probe() throw (GeneralException);
+#ifdef _WIN32
+ protected:
+ static HANDLE OpenIOCTLFile(char cLetter);
+ static void GetIOCTLAdapter(HANDLE hF, int * iDA, int * iDT, int * iDL);
+#endif
+ private:
+ static bool subprobe(String &);
+ friend class cdreader;
+};
+
+#endif
diff --git a/includes/cdreader.h b/includes/cdreader.h index a962d19..6b01efc 100644 --- a/includes/cdreader.h +++ b/includes/cdreader.h @@ -1,66 +1,66 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002-2003 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: cdreader.h,v 1.10 2003-12-04 01:55:15 pixel Exp $ */ - -#ifndef __CDREADER_H__ -#define __CDREADER_H__ - -#include <sys/types.h> -#include <time.h> -#include <BString.h> -#include <Handle.h> -#include "cdabstract.h" - -class cdreader : public Handle { - public: - cdreader(const String &) throw (GeneralException); - cdreader(const cdreader &); - virtual ~cdreader(); - virtual bool CanWrite() const; - virtual bool CanRead() const; - virtual bool CanSeek() const; -#if defined (_MSC_VER) || defined (__MINGW32__) - virtual void close() throw (GeneralException); -#endif - virtual ssize_t read(void *buf, size_t count) throw (GeneralException); - virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException); - virtual String GetName() const; - virtual ssize_t GetSize() const; - void fetchsector(void *, int = -1); - void getsector(void *, int = -1, int = 1) throw (GeneralException); - void sectorseek(int); - - private: - struct cachedsector { - Byte sector[2352]; - cachedsector * next, * prev; - int n; - }; - String n; - int sector; - cachedsector * head, * tail, * sectors[400000]; - int nsectors; - - void removetail(); - void actualize(cachedsector * s); - void introduce(Byte * datas, int n); -}; - -#endif +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: cdreader.h,v 1.11 2004-11-27 21:44:46 pixel Exp $ */
+
+#ifndef __CDREADER_H__
+#define __CDREADER_H__
+
+#include <sys/types.h>
+#include <time.h>
+#include <BString.h>
+#include <Handle.h>
+#include "cdabstract.h"
+
+class cdreader : public Handle {
+ public:
+ cdreader(const String &) throw (GeneralException);
+ cdreader(const cdreader &);
+ virtual ~cdreader();
+ virtual bool CanWrite() const;
+ virtual bool CanRead() const;
+ virtual bool CanSeek() const;
+#if defined (_MSC_VER) || defined (__MINGW32__)
+ virtual void close() throw (GeneralException);
+#endif
+ virtual ssize_t read(void *buf, size_t count) throw (GeneralException);
+ virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException);
+ virtual String GetName() const;
+ virtual ssize_t GetSize() const;
+ void fetchsector(void *, int = -1);
+ void getsector(void *, int = -1, int = 1) throw (GeneralException);
+ void sectorseek(int);
+
+ private:
+ struct cachedsector {
+ Byte sector[2352];
+ cachedsector * next, * prev;
+ int n;
+ };
+ String n;
+ int sector;
+ cachedsector * head, * tail, * sectors[400000];
+ int nsectors;
+
+ void removetail();
+ void actualize(cachedsector * s);
+ void introduce(Byte * datas, int n);
+};
+
+#endif
diff --git a/includes/cdutils.h b/includes/cdutils.h index c81c093..2f59341 100644 --- a/includes/cdutils.h +++ b/includes/cdutils.h @@ -1,139 +1,139 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002-2003 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: cdutils.h,v 1.16 2004-05-03 12:55:04 pixel Exp $ */ - -#ifndef __CDUTILS_H__ -#define __CDUTILS_H__ - -#include "yazedc.h" -#include "generic.h" - -#include "Handle.h" - -#define MODE0 0 -#define MODE1 1 -#define MODE2 2 -#define MODE2_FORM1 3 -#define MODE2_FORM2 4 -#define MODE_RAW 5 -#define GUESS 6 - -extern const long sec_sizes[]; -extern const long sec_offsts[]; -extern const String sec_modes[]; - -#ifdef _MSC_VER -#pragma pack(1) -#endif - -class cdutils : public Base { - public: - cdutils(Handle * f_iso_r, Handle * f_iso_w = 0); - virtual ~cdutils(); - - PPACKED struct DirEntry { - unsigned char R; - unsigned char NExt; - unsigned long Sector; - unsigned long BESector; - unsigned long Size; - unsigned long BESize; - unsigned char Year; - unsigned char Month; - unsigned char Day; - unsigned char Hour; - unsigned char Minute; - unsigned char Second; - unsigned char Offset; - unsigned char Flags; - unsigned char HandleUnit; - unsigned char HandleGap; - unsigned short VolSeq; - unsigned short BEVolSeq; - unsigned char N; - char id[1]; - } PACKED; - - struct DirEntry * rootDir; - - Handle * open_ppf(String ppf, String comment) throw(GeneralException); - void close_ppf() throw(GeneralException); - void set_iso_w(Handle *); - static unsigned short int swap_word(unsigned short int i); - static unsigned long int swap_dword(unsigned long int i); - int guess_type(int number = -1); - void sector_seek(long sector); - 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) 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(); - int show_pt_infos(); - struct DirEntry find_path(String path); - struct DirEntry find_parent(String path); - struct DirEntry * find_path(Byte ** buffer, String path); - struct DirEntry * find_parent(Byte ** buffer, String path); - void show_head_entry(void); - int show_entry(struct DirEntry * dir); - int show_dir(struct DirEntry * dir); - struct DirEntry find_dir_entry(struct DirEntry * dir, String name); - struct DirEntry * find_dir_entry(Byte ** buffer, struct DirEntry * dir, String name); - static unsigned char from_BCD(unsigned char x); - static unsigned char to_BCD(unsigned char x); - 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); - yazedc yazedc_o; - - Handle * f_iso_r, * f_iso_w, * ppf_file; - int pt1, pt2, snum, ptl, root; -}; - -class cdfile : public Handle { - public: - cdfile(cdutils *, const cdutils::DirEntry *, int = GUESS); - cdfile(cdutils *, int sector, ssize_t = -1, int = GUESS); - virtual ~cdfile(); - virtual ssize_t read(void *buf, size_t count) throw (GeneralException); - virtual bool CanRead() const; - virtual String GetName() const; - virtual bool CanWatch() const; - virtual ssize_t GetSize() const; - virtual bool CanSeek() const; - virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException); - private: - cdutils * cd; - int sector, mode; - size_t size; - String name; - cdutils::DirEntry * dir; -}; - -#endif +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: cdutils.h,v 1.17 2004-11-27 21:44:46 pixel Exp $ */
+
+#ifndef __CDUTILS_H__
+#define __CDUTILS_H__
+
+#include "yazedc.h"
+#include "generic.h"
+
+#include "Handle.h"
+
+#define MODE0 0
+#define MODE1 1
+#define MODE2 2
+#define MODE2_FORM1 3
+#define MODE2_FORM2 4
+#define MODE_RAW 5
+#define GUESS 6
+
+extern const long sec_sizes[];
+extern const long sec_offsts[];
+extern const String sec_modes[];
+
+#ifdef _MSC_VER
+#pragma pack(1)
+#endif
+
+class cdutils : public Base {
+ public:
+ cdutils(Handle * f_iso_r, Handle * f_iso_w = 0);
+ virtual ~cdutils();
+
+ PPACKED struct DirEntry {
+ unsigned char R;
+ unsigned char NExt;
+ unsigned long Sector;
+ unsigned long BESector;
+ unsigned long Size;
+ unsigned long BESize;
+ unsigned char Year;
+ unsigned char Month;
+ unsigned char Day;
+ unsigned char Hour;
+ unsigned char Minute;
+ unsigned char Second;
+ unsigned char Offset;
+ unsigned char Flags;
+ unsigned char HandleUnit;
+ unsigned char HandleGap;
+ unsigned short VolSeq;
+ unsigned short BEVolSeq;
+ unsigned char N;
+ char id[1];
+ } PACKED;
+
+ struct DirEntry * rootDir;
+
+ Handle * open_ppf(String ppf, String comment) throw(GeneralException);
+ void close_ppf() throw(GeneralException);
+ void set_iso_w(Handle *);
+ static unsigned short int swap_word(unsigned short int i);
+ static unsigned long int swap_dword(unsigned long int i);
+ int guess_type(int number = -1);
+ void sector_seek(long sector);
+ 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) 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();
+ int show_pt_infos();
+ struct DirEntry find_path(String path);
+ struct DirEntry find_parent(String path);
+ struct DirEntry * find_path(Byte ** buffer, String path);
+ struct DirEntry * find_parent(Byte ** buffer, String path);
+ void show_head_entry(void);
+ int show_entry(struct DirEntry * dir);
+ int show_dir(struct DirEntry * dir);
+ struct DirEntry find_dir_entry(struct DirEntry * dir, String name);
+ struct DirEntry * find_dir_entry(Byte ** buffer, struct DirEntry * dir, String name);
+ static unsigned char from_BCD(unsigned char x);
+ static unsigned char to_BCD(unsigned char x);
+ 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);
+ yazedc yazedc_o;
+
+ Handle * f_iso_r, * f_iso_w, * ppf_file;
+ int pt1, pt2, snum, ptl, root;
+};
+
+class cdfile : public Handle {
+ public:
+ cdfile(cdutils *, const cdutils::DirEntry *, int = GUESS);
+ cdfile(cdutils *, int sector, ssize_t = -1, int = GUESS);
+ virtual ~cdfile();
+ virtual ssize_t read(void *buf, size_t count) throw (GeneralException);
+ virtual bool CanRead() const;
+ virtual String GetName() const;
+ virtual bool CanWatch() const;
+ virtual ssize_t GetSize() const;
+ virtual bool CanSeek() const;
+ virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException);
+ private:
+ cdutils * cd;
+ int sector, mode;
+ size_t size;
+ String name;
+ cdutils::DirEntry * dir;
+};
+
+#endif
diff --git a/includes/dte.h b/includes/dte.h index 3be7f9c..f464084 100644 --- a/includes/dte.h +++ b/includes/dte.h @@ -1,19 +1,19 @@ -#ifndef __DTE_H__ -#define __DTE_H__ - -void dte_reset(void); -void build_dte(void); -void push_entry(long entry); -char * read_line(Handle * f, char * b); -void dte_compress(); -void read_thingy(Handle * f); -void read_thingy_file(Handle * f); - -extern char * dte_text; -extern char * things[256]; -extern long dte_text_size; -extern long dte_usage[256]; - -extern long tnb_dte; - -#endif +#ifndef __DTE_H__
+#define __DTE_H__
+
+void dte_reset(void);
+void build_dte(void);
+void push_entry(long entry);
+char * read_line(Handle * f, char * b);
+void dte_compress();
+void read_thingy(Handle * f);
+void read_thingy_file(Handle * f);
+
+extern char * dte_text;
+extern char * things[256];
+extern long dte_text_size;
+extern long dte_usage[256];
+
+extern long tnb_dte;
+
+#endif
diff --git a/includes/gettext.h b/includes/gettext.h index c37de7f..36573bc 100644 --- a/includes/gettext.h +++ b/includes/gettext.h @@ -1,58 +1,58 @@ -#ifndef __GETTEXT_H__ -#define __GETTEXT_H__ - -#ifndef gettext -# define gettext(Msgid) ((const char *) (Msgid)) -#endif - -#ifndef dgettext -# define dgettext(Domainname, Msgid) ((const char *) (Msgid)) -#endif - -#ifndef dcgettext -# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) -#endif - -#ifndef ngettext -# define ngettext(Msgid1, Msgid2, N) \ - ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) -#endif - -#ifndef dngettext -# define dngettext(Domainname, Msgid1, Msgid2, N) \ - ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) -#endif - -#ifndef dcngettext -# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ - ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) -#endif - -#ifndef textdomain -# define textdomain(Domainname) ((const char *) (Domainname)) -#endif - -#ifndef bindtextdomain -# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname)) -#endif - -#ifndef bind_text_domain_codeset -# define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset)) -#endif - -#ifndef setlocale -# define setlocale(category, locale) -#endif - -#ifndef LC_ALL -# define LC_ALL 0 -#endif - -#ifndef gettext_noop -# define gettext_noop(String) String -#endif - -#define _(Text) dgettext ("bleh", Text) -#define N_(Text) Text - -#endif +#ifndef __GETTEXT_H__
+#define __GETTEXT_H__
+
+#ifndef gettext
+# define gettext(Msgid) ((const char *) (Msgid))
+#endif
+
+#ifndef dgettext
+# define dgettext(Domainname, Msgid) ((const char *) (Msgid))
+#endif
+
+#ifndef dcgettext
+# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
+#endif
+
+#ifndef ngettext
+# define ngettext(Msgid1, Msgid2, N) \
+ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
+#endif
+
+#ifndef dngettext
+# define dngettext(Domainname, Msgid1, Msgid2, N) \
+ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
+#endif
+
+#ifndef dcngettext
+# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
+ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
+#endif
+
+#ifndef textdomain
+# define textdomain(Domainname) ((const char *) (Domainname))
+#endif
+
+#ifndef bindtextdomain
+# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname))
+#endif
+
+#ifndef bind_text_domain_codeset
+# define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset))
+#endif
+
+#ifndef setlocale
+# define setlocale(category, locale)
+#endif
+
+#ifndef LC_ALL
+# define LC_ALL 0
+#endif
+
+#ifndef gettext_noop
+# define gettext_noop(String) String
+#endif
+
+#define _(Text) dgettext ("bleh", Text)
+#define N_(Text) Text
+
+#endif
diff --git a/includes/isobuilder.h b/includes/isobuilder.h index 3a5de00..d693651 100644 --- a/includes/isobuilder.h +++ b/includes/isobuilder.h @@ -1,105 +1,105 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002-2003 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: isobuilder.h,v 1.9 2004-01-03 15:04:47 pixel Exp $ */ - -#ifndef __ISOBUILDER_H__ -#define __ISOBUILDER_H__ - -#include <Handle.h> -#include "cdutils.h" -#include "yazedc.h" - -class isobuilder : public Base { - public: - struct Date { - int year, month, day, hour, minute, second, hundredths, offset; - void dump(Byte * datas); - Date(int = 0); - Date(Byte * datas); - }; - struct PVD { - String sysid, volid; - String volsetid, pubid, prepid, appid; - String copyright, abstract, biblio; - Date volcreat, modif, volexp, voleff; - Byte appdata[512]; - }; - class DirTree : public Base { - public: - DirTree(DirTree * father, bool dir = true); - virtual ~DirTree(); - void fromdir(cdutils::DirEntry *); - void dumpdirs(isobuilder *) throw (GeneralException); - int buildpath(Byte * datas, int size, bool bigendian = false) throw (GeneralException); - bool isdir(); - void setbasicsxa(); - int sector; - int size; - bool hidden; - bool hardhide; - String name; - Date creation; - bool have_xa, xa_dir, xa_audio, xa_str, xa_xa, xa_form1; - int buildentry(Byte * buffer, int spaceleft, bool put_xa = true); - int mode; - DirTree * Father(); - DirTree * Child(); - DirTree * Brother(); - DirTree * Find(const String &); - private: - DirTree * father, * child, * brother; - bool dir; - int node; - int numerate(int); - }; - isobuilder(Handle * w, int mode = MODE2_FORM1); - ~isobuilder(); - void foreword(cdutils *); - void foreword(Handle * forewords, int mode = MODE_RAW); - void foreword(Byte * forewords, int mode = MODE_RAW); - int getdispsect(); - int putfile(Handle * file, int mode = -1, int sector = -1); - int putdatas(Byte * datas, size_t size, int mode = -1, int sector = -1); - int createsector(Byte * datas, int mode = -1, int sector = -1); - void setEOF(); - void clearEOF(); - DirTree * setbasics(PVD pvd, int rootsize = 1, int ptsize = 1, int nvd = 1, int rootsect = -1) throw (GeneralException); - DirTree * createdir(DirTree *, const String & _name, int size = 1, cdutils::DirEntry * = 0, int mode = -1) throw (GeneralException); - DirTree * createfile(DirTree *, Handle * file, const String & _name, cdutils::DirEntry * = 0, int mode = -1) throw (GeneralException); - void copydir(DirTree *, cdutils *, cdutils::DirEntry *, int mode = -1); - static PVD createpvd(Handle *); - static PVD createpvd(cdutils *); - static PVD createpvd(Byte *); - void close(Handle * cue = 0, int mode = -1, int nsects = -1) throw (GeneralException); - private: - Handle * w; - int sector, nsectors; - int sub_EOF, sub_EOR; - bool basics; - PVD pvd; - int rootsize, ptsize, nvd, ptsect, rootsect; - int lastdispsect; - DirTree * root; - yazedc yazedc_o; - bool closed; - int dmode; -}; - -#endif +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: isobuilder.h,v 1.10 2004-11-27 21:44:46 pixel Exp $ */
+
+#ifndef __ISOBUILDER_H__
+#define __ISOBUILDER_H__
+
+#include <Handle.h>
+#include "cdutils.h"
+#include "yazedc.h"
+
+class isobuilder : public Base {
+ public:
+ struct Date {
+ int year, month, day, hour, minute, second, hundredths, offset;
+ void dump(Byte * datas);
+ Date(int = 0);
+ Date(Byte * datas);
+ };
+ struct PVD {
+ String sysid, volid;
+ String volsetid, pubid, prepid, appid;
+ String copyright, abstract, biblio;
+ Date volcreat, modif, volexp, voleff;
+ Byte appdata[512];
+ };
+ class DirTree : public Base {
+ public:
+ DirTree(DirTree * father, bool dir = true);
+ virtual ~DirTree();
+ void fromdir(cdutils::DirEntry *);
+ void dumpdirs(isobuilder *) throw (GeneralException);
+ int buildpath(Byte * datas, int size, bool bigendian = false) throw (GeneralException);
+ bool isdir();
+ void setbasicsxa();
+ int sector;
+ int size;
+ bool hidden;
+ bool hardhide;
+ String name;
+ Date creation;
+ bool have_xa, xa_dir, xa_audio, xa_str, xa_xa, xa_form1;
+ int buildentry(Byte * buffer, int spaceleft, bool put_xa = true);
+ int mode;
+ DirTree * Father();
+ DirTree * Child();
+ DirTree * Brother();
+ DirTree * Find(const String &);
+ private:
+ DirTree * father, * child, * brother;
+ bool dir;
+ int node;
+ int numerate(int);
+ };
+ isobuilder(Handle * w, int mode = MODE2_FORM1);
+ ~isobuilder();
+ void foreword(cdutils *);
+ void foreword(Handle * forewords, int mode = MODE_RAW);
+ void foreword(Byte * forewords, int mode = MODE_RAW);
+ int getdispsect();
+ int putfile(Handle * file, int mode = -1, int sector = -1);
+ int putdatas(Byte * datas, size_t size, int mode = -1, int sector = -1);
+ int createsector(Byte * datas, int mode = -1, int sector = -1);
+ void setEOF();
+ void clearEOF();
+ DirTree * setbasics(PVD pvd, int rootsize = 1, int ptsize = 1, int nvd = 1, int rootsect = -1) throw (GeneralException);
+ DirTree * createdir(DirTree *, const String & _name, int size = 1, cdutils::DirEntry * = 0, int mode = -1) throw (GeneralException);
+ DirTree * createfile(DirTree *, Handle * file, const String & _name, cdutils::DirEntry * = 0, int mode = -1) throw (GeneralException);
+ void copydir(DirTree *, cdutils *, cdutils::DirEntry *, int mode = -1);
+ static PVD createpvd(Handle *);
+ static PVD createpvd(cdutils *);
+ static PVD createpvd(Byte *);
+ void close(Handle * cue = 0, int mode = -1, int nsects = -1) throw (GeneralException);
+ private:
+ Handle * w;
+ int sector, nsectors;
+ int sub_EOF, sub_EOR;
+ bool basics;
+ PVD pvd;
+ int rootsize, ptsize, nvd, ptsect, rootsect;
+ int lastdispsect;
+ DirTree * root;
+ yazedc yazedc_o;
+ bool closed;
+ int dmode;
+};
+
+#endif
diff --git a/includes/luacd.h b/includes/luacd.h index c26957f..f2c7e4a 100644 --- a/includes/luacd.h +++ b/includes/luacd.h @@ -1,92 +1,92 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002-2003 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: luacd.h,v 1.6 2004-05-01 11:48:57 pixel Exp $ */ - -#ifndef __LUACD_H__ -#define __LUACD_H__ - -#include <Exceptions.h> -#include <BLua.h> -#include <LuaHandle.h> -#include <cdutils.h> -#include <isobuilder.h> - -#define CD_PUSHSTATICS(L) { \ - Luacdutils::pushstatics(L); \ - Luacddate::pushstatics(L); \ - LuaPVD::pushstatics(L); \ - LuaDirTree::pushstatics(L); \ - Luaisobuilder::pushstatics(L); \ -} - -class Luacdutils : public LuaObject { - public: - static void pushstatics(Lua *) throw (GeneralException); - Luacdutils(cdutils *); - protected: - virtual void pushmembers(Lua *); - cdutils * cd; -}; - -class Luadirentry : public LuaObject { - public: - Luadirentry(cdutils::DirEntry *); - protected: - virtual void pushmembers(Lua *); - cdutils::DirEntry * dir; -}; - -class Luacddate : public LuaObject { - public: - static void pushstatics(Lua *) throw (GeneralException); - Luacddate(isobuilder::Date *); - private: - virtual void pushmembers(Lua *); - struct isobuilder::Date * date; -}; - -class LuaPVD : public LuaObject { - public: - static void pushstatics(Lua *) throw (GeneralException); - LuaPVD(struct isobuilder::PVD *); - private: - virtual void pushmembers(Lua *); - struct isobuilder::PVD * pvd; -}; - -class LuaDirTree : public LuaObject { - public: - static void pushstatics(Lua *) throw (GeneralException); - LuaDirTree(isobuilder::DirTree *); - private: - virtual void pushmembers(Lua *); - isobuilder::DirTree * dir; -}; - -class Luaisobuilder : public LuaObject { - public: - static void pushstatics(Lua *) throw (GeneralException); - Luaisobuilder(isobuilder *); - private: - virtual void pushmembers(Lua *); - isobuilder * iso; -}; - -#endif +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: luacd.h,v 1.7 2004-11-27 21:44:46 pixel Exp $ */
+
+#ifndef __LUACD_H__
+#define __LUACD_H__
+
+#include <Exceptions.h>
+#include <BLua.h>
+#include <LuaHandle.h>
+#include <cdutils.h>
+#include <isobuilder.h>
+
+#define CD_PUSHSTATICS(L) { \
+ Luacdutils::pushstatics(L); \
+ Luacddate::pushstatics(L); \
+ LuaPVD::pushstatics(L); \
+ LuaDirTree::pushstatics(L); \
+ Luaisobuilder::pushstatics(L); \
+}
+
+class Luacdutils : public LuaObject {
+ public:
+ static void pushstatics(Lua *) throw (GeneralException);
+ Luacdutils(cdutils *);
+ protected:
+ virtual void pushmembers(Lua *);
+ cdutils * cd;
+};
+
+class Luadirentry : public LuaObject {
+ public:
+ Luadirentry(cdutils::DirEntry *);
+ protected:
+ virtual void pushmembers(Lua *);
+ cdutils::DirEntry * dir;
+};
+
+class Luacddate : public LuaObject {
+ public:
+ static void pushstatics(Lua *) throw (GeneralException);
+ Luacddate(isobuilder::Date *);
+ private:
+ virtual void pushmembers(Lua *);
+ struct isobuilder::Date * date;
+};
+
+class LuaPVD : public LuaObject {
+ public:
+ static void pushstatics(Lua *) throw (GeneralException);
+ LuaPVD(struct isobuilder::PVD *);
+ private:
+ virtual void pushmembers(Lua *);
+ struct isobuilder::PVD * pvd;
+};
+
+class LuaDirTree : public LuaObject {
+ public:
+ static void pushstatics(Lua *) throw (GeneralException);
+ LuaDirTree(isobuilder::DirTree *);
+ private:
+ virtual void pushmembers(Lua *);
+ isobuilder::DirTree * dir;
+};
+
+class Luaisobuilder : public LuaObject {
+ public:
+ static void pushstatics(Lua *) throw (GeneralException);
+ Luaisobuilder(isobuilder *);
+ private:
+ virtual void pushmembers(Lua *);
+ isobuilder * iso;
+};
+
+#endif
diff --git a/includes/luapsx.h b/includes/luapsx.h index 1d28dcc..4b8e6e7 100644 --- a/includes/luapsx.h +++ b/includes/luapsx.h @@ -1,34 +1,34 @@ - /* - * PSX-Tools Bundle Pack - * Copyright (C) 2002-2003 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: luapsx.h,v 1.3 2004-05-01 11:48:58 pixel Exp $ */ - -#ifndef __LUAPSX_H__ -#define __LUAPSX_H__ - -#include <Exceptions.h> -#include <BLua.h> -#include <bs.h> - -class Luapsx : public LuaObject { - public: - static void pushstatics(Lua *) throw (GeneralException); -}; - -#endif + /*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: luapsx.h,v 1.4 2004-11-27 21:44:46 pixel Exp $ */
+
+#ifndef __LUAPSX_H__
+#define __LUAPSX_H__
+
+#include <Exceptions.h>
+#include <BLua.h>
+#include <bs.h>
+
+class Luapsx : public LuaObject {
+ public:
+ static void pushstatics(Lua *) throw (GeneralException);
+};
+
+#endif
diff --git a/includes/lzss.h b/includes/lzss.h index 14aa345..d4da684 100644 --- a/includes/lzss.h +++ b/includes/lzss.h @@ -1,81 +1,81 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * aint with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __LZSS_H__ -#define __LZSS_H__ - -#include <stdio.h> -#include "generic.h" -#include "Handle.h" - -#define LZSS_VERSION String("3.0.0-pre1") -#define LZSS_NAME String("lzss") - -class lzss : public Base { - public: - lzss(); - typedef struct { - char * name; - int one_is_compressed, bitmap_inversed, one_jump, overlap_trick, negative_trick, sixteen_bits, ptrb, filling; - int window_start; - int l_mask_1, l_shft_1, l_mask_2, l_shft_2; - int j_mask_1, j_shft_1, j_mask_2, j_shft_2; - int f_mask_1, f_shft_1, f_mask_2, f_shft_2; - int v_mask_1, v_shft_1, v_mask_2, v_shft_2; - } scheme_t; - - enum { - XENO = 0, - DBZ, - FF7, - LM, - MM, - OB, - LODOSS, - FF6, - VP_1, - VP_2, - TOD, - END - }; - - static const scheme_t schemes[]; - int tolerate, blockb; - int blk, bitmap_count; - - unsigned int lzss_decomp(Handle * f_source, Handle * f_cible, int true_length = -1); - void lzss_comp(Handle * f_source, Handle * f_cible, int * delta = NULL); - - Byte swap_bits(Byte); - - void change_scheme(scheme_t); - scheme_t get_scheme(); - - private: - scheme_t scheme; - int lzss_maxsize, lzss_maxptr; - - unsigned int shift(unsigned int, int); - void compute_limits(void); - unsigned char lzss_rd(unsigned char *, int); - int lzss_comp_strstr(unsigned char *, unsigned char *, int *, int); - unsigned char * lzss_memcomp(unsigned char *, int *, int *); -}; - -#endif +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * aint with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __LZSS_H__
+#define __LZSS_H__
+
+#include <stdio.h>
+#include "generic.h"
+#include "Handle.h"
+
+#define LZSS_VERSION String("3.0.0-pre1")
+#define LZSS_NAME String("lzss")
+
+class lzss : public Base {
+ public:
+ lzss();
+ typedef struct {
+ char * name;
+ int one_is_compressed, bitmap_inversed, one_jump, overlap_trick, negative_trick, sixteen_bits, ptrb, filling;
+ int window_start;
+ int l_mask_1, l_shft_1, l_mask_2, l_shft_2;
+ int j_mask_1, j_shft_1, j_mask_2, j_shft_2;
+ int f_mask_1, f_shft_1, f_mask_2, f_shft_2;
+ int v_mask_1, v_shft_1, v_mask_2, v_shft_2;
+ } scheme_t;
+
+ enum {
+ XENO = 0,
+ DBZ,
+ FF7,
+ LM,
+ MM,
+ OB,
+ LODOSS,
+ FF6,
+ VP_1,
+ VP_2,
+ TOD,
+ END
+ };
+
+ static const scheme_t schemes[];
+ int tolerate, blockb;
+ int blk, bitmap_count;
+
+ unsigned int lzss_decomp(Handle * f_source, Handle * f_cible, int true_length = -1);
+ void lzss_comp(Handle * f_source, Handle * f_cible, int * delta = NULL);
+
+ Byte swap_bits(Byte);
+
+ void change_scheme(scheme_t);
+ scheme_t get_scheme();
+
+ private:
+ scheme_t scheme;
+ int lzss_maxsize, lzss_maxptr;
+
+ unsigned int shift(unsigned int, int);
+ void compute_limits(void);
+ unsigned char lzss_rd(unsigned char *, int);
+ int lzss_comp_strstr(unsigned char *, unsigned char *, int *, int);
+ unsigned char * lzss_memcomp(unsigned char *, int *, int *);
+};
+
+#endif
diff --git a/includes/mips.h b/includes/mips.h index 8ace76f..f3fc911 100644 --- a/includes/mips.h +++ b/includes/mips.h @@ -1,18 +1,18 @@ -#ifndef __MIPS_H__ -#define __MIPS_H__ - -#include "mipsdis.h" - -void decode(TDis * d, Uint32 pc); - -enum registers { - Rzr, Rat, Rv0, Rv1, Ra0, Ra1, Ra2, Ra3, - Rt0, Rt1, Rt2, Rt3, Rt4, Rt5, Rt6, Rt7, - Rs0, Rs1, Rs2, Rs3, Rs4, Rs5, Rs6, Rs7, - Rt8, Rt9, Rk0, Rk1, Rgp, Rsp, Rfp, Rra, -}; - -extern char * registers[]; -extern char * CP0registers[]; - -#endif +#ifndef __MIPS_H__
+#define __MIPS_H__
+
+#include "mipsdis.h"
+
+void decode(TDis * d, Uint32 pc);
+
+enum registers {
+ Rzr, Rat, Rv0, Rv1, Ra0, Ra1, Ra2, Ra3,
+ Rt0, Rt1, Rt2, Rt3, Rt4, Rt5, Rt6, Rt7,
+ Rs0, Rs1, Rs2, Rs3, Rs4, Rs5, Rs6, Rs7,
+ Rt8, Rt9, Rk0, Rk1, Rgp, Rsp, Rfp, Rra,
+};
+
+extern char * registers[];
+extern char * CP0registers[];
+
+#endif
diff --git a/includes/mipsdis.h b/includes/mipsdis.h index 5ce2506..e8644cc 100644 --- a/includes/mipsdis.h +++ b/includes/mipsdis.h @@ -1,54 +1,54 @@ -#ifndef __MIPSDIS_H__ -#define __MIPSDIS_H__ -#include <Exceptions.h> -#include <queue> -#include "mipsmem.h" - -class TDis : public Base { - public: - TDis(mipsmem *); - virtual mipsmem * getmem(); - virtual void add_branch(Uint32); - virtual void add_jump(Uint32); - virtual void add_function(Uint32); - virtual void SetTag(Uint32, int, bool); - virtual void Name(const String &); - virtual void PushGPReg(int); - virtual void PushCPReg(int); - virtual void PushImm(Uint32); - virtual void PushTarget(Uint32); - virtual void PushSa(Uint32); - virtual void PushOfB(int reg, Uint32, int); - virtual void PushOffset(Uint32); - virtual void PushFull(Uint32); - virtual void Invalid(); - virtual void Suspect(); - virtual void Comment(const String &); - - virtual void reset(); - - bool invalid; - std::priority_queue<int, std::vector<int>, std::greater<int> > bheap; - std::priority_queue<int, std::vector<int>, std::greater<int> > jheap; - std::priority_queue<int, std::vector<int>, std::greater<int> > fheap; - - Uint32 pc; - private: - mipsmem * mm; -}; - -class Disassembler : public Base { - public: - Disassembler(mipsmem *); - virtual ~Disassembler(); - void mainloop(); - void crawl_code(Uint32 = 0xffffffff); - private: - mipsmem * mm; - TDis * dis; - bool started; - bool infunction; -}; - - -#endif +#ifndef __MIPSDIS_H__
+#define __MIPSDIS_H__
+#include <Exceptions.h>
+#include <queue>
+#include "mipsmem.h"
+
+class TDis : public Base {
+ public:
+ TDis(mipsmem *);
+ virtual mipsmem * getmem();
+ virtual void add_branch(Uint32);
+ virtual void add_jump(Uint32);
+ virtual void add_function(Uint32);
+ virtual void SetTag(Uint32, int, bool);
+ virtual void Name(const String &);
+ virtual void PushGPReg(int);
+ virtual void PushCPReg(int);
+ virtual void PushImm(Uint32);
+ virtual void PushTarget(Uint32);
+ virtual void PushSa(Uint32);
+ virtual void PushOfB(int reg, Uint32, int);
+ virtual void PushOffset(Uint32);
+ virtual void PushFull(Uint32);
+ virtual void Invalid();
+ virtual void Suspect();
+ virtual void Comment(const String &);
+
+ virtual void reset();
+
+ bool invalid;
+ std::priority_queue<int, std::vector<int>, std::greater<int> > bheap;
+ std::priority_queue<int, std::vector<int>, std::greater<int> > jheap;
+ std::priority_queue<int, std::vector<int>, std::greater<int> > fheap;
+
+ Uint32 pc;
+ private:
+ mipsmem * mm;
+};
+
+class Disassembler : public Base {
+ public:
+ Disassembler(mipsmem *);
+ virtual ~Disassembler();
+ void mainloop();
+ void crawl_code(Uint32 = 0xffffffff);
+ private:
+ mipsmem * mm;
+ TDis * dis;
+ bool started;
+ bool infunction;
+};
+
+
+#endif
diff --git a/includes/mipsdump.h b/includes/mipsdump.h index a6c6288..ca2047a 100644 --- a/includes/mipsdump.h +++ b/includes/mipsdump.h @@ -1,73 +1,73 @@ -#ifndef __MIPSDUMP_H__ -#define __MIPSDUMP_H__ - -#include <Exceptions.h> -#include <mipsdis.h> - -enum arg_type { - T_GPREGISTER, - T_CPREGISTER, - T_IMM8, - T_IMM16, - T_IMM32, - T_OFB, -}; - -union arg { - Uint32 v; - struct { - Uint32 o; - int r; - int w; - } OfB; -}; - -template<class T1, class T2> -struct mypair { - T1 left; - T2 right; -}; - -typedef mypair<int, arg> pairarg; - -class TDump : public TDis { - public: - TDump(mipsmem *); - virtual void add_branch(Uint32); - virtual void add_jump(Uint32); - virtual void add_function(Uint32); - virtual void SetTag(Uint32, int, bool); - virtual void Name(const String &); - virtual void PushGPReg(int); - virtual void PushCPReg(int); - virtual void PushImm(Uint32); - virtual void PushTarget(Uint32); - virtual void PushSa(Uint32); - virtual void PushOfB(int reg, Uint32, int); - virtual void PushOffset(Uint32); - virtual void PushFull(Uint32); - virtual void Invalid(); - virtual void Suspect(); - virtual void Comment(const String &); - - virtual void reset(); - - String name; - std::vector<pairarg> args; - String comments; - - Uint32 tg; - - bool invalid, hasbr, hastg, hasfc; -}; - -class Dumper : public Base { - public: - Dumper(mipsmem *); - void process(); - private: - TDump * dump; - mipsmem * mm; -}; - -#endif +#ifndef __MIPSDUMP_H__
+#define __MIPSDUMP_H__
+
+#include <Exceptions.h>
+#include <mipsdis.h>
+
+enum arg_type {
+ T_GPREGISTER,
+ T_CPREGISTER,
+ T_IMM8,
+ T_IMM16,
+ T_IMM32,
+ T_OFB,
+};
+
+union arg {
+ Uint32 v;
+ struct {
+ Uint32 o;
+ int r;
+ int w;
+ } OfB;
+};
+
+template<class T1, class T2>
+struct mypair {
+ T1 left;
+ T2 right;
+};
+
+typedef mypair<int, arg> pairarg;
+
+class TDump : public TDis {
+ public:
+ TDump(mipsmem *);
+ virtual void add_branch(Uint32);
+ virtual void add_jump(Uint32);
+ virtual void add_function(Uint32);
+ virtual void SetTag(Uint32, int, bool);
+ virtual void Name(const String &);
+ virtual void PushGPReg(int);
+ virtual void PushCPReg(int);
+ virtual void PushImm(Uint32);
+ virtual void PushTarget(Uint32);
+ virtual void PushSa(Uint32);
+ virtual void PushOfB(int reg, Uint32, int);
+ virtual void PushOffset(Uint32);
+ virtual void PushFull(Uint32);
+ virtual void Invalid();
+ virtual void Suspect();
+ virtual void Comment(const String &);
+
+ virtual void reset();
+
+ String name;
+ std::vector<pairarg> args;
+ String comments;
+
+ Uint32 tg;
+
+ bool invalid, hasbr, hastg, hasfc;
+};
+
+class Dumper : public Base {
+ public:
+ Dumper(mipsmem *);
+ void process();
+ private:
+ TDump * dump;
+ mipsmem * mm;
+};
+
+#endif
diff --git a/includes/mipsmem.h b/includes/mipsmem.h index f763af8..b083b0f 100644 --- a/includes/mipsmem.h +++ b/includes/mipsmem.h @@ -1,114 +1,114 @@ -#ifndef __MIPSMEM_H__ -#define __MIPSMEM_H__ -#define PSXMEM 0x200000 - -#include <Exceptions.h> -#include <Handle.h> - -enum tags_t { - CODE, - DATA, - STOP, - INVALID, -}; - -class memdata; - -class func_t : public Base { - public: - func_t(); - virtual ~func_t(); - Uint32 endpc; - Uint8 stacksize; -}; - -class refto_t; -class reffrom_t : public Base { - public: - reffrom_t(refto_t *, memdata *); - virtual ~reffrom_t(); - memdata * getref(); - memdata * getmem(); - reffrom_t * getnext(); - private: - refto_t * refto; - reffrom_t * next, * prev; - memdata * header; -}; - -class refto_t : public Base { - public: - refto_t(Uint32, memdata *); - virtual ~refto_t(); - memdata * getref(); - memdata * getmem(); - private: - reffrom_t * reffrom; - memdata * mem; -}; - -class mipsmem; -class memdata : public Base { - public: - memdata(Uint32, mipsmem *); - virtual ~memdata(); - Uint32 getaddress(); - memdata * getmem(Uint32); - static memdata * getmem(Uint32, mipsmem *); - func_t * getfunc(); - refto_t * getrefto(); - reffrom_t * getreffrom(); - void setfunc(func_t *); - void setrefto(refto_t *); - void setreffrom(reffrom_t *); - private: - void checkdestroy(); - Uint32 address; - mipsmem * mm; - func_t * func; - refto_t * refto; - reffrom_t * reffrom; -}; - -class mipsmem : public Base { - public: - mipsmem(); - Uint8 Read8(Uint32 addr); - Uint16 Read16(Uint32 addr); - Uint32 Read32(Uint32 addr); - void Write8(Uint32 addr, Uint8); - void Write16(Uint32 addr, Uint16); - void Write32(Uint32 addr, Uint32); - void unpatch8(Uint32 addr); - void unpatch16(Uint32 addr); - void unpatch32(Uint32 addr); - bool IsPatched(Uint32 addr); - void LoadPSYQ(Handle *); - void SavePSYQ(Handle *); - bool GetTag(Uint32 addr, char tag); - void SetTag(Uint32 addr, char tag, bool); - memdata * GetDatas(Uint32 addr); - void SetDatas(Uint32 addr, memdata * p); - Uint32 GetPC(); - Uint32 GetLower(); - Uint32 GetUpper(); - private: - void patch(Uint32, int); - void unpatch(Uint32, int); - Uint8 psyqhead[0x800]; - Uint8 plainmemory[PSXMEM]; - Uint8 patches[PSXMEM]; - Uint8 patchesmap[PSXMEM / 8]; - Uint8 tags[PSXMEM]; - memdata * datas[PSXMEM]; - Uint32 paddr, psize, startpc; - - struct psyq { - Uint8 id[8]; - Uint32 text, data, pc0, gp0, t_addr, t_size; - Uint32 d_addr, d_size, b_addr, b_size, s_addr, s_size; - Uint32 sp, fp, gp, ra, s0; - }; -}; - -#endif +#ifndef __MIPSMEM_H__
+#define __MIPSMEM_H__
+#define PSXMEM 0x200000
+
+#include <Exceptions.h>
+#include <Handle.h>
+
+enum tags_t {
+ CODE,
+ DATA,
+ STOP,
+ INVALID,
+};
+
+class memdata;
+
+class func_t : public Base {
+ public:
+ func_t();
+ virtual ~func_t();
+ Uint32 endpc;
+ Uint8 stacksize;
+};
+
+class refto_t;
+class reffrom_t : public Base {
+ public:
+ reffrom_t(refto_t *, memdata *);
+ virtual ~reffrom_t();
+ memdata * getref();
+ memdata * getmem();
+ reffrom_t * getnext();
+ private:
+ refto_t * refto;
+ reffrom_t * next, * prev;
+ memdata * header;
+};
+
+class refto_t : public Base {
+ public:
+ refto_t(Uint32, memdata *);
+ virtual ~refto_t();
+ memdata * getref();
+ memdata * getmem();
+ private:
+ reffrom_t * reffrom;
+ memdata * mem;
+};
+
+class mipsmem;
+class memdata : public Base {
+ public:
+ memdata(Uint32, mipsmem *);
+ virtual ~memdata();
+ Uint32 getaddress();
+ memdata * getmem(Uint32);
+ static memdata * getmem(Uint32, mipsmem *);
+ func_t * getfunc();
+ refto_t * getrefto();
+ reffrom_t * getreffrom();
+ void setfunc(func_t *);
+ void setrefto(refto_t *);
+ void setreffrom(reffrom_t *);
+ private:
+ void checkdestroy();
+ Uint32 address;
+ mipsmem * mm;
+ func_t * func;
+ refto_t * refto;
+ reffrom_t * reffrom;
+};
+
+class mipsmem : public Base {
+ public:
+ mipsmem();
+ Uint8 Read8(Uint32 addr);
+ Uint16 Read16(Uint32 addr);
+ Uint32 Read32(Uint32 addr);
+ void Write8(Uint32 addr, Uint8);
+ void Write16(Uint32 addr, Uint16);
+ void Write32(Uint32 addr, Uint32);
+ void unpatch8(Uint32 addr);
+ void unpatch16(Uint32 addr);
+ void unpatch32(Uint32 addr);
+ bool IsPatched(Uint32 addr);
+ void LoadPSYQ(Handle *);
+ void SavePSYQ(Handle *);
+ bool GetTag(Uint32 addr, char tag);
+ void SetTag(Uint32 addr, char tag, bool);
+ memdata * GetDatas(Uint32 addr);
+ void SetDatas(Uint32 addr, memdata * p);
+ Uint32 GetPC();
+ Uint32 GetLower();
+ Uint32 GetUpper();
+ private:
+ void patch(Uint32, int);
+ void unpatch(Uint32, int);
+ Uint8 psyqhead[0x800];
+ Uint8 plainmemory[PSXMEM];
+ Uint8 patches[PSXMEM];
+ Uint8 patchesmap[PSXMEM / 8];
+ Uint8 tags[PSXMEM];
+ memdata * datas[PSXMEM];
+ Uint32 paddr, psize, startpc;
+
+ struct psyq {
+ Uint8 id[8];
+ Uint32 text, data, pc0, gp0, t_addr, t_size;
+ Uint32 d_addr, d_size, b_addr, b_size, s_addr, s_size;
+ Uint32 sp, fp, gp, ra, s0;
+ };
+};
+
+#endif
diff --git a/includes/mipsobj.h b/includes/mipsobj.h index 18ac504..8ed68d8 100644 --- a/includes/mipsobj.h +++ b/includes/mipsobj.h @@ -1,74 +1,74 @@ -#ifndef __MIPSOBJ_H__ -#define __MIPSOBJ_H__ - -#include <map> -#include <Exceptions.h> -#include <Handle.h> - -enum mips_reloc_t { - R_MIPS_26, - R_MIPS_32, - R_MIPS_HI16, - R_MIPS_LO16, -}; - -enum symbol_type_t { - LOCAL, - GLOBAL, - EXTERN, -}; - -enum section_type_t { - TEXT, - DATA, - BSS, -}; - -struct reloc_t { - String symbol; - int type; - Uint32 offset; -}; - -struct symbol_t { - String name; - String section; - int type; - Uint32 offset; -}; - -class section : public Base { - public: - section(const String &, int); - section(); - virtual ~section(); - void setname(const String &); - void settype(int); - void putdatas(const Uint8 *, int); - int gettype(); - int getsize(); - const Uint8 * getdatas(); - void putreloc(const String &, int, Uint32); - void putreloc(const struct reloc_t &); - std::vector<struct reloc_t> relocs; - private: - String name; - int type; - Uint8 * datas; - int length; -}; - -class mipsobj : public Base { - public: - mipsobj(); - virtual ~mipsobj(); - std::map<String, section> sections; - std::map<String, symbol_t> symbols; - void loadELF(Handle *) throw (GeneralException); - void loadOBJ(Handle *) throw (GeneralException); - void loadLIB(Handle *, const String &) throw (GeneralException); - private: - bool loaded; -}; - -#endif +#ifndef __MIPSOBJ_H__
+#define __MIPSOBJ_H__
+
+#include <map>
+#include <Exceptions.h>
+#include <Handle.h>
+
+enum mips_reloc_t {
+ R_MIPS_26,
+ R_MIPS_32,
+ R_MIPS_HI16,
+ R_MIPS_LO16,
+};
+
+enum symbol_type_t {
+ LOCAL,
+ GLOBAL,
+ EXTERN,
+};
+
+enum section_type_t {
+ TEXT,
+ DATA,
+ BSS,
+};
+
+struct reloc_t {
+ String symbol;
+ int type;
+ Uint32 offset;
+};
+
+struct symbol_t {
+ String name;
+ String section;
+ int type;
+ Uint32 offset;
+};
+
+class section : public Base {
+ public:
+ section(const String &, int);
+ section();
+ virtual ~section();
+ void setname(const String &);
+ void settype(int);
+ void putdatas(const Uint8 *, int);
+ int gettype();
+ int getsize();
+ const Uint8 * getdatas();
+ void putreloc(const String &, int, Uint32);
+ void putreloc(const struct reloc_t &);
+ std::vector<struct reloc_t> relocs;
+ private:
+ String name;
+ int type;
+ Uint8 * datas;
+ int length;
+};
+
+class mipsobj : public Base {
+ public:
+ mipsobj();
+ virtual ~mipsobj();
+ std::map<String, section> sections;
+ std::map<String, symbol_t> symbols;
+ void loadELF(Handle *) throw (GeneralException);
+ void loadOBJ(Handle *) throw (GeneralException);
+ void loadLIB(Handle *, const String &) throw (GeneralException);
+ private:
+ bool loaded;
+};
+
+#endif
diff --git a/includes/yazedc.h b/includes/yazedc.h index 296c532..8227e87 100644 --- a/includes/yazedc.h +++ b/includes/yazedc.h @@ -1,110 +1,110 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 1998 Heiko Eissfeldt - * portions used& Chris Smith - * First modified by Yazoo, then by - * Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: yazedc.h,v 1.4 2003-12-04 01:47:37 pixel Exp $ */ - -#ifndef __YAZEDC_H__ -#define __YAZEDC_H__ - -#include "Exceptions.h" - -#define RS_L12_BITS 8 - -/* audio sector definitions for CIRC */ -#define FRAMES_PER_SECTOR 98 -/* user data bytes per frame */ -#define L1_RAW 24 -/* parity bytes with 8 bit */ -#define L1_Q 4 -#define L1_P 4 - -/* data sector definitions for RSPC */ -/* user data bytes per frame */ -#define L2_RAW (1024*2) -/* parity bytes for 16 bit units */ -#define L2_Q (26*2*2) -#define L2_P (43*2*2) - -/* known sector types */ -#define MODE_0 0 -#define MODE_1 1 -#define MODE_2 2 -#define MODE_2_FORM_1 3 -#define MODE_2_FORM_2 4 - -/* r-w sub channel definitions */ -#define RS_SUB_RW_BITS 6 - -#define PACKETS_PER_SUBCHANNELFRAME 4 -#define LSUB_RAW 18 -#define LSUB_QRAW 2 -/* 6 bit */ -#define LSUB_Q 2 -#define LSUB_P 4 - -class yazedc : public Base { - - public: - yazedc(); - -/* set one of the MODE_* constants for subsequent data sector formatting */ - int set_sector_type(int st); -/* get the current sector type setting for data sector formatting */ - int get_sector_type(void); - -/* data sector layer 2 Reed-Solomon Product Code encoder */ -/* encode the given data portion depending on sector type (see - get/set_sector_type() functions). Use the given address for the header. - The returned data is __unscrambled__ and not in F2-frame format (for that - see function scramble_L2()). - Supported sector types: - MODE_0: a 12-byte sync field, a header and 2336 zeros are returned. - MODE_1: the user data portion (2048 bytes) has to be given - at offset 16 in the inout array. - Sync-, header-, edc-, spare-, p- and q- fields will be added. - MODE_2: the user data portion (2336 bytes) has to be given - at offset 16 in the inout array. - Sync- and header- fields will be added. - MODE_2_FORM_1: the user data portion (8 bytes subheader followed - by 2048 bytes data) has to be given at offset 16 - in the inout array. - Sync-, header-, edc-, p- and q- fields will be added. - MODE_2_FORM_2: the user data portion (8 bytes subheader followed - by 2324 bytes data) has to be given at offset 16 - in the inout array. - Sync-, header- and edc- fields will be added. -*/ - int do_encode_L2(unsigned char *inout, int sectortype, unsigned address); - -/* generates f2 frames from otherwise fully formatted sectors (generated by - do_encode_L2()). */ - int scramble_L2(unsigned char *inout); - - unsigned char minute, second, frame; - - private: - int sectortype; - int build_address(unsigned char inout[], int sectortype, unsigned address); - -}; - -#endif +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 1998 Heiko Eissfeldt
+ * portions used& Chris Smith
+ * First modified by Yazoo, then by
+ * Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: yazedc.h,v 1.5 2004-11-27 21:44:46 pixel Exp $ */
+
+#ifndef __YAZEDC_H__
+#define __YAZEDC_H__
+
+#include "Exceptions.h"
+
+#define RS_L12_BITS 8
+
+/* audio sector definitions for CIRC */
+#define FRAMES_PER_SECTOR 98
+/* user data bytes per frame */
+#define L1_RAW 24
+/* parity bytes with 8 bit */
+#define L1_Q 4
+#define L1_P 4
+
+/* data sector definitions for RSPC */
+/* user data bytes per frame */
+#define L2_RAW (1024*2)
+/* parity bytes for 16 bit units */
+#define L2_Q (26*2*2)
+#define L2_P (43*2*2)
+
+/* known sector types */
+#define MODE_0 0
+#define MODE_1 1
+#define MODE_2 2
+#define MODE_2_FORM_1 3
+#define MODE_2_FORM_2 4
+
+/* r-w sub channel definitions */
+#define RS_SUB_RW_BITS 6
+
+#define PACKETS_PER_SUBCHANNELFRAME 4
+#define LSUB_RAW 18
+#define LSUB_QRAW 2
+/* 6 bit */
+#define LSUB_Q 2
+#define LSUB_P 4
+
+class yazedc : public Base {
+
+ public:
+ yazedc();
+
+/* set one of the MODE_* constants for subsequent data sector formatting */
+ int set_sector_type(int st);
+/* get the current sector type setting for data sector formatting */
+ int get_sector_type(void);
+
+/* data sector layer 2 Reed-Solomon Product Code encoder */
+/* encode the given data portion depending on sector type (see
+ get/set_sector_type() functions). Use the given address for the header.
+ The returned data is __unscrambled__ and not in F2-frame format (for that
+ see function scramble_L2()).
+ Supported sector types:
+ MODE_0: a 12-byte sync field, a header and 2336 zeros are returned.
+ MODE_1: the user data portion (2048 bytes) has to be given
+ at offset 16 in the inout array.
+ Sync-, header-, edc-, spare-, p- and q- fields will be added.
+ MODE_2: the user data portion (2336 bytes) has to be given
+ at offset 16 in the inout array.
+ Sync- and header- fields will be added.
+ MODE_2_FORM_1: the user data portion (8 bytes subheader followed
+ by 2048 bytes data) has to be given at offset 16
+ in the inout array.
+ Sync-, header-, edc-, p- and q- fields will be added.
+ MODE_2_FORM_2: the user data portion (8 bytes subheader followed
+ by 2324 bytes data) has to be given at offset 16
+ in the inout array.
+ Sync-, header- and edc- fields will be added.
+*/
+ int do_encode_L2(unsigned char *inout, int sectortype, unsigned address);
+
+/* generates f2 frames from otherwise fully formatted sectors (generated by
+ do_encode_L2()). */
+ int scramble_L2(unsigned char *inout);
+
+ unsigned char minute, second, frame;
+
+ private:
+ int sectortype;
+ int build_address(unsigned char inout[], int sectortype, unsigned address);
+
+};
+
+#endif
diff --git a/info-cd.cpp b/info-cd.cpp index 2ac872f..29d0bc8 100644 --- a/info-cd.cpp +++ b/info-cd.cpp @@ -1,40 +1,40 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <string.h> -#include <stdio.h> -#include "cdutils.h" - -int main(int argc, char ** argv) { - int h; - struct DirEntry dir; - - h = open(argv[1], O_RDONLY); - - show_iso_infos(h); - show_pt_infos(h); - show_head_entry(); - show_dir(h, &rootDir); - show_head_entry(); - dir = find_path(h, strdup("/BATTLE")); - show_dir(h, &dir); -} +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+#include "cdutils.h"
+
+int main(int argc, char ** argv) {
+ int h;
+ struct DirEntry dir;
+
+ h = open(argv[1], O_RDONLY);
+
+ show_iso_infos(h);
+ show_pt_infos(h);
+ show_head_entry();
+ show_dir(h, &rootDir);
+ show_head_entry();
+ dir = find_path(h, strdup("/BATTLE"));
+ show_dir(h, &dir);
+}
diff --git a/lib/cdabstract.cpp b/lib/cdabstract.cpp index ff438c4..ceb5f70 100644 --- a/lib/cdabstract.cpp +++ b/lib/cdabstract.cpp @@ -1,192 +1,192 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002-2003 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: cdabstract.cpp,v 1.7 2003-12-11 16:53:43 pixel Exp $ */ - -#include "cdabstract.h" -#include "Input.h" -#include "cdreader.h" - -#ifdef __linux__ -#include <unistd.h> -#include <sys/ioctl.h> -#include <fcntl.h> -#include <linux/cdrom.h> -#endif - -#if defined (_MSC_VER) || defined (__MINGW32__) -#include <windowsx.h> -#endif - -Handle * cdabstract::open_cd(const String & nom) { - if (nom.extract(0, 2).toupper() == "CD:") { - return new cdreader(nom.extract(3)); - } else { - return new Input(nom); - } -} - -bool cdabstract::canprobe() { -#ifdef __linux__ - return true; -#endif -#ifdef _WIN32 - OSVERSIONINFO ov; - memset(&ov, 0, sizeof(OSVERSIONINFO)); - ov.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - - GetVersionEx(&ov); - - return ((ov.dwPlatformId == VER_PLATFORM_WIN32_NT) && (ov.dwMajorVersion > 4)); -#endif - return false; -} - -std::vector<String> cdabstract::probe() throw (GeneralException) { - int i; - std::vector<String> r; - String probed; - - if (!canprobe()) - throw GeneralException("Can't probe CD devices on this platform."); - -#ifdef __linux__ - if (subprobe(probed = "/dev/cdrom")) - r.push_back(probed); - - for (i = 0; i < 63; i++) { - probed.set("/dev/cdroms/cdrom%i", i); - if (subprobe(probed)) - r.push_back(probed); - } - for (i = 'a'; i <= 'z'; i++) { - probed.set("/dev/hd%c", i); - if (subprobe(probed)) - r.push_back(probed); - } -#endif - -#ifdef _WIN32 - for (i = 'A'; i <= 'Z'; i++) { - probed.set("%c:\\", i); - if (subprobe(probed)) - r.push_back(probed); - } -#endif - - return r; -} - -#ifdef _WIN32 -HANDLE cdabstract::OpenIOCTLFile(char cLetter) { - HANDLE hF; - char szFName[16]; - OSVERSIONINFO ov; - DWORD dwFlags; - DWORD dwIOCTLAttr = 0; - - memset(&ov, 0, sizeof(OSVERSIONINFO)); - ov.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&ov); - - if((ov.dwPlatformId == VER_PLATFORM_WIN32_NT) && (ov.dwMajorVersion > 4)) - dwFlags = GENERIC_READ | GENERIC_WRITE; // add gen write on W2k/XP - else dwFlags = GENERIC_READ; - - sprintf(szFName, "\\\\.\\%c:", cLetter); - - hF = CreateFile(szFName, dwFlags, FILE_SHARE_READ, // open drive - NULL, OPEN_EXISTING, dwIOCTLAttr, NULL); - - if (hF == INVALID_HANDLE_VALUE) { // mmm... no success? - dwFlags ^= GENERIC_WRITE; // -> try write toggle - hF = CreateFile(szFName, dwFlags, FILE_SHARE_READ, // -> open drive again - NULL, OPEN_EXISTING, dwIOCTLAttr, NULL); - if (hF == INVALID_HANDLE_VALUE) - return NULL; - } - return hF; -} - -typedef struct { - ULONG Length; - UCHAR PortNumber; - UCHAR PathId; - UCHAR TargetId; - UCHAR Lun; -} SCSI_ADDRESS, *PSCSI_ADDRESS; - -void cdabstract::GetIOCTLAdapter(HANDLE hF, int * iDA, int * iDT, int * iDL) { - char szBuf[1024]; - PSCSI_ADDRESS pSA; - DWORD dwRet; - - *iDA = *iDT = *iDL = -1; - - if (hF == NULL) - return; - - memset(szBuf,0,1024); - - pSA = (PSCSI_ADDRESS)szBuf; - pSA->Length = sizeof(SCSI_ADDRESS); - - if (!DeviceIoControl(hF, IOCTL_SCSI_GET_ADDRESS, NULL, 0, pSA, - sizeof(SCSI_ADDRESS), &dwRet, NULL)) - return; - - *iDA = pSA->PortNumber; - *iDT = pSA->TargetId; - *iDL = pSA->Lun; -} -#endif - -bool cdabstract::subprobe(String & probed) { -#ifdef __linux__ - int h, caps; - - h = open(probed.to_charp(), O_RDONLY | O_NONBLOCK); - - if (ioctl(h, CDROM_GET_CAPABILITY, &caps) < 0) { - close(h); - return false; - } else { - close(h); - return true; - } -#endif - -#ifdef _WIN32 - int iDA, iDT, iDL; - char letter[4]; - HANDLE h; - - if (GetDriveType(probed.to_charp()) == DRIVE_CDROM) { - h = OpenIOCTLFile(probed[0]); - GetIOCTLAdapter(h, &iDA, &iDT, &iDL); - CloseHandle(h); - if ((iDA != -1) && (iDT != -1) && (iDL != -1)) { - probed += String().set(" [%i:%i:%i]", iDA, iDT, iDL); - return true; - } - } -#endif - - return false; -} +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: cdabstract.cpp,v 1.8 2004-11-27 21:44:48 pixel Exp $ */
+
+#include "cdabstract.h"
+#include "Input.h"
+#include "cdreader.h"
+
+#ifdef __linux__
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <linux/cdrom.h>
+#endif
+
+#if defined (_MSC_VER) || defined (__MINGW32__)
+#include <windowsx.h>
+#endif
+
+Handle * cdabstract::open_cd(const String & nom) {
+ if (nom.extract(0, 2).toupper() == "CD:") {
+ return new cdreader(nom.extract(3));
+ } else {
+ return new Input(nom);
+ }
+}
+
+bool cdabstract::canprobe() {
+#ifdef __linux__
+ return true;
+#endif
+#ifdef _WIN32
+ OSVERSIONINFO ov;
+ memset(&ov, 0, sizeof(OSVERSIONINFO));
+ ov.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ GetVersionEx(&ov);
+
+ return ((ov.dwPlatformId == VER_PLATFORM_WIN32_NT) && (ov.dwMajorVersion > 4));
+#endif
+ return false;
+}
+
+std::vector<String> cdabstract::probe() throw (GeneralException) {
+ int i;
+ std::vector<String> r;
+ String probed;
+
+ if (!canprobe())
+ throw GeneralException("Can't probe CD devices on this platform.");
+
+#ifdef __linux__
+ if (subprobe(probed = "/dev/cdrom"))
+ r.push_back(probed);
+
+ for (i = 0; i < 63; i++) {
+ probed.set("/dev/cdroms/cdrom%i", i);
+ if (subprobe(probed))
+ r.push_back(probed);
+ }
+ for (i = 'a'; i <= 'z'; i++) {
+ probed.set("/dev/hd%c", i);
+ if (subprobe(probed))
+ r.push_back(probed);
+ }
+#endif
+
+#ifdef _WIN32
+ for (i = 'A'; i <= 'Z'; i++) {
+ probed.set("%c:\\", i);
+ if (subprobe(probed))
+ r.push_back(probed);
+ }
+#endif
+
+ return r;
+}
+
+#ifdef _WIN32
+HANDLE cdabstract::OpenIOCTLFile(char cLetter) {
+ HANDLE hF;
+ char szFName[16];
+ OSVERSIONINFO ov;
+ DWORD dwFlags;
+ DWORD dwIOCTLAttr = 0;
+
+ memset(&ov, 0, sizeof(OSVERSIONINFO));
+ ov.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&ov);
+
+ if((ov.dwPlatformId == VER_PLATFORM_WIN32_NT) && (ov.dwMajorVersion > 4))
+ dwFlags = GENERIC_READ | GENERIC_WRITE; // add gen write on W2k/XP
+ else dwFlags = GENERIC_READ;
+
+ sprintf(szFName, "\\\\.\\%c:", cLetter);
+
+ hF = CreateFile(szFName, dwFlags, FILE_SHARE_READ, // open drive
+ NULL, OPEN_EXISTING, dwIOCTLAttr, NULL);
+
+ if (hF == INVALID_HANDLE_VALUE) { // mmm... no success?
+ dwFlags ^= GENERIC_WRITE; // -> try write toggle
+ hF = CreateFile(szFName, dwFlags, FILE_SHARE_READ, // -> open drive again
+ NULL, OPEN_EXISTING, dwIOCTLAttr, NULL);
+ if (hF == INVALID_HANDLE_VALUE)
+ return NULL;
+ }
+ return hF;
+}
+
+typedef struct {
+ ULONG Length;
+ UCHAR PortNumber;
+ UCHAR PathId;
+ UCHAR TargetId;
+ UCHAR Lun;
+} SCSI_ADDRESS, *PSCSI_ADDRESS;
+
+void cdabstract::GetIOCTLAdapter(HANDLE hF, int * iDA, int * iDT, int * iDL) {
+ char szBuf[1024];
+ PSCSI_ADDRESS pSA;
+ DWORD dwRet;
+
+ *iDA = *iDT = *iDL = -1;
+
+ if (hF == NULL)
+ return;
+
+ memset(szBuf,0,1024);
+
+ pSA = (PSCSI_ADDRESS)szBuf;
+ pSA->Length = sizeof(SCSI_ADDRESS);
+
+ if (!DeviceIoControl(hF, IOCTL_SCSI_GET_ADDRESS, NULL, 0, pSA,
+ sizeof(SCSI_ADDRESS), &dwRet, NULL))
+ return;
+
+ *iDA = pSA->PortNumber;
+ *iDT = pSA->TargetId;
+ *iDL = pSA->Lun;
+}
+#endif
+
+bool cdabstract::subprobe(String & probed) {
+#ifdef __linux__
+ int h, caps;
+
+ h = open(probed.to_charp(), O_RDONLY | O_NONBLOCK);
+
+ if (ioctl(h, CDROM_GET_CAPABILITY, &caps) < 0) {
+ close(h);
+ return false;
+ } else {
+ close(h);
+ return true;
+ }
+#endif
+
+#ifdef _WIN32
+ int iDA, iDT, iDL;
+ char letter[4];
+ HANDLE h;
+
+ if (GetDriveType(probed.to_charp()) == DRIVE_CDROM) {
+ h = OpenIOCTLFile(probed[0]);
+ GetIOCTLAdapter(h, &iDA, &iDT, &iDL);
+ CloseHandle(h);
+ if ((iDA != -1) && (iDT != -1) && (iDL != -1)) {
+ probed += String().set(" [%i:%i:%i]", iDA, iDT, iDL);
+ return true;
+ }
+ }
+#endif
+
+ return false;
+}
diff --git a/lib/cdreader.cpp b/lib/cdreader.cpp index 83bd1b3..7777c4d 100644 --- a/lib/cdreader.cpp +++ b/lib/cdreader.cpp @@ -1,334 +1,334 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002-2003 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: cdreader.cpp,v 1.19 2003-12-26 19:05:31 pixel Exp $ */ - -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include "cdreader.h" -#include "Exceptions.h" -#include "generic.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#else -#define _(x) x -#endif -#include "cdabstract.h" - -#define nsectorsarow 1 -#define cachesize 2048 - -bool cdreader::CanWrite() const { - return 0; -} - -bool cdreader::CanRead() const { - return 1; -} - -bool cdreader::CanSeek() const { - return 1; -} - -String cdreader::GetName() const { - return n + " raw reading"; -} - -ssize_t cdreader::GetSize() const { - return -1; -} - -off_t cdreader::seek(off_t offset, int whence) throw (GeneralException) { - switch (whence) { - case SEEK_SET: - itell = offset; - break; - case SEEK_CUR: - itell += offset; - break; - case SEEK_END: - throw GeneralException("Can not yet seek from the end of a CD."); - } - return itell; -} - -ssize_t cdreader::read(void *buf, size_t count) throw (GeneralException) { - char sector[2352]; - size_t r = count; - - size_t remain = itell % 2352; - sectorseek(itell / 2352); - - while (count > 0) { - size_t n = MIN(2352 - remain, count); - fetchsector(sector); - bcopy(sector + remain, buf, n); - buf = ((char *) buf) + n; - itell += n; - count -= n; - remain = 0; - } - - return r; -} - -void cdreader::sectorseek(int sec) { - sector = sec; -} - -void cdreader::fetchsector(void * buf, int sec) { - if (sec >= 0) - sector = sec; - - if (sectors[sector]) { - actualize(sectors[sector]); - memcpy(buf, sectors[sector]->sector, 2352); - return; - } - - Byte buffers[2352 * nsectorsarow]; - - getsector(buffers, sec = sector, nsectorsarow); - - for (int i = nsectorsarow - 1; i >= 0; i--) { - introduce(buffers + i * 2352, sec + i); - } - - memcpy(buf, buffers, 2352); - - while (nsectors > cachesize) { - removetail(); - } -} - -cdreader::~cdreader() { - while (nsectors) { - removetail(); - } -} - -void cdreader::removetail() { - if (!tail) - return; - - sectors[tail->n] = 0; - - if (head == tail) { - free(tail); - head = tail = 0; - nsectors = 0; - } else { - cachedsector * p; - (p = tail->prev)->next = 0; - free(tail); - tail = p; - nsectors--; - } -} - -void cdreader::actualize(cachedsector * s) { - if (s == head) - return; - - if (s != tail) { - s->next->prev = s->prev; - } else { - tail = s->prev; - } - s->prev->next = s->next; - - head->prev = s; - s->prev = 0; - s->next = head; - head = s; -} - -void cdreader::introduce(Byte * datas, int n) { - cachedsector * s; - - s = (cachedsector *) malloc(sizeof(cachedsector)); - memcpy(s->sector, datas, 2352); - s->n = n; - - if (head) { - s->next = head; - head->prev = s; - head = s; - } else { - head = tail = s; - s->prev = s->next = 0; - } - sectors[n] = s; - - nsectors++; -} - -#ifdef __linux__ -#include <unistd.h> -#include <sys/ioctl.h> -#include <linux/cdrom.h> - -cdreader::cdreader(const String & no) throw (GeneralException) : - Handle(open(no.to_charp(), O_RDONLY)), n(no), sector(0) { - int i; - -#ifdef DEBUG - printm(M_INFO, "Opening cdrom device " + no + "\n"); -#endif - - if (GetHandle() < 0) { - throw IOGeneral(String(_("Error opening file ")) + no + _(" for reading: ") + strerror(errno)); - } - - struct stat s; - fstat(GetHandle(), &s); - - if (!S_ISBLK(s.st_mode)) { - throw GeneralException(no + " is not a block device."); - } - - for (i = 0; i < 400000; i++) { - sectors[i] = 0; - } - head = tail = 0; - nsectors = 0; -} - -cdreader::cdreader(const cdreader & inp) : Handle(inp), n(inp.n) { - int i; - - for (i = 0; i < 400000; i++) { - sectors[i] = 0; - } - head = tail = 0; - nsectors = 0; -} - -void cdreader::getsector(void *buf, int sec, int nb) throw (GeneralException) { - struct cdrom_msf * msf = (struct cdrom_msf *) buf; - if (sec >= 0) - sector = sec; - - sector += 150; - - msf->cdmsf_min0 = sector /CD_SECS /CD_FRAMES; - msf->cdmsf_sec0 = (sector /CD_FRAMES)%CD_SECS; - msf->cdmsf_frame0= sector %CD_FRAMES; - msf->cdmsf_min1 = (sector + nb)/CD_SECS /CD_FRAMES; - msf->cdmsf_sec1 = ((sector + nb)/CD_FRAMES)%CD_SECS; - msf->cdmsf_frame1= (sector + nb)%CD_FRAMES; - - sector -= 150; - - if (ioctl(GetHandle(), CDROMREADRAW, buf) < 0) { - throw GeneralException(String("unable to read cd sector ") + sector + ": " + strerror(errno)); - } - - sector += nb; -} -#endif - -#if defined (_MSC_VER) || defined (__MINGW32__) -cdreader::cdreader(const String & no) throw (GeneralException) : - Handle(-1), n(no), sector(0) { - if (!(hFile = cdabstract::OpenIOCTLFile(no[0]))) - throw GeneralException("Error opening device " + no); - for (int i = 0; i < 400000; i++) { - sectors[i] = 0; - } - head = tail = 0; - nsectors = 0; -} - -cdreader::cdreader(const cdreader & i) : Handle(i), n(i.n) { - hFile = i.hFile; - for (int x = 0; x < 400000; x++) { - sectors[x] = 0; - } - head = tail = 0; - nsectors = 0; -} - -void cdreader::close() throw (GeneralException) { - CloseHandle(hFile); -} - -typedef enum _TRACK_MODE_TYPE { - YellowMode2, - XAForm2, - CDDA -} TRACK_MODE_TYPE, *PTRACK_MODE_TYPE; - -typedef struct _RAW_READ_INFO { - LARGE_INTEGER DiskOffset; - ULONG SectorCount; - TRACK_MODE_TYPE TrackMode; -} RAW_READ_INFO, *PRAW_READ_INFO; - -void cdreader::getsector(void *buf, int sec, int nb) throw (GeneralException) { - RAW_READ_INFO rawIOCTL; - DWORD dwRet; - BOOL bStat; - bool done = false; - if (sec >= 0) - sector = sec; - - rawIOCTL.DiskOffset.QuadPart = sector * 2048; - rawIOCTL.SectorCount = nb; - rawIOCTL.TrackMode = YellowMode2; - - while (!done) { - SetLastError(0); - bStat = DeviceIoControl(hFile, IOCTL_CDROM_RAW_READ, - &rawIOCTL, sizeof(RAW_READ_INFO), - buf, 2352 * nb, &dwRet, NULL); - if (!bStat) { - DWORD dwErrCode = GetLastError(); - if (dwErrCode == ERROR_INVALID_FUNCTION) { - if (rawIOCTL.TrackMode == YellowMode2) { - rawIOCTL.TrackMode = XAForm2; - continue; - } - } - if (dwErrCode != ERROR_IO_PENDING) { - LPVOID lpMsgBuf; - if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpMsgBuf, 0, NULL )) - throw GeneralException("Gave up on reading CD: unknown error"); - String errmsg = (LPCTSTR) lpMsgBuf; - LocalFree(lpMsgBuf); - throw GeneralException("Gave up on reading CD: " + errmsg); - } - } else { - done = true; - } - } - - sector += nb; -} - -#endif +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: cdreader.cpp,v 1.20 2004-11-27 21:44:48 pixel Exp $ */
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include "cdreader.h"
+#include "Exceptions.h"
+#include "generic.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#else
+#define _(x) x
+#endif
+#include "cdabstract.h"
+
+#define nsectorsarow 1
+#define cachesize 2048
+
+bool cdreader::CanWrite() const {
+ return 0;
+}
+
+bool cdreader::CanRead() const {
+ return 1;
+}
+
+bool cdreader::CanSeek() const {
+ return 1;
+}
+
+String cdreader::GetName() const {
+ return n + " raw reading";
+}
+
+ssize_t cdreader::GetSize() const {
+ return -1;
+}
+
+off_t cdreader::seek(off_t offset, int whence) throw (GeneralException) {
+ switch (whence) {
+ case SEEK_SET:
+ itell = offset;
+ break;
+ case SEEK_CUR:
+ itell += offset;
+ break;
+ case SEEK_END:
+ throw GeneralException("Can not yet seek from the end of a CD.");
+ }
+ return itell;
+}
+
+ssize_t cdreader::read(void *buf, size_t count) throw (GeneralException) {
+ char sector[2352];
+ size_t r = count;
+
+ size_t remain = itell % 2352;
+ sectorseek(itell / 2352);
+
+ while (count > 0) {
+ size_t n = MIN(2352 - remain, count);
+ fetchsector(sector);
+ bcopy(sector + remain, buf, n);
+ buf = ((char *) buf) + n;
+ itell += n;
+ count -= n;
+ remain = 0;
+ }
+
+ return r;
+}
+
+void cdreader::sectorseek(int sec) {
+ sector = sec;
+}
+
+void cdreader::fetchsector(void * buf, int sec) {
+ if (sec >= 0)
+ sector = sec;
+
+ if (sectors[sector]) {
+ actualize(sectors[sector]);
+ memcpy(buf, sectors[sector]->sector, 2352);
+ return;
+ }
+
+ Byte buffers[2352 * nsectorsarow];
+
+ getsector(buffers, sec = sector, nsectorsarow);
+
+ for (int i = nsectorsarow - 1; i >= 0; i--) {
+ introduce(buffers + i * 2352, sec + i);
+ }
+
+ memcpy(buf, buffers, 2352);
+
+ while (nsectors > cachesize) {
+ removetail();
+ }
+}
+
+cdreader::~cdreader() {
+ while (nsectors) {
+ removetail();
+ }
+}
+
+void cdreader::removetail() {
+ if (!tail)
+ return;
+
+ sectors[tail->n] = 0;
+
+ if (head == tail) {
+ free(tail);
+ head = tail = 0;
+ nsectors = 0;
+ } else {
+ cachedsector * p;
+ (p = tail->prev)->next = 0;
+ free(tail);
+ tail = p;
+ nsectors--;
+ }
+}
+
+void cdreader::actualize(cachedsector * s) {
+ if (s == head)
+ return;
+
+ if (s != tail) {
+ s->next->prev = s->prev;
+ } else {
+ tail = s->prev;
+ }
+ s->prev->next = s->next;
+
+ head->prev = s;
+ s->prev = 0;
+ s->next = head;
+ head = s;
+}
+
+void cdreader::introduce(Byte * datas, int n) {
+ cachedsector * s;
+
+ s = (cachedsector *) malloc(sizeof(cachedsector));
+ memcpy(s->sector, datas, 2352);
+ s->n = n;
+
+ if (head) {
+ s->next = head;
+ head->prev = s;
+ head = s;
+ } else {
+ head = tail = s;
+ s->prev = s->next = 0;
+ }
+ sectors[n] = s;
+
+ nsectors++;
+}
+
+#ifdef __linux__
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <linux/cdrom.h>
+
+cdreader::cdreader(const String & no) throw (GeneralException) :
+ Handle(open(no.to_charp(), O_RDONLY)), n(no), sector(0) {
+ int i;
+
+#ifdef DEBUG
+ printm(M_INFO, "Opening cdrom device " + no + "\n");
+#endif
+
+ if (GetHandle() < 0) {
+ throw IOGeneral(String(_("Error opening file ")) + no + _(" for reading: ") + strerror(errno));
+ }
+
+ struct stat s;
+ fstat(GetHandle(), &s);
+
+ if (!S_ISBLK(s.st_mode)) {
+ throw GeneralException(no + " is not a block device.");
+ }
+
+ for (i = 0; i < 400000; i++) {
+ sectors[i] = 0;
+ }
+ head = tail = 0;
+ nsectors = 0;
+}
+
+cdreader::cdreader(const cdreader & inp) : Handle(inp), n(inp.n) {
+ int i;
+
+ for (i = 0; i < 400000; i++) {
+ sectors[i] = 0;
+ }
+ head = tail = 0;
+ nsectors = 0;
+}
+
+void cdreader::getsector(void *buf, int sec, int nb) throw (GeneralException) {
+ struct cdrom_msf * msf = (struct cdrom_msf *) buf;
+ if (sec >= 0)
+ sector = sec;
+
+ sector += 150;
+
+ msf->cdmsf_min0 = sector /CD_SECS /CD_FRAMES;
+ msf->cdmsf_sec0 = (sector /CD_FRAMES)%CD_SECS;
+ msf->cdmsf_frame0= sector %CD_FRAMES;
+ msf->cdmsf_min1 = (sector + nb)/CD_SECS /CD_FRAMES;
+ msf->cdmsf_sec1 = ((sector + nb)/CD_FRAMES)%CD_SECS;
+ msf->cdmsf_frame1= (sector + nb)%CD_FRAMES;
+
+ sector -= 150;
+
+ if (ioctl(GetHandle(), CDROMREADRAW, buf) < 0) {
+ throw GeneralException(String("unable to read cd sector ") + sector + ": " + strerror(errno));
+ }
+
+ sector += nb;
+}
+#endif
+
+#if defined (_MSC_VER) || defined (__MINGW32__)
+cdreader::cdreader(const String & no) throw (GeneralException) :
+ Handle(-1), n(no), sector(0) {
+ if (!(hFile = cdabstract::OpenIOCTLFile(no[0])))
+ throw GeneralException("Error opening device " + no);
+ for (int i = 0; i < 400000; i++) {
+ sectors[i] = 0;
+ }
+ head = tail = 0;
+ nsectors = 0;
+}
+
+cdreader::cdreader(const cdreader & i) : Handle(i), n(i.n) {
+ hFile = i.hFile;
+ for (int x = 0; x < 400000; x++) {
+ sectors[x] = 0;
+ }
+ head = tail = 0;
+ nsectors = 0;
+}
+
+void cdreader::close() throw (GeneralException) {
+ CloseHandle(hFile);
+}
+
+typedef enum _TRACK_MODE_TYPE {
+ YellowMode2,
+ XAForm2,
+ CDDA
+} TRACK_MODE_TYPE, *PTRACK_MODE_TYPE;
+
+typedef struct _RAW_READ_INFO {
+ LARGE_INTEGER DiskOffset;
+ ULONG SectorCount;
+ TRACK_MODE_TYPE TrackMode;
+} RAW_READ_INFO, *PRAW_READ_INFO;
+
+void cdreader::getsector(void *buf, int sec, int nb) throw (GeneralException) {
+ RAW_READ_INFO rawIOCTL;
+ DWORD dwRet;
+ BOOL bStat;
+ bool done = false;
+ if (sec >= 0)
+ sector = sec;
+
+ rawIOCTL.DiskOffset.QuadPart = sector * 2048;
+ rawIOCTL.SectorCount = nb;
+ rawIOCTL.TrackMode = YellowMode2;
+
+ while (!done) {
+ SetLastError(0);
+ bStat = DeviceIoControl(hFile, IOCTL_CDROM_RAW_READ,
+ &rawIOCTL, sizeof(RAW_READ_INFO),
+ buf, 2352 * nb, &dwRet, NULL);
+ if (!bStat) {
+ DWORD dwErrCode = GetLastError();
+ if (dwErrCode == ERROR_INVALID_FUNCTION) {
+ if (rawIOCTL.TrackMode == YellowMode2) {
+ rawIOCTL.TrackMode = XAForm2;
+ continue;
+ }
+ }
+ if (dwErrCode != ERROR_IO_PENDING) {
+ LPVOID lpMsgBuf;
+ if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPTSTR) &lpMsgBuf, 0, NULL ))
+ throw GeneralException("Gave up on reading CD: unknown error");
+ String errmsg = (LPCTSTR) lpMsgBuf;
+ LocalFree(lpMsgBuf);
+ throw GeneralException("Gave up on reading CD: " + errmsg);
+ }
+ } else {
+ done = true;
+ }
+ }
+
+ sector += nb;
+}
+
+#endif
diff --git a/lib/dteutils.cpp b/lib/dteutils.cpp index 85a7df2..42f36bf 100644 --- a/lib/dteutils.cpp +++ b/lib/dteutils.cpp @@ -1,319 +1,319 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include "generic.h" -#include "Handle.h" - -class thingtree : public Base { - public: - static void addstring(const String, long); - static long look(const String); - static void destroy(); - private: - thingtree(); - thingtree(char, bool, thingtree *, long); - ~thingtree(); - char thischar; - bool terminal; - thingtree * father, * child, * brother; - long thingentry; - static thingtree * root; -}; - -thingtree * thingtree::root = 0; - -thingtree::thingtree(char gchar, bool gterm, thingtree * gfather, long gthingentry) : thischar(gchar), terminal(gterm), thingentry(gthingentry) { - if (!gfather) { - if (!root) { - root = new thingtree(); - } - father = root; - } else { - father = gfather; - } - brother = father->child; - father->child = this; -} - -thingtree::thingtree() : thischar(0), terminal(false), father(0), child(0), brother(0) { } - -long thingtree::look(const String s) { - long currentthing = -1; - thingtree * ptr = root; - int i; - - if (!ptr) { - printm(M_ERROR, "Error: thingtree not initialised\n"); - exit(-1); - } - - for (i = 0; s[i]; i++) { -// printm(M_INFO, "Looking for '%c'\n", *p); - for (ptr = ptr->child; ptr; ptr = ptr->brother) { -// printm(M_INFO, "Looking in %p: %c\n", ptr, ptr->thischar); - if (ptr->thischar == s[i]) { - if (ptr->terminal) { - currentthing = ptr->thingentry; - } - break; - } - } - if (!ptr) { -// printm(M_INFO, "Not found.\n"); - break; - } - } - - if (currentthing == -1) { - printm(M_ERROR, "Error, can't find any entry for string '" + s + "'\n"); - } - - return currentthing; -} - -void thingtree::addstring(const String s, long thingentry) { - thingtree * ptr, * fptr; - int i; - - if (!root) { - root = new thingtree(); - } - -// printm(M_INFO, "Creating new thingtree entry: %li='%s'\n", thingentry, s); - - ptr = root; - for (i = 0; s[i]; i++) { - fptr = ptr; -// printm(M_INFO, "Finding entry for '%c'\n", *p); - for (ptr = ptr->child; ptr; ptr = ptr->brother) { -// printm(M_INFO, "Browsing childs: %p = %c\n", ptr, ptr->thischar); - if (ptr->thischar == s[i]) - break; - } - - if (!ptr) { -// printm(M_INFO, "Creating new branch for %c\n", *p); - ptr = new thingtree(s[i], s[i + 1] == 0, fptr, thingentry); -// printm(M_INFO, "Created branch %p\n", ptr); - } else { - if (s[i + 1] == 0) { - ptr->terminal = true; - ptr->thingentry = thingentry; - } - } - } -} - -void thingtree::destroy() { - delete root; - root = 0; -} - -thingtree::~thingtree() { - if (father->child == this) - father->child = brother; - - while (child) - delete child; -} - -String things[256]; - -char * dte_text; -char dte_flags[256 * 256]; -long dte_counters[256 * 256]; -long dte_entries[256]; -char alloweds[256]; -long dte_usage[256]; - -long dte_most; -long dte_counter; -long dte_text_size; -int dte_size; -long gain; -long nb_dte = 0; -long tnb_dte = 0; - -void dte_reset(void) { - memset(dte_counters, 0, 0x40000); - dte_most = 0; - dte_counter = 0; -} - -void build_dte(void) { - int i; - Uint16 t, t2; - unsigned short p = 0; - - for (i = 0; i < dte_text_size; i++) { - t = *((Uint16 *) (dte_text + i)); - t2 = *((Uint16 *) (dte_text + i + 1)); - if (t == p) { - p = 0; - continue; - } - p = t; - if (!dte_flags[t]) { -// if ((!dte_flags[t]) && (dte_flags[t2] != 3)) { - if ((dte_counters[t]++) == 0) { - nb_dte++; - } - if (dte_counters[t] > dte_counter) { - dte_most = t; - dte_counter = dte_counters[t]; - } -// } else if (dte_flags[t] == 3) { -// i++; - } - } -} - -void push_entry(long entry) { - int i; - char t[3], c1, c2; - t[2] = 0; - - c1 = dte_most & 0xff; - c2 = dte_most >> 8; - t[0] = things[c1][0]; - t[1] = things[c2][0]; - - for (i = 0; i < 256; i++) { - if (!dte_entries[i]) { - dte_entries[i] = entry; - things[i] = strdup(t); - thingtree::addstring(t, i); - break; - } - } -} - -void dte_compress() { - int i, j; - char c1, c2; - - for (i = 0; i < 256; i++) { - for (j = 0; j < 256; j++) { - dte_flags[i * 256 + j] = alloweds[i] ? alloweds[j] ? 0 : 1 : 1; - } - } - - gain = 0; - - printm(M_STATUS, "Going for it: dte_size = %i\n", dte_size); - for (i = 0; i < dte_size; i++) { - dte_reset(); - build_dte(); - if (!tnb_dte) - tnb_dte = nb_dte; - c1 = dte_most & 0xff; - c2 = dte_most >> 8; - c1 = things[c1][0]; - c2 = things[c2][0]; - printm(M_INFO, "Entry #%i, most count: %li, couple = 0x%04x = (%c %c)\n", i, dte_counter, (int) dte_most, c1, c2); - dte_flags[dte_most] = 3; - gain += dte_counter; - push_entry(dte_most); - } - - printm(M_STATUS, "Estimated gain: %li bytes, new file size = %li\n", gain, dte_text_size - gain); -} - -void read_thingy(Handle * f) { - String line, st, thing; - long code; - int i; - - dte_size = 0; - - for (i = 0; i < 256; i++) { - dte_entries[i] = -1; - } - - while (1) { - line = "0x"; - *f >> st; - if (st.strlen()) { - line += st.extract(0, 1); - code = line.to_int(); - thing = st.extract(3); - switch (thing.strlen()) { - case 0: - dte_size++; - dte_entries[code] = 0; - break; - case 1: - alloweds[code] = 1; - default: - things[code] = thing; - thingtree::addstring(thing, code); - } - } - } -} - -void read_thingy_file(Handle * f) { - String line, trans; - long code; - int ptr = 0, i, c; - - for (i = 0; i < 256; i++) { - dte_usage[i] = 0; - } - - while (1) { - *f >> line; - if (!line.strlen()) - continue; - i = 0; - while (line[i]) { - if (line[i] == '<') { - if ((c = line.strchr('>', i)) < 0) { - printm(M_ERROR, "Error in file: '<' not closed.\n"); - exit(-1); - } - i++; - if (c == 2) { - trans = "0x" + line.extract(i, 2); - code = line.to_int(); - dte_text[ptr++] = code; - printm(M_BARE, "0x%02x-", code); - } else { - printm(M_BARE, "Unknow " + trans.extract(2) + "-"); - } - i += c; - } else { - if ((code = thingtree::look(line.extract(i))) == -1) - exit(-1); - dte_text[ptr++] = code; - i += things[code].strlen(); - printm(M_BARE, things[code] + "-"); - dte_usage[code]++; - } - } - printm(M_BARE, "\n"); - } - - dte_text[ptr] = dte_text[ptr + 1] = dte_text[ptr + 2] = dte_text[ptr + 3] = 0; - dte_text_size = ptr; -} +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include "generic.h"
+#include "Handle.h"
+
+class thingtree : public Base {
+ public:
+ static void addstring(const String, long);
+ static long look(const String);
+ static void destroy();
+ private:
+ thingtree();
+ thingtree(char, bool, thingtree *, long);
+ ~thingtree();
+ char thischar;
+ bool terminal;
+ thingtree * father, * child, * brother;
+ long thingentry;
+ static thingtree * root;
+};
+
+thingtree * thingtree::root = 0;
+
+thingtree::thingtree(char gchar, bool gterm, thingtree * gfather, long gthingentry) : thischar(gchar), terminal(gterm), thingentry(gthingentry) {
+ if (!gfather) {
+ if (!root) {
+ root = new thingtree();
+ }
+ father = root;
+ } else {
+ father = gfather;
+ }
+ brother = father->child;
+ father->child = this;
+}
+
+thingtree::thingtree() : thischar(0), terminal(false), father(0), child(0), brother(0) { }
+
+long thingtree::look(const String s) {
+ long currentthing = -1;
+ thingtree * ptr = root;
+ int i;
+
+ if (!ptr) {
+ printm(M_ERROR, "Error: thingtree not initialised\n");
+ exit(-1);
+ }
+
+ for (i = 0; s[i]; i++) {
+// printm(M_INFO, "Looking for '%c'\n", *p);
+ for (ptr = ptr->child; ptr; ptr = ptr->brother) {
+// printm(M_INFO, "Looking in %p: %c\n", ptr, ptr->thischar);
+ if (ptr->thischar == s[i]) {
+ if (ptr->terminal) {
+ currentthing = ptr->thingentry;
+ }
+ break;
+ }
+ }
+ if (!ptr) {
+// printm(M_INFO, "Not found.\n");
+ break;
+ }
+ }
+
+ if (currentthing == -1) {
+ printm(M_ERROR, "Error, can't find any entry for string '" + s + "'\n");
+ }
+
+ return currentthing;
+}
+
+void thingtree::addstring(const String s, long thingentry) {
+ thingtree * ptr, * fptr;
+ int i;
+
+ if (!root) {
+ root = new thingtree();
+ }
+
+// printm(M_INFO, "Creating new thingtree entry: %li='%s'\n", thingentry, s);
+
+ ptr = root;
+ for (i = 0; s[i]; i++) {
+ fptr = ptr;
+// printm(M_INFO, "Finding entry for '%c'\n", *p);
+ for (ptr = ptr->child; ptr; ptr = ptr->brother) {
+// printm(M_INFO, "Browsing childs: %p = %c\n", ptr, ptr->thischar);
+ if (ptr->thischar == s[i])
+ break;
+ }
+
+ if (!ptr) {
+// printm(M_INFO, "Creating new branch for %c\n", *p);
+ ptr = new thingtree(s[i], s[i + 1] == 0, fptr, thingentry);
+// printm(M_INFO, "Created branch %p\n", ptr);
+ } else {
+ if (s[i + 1] == 0) {
+ ptr->terminal = true;
+ ptr->thingentry = thingentry;
+ }
+ }
+ }
+}
+
+void thingtree::destroy() {
+ delete root;
+ root = 0;
+}
+
+thingtree::~thingtree() {
+ if (father->child == this)
+ father->child = brother;
+
+ while (child)
+ delete child;
+}
+
+String things[256];
+
+char * dte_text;
+char dte_flags[256 * 256];
+long dte_counters[256 * 256];
+long dte_entries[256];
+char alloweds[256];
+long dte_usage[256];
+
+long dte_most;
+long dte_counter;
+long dte_text_size;
+int dte_size;
+long gain;
+long nb_dte = 0;
+long tnb_dte = 0;
+
+void dte_reset(void) {
+ memset(dte_counters, 0, 0x40000);
+ dte_most = 0;
+ dte_counter = 0;
+}
+
+void build_dte(void) {
+ int i;
+ Uint16 t, t2;
+ unsigned short p = 0;
+
+ for (i = 0; i < dte_text_size; i++) {
+ t = *((Uint16 *) (dte_text + i));
+ t2 = *((Uint16 *) (dte_text + i + 1));
+ if (t == p) {
+ p = 0;
+ continue;
+ }
+ p = t;
+ if (!dte_flags[t]) {
+// if ((!dte_flags[t]) && (dte_flags[t2] != 3)) {
+ if ((dte_counters[t]++) == 0) {
+ nb_dte++;
+ }
+ if (dte_counters[t] > dte_counter) {
+ dte_most = t;
+ dte_counter = dte_counters[t];
+ }
+// } else if (dte_flags[t] == 3) {
+// i++;
+ }
+ }
+}
+
+void push_entry(long entry) {
+ int i;
+ char t[3], c1, c2;
+ t[2] = 0;
+
+ c1 = dte_most & 0xff;
+ c2 = dte_most >> 8;
+ t[0] = things[c1][0];
+ t[1] = things[c2][0];
+
+ for (i = 0; i < 256; i++) {
+ if (!dte_entries[i]) {
+ dte_entries[i] = entry;
+ things[i] = strdup(t);
+ thingtree::addstring(t, i);
+ break;
+ }
+ }
+}
+
+void dte_compress() {
+ int i, j;
+ char c1, c2;
+
+ for (i = 0; i < 256; i++) {
+ for (j = 0; j < 256; j++) {
+ dte_flags[i * 256 + j] = alloweds[i] ? alloweds[j] ? 0 : 1 : 1;
+ }
+ }
+
+ gain = 0;
+
+ printm(M_STATUS, "Going for it: dte_size = %i\n", dte_size);
+ for (i = 0; i < dte_size; i++) {
+ dte_reset();
+ build_dte();
+ if (!tnb_dte)
+ tnb_dte = nb_dte;
+ c1 = dte_most & 0xff;
+ c2 = dte_most >> 8;
+ c1 = things[c1][0];
+ c2 = things[c2][0];
+ printm(M_INFO, "Entry #%i, most count: %li, couple = 0x%04x = (%c %c)\n", i, dte_counter, (int) dte_most, c1, c2);
+ dte_flags[dte_most] = 3;
+ gain += dte_counter;
+ push_entry(dte_most);
+ }
+
+ printm(M_STATUS, "Estimated gain: %li bytes, new file size = %li\n", gain, dte_text_size - gain);
+}
+
+void read_thingy(Handle * f) {
+ String line, st, thing;
+ long code;
+ int i;
+
+ dte_size = 0;
+
+ for (i = 0; i < 256; i++) {
+ dte_entries[i] = -1;
+ }
+
+ while (1) {
+ line = "0x";
+ *f >> st;
+ if (st.strlen()) {
+ line += st.extract(0, 1);
+ code = line.to_int();
+ thing = st.extract(3);
+ switch (thing.strlen()) {
+ case 0:
+ dte_size++;
+ dte_entries[code] = 0;
+ break;
+ case 1:
+ alloweds[code] = 1;
+ default:
+ things[code] = thing;
+ thingtree::addstring(thing, code);
+ }
+ }
+ }
+}
+
+void read_thingy_file(Handle * f) {
+ String line, trans;
+ long code;
+ int ptr = 0, i, c;
+
+ for (i = 0; i < 256; i++) {
+ dte_usage[i] = 0;
+ }
+
+ while (1) {
+ *f >> line;
+ if (!line.strlen())
+ continue;
+ i = 0;
+ while (line[i]) {
+ if (line[i] == '<') {
+ if ((c = line.strchr('>', i)) < 0) {
+ printm(M_ERROR, "Error in file: '<' not closed.\n");
+ exit(-1);
+ }
+ i++;
+ if (c == 2) {
+ trans = "0x" + line.extract(i, 2);
+ code = line.to_int();
+ dte_text[ptr++] = code;
+ printm(M_BARE, "0x%02x-", code);
+ } else {
+ printm(M_BARE, "Unknow " + trans.extract(2) + "-");
+ }
+ i += c;
+ } else {
+ if ((code = thingtree::look(line.extract(i))) == -1)
+ exit(-1);
+ dte_text[ptr++] = code;
+ i += things[code].strlen();
+ printm(M_BARE, things[code] + "-");
+ dte_usage[code]++;
+ }
+ }
+ printm(M_BARE, "\n");
+ }
+
+ dte_text[ptr] = dte_text[ptr + 1] = dte_text[ptr + 2] = dte_text[ptr + 3] = 0;
+ dte_text_size = ptr;
+}
diff --git a/lib/luapsx.cpp b/lib/luapsx.cpp index b68d3ab..eb1473b 100644 --- a/lib/luapsx.cpp +++ b/lib/luapsx.cpp @@ -1,307 +1,307 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002-2003 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: luapsx.cpp,v 1.5 2004-07-16 15:04:52 pixel Exp $ */ - -#include <LuaHandle.h> -#include "luapsx.h" -#include "generic.h" - -void over(Byte * d, Byte R, Byte G, Byte B, Byte A) { - d[0] = R; - d[1] = G; - d[2] = B; -} - -void alpha(Byte * d, Byte R, Byte G, Byte B, Byte A) { - A = MIN(A, (Byte) 128); - d[0] = ((int)d[0] * (128 - A) + R * A) >> 7; - d[1] = ((int)d[1] * (128 - A) + G * A) >> 7; - d[2] = ((int)d[2] * (128 - A) + B * A) >> 7; -} - -void lighten(Byte * d, Byte R, Byte G, Byte B, Byte A) { - A = MIN(A, (Byte) 128); - R = ((int)d[0] * (128 - A) + R * A) >> 7; - G = ((int)d[1] * (128 - A) + G * A) >> 7; - B = ((int)d[2] * (128 - A) + B * A) >> 7; - d[0] = MAX(R, d[0]); - d[1] = MAX(G, d[1]); - d[2] = MAX(B, d[2]); -} - -void darken(Byte * d, Byte R, Byte G, Byte B, Byte A) { - A = MIN(A, (Byte) 128); - R = ((int)d[0] * (128 - A) + R * A) >> 7; - G = ((int)d[1] * (128 - A) + G * A) >> 7; - B = ((int)d[2] * (128 - A) + B * A) >> 7; - d[0] = MIN(R, d[0]); - d[1] = MIN(G, d[1]); - d[2] = MIN(B, d[2]); -} - -enum { - BLIT_OVER = 0, - BLIT_OVER32, - BLIT_ALPHA, - BLIT_LIGHTEN, - BLIT_LIGHTEN32, - BLIT_DARKEN, - BLIT_DARKEN32, -}; - -typedef void psx; - -enum psx_functions_t { - PSX_BSDECODE = 0, - PSX_BSENCODE, - PSX_BLIT, -}; - -struct lua_functypes_t psx_functions[] = { - { PSX_BSDECODE, "bsdecode", 3, 3, { LUA_OBJECT, LUA_NUMBER, LUA_NUMBER } }, - { PSX_BSENCODE, "bsencode", 3, 5, { LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER } }, - { PSX_BLIT, "blit", 9, 9, { LUA_OBJECT, LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER } }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_psx : public Base { - public: - DECLARE_FUNCTION(psx, PSX_BSDECODE); - DECLARE_FUNCTION(psx, PSX_BSENCODE); - DECLARE_FUNCTION(psx, PSX_BLIT); - private: - static int psx_proceed_statics(Lua * L, int n, int caller); -}; - -void Luapsx::pushstatics(Lua * L) throw (GeneralException ) { - CHECK_FUNCTIONS(psx); - - PUSH_FUNCTION(psx, PSX_BSDECODE); - PUSH_FUNCTION(psx, PSX_BSENCODE); - PUSH_FUNCTION(psx, PSX_BLIT); - - L->push("BLIT_OVER"); - L->push((lua_Number) BLIT_OVER); - L->settable(LUA_GLOBALSINDEX); - - L->push("BLIT_OVER32"); - L->push((lua_Number) BLIT_OVER32); - L->settable(LUA_GLOBALSINDEX); - - L->push("BLIT_ALPHA"); - L->push((lua_Number) BLIT_ALPHA); - L->settable(LUA_GLOBALSINDEX); - - L->push("BLIT_LIGHTEN"); - L->push((lua_Number) BLIT_LIGHTEN); - L->settable(LUA_GLOBALSINDEX); - - L->push("BLIT_LIGHTEN32"); - L->push((lua_Number) BLIT_LIGHTEN32); - L->settable(LUA_GLOBALSINDEX); - - L->push("BLIT_DARKEN"); - L->push((lua_Number) BLIT_DARKEN); - L->settable(LUA_GLOBALSINDEX); - - L->push("BLIT_DARKEN32"); - L->push((lua_Number) BLIT_DARKEN32); - L->settable(LUA_GLOBALSINDEX); -} - -int sLua_psx::psx_proceed_statics(Lua * L, int n, int caller) { - int r = 0; - - switch (caller) { - case PSX_BSDECODE: - r = 1; - { - Buffer * b = new Buffer(true); - Handle * f = (Handle *) LuaObject::getme(L, 1); - int width = L->tonumber(2); - int height = L->tonumber(3); - Byte * in = (Byte *) malloc(f->GetSize() + 10); - Byte * out = (Byte *) malloc(width * height * 3); - LuaBuffer lb(b); - lb.pushdestruct(L); - f->read(in, f->GetSize()); - bs_decode_rgb24(out, (bs_header_t *) in, width, height, 0); - for (int i = 0; i < width * height * 3; i++) { - b[i] = out[i]; - } - free(out); - free(in); - } - case PSX_BSENCODE: - r = 3; - { - unsigned short out[0x80000]; - Buffer * b = new Buffer(true); - LuaBuffer lb(b); - lb.pushdestruct(L); - Handle * f = (Handle *) LuaObject::getme(L, 1); - bs_input_image_t img; - img.width = L->tonumber(2); - img.height = L->tonumber(3); - int max_size = 14112, cur_size; - int q_scale = 1; - if (n >= 4) - max_size = L->tonumber(4); - if (n >= 5) - q_scale = L->tonumber(5); - img.lpbits = (Byte *) malloc(f->GetSize()); - img.top = img.lpbits; - img.nextline = img.width * 3; - img.bit = 24; - - f->read(img.lpbits, f->GetSize()); - - bs_init(); - - cur_size = max_size + 1; - - for (cur_size = max_size + 1; max_size < cur_size; q_scale++) { - cur_size = bs_encode((bs_header_t *) out, &img, 2, q_scale, 0); - } - - for (int i = 0; i < cur_size; i++) { - b[i] = out[i]; - } - - L->push((lua_Number) cur_size); - L->push((lua_Number) q_scale); - } - case PSX_BLIT: - r = 0; - { - Handle * d = (Handle *) LuaObject::getme(L, 1); - Handle * s = (Handle *) LuaObject::getme(L, 2); - int dw = L->tonumber(3), - dh = L->tonumber(4), - sw = L->tonumber(5), - sh = L->tonumber(6), - sx = L->tonumber(7), - sy = L->tonumber(8), - bl = L->tonumber(9); - int bytes, dstart = 0, dskip = 0, sstart = 0, sskip = 0, i, j; - Byte RGB[3], R, G, B, A = 128; - void (*op_func)(Byte *, Byte, Byte, Byte, Byte); - - switch(bl) { - case BLIT_OVER: - bytes = 3; - op_func = over; - break; - case BLIT_OVER32: - bytes = 4; - op_func = over; - break; - case BLIT_ALPHA: - bytes = 4; - op_func = alpha; - break; - case BLIT_LIGHTEN: - bytes = 3; - op_func = lighten; - break; - case BLIT_LIGHTEN32: - bytes = 4; - op_func = lighten; - break; - case BLIT_DARKEN: - bytes = 3; - op_func = darken; - break; - case BLIT_DARKEN32: - bytes = 4; - op_func = darken; - break; - default: - L->error("Blitting operation unknown."); - return 0; - } - -#if 0 - if ((sx + sw) < 0) - return; - - if (sx >= dw) - return; - - if ((sy + sh) < 0) - return; - - if (sy >= dh) - return; -#endif - - if (sy < 0) { - sstart -= sw * bytes * sy; - sh += sy; - sy = 0; - } else { - dstart += dw * 3 * sy; - } - - if ((sy + sh) > dh) { - sh -= (sy + sh) - dh; - } - - if (sx < 0) { - sstart -= sx * bytes; - sskip -= sx * bytes; - sw += sx; - sx = 0; - } else { - dstart += sx * 3; - } - - if ((sx + sw) > dw) { - sskip += (sx + sw) - dw; - sw -= (sx + sw) - dw; - } - - dskip = (dw - sw) * 3; - - d->seek(dstart); - s->seek(sstart); - - for (i = 0; i < sh; i++, s->seek(sskip, SEEK_CUR), d->seek(dskip, SEEK_CUR)) { - for (j = 0; j < sw; j++) { - RGB[0] = d->readU8(); - RGB[1] = d->readU8(); - RGB[2] = d->readU8(); - d->seek(-3, SEEK_CUR); - R = s->readU8(); - G = s->readU8(); - B = s->readU8(); - if (bytes == 4) - A = s->readU8(); - op_func(RGB, R, G, B, A); - d->writeU8(R); - d->writeU8(G); - d->writeU8(B); - } - } - - } - } - return r; -} +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: luapsx.cpp,v 1.6 2004-11-27 21:44:48 pixel Exp $ */
+
+#include <LuaHandle.h>
+#include "luapsx.h"
+#include "generic.h"
+
+void over(Byte * d, Byte R, Byte G, Byte B, Byte A) {
+ d[0] = R;
+ d[1] = G;
+ d[2] = B;
+}
+
+void alpha(Byte * d, Byte R, Byte G, Byte B, Byte A) {
+ A = MIN(A, (Byte) 128);
+ d[0] = ((int)d[0] * (128 - A) + R * A) >> 7;
+ d[1] = ((int)d[1] * (128 - A) + G * A) >> 7;
+ d[2] = ((int)d[2] * (128 - A) + B * A) >> 7;
+}
+
+void lighten(Byte * d, Byte R, Byte G, Byte B, Byte A) {
+ A = MIN(A, (Byte) 128);
+ R = ((int)d[0] * (128 - A) + R * A) >> 7;
+ G = ((int)d[1] * (128 - A) + G * A) >> 7;
+ B = ((int)d[2] * (128 - A) + B * A) >> 7;
+ d[0] = MAX(R, d[0]);
+ d[1] = MAX(G, d[1]);
+ d[2] = MAX(B, d[2]);
+}
+
+void darken(Byte * d, Byte R, Byte G, Byte B, Byte A) {
+ A = MIN(A, (Byte) 128);
+ R = ((int)d[0] * (128 - A) + R * A) >> 7;
+ G = ((int)d[1] * (128 - A) + G * A) >> 7;
+ B = ((int)d[2] * (128 - A) + B * A) >> 7;
+ d[0] = MIN(R, d[0]);
+ d[1] = MIN(G, d[1]);
+ d[2] = MIN(B, d[2]);
+}
+
+enum {
+ BLIT_OVER = 0,
+ BLIT_OVER32,
+ BLIT_ALPHA,
+ BLIT_LIGHTEN,
+ BLIT_LIGHTEN32,
+ BLIT_DARKEN,
+ BLIT_DARKEN32,
+};
+
+typedef void psx;
+
+enum psx_functions_t {
+ PSX_BSDECODE = 0,
+ PSX_BSENCODE,
+ PSX_BLIT,
+};
+
+struct lua_functypes_t psx_functions[] = {
+ { PSX_BSDECODE, "bsdecode", 3, 3, { LUA_OBJECT, LUA_NUMBER, LUA_NUMBER } },
+ { PSX_BSENCODE, "bsencode", 3, 5, { LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER } },
+ { PSX_BLIT, "blit", 9, 9, { LUA_OBJECT, LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER } },
+ { -1, 0, 0, 0, 0 }
+};
+
+class sLua_psx : public Base {
+ public:
+ DECLARE_FUNCTION(psx, PSX_BSDECODE);
+ DECLARE_FUNCTION(psx, PSX_BSENCODE);
+ DECLARE_FUNCTION(psx, PSX_BLIT);
+ private:
+ static int psx_proceed_statics(Lua * L, int n, int caller);
+};
+
+void Luapsx::pushstatics(Lua * L) throw (GeneralException ) {
+ CHECK_FUNCTIONS(psx);
+
+ PUSH_FUNCTION(psx, PSX_BSDECODE);
+ PUSH_FUNCTION(psx, PSX_BSENCODE);
+ PUSH_FUNCTION(psx, PSX_BLIT);
+
+ L->push("BLIT_OVER");
+ L->push((lua_Number) BLIT_OVER);
+ L->settable(LUA_GLOBALSINDEX);
+
+ L->push("BLIT_OVER32");
+ L->push((lua_Number) BLIT_OVER32);
+ L->settable(LUA_GLOBALSINDEX);
+
+ L->push("BLIT_ALPHA");
+ L->push((lua_Number) BLIT_ALPHA);
+ L->settable(LUA_GLOBALSINDEX);
+
+ L->push("BLIT_LIGHTEN");
+ L->push((lua_Number) BLIT_LIGHTEN);
+ L->settable(LUA_GLOBALSINDEX);
+
+ L->push("BLIT_LIGHTEN32");
+ L->push((lua_Number) BLIT_LIGHTEN32);
+ L->settable(LUA_GLOBALSINDEX);
+
+ L->push("BLIT_DARKEN");
+ L->push((lua_Number) BLIT_DARKEN);
+ L->settable(LUA_GLOBALSINDEX);
+
+ L->push("BLIT_DARKEN32");
+ L->push((lua_Number) BLIT_DARKEN32);
+ L->settable(LUA_GLOBALSINDEX);
+}
+
+int sLua_psx::psx_proceed_statics(Lua * L, int n, int caller) {
+ int r = 0;
+
+ switch (caller) {
+ case PSX_BSDECODE:
+ r = 1;
+ {
+ Buffer * b = new Buffer(true);
+ Handle * f = (Handle *) LuaObject::getme(L, 1);
+ int width = L->tonumber(2);
+ int height = L->tonumber(3);
+ Byte * in = (Byte *) malloc(f->GetSize() + 10);
+ Byte * out = (Byte *) malloc(width * height * 3);
+ LuaBuffer lb(b);
+ lb.pushdestruct(L);
+ f->read(in, f->GetSize());
+ bs_decode_rgb24(out, (bs_header_t *) in, width, height, 0);
+ for (int i = 0; i < width * height * 3; i++) {
+ b[i] = out[i];
+ }
+ free(out);
+ free(in);
+ }
+ case PSX_BSENCODE:
+ r = 3;
+ {
+ unsigned short out[0x80000];
+ Buffer * b = new Buffer(true);
+ LuaBuffer lb(b);
+ lb.pushdestruct(L);
+ Handle * f = (Handle *) LuaObject::getme(L, 1);
+ bs_input_image_t img;
+ img.width = L->tonumber(2);
+ img.height = L->tonumber(3);
+ int max_size = 14112, cur_size;
+ int q_scale = 1;
+ if (n >= 4)
+ max_size = L->tonumber(4);
+ if (n >= 5)
+ q_scale = L->tonumber(5);
+ img.lpbits = (Byte *) malloc(f->GetSize());
+ img.top = img.lpbits;
+ img.nextline = img.width * 3;
+ img.bit = 24;
+
+ f->read(img.lpbits, f->GetSize());
+
+ bs_init();
+
+ cur_size = max_size + 1;
+
+ for (cur_size = max_size + 1; max_size < cur_size; q_scale++) {
+ cur_size = bs_encode((bs_header_t *) out, &img, 2, q_scale, 0);
+ }
+
+ for (int i = 0; i < cur_size; i++) {
+ b[i] = out[i];
+ }
+
+ L->push((lua_Number) cur_size);
+ L->push((lua_Number) q_scale);
+ }
+ case PSX_BLIT:
+ r = 0;
+ {
+ Handle * d = (Handle *) LuaObject::getme(L, 1);
+ Handle * s = (Handle *) LuaObject::getme(L, 2);
+ int dw = L->tonumber(3),
+ dh = L->tonumber(4),
+ sw = L->tonumber(5),
+ sh = L->tonumber(6),
+ sx = L->tonumber(7),
+ sy = L->tonumber(8),
+ bl = L->tonumber(9);
+ int bytes, dstart = 0, dskip = 0, sstart = 0, sskip = 0, i, j;
+ Byte RGB[3], R, G, B, A = 128;
+ void (*op_func)(Byte *, Byte, Byte, Byte, Byte);
+
+ switch(bl) {
+ case BLIT_OVER:
+ bytes = 3;
+ op_func = over;
+ break;
+ case BLIT_OVER32:
+ bytes = 4;
+ op_func = over;
+ break;
+ case BLIT_ALPHA:
+ bytes = 4;
+ op_func = alpha;
+ break;
+ case BLIT_LIGHTEN:
+ bytes = 3;
+ op_func = lighten;
+ break;
+ case BLIT_LIGHTEN32:
+ bytes = 4;
+ op_func = lighten;
+ break;
+ case BLIT_DARKEN:
+ bytes = 3;
+ op_func = darken;
+ break;
+ case BLIT_DARKEN32:
+ bytes = 4;
+ op_func = darken;
+ break;
+ default:
+ L->error("Blitting operation unknown.");
+ return 0;
+ }
+
+#if 0
+ if ((sx + sw) < 0)
+ return;
+
+ if (sx >= dw)
+ return;
+
+ if ((sy + sh) < 0)
+ return;
+
+ if (sy >= dh)
+ return;
+#endif
+
+ if (sy < 0) {
+ sstart -= sw * bytes * sy;
+ sh += sy;
+ sy = 0;
+ } else {
+ dstart += dw * 3 * sy;
+ }
+
+ if ((sy + sh) > dh) {
+ sh -= (sy + sh) - dh;
+ }
+
+ if (sx < 0) {
+ sstart -= sx * bytes;
+ sskip -= sx * bytes;
+ sw += sx;
+ sx = 0;
+ } else {
+ dstart += sx * 3;
+ }
+
+ if ((sx + sw) > dw) {
+ sskip += (sx + sw) - dw;
+ sw -= (sx + sw) - dw;
+ }
+
+ dskip = (dw - sw) * 3;
+
+ d->seek(dstart);
+ s->seek(sstart);
+
+ for (i = 0; i < sh; i++, s->seek(sskip, SEEK_CUR), d->seek(dskip, SEEK_CUR)) {
+ for (j = 0; j < sw; j++) {
+ RGB[0] = d->readU8();
+ RGB[1] = d->readU8();
+ RGB[2] = d->readU8();
+ d->seek(-3, SEEK_CUR);
+ R = s->readU8();
+ G = s->readU8();
+ B = s->readU8();
+ if (bytes == 4)
+ A = s->readU8();
+ op_func(RGB, R, G, B, A);
+ d->writeU8(R);
+ d->writeU8(G);
+ d->writeU8(B);
+ }
+ }
+
+ }
+ }
+ return r;
+}
diff --git a/lib/lzss.cpp b/lib/lzss.cpp index 1d7ecfb..7b134aa 100644 --- a/lib/lzss.cpp +++ b/lib/lzss.cpp @@ -1,464 +1,464 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <iostream> -#include "generic.h" -#include "lzss.h" -#include "Handle.h" - -lzss::lzss() : tolerate(1), blockb(0), scheme(schemes[0]), lzss_maxsize(18), lzss_maxptr(0x0fff) { - compute_limits(); -} - -/* - -Valkyrie Profile V2: - -JJJJJJJJ LLLLJJJJ -VVVVVVVV 1111RRRR -RRRRRRRR 11110000 VVVVVVVV - -*/ - -const lzss::scheme_t lzss::schemes[] = { -/* Nom 1 I J O N 16 P F W Lm1 Ls1 Lm2 Ls2 Jm1 Js1 Jm2 Js2 Fm1 Fs1 Fm2 Fs2 Vm1 Vs1 Vm2 Vs2 Flags*/ -#if 0 /* Zelda GC */ - {"Yaz0", 0, 1, 1, 0, 0, 0, 0, 0, 0, 0xf0, -4, 0x00, 0, 0x0f, 8, 0xff, 0, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0}, -#endif - {"Xenogears", 1, 0, 0, 1, 0, 0, 0, 0, 0, 0x00, 0, 0xf0, -4, 0xff, 0, 0x0f, 8, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0}, - {"DBZ RPG", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0f, 0, 0x00, 0, 0xf0, -4, 0xff, 4, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0}, - {"FF7", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0, 0x0f, 0, 0xff, 0, 0xf0, 4, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0}, - {"Leen Mean", 1, 1, 1, 1, 0, 0, 0, 0, 0, 0x0f, 0, 0x00, 0, 0xf0, 4, 0xff, 0, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0}, - {"Metal Max", 0, 0, 0, 1, 0, 0, 2, 0, 0x12, 0x00, 0, 0x0f, 0, 0xff, 0, 0xf0, 4, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0}, - {"Ogre Battle", 0, 0, 0, 1, 0, 0, 1, 0, 0, 0xf8, -3, 0x00, 0, 0x07, 8, 0xff, 0, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0}, - {"Lodoss Wars", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0, 0x7f, 0, 0xff, 0, 0x80, 1, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0}, - {"FF6 PSX", 0, 0, 0, 1, 1, 1, 0, 0, 0, 0x1f, 1, 0x00, 0, 0xe0, -4, 0xff, 4, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0}, - {"Valkyrie-1", 0, 0, 0, 1, 1, 0, 0, 0, 0, 0x00, 0, 0xf0, -4, 0xff, 0, 0x0f, 8, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0}, - {"Valkyrie-2", 0, 0, 0, 1, 1, 0, 0, 2, 0, 0x00, 0, 0xf0, -4, 0xff, 0, 0x0f, 8, 0x00, 0, 0x0f, 0, 0xff, 0, 0x00, 0}, - {"ToD", 0, 0, 0,-1, 1, 0, 1, 1, 3, 0x00, 0, 0x0f, 0, 0xff, 0, 0xf0, 4, 0x00, 0, 0xf0, -4, 0xff, 0, 0x00, 0}, - {0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0} -}; - -Byte lzss::swap_bits(Byte i) { - i = ((i >> 1) & 0x55) | ((i << 1) & 0xaa); - i = ((i >> 2) & 0x33) | ((i << 2) & 0xcc); - i = ((i >> 4) & 0x0f) | ((i << 4) & 0xf0); - return i; -} - -unsigned int lzss::shift(unsigned int c, int s) { - return s > 0 ? (c << s) : c >> (-s); -} - -void lzss::compute_limits(void) { - unsigned char val1, val2; - - val1 = val2 = 0xff; - - lzss_maxsize = shift(val1 & scheme.l_mask_1, scheme.l_shft_1) | - shift(val2 & scheme.l_mask_2, scheme.l_shft_2); - lzss_maxptr = shift(val1 & scheme.j_mask_1, scheme.j_shft_1) | - shift(val2 & scheme.j_mask_2, scheme.j_shft_2); - - lzss_maxsize = lzss_maxsize + 3 + scheme.sixteen_bits; - lzss_maxptr += scheme.one_jump; - - if (scheme.l_mask_1 & scheme.j_mask_1) { - printm(M_ERROR, "Masks are overlapping for value 1\n"); - exit(-1); - } - - if (scheme.l_mask_2 & scheme.j_mask_2) { - printm(M_ERROR, "Masks are overlapping for value 2\n"); - exit(-1); - } - - if (shift(scheme.l_mask_1, scheme.l_shft_1) & shift(scheme.l_mask_2, scheme.l_shft_2)) { - printm(M_ERROR, "Shifts build an overlap for lenght\n"); - exit(-1); - } - - if (shift(scheme.j_mask_1, scheme.j_shft_1) & shift(scheme.j_mask_2, scheme.j_shft_2)) { - printm(M_ERROR, "Shifts build an overlap for jump\n"); - exit(-1); - } - - printm(M_INFO, "Computed values: maxsize = %i, maxptr = 0x%06x\n", lzss_maxsize, lzss_maxptr); -} - -unsigned int lzss::lzss_decomp(Handle * f_source, Handle * f_cible, int true_length) -{ - unsigned char bitmap, fbitmap; - unsigned char valeur; - unsigned char * text_buf; - unsigned char val1, val2, val3; - int negative_error = scheme.negative_trick, overlap_error = scheme.overlap_trick == 1; - int r = 0; - int decomp_count; - int decomp_length; - int decomp_fill; - int decomp_jump; - int decomp_offset = 0; - int loop_length; - int whole_count; - int i, j; - int length, reads; - - compute_limits(); - - f_source->read(&length, 4); - if (true_length >= 0) { - length = true_length; - } - whole_count = 0; - - printm(M_INFO, "Decompressing %i bytes\n", length); - - text_buf = (unsigned char *) malloc(length + 8); - - do { - f_source->read(&bitmap, 1); - if (scheme.sixteen_bits) { - f_source->read(&fbitmap, 1); - printm(M_INFO, "16bits behavior, false bitmap = %02x\n", fbitmap); - } - printm(M_INFO, "Begin of block, bitmap = %02x\n", bitmap); - if (scheme.bitmap_inversed) { - bitmap = swap_bits(bitmap); - } - for (i = 0; i < 8; i++) { - printm(M_INFO, " - Chunk %i (offset cible = %li = 0x%04x, offset source = %li = 0x%04x)\n", i, f_cible->tell(), f_cible->tell(), f_source->tell(), f_source->tell()); - if (whole_count >= length) - break; - if ((bitmap & 1) ^ scheme.one_is_compressed) { - for (j = 0; j < (scheme.sixteen_bits ? 2 : 1); j++) { - reads = f_source->read(&valeur, 1); - if (!reads) { - printm(M_WARNING, " WARNING! PADDING!\n"); - free(text_buf); - return length; - } - printm(M_INFO, " Copying 0x%02x\n", valeur); - f_cible->write(&valeur, 1); - text_buf[r++] = valeur; - whole_count++; - } - } else { - f_source->read(&val1, 1); - f_source->read(&val2, 1); - decomp_length = shift(val1 & scheme.l_mask_1, scheme.l_shft_1) | - shift(val2 & scheme.l_mask_2, scheme.l_shft_2); - decomp_fill = shift(val1 & scheme.f_mask_1, scheme.f_shft_1) | - shift(val2 & scheme.f_mask_2, scheme.f_shft_2); - decomp_jump = shift(val1 & scheme.j_mask_1, scheme.j_shft_1) | - shift(val2 & scheme.j_mask_2, scheme.j_shft_2); - valeur = shift(val1 & scheme.v_mask_1, scheme.v_shft_1) | - shift(val2 & scheme.v_mask_2, scheme.v_shft_2); -// decomp_jump &= lzss_maxptr; bad, ugly, non working - decomp_jump += scheme.one_jump; - decomp_length = decomp_length + 3 + scheme.sixteen_bits; - decomp_fill = decomp_fill + 3 + scheme.sixteen_bits; -#if 0 /* Zelda GC */ - decomp_length--; - if (decomp_length == 2) { - printm(M_INFO, "Big jump\n"); - decomp_length = f_source->readU8() + 18; - } -#endif - if ((decomp_length == lzss_maxsize) && (scheme.filling)) { - if ((decomp_fill == 3) && (scheme.filling == 2)) { - f_source->read(&val3, 1); - printm(M_INFO, " Found an extended needle (val1 = 0x%02x, val2 = 0x%02x, val3 = 0x%02x)\n", val1, val2, val3); - decomp_fill = val1 + 19; - valeur = val3; - } else { - printm(M_INFO, " Found a 0x%02x-filling needle of %li bytes (val1 = 0x%02x, val2 = 0x%02x)\n", valeur, decomp_fill, val1, val2); - } - for (decomp_count = 0; decomp_count < decomp_fill; decomp_count++) { - f_cible->write(&valeur, 1); - text_buf[r++] = valeur; - if (!blockb) - whole_count++; - } - if (blockb) - whole_count++; - } else { - switch (scheme.ptrb) { - case 0: - decomp_offset = r - decomp_jump; - break; - case 1: - decomp_offset = r - lzss_maxptr - 1 + decomp_jump - scheme.window_start; - break; - case 2: - decomp_offset = decomp_jump - scheme.window_start; - break; - } - decomp_offset += scheme.overlap_trick == -1 ? decomp_length : 0; - loop_length = decomp_offset + decomp_length; - if ((loop_length >= r) && (!overlap_error)) { - if (!tolerate) { - free(text_buf); - return 0; - } - printm(M_ERROR, "Overlap trick used without it beeing enabled in the scheme.\n"); - overlap_error = 1; - } - printm(M_INFO, " Found a needle of %li bytes at %li = 0x%04x, jump of %li = 0x%04x (val1 = 0x%02x, val2 = 0x%02x)\n", decomp_length, decomp_offset, decomp_offset, decomp_jump, decomp_jump, val1, val2); - for (decomp_count = decomp_offset; decomp_count < loop_length; decomp_count++) { - if (!blockb) - whole_count++; - if (decomp_count < 0) { - valeur = 0; - f_cible->write(&valeur, 1); - text_buf[r++] = 0; - if (!negative_error) { - if (!tolerate) { - free(text_buf); - return 0; - } - printm(M_ERROR, "Negative trick used without it beeing enabled in the scheme.\n"); - negative_error = 1; - } - printm(M_INFO, "Filling with 0\n"); - } else { - f_cible->write(&text_buf[decomp_count], 1); - printm(M_INFO, "@0x%04x: 0x%02x\n", decomp_count, text_buf[decomp_count]); - text_buf[r++] = text_buf[decomp_count]; - } - if (whole_count >= length) - break; - } - if (blockb) - whole_count++; - } - } - bitmap >>= 1; - } - } while (whole_count < length); - free(text_buf); - - return length; -} - -unsigned char lzss::lzss_rd(unsigned char * t, int p) { - return ((p < 0) ? 0 : (t[p])); -} - -int lzss::lzss_comp_strstr(unsigned char * needle, unsigned char * r, int * l, int sp) { - char redo[256]; - int length, i, p, ptr, maxlength; - - i = 1; - redo[0] = p = 0; - while (i < lzss_maxsize) { - if (needle[i] == needle[p]) { - redo[i++] = ++p; - } else if (p > 0) { - p = redo[p - 1]; - } else { - redo[i++] = 0; - } - } - - length = maxlength = 0; - i = sp; - p = 0; - ptr = 0; - - while ((i - sp - (scheme.overlap_trick ? p : 0)) < *l) { - if (needle[p] == lzss_rd(r, i)) { - if (p == (lzss_maxsize - 1)) { - *l = lzss_maxsize; - return i - lzss_maxsize + 1; - } - i++; - p++; - } else if (p > 0) { - if (p > maxlength) { - if (!((i - p) & scheme.sixteen_bits)) { - ptr = i - (maxlength = p); - } - } - p = redo[p - 1]; - } else { - i++; - } - } - - *l = maxlength; - return ptr; -} - -unsigned char * lzss::lzss_memcomp(unsigned char * r, int * l, int * delta) { - unsigned char bitmap, * comp; - int ptr, needle, needle_length, comp_ptr, bitmap_ptr, val1, val2; - int jump, farest, remaining; - int j; - - comp = (unsigned char *) malloc(3 * *l); - - compute_limits(); - - ptr = 0; - blk = 0; - bitmap_count = 0; - comp_ptr = 1 + scheme.sixteen_bits; - bitmap = 0; - bitmap_ptr = 0; - printm(M_INFO, "Begin of block 0.\n"); - while ((remaining = *l - ptr) > 0) { - printm(M_INFO, " Remaining bytes: %li\n", remaining); - lzss_maxsize = MIN(lzss_maxsize, remaining); - bitmap_count++; - bitmap >>= 1; - farest = ptr - lzss_maxptr; - farest = farest > ((-lzss_maxsize) * scheme.negative_trick) ? farest : -lzss_maxsize * scheme.negative_trick; - needle_length = ptr - farest; - if (scheme.ptrb == 2) { - farest = 0; - needle_length = MIN(lzss_maxptr - scheme.window_start, ptr); - } - needle = lzss_comp_strstr(&r[ptr], r, &needle_length, farest); - if ((needle < 0) && ((-needle) > needle_length)) { - needle = -needle_length; - } - printm(M_INFO, " - Chunk %i (offset source = %li = 0x%04x, offset cible = %li = 0x%04x)\n", bitmap_count - 1, ptr, ptr, comp_ptr, comp_ptr); - jump = ptr - needle; - needle_length = needle_length > remaining ? remaining : needle_length; - - if (needle_length & scheme.sixteen_bits) { - needle_length--; - } - - if ((needle < 0) || (!jump)) { - printm(M_INFO, " Nothing found.\n"); - } else { - printm(M_INFO, " Found a needle of %i bytes at offset %i (jump = %i = 0x%04x)\n", needle_length, needle, jump, jump); - } - - if ((needle_length <= (2 + scheme.sixteen_bits)) || (!jump)) { - if (needle_length > 2) { - printm(M_ERROR, " ** REJECTED **\n"); - } - for (j = 0; j < (scheme.sixteen_bits ? 2 : 1); j++) { - printm(M_INFO, " Repeating 0x%02x\n", r[ptr]); - comp[comp_ptr] = r[ptr]; - ptr++; - comp_ptr++; - } - bitmap |= 0x80; - } else { - int j; - printm(M_INFO, " Found a needle of %li bytes at %li = 0x%04x\n", needle_length, needle, needle); - for (j = 0; j < needle_length; j++) { - printm(M_INFO, "@0x%04x: 0x%02x - @0x%04x: 0x%02x\n", needle + j, lzss_rd(r, needle + j - scheme.window_start), ptr + j, lzss_rd(r, ptr + j)); - if (lzss_rd(r, needle + j) != lzss_rd(r, ptr + j)) { - printm(M_ERROR, "ERROR!!\n"); - } - } - jump -= scheme.one_jump; - printm(M_INFO, "ptr = %li, needle = %li, jump = %li = 0x%03x\n", ptr, needle, jump, jump); - ptr += needle_length; - needle_length -= 3; - switch (scheme.ptrb) { - case 0: - break; - case 1: - jump = lzss_maxptr + 1 - jump; - break; - case 2: - jump = needle + scheme.window_start; - break; - } - val1 = comp[comp_ptr++] = (shift(jump, -scheme.j_shft_1) & scheme.j_mask_1) | - (shift(needle_length, -scheme.l_shft_1) & scheme.l_mask_1); - val2 = comp[comp_ptr++] = (shift(jump, -scheme.j_shft_2) & scheme.j_mask_2) | - (shift(needle_length, -scheme.l_shft_2) & scheme.l_mask_2); - printm(M_INFO, " writing info1 = 0x%02x, info2 = 0x%02x\n", val1, val2); - } - - bitmap ^= scheme.one_is_compressed << 7; - - if (bitmap_count == 8) { - blk++; - printm(M_INFO, "End of block, writing bitmap = 0x%02x\n", bitmap); - printm(M_INFO, "Begin of block %li.\n", blk); - bitmap_count = 0; - if (scheme.bitmap_inversed) - bitmap = swap_bits(bitmap); - comp[bitmap_ptr] = bitmap; - if (scheme.sixteen_bits) { - comp[bitmap_ptr + 1] = 0; - } - bitmap_ptr = comp_ptr; - comp_ptr += (scheme.sixteen_bits ? 2 : 1); - } - } - - if (bitmap_count) { - bitmap >>= (8 - bitmap_count); - if (scheme.bitmap_inversed) - bitmap = swap_bits(bitmap); - comp[bitmap_ptr] = bitmap; - if (scheme.sixteen_bits) { - comp[bitmap_ptr + 1] = 0; - } - } else { - comp_ptr--; - } - - if (delta) { - *delta = (bitmap_count ? 8 - bitmap_count : 0); - } - - *l = comp_ptr; - return comp; -} - -void lzss::lzss_comp(Handle * f_source, Handle * f_cible, int * delta) { - int length = f_source->GetSize(), l; - unsigned char * r = (unsigned char *) malloc(length), * c; - - f_source->read(r, length); - l = length; - c = lzss_memcomp(r, &l, delta); - if (delta) { - length += *delta; - } - f_cible->write(&length, 4); - if (delta) { - length -= *delta; - } - f_cible->write(c, l); - free(c); - free(r); -} - -void lzss::change_scheme(scheme_t new_scheme) { - scheme = new_scheme; - compute_limits(); -} - -lzss::scheme_t lzss::get_scheme() { - return scheme; -} +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <iostream>
+#include "generic.h"
+#include "lzss.h"
+#include "Handle.h"
+
+lzss::lzss() : tolerate(1), blockb(0), scheme(schemes[0]), lzss_maxsize(18), lzss_maxptr(0x0fff) {
+ compute_limits();
+}
+
+/*
+
+Valkyrie Profile V2:
+
+JJJJJJJJ LLLLJJJJ
+VVVVVVVV 1111RRRR
+RRRRRRRR 11110000 VVVVVVVV
+
+*/
+
+const lzss::scheme_t lzss::schemes[] = {
+/* Nom 1 I J O N 16 P F W Lm1 Ls1 Lm2 Ls2 Jm1 Js1 Jm2 Js2 Fm1 Fs1 Fm2 Fs2 Vm1 Vs1 Vm2 Vs2 Flags*/
+#if 0 /* Zelda GC */
+ {"Yaz0", 0, 1, 1, 0, 0, 0, 0, 0, 0, 0xf0, -4, 0x00, 0, 0x0f, 8, 0xff, 0, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+#endif
+ {"Xenogears", 1, 0, 0, 1, 0, 0, 0, 0, 0, 0x00, 0, 0xf0, -4, 0xff, 0, 0x0f, 8, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"DBZ RPG", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0f, 0, 0x00, 0, 0xf0, -4, 0xff, 4, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"FF7", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0, 0x0f, 0, 0xff, 0, 0xf0, 4, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"Leen Mean", 1, 1, 1, 1, 0, 0, 0, 0, 0, 0x0f, 0, 0x00, 0, 0xf0, 4, 0xff, 0, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"Metal Max", 0, 0, 0, 1, 0, 0, 2, 0, 0x12, 0x00, 0, 0x0f, 0, 0xff, 0, 0xf0, 4, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"Ogre Battle", 0, 0, 0, 1, 0, 0, 1, 0, 0, 0xf8, -3, 0x00, 0, 0x07, 8, 0xff, 0, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"Lodoss Wars", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0, 0x7f, 0, 0xff, 0, 0x80, 1, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"FF6 PSX", 0, 0, 0, 1, 1, 1, 0, 0, 0, 0x1f, 1, 0x00, 0, 0xe0, -4, 0xff, 4, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"Valkyrie-1", 0, 0, 0, 1, 1, 0, 0, 0, 0, 0x00, 0, 0xf0, -4, 0xff, 0, 0x0f, 8, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0},
+ {"Valkyrie-2", 0, 0, 0, 1, 1, 0, 0, 2, 0, 0x00, 0, 0xf0, -4, 0xff, 0, 0x0f, 8, 0x00, 0, 0x0f, 0, 0xff, 0, 0x00, 0},
+ {"ToD", 0, 0, 0,-1, 1, 0, 1, 1, 3, 0x00, 0, 0x0f, 0, 0xff, 0, 0xf0, 4, 0x00, 0, 0xf0, -4, 0xff, 0, 0x00, 0},
+ {0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0, 0x00, 0, 0x00, 0, 0x00, 0}
+};
+
+Byte lzss::swap_bits(Byte i) {
+ i = ((i >> 1) & 0x55) | ((i << 1) & 0xaa);
+ i = ((i >> 2) & 0x33) | ((i << 2) & 0xcc);
+ i = ((i >> 4) & 0x0f) | ((i << 4) & 0xf0);
+ return i;
+}
+
+unsigned int lzss::shift(unsigned int c, int s) {
+ return s > 0 ? (c << s) : c >> (-s);
+}
+
+void lzss::compute_limits(void) {
+ unsigned char val1, val2;
+
+ val1 = val2 = 0xff;
+
+ lzss_maxsize = shift(val1 & scheme.l_mask_1, scheme.l_shft_1) |
+ shift(val2 & scheme.l_mask_2, scheme.l_shft_2);
+ lzss_maxptr = shift(val1 & scheme.j_mask_1, scheme.j_shft_1) |
+ shift(val2 & scheme.j_mask_2, scheme.j_shft_2);
+
+ lzss_maxsize = lzss_maxsize + 3 + scheme.sixteen_bits;
+ lzss_maxptr += scheme.one_jump;
+
+ if (scheme.l_mask_1 & scheme.j_mask_1) {
+ printm(M_ERROR, "Masks are overlapping for value 1\n");
+ exit(-1);
+ }
+
+ if (scheme.l_mask_2 & scheme.j_mask_2) {
+ printm(M_ERROR, "Masks are overlapping for value 2\n");
+ exit(-1);
+ }
+
+ if (shift(scheme.l_mask_1, scheme.l_shft_1) & shift(scheme.l_mask_2, scheme.l_shft_2)) {
+ printm(M_ERROR, "Shifts build an overlap for lenght\n");
+ exit(-1);
+ }
+
+ if (shift(scheme.j_mask_1, scheme.j_shft_1) & shift(scheme.j_mask_2, scheme.j_shft_2)) {
+ printm(M_ERROR, "Shifts build an overlap for jump\n");
+ exit(-1);
+ }
+
+ printm(M_INFO, "Computed values: maxsize = %i, maxptr = 0x%06x\n", lzss_maxsize, lzss_maxptr);
+}
+
+unsigned int lzss::lzss_decomp(Handle * f_source, Handle * f_cible, int true_length)
+{
+ unsigned char bitmap, fbitmap;
+ unsigned char valeur;
+ unsigned char * text_buf;
+ unsigned char val1, val2, val3;
+ int negative_error = scheme.negative_trick, overlap_error = scheme.overlap_trick == 1;
+ int r = 0;
+ int decomp_count;
+ int decomp_length;
+ int decomp_fill;
+ int decomp_jump;
+ int decomp_offset = 0;
+ int loop_length;
+ int whole_count;
+ int i, j;
+ int length, reads;
+
+ compute_limits();
+
+ f_source->read(&length, 4);
+ if (true_length >= 0) {
+ length = true_length;
+ }
+ whole_count = 0;
+
+ printm(M_INFO, "Decompressing %i bytes\n", length);
+
+ text_buf = (unsigned char *) malloc(length + 8);
+
+ do {
+ f_source->read(&bitmap, 1);
+ if (scheme.sixteen_bits) {
+ f_source->read(&fbitmap, 1);
+ printm(M_INFO, "16bits behavior, false bitmap = %02x\n", fbitmap);
+ }
+ printm(M_INFO, "Begin of block, bitmap = %02x\n", bitmap);
+ if (scheme.bitmap_inversed) {
+ bitmap = swap_bits(bitmap);
+ }
+ for (i = 0; i < 8; i++) {
+ printm(M_INFO, " - Chunk %i (offset cible = %li = 0x%04x, offset source = %li = 0x%04x)\n", i, f_cible->tell(), f_cible->tell(), f_source->tell(), f_source->tell());
+ if (whole_count >= length)
+ break;
+ if ((bitmap & 1) ^ scheme.one_is_compressed) {
+ for (j = 0; j < (scheme.sixteen_bits ? 2 : 1); j++) {
+ reads = f_source->read(&valeur, 1);
+ if (!reads) {
+ printm(M_WARNING, " WARNING! PADDING!\n");
+ free(text_buf);
+ return length;
+ }
+ printm(M_INFO, " Copying 0x%02x\n", valeur);
+ f_cible->write(&valeur, 1);
+ text_buf[r++] = valeur;
+ whole_count++;
+ }
+ } else {
+ f_source->read(&val1, 1);
+ f_source->read(&val2, 1);
+ decomp_length = shift(val1 & scheme.l_mask_1, scheme.l_shft_1) |
+ shift(val2 & scheme.l_mask_2, scheme.l_shft_2);
+ decomp_fill = shift(val1 & scheme.f_mask_1, scheme.f_shft_1) |
+ shift(val2 & scheme.f_mask_2, scheme.f_shft_2);
+ decomp_jump = shift(val1 & scheme.j_mask_1, scheme.j_shft_1) |
+ shift(val2 & scheme.j_mask_2, scheme.j_shft_2);
+ valeur = shift(val1 & scheme.v_mask_1, scheme.v_shft_1) |
+ shift(val2 & scheme.v_mask_2, scheme.v_shft_2);
+// decomp_jump &= lzss_maxptr; bad, ugly, non working
+ decomp_jump += scheme.one_jump;
+ decomp_length = decomp_length + 3 + scheme.sixteen_bits;
+ decomp_fill = decomp_fill + 3 + scheme.sixteen_bits;
+#if 0 /* Zelda GC */
+ decomp_length--;
+ if (decomp_length == 2) {
+ printm(M_INFO, "Big jump\n");
+ decomp_length = f_source->readU8() + 18;
+ }
+#endif
+ if ((decomp_length == lzss_maxsize) && (scheme.filling)) {
+ if ((decomp_fill == 3) && (scheme.filling == 2)) {
+ f_source->read(&val3, 1);
+ printm(M_INFO, " Found an extended needle (val1 = 0x%02x, val2 = 0x%02x, val3 = 0x%02x)\n", val1, val2, val3);
+ decomp_fill = val1 + 19;
+ valeur = val3;
+ } else {
+ printm(M_INFO, " Found a 0x%02x-filling needle of %li bytes (val1 = 0x%02x, val2 = 0x%02x)\n", valeur, decomp_fill, val1, val2);
+ }
+ for (decomp_count = 0; decomp_count < decomp_fill; decomp_count++) {
+ f_cible->write(&valeur, 1);
+ text_buf[r++] = valeur;
+ if (!blockb)
+ whole_count++;
+ }
+ if (blockb)
+ whole_count++;
+ } else {
+ switch (scheme.ptrb) {
+ case 0:
+ decomp_offset = r - decomp_jump;
+ break;
+ case 1:
+ decomp_offset = r - lzss_maxptr - 1 + decomp_jump - scheme.window_start;
+ break;
+ case 2:
+ decomp_offset = decomp_jump - scheme.window_start;
+ break;
+ }
+ decomp_offset += scheme.overlap_trick == -1 ? decomp_length : 0;
+ loop_length = decomp_offset + decomp_length;
+ if ((loop_length >= r) && (!overlap_error)) {
+ if (!tolerate) {
+ free(text_buf);
+ return 0;
+ }
+ printm(M_ERROR, "Overlap trick used without it beeing enabled in the scheme.\n");
+ overlap_error = 1;
+ }
+ printm(M_INFO, " Found a needle of %li bytes at %li = 0x%04x, jump of %li = 0x%04x (val1 = 0x%02x, val2 = 0x%02x)\n", decomp_length, decomp_offset, decomp_offset, decomp_jump, decomp_jump, val1, val2);
+ for (decomp_count = decomp_offset; decomp_count < loop_length; decomp_count++) {
+ if (!blockb)
+ whole_count++;
+ if (decomp_count < 0) {
+ valeur = 0;
+ f_cible->write(&valeur, 1);
+ text_buf[r++] = 0;
+ if (!negative_error) {
+ if (!tolerate) {
+ free(text_buf);
+ return 0;
+ }
+ printm(M_ERROR, "Negative trick used without it beeing enabled in the scheme.\n");
+ negative_error = 1;
+ }
+ printm(M_INFO, "Filling with 0\n");
+ } else {
+ f_cible->write(&text_buf[decomp_count], 1);
+ printm(M_INFO, "@0x%04x: 0x%02x\n", decomp_count, text_buf[decomp_count]);
+ text_buf[r++] = text_buf[decomp_count];
+ }
+ if (whole_count >= length)
+ break;
+ }
+ if (blockb)
+ whole_count++;
+ }
+ }
+ bitmap >>= 1;
+ }
+ } while (whole_count < length);
+ free(text_buf);
+
+ return length;
+}
+
+unsigned char lzss::lzss_rd(unsigned char * t, int p) {
+ return ((p < 0) ? 0 : (t[p]));
+}
+
+int lzss::lzss_comp_strstr(unsigned char * needle, unsigned char * r, int * l, int sp) {
+ char redo[256];
+ int length, i, p, ptr, maxlength;
+
+ i = 1;
+ redo[0] = p = 0;
+ while (i < lzss_maxsize) {
+ if (needle[i] == needle[p]) {
+ redo[i++] = ++p;
+ } else if (p > 0) {
+ p = redo[p - 1];
+ } else {
+ redo[i++] = 0;
+ }
+ }
+
+ length = maxlength = 0;
+ i = sp;
+ p = 0;
+ ptr = 0;
+
+ while ((i - sp - (scheme.overlap_trick ? p : 0)) < *l) {
+ if (needle[p] == lzss_rd(r, i)) {
+ if (p == (lzss_maxsize - 1)) {
+ *l = lzss_maxsize;
+ return i - lzss_maxsize + 1;
+ }
+ i++;
+ p++;
+ } else if (p > 0) {
+ if (p > maxlength) {
+ if (!((i - p) & scheme.sixteen_bits)) {
+ ptr = i - (maxlength = p);
+ }
+ }
+ p = redo[p - 1];
+ } else {
+ i++;
+ }
+ }
+
+ *l = maxlength;
+ return ptr;
+}
+
+unsigned char * lzss::lzss_memcomp(unsigned char * r, int * l, int * delta) {
+ unsigned char bitmap, * comp;
+ int ptr, needle, needle_length, comp_ptr, bitmap_ptr, val1, val2;
+ int jump, farest, remaining;
+ int j;
+
+ comp = (unsigned char *) malloc(3 * *l);
+
+ compute_limits();
+
+ ptr = 0;
+ blk = 0;
+ bitmap_count = 0;
+ comp_ptr = 1 + scheme.sixteen_bits;
+ bitmap = 0;
+ bitmap_ptr = 0;
+ printm(M_INFO, "Begin of block 0.\n");
+ while ((remaining = *l - ptr) > 0) {
+ printm(M_INFO, " Remaining bytes: %li\n", remaining);
+ lzss_maxsize = MIN(lzss_maxsize, remaining);
+ bitmap_count++;
+ bitmap >>= 1;
+ farest = ptr - lzss_maxptr;
+ farest = farest > ((-lzss_maxsize) * scheme.negative_trick) ? farest : -lzss_maxsize * scheme.negative_trick;
+ needle_length = ptr - farest;
+ if (scheme.ptrb == 2) {
+ farest = 0;
+ needle_length = MIN(lzss_maxptr - scheme.window_start, ptr);
+ }
+ needle = lzss_comp_strstr(&r[ptr], r, &needle_length, farest);
+ if ((needle < 0) && ((-needle) > needle_length)) {
+ needle = -needle_length;
+ }
+ printm(M_INFO, " - Chunk %i (offset source = %li = 0x%04x, offset cible = %li = 0x%04x)\n", bitmap_count - 1, ptr, ptr, comp_ptr, comp_ptr);
+ jump = ptr - needle;
+ needle_length = needle_length > remaining ? remaining : needle_length;
+
+ if (needle_length & scheme.sixteen_bits) {
+ needle_length--;
+ }
+
+ if ((needle < 0) || (!jump)) {
+ printm(M_INFO, " Nothing found.\n");
+ } else {
+ printm(M_INFO, " Found a needle of %i bytes at offset %i (jump = %i = 0x%04x)\n", needle_length, needle, jump, jump);
+ }
+
+ if ((needle_length <= (2 + scheme.sixteen_bits)) || (!jump)) {
+ if (needle_length > 2) {
+ printm(M_ERROR, " ** REJECTED **\n");
+ }
+ for (j = 0; j < (scheme.sixteen_bits ? 2 : 1); j++) {
+ printm(M_INFO, " Repeating 0x%02x\n", r[ptr]);
+ comp[comp_ptr] = r[ptr];
+ ptr++;
+ comp_ptr++;
+ }
+ bitmap |= 0x80;
+ } else {
+ int j;
+ printm(M_INFO, " Found a needle of %li bytes at %li = 0x%04x\n", needle_length, needle, needle);
+ for (j = 0; j < needle_length; j++) {
+ printm(M_INFO, "@0x%04x: 0x%02x - @0x%04x: 0x%02x\n", needle + j, lzss_rd(r, needle + j - scheme.window_start), ptr + j, lzss_rd(r, ptr + j));
+ if (lzss_rd(r, needle + j) != lzss_rd(r, ptr + j)) {
+ printm(M_ERROR, "ERROR!!\n");
+ }
+ }
+ jump -= scheme.one_jump;
+ printm(M_INFO, "ptr = %li, needle = %li, jump = %li = 0x%03x\n", ptr, needle, jump, jump);
+ ptr += needle_length;
+ needle_length -= 3;
+ switch (scheme.ptrb) {
+ case 0:
+ break;
+ case 1:
+ jump = lzss_maxptr + 1 - jump;
+ break;
+ case 2:
+ jump = needle + scheme.window_start;
+ break;
+ }
+ val1 = comp[comp_ptr++] = (shift(jump, -scheme.j_shft_1) & scheme.j_mask_1) |
+ (shift(needle_length, -scheme.l_shft_1) & scheme.l_mask_1);
+ val2 = comp[comp_ptr++] = (shift(jump, -scheme.j_shft_2) & scheme.j_mask_2) |
+ (shift(needle_length, -scheme.l_shft_2) & scheme.l_mask_2);
+ printm(M_INFO, " writing info1 = 0x%02x, info2 = 0x%02x\n", val1, val2);
+ }
+
+ bitmap ^= scheme.one_is_compressed << 7;
+
+ if (bitmap_count == 8) {
+ blk++;
+ printm(M_INFO, "End of block, writing bitmap = 0x%02x\n", bitmap);
+ printm(M_INFO, "Begin of block %li.\n", blk);
+ bitmap_count = 0;
+ if (scheme.bitmap_inversed)
+ bitmap = swap_bits(bitmap);
+ comp[bitmap_ptr] = bitmap;
+ if (scheme.sixteen_bits) {
+ comp[bitmap_ptr + 1] = 0;
+ }
+ bitmap_ptr = comp_ptr;
+ comp_ptr += (scheme.sixteen_bits ? 2 : 1);
+ }
+ }
+
+ if (bitmap_count) {
+ bitmap >>= (8 - bitmap_count);
+ if (scheme.bitmap_inversed)
+ bitmap = swap_bits(bitmap);
+ comp[bitmap_ptr] = bitmap;
+ if (scheme.sixteen_bits) {
+ comp[bitmap_ptr + 1] = 0;
+ }
+ } else {
+ comp_ptr--;
+ }
+
+ if (delta) {
+ *delta = (bitmap_count ? 8 - bitmap_count : 0);
+ }
+
+ *l = comp_ptr;
+ return comp;
+}
+
+void lzss::lzss_comp(Handle * f_source, Handle * f_cible, int * delta) {
+ int length = f_source->GetSize(), l;
+ unsigned char * r = (unsigned char *) malloc(length), * c;
+
+ f_source->read(r, length);
+ l = length;
+ c = lzss_memcomp(r, &l, delta);
+ if (delta) {
+ length += *delta;
+ }
+ f_cible->write(&length, 4);
+ if (delta) {
+ length -= *delta;
+ }
+ f_cible->write(c, l);
+ free(c);
+ free(r);
+}
+
+void lzss::change_scheme(scheme_t new_scheme) {
+ scheme = new_scheme;
+ compute_limits();
+}
+
+lzss::scheme_t lzss::get_scheme() {
+ return scheme;
+}
diff --git a/lib/mips.cpp b/lib/mips.cpp index 1378227..05a1201 100644 --- a/lib/mips.cpp +++ b/lib/mips.cpp @@ -1,1068 +1,1068 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002-2003 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: mips.cpp,v 1.3 2004-01-03 15:04:47 pixel Exp $ */ - -#include "mips.h" - -/* Code HIGHLY ripped off^W^W inspired from PCSX. */ - -#if 1 -char * registers[] = { - "0", "at", "v0", "v1", "a0", "a1", "a2", "a3", - "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", - "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", - "t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra", -}; -#else -char * registers[] = { - "00", "01", "02", "03", "04", "05", "06", "07", - "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", - "10", "11", "12", "13", "14", "15", "16", "17", - "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", -}; -#endif - -char * CP0registers[] = { - "Index" , "Random" , "EntryLo0", "EntryLo1", "Context" , "PageMask" , "Wired" , "*Check me*", - "BadVAddr" , "Count" , "EntryHi" , "Compare" , "Status" , "Cause" , "ExceptPC" , "PRevID" , - "Config" , "LLAddr" , "WatchLo" , "WatchHi" , "XContext", "*RES*" , "*RES*" , "*RES*" , - "*RES*" , "*RES* " , "PErr" , "CacheErr", "TagLo" , "TagHi" , "ErrorEPC" , "*RES*" }; - -typedef void (*TdisR3000AF)(TDis *, Uint32 code, Uint32 pc); - -// These macros are used to assemble the disassembler functions -#define MakeDisF(fn, b) \ - static void fn(TDis * d, Uint32 code, Uint32 pc) { \ - d->pc = pc; \ - b; \ - } - -#define _Funct_ ((code ) & 0x3F) // The funct part of the instruction register -#define _Rd_ ((code >> 11) & 0x1F) // The rd part of the instruction register -#define _Rt_ ((code >> 16) & 0x1F) // The rt part of the instruction register -#define _Rs_ ((code >> 21) & 0x1F) // The rs part of the instruction register -#define _Sa_ ((code >> 6) & 0x1F) // The sa part of the instruction register -#define _Im_ ( code & 0xFFFF) // The immediate part of the instruction register - // The signed immediate part of the instruction register -#define _sIm_ (code & 0x8000 ? - (((~code) & 0x7FFF) + 1) : ( code & 0x7FFF)) - -#define _Target_ (0x80000000 + ((code & 0x03ffffff) * 4)) -#define _Branch_ (pc + 4 + ((short)_Im_ * 4)) -#define _OfB_ _Im_, _nRs_ - -#define dName(n) { d->Name(n); } -#define dGPR(i) { d->PushGPReg(i); } -#define dCP0(i) { d->PushCPReg(i); } -#define dImm() { d->PushImm(_Im_); } -#define dTarget() { d->PushTarget(_Target_); } -#define dSa() { d->PushSa(_Sa_); } -#if 0 -#define dOfB() { \ - Uint32 pcode = d->getmem()->Read32(pc - 4); \ - if ((((pcode >> 16) & 0x1F) == _Rs_) && ((pcode >> 26) == 0xf)) { \ - Uint32 full; \ - Uint16 lower; \ - int16 slower; \ - lower = _Im_; \ - slower = *((int16 *) &lower); \ - \ - full = ((pcode & 0xffff) << 16) + slower; \ - \ - d->PushOfB(_Rs_, full, width); \ - \ - dMemRefer(full, width); \ - } else { \ - d->PushOfB(_Rs_, _Im_, width); \ - } \ -} -#else -#define dOfB() { \ - d->PushOfB(_Rs_, _Im_, width); \ -} -#endif -#define dOffset() { \ - d->PushOffset(_Branch_); \ -} -// printf(" ; Maybe RefTo %8.8lX", offset); -#define dFull(full) { \ - d->PushFull(full); \ - d->Comment("MaybeRefTo..."); \ -} - -#define sep - -#define dInvalid() { \ - d->SetTag(pc, CODE, false); \ - d->SetTag(pc, STOP, true); \ - d->Invalid(); \ -} - -#define dSuspect() { \ - d->Suspect(); \ - d->Comment("Suspect!"); \ -} -#if 0 // with OfB... -// printf(" ; RefTo %8.8lX - %i bits", offset, width); -#define dMemRefer(offset, width) { \ - d->PushMemref(offset, width); \ - d->Comment("RefTo..."); \ -} -#endif - -#define Invalidate(reg) { \ - if (!reg) \ - dSuspect(); \ -} - -#define SetReg(reg, val) { \ - if (!reg) \ - dSuspect(); \ -} - -#define MarkFunction(target) { \ - d->add_function(target); \ -} - -#define Branch(branch) { \ - d->add_branch(branch); \ -} - -#define Jump(target) { \ - d->add_jump(target); \ -} - -#define Stop(target) { \ - d->SetTag(target, STOP, true); \ -} - -/********************************************************* -* Arithmetic with immediate operand * -* Format: OP rt, rs, immediate * -*********************************************************/ - -MakeDisF(disADDI, - dName("addi"); - - dGPR(_Rt_); sep; - if (_Rt_ != _Rs_) { - dGPR(_Rs_); sep; - } - dImm(); - - Invalidate(_Rt_); - - d->Comment("Add immediate"); -) - -MakeDisF(disADDIU, - if (!_Rs_) { - dName("li"); - - dGPR(_Rt_); sep; - dImm(); - - Uint32 full; - int32 sfull; - Uint16 lower; - int16 slower; - lower = _Im_; - slower = *((int16 *) &lower); - - sfull = slower; - full = *((Uint32 *) &sfull); - - SetReg(_Rt_, full); - - d->Comment("Load immediate"); - } else { - Uint32 pcode = d->getmem()->Read32(pc - 4); - if ((((pcode >> 16) & 0x1F) == _Rt_) && (_Rt_ == _Rs_) && ((pcode >> 26) == 0xf)) { - Uint32 full; - Uint16 lower; - int16 slower; - lower = _Im_; - slower = *((int16 *) &lower); - - full = ((pcode & 0xffff) << 16) + slower; - - dName("li"); - dGPR(_Rt_); sep; - dFull(full); - SetReg(_Rt_, full); - d->Comment("Load immediate (aggregate)"); - } else { - dName("addiu"); - - dGPR(_Rt_); sep; - if (_Rt_ != _Rs_) { - dGPR(_Rs_); sep; - } - dImm(); - - Invalidate(_Rt_); - - d->Comment("Add immediate"); - } - } -) - -MakeDisF(disANDI, - dName("andi"); - - dGPR(_Rt_); sep; - if (_Rt_ != _Rs_) { - dGPR(_Rs_); sep; - } - dImm(); - - Invalidate(_Rt_); - - d->Comment("And immediate"); -) - -MakeDisF(disORI, - if (!_Rs_) { - dName("liu"); - - dGPR(_Rt_); sep; - dImm(); - SetReg(_Rt_, _Im_); - - d->Comment("Load immediate without sign extension"); - } else { - dName("ori"); - - dGPR(_Rt_); sep; - if (_Rt_ != _Rs_) { - dGPR(_Rs_); sep; - } - dImm(); - Invalidate(_Rt_); - d->Comment("Or immediate"); - } -) - -MakeDisF(disSLTI, - dName("slti"); - - dGPR(_Rt_); sep; - if (_Rt_ != _Rs_) { - dGPR(_Rs_); sep; - } - dImm(); - - Invalidate(_Rt_); - - d->Comment(registers[_Rt_] + String(" = ") + registers[_Rs_] + " < immediate ? 1 : 0 (signed)"); -) - -MakeDisF(disSLTIU, - dName("sltiu"); - - dGPR(_Rt_); sep; - if (_Rt_ != _Rs_) { - dGPR(_Rs_); sep; - } - dImm(); - - Invalidate(_Rt_); - - d->Comment(registers[_Rt_] + String(" = ") + registers[_Rs_] + " < immediate ? 1 : 0 (unsigned)"); -) - -MakeDisF(disXORI, - dName("xori"); - - dGPR(_Rt_); sep; - if (_Rt_ != _Rs_) { - dGPR(_Rs_); sep; - } - dImm(); - - Invalidate(_Rt_); - - d->Comment("XOr immediate"); -) - -/********************************************************* -* Register arithmetic * -* Format: OP rd, rs, rt * -*********************************************************/ -MakeDisF(disADD, - dName("add"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rs_) { - dGPR(_Rs_); sep; - } - dGPR(_Rt_); - - Invalidate(_Rt_); - - d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_] + " + " + registers[_Rt_]); -) - -MakeDisF(disADDU, - if (!_Rt_) { - dName("move"); - - dGPR(_Rd_); sep; - dGPR(_Rs_); - if (_Rs_) { - Invalidate(_Rd_); - } else { - SetReg(_Rd_, 0); - } - d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_]); - } else { - dName("addu"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rs_) { - dGPR(_Rs_); sep; - } - dGPR(_Rt_); - Invalidate(_Rd_); - d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_] + " + " + registers[_Rt_]); - } -) - -MakeDisF(disAND, - dName("and"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rs_) { - dGPR(_Rs_); sep; - } - dGPR(_Rt_); - Invalidate(_Rd_); - d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_] + " & " + registers[_Rt_]); -) - -MakeDisF(disNOR, - dName("nor"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rs_) { - dGPR(_Rs_); sep; - } - dGPR(_Rt_); - Invalidate(_Rd_); - d->Comment(String(registers[_Rd_]) + " = ~(" + registers[_Rs_] + " & " + registers[_Rt_] + ")"); -) - -MakeDisF(disOR, - dName("or"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rs_) { - dGPR(_Rs_); sep; - } - dGPR(_Rt_); - Invalidate(_Rd_); - d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_] + " | " + registers[_Rt_]); -) - -MakeDisF(disSLT, - dName("slt"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rs_) { - dGPR(_Rs_); sep; - } - dGPR(_Rt_); - Invalidate(_Rd_); - d->Comment(registers[_Rd_] + String(" = ") + registers[_Rs_] + " < " + registers[_Rt_] + " ? 1 : 0 (signed)"); -) - -MakeDisF(disSLTU, - dName("sltu"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rs_) { - dGPR(_Rs_); sep; - } - dGPR(_Rt_); - Invalidate(_Rd_); - d->Comment(registers[_Rd_] + String(" = ") + registers[_Rs_] + " < " + registers[_Rt_] + " ? 1 : 0 (unsigned)"); -) - -MakeDisF(disSUB, - dName("sub"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rs_) { - dGPR(_Rs_); sep; - } - dGPR(_Rt_); - Invalidate(_Rd_); - d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_] + " - " + registers[_Rt_]); -) - -MakeDisF(disSUBU, - dName("subu"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rs_) { - dGPR(_Rs_); sep; - } - dGPR(_Rt_); - Invalidate(_Rd_); - d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_] + " - " + registers[_Rt_]); -) - -MakeDisF(disXOR, - dName("xor"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rs_) { - dGPR(_Rs_); sep; - } - dGPR(_Rt_); - Invalidate(_Rd_); - d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_] + " ^ " + registers[_Rt_]); -) - -/********************************************************* -* Register arithmetic & Register trap logic * -* Format: OP rs, rt * -*********************************************************/ -MakeDisF(disDIV, - dName("div"); - - dGPR(_Rs_); sep; - dGPR(_Rt_); - - String c1 = String(registers[_Rs_]) + " / " + registers[_Rt_]; - String c2 = String(registers[_Rs_]) + " %% " + registers[_Rt_]; - - d->Comment("lo = " + c1 + "; hi = " + c2); -) - -MakeDisF(disDIVU, - dName("divu"); - - dGPR(_Rs_); sep; - dGPR(_Rt_); - - d->Comment(String("lo = " ) + registers[_Rs_] + " / " + registers[_Rt_] + "; hi = " + registers[_Rs_] + " % " + registers[_Rt_]); -) - -MakeDisF(disMULT, - dName("mult"); - - dGPR(_Rs_); sep; - dGPR(_Rt_); - - d->Comment(String("hilo = ") + registers[_Rs_] + " * " + registers[_Rt_]); -) - -MakeDisF(disMULTU, - dName("multu"); - - dGPR(_Rs_); sep; - dGPR(_Rt_); - - d->Comment(String("hilo = ") + registers[_Rs_] + " * " + registers[_Rt_]); -) - -/********************************************************* -* Register branch logic * -* Format: OP rs, offset * -*********************************************************/ -MakeDisF(disBGEZ, - dName("bgez"); - - dGPR(_Rs_); sep; - dOffset(); - Branch(_Branch_); - d->Comment("Branch if " + String(registers[_Rs_]) + " >= 0"); -) - -MakeDisF(disBGEZAL, - dName("bgezal"); - - dGPR(_Rs_); sep; - dOffset(); - Branch(_Branch_); - d->Comment("Branch and link if " + String(registers[_Rs_]) + " >= 0"); -) - -MakeDisF(disBGTZ, - dName("bgtz"); - - dGPR(_Rs_); sep; - dOffset(); - Branch(_Branch_); - d->Comment("Branch if " + String(registers[_Rs_]) + " > 0"); -) - -MakeDisF(disBLEZ, - dName("blez"); - - dGPR(_Rs_); sep; - dOffset(); - Branch(_Branch_); - d->Comment("Branch if " + String(registers[_Rs_]) + " <= 0"); -) - -MakeDisF(disBLTZ, - dName("bltz"); - - dGPR(_Rs_); sep; - dOffset(); - Branch(_Branch_); - d->Comment("Branch if " + String(registers[_Rs_]) + " < 0"); -) - -MakeDisF(disBLTZAL, - dName("bltzal"); - - dGPR(_Rs_); sep; - dOffset(); - Branch(_Branch_); - d->Comment("Branch and link if " + String(registers[_Rs_]) + " <= 0"); -) - -/********************************************************* -* Shift arithmetic with constant shift * -* Format: OP rd, rt, sa * -*********************************************************/ -MakeDisF(disSLL, - if ((!_Rd_) && (!_Rt_)) { - dName("nop"); - if (code) { - dSuspect(); - } - } else { - dName("sll"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rt_) { - dGPR(_Rt_); sep; - } - dSa(); - Invalidate(_Rd_); - d->Comment(String(registers[_Rd_]) + " = " + registers[_Rt_] + " << immediate"); - } -) - -MakeDisF(disSRA, - dName("sra"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rt_) { - dGPR(_Rt_); sep; - } - dSa(); - Invalidate(_Rd_); - d->Comment(String(registers[_Rd_]) + " = " + registers[_Rt_] + " >> immediate (arithmetic)"); -) - -MakeDisF(disSRL, - dName("srl"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rt_) { - dGPR(_Rt_); sep; - } - dSa(); - Invalidate(_Rd_); - d->Comment(String(registers[_Rd_]) + " = " + registers[_Rt_] + " >> immediate (logical)"); -) - -/********************************************************* -* Shift arithmetic with variant register shift * -* Format: OP rd, rt, rs * -*********************************************************/ -MakeDisF(disSLLV, - dName("sllv"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rt_) { - dGPR(_Rt_); sep; - } - dGPR(_Rs_); - Invalidate(_Rd_); - d->Comment(String(registers[_Rd_]) + " = " + registers[_Rt_] + " << " + registers[_Rs_]); -) - -MakeDisF(disSRAV, - dName("srav"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rt_) { - dGPR(_Rt_); sep; - } - dGPR(_Rs_); - Invalidate(_Rd_); - d->Comment(String(registers[_Rd_]) + " = " + registers[_Rt_] + " >> " + registers[_Rs_] + " (arithmetic)"); -) - -MakeDisF(disSRLV, - dName("srlv"); - - dGPR(_Rd_); sep; - if (_Rd_ != _Rt_) { - dGPR(_Rt_); sep; - } - dGPR(_Rs_); - Invalidate(_Rd_); - d->Comment(String(registers[_Rd_]) + " = " + registers[_Rt_] + " >> " + registers[_Rs_] + " (logical)"); -) - -/********************************************************* -* Load higher 16 bits of the first word in GPR with imm * -* Format: OP rt, immediate * -*********************************************************/ -MakeDisF(disLUI, - dName("lui"); - - dGPR(_Rt_); sep; - dImm(); - - Invalidate(_Rt_); - - d->Comment("Load upper immediate"); -) - -/********************************************************* -* Move from HI/LO to GPR * -* Format: OP rd * -*********************************************************/ -MakeDisF(disMFHI, - dName("mfhi"); - - dGPR(_Rd_); - Invalidate(_Rd_); - - d->Comment(String(registers[_Rd_]) + " = hi"); -) - -MakeDisF(disMFLO, - dName("mflo"); - - dGPR(_Rd_); - Invalidate(_Rd_); - - d->Comment(String(registers[_Rd_]) + " = lo"); -) - -/********************************************************* -* Move from GPR to HI/LO * -* Format: OP rd * -*********************************************************/ -MakeDisF(disMTHI, - dName("mthi"); - - dGPR(_Rd_); - - d->Comment("hi = " + String(registers[_Rd_])); -) - -MakeDisF(disMTLO, - dName("mtlo"); - - dGPR(_Rd_); - - d->Comment("lo = " + String(registers[_Rd_])); -) - -/********************************************************* -* Special purpose instructions * -* Format: OP * -*********************************************************/ -MakeDisF(disBREAK, - dName("break"); - - Stop(pc + 4); - - d->Comment("Stops the machine"); -) -MakeDisF(disRFE, dName("rfe")) - -MakeDisF(disSYSCALL, - int syscall; - dName("syscall"); - syscall = code & 0xfffff; - - d->Comment(String("Syscall number ") + syscall); -) - -MakeDisF(disHLE, dName("hle")) - -MakeDisF(disRTPS, dName("rtps")) -MakeDisF(disOP , dName("op")) -MakeDisF(disNCLIP, dName("nclip")) -MakeDisF(disDPCS, dName("dpcs")) -MakeDisF(disINTPL, dName("intpl")) -MakeDisF(disMVMVA, dName("mvmva")) -MakeDisF(disNCDS , dName("ncds")) -MakeDisF(disCDP , dName("cdp")) -MakeDisF(disNCDT , dName("ncdt")) -MakeDisF(disNCCS , dName("nccs")) -MakeDisF(disCC , dName("cc")) -MakeDisF(disNCS , dName("ncs")) -MakeDisF(disNCT , dName("nct")) -MakeDisF(disSQR , dName("sqr")) -MakeDisF(disDCPL , dName("dcpl")) -MakeDisF(disDPCT , dName("dpct")) -MakeDisF(disAVSZ3, dName("avsz3")) -MakeDisF(disAVSZ4, dName("avsz4")) -MakeDisF(disRTPT , dName("rtpt")) -MakeDisF(disGPF , dName("gpf")) -MakeDisF(disGPL , dName("gpl")) -MakeDisF(disNCCT , dName("ncct")) - -MakeDisF(disMFC2, dName("mfc2"); dGPR(_Rt_); Invalidate(_Rt_); ) -MakeDisF(disCFC2, dName("cfc2"); dGPR(_Rt_); Invalidate(_Rt_); ) -MakeDisF(disMTC2, dName("mtc2"); dGPR(_Rt_);) -MakeDisF(disCTC2, dName("ctc2"); dGPR(_Rt_);) - -/********************************************************* -* Register branch logic * -* Format: OP rs, rt, offset * -*********************************************************/ -MakeDisF(disBEQ, - if ((!_Rt_) && (!_Rs_)) { - dName("b"); - - dOffset(); - Branch(_Branch_); - Stop(pc + 8); - - d->Comment("Branch always"); - } - if (!_Rt_) { - dName("bez"); - - dGPR(_Rs_); sep; - dOffset(); - Branch(_Branch_); - - d->Comment(String("Branch if ") + registers[_Rs_] + " == 0"); - } else { - dName("beq"); - - dGPR(_Rs_); sep; - dGPR(_Rt_); sep; - dOffset(); - Branch(_Branch_); - - d->Comment(String("Branch if ") + registers[_Rs_] + " == " + registers[_Rt_]); - } -) - -MakeDisF(disBNE, - if (!_Rt_) { - dName("bnz"); - - dGPR(_Rs_); sep; - dOffset(); - Branch(_Branch_); - - d->Comment(String("Branch if ") + registers[_Rs_] + " != 0"); - } else { - dName("bne"); - - dGPR(_Rs_); sep; - dGPR(_Rt_); sep; - dOffset(); - Branch(_Branch_); - - d->Comment(String("Branch if ") + registers[_Rs_] + " != " + registers[_Rt_]); - } -) - -/********************************************************* -* Jump to target * -* Format: OP target * -*********************************************************/ -MakeDisF(disJ, - dName("j"); - - dTarget(); - Jump(_Target_); - Stop(pc + 8); - - d->Comment("Jump always"); -) - -MakeDisF(disJAL, - dName("jal"); - - dTarget(); - Invalidate(Rra); - MarkFunction(_Target_); - - d->Comment("Jump and link (function call)"); -) - -/********************************************************* -* Register jump * -* Format: OP rs, rd * -*********************************************************/ -MakeDisF(disJR, - dName("jr"); - dGPR(_Rs_); - Stop(pc + 8); - - d->Comment("Jump register"); -) - -MakeDisF(disJALR, - dName("jalr"); - - dGPR(_Rs_); - - if ((_Rd_) != Rra) { - sep; dGPR(_Rd_); - } - - Invalidate(_Rd_); - - d->Comment("Jump and link register (function call)"); -) - -/********************************************************* -* Load and store for GPR * -* Format: OP rt, offset(base) * -*********************************************************/ -MakeDisF(disLB, - int width = 8; - dName("lb"); - - dGPR(_Rt_); sep; - dOfB(); - - Invalidate(_Rt_); - d->Comment("Load signed byte"); -) - -MakeDisF(disLBU, - int width = 8; - dName("lbu"); - - dGPR(_Rt_); sep; - dOfB(); - - Invalidate(_Rt_); - d->Comment("Load unsigned byte"); -) - -MakeDisF(disLH, - int width = 16; - dName("lh"); - - dGPR(_Rt_); sep; - dOfB(); - - Invalidate(_Rt_); - d->Comment("Load signed half"); -) - -MakeDisF(disLHU, - int width = 16; - dName("lhu"); - - dGPR(_Rt_); sep; - dOfB(); - - Invalidate(_Rt_); - d->Comment("Load unsigned half"); -) - -MakeDisF(disLW, - int width = 32; - dName("lw"); - - dGPR(_Rt_); sep; - dOfB(); - - Invalidate(_Rt_); - d->Comment("Load word"); -) - -MakeDisF(disLWL, - int width = 32; - dName("lwl"); - - dGPR(_Rt_); sep; - dOfB(); - - Invalidate(_Rt_); - d->Comment("Load word left"); -) - -MakeDisF(disLWR, - int width = 32; - dName("lwr"); - - dGPR(_Rt_); sep; - dOfB(); - - Invalidate(_Rt_); - d->Comment("Load word right"); -) - -MakeDisF(disLWC2, - int width = 32; - dName("lwc2"); - - dCP0(_Rt_); sep; - dOfB(); -) - -MakeDisF(disSB, - int width = 8; - dName("sb"); - - dGPR(_Rt_); sep; - dOfB(); - d->Comment("Store byte"); -) - -MakeDisF(disSH, - int width = 16; - dName("sh"); - - dGPR(_Rt_); sep; - dOfB(); - d->Comment("Store half"); -) - -MakeDisF(disSW, - int width = 32; - dName("sw"); - - dGPR(_Rt_); sep; - dOfB(); - d->Comment("Store word"); -) - -MakeDisF(disSWL, - int width = 32; - dName("swl"); - - dGPR(_Rt_); sep; - dOfB(); - d->Comment("Store word left"); -) - -MakeDisF(disSWR, - int width = 32; - dName("swr"); - - dGPR(_Rt_); sep; - dOfB(); - d->Comment("Store word right"); -) - -MakeDisF(disSWC2, - int width = 32; - dName("swc2"); - - dGPR(_Rt_); sep; - dOfB(); -) - -/********************************************************* -* Moves between GPR and COPx * -* Format: OP rt, fs * -*********************************************************/ -MakeDisF(disMFC0, dName("mfc0"); dGPR(_Rt_); sep; dCP0(_Rd_); Invalidate(_Rt_);) -MakeDisF(disMTC0, dName("mtc0"); dCP0(_Rd_); sep; dGPR(_Rt_);) -MakeDisF(disCFC0, dName("cfc0"); dGPR(_Rt_); sep; dCP0(_Rd_); Invalidate(_Rt_);) -MakeDisF(disCTC0, dName("ctc0"); dCP0(_Rd_); sep; dGPR(_Rt_);) - -/********************************************************* -* Unknow instruction (would generate an exception) * -* Format: ? * -*********************************************************/ -MakeDisF(disNULL, - dName("*** Bad OP ***"); - dInvalid(); -) - - -TdisR3000AF disR3000A_SPECIAL[] = { // Subset of disSPECIAL - disSLL , disNULL , disSRL , disSRA , disSLLV , disNULL , disSRLV , disSRAV , - disJR , disJALR , disNULL, disNULL, disSYSCALL, disBREAK , disNULL , disNULL , - disMFHI, disMTHI , disMFLO, disMTLO, disNULL , disNULL , disNULL , disNULL , - disMULT, disMULTU, disDIV , disDIVU, disNULL , disNULL , disNULL , disNULL , - disADD , disADDU , disSUB , disSUBU, disAND , disOR , disXOR , disNOR , - disNULL, disNULL , disSLT , disSLTU, disNULL , disNULL , disNULL , disNULL , - disNULL, disNULL , disNULL, disNULL, disNULL , disNULL , disNULL , disNULL , - disNULL, disNULL , disNULL, disNULL, disNULL , disNULL , disNULL , disNULL}; - -MakeDisF(disSPECIAL, disR3000A_SPECIAL[_Funct_](d, code, pc)) - -TdisR3000AF disR3000A_BCOND[] = { // Subset of disBCOND - disBLTZ , disBGEZ , disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, - disNULL , disNULL , disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, - disBLTZAL, disBGEZAL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, - disNULL , disNULL , disNULL, disNULL, disNULL, disNULL, disNULL, disNULL}; - -MakeDisF(disBCOND, disR3000A_BCOND[_Rt_](d, code, pc)) - -TdisR3000AF disR3000A_COP0[] = { // Subset of disCOP0 - disMFC0, disNULL, disCFC0, disNULL, disMTC0, disNULL, disCTC0, disNULL, - disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, - disRFE , disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, - disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL}; - -MakeDisF(disCOP0, disR3000A_COP0[_Rs_](d, code, pc)) - -TdisR3000AF disR3000A_BASIC[] = { // Subset of disBASIC (based on rs) - disMFC2, disNULL, disCFC2, disNULL, disMTC2, disNULL, disCTC2, disNULL, - disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, - disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, - disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL}; - -MakeDisF(disBASIC, disR3000A_BASIC[_Rs_](d, code, pc)) - -TdisR3000AF disR3000A_COP2[] = { // Subset of disR3000F_COP2 (based on funct) - disBASIC, disRTPS , disNULL , disNULL , disNULL, disNULL , disNCLIP, disNULL, - disNULL , disNULL , disNULL , disNULL , disOP , disNULL , disNULL , disNULL, - disDPCS , disINTPL, disMVMVA, disNCDS , disCDP , disNULL , disNCDT , disNULL, - disNULL , disNULL , disNULL , disNCCS , disCC , disNULL , disNCS , disNULL, - disNCT , disNULL , disNULL , disNULL , disNULL, disNULL , disNULL , disNULL, - disSQR , disDCPL , disDPCT , disNULL , disNULL, disAVSZ3, disAVSZ4, disNULL, - disRTPT , disNULL , disNULL , disNULL , disNULL, disNULL , disNULL , disNULL, - disNULL , disNULL , disNULL , disNULL , disNULL, disGPF , disGPL , disNCCT }; - -MakeDisF(disCOP2, disR3000A_COP2[_Funct_](d, code, pc)) - -TdisR3000AF disR3000A[] = { - disSPECIAL , disBCOND , disJ , disJAL , disBEQ , disBNE , disBLEZ , disBGTZ , - disADDI , disADDIU , disSLTI , disSLTIU, disANDI, disORI , disXORI , disLUI , - disCOP0 , disNULL , disCOP2 , disNULL , disNULL, disNULL, disNULL , disNULL , - disNULL , disNULL , disNULL , disNULL , disNULL, disNULL, disNULL , disNULL , - disLB , disLH , disLWL , disLW , disLBU , disLHU , disLWR , disNULL , - disSB , disSH , disSWL , disSW , disNULL, disNULL, disSWR , disNULL , - disNULL , disNULL , disLWC2 , disNULL , disNULL, disNULL, disNULL , disNULL , - disNULL , disNULL , disSWC2 , disHLE , disNULL, disNULL, disNULL , disNULL }; - -//MakeDisFg(disR3000AF, disR3000A[code >> 26](code, pc)) - -void decode(TDis * d, Uint32 pc) { - Uint32 code = d->getmem()->Read32(pc); - disR3000A[code >> 26](d, code, pc); -} +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: mips.cpp,v 1.4 2004-11-27 21:44:48 pixel Exp $ */
+
+#include "mips.h"
+
+/* Code HIGHLY ripped off^W^W inspired from PCSX. */
+
+#if 1
+char * registers[] = {
+ "0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
+ "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
+ "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
+ "t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra",
+};
+#else
+char * registers[] = {
+ "00", "01", "02", "03", "04", "05", "06", "07",
+ "08", "09", "0a", "0b", "0c", "0d", "0e", "0f",
+ "10", "11", "12", "13", "14", "15", "16", "17",
+ "18", "19", "1a", "1b", "1c", "1d", "1e", "1f",
+};
+#endif
+
+char * CP0registers[] = {
+ "Index" , "Random" , "EntryLo0", "EntryLo1", "Context" , "PageMask" , "Wired" , "*Check me*",
+ "BadVAddr" , "Count" , "EntryHi" , "Compare" , "Status" , "Cause" , "ExceptPC" , "PRevID" ,
+ "Config" , "LLAddr" , "WatchLo" , "WatchHi" , "XContext", "*RES*" , "*RES*" , "*RES*" ,
+ "*RES*" , "*RES* " , "PErr" , "CacheErr", "TagLo" , "TagHi" , "ErrorEPC" , "*RES*" };
+
+typedef void (*TdisR3000AF)(TDis *, Uint32 code, Uint32 pc);
+
+// These macros are used to assemble the disassembler functions
+#define MakeDisF(fn, b) \
+ static void fn(TDis * d, Uint32 code, Uint32 pc) { \
+ d->pc = pc; \
+ b; \
+ }
+
+#define _Funct_ ((code ) & 0x3F) // The funct part of the instruction register
+#define _Rd_ ((code >> 11) & 0x1F) // The rd part of the instruction register
+#define _Rt_ ((code >> 16) & 0x1F) // The rt part of the instruction register
+#define _Rs_ ((code >> 21) & 0x1F) // The rs part of the instruction register
+#define _Sa_ ((code >> 6) & 0x1F) // The sa part of the instruction register
+#define _Im_ ( code & 0xFFFF) // The immediate part of the instruction register
+ // The signed immediate part of the instruction register
+#define _sIm_ (code & 0x8000 ? - (((~code) & 0x7FFF) + 1) : ( code & 0x7FFF))
+
+#define _Target_ (0x80000000 + ((code & 0x03ffffff) * 4))
+#define _Branch_ (pc + 4 + ((short)_Im_ * 4))
+#define _OfB_ _Im_, _nRs_
+
+#define dName(n) { d->Name(n); }
+#define dGPR(i) { d->PushGPReg(i); }
+#define dCP0(i) { d->PushCPReg(i); }
+#define dImm() { d->PushImm(_Im_); }
+#define dTarget() { d->PushTarget(_Target_); }
+#define dSa() { d->PushSa(_Sa_); }
+#if 0
+#define dOfB() { \
+ Uint32 pcode = d->getmem()->Read32(pc - 4); \
+ if ((((pcode >> 16) & 0x1F) == _Rs_) && ((pcode >> 26) == 0xf)) { \
+ Uint32 full; \
+ Uint16 lower; \
+ int16 slower; \
+ lower = _Im_; \
+ slower = *((int16 *) &lower); \
+ \
+ full = ((pcode & 0xffff) << 16) + slower; \
+ \
+ d->PushOfB(_Rs_, full, width); \
+ \
+ dMemRefer(full, width); \
+ } else { \
+ d->PushOfB(_Rs_, _Im_, width); \
+ } \
+}
+#else
+#define dOfB() { \
+ d->PushOfB(_Rs_, _Im_, width); \
+}
+#endif
+#define dOffset() { \
+ d->PushOffset(_Branch_); \
+}
+// printf(" ; Maybe RefTo %8.8lX", offset);
+#define dFull(full) { \
+ d->PushFull(full); \
+ d->Comment("MaybeRefTo..."); \
+}
+
+#define sep
+
+#define dInvalid() { \
+ d->SetTag(pc, CODE, false); \
+ d->SetTag(pc, STOP, true); \
+ d->Invalid(); \
+}
+
+#define dSuspect() { \
+ d->Suspect(); \
+ d->Comment("Suspect!"); \
+}
+#if 0 // with OfB...
+// printf(" ; RefTo %8.8lX - %i bits", offset, width);
+#define dMemRefer(offset, width) { \
+ d->PushMemref(offset, width); \
+ d->Comment("RefTo..."); \
+}
+#endif
+
+#define Invalidate(reg) { \
+ if (!reg) \
+ dSuspect(); \
+}
+
+#define SetReg(reg, val) { \
+ if (!reg) \
+ dSuspect(); \
+}
+
+#define MarkFunction(target) { \
+ d->add_function(target); \
+}
+
+#define Branch(branch) { \
+ d->add_branch(branch); \
+}
+
+#define Jump(target) { \
+ d->add_jump(target); \
+}
+
+#define Stop(target) { \
+ d->SetTag(target, STOP, true); \
+}
+
+/*********************************************************
+* Arithmetic with immediate operand *
+* Format: OP rt, rs, immediate *
+*********************************************************/
+
+MakeDisF(disADDI,
+ dName("addi");
+
+ dGPR(_Rt_); sep;
+ if (_Rt_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dImm();
+
+ Invalidate(_Rt_);
+
+ d->Comment("Add immediate");
+)
+
+MakeDisF(disADDIU,
+ if (!_Rs_) {
+ dName("li");
+
+ dGPR(_Rt_); sep;
+ dImm();
+
+ Uint32 full;
+ int32 sfull;
+ Uint16 lower;
+ int16 slower;
+ lower = _Im_;
+ slower = *((int16 *) &lower);
+
+ sfull = slower;
+ full = *((Uint32 *) &sfull);
+
+ SetReg(_Rt_, full);
+
+ d->Comment("Load immediate");
+ } else {
+ Uint32 pcode = d->getmem()->Read32(pc - 4);
+ if ((((pcode >> 16) & 0x1F) == _Rt_) && (_Rt_ == _Rs_) && ((pcode >> 26) == 0xf)) {
+ Uint32 full;
+ Uint16 lower;
+ int16 slower;
+ lower = _Im_;
+ slower = *((int16 *) &lower);
+
+ full = ((pcode & 0xffff) << 16) + slower;
+
+ dName("li");
+ dGPR(_Rt_); sep;
+ dFull(full);
+ SetReg(_Rt_, full);
+ d->Comment("Load immediate (aggregate)");
+ } else {
+ dName("addiu");
+
+ dGPR(_Rt_); sep;
+ if (_Rt_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dImm();
+
+ Invalidate(_Rt_);
+
+ d->Comment("Add immediate");
+ }
+ }
+)
+
+MakeDisF(disANDI,
+ dName("andi");
+
+ dGPR(_Rt_); sep;
+ if (_Rt_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dImm();
+
+ Invalidate(_Rt_);
+
+ d->Comment("And immediate");
+)
+
+MakeDisF(disORI,
+ if (!_Rs_) {
+ dName("liu");
+
+ dGPR(_Rt_); sep;
+ dImm();
+ SetReg(_Rt_, _Im_);
+
+ d->Comment("Load immediate without sign extension");
+ } else {
+ dName("ori");
+
+ dGPR(_Rt_); sep;
+ if (_Rt_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dImm();
+ Invalidate(_Rt_);
+ d->Comment("Or immediate");
+ }
+)
+
+MakeDisF(disSLTI,
+ dName("slti");
+
+ dGPR(_Rt_); sep;
+ if (_Rt_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dImm();
+
+ Invalidate(_Rt_);
+
+ d->Comment(registers[_Rt_] + String(" = ") + registers[_Rs_] + " < immediate ? 1 : 0 (signed)");
+)
+
+MakeDisF(disSLTIU,
+ dName("sltiu");
+
+ dGPR(_Rt_); sep;
+ if (_Rt_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dImm();
+
+ Invalidate(_Rt_);
+
+ d->Comment(registers[_Rt_] + String(" = ") + registers[_Rs_] + " < immediate ? 1 : 0 (unsigned)");
+)
+
+MakeDisF(disXORI,
+ dName("xori");
+
+ dGPR(_Rt_); sep;
+ if (_Rt_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dImm();
+
+ Invalidate(_Rt_);
+
+ d->Comment("XOr immediate");
+)
+
+/*********************************************************
+* Register arithmetic *
+* Format: OP rd, rs, rt *
+*********************************************************/
+MakeDisF(disADD,
+ dName("add");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dGPR(_Rt_);
+
+ Invalidate(_Rt_);
+
+ d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_] + " + " + registers[_Rt_]);
+)
+
+MakeDisF(disADDU,
+ if (!_Rt_) {
+ dName("move");
+
+ dGPR(_Rd_); sep;
+ dGPR(_Rs_);
+ if (_Rs_) {
+ Invalidate(_Rd_);
+ } else {
+ SetReg(_Rd_, 0);
+ }
+ d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_]);
+ } else {
+ dName("addu");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dGPR(_Rt_);
+ Invalidate(_Rd_);
+ d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_] + " + " + registers[_Rt_]);
+ }
+)
+
+MakeDisF(disAND,
+ dName("and");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dGPR(_Rt_);
+ Invalidate(_Rd_);
+ d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_] + " & " + registers[_Rt_]);
+)
+
+MakeDisF(disNOR,
+ dName("nor");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dGPR(_Rt_);
+ Invalidate(_Rd_);
+ d->Comment(String(registers[_Rd_]) + " = ~(" + registers[_Rs_] + " & " + registers[_Rt_] + ")");
+)
+
+MakeDisF(disOR,
+ dName("or");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dGPR(_Rt_);
+ Invalidate(_Rd_);
+ d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_] + " | " + registers[_Rt_]);
+)
+
+MakeDisF(disSLT,
+ dName("slt");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dGPR(_Rt_);
+ Invalidate(_Rd_);
+ d->Comment(registers[_Rd_] + String(" = ") + registers[_Rs_] + " < " + registers[_Rt_] + " ? 1 : 0 (signed)");
+)
+
+MakeDisF(disSLTU,
+ dName("sltu");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dGPR(_Rt_);
+ Invalidate(_Rd_);
+ d->Comment(registers[_Rd_] + String(" = ") + registers[_Rs_] + " < " + registers[_Rt_] + " ? 1 : 0 (unsigned)");
+)
+
+MakeDisF(disSUB,
+ dName("sub");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dGPR(_Rt_);
+ Invalidate(_Rd_);
+ d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_] + " - " + registers[_Rt_]);
+)
+
+MakeDisF(disSUBU,
+ dName("subu");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dGPR(_Rt_);
+ Invalidate(_Rd_);
+ d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_] + " - " + registers[_Rt_]);
+)
+
+MakeDisF(disXOR,
+ dName("xor");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rs_) {
+ dGPR(_Rs_); sep;
+ }
+ dGPR(_Rt_);
+ Invalidate(_Rd_);
+ d->Comment(String(registers[_Rd_]) + " = " + registers[_Rs_] + " ^ " + registers[_Rt_]);
+)
+
+/*********************************************************
+* Register arithmetic & Register trap logic *
+* Format: OP rs, rt *
+*********************************************************/
+MakeDisF(disDIV,
+ dName("div");
+
+ dGPR(_Rs_); sep;
+ dGPR(_Rt_);
+
+ String c1 = String(registers[_Rs_]) + " / " + registers[_Rt_];
+ String c2 = String(registers[_Rs_]) + " %% " + registers[_Rt_];
+
+ d->Comment("lo = " + c1 + "; hi = " + c2);
+)
+
+MakeDisF(disDIVU,
+ dName("divu");
+
+ dGPR(_Rs_); sep;
+ dGPR(_Rt_);
+
+ d->Comment(String("lo = " ) + registers[_Rs_] + " / " + registers[_Rt_] + "; hi = " + registers[_Rs_] + " % " + registers[_Rt_]);
+)
+
+MakeDisF(disMULT,
+ dName("mult");
+
+ dGPR(_Rs_); sep;
+ dGPR(_Rt_);
+
+ d->Comment(String("hilo = ") + registers[_Rs_] + " * " + registers[_Rt_]);
+)
+
+MakeDisF(disMULTU,
+ dName("multu");
+
+ dGPR(_Rs_); sep;
+ dGPR(_Rt_);
+
+ d->Comment(String("hilo = ") + registers[_Rs_] + " * " + registers[_Rt_]);
+)
+
+/*********************************************************
+* Register branch logic *
+* Format: OP rs, offset *
+*********************************************************/
+MakeDisF(disBGEZ,
+ dName("bgez");
+
+ dGPR(_Rs_); sep;
+ dOffset();
+ Branch(_Branch_);
+ d->Comment("Branch if " + String(registers[_Rs_]) + " >= 0");
+)
+
+MakeDisF(disBGEZAL,
+ dName("bgezal");
+
+ dGPR(_Rs_); sep;
+ dOffset();
+ Branch(_Branch_);
+ d->Comment("Branch and link if " + String(registers[_Rs_]) + " >= 0");
+)
+
+MakeDisF(disBGTZ,
+ dName("bgtz");
+
+ dGPR(_Rs_); sep;
+ dOffset();
+ Branch(_Branch_);
+ d->Comment("Branch if " + String(registers[_Rs_]) + " > 0");
+)
+
+MakeDisF(disBLEZ,
+ dName("blez");
+
+ dGPR(_Rs_); sep;
+ dOffset();
+ Branch(_Branch_);
+ d->Comment("Branch if " + String(registers[_Rs_]) + " <= 0");
+)
+
+MakeDisF(disBLTZ,
+ dName("bltz");
+
+ dGPR(_Rs_); sep;
+ dOffset();
+ Branch(_Branch_);
+ d->Comment("Branch if " + String(registers[_Rs_]) + " < 0");
+)
+
+MakeDisF(disBLTZAL,
+ dName("bltzal");
+
+ dGPR(_Rs_); sep;
+ dOffset();
+ Branch(_Branch_);
+ d->Comment("Branch and link if " + String(registers[_Rs_]) + " <= 0");
+)
+
+/*********************************************************
+* Shift arithmetic with constant shift *
+* Format: OP rd, rt, sa *
+*********************************************************/
+MakeDisF(disSLL,
+ if ((!_Rd_) && (!_Rt_)) {
+ dName("nop");
+ if (code) {
+ dSuspect();
+ }
+ } else {
+ dName("sll");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rt_) {
+ dGPR(_Rt_); sep;
+ }
+ dSa();
+ Invalidate(_Rd_);
+ d->Comment(String(registers[_Rd_]) + " = " + registers[_Rt_] + " << immediate");
+ }
+)
+
+MakeDisF(disSRA,
+ dName("sra");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rt_) {
+ dGPR(_Rt_); sep;
+ }
+ dSa();
+ Invalidate(_Rd_);
+ d->Comment(String(registers[_Rd_]) + " = " + registers[_Rt_] + " >> immediate (arithmetic)");
+)
+
+MakeDisF(disSRL,
+ dName("srl");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rt_) {
+ dGPR(_Rt_); sep;
+ }
+ dSa();
+ Invalidate(_Rd_);
+ d->Comment(String(registers[_Rd_]) + " = " + registers[_Rt_] + " >> immediate (logical)");
+)
+
+/*********************************************************
+* Shift arithmetic with variant register shift *
+* Format: OP rd, rt, rs *
+*********************************************************/
+MakeDisF(disSLLV,
+ dName("sllv");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rt_) {
+ dGPR(_Rt_); sep;
+ }
+ dGPR(_Rs_);
+ Invalidate(_Rd_);
+ d->Comment(String(registers[_Rd_]) + " = " + registers[_Rt_] + " << " + registers[_Rs_]);
+)
+
+MakeDisF(disSRAV,
+ dName("srav");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rt_) {
+ dGPR(_Rt_); sep;
+ }
+ dGPR(_Rs_);
+ Invalidate(_Rd_);
+ d->Comment(String(registers[_Rd_]) + " = " + registers[_Rt_] + " >> " + registers[_Rs_] + " (arithmetic)");
+)
+
+MakeDisF(disSRLV,
+ dName("srlv");
+
+ dGPR(_Rd_); sep;
+ if (_Rd_ != _Rt_) {
+ dGPR(_Rt_); sep;
+ }
+ dGPR(_Rs_);
+ Invalidate(_Rd_);
+ d->Comment(String(registers[_Rd_]) + " = " + registers[_Rt_] + " >> " + registers[_Rs_] + " (logical)");
+)
+
+/*********************************************************
+* Load higher 16 bits of the first word in GPR with imm *
+* Format: OP rt, immediate *
+*********************************************************/
+MakeDisF(disLUI,
+ dName("lui");
+
+ dGPR(_Rt_); sep;
+ dImm();
+
+ Invalidate(_Rt_);
+
+ d->Comment("Load upper immediate");
+)
+
+/*********************************************************
+* Move from HI/LO to GPR *
+* Format: OP rd *
+*********************************************************/
+MakeDisF(disMFHI,
+ dName("mfhi");
+
+ dGPR(_Rd_);
+ Invalidate(_Rd_);
+
+ d->Comment(String(registers[_Rd_]) + " = hi");
+)
+
+MakeDisF(disMFLO,
+ dName("mflo");
+
+ dGPR(_Rd_);
+ Invalidate(_Rd_);
+
+ d->Comment(String(registers[_Rd_]) + " = lo");
+)
+
+/*********************************************************
+* Move from GPR to HI/LO *
+* Format: OP rd *
+*********************************************************/
+MakeDisF(disMTHI,
+ dName("mthi");
+
+ dGPR(_Rd_);
+
+ d->Comment("hi = " + String(registers[_Rd_]));
+)
+
+MakeDisF(disMTLO,
+ dName("mtlo");
+
+ dGPR(_Rd_);
+
+ d->Comment("lo = " + String(registers[_Rd_]));
+)
+
+/*********************************************************
+* Special purpose instructions *
+* Format: OP *
+*********************************************************/
+MakeDisF(disBREAK,
+ dName("break");
+
+ Stop(pc + 4);
+
+ d->Comment("Stops the machine");
+)
+MakeDisF(disRFE, dName("rfe"))
+
+MakeDisF(disSYSCALL,
+ int syscall;
+ dName("syscall");
+ syscall = code & 0xfffff;
+
+ d->Comment(String("Syscall number ") + syscall);
+)
+
+MakeDisF(disHLE, dName("hle"))
+
+MakeDisF(disRTPS, dName("rtps"))
+MakeDisF(disOP , dName("op"))
+MakeDisF(disNCLIP, dName("nclip"))
+MakeDisF(disDPCS, dName("dpcs"))
+MakeDisF(disINTPL, dName("intpl"))
+MakeDisF(disMVMVA, dName("mvmva"))
+MakeDisF(disNCDS , dName("ncds"))
+MakeDisF(disCDP , dName("cdp"))
+MakeDisF(disNCDT , dName("ncdt"))
+MakeDisF(disNCCS , dName("nccs"))
+MakeDisF(disCC , dName("cc"))
+MakeDisF(disNCS , dName("ncs"))
+MakeDisF(disNCT , dName("nct"))
+MakeDisF(disSQR , dName("sqr"))
+MakeDisF(disDCPL , dName("dcpl"))
+MakeDisF(disDPCT , dName("dpct"))
+MakeDisF(disAVSZ3, dName("avsz3"))
+MakeDisF(disAVSZ4, dName("avsz4"))
+MakeDisF(disRTPT , dName("rtpt"))
+MakeDisF(disGPF , dName("gpf"))
+MakeDisF(disGPL , dName("gpl"))
+MakeDisF(disNCCT , dName("ncct"))
+
+MakeDisF(disMFC2, dName("mfc2"); dGPR(_Rt_); Invalidate(_Rt_); )
+MakeDisF(disCFC2, dName("cfc2"); dGPR(_Rt_); Invalidate(_Rt_); )
+MakeDisF(disMTC2, dName("mtc2"); dGPR(_Rt_);)
+MakeDisF(disCTC2, dName("ctc2"); dGPR(_Rt_);)
+
+/*********************************************************
+* Register branch logic *
+* Format: OP rs, rt, offset *
+*********************************************************/
+MakeDisF(disBEQ,
+ if ((!_Rt_) && (!_Rs_)) {
+ dName("b");
+
+ dOffset();
+ Branch(_Branch_);
+ Stop(pc + 8);
+
+ d->Comment("Branch always");
+ }
+ if (!_Rt_) {
+ dName("bez");
+
+ dGPR(_Rs_); sep;
+ dOffset();
+ Branch(_Branch_);
+
+ d->Comment(String("Branch if ") + registers[_Rs_] + " == 0");
+ } else {
+ dName("beq");
+
+ dGPR(_Rs_); sep;
+ dGPR(_Rt_); sep;
+ dOffset();
+ Branch(_Branch_);
+
+ d->Comment(String("Branch if ") + registers[_Rs_] + " == " + registers[_Rt_]);
+ }
+)
+
+MakeDisF(disBNE,
+ if (!_Rt_) {
+ dName("bnz");
+
+ dGPR(_Rs_); sep;
+ dOffset();
+ Branch(_Branch_);
+
+ d->Comment(String("Branch if ") + registers[_Rs_] + " != 0");
+ } else {
+ dName("bne");
+
+ dGPR(_Rs_); sep;
+ dGPR(_Rt_); sep;
+ dOffset();
+ Branch(_Branch_);
+
+ d->Comment(String("Branch if ") + registers[_Rs_] + " != " + registers[_Rt_]);
+ }
+)
+
+/*********************************************************
+* Jump to target *
+* Format: OP target *
+*********************************************************/
+MakeDisF(disJ,
+ dName("j");
+
+ dTarget();
+ Jump(_Target_);
+ Stop(pc + 8);
+
+ d->Comment("Jump always");
+)
+
+MakeDisF(disJAL,
+ dName("jal");
+
+ dTarget();
+ Invalidate(Rra);
+ MarkFunction(_Target_);
+
+ d->Comment("Jump and link (function call)");
+)
+
+/*********************************************************
+* Register jump *
+* Format: OP rs, rd *
+*********************************************************/
+MakeDisF(disJR,
+ dName("jr");
+ dGPR(_Rs_);
+ Stop(pc + 8);
+
+ d->Comment("Jump register");
+)
+
+MakeDisF(disJALR,
+ dName("jalr");
+
+ dGPR(_Rs_);
+
+ if ((_Rd_) != Rra) {
+ sep; dGPR(_Rd_);
+ }
+
+ Invalidate(_Rd_);
+
+ d->Comment("Jump and link register (function call)");
+)
+
+/*********************************************************
+* Load and store for GPR *
+* Format: OP rt, offset(base) *
+*********************************************************/
+MakeDisF(disLB,
+ int width = 8;
+ dName("lb");
+
+ dGPR(_Rt_); sep;
+ dOfB();
+
+ Invalidate(_Rt_);
+ d->Comment("Load signed byte");
+)
+
+MakeDisF(disLBU,
+ int width = 8;
+ dName("lbu");
+
+ dGPR(_Rt_); sep;
+ dOfB();
+
+ Invalidate(_Rt_);
+ d->Comment("Load unsigned byte");
+)
+
+MakeDisF(disLH,
+ int width = 16;
+ dName("lh");
+
+ dGPR(_Rt_); sep;
+ dOfB();
+
+ Invalidate(_Rt_);
+ d->Comment("Load signed half");
+)
+
+MakeDisF(disLHU,
+ int width = 16;
+ dName("lhu");
+
+ dGPR(_Rt_); sep;
+ dOfB();
+
+ Invalidate(_Rt_);
+ d->Comment("Load unsigned half");
+)
+
+MakeDisF(disLW,
+ int width = 32;
+ dName("lw");
+
+ dGPR(_Rt_); sep;
+ dOfB();
+
+ Invalidate(_Rt_);
+ d->Comment("Load word");
+)
+
+MakeDisF(disLWL,
+ int width = 32;
+ dName("lwl");
+
+ dGPR(_Rt_); sep;
+ dOfB();
+
+ Invalidate(_Rt_);
+ d->Comment("Load word left");
+)
+
+MakeDisF(disLWR,
+ int width = 32;
+ dName("lwr");
+
+ dGPR(_Rt_); sep;
+ dOfB();
+
+ Invalidate(_Rt_);
+ d->Comment("Load word right");
+)
+
+MakeDisF(disLWC2,
+ int width = 32;
+ dName("lwc2");
+
+ dCP0(_Rt_); sep;
+ dOfB();
+)
+
+MakeDisF(disSB,
+ int width = 8;
+ dName("sb");
+
+ dGPR(_Rt_); sep;
+ dOfB();
+ d->Comment("Store byte");
+)
+
+MakeDisF(disSH,
+ int width = 16;
+ dName("sh");
+
+ dGPR(_Rt_); sep;
+ dOfB();
+ d->Comment("Store half");
+)
+
+MakeDisF(disSW,
+ int width = 32;
+ dName("sw");
+
+ dGPR(_Rt_); sep;
+ dOfB();
+ d->Comment("Store word");
+)
+
+MakeDisF(disSWL,
+ int width = 32;
+ dName("swl");
+
+ dGPR(_Rt_); sep;
+ dOfB();
+ d->Comment("Store word left");
+)
+
+MakeDisF(disSWR,
+ int width = 32;
+ dName("swr");
+
+ dGPR(_Rt_); sep;
+ dOfB();
+ d->Comment("Store word right");
+)
+
+MakeDisF(disSWC2,
+ int width = 32;
+ dName("swc2");
+
+ dGPR(_Rt_); sep;
+ dOfB();
+)
+
+/*********************************************************
+* Moves between GPR and COPx *
+* Format: OP rt, fs *
+*********************************************************/
+MakeDisF(disMFC0, dName("mfc0"); dGPR(_Rt_); sep; dCP0(_Rd_); Invalidate(_Rt_);)
+MakeDisF(disMTC0, dName("mtc0"); dCP0(_Rd_); sep; dGPR(_Rt_);)
+MakeDisF(disCFC0, dName("cfc0"); dGPR(_Rt_); sep; dCP0(_Rd_); Invalidate(_Rt_);)
+MakeDisF(disCTC0, dName("ctc0"); dCP0(_Rd_); sep; dGPR(_Rt_);)
+
+/*********************************************************
+* Unknow instruction (would generate an exception) *
+* Format: ? *
+*********************************************************/
+MakeDisF(disNULL,
+ dName("*** Bad OP ***");
+ dInvalid();
+)
+
+
+TdisR3000AF disR3000A_SPECIAL[] = { // Subset of disSPECIAL
+ disSLL , disNULL , disSRL , disSRA , disSLLV , disNULL , disSRLV , disSRAV ,
+ disJR , disJALR , disNULL, disNULL, disSYSCALL, disBREAK , disNULL , disNULL ,
+ disMFHI, disMTHI , disMFLO, disMTLO, disNULL , disNULL , disNULL , disNULL ,
+ disMULT, disMULTU, disDIV , disDIVU, disNULL , disNULL , disNULL , disNULL ,
+ disADD , disADDU , disSUB , disSUBU, disAND , disOR , disXOR , disNOR ,
+ disNULL, disNULL , disSLT , disSLTU, disNULL , disNULL , disNULL , disNULL ,
+ disNULL, disNULL , disNULL, disNULL, disNULL , disNULL , disNULL , disNULL ,
+ disNULL, disNULL , disNULL, disNULL, disNULL , disNULL , disNULL , disNULL};
+
+MakeDisF(disSPECIAL, disR3000A_SPECIAL[_Funct_](d, code, pc))
+
+TdisR3000AF disR3000A_BCOND[] = { // Subset of disBCOND
+ disBLTZ , disBGEZ , disNULL, disNULL, disNULL, disNULL, disNULL, disNULL,
+ disNULL , disNULL , disNULL, disNULL, disNULL, disNULL, disNULL, disNULL,
+ disBLTZAL, disBGEZAL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL,
+ disNULL , disNULL , disNULL, disNULL, disNULL, disNULL, disNULL, disNULL};
+
+MakeDisF(disBCOND, disR3000A_BCOND[_Rt_](d, code, pc))
+
+TdisR3000AF disR3000A_COP0[] = { // Subset of disCOP0
+ disMFC0, disNULL, disCFC0, disNULL, disMTC0, disNULL, disCTC0, disNULL,
+ disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL,
+ disRFE , disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL,
+ disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL};
+
+MakeDisF(disCOP0, disR3000A_COP0[_Rs_](d, code, pc))
+
+TdisR3000AF disR3000A_BASIC[] = { // Subset of disBASIC (based on rs)
+ disMFC2, disNULL, disCFC2, disNULL, disMTC2, disNULL, disCTC2, disNULL,
+ disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL,
+ disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL,
+ disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL, disNULL};
+
+MakeDisF(disBASIC, disR3000A_BASIC[_Rs_](d, code, pc))
+
+TdisR3000AF disR3000A_COP2[] = { // Subset of disR3000F_COP2 (based on funct)
+ disBASIC, disRTPS , disNULL , disNULL , disNULL, disNULL , disNCLIP, disNULL,
+ disNULL , disNULL , disNULL , disNULL , disOP , disNULL , disNULL , disNULL,
+ disDPCS , disINTPL, disMVMVA, disNCDS , disCDP , disNULL , disNCDT , disNULL,
+ disNULL , disNULL , disNULL , disNCCS , disCC , disNULL , disNCS , disNULL,
+ disNCT , disNULL , disNULL , disNULL , disNULL, disNULL , disNULL , disNULL,
+ disSQR , disDCPL , disDPCT , disNULL , disNULL, disAVSZ3, disAVSZ4, disNULL,
+ disRTPT , disNULL , disNULL , disNULL , disNULL, disNULL , disNULL , disNULL,
+ disNULL , disNULL , disNULL , disNULL , disNULL, disGPF , disGPL , disNCCT };
+
+MakeDisF(disCOP2, disR3000A_COP2[_Funct_](d, code, pc))
+
+TdisR3000AF disR3000A[] = {
+ disSPECIAL , disBCOND , disJ , disJAL , disBEQ , disBNE , disBLEZ , disBGTZ ,
+ disADDI , disADDIU , disSLTI , disSLTIU, disANDI, disORI , disXORI , disLUI ,
+ disCOP0 , disNULL , disCOP2 , disNULL , disNULL, disNULL, disNULL , disNULL ,
+ disNULL , disNULL , disNULL , disNULL , disNULL, disNULL, disNULL , disNULL ,
+ disLB , disLH , disLWL , disLW , disLBU , disLHU , disLWR , disNULL ,
+ disSB , disSH , disSWL , disSW , disNULL, disNULL, disSWR , disNULL ,
+ disNULL , disNULL , disLWC2 , disNULL , disNULL, disNULL, disNULL , disNULL ,
+ disNULL , disNULL , disSWC2 , disHLE , disNULL, disNULL, disNULL , disNULL };
+
+//MakeDisFg(disR3000AF, disR3000A[code >> 26](code, pc))
+
+void decode(TDis * d, Uint32 pc) {
+ Uint32 code = d->getmem()->Read32(pc);
+ disR3000A[code >> 26](d, code, pc);
+}
diff --git a/lib/mipsdis.cpp b/lib/mipsdis.cpp index cbaf9e3..bb6364c 100644 --- a/lib/mipsdis.cpp +++ b/lib/mipsdis.cpp @@ -1,180 +1,180 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002-2003 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: mipsdis.cpp,v 1.2 2004-01-26 15:31:55 pixel Exp $ */ - -#include "mipsdis.h" -#include "mips.h" - -TDis::TDis(mipsmem * _m) : mm(_m) { - reset(); -} - -void TDis::reset() { - invalid = false; -} - -mipsmem * TDis::getmem() { - return mm; -} - -void TDis::add_branch(Uint32 target) { - bheap.push(target); -} - -void TDis::add_jump(Uint32 target) { - jheap.push(target); -} - -void TDis::add_function(Uint32 target) { - fheap.push(target); -} - -void TDis::SetTag(Uint32 target, int tag, bool v) { - mm->SetTag(target, tag, v); -} - -void TDis::Name(const String & name) { -} - -void TDis::PushGPReg(int reg) { -} - -void TDis::PushCPReg(int reg) { -} - -void TDis::PushImm(Uint32 imm) { -} - -void TDis::PushTarget(Uint32 target) { - new refto_t(target, memdata::getmem(pc, getmem())); -} - -void TDis::PushSa(Uint32 sa) { -} - -void TDis::PushOfB(int reg, Uint32 offset, int width) { -} - -void TDis::PushOffset(Uint32 offset) { - new refto_t(offset, memdata::getmem(pc, getmem())); -} - -void TDis::PushFull(Uint32 full) { - if ((full >= 0x80000000) && (full < (0x80000000 + PSXMEM))) - new refto_t(full, memdata::getmem(pc, getmem())); -} - -void TDis::Invalid() { - invalid = true; -} - -void TDis::Suspect() { -} - -void TDis::Comment(const String & c) { -} - -Disassembler::Disassembler(mipsmem * _mm) : mm(_mm), dis(new TDis(mm)), started(false), infunction(false) { -} - -Disassembler::~Disassembler() { - delete dis; -} - -void Disassembler::crawl_code(Uint32 pc) { - Uint32 branched, ipc; - - if (pc == 0xffffffff) { - pc = mm->GetPC(); - } - - dis->bheap.push(pc); - - while (dis->bheap.size()) { - branched = pc = dis->bheap.top(); - dis->bheap.pop(); - printm(M_STATUS, "Crawling to branch %8.8lX\n", pc); - do { - if (pc >= (0x80000000 + PSXMEM)) { - dis->invalid = true; - break; - } - if (mm->GetTag(pc, CODE) || mm->GetTag(pc, INVALID)) { - pc += 4; - continue; - } - mm->SetTag(pc, CODE, true); - - printm(M_STATUS, "Working at %8.8lX\n", pc); - decode(dis, pc); - - pc += 4; - dis->reset(); - } while (!mm->GetTag(pc, STOP) && !dis->invalid); - - if (dis->invalid) { - for (ipc = branched; ipc <= pc; ipc += 4) { - mm->SetTag(ipc, CODE, false); - mm->SetTag(ipc, INVALID, true); - } - } - - if (dis->invalid && infunction) { - } - } -} - -void Disassembler::mainloop(void) { - Uint32 pc; - - infunction = false; - - // Crawl the start part. - printm(M_STATUS, "Starting crawl at %8.8lX\n", mm->GetPC()); - if (!started) - crawl_code(); - - started = true; - - // Work out all the functions. - printm(M_STATUS, "Crawling all detected functions\n"); - infunction = true; - while (dis->fheap.size()) { - pc = dis->fheap.top(); - dis->fheap.pop(); - printm(M_STATUS, "Crawling function %8.8lX\n", pc); - if (mm->GetTag(pc, CODE)) - continue; - crawl_code(pc); - } - - // Complete functions and all the detected jumps. - printm(M_STATUS, "Fixing all the remaining jumps\n"); -#if 0 - infunction = false; - while (dis->jheap.size()) { - pc = dis->jheap.top(); - dis->jheap.pop(); - if (mm->GetTag(pc, CODE)) - continue; - crawl_code(pc); - } -#endif -} +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: mipsdis.cpp,v 1.3 2004-11-27 21:44:48 pixel Exp $ */
+
+#include "mipsdis.h"
+#include "mips.h"
+
+TDis::TDis(mipsmem * _m) : mm(_m) {
+ reset();
+}
+
+void TDis::reset() {
+ invalid = false;
+}
+
+mipsmem * TDis::getmem() {
+ return mm;
+}
+
+void TDis::add_branch(Uint32 target) {
+ bheap.push(target);
+}
+
+void TDis::add_jump(Uint32 target) {
+ jheap.push(target);
+}
+
+void TDis::add_function(Uint32 target) {
+ fheap.push(target);
+}
+
+void TDis::SetTag(Uint32 target, int tag, bool v) {
+ mm->SetTag(target, tag, v);
+}
+
+void TDis::Name(const String & name) {
+}
+
+void TDis::PushGPReg(int reg) {
+}
+
+void TDis::PushCPReg(int reg) {
+}
+
+void TDis::PushImm(Uint32 imm) {
+}
+
+void TDis::PushTarget(Uint32 target) {
+ new refto_t(target, memdata::getmem(pc, getmem()));
+}
+
+void TDis::PushSa(Uint32 sa) {
+}
+
+void TDis::PushOfB(int reg, Uint32 offset, int width) {
+}
+
+void TDis::PushOffset(Uint32 offset) {
+ new refto_t(offset, memdata::getmem(pc, getmem()));
+}
+
+void TDis::PushFull(Uint32 full) {
+ if ((full >= 0x80000000) && (full < (0x80000000 + PSXMEM)))
+ new refto_t(full, memdata::getmem(pc, getmem()));
+}
+
+void TDis::Invalid() {
+ invalid = true;
+}
+
+void TDis::Suspect() {
+}
+
+void TDis::Comment(const String & c) {
+}
+
+Disassembler::Disassembler(mipsmem * _mm) : mm(_mm), dis(new TDis(mm)), started(false), infunction(false) {
+}
+
+Disassembler::~Disassembler() {
+ delete dis;
+}
+
+void Disassembler::crawl_code(Uint32 pc) {
+ Uint32 branched, ipc;
+
+ if (pc == 0xffffffff) {
+ pc = mm->GetPC();
+ }
+
+ dis->bheap.push(pc);
+
+ while (dis->bheap.size()) {
+ branched = pc = dis->bheap.top();
+ dis->bheap.pop();
+ printm(M_STATUS, "Crawling to branch %8.8lX\n", pc);
+ do {
+ if (pc >= (0x80000000 + PSXMEM)) {
+ dis->invalid = true;
+ break;
+ }
+ if (mm->GetTag(pc, CODE) || mm->GetTag(pc, INVALID)) {
+ pc += 4;
+ continue;
+ }
+ mm->SetTag(pc, CODE, true);
+
+ printm(M_STATUS, "Working at %8.8lX\n", pc);
+ decode(dis, pc);
+
+ pc += 4;
+ dis->reset();
+ } while (!mm->GetTag(pc, STOP) && !dis->invalid);
+
+ if (dis->invalid) {
+ for (ipc = branched; ipc <= pc; ipc += 4) {
+ mm->SetTag(ipc, CODE, false);
+ mm->SetTag(ipc, INVALID, true);
+ }
+ }
+
+ if (dis->invalid && infunction) {
+ }
+ }
+}
+
+void Disassembler::mainloop(void) {
+ Uint32 pc;
+
+ infunction = false;
+
+ // Crawl the start part.
+ printm(M_STATUS, "Starting crawl at %8.8lX\n", mm->GetPC());
+ if (!started)
+ crawl_code();
+
+ started = true;
+
+ // Work out all the functions.
+ printm(M_STATUS, "Crawling all detected functions\n");
+ infunction = true;
+ while (dis->fheap.size()) {
+ pc = dis->fheap.top();
+ dis->fheap.pop();
+ printm(M_STATUS, "Crawling function %8.8lX\n", pc);
+ if (mm->GetTag(pc, CODE))
+ continue;
+ crawl_code(pc);
+ }
+
+ // Complete functions and all the detected jumps.
+ printm(M_STATUS, "Fixing all the remaining jumps\n");
+#if 0
+ infunction = false;
+ while (dis->jheap.size()) {
+ pc = dis->jheap.top();
+ dis->jheap.pop();
+ if (mm->GetTag(pc, CODE))
+ continue;
+ crawl_code(pc);
+ }
+#endif
+}
diff --git a/lib/mipsdump.cpp b/lib/mipsdump.cpp index ac77b33..1eb59f7 100644 --- a/lib/mipsdump.cpp +++ b/lib/mipsdump.cpp @@ -1,207 +1,207 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002-2003 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: mipsdump.cpp,v 1.1 2004-01-03 15:04:47 pixel Exp $ */ - -#include "mipsdump.h" -#include "mips.h" - -TDump::TDump(mipsmem * mm) : TDis(mm) { - reset(); -} - -void TDump::reset() { - invalid = false; - hasbr = false; - hastg = false; - hasfc = false; - name = ""; - comments = ""; - args.clear(); -} - -void TDump::add_branch(Uint32 _tg) { - tg = _tg; - hasbr = true; -} - -void TDump::add_jump(Uint32 _tg) { - tg = _tg; - hastg = true; -} - -void TDump::add_function(Uint32 _tg) { - tg = _tg; - hasfc = true; -} - -void TDump::SetTag(Uint32 a, int t, bool v) { -} - -void TDump::Name(const String & _name) { - name = _name; -} - -void TDump::PushGPReg(int r) { - pairarg p; - - p.left = T_GPREGISTER; - p.right.v = r; - - args.push_back(p); -} - -void TDump::PushCPReg(int r) { - pairarg p; - - p.left = T_CPREGISTER; - p.right.v = r; - - args.push_back(p); -} - -void TDump::PushImm(Uint32 imm) { - pairarg p; - - p.left = T_IMM16; - p.right.v = imm; - - args.push_back(p); -} - -void TDump::PushTarget(Uint32 target) { - pairarg p; - - p.left = T_IMM32; - p.right.v = target; - - args.push_back(p); -} - -void TDump::PushSa(Uint32 sa) { - pairarg p; - - p.left = T_IMM8; - p.right.v = sa; - - args.push_back(p); -} - -void TDump::PushOfB(int reg, Uint32 offset, int width) { - pairarg p; - - p.left = T_OFB; - p.right.OfB.o = offset; - p.right.OfB.r = reg; - p.right.OfB.w = width; - - args.push_back(p); -} - -void TDump::PushOffset(Uint32 offset) { - pairarg p; - - p.left = T_IMM32; - p.right.v = offset; - - args.push_back(p); -} - -void TDump::PushFull(Uint32 full) { - pairarg p; - - p.left = T_IMM32; - p.right.v = full; - - args.push_back(p); -} - -void TDump::Invalid() { - invalid = true; -} - -void TDump::Suspect() { -} - -void TDump::Comment(const String & c) { - comments = c; -} - -Dumper::Dumper(mipsmem * _mm) : dump(new TDump(_mm)), mm(_mm) { -} - -void Dumper::process() { - Uint32 pc, code; - memdata * mem; - - for (pc = 0x80000000; pc < (0x80000000 + PSXMEM); pc++) { - if (mm->GetTag(pc, CODE)) { - decode(dump, pc); - code = mm->Read32(pc); - printm(M_STATUS, "%8.8lX %8.8lX: " + dump->name + "\t", pc, code); - for (std::vector<pairarg>::iterator i = dump->args.begin(); i != dump->args.end(); i++) { - switch(i->left) { - case T_GPREGISTER: - printm(M_BARE, "$%s", registers[i->right.v]); - break; - case T_CPREGISTER: - printm(M_BARE, "$%s", CP0registers[i->right.v]); - break; - case T_IMM8: - printm(M_BARE, "0x%2.2lX", i->right.v); - break; - case T_IMM16: - printm(M_BARE, "0x%4.4lX", i->right.v); - break; - case T_IMM32: - printm(M_BARE, "0x%8.8lX", i->right.v); - break; - case T_OFB: - printm(M_BARE, "0x%4.4lX($%s)", i->right.OfB.o, registers[i->right.OfB.r]); - break; - } - if ((i + 1) != dump->args.end()) { - printm(M_BARE, ", "); - } - } - if (dump->comments != "") { - printm(M_BARE, "\t; " + dump->comments); - } - printm(M_BARE, "\n"); - mem = mm->GetDatas(pc); - if (mem) { - reffrom_t * from; - refto_t * to; - - from = mem->getreffrom(); - to = mem->getrefto(); - - for (from = mem->getreffrom(); from; from = from->getnext()) { - printm(M_STATUS, " Reference from 0x%8.8lX\n", from->getref()->getaddress()); - } - - if (to) { - printm(M_STATUS, " Reference to 0x%8.8lX\n", to->getref()->getaddress()); - } - } - pc += 3; - dump->reset(); - } - } -} +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: mipsdump.cpp,v 1.2 2004-11-27 21:44:48 pixel Exp $ */
+
+#include "mipsdump.h"
+#include "mips.h"
+
+TDump::TDump(mipsmem * mm) : TDis(mm) {
+ reset();
+}
+
+void TDump::reset() {
+ invalid = false;
+ hasbr = false;
+ hastg = false;
+ hasfc = false;
+ name = "";
+ comments = "";
+ args.clear();
+}
+
+void TDump::add_branch(Uint32 _tg) {
+ tg = _tg;
+ hasbr = true;
+}
+
+void TDump::add_jump(Uint32 _tg) {
+ tg = _tg;
+ hastg = true;
+}
+
+void TDump::add_function(Uint32 _tg) {
+ tg = _tg;
+ hasfc = true;
+}
+
+void TDump::SetTag(Uint32 a, int t, bool v) {
+}
+
+void TDump::Name(const String & _name) {
+ name = _name;
+}
+
+void TDump::PushGPReg(int r) {
+ pairarg p;
+
+ p.left = T_GPREGISTER;
+ p.right.v = r;
+
+ args.push_back(p);
+}
+
+void TDump::PushCPReg(int r) {
+ pairarg p;
+
+ p.left = T_CPREGISTER;
+ p.right.v = r;
+
+ args.push_back(p);
+}
+
+void TDump::PushImm(Uint32 imm) {
+ pairarg p;
+
+ p.left = T_IMM16;
+ p.right.v = imm;
+
+ args.push_back(p);
+}
+
+void TDump::PushTarget(Uint32 target) {
+ pairarg p;
+
+ p.left = T_IMM32;
+ p.right.v = target;
+
+ args.push_back(p);
+}
+
+void TDump::PushSa(Uint32 sa) {
+ pairarg p;
+
+ p.left = T_IMM8;
+ p.right.v = sa;
+
+ args.push_back(p);
+}
+
+void TDump::PushOfB(int reg, Uint32 offset, int width) {
+ pairarg p;
+
+ p.left = T_OFB;
+ p.right.OfB.o = offset;
+ p.right.OfB.r = reg;
+ p.right.OfB.w = width;
+
+ args.push_back(p);
+}
+
+void TDump::PushOffset(Uint32 offset) {
+ pairarg p;
+
+ p.left = T_IMM32;
+ p.right.v = offset;
+
+ args.push_back(p);
+}
+
+void TDump::PushFull(Uint32 full) {
+ pairarg p;
+
+ p.left = T_IMM32;
+ p.right.v = full;
+
+ args.push_back(p);
+}
+
+void TDump::Invalid() {
+ invalid = true;
+}
+
+void TDump::Suspect() {
+}
+
+void TDump::Comment(const String & c) {
+ comments = c;
+}
+
+Dumper::Dumper(mipsmem * _mm) : dump(new TDump(_mm)), mm(_mm) {
+}
+
+void Dumper::process() {
+ Uint32 pc, code;
+ memdata * mem;
+
+ for (pc = 0x80000000; pc < (0x80000000 + PSXMEM); pc++) {
+ if (mm->GetTag(pc, CODE)) {
+ decode(dump, pc);
+ code = mm->Read32(pc);
+ printm(M_STATUS, "%8.8lX %8.8lX: " + dump->name + "\t", pc, code);
+ for (std::vector<pairarg>::iterator i = dump->args.begin(); i != dump->args.end(); i++) {
+ switch(i->left) {
+ case T_GPREGISTER:
+ printm(M_BARE, "$%s", registers[i->right.v]);
+ break;
+ case T_CPREGISTER:
+ printm(M_BARE, "$%s", CP0registers[i->right.v]);
+ break;
+ case T_IMM8:
+ printm(M_BARE, "0x%2.2lX", i->right.v);
+ break;
+ case T_IMM16:
+ printm(M_BARE, "0x%4.4lX", i->right.v);
+ break;
+ case T_IMM32:
+ printm(M_BARE, "0x%8.8lX", i->right.v);
+ break;
+ case T_OFB:
+ printm(M_BARE, "0x%4.4lX($%s)", i->right.OfB.o, registers[i->right.OfB.r]);
+ break;
+ }
+ if ((i + 1) != dump->args.end()) {
+ printm(M_BARE, ", ");
+ }
+ }
+ if (dump->comments != "") {
+ printm(M_BARE, "\t; " + dump->comments);
+ }
+ printm(M_BARE, "\n");
+ mem = mm->GetDatas(pc);
+ if (mem) {
+ reffrom_t * from;
+ refto_t * to;
+
+ from = mem->getreffrom();
+ to = mem->getrefto();
+
+ for (from = mem->getreffrom(); from; from = from->getnext()) {
+ printm(M_STATUS, " Reference from 0x%8.8lX\n", from->getref()->getaddress());
+ }
+
+ if (to) {
+ printm(M_STATUS, " Reference to 0x%8.8lX\n", to->getref()->getaddress());
+ }
+ }
+ pc += 3;
+ dump->reset();
+ }
+ }
+}
diff --git a/lib/mipsmem.cpp b/lib/mipsmem.cpp index 761df13..660c3fc 100644 --- a/lib/mipsmem.cpp +++ b/lib/mipsmem.cpp @@ -1,349 +1,349 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002-2003 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: mipsmem.cpp,v 1.1 2004-01-03 15:04:47 pixel Exp $ */ - -#include "mipsmem.h" - -refto_t::refto_t(Uint32 to, memdata * _m) : reffrom(new reffrom_t(this, _m->getmem(to))), mem(_m) { - refto_t * t = mem->getrefto(); - if (t) - delete t; - mem->setrefto(this); -} - -refto_t::~refto_t() { - mem->setrefto(0); - delete reffrom; -} - -memdata * refto_t::getmem() { - return mem; -} - -memdata * refto_t::getref() { - return reffrom->getmem(); -} - -reffrom_t::reffrom_t(refto_t * _refto, memdata * _m) : refto(_refto), header(_m) { - next = header->getreffrom(); - prev = 0; - header->setreffrom(this); - if (next) - next->prev = this; -} - -reffrom_t::~reffrom_t() { - if (next) - next->prev = prev; - if (prev) - prev->next = next; - else - header->setreffrom(next); -} - -memdata * reffrom_t::getmem() { - return header; -} - -memdata * reffrom_t::getref() { - return refto->getmem(); -} - -reffrom_t * reffrom_t::getnext() { - return next; -} - -memdata::memdata(Uint32 _address, mipsmem * _mm) : address(_address), mm(_mm), func(0), refto(0), reffrom(0) { - mm->SetDatas(address, this); -} - -memdata::~memdata() { - mm->SetDatas(address, 0); -} - -Uint32 memdata::getaddress() { - return address; -} - -memdata * memdata::getmem(Uint32 addr) { - return getmem(addr, mm); -} - -memdata * memdata::getmem(Uint32 addr, mipsmem * mm) { - memdata * t = mm->GetDatas(addr); - - if (!t) { - t = new memdata(addr, mm); - } - return t; -} - -func_t * memdata::getfunc() { - return func; -} - -refto_t * memdata::getrefto() { - return refto; -} - -reffrom_t * memdata::getreffrom() { - return reffrom; -} - -void memdata::setfunc(func_t * f) { - func = f; - checkdestroy(); -} - -void memdata::setrefto(refto_t * r) { - refto = r; - checkdestroy(); -} - -void memdata::setreffrom(reffrom_t * r) { - reffrom = r; - checkdestroy(); -} - -void memdata::checkdestroy() { - if (!func && !refto && !reffrom) { - delete this; - } -} - - -mipsmem::mipsmem() { - memset(psyqhead, 0, 0x800); - memset(plainmemory, 0, PSXMEM); - memset(patches, 0, PSXMEM); - memset(patchesmap, 0, PSXMEM / 8); - memset(tags, 0, PSXMEM); - memset(datas, 0, PSXMEM * sizeof(memdata *)); -} - -Uint8 mipsmem::Read8(Uint32 mem) { - if ((mem < 0x80000000) || (mem >= (0x80000000 + PSXMEM))) { - printm(M_WARNING, "Reading at out of bound of memory: 0x%08x\n", mem); - return 0xff; - } - - mem -= 0x80000000; - - if (IsPatched(mem)) { - return patches[mem]; - } else { - return plainmemory[mem]; - } -} - -Uint16 mipsmem::Read16(Uint32 mem) { - Uint8 a, b; - - if (mem & 1) { - printm(M_WARNING, "Read16 at a non 16-bits boundary: 0x%08x\n", mem); - } - - a = Read8(mem); - b = Read8(mem + 1); - - return a | (b << 8); -} - -Uint32 mipsmem::Read32(Uint32 mem) { - Uint8 a, b, c, d; - - if (mem & 3) { - printm(M_WARNING, "Read32 at a non 32-bits boundary: 0x%08x\n", mem); - } - - a = Read8(mem); - b = Read8(mem + 1); - c = Read8(mem + 2); - d = Read8(mem + 3); - - return a | (b << 8) | (c << 16) | (d << 24); -} - -void mipsmem::Write8(Uint32 mem, Uint8 value) { - if ((mem < 0x80000000) || (mem > (0x80000000 + PSXMEM - 1))) { - printm(M_WARNING, "Writing at out of bound of memory: 0x%08x\n", mem); - return; - } - - mem -= 0x80000000; - - patch(mem, 1); - patches[mem] = value; -} - -void mipsmem::Write16(Uint32 mem, Uint16 value) { - if ((mem < 0x80000000) || (mem > (0x80000000 + PSXMEM - 2))) { - printm(M_WARNING, "Writing at out of bound of memory: 0x%08x\n", mem); - return; - } - - mem -= 0x80000000; - - patch(mem, 2); - patches[mem] = value & 0xff; - patches[mem + 1] = (value >> 8) & 0xff; -} - -void mipsmem::Write32(Uint32 mem, Uint32 value) { - if ((mem < 0x80000000) || (mem > (0x80000000 + PSXMEM - 4))) { - printm(M_WARNING, "Writing at out of bound of memory: 0x%08x\n", mem); - return; - } - - mem -= 0x80000000; - - patch(mem, 4); - patches[mem] = value & 0xff; - patches[mem + 1] = (value >> 8) & 0xff; - patches[mem + 2] = (value >> 16) & 0xff; - patches[mem + 3] = (value >> 24) & 0xff; -} - -void mipsmem::unpatch8(Uint32 mem) { - unpatch(mem, 1); -} - -void mipsmem::unpatch16(Uint32 mem) { - unpatch(mem, 2); -} - -void mipsmem::unpatch32(Uint32 mem) { - unpatch(mem, 4); -} - -bool mipsmem::IsPatched(Uint32 mem) { - int mask, pos; - - pos = mem / 8; - mask = 1 << (mem % 8); - - return patchesmap[pos] & mask; -} - -void mipsmem::LoadPSYQ(Handle * h) { - h->read(psyqhead, 0x800); - memset(plainmemory, 0, PSXMEM); - paddr = ((psyq*)psyqhead)->t_addr; - psize = ((psyq*)psyqhead)->t_size; - startpc = ((psyq*)psyqhead)->pc0; - - printm(M_INFO, "Loading %i (%08x) bytes of data at %i (%08x).\n", psize, psize, paddr - 0x80000000, paddr); - - h->read(plainmemory + paddr - 0x80000000, psize); -} - -void mipsmem::SavePSYQ(Handle * h) {\ - Uint32 i; - - if (!*((Uint32 *)psyqhead)) - return; - h->write(psyqhead, 0x800); - paddr = ((psyq*)psyqhead)->t_addr; - psize = ((psyq*)psyqhead)->t_size; - - printm(M_INFO, "Writing %i (%08x) bytes of data from %i (%08x).\n", psize, psize, paddr - 0x80000000, paddr); - - for (i = paddr - 0x80000000; i < psize; i++) { - h->writeU8(Read8(i)); - } -} - -bool mipsmem::GetTag(Uint32 addr, char tag) { - int mask; - - if ((addr < 0x80000000) || (addr >= (0x80000000 + PSXMEM))) { - printm(M_WARNING, "Reading tag at out of bound of memory: 0x%08x\n", addr); - return false; - } - - mask = 1 << tag; - addr -= 0x80000000; - - return tags[addr] & mask; -} - -void mipsmem::SetTag(Uint32 addr, char tag, bool t) { - int mask; - - if ((addr < 0x80000000) || (addr >= (0x80000000 + PSXMEM))) { - printm(M_WARNING, "Setting tag at out of bound of memory: 0x%08x\n", addr); - return; - } - - mask = 1 << tag; - addr -= 0x80000000; - - if (t) { - tags[addr] |= mask; - } else { - tags[addr] &= ~mask; - } -} - -memdata * mipsmem::GetDatas(Uint32 addr) { - return datas[addr]; -} - -void mipsmem::SetDatas(Uint32 addr, memdata * p) { - datas[addr] = p; -} - -Uint32 mipsmem::GetPC() { - return startpc; -} - -Uint32 mipsmem::GetLower() { - return paddr; -} - -Uint32 mipsmem::GetUpper() { - return paddr + psize; -} - -void mipsmem::patch(Uint32 mem, int size) { - int mask, pos; - - pos = mem / 8; - mask = 1 << (mem % 8); - - patchesmap[pos] |= mask; - - if (size != 1) { - patch(mem + 1, size - 1); - } -} - -void mipsmem::unpatch(Uint32 mem, int size) { - int mask, pos; - - pos = mem / 8; - mask = ~(1 << (mem % 8)); - - patchesmap[pos] &= mask; - - if (size != 1) { - unpatch(mem + 1, size - 1); - } -} +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: mipsmem.cpp,v 1.2 2004-11-27 21:44:48 pixel Exp $ */
+
+#include "mipsmem.h"
+
+refto_t::refto_t(Uint32 to, memdata * _m) : reffrom(new reffrom_t(this, _m->getmem(to))), mem(_m) {
+ refto_t * t = mem->getrefto();
+ if (t)
+ delete t;
+ mem->setrefto(this);
+}
+
+refto_t::~refto_t() {
+ mem->setrefto(0);
+ delete reffrom;
+}
+
+memdata * refto_t::getmem() {
+ return mem;
+}
+
+memdata * refto_t::getref() {
+ return reffrom->getmem();
+}
+
+reffrom_t::reffrom_t(refto_t * _refto, memdata * _m) : refto(_refto), header(_m) {
+ next = header->getreffrom();
+ prev = 0;
+ header->setreffrom(this);
+ if (next)
+ next->prev = this;
+}
+
+reffrom_t::~reffrom_t() {
+ if (next)
+ next->prev = prev;
+ if (prev)
+ prev->next = next;
+ else
+ header->setreffrom(next);
+}
+
+memdata * reffrom_t::getmem() {
+ return header;
+}
+
+memdata * reffrom_t::getref() {
+ return refto->getmem();
+}
+
+reffrom_t * reffrom_t::getnext() {
+ return next;
+}
+
+memdata::memdata(Uint32 _address, mipsmem * _mm) : address(_address), mm(_mm), func(0), refto(0), reffrom(0) {
+ mm->SetDatas(address, this);
+}
+
+memdata::~memdata() {
+ mm->SetDatas(address, 0);
+}
+
+Uint32 memdata::getaddress() {
+ return address;
+}
+
+memdata * memdata::getmem(Uint32 addr) {
+ return getmem(addr, mm);
+}
+
+memdata * memdata::getmem(Uint32 addr, mipsmem * mm) {
+ memdata * t = mm->GetDatas(addr);
+
+ if (!t) {
+ t = new memdata(addr, mm);
+ }
+ return t;
+}
+
+func_t * memdata::getfunc() {
+ return func;
+}
+
+refto_t * memdata::getrefto() {
+ return refto;
+}
+
+reffrom_t * memdata::getreffrom() {
+ return reffrom;
+}
+
+void memdata::setfunc(func_t * f) {
+ func = f;
+ checkdestroy();
+}
+
+void memdata::setrefto(refto_t * r) {
+ refto = r;
+ checkdestroy();
+}
+
+void memdata::setreffrom(reffrom_t * r) {
+ reffrom = r;
+ checkdestroy();
+}
+
+void memdata::checkdestroy() {
+ if (!func && !refto && !reffrom) {
+ delete this;
+ }
+}
+
+
+mipsmem::mipsmem() {
+ memset(psyqhead, 0, 0x800);
+ memset(plainmemory, 0, PSXMEM);
+ memset(patches, 0, PSXMEM);
+ memset(patchesmap, 0, PSXMEM / 8);
+ memset(tags, 0, PSXMEM);
+ memset(datas, 0, PSXMEM * sizeof(memdata *));
+}
+
+Uint8 mipsmem::Read8(Uint32 mem) {
+ if ((mem < 0x80000000) || (mem >= (0x80000000 + PSXMEM))) {
+ printm(M_WARNING, "Reading at out of bound of memory: 0x%08x\n", mem);
+ return 0xff;
+ }
+
+ mem -= 0x80000000;
+
+ if (IsPatched(mem)) {
+ return patches[mem];
+ } else {
+ return plainmemory[mem];
+ }
+}
+
+Uint16 mipsmem::Read16(Uint32 mem) {
+ Uint8 a, b;
+
+ if (mem & 1) {
+ printm(M_WARNING, "Read16 at a non 16-bits boundary: 0x%08x\n", mem);
+ }
+
+ a = Read8(mem);
+ b = Read8(mem + 1);
+
+ return a | (b << 8);
+}
+
+Uint32 mipsmem::Read32(Uint32 mem) {
+ Uint8 a, b, c, d;
+
+ if (mem & 3) {
+ printm(M_WARNING, "Read32 at a non 32-bits boundary: 0x%08x\n", mem);
+ }
+
+ a = Read8(mem);
+ b = Read8(mem + 1);
+ c = Read8(mem + 2);
+ d = Read8(mem + 3);
+
+ return a | (b << 8) | (c << 16) | (d << 24);
+}
+
+void mipsmem::Write8(Uint32 mem, Uint8 value) {
+ if ((mem < 0x80000000) || (mem > (0x80000000 + PSXMEM - 1))) {
+ printm(M_WARNING, "Writing at out of bound of memory: 0x%08x\n", mem);
+ return;
+ }
+
+ mem -= 0x80000000;
+
+ patch(mem, 1);
+ patches[mem] = value;
+}
+
+void mipsmem::Write16(Uint32 mem, Uint16 value) {
+ if ((mem < 0x80000000) || (mem > (0x80000000 + PSXMEM - 2))) {
+ printm(M_WARNING, "Writing at out of bound of memory: 0x%08x\n", mem);
+ return;
+ }
+
+ mem -= 0x80000000;
+
+ patch(mem, 2);
+ patches[mem] = value & 0xff;
+ patches[mem + 1] = (value >> 8) & 0xff;
+}
+
+void mipsmem::Write32(Uint32 mem, Uint32 value) {
+ if ((mem < 0x80000000) || (mem > (0x80000000 + PSXMEM - 4))) {
+ printm(M_WARNING, "Writing at out of bound of memory: 0x%08x\n", mem);
+ return;
+ }
+
+ mem -= 0x80000000;
+
+ patch(mem, 4);
+ patches[mem] = value & 0xff;
+ patches[mem + 1] = (value >> 8) & 0xff;
+ patches[mem + 2] = (value >> 16) & 0xff;
+ patches[mem + 3] = (value >> 24) & 0xff;
+}
+
+void mipsmem::unpatch8(Uint32 mem) {
+ unpatch(mem, 1);
+}
+
+void mipsmem::unpatch16(Uint32 mem) {
+ unpatch(mem, 2);
+}
+
+void mipsmem::unpatch32(Uint32 mem) {
+ unpatch(mem, 4);
+}
+
+bool mipsmem::IsPatched(Uint32 mem) {
+ int mask, pos;
+
+ pos = mem / 8;
+ mask = 1 << (mem % 8);
+
+ return patchesmap[pos] & mask;
+}
+
+void mipsmem::LoadPSYQ(Handle * h) {
+ h->read(psyqhead, 0x800);
+ memset(plainmemory, 0, PSXMEM);
+ paddr = ((psyq*)psyqhead)->t_addr;
+ psize = ((psyq*)psyqhead)->t_size;
+ startpc = ((psyq*)psyqhead)->pc0;
+
+ printm(M_INFO, "Loading %i (%08x) bytes of data at %i (%08x).\n", psize, psize, paddr - 0x80000000, paddr);
+
+ h->read(plainmemory + paddr - 0x80000000, psize);
+}
+
+void mipsmem::SavePSYQ(Handle * h) {\
+ Uint32 i;
+
+ if (!*((Uint32 *)psyqhead))
+ return;
+ h->write(psyqhead, 0x800);
+ paddr = ((psyq*)psyqhead)->t_addr;
+ psize = ((psyq*)psyqhead)->t_size;
+
+ printm(M_INFO, "Writing %i (%08x) bytes of data from %i (%08x).\n", psize, psize, paddr - 0x80000000, paddr);
+
+ for (i = paddr - 0x80000000; i < psize; i++) {
+ h->writeU8(Read8(i));
+ }
+}
+
+bool mipsmem::GetTag(Uint32 addr, char tag) {
+ int mask;
+
+ if ((addr < 0x80000000) || (addr >= (0x80000000 + PSXMEM))) {
+ printm(M_WARNING, "Reading tag at out of bound of memory: 0x%08x\n", addr);
+ return false;
+ }
+
+ mask = 1 << tag;
+ addr -= 0x80000000;
+
+ return tags[addr] & mask;
+}
+
+void mipsmem::SetTag(Uint32 addr, char tag, bool t) {
+ int mask;
+
+ if ((addr < 0x80000000) || (addr >= (0x80000000 + PSXMEM))) {
+ printm(M_WARNING, "Setting tag at out of bound of memory: 0x%08x\n", addr);
+ return;
+ }
+
+ mask = 1 << tag;
+ addr -= 0x80000000;
+
+ if (t) {
+ tags[addr] |= mask;
+ } else {
+ tags[addr] &= ~mask;
+ }
+}
+
+memdata * mipsmem::GetDatas(Uint32 addr) {
+ return datas[addr];
+}
+
+void mipsmem::SetDatas(Uint32 addr, memdata * p) {
+ datas[addr] = p;
+}
+
+Uint32 mipsmem::GetPC() {
+ return startpc;
+}
+
+Uint32 mipsmem::GetLower() {
+ return paddr;
+}
+
+Uint32 mipsmem::GetUpper() {
+ return paddr + psize;
+}
+
+void mipsmem::patch(Uint32 mem, int size) {
+ int mask, pos;
+
+ pos = mem / 8;
+ mask = 1 << (mem % 8);
+
+ patchesmap[pos] |= mask;
+
+ if (size != 1) {
+ patch(mem + 1, size - 1);
+ }
+}
+
+void mipsmem::unpatch(Uint32 mem, int size) {
+ int mask, pos;
+
+ pos = mem / 8;
+ mask = ~(1 << (mem % 8));
+
+ patchesmap[pos] &= mask;
+
+ if (size != 1) {
+ unpatch(mem + 1, size - 1);
+ }
+}
diff --git a/lib/mipsobj.cpp b/lib/mipsobj.cpp index 97663e6..233c5c5 100644 --- a/lib/mipsobj.cpp +++ b/lib/mipsobj.cpp @@ -1,269 +1,269 @@ -#include "mipsobj.h" - -section::section(const String & _name, int _type) : name(_name), type(_type), datas(0), length(0) { } -section::section() : name(""), type(-1), datas(0), length(0) { } - -section::~section() { - if (datas) - free(datas); -} - -void section::setname(const String & _name) { - name = _name; -} - -void section::settype(int _type) { - type = _type; -} - -void section::putdatas(const Uint8 * _datas, int _length) { - if (type != BSS) { - datas = (Uint8 *) realloc(datas, length + _length); - memcpy(datas + length, _datas, _length); - } - length += _length; -} - -int section::gettype() { - return type; -} - -int section::getsize() { - return length; -} - -const Uint8 * section::getdatas() { - return datas; -} - -void section::putreloc(const String & _symbol, int _type, Uint32 _offset) { - struct reloc_t r; - - r.symbol = _symbol; - r.type = _type; - r.offset = _offset; - - putreloc(r); -} - -void section::putreloc(const struct reloc_t & r) { - relocs.push_back(r); -} - -mipsobj::mipsobj() : loaded(false) { } - -mipsobj::~mipsobj() { } - -void loadELF(Handle * elf) throw (GeneralException) { -} - -#define OBJSIG 0x024b4e4c - -#define READNAME(_str, _file) { \ - char _name[256]; \ - int _len; \ - \ - _len = _file->readU8(); \ - _file->read(_name, _len); \ - _name[_len] = 0; \ - _str = _name; \ -} - -void mipsobj::loadOBJ(Handle * obj) throw (GeneralException) { - int cursec, len, reloctype, relocexpr, id; - bool eof = false; - std::map<int, String> secnames; - std::map<int, String> symbolnames; - Uint8 * datas; - struct reloc_t reloc; - struct symbol_t symbol; - String name; - - while (!eof) { - int entryid = obj->readU8(); - - switch (entryid) { - case 0x00: - eof = true; - break; - - case 0x02: - len = obj->readU16(); - datas = (Uint8 *) malloc(len); - - obj->read(datas, len); - sections[secnames[cursec]].putdatas(datas, len); - - free(datas); - break; - - case 0x06: - cursec = obj->readU16(); - break; - - case 0x08: - len = obj->readU32(); - - sections[secnames[cursec]].putdatas(0, len); - break; - - case 0x0a: - reloctype = obj->readU8(); - reloc.offset = obj->readU16(); - - switch (reloctype) { - case 0x10: - reloc.type = R_MIPS_32; - break; - case 0x4a: - reloc.type = R_MIPS_26; - break; - case 0x52: - reloc.type = R_MIPS_HI16; - break; - case 0x54: - reloc.type = R_MIPS_LO16; - break; - case 0x0a: - case 0x26: - case 0x28: - case 0x64: - printm(M_ERROR, "Relocation type %02x not supported.\n", reloctype); - exit(-1); - break; - default: - printm(M_ERROR, "Relocation type %02x UNKNOWN! Please send the object to the author.\n", reloctype); - exit(-1); - } - - relocexpr = obj->readU8(); - - switch (relocexpr) { - case 0x02: - reloc.symbol = symbolnames[obj->readU16()]; - break; - case 0x04: - reloc.symbol = secnames[obj->readU16()]; - break; - case 0x00: - case 0x0c: - case 0x16: - case 0x2c: - case 0x2e: - case 0x30: - case 0x32: - case 0x36: - printm(M_ERROR, "Relocation expression %02x not supported.\n", relocexpr); - exit(-1); - break; - default: - printm(M_ERROR, "Relocation expression %02x UNKNOWN! Please mail the author.\n", relocexpr); - exit(-1); - break; - } - - sections[secnames[cursec]].relocs.push_back(reloc); - - break; - - case 0x0c: - id = obj->readU16(); - symbol.section = obj->readU16(); - symbol.offset = obj->readU32(); - READNAME(symbol.name, obj); - symbol.type = GLOBAL; - - symbolnames[id] = symbol.name; - - break; - - case 0x0e: - id = obj->readU16(); - READNAME(symbol.name, obj); - symbol.type = EXTERN; - - symbolnames[id] = symbol.name; - - break; - - case 0x10: - id = obj->readU16(); - obj->readU8(); - obj->readU16(); - READNAME(name, obj); - - secnames[id] = name; - - break; - - case 0x12: - printm(M_WARNING, "Local symbol not supported.\n"); - obj->readU16(); - obj->readU32(); - READNAME(name, obj); - break; - - case 0x1c: - printm(M_WARNING, "File number and name not supported.\n"); - obj->readU16(); - READNAME(name, obj); - break; - - case 0x2e: - if ((id = obj->readU8()) != 7) { - printm(M_ERROR, "CPU type %i not supported.\n", id); - exit(-1); - } - break; - - case 0x30: - printm(M_ERROR, "Constant not supported.\n"); - exit(-1); - break; - - default: - printm(M_ERROR, "Object entry type %i UNKNOWN! Please send the object to the author.\n", entryid); - exit(-1); - break; - } - } -} - -#define LIBSIG 0x0142494c - -void mipsobj::loadLIB(Handle * lib, const String & objname) throw (GeneralException) { - char _name[9]; - String name; - int hsize, size, ptr; - bool found = false; - - lib->seek(0); - - if (lib->readU32() != LIBSIG) { - throw GeneralException("Not a Psy-Q lib file"); - } - - while (lib->tell() != lib->GetSize()) { - ptr = lib->tell(); - - lib->read(_name, 8); - name = _name; - lib->seek(4, SEEK_CUR); - hsize = lib->readU32(); - size = lib->readU32(); - - if (objname == name.trim()) { - lib->seek(ptr + hsize); - found = true; - break; - } - - lib->seek(ptr + size); - } - - if (!found) { - throw GeneralException("Object `" + objname + "' not found in archive " + lib->GetName()); - } - - loadOBJ(lib); -} +#include "mipsobj.h"
+
+section::section(const String & _name, int _type) : name(_name), type(_type), datas(0), length(0) { }
+section::section() : name(""), type(-1), datas(0), length(0) { }
+
+section::~section() {
+ if (datas)
+ free(datas);
+}
+
+void section::setname(const String & _name) {
+ name = _name;
+}
+
+void section::settype(int _type) {
+ type = _type;
+}
+
+void section::putdatas(const Uint8 * _datas, int _length) {
+ if (type != BSS) {
+ datas = (Uint8 *) realloc(datas, length + _length);
+ memcpy(datas + length, _datas, _length);
+ }
+ length += _length;
+}
+
+int section::gettype() {
+ return type;
+}
+
+int section::getsize() {
+ return length;
+}
+
+const Uint8 * section::getdatas() {
+ return datas;
+}
+
+void section::putreloc(const String & _symbol, int _type, Uint32 _offset) {
+ struct reloc_t r;
+
+ r.symbol = _symbol;
+ r.type = _type;
+ r.offset = _offset;
+
+ putreloc(r);
+}
+
+void section::putreloc(const struct reloc_t & r) {
+ relocs.push_back(r);
+}
+
+mipsobj::mipsobj() : loaded(false) { }
+
+mipsobj::~mipsobj() { }
+
+void loadELF(Handle * elf) throw (GeneralException) {
+}
+
+#define OBJSIG 0x024b4e4c
+
+#define READNAME(_str, _file) { \
+ char _name[256]; \
+ int _len; \
+ \
+ _len = _file->readU8(); \
+ _file->read(_name, _len); \
+ _name[_len] = 0; \
+ _str = _name; \
+}
+
+void mipsobj::loadOBJ(Handle * obj) throw (GeneralException) {
+ int cursec, len, reloctype, relocexpr, id;
+ bool eof = false;
+ std::map<int, String> secnames;
+ std::map<int, String> symbolnames;
+ Uint8 * datas;
+ struct reloc_t reloc;
+ struct symbol_t symbol;
+ String name;
+
+ while (!eof) {
+ int entryid = obj->readU8();
+
+ switch (entryid) {
+ case 0x00:
+ eof = true;
+ break;
+
+ case 0x02:
+ len = obj->readU16();
+ datas = (Uint8 *) malloc(len);
+
+ obj->read(datas, len);
+ sections[secnames[cursec]].putdatas(datas, len);
+
+ free(datas);
+ break;
+
+ case 0x06:
+ cursec = obj->readU16();
+ break;
+
+ case 0x08:
+ len = obj->readU32();
+
+ sections[secnames[cursec]].putdatas(0, len);
+ break;
+
+ case 0x0a:
+ reloctype = obj->readU8();
+ reloc.offset = obj->readU16();
+
+ switch (reloctype) {
+ case 0x10:
+ reloc.type = R_MIPS_32;
+ break;
+ case 0x4a:
+ reloc.type = R_MIPS_26;
+ break;
+ case 0x52:
+ reloc.type = R_MIPS_HI16;
+ break;
+ case 0x54:
+ reloc.type = R_MIPS_LO16;
+ break;
+ case 0x0a:
+ case 0x26:
+ case 0x28:
+ case 0x64:
+ printm(M_ERROR, "Relocation type %02x not supported.\n", reloctype);
+ exit(-1);
+ break;
+ default:
+ printm(M_ERROR, "Relocation type %02x UNKNOWN! Please send the object to the author.\n", reloctype);
+ exit(-1);
+ }
+
+ relocexpr = obj->readU8();
+
+ switch (relocexpr) {
+ case 0x02:
+ reloc.symbol = symbolnames[obj->readU16()];
+ break;
+ case 0x04:
+ reloc.symbol = secnames[obj->readU16()];
+ break;
+ case 0x00:
+ case 0x0c:
+ case 0x16:
+ case 0x2c:
+ case 0x2e:
+ case 0x30:
+ case 0x32:
+ case 0x36:
+ printm(M_ERROR, "Relocation expression %02x not supported.\n", relocexpr);
+ exit(-1);
+ break;
+ default:
+ printm(M_ERROR, "Relocation expression %02x UNKNOWN! Please mail the author.\n", relocexpr);
+ exit(-1);
+ break;
+ }
+
+ sections[secnames[cursec]].relocs.push_back(reloc);
+
+ break;
+
+ case 0x0c:
+ id = obj->readU16();
+ symbol.section = obj->readU16();
+ symbol.offset = obj->readU32();
+ READNAME(symbol.name, obj);
+ symbol.type = GLOBAL;
+
+ symbolnames[id] = symbol.name;
+
+ break;
+
+ case 0x0e:
+ id = obj->readU16();
+ READNAME(symbol.name, obj);
+ symbol.type = EXTERN;
+
+ symbolnames[id] = symbol.name;
+
+ break;
+
+ case 0x10:
+ id = obj->readU16();
+ obj->readU8();
+ obj->readU16();
+ READNAME(name, obj);
+
+ secnames[id] = name;
+
+ break;
+
+ case 0x12:
+ printm(M_WARNING, "Local symbol not supported.\n");
+ obj->readU16();
+ obj->readU32();
+ READNAME(name, obj);
+ break;
+
+ case 0x1c:
+ printm(M_WARNING, "File number and name not supported.\n");
+ obj->readU16();
+ READNAME(name, obj);
+ break;
+
+ case 0x2e:
+ if ((id = obj->readU8()) != 7) {
+ printm(M_ERROR, "CPU type %i not supported.\n", id);
+ exit(-1);
+ }
+ break;
+
+ case 0x30:
+ printm(M_ERROR, "Constant not supported.\n");
+ exit(-1);
+ break;
+
+ default:
+ printm(M_ERROR, "Object entry type %i UNKNOWN! Please send the object to the author.\n", entryid);
+ exit(-1);
+ break;
+ }
+ }
+}
+
+#define LIBSIG 0x0142494c
+
+void mipsobj::loadLIB(Handle * lib, const String & objname) throw (GeneralException) {
+ char _name[9];
+ String name;
+ int hsize, size, ptr;
+ bool found = false;
+
+ lib->seek(0);
+
+ if (lib->readU32() != LIBSIG) {
+ throw GeneralException("Not a Psy-Q lib file");
+ }
+
+ while (lib->tell() != lib->GetSize()) {
+ ptr = lib->tell();
+
+ lib->read(_name, 8);
+ name = _name;
+ lib->seek(4, SEEK_CUR);
+ hsize = lib->readU32();
+ size = lib->readU32();
+
+ if (objname == name.trim()) {
+ lib->seek(ptr + hsize);
+ found = true;
+ break;
+ }
+
+ lib->seek(ptr + size);
+ }
+
+ if (!found) {
+ throw GeneralException("Object `" + objname + "' not found in archive " + lib->GetName());
+ }
+
+ loadOBJ(lib);
+}
diff --git a/lib/yazedc.cpp b/lib/yazedc.cpp index 6350ef7..100cd38 100644 --- a/lib/yazedc.cpp +++ b/lib/yazedc.cpp @@ -1,273 +1,273 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 1998 Heiko Eissfeldt - * portions used& Chris Smith - * Modified by Yazoo, then by - * Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: yazedc.cpp,v 1.3 2003-12-04 01:47:37 pixel Exp $ */ - -#include <stdio.h> -#include <string.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "yazedc.h" - -yazedc::yazedc() : minute(0), second(2), frame(0), sectortype(0) {} - -/* ------------- tables generated by gen_encodes --------------*/ - -#include "crctables" - -static int encode_L2_Q(unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P + L2_Q]) -{ - unsigned char *Q; - int i,j; - - Q = inout + 4 + L2_RAW + 4 + 8 + L2_P; - memset(Q, 0, L2_Q); - for (j = 0; j < 26; j++) { - for (i = 0; i < 43; i++) { - unsigned char data; - - /* LSB */ - data = inout[(j*43*2+i*2*44) % (4 + L2_RAW + 4 + 8 + L2_P)]; - if (data != 0) { - unsigned int base = rs_l12_log[data]; - - unsigned int sum = base + DQ[0][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - - Q[0] ^= rs_l12_alog[sum]; - - sum = base + DQ[1][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - - Q[26*2] ^= rs_l12_alog[sum]; - } - /* MSB */ - data = inout[(j*43*2+i*2*44+1) % (4 + L2_RAW + 4 + 8 + L2_P)]; - if (data != 0) { - unsigned int base = rs_l12_log[data]; - - unsigned int sum = base+DQ[0][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - - Q[1] ^= rs_l12_alog[sum]; - - sum = base + DQ[1][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - - Q[26*2+1] ^= rs_l12_alog[sum]; - } - } - Q += 2; - } - return 0; -} - -static int encode_L2_P(unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P]) -{ - unsigned char *P; - int i,j; - - P = inout + 4 + L2_RAW + 4 + 8; - memset(P, 0, L2_P); - for (j = 0; j < 43; j++) { - for (i = 0; i < 24; i++) { - unsigned char data; - - /* LSB */ - data = inout[i*2*43]; - if (data != 0) { - unsigned int base = rs_l12_log[data]; - - unsigned int sum = base + DP[0][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - - P[0] ^= rs_l12_alog[sum]; - - sum = base + DP[1][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - - P[43*2] ^= rs_l12_alog[sum]; - } - /* MSB */ - data = inout[i*2*43+1]; - if (data != 0) { - unsigned int base = rs_l12_log[data]; - - unsigned int sum = base + DP[0][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - - P[1] ^= rs_l12_alog[sum]; - - sum = base + DP[1][i]; - if (sum >= ((1 << RS_L12_BITS)-1)) - sum -= (1 << RS_L12_BITS)-1; - - P[43*2+1] ^= rs_l12_alog[sum]; - } - } - P += 2; - inout += 2; - } - return 0; -} - -int yazedc::scramble_L2(unsigned char *inout) -{ - unsigned char *r = inout + 12; - const unsigned char *s = yellowbook_scrambler; - unsigned int i; - unsigned int *f = (unsigned int *)inout; - - for (i = (L2_RAW + L2_Q + L2_P +16)/sizeof(unsigned char); i; i--) { - *r++ ^= *s++; - } - - /* generate F1 frames */ - for (i = (2352/sizeof(unsigned int)); i; i--) { - *f++ = ((*f & 0xff00ff00UL) >> 8) | ((*f & 0x00ff00ffUL) << 8); - } - - return 0; -} - -int yazedc::build_address(unsigned char inout[], int sectortype, unsigned address) -{ - inout[12] = minute; - inout[13] = second; - inout[14] = frame; - if (sectortype == MODE_0) - inout[15] = 0; - else if (sectortype == MODE_1) - inout[15] = 1; - else if (sectortype == MODE_2) - inout[15] = 2; - else if (sectortype == MODE_2_FORM_1) - inout[15] = 2; - else if (sectortype == MODE_2_FORM_2) - inout[15] = 2; - else - return -1; - return 0; -} - -#include "crctable.out" -unsigned long int build_edc(unsigned char inout[], int from, int upto) -{ - unsigned char *p = inout+from; - unsigned long result = 0; - - for (; from <= upto; from++) - result = EDC_crctable[(result ^ *p++) & 0xffL] ^ (result >> 8); - - return result; -} - -/* Layer 2 Product code en/decoder */ -int yazedc::do_encode_L2(unsigned char inout[(12 + 4 + L2_RAW+4+8+L2_Q+L2_P)], int sectortype, unsigned address) -{ - unsigned long int result; - -#define SYNCPATTERN "\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" - - /* supply initial sync pattern */ - memcpy(inout, SYNCPATTERN, sizeof(SYNCPATTERN)); - - if (sectortype == MODE_0) { - memset(inout + sizeof(SYNCPATTERN), 0, 4 + L2_RAW + 12 + L2_P + L2_Q); - build_address(inout, sectortype, address); - return 0; - } - - switch (sectortype) { - case MODE_1: - build_address(inout, sectortype, address); - result = build_edc(inout, 0, 16+2048-1); - inout[2064+0] = result >> 0L; - inout[2064+1] = result >> 8L; - inout[2064+2] = result >> 16L; - inout[2064+3] = result >> 24L; - memset(inout+2064+4, 0, 8); - encode_L2_P(inout+12); - encode_L2_Q(inout+12); - break; - case MODE_2: - build_address(inout, sectortype, address); - break; - case MODE_2_FORM_1: - result = build_edc(inout, 16, 16+8+2048-1); - inout[2072+0] = result >> 0L; - inout[2072+1] = result >> 8L; - inout[2072+2] = result >> 16L; - inout[2072+3] = result >> 24L; - - /* clear header for P/Q parity calculation */ - inout[12] = 0; - inout[12+1] = 0; - inout[12+2] = 0; - inout[12+3] = 0; - encode_L2_P(inout+12); - encode_L2_Q(inout+12); - build_address(inout, sectortype, address); - break; - case MODE_2_FORM_2: - build_address(inout, sectortype, address); - result = build_edc(inout, 16, 16+8+2324-1); - inout[2348+0] = result >> 0L; - inout[2348+1] = result >> 8L; - inout[2348+2] = result >> 16L; - inout[2348+3] = result >> 24L; - break; - default: - return -1; - } - - return 0; -} - -int yazedc::get_sector_type(void) -{ - return sectortype; -} - -int yazedc::set_sector_type(int st) -{ - switch(st) { - case MODE_0: - case MODE_1: - case MODE_2: - case MODE_2_FORM_1: - case MODE_2_FORM_2: - sectortype = st; - default: - return -1; - } - return 0; -} +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 1998 Heiko Eissfeldt
+ * portions used& Chris Smith
+ * Modified by Yazoo, then by
+ * Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: yazedc.cpp,v 1.4 2004-11-27 21:44:48 pixel Exp $ */
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "yazedc.h"
+
+yazedc::yazedc() : minute(0), second(2), frame(0), sectortype(0) {}
+
+/* ------------- tables generated by gen_encodes --------------*/
+
+#include "crctables"
+
+static int encode_L2_Q(unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P + L2_Q])
+{
+ unsigned char *Q;
+ int i,j;
+
+ Q = inout + 4 + L2_RAW + 4 + 8 + L2_P;
+ memset(Q, 0, L2_Q);
+ for (j = 0; j < 26; j++) {
+ for (i = 0; i < 43; i++) {
+ unsigned char data;
+
+ /* LSB */
+ data = inout[(j*43*2+i*2*44) % (4 + L2_RAW + 4 + 8 + L2_P)];
+ if (data != 0) {
+ unsigned int base = rs_l12_log[data];
+
+ unsigned int sum = base + DQ[0][i];
+ if (sum >= ((1 << RS_L12_BITS)-1))
+ sum -= (1 << RS_L12_BITS)-1;
+
+ Q[0] ^= rs_l12_alog[sum];
+
+ sum = base + DQ[1][i];
+ if (sum >= ((1 << RS_L12_BITS)-1))
+ sum -= (1 << RS_L12_BITS)-1;
+
+ Q[26*2] ^= rs_l12_alog[sum];
+ }
+ /* MSB */
+ data = inout[(j*43*2+i*2*44+1) % (4 + L2_RAW + 4 + 8 + L2_P)];
+ if (data != 0) {
+ unsigned int base = rs_l12_log[data];
+
+ unsigned int sum = base+DQ[0][i];
+ if (sum >= ((1 << RS_L12_BITS)-1))
+ sum -= (1 << RS_L12_BITS)-1;
+
+ Q[1] ^= rs_l12_alog[sum];
+
+ sum = base + DQ[1][i];
+ if (sum >= ((1 << RS_L12_BITS)-1))
+ sum -= (1 << RS_L12_BITS)-1;
+
+ Q[26*2+1] ^= rs_l12_alog[sum];
+ }
+ }
+ Q += 2;
+ }
+ return 0;
+}
+
+static int encode_L2_P(unsigned char inout[4 + L2_RAW + 4 + 8 + L2_P])
+{
+ unsigned char *P;
+ int i,j;
+
+ P = inout + 4 + L2_RAW + 4 + 8;
+ memset(P, 0, L2_P);
+ for (j = 0; j < 43; j++) {
+ for (i = 0; i < 24; i++) {
+ unsigned char data;
+
+ /* LSB */
+ data = inout[i*2*43];
+ if (data != 0) {
+ unsigned int base = rs_l12_log[data];
+
+ unsigned int sum = base + DP[0][i];
+ if (sum >= ((1 << RS_L12_BITS)-1))
+ sum -= (1 << RS_L12_BITS)-1;
+
+ P[0] ^= rs_l12_alog[sum];
+
+ sum = base + DP[1][i];
+ if (sum >= ((1 << RS_L12_BITS)-1))
+ sum -= (1 << RS_L12_BITS)-1;
+
+ P[43*2] ^= rs_l12_alog[sum];
+ }
+ /* MSB */
+ data = inout[i*2*43+1];
+ if (data != 0) {
+ unsigned int base = rs_l12_log[data];
+
+ unsigned int sum = base + DP[0][i];
+ if (sum >= ((1 << RS_L12_BITS)-1))
+ sum -= (1 << RS_L12_BITS)-1;
+
+ P[1] ^= rs_l12_alog[sum];
+
+ sum = base + DP[1][i];
+ if (sum >= ((1 << RS_L12_BITS)-1))
+ sum -= (1 << RS_L12_BITS)-1;
+
+ P[43*2+1] ^= rs_l12_alog[sum];
+ }
+ }
+ P += 2;
+ inout += 2;
+ }
+ return 0;
+}
+
+int yazedc::scramble_L2(unsigned char *inout)
+{
+ unsigned char *r = inout + 12;
+ const unsigned char *s = yellowbook_scrambler;
+ unsigned int i;
+ unsigned int *f = (unsigned int *)inout;
+
+ for (i = (L2_RAW + L2_Q + L2_P +16)/sizeof(unsigned char); i; i--) {
+ *r++ ^= *s++;
+ }
+
+ /* generate F1 frames */
+ for (i = (2352/sizeof(unsigned int)); i; i--) {
+ *f++ = ((*f & 0xff00ff00UL) >> 8) | ((*f & 0x00ff00ffUL) << 8);
+ }
+
+ return 0;
+}
+
+int yazedc::build_address(unsigned char inout[], int sectortype, unsigned address)
+{
+ inout[12] = minute;
+ inout[13] = second;
+ inout[14] = frame;
+ if (sectortype == MODE_0)
+ inout[15] = 0;
+ else if (sectortype == MODE_1)
+ inout[15] = 1;
+ else if (sectortype == MODE_2)
+ inout[15] = 2;
+ else if (sectortype == MODE_2_FORM_1)
+ inout[15] = 2;
+ else if (sectortype == MODE_2_FORM_2)
+ inout[15] = 2;
+ else
+ return -1;
+ return 0;
+}
+
+#include "crctable.out"
+unsigned long int build_edc(unsigned char inout[], int from, int upto)
+{
+ unsigned char *p = inout+from;
+ unsigned long result = 0;
+
+ for (; from <= upto; from++)
+ result = EDC_crctable[(result ^ *p++) & 0xffL] ^ (result >> 8);
+
+ return result;
+}
+
+/* Layer 2 Product code en/decoder */
+int yazedc::do_encode_L2(unsigned char inout[(12 + 4 + L2_RAW+4+8+L2_Q+L2_P)], int sectortype, unsigned address)
+{
+ unsigned long int result;
+
+#define SYNCPATTERN "\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
+
+ /* supply initial sync pattern */
+ memcpy(inout, SYNCPATTERN, sizeof(SYNCPATTERN));
+
+ if (sectortype == MODE_0) {
+ memset(inout + sizeof(SYNCPATTERN), 0, 4 + L2_RAW + 12 + L2_P + L2_Q);
+ build_address(inout, sectortype, address);
+ return 0;
+ }
+
+ switch (sectortype) {
+ case MODE_1:
+ build_address(inout, sectortype, address);
+ result = build_edc(inout, 0, 16+2048-1);
+ inout[2064+0] = result >> 0L;
+ inout[2064+1] = result >> 8L;
+ inout[2064+2] = result >> 16L;
+ inout[2064+3] = result >> 24L;
+ memset(inout+2064+4, 0, 8);
+ encode_L2_P(inout+12);
+ encode_L2_Q(inout+12);
+ break;
+ case MODE_2:
+ build_address(inout, sectortype, address);
+ break;
+ case MODE_2_FORM_1:
+ result = build_edc(inout, 16, 16+8+2048-1);
+ inout[2072+0] = result >> 0L;
+ inout[2072+1] = result >> 8L;
+ inout[2072+2] = result >> 16L;
+ inout[2072+3] = result >> 24L;
+
+ /* clear header for P/Q parity calculation */
+ inout[12] = 0;
+ inout[12+1] = 0;
+ inout[12+2] = 0;
+ inout[12+3] = 0;
+ encode_L2_P(inout+12);
+ encode_L2_Q(inout+12);
+ build_address(inout, sectortype, address);
+ break;
+ case MODE_2_FORM_2:
+ build_address(inout, sectortype, address);
+ result = build_edc(inout, 16, 16+8+2324-1);
+ inout[2348+0] = result >> 0L;
+ inout[2348+1] = result >> 8L;
+ inout[2348+2] = result >> 16L;
+ inout[2348+3] = result >> 24L;
+ break;
+ default:
+ return -1;
+ }
+
+ return 0;
+}
+
+int yazedc::get_sector_type(void)
+{
+ return sectortype;
+}
+
+int yazedc::set_sector_type(int st)
+{
+ switch(st) {
+ case MODE_0:
+ case MODE_1:
+ case MODE_2:
+ case MODE_2_FORM_1:
+ case MODE_2_FORM_2:
+ sectortype = st;
+ default:
+ return -1;
+ }
+ return 0;
+}
diff --git a/luapatch.cpp b/luapatch.cpp index 0dbae95..8e5c8ee 100644 --- a/luapatch.cpp +++ b/luapatch.cpp @@ -10,17 +10,17 @@ #include "cdutils.h"
#include "isobuilder.h"
#include "luacd.h"
-#include "luapsx.h" +#include "luapsx.h"
#include "luapatch-res.h"
-static int myprint(lua_State * _L) { - Lua * L = Lua::find(_L); - String t = L->tostring(); - - Base::printm(M_BARE, t + "\n"); - - return 0; +static int myprint(lua_State * _L) {
+ Lua * L = Lua::find(_L);
+ String t = L->tostring();
+
+ Base::printm(M_BARE, t + "\n");
+
+ return 0;
}
bool Verify(HWND);
@@ -90,7 +90,7 @@ struct texts_t t_french[] = { struct texts_t t_german[] = {
{IDC_ABOUTTEXT, IDD_ABOUT,
"LuaPatch version 0.3.0\n"
-"Adaptierte MFC Version \"Eve\"\n\n" +"Adaptierte MFC Version \"Eve\"\n\n"
"CD Patch System\n\n"
"Copyright © 2003-2004 Nicolas \"Pixel\" Noble / NOBIS\n\n"
"http://www.nobis-crew.org/luapatch/\n"
@@ -98,7 +98,7 @@ struct texts_t t_german[] = { {IDCANCEL, IDD_FILESELECT, "Beenden"},
{IDC_ABOUT, IDD_FILESELECT, "Info"},
{IDC_ST_SOURCETYPE, IDD_FILESELECT, "Quelletyp:"},
- {IDC_ST_SOURCE, IDD_FILESELECT, "Quelle:"}, + {IDC_ST_SOURCE, IDD_FILESELECT, "Quelle:"},
{IDC_ST_DEST, IDD_FILESELECT, "Ziel Datei:"},
{IDC_ST_PATCH, IDD_FILESELECT, "Patch Datei:"},
{ISOFILE, 0, "Iso Image"},
@@ -299,14 +299,14 @@ BOOL CALLBACK FileSelectDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam ComboBox_SetCurSel(control, 1);
control = GetDlgItem(hW, IDC_DRIVE);
- - std::vector<String> p; - p = cdabstract::probe(); - - for (std::vector<String>::iterator i = p.begin(); i != p.end(); i++) { - ComboBox_AddString(control, i->to_charp()); - } - ComboBox_SetCurSel(control, 0); +
+ std::vector<String> p;
+ p = cdabstract::probe();
+
+ for (std::vector<String>::iterator i = p.begin(); i != p.end(); i++) {
+ ComboBox_AddString(control, i->to_charp());
+ }
+ ComboBox_SetCurSel(control, 0);
fromdrive = true;
ShowWindow(GetDlgItem(hW, IDC_DRIVE), SW_SHOW);
ShowWindow(GetDlgItem(hW, IDC_SOURCE), SW_HIDE);
@@ -418,47 +418,47 @@ virtual int startup(void) throw (GeneralException) { if (quit)
exit(0);
- - Input * fpatch = new Input(patch); - fpatch->seek(0); - - new Archive(fpatch); +
+ Input * fpatch = new Input(patch);
+ fpatch->seek(0);
+
+ new Archive(fpatch);
Output * o;
cdutils * cdutil;
Handle * iso_r;
- cdutil = new cdutils(iso_r = cdabstract::open_cd(source)); + cdutil = new cdutils(iso_r = cdabstract::open_cd(source));
isobuilder * b = new isobuilder(o = new Output(dest));
- - Lua * L = new Lua(); - L->open_base(); - L->open_math(); - L->open_string(); - L->open_table(); - LuaInput::pushconstruct(L); - LuaOutput::pushconstruct(L); - LuaBuffer::pushconstruct(L); - CD_PUSHSTATICS(L); - Luapsx::pushstatics(L); - L->push("print"); - L->push(myprint); - L->settable(LUA_GLOBALSINDEX); - - Luacdutils lcdutil(cdutil); - L->push("cdutil"); - lcdutil.push(L); - L->setvar(); - Luaisobuilder liso(b); - L->push("iso"); - liso.push(L); - L->setvar(); - L->load(&Input("main")); - - delete b; - delete o; - delete cdutil; - delete iso_r; +
+ Lua * L = new Lua();
+ L->open_base();
+ L->open_math();
+ L->open_string();
+ L->open_table();
+ LuaInput::pushconstruct(L);
+ LuaOutput::pushconstruct(L);
+ LuaBuffer::pushconstruct(L);
+ CD_PUSHSTATICS(L);
+ Luapsx::pushstatics(L);
+ L->push("print");
+ L->push(myprint);
+ L->settable(LUA_GLOBALSINDEX);
+
+ Luacdutils lcdutil(cdutil);
+ L->push("cdutil");
+ lcdutil.push(L);
+ L->setvar();
+ Luaisobuilder liso(b);
+ L->push("iso");
+ liso.push(L);
+ L->setvar();
+ L->load(&Input("main"));
+
+ delete b;
+ delete o;
+ delete cdutil;
+ delete iso_r;
return 0;
}
diff --git a/lzss-main.cpp b/lzss-main.cpp index ec17495..b5587a2 100644 --- a/lzss-main.cpp +++ b/lzss-main.cpp @@ -1,403 +1,403 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <getopt.h> -#include "Input.h" -#include "Output.h" -#include "generic.h" -#include "lzss.h" -#include "Main.h" - -int lga = 0; - -struct option long_options[] = { - {"1iscomp", 1, &lga, 1 }, - {"overlap", 1, &lga, 2 }, - {"16bits", 1, &lga, 11 }, - {"negative", 1, &lga, 12 }, - {"ptrb", 1, &lga, 13 }, - {"filling", 1, &lga, 14 }, - {"inverse", 1, &lga, 23 }, - {"onejump", 1, &lga, 24 }, - {"window", 1, &lga, 25 }, - {"lmask1", 1, &lga, 3 }, - {"lshft1", 1, &lga, 4 }, - {"lmask2", 1, &lga, 5 }, - {"lshft2", 1, &lga, 6 }, - {"jmask1", 1, &lga, 7 }, - {"jshft1", 1, &lga, 8 }, - {"jmask2", 1, &lga, 9 }, - {"jshft2", 1, &lga, 10 }, - {"fmask1", 1, &lga, 15 }, - {"fshft1", 1, &lga, 16 }, - {"fmask2", 1, &lga, 17 }, - {"fshft2", 1, &lga, 18 }, - {"vmask1", 1, &lga, 19 }, - {"vshft1", 1, &lga, 20 }, - {"vmask2", 1, &lga, 21 }, - {"vshft2", 1, &lga, 22 }, - {"help", 0, NULL, 'h'}, - {"scheme", 1, NULL, 's'}, - {"length", 1, NULL, 'l'}, - {"version", 0, NULL, 'V'}, - {"verbose", 0, NULL, 'v'}, - {"show", 0, NULL, 'S'}, - {"dump", 0, NULL, 'D'}, - {"compress", 0, NULL, 'c'}, - {"decompress", 0, NULL, 'd'}, - {"blocks", 0, NULL, 'b'}, - {0, 0, NULL, 0 } -}; - -CODE_BEGINS -public: -Appli() : lzsscompress(1), lzss_o(new lzss) {} -virtual ~Appli() { - delete lzss_o; -} -private: - -char * fn1, * fn2, * pname; - -int lzsscompress; - -lzss * lzss_o; - -void showhelp(void) { - printm(M_BARE, -"Usages:\n" -" %s <--help|-h|-H|-?> Show this help and exit.\n" -" %s <--dump> Show the built-in schemes and exit.\n" -" %s <--version|-V> Show the version and copyrights and exit.\n" -" %s [-c|-d] [-s <scheme>] [-l <length>] [-S] [-v] <infile> <outfile>\n" -"\n" -"-c --compress Compress <infile> to <outfile>\n" -"-d --decompress Decompress <infile> to <outfile>\n" -"-s <scheme> --scheme=<scheme> Loads the built-in scheme number <scheme>\n" -"-l <length> --length=<length> Specify the true length for decompression,\n" -" or enable the padding behavior for compression.\n" -"-S --show Show the actual scheme before processing.\n" -"-v --verbose Display a *LOT* of informations.\n" -"-b --blocks Switch to blocks decompression behaviour\n" -"\n" -"Additionnaly you have the scheme manipulation options:\n" -"--1iscomp --overlap --negative --16bits --ptrb\n" -"--filling --inverse --onejump --window\n" -"--lmask1 --lshft1 --lmask2 --lshft2 --jmask1 --jshft1 --jmask2 --jshft2\n" -"--vmask1 --vshft1 --vmask2 --vshft2 --fmask1 --fshft1 --fmask2 --fshft2\n" -"\n" -"If you don't know what they are, forget them.\n" -"\n" -"Default behavior is to %scompress.\n" -"\n", pname, pname, pname, pname, lzsscompress ? "" : "de"); -} - -void showscheme(void) { - lzss::scheme_t scheme = lzss_o->get_scheme(); - printm(M_BARE, -"Actual scheme:\n" -"--1iscomp %i\n" -"--overlap %i\n" -"--negative %i\n" -"--16bits %i\n" -"--ptrb %i\n" -"--filling %i\n" -"--inverse %i\n" -"--onejump %i\n" -"--window %i\n" -"--lmask1 0x%02x\n" -"--lshft1 %i\n" -"--lmask2 0x%02x\n" -"--lshft2 %i\n" -"--jmask1 0x%02x\n" -"--jshft1 %i\n" -"--jmask2 0x%02x\n" -"--jshft2 %i\n" -"--fmask1 0x%02x\n" -"--fshft1 %i\n" -"--fmask2 0x%02x\n" -"--fshft2 %i\n" -"--vmask1 0x%02x\n" -"--vshft1 %i\n" -"--vmask2 0x%02x\n" -"--vshft2 %i\n\n", -scheme.one_is_compressed, scheme.overlap_trick, scheme.negative_trick, scheme.sixteen_bits, -scheme.ptrb, scheme.filling, scheme.bitmap_inversed, scheme.one_jump, scheme.window_start, -scheme.l_mask_1, scheme.l_shft_1, scheme.l_mask_2, scheme.l_shft_2, -scheme.j_mask_1, scheme.j_shft_1, scheme.j_mask_2, scheme.j_shft_2, -scheme.f_mask_1, scheme.f_shft_1, scheme.f_mask_2, scheme.f_shft_2, -scheme.v_mask_1, scheme.v_shft_1, scheme.v_mask_2, scheme.v_shft_2); -} - -void dump(void) { - int i; - - printm(M_BARE, "Built-in schemes:\n"); - for (i = 0; lzss::schemes[i].name; i++) { - printm(M_BARE, "%2i - %s\n", i, lzss::schemes[i].name); - } -} - -virtual int startup() throw (GeneralException) { - int length = -1; - Handle * f1, * f2; - int p, show = 0; - int c, s, t; - lzss::scheme_t scheme = lzss_o->get_scheme(); - - pname = strdup(argv[0]); - p = strlen(pname) - 5; - - verbosity = M_STATUS; - -#ifdef __linux__ - if (!strcasecmp(pname + p, "dlzss")) { - lzsscompress = 0; - } -#endif - - printm(M_BARE, -LZSS_NAME + " compressor/decompressor version " + LZSS_VERSION + ",\n" -"Copyright (C) 2002 Nicolas \"Pixel\" Noble\n" -"This software comes with ABSOLUTELY NO WARRANTY; see COPYING for details\n" -"Thanks to Czar Dragon, for his little 'lzss' schemes FAQ.\n" -"Special thanks to Yazoo, who taught me PSX hacking.\n" -"\n"); - - while ((c = getopt_long(argc, argv, "Hhs:l:vVScdb", long_options, NULL)) != EOF) { - switch (c) { - case 0: - switch (lga) { - case 1: - t = atoi(optarg); - if ((t != 1) && (t != 0)) { - printm(M_ERROR, "Invalid value for boolean: %s\n", optarg); - } else { - scheme.one_is_compressed = t; - } - break; - case 2: - t = atoi(optarg); - if ((t != 1) && (t != 0)) { - printm(M_ERROR, "Invalid value for boolean: %s\n", optarg); - } else { - scheme.overlap_trick = t; - } - break; - case 3: - sscanf(optarg, "%i", &scheme.l_mask_1); - break; - case 4: - scheme.l_shft_1 = atoi(optarg); - break; - case 5: - sscanf(optarg, "%i", &scheme.l_mask_2); - break; - case 6: - scheme.l_shft_2 = atoi(optarg); - break; - case 7: - sscanf(optarg, "%i", &scheme.j_mask_1); - break; - case 8: - scheme.j_shft_1 = atoi(optarg); - break; - case 9: - sscanf(optarg, "%i", &scheme.j_mask_2); - break; - case 10: - scheme.j_mask_2 = atoi(optarg); - break; - case 11: - t = atoi(optarg); - if ((t != 1) && (t != 0)) { - printm(M_ERROR, "Invalid value for boolean: %s\n", optarg); - } else { - scheme.sixteen_bits = t; - } - break; - case 12: - t = atoi(optarg); - if ((t != 1) && (t != 0)) { - printm(M_ERROR, "Invalid value for boolean: %s\n", optarg); - } else { - scheme.negative_trick = t; - } - break; - case 13: - t = atoi(optarg); - if ((t != 2) && (t != 1) && (t != 0)) { - printm(M_ERROR, "Invalid value for ter: %s\n", optarg); - } else { - scheme.ptrb = t; - } - break; - case 14: - t = atoi(optarg); - if ((t != 2) && (t != 1) && (t != 0)) { - printm(M_ERROR, "Invalid value for ter: %s\n", optarg); - } else { - scheme.filling = t; - } - break; - case 15: - sscanf(optarg, "%i", &scheme.f_mask_1); - break; - case 16: - scheme.f_shft_1 = atoi(optarg); - break; - case 17: - sscanf(optarg, "%i", &scheme.f_mask_2); - break; - case 18: - scheme.f_shft_2 = atoi(optarg); - break; - case 19: - sscanf(optarg, "%i", &scheme.v_mask_1); - break; - case 20: - scheme.v_shft_1 = atoi(optarg); - break; - case 21: - sscanf(optarg, "%i", &scheme.v_mask_2); - break; - case 22: - scheme.v_mask_2 = atoi(optarg); - break; - case 23: - t = atoi(optarg); - if ((t != 1) && (t != 0)) { - printm(M_ERROR, "Invalid value for boolean: %s\n", optarg); - } else { - scheme.bitmap_inversed = t; - } - break; - case 24: - t = atoi(optarg); - if ((t != 1) && (t != 0)) { - printm(M_ERROR, "Invalid value for boolean: %s\n", optarg); - } else { - scheme.one_jump = t; - } - break; - case 25: - t = sscanf(optarg, "%i", &scheme.window_start); - break; - default: - showhelp(); - printm(M_ERROR, "Unknow option.\n"); - exit(-1); - } - break; - case '?': - case 'H': - case 'h': - showhelp(); - exit(0); - case 's': - s = atoi(optarg); - if (s >= lzss_o->END) { - printm(M_ERROR, "%s: value too high (no such scheme)\n", s); - exit(-1); - } - scheme = lzss::schemes[s]; - break; - case 'l': - length = atoi(optarg); - break; - case 'v': - verbosity = M_INFO; - break; - case 'V': - exit(0); - case 'S': - show = 1; - break; - case 'D': - dump(); - exit(0); - break; - case 'd': - lzsscompress = 0; - break; - case 'c': - lzsscompress = 1; - break; - case 'b': - lzss_o->blockb = 1; - break; - default: - showhelp(); - printm(M_ERROR, "Unknow option.\n"); - exit(-1); - } - } - - if (show) showscheme(); - - if (optind != (argc - 2)) { - if (optind > (argc - 2)) { - printm(M_ERROR, "Not enough filenames\n"); - exit(-1); - } else { - printm(M_ERROR, "Too much arguments\n"); - exit(-1); - } - } - - fn1 = argv[optind++]; - fn2 = argv[optind++]; - - f1 = new Input(fn1); - - f2 = new Output(fn2); - - if (lzsscompress) { - printm(M_STATUS, "Compressing `%s' to `%s'...\n", fn1, fn2); - } else { - printm(M_STATUS, "Decompressing `%s' to `%s'...\n", fn1, fn2); - } - - lzss_o->change_scheme(scheme); - - if (lzsscompress) { - if (length == -1) { - lzss_o->lzss_comp(f1, f2); - } else { - lzss_o->lzss_comp(f1, f2, &length); - } - } else { - length = lzss_o->lzss_decomp(f1, f2, length); - } - - printm(M_STATUS, "Done, filesize changed from %i to %i.\n", f1->GetSize(), f2->GetSize()); - if (!lzss_o->bitmap_count) - lzss_o->bitmap_count = 8; - if (lzsscompress) - printm(M_STATUS, "Compressed %i = 0x%08x blocs, containing %i = 0x%08x chunks.\n", lzss_o->blk + 1, lzss_o->blk + 1, lzss_o->blk * 8 + lzss_o->bitmap_count, lzss_o->blk * 8 + lzss_o->bitmap_count); - - delete f1; - delete f2; - - return 0; -} -CODE_ENDS +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include "Input.h"
+#include "Output.h"
+#include "generic.h"
+#include "lzss.h"
+#include "Main.h"
+
+int lga = 0;
+
+struct option long_options[] = {
+ {"1iscomp", 1, &lga, 1 },
+ {"overlap", 1, &lga, 2 },
+ {"16bits", 1, &lga, 11 },
+ {"negative", 1, &lga, 12 },
+ {"ptrb", 1, &lga, 13 },
+ {"filling", 1, &lga, 14 },
+ {"inverse", 1, &lga, 23 },
+ {"onejump", 1, &lga, 24 },
+ {"window", 1, &lga, 25 },
+ {"lmask1", 1, &lga, 3 },
+ {"lshft1", 1, &lga, 4 },
+ {"lmask2", 1, &lga, 5 },
+ {"lshft2", 1, &lga, 6 },
+ {"jmask1", 1, &lga, 7 },
+ {"jshft1", 1, &lga, 8 },
+ {"jmask2", 1, &lga, 9 },
+ {"jshft2", 1, &lga, 10 },
+ {"fmask1", 1, &lga, 15 },
+ {"fshft1", 1, &lga, 16 },
+ {"fmask2", 1, &lga, 17 },
+ {"fshft2", 1, &lga, 18 },
+ {"vmask1", 1, &lga, 19 },
+ {"vshft1", 1, &lga, 20 },
+ {"vmask2", 1, &lga, 21 },
+ {"vshft2", 1, &lga, 22 },
+ {"help", 0, NULL, 'h'},
+ {"scheme", 1, NULL, 's'},
+ {"length", 1, NULL, 'l'},
+ {"version", 0, NULL, 'V'},
+ {"verbose", 0, NULL, 'v'},
+ {"show", 0, NULL, 'S'},
+ {"dump", 0, NULL, 'D'},
+ {"compress", 0, NULL, 'c'},
+ {"decompress", 0, NULL, 'd'},
+ {"blocks", 0, NULL, 'b'},
+ {0, 0, NULL, 0 }
+};
+
+CODE_BEGINS
+public:
+Appli() : lzsscompress(1), lzss_o(new lzss) {}
+virtual ~Appli() {
+ delete lzss_o;
+}
+private:
+
+char * fn1, * fn2, * pname;
+
+int lzsscompress;
+
+lzss * lzss_o;
+
+void showhelp(void) {
+ printm(M_BARE,
+"Usages:\n"
+" %s <--help|-h|-H|-?> Show this help and exit.\n"
+" %s <--dump> Show the built-in schemes and exit.\n"
+" %s <--version|-V> Show the version and copyrights and exit.\n"
+" %s [-c|-d] [-s <scheme>] [-l <length>] [-S] [-v] <infile> <outfile>\n"
+"\n"
+"-c --compress Compress <infile> to <outfile>\n"
+"-d --decompress Decompress <infile> to <outfile>\n"
+"-s <scheme> --scheme=<scheme> Loads the built-in scheme number <scheme>\n"
+"-l <length> --length=<length> Specify the true length for decompression,\n"
+" or enable the padding behavior for compression.\n"
+"-S --show Show the actual scheme before processing.\n"
+"-v --verbose Display a *LOT* of informations.\n"
+"-b --blocks Switch to blocks decompression behaviour\n"
+"\n"
+"Additionnaly you have the scheme manipulation options:\n"
+"--1iscomp --overlap --negative --16bits --ptrb\n"
+"--filling --inverse --onejump --window\n"
+"--lmask1 --lshft1 --lmask2 --lshft2 --jmask1 --jshft1 --jmask2 --jshft2\n"
+"--vmask1 --vshft1 --vmask2 --vshft2 --fmask1 --fshft1 --fmask2 --fshft2\n"
+"\n"
+"If you don't know what they are, forget them.\n"
+"\n"
+"Default behavior is to %scompress.\n"
+"\n", pname, pname, pname, pname, lzsscompress ? "" : "de");
+}
+
+void showscheme(void) {
+ lzss::scheme_t scheme = lzss_o->get_scheme();
+ printm(M_BARE,
+"Actual scheme:\n"
+"--1iscomp %i\n"
+"--overlap %i\n"
+"--negative %i\n"
+"--16bits %i\n"
+"--ptrb %i\n"
+"--filling %i\n"
+"--inverse %i\n"
+"--onejump %i\n"
+"--window %i\n"
+"--lmask1 0x%02x\n"
+"--lshft1 %i\n"
+"--lmask2 0x%02x\n"
+"--lshft2 %i\n"
+"--jmask1 0x%02x\n"
+"--jshft1 %i\n"
+"--jmask2 0x%02x\n"
+"--jshft2 %i\n"
+"--fmask1 0x%02x\n"
+"--fshft1 %i\n"
+"--fmask2 0x%02x\n"
+"--fshft2 %i\n"
+"--vmask1 0x%02x\n"
+"--vshft1 %i\n"
+"--vmask2 0x%02x\n"
+"--vshft2 %i\n\n",
+scheme.one_is_compressed, scheme.overlap_trick, scheme.negative_trick, scheme.sixteen_bits,
+scheme.ptrb, scheme.filling, scheme.bitmap_inversed, scheme.one_jump, scheme.window_start,
+scheme.l_mask_1, scheme.l_shft_1, scheme.l_mask_2, scheme.l_shft_2,
+scheme.j_mask_1, scheme.j_shft_1, scheme.j_mask_2, scheme.j_shft_2,
+scheme.f_mask_1, scheme.f_shft_1, scheme.f_mask_2, scheme.f_shft_2,
+scheme.v_mask_1, scheme.v_shft_1, scheme.v_mask_2, scheme.v_shft_2);
+}
+
+void dump(void) {
+ int i;
+
+ printm(M_BARE, "Built-in schemes:\n");
+ for (i = 0; lzss::schemes[i].name; i++) {
+ printm(M_BARE, "%2i - %s\n", i, lzss::schemes[i].name);
+ }
+}
+
+virtual int startup() throw (GeneralException) {
+ int length = -1;
+ Handle * f1, * f2;
+ int p, show = 0;
+ int c, s, t;
+ lzss::scheme_t scheme = lzss_o->get_scheme();
+
+ pname = strdup(argv[0]);
+ p = strlen(pname) - 5;
+
+ verbosity = M_STATUS;
+
+#ifdef __linux__
+ if (!strcasecmp(pname + p, "dlzss")) {
+ lzsscompress = 0;
+ }
+#endif
+
+ printm(M_BARE,
+LZSS_NAME + " compressor/decompressor version " + LZSS_VERSION + ",\n"
+"Copyright (C) 2002 Nicolas \"Pixel\" Noble\n"
+"This software comes with ABSOLUTELY NO WARRANTY; see COPYING for details\n"
+"Thanks to Czar Dragon, for his little 'lzss' schemes FAQ.\n"
+"Special thanks to Yazoo, who taught me PSX hacking.\n"
+"\n");
+
+ while ((c = getopt_long(argc, argv, "Hhs:l:vVScdb", long_options, NULL)) != EOF) {
+ switch (c) {
+ case 0:
+ switch (lga) {
+ case 1:
+ t = atoi(optarg);
+ if ((t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for boolean: %s\n", optarg);
+ } else {
+ scheme.one_is_compressed = t;
+ }
+ break;
+ case 2:
+ t = atoi(optarg);
+ if ((t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for boolean: %s\n", optarg);
+ } else {
+ scheme.overlap_trick = t;
+ }
+ break;
+ case 3:
+ sscanf(optarg, "%i", &scheme.l_mask_1);
+ break;
+ case 4:
+ scheme.l_shft_1 = atoi(optarg);
+ break;
+ case 5:
+ sscanf(optarg, "%i", &scheme.l_mask_2);
+ break;
+ case 6:
+ scheme.l_shft_2 = atoi(optarg);
+ break;
+ case 7:
+ sscanf(optarg, "%i", &scheme.j_mask_1);
+ break;
+ case 8:
+ scheme.j_shft_1 = atoi(optarg);
+ break;
+ case 9:
+ sscanf(optarg, "%i", &scheme.j_mask_2);
+ break;
+ case 10:
+ scheme.j_mask_2 = atoi(optarg);
+ break;
+ case 11:
+ t = atoi(optarg);
+ if ((t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for boolean: %s\n", optarg);
+ } else {
+ scheme.sixteen_bits = t;
+ }
+ break;
+ case 12:
+ t = atoi(optarg);
+ if ((t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for boolean: %s\n", optarg);
+ } else {
+ scheme.negative_trick = t;
+ }
+ break;
+ case 13:
+ t = atoi(optarg);
+ if ((t != 2) && (t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for ter: %s\n", optarg);
+ } else {
+ scheme.ptrb = t;
+ }
+ break;
+ case 14:
+ t = atoi(optarg);
+ if ((t != 2) && (t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for ter: %s\n", optarg);
+ } else {
+ scheme.filling = t;
+ }
+ break;
+ case 15:
+ sscanf(optarg, "%i", &scheme.f_mask_1);
+ break;
+ case 16:
+ scheme.f_shft_1 = atoi(optarg);
+ break;
+ case 17:
+ sscanf(optarg, "%i", &scheme.f_mask_2);
+ break;
+ case 18:
+ scheme.f_shft_2 = atoi(optarg);
+ break;
+ case 19:
+ sscanf(optarg, "%i", &scheme.v_mask_1);
+ break;
+ case 20:
+ scheme.v_shft_1 = atoi(optarg);
+ break;
+ case 21:
+ sscanf(optarg, "%i", &scheme.v_mask_2);
+ break;
+ case 22:
+ scheme.v_mask_2 = atoi(optarg);
+ break;
+ case 23:
+ t = atoi(optarg);
+ if ((t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for boolean: %s\n", optarg);
+ } else {
+ scheme.bitmap_inversed = t;
+ }
+ break;
+ case 24:
+ t = atoi(optarg);
+ if ((t != 1) && (t != 0)) {
+ printm(M_ERROR, "Invalid value for boolean: %s\n", optarg);
+ } else {
+ scheme.one_jump = t;
+ }
+ break;
+ case 25:
+ t = sscanf(optarg, "%i", &scheme.window_start);
+ break;
+ default:
+ showhelp();
+ printm(M_ERROR, "Unknow option.\n");
+ exit(-1);
+ }
+ break;
+ case '?':
+ case 'H':
+ case 'h':
+ showhelp();
+ exit(0);
+ case 's':
+ s = atoi(optarg);
+ if (s >= lzss_o->END) {
+ printm(M_ERROR, "%s: value too high (no such scheme)\n", s);
+ exit(-1);
+ }
+ scheme = lzss::schemes[s];
+ break;
+ case 'l':
+ length = atoi(optarg);
+ break;
+ case 'v':
+ verbosity = M_INFO;
+ break;
+ case 'V':
+ exit(0);
+ case 'S':
+ show = 1;
+ break;
+ case 'D':
+ dump();
+ exit(0);
+ break;
+ case 'd':
+ lzsscompress = 0;
+ break;
+ case 'c':
+ lzsscompress = 1;
+ break;
+ case 'b':
+ lzss_o->blockb = 1;
+ break;
+ default:
+ showhelp();
+ printm(M_ERROR, "Unknow option.\n");
+ exit(-1);
+ }
+ }
+
+ if (show) showscheme();
+
+ if (optind != (argc - 2)) {
+ if (optind > (argc - 2)) {
+ printm(M_ERROR, "Not enough filenames\n");
+ exit(-1);
+ } else {
+ printm(M_ERROR, "Too much arguments\n");
+ exit(-1);
+ }
+ }
+
+ fn1 = argv[optind++];
+ fn2 = argv[optind++];
+
+ f1 = new Input(fn1);
+
+ f2 = new Output(fn2);
+
+ if (lzsscompress) {
+ printm(M_STATUS, "Compressing `%s' to `%s'...\n", fn1, fn2);
+ } else {
+ printm(M_STATUS, "Decompressing `%s' to `%s'...\n", fn1, fn2);
+ }
+
+ lzss_o->change_scheme(scheme);
+
+ if (lzsscompress) {
+ if (length == -1) {
+ lzss_o->lzss_comp(f1, f2);
+ } else {
+ lzss_o->lzss_comp(f1, f2, &length);
+ }
+ } else {
+ length = lzss_o->lzss_decomp(f1, f2, length);
+ }
+
+ printm(M_STATUS, "Done, filesize changed from %i to %i.\n", f1->GetSize(), f2->GetSize());
+ if (!lzss_o->bitmap_count)
+ lzss_o->bitmap_count = 8;
+ if (lzsscompress)
+ printm(M_STATUS, "Compressed %i = 0x%08x blocs, containing %i = 0x%08x chunks.\n", lzss_o->blk + 1, lzss_o->blk + 1, lzss_o->blk * 8 + lzss_o->bitmap_count, lzss_o->blk * 8 + lzss_o->bitmap_count);
+
+ delete f1;
+ delete f2;
+
+ return 0;
+}
+CODE_ENDS
diff --git a/mipspoke.cpp b/mipspoke.cpp index e4551fb..ef956fd 100644 --- a/mipspoke.cpp +++ b/mipspoke.cpp @@ -1,30 +1,30 @@ -#include <Main.h> -#include <Input.h> - -#include "mips.h" -#include "mipsdis.h" -#include "mipsdump.h" - -CODE_BEGINS -virtual int startup(void) throw (GeneralException) { - mipsmem * mymips = new mipsmem(); - Handle * exe = new Input("psx.exe"); - Disassembler * dis = new Disassembler(mymips); - Dumper * dump = new Dumper(mymips); - - verbosity = M_INFO; - - mymips->LoadPSYQ(exe); - - dis->mainloop(); - delete dis; - - printm(M_STATUS, "Finished crawling, dumping...\n"); - - dump->process(); - - while (true); - - return 0; -} -CODE_ENDS +#include <Main.h>
+#include <Input.h>
+
+#include "mips.h"
+#include "mipsdis.h"
+#include "mipsdump.h"
+
+CODE_BEGINS
+virtual int startup(void) throw (GeneralException) {
+ mipsmem * mymips = new mipsmem();
+ Handle * exe = new Input("psx.exe");
+ Disassembler * dis = new Disassembler(mymips);
+ Dumper * dump = new Dumper(mymips);
+
+ verbosity = M_INFO;
+
+ mymips->LoadPSYQ(exe);
+
+ dis->mainloop();
+ delete dis;
+
+ printm(M_STATUS, "Finished crawling, dumping...\n");
+
+ dump->process();
+
+ while (true);
+
+ return 0;
+}
+CODE_ENDS
diff --git a/psxdev/bs.c b/psxdev/bs.c index a79a877..e7c3526 100644 --- a/psxdev/bs.c +++ b/psxdev/bs.c @@ -1,349 +1,349 @@ -/* - (c)2000 by BERO bero@geocities.co.jp - - under GPL - - some changes by dbalster@psxdev.de - - - all globals now in a context (to use it as shlib) - - removed debugging printfs -*/ - -typedef struct { -/* bit i/o */ - unsigned int bitbuf; - int bitcount,bs_size,totalbit; - unsigned short *bsbuf; -/* huffman */ - int last_dc[3]; - int _type; - int rlsize; - const unsigned char *iqtab; -} bs_context_t; - -#include <stdlib.h> -#include "bs.h" -#include "common.h" - -/* static const char *copyright = N_("Copyright (C) 2000 by Daniel Balster <dbalster@psxdev.de>"); */ - -enum {B,G,R}; -typedef int BLOCK; - -#define DCTSIZE2 64 -#define RGB2Y(r,g,b) ( 0.299*(r) + 0.587*(g) + 0.114*(b) ) -#define RGB2Cb(r,g,b) ( -0.16874*(r) - 0.33126*(g) +0.5*(b) ) -#define RGB2Cr(r,g,b) ( 0.5*(r) - 0.41869*(g) - 0.08131*(b) ) - -/* -16x16 RGB -> 8x8 Cb,Cr,Y0,Y1,Y2,Y3 - -[Y0][Y1] [Cb] [Cr] -[Y2][Y3] -*/ -#define Cb 0 -#define Cr DCTSIZE2 - -static void rgb2yuv (unsigned char image[][3], BLOCK *blk) -{ - int x,y,i; - int tmpblk[16*16][3],(*yuv)[3]; - BLOCK *yblk; - - yuv=tmpblk; - for(i=0;i<16*16;i++) { - yuv[0][0] = RGB2Y (image[0][R],image[0][G],image[0][B])-128; - yuv[0][1] = RGB2Cb(image[0][R],image[0][G],image[0][B]); - yuv[0][2] = RGB2Cr(image[0][R],image[0][G],image[0][B]); - yuv++; image++; - } - - yuv = tmpblk; - yblk = blk+DCTSIZE2*2; - for(y=0;y<16;y+=2,blk+=4,yblk+=8,yuv+=8+16) { - if (y==8) yblk+=DCTSIZE2; - for(x=0;x<4;x++,blk++,yblk+=2,yuv+=2) { - blk[Cb] = (yuv[0][1]+yuv[1][1]+yuv[16][1]+yuv[17][1])/4; - blk[Cr] = (yuv[0][2]+yuv[1][2]+yuv[16][2]+yuv[17][2])/4; - yblk[0] = yuv[ 0][0]; - yblk[1] = yuv[ 1][0]; - yblk[8] = yuv[16][0]; - yblk[9] = yuv[17][0]; - - blk[4+Cb] = (yuv[8+0][1]+yuv[8+1][1]+yuv[8+16][1]+yuv[8+17][1])/4; - blk[4+Cr] = (yuv[8+0][2]+yuv[8+1][2]+yuv[8+16][2]+yuv[8+17][2])/4; - yblk[DCTSIZE2+0] = yuv[8+ 0][0]; - yblk[DCTSIZE2+1] = yuv[8+ 1][0]; - yblk[DCTSIZE2+8] = yuv[8+16][0]; - yblk[DCTSIZE2+9] = yuv[8+17][0]; - } - } -} - -#undef Cb -#undef Cr - -/* bit i/o */ -#define BITBUFSIZE 16 -#define WriteWord(x) ctxt->bsbuf[ctxt->bs_size++]=(x) - -static void putbits_init (bs_context_t *ctxt) -{ - ctxt->bitbuf = 0; - ctxt->bitcount = BITBUFSIZE; - ctxt->bs_size = 0; - ctxt->totalbit = 0; -} - -static void putbits_flush (bs_context_t *ctxt) -{ - WriteWord(ctxt->bitbuf); -} - -static void putbits (bs_context_t *ctxt, unsigned int x, unsigned int n) -{ - ctxt->totalbit+=n; - - if (n<ctxt->bitcount) { - ctxt->bitcount-=n; - ctxt->bitbuf |= x << ctxt->bitcount; - } else { - n-=ctxt->bitcount; - WriteWord(ctxt->bitbuf | (x>>n) ); - if (n<BITBUFSIZE) { - ctxt->bitcount = BITBUFSIZE-n; - } else { - WriteWord( x>>(n-BITBUFSIZE) ); - ctxt->bitcount = BITBUFSIZE*2-n; - } - ctxt->bitbuf = x << ctxt->bitcount; - } -} - -typedef struct { - unsigned int code,nbits; -} huff_t; - -const static huff_t dc_y_table[] = { - {4,3},{0,2},{1,2},{5,3},{6,3},{14,4},{30,5},{62,6},{126,7},{254,8} -}; - -const static huff_t dc_c_table[] = { - {0,2},{1,2},{2,2},{6,3},{14,4},{30,5},{62,6},{126,7},{254,8},{510,9} -}; - -#include "table.h" - -static void encode_init (bs_context_t *ctxt, void *outbuf, int type, int q_scale) -{ - ctxt->_type = type; - ctxt->last_dc[0] = 0; - ctxt->last_dc[1] = 0; - ctxt->last_dc[2] = 0; - ctxt->rlsize = 0; - putbits_init(ctxt); - - ctxt->bsbuf = outbuf; - ctxt->bsbuf[1] = 0x3800; - ctxt->bsbuf[2] = q_scale; - ctxt->bsbuf[3] = type; - ctxt->bs_size+=4; -} - -static void encode_finish (bs_context_t *ctxt) -{ - putbits_flush(ctxt); - ctxt->bsbuf[0] = (((ctxt->rlsize+1)/2)+31)&~31; -} - -static void encode_dc (bs_context_t *ctxt, int n, int level) -{ - if (ctxt->_type==2) { - putbits(ctxt,level&0x3ff,10); - } else { - const huff_t *table; - int prev,cnt; - - level = level/4; - if (n<2) { - table = dc_c_table; - prev = ctxt->last_dc[n]; - ctxt->last_dc[n] = level; - } else { - table = dc_y_table; - prev = ctxt->last_dc[2]; - ctxt->last_dc[2] = level; - } - level -= prev; - if (level==0) cnt=0; - else { - int alevel = level; - if (alevel<0) alevel=-alevel; - for(cnt=8;(alevel>>cnt)==0;cnt--); - cnt++; - if (level<0) level--; - } - putbits(ctxt,table[cnt].code,table[cnt].nbits); - if (cnt) putbits(ctxt,level&((1<<cnt)-1),cnt); - } - ctxt->rlsize++; -} - -static void encode_ac (bs_context_t *ctxt, int run, int level) -{ - int abslevel,sign; - if (level>0) { - abslevel = level; - sign = 0; - } else { - abslevel = -level; - sign = 1; - } - if (run<=31 && abslevel<=maxlevel[run]) { - putbits(ctxt,huff_table[run][abslevel-1].code+sign,huff_table[run][abslevel-1].nbits); - } else { - /* ESCAPE */ - putbits(ctxt,1,6); - putbits(ctxt,(run<<10)+(level&0x3ff),16); - } - ctxt->rlsize++; -} - -static void encode_eob (bs_context_t *ctxt) -{ - putbits(ctxt, 2,2); - ctxt->rlsize++; -} - -extern void DCT(BLOCK *blk); - -unsigned char zscan[DCTSIZE2] = { - 0 ,1 ,8 ,16,9 ,2 ,3 ,10, - 17,24,32,25,18,11,4 ,5 , - 12,19,26,33,40,48,41,34, - 27,20,13,6 ,7 ,14,21,28, - 35,42,49,56,57,50,43,36, - 29,22,15,23,30,37,44,51, - 58,59,52,45,38,31,39,46, - 53,60,61,54,47,55,62,63 -}; - -static unsigned char xxx_iqtab[DCTSIZE2] = { - 2,16,19,22,26,27,29,34, - 16,16,22,24,27,29,34,37, - 19,22,26,27,29,34,34,38, - 22,22,26,27,29,34,37,40, - 22,26,27,29,32,35,40,48, - 26,27,29,32,35,40,48,58, - 26,27,29,34,38,46,56,69, - 27,29,35,38,46,56,69,83 -}; - -const unsigned char *bs_iqtab (void) { return xxx_iqtab; } - -static void blk2huff (bs_context_t *ctxt,BLOCK *blk,int q_scale) -{ - int i,k,run,level; - for(i=0;i<6;i++) { - DCT(blk); - for(k=0;k<DCTSIZE2;k++) blk[k]>>=3; - level = blk[0]/ctxt->iqtab[0]; - encode_dc(ctxt,i,level); - run = 0; - for(k=1;k<64;k++) { - level = blk[zscan[k]]*8/(ctxt->iqtab[zscan[k]]*q_scale); - if (level==0) { - run++; - } else { - encode_ac(ctxt,run,level); - run=0; - } - } - encode_eob(ctxt); - blk+=DCTSIZE2; - } -} - -Uint8 bs_roundtbl[256*3]; - -void bs_init (void) -{ - int i; - for(i=0;i<256;i++) { - bs_roundtbl [i]=0; - bs_roundtbl [i+256]=i; - bs_roundtbl [i+512]=255; - } -} - -int bs_encode (bs_header_t *outbuf,bs_input_image_t *img,int type,int q_scale, - const unsigned char *myiqtab) -{ - unsigned char image[16][16][3]; - BLOCK blk[6][DCTSIZE2]; - bs_context_t *ctxt = malloc(sizeof(bs_context_t)); - - int x,y,xw,yw,rl; - - ctxt->iqtab = myiqtab ? myiqtab : bs_iqtab(); - - encode_init (ctxt,outbuf,type,q_scale); - - for(x=0;x<img->width;x+=16) { - xw = img->width-x; if (xw>16) xw = 16; - for(y=0;y<img->height;y+=16) { - unsigned char *p0 = img->top + x*(img->bit)/8 + y*img->nextline; - int i,j=0; - yw = img->height-y; if (yw>16) yw = 16; - - /* get 16x16 image */ - - for(i=0;i<yw;i++) { - unsigned char *p = p0; - p0+=img->nextline; - switch(img->bit) { - case 16: - for(j=0;j<xw;j++) { - int c = *(unsigned short*)p; - image[i][j][B] = ((c>>10)&31)*8; - image[i][j][G] = ((c>>5)&31)*8; - image[i][j][R] = ((c&31))*8; - p+=2; - } - break; - case 24: - for(j=0;j<xw;j++) { - image[i][j][R] = p[R]; - image[i][j][G] = p[G]; - image[i][j][B] = p[B]; - p+=3; - } - break; - } - for(;j<16;j++) { - image[i][j][R] = image[i][xw-1][R]; - image[i][j][G] = image[i][xw-1][G]; - image[i][j][B] = image[i][xw-1][B]; - } - } - - for(;i<16;i++) { - for(j=0;j<16;j++) { - image[i][j][R] = image[yw-1][j][R]; - image[i][j][G] = image[yw-1][j][G]; - image[i][j][B] = image[yw-1][j][B]; - } - } - - rgb2yuv(image[0],blk[0]); - blk2huff(ctxt,blk[0],q_scale); - } - } - - encode_finish(ctxt); - - rl = (ctxt->bs_size * 2); - free (ctxt); - - return rl; -} +/*
+ (c)2000 by BERO bero@geocities.co.jp
+
+ under GPL
+
+ some changes by dbalster@psxdev.de
+
+ - all globals now in a context (to use it as shlib)
+ - removed debugging printfs
+*/
+
+typedef struct {
+/* bit i/o */
+ unsigned int bitbuf;
+ int bitcount,bs_size,totalbit;
+ unsigned short *bsbuf;
+/* huffman */
+ int last_dc[3];
+ int _type;
+ int rlsize;
+ const unsigned char *iqtab;
+} bs_context_t;
+
+#include <stdlib.h>
+#include "bs.h"
+#include "common.h"
+
+/* static const char *copyright = N_("Copyright (C) 2000 by Daniel Balster <dbalster@psxdev.de>"); */
+
+enum {B,G,R};
+typedef int BLOCK;
+
+#define DCTSIZE2 64
+#define RGB2Y(r,g,b) ( 0.299*(r) + 0.587*(g) + 0.114*(b) )
+#define RGB2Cb(r,g,b) ( -0.16874*(r) - 0.33126*(g) +0.5*(b) )
+#define RGB2Cr(r,g,b) ( 0.5*(r) - 0.41869*(g) - 0.08131*(b) )
+
+/*
+16x16 RGB -> 8x8 Cb,Cr,Y0,Y1,Y2,Y3
+
+[Y0][Y1] [Cb] [Cr]
+[Y2][Y3]
+*/
+#define Cb 0
+#define Cr DCTSIZE2
+
+static void rgb2yuv (unsigned char image[][3], BLOCK *blk)
+{
+ int x,y,i;
+ int tmpblk[16*16][3],(*yuv)[3];
+ BLOCK *yblk;
+
+ yuv=tmpblk;
+ for(i=0;i<16*16;i++) {
+ yuv[0][0] = RGB2Y (image[0][R],image[0][G],image[0][B])-128;
+ yuv[0][1] = RGB2Cb(image[0][R],image[0][G],image[0][B]);
+ yuv[0][2] = RGB2Cr(image[0][R],image[0][G],image[0][B]);
+ yuv++; image++;
+ }
+
+ yuv = tmpblk;
+ yblk = blk+DCTSIZE2*2;
+ for(y=0;y<16;y+=2,blk+=4,yblk+=8,yuv+=8+16) {
+ if (y==8) yblk+=DCTSIZE2;
+ for(x=0;x<4;x++,blk++,yblk+=2,yuv+=2) {
+ blk[Cb] = (yuv[0][1]+yuv[1][1]+yuv[16][1]+yuv[17][1])/4;
+ blk[Cr] = (yuv[0][2]+yuv[1][2]+yuv[16][2]+yuv[17][2])/4;
+ yblk[0] = yuv[ 0][0];
+ yblk[1] = yuv[ 1][0];
+ yblk[8] = yuv[16][0];
+ yblk[9] = yuv[17][0];
+
+ blk[4+Cb] = (yuv[8+0][1]+yuv[8+1][1]+yuv[8+16][1]+yuv[8+17][1])/4;
+ blk[4+Cr] = (yuv[8+0][2]+yuv[8+1][2]+yuv[8+16][2]+yuv[8+17][2])/4;
+ yblk[DCTSIZE2+0] = yuv[8+ 0][0];
+ yblk[DCTSIZE2+1] = yuv[8+ 1][0];
+ yblk[DCTSIZE2+8] = yuv[8+16][0];
+ yblk[DCTSIZE2+9] = yuv[8+17][0];
+ }
+ }
+}
+
+#undef Cb
+#undef Cr
+
+/* bit i/o */
+#define BITBUFSIZE 16
+#define WriteWord(x) ctxt->bsbuf[ctxt->bs_size++]=(x)
+
+static void putbits_init (bs_context_t *ctxt)
+{
+ ctxt->bitbuf = 0;
+ ctxt->bitcount = BITBUFSIZE;
+ ctxt->bs_size = 0;
+ ctxt->totalbit = 0;
+}
+
+static void putbits_flush (bs_context_t *ctxt)
+{
+ WriteWord(ctxt->bitbuf);
+}
+
+static void putbits (bs_context_t *ctxt, unsigned int x, unsigned int n)
+{
+ ctxt->totalbit+=n;
+
+ if (n<ctxt->bitcount) {
+ ctxt->bitcount-=n;
+ ctxt->bitbuf |= x << ctxt->bitcount;
+ } else {
+ n-=ctxt->bitcount;
+ WriteWord(ctxt->bitbuf | (x>>n) );
+ if (n<BITBUFSIZE) {
+ ctxt->bitcount = BITBUFSIZE-n;
+ } else {
+ WriteWord( x>>(n-BITBUFSIZE) );
+ ctxt->bitcount = BITBUFSIZE*2-n;
+ }
+ ctxt->bitbuf = x << ctxt->bitcount;
+ }
+}
+
+typedef struct {
+ unsigned int code,nbits;
+} huff_t;
+
+const static huff_t dc_y_table[] = {
+ {4,3},{0,2},{1,2},{5,3},{6,3},{14,4},{30,5},{62,6},{126,7},{254,8}
+};
+
+const static huff_t dc_c_table[] = {
+ {0,2},{1,2},{2,2},{6,3},{14,4},{30,5},{62,6},{126,7},{254,8},{510,9}
+};
+
+#include "table.h"
+
+static void encode_init (bs_context_t *ctxt, void *outbuf, int type, int q_scale)
+{
+ ctxt->_type = type;
+ ctxt->last_dc[0] = 0;
+ ctxt->last_dc[1] = 0;
+ ctxt->last_dc[2] = 0;
+ ctxt->rlsize = 0;
+ putbits_init(ctxt);
+
+ ctxt->bsbuf = outbuf;
+ ctxt->bsbuf[1] = 0x3800;
+ ctxt->bsbuf[2] = q_scale;
+ ctxt->bsbuf[3] = type;
+ ctxt->bs_size+=4;
+}
+
+static void encode_finish (bs_context_t *ctxt)
+{
+ putbits_flush(ctxt);
+ ctxt->bsbuf[0] = (((ctxt->rlsize+1)/2)+31)&~31;
+}
+
+static void encode_dc (bs_context_t *ctxt, int n, int level)
+{
+ if (ctxt->_type==2) {
+ putbits(ctxt,level&0x3ff,10);
+ } else {
+ const huff_t *table;
+ int prev,cnt;
+
+ level = level/4;
+ if (n<2) {
+ table = dc_c_table;
+ prev = ctxt->last_dc[n];
+ ctxt->last_dc[n] = level;
+ } else {
+ table = dc_y_table;
+ prev = ctxt->last_dc[2];
+ ctxt->last_dc[2] = level;
+ }
+ level -= prev;
+ if (level==0) cnt=0;
+ else {
+ int alevel = level;
+ if (alevel<0) alevel=-alevel;
+ for(cnt=8;(alevel>>cnt)==0;cnt--);
+ cnt++;
+ if (level<0) level--;
+ }
+ putbits(ctxt,table[cnt].code,table[cnt].nbits);
+ if (cnt) putbits(ctxt,level&((1<<cnt)-1),cnt);
+ }
+ ctxt->rlsize++;
+}
+
+static void encode_ac (bs_context_t *ctxt, int run, int level)
+{
+ int abslevel,sign;
+ if (level>0) {
+ abslevel = level;
+ sign = 0;
+ } else {
+ abslevel = -level;
+ sign = 1;
+ }
+ if (run<=31 && abslevel<=maxlevel[run]) {
+ putbits(ctxt,huff_table[run][abslevel-1].code+sign,huff_table[run][abslevel-1].nbits);
+ } else {
+ /* ESCAPE */
+ putbits(ctxt,1,6);
+ putbits(ctxt,(run<<10)+(level&0x3ff),16);
+ }
+ ctxt->rlsize++;
+}
+
+static void encode_eob (bs_context_t *ctxt)
+{
+ putbits(ctxt, 2,2);
+ ctxt->rlsize++;
+}
+
+extern void DCT(BLOCK *blk);
+
+unsigned char zscan[DCTSIZE2] = {
+ 0 ,1 ,8 ,16,9 ,2 ,3 ,10,
+ 17,24,32,25,18,11,4 ,5 ,
+ 12,19,26,33,40,48,41,34,
+ 27,20,13,6 ,7 ,14,21,28,
+ 35,42,49,56,57,50,43,36,
+ 29,22,15,23,30,37,44,51,
+ 58,59,52,45,38,31,39,46,
+ 53,60,61,54,47,55,62,63
+};
+
+static unsigned char xxx_iqtab[DCTSIZE2] = {
+ 2,16,19,22,26,27,29,34,
+ 16,16,22,24,27,29,34,37,
+ 19,22,26,27,29,34,34,38,
+ 22,22,26,27,29,34,37,40,
+ 22,26,27,29,32,35,40,48,
+ 26,27,29,32,35,40,48,58,
+ 26,27,29,34,38,46,56,69,
+ 27,29,35,38,46,56,69,83
+};
+
+const unsigned char *bs_iqtab (void) { return xxx_iqtab; }
+
+static void blk2huff (bs_context_t *ctxt,BLOCK *blk,int q_scale)
+{
+ int i,k,run,level;
+ for(i=0;i<6;i++) {
+ DCT(blk);
+ for(k=0;k<DCTSIZE2;k++) blk[k]>>=3;
+ level = blk[0]/ctxt->iqtab[0];
+ encode_dc(ctxt,i,level);
+ run = 0;
+ for(k=1;k<64;k++) {
+ level = blk[zscan[k]]*8/(ctxt->iqtab[zscan[k]]*q_scale);
+ if (level==0) {
+ run++;
+ } else {
+ encode_ac(ctxt,run,level);
+ run=0;
+ }
+ }
+ encode_eob(ctxt);
+ blk+=DCTSIZE2;
+ }
+}
+
+Uint8 bs_roundtbl[256*3];
+
+void bs_init (void)
+{
+ int i;
+ for(i=0;i<256;i++) {
+ bs_roundtbl [i]=0;
+ bs_roundtbl [i+256]=i;
+ bs_roundtbl [i+512]=255;
+ }
+}
+
+int bs_encode (bs_header_t *outbuf,bs_input_image_t *img,int type,int q_scale,
+ const unsigned char *myiqtab)
+{
+ unsigned char image[16][16][3];
+ BLOCK blk[6][DCTSIZE2];
+ bs_context_t *ctxt = malloc(sizeof(bs_context_t));
+
+ int x,y,xw,yw,rl;
+
+ ctxt->iqtab = myiqtab ? myiqtab : bs_iqtab();
+
+ encode_init (ctxt,outbuf,type,q_scale);
+
+ for(x=0;x<img->width;x+=16) {
+ xw = img->width-x; if (xw>16) xw = 16;
+ for(y=0;y<img->height;y+=16) {
+ unsigned char *p0 = img->top + x*(img->bit)/8 + y*img->nextline;
+ int i,j=0;
+ yw = img->height-y; if (yw>16) yw = 16;
+
+ /* get 16x16 image */
+
+ for(i=0;i<yw;i++) {
+ unsigned char *p = p0;
+ p0+=img->nextline;
+ switch(img->bit) {
+ case 16:
+ for(j=0;j<xw;j++) {
+ int c = *(unsigned short*)p;
+ image[i][j][B] = ((c>>10)&31)*8;
+ image[i][j][G] = ((c>>5)&31)*8;
+ image[i][j][R] = ((c&31))*8;
+ p+=2;
+ }
+ break;
+ case 24:
+ for(j=0;j<xw;j++) {
+ image[i][j][R] = p[R];
+ image[i][j][G] = p[G];
+ image[i][j][B] = p[B];
+ p+=3;
+ }
+ break;
+ }
+ for(;j<16;j++) {
+ image[i][j][R] = image[i][xw-1][R];
+ image[i][j][G] = image[i][xw-1][G];
+ image[i][j][B] = image[i][xw-1][B];
+ }
+ }
+
+ for(;i<16;i++) {
+ for(j=0;j<16;j++) {
+ image[i][j][R] = image[yw-1][j][R];
+ image[i][j][G] = image[yw-1][j][G];
+ image[i][j][B] = image[yw-1][j][B];
+ }
+ }
+
+ rgb2yuv(image[0],blk[0]);
+ blk2huff(ctxt,blk[0],q_scale);
+ }
+ }
+
+ encode_finish(ctxt);
+
+ rl = (ctxt->bs_size * 2);
+ free (ctxt);
+
+ return rl;
+}
diff --git a/psxdev/bs.h b/psxdev/bs.h index 4d66e0c..ac6f22c 100644 --- a/psxdev/bs.h +++ b/psxdev/bs.h @@ -1,94 +1,94 @@ -/* $Id: bs.h,v 1.3 2002-06-23 15:47:03 Pixel Exp $ */ - -/* - libbs - library for the bitstream image format - - Copyright (C) 1999, 2000 by these people, who contributed to this project - - bero@geocities.co.jp - Daniel Balster <dbalster@psxdev.de> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -/* - DCT code is based on Independent JPEG Group's sotfware -*/ - -#ifndef __LIB_BS_H -#define __LIB_BS_H - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include <sys/types.h> -#include <stdarg.h> -#include "generic.h" - -typedef struct { - int width,height; - int bit; - int nextline; - unsigned char *top,*lpbits; -} bs_input_image_t; - -#define BS_MAGIC 0x3800 -#define BS_TYPE 2 - -typedef struct { - Uint16 length; - Uint16 magic; - Uint16 q_scale; - Uint16 type; -} bs_header_t; - -/* prototypes */ - -#ifdef __cplusplus -extern "C" { -#endif - -void bs_init (void); - -int bs_encode ( /* returns BS image size in bytes */ - bs_header_t *outbuf, /* output BS image */ - bs_input_image_t *img, /* input image descriptor */ - int type, /* image type (use BS_TYPE) */ - int q_scale, /* Q scaling factor (1=best,>= lower quality) */ - const unsigned char *myiqtab /* provide own iqtab (NULL == default) */ - ); - -void bs_decode_rgb24 ( - unsigned char *outbuf, /* output RGB bytes (width*height*3) */ - bs_header_t *img, /* input BS image */ - int width, int height, /* dimension of BS image */ - const unsigned char *myiqtab - ); - -void bs_decode_rgb15 ( - unsigned short *outbuf, /* output RGB bytes (width*height*2) */ - bs_header_t *img, /* input BS image */ - int width, int height, /* dimension of BS image */ - const unsigned char *myiqtab - ); - -const unsigned char *bs_iqtab (void); - -#ifdef __cplusplus -} -#endif - -#endif /* __LIB_BS_H */ +/* $Id: bs.h,v 1.4 2004-11-27 21:44:57 pixel Exp $ */
+
+/*
+ libbs - library for the bitstream image format
+
+ Copyright (C) 1999, 2000 by these people, who contributed to this project
+
+ bero@geocities.co.jp
+ Daniel Balster <dbalster@psxdev.de>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/*
+ DCT code is based on Independent JPEG Group's sotfware
+*/
+
+#ifndef __LIB_BS_H
+#define __LIB_BS_H
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <sys/types.h>
+#include <stdarg.h>
+#include "generic.h"
+
+typedef struct {
+ int width,height;
+ int bit;
+ int nextline;
+ unsigned char *top,*lpbits;
+} bs_input_image_t;
+
+#define BS_MAGIC 0x3800
+#define BS_TYPE 2
+
+typedef struct {
+ Uint16 length;
+ Uint16 magic;
+ Uint16 q_scale;
+ Uint16 type;
+} bs_header_t;
+
+/* prototypes */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void bs_init (void);
+
+int bs_encode ( /* returns BS image size in bytes */
+ bs_header_t *outbuf, /* output BS image */
+ bs_input_image_t *img, /* input image descriptor */
+ int type, /* image type (use BS_TYPE) */
+ int q_scale, /* Q scaling factor (1=best,>= lower quality) */
+ const unsigned char *myiqtab /* provide own iqtab (NULL == default) */
+ );
+
+void bs_decode_rgb24 (
+ unsigned char *outbuf, /* output RGB bytes (width*height*3) */
+ bs_header_t *img, /* input BS image */
+ int width, int height, /* dimension of BS image */
+ const unsigned char *myiqtab
+ );
+
+void bs_decode_rgb15 (
+ unsigned short *outbuf, /* output RGB bytes (width*height*2) */
+ bs_header_t *img, /* input BS image */
+ int width, int height, /* dimension of BS image */
+ const unsigned char *myiqtab
+ );
+
+const unsigned char *bs_iqtab (void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LIB_BS_H */
diff --git a/psxdev/common.h b/psxdev/common.h index 3a3c9d1..be53bc9 100644 --- a/psxdev/common.h +++ b/psxdev/common.h @@ -1,49 +1,49 @@ -/* $Id: common.h,v 1.2 2002-06-23 15:47:03 Pixel Exp $ */ - -/* - common stuff - - Copyright (C) 1997, 1998, 1999, 2000 by these people, who contributed to this project - - Daniel Balster <dbalster@psxdev.de> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#ifndef __COMMON_H -#define __COMMON_H - -#define _GNU_SOURCE -#define _USE_GNU - -#include "generic.h" - -#include <sys/types.h> - -#if ENABLE_NLS -#if HAVE_LOCALE_H -#include <locale.h> -#endif -#if HAVE_LIBINTL_H -#include <libintl.h> -#endif -#define _(string) gettext(string) -#define N_(string) (string) -#else -#define _(string) (string) -#define N_(string) (string) -#endif - -#endif +/* $Id: common.h,v 1.3 2004-11-27 21:44:57 pixel Exp $ */
+
+/*
+ common stuff
+
+ Copyright (C) 1997, 1998, 1999, 2000 by these people, who contributed to this project
+
+ Daniel Balster <dbalster@psxdev.de>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef __COMMON_H
+#define __COMMON_H
+
+#define _GNU_SOURCE
+#define _USE_GNU
+
+#include "generic.h"
+
+#include <sys/types.h>
+
+#if ENABLE_NLS
+#if HAVE_LOCALE_H
+#include <locale.h>
+#endif
+#if HAVE_LIBINTL_H
+#include <libintl.h>
+#endif
+#define _(string) gettext(string)
+#define N_(string) (string)
+#else
+#define _(string) (string)
+#define N_(string) (string)
+#endif
+
+#endif
diff --git a/psxdev/idctfst.c b/psxdev/idctfst.c index 345cdb1..5b857e9 100644 --- a/psxdev/idctfst.c +++ b/psxdev/idctfst.c @@ -1,287 +1,287 @@ -/* - * jidctfst.c - * - * Copyright (C) 1994-1996, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains a fast, not so accurate integer implementation of the - * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine - * must also perform dequantization of the input coefficients. - * - * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT - * on each row (or vice versa, but it's more convenient to emit a row at - * a time). Direct algorithms are also available, but they are much more - * complex and seem not to be any faster when reduced to code. - * - * This implementation is based on Arai, Agui, and Nakajima's algorithm for - * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in - * Japanese, but the algorithm is described in the Pennebaker & Mitchell - * JPEG textbook (see REFERENCES section in file README). The following code - * is based directly on figure 4-8 in P&M. - * While an 8-point DCT cannot be done in less than 11 multiplies, it is - * possible to arrange the computation so that many of the multiplies are - * simple scalings of the final outputs. These multiplies can then be - * folded into the multiplications or divisions by the JPEG quantization - * table entries. The AA&N method leaves only 5 multiplies and 29 adds - * to be done in the DCT itself. - * The primary disadvantage of this method is that with fixed-point math, - * accuracy is lost due to imprecise representation of the scaled - * quantization values. The smaller the quantization table entry, the less - * precise the scaled value, so this implementation does worse with high- - * quality-setting files than with low-quality ones. - */ - -/* - * This module is specialized to the case DCTSIZE = 8. - */ - -/* Scaling decisions are generally the same as in the LL&M algorithm; - * see jidctint.c for more details. However, we choose to descale - * (right shift) multiplication products as soon as they are formed, - * rather than carrying additional fractional bits into subsequent additions. - * This compromises accuracy slightly, but it lets us save a few shifts. - * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples) - * everywhere except in the multiplications proper; this saves a good deal - * of work on 16-bit-int machines. - * - * The dequantized coefficients are not integers because the AA&N scaling - * factors have been incorporated. We represent them scaled up by PASS1_BITS, - * so that the first and second IDCT rounds have the same input scaling. - * For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to - * avoid a descaling shift; this compromises accuracy rather drastically - * for small quantization table entries, but it saves a lot of shifts. - * For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway, - * so we use a much larger scaling factor to preserve accuracy. - * - * A final compromise is to represent the multiplicative constants to only - * 8 fractional bits, rather than 13. This saves some shifting work on some - * machines, and may also reduce the cost of multiplication (since there - * are fewer one-bits in the constants). - */ - -#define BITS_IN_JSAMPLE 8 - -#if BITS_IN_JSAMPLE == 8 -#define CONST_BITS 8 -#define PASS1_BITS 2 -#else -#define CONST_BITS 8 -#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ -#endif - -/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus - * causing a lot of useless floating-point operations at run time. - * To get around this we use the following pre-calculated constants. - * If you change CONST_BITS you may want to add appropriate values. - * (With a reasonable C compiler, you can just rely on the FIX() macro...) - */ - -#if CONST_BITS == 8 -#define FIX_1_082392200 (277) /* FIX(1.082392200) */ -#define FIX_1_414213562 (362) /* FIX(1.414213562) */ -#define FIX_1_847759065 (473) /* FIX(1.847759065) */ -#define FIX_2_613125930 (669) /* FIX(2.613125930) */ -#else -#define FIX_1_082392200 FIX(1.082392200) -#define FIX_1_414213562 FIX(1.414213562) -#define FIX_1_847759065 FIX(1.847759065) -#define FIX_2_613125930 FIX(2.613125930) -#endif - - -/* We can gain a little more speed, with a further compromise in accuracy, - * by omitting the addition in a descaling shift. This yields an incorrectly - * rounded result half the time... - */ - - -/* Multiply a DCTELEM variable by an INT32 constant, and immediately - * descale to yield a DCTELEM result. - */ - -#define MULTIPLY(var,const) (DESCALE((var) * (const), CONST_BITS)) - - -/* Dequantize a coefficient by multiplying it by the multiplier-table - * entry; produce a DCTELEM result. For 8-bit data a 16x16->16 - * multiplication will do. For 12-bit data, the multiplier table is - * declared INT32, so a 32-bit multiply will be used. - */ - -#if BITS_IN_JSAMPLE == 8 -#define DEQUANTIZE(coef,quantval) (coef) -#else -#define DEQUANTIZE(coef,quantval) \ - DESCALE((coef), IFAST_SCALE_BITS-PASS1_BITS) -#endif - - -/* Like DESCALE, but applies to a DCTELEM and produces an int. - * We assume that int right shift is unsigned if INT32 right shift is. - */ - -#define DESCALE(x,n) ((x)>>(n)) -#define RANGE(n) (n) -#define BLOCK int - -/* - * Perform dequantization and inverse DCT on one block of coefficients. - */ -#define DCTSIZE 8 -#define DCTSIZE2 64 - -static void IDCT1(BLOCK *block) -{ - int val = RANGE(DESCALE(block[0], PASS1_BITS+3)); - int i; - for(i=0;i<DCTSIZE2;i++) block[i]=val; -} - -void IDCT(BLOCK *block,int k) -{ - int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; - int z5, z10, z11, z12, z13; - BLOCK *ptr; - int i; - - /* Pass 1: process columns from input, store into work array. */ - switch(k){ - case 1:IDCT1(block); return; - } - - ptr = block; - for (i = 0; i< DCTSIZE; i++,ptr++) { - /* Due to quantization, we will usually find that many of the input - * coefficients are zero, especially the AC terms. We can exploit this - * by short-circuiting the IDCT calculation for any column in which all - * the AC terms are zero. In that case each output is equal to the - * DC coefficient (with scale factor as needed). - * With typical images and quantization tables, half or more of the - * column DCT calculations can be simplified this way. - */ - - if ((ptr[DCTSIZE*1] | ptr[DCTSIZE*2] | ptr[DCTSIZE*3] | - ptr[DCTSIZE*4] | ptr[DCTSIZE*5] | ptr[DCTSIZE*6] | - ptr[DCTSIZE*7]) == 0) { - /* AC terms all zero */ - ptr[DCTSIZE*0] = - ptr[DCTSIZE*1] = - ptr[DCTSIZE*2] = - ptr[DCTSIZE*3] = - ptr[DCTSIZE*4] = - ptr[DCTSIZE*5] = - ptr[DCTSIZE*6] = - ptr[DCTSIZE*7] = - ptr[DCTSIZE*0]; - - continue; - } - - /* Even part */ - - z10 = ptr[DCTSIZE*0] + ptr[DCTSIZE*4]; /* phase 3 */ - z11 = ptr[DCTSIZE*0] - ptr[DCTSIZE*4]; - z13 = ptr[DCTSIZE*2] + ptr[DCTSIZE*6]; /* phases 5-3 */ - z12 = MULTIPLY(ptr[DCTSIZE*2] - ptr[DCTSIZE*6], FIX_1_414213562) - z13; /* 2*c4 */ - - tmp0 = z10 + z13; /* phase 2 */ - tmp3 = z10 - z13; - tmp1 = z11 + z12; - tmp2 = z11 - z12; - - /* Odd part */ - - z13 = ptr[DCTSIZE*3] + ptr[DCTSIZE*5]; /* phase 6 */ - z10 = ptr[DCTSIZE*3] - ptr[DCTSIZE*5]; - z11 = ptr[DCTSIZE*1] + ptr[DCTSIZE*7]; - z12 = ptr[DCTSIZE*1] - ptr[DCTSIZE*7]; - - z5 = MULTIPLY(z12 - z10, FIX_1_847759065); - tmp7 = z11 + z13; /* phase 5 */ - tmp6 = MULTIPLY(z10, FIX_2_613125930) + z5 - tmp7; /* phase 2 */ - tmp5 = MULTIPLY(z11 - z13, FIX_1_414213562) - tmp6; - tmp4 = MULTIPLY(z12, FIX_1_082392200) - z5 + tmp5; - - ptr[DCTSIZE*0] = (tmp0 + tmp7); - ptr[DCTSIZE*7] = (tmp0 - tmp7); - ptr[DCTSIZE*1] = (tmp1 + tmp6); - ptr[DCTSIZE*6] = (tmp1 - tmp6); - ptr[DCTSIZE*2] = (tmp2 + tmp5); - ptr[DCTSIZE*5] = (tmp2 - tmp5); - ptr[DCTSIZE*4] = (tmp3 + tmp4); - ptr[DCTSIZE*3] = (tmp3 - tmp4); - - } - - /* Pass 2: process rows from work array, store into output array. */ - /* Note that we must descale the results by a factor of 8 == 2**3, */ - /* and also undo the PASS1_BITS scaling. */ - - ptr = block; - for (i = 0; i < DCTSIZE; i++ ,ptr+=DCTSIZE) { - /* Rows of zeroes can be exploited in the same way as we did with columns. - * However, the column calculation has created many nonzero AC terms, so - * the simplification applies less often (typically 5% to 10% of the time). - * On machines with very fast multiplication, it's possible that the - * test takes more time than it's worth. In that case this section - * may be commented out. - */ - -#ifndef NO_ZERO_ROW_TEST - if ((ptr[1] | ptr[2] | ptr[3] | ptr[4] | ptr[5] | ptr[6] | - ptr[7]) == 0) { - /* AC terms all zero */ - ptr[0] = - ptr[1] = - ptr[2] = - ptr[3] = - ptr[4] = - ptr[5] = - ptr[6] = - ptr[7] = - RANGE(DESCALE(ptr[0], PASS1_BITS+3));; - - continue; - } -#endif - - /* Even part */ - - z10 = ptr[0] + ptr[4]; - z11 = ptr[0] - ptr[4]; - z13 = ptr[2] + ptr[6]; - z12 = MULTIPLY(ptr[2] - ptr[6], FIX_1_414213562) - z13; - - tmp0 = z10 + z13; - tmp3 = z10 - z13; - tmp1 = z11 + z12; - tmp2 = z11 - z12; - - /* Odd part */ - - z13 = ptr[3] + ptr[5]; - z10 = ptr[3] - ptr[5]; - z11 = ptr[1] + ptr[7]; - z12 = ptr[1] - ptr[7]; - - z5 = MULTIPLY(z12 - z10, FIX_1_847759065); - tmp7 = z11 + z13; /* phase 5 */ - tmp6 = MULTIPLY(z10, FIX_2_613125930) + z5 - tmp7; /* phase 2 */ - tmp5 = MULTIPLY(z11 - z13, FIX_1_414213562) - tmp6; - tmp4 = MULTIPLY(z12, FIX_1_082392200) - z5 + tmp5; - - /* Final output stage: scale down by a factor of 8 and range-limit */ - - ptr[0] = RANGE(DESCALE(tmp0 + tmp7, PASS1_BITS+3));; - ptr[7] = RANGE(DESCALE(tmp0 - tmp7, PASS1_BITS+3));; - ptr[1] = RANGE(DESCALE(tmp1 + tmp6, PASS1_BITS+3));; - ptr[6] = RANGE(DESCALE(tmp1 - tmp6, PASS1_BITS+3));; - ptr[2] = RANGE(DESCALE(tmp2 + tmp5, PASS1_BITS+3));; - ptr[5] = RANGE(DESCALE(tmp2 - tmp5, PASS1_BITS+3));; - ptr[4] = RANGE(DESCALE(tmp3 + tmp4, PASS1_BITS+3));; - ptr[3] = RANGE(DESCALE(tmp3 - tmp4, PASS1_BITS+3));; - - } -} - +/*
+ * jidctfst.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a fast, not so accurate integer implementation of the
+ * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
+ * must also perform dequantization of the input coefficients.
+ *
+ * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
+ * on each row (or vice versa, but it's more convenient to emit a row at
+ * a time). Direct algorithms are also available, but they are much more
+ * complex and seem not to be any faster when reduced to code.
+ *
+ * This implementation is based on Arai, Agui, and Nakajima's algorithm for
+ * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
+ * Japanese, but the algorithm is described in the Pennebaker & Mitchell
+ * JPEG textbook (see REFERENCES section in file README). The following code
+ * is based directly on figure 4-8 in P&M.
+ * While an 8-point DCT cannot be done in less than 11 multiplies, it is
+ * possible to arrange the computation so that many of the multiplies are
+ * simple scalings of the final outputs. These multiplies can then be
+ * folded into the multiplications or divisions by the JPEG quantization
+ * table entries. The AA&N method leaves only 5 multiplies and 29 adds
+ * to be done in the DCT itself.
+ * The primary disadvantage of this method is that with fixed-point math,
+ * accuracy is lost due to imprecise representation of the scaled
+ * quantization values. The smaller the quantization table entry, the less
+ * precise the scaled value, so this implementation does worse with high-
+ * quality-setting files than with low-quality ones.
+ */
+
+/*
+ * This module is specialized to the case DCTSIZE = 8.
+ */
+
+/* Scaling decisions are generally the same as in the LL&M algorithm;
+ * see jidctint.c for more details. However, we choose to descale
+ * (right shift) multiplication products as soon as they are formed,
+ * rather than carrying additional fractional bits into subsequent additions.
+ * This compromises accuracy slightly, but it lets us save a few shifts.
+ * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples)
+ * everywhere except in the multiplications proper; this saves a good deal
+ * of work on 16-bit-int machines.
+ *
+ * The dequantized coefficients are not integers because the AA&N scaling
+ * factors have been incorporated. We represent them scaled up by PASS1_BITS,
+ * so that the first and second IDCT rounds have the same input scaling.
+ * For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to
+ * avoid a descaling shift; this compromises accuracy rather drastically
+ * for small quantization table entries, but it saves a lot of shifts.
+ * For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway,
+ * so we use a much larger scaling factor to preserve accuracy.
+ *
+ * A final compromise is to represent the multiplicative constants to only
+ * 8 fractional bits, rather than 13. This saves some shifting work on some
+ * machines, and may also reduce the cost of multiplication (since there
+ * are fewer one-bits in the constants).
+ */
+
+#define BITS_IN_JSAMPLE 8
+
+#if BITS_IN_JSAMPLE == 8
+#define CONST_BITS 8
+#define PASS1_BITS 2
+#else
+#define CONST_BITS 8
+#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
+#endif
+
+/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
+ * causing a lot of useless floating-point operations at run time.
+ * To get around this we use the following pre-calculated constants.
+ * If you change CONST_BITS you may want to add appropriate values.
+ * (With a reasonable C compiler, you can just rely on the FIX() macro...)
+ */
+
+#if CONST_BITS == 8
+#define FIX_1_082392200 (277) /* FIX(1.082392200) */
+#define FIX_1_414213562 (362) /* FIX(1.414213562) */
+#define FIX_1_847759065 (473) /* FIX(1.847759065) */
+#define FIX_2_613125930 (669) /* FIX(2.613125930) */
+#else
+#define FIX_1_082392200 FIX(1.082392200)
+#define FIX_1_414213562 FIX(1.414213562)
+#define FIX_1_847759065 FIX(1.847759065)
+#define FIX_2_613125930 FIX(2.613125930)
+#endif
+
+
+/* We can gain a little more speed, with a further compromise in accuracy,
+ * by omitting the addition in a descaling shift. This yields an incorrectly
+ * rounded result half the time...
+ */
+
+
+/* Multiply a DCTELEM variable by an INT32 constant, and immediately
+ * descale to yield a DCTELEM result.
+ */
+
+#define MULTIPLY(var,const) (DESCALE((var) * (const), CONST_BITS))
+
+
+/* Dequantize a coefficient by multiplying it by the multiplier-table
+ * entry; produce a DCTELEM result. For 8-bit data a 16x16->16
+ * multiplication will do. For 12-bit data, the multiplier table is
+ * declared INT32, so a 32-bit multiply will be used.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+#define DEQUANTIZE(coef,quantval) (coef)
+#else
+#define DEQUANTIZE(coef,quantval) \
+ DESCALE((coef), IFAST_SCALE_BITS-PASS1_BITS)
+#endif
+
+
+/* Like DESCALE, but applies to a DCTELEM and produces an int.
+ * We assume that int right shift is unsigned if INT32 right shift is.
+ */
+
+#define DESCALE(x,n) ((x)>>(n))
+#define RANGE(n) (n)
+#define BLOCK int
+
+/*
+ * Perform dequantization and inverse DCT on one block of coefficients.
+ */
+#define DCTSIZE 8
+#define DCTSIZE2 64
+
+static void IDCT1(BLOCK *block)
+{
+ int val = RANGE(DESCALE(block[0], PASS1_BITS+3));
+ int i;
+ for(i=0;i<DCTSIZE2;i++) block[i]=val;
+}
+
+void IDCT(BLOCK *block,int k)
+{
+ int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+ int z5, z10, z11, z12, z13;
+ BLOCK *ptr;
+ int i;
+
+ /* Pass 1: process columns from input, store into work array. */
+ switch(k){
+ case 1:IDCT1(block); return;
+ }
+
+ ptr = block;
+ for (i = 0; i< DCTSIZE; i++,ptr++) {
+ /* Due to quantization, we will usually find that many of the input
+ * coefficients are zero, especially the AC terms. We can exploit this
+ * by short-circuiting the IDCT calculation for any column in which all
+ * the AC terms are zero. In that case each output is equal to the
+ * DC coefficient (with scale factor as needed).
+ * With typical images and quantization tables, half or more of the
+ * column DCT calculations can be simplified this way.
+ */
+
+ if ((ptr[DCTSIZE*1] | ptr[DCTSIZE*2] | ptr[DCTSIZE*3] |
+ ptr[DCTSIZE*4] | ptr[DCTSIZE*5] | ptr[DCTSIZE*6] |
+ ptr[DCTSIZE*7]) == 0) {
+ /* AC terms all zero */
+ ptr[DCTSIZE*0] =
+ ptr[DCTSIZE*1] =
+ ptr[DCTSIZE*2] =
+ ptr[DCTSIZE*3] =
+ ptr[DCTSIZE*4] =
+ ptr[DCTSIZE*5] =
+ ptr[DCTSIZE*6] =
+ ptr[DCTSIZE*7] =
+ ptr[DCTSIZE*0];
+
+ continue;
+ }
+
+ /* Even part */
+
+ z10 = ptr[DCTSIZE*0] + ptr[DCTSIZE*4]; /* phase 3 */
+ z11 = ptr[DCTSIZE*0] - ptr[DCTSIZE*4];
+ z13 = ptr[DCTSIZE*2] + ptr[DCTSIZE*6]; /* phases 5-3 */
+ z12 = MULTIPLY(ptr[DCTSIZE*2] - ptr[DCTSIZE*6], FIX_1_414213562) - z13; /* 2*c4 */
+
+ tmp0 = z10 + z13; /* phase 2 */
+ tmp3 = z10 - z13;
+ tmp1 = z11 + z12;
+ tmp2 = z11 - z12;
+
+ /* Odd part */
+
+ z13 = ptr[DCTSIZE*3] + ptr[DCTSIZE*5]; /* phase 6 */
+ z10 = ptr[DCTSIZE*3] - ptr[DCTSIZE*5];
+ z11 = ptr[DCTSIZE*1] + ptr[DCTSIZE*7];
+ z12 = ptr[DCTSIZE*1] - ptr[DCTSIZE*7];
+
+ z5 = MULTIPLY(z12 - z10, FIX_1_847759065);
+ tmp7 = z11 + z13; /* phase 5 */
+ tmp6 = MULTIPLY(z10, FIX_2_613125930) + z5 - tmp7; /* phase 2 */
+ tmp5 = MULTIPLY(z11 - z13, FIX_1_414213562) - tmp6;
+ tmp4 = MULTIPLY(z12, FIX_1_082392200) - z5 + tmp5;
+
+ ptr[DCTSIZE*0] = (tmp0 + tmp7);
+ ptr[DCTSIZE*7] = (tmp0 - tmp7);
+ ptr[DCTSIZE*1] = (tmp1 + tmp6);
+ ptr[DCTSIZE*6] = (tmp1 - tmp6);
+ ptr[DCTSIZE*2] = (tmp2 + tmp5);
+ ptr[DCTSIZE*5] = (tmp2 - tmp5);
+ ptr[DCTSIZE*4] = (tmp3 + tmp4);
+ ptr[DCTSIZE*3] = (tmp3 - tmp4);
+
+ }
+
+ /* Pass 2: process rows from work array, store into output array. */
+ /* Note that we must descale the results by a factor of 8 == 2**3, */
+ /* and also undo the PASS1_BITS scaling. */
+
+ ptr = block;
+ for (i = 0; i < DCTSIZE; i++ ,ptr+=DCTSIZE) {
+ /* Rows of zeroes can be exploited in the same way as we did with columns.
+ * However, the column calculation has created many nonzero AC terms, so
+ * the simplification applies less often (typically 5% to 10% of the time).
+ * On machines with very fast multiplication, it's possible that the
+ * test takes more time than it's worth. In that case this section
+ * may be commented out.
+ */
+
+#ifndef NO_ZERO_ROW_TEST
+ if ((ptr[1] | ptr[2] | ptr[3] | ptr[4] | ptr[5] | ptr[6] |
+ ptr[7]) == 0) {
+ /* AC terms all zero */
+ ptr[0] =
+ ptr[1] =
+ ptr[2] =
+ ptr[3] =
+ ptr[4] =
+ ptr[5] =
+ ptr[6] =
+ ptr[7] =
+ RANGE(DESCALE(ptr[0], PASS1_BITS+3));;
+
+ continue;
+ }
+#endif
+
+ /* Even part */
+
+ z10 = ptr[0] + ptr[4];
+ z11 = ptr[0] - ptr[4];
+ z13 = ptr[2] + ptr[6];
+ z12 = MULTIPLY(ptr[2] - ptr[6], FIX_1_414213562) - z13;
+
+ tmp0 = z10 + z13;
+ tmp3 = z10 - z13;
+ tmp1 = z11 + z12;
+ tmp2 = z11 - z12;
+
+ /* Odd part */
+
+ z13 = ptr[3] + ptr[5];
+ z10 = ptr[3] - ptr[5];
+ z11 = ptr[1] + ptr[7];
+ z12 = ptr[1] - ptr[7];
+
+ z5 = MULTIPLY(z12 - z10, FIX_1_847759065);
+ tmp7 = z11 + z13; /* phase 5 */
+ tmp6 = MULTIPLY(z10, FIX_2_613125930) + z5 - tmp7; /* phase 2 */
+ tmp5 = MULTIPLY(z11 - z13, FIX_1_414213562) - tmp6;
+ tmp4 = MULTIPLY(z12, FIX_1_082392200) - z5 + tmp5;
+
+ /* Final output stage: scale down by a factor of 8 and range-limit */
+
+ ptr[0] = RANGE(DESCALE(tmp0 + tmp7, PASS1_BITS+3));;
+ ptr[7] = RANGE(DESCALE(tmp0 - tmp7, PASS1_BITS+3));;
+ ptr[1] = RANGE(DESCALE(tmp1 + tmp6, PASS1_BITS+3));;
+ ptr[6] = RANGE(DESCALE(tmp1 - tmp6, PASS1_BITS+3));;
+ ptr[2] = RANGE(DESCALE(tmp2 + tmp5, PASS1_BITS+3));;
+ ptr[5] = RANGE(DESCALE(tmp2 - tmp5, PASS1_BITS+3));;
+ ptr[4] = RANGE(DESCALE(tmp3 + tmp4, PASS1_BITS+3));;
+ ptr[3] = RANGE(DESCALE(tmp3 - tmp4, PASS1_BITS+3));;
+
+ }
+}
+
diff --git a/psxdev/jfdctint.c b/psxdev/jfdctint.c index f9299e1..c2a58d2 100644 --- a/psxdev/jfdctint.c +++ b/psxdev/jfdctint.c @@ -1,291 +1,291 @@ -/* - * jfdctint.c - * - * Copyright (C) 1991-1994, Thomas G. Lane. - * This file is part of the Independent JPEG Group's software. - * For conditions of distribution and use, see the accompanying README file. - * - * This file contains a slow-but-accurate integer implementation of the - * forward DCT (Discrete Cosine Transform). - * - * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT - * on each column. Direct algorithms are also available, but they are - * much more complex and seem not to be any faster when reduced to code. - * - * This implementation is based on an algorithm described in - * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT - * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics, - * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991. - * The primary algorithm described there uses 11 multiplies and 29 adds. - * We use their alternate method with 12 multiplies and 32 adds. - * The advantage of this method is that no data path contains more than one - * multiplication; this allows a very simple and accurate implementation in - * scaled fixed-point arithmetic, with a minimal number of shifts. - */ - -#define DCT_ISLOW_SUPPORTED -#define DCTSIZE 8 -#define DCTELEM int -#define INT32 int -#define DESCALE(x,n) RIGHT_SHIFT((x) + (1 << ((n)-1)), n) -#define RIGHT_SHIFT(x,n) ((x)>>(n)) -#define GLOBAL -#define jpeg_fdct_islow DCT -#define SHIFT_TEMPS -/* #define BITS_IN_JSAMPLE 8 - #define MULTIPLY16C16(var,const) ((var) * (const)) */ - - -#ifdef DCT_ISLOW_SUPPORTED - - -/* - * This module is specialized to the case DCTSIZE = 8. - */ - -#if DCTSIZE != 8 -#error Sorry, this code only copes with 8x8 DCTs. -#endif - - -/* - * The poop on this scaling stuff is as follows: - * - * Each 1-D DCT step produces outputs which are a factor of sqrt(N) - * larger than the true DCT outputs. The final outputs are therefore - * a factor of N larger than desired; since N=8 this can be cured by - * a simple right shift at the end of the algorithm. The advantage of - * this arrangement is that we save two multiplications per 1-D DCT, - * because the y0 and y4 outputs need not be divided by sqrt(N). - * In the IJG code, this factor of 8 is removed by the quantization step - * (in jcdctmgr.c), NOT in this module. - * - * We have to do addition and subtraction of the integer inputs, which - * is no problem, and multiplication by fractional constants, which is - * a problem to do in integer arithmetic. We multiply all the constants - * by CONST_SCALE and convert them to integer constants (thus retaining - * CONST_BITS bits of precision in the constants). After doing a - * multiplication we have to divide the product by CONST_SCALE, with proper - * rounding, to produce the correct output. This division can be done - * cheaply as a right shift of CONST_BITS bits. We postpone shifting - * as long as possible so that partial sums can be added together with - * full fractional precision. - * - * The outputs of the first pass are scaled up by PASS1_BITS bits so that - * they are represented to better-than-integral precision. These outputs - * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word - * with the recommended scaling. (For 12-bit sample data, the intermediate - * array is INT32 anyway.) - * - * To avoid overflow of the 32-bit intermediate results in pass 2, we must - * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis - * shows that the values given below are the most effective. - */ - -#if BITS_IN_JSAMPLE == 8 -#define CONST_BITS 13 -#define PASS1_BITS 2 -#else -#define CONST_BITS 13 -#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ -#endif - -/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus - * causing a lot of useless floating-point operations at run time. - * To get around this we use the following pre-calculated constants. - * If you change CONST_BITS you may want to add appropriate values. - * (With a reasonable C compiler, you can just rely on the FIX() macro...) - */ - -#if CONST_BITS == 13 -#define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */ -#define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */ -#define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */ -#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */ -#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */ -#define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */ -#define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */ -#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */ -#define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */ -#define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */ -#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */ -#define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */ -#else -#define FIX_0_298631336 FIX(0.298631336) -#define FIX_0_390180644 FIX(0.390180644) -#define FIX_0_541196100 FIX(0.541196100) -#define FIX_0_765366865 FIX(0.765366865) -#define FIX_0_899976223 FIX(0.899976223) -#define FIX_1_175875602 FIX(1.175875602) -#define FIX_1_501321110 FIX(1.501321110) -#define FIX_1_847759065 FIX(1.847759065) -#define FIX_1_961570560 FIX(1.961570560) -#define FIX_2_053119869 FIX(2.053119869) -#define FIX_2_562915447 FIX(2.562915447) -#define FIX_3_072711026 FIX(3.072711026) -#endif - - -/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. - * For 8-bit samples with the recommended scaling, all the variable - * and constant values involved are no more than 16 bits wide, so a - * 16x16->32 bit multiply can be used instead of a full 32x32 multiply. - * For 12-bit samples, a full 32-bit multiplication will be needed. - */ - -#if BITS_IN_JSAMPLE == 8 -#define MULTIPLY(var,const) MULTIPLY16C16(var,const) -#else -#define MULTIPLY(var,const) ((var) * (const)) -#endif - - -/* - * Perform the forward DCT on one block of samples. - */ - -GLOBAL void -jpeg_fdct_islow (DCTELEM * data) -{ - INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; - INT32 tmp10, tmp11, tmp12, tmp13; - INT32 z1, z2, z3, z4, z5; - DCTELEM *dataptr; - int ctr; - SHIFT_TEMPS - - /* Pass 1: process rows. */ - /* Note results are scaled up by sqrt(8) compared to a true DCT; */ - /* furthermore, we scale the results by 2**PASS1_BITS. */ - - dataptr = data; - for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { - tmp0 = dataptr[0] + dataptr[7]; - tmp7 = dataptr[0] - dataptr[7]; - tmp1 = dataptr[1] + dataptr[6]; - tmp6 = dataptr[1] - dataptr[6]; - tmp2 = dataptr[2] + dataptr[5]; - tmp5 = dataptr[2] - dataptr[5]; - tmp3 = dataptr[3] + dataptr[4]; - tmp4 = dataptr[3] - dataptr[4]; - - /* Even part per LL&M figure 1 --- note that published figure is faulty; - * rotator "sqrt(2)*c1" should be "sqrt(2)*c6". - */ - - tmp10 = tmp0 + tmp3; - tmp13 = tmp0 - tmp3; - tmp11 = tmp1 + tmp2; - tmp12 = tmp1 - tmp2; - - dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS); - dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS); - - z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); - dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), - CONST_BITS-PASS1_BITS); - dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), - CONST_BITS-PASS1_BITS); - - /* Odd part per figure 8 --- note paper omits factor of sqrt(2). - * cK represents cos(K*pi/16). - * i0..i3 in the paper are tmp4..tmp7 here. - */ - - z1 = tmp4 + tmp7; - z2 = tmp5 + tmp6; - z3 = tmp4 + tmp6; - z4 = tmp5 + tmp7; - z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ - - tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ - tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ - tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ - tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ - z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ - z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ - z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ - z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ - - z3 += z5; - z4 += z5; - - dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS); - dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS); - dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS); - dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS); - - dataptr += DCTSIZE; /* advance pointer to next row */ - } - - /* Pass 2: process columns. - * We remove the PASS1_BITS scaling, but leave the results scaled up - * by an overall factor of 8. - */ - - dataptr = data; - for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { - tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; - tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; - tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; - tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; - tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; - tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; - tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; - tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; - - /* Even part per LL&M figure 1 --- note that published figure is faulty; - * rotator "sqrt(2)*c1" should be "sqrt(2)*c6". - */ - - tmp10 = tmp0 + tmp3; - tmp13 = tmp0 - tmp3; - tmp11 = tmp1 + tmp2; - tmp12 = tmp1 - tmp2; - - dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS); - dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS); - - z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); - dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), - CONST_BITS+PASS1_BITS); - dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), - CONST_BITS+PASS1_BITS); - - /* Odd part per figure 8 --- note paper omits factor of sqrt(2). - * cK represents cos(K*pi/16). - * i0..i3 in the paper are tmp4..tmp7 here. - */ - - z1 = tmp4 + tmp7; - z2 = tmp5 + tmp6; - z3 = tmp4 + tmp6; - z4 = tmp5 + tmp7; - z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ - - tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ - tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ - tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ - tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ - z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ - z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ - z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ - z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ - - z3 += z5; - z4 += z5; - - dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, - CONST_BITS+PASS1_BITS); - dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, - CONST_BITS+PASS1_BITS); - dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, - CONST_BITS+PASS1_BITS); - dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, - CONST_BITS+PASS1_BITS); - - dataptr++; /* advance pointer to next column */ - } -} - -#endif /* DCT_ISLOW_SUPPORTED */ +/*
+ * jfdctint.c
+ *
+ * Copyright (C) 1991-1994, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains a slow-but-accurate integer implementation of the
+ * forward DCT (Discrete Cosine Transform).
+ *
+ * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
+ * on each column. Direct algorithms are also available, but they are
+ * much more complex and seem not to be any faster when reduced to code.
+ *
+ * This implementation is based on an algorithm described in
+ * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
+ * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
+ * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
+ * The primary algorithm described there uses 11 multiplies and 29 adds.
+ * We use their alternate method with 12 multiplies and 32 adds.
+ * The advantage of this method is that no data path contains more than one
+ * multiplication; this allows a very simple and accurate implementation in
+ * scaled fixed-point arithmetic, with a minimal number of shifts.
+ */
+
+#define DCT_ISLOW_SUPPORTED
+#define DCTSIZE 8
+#define DCTELEM int
+#define INT32 int
+#define DESCALE(x,n) RIGHT_SHIFT((x) + (1 << ((n)-1)), n)
+#define RIGHT_SHIFT(x,n) ((x)>>(n))
+#define GLOBAL
+#define jpeg_fdct_islow DCT
+#define SHIFT_TEMPS
+/* #define BITS_IN_JSAMPLE 8
+ #define MULTIPLY16C16(var,const) ((var) * (const)) */
+
+
+#ifdef DCT_ISLOW_SUPPORTED
+
+
+/*
+ * This module is specialized to the case DCTSIZE = 8.
+ */
+
+#if DCTSIZE != 8
+#error Sorry, this code only copes with 8x8 DCTs.
+#endif
+
+
+/*
+ * The poop on this scaling stuff is as follows:
+ *
+ * Each 1-D DCT step produces outputs which are a factor of sqrt(N)
+ * larger than the true DCT outputs. The final outputs are therefore
+ * a factor of N larger than desired; since N=8 this can be cured by
+ * a simple right shift at the end of the algorithm. The advantage of
+ * this arrangement is that we save two multiplications per 1-D DCT,
+ * because the y0 and y4 outputs need not be divided by sqrt(N).
+ * In the IJG code, this factor of 8 is removed by the quantization step
+ * (in jcdctmgr.c), NOT in this module.
+ *
+ * We have to do addition and subtraction of the integer inputs, which
+ * is no problem, and multiplication by fractional constants, which is
+ * a problem to do in integer arithmetic. We multiply all the constants
+ * by CONST_SCALE and convert them to integer constants (thus retaining
+ * CONST_BITS bits of precision in the constants). After doing a
+ * multiplication we have to divide the product by CONST_SCALE, with proper
+ * rounding, to produce the correct output. This division can be done
+ * cheaply as a right shift of CONST_BITS bits. We postpone shifting
+ * as long as possible so that partial sums can be added together with
+ * full fractional precision.
+ *
+ * The outputs of the first pass are scaled up by PASS1_BITS bits so that
+ * they are represented to better-than-integral precision. These outputs
+ * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
+ * with the recommended scaling. (For 12-bit sample data, the intermediate
+ * array is INT32 anyway.)
+ *
+ * To avoid overflow of the 32-bit intermediate results in pass 2, we must
+ * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
+ * shows that the values given below are the most effective.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+#define CONST_BITS 13
+#define PASS1_BITS 2
+#else
+#define CONST_BITS 13
+#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
+#endif
+
+/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
+ * causing a lot of useless floating-point operations at run time.
+ * To get around this we use the following pre-calculated constants.
+ * If you change CONST_BITS you may want to add appropriate values.
+ * (With a reasonable C compiler, you can just rely on the FIX() macro...)
+ */
+
+#if CONST_BITS == 13
+#define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
+#define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
+#define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
+#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
+#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
+#define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
+#define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
+#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
+#define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
+#define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
+#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
+#define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
+#else
+#define FIX_0_298631336 FIX(0.298631336)
+#define FIX_0_390180644 FIX(0.390180644)
+#define FIX_0_541196100 FIX(0.541196100)
+#define FIX_0_765366865 FIX(0.765366865)
+#define FIX_0_899976223 FIX(0.899976223)
+#define FIX_1_175875602 FIX(1.175875602)
+#define FIX_1_501321110 FIX(1.501321110)
+#define FIX_1_847759065 FIX(1.847759065)
+#define FIX_1_961570560 FIX(1.961570560)
+#define FIX_2_053119869 FIX(2.053119869)
+#define FIX_2_562915447 FIX(2.562915447)
+#define FIX_3_072711026 FIX(3.072711026)
+#endif
+
+
+/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
+ * For 8-bit samples with the recommended scaling, all the variable
+ * and constant values involved are no more than 16 bits wide, so a
+ * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
+ * For 12-bit samples, a full 32-bit multiplication will be needed.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+#define MULTIPLY(var,const) MULTIPLY16C16(var,const)
+#else
+#define MULTIPLY(var,const) ((var) * (const))
+#endif
+
+
+/*
+ * Perform the forward DCT on one block of samples.
+ */
+
+GLOBAL void
+jpeg_fdct_islow (DCTELEM * data)
+{
+ INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+ INT32 tmp10, tmp11, tmp12, tmp13;
+ INT32 z1, z2, z3, z4, z5;
+ DCTELEM *dataptr;
+ int ctr;
+ SHIFT_TEMPS
+
+ /* Pass 1: process rows. */
+ /* Note results are scaled up by sqrt(8) compared to a true DCT; */
+ /* furthermore, we scale the results by 2**PASS1_BITS. */
+
+ dataptr = data;
+ for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
+ tmp0 = dataptr[0] + dataptr[7];
+ tmp7 = dataptr[0] - dataptr[7];
+ tmp1 = dataptr[1] + dataptr[6];
+ tmp6 = dataptr[1] - dataptr[6];
+ tmp2 = dataptr[2] + dataptr[5];
+ tmp5 = dataptr[2] - dataptr[5];
+ tmp3 = dataptr[3] + dataptr[4];
+ tmp4 = dataptr[3] - dataptr[4];
+
+ /* Even part per LL&M figure 1 --- note that published figure is faulty;
+ * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
+ */
+
+ tmp10 = tmp0 + tmp3;
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
+ dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
+
+ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
+ dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
+ CONST_BITS-PASS1_BITS);
+ dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
+ CONST_BITS-PASS1_BITS);
+
+ /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
+ * cK represents cos(K*pi/16).
+ * i0..i3 in the paper are tmp4..tmp7 here.
+ */
+
+ z1 = tmp4 + tmp7;
+ z2 = tmp5 + tmp6;
+ z3 = tmp4 + tmp6;
+ z4 = tmp5 + tmp7;
+ z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
+
+ tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
+ tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
+ tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
+ tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
+ z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
+ z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
+ z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
+ z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
+
+ z3 += z5;
+ z4 += z5;
+
+ dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
+ dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
+ dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
+ dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
+
+ dataptr += DCTSIZE; /* advance pointer to next row */
+ }
+
+ /* Pass 2: process columns.
+ * We remove the PASS1_BITS scaling, but leave the results scaled up
+ * by an overall factor of 8.
+ */
+
+ dataptr = data;
+ for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
+ tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
+ tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
+ tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
+ tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
+ tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
+ tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
+ tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
+ tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
+
+ /* Even part per LL&M figure 1 --- note that published figure is faulty;
+ * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
+ */
+
+ tmp10 = tmp0 + tmp3;
+ tmp13 = tmp0 - tmp3;
+ tmp11 = tmp1 + tmp2;
+ tmp12 = tmp1 - tmp2;
+
+ dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
+ dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
+
+ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
+ dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
+ CONST_BITS+PASS1_BITS);
+ dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
+ CONST_BITS+PASS1_BITS);
+
+ /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
+ * cK represents cos(K*pi/16).
+ * i0..i3 in the paper are tmp4..tmp7 here.
+ */
+
+ z1 = tmp4 + tmp7;
+ z2 = tmp5 + tmp6;
+ z3 = tmp4 + tmp6;
+ z4 = tmp5 + tmp7;
+ z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
+
+ tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
+ tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
+ tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
+ tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
+ z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
+ z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
+ z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
+ z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
+
+ z3 += z5;
+ z4 += z5;
+
+ dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
+ CONST_BITS+PASS1_BITS);
+ dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
+ CONST_BITS+PASS1_BITS);
+ dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
+ CONST_BITS+PASS1_BITS);
+ dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
+ CONST_BITS+PASS1_BITS);
+
+ dataptr++; /* advance pointer to next column */
+ }
+}
+
+#endif /* DCT_ISLOW_SUPPORTED */
diff --git a/psxdev/table.h b/psxdev/table.h index 0b50ad3..3e50b18 100644 --- a/psxdev/table.h +++ b/psxdev/table.h @@ -1,102 +1,102 @@ -const static huff_t table0[]={ - {6,3},{8,5},{10,6},{12,8},{76,9},{66,9},{20,11},{58,13},{48,13},{38,13},{32,13},{52,14},{50,14},{48,14},{46,14},{62,15},{60,15},{58,15},{56,15},{54,15},{52,15},{50,15},{48,15},{46,15},{44,15},{42,15},{40,15},{38,15},{36,15},{34,15},{32,15},{48,16},{46,16},{44,16},{42,16},{40,16},{38,16},{36,16},{34,16},{32,16}, -}; -const static huff_t table1[]={ - {6,4},{12,7},{74,9},{24,11},{54,13},{44,14},{42,14},{62,16},{60,16},{58,16},{56,16},{54,16},{52,16},{50,16},{38,17},{36,17},{34,17},{32,17}, -}; -const static huff_t table2[]={ - {10,5},{8,8},{22,11},{40,13},{40,14}, -}; -const static huff_t table3[]={ - {14,6},{72,9},{56,13},{38,14}, -}; -const static huff_t table4[]={ - {12,6},{30,11},{36,13}, -}; -const static huff_t table5[]={ - {14,7},{18,11},{36,14}, -}; -const static huff_t table6[]={ - {10,7},{60,13},{40,17}, -}; -const static huff_t table7[]={ - {8,7},{42,13}, -}; -const static huff_t table8[]={ - {14,8},{34,13}, -}; -const static huff_t table9[]={ - {10,8},{34,14}, -}; -const static huff_t table10[]={ - {78,9},{32,14}, -}; -const static huff_t table11[]={ - {70,9},{52,17}, -}; -const static huff_t table12[]={ - {68,9},{50,17}, -}; -const static huff_t table13[]={ - {64,9},{48,17}, -}; -const static huff_t table14[]={ - {28,11},{46,17}, -}; -const static huff_t table15[]={ - {26,11},{44,17}, -}; -const static huff_t table16[]={ - {16,11},{42,17}, -}; -const static huff_t table17[]={ - {62,13}, -}; -const static huff_t table18[]={ - {52,13}, -}; -const static huff_t table19[]={ - {50,13}, -}; -const static huff_t table20[]={ - {46,13}, -}; -const static huff_t table21[]={ - {44,13}, -}; -const static huff_t table22[]={ - {62,14}, -}; -const static huff_t table23[]={ - {60,14}, -}; -const static huff_t table24[]={ - {58,14}, -}; -const static huff_t table25[]={ - {56,14}, -}; -const static huff_t table26[]={ - {54,14}, -}; -const static huff_t table27[]={ - {62,17}, -}; -const static huff_t table28[]={ - {60,17}, -}; -const static huff_t table29[]={ - {58,17}, -}; -const static huff_t table30[]={ - {56,17}, -}; -const static huff_t table31[]={ - {54,17}, -}; -const static huff_t *huff_table[]={ - table0,table1,table2,table3,table4,table5,table6,table7,table8,table9,table10,table11,table12,table13,table14,table15,table16,table17,table18,table19,table20,table21,table22,table23,table24,table25,table26,table27,table28,table29,table30,table31, -}; -const static int maxlevel[]={ - 40,18,5,4,3,3,3,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, -}; +const static huff_t table0[]={
+ {6,3},{8,5},{10,6},{12,8},{76,9},{66,9},{20,11},{58,13},{48,13},{38,13},{32,13},{52,14},{50,14},{48,14},{46,14},{62,15},{60,15},{58,15},{56,15},{54,15},{52,15},{50,15},{48,15},{46,15},{44,15},{42,15},{40,15},{38,15},{36,15},{34,15},{32,15},{48,16},{46,16},{44,16},{42,16},{40,16},{38,16},{36,16},{34,16},{32,16},
+};
+const static huff_t table1[]={
+ {6,4},{12,7},{74,9},{24,11},{54,13},{44,14},{42,14},{62,16},{60,16},{58,16},{56,16},{54,16},{52,16},{50,16},{38,17},{36,17},{34,17},{32,17},
+};
+const static huff_t table2[]={
+ {10,5},{8,8},{22,11},{40,13},{40,14},
+};
+const static huff_t table3[]={
+ {14,6},{72,9},{56,13},{38,14},
+};
+const static huff_t table4[]={
+ {12,6},{30,11},{36,13},
+};
+const static huff_t table5[]={
+ {14,7},{18,11},{36,14},
+};
+const static huff_t table6[]={
+ {10,7},{60,13},{40,17},
+};
+const static huff_t table7[]={
+ {8,7},{42,13},
+};
+const static huff_t table8[]={
+ {14,8},{34,13},
+};
+const static huff_t table9[]={
+ {10,8},{34,14},
+};
+const static huff_t table10[]={
+ {78,9},{32,14},
+};
+const static huff_t table11[]={
+ {70,9},{52,17},
+};
+const static huff_t table12[]={
+ {68,9},{50,17},
+};
+const static huff_t table13[]={
+ {64,9},{48,17},
+};
+const static huff_t table14[]={
+ {28,11},{46,17},
+};
+const static huff_t table15[]={
+ {26,11},{44,17},
+};
+const static huff_t table16[]={
+ {16,11},{42,17},
+};
+const static huff_t table17[]={
+ {62,13},
+};
+const static huff_t table18[]={
+ {52,13},
+};
+const static huff_t table19[]={
+ {50,13},
+};
+const static huff_t table20[]={
+ {46,13},
+};
+const static huff_t table21[]={
+ {44,13},
+};
+const static huff_t table22[]={
+ {62,14},
+};
+const static huff_t table23[]={
+ {60,14},
+};
+const static huff_t table24[]={
+ {58,14},
+};
+const static huff_t table25[]={
+ {56,14},
+};
+const static huff_t table26[]={
+ {54,14},
+};
+const static huff_t table27[]={
+ {62,17},
+};
+const static huff_t table28[]={
+ {60,17},
+};
+const static huff_t table29[]={
+ {58,17},
+};
+const static huff_t table30[]={
+ {56,17},
+};
+const static huff_t table31[]={
+ {54,17},
+};
+const static huff_t *huff_table[]={
+ table0,table1,table2,table3,table4,table5,table6,table7,table8,table9,table10,table11,table12,table13,table14,table15,table16,table17,table18,table19,table20,table21,table22,table23,table24,table25,table26,table27,table28,table29,table30,table31,
+};
+const static int maxlevel[]={
+ 40,18,5,4,3,3,3,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+};
diff --git a/psxdev/vlc.c b/psxdev/vlc.c index 4ff3d06..c313cdc 100644 --- a/psxdev/vlc.c +++ b/psxdev/vlc.c @@ -1,606 +1,606 @@ -#include <sys/types.h> -#include <stdlib.h> -#include <string.h> -#include "bs.h" - -#define SOFT - -#define CODE1(a,b,c) (((a)<<10)|((b)&0x3ff)|((c)<<16)) -/* run, level, bit */ -#define CODE(a,b,c) CODE1(a,b,c+1),CODE1(a,-b,c+1) -#define CODE0(a,b,c) CODE1(a,b,c),CODE1(a,b,c) -#define CODE2(a,b,c) CODE1(a,b,c+1),CODE1(a,b,c+1) -#define RUNOF(a) ((a)>>10) -#define VALOF(a) ((short)((a)<<6)>>6) -#define BITOF(a) ((a)>>16) -#define EOB 0xfe00 -#define ESCAPE_CODE CODE1(63,0,6) -#define EOB_CODE CODE1(63,512,2) - -/* - DC code - Y U,V -0 100 00 0 -1 00x 01x -1,1 -2 01xx 10xx -3,-2,2,3 -3 101xxx 110xxx -7..-4,4..7 -4 110xxxx 1110 -15..-8,8..15 -5 1110xxxxx 11110 -31..-16,16..31 -6 11110xxxxxx 111110 -63..-32,32..63 -7 111110 1111110 -127..-64,64..127 -8 1111110 11111110 -255..-128,128..255 - 7+8 8+8 -*/ - -/* - This table based on MPEG2DEC by MPEG Software Simulation Group -*/ - -/* Table B-14, DCT coefficients table zero, -* codes 0100 ... 1xxx (used for all other coefficients) -*/ -static const Uint32 VLCtabnext[12*2] = { - CODE(0,2,4), CODE(2,1,4), CODE2(1,1,3), CODE2(1,-1,3), - CODE0(63,512,2), CODE0(63,512,2), CODE0(63,512,2), CODE0(63,512,2), /*EOB*/ - CODE2(0,1,2), CODE2(0,1,2), CODE2(0,-1,2), CODE2(0,-1,2) -}; - -/* Table B-14, DCT coefficients table zero, -* codes 000001xx ... 00111xxx -*/ -static const Uint32 VLCtab0[60*2] = { - CODE0(63,0,6), CODE0(63,0,6),CODE0(63,0,6), CODE0(63,0,6), /* ESCAPE */ - CODE2(2,2,7), CODE2(2,-2,7), CODE2(9,1,7), CODE2(9,-1,7), - CODE2(0,4,7), CODE2(0,-4,7), CODE2(8,1,7), CODE2(8,-1,7), - CODE2(7,1,6), CODE2(7,1,6), CODE2(7,-1,6), CODE2(7,-1,6), - CODE2(6,1,6), CODE2(6,1,6), CODE2(6,-1,6), CODE2(6,-1,6), - CODE2(1,2,6), CODE2(1,2,6), CODE2(1,-2,6), CODE2(1,-2,6), - CODE2(5,1,6), CODE2(5,1,6), CODE2(5,-1,6), CODE2(5,-1,6), - CODE(13,1,8), CODE(0,6,8), CODE(12,1,8), CODE(11,1,8), - CODE(3,2,8), CODE(1,3,8), CODE(0,5,8), CODE(10,1,8), - CODE2(0,3,5), CODE2(0,3,5), CODE2(0,3,5), CODE2(0,3,5), - CODE2(0,-3,5), CODE2(0,-3,5), CODE2(0,-3,5), CODE2(0,-3,5), - CODE2(4,1,5), CODE2(4,1,5), CODE2(4,1,5), CODE2(4,1,5), - CODE2(4,-1,5), CODE2(4,-1,5), CODE2(4,-1,5), CODE2(4,-1,5), - CODE2(3,1,5), CODE2(3,1,5), CODE2(3,1,5), CODE2(3,1,5), - CODE2(3,-1,5), CODE2(3,-1,5), CODE2(3,-1,5), CODE2(3,-1,5) -}; - -/* Table B-14, DCT coefficients table zero, -* codes 0000001000 ... 0000001111 -*/ -static const Uint32 VLCtab1[8*2] = { - CODE(16,1,10), CODE(5,2,10), CODE(0,7,10), CODE(2,3,10), - CODE(1,4,10), CODE(15,1,10), CODE(14,1,10), CODE(4,2,10) -}; - -/* Table B-14/15, DCT coefficients table zero / one, -* codes 000000010000 ... 000000011111 -*/ -static const Uint32 VLCtab2[16*2] = { - CODE(0,11,12), CODE(8,2,12), CODE(4,3,12), CODE(0,10,12), - CODE(2,4,12), CODE(7,2,12), CODE(21,1,12), CODE(20,1,12), - CODE(0,9,12), CODE(19,1,12), CODE(18,1,12), CODE(1,5,12), - CODE(3,3,12), CODE(0,8,12), CODE(6,2,12), CODE(17,1,12) -}; - -/* Table B-14/15, DCT coefficients table zero / one, -* codes 0000000010000 ... 0000000011111 -*/ -static const Uint32 VLCtab3[16*2] = { - CODE(10,2,13), CODE(9,2,13), CODE(5,3,13), CODE(3,4,13), - CODE(2,5,13), CODE(1,7,13), CODE(1,6,13), CODE(0,15,13), - CODE(0,14,13), CODE(0,13,13), CODE(0,12,13), CODE(26,1,13), - CODE(25,1,13), CODE(24,1,13), CODE(23,1,13), CODE(22,1,13) -}; - -/* Table B-14/15, DCT coefficients table zero / one, -* codes 00000000010000 ... 00000000011111 -*/ -static const Uint32 VLCtab4[16*2] = { - CODE(0,31,14), CODE(0,30,14), CODE(0,29,14), CODE(0,28,14), - CODE(0,27,14), CODE(0,26,14), CODE(0,25,14), CODE(0,24,14), - CODE(0,23,14), CODE(0,22,14), CODE(0,21,14), CODE(0,20,14), - CODE(0,19,14), CODE(0,18,14), CODE(0,17,14), CODE(0,16,14) -}; - -/* Table B-14/15, DCT coefficients table zero / one, -* codes 000000000010000 ... 000000000011111 -*/ -static const Uint32 VLCtab5[16*2] = { - CODE(0,40,15), CODE(0,39,15), CODE(0,38,15), CODE(0,37,15), - CODE(0,36,15), CODE(0,35,15), CODE(0,34,15), CODE(0,33,15), - CODE(0,32,15), CODE(1,14,15), CODE(1,13,15), CODE(1,12,15), - CODE(1,11,15), CODE(1,10,15), CODE(1,9,15), CODE(1,8,15) -}; - -/* Table B-14/15, DCT coefficients table zero / one, -* codes 0000000000010000 ... 0000000000011111 -*/ -static const Uint32 VLCtab6[16*2] = { - CODE(1,18,16), CODE(1,17,16), CODE(1,16,16), CODE(1,15,16), - CODE(6,3,16), CODE(16,2,16), CODE(15,2,16), CODE(14,2,16), - CODE(13,2,16), CODE(12,2,16), CODE(11,2,16), CODE(31,1,16), - CODE(30,1,16), CODE(29,1,16), CODE(28,1,16), CODE(27,1,16) -}; - -/* - DC code - Y U,V -0 100 00 0 -1 00x 01x -1,1 -2 01xx 10xx -3,-2,2,3 -3 101xxx 110xxx -7..-4,4..7 -4 110xxxx 1110xxxx -15..-8,8..15 -5 1110xxxxx 11110xxxxx -31..-16,16..31 -6 11110xxxxxx 111110xxxxxx -63..-32,32..63 -7 111110xxxxxxx 1111110xxxxxxx -127..-64,64..127 -8 1111110xxxxxxxx 11111110xxxxxxxx -255..-128,128..255 -*/ - -static const Uint32 DC_Ytab0[48] = { - CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3), - CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3), - CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3), - CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3), - - CODE1(0,-3,4),CODE1(0,-3,4),CODE1(0,-3,4),CODE1(0,-3,4), - CODE1(0,-2,4),CODE1(0,-2,4),CODE1(0,-2,4),CODE1(0,-2,4), - CODE1(0,2,4),CODE1(0,2,4),CODE1(0,2,4),CODE1(0,2,4), - CODE1(0,3,4),CODE1(0,3,4),CODE1(0,3,4),CODE1(0,3,4), - - CODE1(0,0,3),CODE1(0,0,3),CODE1(0,0,3),CODE1(0,0,3), - CODE1(0,0,3),CODE1(0,0,3),CODE1(0,0,3),CODE1(0,0,3), - CODE1(0,-7,6),CODE1(0,-6,6),CODE1(0,-5,6),CODE1(0,-4,6), - CODE1(0,4,6),CODE1(0,5,6),CODE1(0,6,6),CODE1(0,7,6), - -}; - -static const Uint32 DC_UVtab0[56] = { - CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2), - CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2), - CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2), - CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2), - - CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3), - CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3), - CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3), - CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3), - - CODE1(0,-3,4),CODE1(0,-3,4),CODE1(0,-3,4),CODE1(0,-3,4), - CODE1(0,-2,4),CODE1(0,-2,4),CODE1(0,-2,4),CODE1(0,-2,4), - CODE1(0,2,4),CODE1(0,2,4),CODE1(0,2,4),CODE1(0,2,4), - CODE1(0,3,4),CODE1(0,3,4),CODE1(0,3,4),CODE1(0,3,4), - - CODE1(0,-7,6),CODE1(0,-6,6),CODE1(0,-5,6),CODE1(0,-4,6), - CODE1(0,4,6),CODE1(0,5,6),CODE1(0,6,6),CODE1(0,7,6), -}; - -#define DCTSIZE2 64 - -/* decode one intra coded MPEG-1 block */ - -#define Show_Bits(N) (bitbuf>>(32-(N))) -/* Ŭ—LŒøbit 17 bit*/ - -#define Flush_Buffer(N) {bitbuf <<=(N);incnt +=(N);while(incnt>=0) {bitbuf |= Get_Word()<<incnt;incnt-=16;}} - -#define Init_Buffer() {bitbuf = (mdec_bs[0]<<16)|(mdec_bs[1]);mdec_bs+=2;incnt = -16;} - -#define Get_Word() (*mdec_bs++) -#define Printf printf - - -int DecDCTvlc(Uint16 *mdec_bs,Uint16 *mdec_rl) -{ -/* Uint16 *mdec_bs = mdecbs,*mdec_rl = mdecrl */ - Uint16 *rl_end; - Uint32 bitbuf; - int incnt; /* 16-—LŒøbit” x86=char risc = long */ - int q_code; - int type,n; - int last_dc[3]; - -/* BS_HDR Uint16 rlsize,magic,ver,q_scale */ - - /* printf("%04x,%04x,",mdec_bs[0],mdec_bs[1]); */ - *(long*)mdec_rl=*(long*)mdec_bs; - mdec_rl+=2; - rl_end = mdec_rl+(int)mdec_bs[0]*2; - q_code = (mdec_bs[2]<<10); /* code = q */ - type = mdec_bs[3]; - mdec_bs+=4; - - Init_Buffer(); - - n = 0; - last_dc[0]=last_dc[1]=last_dc[2] = 0; - while(mdec_rl<rl_end) { - Uint32 code2; - /* DC */ - if (type==2) { - code2 = Show_Bits(10)|(10<<16); /* DC code */ - } else { - code2 = Show_Bits(6); - if (n>=2) { - /* Y */ - if (code2<48) { - code2 = DC_Ytab0[code2]; - code2 = (code2&0xffff0000)|((last_dc[2]+=VALOF(code2)*4)&0x3ff); - } else { - int nbit,val; - int bit = 3; - while(Show_Bits(bit)&1) { bit++;} - bit++; - nbit = bit*2-1; - val = Show_Bits(nbit)&((1<<bit)-1); - if ((val&(1<<(bit-1)))==0) - val -= (1<<bit)-1; - val = (last_dc[2]+=val*4); - code2 = (nbit<<16) | (val&0x3ff); - } - /* printf("%d ",last_dc[2]); */ - } else { - /* U,V */ - if (code2<56) { - code2 = DC_UVtab0[code2]; - code2 = (code2&0xffff0000)|((last_dc[n]+=VALOF(code2)*4)&0x3ff); - } else { - int nbit,val; - int bit = 4; - while(Show_Bits(bit)&1) { bit++;} - nbit = bit*2; - val = Show_Bits(nbit)&((1<<bit)-1); - if ((val&(1<<(bit-1)))==0) - val -= (1<<bit)-1; - val = (last_dc[n]+=val*4); - code2 = (nbit<<16) | (val&0x3ff); - } - /* printf("%d ",last_dc[n]); */ - } - if (++n==6) n=0; - } - /* printf("%d ",VALOF(code2)); */ - code2 |= q_code; - - /* AC */ - for(;;){ -/* Uint32 code; */ -#define code code2 -#define SBIT 17 - *mdec_rl++=code2; - Flush_Buffer(BITOF(code2)); - code = Show_Bits(SBIT); - if (code>=1<<(SBIT- 2)) { - code2 = VLCtabnext[(code>>12)-8]; - if (code2==EOB_CODE) break; - } - else if (code>=1<<(SBIT- 6)) { - code2 = VLCtab0[(code>>8)-8]; - if (code2==ESCAPE_CODE) { - Flush_Buffer(6); /* ESCAPE len */ - code2 = Show_Bits(16)| (16<<16); - } - } - else if (code>=1<<(SBIT- 7)) code2 = VLCtab1[(code>>6)-16]; - else if (code>=1<<(SBIT- 8)) code2 = VLCtab2[(code>>4)-32]; - else if (code>=1<<(SBIT- 9)) code2 = VLCtab3[(code>>3)-32]; - else if (code>=1<<(SBIT-10)) code2 = VLCtab4[(code>>2)-32]; - else if (code>=1<<(SBIT-11)) code2 = VLCtab5[(code>>1)-32]; - else if (code>=1<<(SBIT-12)) code2 = VLCtab6[(code>>0)-32]; - else { - do { - *mdec_rl++=EOB; - } while(mdec_rl<rl_end); - return 0; - } - } - *mdec_rl++=code2; /* EOB code */ - Flush_Buffer(2); /* EOB bitlen */ - } - return 0; -} - - - -/* this table is based on djpeg by Independent Jpeg Group */ - -static const int aanscales[DCTSIZE2] = { - /* precomputed values scaled up by 14 bits */ - 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, - 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, - 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, - 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, - 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, - 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, - 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, - 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 -}; - -extern unsigned char zscan[DCTSIZE2]; - -typedef struct { - int iqtab[DCTSIZE2]; - const unsigned char *iq_y; - Uint16 *mdec_rl,*rl_end; - int mdec_mode; -} bs_context_t; - -void iqtab_init(bs_context_t *ctxt) -{ -#define CONST_BITS 14 -#define IFAST_SCALE_BITS 2 - int i; - for(i=0;i<DCTSIZE2;i++) { - ctxt->iqtab[i] =ctxt->iq_y[i]*aanscales[i]>>(CONST_BITS-IFAST_SCALE_BITS); - } -} - -#define BLOCK long - -extern void IDCT(BLOCK *blk,int k); - -Uint16* rl2blk(bs_context_t *ctxt, BLOCK *blk,Uint16 *mdec_rl) -{ - int i,k,q_scale,rl; - memset(blk,0,6*DCTSIZE2*sizeof(BLOCK)); - for(i=0;i<6;i++) { - rl = *mdec_rl++; - q_scale = RUNOF(rl); - blk[0] = ctxt->iqtab[0]*VALOF(rl); - k = 0; - for(;;) { - rl = *mdec_rl++; - if (rl==EOB) break; - k += RUNOF(rl)+1; - blk[zscan[k]] = ctxt->iqtab[zscan[k]]*q_scale*VALOF(rl)/8; - } - - IDCT(blk,k+1); - - blk+=DCTSIZE2; - } - return mdec_rl; -} - -#define RGB15(r,g,b) ( (((b)&0xf8)<<7)|(((g)&0xf8)<<2)|((r)>>3) ) - -#define ROUND(r) bs_roundtbl[(r)+256] -#if 1 -#define SHIFT 12 -#define toFIX(a) (int)((a)*(1<<SHIFT)) -#define toINT(a) ((a)>>SHIFT) -#define FIX_1 toFIX(1) -#define MULR(a) toINT((a)*toFIX(1.402)) -#define MULG(a) toINT((a)*toFIX(-0.3437)) -#define MULG2(a) toINT((a)*toFIX(-0.7143)) -#define MULB(a) toINT((a)*toFIX(1.772)) -#else -#define MULR(a) 0 -#define MULG(a) 0 -#define MULG2(a) 0 -#define MULB(a) 0 -#endif - - -/* -int ROUND(int r) -{ - if (r<0) return 0; - else if (r>255) return 255; - else return r; -} -*/ - -extern Uint8 bs_roundtbl[256*3]; - -static void yuv2rgb15(BLOCK *blk,Uint16 *image) -{ - int x,yy; - BLOCK *yblk = blk+DCTSIZE2*2; - for(yy=0;yy<16;yy+=2,blk+=4,yblk+=8,image+=8+16) { - if (yy==8) yblk+=DCTSIZE2; - for(x=0;x<4;x++,blk++,yblk+=2,image+=2) { - int r0,b0,g0,y; - r0 = MULR(blk[DCTSIZE2]); /* cr */ - g0 = MULG(blk[0])+MULG2(blk[DCTSIZE2]); - b0 = MULB(blk[0]); /* cb */ - y = yblk[0]+128; - image[0] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y)); - y = yblk[1]+128+4; - image[1] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y)); - y = yblk[8]+128+6; - image[16] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y)); - y = yblk[9]+128+2; - image[17] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y)); - r0 = MULR(blk[4+DCTSIZE2]); - g0 = MULG(blk[4])+MULG2(blk[4+DCTSIZE2]); - b0 = MULB(blk[4]); - y = yblk[DCTSIZE2+0]+128; - image[8+0] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y)); - y = yblk[DCTSIZE2+1]+128+4; - image[8+1] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y)); - y = yblk[DCTSIZE2+8]+128+6; - image[8+16] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y)); - y = yblk[DCTSIZE2+9]+128+2; - image[8+17] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y)); - } - } -} - -enum {R, G, B}; - -static void yuv2rgb24(BLOCK *blk,Uint8 image[][3]) -{ - int x,yy; - BLOCK *yblk = blk+DCTSIZE2*2; - for(yy=0;yy<16;yy+=2,blk+=4,yblk+=8,image+=8+16) { - if (yy==8) yblk+=DCTSIZE2; - for(x=0;x<4;x++,blk++,yblk+=2,image+=2) { - int r0,b0,g0,y; - r0 = MULR(blk[DCTSIZE2]); /* cr */ - g0 = MULG(blk[0])+MULG2(blk[DCTSIZE2]); - b0 = MULB(blk[0]); /* cb */ - y = yblk[0]+128; - image[0][R] = ROUND(r0+y); - image[0][G] = ROUND(g0+y); - image[0][B] = ROUND(b0+y); - y = yblk[1]+128; - image[1][R] = ROUND(r0+y); - image[1][G] = ROUND(g0+y); - image[1][B] = ROUND(b0+y); - y = yblk[8]+128; - image[16][R] = ROUND(r0+y); - image[16][G] = ROUND(g0+y); - image[16][B] = ROUND(b0+y); - y = yblk[9]+128; - image[17][R] = ROUND(r0+y); - image[17][G] = ROUND(g0+y); - image[17][B] = ROUND(b0+y); - - r0 = MULR(blk[4+DCTSIZE2]); - g0 = MULG(blk[4])+MULG2(blk[4+DCTSIZE2]); - b0 = MULB(blk[4]); - y = yblk[DCTSIZE2+0]+128; - image[8+0][R] = ROUND(r0+y); - image[8+0][G] = ROUND(g0+y); - image[8+0][B] = ROUND(b0+y); - y = yblk[DCTSIZE2+1]+128; - image[8+1][R] = ROUND(r0+y); - image[8+1][G] = ROUND(g0+y); - image[8+1][B] = ROUND(b0+y); - y = yblk[DCTSIZE2+8]+128; - image[8+16][R] = ROUND(r0+y); - image[8+16][G] = ROUND(g0+y); - image[8+16][B] = ROUND(b0+y); - y = yblk[DCTSIZE2+9]+128; - image[8+17][R] = ROUND(r0+y); - image[8+17][G] = ROUND(g0+y); - image[8+17][B] = ROUND(b0+y); - } - } -} - -static void DecDCTReset(bs_context_t *ctxt, int mode) -{ - iqtab_init(ctxt); -} - -static void DecDCTin(bs_context_t *ctxt, Uint16 *mdecrl,int mode) -{ - mdecrl+=2; - ctxt->mdec_rl = mdecrl; - ctxt->rl_end = mdecrl+mdecrl[-2]*2; - ctxt->mdec_mode = mode; -} - -static void DecDCTout(bs_context_t *ctxt, Uint16 *image,int size) -{ - BLOCK blk[DCTSIZE2*6]; - int blocksize=16*16; - if (ctxt->mdec_mode) blocksize = 16*16*3/2; - for(;size>0;size-=blocksize/2,image+=blocksize) { - ctxt->mdec_rl = rl2blk(ctxt,blk,ctxt->mdec_rl); - if (ctxt->mdec_mode==0) yuv2rgb15(blk,image); - else yuv2rgb24(blk,image); - } -} - -void bs_decode_rgb24 ( - unsigned char *outbuf, /* output RGB bytes (width*height*3) */ - bs_header_t *img, /* input BS image */ - int width, int height, /* dimension of BS image */ - const unsigned char *myiqtab - ) -{ - unsigned short *buf2 = (unsigned short *) outbuf; - unsigned short *bufp = (unsigned short *) img; - bs_context_t ctxt; - unsigned short *rl,*image; - int slice; - /* int rlsize; */ - int mode; - int x,y; - int height2 = (height+15)&~15; - int w; - - ctxt.iq_y = myiqtab ? myiqtab : bs_iqtab(); - mode=1; - w=24; - width = width*3/2; - - image = (unsigned short *) malloc (height2*w*sizeof(short)); - rl = (unsigned short *) malloc ((bufp[0]+2)*sizeof(long)); - - DecDCTReset(&ctxt,0); - DecDCTvlc(bufp,rl); - DecDCTin(&ctxt,rl,mode); - - slice = height2*w/2; - - for(x=0;x<width;x+=w) - { - Uint16 *dst,*src; - DecDCTout(&ctxt,image,slice); - src = image; - dst = buf2+x+(0)*width; - for(y=height-1;y>=0;y--) - { - memcpy(dst,src,w*2); - src+=w; - dst+=width; - } - } - - free (image); - free (rl); -} - -void bs_decode_rgb15 ( - unsigned short *outbuf, /* output RGB bytes (width*height*2) */ - bs_header_t *img, /* input BS image */ - int width, int height, /* dimension of BS image */ - const unsigned char *myiqtab - ) -{ - unsigned short *buf2 = (unsigned short *) outbuf; - unsigned short *bufp = (unsigned short *) img; - bs_context_t ctxt; - unsigned short *rl,*image; - int slice; - /* int rlsize; */ - int mode; - int x,y; - int height2 = (height+15)&~15; - int w; - - ctxt.iq_y = myiqtab ? myiqtab : bs_iqtab(); - mode=0; - w=24; - - image = (unsigned short *) malloc (height2*w*sizeof(short)); - rl = (unsigned short *) malloc ((bufp[0]+2)*sizeof(long)); - - DecDCTReset(&ctxt,0); - DecDCTvlc(bufp,rl); - DecDCTin(&ctxt,rl,mode); - - slice = height2*w/2; - - for(x=0;x<width;x+=w) - { - Uint16 *dst,*src; - DecDCTout(&ctxt,image,slice); - src = image; - dst = buf2+x+(height-1)*width; - for(y=height-1;y>=0;y--) - { - memcpy(dst,src,w*2); - src+=w; - dst-=width; - } - } - - free (image); - free (rl); -} +#include <sys/types.h>
+#include <stdlib.h>
+#include <string.h>
+#include "bs.h"
+
+#define SOFT
+
+#define CODE1(a,b,c) (((a)<<10)|((b)&0x3ff)|((c)<<16))
+/* run, level, bit */
+#define CODE(a,b,c) CODE1(a,b,c+1),CODE1(a,-b,c+1)
+#define CODE0(a,b,c) CODE1(a,b,c),CODE1(a,b,c)
+#define CODE2(a,b,c) CODE1(a,b,c+1),CODE1(a,b,c+1)
+#define RUNOF(a) ((a)>>10)
+#define VALOF(a) ((short)((a)<<6)>>6)
+#define BITOF(a) ((a)>>16)
+#define EOB 0xfe00
+#define ESCAPE_CODE CODE1(63,0,6)
+#define EOB_CODE CODE1(63,512,2)
+
+/*
+ DC code
+ Y U,V
+0 100 00 0
+1 00x 01x -1,1
+2 01xx 10xx -3,-2,2,3
+3 101xxx 110xxx -7..-4,4..7
+4 110xxxx 1110 -15..-8,8..15
+5 1110xxxxx 11110 -31..-16,16..31
+6 11110xxxxxx 111110 -63..-32,32..63
+7 111110 1111110 -127..-64,64..127
+8 1111110 11111110 -255..-128,128..255
+ 7+8 8+8
+*/
+
+/*
+ This table based on MPEG2DEC by MPEG Software Simulation Group
+*/
+
+/* Table B-14, DCT coefficients table zero,
+* codes 0100 ... 1xxx (used for all other coefficients)
+*/
+static const Uint32 VLCtabnext[12*2] = {
+ CODE(0,2,4), CODE(2,1,4), CODE2(1,1,3), CODE2(1,-1,3),
+ CODE0(63,512,2), CODE0(63,512,2), CODE0(63,512,2), CODE0(63,512,2), /*EOB*/
+ CODE2(0,1,2), CODE2(0,1,2), CODE2(0,-1,2), CODE2(0,-1,2)
+};
+
+/* Table B-14, DCT coefficients table zero,
+* codes 000001xx ... 00111xxx
+*/
+static const Uint32 VLCtab0[60*2] = {
+ CODE0(63,0,6), CODE0(63,0,6),CODE0(63,0,6), CODE0(63,0,6), /* ESCAPE */
+ CODE2(2,2,7), CODE2(2,-2,7), CODE2(9,1,7), CODE2(9,-1,7),
+ CODE2(0,4,7), CODE2(0,-4,7), CODE2(8,1,7), CODE2(8,-1,7),
+ CODE2(7,1,6), CODE2(7,1,6), CODE2(7,-1,6), CODE2(7,-1,6),
+ CODE2(6,1,6), CODE2(6,1,6), CODE2(6,-1,6), CODE2(6,-1,6),
+ CODE2(1,2,6), CODE2(1,2,6), CODE2(1,-2,6), CODE2(1,-2,6),
+ CODE2(5,1,6), CODE2(5,1,6), CODE2(5,-1,6), CODE2(5,-1,6),
+ CODE(13,1,8), CODE(0,6,8), CODE(12,1,8), CODE(11,1,8),
+ CODE(3,2,8), CODE(1,3,8), CODE(0,5,8), CODE(10,1,8),
+ CODE2(0,3,5), CODE2(0,3,5), CODE2(0,3,5), CODE2(0,3,5),
+ CODE2(0,-3,5), CODE2(0,-3,5), CODE2(0,-3,5), CODE2(0,-3,5),
+ CODE2(4,1,5), CODE2(4,1,5), CODE2(4,1,5), CODE2(4,1,5),
+ CODE2(4,-1,5), CODE2(4,-1,5), CODE2(4,-1,5), CODE2(4,-1,5),
+ CODE2(3,1,5), CODE2(3,1,5), CODE2(3,1,5), CODE2(3,1,5),
+ CODE2(3,-1,5), CODE2(3,-1,5), CODE2(3,-1,5), CODE2(3,-1,5)
+};
+
+/* Table B-14, DCT coefficients table zero,
+* codes 0000001000 ... 0000001111
+*/
+static const Uint32 VLCtab1[8*2] = {
+ CODE(16,1,10), CODE(5,2,10), CODE(0,7,10), CODE(2,3,10),
+ CODE(1,4,10), CODE(15,1,10), CODE(14,1,10), CODE(4,2,10)
+};
+
+/* Table B-14/15, DCT coefficients table zero / one,
+* codes 000000010000 ... 000000011111
+*/
+static const Uint32 VLCtab2[16*2] = {
+ CODE(0,11,12), CODE(8,2,12), CODE(4,3,12), CODE(0,10,12),
+ CODE(2,4,12), CODE(7,2,12), CODE(21,1,12), CODE(20,1,12),
+ CODE(0,9,12), CODE(19,1,12), CODE(18,1,12), CODE(1,5,12),
+ CODE(3,3,12), CODE(0,8,12), CODE(6,2,12), CODE(17,1,12)
+};
+
+/* Table B-14/15, DCT coefficients table zero / one,
+* codes 0000000010000 ... 0000000011111
+*/
+static const Uint32 VLCtab3[16*2] = {
+ CODE(10,2,13), CODE(9,2,13), CODE(5,3,13), CODE(3,4,13),
+ CODE(2,5,13), CODE(1,7,13), CODE(1,6,13), CODE(0,15,13),
+ CODE(0,14,13), CODE(0,13,13), CODE(0,12,13), CODE(26,1,13),
+ CODE(25,1,13), CODE(24,1,13), CODE(23,1,13), CODE(22,1,13)
+};
+
+/* Table B-14/15, DCT coefficients table zero / one,
+* codes 00000000010000 ... 00000000011111
+*/
+static const Uint32 VLCtab4[16*2] = {
+ CODE(0,31,14), CODE(0,30,14), CODE(0,29,14), CODE(0,28,14),
+ CODE(0,27,14), CODE(0,26,14), CODE(0,25,14), CODE(0,24,14),
+ CODE(0,23,14), CODE(0,22,14), CODE(0,21,14), CODE(0,20,14),
+ CODE(0,19,14), CODE(0,18,14), CODE(0,17,14), CODE(0,16,14)
+};
+
+/* Table B-14/15, DCT coefficients table zero / one,
+* codes 000000000010000 ... 000000000011111
+*/
+static const Uint32 VLCtab5[16*2] = {
+ CODE(0,40,15), CODE(0,39,15), CODE(0,38,15), CODE(0,37,15),
+ CODE(0,36,15), CODE(0,35,15), CODE(0,34,15), CODE(0,33,15),
+ CODE(0,32,15), CODE(1,14,15), CODE(1,13,15), CODE(1,12,15),
+ CODE(1,11,15), CODE(1,10,15), CODE(1,9,15), CODE(1,8,15)
+};
+
+/* Table B-14/15, DCT coefficients table zero / one,
+* codes 0000000000010000 ... 0000000000011111
+*/
+static const Uint32 VLCtab6[16*2] = {
+ CODE(1,18,16), CODE(1,17,16), CODE(1,16,16), CODE(1,15,16),
+ CODE(6,3,16), CODE(16,2,16), CODE(15,2,16), CODE(14,2,16),
+ CODE(13,2,16), CODE(12,2,16), CODE(11,2,16), CODE(31,1,16),
+ CODE(30,1,16), CODE(29,1,16), CODE(28,1,16), CODE(27,1,16)
+};
+
+/*
+ DC code
+ Y U,V
+0 100 00 0
+1 00x 01x -1,1
+2 01xx 10xx -3,-2,2,3
+3 101xxx 110xxx -7..-4,4..7
+4 110xxxx 1110xxxx -15..-8,8..15
+5 1110xxxxx 11110xxxxx -31..-16,16..31
+6 11110xxxxxx 111110xxxxxx -63..-32,32..63
+7 111110xxxxxxx 1111110xxxxxxx -127..-64,64..127
+8 1111110xxxxxxxx 11111110xxxxxxxx -255..-128,128..255
+*/
+
+static const Uint32 DC_Ytab0[48] = {
+ CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3),
+ CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3),
+ CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3),
+ CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3),
+
+ CODE1(0,-3,4),CODE1(0,-3,4),CODE1(0,-3,4),CODE1(0,-3,4),
+ CODE1(0,-2,4),CODE1(0,-2,4),CODE1(0,-2,4),CODE1(0,-2,4),
+ CODE1(0,2,4),CODE1(0,2,4),CODE1(0,2,4),CODE1(0,2,4),
+ CODE1(0,3,4),CODE1(0,3,4),CODE1(0,3,4),CODE1(0,3,4),
+
+ CODE1(0,0,3),CODE1(0,0,3),CODE1(0,0,3),CODE1(0,0,3),
+ CODE1(0,0,3),CODE1(0,0,3),CODE1(0,0,3),CODE1(0,0,3),
+ CODE1(0,-7,6),CODE1(0,-6,6),CODE1(0,-5,6),CODE1(0,-4,6),
+ CODE1(0,4,6),CODE1(0,5,6),CODE1(0,6,6),CODE1(0,7,6),
+
+};
+
+static const Uint32 DC_UVtab0[56] = {
+ CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2),
+ CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2),
+ CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2),
+ CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2),CODE1(0,0,2),
+
+ CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3),
+ CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3),CODE1(0,-1,3),
+ CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3),
+ CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3),CODE1(0,1,3),
+
+ CODE1(0,-3,4),CODE1(0,-3,4),CODE1(0,-3,4),CODE1(0,-3,4),
+ CODE1(0,-2,4),CODE1(0,-2,4),CODE1(0,-2,4),CODE1(0,-2,4),
+ CODE1(0,2,4),CODE1(0,2,4),CODE1(0,2,4),CODE1(0,2,4),
+ CODE1(0,3,4),CODE1(0,3,4),CODE1(0,3,4),CODE1(0,3,4),
+
+ CODE1(0,-7,6),CODE1(0,-6,6),CODE1(0,-5,6),CODE1(0,-4,6),
+ CODE1(0,4,6),CODE1(0,5,6),CODE1(0,6,6),CODE1(0,7,6),
+};
+
+#define DCTSIZE2 64
+
+/* decode one intra coded MPEG-1 block */
+
+#define Show_Bits(N) (bitbuf>>(32-(N)))
+/* Ŭ—LŒøbit 17 bit*/
+
+#define Flush_Buffer(N) {bitbuf <<=(N);incnt +=(N);while(incnt>=0) {bitbuf |= Get_Word()<<incnt;incnt-=16;}}
+
+#define Init_Buffer() {bitbuf = (mdec_bs[0]<<16)|(mdec_bs[1]);mdec_bs+=2;incnt = -16;}
+
+#define Get_Word() (*mdec_bs++)
+#define Printf printf
+
+
+int DecDCTvlc(Uint16 *mdec_bs,Uint16 *mdec_rl)
+{
+/* Uint16 *mdec_bs = mdecbs,*mdec_rl = mdecrl */
+ Uint16 *rl_end;
+ Uint32 bitbuf;
+ int incnt; /* 16-—LŒøbit” x86=char risc = long */
+ int q_code;
+ int type,n;
+ int last_dc[3];
+
+/* BS_HDR Uint16 rlsize,magic,ver,q_scale */
+
+ /* printf("%04x,%04x,",mdec_bs[0],mdec_bs[1]); */
+ *(long*)mdec_rl=*(long*)mdec_bs;
+ mdec_rl+=2;
+ rl_end = mdec_rl+(int)mdec_bs[0]*2;
+ q_code = (mdec_bs[2]<<10); /* code = q */
+ type = mdec_bs[3];
+ mdec_bs+=4;
+
+ Init_Buffer();
+
+ n = 0;
+ last_dc[0]=last_dc[1]=last_dc[2] = 0;
+ while(mdec_rl<rl_end) {
+ Uint32 code2;
+ /* DC */
+ if (type==2) {
+ code2 = Show_Bits(10)|(10<<16); /* DC code */
+ } else {
+ code2 = Show_Bits(6);
+ if (n>=2) {
+ /* Y */
+ if (code2<48) {
+ code2 = DC_Ytab0[code2];
+ code2 = (code2&0xffff0000)|((last_dc[2]+=VALOF(code2)*4)&0x3ff);
+ } else {
+ int nbit,val;
+ int bit = 3;
+ while(Show_Bits(bit)&1) { bit++;}
+ bit++;
+ nbit = bit*2-1;
+ val = Show_Bits(nbit)&((1<<bit)-1);
+ if ((val&(1<<(bit-1)))==0)
+ val -= (1<<bit)-1;
+ val = (last_dc[2]+=val*4);
+ code2 = (nbit<<16) | (val&0x3ff);
+ }
+ /* printf("%d ",last_dc[2]); */
+ } else {
+ /* U,V */
+ if (code2<56) {
+ code2 = DC_UVtab0[code2];
+ code2 = (code2&0xffff0000)|((last_dc[n]+=VALOF(code2)*4)&0x3ff);
+ } else {
+ int nbit,val;
+ int bit = 4;
+ while(Show_Bits(bit)&1) { bit++;}
+ nbit = bit*2;
+ val = Show_Bits(nbit)&((1<<bit)-1);
+ if ((val&(1<<(bit-1)))==0)
+ val -= (1<<bit)-1;
+ val = (last_dc[n]+=val*4);
+ code2 = (nbit<<16) | (val&0x3ff);
+ }
+ /* printf("%d ",last_dc[n]); */
+ }
+ if (++n==6) n=0;
+ }
+ /* printf("%d ",VALOF(code2)); */
+ code2 |= q_code;
+
+ /* AC */
+ for(;;){
+/* Uint32 code; */
+#define code code2
+#define SBIT 17
+ *mdec_rl++=code2;
+ Flush_Buffer(BITOF(code2));
+ code = Show_Bits(SBIT);
+ if (code>=1<<(SBIT- 2)) {
+ code2 = VLCtabnext[(code>>12)-8];
+ if (code2==EOB_CODE) break;
+ }
+ else if (code>=1<<(SBIT- 6)) {
+ code2 = VLCtab0[(code>>8)-8];
+ if (code2==ESCAPE_CODE) {
+ Flush_Buffer(6); /* ESCAPE len */
+ code2 = Show_Bits(16)| (16<<16);
+ }
+ }
+ else if (code>=1<<(SBIT- 7)) code2 = VLCtab1[(code>>6)-16];
+ else if (code>=1<<(SBIT- 8)) code2 = VLCtab2[(code>>4)-32];
+ else if (code>=1<<(SBIT- 9)) code2 = VLCtab3[(code>>3)-32];
+ else if (code>=1<<(SBIT-10)) code2 = VLCtab4[(code>>2)-32];
+ else if (code>=1<<(SBIT-11)) code2 = VLCtab5[(code>>1)-32];
+ else if (code>=1<<(SBIT-12)) code2 = VLCtab6[(code>>0)-32];
+ else {
+ do {
+ *mdec_rl++=EOB;
+ } while(mdec_rl<rl_end);
+ return 0;
+ }
+ }
+ *mdec_rl++=code2; /* EOB code */
+ Flush_Buffer(2); /* EOB bitlen */
+ }
+ return 0;
+}
+
+
+
+/* this table is based on djpeg by Independent Jpeg Group */
+
+static const int aanscales[DCTSIZE2] = {
+ /* precomputed values scaled up by 14 bits */
+ 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+ 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
+ 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
+ 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
+ 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+ 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
+ 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
+ 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
+};
+
+extern unsigned char zscan[DCTSIZE2];
+
+typedef struct {
+ int iqtab[DCTSIZE2];
+ const unsigned char *iq_y;
+ Uint16 *mdec_rl,*rl_end;
+ int mdec_mode;
+} bs_context_t;
+
+void iqtab_init(bs_context_t *ctxt)
+{
+#define CONST_BITS 14
+#define IFAST_SCALE_BITS 2
+ int i;
+ for(i=0;i<DCTSIZE2;i++) {
+ ctxt->iqtab[i] =ctxt->iq_y[i]*aanscales[i]>>(CONST_BITS-IFAST_SCALE_BITS);
+ }
+}
+
+#define BLOCK long
+
+extern void IDCT(BLOCK *blk,int k);
+
+Uint16* rl2blk(bs_context_t *ctxt, BLOCK *blk,Uint16 *mdec_rl)
+{
+ int i,k,q_scale,rl;
+ memset(blk,0,6*DCTSIZE2*sizeof(BLOCK));
+ for(i=0;i<6;i++) {
+ rl = *mdec_rl++;
+ q_scale = RUNOF(rl);
+ blk[0] = ctxt->iqtab[0]*VALOF(rl);
+ k = 0;
+ for(;;) {
+ rl = *mdec_rl++;
+ if (rl==EOB) break;
+ k += RUNOF(rl)+1;
+ blk[zscan[k]] = ctxt->iqtab[zscan[k]]*q_scale*VALOF(rl)/8;
+ }
+
+ IDCT(blk,k+1);
+
+ blk+=DCTSIZE2;
+ }
+ return mdec_rl;
+}
+
+#define RGB15(r,g,b) ( (((b)&0xf8)<<7)|(((g)&0xf8)<<2)|((r)>>3) )
+
+#define ROUND(r) bs_roundtbl[(r)+256]
+#if 1
+#define SHIFT 12
+#define toFIX(a) (int)((a)*(1<<SHIFT))
+#define toINT(a) ((a)>>SHIFT)
+#define FIX_1 toFIX(1)
+#define MULR(a) toINT((a)*toFIX(1.402))
+#define MULG(a) toINT((a)*toFIX(-0.3437))
+#define MULG2(a) toINT((a)*toFIX(-0.7143))
+#define MULB(a) toINT((a)*toFIX(1.772))
+#else
+#define MULR(a) 0
+#define MULG(a) 0
+#define MULG2(a) 0
+#define MULB(a) 0
+#endif
+
+
+/*
+int ROUND(int r)
+{
+ if (r<0) return 0;
+ else if (r>255) return 255;
+ else return r;
+}
+*/
+
+extern Uint8 bs_roundtbl[256*3];
+
+static void yuv2rgb15(BLOCK *blk,Uint16 *image)
+{
+ int x,yy;
+ BLOCK *yblk = blk+DCTSIZE2*2;
+ for(yy=0;yy<16;yy+=2,blk+=4,yblk+=8,image+=8+16) {
+ if (yy==8) yblk+=DCTSIZE2;
+ for(x=0;x<4;x++,blk++,yblk+=2,image+=2) {
+ int r0,b0,g0,y;
+ r0 = MULR(blk[DCTSIZE2]); /* cr */
+ g0 = MULG(blk[0])+MULG2(blk[DCTSIZE2]);
+ b0 = MULB(blk[0]); /* cb */
+ y = yblk[0]+128;
+ image[0] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y));
+ y = yblk[1]+128+4;
+ image[1] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y));
+ y = yblk[8]+128+6;
+ image[16] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y));
+ y = yblk[9]+128+2;
+ image[17] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y));
+ r0 = MULR(blk[4+DCTSIZE2]);
+ g0 = MULG(blk[4])+MULG2(blk[4+DCTSIZE2]);
+ b0 = MULB(blk[4]);
+ y = yblk[DCTSIZE2+0]+128;
+ image[8+0] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y));
+ y = yblk[DCTSIZE2+1]+128+4;
+ image[8+1] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y));
+ y = yblk[DCTSIZE2+8]+128+6;
+ image[8+16] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y));
+ y = yblk[DCTSIZE2+9]+128+2;
+ image[8+17] = RGB15(ROUND(r0+y),ROUND(g0+y),ROUND(b0+y));
+ }
+ }
+}
+
+enum {R, G, B};
+
+static void yuv2rgb24(BLOCK *blk,Uint8 image[][3])
+{
+ int x,yy;
+ BLOCK *yblk = blk+DCTSIZE2*2;
+ for(yy=0;yy<16;yy+=2,blk+=4,yblk+=8,image+=8+16) {
+ if (yy==8) yblk+=DCTSIZE2;
+ for(x=0;x<4;x++,blk++,yblk+=2,image+=2) {
+ int r0,b0,g0,y;
+ r0 = MULR(blk[DCTSIZE2]); /* cr */
+ g0 = MULG(blk[0])+MULG2(blk[DCTSIZE2]);
+ b0 = MULB(blk[0]); /* cb */
+ y = yblk[0]+128;
+ image[0][R] = ROUND(r0+y);
+ image[0][G] = ROUND(g0+y);
+ image[0][B] = ROUND(b0+y);
+ y = yblk[1]+128;
+ image[1][R] = ROUND(r0+y);
+ image[1][G] = ROUND(g0+y);
+ image[1][B] = ROUND(b0+y);
+ y = yblk[8]+128;
+ image[16][R] = ROUND(r0+y);
+ image[16][G] = ROUND(g0+y);
+ image[16][B] = ROUND(b0+y);
+ y = yblk[9]+128;
+ image[17][R] = ROUND(r0+y);
+ image[17][G] = ROUND(g0+y);
+ image[17][B] = ROUND(b0+y);
+
+ r0 = MULR(blk[4+DCTSIZE2]);
+ g0 = MULG(blk[4])+MULG2(blk[4+DCTSIZE2]);
+ b0 = MULB(blk[4]);
+ y = yblk[DCTSIZE2+0]+128;
+ image[8+0][R] = ROUND(r0+y);
+ image[8+0][G] = ROUND(g0+y);
+ image[8+0][B] = ROUND(b0+y);
+ y = yblk[DCTSIZE2+1]+128;
+ image[8+1][R] = ROUND(r0+y);
+ image[8+1][G] = ROUND(g0+y);
+ image[8+1][B] = ROUND(b0+y);
+ y = yblk[DCTSIZE2+8]+128;
+ image[8+16][R] = ROUND(r0+y);
+ image[8+16][G] = ROUND(g0+y);
+ image[8+16][B] = ROUND(b0+y);
+ y = yblk[DCTSIZE2+9]+128;
+ image[8+17][R] = ROUND(r0+y);
+ image[8+17][G] = ROUND(g0+y);
+ image[8+17][B] = ROUND(b0+y);
+ }
+ }
+}
+
+static void DecDCTReset(bs_context_t *ctxt, int mode)
+{
+ iqtab_init(ctxt);
+}
+
+static void DecDCTin(bs_context_t *ctxt, Uint16 *mdecrl,int mode)
+{
+ mdecrl+=2;
+ ctxt->mdec_rl = mdecrl;
+ ctxt->rl_end = mdecrl+mdecrl[-2]*2;
+ ctxt->mdec_mode = mode;
+}
+
+static void DecDCTout(bs_context_t *ctxt, Uint16 *image,int size)
+{
+ BLOCK blk[DCTSIZE2*6];
+ int blocksize=16*16;
+ if (ctxt->mdec_mode) blocksize = 16*16*3/2;
+ for(;size>0;size-=blocksize/2,image+=blocksize) {
+ ctxt->mdec_rl = rl2blk(ctxt,blk,ctxt->mdec_rl);
+ if (ctxt->mdec_mode==0) yuv2rgb15(blk,image);
+ else yuv2rgb24(blk,image);
+ }
+}
+
+void bs_decode_rgb24 (
+ unsigned char *outbuf, /* output RGB bytes (width*height*3) */
+ bs_header_t *img, /* input BS image */
+ int width, int height, /* dimension of BS image */
+ const unsigned char *myiqtab
+ )
+{
+ unsigned short *buf2 = (unsigned short *) outbuf;
+ unsigned short *bufp = (unsigned short *) img;
+ bs_context_t ctxt;
+ unsigned short *rl,*image;
+ int slice;
+ /* int rlsize; */
+ int mode;
+ int x,y;
+ int height2 = (height+15)&~15;
+ int w;
+
+ ctxt.iq_y = myiqtab ? myiqtab : bs_iqtab();
+ mode=1;
+ w=24;
+ width = width*3/2;
+
+ image = (unsigned short *) malloc (height2*w*sizeof(short));
+ rl = (unsigned short *) malloc ((bufp[0]+2)*sizeof(long));
+
+ DecDCTReset(&ctxt,0);
+ DecDCTvlc(bufp,rl);
+ DecDCTin(&ctxt,rl,mode);
+
+ slice = height2*w/2;
+
+ for(x=0;x<width;x+=w)
+ {
+ Uint16 *dst,*src;
+ DecDCTout(&ctxt,image,slice);
+ src = image;
+ dst = buf2+x+(0)*width;
+ for(y=height-1;y>=0;y--)
+ {
+ memcpy(dst,src,w*2);
+ src+=w;
+ dst+=width;
+ }
+ }
+
+ free (image);
+ free (rl);
+}
+
+void bs_decode_rgb15 (
+ unsigned short *outbuf, /* output RGB bytes (width*height*2) */
+ bs_header_t *img, /* input BS image */
+ int width, int height, /* dimension of BS image */
+ const unsigned char *myiqtab
+ )
+{
+ unsigned short *buf2 = (unsigned short *) outbuf;
+ unsigned short *bufp = (unsigned short *) img;
+ bs_context_t ctxt;
+ unsigned short *rl,*image;
+ int slice;
+ /* int rlsize; */
+ int mode;
+ int x,y;
+ int height2 = (height+15)&~15;
+ int w;
+
+ ctxt.iq_y = myiqtab ? myiqtab : bs_iqtab();
+ mode=0;
+ w=24;
+
+ image = (unsigned short *) malloc (height2*w*sizeof(short));
+ rl = (unsigned short *) malloc ((bufp[0]+2)*sizeof(long));
+
+ DecDCTReset(&ctxt,0);
+ DecDCTvlc(bufp,rl);
+ DecDCTin(&ctxt,rl,mode);
+
+ slice = height2*w/2;
+
+ for(x=0;x<width;x+=w)
+ {
+ Uint16 *dst,*src;
+ DecDCTout(&ctxt,image,slice);
+ src = image;
+ dst = buf2+x+(height-1)*width;
+ for(y=height-1;y>=0;y--)
+ {
+ memcpy(dst,src,w*2);
+ src+=w;
+ dst-=width;
+ }
+ }
+
+ free (image);
+ free (rl);
+}
diff --git a/psxdev/xadecode.c b/psxdev/xadecode.c index 10da6c9..39523aa 100644 --- a/psxdev/xadecode.c +++ b/psxdev/xadecode.c @@ -1,302 +1,302 @@ -/* - author: unknown, probably bitmaster? - slightly modified by dbalster -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <math.h> -#include "common.h" -#include "xadecode.h" - -#if USE_FXD -static FXD K0[4] = { - 0x00000000, - 0x0000F000, - 0x0001CC00, - 0x00018800 -}; -static FXD K1[4] = { - 0x00000000, - 0x00000000, - 0xFFFF3000, - 0xFFFF2400 -}; -FXD t1, t2, at1[256], at2[256]; -FXD t1_x, t2_x, at1_x[256], at2_x[256]; -#else -static double K0[4] = { - 0.0, - 0.9375, - 1.796875, - 1.53125 -}; -static double K1[4] = { - 0.0, - 0.0, - -0.8125, - -0.859375 -}; -double t1, t2, at1[256], at2[256]; -double t1_x, t2_x, at1_x[256], at2_x[256]; -#endif - -void initXaDecode(void) -{ - int i; - - for (i=0; i<256; ++i) - { - at1[i] = at2[i] = at1_x[i] = at2_x[i] = 0; - } -} -void reinitXaDecode(int i) -{ - at1[i] = at2[i] = at1_x[i] = at2_x[i] = 0; -} -void switchXaDecode(int i) -{ - t1 = at1[i]; - t2 = at2[i]; - t1_x = at1_x[i]; - t2_x = at2_x[i]; -} -void saveXaDecode(int i) -{ - at1[i] = t1; - at2[i] = t2; - at1_x[i]= t1_x; - at2_x[i]= t2_x; -} - -char xachannel(SoundSector *ss) -{ - return(ss->sectorFiller[XAChannel]); -} - -unsigned char xatype(SoundSector *ss) -{ - return(unsigned char) (ss->sectorFiller[XAType]); -} - -char xafileno(SoundSector *ss) -{ - return(ss->sectorFiller[XAFile]); -} - -char xastereo(SoundSector *ss) -{ - return(ss->sectorFiller[XAFlags]&XAFStereo); -} - -char xahalfhz(SoundSector *ss) -{ - return(ss->sectorFiller[XAFlags]&XAFHalfHz); -} - -long convXaToWave(char *adp, char *wav, int cn, int fn_s, int fn_e) -{ - SoundSector ssct; - int i; - - memcpy(ssct.sectorFiller,adp,sizeof(ssct.sectorFiller)); - for(i=0;i<18;i++) - memcpy(ssct.SoundGroups[i],adp+sizeof(ssct.sectorFiller)+(128*i),128); - if ((xachannel(&ssct) == cn) && (xatype(&ssct) == XAAUDIO)) - { - if (xafileno(&ssct) >= fn_s - && xafileno(&ssct) <= fn_e) - { - if (xastereo(&ssct)) - return(decodeSoundSect1(&ssct, wav)); - else - return(decodeSoundSect(&ssct, wav)); - } - } - return(0); -} - -long decodeSoundSect(SoundSector *ssct, char *wav) -{ - long count, outputBytes; - signed char snddat, filt, range; - short decoded; - long unit, sample; - long sndgrp; -#if USE_FXD - FXD tmp2, tmp3, tmp4, tmp5; -#else - double tmp2, tmp3, tmp4, tmp5; -#endif - - outputBytes = 0; - - for (sndgrp = 0; sndgrp < kNumOfSGs; sndgrp++) - { - count = 0; - for (unit = 0; unit < 8; unit++) - { - range = getRange(ssct->SoundGroups[sndgrp], unit); - filt = getFilter(ssct->SoundGroups[sndgrp], unit); - for (sample = 0; sample < 28; sample++) - { - snddat = getSoundData(ssct->SoundGroups[sndgrp], unit, sample); -#if USE_FXD - tmp2 = (long)(snddat) << (12 - range); - tmp3 = FXD_Pcm16ToFxd(tmp2); - tmp4 = FXD_FixMul(K0[filt], t1); - tmp5 = FXD_FixMul(K1[filt], t2); - t2 = t1; - t1 = tmp3 + tmp4 + tmp5; - decoded = FXD_FxdToPcm16(t1); -#else - tmp2 = (double)(1 << (12 - range)); - tmp3 = (double)snddat * tmp2; - tmp4 = t1 * K0[filt]; - tmp5 = t2 * K1[filt]; - t2 = t1; - t1 = tmp3 + tmp4 + tmp5; - decoded = DblToPCM(t1); -#endif - wav[outputBytes+count++] = (char)(decoded & 0x0000ffff); - wav[outputBytes+count++] = (char)(decoded >> 8); - } - } - outputBytes += count; - } - return outputBytes; -} - -long decodeSoundSect1(SoundSector *ssct, char *wav) -{ - long count, outputBytes; - signed char snddat, filt, range; - signed char filt1, range1; - short decoded; - long unit, sample; - long sndgrp; -#if USE_FXD - FXD tmp2, tmp3, tmp4, tmp5; -#else - double tmp2, tmp3, tmp4, tmp5; -#endif - - outputBytes = 0; - - for (sndgrp = 0; sndgrp < kNumOfSGs; sndgrp++) - { - count = 0; - for (unit = 0; unit < 8; unit+= 2) - { - range = getRange(ssct->SoundGroups[sndgrp], unit); - filt = getFilter(ssct->SoundGroups[sndgrp], unit); - range1 = getRange(ssct->SoundGroups[sndgrp], unit+1); - filt1 = getFilter(ssct->SoundGroups[sndgrp], unit+1); - - for (sample = 0; sample < 28; sample++) - { - /* Channel 1 */ - snddat = getSoundData(ssct->SoundGroups[sndgrp], unit, sample); -#if USE_FXD - tmp2 = (long)(snddat) << (12 - range); - tmp3 = FXD_Pcm16ToFxd(tmp2); - tmp4 = FXD_FixMul(K0[filt], t1); - tmp5 = FXD_FixMul(K1[filt], t2); - t2 = t1; - t1 = tmp3 + tmp4 + tmp5; - decoded = FXD_FxdToPcm16(t1); -#else - tmp2 = (double)(1 << (12 - range)); - tmp3 = (double)snddat * tmp2; - tmp4 = t1 * K0[filt]; - tmp5 = t2 * K1[filt]; - t2 = t1; - t1 = tmp3 + tmp4 + tmp5; - decoded = DblToPCM(t1); -#endif - wav[outputBytes + count++] = (char)(decoded & 0x0000ffff); - wav[outputBytes + count++] = (char)(decoded >> 8); - - /* Channel 2 */ - snddat = getSoundData(ssct->SoundGroups[sndgrp], unit+1, sample); -#if USE_FXD - tmp2 = (long)(snddat) << (12 - range1); - tmp3 = FXD_Pcm16ToFxd(tmp2); - tmp4 = FXD_FixMul(K0[filt1], t1_x); - tmp5 = FXD_FixMul(K1[filt1], t2_x); - t2_x = t1_x; - t1_x = tmp3 + tmp4 + tmp5; - decoded = FXD_FxdToPcm16(t1_x); -#else - tmp2 = (double)(1 << (12 - range1)); - tmp3 = (double)snddat * tmp2; - tmp4 = t1_x * K0[filt1]; - tmp5 = t2_x * K1[filt1]; - t2_x = t1_x; - t1_x = tmp3 + tmp4 + tmp5; - decoded = DblToPCM(t1_x); -#endif - wav[outputBytes + count++] = (char)(decoded & 0x0000ffff); - wav[outputBytes + count++] = (char)(decoded >> 8); - } - } - outputBytes += count; - } - return outputBytes; -} - -signed char getSoundData(char *buf, long unit, long sample) -{ - signed char ret; - char *p; - long offset, shift; - - p = buf; - shift = (unit%2) * 4; - - offset = 16 + (unit / 2) + (sample * 4); - p += offset; - - ret = (*p >> shift) & 0x0F; - - if (ret > 7) { - ret -= 16; - } - return ret; -} - -signed char getFilter(char *buf, long unit) -{ - return (*(buf + 4 + unit) >> 4) & 0x03; -} - - -signed char getRange(char *buf, long unit) -{ - return *(buf + 4 + unit) & 0x0F; -} - -#if USE_FXD -FXD FXD_FixMul(FXD a, FXD b) -{ - long high_a, low_a, high_b, low_b; - long hahb, halb, lahb; - unsigned long lalb; - FXD ret; - - high_a = a >> 16; - low_a = a & 0x0000FFFF; - high_b = b >> 16; - low_b = b & 0x0000FFFF; - - hahb = (high_a * high_b) << 16; - halb = high_a * low_b; - lahb = low_a * high_b; - lalb = (unsigned long)(low_a * low_b) >> 16; - - ret = hahb + halb + lahb + lalb; - - return ret; -} -#endif +/*
+ author: unknown, probably bitmaster?
+ slightly modified by dbalster
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "common.h"
+#include "xadecode.h"
+
+#if USE_FXD
+static FXD K0[4] = {
+ 0x00000000,
+ 0x0000F000,
+ 0x0001CC00,
+ 0x00018800
+};
+static FXD K1[4] = {
+ 0x00000000,
+ 0x00000000,
+ 0xFFFF3000,
+ 0xFFFF2400
+};
+FXD t1, t2, at1[256], at2[256];
+FXD t1_x, t2_x, at1_x[256], at2_x[256];
+#else
+static double K0[4] = {
+ 0.0,
+ 0.9375,
+ 1.796875,
+ 1.53125
+};
+static double K1[4] = {
+ 0.0,
+ 0.0,
+ -0.8125,
+ -0.859375
+};
+double t1, t2, at1[256], at2[256];
+double t1_x, t2_x, at1_x[256], at2_x[256];
+#endif
+
+void initXaDecode(void)
+{
+ int i;
+
+ for (i=0; i<256; ++i)
+ {
+ at1[i] = at2[i] = at1_x[i] = at2_x[i] = 0;
+ }
+}
+void reinitXaDecode(int i)
+{
+ at1[i] = at2[i] = at1_x[i] = at2_x[i] = 0;
+}
+void switchXaDecode(int i)
+{
+ t1 = at1[i];
+ t2 = at2[i];
+ t1_x = at1_x[i];
+ t2_x = at2_x[i];
+}
+void saveXaDecode(int i)
+{
+ at1[i] = t1;
+ at2[i] = t2;
+ at1_x[i]= t1_x;
+ at2_x[i]= t2_x;
+}
+
+char xachannel(SoundSector *ss)
+{
+ return(ss->sectorFiller[XAChannel]);
+}
+
+unsigned char xatype(SoundSector *ss)
+{
+ return(unsigned char) (ss->sectorFiller[XAType]);
+}
+
+char xafileno(SoundSector *ss)
+{
+ return(ss->sectorFiller[XAFile]);
+}
+
+char xastereo(SoundSector *ss)
+{
+ return(ss->sectorFiller[XAFlags]&XAFStereo);
+}
+
+char xahalfhz(SoundSector *ss)
+{
+ return(ss->sectorFiller[XAFlags]&XAFHalfHz);
+}
+
+long convXaToWave(char *adp, char *wav, int cn, int fn_s, int fn_e)
+{
+ SoundSector ssct;
+ int i;
+
+ memcpy(ssct.sectorFiller,adp,sizeof(ssct.sectorFiller));
+ for(i=0;i<18;i++)
+ memcpy(ssct.SoundGroups[i],adp+sizeof(ssct.sectorFiller)+(128*i),128);
+ if ((xachannel(&ssct) == cn) && (xatype(&ssct) == XAAUDIO))
+ {
+ if (xafileno(&ssct) >= fn_s
+ && xafileno(&ssct) <= fn_e)
+ {
+ if (xastereo(&ssct))
+ return(decodeSoundSect1(&ssct, wav));
+ else
+ return(decodeSoundSect(&ssct, wav));
+ }
+ }
+ return(0);
+}
+
+long decodeSoundSect(SoundSector *ssct, char *wav)
+{
+ long count, outputBytes;
+ signed char snddat, filt, range;
+ short decoded;
+ long unit, sample;
+ long sndgrp;
+#if USE_FXD
+ FXD tmp2, tmp3, tmp4, tmp5;
+#else
+ double tmp2, tmp3, tmp4, tmp5;
+#endif
+
+ outputBytes = 0;
+
+ for (sndgrp = 0; sndgrp < kNumOfSGs; sndgrp++)
+ {
+ count = 0;
+ for (unit = 0; unit < 8; unit++)
+ {
+ range = getRange(ssct->SoundGroups[sndgrp], unit);
+ filt = getFilter(ssct->SoundGroups[sndgrp], unit);
+ for (sample = 0; sample < 28; sample++)
+ {
+ snddat = getSoundData(ssct->SoundGroups[sndgrp], unit, sample);
+#if USE_FXD
+ tmp2 = (long)(snddat) << (12 - range);
+ tmp3 = FXD_Pcm16ToFxd(tmp2);
+ tmp4 = FXD_FixMul(K0[filt], t1);
+ tmp5 = FXD_FixMul(K1[filt], t2);
+ t2 = t1;
+ t1 = tmp3 + tmp4 + tmp5;
+ decoded = FXD_FxdToPcm16(t1);
+#else
+ tmp2 = (double)(1 << (12 - range));
+ tmp3 = (double)snddat * tmp2;
+ tmp4 = t1 * K0[filt];
+ tmp5 = t2 * K1[filt];
+ t2 = t1;
+ t1 = tmp3 + tmp4 + tmp5;
+ decoded = DblToPCM(t1);
+#endif
+ wav[outputBytes+count++] = (char)(decoded & 0x0000ffff);
+ wav[outputBytes+count++] = (char)(decoded >> 8);
+ }
+ }
+ outputBytes += count;
+ }
+ return outputBytes;
+}
+
+long decodeSoundSect1(SoundSector *ssct, char *wav)
+{
+ long count, outputBytes;
+ signed char snddat, filt, range;
+ signed char filt1, range1;
+ short decoded;
+ long unit, sample;
+ long sndgrp;
+#if USE_FXD
+ FXD tmp2, tmp3, tmp4, tmp5;
+#else
+ double tmp2, tmp3, tmp4, tmp5;
+#endif
+
+ outputBytes = 0;
+
+ for (sndgrp = 0; sndgrp < kNumOfSGs; sndgrp++)
+ {
+ count = 0;
+ for (unit = 0; unit < 8; unit+= 2)
+ {
+ range = getRange(ssct->SoundGroups[sndgrp], unit);
+ filt = getFilter(ssct->SoundGroups[sndgrp], unit);
+ range1 = getRange(ssct->SoundGroups[sndgrp], unit+1);
+ filt1 = getFilter(ssct->SoundGroups[sndgrp], unit+1);
+
+ for (sample = 0; sample < 28; sample++)
+ {
+ /* Channel 1 */
+ snddat = getSoundData(ssct->SoundGroups[sndgrp], unit, sample);
+#if USE_FXD
+ tmp2 = (long)(snddat) << (12 - range);
+ tmp3 = FXD_Pcm16ToFxd(tmp2);
+ tmp4 = FXD_FixMul(K0[filt], t1);
+ tmp5 = FXD_FixMul(K1[filt], t2);
+ t2 = t1;
+ t1 = tmp3 + tmp4 + tmp5;
+ decoded = FXD_FxdToPcm16(t1);
+#else
+ tmp2 = (double)(1 << (12 - range));
+ tmp3 = (double)snddat * tmp2;
+ tmp4 = t1 * K0[filt];
+ tmp5 = t2 * K1[filt];
+ t2 = t1;
+ t1 = tmp3 + tmp4 + tmp5;
+ decoded = DblToPCM(t1);
+#endif
+ wav[outputBytes + count++] = (char)(decoded & 0x0000ffff);
+ wav[outputBytes + count++] = (char)(decoded >> 8);
+
+ /* Channel 2 */
+ snddat = getSoundData(ssct->SoundGroups[sndgrp], unit+1, sample);
+#if USE_FXD
+ tmp2 = (long)(snddat) << (12 - range1);
+ tmp3 = FXD_Pcm16ToFxd(tmp2);
+ tmp4 = FXD_FixMul(K0[filt1], t1_x);
+ tmp5 = FXD_FixMul(K1[filt1], t2_x);
+ t2_x = t1_x;
+ t1_x = tmp3 + tmp4 + tmp5;
+ decoded = FXD_FxdToPcm16(t1_x);
+#else
+ tmp2 = (double)(1 << (12 - range1));
+ tmp3 = (double)snddat * tmp2;
+ tmp4 = t1_x * K0[filt1];
+ tmp5 = t2_x * K1[filt1];
+ t2_x = t1_x;
+ t1_x = tmp3 + tmp4 + tmp5;
+ decoded = DblToPCM(t1_x);
+#endif
+ wav[outputBytes + count++] = (char)(decoded & 0x0000ffff);
+ wav[outputBytes + count++] = (char)(decoded >> 8);
+ }
+ }
+ outputBytes += count;
+ }
+ return outputBytes;
+}
+
+signed char getSoundData(char *buf, long unit, long sample)
+{
+ signed char ret;
+ char *p;
+ long offset, shift;
+
+ p = buf;
+ shift = (unit%2) * 4;
+
+ offset = 16 + (unit / 2) + (sample * 4);
+ p += offset;
+
+ ret = (*p >> shift) & 0x0F;
+
+ if (ret > 7) {
+ ret -= 16;
+ }
+ return ret;
+}
+
+signed char getFilter(char *buf, long unit)
+{
+ return (*(buf + 4 + unit) >> 4) & 0x03;
+}
+
+
+signed char getRange(char *buf, long unit)
+{
+ return *(buf + 4 + unit) & 0x0F;
+}
+
+#if USE_FXD
+FXD FXD_FixMul(FXD a, FXD b)
+{
+ long high_a, low_a, high_b, low_b;
+ long hahb, halb, lahb;
+ unsigned long lalb;
+ FXD ret;
+
+ high_a = a >> 16;
+ low_a = a & 0x0000FFFF;
+ high_b = b >> 16;
+ low_b = b & 0x0000FFFF;
+
+ hahb = (high_a * high_b) << 16;
+ halb = high_a * low_b;
+ lahb = low_a * high_b;
+ lalb = (unsigned long)(low_a * low_b) >> 16;
+
+ ret = hahb + halb + lahb + lalb;
+
+ return ret;
+}
+#endif
diff --git a/psxdev/xadecode.h b/psxdev/xadecode.h index b886285..4714667 100644 --- a/psxdev/xadecode.h +++ b/psxdev/xadecode.h @@ -1,92 +1,92 @@ -/* - author: unknown, probably bitmaster? - slightly modified by dbalster -*/ - -#include "generic.h" - -#ifndef XADECODE_H -#define XADECODE_H - -#define USE_FXD 1 - -#define kNumOfSamples 224 -#define kNumOfSGs 18 - -#define XAFile 0 -#define XAChannel 1 -#define XAType 2 -#define XAFlags 3 -/* bits in XAFlags byte */ -#define XAFStereo 1<<0 -#define XAFHalfHz 1<<2 - -#define XAAUDIO 0x64 -#define XAVIDEO 0x48 -#define XABREAK 0xE4 -#define XACURRENT 0x100 /* for application use only! */ -#define XANONE 0x200 /* for application use only! */ -#define XAAV 0x400 /* for application use only! */ - -#define max(a,b) (a<b?b:a) -#define min(a,b) (a>b?b:a) - -#define FXD_FxdToPCM(dt) (max(min((short)((dt)>>16), 32767), -32768)) -#define DblToPCM(dt) (short)(max(min((dt), 32767), -32768)) - -#define WHP_READ68_AUTO(fp, dt) WHP_Read68(dt, sizeof(*(dt)), 1, fp) -#define WHP_WRITE68_AUTO(fp, dt) WHP_Write68(dt, sizeof(*(dt)), 1, fp) - -#define WHP_CNV_SHORT68(dt, ndt) WHP_CnvEndianShort((dt), (ndt)) -#define WHP_CNV_LONG68(dt, ndt) WHP_CnvEndianLong((dt), (ndt)) - -#if USE_FXD -#define FXD_FxdToPcm16(dt) (max(min((dt)/2, 32767), -32768)) -#define FXD_Pcm16ToFxd(dt) ((long)dt*2) -#endif - -#define XAWAVBUFSIZE (kNumOfSamples*kNumOfSGs*2) - -typedef char SoundGroup[128]; - -typedef struct SoundSector { - char sectorFiller[8]; - SoundGroup SoundGroups[kNumOfSGs]; -} PACKED SoundSector; - -typedef unsigned long DWORD; -typedef unsigned short WORD; - -#if USE_FXD -typedef long FXD; -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -long decodeSoundSect(SoundSector *ssct, char *wav); -long decodeSoundSect1(SoundSector *ssct, char *wav); -long convXaToWave(char *adp, char *wav, int cn, int fn_s, int fn_e); -void initXaDecode(void); -void switchXaDecode(int channel); -void saveXaDecode(int channel); -void reinitXaDecode(int channel); -signed char getSoundData(char *buf, long unit, long sample); -signed char getFilter(char *buf, long unit); -signed char getRange(char *buf, long unit); -char xachannel(SoundSector *ss); -unsigned char xatype(SoundSector *ss); -char xafileno(SoundSector *ss); -char xastereo(SoundSector *ss); -char xahalfhz(SoundSector *ss); - -#if USE_FXD -FXD FXD_FixMul(FXD a, FXD b); -#endif - -#ifdef __cplusplus -} -#endif - -#endif +/*
+ author: unknown, probably bitmaster?
+ slightly modified by dbalster
+*/
+
+#include "generic.h"
+
+#ifndef XADECODE_H
+#define XADECODE_H
+
+#define USE_FXD 1
+
+#define kNumOfSamples 224
+#define kNumOfSGs 18
+
+#define XAFile 0
+#define XAChannel 1
+#define XAType 2
+#define XAFlags 3
+/* bits in XAFlags byte */
+#define XAFStereo 1<<0
+#define XAFHalfHz 1<<2
+
+#define XAAUDIO 0x64
+#define XAVIDEO 0x48
+#define XABREAK 0xE4
+#define XACURRENT 0x100 /* for application use only! */
+#define XANONE 0x200 /* for application use only! */
+#define XAAV 0x400 /* for application use only! */
+
+#define max(a,b) (a<b?b:a)
+#define min(a,b) (a>b?b:a)
+
+#define FXD_FxdToPCM(dt) (max(min((short)((dt)>>16), 32767), -32768))
+#define DblToPCM(dt) (short)(max(min((dt), 32767), -32768))
+
+#define WHP_READ68_AUTO(fp, dt) WHP_Read68(dt, sizeof(*(dt)), 1, fp)
+#define WHP_WRITE68_AUTO(fp, dt) WHP_Write68(dt, sizeof(*(dt)), 1, fp)
+
+#define WHP_CNV_SHORT68(dt, ndt) WHP_CnvEndianShort((dt), (ndt))
+#define WHP_CNV_LONG68(dt, ndt) WHP_CnvEndianLong((dt), (ndt))
+
+#if USE_FXD
+#define FXD_FxdToPcm16(dt) (max(min((dt)/2, 32767), -32768))
+#define FXD_Pcm16ToFxd(dt) ((long)dt*2)
+#endif
+
+#define XAWAVBUFSIZE (kNumOfSamples*kNumOfSGs*2)
+
+typedef char SoundGroup[128];
+
+typedef struct SoundSector {
+ char sectorFiller[8];
+ SoundGroup SoundGroups[kNumOfSGs];
+} PACKED SoundSector;
+
+typedef unsigned long DWORD;
+typedef unsigned short WORD;
+
+#if USE_FXD
+typedef long FXD;
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+long decodeSoundSect(SoundSector *ssct, char *wav);
+long decodeSoundSect1(SoundSector *ssct, char *wav);
+long convXaToWave(char *adp, char *wav, int cn, int fn_s, int fn_e);
+void initXaDecode(void);
+void switchXaDecode(int channel);
+void saveXaDecode(int channel);
+void reinitXaDecode(int channel);
+signed char getSoundData(char *buf, long unit, long sample);
+signed char getFilter(char *buf, long unit);
+signed char getRange(char *buf, long unit);
+char xachannel(SoundSector *ss);
+unsigned char xatype(SoundSector *ss);
+char xafileno(SoundSector *ss);
+char xastereo(SoundSector *ss);
+char xahalfhz(SoundSector *ss);
+
+#if USE_FXD
+FXD FXD_FixMul(FXD a, FXD b);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/str-player.cpp b/str-player.cpp index 99ddd15..de62e50 100644 --- a/str-player.cpp +++ b/str-player.cpp @@ -1,262 +1,262 @@ -#include <stdlib.h> -#include <string.h> -#include <SDL/SDL.h> -#include <SDL/SDL_audio.h> -#include <getopt.h> -#include "Input.h" -#include "Output.h" -#include "psxdev/bs.h" -#include "generic.h" -#include "cdutils.h" -#include "psxdev/xadecode.h" -#include "Main.h" - -/* - - From the documentation: - - 32 bytes header: - -StSTATUS : 2 bytes 0 -StTYPE : 2 bytes 2 -StSECTOR_OFFSET: 2 bytes 4 -StSECTOR_SIZE : 2 bytes 6 -StFRAME_NO : 4 bytes 10 -StFRAME_SIZE : 4 bytes 14 -StMOVIE_WIDTH : 2 bytes 16 -StMOVIE_HEIGHT : 2 bytes 18 -StMOVIE_HEADM : 4 bytes 22 -StMOVIE_HEADV : 4 bytes 26 -Channels : 2 bytes 30 - - */ - -struct STR_Header { - Uint16 StSTATUS; - Uint16 StTYPE; - Uint16 StSECTOR_OFFSET; - Uint16 StSECTOR_SIZE; - Uint32 StFRAME_NO; - Uint32 StFRAME_SIZE; - Uint16 StMOVIE_WIDTH; - Uint16 StMOVIE_HEIGHT; - Uint32 StMOVIE_HEADM; - Uint32 StMOVIE_HEADV; - Uint16 Channels; -} PACKED; - -Byte * video = 0, * audio = 0, * audio2 = 0, * tbuffer = 0; - -int channel = -1; - -int width, height; - -SDL_Surface * screen = 0; -Uint8 bpp; - -int32 audio_len = 0, audio_len2 = 0; -Uint8 *audio_pos; - -void mixaudio(void *unused, Uint8 *stream, int len) { - /* Only play if we have data left */ - if ( audio_len == 0 ) - return; - - /* Mix as much data as possible */ - len = ( len > audio_len ? audio_len : len ); - SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME); - audio_pos += len; - audio_len -= len; -} - -CODE_BEGINS -int process_one_sector(Handle * f) { - Byte sector[2336]; - STR_Header * h; - - if (!f->read(sector, 2336)) - return 0; - h = (STR_Header *) ((Byte *) sector + 8); - -#ifdef CHATTING - printm(M_INFO, "SubHeader: FN = %x, CN = %x, SM = %x, CI = %x: ", sector[0], sector[1], sector[2], sector[3]); - - printm(M_BARE, "SubHeader FN : %x\n", sector[0]); - printm(M_BARE, "SubHeader CN : %x\n", sector[1]); - printm(M_BARE, "SubHeader SM : %x\n", sector[2]); - printm(M_BARE, "SubHeader CI : %x\n", sector[3]); -#endif - - if ((channel != -1) && (channel != sector[1])) - return -1; - - if ((sector[2] == 0x48) || (sector[2] == 0x42) || ((sector[2] == 8) && (sector[14] == 8))) { -#ifdef CHATTING - printm(M_BARE, "Video sector\n"); - printm(M_BARE, "Status : %04x\n", h->StSTATUS); - printm(M_BARE, "Type : %04x\n", h->StTYPE); - printm(M_BARE, "Sector Offset: %i\n", h->StSECTOR_OFFSET); - printm(M_BARE, "Sector Size : %i\n", h->StSECTOR_SIZE); - printm(M_BARE, "Frame Number : %i\n", h->StFRAME_NO); - printm(M_BARE, "Frame Size : %i\n", h->StFRAME_SIZE); - printm(M_BARE, "Movie Width : %i\n", h->StMOVIE_WIDTH); - printm(M_BARE, "Movie Height : %i\n", h->StMOVIE_HEIGHT); - printm(M_BARE, "Movie HeadM : %08x\n", h->StMOVIE_HEADM); - printm(M_BARE, "Movie HeadV : %08x\n", h->StMOVIE_HEADV); - printm(M_BARE, "Channels : %04x\n", h->Channels); -#endif - if (h->StSECTOR_OFFSET == 0) { - bs_init(); - video = (Byte *) malloc(h->StSECTOR_SIZE * 2016); - if (!screen) { - width = h->StMOVIE_WIDTH; - height = h->StMOVIE_HEIGHT; - screen = SDL_SetVideoMode(width, height, 24, SDL_HWSURFACE | SDL_DOUBLEBUF); - if (!screen) { - printm(M_ERROR, "Couldn't get framebuffer\n"); - exit(-1); - } - bpp = screen->format->BytesPerPixel; - } - } - - memcpy(video + h->StSECTOR_OFFSET * 2016, sector + 40, 2016); - - if (h->StSECTOR_SIZE == (h->StSECTOR_OFFSET + 1)) { - // Frame finished. -#ifdef CHATTING - printm(M_BARE, "End of Frame.\n"); -#endif - - Uint8 * buffer = ((Uint8 *) screen->pixels); - - if (SDL_MUSTLOCK(screen)) - if (SDL_LockSurface(screen) < 0) - exit(1); -#ifdef CHATTING - printm(M_BARE, "Width: %i, Height: %i - bpp: %i\n", width, height, bpp); -#endif - memset(video + h->StFRAME_SIZE, 0, h->StSECTOR_SIZE * 2016 - h->StFRAME_SIZE); -#ifdef DUMPING - String fn; - fn.set("frame-%04i.bs", h->StFRAME_NO); - Output * tf = new Output(fn); - tf->write(video, h->StFRAME_SIZE); - delete tf; -#endif - bs_decode_rgb24(buffer, (bs_header_t *) video, width, height, 0); - -// fwrite(screen->pixels, 3, width * height, stdout); - - if (SDL_MUSTLOCK(screen)) - SDL_UnlockSurface(screen); - SDL_Flip(screen); - - free(video); - } - } else if (sector[2] == 0x64) { - int locked = 0; - - SoundSector * buffer = (SoundSector *) sector; -#ifdef CHATTING - printm(M_BARE, "Audio sector\n"); - printm(M_BARE, "Frequency: %i\n", xahalfhz(buffer) ? 18900 : 37800); - printm(M_BARE, "Channels : %s\n", xastereo(buffer) ? "stereo" : "mono"); -#endif -// fwrite(sector + 8, 1, 2324, stdout); - - while (audio_len > 0) { - SDL_Delay(1); - } - - if (!audio2) { - SDL_AudioSpec fmt; - - /* Un son sereo de 16 bits à 44kHz */ - fmt.freq = xahalfhz(buffer) ? 18900 : 37800; - fmt.format = AUDIO_S16; - fmt.channels = xastereo(buffer) ? 2 : 1; - fmt.samples = 128; /*Une bonne valeur pour les jeux */ - fmt.callback = mixaudio; - fmt.userdata = NULL; - - /* Ouvre le contexte audio et joue le son */ - if (SDL_OpenAudio(&fmt, NULL) < 0) { - fprintf(stderr, "Impossible d'accéder à l'audio: %s\n", SDL_GetError()); - exit(1); - } - - initXaDecode(); - } else { - if (audio) { - SDL_LockAudio(); - free(audio); - locked = 1; - } - audio_pos = audio = audio2; - audio_len = audio_len2; - } - - audio2 = (Byte *) malloc(8192); - switchXaDecode(xachannel(buffer)); - audio_len2 = convXaToWave((char *) buffer, (char *) audio2, xachannel(buffer), 0, 255); - if (locked) - SDL_UnlockAudio(); - else if (audio) - SDL_PauseAudio(0); - saveXaDecode(xachannel(buffer)); - - } else { -#ifdef CHATTING - printm(M_BARE, "Unknow sector\n"); -#endif - } -#ifdef CHATTING - printm(M_BARE, "---------------------------------\n\n"); -#endif - return 1; -} - -virtual int startup() throw (GeneralException) { - Handle * file = 0; - int c; - - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0) { - printm(M_ERROR, "Couldn't initialise SDL: %s\n", SDL_GetError()); - exit(-1); - } - atexit(SDL_Quit); - SDL_ShowCursor(SDL_DISABLE); - - while ((c = getopt(argc, argv, "c:")) != EOF) { - switch (c) { - case 'c': - channel = atoi(optarg); - break; - default: - printm(M_ERROR, "Unknow argument.\n"); - break; - } - } - - switch (argc - optind) { - case 0: - file = &Stdin; - break; - case 1: - file = new Input(argv[optind]); - break; - default: - printm(M_ERROR, "Too much arguments.\n"); - exit(-1); - } - - while (process_one_sector(file)); - - if (!audio) - SDL_CloseAudio(); - - SDL_Quit(); - return 0; -} -CODE_ENDS +#include <stdlib.h>
+#include <string.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_audio.h>
+#include <getopt.h>
+#include "Input.h"
+#include "Output.h"
+#include "psxdev/bs.h"
+#include "generic.h"
+#include "cdutils.h"
+#include "psxdev/xadecode.h"
+#include "Main.h"
+
+/*
+
+ From the documentation:
+
+ 32 bytes header:
+
+StSTATUS : 2 bytes 0
+StTYPE : 2 bytes 2
+StSECTOR_OFFSET: 2 bytes 4
+StSECTOR_SIZE : 2 bytes 6
+StFRAME_NO : 4 bytes 10
+StFRAME_SIZE : 4 bytes 14
+StMOVIE_WIDTH : 2 bytes 16
+StMOVIE_HEIGHT : 2 bytes 18
+StMOVIE_HEADM : 4 bytes 22
+StMOVIE_HEADV : 4 bytes 26
+Channels : 2 bytes 30
+
+ */
+
+struct STR_Header {
+ Uint16 StSTATUS;
+ Uint16 StTYPE;
+ Uint16 StSECTOR_OFFSET;
+ Uint16 StSECTOR_SIZE;
+ Uint32 StFRAME_NO;
+ Uint32 StFRAME_SIZE;
+ Uint16 StMOVIE_WIDTH;
+ Uint16 StMOVIE_HEIGHT;
+ Uint32 StMOVIE_HEADM;
+ Uint32 StMOVIE_HEADV;
+ Uint16 Channels;
+} PACKED;
+
+Byte * video = 0, * audio = 0, * audio2 = 0, * tbuffer = 0;
+
+int channel = -1;
+
+int width, height;
+
+SDL_Surface * screen = 0;
+Uint8 bpp;
+
+int32 audio_len = 0, audio_len2 = 0;
+Uint8 *audio_pos;
+
+void mixaudio(void *unused, Uint8 *stream, int len) {
+ /* Only play if we have data left */
+ if ( audio_len == 0 )
+ return;
+
+ /* Mix as much data as possible */
+ len = ( len > audio_len ? audio_len : len );
+ SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME);
+ audio_pos += len;
+ audio_len -= len;
+}
+
+CODE_BEGINS
+int process_one_sector(Handle * f) {
+ Byte sector[2336];
+ STR_Header * h;
+
+ if (!f->read(sector, 2336))
+ return 0;
+ h = (STR_Header *) ((Byte *) sector + 8);
+
+#ifdef CHATTING
+ printm(M_INFO, "SubHeader: FN = %x, CN = %x, SM = %x, CI = %x: ", sector[0], sector[1], sector[2], sector[3]);
+
+ printm(M_BARE, "SubHeader FN : %x\n", sector[0]);
+ printm(M_BARE, "SubHeader CN : %x\n", sector[1]);
+ printm(M_BARE, "SubHeader SM : %x\n", sector[2]);
+ printm(M_BARE, "SubHeader CI : %x\n", sector[3]);
+#endif
+
+ if ((channel != -1) && (channel != sector[1]))
+ return -1;
+
+ if ((sector[2] == 0x48) || (sector[2] == 0x42) || ((sector[2] == 8) && (sector[14] == 8))) {
+#ifdef CHATTING
+ printm(M_BARE, "Video sector\n");
+ printm(M_BARE, "Status : %04x\n", h->StSTATUS);
+ printm(M_BARE, "Type : %04x\n", h->StTYPE);
+ printm(M_BARE, "Sector Offset: %i\n", h->StSECTOR_OFFSET);
+ printm(M_BARE, "Sector Size : %i\n", h->StSECTOR_SIZE);
+ printm(M_BARE, "Frame Number : %i\n", h->StFRAME_NO);
+ printm(M_BARE, "Frame Size : %i\n", h->StFRAME_SIZE);
+ printm(M_BARE, "Movie Width : %i\n", h->StMOVIE_WIDTH);
+ printm(M_BARE, "Movie Height : %i\n", h->StMOVIE_HEIGHT);
+ printm(M_BARE, "Movie HeadM : %08x\n", h->StMOVIE_HEADM);
+ printm(M_BARE, "Movie HeadV : %08x\n", h->StMOVIE_HEADV);
+ printm(M_BARE, "Channels : %04x\n", h->Channels);
+#endif
+ if (h->StSECTOR_OFFSET == 0) {
+ bs_init();
+ video = (Byte *) malloc(h->StSECTOR_SIZE * 2016);
+ if (!screen) {
+ width = h->StMOVIE_WIDTH;
+ height = h->StMOVIE_HEIGHT;
+ screen = SDL_SetVideoMode(width, height, 24, SDL_HWSURFACE | SDL_DOUBLEBUF);
+ if (!screen) {
+ printm(M_ERROR, "Couldn't get framebuffer\n");
+ exit(-1);
+ }
+ bpp = screen->format->BytesPerPixel;
+ }
+ }
+
+ memcpy(video + h->StSECTOR_OFFSET * 2016, sector + 40, 2016);
+
+ if (h->StSECTOR_SIZE == (h->StSECTOR_OFFSET + 1)) {
+ // Frame finished.
+#ifdef CHATTING
+ printm(M_BARE, "End of Frame.\n");
+#endif
+
+ Uint8 * buffer = ((Uint8 *) screen->pixels);
+
+ if (SDL_MUSTLOCK(screen))
+ if (SDL_LockSurface(screen) < 0)
+ exit(1);
+#ifdef CHATTING
+ printm(M_BARE, "Width: %i, Height: %i - bpp: %i\n", width, height, bpp);
+#endif
+ memset(video + h->StFRAME_SIZE, 0, h->StSECTOR_SIZE * 2016 - h->StFRAME_SIZE);
+#ifdef DUMPING
+ String fn;
+ fn.set("frame-%04i.bs", h->StFRAME_NO);
+ Output * tf = new Output(fn);
+ tf->write(video, h->StFRAME_SIZE);
+ delete tf;
+#endif
+ bs_decode_rgb24(buffer, (bs_header_t *) video, width, height, 0);
+
+// fwrite(screen->pixels, 3, width * height, stdout);
+
+ if (SDL_MUSTLOCK(screen))
+ SDL_UnlockSurface(screen);
+ SDL_Flip(screen);
+
+ free(video);
+ }
+ } else if (sector[2] == 0x64) {
+ int locked = 0;
+
+ SoundSector * buffer = (SoundSector *) sector;
+#ifdef CHATTING
+ printm(M_BARE, "Audio sector\n");
+ printm(M_BARE, "Frequency: %i\n", xahalfhz(buffer) ? 18900 : 37800);
+ printm(M_BARE, "Channels : %s\n", xastereo(buffer) ? "stereo" : "mono");
+#endif
+// fwrite(sector + 8, 1, 2324, stdout);
+
+ while (audio_len > 0) {
+ SDL_Delay(1);
+ }
+
+ if (!audio2) {
+ SDL_AudioSpec fmt;
+
+ /* Un son sereo de 16 bits à 44kHz */
+ fmt.freq = xahalfhz(buffer) ? 18900 : 37800;
+ fmt.format = AUDIO_S16;
+ fmt.channels = xastereo(buffer) ? 2 : 1;
+ fmt.samples = 128; /*Une bonne valeur pour les jeux */
+ fmt.callback = mixaudio;
+ fmt.userdata = NULL;
+
+ /* Ouvre le contexte audio et joue le son */
+ if (SDL_OpenAudio(&fmt, NULL) < 0) {
+ fprintf(stderr, "Impossible d'accéder à l'audio: %s\n", SDL_GetError());
+ exit(1);
+ }
+
+ initXaDecode();
+ } else {
+ if (audio) {
+ SDL_LockAudio();
+ free(audio);
+ locked = 1;
+ }
+ audio_pos = audio = audio2;
+ audio_len = audio_len2;
+ }
+
+ audio2 = (Byte *) malloc(8192);
+ switchXaDecode(xachannel(buffer));
+ audio_len2 = convXaToWave((char *) buffer, (char *) audio2, xachannel(buffer), 0, 255);
+ if (locked)
+ SDL_UnlockAudio();
+ else if (audio)
+ SDL_PauseAudio(0);
+ saveXaDecode(xachannel(buffer));
+
+ } else {
+#ifdef CHATTING
+ printm(M_BARE, "Unknow sector\n");
+#endif
+ }
+#ifdef CHATTING
+ printm(M_BARE, "---------------------------------\n\n");
+#endif
+ return 1;
+}
+
+virtual int startup() throw (GeneralException) {
+ Handle * file = 0;
+ int c;
+
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0) {
+ printm(M_ERROR, "Couldn't initialise SDL: %s\n", SDL_GetError());
+ exit(-1);
+ }
+ atexit(SDL_Quit);
+ SDL_ShowCursor(SDL_DISABLE);
+
+ while ((c = getopt(argc, argv, "c:")) != EOF) {
+ switch (c) {
+ case 'c':
+ channel = atoi(optarg);
+ break;
+ default:
+ printm(M_ERROR, "Unknow argument.\n");
+ break;
+ }
+ }
+
+ switch (argc - optind) {
+ case 0:
+ file = &Stdin;
+ break;
+ case 1:
+ file = new Input(argv[optind]);
+ break;
+ default:
+ printm(M_ERROR, "Too much arguments.\n");
+ exit(-1);
+ }
+
+ while (process_one_sector(file));
+
+ if (!audio)
+ SDL_CloseAudio();
+
+ SDL_Quit();
+ return 0;
+}
+CODE_ENDS
diff --git a/str-util.cpp b/str-util.cpp index 223270c..914f2a9 100644 --- a/str-util.cpp +++ b/str-util.cpp @@ -1,215 +1,215 @@ -#include <stdlib.h> -#include <string.h> -#include <SDL/SDL.h> -#include <SDL/SDL_audio.h> -#include "psxdev/bs.h" -#include "fileutils.h" -#include "generic.h" -#include "cdutils.h" -#include "psxdev/xadecode.h" - -/* - - From the SONY documentation: - - 32 bytes header: - -StSTATUS : 2 bytes 0 -StTYPE : 2 bytes 2 -StSECTOR_OFFSET: 2 bytes 4 -StSECTOR_SIZE : 2 bytes 6 -StFRAME_NO : 4 bytes 10 -StFRAME_SIZE : 4 bytes 14 -StMOVIE_WIDTH : 2 bytes 16 -StMOVIE_HEIGHT : 2 bytes 18 -StMOVIE_HEADM : 4 bytes 22 -StMOVIE_HEADV : 4 bytes 26 -Channels : 2 bytes 30 - - */ - -struct STR_Header { - Uint16 StSTATUS; - Uint16 StTYPE; - Uint16 StSECTOR_OFFSET; - Uint16 StSECTOR_SIZE; - Uint32 StFRAME_NO; - Uint32 StFRAME_SIZE; - Uint16 StMOVIE_WIDTH; - Uint16 StMOVIE_HEIGHT; - Uint32 StMOVIE_HEADM; - Uint32 StMOVIE_HEADV; - Uint16 Channels; -} PACKED; - -Byte * video = 0, * audio = 0, * audio2 = 0; - -int width, height; - -SDL_Surface * screen = 0; -Uint8 bpp; - -int32 audio_len = 0, audio_len2 = 0; -Uint8 *audio_pos; - -void mixaudio(void *unused, Uint8 *stream, int len) { - /* Only play if we have data left */ - if ( audio_len == 0 ) - return; - - /* Mix as much data as possible */ - len = ( len > audio_len ? audio_len : len ); - SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME); - audio_pos += len; - audio_len -= len; -} - -void process_one_sector(FILE * f) { - Byte sector[2336]; - STR_Header * h; - - fread(sector, 2336, 1, f); - h = (STR_Header *) ((Byte *) sector + 8); -// printm(M_INFO, "SubHeader: FN = %x, CN = %x, SM = %x, CI = %x: ", sector[0], sector[1], sector[2], sector[3]); -/* - printm(M_BARE, "SubHeader FN : %x\n", sector[0]); - printm(M_BARE, "SubHeader CN : %x\n", sector[1]); - printm(M_BARE, "SubHeader SM : %x\n", sector[2]); - printm(M_BARE, "SubHeader CI : %x\n", sector[3]); -*/ - if ((sector[2] == 0x48) || (sector[2] == 0x42)) { -// printm(M_BARE, "Video sector\n"); -/* printm(M_BARE, "Status : %04x\n", h->StSTATUS); - printm(M_BARE, "Type : %04x\n", h->StTYPE); - printm(M_BARE, "Sector Offset: %i\n", h->StSECTOR_OFFSET); - printm(M_BARE, "Sector Size : %i\n", h->StSECTOR_SIZE); - printm(M_BARE, "Frame Number : %i\n", h->StFRAME_NO); - printm(M_BARE, "Frame Size : %i\n", h->StFRAME_SIZE); - printm(M_BARE, "Movie Width : %i\n", h->StMOVIE_WIDTH); - printm(M_BARE, "Movie Height : %i\n", h->StMOVIE_HEIGHT); - printm(M_BARE, "Movie HeadM : %08x\n", h->StMOVIE_HEADM); - printm(M_BARE, "Movie HeadV : %08x\n", h->StMOVIE_HEADV); - printm(M_BARE, "Channels : %04x\n", h->Channels); */ - if (h->StSECTOR_OFFSET == 0) { - video = (Byte *) malloc(h->StSECTOR_SIZE * 2016); - if (!screen) { - bs_init(); - width = h->StMOVIE_WIDTH; - height = h->StMOVIE_HEIGHT; - screen = SDL_SetVideoMode(width, height, 24, SDL_HWSURFACE | SDL_DOUBLEBUF); - if (!screen) { - printm(M_ERROR, "Couldn't get framebuffer\n"); - exit(-1); - } - bpp = screen->format->BytesPerPixel; - } - } - - memcpy(video + h->StSECTOR_OFFSET * 2016, sector + 40, 2016); - - if (h->StSECTOR_SIZE == (h->StSECTOR_OFFSET + 1)) { - // Frame finished. -// printm(M_BARE, "End of Frame.\n"); - - Uint8 * buffer = ((Uint8 *) screen->pixels); - - if (SDL_MUSTLOCK(screen)) - if (SDL_LockSurface(screen) < 0) - exit(1); -// printm(M_BARE, "Width: %i, Height: %i - bpp: %i\n", width, height, bpp); - bs_decode_rgb24(buffer, (bs_header_t *) video, width, height, 0); - -// fwrite(screen->pixels, 3, width * height, stdout); - - if (SDL_MUSTLOCK(screen)) - SDL_UnlockSurface(screen); - SDL_Flip(screen); - - free(video); - } - } else if (sector[2] == 0x64) { - int locked = 0; - - SoundSector * buffer = (SoundSector *) sector; -// printm(M_BARE, "Audio sector\n"); -/* printm(M_BARE, "Frequency: %i\n", xahalfhz(buffer) ? 18900 : 37800); - printm(M_BARE, "Channels : %s\n", xastereo(buffer) ? "stereo" : "mono"); */ -// fwrite(sector + 8, 1, 2324, stdout); - - while (audio_len > 0) { - SDL_Delay(1); - } - - if (!audio2) { - SDL_AudioSpec fmt; - - /* Un son sereo de 16 bits à 44kHz */ - fmt.freq = xahalfhz(buffer) ? 18900 : 37800; - fmt.format = AUDIO_S16; - fmt.channels = xastereo(buffer) ? 2 : 1; - fmt.samples = 128; /*Une bonne valeur pour les jeux */ - fmt.callback = mixaudio; - fmt.userdata = NULL; - - /* Ouvre le contexte audio et joue le son */ - if (SDL_OpenAudio(&fmt, NULL) < 0) { - fprintf(stderr, "Impossible d'accéder à l'audio: %s\n", SDL_GetError()); - exit(1); - } - - initXaDecode(); - } else { - if (audio) { - SDL_LockAudio(); - free(audio); - locked = 1; - } - audio_pos = audio = audio2; - audio_len = audio_len2; - } - - audio2 = (Byte *) malloc(8192); - switchXaDecode(xachannel(buffer)); - audio_len2 = convXaToWave((char *) buffer, (char *) audio2, xachannel(buffer), 0, 255); - if (locked) - SDL_UnlockAudio(); - else if (audio) - SDL_PauseAudio(0); - saveXaDecode(xachannel(buffer)); - - } else { -// printm(M_BARE, "Unknow sector\n"); - } -// printm(M_BARE, "---------------------------------\n\n"); -} - -int main(int argc, char ** argv) { - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0) { - printm(M_ERROR, "Couldn't initialise SDL: %s\n", SDL_GetError()); - exit(-1); - } - atexit(SDL_Quit); - SDL_ShowCursor(SDL_DISABLE); - - - switch (argc) { - case 1: - break; - case 2: - fclose(stdin); - stdin = fopen(argv[1], "r"); - break; - default: - printm(M_ERROR, "Too much arguments.\n"); - exit(-1); - } - - while (!feof(stdin)) { - process_one_sector(stdin); - } - - if (!audio) - SDL_CloseAudio(); - - SDL_Quit(); -} +#include <stdlib.h>
+#include <string.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_audio.h>
+#include "psxdev/bs.h"
+#include "fileutils.h"
+#include "generic.h"
+#include "cdutils.h"
+#include "psxdev/xadecode.h"
+
+/*
+
+ From the SONY documentation:
+
+ 32 bytes header:
+
+StSTATUS : 2 bytes 0
+StTYPE : 2 bytes 2
+StSECTOR_OFFSET: 2 bytes 4
+StSECTOR_SIZE : 2 bytes 6
+StFRAME_NO : 4 bytes 10
+StFRAME_SIZE : 4 bytes 14
+StMOVIE_WIDTH : 2 bytes 16
+StMOVIE_HEIGHT : 2 bytes 18
+StMOVIE_HEADM : 4 bytes 22
+StMOVIE_HEADV : 4 bytes 26
+Channels : 2 bytes 30
+
+ */
+
+struct STR_Header {
+ Uint16 StSTATUS;
+ Uint16 StTYPE;
+ Uint16 StSECTOR_OFFSET;
+ Uint16 StSECTOR_SIZE;
+ Uint32 StFRAME_NO;
+ Uint32 StFRAME_SIZE;
+ Uint16 StMOVIE_WIDTH;
+ Uint16 StMOVIE_HEIGHT;
+ Uint32 StMOVIE_HEADM;
+ Uint32 StMOVIE_HEADV;
+ Uint16 Channels;
+} PACKED;
+
+Byte * video = 0, * audio = 0, * audio2 = 0;
+
+int width, height;
+
+SDL_Surface * screen = 0;
+Uint8 bpp;
+
+int32 audio_len = 0, audio_len2 = 0;
+Uint8 *audio_pos;
+
+void mixaudio(void *unused, Uint8 *stream, int len) {
+ /* Only play if we have data left */
+ if ( audio_len == 0 )
+ return;
+
+ /* Mix as much data as possible */
+ len = ( len > audio_len ? audio_len : len );
+ SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME);
+ audio_pos += len;
+ audio_len -= len;
+}
+
+void process_one_sector(FILE * f) {
+ Byte sector[2336];
+ STR_Header * h;
+
+ fread(sector, 2336, 1, f);
+ h = (STR_Header *) ((Byte *) sector + 8);
+// printm(M_INFO, "SubHeader: FN = %x, CN = %x, SM = %x, CI = %x: ", sector[0], sector[1], sector[2], sector[3]);
+/*
+ printm(M_BARE, "SubHeader FN : %x\n", sector[0]);
+ printm(M_BARE, "SubHeader CN : %x\n", sector[1]);
+ printm(M_BARE, "SubHeader SM : %x\n", sector[2]);
+ printm(M_BARE, "SubHeader CI : %x\n", sector[3]);
+*/
+ if ((sector[2] == 0x48) || (sector[2] == 0x42)) {
+// printm(M_BARE, "Video sector\n");
+/* printm(M_BARE, "Status : %04x\n", h->StSTATUS);
+ printm(M_BARE, "Type : %04x\n", h->StTYPE);
+ printm(M_BARE, "Sector Offset: %i\n", h->StSECTOR_OFFSET);
+ printm(M_BARE, "Sector Size : %i\n", h->StSECTOR_SIZE);
+ printm(M_BARE, "Frame Number : %i\n", h->StFRAME_NO);
+ printm(M_BARE, "Frame Size : %i\n", h->StFRAME_SIZE);
+ printm(M_BARE, "Movie Width : %i\n", h->StMOVIE_WIDTH);
+ printm(M_BARE, "Movie Height : %i\n", h->StMOVIE_HEIGHT);
+ printm(M_BARE, "Movie HeadM : %08x\n", h->StMOVIE_HEADM);
+ printm(M_BARE, "Movie HeadV : %08x\n", h->StMOVIE_HEADV);
+ printm(M_BARE, "Channels : %04x\n", h->Channels); */
+ if (h->StSECTOR_OFFSET == 0) {
+ video = (Byte *) malloc(h->StSECTOR_SIZE * 2016);
+ if (!screen) {
+ bs_init();
+ width = h->StMOVIE_WIDTH;
+ height = h->StMOVIE_HEIGHT;
+ screen = SDL_SetVideoMode(width, height, 24, SDL_HWSURFACE | SDL_DOUBLEBUF);
+ if (!screen) {
+ printm(M_ERROR, "Couldn't get framebuffer\n");
+ exit(-1);
+ }
+ bpp = screen->format->BytesPerPixel;
+ }
+ }
+
+ memcpy(video + h->StSECTOR_OFFSET * 2016, sector + 40, 2016);
+
+ if (h->StSECTOR_SIZE == (h->StSECTOR_OFFSET + 1)) {
+ // Frame finished.
+// printm(M_BARE, "End of Frame.\n");
+
+ Uint8 * buffer = ((Uint8 *) screen->pixels);
+
+ if (SDL_MUSTLOCK(screen))
+ if (SDL_LockSurface(screen) < 0)
+ exit(1);
+// printm(M_BARE, "Width: %i, Height: %i - bpp: %i\n", width, height, bpp);
+ bs_decode_rgb24(buffer, (bs_header_t *) video, width, height, 0);
+
+// fwrite(screen->pixels, 3, width * height, stdout);
+
+ if (SDL_MUSTLOCK(screen))
+ SDL_UnlockSurface(screen);
+ SDL_Flip(screen);
+
+ free(video);
+ }
+ } else if (sector[2] == 0x64) {
+ int locked = 0;
+
+ SoundSector * buffer = (SoundSector *) sector;
+// printm(M_BARE, "Audio sector\n");
+/* printm(M_BARE, "Frequency: %i\n", xahalfhz(buffer) ? 18900 : 37800);
+ printm(M_BARE, "Channels : %s\n", xastereo(buffer) ? "stereo" : "mono"); */
+// fwrite(sector + 8, 1, 2324, stdout);
+
+ while (audio_len > 0) {
+ SDL_Delay(1);
+ }
+
+ if (!audio2) {
+ SDL_AudioSpec fmt;
+
+ /* Un son sereo de 16 bits à 44kHz */
+ fmt.freq = xahalfhz(buffer) ? 18900 : 37800;
+ fmt.format = AUDIO_S16;
+ fmt.channels = xastereo(buffer) ? 2 : 1;
+ fmt.samples = 128; /*Une bonne valeur pour les jeux */
+ fmt.callback = mixaudio;
+ fmt.userdata = NULL;
+
+ /* Ouvre le contexte audio et joue le son */
+ if (SDL_OpenAudio(&fmt, NULL) < 0) {
+ fprintf(stderr, "Impossible d'accéder à l'audio: %s\n", SDL_GetError());
+ exit(1);
+ }
+
+ initXaDecode();
+ } else {
+ if (audio) {
+ SDL_LockAudio();
+ free(audio);
+ locked = 1;
+ }
+ audio_pos = audio = audio2;
+ audio_len = audio_len2;
+ }
+
+ audio2 = (Byte *) malloc(8192);
+ switchXaDecode(xachannel(buffer));
+ audio_len2 = convXaToWave((char *) buffer, (char *) audio2, xachannel(buffer), 0, 255);
+ if (locked)
+ SDL_UnlockAudio();
+ else if (audio)
+ SDL_PauseAudio(0);
+ saveXaDecode(xachannel(buffer));
+
+ } else {
+// printm(M_BARE, "Unknow sector\n");
+ }
+// printm(M_BARE, "---------------------------------\n\n");
+}
+
+int main(int argc, char ** argv) {
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0) {
+ printm(M_ERROR, "Couldn't initialise SDL: %s\n", SDL_GetError());
+ exit(-1);
+ }
+ atexit(SDL_Quit);
+ SDL_ShowCursor(SDL_DISABLE);
+
+
+ switch (argc) {
+ case 1:
+ break;
+ case 2:
+ fclose(stdin);
+ stdin = fopen(argv[1], "r");
+ break;
+ default:
+ printm(M_ERROR, "Too much arguments.\n");
+ exit(-1);
+ }
+
+ while (!feof(stdin)) {
+ process_one_sector(stdin);
+ }
+
+ if (!audio)
+ SDL_CloseAudio();
+
+ SDL_Quit();
+}
diff --git a/tile-convert.cpp b/tile-convert.cpp index eb9dd71..c88df53 100644 --- a/tile-convert.cpp +++ b/tile-convert.cpp @@ -1,238 +1,238 @@ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <SDL/SDL.h> -#include "generic.h" -#include "Image.h" -#include "Input.h" -#include "Output.h" -#include "Main.h" - -int IMG_SX = 128, IMG_SY = 128, BLOC_SX = 128, BLOC_SY = 128; - -int do_swap = 0; - -Uint8 * pixels; - -CODE_BEGINS - -Color LookUp(char i) { - return Color(i << 4, i << 4, i << 4, 255); -} - -void countdown(int o_x, int o_y, int size, int * counter, int * a_x, int * a_y) { - if (*counter) { - if (size != 1) { - int hs = size >> 1; - countdown(o_x, o_y, hs, counter, a_x, a_y); - if (!*counter) - return; - countdown(o_x, o_y + hs, hs, counter, a_x, a_y); - if (!*counter) - return; - countdown(o_x + hs, o_y, hs, counter, a_x, a_y); - if (!*counter) - return; - countdown(o_x + hs, o_y + hs, hs, counter, a_x, a_y); - } else { - *counter = *counter - 1; - *a_x = o_x; - *a_y = o_y; - } - } -} - -void putpixel(int x, int y, Color C) { - pixels[(y * IMG_SX * 2 + x) * 3 + 0] = C.R; - pixels[(y * IMG_SX * 2 + x) * 3 + 1] = C.G; - pixels[(y * IMG_SX * 2 + x) * 3 + 2] = C.B; -} - -void drawhline(int y, Color C) { - for (int i = 0; i < (IMG_SX << 1); i++) { - putpixel(i, y, C); - } -} - -void drawvline(int x, Color C) { - for (int i = 0; i < (IMG_SY << 1); i++) { - putpixel(x, i, C); - } -} - -int transform(int x, int y) { - - int numero_bloc_x = x / BLOC_SX; - int numero_bloc_y = y / BLOC_SY; - - int numero_bloc = numero_bloc_y * (IMG_SX / BLOC_SX) + numero_bloc_x; - - if (do_swap) { - if ((BLOC_SX == BLOC_SY) || ((BLOC_SX >> 1) == BLOC_SY)) { - countdown(0, 0, IMG_SY / BLOC_SY, &numero_bloc, &numero_bloc_x, &numero_bloc_y); - numero_bloc = numero_bloc_y * (IMG_SX / BLOC_SX) + numero_bloc_x; - } - } - - int bx = x % BLOC_SX; - int by = y % BLOC_SY; - - return numero_bloc * BLOC_SX * BLOC_SY + by * BLOC_SX + bx; - -// return y * IMG_SX + x; - -} - -virtual int startup() throw (GeneralException) { - int c; - - if (SDL_Init(SDL_INIT_VIDEO) < 0) { - printm(M_ERROR, "Couldn't initialise SDL: %s\n", SDL_GetError()); - exit(-1); - } - atexit(SDL_Quit); - SDL_ShowCursor(SDL_DISABLE); - - while ((c = getopt(argc, argv, "x:y:z:t:")) != EOF) { - switch (c) { - case 'x': - IMG_SX = atoi(optarg); - break; - case 'y': - IMG_SY = atoi(optarg); - break; - case 'z': - BLOC_SX = atoi(optarg); - break; - case 't': - BLOC_SY = atoi(optarg); - break; - default: - printm(M_ERROR, "Unknow option: %c\n", c); - throw Exit(-1); - } - } - - if ((argc - optind) != 2) { - printm(M_ERROR, "Need two arguments\n"); - throw Exit(-1); - } - - Input * map = new Input(argv[optind]); - Output * tga = new Output(argv[optind + 1]); - Image * img = new Image(IMG_SX, IMG_SY); - - char * buffer = (char *) malloc(IMG_SX * IMG_SY); - - Byte b; - - for (int i = 0; i < ((IMG_SX * IMG_SY) >> 1); i++) { - int j = i << 1; - map->read(&b, 1); - buffer[j] = b & 0x0f; - buffer[j + 1] = (b & 0xf0) >> 4; - } - - SDL_Surface * screen = 0; - screen = SDL_SetVideoMode(IMG_SX * 2, IMG_SY * 2, 24, SDL_HWSURFACE | SDL_DOUBLEBUF); - if (!screen) { - printm(M_ERROR, "Couldn't get framebuffer\n"); - exit(-1); - } - - pixels = ((Uint8 *) screen->pixels); - SDL_Event event; - - bool exitting = false; - - while (!exitting) { - for (int y = 0; y < IMG_SY; y++) { - for (int x = 0; x < IMG_SX; x++) { - Color c = LookUp(buffer[transform(x, y)]); - pixels[((y * 2 + 0) * IMG_SX * 2 + (x * 2 + 0)) * 3 + 0] = c.R; - pixels[((y * 2 + 0) * IMG_SX * 2 + (x * 2 + 0)) * 3 + 1] = c.G; - pixels[((y * 2 + 0) * IMG_SX * 2 + (x * 2 + 0)) * 3 + 2] = c.B; - - pixels[((y * 2 + 0) * IMG_SX * 2 + (x * 2 + 1)) * 3 + 0] = c.R; - pixels[((y * 2 + 0) * IMG_SX * 2 + (x * 2 + 1)) * 3 + 1] = c.G; - pixels[((y * 2 + 0) * IMG_SX * 2 + (x * 2 + 1)) * 3 + 2] = c.B; - - pixels[((y * 2 + 1) * IMG_SX * 2 + (x * 2 + 0)) * 3 + 0] = c.R; - pixels[((y * 2 + 1) * IMG_SX * 2 + (x * 2 + 0)) * 3 + 1] = c.G; - pixels[((y * 2 + 1) * IMG_SX * 2 + (x * 2 + 0)) * 3 + 2] = c.B; - - pixels[((y * 2 + 1) * IMG_SX * 2 + (x * 2 + 1)) * 3 + 0] = c.R; - pixels[((y * 2 + 1) * IMG_SX * 2 + (x * 2 + 1)) * 3 + 1] = c.G; - pixels[((y * 2 + 1) * IMG_SX * 2 + (x * 2 + 1)) * 3 + 2] = c.B; - - } - } - - for (int x = 0; x < IMG_SX; x += BLOC_SX) { - drawvline(x << 1, Color(255, 255, 0)); - } - - for (int y = 0; y < IMG_SY; y += BLOC_SY) { - drawhline(y << 1, Color(255, 255, 0)); - } - - SDL_Flip(screen); - - SDL_WaitEvent(&event); - - switch (event.type) { - case SDL_KEYDOWN: - switch (event.key.keysym.sym) { - case SDLK_UP: - BLOC_SY >>= 1; - break; - case SDLK_DOWN: - BLOC_SY <<= 1; - break; - case SDLK_LEFT: - BLOC_SX >>= 1; - break; - case SDLK_RIGHT: - BLOC_SX <<= 1; - break; - case SDLK_SPACE: - do_swap ^= 1; - break; - default: - break; - } - if (BLOC_SX == 0) - BLOC_SX = 1; - if (BLOC_SY == 0) - BLOC_SY = 1; - if (BLOC_SX > IMG_SX) - BLOC_SX = IMG_SX; - if (BLOC_SY > IMG_SY) - BLOC_SY = IMG_SY; - printm(M_BARE, "Bloc size = %3ix%3i\n", BLOC_SX, BLOC_SY); - break; - case SDL_QUIT: - exitting = true; - break; - } - } - - img->Fill(); - - for (int y = 0; y < IMG_SX; y++) { - for (int x = 0; x < IMG_SY; x++) { - img->SetPixel(x, y, LookUp(buffer[transform(x, y)])); - } - } - - img->Prepare(FORMAT_TGA_BASIC); - - copy(img, tga); - - SDL_Quit(); - - return 0; -} - -CODE_ENDS +#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <SDL/SDL.h>
+#include "generic.h"
+#include "Image.h"
+#include "Input.h"
+#include "Output.h"
+#include "Main.h"
+
+int IMG_SX = 128, IMG_SY = 128, BLOC_SX = 128, BLOC_SY = 128;
+
+int do_swap = 0;
+
+Uint8 * pixels;
+
+CODE_BEGINS
+
+Color LookUp(char i) {
+ return Color(i << 4, i << 4, i << 4, 255);
+}
+
+void countdown(int o_x, int o_y, int size, int * counter, int * a_x, int * a_y) {
+ if (*counter) {
+ if (size != 1) {
+ int hs = size >> 1;
+ countdown(o_x, o_y, hs, counter, a_x, a_y);
+ if (!*counter)
+ return;
+ countdown(o_x, o_y + hs, hs, counter, a_x, a_y);
+ if (!*counter)
+ return;
+ countdown(o_x + hs, o_y, hs, counter, a_x, a_y);
+ if (!*counter)
+ return;
+ countdown(o_x + hs, o_y + hs, hs, counter, a_x, a_y);
+ } else {
+ *counter = *counter - 1;
+ *a_x = o_x;
+ *a_y = o_y;
+ }
+ }
+}
+
+void putpixel(int x, int y, Color C) {
+ pixels[(y * IMG_SX * 2 + x) * 3 + 0] = C.R;
+ pixels[(y * IMG_SX * 2 + x) * 3 + 1] = C.G;
+ pixels[(y * IMG_SX * 2 + x) * 3 + 2] = C.B;
+}
+
+void drawhline(int y, Color C) {
+ for (int i = 0; i < (IMG_SX << 1); i++) {
+ putpixel(i, y, C);
+ }
+}
+
+void drawvline(int x, Color C) {
+ for (int i = 0; i < (IMG_SY << 1); i++) {
+ putpixel(x, i, C);
+ }
+}
+
+int transform(int x, int y) {
+
+ int numero_bloc_x = x / BLOC_SX;
+ int numero_bloc_y = y / BLOC_SY;
+
+ int numero_bloc = numero_bloc_y * (IMG_SX / BLOC_SX) + numero_bloc_x;
+
+ if (do_swap) {
+ if ((BLOC_SX == BLOC_SY) || ((BLOC_SX >> 1) == BLOC_SY)) {
+ countdown(0, 0, IMG_SY / BLOC_SY, &numero_bloc, &numero_bloc_x, &numero_bloc_y);
+ numero_bloc = numero_bloc_y * (IMG_SX / BLOC_SX) + numero_bloc_x;
+ }
+ }
+
+ int bx = x % BLOC_SX;
+ int by = y % BLOC_SY;
+
+ return numero_bloc * BLOC_SX * BLOC_SY + by * BLOC_SX + bx;
+
+// return y * IMG_SX + x;
+
+}
+
+virtual int startup() throw (GeneralException) {
+ int c;
+
+ if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+ printm(M_ERROR, "Couldn't initialise SDL: %s\n", SDL_GetError());
+ exit(-1);
+ }
+ atexit(SDL_Quit);
+ SDL_ShowCursor(SDL_DISABLE);
+
+ while ((c = getopt(argc, argv, "x:y:z:t:")) != EOF) {
+ switch (c) {
+ case 'x':
+ IMG_SX = atoi(optarg);
+ break;
+ case 'y':
+ IMG_SY = atoi(optarg);
+ break;
+ case 'z':
+ BLOC_SX = atoi(optarg);
+ break;
+ case 't':
+ BLOC_SY = atoi(optarg);
+ break;
+ default:
+ printm(M_ERROR, "Unknow option: %c\n", c);
+ throw Exit(-1);
+ }
+ }
+
+ if ((argc - optind) != 2) {
+ printm(M_ERROR, "Need two arguments\n");
+ throw Exit(-1);
+ }
+
+ Input * map = new Input(argv[optind]);
+ Output * tga = new Output(argv[optind + 1]);
+ Image * img = new Image(IMG_SX, IMG_SY);
+
+ char * buffer = (char *) malloc(IMG_SX * IMG_SY);
+
+ Byte b;
+
+ for (int i = 0; i < ((IMG_SX * IMG_SY) >> 1); i++) {
+ int j = i << 1;
+ map->read(&b, 1);
+ buffer[j] = b & 0x0f;
+ buffer[j + 1] = (b & 0xf0) >> 4;
+ }
+
+ SDL_Surface * screen = 0;
+ screen = SDL_SetVideoMode(IMG_SX * 2, IMG_SY * 2, 24, SDL_HWSURFACE | SDL_DOUBLEBUF);
+ if (!screen) {
+ printm(M_ERROR, "Couldn't get framebuffer\n");
+ exit(-1);
+ }
+
+ pixels = ((Uint8 *) screen->pixels);
+ SDL_Event event;
+
+ bool exitting = false;
+
+ while (!exitting) {
+ for (int y = 0; y < IMG_SY; y++) {
+ for (int x = 0; x < IMG_SX; x++) {
+ Color c = LookUp(buffer[transform(x, y)]);
+ pixels[((y * 2 + 0) * IMG_SX * 2 + (x * 2 + 0)) * 3 + 0] = c.R;
+ pixels[((y * 2 + 0) * IMG_SX * 2 + (x * 2 + 0)) * 3 + 1] = c.G;
+ pixels[((y * 2 + 0) * IMG_SX * 2 + (x * 2 + 0)) * 3 + 2] = c.B;
+
+ pixels[((y * 2 + 0) * IMG_SX * 2 + (x * 2 + 1)) * 3 + 0] = c.R;
+ pixels[((y * 2 + 0) * IMG_SX * 2 + (x * 2 + 1)) * 3 + 1] = c.G;
+ pixels[((y * 2 + 0) * IMG_SX * 2 + (x * 2 + 1)) * 3 + 2] = c.B;
+
+ pixels[((y * 2 + 1) * IMG_SX * 2 + (x * 2 + 0)) * 3 + 0] = c.R;
+ pixels[((y * 2 + 1) * IMG_SX * 2 + (x * 2 + 0)) * 3 + 1] = c.G;
+ pixels[((y * 2 + 1) * IMG_SX * 2 + (x * 2 + 0)) * 3 + 2] = c.B;
+
+ pixels[((y * 2 + 1) * IMG_SX * 2 + (x * 2 + 1)) * 3 + 0] = c.R;
+ pixels[((y * 2 + 1) * IMG_SX * 2 + (x * 2 + 1)) * 3 + 1] = c.G;
+ pixels[((y * 2 + 1) * IMG_SX * 2 + (x * 2 + 1)) * 3 + 2] = c.B;
+
+ }
+ }
+
+ for (int x = 0; x < IMG_SX; x += BLOC_SX) {
+ drawvline(x << 1, Color(255, 255, 0));
+ }
+
+ for (int y = 0; y < IMG_SY; y += BLOC_SY) {
+ drawhline(y << 1, Color(255, 255, 0));
+ }
+
+ SDL_Flip(screen);
+
+ SDL_WaitEvent(&event);
+
+ switch (event.type) {
+ case SDL_KEYDOWN:
+ switch (event.key.keysym.sym) {
+ case SDLK_UP:
+ BLOC_SY >>= 1;
+ break;
+ case SDLK_DOWN:
+ BLOC_SY <<= 1;
+ break;
+ case SDLK_LEFT:
+ BLOC_SX >>= 1;
+ break;
+ case SDLK_RIGHT:
+ BLOC_SX <<= 1;
+ break;
+ case SDLK_SPACE:
+ do_swap ^= 1;
+ break;
+ default:
+ break;
+ }
+ if (BLOC_SX == 0)
+ BLOC_SX = 1;
+ if (BLOC_SY == 0)
+ BLOC_SY = 1;
+ if (BLOC_SX > IMG_SX)
+ BLOC_SX = IMG_SX;
+ if (BLOC_SY > IMG_SY)
+ BLOC_SY = IMG_SY;
+ printm(M_BARE, "Bloc size = %3ix%3i\n", BLOC_SX, BLOC_SY);
+ break;
+ case SDL_QUIT:
+ exitting = true;
+ break;
+ }
+ }
+
+ img->Fill();
+
+ for (int y = 0; y < IMG_SX; y++) {
+ for (int x = 0; x < IMG_SY; x++) {
+ img->SetPixel(x, y, LookUp(buffer[transform(x, y)]));
+ }
+ }
+
+ img->Prepare(FORMAT_TGA_BASIC);
+
+ copy(img, tga);
+
+ SDL_Quit();
+
+ return 0;
+}
+
+CODE_ENDS
diff --git a/yazedc-main.cpp b/yazedc-main.cpp index 533567c..0c5a836 100644 --- a/yazedc-main.cpp +++ b/yazedc-main.cpp @@ -1,314 +1,314 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 1998 Heiko Eissfeldt - * portions used& Chris Smith - * Modified by Yazoo, then by - * Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <stdio.h> -#include <string.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -static int do_decode_L2(unsigned char in[(L2_RAW+L2_Q+L2_P)], - unsigned char out[L2_RAW]) -{ - return 0; -} -#endif - - -#define MAX_SUB_DEL 8 -static unsigned char sub_delay_line[MAX_SUB_DEL][LSUB_RAW+LSUB_Q+LSUB_P]; -static unsigned sub_del_index; - -/* R-W Subchannel en/decoder */ -int do_encode_sub(unsigned char in[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME], - unsigned char out[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME], - int delay1, int permute) -{ - int i; - - if (in == out) return -1; - - for (i = 0; i < PACKETS_PER_SUBCHANNELFRAME; i++) { - int j; - unsigned char t; - - memcpy(out, in, (LSUB_RAW)); - - /* build Q parity */ - encode_LSUB_Q(out); - - /* build P parity */ - encode_LSUB_P(out); - - if (permute) { - /* permute */ - t = out[1]; out[1] = out[18]; out[18] = t; - t = out[2]; out[2] = out[ 5]; out[ 5] = t; - t = out[3]; out[3] = out[23]; out[23] = t; - } - - if (delay1) { - /* shift through delay_line */ - for (j = 0; j < LSUB_RAW+LSUB_Q+LSUB_P; j++) { - if ((j % MAX_SUB_DEL) != 0) { - t = sub_delay_line[(sub_del_index) % MAX_SUB_DEL][j]; - sub_delay_line[(sub_del_index + j) % MAX_SUB_DEL][j] = out[j]; - out[j] = t; - } - } - } - sub_del_index++; - out += LSUB_RAW+LSUB_Q+LSUB_P; - in += LSUB_RAW; - } - return 0; -} - -int -do_decode_sub( - unsigned char in[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME], - unsigned char out[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME], - int delay1, int permute) -{ - int i; - - if (in == out) return -1; - - for (i = 0; i < PACKETS_PER_SUBCHANNELFRAME; i++) { - int j; - unsigned char t; - - if (delay1) { - /* shift through delay_line */ - for (j = 0; j < LSUB_RAW+LSUB_Q+LSUB_P; j++) { - if ((j % MAX_SUB_DEL) != MAX_SUB_DEL-1) { - t = sub_delay_line[(sub_del_index) % MAX_SUB_DEL][j]; - sub_delay_line[(sub_del_index + (MAX_SUB_DEL - j)) % MAX_SUB_DEL][j] = in[j]; - in[j] = t; - } - } - } - - if (permute) { - /* permute */ - t = in[1]; in[1] = in[18]; in[18] = t; - t = in[2]; in[2] = in[ 5]; in[ 5] = t; - t = in[3]; in[3] = in[23]; in[23] = t; - } - - /* build P parity */ - decode_LSUB_P(in); - - /* build Q parity */ - decode_LSUB_Q(in); - - memcpy(out, in, LSUB_QRAW); - memcpy(out+LSUB_QRAW, in+LSUB_QRAW+LSUB_Q, LSUB_RAW-LSUB_QRAW); - - sub_del_index++; - in += LSUB_RAW+LSUB_Q+LSUB_P; - out += LSUB_RAW; - } - return 0; -} - -static int sectortype = MODE_0; -int get_sector_type(void) -{ - return sectortype; -} - -int set_sector_type(int st) -{ - switch(st) { - case MODE_0: - case MODE_1: - case MODE_2: - case MODE_2_FORM_1: - case MODE_2_FORM_2: - sectortype = st; - default: - return -1; - } - return 0; -} - -/* ------------- --------------*/ -#ifdef MAIN - -#define DO_L1 1 -#define DO_L2 2 -#define DO_SUB 4 - -static const unsigned sect_size[8][2] = { -/* nothing */ -{0,0}, -/* Layer 1 decode/encode */ -{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR, L1_RAW*FRAMES_PER_SECTOR}, -/* Layer 2 decode/encode */ -{ 16+L2_RAW+12+L2_Q+L2_P, L2_RAW}, -/* Layer 1 and 2 decode/encode */ -{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR, L1_RAW*FRAMES_PER_SECTOR}, -/* Subchannel decode/encode */ -{ (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME, - LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME}, -/* Layer 1 and subchannel decode/encode */ -{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR + - (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME, - LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME + - L1_RAW*FRAMES_PER_SECTOR}, -/* Layer 2 and subchannel decode/encode */ -{ L2_RAW+L2_Q+L2_P+ - (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME, - LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME + - L2_RAW}, -/* Layer 1, 2 and subchannel decode/encode */ -{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR + - (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME, - LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME + - L1_RAW*FRAMES_PER_SECTOR}, -}; - -int main(int argc, char **argv) -{ - int encode = 1; - int mask = DO_L2; - FILE * infp; - FILE * outfp; - unsigned address = 0; - unsigned char *l1_inbuf; - unsigned char *l1_outbuf; - unsigned char *l2_inbuf; - unsigned char *l2_outbuf; - unsigned char *sub_inbuf; - unsigned char *sub_outbuf; - unsigned char *last_outbuf; - unsigned char inbuf[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME + - (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR]; - unsigned char outbuf[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME + - (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR]; - unsigned load_offset; - - l1_inbuf = l2_inbuf = sub_inbuf = inbuf; - l1_outbuf = l2_outbuf = sub_outbuf = last_outbuf = outbuf; - - infp = fopen("sectors_in", "rb"); - outfp = fopen("sectors_out", "wb"); - - sectortype= MODE_2_FORM_1; - address = 0 + 75*2; - - switch (sectortype) { - case MODE_1: - case MODE_2: - load_offset = 16; - break; - case MODE_2_FORM_1: - case MODE_2_FORM_2: - load_offset = 24; - break; - default: - load_offset = 0; - } - while(1) { - - if (1 != fread(inbuf+load_offset, - sect_size[mask][encode], 1, infp)) { perror(""); break; } - if (encode == 1) { - if (mask & DO_L2) { - switch (sectortype) { - case MODE_0: - break; - case MODE_1: - break; - case MODE_2: - if (1 != - fread(inbuf+load_offset+ - sect_size[mask][encode], - 2336 - sect_size[mask][encode], - 1, infp)) { perror(""); break; } - break; - case MODE_2_FORM_1: - break; - case MODE_2_FORM_2: - if (1 != - fread(inbuf+load_offset+ - sect_size[mask][encode], - 2324 - sect_size[mask][encode], - 1, infp)) { perror(""); break; } - break; - default: - if (1 != - fread(inbuf+load_offset+ - sect_size[mask][encode], - 2448 - sect_size[mask][encode], - 1, infp)) { perror(""); break; } - memset(inbuf,0,16); - /*memset(inbuf+16+2048,0,12+272);*/ - break; - } - do_encode_L2(l2_inbuf, MODE_1, address); - if (0) scramble_L2(l2_inbuf); - last_outbuf = l1_inbuf = l2_inbuf; - l1_outbuf = l2_inbuf; - sub_inbuf = l2_inbuf + L2_RAW; - sub_outbuf = l2_outbuf + 12 + 4+ L2_RAW+4+ 8+ L2_Q+L2_P; - } - if (mask & DO_L1) { - do_encode_L1(l1_inbuf, l1_outbuf,1,1,1,1); - last_outbuf = l1_outbuf; - sub_inbuf = l1_inbuf + L1_RAW*FRAMES_PER_SECTOR; - sub_outbuf = l1_outbuf + (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR; - } - if (mask & DO_SUB) { - do_encode_sub(sub_inbuf, sub_outbuf, 0, 0); - } - } else { - if (mask & DO_L1) { - do_decode_L1(l1_inbuf, l1_outbuf,1,1,1,1); - last_outbuf = l2_inbuf = l1_outbuf; - l2_outbuf = l1_inbuf; - sub_inbuf = l1_inbuf + (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR; - sub_outbuf = l1_outbuf + L1_RAW*FRAMES_PER_SECTOR; - } - if (mask & DO_L2) { - do_decode_L2(l2_inbuf, l2_outbuf); - last_outbuf = l2_outbuf; - sub_inbuf = l2_inbuf + L2_RAW+L2_Q+L2_P; - sub_outbuf = l2_outbuf + L2_RAW; - } - if (mask & DO_SUB) { - do_decode_sub(sub_inbuf, sub_outbuf, 1, 1); - } - } - if (1 != fwrite(last_outbuf, sect_size[mask][1 - encode], 1, outfp)) { - perror(""); - break; - } - address++; - } -#if 0 - /* flush the data from the delay lines with zeroed sectors, if necessary */ -#endif - return 0; -} +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 1998 Heiko Eissfeldt
+ * portions used& Chris Smith
+ * Modified by Yazoo, then by
+ * Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int do_decode_L2(unsigned char in[(L2_RAW+L2_Q+L2_P)],
+ unsigned char out[L2_RAW])
+{
+ return 0;
+}
+#endif
+
+
+#define MAX_SUB_DEL 8
+static unsigned char sub_delay_line[MAX_SUB_DEL][LSUB_RAW+LSUB_Q+LSUB_P];
+static unsigned sub_del_index;
+
+/* R-W Subchannel en/decoder */
+int do_encode_sub(unsigned char in[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
+ unsigned char out[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
+ int delay1, int permute)
+{
+ int i;
+
+ if (in == out) return -1;
+
+ for (i = 0; i < PACKETS_PER_SUBCHANNELFRAME; i++) {
+ int j;
+ unsigned char t;
+
+ memcpy(out, in, (LSUB_RAW));
+
+ /* build Q parity */
+ encode_LSUB_Q(out);
+
+ /* build P parity */
+ encode_LSUB_P(out);
+
+ if (permute) {
+ /* permute */
+ t = out[1]; out[1] = out[18]; out[18] = t;
+ t = out[2]; out[2] = out[ 5]; out[ 5] = t;
+ t = out[3]; out[3] = out[23]; out[23] = t;
+ }
+
+ if (delay1) {
+ /* shift through delay_line */
+ for (j = 0; j < LSUB_RAW+LSUB_Q+LSUB_P; j++) {
+ if ((j % MAX_SUB_DEL) != 0) {
+ t = sub_delay_line[(sub_del_index) % MAX_SUB_DEL][j];
+ sub_delay_line[(sub_del_index + j) % MAX_SUB_DEL][j] = out[j];
+ out[j] = t;
+ }
+ }
+ }
+ sub_del_index++;
+ out += LSUB_RAW+LSUB_Q+LSUB_P;
+ in += LSUB_RAW;
+ }
+ return 0;
+}
+
+int
+do_decode_sub(
+ unsigned char in[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME],
+ unsigned char out[LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME],
+ int delay1, int permute)
+{
+ int i;
+
+ if (in == out) return -1;
+
+ for (i = 0; i < PACKETS_PER_SUBCHANNELFRAME; i++) {
+ int j;
+ unsigned char t;
+
+ if (delay1) {
+ /* shift through delay_line */
+ for (j = 0; j < LSUB_RAW+LSUB_Q+LSUB_P; j++) {
+ if ((j % MAX_SUB_DEL) != MAX_SUB_DEL-1) {
+ t = sub_delay_line[(sub_del_index) % MAX_SUB_DEL][j];
+ sub_delay_line[(sub_del_index + (MAX_SUB_DEL - j)) % MAX_SUB_DEL][j] = in[j];
+ in[j] = t;
+ }
+ }
+ }
+
+ if (permute) {
+ /* permute */
+ t = in[1]; in[1] = in[18]; in[18] = t;
+ t = in[2]; in[2] = in[ 5]; in[ 5] = t;
+ t = in[3]; in[3] = in[23]; in[23] = t;
+ }
+
+ /* build P parity */
+ decode_LSUB_P(in);
+
+ /* build Q parity */
+ decode_LSUB_Q(in);
+
+ memcpy(out, in, LSUB_QRAW);
+ memcpy(out+LSUB_QRAW, in+LSUB_QRAW+LSUB_Q, LSUB_RAW-LSUB_QRAW);
+
+ sub_del_index++;
+ in += LSUB_RAW+LSUB_Q+LSUB_P;
+ out += LSUB_RAW;
+ }
+ return 0;
+}
+
+static int sectortype = MODE_0;
+int get_sector_type(void)
+{
+ return sectortype;
+}
+
+int set_sector_type(int st)
+{
+ switch(st) {
+ case MODE_0:
+ case MODE_1:
+ case MODE_2:
+ case MODE_2_FORM_1:
+ case MODE_2_FORM_2:
+ sectortype = st;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+/* ------------- --------------*/
+#ifdef MAIN
+
+#define DO_L1 1
+#define DO_L2 2
+#define DO_SUB 4
+
+static const unsigned sect_size[8][2] = {
+/* nothing */
+{0,0},
+/* Layer 1 decode/encode */
+{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR, L1_RAW*FRAMES_PER_SECTOR},
+/* Layer 2 decode/encode */
+{ 16+L2_RAW+12+L2_Q+L2_P, L2_RAW},
+/* Layer 1 and 2 decode/encode */
+{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR, L1_RAW*FRAMES_PER_SECTOR},
+/* Subchannel decode/encode */
+{ (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
+ LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME},
+/* Layer 1 and subchannel decode/encode */
+{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR +
+ (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
+ LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME +
+ L1_RAW*FRAMES_PER_SECTOR},
+/* Layer 2 and subchannel decode/encode */
+{ L2_RAW+L2_Q+L2_P+
+ (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
+ LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME +
+ L2_RAW},
+/* Layer 1, 2 and subchannel decode/encode */
+{ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR +
+ (LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME,
+ LSUB_RAW*PACKETS_PER_SUBCHANNELFRAME +
+ L1_RAW*FRAMES_PER_SECTOR},
+};
+
+int main(int argc, char **argv)
+{
+ int encode = 1;
+ int mask = DO_L2;
+ FILE * infp;
+ FILE * outfp;
+ unsigned address = 0;
+ unsigned char *l1_inbuf;
+ unsigned char *l1_outbuf;
+ unsigned char *l2_inbuf;
+ unsigned char *l2_outbuf;
+ unsigned char *sub_inbuf;
+ unsigned char *sub_outbuf;
+ unsigned char *last_outbuf;
+ unsigned char inbuf[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME +
+ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR];
+ unsigned char outbuf[(LSUB_RAW+LSUB_Q+LSUB_P)*PACKETS_PER_SUBCHANNELFRAME +
+ (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR];
+ unsigned load_offset;
+
+ l1_inbuf = l2_inbuf = sub_inbuf = inbuf;
+ l1_outbuf = l2_outbuf = sub_outbuf = last_outbuf = outbuf;
+
+ infp = fopen("sectors_in", "rb");
+ outfp = fopen("sectors_out", "wb");
+
+ sectortype= MODE_2_FORM_1;
+ address = 0 + 75*2;
+
+ switch (sectortype) {
+ case MODE_1:
+ case MODE_2:
+ load_offset = 16;
+ break;
+ case MODE_2_FORM_1:
+ case MODE_2_FORM_2:
+ load_offset = 24;
+ break;
+ default:
+ load_offset = 0;
+ }
+ while(1) {
+
+ if (1 != fread(inbuf+load_offset,
+ sect_size[mask][encode], 1, infp)) { perror(""); break; }
+ if (encode == 1) {
+ if (mask & DO_L2) {
+ switch (sectortype) {
+ case MODE_0:
+ break;
+ case MODE_1:
+ break;
+ case MODE_2:
+ if (1 !=
+ fread(inbuf+load_offset+
+ sect_size[mask][encode],
+ 2336 - sect_size[mask][encode],
+ 1, infp)) { perror(""); break; }
+ break;
+ case MODE_2_FORM_1:
+ break;
+ case MODE_2_FORM_2:
+ if (1 !=
+ fread(inbuf+load_offset+
+ sect_size[mask][encode],
+ 2324 - sect_size[mask][encode],
+ 1, infp)) { perror(""); break; }
+ break;
+ default:
+ if (1 !=
+ fread(inbuf+load_offset+
+ sect_size[mask][encode],
+ 2448 - sect_size[mask][encode],
+ 1, infp)) { perror(""); break; }
+ memset(inbuf,0,16);
+ /*memset(inbuf+16+2048,0,12+272);*/
+ break;
+ }
+ do_encode_L2(l2_inbuf, MODE_1, address);
+ if (0) scramble_L2(l2_inbuf);
+ last_outbuf = l1_inbuf = l2_inbuf;
+ l1_outbuf = l2_inbuf;
+ sub_inbuf = l2_inbuf + L2_RAW;
+ sub_outbuf = l2_outbuf + 12 + 4+ L2_RAW+4+ 8+ L2_Q+L2_P;
+ }
+ if (mask & DO_L1) {
+ do_encode_L1(l1_inbuf, l1_outbuf,1,1,1,1);
+ last_outbuf = l1_outbuf;
+ sub_inbuf = l1_inbuf + L1_RAW*FRAMES_PER_SECTOR;
+ sub_outbuf = l1_outbuf + (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR;
+ }
+ if (mask & DO_SUB) {
+ do_encode_sub(sub_inbuf, sub_outbuf, 0, 0);
+ }
+ } else {
+ if (mask & DO_L1) {
+ do_decode_L1(l1_inbuf, l1_outbuf,1,1,1,1);
+ last_outbuf = l2_inbuf = l1_outbuf;
+ l2_outbuf = l1_inbuf;
+ sub_inbuf = l1_inbuf + (L1_RAW+L1_Q+L1_P)*FRAMES_PER_SECTOR;
+ sub_outbuf = l1_outbuf + L1_RAW*FRAMES_PER_SECTOR;
+ }
+ if (mask & DO_L2) {
+ do_decode_L2(l2_inbuf, l2_outbuf);
+ last_outbuf = l2_outbuf;
+ sub_inbuf = l2_inbuf + L2_RAW+L2_Q+L2_P;
+ sub_outbuf = l2_outbuf + L2_RAW;
+ }
+ if (mask & DO_SUB) {
+ do_decode_sub(sub_inbuf, sub_outbuf, 1, 1);
+ }
+ }
+ if (1 != fwrite(last_outbuf, sect_size[mask][1 - encode], 1, outfp)) {
+ perror("");
+ break;
+ }
+ address++;
+ }
+#if 0
+ /* flush the data from the delay lines with zeroed sectors, if necessary */
+#endif
+ return 0;
+}
|