From d38e80ee04afe582e70150d3884e56c05f3fd7a8 Mon Sep 17 00:00:00 2001 From: pixel Date: Sat, 27 Nov 2004 21:44:44 +0000 Subject: Large dos2unix commit... --- Dalos/Console.cc | 618 ++--- Dalos/Console.h | 126 +- Dalos/Dalos.cc | 2 +- MegamanX5/unarc.cpp | 80 +- PE/afxres.h | 1616 +++++------ PE/extract-rooms.cpp | 284 +- PE/extract-various.cpp | 330 +-- PE/extract.cpp | 166 +- PE/pepatch-res.h | 58 +- PE/pepatch.cpp | 102 +- PE/rebuildmenus.cpp | 152 +- PE/reinsert-res.h | 40 +- PE/reinsert.cpp | 488 ++-- PE/table.h | 134 +- PcsxSrc/CdRom.c | 2098 +++++++------- PcsxSrc/CdRom.h | 176 +- PcsxSrc/Coff.h | 74 +- PcsxSrc/Debug.h | 106 +- PcsxSrc/Decode_XA.c | 610 ++-- PcsxSrc/Decode_XA.h | 52 +- PcsxSrc/DisR3000A.c | 636 ++--- PcsxSrc/Gte.c | 5692 +++++++++++++++++++------------------- PcsxSrc/Gte.h | 104 +- PcsxSrc/Linux/Config.c | 254 +- PcsxSrc/Linux/GladeCalls.c | 1022 +++---- PcsxSrc/Linux/GladeCalls.h | 502 ++-- PcsxSrc/Linux/GladeFuncs.c | 324 +-- PcsxSrc/Linux/GladeFuncs.h | 76 +- PcsxSrc/Linux/GladeGui.c | 3288 +++++++++++----------- PcsxSrc/Linux/GladeGui.h | 20 +- PcsxSrc/Linux/GtkGui.c | 2652 +++++++++--------- PcsxSrc/Linux/Linux.h | 78 +- PcsxSrc/Linux/LnxMain.c | 392 +-- PcsxSrc/Linux/Plugin.c | 416 +-- PcsxSrc/Linux/Plugin.h | 76 +- PcsxSrc/Mdec.c | 1174 ++++---- PcsxSrc/Mdec.h | 62 +- PcsxSrc/Misc.c | 900 +++--- PcsxSrc/Misc.h | 62 +- PcsxSrc/PSEmu_Plugin_Defs.h | 494 ++-- PcsxSrc/PsxBios.c | 4326 ++++++++++++++--------------- PcsxSrc/PsxBios.h | 70 +- PcsxSrc/PsxCommon.h | 264 +- PcsxSrc/PsxCounters.c | 404 +-- PcsxSrc/PsxCounters.h | 82 +- PcsxSrc/PsxDma.c | 192 +- PcsxSrc/PsxDma.h | 54 +- PcsxSrc/PsxHLE.c | 182 +- PcsxSrc/PsxHLE.h | 48 +- PcsxSrc/PsxHw.c | 1512 +++++----- PcsxSrc/PsxHw.h | 62 +- PcsxSrc/PsxInterpreter.c | 942 +++---- PcsxSrc/PsxMem.c | 500 ++-- PcsxSrc/PsxMem.h | 150 +- PcsxSrc/R3000A.c | 330 +-- PcsxSrc/R3000A.h | 372 +-- PcsxSrc/Sio.c | 1176 ++++---- PcsxSrc/Sio.h | 152 +- PcsxSrc/Spu.c | 46 +- PcsxSrc/Spu.h | 72 +- PcsxSrc/System.h | 68 +- PcsxSrc/Win32/AboutDlg.c | 88 +- PcsxSrc/Win32/AboutDlg.h | 46 +- PcsxSrc/Win32/ConfigurePlugins.c | 942 +++---- PcsxSrc/Win32/Win32.h | 94 +- PcsxSrc/Win32/WndMain.c | 2086 +++++++------- PcsxSrc/Win32/plugin.c | 402 +-- PcsxSrc/Win32/plugin.h | 56 +- PcsxSrc/Win32/resource.h | 532 ++-- PcsxSrc/ix86/iR3000A.c | 2472 ++++++++--------- PcsxSrc/ix86/ix86.c | 1932 ++++++------- PcsxSrc/ix86/ix86.h | 794 +++--- PcsxSrc/plugins.c | 1356 ++++----- PcsxSrc/plugins.h | 538 ++-- ToD/ExtracteurIdiot.cpp | 190 +- ToD/c_dumper.cpp | 280 +- ToF/main_dump.cpp | 550 ++-- VP/decomp-slz.cpp | 126 +- VP/main_dump.cpp | 568 ++-- VP/search-script.cpp | 146 +- VP/unarc.cpp | 158 +- Xenogears/Decrypt.cpp | 1026 +++---- Xenogears/Translate.cpp | 512 ++-- Xenogears/archive.cpp | 74 +- Xenogears/build-sector-2.cpp | 28 +- Xenogears/build-sector.cpp | 28 +- Xenogears/main_dump.cpp | 566 ++-- Xenogears/reinsert.cpp | 580 ++-- Xenogears/script-comp.cpp | 218 +- Xenogears/script-dec.cpp | 164 +- Xenogears/test-dlzss.cpp | 14 +- Xenogears/test-lzss.cpp | 14 +- bgrep.cpp | 66 +- bin2c.cpp | 80 +- cd-tool.cpp | 1370 ++++----- compile/Makefile | 7 + compile/linux/Makefile | 2 +- compile/win32/Makefile | 30 +- crypto-search.cpp | 212 +- dtemain.cpp | 138 +- gltest.cpp | 162 +- includes/cdabstract.h | 130 +- includes/cdreader.h | 132 +- includes/cdutils.h | 278 +- includes/dte.h | 38 +- includes/gettext.h | 116 +- includes/isobuilder.h | 210 +- includes/luacd.h | 184 +- includes/luapsx.h | 68 +- includes/lzss.h | 162 +- includes/mips.h | 36 +- includes/mipsdis.h | 108 +- includes/mipsdump.h | 146 +- includes/mipsmem.h | 228 +- includes/mipsobj.h | 148 +- includes/yazedc.h | 220 +- info-cd.cpp | 80 +- lib/cdabstract.cpp | 384 +-- lib/cdreader.cpp | 668 ++--- lib/cdutils.cpp | 1904 ++++++------- lib/dteutils.cpp | 638 ++--- lib/isobuilder.cpp | 1752 ++++++------ lib/luacd.cpp | 3318 +++++++++++----------- lib/luapsx.cpp | 614 ++-- lib/lzss.cpp | 928 +++---- lib/mips.cpp | 2136 +++++++------- lib/mipsdis.cpp | 360 +-- lib/mipsdump.cpp | 414 +-- lib/mipsmem.cpp | 698 ++--- lib/mipsobj.cpp | 538 ++-- lib/yazedc.cpp | 546 ++-- luapatch-res.h | 68 +- luapatch.cpp | 1198 ++++---- lzss-main.cpp | 806 +++--- mipspoke.cpp | 60 +- psxdev/bs.c | 698 ++--- psxdev/bs.h | 188 +- psxdev/common.h | 98 +- psxdev/idctfst.c | 574 ++-- psxdev/jfdctint.c | 582 ++-- psxdev/table.h | 204 +- psxdev/vlc.c | 1212 ++++---- psxdev/xadecode.c | 604 ++-- psxdev/xadecode.h | 184 +- str-player.cpp | 524 ++-- str-util.cpp | 430 +-- tile-convert.cpp | 476 ++-- yazedc-main.cpp | 628 ++--- 148 files changed, 40466 insertions(+), 40437 deletions(-) diff --git a/Dalos/Console.cc b/Dalos/Console.cc index 9078ef9..1cc2b08 100644 --- a/Dalos/Console.cc +++ b/Dalos/Console.cc @@ -1,309 +1,309 @@ -/* - * 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: Console.cc,v 1.1 2004-10-19 01:27:27 pixel Exp $ */ - -#include -#include - -#include -#include -#include - -#include -#include - -#include - -#include - -SDL_mutex * console_lock; -SDL_sem * console_sem; -Buffer console_buffer; - -SDL_mutex * key_vect_mutex; -SDL_sem * key_vect_size; -std::vector key_vect; - -String console_prompt = "> "; - -class ReadLineInternals : public Base { - public: - static int readline_thread(void * d) { - char * line_read; - String line, endline; - bool runit; - int pos; - - rl_getc_function = ReadLineInternals::rl_getc_func; - rl_redisplay_function = ReadLineInternals::rl_redisplay_func; - rl_prep_term_function = ReadLineInternals::rl_prep_term_func; - rl_deprep_term_function = ReadLineInternals::rl_deprep_term_func; - rl_bind_key('\t', rl_insert); - - while (true) { - line_read = readline(""); - if (!line_read) - continue; - if (*line_read) - add_history(line_read); - CurrentConsole->add_line(console_prompt + line_read); - - line = line_read; - line = line.trim(); - endline = ""; - - /* Splitting the line between ;; */ - while (line.strlen()) { - runit = false; - - if ((pos = line.strstr(";;")) >= 0) { - endline = line.extract(pos + 2); - line = line.extract(0, pos); - runit = true; - } else { - endline = ""; - } - - if (line[line.strlen() - 1] == '\\') { - line[line.strlen() - 1] = ' '; - } else if (auto_exec) { - runit = true; - } - - SDL_mutexP(console_lock); - console_buffer << line; - SDL_mutexV(console_lock); - - if (runit) { - SDL_SemPost(console_sem); - prompt = "> "; - } else { - prompt = "- "; - } - line = endline.trim(); - } - - free(line_read); - } - - return 0; - } - private: - static int rl_getc_func(FILE * d) { - int k; - SDL_SemWait(key_vect_size); - SDL_mutexP(key_vect_mutex); - k = key_vect[0]; - key_vect.erase(key_vect.begin()); - SDL_mutexV(key_vect_mutex); - return k; - } - - static void rl_redisplay_func(void) { - CurrentConsole->page_reset(); - } - - static void rl_prep_term_func(int b) { - } - - static void rl_deprep_term_func(void) { - } -}; - -virtual void console_keyevent::down(SDL_keysym k) { - if (Application->Console->GetVisible()) { - SDL_mutexP(key_vect_mutex); - switch (k.sym) { - case SDLK_ESCAPE: - Application->Console->SetVisible(false); - SDL_mutexV(key_vect_mutex); - return; - case SDLK_DELETE: - key_vect.push_back('D' - '@'); - break; - case SDLK_LEFT: - key_vect.push_back('B' - '@'); - break; - case SDLK_RIGHT: - key_vect.push_back('F' - '@'); - break; - case SDLK_UP: - key_vect.push_back('P' - '@'); - break; - case SDLK_DOWN: - key_vect.push_back('N' - '@'); - break; - case SDLK_HOME: - key_vect.push_back('A' - '@'); - break; - case SDLK_END: - key_vect.push_back('E' - '@'); - break; - case SDLK_PAGEUP: - Application->Console->page_up(); - SDL_mutexV(key_vect_mutex); - return; - case SDLK_PAGEDOWN: - Application->Console->page_down(); - SDL_mutexV(key_vect_mutex); - return; - case SDLK_c: - if (k.mod & KMOD_CTRL) { - if (lua_started) - do_lua_break = true; - SDL_mutexV(key_vect_mutex); - return; - } - default: - if (k.unicode) { - switch (k.unicode) { - case 0xb4: - key_vect.push_back('\''); - break; - case 0xa8: - key_vect.push_back('"'); - break; - default: - key_vect.push_back(k.unicode); - } - } else { - SDL_mutexV(key_vect_mutex); - if (old_handler) - old_handler->down(k); - return; - } - } - // hack... - if (lua_started) - key_vect.pop_back(); - SDL_mutexV(key_vect_mutex); - if (!lua_started) - SDL_SemPost(key_vect_size); - } else { - if (k.sym == SDLK_ESCAPE) { - CurrentConsole->SetVisible(true); - return; - } - if (old_handler) - old_handler->down(k); - } -} - -void console_keyevent::up(SDL_keysym k) { - if (old_handler) - old_handler->up(k); -} - -console::console(mogltk::shape * sh, mogltk::widget * father, int y, int _nlines) : - widget(father, 0, y, father->GetW(), _nlines * 13, 0, "console", sh), nlines(_nlines), page(0), protect_add_line(SDL_CreateMutex()) { - SetVisible(false); -} - -console::~console() { - SDL_DestroyMutex(protect_add_line); -} - -void console::add_line(const String & s) { - SDL_mutexP(protect_add_line); - lines.insert(lines.begin(), 1, s); - while (lines.size() >= 1024) { - lines.pop_back(); - } - SDL_mutexV(protect_add_line); -} - -void console::page_reset() { - page = 0; -} - -void console::page_up() { - page += nlines - 1; - if (page > (lines.size() - nlines)) - page = lines.size() - nlines; -} - -void console::page_down() { - page -= nlines - 1; - if (page < 0) - page = 0; -} - -void console::draw() { - int cursor_pos, start, line_length, line_pos, cur_page; - - mogltk::ColorP::Max.A = 180; - std::vector::iterator i; - - // Background - Shaper()->box(GetAX(), GetAY(), GetAX2(), GetAY2(), DODGERBLUE); - Shaper()->obox(GetAX(), GetAY(), GetAX2(), GetAY2(), BLUE); - - mogltk::ColorP::Max.A = 255; - mogltk::FixedFont->setcolor(WHITE); - - // Lines - SDL_mutexP(protect_add_line); - i = lines.begin(); - for (cur_page = page; cur_page && (i != lines.end()); cur_page--, i++); - - for (line_pos = nlines - 2; (line_pos >= 0) && (i != lines.end()); line_pos--, i++) { - const char * line; - mogltk::FixedFont->putcursor(GetAX(), GetAY() + line_pos * 13); - line = i->to_charp(); - mogltk::FixedFont->printf("%s", line); - } - SDL_mutexV(protect_add_line); - - // Cursor - cursor_pos = rl_point; - start = 0; - - line_length = strlen(rl_line_buffer); - -// while ((((cursor_pos + 2) * 6) >= GetW() || (((line_length - start + 2) * 6) >= GetW())) && (cursor_pos >= 16)) { - while (((cursor_pos + 2) * 6) >= GetW()) { - cursor_pos -= 16; - start += 16; - } - - mogltk::ColorP::Max.A = 220; - - if (lua_started) { - Shaper()->box(GetAX(), GetAY() + (nlines - 1) * 13, GetAX() + 6, GetAY() + nlines * 13, FORESTGREEN); - } else { - Shaper()->box(GetAX() + 6 * (cursor_pos + 2), GetAY() + (nlines - 1) * 13, GetAX() + 6 * (cursor_pos + 3) - 1, GetAY() + nlines * 13, FORESTGREEN); - - mogltk::ColorP::Max.A = 255; - mogltk::FixedFont->putcursor(GetAX(), GetAY() + (nlines - 1) * 13); - mogltk::FixedFont->printf(prompt); - mogltk::FixedFont->printf("%s", rl_line_buffer + start); - } -} - -bool console::process_event(int mx, int my, mogltk::event_t event) { - return false; -} - -void create_console_thread { - key_vect_mutex = SDL_CreateMutex(); - key_vect_size = SDL_CreateSemaphore(0); - - SDL_CreateThread(readline_thread, 0); -} +/* + * 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: Console.cc,v 1.2 2004-11-27 21:47:23 pixel Exp $ */ + +#include +#include + +#include +#include +#include + +#include +#include + +#include + +#include + +SDL_mutex * console_lock; +SDL_sem * console_sem; +Buffer console_buffer; + +SDL_mutex * key_vect_mutex; +SDL_sem * key_vect_size; +std::vector key_vect; + +String console_prompt = "> "; + +class ReadLineInternals : public Base { + public: + static int readline_thread(void * d) { + char * line_read; + String line, endline; + bool runit; + int pos; + + rl_getc_function = ReadLineInternals::rl_getc_func; + rl_redisplay_function = ReadLineInternals::rl_redisplay_func; + rl_prep_term_function = ReadLineInternals::rl_prep_term_func; + rl_deprep_term_function = ReadLineInternals::rl_deprep_term_func; + rl_bind_key('\t', rl_insert); + + while (true) { + line_read = readline(""); + if (!line_read) + continue; + if (*line_read) + add_history(line_read); + CurrentConsole->add_line(console_prompt + line_read); + + line = line_read; + line = line.trim(); + endline = ""; + + /* Splitting the line between ;; */ + while (line.strlen()) { + runit = false; + + if ((pos = line.strstr(";;")) >= 0) { + endline = line.extract(pos + 2); + line = line.extract(0, pos); + runit = true; + } else { + endline = ""; + } + + if (line[line.strlen() - 1] == '\\') { + line[line.strlen() - 1] = ' '; + } else if (auto_exec) { + runit = true; + } + + SDL_mutexP(console_lock); + console_buffer << line; + SDL_mutexV(console_lock); + + if (runit) { + SDL_SemPost(console_sem); + prompt = "> "; + } else { + prompt = "- "; + } + line = endline.trim(); + } + + free(line_read); + } + + return 0; + } + private: + static int rl_getc_func(FILE * d) { + int k; + SDL_SemWait(key_vect_size); + SDL_mutexP(key_vect_mutex); + k = key_vect[0]; + key_vect.erase(key_vect.begin()); + SDL_mutexV(key_vect_mutex); + return k; + } + + static void rl_redisplay_func(void) { + CurrentConsole->page_reset(); + } + + static void rl_prep_term_func(int b) { + } + + static void rl_deprep_term_func(void) { + } +}; + +virtual void console_keyevent::down(SDL_keysym k) { + if (Application->Console->GetVisible()) { + SDL_mutexP(key_vect_mutex); + switch (k.sym) { + case SDLK_ESCAPE: + Application->Console->SetVisible(false); + SDL_mutexV(key_vect_mutex); + return; + case SDLK_DELETE: + key_vect.push_back('D' - '@'); + break; + case SDLK_LEFT: + key_vect.push_back('B' - '@'); + break; + case SDLK_RIGHT: + key_vect.push_back('F' - '@'); + break; + case SDLK_UP: + key_vect.push_back('P' - '@'); + break; + case SDLK_DOWN: + key_vect.push_back('N' - '@'); + break; + case SDLK_HOME: + key_vect.push_back('A' - '@'); + break; + case SDLK_END: + key_vect.push_back('E' - '@'); + break; + case SDLK_PAGEUP: + Application->Console->page_up(); + SDL_mutexV(key_vect_mutex); + return; + case SDLK_PAGEDOWN: + Application->Console->page_down(); + SDL_mutexV(key_vect_mutex); + return; + case SDLK_c: + if (k.mod & KMOD_CTRL) { + if (lua_started) + do_lua_break = true; + SDL_mutexV(key_vect_mutex); + return; + } + default: + if (k.unicode) { + switch (k.unicode) { + case 0xb4: + key_vect.push_back('\''); + break; + case 0xa8: + key_vect.push_back('"'); + break; + default: + key_vect.push_back(k.unicode); + } + } else { + SDL_mutexV(key_vect_mutex); + if (old_handler) + old_handler->down(k); + return; + } + } + // hack... + if (lua_started) + key_vect.pop_back(); + SDL_mutexV(key_vect_mutex); + if (!lua_started) + SDL_SemPost(key_vect_size); + } else { + if (k.sym == SDLK_ESCAPE) { + CurrentConsole->SetVisible(true); + return; + } + if (old_handler) + old_handler->down(k); + } +} + +void console_keyevent::up(SDL_keysym k) { + if (old_handler) + old_handler->up(k); +} + +console::console(mogltk::shape * sh, mogltk::widget * father, int y, int _nlines) : + widget(father, 0, y, father->GetW(), _nlines * 13, 0, "console", sh), nlines(_nlines), page(0), protect_add_line(SDL_CreateMutex()) { + SetVisible(false); +} + +console::~console() { + SDL_DestroyMutex(protect_add_line); +} + +void console::add_line(const String & s) { + SDL_mutexP(protect_add_line); + lines.insert(lines.begin(), 1, s); + while (lines.size() >= 1024) { + lines.pop_back(); + } + SDL_mutexV(protect_add_line); +} + +void console::page_reset() { + page = 0; +} + +void console::page_up() { + page += nlines - 1; + if (page > (lines.size() - nlines)) + page = lines.size() - nlines; +} + +void console::page_down() { + page -= nlines - 1; + if (page < 0) + page = 0; +} + +void console::draw() { + int cursor_pos, start, line_length, line_pos, cur_page; + + mogltk::ColorP::Max.A = 180; + std::vector::iterator i; + + // Background + Shaper()->box(GetAX(), GetAY(), GetAX2(), GetAY2(), DODGERBLUE); + Shaper()->obox(GetAX(), GetAY(), GetAX2(), GetAY2(), BLUE); + + mogltk::ColorP::Max.A = 255; + mogltk::FixedFont->setcolor(WHITE); + + // Lines + SDL_mutexP(protect_add_line); + i = lines.begin(); + for (cur_page = page; cur_page && (i != lines.end()); cur_page--, i++); + + for (line_pos = nlines - 2; (line_pos >= 0) && (i != lines.end()); line_pos--, i++) { + const char * line; + mogltk::FixedFont->putcursor(GetAX(), GetAY() + line_pos * 13); + line = i->to_charp(); + mogltk::FixedFont->printf("%s", line); + } + SDL_mutexV(protect_add_line); + + // Cursor + cursor_pos = rl_point; + start = 0; + + line_length = strlen(rl_line_buffer); + +// while ((((cursor_pos + 2) * 6) >= GetW() || (((line_length - start + 2) * 6) >= GetW())) && (cursor_pos >= 16)) { + while (((cursor_pos + 2) * 6) >= GetW()) { + cursor_pos -= 16; + start += 16; + } + + mogltk::ColorP::Max.A = 220; + + if (lua_started) { + Shaper()->box(GetAX(), GetAY() + (nlines - 1) * 13, GetAX() + 6, GetAY() + nlines * 13, FORESTGREEN); + } else { + Shaper()->box(GetAX() + 6 * (cursor_pos + 2), GetAY() + (nlines - 1) * 13, GetAX() + 6 * (cursor_pos + 3) - 1, GetAY() + nlines * 13, FORESTGREEN); + + mogltk::ColorP::Max.A = 255; + mogltk::FixedFont->putcursor(GetAX(), GetAY() + (nlines - 1) * 13); + mogltk::FixedFont->printf(prompt); + mogltk::FixedFont->printf("%s", rl_line_buffer + start); + } +} + +bool console::process_event(int mx, int my, mogltk::event_t event) { + return false; +} + +void create_console_thread { + key_vect_mutex = SDL_CreateMutex(); + key_vect_size = SDL_CreateSemaphore(0); + + SDL_CreateThread(readline_thread, 0); +} diff --git a/Dalos/Console.h b/Dalos/Console.h index 5a632fa..8073a4d 100644 --- a/Dalos/Console.h +++ b/Dalos/Console.h @@ -1,63 +1,63 @@ -/* - * 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: Console.h,v 1.1 2004-10-19 01:27:27 pixel Exp $ */ - -#ifndef __CONSOLE_H__ -#define __CONSOLE_H__ - -#include -#include - -#include - -#include -#include - -class console_keyevent : public mogltk::engine::keyevent { - public: - virtual void down(SDL_keysym k); - virtual void up(SDL_keysym k); -}; - -class console : public mogltk::widget { - public: - console(mogltk::shape * sh, mogltk::widget * father, int y, int _nlines); - virtual ~console(); - void add_line(const String & s); - void page_reset(); - void page_up(); - void page_down(); - protected: - virtual void draw(); - virtual bool process_event(int mx, int my, mogltk::event_t event); - private: - int nlines, page; - std::vector lines; - SDL_mutex * protect_add_line; -} * CurrentConsole; - -extern SDL_mutex * console_lock; -extern SDL_sem * console_sem; -extern Buffer console_buffer; - -extern String console_prompt; - - -#endif +/* + * 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: Console.h,v 1.2 2004-11-27 21:47:23 pixel Exp $ */ + +#ifndef __CONSOLE_H__ +#define __CONSOLE_H__ + +#include +#include + +#include + +#include +#include + +class console_keyevent : public mogltk::engine::keyevent { + public: + virtual void down(SDL_keysym k); + virtual void up(SDL_keysym k); +}; + +class console : public mogltk::widget { + public: + console(mogltk::shape * sh, mogltk::widget * father, int y, int _nlines); + virtual ~console(); + void add_line(const String & s); + void page_reset(); + void page_up(); + void page_down(); + protected: + virtual void draw(); + virtual bool process_event(int mx, int my, mogltk::event_t event); + private: + int nlines, page; + std::vector lines; + SDL_mutex * protect_add_line; +} * CurrentConsole; + +extern SDL_mutex * console_lock; +extern SDL_sem * console_sem; +extern Buffer console_buffer; + +extern String console_prompt; + + +#endif diff --git a/Dalos/Dalos.cc b/Dalos/Dalos.cc index b2f4212..78f2de1 100644 --- a/Dalos/Dalos.cc +++ b/Dalos/Dalos.cc @@ -1 +1 @@ -int main(void) { return 0; } +int main(void) { return 0; } diff --git a/MegamanX5/unarc.cpp b/MegamanX5/unarc.cpp index 098af51..ea5e498 100644 --- a/MegamanX5/unarc.cpp +++ b/MegamanX5/unarc.cpp @@ -1,40 +1,40 @@ -#include -#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 +#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/afxres.h b/PE/afxres.h index a8f555d..f237de7 100644 --- a/PE/afxres.h +++ b/PE/afxres.h @@ -1,808 +1,808 @@ -// This is a part of the Microsoft Foundation Classes C++ library. -// Copyright (C) 1992-2001 Microsoft Corporation -// All rights reserved. -// -// This source code is only intended as a supplement to the -// Microsoft Foundation Classes Reference and related -// electronic documentation provided with the library. -// See these sources for detailed information regarding the -// Microsoft Foundation Classes product. - -#ifndef __AFXRES_H__ -#define __AFXRES_H__ - -#ifdef RC_INVOKED -#ifndef _INC_WINDOWS -#define _INC_WINDOWS - #include "winresrc.h" // extract from windows header -#endif -#endif - -#ifdef _AFX_MINREBUILD -#pragma component(minrebuild, off) -#endif - -#ifdef APSTUDIO_INVOKED -#define APSTUDIO_HIDDEN_SYMBOLS -#endif - -///////////////////////////////////////////////////////////////////////////// -// MFC resource types (see Technical note TN024 for implementation details) - -#ifndef RC_INVOKED -#define RT_DLGINIT MAKEINTRESOURCE(240) -#define RT_TOOLBAR MAKEINTRESOURCE(241) -#endif - -///////////////////////////////////////////////////////////////////////////// - -#ifdef APSTUDIO_INVOKED -#undef APSTUDIO_HIDDEN_SYMBOLS -#endif - -///////////////////////////////////////////////////////////////////////////// -// General style bits etc - -// ControlBar styles -#define CBRS_ALIGN_LEFT 0x1000L -#define CBRS_ALIGN_TOP 0x2000L -#define CBRS_ALIGN_RIGHT 0x4000L -#define CBRS_ALIGN_BOTTOM 0x8000L -#define CBRS_ALIGN_ANY 0xF000L - -#define CBRS_BORDER_LEFT 0x0100L -#define CBRS_BORDER_TOP 0x0200L -#define CBRS_BORDER_RIGHT 0x0400L -#define CBRS_BORDER_BOTTOM 0x0800L -#define CBRS_BORDER_ANY 0x0F00L - -#define CBRS_TOOLTIPS 0x0010L -#define CBRS_FLYBY 0x0020L -#define CBRS_FLOAT_MULTI 0x0040L -#define CBRS_BORDER_3D 0x0080L -#define CBRS_HIDE_INPLACE 0x0008L -#define CBRS_SIZE_DYNAMIC 0x0004L -#define CBRS_SIZE_FIXED 0x0002L -#define CBRS_FLOATING 0x0001L - -#define CBRS_GRIPPER 0x00400000L - -#define CBRS_ORIENT_HORZ (CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM) -#define CBRS_ORIENT_VERT (CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT) -#define CBRS_ORIENT_ANY (CBRS_ORIENT_HORZ|CBRS_ORIENT_VERT) - -#define CBRS_ALL 0x0040FFFFL - -// the CBRS_ style is made up of an alignment style and a draw border style -// the alignment styles are mutually exclusive -// the draw border styles may be combined -#define CBRS_NOALIGN 0x00000000L -#define CBRS_LEFT (CBRS_ALIGN_LEFT|CBRS_BORDER_RIGHT) -#define CBRS_TOP (CBRS_ALIGN_TOP|CBRS_BORDER_BOTTOM) -#define CBRS_RIGHT (CBRS_ALIGN_RIGHT|CBRS_BORDER_LEFT) -#define CBRS_BOTTOM (CBRS_ALIGN_BOTTOM|CBRS_BORDER_TOP) - -///////////////////////////////////////////////////////////////////////////// -// Standard window components - -// Mode indicators in status bar - these are routed like commands -#define ID_INDICATOR_EXT 0xE700 // extended selection indicator -#define ID_INDICATOR_CAPS 0xE701 // cap lock indicator -#define ID_INDICATOR_NUM 0xE702 // num lock indicator -#define ID_INDICATOR_SCRL 0xE703 // scroll lock indicator -#define ID_INDICATOR_OVR 0xE704 // overtype mode indicator -#define ID_INDICATOR_REC 0xE705 // record mode indicator -#define ID_INDICATOR_KANA 0xE706 // kana lock indicator - -#define ID_SEPARATOR 0 // special separator value - -#ifndef RC_INVOKED // code only -// Standard control bars (IDW = window ID) -#define AFX_IDW_CONTROLBAR_FIRST 0xE800 -#define AFX_IDW_CONTROLBAR_LAST 0xE8FF - -#define AFX_IDW_TOOLBAR 0xE800 // main Toolbar for window -#define AFX_IDW_STATUS_BAR 0xE801 // Status bar window -#define AFX_IDW_PREVIEW_BAR 0xE802 // PrintPreview Dialog Bar -#define AFX_IDW_RESIZE_BAR 0xE803 // OLE in-place resize bar -#define AFX_IDW_REBAR 0xE804 // COMCTL32 "rebar" Bar -#define AFX_IDW_DIALOGBAR 0xE805 // CDialogBar - -// Note: If your application supports docking toolbars, you should -// not use the following IDs for your own toolbars. The IDs chosen -// are at the top of the first 32 such that the bars will be hidden -// while in print preview mode, and are not likely to conflict with -// IDs your application may have used succesfully in the past. - -#define AFX_IDW_DOCKBAR_TOP 0xE81B -#define AFX_IDW_DOCKBAR_LEFT 0xE81C -#define AFX_IDW_DOCKBAR_RIGHT 0xE81D -#define AFX_IDW_DOCKBAR_BOTTOM 0xE81E -#define AFX_IDW_DOCKBAR_FLOAT 0xE81F - -// Macro for mapping standard control bars to bitmask (limit of 32) -#define AFX_CONTROLBAR_MASK(nIDC) (1L << (nIDC - AFX_IDW_CONTROLBAR_FIRST)) - -// parts of Main Frame -#define AFX_IDW_PANE_FIRST 0xE900 // first pane (256 max) -#define AFX_IDW_PANE_LAST 0xE9ff -#define AFX_IDW_HSCROLL_FIRST 0xEA00 // first Horz scrollbar (16 max) -#define AFX_IDW_VSCROLL_FIRST 0xEA10 // first Vert scrollbar (16 max) - -#define AFX_IDW_SIZE_BOX 0xEA20 // size box for splitters -#define AFX_IDW_PANE_SAVE 0xEA21 // to shift AFX_IDW_PANE_FIRST -#endif //!RC_INVOKED - -#ifndef APSTUDIO_INVOKED - -// common style for form views -#define AFX_WS_DEFAULT_VIEW (WS_CHILD | WS_VISIBLE | WS_BORDER) - -#endif //!APSTUDIO_INVOKED - -///////////////////////////////////////////////////////////////////////////// -// Standard app configurable strings - -// for application title (defaults to EXE name or name in constructor) -#define AFX_IDS_APP_TITLE 0xE000 -// idle message bar line -#define AFX_IDS_IDLEMESSAGE 0xE001 -// message bar line when in shift-F1 help mode -#define AFX_IDS_HELPMODEMESSAGE 0xE002 -// document title when editing OLE embedding -#define AFX_IDS_APP_TITLE_EMBEDDING 0xE003 -// company name -#define AFX_IDS_COMPANY_NAME 0xE004 -// object name when server is inplace -#define AFX_IDS_OBJ_TITLE_INPLACE 0xE005 - -///////////////////////////////////////////////////////////////////////////// -// Standard Commands - -// File commands -#define ID_FILE_NEW 0xE100 -#define ID_FILE_OPEN 0xE101 -#define ID_FILE_CLOSE 0xE102 -#define ID_FILE_SAVE 0xE103 -#define ID_FILE_SAVE_AS 0xE104 -#define ID_FILE_PAGE_SETUP 0xE105 -#define ID_FILE_PRINT_SETUP 0xE106 -#define ID_FILE_PRINT 0xE107 -#define ID_FILE_PRINT_DIRECT 0xE108 -#define ID_FILE_PRINT_PREVIEW 0xE109 -#define ID_FILE_UPDATE 0xE10A -#define ID_FILE_SAVE_COPY_AS 0xE10B -#define ID_FILE_SEND_MAIL 0xE10C -#define ID_FILE_NEW_FRAME 0xE10D - -#define ID_FILE_MRU_FIRST 0xE110 -#define ID_FILE_MRU_FILE1 0xE110 // range - 16 max -#define ID_FILE_MRU_FILE2 0xE111 -#define ID_FILE_MRU_FILE3 0xE112 -#define ID_FILE_MRU_FILE4 0xE113 -#define ID_FILE_MRU_FILE5 0xE114 -#define ID_FILE_MRU_FILE6 0xE115 -#define ID_FILE_MRU_FILE7 0xE116 -#define ID_FILE_MRU_FILE8 0xE117 -#define ID_FILE_MRU_FILE9 0xE118 -#define ID_FILE_MRU_FILE10 0xE119 -#define ID_FILE_MRU_FILE11 0xE11A -#define ID_FILE_MRU_FILE12 0xE11B -#define ID_FILE_MRU_FILE13 0xE11C -#define ID_FILE_MRU_FILE14 0xE11D -#define ID_FILE_MRU_FILE15 0xE11E -#define ID_FILE_MRU_FILE16 0xE11F -#define ID_FILE_MRU_LAST 0xE11F - -// Edit commands -#define ID_EDIT_CLEAR 0xE120 -#define ID_EDIT_CLEAR_ALL 0xE121 -#define ID_EDIT_COPY 0xE122 -#define ID_EDIT_CUT 0xE123 -#define ID_EDIT_FIND 0xE124 -#define ID_EDIT_PASTE 0xE125 -#define ID_EDIT_PASTE_LINK 0xE126 -#define ID_EDIT_PASTE_SPECIAL 0xE127 -#define ID_EDIT_REPEAT 0xE128 -#define ID_EDIT_REPLACE 0xE129 -#define ID_EDIT_SELECT_ALL 0xE12A -#define ID_EDIT_UNDO 0xE12B -#define ID_EDIT_REDO 0xE12C - -// Window commands -#define ID_WINDOW_NEW 0xE130 -#define ID_WINDOW_ARRANGE 0xE131 -#define ID_WINDOW_CASCADE 0xE132 -#define ID_WINDOW_TILE_HORZ 0xE133 -#define ID_WINDOW_TILE_VERT 0xE134 -#define ID_WINDOW_SPLIT 0xE135 -#ifndef RC_INVOKED // code only -#define AFX_IDM_WINDOW_FIRST 0xE130 -#define AFX_IDM_WINDOW_LAST 0xE13F -#define AFX_IDM_FIRST_MDICHILD 0xFF00 // window list starts here -#endif //!RC_INVOKED - -// Help and App commands -#define ID_APP_ABOUT 0xE140 -#define ID_APP_EXIT 0xE141 -#define ID_HELP_INDEX 0xE142 -#define ID_HELP_FINDER 0xE143 -#define ID_HELP_USING 0xE144 -#define ID_CONTEXT_HELP 0xE145 // shift-F1 -// special commands for processing help -#define ID_HELP 0xE146 // first attempt for F1 -#define ID_DEFAULT_HELP 0xE147 // last attempt - -// Misc -#define ID_NEXT_PANE 0xE150 -#define ID_PREV_PANE 0xE151 - -// Format -#define ID_FORMAT_FONT 0xE160 - -// OLE commands -#define ID_OLE_INSERT_NEW 0xE200 -#define ID_OLE_EDIT_LINKS 0xE201 -#define ID_OLE_EDIT_CONVERT 0xE202 -#define ID_OLE_EDIT_CHANGE_ICON 0xE203 -#define ID_OLE_EDIT_PROPERTIES 0xE204 -#define ID_OLE_VERB_FIRST 0xE210 // range - 16 max -#ifndef RC_INVOKED // code only -#define ID_OLE_VERB_LAST 0xE21F -#endif //!RC_INVOKED - -// for print preview dialog bar -#define AFX_ID_PREVIEW_CLOSE 0xE300 -#define AFX_ID_PREVIEW_NUMPAGE 0xE301 // One/Two Page button -#define AFX_ID_PREVIEW_NEXT 0xE302 -#define AFX_ID_PREVIEW_PREV 0xE303 -#define AFX_ID_PREVIEW_PRINT 0xE304 -#define AFX_ID_PREVIEW_ZOOMIN 0xE305 -#define AFX_ID_PREVIEW_ZOOMOUT 0xE306 - -// View commands (same number used as IDW used for control bar) -#define ID_VIEW_TOOLBAR 0xE800 -#define ID_VIEW_STATUS_BAR 0xE801 -#define ID_VIEW_REBAR 0xE804 -#define ID_VIEW_AUTOARRANGE 0xE805 - // E810 -> E81F must be kept in order for RANGE macros -#define ID_VIEW_SMALLICON 0xE810 -#define ID_VIEW_LARGEICON 0xE811 -#define ID_VIEW_LIST 0xE812 -#define ID_VIEW_DETAILS 0xE813 -#define ID_VIEW_LINEUP 0xE814 -#define ID_VIEW_BYNAME 0xE815 -#define AFX_ID_VIEW_MINIMUM ID_VIEW_SMALLICON -#define AFX_ID_VIEW_MAXIMUM ID_VIEW_BYNAME - // E800 -> E8FF reserved for other control bar commands - -// RecordForm commands -#define ID_RECORD_FIRST 0xE900 -#define ID_RECORD_LAST 0xE901 -#define ID_RECORD_NEXT 0xE902 -#define ID_RECORD_PREV 0xE903 - -///////////////////////////////////////////////////////////////////////////// -// Standard control IDs - -#ifdef IDC_STATIC -#undef IDC_STATIC -#endif -#define IDC_STATIC (-1) // all static controls - -///////////////////////////////////////////////////////////////////////////// -// Standard string error/warnings - -#ifndef RC_INVOKED // code only -#define AFX_IDS_SCFIRST 0xEF00 -#endif //!RC_INVOKED - -#define AFX_IDS_SCSIZE 0xEF00 -#define AFX_IDS_SCMOVE 0xEF01 -#define AFX_IDS_SCMINIMIZE 0xEF02 -#define AFX_IDS_SCMAXIMIZE 0xEF03 -#define AFX_IDS_SCNEXTWINDOW 0xEF04 -#define AFX_IDS_SCPREVWINDOW 0xEF05 -#define AFX_IDS_SCCLOSE 0xEF06 -#define AFX_IDS_SCRESTORE 0xEF12 -#define AFX_IDS_SCTASKLIST 0xEF13 - -#define AFX_IDS_MDICHILD 0xEF1F - -#define AFX_IDS_DESKACCESSORY 0xEFDA - -// General strings -#define AFX_IDS_OPENFILE 0xF000 -#define AFX_IDS_SAVEFILE 0xF001 -#define AFX_IDS_ALLFILTER 0xF002 -#define AFX_IDS_UNTITLED 0xF003 -#define AFX_IDS_SAVEFILECOPY 0xF004 -#define AFX_IDS_PREVIEW_CLOSE 0xF005 -#define AFX_IDS_UNNAMED_FILE 0xF006 -#define AFX_IDS_HIDE 0xF011 - -// MFC Standard Exception Error messages -#define AFX_IDP_NO_ERROR_AVAILABLE 0xF020 -#define AFX_IDS_NOT_SUPPORTED_EXCEPTION 0xF021 -#define AFX_IDS_RESOURCE_EXCEPTION 0xF022 -#define AFX_IDS_MEMORY_EXCEPTION 0xF023 -#define AFX_IDS_USER_EXCEPTION 0xF024 - -// Printing and print preview strings -#define AFX_IDS_PRINTONPORT 0xF040 -#define AFX_IDS_ONEPAGE 0xF041 -#define AFX_IDS_TWOPAGE 0xF042 -#define AFX_IDS_PRINTPAGENUM 0xF043 -#define AFX_IDS_PREVIEWPAGEDESC 0xF044 -#define AFX_IDS_PRINTDEFAULTEXT 0xF045 -#define AFX_IDS_PRINTDEFAULT 0xF046 -#define AFX_IDS_PRINTFILTER 0xF047 -#define AFX_IDS_PRINTCAPTION 0xF048 -#define AFX_IDS_PRINTTOFILE 0xF049 - - -// OLE strings -#define AFX_IDS_OBJECT_MENUITEM 0xF080 -#define AFX_IDS_EDIT_VERB 0xF081 -#define AFX_IDS_ACTIVATE_VERB 0xF082 -#define AFX_IDS_CHANGE_LINK 0xF083 -#define AFX_IDS_AUTO 0xF084 -#define AFX_IDS_MANUAL 0xF085 -#define AFX_IDS_FROZEN 0xF086 -#define AFX_IDS_ALL_FILES 0xF087 -// dynamically changing menu items -#define AFX_IDS_SAVE_MENU 0xF088 -#define AFX_IDS_UPDATE_MENU 0xF089 -#define AFX_IDS_SAVE_AS_MENU 0xF08A -#define AFX_IDS_SAVE_COPY_AS_MENU 0xF08B -#define AFX_IDS_EXIT_MENU 0xF08C -#define AFX_IDS_UPDATING_ITEMS 0xF08D -// COlePasteSpecialDialog defines -#define AFX_IDS_METAFILE_FORMAT 0xF08E -#define AFX_IDS_DIB_FORMAT 0xF08F -#define AFX_IDS_BITMAP_FORMAT 0xF090 -#define AFX_IDS_LINKSOURCE_FORMAT 0xF091 -#define AFX_IDS_EMBED_FORMAT 0xF092 -// other OLE utility strings -#define AFX_IDS_PASTELINKEDTYPE 0xF094 -#define AFX_IDS_UNKNOWNTYPE 0xF095 -#define AFX_IDS_RTF_FORMAT 0xF096 -#define AFX_IDS_TEXT_FORMAT 0xF097 -// OLE datatype format error strings -#define AFX_IDS_INVALID_CURRENCY 0xF098 -#define AFX_IDS_INVALID_DATETIME 0xF099 -#define AFX_IDS_INVALID_DATETIMESPAN 0xF09A - -// General error / prompt strings -#define AFX_IDP_INVALID_FILENAME 0xF100 -#define AFX_IDP_FAILED_TO_OPEN_DOC 0xF101 -#define AFX_IDP_FAILED_TO_SAVE_DOC 0xF102 -#define AFX_IDP_ASK_TO_SAVE 0xF103 -#define AFX_IDP_FAILED_TO_CREATE_DOC 0xF104 -#define AFX_IDP_FILE_TOO_LARGE 0xF105 -#define AFX_IDP_FAILED_TO_START_PRINT 0xF106 -#define AFX_IDP_FAILED_TO_LAUNCH_HELP 0xF107 -#define AFX_IDP_INTERNAL_FAILURE 0xF108 // general failure -#define AFX_IDP_COMMAND_FAILURE 0xF109 // command failure -#define AFX_IDP_FAILED_MEMORY_ALLOC 0xF10A -#define AFX_IDP_UNREG_DONE 0xF10B -#define AFX_IDP_UNREG_FAILURE 0xF10C -#define AFX_IDP_DLL_LOAD_FAILED 0xF10D -#define AFX_IDP_DLL_BAD_VERSION 0xF10E - -// DDV parse errors -#define AFX_IDP_PARSE_INT 0xF110 -#define AFX_IDP_PARSE_REAL 0xF111 -#define AFX_IDP_PARSE_INT_RANGE 0xF112 -#define AFX_IDP_PARSE_REAL_RANGE 0xF113 -#define AFX_IDP_PARSE_STRING_SIZE 0xF114 -#define AFX_IDP_PARSE_RADIO_BUTTON 0xF115 -#define AFX_IDP_PARSE_BYTE 0xF116 -#define AFX_IDP_PARSE_UINT 0xF117 -#define AFX_IDP_PARSE_DATETIME 0xF118 -#define AFX_IDP_PARSE_CURRENCY 0xF119 -#define AFX_IDP_PARSE_GUID 0xF11A -#define AFX_IDP_PARSE_TIME 0xF11B -#define AFX_IDP_PARSE_DATE 0xF11C - -// CFile/CArchive error strings for user failure -#define AFX_IDP_FAILED_INVALID_FORMAT 0xF120 -#define AFX_IDP_FAILED_INVALID_PATH 0xF121 -#define AFX_IDP_FAILED_DISK_FULL 0xF122 -#define AFX_IDP_FAILED_ACCESS_READ 0xF123 -#define AFX_IDP_FAILED_ACCESS_WRITE 0xF124 -#define AFX_IDP_FAILED_IO_ERROR_READ 0xF125 -#define AFX_IDP_FAILED_IO_ERROR_WRITE 0xF126 - -// Script errors / prompt strings -#define AFX_IDP_SCRIPT_ERROR 0xF130 -#define AFX_IDP_SCRIPT_DISPATCH_EXCEPTION 0xF131 - -// OLE errors / prompt strings -#define AFX_IDP_STATIC_OBJECT 0xF180 -#define AFX_IDP_FAILED_TO_CONNECT 0xF181 -#define AFX_IDP_SERVER_BUSY 0xF182 -#define AFX_IDP_BAD_VERB 0xF183 -#define AFX_IDS_NOT_DOCOBJECT 0xF184 -#define AFX_IDP_FAILED_TO_NOTIFY 0xF185 -#define AFX_IDP_FAILED_TO_LAUNCH 0xF186 -#define AFX_IDP_ASK_TO_UPDATE 0xF187 -#define AFX_IDP_FAILED_TO_UPDATE 0xF188 -#define AFX_IDP_FAILED_TO_REGISTER 0xF189 -#define AFX_IDP_FAILED_TO_AUTO_REGISTER 0xF18A -#define AFX_IDP_FAILED_TO_CONVERT 0xF18B -#define AFX_IDP_GET_NOT_SUPPORTED 0xF18C -#define AFX_IDP_SET_NOT_SUPPORTED 0xF18D -#define AFX_IDP_ASK_TO_DISCARD 0xF18E -#define AFX_IDP_FAILED_TO_CREATE 0xF18F - -// MAPI errors / prompt strings -#define AFX_IDP_FAILED_MAPI_LOAD 0xF190 -#define AFX_IDP_INVALID_MAPI_DLL 0xF191 -#define AFX_IDP_FAILED_MAPI_SEND 0xF192 - -#define AFX_IDP_FILE_NONE 0xF1A0 -#define AFX_IDP_FILE_GENERIC 0xF1A1 -#define AFX_IDP_FILE_NOT_FOUND 0xF1A2 -#define AFX_IDP_FILE_BAD_PATH 0xF1A3 -#define AFX_IDP_FILE_TOO_MANY_OPEN 0xF1A4 -#define AFX_IDP_FILE_ACCESS_DENIED 0xF1A5 -#define AFX_IDP_FILE_INVALID_FILE 0xF1A6 -#define AFX_IDP_FILE_REMOVE_CURRENT 0xF1A7 -#define AFX_IDP_FILE_DIR_FULL 0xF1A8 -#define AFX_IDP_FILE_BAD_SEEK 0xF1A9 -#define AFX_IDP_FILE_HARD_IO 0xF1AA -#define AFX_IDP_FILE_SHARING 0xF1AB -#define AFX_IDP_FILE_LOCKING 0xF1AC -#define AFX_IDP_FILE_DISKFULL 0xF1AD -#define AFX_IDP_FILE_EOF 0xF1AE - -#define AFX_IDP_ARCH_NONE 0xF1B0 -#define AFX_IDP_ARCH_GENERIC 0xF1B1 -#define AFX_IDP_ARCH_READONLY 0xF1B2 -#define AFX_IDP_ARCH_ENDOFFILE 0xF1B3 -#define AFX_IDP_ARCH_WRITEONLY 0xF1B4 -#define AFX_IDP_ARCH_BADINDEX 0xF1B5 -#define AFX_IDP_ARCH_BADCLASS 0xF1B6 -#define AFX_IDP_ARCH_BADSCHEMA 0xF1B7 - -#define AFX_IDS_OCC_SCALEUNITS_PIXELS 0xF1C0 - -// 0xf200-0xf20f reserved - -// font names and point sizes -#define AFX_IDS_STATUS_FONT 0xF230 -#define AFX_IDS_TOOLTIP_FONT 0xF231 -#define AFX_IDS_UNICODE_FONT 0xF232 -#define AFX_IDS_MINI_FONT 0xF233 - -// ODBC Database errors / prompt strings -#ifndef RC_INVOKED // code only -#define AFX_IDP_SQL_FIRST 0xF280 -#endif //!RC_INVOKED -#define AFX_IDP_SQL_CONNECT_FAIL 0xF281 -#define AFX_IDP_SQL_RECORDSET_FORWARD_ONLY 0xF282 -#define AFX_IDP_SQL_EMPTY_COLUMN_LIST 0xF283 -#define AFX_IDP_SQL_FIELD_SCHEMA_MISMATCH 0xF284 -#define AFX_IDP_SQL_ILLEGAL_MODE 0xF285 -#define AFX_IDP_SQL_MULTIPLE_ROWS_AFFECTED 0xF286 -#define AFX_IDP_SQL_NO_CURRENT_RECORD 0xF287 -#define AFX_IDP_SQL_NO_ROWS_AFFECTED 0xF288 -#define AFX_IDP_SQL_RECORDSET_READONLY 0xF289 -#define AFX_IDP_SQL_SQL_NO_TOTAL 0xF28A -#define AFX_IDP_SQL_ODBC_LOAD_FAILED 0xF28B -#define AFX_IDP_SQL_DYNASET_NOT_SUPPORTED 0xF28C -#define AFX_IDP_SQL_SNAPSHOT_NOT_SUPPORTED 0xF28D -#define AFX_IDP_SQL_API_CONFORMANCE 0xF28E -#define AFX_IDP_SQL_SQL_CONFORMANCE 0xF28F -#define AFX_IDP_SQL_NO_DATA_FOUND 0xF290 -#define AFX_IDP_SQL_ROW_UPDATE_NOT_SUPPORTED 0xF291 -#define AFX_IDP_SQL_ODBC_V2_REQUIRED 0xF292 -#define AFX_IDP_SQL_NO_POSITIONED_UPDATES 0xF293 -#define AFX_IDP_SQL_LOCK_MODE_NOT_SUPPORTED 0xF294 -#define AFX_IDP_SQL_DATA_TRUNCATED 0xF295 -#define AFX_IDP_SQL_ROW_FETCH 0xF296 -#define AFX_IDP_SQL_INCORRECT_ODBC 0xF297 -#define AFX_IDP_SQL_UPDATE_DELETE_FAILED 0xF298 -#define AFX_IDP_SQL_DYNAMIC_CURSOR_NOT_SUPPORTED 0xF299 -#define AFX_IDP_SQL_FIELD_NOT_FOUND 0xF29A -#define AFX_IDP_SQL_BOOKMARKS_NOT_SUPPORTED 0xF29B -#define AFX_IDP_SQL_BOOKMARKS_NOT_ENABLED 0xF29C - -// ODBC Database strings -#define AFX_IDS_DELETED 0xF29D - -// DAO Database errors / prompt strings -#ifndef RC_INVOKED // code only -#define AFX_IDP_DAO_FIRST 0xF2B0 -#endif //!RC_INVOKED -#define AFX_IDP_DAO_ENGINE_INITIALIZATION 0xF2B0 -#define AFX_IDP_DAO_DFX_BIND 0xF2B1 -#define AFX_IDP_DAO_OBJECT_NOT_OPEN 0xF2B2 - -// ICDAORecordset::GetRows Errors -// These are not placed in DAO Errors collection -// and must be handled directly by MFC. -#define AFX_IDP_DAO_ROWTOOSHORT 0xF2B3 -#define AFX_IDP_DAO_BADBINDINFO 0xF2B4 -#define AFX_IDP_DAO_COLUMNUNAVAILABLE 0xF2B5 - -///////////////////////////////////////////////////////////////////////////// -// Strings for ISAPI support - -#define AFX_IDS_HTTP_TITLE 0xF2D1 -#define AFX_IDS_HTTP_NO_TEXT 0xF2D2 -#define AFX_IDS_HTTP_BAD_REQUEST 0xF2D3 -#define AFX_IDS_HTTP_AUTH_REQUIRED 0xF2D4 -#define AFX_IDS_HTTP_FORBIDDEN 0xF2D5 -#define AFX_IDS_HTTP_NOT_FOUND 0xF2D6 -#define AFX_IDS_HTTP_SERVER_ERROR 0xF2D7 -#define AFX_IDS_HTTP_NOT_IMPLEMENTED 0xF2D8 - -///////////////////////////////////////////////////////////////////////////// -// Strings for Accessibility support for CCheckListBox -#define AFX_IDS_CHECKLISTBOX_UNCHECK 0xF2E1 -#define AFX_IDS_CHECKLISTBOX_CHECK 0xF2E2 -#define AFX_IDS_CHECKLISTBOX_MIXED 0xF2E3 - -///////////////////////////////////////////////////////////////////////////// -// AFX implementation - control IDs (AFX_IDC) - -// Parts of dialogs -#define AFX_IDC_LISTBOX 100 -#define AFX_IDC_CHANGE 101 -#define AFX_IDC_BROWSER 102 - -// for print dialog -#define AFX_IDC_PRINT_DOCNAME 201 -#define AFX_IDC_PRINT_PRINTERNAME 202 -#define AFX_IDC_PRINT_PORTNAME 203 -#define AFX_IDC_PRINT_PAGENUM 204 - -// Property Sheet control id's (determined with Spy++) -#define ID_APPLY_NOW 0x3021 -#define ID_WIZBACK 0x3023 -#define ID_WIZNEXT 0x3024 -#define ID_WIZFINISH 0x3025 -#define AFX_IDC_TAB_CONTROL 0x3020 - -///////////////////////////////////////////////////////////////////////////// -// IDRs for standard components - -#ifndef RC_INVOKED // code only -// These are really COMMDLG dialogs, so there usually isn't a resource -// for them, but these IDs are used as help IDs. -#define AFX_IDD_FILEOPEN 28676 -#define AFX_IDD_FILESAVE 28677 -#define AFX_IDD_FONT 28678 -#define AFX_IDD_COLOR 28679 -#define AFX_IDD_PRINT 28680 -#define AFX_IDD_PRINTSETUP 28681 -#define AFX_IDD_FIND 28682 -#define AFX_IDD_REPLACE 28683 -#endif //!RC_INVOKED - -// Standard dialogs app should leave alone (0x7801->) -#define AFX_IDD_NEWTYPEDLG 30721 -#define AFX_IDD_PRINTDLG 30722 -#define AFX_IDD_PREVIEW_TOOLBAR 30723 - -// Dialogs defined for OLE2UI library -#define AFX_IDD_INSERTOBJECT 30724 -#define AFX_IDD_CHANGEICON 30725 -#define AFX_IDD_CONVERT 30726 -#define AFX_IDD_PASTESPECIAL 30727 -#define AFX_IDD_EDITLINKS 30728 -#define AFX_IDD_FILEBROWSE 30729 -#define AFX_IDD_BUSY 30730 - -#define AFX_IDD_OBJECTPROPERTIES 30732 -#define AFX_IDD_CHANGESOURCE 30733 - -// Standard cursors (0x7901->) - // AFX_IDC = Cursor resources -#define AFX_IDC_CONTEXTHELP 30977 // context sensitive help -#define AFX_IDC_MAGNIFY 30978 // print preview zoom -#define AFX_IDC_SMALLARROWS 30979 // splitter -#define AFX_IDC_HSPLITBAR 30980 // splitter -#define AFX_IDC_VSPLITBAR 30981 // splitter -#define AFX_IDC_NODROPCRSR 30982 // No Drop Cursor -#define AFX_IDC_TRACKNWSE 30983 // tracker -#define AFX_IDC_TRACKNESW 30984 // tracker -#define AFX_IDC_TRACKNS 30985 // tracker -#define AFX_IDC_TRACKWE 30986 // tracker -#define AFX_IDC_TRACK4WAY 30987 // tracker -#define AFX_IDC_MOVE4WAY 30988 // resize bar (server only) - -// Wheel mouse cursors -// NOTE: values must be in this order! See CScrollView::OnTimer() -#define AFX_IDC_MOUSE_PAN_NW 30998 // pan east -#define AFX_IDC_MOUSE_PAN_N 30999 // pan northeast -#define AFX_IDC_MOUSE_PAN_NE 31000 // pan north -#define AFX_IDC_MOUSE_PAN_W 31001 // pan northwest -#define AFX_IDC_MOUSE_PAN_HV 31002 // pan both axis -#define AFX_IDC_MOUSE_PAN_E 31003 // pan west -#define AFX_IDC_MOUSE_PAN_SW 31004 // pan south-west -#define AFX_IDC_MOUSE_PAN_S 31005 // pan south -#define AFX_IDC_MOUSE_PAN_SE 31006 // pan south-east -#define AFX_IDC_MOUSE_PAN_HORZ 31007 // pan X-axis -#define AFX_IDC_MOUSE_PAN_VERT 31008 // pan Y-axis - -// Wheel mouse bitmaps -#define AFX_IDC_MOUSE_ORG_HORZ 31009 // anchor for horz only -#define AFX_IDC_MOUSE_ORG_VERT 31010 // anchor for vert only -#define AFX_IDC_MOUSE_ORG_HV 31011 // anchor for horz/vert -#define AFX_IDC_MOUSE_MASK 31012 - -// Mini frame window bitmap ID -#define AFX_IDB_MINIFRAME_MENU 30994 - -// CheckListBox checks bitmap ID -#define AFX_IDB_CHECKLISTBOX_95 30996 - -// AFX standard accelerator resources -#define AFX_IDR_PREVIEW_ACCEL 30997 - -// AFX standard ICON IDs (for MFC V1 apps) (0x7A01->) -#define AFX_IDI_STD_MDIFRAME 31233 -#define AFX_IDI_STD_FRAME 31234 - -///////////////////////////////////////////////////////////////////////////// -// AFX OLE control implementation - control IDs (AFX_IDC) - -// Font property page -#define AFX_IDC_FONTPROP 1000 -#define AFX_IDC_FONTNAMES 1001 -#define AFX_IDC_FONTSTYLES 1002 -#define AFX_IDC_FONTSIZES 1003 -#define AFX_IDC_STRIKEOUT 1004 -#define AFX_IDC_UNDERLINE 1005 -#define AFX_IDC_SAMPLEBOX 1006 - -// Color property page -#define AFX_IDC_COLOR_BLACK 1100 -#define AFX_IDC_COLOR_WHITE 1101 -#define AFX_IDC_COLOR_RED 1102 -#define AFX_IDC_COLOR_GREEN 1103 -#define AFX_IDC_COLOR_BLUE 1104 -#define AFX_IDC_COLOR_YELLOW 1105 -#define AFX_IDC_COLOR_MAGENTA 1106 -#define AFX_IDC_COLOR_CYAN 1107 -#define AFX_IDC_COLOR_GRAY 1108 -#define AFX_IDC_COLOR_LIGHTGRAY 1109 -#define AFX_IDC_COLOR_DARKRED 1110 -#define AFX_IDC_COLOR_DARKGREEN 1111 -#define AFX_IDC_COLOR_DARKBLUE 1112 -#define AFX_IDC_COLOR_LIGHTBROWN 1113 -#define AFX_IDC_COLOR_DARKMAGENTA 1114 -#define AFX_IDC_COLOR_DARKCYAN 1115 -#define AFX_IDC_COLORPROP 1116 -#define AFX_IDC_SYSTEMCOLORS 1117 - -// Picture porperty page -#define AFX_IDC_PROPNAME 1201 -#define AFX_IDC_PICTURE 1202 -#define AFX_IDC_BROWSE 1203 -#define AFX_IDC_CLEAR 1204 - -///////////////////////////////////////////////////////////////////////////// -// IDRs for OLE control standard components - -// Standard propery page dialogs app should leave alone (0x7E01->) -#define AFX_IDD_PROPPAGE_COLOR 32257 -#define AFX_IDD_PROPPAGE_FONT 32258 -#define AFX_IDD_PROPPAGE_PICTURE 32259 - -#define AFX_IDB_TRUETYPE 32384 - -///////////////////////////////////////////////////////////////////////////// -// Standard OLE control strings - -// OLE Control page strings -#define AFX_IDS_PROPPAGE_UNKNOWN 0xFE01 -#define AFX_IDS_COLOR_DESKTOP 0xFE04 -#define AFX_IDS_COLOR_APPWORKSPACE 0xFE05 -#define AFX_IDS_COLOR_WNDBACKGND 0xFE06 -#define AFX_IDS_COLOR_WNDTEXT 0xFE07 -#define AFX_IDS_COLOR_MENUBAR 0xFE08 -#define AFX_IDS_COLOR_MENUTEXT 0xFE09 -#define AFX_IDS_COLOR_ACTIVEBAR 0xFE0A -#define AFX_IDS_COLOR_INACTIVEBAR 0xFE0B -#define AFX_IDS_COLOR_ACTIVETEXT 0xFE0C -#define AFX_IDS_COLOR_INACTIVETEXT 0xFE0D -#define AFX_IDS_COLOR_ACTIVEBORDER 0xFE0E -#define AFX_IDS_COLOR_INACTIVEBORDER 0xFE0F -#define AFX_IDS_COLOR_WNDFRAME 0xFE10 -#define AFX_IDS_COLOR_SCROLLBARS 0xFE11 -#define AFX_IDS_COLOR_BTNFACE 0xFE12 -#define AFX_IDS_COLOR_BTNSHADOW 0xFE13 -#define AFX_IDS_COLOR_BTNTEXT 0xFE14 -#define AFX_IDS_COLOR_BTNHIGHLIGHT 0xFE15 -#define AFX_IDS_COLOR_DISABLEDTEXT 0xFE16 -#define AFX_IDS_COLOR_HIGHLIGHT 0xFE17 -#define AFX_IDS_COLOR_HIGHLIGHTTEXT 0xFE18 -#define AFX_IDS_REGULAR 0xFE19 -#define AFX_IDS_BOLD 0xFE1A -#define AFX_IDS_ITALIC 0xFE1B -#define AFX_IDS_BOLDITALIC 0xFE1C -#define AFX_IDS_SAMPLETEXT 0xFE1D -#define AFX_IDS_DISPLAYSTRING_FONT 0xFE1E -#define AFX_IDS_DISPLAYSTRING_COLOR 0xFE1F -#define AFX_IDS_DISPLAYSTRING_PICTURE 0xFE20 -#define AFX_IDS_PICTUREFILTER 0xFE21 -#define AFX_IDS_PICTYPE_UNKNOWN 0xFE22 -#define AFX_IDS_PICTYPE_NONE 0xFE23 -#define AFX_IDS_PICTYPE_BITMAP 0xFE24 -#define AFX_IDS_PICTYPE_METAFILE 0xFE25 -#define AFX_IDS_PICTYPE_ICON 0xFE26 -#define AFX_IDS_COLOR_PPG 0xFE28 -#define AFX_IDS_COLOR_PPG_CAPTION 0xFE29 -#define AFX_IDS_FONT_PPG 0xFE2A -#define AFX_IDS_FONT_PPG_CAPTION 0xFE2B -#define AFX_IDS_PICTURE_PPG 0xFE2C -#define AFX_IDS_PICTURE_PPG_CAPTION 0xFE2D -#define AFX_IDS_PICTUREBROWSETITLE 0xFE30 -#define AFX_IDS_BORDERSTYLE_0 0xFE31 -#define AFX_IDS_BORDERSTYLE_1 0xFE32 - -// OLE Control verb names -#define AFX_IDS_VERB_EDIT 0xFE40 -#define AFX_IDS_VERB_PROPERTIES 0xFE41 - -// OLE Control internal error messages -#define AFX_IDP_PICTURECANTOPEN 0xFE83 -#define AFX_IDP_PICTURECANTLOAD 0xFE84 -#define AFX_IDP_PICTURETOOLARGE 0xFE85 -#define AFX_IDP_PICTUREREADFAILED 0xFE86 - -// Standard OLE Control error strings -#define AFX_IDP_E_ILLEGALFUNCTIONCALL 0xFEA0 -#define AFX_IDP_E_OVERFLOW 0xFEA1 -#define AFX_IDP_E_OUTOFMEMORY 0xFEA2 -#define AFX_IDP_E_DIVISIONBYZERO 0xFEA3 -#define AFX_IDP_E_OUTOFSTRINGSPACE 0xFEA4 -#define AFX_IDP_E_OUTOFSTACKSPACE 0xFEA5 -#define AFX_IDP_E_BADFILENAMEORNUMBER 0xFEA6 -#define AFX_IDP_E_FILENOTFOUND 0xFEA7 -#define AFX_IDP_E_BADFILEMODE 0xFEA8 -#define AFX_IDP_E_FILEALREADYOPEN 0xFEA9 -#define AFX_IDP_E_DEVICEIOERROR 0xFEAA -#define AFX_IDP_E_FILEALREADYEXISTS 0xFEAB -#define AFX_IDP_E_BADRECORDLENGTH 0xFEAC -#define AFX_IDP_E_DISKFULL 0xFEAD -#define AFX_IDP_E_BADRECORDNUMBER 0xFEAE -#define AFX_IDP_E_BADFILENAME 0xFEAF -#define AFX_IDP_E_TOOMANYFILES 0xFEB0 -#define AFX_IDP_E_DEVICEUNAVAILABLE 0xFEB1 -#define AFX_IDP_E_PERMISSIONDENIED 0xFEB2 -#define AFX_IDP_E_DISKNOTREADY 0xFEB3 -#define AFX_IDP_E_PATHFILEACCESSERROR 0xFEB4 -#define AFX_IDP_E_PATHNOTFOUND 0xFEB5 -#define AFX_IDP_E_INVALIDPATTERNSTRING 0xFEB6 -#define AFX_IDP_E_INVALIDUSEOFNULL 0xFEB7 -#define AFX_IDP_E_INVALIDFILEFORMAT 0xFEB8 -#define AFX_IDP_E_INVALIDPROPERTYVALUE 0xFEB9 -#define AFX_IDP_E_INVALIDPROPERTYARRAYINDEX 0xFEBA -#define AFX_IDP_E_SETNOTSUPPORTEDATRUNTIME 0xFEBB -#define AFX_IDP_E_SETNOTSUPPORTED 0xFEBC -#define AFX_IDP_E_NEEDPROPERTYARRAYINDEX 0xFEBD -#define AFX_IDP_E_SETNOTPERMITTED 0xFEBE -#define AFX_IDP_E_GETNOTSUPPORTEDATRUNTIME 0xFEBF -#define AFX_IDP_E_GETNOTSUPPORTED 0xFEC0 -#define AFX_IDP_E_PROPERTYNOTFOUND 0xFEC1 -#define AFX_IDP_E_INVALIDCLIPBOARDFORMAT 0xFEC2 -#define AFX_IDP_E_INVALIDPICTURE 0xFEC3 -#define AFX_IDP_E_PRINTERERROR 0xFEC4 -#define AFX_IDP_E_CANTSAVEFILETOTEMP 0xFEC5 -#define AFX_IDP_E_SEARCHTEXTNOTFOUND 0xFEC6 -#define AFX_IDP_E_REPLACEMENTSTOOLONG 0xFEC7 - -///////////////////////////////////////////////////////////////////////////// - -#ifdef _AFX_MINREBUILD -#pragma component(minrebuild, on) -#endif - -#endif //__AFXRES_H__ - -///////////////////////////////////////////////////////////////////////////// +// This is a part of the Microsoft Foundation Classes C++ library. +// Copyright (C) 1992-2001 Microsoft Corporation +// All rights reserved. +// +// This source code is only intended as a supplement to the +// Microsoft Foundation Classes Reference and related +// electronic documentation provided with the library. +// See these sources for detailed information regarding the +// Microsoft Foundation Classes product. + +#ifndef __AFXRES_H__ +#define __AFXRES_H__ + +#ifdef RC_INVOKED +#ifndef _INC_WINDOWS +#define _INC_WINDOWS + #include "winresrc.h" // extract from windows header +#endif +#endif + +#ifdef _AFX_MINREBUILD +#pragma component(minrebuild, off) +#endif + +#ifdef APSTUDIO_INVOKED +#define APSTUDIO_HIDDEN_SYMBOLS +#endif + +///////////////////////////////////////////////////////////////////////////// +// MFC resource types (see Technical note TN024 for implementation details) + +#ifndef RC_INVOKED +#define RT_DLGINIT MAKEINTRESOURCE(240) +#define RT_TOOLBAR MAKEINTRESOURCE(241) +#endif + +///////////////////////////////////////////////////////////////////////////// + +#ifdef APSTUDIO_INVOKED +#undef APSTUDIO_HIDDEN_SYMBOLS +#endif + +///////////////////////////////////////////////////////////////////////////// +// General style bits etc + +// ControlBar styles +#define CBRS_ALIGN_LEFT 0x1000L +#define CBRS_ALIGN_TOP 0x2000L +#define CBRS_ALIGN_RIGHT 0x4000L +#define CBRS_ALIGN_BOTTOM 0x8000L +#define CBRS_ALIGN_ANY 0xF000L + +#define CBRS_BORDER_LEFT 0x0100L +#define CBRS_BORDER_TOP 0x0200L +#define CBRS_BORDER_RIGHT 0x0400L +#define CBRS_BORDER_BOTTOM 0x0800L +#define CBRS_BORDER_ANY 0x0F00L + +#define CBRS_TOOLTIPS 0x0010L +#define CBRS_FLYBY 0x0020L +#define CBRS_FLOAT_MULTI 0x0040L +#define CBRS_BORDER_3D 0x0080L +#define CBRS_HIDE_INPLACE 0x0008L +#define CBRS_SIZE_DYNAMIC 0x0004L +#define CBRS_SIZE_FIXED 0x0002L +#define CBRS_FLOATING 0x0001L + +#define CBRS_GRIPPER 0x00400000L + +#define CBRS_ORIENT_HORZ (CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM) +#define CBRS_ORIENT_VERT (CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT) +#define CBRS_ORIENT_ANY (CBRS_ORIENT_HORZ|CBRS_ORIENT_VERT) + +#define CBRS_ALL 0x0040FFFFL + +// the CBRS_ style is made up of an alignment style and a draw border style +// the alignment styles are mutually exclusive +// the draw border styles may be combined +#define CBRS_NOALIGN 0x00000000L +#define CBRS_LEFT (CBRS_ALIGN_LEFT|CBRS_BORDER_RIGHT) +#define CBRS_TOP (CBRS_ALIGN_TOP|CBRS_BORDER_BOTTOM) +#define CBRS_RIGHT (CBRS_ALIGN_RIGHT|CBRS_BORDER_LEFT) +#define CBRS_BOTTOM (CBRS_ALIGN_BOTTOM|CBRS_BORDER_TOP) + +///////////////////////////////////////////////////////////////////////////// +// Standard window components + +// Mode indicators in status bar - these are routed like commands +#define ID_INDICATOR_EXT 0xE700 // extended selection indicator +#define ID_INDICATOR_CAPS 0xE701 // cap lock indicator +#define ID_INDICATOR_NUM 0xE702 // num lock indicator +#define ID_INDICATOR_SCRL 0xE703 // scroll lock indicator +#define ID_INDICATOR_OVR 0xE704 // overtype mode indicator +#define ID_INDICATOR_REC 0xE705 // record mode indicator +#define ID_INDICATOR_KANA 0xE706 // kana lock indicator + +#define ID_SEPARATOR 0 // special separator value + +#ifndef RC_INVOKED // code only +// Standard control bars (IDW = window ID) +#define AFX_IDW_CONTROLBAR_FIRST 0xE800 +#define AFX_IDW_CONTROLBAR_LAST 0xE8FF + +#define AFX_IDW_TOOLBAR 0xE800 // main Toolbar for window +#define AFX_IDW_STATUS_BAR 0xE801 // Status bar window +#define AFX_IDW_PREVIEW_BAR 0xE802 // PrintPreview Dialog Bar +#define AFX_IDW_RESIZE_BAR 0xE803 // OLE in-place resize bar +#define AFX_IDW_REBAR 0xE804 // COMCTL32 "rebar" Bar +#define AFX_IDW_DIALOGBAR 0xE805 // CDialogBar + +// Note: If your application supports docking toolbars, you should +// not use the following IDs for your own toolbars. The IDs chosen +// are at the top of the first 32 such that the bars will be hidden +// while in print preview mode, and are not likely to conflict with +// IDs your application may have used succesfully in the past. + +#define AFX_IDW_DOCKBAR_TOP 0xE81B +#define AFX_IDW_DOCKBAR_LEFT 0xE81C +#define AFX_IDW_DOCKBAR_RIGHT 0xE81D +#define AFX_IDW_DOCKBAR_BOTTOM 0xE81E +#define AFX_IDW_DOCKBAR_FLOAT 0xE81F + +// Macro for mapping standard control bars to bitmask (limit of 32) +#define AFX_CONTROLBAR_MASK(nIDC) (1L << (nIDC - AFX_IDW_CONTROLBAR_FIRST)) + +// parts of Main Frame +#define AFX_IDW_PANE_FIRST 0xE900 // first pane (256 max) +#define AFX_IDW_PANE_LAST 0xE9ff +#define AFX_IDW_HSCROLL_FIRST 0xEA00 // first Horz scrollbar (16 max) +#define AFX_IDW_VSCROLL_FIRST 0xEA10 // first Vert scrollbar (16 max) + +#define AFX_IDW_SIZE_BOX 0xEA20 // size box for splitters +#define AFX_IDW_PANE_SAVE 0xEA21 // to shift AFX_IDW_PANE_FIRST +#endif //!RC_INVOKED + +#ifndef APSTUDIO_INVOKED + +// common style for form views +#define AFX_WS_DEFAULT_VIEW (WS_CHILD | WS_VISIBLE | WS_BORDER) + +#endif //!APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// +// Standard app configurable strings + +// for application title (defaults to EXE name or name in constructor) +#define AFX_IDS_APP_TITLE 0xE000 +// idle message bar line +#define AFX_IDS_IDLEMESSAGE 0xE001 +// message bar line when in shift-F1 help mode +#define AFX_IDS_HELPMODEMESSAGE 0xE002 +// document title when editing OLE embedding +#define AFX_IDS_APP_TITLE_EMBEDDING 0xE003 +// company name +#define AFX_IDS_COMPANY_NAME 0xE004 +// object name when server is inplace +#define AFX_IDS_OBJ_TITLE_INPLACE 0xE005 + +///////////////////////////////////////////////////////////////////////////// +// Standard Commands + +// File commands +#define ID_FILE_NEW 0xE100 +#define ID_FILE_OPEN 0xE101 +#define ID_FILE_CLOSE 0xE102 +#define ID_FILE_SAVE 0xE103 +#define ID_FILE_SAVE_AS 0xE104 +#define ID_FILE_PAGE_SETUP 0xE105 +#define ID_FILE_PRINT_SETUP 0xE106 +#define ID_FILE_PRINT 0xE107 +#define ID_FILE_PRINT_DIRECT 0xE108 +#define ID_FILE_PRINT_PREVIEW 0xE109 +#define ID_FILE_UPDATE 0xE10A +#define ID_FILE_SAVE_COPY_AS 0xE10B +#define ID_FILE_SEND_MAIL 0xE10C +#define ID_FILE_NEW_FRAME 0xE10D + +#define ID_FILE_MRU_FIRST 0xE110 +#define ID_FILE_MRU_FILE1 0xE110 // range - 16 max +#define ID_FILE_MRU_FILE2 0xE111 +#define ID_FILE_MRU_FILE3 0xE112 +#define ID_FILE_MRU_FILE4 0xE113 +#define ID_FILE_MRU_FILE5 0xE114 +#define ID_FILE_MRU_FILE6 0xE115 +#define ID_FILE_MRU_FILE7 0xE116 +#define ID_FILE_MRU_FILE8 0xE117 +#define ID_FILE_MRU_FILE9 0xE118 +#define ID_FILE_MRU_FILE10 0xE119 +#define ID_FILE_MRU_FILE11 0xE11A +#define ID_FILE_MRU_FILE12 0xE11B +#define ID_FILE_MRU_FILE13 0xE11C +#define ID_FILE_MRU_FILE14 0xE11D +#define ID_FILE_MRU_FILE15 0xE11E +#define ID_FILE_MRU_FILE16 0xE11F +#define ID_FILE_MRU_LAST 0xE11F + +// Edit commands +#define ID_EDIT_CLEAR 0xE120 +#define ID_EDIT_CLEAR_ALL 0xE121 +#define ID_EDIT_COPY 0xE122 +#define ID_EDIT_CUT 0xE123 +#define ID_EDIT_FIND 0xE124 +#define ID_EDIT_PASTE 0xE125 +#define ID_EDIT_PASTE_LINK 0xE126 +#define ID_EDIT_PASTE_SPECIAL 0xE127 +#define ID_EDIT_REPEAT 0xE128 +#define ID_EDIT_REPLACE 0xE129 +#define ID_EDIT_SELECT_ALL 0xE12A +#define ID_EDIT_UNDO 0xE12B +#define ID_EDIT_REDO 0xE12C + +// Window commands +#define ID_WINDOW_NEW 0xE130 +#define ID_WINDOW_ARRANGE 0xE131 +#define ID_WINDOW_CASCADE 0xE132 +#define ID_WINDOW_TILE_HORZ 0xE133 +#define ID_WINDOW_TILE_VERT 0xE134 +#define ID_WINDOW_SPLIT 0xE135 +#ifndef RC_INVOKED // code only +#define AFX_IDM_WINDOW_FIRST 0xE130 +#define AFX_IDM_WINDOW_LAST 0xE13F +#define AFX_IDM_FIRST_MDICHILD 0xFF00 // window list starts here +#endif //!RC_INVOKED + +// Help and App commands +#define ID_APP_ABOUT 0xE140 +#define ID_APP_EXIT 0xE141 +#define ID_HELP_INDEX 0xE142 +#define ID_HELP_FINDER 0xE143 +#define ID_HELP_USING 0xE144 +#define ID_CONTEXT_HELP 0xE145 // shift-F1 +// special commands for processing help +#define ID_HELP 0xE146 // first attempt for F1 +#define ID_DEFAULT_HELP 0xE147 // last attempt + +// Misc +#define ID_NEXT_PANE 0xE150 +#define ID_PREV_PANE 0xE151 + +// Format +#define ID_FORMAT_FONT 0xE160 + +// OLE commands +#define ID_OLE_INSERT_NEW 0xE200 +#define ID_OLE_EDIT_LINKS 0xE201 +#define ID_OLE_EDIT_CONVERT 0xE202 +#define ID_OLE_EDIT_CHANGE_ICON 0xE203 +#define ID_OLE_EDIT_PROPERTIES 0xE204 +#define ID_OLE_VERB_FIRST 0xE210 // range - 16 max +#ifndef RC_INVOKED // code only +#define ID_OLE_VERB_LAST 0xE21F +#endif //!RC_INVOKED + +// for print preview dialog bar +#define AFX_ID_PREVIEW_CLOSE 0xE300 +#define AFX_ID_PREVIEW_NUMPAGE 0xE301 // One/Two Page button +#define AFX_ID_PREVIEW_NEXT 0xE302 +#define AFX_ID_PREVIEW_PREV 0xE303 +#define AFX_ID_PREVIEW_PRINT 0xE304 +#define AFX_ID_PREVIEW_ZOOMIN 0xE305 +#define AFX_ID_PREVIEW_ZOOMOUT 0xE306 + +// View commands (same number used as IDW used for control bar) +#define ID_VIEW_TOOLBAR 0xE800 +#define ID_VIEW_STATUS_BAR 0xE801 +#define ID_VIEW_REBAR 0xE804 +#define ID_VIEW_AUTOARRANGE 0xE805 + // E810 -> E81F must be kept in order for RANGE macros +#define ID_VIEW_SMALLICON 0xE810 +#define ID_VIEW_LARGEICON 0xE811 +#define ID_VIEW_LIST 0xE812 +#define ID_VIEW_DETAILS 0xE813 +#define ID_VIEW_LINEUP 0xE814 +#define ID_VIEW_BYNAME 0xE815 +#define AFX_ID_VIEW_MINIMUM ID_VIEW_SMALLICON +#define AFX_ID_VIEW_MAXIMUM ID_VIEW_BYNAME + // E800 -> E8FF reserved for other control bar commands + +// RecordForm commands +#define ID_RECORD_FIRST 0xE900 +#define ID_RECORD_LAST 0xE901 +#define ID_RECORD_NEXT 0xE902 +#define ID_RECORD_PREV 0xE903 + +///////////////////////////////////////////////////////////////////////////// +// Standard control IDs + +#ifdef IDC_STATIC +#undef IDC_STATIC +#endif +#define IDC_STATIC (-1) // all static controls + +///////////////////////////////////////////////////////////////////////////// +// Standard string error/warnings + +#ifndef RC_INVOKED // code only +#define AFX_IDS_SCFIRST 0xEF00 +#endif //!RC_INVOKED + +#define AFX_IDS_SCSIZE 0xEF00 +#define AFX_IDS_SCMOVE 0xEF01 +#define AFX_IDS_SCMINIMIZE 0xEF02 +#define AFX_IDS_SCMAXIMIZE 0xEF03 +#define AFX_IDS_SCNEXTWINDOW 0xEF04 +#define AFX_IDS_SCPREVWINDOW 0xEF05 +#define AFX_IDS_SCCLOSE 0xEF06 +#define AFX_IDS_SCRESTORE 0xEF12 +#define AFX_IDS_SCTASKLIST 0xEF13 + +#define AFX_IDS_MDICHILD 0xEF1F + +#define AFX_IDS_DESKACCESSORY 0xEFDA + +// General strings +#define AFX_IDS_OPENFILE 0xF000 +#define AFX_IDS_SAVEFILE 0xF001 +#define AFX_IDS_ALLFILTER 0xF002 +#define AFX_IDS_UNTITLED 0xF003 +#define AFX_IDS_SAVEFILECOPY 0xF004 +#define AFX_IDS_PREVIEW_CLOSE 0xF005 +#define AFX_IDS_UNNAMED_FILE 0xF006 +#define AFX_IDS_HIDE 0xF011 + +// MFC Standard Exception Error messages +#define AFX_IDP_NO_ERROR_AVAILABLE 0xF020 +#define AFX_IDS_NOT_SUPPORTED_EXCEPTION 0xF021 +#define AFX_IDS_RESOURCE_EXCEPTION 0xF022 +#define AFX_IDS_MEMORY_EXCEPTION 0xF023 +#define AFX_IDS_USER_EXCEPTION 0xF024 + +// Printing and print preview strings +#define AFX_IDS_PRINTONPORT 0xF040 +#define AFX_IDS_ONEPAGE 0xF041 +#define AFX_IDS_TWOPAGE 0xF042 +#define AFX_IDS_PRINTPAGENUM 0xF043 +#define AFX_IDS_PREVIEWPAGEDESC 0xF044 +#define AFX_IDS_PRINTDEFAULTEXT 0xF045 +#define AFX_IDS_PRINTDEFAULT 0xF046 +#define AFX_IDS_PRINTFILTER 0xF047 +#define AFX_IDS_PRINTCAPTION 0xF048 +#define AFX_IDS_PRINTTOFILE 0xF049 + + +// OLE strings +#define AFX_IDS_OBJECT_MENUITEM 0xF080 +#define AFX_IDS_EDIT_VERB 0xF081 +#define AFX_IDS_ACTIVATE_VERB 0xF082 +#define AFX_IDS_CHANGE_LINK 0xF083 +#define AFX_IDS_AUTO 0xF084 +#define AFX_IDS_MANUAL 0xF085 +#define AFX_IDS_FROZEN 0xF086 +#define AFX_IDS_ALL_FILES 0xF087 +// dynamically changing menu items +#define AFX_IDS_SAVE_MENU 0xF088 +#define AFX_IDS_UPDATE_MENU 0xF089 +#define AFX_IDS_SAVE_AS_MENU 0xF08A +#define AFX_IDS_SAVE_COPY_AS_MENU 0xF08B +#define AFX_IDS_EXIT_MENU 0xF08C +#define AFX_IDS_UPDATING_ITEMS 0xF08D +// COlePasteSpecialDialog defines +#define AFX_IDS_METAFILE_FORMAT 0xF08E +#define AFX_IDS_DIB_FORMAT 0xF08F +#define AFX_IDS_BITMAP_FORMAT 0xF090 +#define AFX_IDS_LINKSOURCE_FORMAT 0xF091 +#define AFX_IDS_EMBED_FORMAT 0xF092 +// other OLE utility strings +#define AFX_IDS_PASTELINKEDTYPE 0xF094 +#define AFX_IDS_UNKNOWNTYPE 0xF095 +#define AFX_IDS_RTF_FORMAT 0xF096 +#define AFX_IDS_TEXT_FORMAT 0xF097 +// OLE datatype format error strings +#define AFX_IDS_INVALID_CURRENCY 0xF098 +#define AFX_IDS_INVALID_DATETIME 0xF099 +#define AFX_IDS_INVALID_DATETIMESPAN 0xF09A + +// General error / prompt strings +#define AFX_IDP_INVALID_FILENAME 0xF100 +#define AFX_IDP_FAILED_TO_OPEN_DOC 0xF101 +#define AFX_IDP_FAILED_TO_SAVE_DOC 0xF102 +#define AFX_IDP_ASK_TO_SAVE 0xF103 +#define AFX_IDP_FAILED_TO_CREATE_DOC 0xF104 +#define AFX_IDP_FILE_TOO_LARGE 0xF105 +#define AFX_IDP_FAILED_TO_START_PRINT 0xF106 +#define AFX_IDP_FAILED_TO_LAUNCH_HELP 0xF107 +#define AFX_IDP_INTERNAL_FAILURE 0xF108 // general failure +#define AFX_IDP_COMMAND_FAILURE 0xF109 // command failure +#define AFX_IDP_FAILED_MEMORY_ALLOC 0xF10A +#define AFX_IDP_UNREG_DONE 0xF10B +#define AFX_IDP_UNREG_FAILURE 0xF10C +#define AFX_IDP_DLL_LOAD_FAILED 0xF10D +#define AFX_IDP_DLL_BAD_VERSION 0xF10E + +// DDV parse errors +#define AFX_IDP_PARSE_INT 0xF110 +#define AFX_IDP_PARSE_REAL 0xF111 +#define AFX_IDP_PARSE_INT_RANGE 0xF112 +#define AFX_IDP_PARSE_REAL_RANGE 0xF113 +#define AFX_IDP_PARSE_STRING_SIZE 0xF114 +#define AFX_IDP_PARSE_RADIO_BUTTON 0xF115 +#define AFX_IDP_PARSE_BYTE 0xF116 +#define AFX_IDP_PARSE_UINT 0xF117 +#define AFX_IDP_PARSE_DATETIME 0xF118 +#define AFX_IDP_PARSE_CURRENCY 0xF119 +#define AFX_IDP_PARSE_GUID 0xF11A +#define AFX_IDP_PARSE_TIME 0xF11B +#define AFX_IDP_PARSE_DATE 0xF11C + +// CFile/CArchive error strings for user failure +#define AFX_IDP_FAILED_INVALID_FORMAT 0xF120 +#define AFX_IDP_FAILED_INVALID_PATH 0xF121 +#define AFX_IDP_FAILED_DISK_FULL 0xF122 +#define AFX_IDP_FAILED_ACCESS_READ 0xF123 +#define AFX_IDP_FAILED_ACCESS_WRITE 0xF124 +#define AFX_IDP_FAILED_IO_ERROR_READ 0xF125 +#define AFX_IDP_FAILED_IO_ERROR_WRITE 0xF126 + +// Script errors / prompt strings +#define AFX_IDP_SCRIPT_ERROR 0xF130 +#define AFX_IDP_SCRIPT_DISPATCH_EXCEPTION 0xF131 + +// OLE errors / prompt strings +#define AFX_IDP_STATIC_OBJECT 0xF180 +#define AFX_IDP_FAILED_TO_CONNECT 0xF181 +#define AFX_IDP_SERVER_BUSY 0xF182 +#define AFX_IDP_BAD_VERB 0xF183 +#define AFX_IDS_NOT_DOCOBJECT 0xF184 +#define AFX_IDP_FAILED_TO_NOTIFY 0xF185 +#define AFX_IDP_FAILED_TO_LAUNCH 0xF186 +#define AFX_IDP_ASK_TO_UPDATE 0xF187 +#define AFX_IDP_FAILED_TO_UPDATE 0xF188 +#define AFX_IDP_FAILED_TO_REGISTER 0xF189 +#define AFX_IDP_FAILED_TO_AUTO_REGISTER 0xF18A +#define AFX_IDP_FAILED_TO_CONVERT 0xF18B +#define AFX_IDP_GET_NOT_SUPPORTED 0xF18C +#define AFX_IDP_SET_NOT_SUPPORTED 0xF18D +#define AFX_IDP_ASK_TO_DISCARD 0xF18E +#define AFX_IDP_FAILED_TO_CREATE 0xF18F + +// MAPI errors / prompt strings +#define AFX_IDP_FAILED_MAPI_LOAD 0xF190 +#define AFX_IDP_INVALID_MAPI_DLL 0xF191 +#define AFX_IDP_FAILED_MAPI_SEND 0xF192 + +#define AFX_IDP_FILE_NONE 0xF1A0 +#define AFX_IDP_FILE_GENERIC 0xF1A1 +#define AFX_IDP_FILE_NOT_FOUND 0xF1A2 +#define AFX_IDP_FILE_BAD_PATH 0xF1A3 +#define AFX_IDP_FILE_TOO_MANY_OPEN 0xF1A4 +#define AFX_IDP_FILE_ACCESS_DENIED 0xF1A5 +#define AFX_IDP_FILE_INVALID_FILE 0xF1A6 +#define AFX_IDP_FILE_REMOVE_CURRENT 0xF1A7 +#define AFX_IDP_FILE_DIR_FULL 0xF1A8 +#define AFX_IDP_FILE_BAD_SEEK 0xF1A9 +#define AFX_IDP_FILE_HARD_IO 0xF1AA +#define AFX_IDP_FILE_SHARING 0xF1AB +#define AFX_IDP_FILE_LOCKING 0xF1AC +#define AFX_IDP_FILE_DISKFULL 0xF1AD +#define AFX_IDP_FILE_EOF 0xF1AE + +#define AFX_IDP_ARCH_NONE 0xF1B0 +#define AFX_IDP_ARCH_GENERIC 0xF1B1 +#define AFX_IDP_ARCH_READONLY 0xF1B2 +#define AFX_IDP_ARCH_ENDOFFILE 0xF1B3 +#define AFX_IDP_ARCH_WRITEONLY 0xF1B4 +#define AFX_IDP_ARCH_BADINDEX 0xF1B5 +#define AFX_IDP_ARCH_BADCLASS 0xF1B6 +#define AFX_IDP_ARCH_BADSCHEMA 0xF1B7 + +#define AFX_IDS_OCC_SCALEUNITS_PIXELS 0xF1C0 + +// 0xf200-0xf20f reserved + +// font names and point sizes +#define AFX_IDS_STATUS_FONT 0xF230 +#define AFX_IDS_TOOLTIP_FONT 0xF231 +#define AFX_IDS_UNICODE_FONT 0xF232 +#define AFX_IDS_MINI_FONT 0xF233 + +// ODBC Database errors / prompt strings +#ifndef RC_INVOKED // code only +#define AFX_IDP_SQL_FIRST 0xF280 +#endif //!RC_INVOKED +#define AFX_IDP_SQL_CONNECT_FAIL 0xF281 +#define AFX_IDP_SQL_RECORDSET_FORWARD_ONLY 0xF282 +#define AFX_IDP_SQL_EMPTY_COLUMN_LIST 0xF283 +#define AFX_IDP_SQL_FIELD_SCHEMA_MISMATCH 0xF284 +#define AFX_IDP_SQL_ILLEGAL_MODE 0xF285 +#define AFX_IDP_SQL_MULTIPLE_ROWS_AFFECTED 0xF286 +#define AFX_IDP_SQL_NO_CURRENT_RECORD 0xF287 +#define AFX_IDP_SQL_NO_ROWS_AFFECTED 0xF288 +#define AFX_IDP_SQL_RECORDSET_READONLY 0xF289 +#define AFX_IDP_SQL_SQL_NO_TOTAL 0xF28A +#define AFX_IDP_SQL_ODBC_LOAD_FAILED 0xF28B +#define AFX_IDP_SQL_DYNASET_NOT_SUPPORTED 0xF28C +#define AFX_IDP_SQL_SNAPSHOT_NOT_SUPPORTED 0xF28D +#define AFX_IDP_SQL_API_CONFORMANCE 0xF28E +#define AFX_IDP_SQL_SQL_CONFORMANCE 0xF28F +#define AFX_IDP_SQL_NO_DATA_FOUND 0xF290 +#define AFX_IDP_SQL_ROW_UPDATE_NOT_SUPPORTED 0xF291 +#define AFX_IDP_SQL_ODBC_V2_REQUIRED 0xF292 +#define AFX_IDP_SQL_NO_POSITIONED_UPDATES 0xF293 +#define AFX_IDP_SQL_LOCK_MODE_NOT_SUPPORTED 0xF294 +#define AFX_IDP_SQL_DATA_TRUNCATED 0xF295 +#define AFX_IDP_SQL_ROW_FETCH 0xF296 +#define AFX_IDP_SQL_INCORRECT_ODBC 0xF297 +#define AFX_IDP_SQL_UPDATE_DELETE_FAILED 0xF298 +#define AFX_IDP_SQL_DYNAMIC_CURSOR_NOT_SUPPORTED 0xF299 +#define AFX_IDP_SQL_FIELD_NOT_FOUND 0xF29A +#define AFX_IDP_SQL_BOOKMARKS_NOT_SUPPORTED 0xF29B +#define AFX_IDP_SQL_BOOKMARKS_NOT_ENABLED 0xF29C + +// ODBC Database strings +#define AFX_IDS_DELETED 0xF29D + +// DAO Database errors / prompt strings +#ifndef RC_INVOKED // code only +#define AFX_IDP_DAO_FIRST 0xF2B0 +#endif //!RC_INVOKED +#define AFX_IDP_DAO_ENGINE_INITIALIZATION 0xF2B0 +#define AFX_IDP_DAO_DFX_BIND 0xF2B1 +#define AFX_IDP_DAO_OBJECT_NOT_OPEN 0xF2B2 + +// ICDAORecordset::GetRows Errors +// These are not placed in DAO Errors collection +// and must be handled directly by MFC. +#define AFX_IDP_DAO_ROWTOOSHORT 0xF2B3 +#define AFX_IDP_DAO_BADBINDINFO 0xF2B4 +#define AFX_IDP_DAO_COLUMNUNAVAILABLE 0xF2B5 + +///////////////////////////////////////////////////////////////////////////// +// Strings for ISAPI support + +#define AFX_IDS_HTTP_TITLE 0xF2D1 +#define AFX_IDS_HTTP_NO_TEXT 0xF2D2 +#define AFX_IDS_HTTP_BAD_REQUEST 0xF2D3 +#define AFX_IDS_HTTP_AUTH_REQUIRED 0xF2D4 +#define AFX_IDS_HTTP_FORBIDDEN 0xF2D5 +#define AFX_IDS_HTTP_NOT_FOUND 0xF2D6 +#define AFX_IDS_HTTP_SERVER_ERROR 0xF2D7 +#define AFX_IDS_HTTP_NOT_IMPLEMENTED 0xF2D8 + +///////////////////////////////////////////////////////////////////////////// +// Strings for Accessibility support for CCheckListBox +#define AFX_IDS_CHECKLISTBOX_UNCHECK 0xF2E1 +#define AFX_IDS_CHECKLISTBOX_CHECK 0xF2E2 +#define AFX_IDS_CHECKLISTBOX_MIXED 0xF2E3 + +///////////////////////////////////////////////////////////////////////////// +// AFX implementation - control IDs (AFX_IDC) + +// Parts of dialogs +#define AFX_IDC_LISTBOX 100 +#define AFX_IDC_CHANGE 101 +#define AFX_IDC_BROWSER 102 + +// for print dialog +#define AFX_IDC_PRINT_DOCNAME 201 +#define AFX_IDC_PRINT_PRINTERNAME 202 +#define AFX_IDC_PRINT_PORTNAME 203 +#define AFX_IDC_PRINT_PAGENUM 204 + +// Property Sheet control id's (determined with Spy++) +#define ID_APPLY_NOW 0x3021 +#define ID_WIZBACK 0x3023 +#define ID_WIZNEXT 0x3024 +#define ID_WIZFINISH 0x3025 +#define AFX_IDC_TAB_CONTROL 0x3020 + +///////////////////////////////////////////////////////////////////////////// +// IDRs for standard components + +#ifndef RC_INVOKED // code only +// These are really COMMDLG dialogs, so there usually isn't a resource +// for them, but these IDs are used as help IDs. +#define AFX_IDD_FILEOPEN 28676 +#define AFX_IDD_FILESAVE 28677 +#define AFX_IDD_FONT 28678 +#define AFX_IDD_COLOR 28679 +#define AFX_IDD_PRINT 28680 +#define AFX_IDD_PRINTSETUP 28681 +#define AFX_IDD_FIND 28682 +#define AFX_IDD_REPLACE 28683 +#endif //!RC_INVOKED + +// Standard dialogs app should leave alone (0x7801->) +#define AFX_IDD_NEWTYPEDLG 30721 +#define AFX_IDD_PRINTDLG 30722 +#define AFX_IDD_PREVIEW_TOOLBAR 30723 + +// Dialogs defined for OLE2UI library +#define AFX_IDD_INSERTOBJECT 30724 +#define AFX_IDD_CHANGEICON 30725 +#define AFX_IDD_CONVERT 30726 +#define AFX_IDD_PASTESPECIAL 30727 +#define AFX_IDD_EDITLINKS 30728 +#define AFX_IDD_FILEBROWSE 30729 +#define AFX_IDD_BUSY 30730 + +#define AFX_IDD_OBJECTPROPERTIES 30732 +#define AFX_IDD_CHANGESOURCE 30733 + +// Standard cursors (0x7901->) + // AFX_IDC = Cursor resources +#define AFX_IDC_CONTEXTHELP 30977 // context sensitive help +#define AFX_IDC_MAGNIFY 30978 // print preview zoom +#define AFX_IDC_SMALLARROWS 30979 // splitter +#define AFX_IDC_HSPLITBAR 30980 // splitter +#define AFX_IDC_VSPLITBAR 30981 // splitter +#define AFX_IDC_NODROPCRSR 30982 // No Drop Cursor +#define AFX_IDC_TRACKNWSE 30983 // tracker +#define AFX_IDC_TRACKNESW 30984 // tracker +#define AFX_IDC_TRACKNS 30985 // tracker +#define AFX_IDC_TRACKWE 30986 // tracker +#define AFX_IDC_TRACK4WAY 30987 // tracker +#define AFX_IDC_MOVE4WAY 30988 // resize bar (server only) + +// Wheel mouse cursors +// NOTE: values must be in this order! See CScrollView::OnTimer() +#define AFX_IDC_MOUSE_PAN_NW 30998 // pan east +#define AFX_IDC_MOUSE_PAN_N 30999 // pan northeast +#define AFX_IDC_MOUSE_PAN_NE 31000 // pan north +#define AFX_IDC_MOUSE_PAN_W 31001 // pan northwest +#define AFX_IDC_MOUSE_PAN_HV 31002 // pan both axis +#define AFX_IDC_MOUSE_PAN_E 31003 // pan west +#define AFX_IDC_MOUSE_PAN_SW 31004 // pan south-west +#define AFX_IDC_MOUSE_PAN_S 31005 // pan south +#define AFX_IDC_MOUSE_PAN_SE 31006 // pan south-east +#define AFX_IDC_MOUSE_PAN_HORZ 31007 // pan X-axis +#define AFX_IDC_MOUSE_PAN_VERT 31008 // pan Y-axis + +// Wheel mouse bitmaps +#define AFX_IDC_MOUSE_ORG_HORZ 31009 // anchor for horz only +#define AFX_IDC_MOUSE_ORG_VERT 31010 // anchor for vert only +#define AFX_IDC_MOUSE_ORG_HV 31011 // anchor for horz/vert +#define AFX_IDC_MOUSE_MASK 31012 + +// Mini frame window bitmap ID +#define AFX_IDB_MINIFRAME_MENU 30994 + +// CheckListBox checks bitmap ID +#define AFX_IDB_CHECKLISTBOX_95 30996 + +// AFX standard accelerator resources +#define AFX_IDR_PREVIEW_ACCEL 30997 + +// AFX standard ICON IDs (for MFC V1 apps) (0x7A01->) +#define AFX_IDI_STD_MDIFRAME 31233 +#define AFX_IDI_STD_FRAME 31234 + +///////////////////////////////////////////////////////////////////////////// +// AFX OLE control implementation - control IDs (AFX_IDC) + +// Font property page +#define AFX_IDC_FONTPROP 1000 +#define AFX_IDC_FONTNAMES 1001 +#define AFX_IDC_FONTSTYLES 1002 +#define AFX_IDC_FONTSIZES 1003 +#define AFX_IDC_STRIKEOUT 1004 +#define AFX_IDC_UNDERLINE 1005 +#define AFX_IDC_SAMPLEBOX 1006 + +// Color property page +#define AFX_IDC_COLOR_BLACK 1100 +#define AFX_IDC_COLOR_WHITE 1101 +#define AFX_IDC_COLOR_RED 1102 +#define AFX_IDC_COLOR_GREEN 1103 +#define AFX_IDC_COLOR_BLUE 1104 +#define AFX_IDC_COLOR_YELLOW 1105 +#define AFX_IDC_COLOR_MAGENTA 1106 +#define AFX_IDC_COLOR_CYAN 1107 +#define AFX_IDC_COLOR_GRAY 1108 +#define AFX_IDC_COLOR_LIGHTGRAY 1109 +#define AFX_IDC_COLOR_DARKRED 1110 +#define AFX_IDC_COLOR_DARKGREEN 1111 +#define AFX_IDC_COLOR_DARKBLUE 1112 +#define AFX_IDC_COLOR_LIGHTBROWN 1113 +#define AFX_IDC_COLOR_DARKMAGENTA 1114 +#define AFX_IDC_COLOR_DARKCYAN 1115 +#define AFX_IDC_COLORPROP 1116 +#define AFX_IDC_SYSTEMCOLORS 1117 + +// Picture porperty page +#define AFX_IDC_PROPNAME 1201 +#define AFX_IDC_PICTURE 1202 +#define AFX_IDC_BROWSE 1203 +#define AFX_IDC_CLEAR 1204 + +///////////////////////////////////////////////////////////////////////////// +// IDRs for OLE control standard components + +// Standard propery page dialogs app should leave alone (0x7E01->) +#define AFX_IDD_PROPPAGE_COLOR 32257 +#define AFX_IDD_PROPPAGE_FONT 32258 +#define AFX_IDD_PROPPAGE_PICTURE 32259 + +#define AFX_IDB_TRUETYPE 32384 + +///////////////////////////////////////////////////////////////////////////// +// Standard OLE control strings + +// OLE Control page strings +#define AFX_IDS_PROPPAGE_UNKNOWN 0xFE01 +#define AFX_IDS_COLOR_DESKTOP 0xFE04 +#define AFX_IDS_COLOR_APPWORKSPACE 0xFE05 +#define AFX_IDS_COLOR_WNDBACKGND 0xFE06 +#define AFX_IDS_COLOR_WNDTEXT 0xFE07 +#define AFX_IDS_COLOR_MENUBAR 0xFE08 +#define AFX_IDS_COLOR_MENUTEXT 0xFE09 +#define AFX_IDS_COLOR_ACTIVEBAR 0xFE0A +#define AFX_IDS_COLOR_INACTIVEBAR 0xFE0B +#define AFX_IDS_COLOR_ACTIVETEXT 0xFE0C +#define AFX_IDS_COLOR_INACTIVETEXT 0xFE0D +#define AFX_IDS_COLOR_ACTIVEBORDER 0xFE0E +#define AFX_IDS_COLOR_INACTIVEBORDER 0xFE0F +#define AFX_IDS_COLOR_WNDFRAME 0xFE10 +#define AFX_IDS_COLOR_SCROLLBARS 0xFE11 +#define AFX_IDS_COLOR_BTNFACE 0xFE12 +#define AFX_IDS_COLOR_BTNSHADOW 0xFE13 +#define AFX_IDS_COLOR_BTNTEXT 0xFE14 +#define AFX_IDS_COLOR_BTNHIGHLIGHT 0xFE15 +#define AFX_IDS_COLOR_DISABLEDTEXT 0xFE16 +#define AFX_IDS_COLOR_HIGHLIGHT 0xFE17 +#define AFX_IDS_COLOR_HIGHLIGHTTEXT 0xFE18 +#define AFX_IDS_REGULAR 0xFE19 +#define AFX_IDS_BOLD 0xFE1A +#define AFX_IDS_ITALIC 0xFE1B +#define AFX_IDS_BOLDITALIC 0xFE1C +#define AFX_IDS_SAMPLETEXT 0xFE1D +#define AFX_IDS_DISPLAYSTRING_FONT 0xFE1E +#define AFX_IDS_DISPLAYSTRING_COLOR 0xFE1F +#define AFX_IDS_DISPLAYSTRING_PICTURE 0xFE20 +#define AFX_IDS_PICTUREFILTER 0xFE21 +#define AFX_IDS_PICTYPE_UNKNOWN 0xFE22 +#define AFX_IDS_PICTYPE_NONE 0xFE23 +#define AFX_IDS_PICTYPE_BITMAP 0xFE24 +#define AFX_IDS_PICTYPE_METAFILE 0xFE25 +#define AFX_IDS_PICTYPE_ICON 0xFE26 +#define AFX_IDS_COLOR_PPG 0xFE28 +#define AFX_IDS_COLOR_PPG_CAPTION 0xFE29 +#define AFX_IDS_FONT_PPG 0xFE2A +#define AFX_IDS_FONT_PPG_CAPTION 0xFE2B +#define AFX_IDS_PICTURE_PPG 0xFE2C +#define AFX_IDS_PICTURE_PPG_CAPTION 0xFE2D +#define AFX_IDS_PICTUREBROWSETITLE 0xFE30 +#define AFX_IDS_BORDERSTYLE_0 0xFE31 +#define AFX_IDS_BORDERSTYLE_1 0xFE32 + +// OLE Control verb names +#define AFX_IDS_VERB_EDIT 0xFE40 +#define AFX_IDS_VERB_PROPERTIES 0xFE41 + +// OLE Control internal error messages +#define AFX_IDP_PICTURECANTOPEN 0xFE83 +#define AFX_IDP_PICTURECANTLOAD 0xFE84 +#define AFX_IDP_PICTURETOOLARGE 0xFE85 +#define AFX_IDP_PICTUREREADFAILED 0xFE86 + +// Standard OLE Control error strings +#define AFX_IDP_E_ILLEGALFUNCTIONCALL 0xFEA0 +#define AFX_IDP_E_OVERFLOW 0xFEA1 +#define AFX_IDP_E_OUTOFMEMORY 0xFEA2 +#define AFX_IDP_E_DIVISIONBYZERO 0xFEA3 +#define AFX_IDP_E_OUTOFSTRINGSPACE 0xFEA4 +#define AFX_IDP_E_OUTOFSTACKSPACE 0xFEA5 +#define AFX_IDP_E_BADFILENAMEORNUMBER 0xFEA6 +#define AFX_IDP_E_FILENOTFOUND 0xFEA7 +#define AFX_IDP_E_BADFILEMODE 0xFEA8 +#define AFX_IDP_E_FILEALREADYOPEN 0xFEA9 +#define AFX_IDP_E_DEVICEIOERROR 0xFEAA +#define AFX_IDP_E_FILEALREADYEXISTS 0xFEAB +#define AFX_IDP_E_BADRECORDLENGTH 0xFEAC +#define AFX_IDP_E_DISKFULL 0xFEAD +#define AFX_IDP_E_BADRECORDNUMBER 0xFEAE +#define AFX_IDP_E_BADFILENAME 0xFEAF +#define AFX_IDP_E_TOOMANYFILES 0xFEB0 +#define AFX_IDP_E_DEVICEUNAVAILABLE 0xFEB1 +#define AFX_IDP_E_PERMISSIONDENIED 0xFEB2 +#define AFX_IDP_E_DISKNOTREADY 0xFEB3 +#define AFX_IDP_E_PATHFILEACCESSERROR 0xFEB4 +#define AFX_IDP_E_PATHNOTFOUND 0xFEB5 +#define AFX_IDP_E_INVALIDPATTERNSTRING 0xFEB6 +#define AFX_IDP_E_INVALIDUSEOFNULL 0xFEB7 +#define AFX_IDP_E_INVALIDFILEFORMAT 0xFEB8 +#define AFX_IDP_E_INVALIDPROPERTYVALUE 0xFEB9 +#define AFX_IDP_E_INVALIDPROPERTYARRAYINDEX 0xFEBA +#define AFX_IDP_E_SETNOTSUPPORTEDATRUNTIME 0xFEBB +#define AFX_IDP_E_SETNOTSUPPORTED 0xFEBC +#define AFX_IDP_E_NEEDPROPERTYARRAYINDEX 0xFEBD +#define AFX_IDP_E_SETNOTPERMITTED 0xFEBE +#define AFX_IDP_E_GETNOTSUPPORTEDATRUNTIME 0xFEBF +#define AFX_IDP_E_GETNOTSUPPORTED 0xFEC0 +#define AFX_IDP_E_PROPERTYNOTFOUND 0xFEC1 +#define AFX_IDP_E_INVALIDCLIPBOARDFORMAT 0xFEC2 +#define AFX_IDP_E_INVALIDPICTURE 0xFEC3 +#define AFX_IDP_E_PRINTERERROR 0xFEC4 +#define AFX_IDP_E_CANTSAVEFILETOTEMP 0xFEC5 +#define AFX_IDP_E_SEARCHTEXTNOTFOUND 0xFEC6 +#define AFX_IDP_E_REPLACEMENTSTOOLONG 0xFEC7 + +///////////////////////////////////////////////////////////////////////////// + +#ifdef _AFX_MINREBUILD +#pragma component(minrebuild, on) +#endif + +#endif //__AFXRES_H__ + +///////////////////////////////////////////////////////////////////////////// diff --git a/PE/extract-rooms.cpp b/PE/extract-rooms.cpp index f2e2e31..a23026f 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 cd0d8e1..6f02fba 100644 --- a/PE/extract-various.cpp +++ b/PE/extract-various.cpp @@ -1,165 +1,165 @@ -#include -#include -#include -#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) << "\n"; - break; - case 0xff: - (*s) << "\n\n"; - c++; - break; - default: - (*s) << String().set("", 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) << "\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\n"; - c++; - changed = 1; - break; - default: - (*s) << String().set("", 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 +#include +#include +#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) << "\n"; + break; + case 0xff: + (*s) << "\n\n"; + c++; + break; + default: + (*s) << String().set("", 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) << "\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\n"; + c++; + changed = 1; + break; + default: + (*s) << String().set("", 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 4418fb9..4fa8b2f 100644 --- a/PE/extract.cpp +++ b/PE/extract.cpp @@ -1,83 +1,83 @@ -#include -#include -#include - -#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 +#include +#include + +#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-res.h b/PE/pepatch-res.h index 7559d25..0ecb46b 100644 --- a/PE/pepatch-res.h +++ b/PE/pepatch-res.h @@ -1,29 +1,29 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by pepatch.rc -// -#define IDI_ICON 101 -#define IDD_PROGRESS 102 -#define IDB_AYA 103 -#define IDD_ABOUT 104 -#define IDC_FILLOUT1 1001 -#define IDC_FILLIN1 1002 -#define IDC_FILLOUT2 1003 -#define IDC_FILLIN2 1004 -#define IDC_INFO1 1005 -#define IDC_INFO2 1006 -#define IDC_INFO3 1007 -#define IDC_PALFIX 1011 -#define IDC_ABOUT 1012 -#define IDC_CUSTOM1 1013 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 105 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1014 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by pepatch.rc +// +#define IDI_ICON 101 +#define IDD_PROGRESS 102 +#define IDB_AYA 103 +#define IDD_ABOUT 104 +#define IDC_FILLOUT1 1001 +#define IDC_FILLIN1 1002 +#define IDC_FILLOUT2 1003 +#define IDC_FILLIN2 1004 +#define IDC_INFO1 1005 +#define IDC_INFO2 1006 +#define IDC_INFO3 1007 +#define IDC_PALFIX 1011 +#define IDC_ABOUT 1012 +#define IDC_CUSTOM1 1013 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 105 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1014 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/PE/pepatch.cpp b/PE/pepatch.cpp index 18e11dd..4cf1e06 100644 --- a/PE/pepatch.cpp +++ b/PE/pepatch.cpp @@ -1,51 +1,51 @@ -#include -#include -#include "pepatch-res.h" - -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) { - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: DestroyWindow(hW); return TRUE; - case IDOK: DestroyWindow(hW); return TRUE; - } - } - return FALSE; -} - -CODE_BEGINS -virtual int startup() throw (GeneralException) { - verbosity = M_INFO; - HBITMAP bmp; - Output * out = new Output("TestBmp.bmp"); - char buffer[2048]; - DWORD readed; - - DialogBox(0, MAKEINTRESOURCE(IDD_ABOUT), - GetActiveWindow(), 0); -// 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); - } - printm(M_INFO, "Read %i bytes\n", readed); - out->write(buffer, readed); - } while (readed != 0); - - return 0; -} -CODE_ENDS +#include +#include +#include "pepatch-res.h" + +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) { + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDCANCEL: DestroyWindow(hW); return TRUE; + case IDOK: DestroyWindow(hW); return TRUE; + } + } + return FALSE; +} + +CODE_BEGINS +virtual int startup() throw (GeneralException) { + verbosity = M_INFO; + HBITMAP bmp; + Output * out = new Output("TestBmp.bmp"); + char buffer[2048]; + DWORD readed; + + DialogBox(0, MAKEINTRESOURCE(IDD_ABOUT), + GetActiveWindow(), 0); +// 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); + } + printm(M_INFO, "Read %i bytes\n", readed); + out->write(buffer, readed); + } while (readed != 0); + + return 0; +} +CODE_ENDS diff --git a/PE/rebuildmenus.cpp b/PE/rebuildmenus.cpp index bfbda61..681e909 100644 --- a/PE/rebuildmenus.cpp +++ b/PE/rebuildmenus.cpp @@ -1,76 +1,76 @@ -#include -#include -#include - -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 +#include +#include + +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-res.h b/PE/reinsert-res.h index c881b35..e3eb452 100644 --- a/PE/reinsert-res.h +++ b/PE/reinsert-res.h @@ -1,20 +1,20 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by reinsert.rc -// -#define IDI_ICON 101 -#define IDD_ABOUT 102 -#define IDC_FILLOUT 1005 -#define IDC_FILLIN 1006 -#define IDC_BLAHBLAH 1008 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 104 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1009 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by reinsert.rc +// +#define IDI_ICON 101 +#define IDD_ABOUT 102 +#define IDC_FILLOUT 1005 +#define IDC_FILLIN 1006 +#define IDC_BLAHBLAH 1008 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 104 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1009 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/PE/reinsert.cpp b/PE/reinsert.cpp index 1ad4441..9471fa3 100644 --- a/PE/reinsert.cpp +++ b/PE/reinsert.cpp @@ -1,244 +1,244 @@ -#include -#include -#include -#include -#include "cdutils.h" - -#include "reinsert-res.h" -#include - -#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) { - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: DestroyWindow(hW); return TRUE; - case IDOK: DestroyWindow(hW); return TRUE; - } - } - return FALSE; -} - -void LaisserSouffler(HWND Dlg) { - LPMSG msg; - - UpdateWindow(Dlg); - while (PeekMessage(msg, NULL, 0, 0, PM_REMOVE) != 0) { - TranslateMessage(msg); - DispatchMessage(msg); - } -} - -void UpdateProgress(HWND Dlg, float percent) { - RECT r; - HWND ctrl = GetDlgItem(Dlg, IDC_FILLOUT); - - GetWindowRect(ctrl, &r); - r.right -= r.left; - r.bottom -= r.top; - ScreenToClient(Dlg, (LPPOINT)&r); - r.top += 2; - r.left += 2; - r.right -= 5; - r.bottom -= 5; - - ctrl = GetDlgItem(Dlg, IDC_FILLIN); - - r.right = percent * r.right / 100; - MoveWindow(ctrl, r.left, r.top, r.right, r.bottom, TRUE); - InvalidateRect(ctrl, NULL, TRUE); - ctrl = GetDlgItem(Dlg, IDC_BLAHBLAH); - Static_SetText(ctrl, "Toto"); - 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 +#include +#include +#include +#include +#include "cdutils.h" + +#include "reinsert-res.h" +#include + +#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) { + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDCANCEL: DestroyWindow(hW); return TRUE; + case IDOK: DestroyWindow(hW); return TRUE; + } + } + return FALSE; +} + +void LaisserSouffler(HWND Dlg) { + LPMSG msg; + + UpdateWindow(Dlg); + while (PeekMessage(msg, NULL, 0, 0, PM_REMOVE) != 0) { + TranslateMessage(msg); + DispatchMessage(msg); + } +} + +void UpdateProgress(HWND Dlg, float percent) { + RECT r; + HWND ctrl = GetDlgItem(Dlg, IDC_FILLOUT); + + GetWindowRect(ctrl, &r); + r.right -= r.left; + r.bottom -= r.top; + ScreenToClient(Dlg, (LPPOINT)&r); + r.top += 2; + r.left += 2; + r.right -= 5; + r.bottom -= 5; + + ctrl = GetDlgItem(Dlg, IDC_FILLIN); + + r.right = percent * r.right / 100; + MoveWindow(ctrl, r.left, r.top, r.right, r.bottom, TRUE); + InvalidateRect(ctrl, NULL, TRUE); + ctrl = GetDlgItem(Dlg, IDC_BLAHBLAH); + Static_SetText(ctrl, "Toto"); + 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 diff --git a/PE/table.h b/PE/table.h index 24c0a39..a2551fa 100644 --- a/PE/table.h +++ b/PE/table.h @@ -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) << "\n"; - break; - case 0xf9: - (*t) << "\n\n"; - break; - case 0xfa: - (*t) << ""; - break; - case 0xfb: - j++; - j++; - a1 = f->readU8(); - switch(a1) { - case 0: - (*t) << ""; - break; - case 1: - (*t) << ""; - break; - case 9: - a2 = f->readU8(); - (*t) << "\n"; - break; - case 7: - a2 = f->readU8(); - (*t) << ""; - break; - default: - (*t) << ""; - break; - } - break; - case 0xfe: - j++; - b = f->readU8(); - (*t) << "\n"; - break; - case 0xff: - (*t) << "\n\n"; - break; - default: - (*t) << String().set("", 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) << "\n"; + break; + case 0xf9: + (*t) << "\n\n"; + break; + case 0xfa: + (*t) << ""; + break; + case 0xfb: + j++; + j++; + a1 = f->readU8(); + switch(a1) { + case 0: + (*t) << ""; + break; + case 1: + (*t) << ""; + break; + case 9: + a2 = f->readU8(); + (*t) << "\n"; + break; + case 7: + a2 = f->readU8(); + (*t) << ""; + break; + default: + (*t) << ""; + break; + } + break; + case 0xfe: + j++; + b = f->readU8(); + (*t) << "\n"; + break; + case 0xff: + (*t) << "\n\n"; + break; + default: + (*t) << String().set("", b); + } + } + } +} +#endif diff --git a/PcsxSrc/CdRom.c b/PcsxSrc/CdRom.c index 795cdce..303548c 100644 --- a/PcsxSrc/CdRom.c +++ b/PcsxSrc/CdRom.c @@ -1,1049 +1,1049 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include -//THIS ALL IS FOR THE CDROM REGISTERS HANDLING -#include "PsxCommon.h" - -#define CdlSync 0 -#define CdlNop 1 -#define CdlSetloc 2 -#define CdlPlay 3 -#define CdlForward 4 -#define CdlBackward 5 -#define CdlReadN 6 -#define CdlStandby 7 -#define CdlStop 8 -#define CdlPause 9 -#define CdlInit 10 -#define CdlMute 11 -#define CdlDemute 12 -#define CdlSetfilter 13 -#define CdlSetmode 14 -#define CdlGetmode 15 -#define CdlGetlocL 16 -#define CdlGetlocP 17 -#define Cdl18 18 -#define CdlGetTN 19 -#define CdlGetTD 20 -#define CdlSeekL 21 -#define CdlSeekP 22 -#define CdlTest 25 -#define CdlID 26 -#define CdlReadS 27 -#define CdlReset 28 -#define CdlReadToc 30 - -#define AUTOPAUSE 249 -#define READ_ACK 250 -#define READ 251 -#define REPPLAY_ACK 252 -#define REPPLAY 253 -#define ASYNC 254 -/* don't set 255, it's reserved */ - -char *CmdName[0x100]= { - "CdlSync", "CdlNop", "CdlSetloc", "CdlPlay", - "CdlForward", "CdlBackward", "CdlReadN", "CdlStandby", - "CdlStop", "CdlPause", "CdlInit", "CdlMute", - "CdlDemute", "CdlSetfilter", "CdlSetmode", "CdlGetmode", - "CdlGetlocL", "CdlGetlocP", "Cdl18", "CdlGetTN", - "CdlGetTD", "CdlSeekL", "CdlSeekP", NULL, - NULL, "CdlTest", "CdlID", "CdlReadS", - "CdlReset", NULL, "CDlReadToc", NULL -}; - -unsigned char Test04[] = { 0 }; -unsigned char Test05[] = { 0 }; -unsigned char Test20[] = { 0x98, 0x06, 0x10, 0xC3 }; -unsigned char Test22[] = { 0x66, 0x6F, 0x72, 0x20, 0x45, 0x75, 0x72, 0x6F }; -unsigned char Test23[] = { 0x43, 0x58, 0x44, 0x32, 0x39 ,0x34, 0x30, 0x51 }; - -// 1x = 75 sectors per second -// PSXCLK = 1 sec in the ps -// so (PSXCLK / 75) / BIAS = cdr read time (linuzappz) -//#define cdReadTime ((PSXCLK / 75) / BIAS) -unsigned long cdReadTime = ((PSXCLK / 75) / BIAS); - -#define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */ -#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */ - -static struct CdrStat stat; -static struct SubQ *subq; - -#define CDR_INT(eCycle) { \ - psxRegs.interrupt|= 0x4; \ - psxRegs.intCycle[2+1] = eCycle; \ - psxRegs.intCycle[2] = psxRegs.cycle; } - -#define CDREAD_INT(eCycle) { \ - psxRegs.interrupt|= 0x40000; \ - psxRegs.intCycle[2+16+1] = eCycle; \ - psxRegs.intCycle[2+16] = psxRegs.cycle; } - -#define StartReading(type) { \ - cdr.Reading = type; \ - cdr.FirstSector = 1; \ - cdr.Readed = 0xff; \ - AddIrqQueue(READ_ACK, 0x800); \ -} - -#define StopReading() { \ - if (cdr.Reading) { \ - cdr.Reading = 0; \ - psxRegs.interrupt&=~0x40000; \ - } \ -} - -#define StopCdda() { \ - if (cdr.Play) { \ - if (!Config.Cdda) CDR_stop(); \ - cdr.StatP&=~0x80; \ - cdr.Play = 0; \ - } \ -} - -#define SetResultSize(size) { \ - cdr.ResultP = 0; \ - cdr.ResultC = size; \ - cdr.ResultReady = 1; \ -} - -void ReadTrack() { - - cdr.Prev[0] = itob(cdr.SetSector[0]); - cdr.Prev[1] = itob(cdr.SetSector[1]); - cdr.Prev[2] = itob(cdr.SetSector[2]); - -#ifdef CDR_LOG - CDR_LOG("KEY *** %x:%x:%x\n", cdr.Prev[0], cdr.Prev[1], cdr.Prev[2]); -#endif - cdr.RErr = CDR_readTrack(cdr.Prev); -} - -// cdr.Stat: -#define NoIntr 0 -#define DataReady 1 -#define Complete 2 -#define Acknowledge 3 -#define DataEnd 4 -#define DiskError 5 - -void AddIrqQueue(unsigned char irq, unsigned long ecycle) { - cdr.Irq = irq; - if (cdr.Stat) { - cdr.eCycle = ecycle; - } else { - CDR_INT(ecycle); - } -} - -void cdrInterrupt() { - int i; - unsigned char Irq = cdr.Irq; - - if (cdr.Stat) { - CDR_INT(0x800); - return; - } - - cdr.Irq = 0xff; - cdr.Ctrl&=~0x80; - - switch (Irq) { - case CdlSync: - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - break; - - case CdlNop: - SetResultSize(1); - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - i = stat.Status; - if (CDR_getStatus(&stat) != -1) { - if (stat.Type == 0xff) cdr.Stat = DiskError; - if (stat.Status & 0x10) { - cdr.Stat = DiskError; - cdr.Result[0]|= 0x11; - cdr.Result[0]&=~0x02; - } - else if (i & 0x10) { - cdr.StatP |= 0x2; - cdr.Result[0]|= 0x2; - CheckCdrom(); - } - } - break; - - case CdlSetloc: - cdr.CmdProcess = 0; - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - break; - - case CdlPlay: - cdr.CmdProcess = 0; - SetResultSize(1); - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - cdr.StatP|= 0x82; -// if ((cdr.Mode & 0x5) == 0x5) AddIrqQueue(REPPLAY, cdReadTime); - break; - - case CdlForward: - cdr.CmdProcess = 0; - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; - break; - - case CdlBackward: - cdr.CmdProcess = 0; - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; - break; - - case CdlStandby: - cdr.CmdProcess = 0; - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; - break; - - case CdlStop: - cdr.CmdProcess = 0; - SetResultSize(1); - cdr.StatP&=~0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; -// cdr.Stat = Acknowledge; - break; - - case CdlPause: - SetResultSize(1); - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - AddIrqQueue(CdlPause + 0x20, 0x800); - break; - - case CdlPause + 0x20: - SetResultSize(1); - cdr.StatP&=~0x20; - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; - break; - - case CdlInit: - SetResultSize(1); - cdr.StatP = 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; -// if (!cdr.Init) { - AddIrqQueue(CdlInit + 0x20, 0x800); -// } - break; - - case CdlInit + 0x20: - SetResultSize(1); - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; - cdr.Init = 1; - break; - - case CdlMute: - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - break; - - case CdlDemute: - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - break; - - case CdlSetfilter: - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - break; - - case CdlSetmode: - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - break; - - case CdlGetmode: - SetResultSize(6); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Result[1] = cdr.Mode; - cdr.Result[2] = cdr.File; - cdr.Result[3] = cdr.Channel; - cdr.Result[4] = 0; - cdr.Result[5] = 0; - cdr.Stat = Acknowledge; - break; - - case CdlGetlocL: - SetResultSize(8); -// for (i=0; i<8; i++) cdr.Result[i] = itob(cdr.Transfer[i]); - for (i=0; i<8; i++) cdr.Result[i] = cdr.Transfer[i]; - cdr.Stat = Acknowledge; - break; - - case CdlGetlocP: - SetResultSize(8); - subq = (struct SubQ*) CDR_getBufferSub(); - if (subq != NULL) { - cdr.Result[0] = subq->TrackNumber; - cdr.Result[1] = subq->IndexNumber; - memcpy(cdr.Result+2, subq->TrackRelativeAddress, 3); - memcpy(cdr.Result+5, subq->AbsoluteAddress, 3); - } else { - cdr.Result[0] = 1; - cdr.Result[1] = 1; - cdr.Result[2] = cdr.Prev[0]; - cdr.Result[3] = itob((btoi(cdr.Prev[1])) - 2); - cdr.Result[4] = cdr.Prev[2]; - memcpy(cdr.Result+5, cdr.Prev, 3); - } - cdr.Stat = Acknowledge; - break; - - case CdlGetTN: - cdr.CmdProcess = 0; - SetResultSize(3); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - if (CDR_getTN(cdr.ResultTN) == -1) { - cdr.Stat = DiskError; - cdr.Result[0]|= 0x01; - } else { - cdr.Stat = Acknowledge; - cdr.Result[1] = itob(cdr.ResultTN[0]); - cdr.Result[2] = itob(cdr.ResultTN[1]); - } - break; - - case CdlGetTD: - cdr.CmdProcess = 0; - cdr.Track = btoi(cdr.Param[0]); - SetResultSize(4); - cdr.StatP|= 0x2; - if (CDR_getTD(cdr.Track, cdr.ResultTD) == -1) { - cdr.Stat = DiskError; - cdr.Result[0]|= 0x01; - } else { - cdr.Stat = Acknowledge; - cdr.Result[0] = cdr.StatP; - cdr.Result[1] = itob(cdr.ResultTD[2]); - cdr.Result[2] = itob(cdr.ResultTD[1]); - cdr.Result[3] = itob(cdr.ResultTD[0]); - } - break; - - case CdlSeekL: - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - AddIrqQueue(CdlSeekL + 0x20, 0x800); - break; - - case CdlSeekL + 0x20: - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; - break; - - case CdlSeekP: - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - AddIrqQueue(CdlSeekP + 0x20, 0x800); - break; - - case CdlSeekP + 0x20: - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; - break; - - case CdlTest: - cdr.Stat = Acknowledge; - switch (cdr.Param[0]) { - case 0x20: // System Controller ROM Version - SetResultSize(4); - memcpy(cdr.Result, Test20, 4); - break; - case 0x22: - SetResultSize(8); - memcpy(cdr.Result, Test22, 4); - break; - case 0x23: case 0x24: - SetResultSize(8); - memcpy(cdr.Result, Test23, 4); - break; - } - break; - - case CdlID: - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - AddIrqQueue(CdlID + 0x20, 0x800); - break; - - case CdlID + 0x20: - SetResultSize(8); - if (CDR_getStatus(&stat) == -1) { - cdr.Result[0] = 0x00; // 0x08 and cdr.Result[1]|0x10 : audio cd, enters cd player - cdr.Result[1] = 0x00; // 0x80 leads to the menu in the bios, else loads CD - } - else { - if (stat.Type == 2) { - cdr.Result[0] = 0x08; - cdr.Result[1] = 0x10; - } - else { - cdr.Result[0] = 0x00; - cdr.Result[1] = 0x00; - } - } - if (!LoadCdBios) cdr.Result[1] |= 0x80; - - cdr.Result[2] = 0x00; - cdr.Result[3] = 0x00; - strncpy((char *)&cdr.Result[4], "PCSX", 4); - cdr.Stat = Complete; - break; - - case CdlReset: - SetResultSize(1); - cdr.StatP = 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - break; - - case CdlReadToc: - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - AddIrqQueue(CdlReadToc + 0x20, 0x800); - break; - - case CdlReadToc + 0x20: - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; - break; - - case AUTOPAUSE: - cdr.OCUP = 0; -/* SetResultSize(1); - StopCdda(); - StopReading(); - cdr.OCUP = 0; - cdr.StatP&=~0x20; - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = DataEnd; -*/ AddIrqQueue(CdlPause, 0x400); - break; - - case READ_ACK: - if (!cdr.Reading) return; - - SetResultSize(1); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - - ReadTrack(); - - CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); - - break; - - case REPPLAY_ACK: - cdr.Stat = Acknowledge; - cdr.Result[0] = cdr.StatP; - SetResultSize(1); - AddIrqQueue(REPPLAY, cdReadTime); - break; - - case REPPLAY: - if ((cdr.Mode & 5) != 5) break; -/* if (CDR_getStatus(&stat) == -1) { - cdr.Result[0] = 0; - cdr.Result[1] = 0; - cdr.Result[2] = 0; - cdr.Result[3] = 0; - cdr.Result[4] = 0; - cdr.Result[5] = 0; - cdr.Result[6] = 0; - cdr.Result[7] = 0; - } else memcpy(cdr.Result, &stat.Track, 8); - cdr.Stat = 1; - SetResultSize(8); - AddIrqQueue(REPPLAY_ACK, cdReadTime); -*/ break; - - case 0xff: - return; - - default: - cdr.Stat = Complete; - break; - } - - if (cdr.Stat != NoIntr && cdr.Reg2 != 0x18) psxHu32(0x1070)|=0x4; - -#ifdef CDR_LOG - CDR_LOG("Cdr Interrupt %x\n", Irq); -#endif -} - -void cdrReadInterrupt() { - unsigned char *buf; - - if (!cdr.Reading) return; - - if (cdr.Stat) { - CDREAD_INT(0x800); - return; - } - -#ifdef CDR_LOG - CDR_LOG("KEY END"); -#endif - - cdr.OCUP = 1; - SetResultSize(1); - cdr.StatP|= 0x22; - cdr.Result[0] = cdr.StatP; - - buf = CDR_getBuffer(); - if (buf == NULL) cdr.RErr = -1; - - if (cdr.RErr == -1) { -#ifdef CDR_LOG - fprintf(emuLog, " err\n"); -#endif - memset(cdr.Transfer, 0, 2340); - cdr.Stat = DiskError; - cdr.Result[0]|= 0x01; - ReadTrack(); - CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); - return; - } - - memcpy(cdr.Transfer, buf, 2340); - cdr.Stat = DataReady; - -#ifdef CDR_LOG - fprintf(emuLog, " %x:%x:%x\n", cdr.Transfer[0], cdr.Transfer[1], cdr.Transfer[2]); -#endif - - if ((cdr.Muted == 1) && (cdr.Mode & 0x40) && (!Config.Xa) && (cdr.FirstSector != -1)) { // CD-XA - if ((cdr.Transfer[4+2] & 0x4) && - ((cdr.Mode&0x8) ? (cdr.Transfer[4+1] == cdr.Channel) : 1) && - (cdr.Transfer[4+0] == cdr.File)) { - int ret = xa_decode_sector(&cdr.Xa, cdr.Transfer+4, cdr.FirstSector); - - if (!ret) { - SPU_playADPCMchannel(&cdr.Xa); - cdr.FirstSector = 0; - } - else cdr.FirstSector = -1; - } - } - - cdr.SetSector[2]++; - if (cdr.SetSector[2] == 75) { - cdr.SetSector[2] = 0; - cdr.SetSector[1]++; - if (cdr.SetSector[1] == 60) { - cdr.SetSector[1] = 0; - cdr.SetSector[0]++; - } - } - - cdr.Readed = 0; - - if ((cdr.Transfer[4+2] & 0x80) && (cdr.Mode & 0x2)) { // EOF -#ifdef CDR_LOG - CDR_LOG("AutoPausing Read\n"); -#endif -// AddIrqQueue(AUTOPAUSE, 0x800); - AddIrqQueue(CdlPause, 0x800); - } - else { - ReadTrack(); - CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); - } - psxHu32(0x1070)|=0x4; -} - -/* -cdrRead0: - bit 0 - 0 REG1 command send / 1 REG1 data read - bit 1 - 0 data transfer finish / 1 data transfer ready/in progress - bit 2 - unknown - bit 3 - unknown - bit 4 - unknown - bit 5 - 1 result ready - bit 6 - 1 dma ready - bit 7 - 1 command being processed -*/ - -unsigned char cdrRead0(void) { - if (cdr.ResultReady) cdr.Ctrl|= 0x20; - else cdr.Ctrl&=~0x20; - - if (cdr.OCUP) cdr.Ctrl|= 0x40; - else cdr.Ctrl&=~0x40; - - // what means the 0x10 and the 0x08 bits? i only saw it used by the bios - cdr.Ctrl|=0x18; - -#ifdef CDR_LOG - CDR_LOG("CD0 Read: %x\n", cdr.Ctrl); -#endif - return psxHu8(0x1800) = cdr.Ctrl; -} - -/* -cdrWrite0: - 0 - to send a command / 1 - to get the result -*/ - -void cdrWrite0(unsigned char rt) { -#ifdef CDR_LOG - CDR_LOG("CD0 write: %x\n", rt); -#endif - cdr.Ctrl = rt | (cdr.Ctrl & ~0x3); - - if (rt == 0) { - cdr.ParamP = 0; - cdr.ParamC = 0; - cdr.ResultReady = 0; - } -} - -unsigned char cdrRead1(void) { - if (cdr.ResultReady && cdr.Ctrl & 0x1) { - psxHu8(0x1801) = cdr.Result[cdr.ResultP++]; - if (cdr.ResultP == cdr.ResultC) cdr.ResultReady = 0; - } else psxHu8(0x1801) = 0; -#ifdef CDR_LOG - CDR_LOG("CD1 Read: %x\n", psxHu8(0x1801)); -#endif - return psxHu8(0x1801); -} - -void cdrWrite1(unsigned char rt) { - int i; - -#ifdef CDR_LOG - CDR_LOG("CD1 write: %x (%s)\n", rt, CmdName[rt]); -#endif -// psxHu8(0x1801) = rt; - cdr.Cmd = rt; - cdr.OCUP = 0; - -#ifdef CDRCMD_DEBUG - SysPrintf("CD1 write: %x (%s)", rt, CmdName[rt]); - if (cdr.ParamC) { - SysPrintf(" Param[%d] = {", cdr.ParamC); - for (i=0;i cdr.ResultTN[1]) cdr.CurTrack = cdr.ResultTN[1]; - if (CDR_getTD((unsigned char)(cdr.CurTrack), cdr.ResultTD) != -1) { - int tmp = cdr.ResultTD[2]; - cdr.ResultTD[2] = cdr.ResultTD[0]; - cdr.ResultTD[0] = tmp; - if (!Config.Cdda) CDR_play(cdr.ResultTD); - } - } - } - else if (!Config.Cdda) CDR_play(cdr.SetSector); - cdr.Play = 1; - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlForward: - if (cdr.CurTrack < 0xaa) cdr.CurTrack++; - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlBackward: - if (cdr.CurTrack > 1) cdr.CurTrack--; - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlReadN: - cdr.Irq = 0; - StopReading(); - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - StartReading(1); - break; - - case CdlStandby: - StopCdda(); - StopReading(); - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlStop: - StopCdda(); - StopReading(); - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlPause: - StopCdda(); - StopReading(); - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x40000); - break; - - case CdlReset: - case CdlInit: - StopCdda(); - StopReading(); - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlMute: - cdr.Muted = 0; - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlDemute: - cdr.Muted = 1; - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlSetfilter: - cdr.File = cdr.Param[0]; - cdr.Channel = cdr.Param[1]; - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlSetmode: -#ifdef CDR_LOG - CDR_LOG("Setmode %x\n", cdr.Param[0]); -#endif - cdr.Mode = cdr.Param[0]; - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlGetmode: - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlGetlocL: - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlGetlocP: - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlGetTN: - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlGetTD: - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlSeekL: - ((unsigned long *)cdr.SetSectorSeek)[0] = ((unsigned long *)cdr.SetSector)[0]; - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlSeekP: - ((unsigned long *)cdr.SetSectorSeek)[0] = ((unsigned long *)cdr.SetSector)[0]; - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlTest: - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlID: - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlReadS: - cdr.Irq = 0; - StopReading(); - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - StartReading(2); - break; - - case CdlReadToc: - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - default: -#ifdef CDR_LOG - CDR_LOG("Unknown Cmd: %x\n", cdr.Cmd); -#endif - return; - } - if (cdr.Stat != NoIntr) psxHu32(0x1070)|=0x4; -} - -unsigned char cdrRead2(void) { - unsigned char ret; - - if (cdr.Readed == 0) { - ret = 0; - } else { - ret = *cdr.pTransfer++; - } - -#ifdef CDR_LOG - CDR_LOG("CD2 Read: %x\n", ret); -#endif - return ret; -} - -void cdrWrite2(unsigned char rt) { -#ifdef CDR_LOG - CDR_LOG("CD2 write: %x\n", rt); -#endif - if (cdr.Ctrl & 0x1) { - switch (rt) { - case 0x07: - cdr.ParamP = 0; - cdr.ParamC = 0; - cdr.ResultReady = 0; - cdr.Ctrl = 0; - break; - - default: - cdr.Reg2 = rt; - break; - } - } else if (!(cdr.Ctrl & 0x1) && cdr.ParamP < 8) { - cdr.Param[cdr.ParamP++] = rt; - cdr.ParamC++; - } -} - -unsigned char cdrRead3(void) { - if (cdr.Stat) { - if (cdr.Ctrl & 0x1) psxHu8(0x1803) = cdr.Stat | 0xE0; - else psxHu8(0x1803) = 0xff; - } else psxHu8(0x1803) = 0; -#ifdef CDR_LOG - CDR_LOG("CD3 Read: %x\n", psxHu8(0x1803)); -#endif - return psxHu8(0x1803); -} - -void cdrWrite3(unsigned char rt) { -#ifdef CDR_LOG - CDR_LOG("CD3 write: %x\n", rt); -#endif - if (rt == 0x07 && cdr.Ctrl & 0x1) { - cdr.Stat = 0; - - if (cdr.Irq == 0xff) { cdr.Irq = 0; return; } - if (cdr.Irq) CDR_INT(cdr.eCycle); - if (cdr.Reading && !cdr.ResultReady) - CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); - - return; - } - if (rt == 0x80 && !(cdr.Ctrl & 0x1) && cdr.Readed == 0) { - cdr.Readed = 1; - cdr.pTransfer = cdr.Transfer; - - switch (cdr.Mode&0x30) { - case 0x10: - case 0x00: cdr.pTransfer+=12; break; - default: break; - } - } -} - -void psxDma3(u32 madr, u32 bcr, u32 chcr) { - u32 cdsize; - -#ifdef CDR_LOG - CDR_LOG("*** DMA 3 *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif - - switch (chcr) { - case 0x11000000: - case 0x11400100: - if (cdr.Readed == 0) { -#ifdef CDR_LOG - CDR_LOG("*** DMA 3 *** NOT READY\n"); -#endif - return; - } - - cdsize = (bcr & 0xffff) * 4; - - memcpy((u8*)PSXM(madr), cdr.pTransfer, cdsize); - psxCpu->Clear(madr, cdsize/4); - cdr.pTransfer+=cdsize; - - break; - default: -#ifdef CDR_LOG - CDR_LOG("Unknown cddma %lx\n", chcr); -#endif - break; - } -} - -void cdrReset() { - memset(&cdr, 0, sizeof(cdr)); - cdr.CurTrack=1; - cdr.File=1; cdr.Channel=1; - // with the timing set to 60 Gran Turismo works - // anybody knows why it doesn't with 75? - // 75 is the correct cdrom timing - if (Config.CdTiming) - cdReadTime = (PSXCLK / 60) / BIAS; - // this seems to be the most compatible - // let's leave like this until we know why - // 75 is buggy with some games - else cdReadTime = (PSXCLK / 65) / BIAS; -// else cdReadTime = (PSXCLK / 75) / BIAS; -} - -int cdrFreeze(gzFile f, int Mode) { - int tmp; - - gzfreeze(&cdr, sizeof(cdr)); - - if (Mode == 1) tmp = cdr.pTransfer - cdr.Transfer; - gzfreezel(&tmp); - if (Mode == 0) cdr.pTransfer = cdr.Transfer + tmp; - - return 0; -} - +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include +//THIS ALL IS FOR THE CDROM REGISTERS HANDLING +#include "PsxCommon.h" + +#define CdlSync 0 +#define CdlNop 1 +#define CdlSetloc 2 +#define CdlPlay 3 +#define CdlForward 4 +#define CdlBackward 5 +#define CdlReadN 6 +#define CdlStandby 7 +#define CdlStop 8 +#define CdlPause 9 +#define CdlInit 10 +#define CdlMute 11 +#define CdlDemute 12 +#define CdlSetfilter 13 +#define CdlSetmode 14 +#define CdlGetmode 15 +#define CdlGetlocL 16 +#define CdlGetlocP 17 +#define Cdl18 18 +#define CdlGetTN 19 +#define CdlGetTD 20 +#define CdlSeekL 21 +#define CdlSeekP 22 +#define CdlTest 25 +#define CdlID 26 +#define CdlReadS 27 +#define CdlReset 28 +#define CdlReadToc 30 + +#define AUTOPAUSE 249 +#define READ_ACK 250 +#define READ 251 +#define REPPLAY_ACK 252 +#define REPPLAY 253 +#define ASYNC 254 +/* don't set 255, it's reserved */ + +char *CmdName[0x100]= { + "CdlSync", "CdlNop", "CdlSetloc", "CdlPlay", + "CdlForward", "CdlBackward", "CdlReadN", "CdlStandby", + "CdlStop", "CdlPause", "CdlInit", "CdlMute", + "CdlDemute", "CdlSetfilter", "CdlSetmode", "CdlGetmode", + "CdlGetlocL", "CdlGetlocP", "Cdl18", "CdlGetTN", + "CdlGetTD", "CdlSeekL", "CdlSeekP", NULL, + NULL, "CdlTest", "CdlID", "CdlReadS", + "CdlReset", NULL, "CDlReadToc", NULL +}; + +unsigned char Test04[] = { 0 }; +unsigned char Test05[] = { 0 }; +unsigned char Test20[] = { 0x98, 0x06, 0x10, 0xC3 }; +unsigned char Test22[] = { 0x66, 0x6F, 0x72, 0x20, 0x45, 0x75, 0x72, 0x6F }; +unsigned char Test23[] = { 0x43, 0x58, 0x44, 0x32, 0x39 ,0x34, 0x30, 0x51 }; + +// 1x = 75 sectors per second +// PSXCLK = 1 sec in the ps +// so (PSXCLK / 75) / BIAS = cdr read time (linuzappz) +//#define cdReadTime ((PSXCLK / 75) / BIAS) +unsigned long cdReadTime = ((PSXCLK / 75) / BIAS); + +#define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */ +#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */ + +static struct CdrStat stat; +static struct SubQ *subq; + +#define CDR_INT(eCycle) { \ + psxRegs.interrupt|= 0x4; \ + psxRegs.intCycle[2+1] = eCycle; \ + psxRegs.intCycle[2] = psxRegs.cycle; } + +#define CDREAD_INT(eCycle) { \ + psxRegs.interrupt|= 0x40000; \ + psxRegs.intCycle[2+16+1] = eCycle; \ + psxRegs.intCycle[2+16] = psxRegs.cycle; } + +#define StartReading(type) { \ + cdr.Reading = type; \ + cdr.FirstSector = 1; \ + cdr.Readed = 0xff; \ + AddIrqQueue(READ_ACK, 0x800); \ +} + +#define StopReading() { \ + if (cdr.Reading) { \ + cdr.Reading = 0; \ + psxRegs.interrupt&=~0x40000; \ + } \ +} + +#define StopCdda() { \ + if (cdr.Play) { \ + if (!Config.Cdda) CDR_stop(); \ + cdr.StatP&=~0x80; \ + cdr.Play = 0; \ + } \ +} + +#define SetResultSize(size) { \ + cdr.ResultP = 0; \ + cdr.ResultC = size; \ + cdr.ResultReady = 1; \ +} + +void ReadTrack() { + + cdr.Prev[0] = itob(cdr.SetSector[0]); + cdr.Prev[1] = itob(cdr.SetSector[1]); + cdr.Prev[2] = itob(cdr.SetSector[2]); + +#ifdef CDR_LOG + CDR_LOG("KEY *** %x:%x:%x\n", cdr.Prev[0], cdr.Prev[1], cdr.Prev[2]); +#endif + cdr.RErr = CDR_readTrack(cdr.Prev); +} + +// cdr.Stat: +#define NoIntr 0 +#define DataReady 1 +#define Complete 2 +#define Acknowledge 3 +#define DataEnd 4 +#define DiskError 5 + +void AddIrqQueue(unsigned char irq, unsigned long ecycle) { + cdr.Irq = irq; + if (cdr.Stat) { + cdr.eCycle = ecycle; + } else { + CDR_INT(ecycle); + } +} + +void cdrInterrupt() { + int i; + unsigned char Irq = cdr.Irq; + + if (cdr.Stat) { + CDR_INT(0x800); + return; + } + + cdr.Irq = 0xff; + cdr.Ctrl&=~0x80; + + switch (Irq) { + case CdlSync: + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + break; + + case CdlNop: + SetResultSize(1); + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + i = stat.Status; + if (CDR_getStatus(&stat) != -1) { + if (stat.Type == 0xff) cdr.Stat = DiskError; + if (stat.Status & 0x10) { + cdr.Stat = DiskError; + cdr.Result[0]|= 0x11; + cdr.Result[0]&=~0x02; + } + else if (i & 0x10) { + cdr.StatP |= 0x2; + cdr.Result[0]|= 0x2; + CheckCdrom(); + } + } + break; + + case CdlSetloc: + cdr.CmdProcess = 0; + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + break; + + case CdlPlay: + cdr.CmdProcess = 0; + SetResultSize(1); + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + cdr.StatP|= 0x82; +// if ((cdr.Mode & 0x5) == 0x5) AddIrqQueue(REPPLAY, cdReadTime); + break; + + case CdlForward: + cdr.CmdProcess = 0; + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; + break; + + case CdlBackward: + cdr.CmdProcess = 0; + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; + break; + + case CdlStandby: + cdr.CmdProcess = 0; + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; + break; + + case CdlStop: + cdr.CmdProcess = 0; + SetResultSize(1); + cdr.StatP&=~0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; +// cdr.Stat = Acknowledge; + break; + + case CdlPause: + SetResultSize(1); + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + AddIrqQueue(CdlPause + 0x20, 0x800); + break; + + case CdlPause + 0x20: + SetResultSize(1); + cdr.StatP&=~0x20; + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; + break; + + case CdlInit: + SetResultSize(1); + cdr.StatP = 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; +// if (!cdr.Init) { + AddIrqQueue(CdlInit + 0x20, 0x800); +// } + break; + + case CdlInit + 0x20: + SetResultSize(1); + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; + cdr.Init = 1; + break; + + case CdlMute: + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + break; + + case CdlDemute: + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + break; + + case CdlSetfilter: + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + break; + + case CdlSetmode: + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + break; + + case CdlGetmode: + SetResultSize(6); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Result[1] = cdr.Mode; + cdr.Result[2] = cdr.File; + cdr.Result[3] = cdr.Channel; + cdr.Result[4] = 0; + cdr.Result[5] = 0; + cdr.Stat = Acknowledge; + break; + + case CdlGetlocL: + SetResultSize(8); +// for (i=0; i<8; i++) cdr.Result[i] = itob(cdr.Transfer[i]); + for (i=0; i<8; i++) cdr.Result[i] = cdr.Transfer[i]; + cdr.Stat = Acknowledge; + break; + + case CdlGetlocP: + SetResultSize(8); + subq = (struct SubQ*) CDR_getBufferSub(); + if (subq != NULL) { + cdr.Result[0] = subq->TrackNumber; + cdr.Result[1] = subq->IndexNumber; + memcpy(cdr.Result+2, subq->TrackRelativeAddress, 3); + memcpy(cdr.Result+5, subq->AbsoluteAddress, 3); + } else { + cdr.Result[0] = 1; + cdr.Result[1] = 1; + cdr.Result[2] = cdr.Prev[0]; + cdr.Result[3] = itob((btoi(cdr.Prev[1])) - 2); + cdr.Result[4] = cdr.Prev[2]; + memcpy(cdr.Result+5, cdr.Prev, 3); + } + cdr.Stat = Acknowledge; + break; + + case CdlGetTN: + cdr.CmdProcess = 0; + SetResultSize(3); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + if (CDR_getTN(cdr.ResultTN) == -1) { + cdr.Stat = DiskError; + cdr.Result[0]|= 0x01; + } else { + cdr.Stat = Acknowledge; + cdr.Result[1] = itob(cdr.ResultTN[0]); + cdr.Result[2] = itob(cdr.ResultTN[1]); + } + break; + + case CdlGetTD: + cdr.CmdProcess = 0; + cdr.Track = btoi(cdr.Param[0]); + SetResultSize(4); + cdr.StatP|= 0x2; + if (CDR_getTD(cdr.Track, cdr.ResultTD) == -1) { + cdr.Stat = DiskError; + cdr.Result[0]|= 0x01; + } else { + cdr.Stat = Acknowledge; + cdr.Result[0] = cdr.StatP; + cdr.Result[1] = itob(cdr.ResultTD[2]); + cdr.Result[2] = itob(cdr.ResultTD[1]); + cdr.Result[3] = itob(cdr.ResultTD[0]); + } + break; + + case CdlSeekL: + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + AddIrqQueue(CdlSeekL + 0x20, 0x800); + break; + + case CdlSeekL + 0x20: + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; + break; + + case CdlSeekP: + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + AddIrqQueue(CdlSeekP + 0x20, 0x800); + break; + + case CdlSeekP + 0x20: + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; + break; + + case CdlTest: + cdr.Stat = Acknowledge; + switch (cdr.Param[0]) { + case 0x20: // System Controller ROM Version + SetResultSize(4); + memcpy(cdr.Result, Test20, 4); + break; + case 0x22: + SetResultSize(8); + memcpy(cdr.Result, Test22, 4); + break; + case 0x23: case 0x24: + SetResultSize(8); + memcpy(cdr.Result, Test23, 4); + break; + } + break; + + case CdlID: + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + AddIrqQueue(CdlID + 0x20, 0x800); + break; + + case CdlID + 0x20: + SetResultSize(8); + if (CDR_getStatus(&stat) == -1) { + cdr.Result[0] = 0x00; // 0x08 and cdr.Result[1]|0x10 : audio cd, enters cd player + cdr.Result[1] = 0x00; // 0x80 leads to the menu in the bios, else loads CD + } + else { + if (stat.Type == 2) { + cdr.Result[0] = 0x08; + cdr.Result[1] = 0x10; + } + else { + cdr.Result[0] = 0x00; + cdr.Result[1] = 0x00; + } + } + if (!LoadCdBios) cdr.Result[1] |= 0x80; + + cdr.Result[2] = 0x00; + cdr.Result[3] = 0x00; + strncpy((char *)&cdr.Result[4], "PCSX", 4); + cdr.Stat = Complete; + break; + + case CdlReset: + SetResultSize(1); + cdr.StatP = 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + break; + + case CdlReadToc: + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + AddIrqQueue(CdlReadToc + 0x20, 0x800); + break; + + case CdlReadToc + 0x20: + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; + break; + + case AUTOPAUSE: + cdr.OCUP = 0; +/* SetResultSize(1); + StopCdda(); + StopReading(); + cdr.OCUP = 0; + cdr.StatP&=~0x20; + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = DataEnd; +*/ AddIrqQueue(CdlPause, 0x400); + break; + + case READ_ACK: + if (!cdr.Reading) return; + + SetResultSize(1); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + + ReadTrack(); + + CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); + + break; + + case REPPLAY_ACK: + cdr.Stat = Acknowledge; + cdr.Result[0] = cdr.StatP; + SetResultSize(1); + AddIrqQueue(REPPLAY, cdReadTime); + break; + + case REPPLAY: + if ((cdr.Mode & 5) != 5) break; +/* if (CDR_getStatus(&stat) == -1) { + cdr.Result[0] = 0; + cdr.Result[1] = 0; + cdr.Result[2] = 0; + cdr.Result[3] = 0; + cdr.Result[4] = 0; + cdr.Result[5] = 0; + cdr.Result[6] = 0; + cdr.Result[7] = 0; + } else memcpy(cdr.Result, &stat.Track, 8); + cdr.Stat = 1; + SetResultSize(8); + AddIrqQueue(REPPLAY_ACK, cdReadTime); +*/ break; + + case 0xff: + return; + + default: + cdr.Stat = Complete; + break; + } + + if (cdr.Stat != NoIntr && cdr.Reg2 != 0x18) psxHu32(0x1070)|=0x4; + +#ifdef CDR_LOG + CDR_LOG("Cdr Interrupt %x\n", Irq); +#endif +} + +void cdrReadInterrupt() { + unsigned char *buf; + + if (!cdr.Reading) return; + + if (cdr.Stat) { + CDREAD_INT(0x800); + return; + } + +#ifdef CDR_LOG + CDR_LOG("KEY END"); +#endif + + cdr.OCUP = 1; + SetResultSize(1); + cdr.StatP|= 0x22; + cdr.Result[0] = cdr.StatP; + + buf = CDR_getBuffer(); + if (buf == NULL) cdr.RErr = -1; + + if (cdr.RErr == -1) { +#ifdef CDR_LOG + fprintf(emuLog, " err\n"); +#endif + memset(cdr.Transfer, 0, 2340); + cdr.Stat = DiskError; + cdr.Result[0]|= 0x01; + ReadTrack(); + CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); + return; + } + + memcpy(cdr.Transfer, buf, 2340); + cdr.Stat = DataReady; + +#ifdef CDR_LOG + fprintf(emuLog, " %x:%x:%x\n", cdr.Transfer[0], cdr.Transfer[1], cdr.Transfer[2]); +#endif + + if ((cdr.Muted == 1) && (cdr.Mode & 0x40) && (!Config.Xa) && (cdr.FirstSector != -1)) { // CD-XA + if ((cdr.Transfer[4+2] & 0x4) && + ((cdr.Mode&0x8) ? (cdr.Transfer[4+1] == cdr.Channel) : 1) && + (cdr.Transfer[4+0] == cdr.File)) { + int ret = xa_decode_sector(&cdr.Xa, cdr.Transfer+4, cdr.FirstSector); + + if (!ret) { + SPU_playADPCMchannel(&cdr.Xa); + cdr.FirstSector = 0; + } + else cdr.FirstSector = -1; + } + } + + cdr.SetSector[2]++; + if (cdr.SetSector[2] == 75) { + cdr.SetSector[2] = 0; + cdr.SetSector[1]++; + if (cdr.SetSector[1] == 60) { + cdr.SetSector[1] = 0; + cdr.SetSector[0]++; + } + } + + cdr.Readed = 0; + + if ((cdr.Transfer[4+2] & 0x80) && (cdr.Mode & 0x2)) { // EOF +#ifdef CDR_LOG + CDR_LOG("AutoPausing Read\n"); +#endif +// AddIrqQueue(AUTOPAUSE, 0x800); + AddIrqQueue(CdlPause, 0x800); + } + else { + ReadTrack(); + CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); + } + psxHu32(0x1070)|=0x4; +} + +/* +cdrRead0: + bit 0 - 0 REG1 command send / 1 REG1 data read + bit 1 - 0 data transfer finish / 1 data transfer ready/in progress + bit 2 - unknown + bit 3 - unknown + bit 4 - unknown + bit 5 - 1 result ready + bit 6 - 1 dma ready + bit 7 - 1 command being processed +*/ + +unsigned char cdrRead0(void) { + if (cdr.ResultReady) cdr.Ctrl|= 0x20; + else cdr.Ctrl&=~0x20; + + if (cdr.OCUP) cdr.Ctrl|= 0x40; + else cdr.Ctrl&=~0x40; + + // what means the 0x10 and the 0x08 bits? i only saw it used by the bios + cdr.Ctrl|=0x18; + +#ifdef CDR_LOG + CDR_LOG("CD0 Read: %x\n", cdr.Ctrl); +#endif + return psxHu8(0x1800) = cdr.Ctrl; +} + +/* +cdrWrite0: + 0 - to send a command / 1 - to get the result +*/ + +void cdrWrite0(unsigned char rt) { +#ifdef CDR_LOG + CDR_LOG("CD0 write: %x\n", rt); +#endif + cdr.Ctrl = rt | (cdr.Ctrl & ~0x3); + + if (rt == 0) { + cdr.ParamP = 0; + cdr.ParamC = 0; + cdr.ResultReady = 0; + } +} + +unsigned char cdrRead1(void) { + if (cdr.ResultReady && cdr.Ctrl & 0x1) { + psxHu8(0x1801) = cdr.Result[cdr.ResultP++]; + if (cdr.ResultP == cdr.ResultC) cdr.ResultReady = 0; + } else psxHu8(0x1801) = 0; +#ifdef CDR_LOG + CDR_LOG("CD1 Read: %x\n", psxHu8(0x1801)); +#endif + return psxHu8(0x1801); +} + +void cdrWrite1(unsigned char rt) { + int i; + +#ifdef CDR_LOG + CDR_LOG("CD1 write: %x (%s)\n", rt, CmdName[rt]); +#endif +// psxHu8(0x1801) = rt; + cdr.Cmd = rt; + cdr.OCUP = 0; + +#ifdef CDRCMD_DEBUG + SysPrintf("CD1 write: %x (%s)", rt, CmdName[rt]); + if (cdr.ParamC) { + SysPrintf(" Param[%d] = {", cdr.ParamC); + for (i=0;i cdr.ResultTN[1]) cdr.CurTrack = cdr.ResultTN[1]; + if (CDR_getTD((unsigned char)(cdr.CurTrack), cdr.ResultTD) != -1) { + int tmp = cdr.ResultTD[2]; + cdr.ResultTD[2] = cdr.ResultTD[0]; + cdr.ResultTD[0] = tmp; + if (!Config.Cdda) CDR_play(cdr.ResultTD); + } + } + } + else if (!Config.Cdda) CDR_play(cdr.SetSector); + cdr.Play = 1; + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlForward: + if (cdr.CurTrack < 0xaa) cdr.CurTrack++; + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlBackward: + if (cdr.CurTrack > 1) cdr.CurTrack--; + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlReadN: + cdr.Irq = 0; + StopReading(); + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + StartReading(1); + break; + + case CdlStandby: + StopCdda(); + StopReading(); + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlStop: + StopCdda(); + StopReading(); + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlPause: + StopCdda(); + StopReading(); + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x40000); + break; + + case CdlReset: + case CdlInit: + StopCdda(); + StopReading(); + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlMute: + cdr.Muted = 0; + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlDemute: + cdr.Muted = 1; + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlSetfilter: + cdr.File = cdr.Param[0]; + cdr.Channel = cdr.Param[1]; + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlSetmode: +#ifdef CDR_LOG + CDR_LOG("Setmode %x\n", cdr.Param[0]); +#endif + cdr.Mode = cdr.Param[0]; + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlGetmode: + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlGetlocL: + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlGetlocP: + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlGetTN: + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlGetTD: + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlSeekL: + ((unsigned long *)cdr.SetSectorSeek)[0] = ((unsigned long *)cdr.SetSector)[0]; + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlSeekP: + ((unsigned long *)cdr.SetSectorSeek)[0] = ((unsigned long *)cdr.SetSector)[0]; + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlTest: + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlID: + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlReadS: + cdr.Irq = 0; + StopReading(); + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + StartReading(2); + break; + + case CdlReadToc: + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + default: +#ifdef CDR_LOG + CDR_LOG("Unknown Cmd: %x\n", cdr.Cmd); +#endif + return; + } + if (cdr.Stat != NoIntr) psxHu32(0x1070)|=0x4; +} + +unsigned char cdrRead2(void) { + unsigned char ret; + + if (cdr.Readed == 0) { + ret = 0; + } else { + ret = *cdr.pTransfer++; + } + +#ifdef CDR_LOG + CDR_LOG("CD2 Read: %x\n", ret); +#endif + return ret; +} + +void cdrWrite2(unsigned char rt) { +#ifdef CDR_LOG + CDR_LOG("CD2 write: %x\n", rt); +#endif + if (cdr.Ctrl & 0x1) { + switch (rt) { + case 0x07: + cdr.ParamP = 0; + cdr.ParamC = 0; + cdr.ResultReady = 0; + cdr.Ctrl = 0; + break; + + default: + cdr.Reg2 = rt; + break; + } + } else if (!(cdr.Ctrl & 0x1) && cdr.ParamP < 8) { + cdr.Param[cdr.ParamP++] = rt; + cdr.ParamC++; + } +} + +unsigned char cdrRead3(void) { + if (cdr.Stat) { + if (cdr.Ctrl & 0x1) psxHu8(0x1803) = cdr.Stat | 0xE0; + else psxHu8(0x1803) = 0xff; + } else psxHu8(0x1803) = 0; +#ifdef CDR_LOG + CDR_LOG("CD3 Read: %x\n", psxHu8(0x1803)); +#endif + return psxHu8(0x1803); +} + +void cdrWrite3(unsigned char rt) { +#ifdef CDR_LOG + CDR_LOG("CD3 write: %x\n", rt); +#endif + if (rt == 0x07 && cdr.Ctrl & 0x1) { + cdr.Stat = 0; + + if (cdr.Irq == 0xff) { cdr.Irq = 0; return; } + if (cdr.Irq) CDR_INT(cdr.eCycle); + if (cdr.Reading && !cdr.ResultReady) + CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); + + return; + } + if (rt == 0x80 && !(cdr.Ctrl & 0x1) && cdr.Readed == 0) { + cdr.Readed = 1; + cdr.pTransfer = cdr.Transfer; + + switch (cdr.Mode&0x30) { + case 0x10: + case 0x00: cdr.pTransfer+=12; break; + default: break; + } + } +} + +void psxDma3(u32 madr, u32 bcr, u32 chcr) { + u32 cdsize; + +#ifdef CDR_LOG + CDR_LOG("*** DMA 3 *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); +#endif + + switch (chcr) { + case 0x11000000: + case 0x11400100: + if (cdr.Readed == 0) { +#ifdef CDR_LOG + CDR_LOG("*** DMA 3 *** NOT READY\n"); +#endif + return; + } + + cdsize = (bcr & 0xffff) * 4; + + memcpy((u8*)PSXM(madr), cdr.pTransfer, cdsize); + psxCpu->Clear(madr, cdsize/4); + cdr.pTransfer+=cdsize; + + break; + default: +#ifdef CDR_LOG + CDR_LOG("Unknown cddma %lx\n", chcr); +#endif + break; + } +} + +void cdrReset() { + memset(&cdr, 0, sizeof(cdr)); + cdr.CurTrack=1; + cdr.File=1; cdr.Channel=1; + // with the timing set to 60 Gran Turismo works + // anybody knows why it doesn't with 75? + // 75 is the correct cdrom timing + if (Config.CdTiming) + cdReadTime = (PSXCLK / 60) / BIAS; + // this seems to be the most compatible + // let's leave like this until we know why + // 75 is buggy with some games + else cdReadTime = (PSXCLK / 65) / BIAS; +// else cdReadTime = (PSXCLK / 75) / BIAS; +} + +int cdrFreeze(gzFile f, int Mode) { + int tmp; + + gzfreeze(&cdr, sizeof(cdr)); + + if (Mode == 1) tmp = cdr.pTransfer - cdr.Transfer; + gzfreezel(&tmp); + if (Mode == 0) cdr.pTransfer = cdr.Transfer + tmp; + + return 0; +} + diff --git a/PcsxSrc/CdRom.h b/PcsxSrc/CdRom.h index 66aca78..c589af5 100644 --- a/PcsxSrc/CdRom.h +++ b/PcsxSrc/CdRom.h @@ -1,88 +1,88 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __CDROM_H__ -#define __CDROM_H__ - -#include "PsxCommon.h" -#include "Decode_XA.h" - -typedef struct { - unsigned char OCUP; - unsigned char Reg1Mode; - unsigned char Reg2; - unsigned char CmdProcess; - unsigned char Ctrl; - unsigned char Stat; - - unsigned char StatP; - - unsigned char Transfer[2352]; - unsigned char *pTransfer; - - unsigned char Prev[4]; - unsigned char Param[8]; - unsigned char Result[8]; - - unsigned char ParamC; - unsigned char ParamP; - unsigned char ResultC; - unsigned char ResultP; - unsigned char ResultReady; - unsigned char Cmd; - unsigned char Readed; - unsigned long Reading; - - unsigned char ResultTN[6]; - unsigned char ResultTD[4]; - unsigned char SetSector[4]; - unsigned char SetSectorSeek[4]; - unsigned char Track; - int Play; - int CurTrack; - int Mode, File, Channel, Muted; - int Reset; - int RErr; - int FirstSector; - - xa_decode_t Xa; - - int Init; - - unsigned char Irq; - unsigned long eCycle; - - char Unused[4087]; -} cdrStruct; - -cdrStruct cdr; - -void cdrReset(); -void cdrInterrupt(); -void cdrReadInterrupt(); -unsigned char cdrRead0(void); -unsigned char cdrRead1(void); -unsigned char cdrRead2(void); -unsigned char cdrRead3(void); -void cdrWrite0(unsigned char rt); -void cdrWrite1(unsigned char rt); -void cdrWrite2(unsigned char rt); -void cdrWrite3(unsigned char rt); -int cdrFreeze(gzFile f, int Mode); - -#endif /* __CDROM_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __CDROM_H__ +#define __CDROM_H__ + +#include "PsxCommon.h" +#include "Decode_XA.h" + +typedef struct { + unsigned char OCUP; + unsigned char Reg1Mode; + unsigned char Reg2; + unsigned char CmdProcess; + unsigned char Ctrl; + unsigned char Stat; + + unsigned char StatP; + + unsigned char Transfer[2352]; + unsigned char *pTransfer; + + unsigned char Prev[4]; + unsigned char Param[8]; + unsigned char Result[8]; + + unsigned char ParamC; + unsigned char ParamP; + unsigned char ResultC; + unsigned char ResultP; + unsigned char ResultReady; + unsigned char Cmd; + unsigned char Readed; + unsigned long Reading; + + unsigned char ResultTN[6]; + unsigned char ResultTD[4]; + unsigned char SetSector[4]; + unsigned char SetSectorSeek[4]; + unsigned char Track; + int Play; + int CurTrack; + int Mode, File, Channel, Muted; + int Reset; + int RErr; + int FirstSector; + + xa_decode_t Xa; + + int Init; + + unsigned char Irq; + unsigned long eCycle; + + char Unused[4087]; +} cdrStruct; + +cdrStruct cdr; + +void cdrReset(); +void cdrInterrupt(); +void cdrReadInterrupt(); +unsigned char cdrRead0(void); +unsigned char cdrRead1(void); +unsigned char cdrRead2(void); +unsigned char cdrRead3(void); +void cdrWrite0(unsigned char rt); +void cdrWrite1(unsigned char rt); +void cdrWrite2(unsigned char rt); +void cdrWrite3(unsigned char rt); +int cdrFreeze(gzFile f, int Mode); + +#endif /* __CDROM_H__ */ diff --git a/PcsxSrc/Coff.h b/PcsxSrc/Coff.h index c725aa7..41ac5ec 100644 --- a/PcsxSrc/Coff.h +++ b/PcsxSrc/Coff.h @@ -1,37 +1,37 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __COFF_H__ -#define __COFF_H__ - -/********************** FILE HEADER **********************/ - -struct external_filehdr { - unsigned short f_magic; /* magic number */ - unsigned short f_nscns; /* number of sections */ - unsigned long f_timdat; /* time & date stamp */ - unsigned long f_symptr; /* file pointer to symtab */ - unsigned long f_nsyms; /* number of symtab entries */ - unsigned short f_opthdr; /* sizeof(optional hdr) */ - unsigned short f_flags; /* flags */ -}; - -#define FILHDR struct external_filehdr -#define FILHSZ sizeof(FILHDR) - -#endif /* __COFF_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __COFF_H__ +#define __COFF_H__ + +/********************** FILE HEADER **********************/ + +struct external_filehdr { + unsigned short f_magic; /* magic number */ + unsigned short f_nscns; /* number of sections */ + unsigned long f_timdat; /* time & date stamp */ + unsigned long f_symptr; /* file pointer to symtab */ + unsigned long f_nsyms; /* number of symtab entries */ + unsigned short f_opthdr; /* sizeof(optional hdr) */ + unsigned short f_flags; /* flags */ +}; + +#define FILHDR struct external_filehdr +#define FILHSZ sizeof(FILHDR) + +#endif /* __COFF_H__ */ diff --git a/PcsxSrc/Debug.h b/PcsxSrc/Debug.h index 4012c0b..239972f 100644 --- a/PcsxSrc/Debug.h +++ b/PcsxSrc/Debug.h @@ -1,53 +1,53 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __DEBUG_H__ -#define __DEBUG_H__ - -#include "PsxCommon.h" - -char* disR3000AF(u32 code, u32 pc); - -FILE *emuLog; - -//#define GTE_DUMP - -#ifdef GTE_DUMP -FILE *gteLog; -#endif - -//#define LOG_STDOUT - -//#define PAD_LOG __Log -//#define GTE_LOG __Log -//#define CDR_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log - -//#define PSXHW_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log -//#define PSXBIOS_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log -//#define PSXDMA_LOG __Log -//#define PSXMEM_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log -#define PSXCPU_LOG __Log - -//#define CDRCMD_DEBUG - -#if defined (PSXCPU_LOG) || defined(PSXDMA_LOG) || defined(CDR_LOG) || defined(PSXHW_LOG) || \ - defined(PSXBIOS_LOG) || defined(GTE_LOG) || defined(PAD_LOG) -#define EMU_LOG __Log -#endif - -#endif /* __DEBUG_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __DEBUG_H__ +#define __DEBUG_H__ + +#include "PsxCommon.h" + +char* disR3000AF(u32 code, u32 pc); + +FILE *emuLog; + +//#define GTE_DUMP + +#ifdef GTE_DUMP +FILE *gteLog; +#endif + +//#define LOG_STDOUT + +//#define PAD_LOG __Log +//#define GTE_LOG __Log +//#define CDR_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log + +//#define PSXHW_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log +//#define PSXBIOS_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log +//#define PSXDMA_LOG __Log +//#define PSXMEM_LOG __Log("%8.8lx %8.8lx: ", psxRegs.pc, psxRegs.cycle); __Log +#define PSXCPU_LOG __Log + +//#define CDRCMD_DEBUG + +#if defined (PSXCPU_LOG) || defined(PSXDMA_LOG) || defined(CDR_LOG) || defined(PSXHW_LOG) || \ + defined(PSXBIOS_LOG) || defined(GTE_LOG) || defined(PAD_LOG) +#define EMU_LOG __Log +#endif + +#endif /* __DEBUG_H__ */ diff --git a/PcsxSrc/Decode_XA.c b/PcsxSrc/Decode_XA.c index 3bd53f4..cc7ebe7 100644 --- a/PcsxSrc/Decode_XA.c +++ b/PcsxSrc/Decode_XA.c @@ -1,305 +1,305 @@ -//============================================ -//=== Audio XA decoding -//=== Kazzuya -//============================================ -//=== Modified by linuzappz -//============================================ - -#include - -#include "Decode_XA.h" - -#ifdef __WIN32__ -#pragma warning(disable:4244) -#endif - -typedef unsigned char U8; -typedef unsigned short U16; -typedef unsigned long U32; - -#define NOT(_X_) (!(_X_)) -#define CLAMP(_X_,_MI_,_MA_) {if(_X_<_MI_)_X_=_MI_;if(_X_>_MA_)_X_=_MA_;} - -//============================================ -//=== ADPCM DECODING ROUTINES -//============================================ - -static double K0[4] = { - 0.0, - 0.9375, - 1.796875, - 1.53125 -}; - -static double K1[4] = { - 0.0, - 0.0, - -0.8125, - -0.859375 -}; - -#define BLKSIZ 28 /* block size (32 - 4 nibbles) */ - -//=========================================== -void ADPCM_InitDecode( ADPCM_Decode_t *decp ) -{ - decp->y0 = 0; - decp->y1 = 0; -} - -//=========================================== -#define SH 4 -#define SHC 10 - -#define IK0(fid) ((int)((-K0[fid]) * (1<> 4) & 0x0f; - range = (filter_range >> 0) & 0x0f; - - fy0 = decp->y0; - fy1 = decp->y1; - - for (i = BLKSIZ/4; i; --i) { - long y; - long x0, x1, x2, x3; - - y = *blockp++; - x3 = (short)( y & 0xf000) >> range; x3 <<= SH; - x2 = (short)((y << 4) & 0xf000) >> range; x2 <<= SH; - x1 = (short)((y << 8) & 0xf000) >> range; x1 <<= SH; - x0 = (short)((y << 12) & 0xf000) >> range; x0 <<= SH; - - x0 -= (IK0(filterid) * fy0 + (IK1(filterid) * fy1)) >> SHC; fy1 = fy0; fy0 = x0; - x1 -= (IK0(filterid) * fy0 + (IK1(filterid) * fy1)) >> SHC; fy1 = fy0; fy0 = x1; - x2 -= (IK0(filterid) * fy0 + (IK1(filterid) * fy1)) >> SHC; fy1 = fy0; fy0 = x2; - x3 -= (IK0(filterid) * fy0 + (IK1(filterid) * fy1)) >> SHC; fy1 = fy0; fy0 = x3; - - CLAMP( x0, -32768<> SH; destp += inc; - CLAMP( x1, -32768<> SH; destp += inc; - CLAMP( x2, -32768<> SH; destp += inc; - CLAMP( x3, -32768<> SH; destp += inc; - } - decp->y0 = fy0; - decp->y1 = fy1; -} - -static int headtable[4] = {0,2,8,10}; - -//=========================================== -static void xa_decode_data( xa_decode_t *xdp, unsigned char *srcp ) { - const U8 *sound_groupsp; - const U8 *sound_datap, *sound_datap2; - int i, j, k, nbits; - U16 data[4096], *datap; - short *destp; - - destp = xdp->pcm; - nbits = xdp->nbits == 4 ? 4 : 2; - - if (xdp->stereo) { // stereo - for (j=0; j < 18; j++) { - sound_groupsp = srcp + j * 128; // sound groups header - sound_datap = sound_groupsp + 16; // sound data just after the header - - for (i=0; i < nbits; i++) { - datap = data; - sound_datap2 = sound_datap + i; - if ((xdp->nbits == 8) && (xdp->freq == 37800)) { // level A - for (k=0; k < 14; k++, sound_datap2 += 8) { - *(datap++) = (U16)sound_datap2[0] | - (U16)(sound_datap2[4] << 8); - } - } else { // level B/C - for (k=0; k < 7; k++, sound_datap2 += 16) { - *(datap++) = (U16)(sound_datap2[ 0] & 0x0f) | - ((U16)(sound_datap2[ 4] & 0x0f) << 4) | - ((U16)(sound_datap2[ 8] & 0x0f) << 8) | - ((U16)(sound_datap2[12] & 0x0f) << 12); - } - } - ADPCM_DecodeBlock16( &xdp->left, sound_groupsp[headtable[i]+0], data, - destp+0, 2 ); - - datap = data; - sound_datap2 = sound_datap + i; - if ((xdp->nbits == 8) && (xdp->freq == 37800)) { // level A - for (k=0; k < 14; k++, sound_datap2 += 8) { - *(datap++) = (U16)sound_datap2[0] | - (U16)(sound_datap2[4] << 8); - } - } else { // level B/C - for (k=0; k < 7; k++, sound_datap2 += 16) { - *(datap++) = (U16)(sound_datap2[ 0] >> 4) | - ((U16)(sound_datap2[ 4] >> 4) << 4) | - ((U16)(sound_datap2[ 8] >> 4) << 8) | - ((U16)(sound_datap2[12] >> 4) << 12); - } - } - ADPCM_DecodeBlock16( &xdp->right, sound_groupsp[headtable[i]+1], data, - destp+1, 2 ); - - destp += 28*2; - } - } - } - else { // mono - for (j=0; j < 18; j++) { - sound_groupsp = srcp + j * 128; // sound groups header - sound_datap = sound_groupsp + 16; // sound data just after the header - - for (i=0; i < nbits; i++) { - datap = data; - sound_datap2 = sound_datap + i; - if ((xdp->nbits == 8) && (xdp->freq == 37800)) { // level A - for (k=0; k < 14; k++, sound_datap2 += 8) { - *(datap++) = (U16)sound_datap2[0] | - (U16)(sound_datap2[4] << 8); - } - } else { // level B/C - for (k=0; k < 7; k++, sound_datap2 += 16) { - *(datap++) = (U16)(sound_datap2[ 0] & 0x0f) | - ((U16)(sound_datap2[ 4] & 0x0f) << 4) | - ((U16)(sound_datap2[ 8] & 0x0f) << 8) | - ((U16)(sound_datap2[12] & 0x0f) << 12); - } - } - ADPCM_DecodeBlock16( &xdp->left, sound_groupsp[headtable[i]+0], data, - destp, 1 ); - - destp += 28; - - datap = data; - sound_datap2 = sound_datap + i; - if ((xdp->nbits == 8) && (xdp->freq == 37800)) { // level A - for (k=0; k < 14; k++, sound_datap2 += 8) { - *(datap++) = (U16)sound_datap2[0] | - (U16)(sound_datap2[4] << 8); - } - } else { // level B/C - for (k=0; k < 7; k++, sound_datap2 += 16) { - *(datap++) = (U16)(sound_datap2[ 0] >> 4) | - ((U16)(sound_datap2[ 4] >> 4) << 4) | - ((U16)(sound_datap2[ 8] >> 4) << 8) | - ((U16)(sound_datap2[12] >> 4) << 12); - } - } - ADPCM_DecodeBlock16( &xdp->left, sound_groupsp[headtable[i]+1], data, - destp, 1 ); - - destp += 28; - } - } - } -} - -//============================================ -//=== XA SPECIFIC ROUTINES -//============================================ -typedef struct { -U8 filenum; -U8 channum; -U8 submode; -U8 coding; - -U8 filenum2; -U8 channum2; -U8 submode2; -U8 coding2; -} xa_subheader_t; - -#define SUB_SUB_EOF (1<<7) // end of file -#define SUB_SUB_RT (1<<6) // real-time sector -#define SUB_SUB_FORM (1<<5) // 0 form1 1 form2 -#define SUB_SUB_TRIGGER (1<<4) // used for interrupt -#define SUB_SUB_DATA (1<<3) // contains data -#define SUB_SUB_AUDIO (1<<2) // contains audio -#define SUB_SUB_VIDEO (1<<1) // contains video -#define SUB_SUB_EOR (1<<0) // end of record - -#define AUDIO_CODING_GET_STEREO(_X_) ( (_X_) & 3) -#define AUDIO_CODING_GET_FREQ(_X_) (((_X_) >> 2) & 3) -#define AUDIO_CODING_GET_BPS(_X_) (((_X_) >> 4) & 3) -#define AUDIO_CODING_GET_EMPHASIS(_X_) (((_X_) >> 6) & 1) - -#define SUB_UNKNOWN 0 -#define SUB_VIDEO 1 -#define SUB_AUDIO 2 - -//============================================ -static int parse_xa_audio_sector( xa_decode_t *xdp, - xa_subheader_t *subheadp, - unsigned char *sectorp, - int is_first_sector ) { - if ( is_first_sector ) { - switch ( AUDIO_CODING_GET_FREQ(subheadp->coding) ) { - case 0: xdp->freq = 37800; break; - case 1: xdp->freq = 18900; break; - default: xdp->freq = 0; break; - } - switch ( AUDIO_CODING_GET_BPS(subheadp->coding) ) { - case 0: xdp->nbits = 4; break; - case 1: xdp->nbits = 8; break; - default: xdp->nbits = 0; break; - } - switch ( AUDIO_CODING_GET_STEREO(subheadp->coding) ) { - case 0: xdp->stereo = 0; break; - case 1: xdp->stereo = 1; break; - default: xdp->stereo = 0; break; - } - - if ( xdp->freq == 0 ) - return -1; - - ADPCM_InitDecode( &xdp->left ); - ADPCM_InitDecode( &xdp->right ); - - xdp->nsamples = 18 * 28 * 8; - if (xdp->stereo == 1) xdp->nsamples /= 2; - } - xa_decode_data( xdp, sectorp ); - - return 0; -} - -//================================================================ -//=== THIS IS WHAT YOU HAVE TO CALL -//=== xdp - structure were all important data are returned -//=== sectorp - data in input -//=== pcmp - data in output -//=== is_first_sector - 1 if it's the 1st sector of the stream -//=== - 0 for any other successive sector -//=== return -1 if error -//================================================================ -long xa_decode_sector( xa_decode_t *xdp, - unsigned char *sectorp, int is_first_sector ) { - if (parse_xa_audio_sector(xdp, (xa_subheader_t *)sectorp, sectorp + sizeof(xa_subheader_t), is_first_sector)) - return -1; - - return 0; -} - -/* EXAMPLE: -"nsamples" is the number of 16 bit samples -every sample is 2 bytes in mono and 4 bytes in stereo - -xa_decode_t xa; - - sectorp = read_first_sector(); - xa_decode_sector( &xa, sectorp, 1 ); - play_wave( xa.pcm, xa.freq, xa.nsamples ); - - while ( --n_sectors ) - { - sectorp = read_next_sector(); - xa_decode_sector( &xa, sectorp, 0 ); - play_wave( xa.pcm, xa.freq, xa.nsamples ); - } -*/ +//============================================ +//=== Audio XA decoding +//=== Kazzuya +//============================================ +//=== Modified by linuzappz +//============================================ + +#include + +#include "Decode_XA.h" + +#ifdef __WIN32__ +#pragma warning(disable:4244) +#endif + +typedef unsigned char U8; +typedef unsigned short U16; +typedef unsigned long U32; + +#define NOT(_X_) (!(_X_)) +#define CLAMP(_X_,_MI_,_MA_) {if(_X_<_MI_)_X_=_MI_;if(_X_>_MA_)_X_=_MA_;} + +//============================================ +//=== ADPCM DECODING ROUTINES +//============================================ + +static double K0[4] = { + 0.0, + 0.9375, + 1.796875, + 1.53125 +}; + +static double K1[4] = { + 0.0, + 0.0, + -0.8125, + -0.859375 +}; + +#define BLKSIZ 28 /* block size (32 - 4 nibbles) */ + +//=========================================== +void ADPCM_InitDecode( ADPCM_Decode_t *decp ) +{ + decp->y0 = 0; + decp->y1 = 0; +} + +//=========================================== +#define SH 4 +#define SHC 10 + +#define IK0(fid) ((int)((-K0[fid]) * (1<> 4) & 0x0f; + range = (filter_range >> 0) & 0x0f; + + fy0 = decp->y0; + fy1 = decp->y1; + + for (i = BLKSIZ/4; i; --i) { + long y; + long x0, x1, x2, x3; + + y = *blockp++; + x3 = (short)( y & 0xf000) >> range; x3 <<= SH; + x2 = (short)((y << 4) & 0xf000) >> range; x2 <<= SH; + x1 = (short)((y << 8) & 0xf000) >> range; x1 <<= SH; + x0 = (short)((y << 12) & 0xf000) >> range; x0 <<= SH; + + x0 -= (IK0(filterid) * fy0 + (IK1(filterid) * fy1)) >> SHC; fy1 = fy0; fy0 = x0; + x1 -= (IK0(filterid) * fy0 + (IK1(filterid) * fy1)) >> SHC; fy1 = fy0; fy0 = x1; + x2 -= (IK0(filterid) * fy0 + (IK1(filterid) * fy1)) >> SHC; fy1 = fy0; fy0 = x2; + x3 -= (IK0(filterid) * fy0 + (IK1(filterid) * fy1)) >> SHC; fy1 = fy0; fy0 = x3; + + CLAMP( x0, -32768<> SH; destp += inc; + CLAMP( x1, -32768<> SH; destp += inc; + CLAMP( x2, -32768<> SH; destp += inc; + CLAMP( x3, -32768<> SH; destp += inc; + } + decp->y0 = fy0; + decp->y1 = fy1; +} + +static int headtable[4] = {0,2,8,10}; + +//=========================================== +static void xa_decode_data( xa_decode_t *xdp, unsigned char *srcp ) { + const U8 *sound_groupsp; + const U8 *sound_datap, *sound_datap2; + int i, j, k, nbits; + U16 data[4096], *datap; + short *destp; + + destp = xdp->pcm; + nbits = xdp->nbits == 4 ? 4 : 2; + + if (xdp->stereo) { // stereo + for (j=0; j < 18; j++) { + sound_groupsp = srcp + j * 128; // sound groups header + sound_datap = sound_groupsp + 16; // sound data just after the header + + for (i=0; i < nbits; i++) { + datap = data; + sound_datap2 = sound_datap + i; + if ((xdp->nbits == 8) && (xdp->freq == 37800)) { // level A + for (k=0; k < 14; k++, sound_datap2 += 8) { + *(datap++) = (U16)sound_datap2[0] | + (U16)(sound_datap2[4] << 8); + } + } else { // level B/C + for (k=0; k < 7; k++, sound_datap2 += 16) { + *(datap++) = (U16)(sound_datap2[ 0] & 0x0f) | + ((U16)(sound_datap2[ 4] & 0x0f) << 4) | + ((U16)(sound_datap2[ 8] & 0x0f) << 8) | + ((U16)(sound_datap2[12] & 0x0f) << 12); + } + } + ADPCM_DecodeBlock16( &xdp->left, sound_groupsp[headtable[i]+0], data, + destp+0, 2 ); + + datap = data; + sound_datap2 = sound_datap + i; + if ((xdp->nbits == 8) && (xdp->freq == 37800)) { // level A + for (k=0; k < 14; k++, sound_datap2 += 8) { + *(datap++) = (U16)sound_datap2[0] | + (U16)(sound_datap2[4] << 8); + } + } else { // level B/C + for (k=0; k < 7; k++, sound_datap2 += 16) { + *(datap++) = (U16)(sound_datap2[ 0] >> 4) | + ((U16)(sound_datap2[ 4] >> 4) << 4) | + ((U16)(sound_datap2[ 8] >> 4) << 8) | + ((U16)(sound_datap2[12] >> 4) << 12); + } + } + ADPCM_DecodeBlock16( &xdp->right, sound_groupsp[headtable[i]+1], data, + destp+1, 2 ); + + destp += 28*2; + } + } + } + else { // mono + for (j=0; j < 18; j++) { + sound_groupsp = srcp + j * 128; // sound groups header + sound_datap = sound_groupsp + 16; // sound data just after the header + + for (i=0; i < nbits; i++) { + datap = data; + sound_datap2 = sound_datap + i; + if ((xdp->nbits == 8) && (xdp->freq == 37800)) { // level A + for (k=0; k < 14; k++, sound_datap2 += 8) { + *(datap++) = (U16)sound_datap2[0] | + (U16)(sound_datap2[4] << 8); + } + } else { // level B/C + for (k=0; k < 7; k++, sound_datap2 += 16) { + *(datap++) = (U16)(sound_datap2[ 0] & 0x0f) | + ((U16)(sound_datap2[ 4] & 0x0f) << 4) | + ((U16)(sound_datap2[ 8] & 0x0f) << 8) | + ((U16)(sound_datap2[12] & 0x0f) << 12); + } + } + ADPCM_DecodeBlock16( &xdp->left, sound_groupsp[headtable[i]+0], data, + destp, 1 ); + + destp += 28; + + datap = data; + sound_datap2 = sound_datap + i; + if ((xdp->nbits == 8) && (xdp->freq == 37800)) { // level A + for (k=0; k < 14; k++, sound_datap2 += 8) { + *(datap++) = (U16)sound_datap2[0] | + (U16)(sound_datap2[4] << 8); + } + } else { // level B/C + for (k=0; k < 7; k++, sound_datap2 += 16) { + *(datap++) = (U16)(sound_datap2[ 0] >> 4) | + ((U16)(sound_datap2[ 4] >> 4) << 4) | + ((U16)(sound_datap2[ 8] >> 4) << 8) | + ((U16)(sound_datap2[12] >> 4) << 12); + } + } + ADPCM_DecodeBlock16( &xdp->left, sound_groupsp[headtable[i]+1], data, + destp, 1 ); + + destp += 28; + } + } + } +} + +//============================================ +//=== XA SPECIFIC ROUTINES +//============================================ +typedef struct { +U8 filenum; +U8 channum; +U8 submode; +U8 coding; + +U8 filenum2; +U8 channum2; +U8 submode2; +U8 coding2; +} xa_subheader_t; + +#define SUB_SUB_EOF (1<<7) // end of file +#define SUB_SUB_RT (1<<6) // real-time sector +#define SUB_SUB_FORM (1<<5) // 0 form1 1 form2 +#define SUB_SUB_TRIGGER (1<<4) // used for interrupt +#define SUB_SUB_DATA (1<<3) // contains data +#define SUB_SUB_AUDIO (1<<2) // contains audio +#define SUB_SUB_VIDEO (1<<1) // contains video +#define SUB_SUB_EOR (1<<0) // end of record + +#define AUDIO_CODING_GET_STEREO(_X_) ( (_X_) & 3) +#define AUDIO_CODING_GET_FREQ(_X_) (((_X_) >> 2) & 3) +#define AUDIO_CODING_GET_BPS(_X_) (((_X_) >> 4) & 3) +#define AUDIO_CODING_GET_EMPHASIS(_X_) (((_X_) >> 6) & 1) + +#define SUB_UNKNOWN 0 +#define SUB_VIDEO 1 +#define SUB_AUDIO 2 + +//============================================ +static int parse_xa_audio_sector( xa_decode_t *xdp, + xa_subheader_t *subheadp, + unsigned char *sectorp, + int is_first_sector ) { + if ( is_first_sector ) { + switch ( AUDIO_CODING_GET_FREQ(subheadp->coding) ) { + case 0: xdp->freq = 37800; break; + case 1: xdp->freq = 18900; break; + default: xdp->freq = 0; break; + } + switch ( AUDIO_CODING_GET_BPS(subheadp->coding) ) { + case 0: xdp->nbits = 4; break; + case 1: xdp->nbits = 8; break; + default: xdp->nbits = 0; break; + } + switch ( AUDIO_CODING_GET_STEREO(subheadp->coding) ) { + case 0: xdp->stereo = 0; break; + case 1: xdp->stereo = 1; break; + default: xdp->stereo = 0; break; + } + + if ( xdp->freq == 0 ) + return -1; + + ADPCM_InitDecode( &xdp->left ); + ADPCM_InitDecode( &xdp->right ); + + xdp->nsamples = 18 * 28 * 8; + if (xdp->stereo == 1) xdp->nsamples /= 2; + } + xa_decode_data( xdp, sectorp ); + + return 0; +} + +//================================================================ +//=== THIS IS WHAT YOU HAVE TO CALL +//=== xdp - structure were all important data are returned +//=== sectorp - data in input +//=== pcmp - data in output +//=== is_first_sector - 1 if it's the 1st sector of the stream +//=== - 0 for any other successive sector +//=== return -1 if error +//================================================================ +long xa_decode_sector( xa_decode_t *xdp, + unsigned char *sectorp, int is_first_sector ) { + if (parse_xa_audio_sector(xdp, (xa_subheader_t *)sectorp, sectorp + sizeof(xa_subheader_t), is_first_sector)) + return -1; + + return 0; +} + +/* EXAMPLE: +"nsamples" is the number of 16 bit samples +every sample is 2 bytes in mono and 4 bytes in stereo + +xa_decode_t xa; + + sectorp = read_first_sector(); + xa_decode_sector( &xa, sectorp, 1 ); + play_wave( xa.pcm, xa.freq, xa.nsamples ); + + while ( --n_sectors ) + { + sectorp = read_next_sector(); + xa_decode_sector( &xa, sectorp, 0 ); + play_wave( xa.pcm, xa.freq, xa.nsamples ); + } +*/ diff --git a/PcsxSrc/Decode_XA.h b/PcsxSrc/Decode_XA.h index d363fb4..443da75 100644 --- a/PcsxSrc/Decode_XA.h +++ b/PcsxSrc/Decode_XA.h @@ -1,26 +1,26 @@ -//============================================ -//=== Audio XA decoding -//=== Kazzuya -//============================================ - -#ifndef DECODEXA_H -#define DECODEXA_H - -typedef struct { - long y0, y1; -} ADPCM_Decode_t; - -typedef struct { - int freq; - int nbits; - int stereo; - int nsamples; - ADPCM_Decode_t left, right; - short pcm[16384]; -} xa_decode_t; - -long xa_decode_sector( xa_decode_t *xdp, - unsigned char *sectorp, - int is_first_sector ); - -#endif +//============================================ +//=== Audio XA decoding +//=== Kazzuya +//============================================ + +#ifndef DECODEXA_H +#define DECODEXA_H + +typedef struct { + long y0, y1; +} ADPCM_Decode_t; + +typedef struct { + int freq; + int nbits; + int stereo; + int nsamples; + ADPCM_Decode_t left, right; + short pcm[16384]; +} xa_decode_t; + +long xa_decode_sector( xa_decode_t *xdp, + unsigned char *sectorp, + int is_first_sector ); + +#endif diff --git a/PcsxSrc/DisR3000A.c b/PcsxSrc/DisR3000A.c index d23da72..132ca97 100644 --- a/PcsxSrc/DisR3000A.c +++ b/PcsxSrc/DisR3000A.c @@ -1,318 +1,318 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 "Debug.h" - -char ostr[256]; - -// Names of registers -static char *disRNameGPR[] = { - "r0", "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"}; - -static char *disRNameCP0[] = { - "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*" }; - - -// Type deffinition of our functions - -typedef char* (*TdisR3000AF)(u32 code, u32 pc); - -// These macros are used to assemble the disassembler functions -#define MakeDisFg(fn, b) char* fn(u32 code, u32 pc) { b; return ostr; } -#define MakeDisF(fn, b) \ - static char* fn(u32 code, u32 pc) { \ - sprintf (ostr, "%8.8lx %8.8lx:", pc, code); \ - b; /*ostr[(strlen(ostr) - 1)] = 0;*/ return ostr; \ - } - - -#include "R3000A.h" - -#undef _Funct_ -#undef _Rd_ -#undef _Rt_ -#undef _Rs_ -#undef _Sa_ -#undef _Im_ -#undef _Target_ - -#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 - -#define _Target_ ((pc & 0xf0000000) + ((code & 0x03ffffff) * 4)) -#define _Branch_ (pc + 4 + ((short)_Im_ * 4)) -#define _OfB_ _Im_, _nRs_ - -#define dName(i) sprintf(ostr, "%s %-7s,", ostr, i) -#define dGPR(i) sprintf(ostr, "%s %8.8lx (%s),", ostr, psxRegs.GPR.r[i], disRNameGPR[i]) -#define dCP0(i) sprintf(ostr, "%s %8.8lx (%s),", ostr, psxRegs.CP0.r[i], disRNameCP0[i]) -#define dHI() sprintf(ostr, "%s %8.8lx (%s),", ostr, psxRegs.GPR.n.hi, "hi") -#define dLO() sprintf(ostr, "%s %8.8lx (%s),", ostr, psxRegs.GPR.n.lo, "lo") -#define dImm() sprintf(ostr, "%s %4.4lx (%ld),", ostr, _Im_, _Im_) -#define dTarget() sprintf(ostr, "%s %8.8lx,", ostr, _Target_) -#define dSa() sprintf(ostr, "%s %2.2lx (%ld),", ostr, _Sa_, _Sa_) -#define dOfB() sprintf(ostr, "%s %4.4lx (%8.8lx (%s)),", ostr, _Im_, psxRegs.GPR.r[_Rs_], disRNameGPR[_Rs_]) -#define dOffset() sprintf(ostr, "%s %8.8lx,", ostr, _Branch_) -#define dCode() sprintf(ostr, "%s %8.8lx,", ostr, (code >> 6) & 0xffffff) - -/********************************************************* -* Arithmetic with immediate operand * -* Format: OP rt, rs, immediate * -*********************************************************/ -MakeDisF(disADDI, dName("ADDI"); dGPR(_Rt_); dGPR(_Rs_); dImm();) -MakeDisF(disADDIU, dName("ADDIU"); dGPR(_Rt_); dGPR(_Rs_); dImm();) -MakeDisF(disANDI, dName("ANDI"); dGPR(_Rt_); dGPR(_Rs_); dImm();) -MakeDisF(disORI, dName("ORI"); dGPR(_Rt_); dGPR(_Rs_); dImm();) -MakeDisF(disSLTI, dName("SLTI"); dGPR(_Rt_); dGPR(_Rs_); dImm();) -MakeDisF(disSLTIU, dName("SLTIU"); dGPR(_Rt_); dGPR(_Rs_); dImm();) -MakeDisF(disXORI, dName("XORI"); dGPR(_Rt_); dGPR(_Rs_); dImm();) - -/********************************************************* -* Register arithmetic * -* Format: OP rd, rs, rt * -*********************************************************/ -MakeDisF(disADD, dName("ADD"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) -MakeDisF(disADDU, dName("ADDU"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) -MakeDisF(disAND, dName("AND"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) -MakeDisF(disNOR, dName("NOR"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) -MakeDisF(disOR, dName("OR"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) -MakeDisF(disSLT, dName("SLT"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) -MakeDisF(disSLTU, dName("SLTU"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) -MakeDisF(disSUB, dName("SUB"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) -MakeDisF(disSUBU, dName("SUBU"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) -MakeDisF(disXOR, dName("XOR"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) - -/********************************************************* -* Register arithmetic & Register trap logic * -* Format: OP rs, rt * -*********************************************************/ -MakeDisF(disDIV, dName("DIV"); dGPR(_Rs_); dGPR(_Rt_);) -MakeDisF(disDIVU, dName("DIVU"); dGPR(_Rs_); dGPR(_Rt_);) -MakeDisF(disMULT, dName("MULT"); dGPR(_Rs_); dGPR(_Rt_);) -MakeDisF(disMULTU, dName("MULTU"); dGPR(_Rs_); dGPR(_Rt_);) - -/********************************************************* -* Register branch logic * -* Format: OP rs, offset * -*********************************************************/ -MakeDisF(disBGEZ, dName("BGEZ"); dGPR(_Rs_); dOffset();) -MakeDisF(disBGEZAL, dName("BGEZAL"); dGPR(_Rs_); dOffset();) -MakeDisF(disBGTZ, dName("BGTZ"); dGPR(_Rs_); dOffset();) -MakeDisF(disBLEZ, dName("BLEZ"); dGPR(_Rs_); dOffset();) -MakeDisF(disBLTZ, dName("BLTZ"); dGPR(_Rs_); dOffset();) -MakeDisF(disBLTZAL, dName("BLTZAL"); dGPR(_Rs_); dOffset();) - -/********************************************************* -* Shift arithmetic with constant shift * -* Format: OP rd, rt, sa * -*********************************************************/ -MakeDisF(disSLL, if (code) { dName("SLL"); dGPR(_Rd_); dGPR(_Rt_); dSa(); } else { dName("NOP"); }) -MakeDisF(disSRA, dName("SRA"); dGPR(_Rd_); dGPR(_Rt_); dSa();) -MakeDisF(disSRL, dName("SRL"); dGPR(_Rd_); dGPR(_Rt_); dSa();) - -/********************************************************* -* Shift arithmetic with variant register shift * -* Format: OP rd, rt, rs * -*********************************************************/ -MakeDisF(disSLLV, dName("SLLV"); dGPR(_Rd_); dGPR(_Rt_); dGPR(_Rs_);) -MakeDisF(disSRAV, dName("SRAV"); dGPR(_Rd_); dGPR(_Rt_); dGPR(_Rs_);) -MakeDisF(disSRLV, dName("SRLV"); dGPR(_Rd_); dGPR(_Rt_); dGPR(_Rs_);) - -/********************************************************* -* Load higher 16 bits of the first word in GPR with imm * -* Format: OP rt, immediate * -*********************************************************/ -MakeDisF(disLUI, dName("LUI"); dGPR(_Rt_); dImm();) - -/********************************************************* -* Move from HI/LO to GPR * -* Format: OP rd * -*********************************************************/ -MakeDisF(disMFHI, dName("MFHI"); dGPR(_Rd_); dHI();) -MakeDisF(disMFLO, dName("MFLO"); dGPR(_Rd_); dLO();) - -/********************************************************* -* Move from GPR to HI/LO * -* Format: OP rd * -*********************************************************/ -MakeDisF(disMTHI, dName("MTHI"); dHI(); dGPR(_Rs_);) -MakeDisF(disMTLO, dName("MTLO"); dLO(); dGPR(_Rs_);) - -/********************************************************* -* Special purpose instructions * -* Format: OP * -*********************************************************/ -MakeDisF(disBREAK, dName("BREAK")) -MakeDisF(disRFE, dName("RFE")) -MakeDisF(disSYSCALL, dName("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")) -MakeDisF(disCFC2, dName("CFC2")) -MakeDisF(disMTC2, dName("MTC2")) -MakeDisF(disCTC2, dName("CTC2")) - -/********************************************************* -* Register branch logic * -* Format: OP rs, rt, offset * -*********************************************************/ -MakeDisF(disBEQ, dName("BEQ"); dGPR(_Rs_); dGPR(_Rt_); dOffset();) -MakeDisF(disBNE, dName("BNE"); dGPR(_Rs_); dGPR(_Rt_); dOffset();) - -/********************************************************* -* Jump to target * -* Format: OP target * -*********************************************************/ -MakeDisF(disJ, dName("J"); dTarget();) -MakeDisF(disJAL, dName("JAL"); dTarget(); dGPR(31);) - -/********************************************************* -* Register jump * -* Format: OP rs, rd * -*********************************************************/ -MakeDisF(disJR, dName("JR"); dGPR(_Rs_);) -MakeDisF(disJALR, dName("JALR"); dGPR(_Rs_); dGPR(_Rd_)) - -/********************************************************* -* Load and store for GPR * -* Format: OP rt, offset(base) * -*********************************************************/ -MakeDisF(disLB, dName("LB"); dGPR(_Rt_); dOfB();) -MakeDisF(disLBU, dName("LBU"); dGPR(_Rt_); dOfB();) -MakeDisF(disLH, dName("LH"); dGPR(_Rt_); dOfB();) -MakeDisF(disLHU, dName("LHU"); dGPR(_Rt_); dOfB();) -MakeDisF(disLW, dName("LW"); dGPR(_Rt_); dOfB();) -MakeDisF(disLWL, dName("LWL"); dGPR(_Rt_); dOfB();) -MakeDisF(disLWR, dName("LWR"); dGPR(_Rt_); dOfB();) -MakeDisF(disLWC2, dName("LWC2"); dGPR(_Rt_); dOfB();) -MakeDisF(disSB, dName("SB"); dGPR(_Rt_); dOfB();) -MakeDisF(disSH, dName("SH"); dGPR(_Rt_); dOfB();) -MakeDisF(disSW, dName("SW"); dGPR(_Rt_); dOfB();) -MakeDisF(disSWL, dName("SWL"); dGPR(_Rt_); dOfB();) -MakeDisF(disSWR, dName("SWR"); dGPR(_Rt_); dOfB();) -MakeDisF(disSWC2, dName("SWC2"); dGPR(_Rt_); dOfB();) - -/********************************************************* -* Moves between GPR and COPx * -* Format: OP rt, fs * -*********************************************************/ -MakeDisF(disMFC0, dName("MFC0"); dGPR(_Rt_); dCP0(_Rd_);) -MakeDisF(disMTC0, dName("MTC0"); dCP0(_Rd_); dGPR(_Rt_);) -MakeDisF(disCFC0, dName("CFC0"); dGPR(_Rt_); dCP0(_Rd_);) -MakeDisF(disCTC0, dName("CTC0"); dCP0(_Rd_); dGPR(_Rt_);) - -/********************************************************* -* Unknow instruction (would generate an exception) * -* Format: ? * -*********************************************************/ -MakeDisF(disNULL, dName("*** Bad OP ***");) - - -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_](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_](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_](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_](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_](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)) +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 "Debug.h" + +char ostr[256]; + +// Names of registers +static char *disRNameGPR[] = { + "r0", "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"}; + +static char *disRNameCP0[] = { + "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*" }; + + +// Type deffinition of our functions + +typedef char* (*TdisR3000AF)(u32 code, u32 pc); + +// These macros are used to assemble the disassembler functions +#define MakeDisFg(fn, b) char* fn(u32 code, u32 pc) { b; return ostr; } +#define MakeDisF(fn, b) \ + static char* fn(u32 code, u32 pc) { \ + sprintf (ostr, "%8.8lx %8.8lx:", pc, code); \ + b; /*ostr[(strlen(ostr) - 1)] = 0;*/ return ostr; \ + } + + +#include "R3000A.h" + +#undef _Funct_ +#undef _Rd_ +#undef _Rt_ +#undef _Rs_ +#undef _Sa_ +#undef _Im_ +#undef _Target_ + +#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 + +#define _Target_ ((pc & 0xf0000000) + ((code & 0x03ffffff) * 4)) +#define _Branch_ (pc + 4 + ((short)_Im_ * 4)) +#define _OfB_ _Im_, _nRs_ + +#define dName(i) sprintf(ostr, "%s %-7s,", ostr, i) +#define dGPR(i) sprintf(ostr, "%s %8.8lx (%s),", ostr, psxRegs.GPR.r[i], disRNameGPR[i]) +#define dCP0(i) sprintf(ostr, "%s %8.8lx (%s),", ostr, psxRegs.CP0.r[i], disRNameCP0[i]) +#define dHI() sprintf(ostr, "%s %8.8lx (%s),", ostr, psxRegs.GPR.n.hi, "hi") +#define dLO() sprintf(ostr, "%s %8.8lx (%s),", ostr, psxRegs.GPR.n.lo, "lo") +#define dImm() sprintf(ostr, "%s %4.4lx (%ld),", ostr, _Im_, _Im_) +#define dTarget() sprintf(ostr, "%s %8.8lx,", ostr, _Target_) +#define dSa() sprintf(ostr, "%s %2.2lx (%ld),", ostr, _Sa_, _Sa_) +#define dOfB() sprintf(ostr, "%s %4.4lx (%8.8lx (%s)),", ostr, _Im_, psxRegs.GPR.r[_Rs_], disRNameGPR[_Rs_]) +#define dOffset() sprintf(ostr, "%s %8.8lx,", ostr, _Branch_) +#define dCode() sprintf(ostr, "%s %8.8lx,", ostr, (code >> 6) & 0xffffff) + +/********************************************************* +* Arithmetic with immediate operand * +* Format: OP rt, rs, immediate * +*********************************************************/ +MakeDisF(disADDI, dName("ADDI"); dGPR(_Rt_); dGPR(_Rs_); dImm();) +MakeDisF(disADDIU, dName("ADDIU"); dGPR(_Rt_); dGPR(_Rs_); dImm();) +MakeDisF(disANDI, dName("ANDI"); dGPR(_Rt_); dGPR(_Rs_); dImm();) +MakeDisF(disORI, dName("ORI"); dGPR(_Rt_); dGPR(_Rs_); dImm();) +MakeDisF(disSLTI, dName("SLTI"); dGPR(_Rt_); dGPR(_Rs_); dImm();) +MakeDisF(disSLTIU, dName("SLTIU"); dGPR(_Rt_); dGPR(_Rs_); dImm();) +MakeDisF(disXORI, dName("XORI"); dGPR(_Rt_); dGPR(_Rs_); dImm();) + +/********************************************************* +* Register arithmetic * +* Format: OP rd, rs, rt * +*********************************************************/ +MakeDisF(disADD, dName("ADD"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) +MakeDisF(disADDU, dName("ADDU"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) +MakeDisF(disAND, dName("AND"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) +MakeDisF(disNOR, dName("NOR"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) +MakeDisF(disOR, dName("OR"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) +MakeDisF(disSLT, dName("SLT"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) +MakeDisF(disSLTU, dName("SLTU"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) +MakeDisF(disSUB, dName("SUB"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) +MakeDisF(disSUBU, dName("SUBU"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) +MakeDisF(disXOR, dName("XOR"); dGPR(_Rd_); dGPR(_Rs_); dGPR(_Rt_);) + +/********************************************************* +* Register arithmetic & Register trap logic * +* Format: OP rs, rt * +*********************************************************/ +MakeDisF(disDIV, dName("DIV"); dGPR(_Rs_); dGPR(_Rt_);) +MakeDisF(disDIVU, dName("DIVU"); dGPR(_Rs_); dGPR(_Rt_);) +MakeDisF(disMULT, dName("MULT"); dGPR(_Rs_); dGPR(_Rt_);) +MakeDisF(disMULTU, dName("MULTU"); dGPR(_Rs_); dGPR(_Rt_);) + +/********************************************************* +* Register branch logic * +* Format: OP rs, offset * +*********************************************************/ +MakeDisF(disBGEZ, dName("BGEZ"); dGPR(_Rs_); dOffset();) +MakeDisF(disBGEZAL, dName("BGEZAL"); dGPR(_Rs_); dOffset();) +MakeDisF(disBGTZ, dName("BGTZ"); dGPR(_Rs_); dOffset();) +MakeDisF(disBLEZ, dName("BLEZ"); dGPR(_Rs_); dOffset();) +MakeDisF(disBLTZ, dName("BLTZ"); dGPR(_Rs_); dOffset();) +MakeDisF(disBLTZAL, dName("BLTZAL"); dGPR(_Rs_); dOffset();) + +/********************************************************* +* Shift arithmetic with constant shift * +* Format: OP rd, rt, sa * +*********************************************************/ +MakeDisF(disSLL, if (code) { dName("SLL"); dGPR(_Rd_); dGPR(_Rt_); dSa(); } else { dName("NOP"); }) +MakeDisF(disSRA, dName("SRA"); dGPR(_Rd_); dGPR(_Rt_); dSa();) +MakeDisF(disSRL, dName("SRL"); dGPR(_Rd_); dGPR(_Rt_); dSa();) + +/********************************************************* +* Shift arithmetic with variant register shift * +* Format: OP rd, rt, rs * +*********************************************************/ +MakeDisF(disSLLV, dName("SLLV"); dGPR(_Rd_); dGPR(_Rt_); dGPR(_Rs_);) +MakeDisF(disSRAV, dName("SRAV"); dGPR(_Rd_); dGPR(_Rt_); dGPR(_Rs_);) +MakeDisF(disSRLV, dName("SRLV"); dGPR(_Rd_); dGPR(_Rt_); dGPR(_Rs_);) + +/********************************************************* +* Load higher 16 bits of the first word in GPR with imm * +* Format: OP rt, immediate * +*********************************************************/ +MakeDisF(disLUI, dName("LUI"); dGPR(_Rt_); dImm();) + +/********************************************************* +* Move from HI/LO to GPR * +* Format: OP rd * +*********************************************************/ +MakeDisF(disMFHI, dName("MFHI"); dGPR(_Rd_); dHI();) +MakeDisF(disMFLO, dName("MFLO"); dGPR(_Rd_); dLO();) + +/********************************************************* +* Move from GPR to HI/LO * +* Format: OP rd * +*********************************************************/ +MakeDisF(disMTHI, dName("MTHI"); dHI(); dGPR(_Rs_);) +MakeDisF(disMTLO, dName("MTLO"); dLO(); dGPR(_Rs_);) + +/********************************************************* +* Special purpose instructions * +* Format: OP * +*********************************************************/ +MakeDisF(disBREAK, dName("BREAK")) +MakeDisF(disRFE, dName("RFE")) +MakeDisF(disSYSCALL, dName("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")) +MakeDisF(disCFC2, dName("CFC2")) +MakeDisF(disMTC2, dName("MTC2")) +MakeDisF(disCTC2, dName("CTC2")) + +/********************************************************* +* Register branch logic * +* Format: OP rs, rt, offset * +*********************************************************/ +MakeDisF(disBEQ, dName("BEQ"); dGPR(_Rs_); dGPR(_Rt_); dOffset();) +MakeDisF(disBNE, dName("BNE"); dGPR(_Rs_); dGPR(_Rt_); dOffset();) + +/********************************************************* +* Jump to target * +* Format: OP target * +*********************************************************/ +MakeDisF(disJ, dName("J"); dTarget();) +MakeDisF(disJAL, dName("JAL"); dTarget(); dGPR(31);) + +/********************************************************* +* Register jump * +* Format: OP rs, rd * +*********************************************************/ +MakeDisF(disJR, dName("JR"); dGPR(_Rs_);) +MakeDisF(disJALR, dName("JALR"); dGPR(_Rs_); dGPR(_Rd_)) + +/********************************************************* +* Load and store for GPR * +* Format: OP rt, offset(base) * +*********************************************************/ +MakeDisF(disLB, dName("LB"); dGPR(_Rt_); dOfB();) +MakeDisF(disLBU, dName("LBU"); dGPR(_Rt_); dOfB();) +MakeDisF(disLH, dName("LH"); dGPR(_Rt_); dOfB();) +MakeDisF(disLHU, dName("LHU"); dGPR(_Rt_); dOfB();) +MakeDisF(disLW, dName("LW"); dGPR(_Rt_); dOfB();) +MakeDisF(disLWL, dName("LWL"); dGPR(_Rt_); dOfB();) +MakeDisF(disLWR, dName("LWR"); dGPR(_Rt_); dOfB();) +MakeDisF(disLWC2, dName("LWC2"); dGPR(_Rt_); dOfB();) +MakeDisF(disSB, dName("SB"); dGPR(_Rt_); dOfB();) +MakeDisF(disSH, dName("SH"); dGPR(_Rt_); dOfB();) +MakeDisF(disSW, dName("SW"); dGPR(_Rt_); dOfB();) +MakeDisF(disSWL, dName("SWL"); dGPR(_Rt_); dOfB();) +MakeDisF(disSWR, dName("SWR"); dGPR(_Rt_); dOfB();) +MakeDisF(disSWC2, dName("SWC2"); dGPR(_Rt_); dOfB();) + +/********************************************************* +* Moves between GPR and COPx * +* Format: OP rt, fs * +*********************************************************/ +MakeDisF(disMFC0, dName("MFC0"); dGPR(_Rt_); dCP0(_Rd_);) +MakeDisF(disMTC0, dName("MTC0"); dCP0(_Rd_); dGPR(_Rt_);) +MakeDisF(disCFC0, dName("CFC0"); dGPR(_Rt_); dCP0(_Rd_);) +MakeDisF(disCTC0, dName("CTC0"); dCP0(_Rd_); dGPR(_Rt_);) + +/********************************************************* +* Unknow instruction (would generate an exception) * +* Format: ? * +*********************************************************/ +MakeDisF(disNULL, dName("*** Bad OP ***");) + + +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_](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_](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_](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_](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_](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)) diff --git a/PcsxSrc/Gte.c b/PcsxSrc/Gte.c index 4278161..ccacbda 100644 --- a/PcsxSrc/Gte.c +++ b/PcsxSrc/Gte.c @@ -1,2846 +1,2846 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include -#include "Gte.h" -#include "R3000A.h" - -#ifdef GTE_DUMP -#define G_OP(name,delay) fprintf(gteLog, "* : %08X : %02d : %s\n", psxRegs.code, delay, name); -#define G_SD(reg) fprintf(gteLog, "+D%02d : %08X\n", reg, psxRegs.CP2D.r[reg]); -#define G_SC(reg) fprintf(gteLog, "+C%02d : %08X\n", reg, psxRegs.CP2C.r[reg]); -#define G_GD(reg) fprintf(gteLog, "-D%02d : %08X\n", reg, psxRegs.CP2D.r[reg]); -#define G_GC(reg) fprintf(gteLog, "-C%02d : %08X\n", reg, psxRegs.CP2C.r[reg]); -#else -#define G_OP(name,delay) -#define G_SD(reg) -#define G_SC(reg) -#define G_GD(reg) -#define G_GC(reg) -#endif - -#define SUM_FLAG if(gteFLAG & 0x7F87E000) gteFLAG |= 0x80000000; - -#ifdef __WIN32__ -#pragma warning(disable:4244) -#endif - -#define gteVX0 ((s16*)psxRegs.CP2D.r)[0] -#define gteVY0 ((s16*)psxRegs.CP2D.r)[1] -#define gteVZ0 ((s16*)psxRegs.CP2D.r)[2] -#define gteVX1 ((s16*)psxRegs.CP2D.r)[4] -#define gteVY1 ((s16*)psxRegs.CP2D.r)[5] -#define gteVZ1 ((s16*)psxRegs.CP2D.r)[6] -#define gteVX2 ((s16*)psxRegs.CP2D.r)[8] -#define gteVY2 ((s16*)psxRegs.CP2D.r)[9] -#define gteVZ2 ((s16*)psxRegs.CP2D.r)[10] -#define gteRGB psxRegs.CP2D.r[6] -#define gteOTZ ((s16*)psxRegs.CP2D.r)[7*2] -#define gteIR0 ((s32*)psxRegs.CP2D.r)[8] -#define gteIR1 ((s32*)psxRegs.CP2D.r)[9] -#define gteIR2 ((s32*)psxRegs.CP2D.r)[10] -#define gteIR3 ((s32*)psxRegs.CP2D.r)[11] -#define gteSX0 ((s16*)psxRegs.CP2D.r)[12*2] -#define gteSY0 ((s16*)psxRegs.CP2D.r)[12*2+1] -#define gteSX1 ((s16*)psxRegs.CP2D.r)[13*2] -#define gteSY1 ((s16*)psxRegs.CP2D.r)[13*2+1] -#define gteSX2 ((s16*)psxRegs.CP2D.r)[14*2] -#define gteSY2 ((s16*)psxRegs.CP2D.r)[14*2+1] -#define gteSXP ((s16*)psxRegs.CP2D.r)[15*2] -#define gteSYP ((s16*)psxRegs.CP2D.r)[15*2+1] -#define gteSZx ((u16*)psxRegs.CP2D.r)[16*2] -#define gteSZ0 ((u16*)psxRegs.CP2D.r)[17*2] -#define gteSZ1 ((u16*)psxRegs.CP2D.r)[18*2] -#define gteSZ2 ((u16*)psxRegs.CP2D.r)[19*2] -#define gteRGB0 psxRegs.CP2D.r[20] -#define gteRGB1 psxRegs.CP2D.r[21] -#define gteRGB2 psxRegs.CP2D.r[22] -#define gteMAC0 psxRegs.CP2D.r[24] -#define gteMAC1 ((s32*)psxRegs.CP2D.r)[25] -#define gteMAC2 ((s32*)psxRegs.CP2D.r)[26] -#define gteMAC3 ((s32*)psxRegs.CP2D.r)[27] -#define gteIRGB psxRegs.CP2D.r[28] -#define gteORGB psxRegs.CP2D.r[29] -#define gteLZCS psxRegs.CP2D.r[30] -#define gteLZCR psxRegs.CP2D.r[31] - -#define gteR ((u8 *)psxRegs.CP2D.r)[6*4] -#define gteG ((u8 *)psxRegs.CP2D.r)[6*4+1] -#define gteB ((u8 *)psxRegs.CP2D.r)[6*4+2] -#define gteCODE ((u8 *)psxRegs.CP2D.r)[6*4+3] -#define gteC gteCODE - -#define gteR0 ((u8 *)psxRegs.CP2D.r)[20*4] -#define gteG0 ((u8 *)psxRegs.CP2D.r)[20*4+1] -#define gteB0 ((u8 *)psxRegs.CP2D.r)[20*4+2] -#define gteCODE0 ((u8 *)psxRegs.CP2D.r)[20*4+3] -#define gteC0 gteCODE0 - -#define gteR1 ((u8 *)psxRegs.CP2D.r)[21*4] -#define gteG1 ((u8 *)psxRegs.CP2D.r)[21*4+1] -#define gteB1 ((u8 *)psxRegs.CP2D.r)[21*4+2] -#define gteCODE1 ((u8 *)psxRegs.CP2D.r)[21*4+3] -#define gteC1 gteCODE1 - -#define gteR2 ((u8 *)psxRegs.CP2D.r)[22*4] -#define gteG2 ((u8 *)psxRegs.CP2D.r)[22*4+1] -#define gteB2 ((u8 *)psxRegs.CP2D.r)[22*4+2] -#define gteCODE2 ((u8 *)psxRegs.CP2D.r)[22*4+3] -#define gteC2 gteCODE2 - - - -#define gteR11 ((s16*)psxRegs.CP2C.r)[0] -#define gteR12 ((s16*)psxRegs.CP2C.r)[1] -#define gteR13 ((s16*)psxRegs.CP2C.r)[2] -#define gteR21 ((s16*)psxRegs.CP2C.r)[3] -#define gteR22 ((s16*)psxRegs.CP2C.r)[4] -#define gteR23 ((s16*)psxRegs.CP2C.r)[5] -#define gteR31 ((s16*)psxRegs.CP2C.r)[6] -#define gteR32 ((s16*)psxRegs.CP2C.r)[7] -#define gteR33 ((s16*)psxRegs.CP2C.r)[8] -#define gteTRX ((s32*)psxRegs.CP2C.r)[5] -#define gteTRY ((s32*)psxRegs.CP2C.r)[6] -#define gteTRZ ((s32*)psxRegs.CP2C.r)[7] -#define gteL11 ((s16*)psxRegs.CP2C.r)[16] -#define gteL12 ((s16*)psxRegs.CP2C.r)[17] -#define gteL13 ((s16*)psxRegs.CP2C.r)[18] -#define gteL21 ((s16*)psxRegs.CP2C.r)[19] -#define gteL22 ((s16*)psxRegs.CP2C.r)[20] -#define gteL23 ((s16*)psxRegs.CP2C.r)[21] -#define gteL31 ((s16*)psxRegs.CP2C.r)[22] -#define gteL32 ((s16*)psxRegs.CP2C.r)[23] -#define gteL33 ((s16*)psxRegs.CP2C.r)[24] -#define gteRBK ((s32*)psxRegs.CP2C.r)[13] -#define gteGBK ((s32*)psxRegs.CP2C.r)[14] -#define gteBBK ((s32*)psxRegs.CP2C.r)[15] -#define gteLR1 ((s16*)psxRegs.CP2C.r)[32] -#define gteLR2 ((s16*)psxRegs.CP2C.r)[33] -#define gteLR3 ((s16*)psxRegs.CP2C.r)[34] -#define gteLG1 ((s16*)psxRegs.CP2C.r)[35] -#define gteLG2 ((s16*)psxRegs.CP2C.r)[36] -#define gteLG3 ((s16*)psxRegs.CP2C.r)[37] -#define gteLB1 ((s16*)psxRegs.CP2C.r)[38] -#define gteLB2 ((s16*)psxRegs.CP2C.r)[39] -#define gteLB3 ((s16*)psxRegs.CP2C.r)[40] -#define gteRFC ((s32*)psxRegs.CP2C.r)[21] -#define gteGFC ((s32*)psxRegs.CP2C.r)[22] -#define gteBFC ((s32*)psxRegs.CP2C.r)[23] -#define gteOFX ((s32*)psxRegs.CP2C.r)[24] -#define gteOFY ((s32*)psxRegs.CP2C.r)[25] -#define gteH ((u16*)psxRegs.CP2C.r)[52] -#define gteDQA ((s16*)psxRegs.CP2C.r)[54] -#define gteDQB ((s32*)psxRegs.CP2C.r)[28] -#define gteZSF3 ((s16*)psxRegs.CP2C.r)[58] -#define gteZSF4 ((s16*)psxRegs.CP2C.r)[60] -#define gteFLAG psxRegs.CP2C.r[31] - -__inline unsigned long MFC2(int reg) { - switch(reg) { - case 29: - gteORGB = (gteIR1 ) | - (gteIR2 << 5) | - (gteIR3 << 10); -// gteORGB = ((gteIR1 & 0xf80)>>7) | -// ((gteIR2 & 0xf80)>>2) | -// ((gteIR3 & 0xf80)<<3); - return gteORGB; - - default: - return psxRegs.CP2D.r[reg]; - } -} - -__inline void MTC2(unsigned long value, int reg) { - int a; - - switch(reg) { - case 8: case 9: case 10: case 11: - psxRegs.CP2D.r[reg] = (short)value; - break; - - case 15: - psxRegs.CP2D.r[12] = psxRegs.CP2D.r[13]; - psxRegs.CP2D.r[13] = psxRegs.CP2D.r[14]; - psxRegs.CP2D.r[14] = value; - psxRegs.CP2D.r[15] = value; - break; - - case 16: case 17: case 18: case 19: - psxRegs.CP2D.r[reg] = (value & 0xffff); - break; - - case 28: - psxRegs.CP2D.r[28] = value; - gteIR1 = (value ) & 0x1f; - gteIR2 = (value >> 5) & 0x1f; - gteIR3 = (value >> 10) & 0x1f; -// gteIR1 = ((value ) & 0x1f) << 4; -// gteIR2 = ((value >> 5) & 0x1f) << 4; -// gteIR3 = ((value >> 10) & 0x1f) << 4; - break; - - case 30: - psxRegs.CP2D.r[30] = value; - - a = psxRegs.CP2D.r[30]; -#if defined(__WIN32__) - if (a > 0) { - __asm { - mov eax, a; - bsr eax, eax; - mov a, eax; - } - psxRegs.CP2D.r[31] = 31 - a; - } else if (a < 0) { - __asm { - mov eax, a; - xor eax, 0xffffffff; - bsr eax, eax; - mov a, eax; - } - psxRegs.CP2D.r[31] = 31 - a; - } else { - psxRegs.CP2D.r[31] = 32; - } -#elif defined(__LINUX__) - if (a > 0) { - __asm__ ("bsrl %1, %0\n" : "=r"(a) : "r"(a) ); - psxRegs.CP2D.r[31] = 31 - a; - } else if (a < 0) { - a^= 0xffffffff; - __asm__ ("bsrl %1, %0\n" : "=r"(a) : "r"(a) ); - psxRegs.CP2D.r[31] = 31 - a; - } else { - psxRegs.CP2D.r[31] = 32; - } -#else - if (a > 0) { - int i; - for (i=31; (a & (1 << i)) == 0 && i >= 0; i--); - psxRegs.CP2D.r[31] = 31 - i; - } else if (a < 0) { - int i; - a^= 0xffffffff; - for (i=31; (a & (1 << i)) == 0 && i >= 0; i--); - psxRegs.CP2D.r[31] = 31 - i; - } else { - psxRegs.CP2D.r[31] = 32; - } -#endif - break; - - default: - psxRegs.CP2D.r[reg] = value; - } -} - -void gteMFC2() { - if (!_Rt_) return; - psxRegs.GPR.r[_Rt_] = MFC2(_Rd_); -} - -void gteCFC2() { - if (!_Rt_) return; - psxRegs.GPR.r[_Rt_] = psxRegs.CP2C.r[_Rd_]; -} - -void gteMTC2() { - MTC2(psxRegs.GPR.r[_Rt_], _Rd_); -} - -void gteCTC2() { - psxRegs.CP2C.r[_Rd_] = psxRegs.GPR.r[_Rt_]; -} - -#define _oB_ (psxRegs.GPR.r[_Rs_] + _Imm_) - -void gteLWC2() { - MTC2(psxMemRead32(_oB_), _Rt_); -} - -void gteSWC2() { - psxMemWrite32(_oB_, MFC2(_Rt_)); -} - -/////LIMITATIONS AND OTHER STUFF************************************ -#define MAC2IR() \ -{ \ - if (gteMAC1 < (long)(-32768)) { gteIR1=(long)(-32768); gteFLAG|=1<<24;} \ - else \ - if (gteMAC1 > (long)( 32767)) { gteIR1=(long)( 32767); gteFLAG|=1<<24;} \ - else gteIR1=(long)gteMAC1; \ - if (gteMAC2 < (long)(-32768)) { gteIR2=(long)(-32768); gteFLAG|=1<<23;} \ - else \ - if (gteMAC2 > (long)( 32767)) { gteIR2=(long)( 32767); gteFLAG|=1<<23;} \ - else gteIR2=(long)gteMAC2; \ - if (gteMAC3 < (long)(-32768)) { gteIR3=(long)(-32768); gteFLAG|=1<<22;} \ - else \ - if (gteMAC3 > (long)( 32767)) { gteIR3=(long)( 32767); gteFLAG|=1<<22;} \ - else gteIR3=(long)gteMAC3; \ -} - - -#define MAC2IR1() \ -{ \ - if (gteMAC1 < (long)0) { gteIR1=(long)0; gteFLAG|=1<<24;} \ - else if (gteMAC1 > (long)(32767)) { gteIR1=(long)(32767); gteFLAG|=1<<24;} \ - else gteIR1=(long)gteMAC1; \ - if (gteMAC2 < (long)0) { gteIR2=(long)0; gteFLAG|=1<<23;} \ - else if (gteMAC2 > (long)(32767)) { gteIR2=(long)(32767); gteFLAG|=1<<23;} \ - else gteIR2=(long)gteMAC2; \ - if (gteMAC3 < (long)0) { gteIR3=(long)0; gteFLAG|=1<<22;} \ - else if (gteMAC3 > (long)(32767)) { gteIR3=(long)(32767); gteFLAG|=1<<22;} \ - else gteIR3=(long)gteMAC3; \ -} - - - -/* -#define MAGIC (((65536. * 65536. * 16) + (65536.*.5)) * 65536.) - -static __inline long float2int(double d) -{ - double dtemp = MAGIC + d; - return (*(long *)&dtemp)-0x80000000; -}*/ -__inline double NC_OVERFLOW1(double x) -{ - if (x<-2147483648.0) {gteFLAG |= 1<<29;} - else - if (x> 2147483647.0) {gteFLAG |= 1<<26;} - - return x; -} - -__inline double NC_OVERFLOW2(double x) -{ - if (x<-2147483648.0) {gteFLAG |= 1<<28;} - else - if (x> 2147483647.0) {gteFLAG |= 1<<25;} - - return x; -} - -__inline double NC_OVERFLOW3(double x) -{ - if (x<-2147483648.0) {gteFLAG |= 1<<27;} - else - if (x> 2147483647.0) {gteFLAG |= 1<<24;} - - return x; -} - -__inline double NC_OVERFLOW4(double x) -{ - if (x<-2147483648.0) {gteFLAG |= 1<<16;} - else - if (x> 2147483647.0) {gteFLAG |= 1<<15;} - - return x; -} -/* -__inline double EDETEC1(double data) -{ - if (data<(double)-2147483647) {gteFLAG|=1<<30; return (double)-2147483647;} - else - if (data>(double) 2147483647) {gteFLAG|=1<<27; return (double) 2147483647;} - - else return data; -} - -__inline double EDETEC2(double data) -{ - if (data<(double)-2147483647) {gteFLAG|=1<<29; return (double)-2147483647;} - else - if (data>(double) 2147483647) {gteFLAG|=1<<26; return (double) 2147483647;} - - else return data; -} - -__inline double EDETEC3(double data) -{ - if (data<(double)-2147483647) {gteFLAG|=1<<28; return (double)-2147483647;} - else - if (data>(double) 2147483647) {gteFLAG|=1<<25; return (double) 2147483647;} - - else return data; -} - -__inline double EDETEC4(double data) -{ - if (data<(double)-2147483647) {gteFLAG|=1<<16; return (double)-2147483647;} - else - if (data>(double) 2147483647) {gteFLAG|=1<<15; return (double) 2147483647;} - - else return data; -}*/ -/* -double LimitAU(double fraction,unsigned long bitIndex) { - if (fraction < 0.0) { fraction = 0.0; gteFLAG |= (1< 32767.0) { fraction = 32767.0; gteFLAG |= (1< 32767.0) { fraction = 32767.0; gteFLAG |= (1< 255.0) { fraction = 255.0; gteFLAG |= (1< 65535.0) { fraction = 65535.0; gteFLAG |= (1< 1023.0) { fraction = 1023.0; gteFLAG |= (1< 1023.0) { fraction = 1023.0; gteFLAG |= (1<MAX) {gteFLAG|=1<MAX) return MAX; - - else return data; -} - -double OLIMIT(double data) -{ - data=(data); - - if (data<(double)-2147483647) {return (double)-2147483647;} - else - if (data>(double) 2147483647) {return (double) 2147483647;} - - else return data; -}*/ - -double limA1S(double x) { - - if (x <-32768.0) { x =-32768.0; gteFLAG |= (1<<24); } else - if (x > 32767.0) { x = 32767.0; gteFLAG |= (1<<24); } return (x); -} - -double limA2S(double x) { - - if (x <-32768.0) { x =-32768.0; gteFLAG |= (1<<23); } else - if (x > 32767.0) { x = 32767.0; gteFLAG |= (1<<23); } return (x); -} - -double limA3S(double x) { - - if (x <-32768.0) { x =-32768.0; gteFLAG |= (1<<22); } else - if (x > 32767.0) { x = 32767.0; gteFLAG |= (1<<22); } return (x); -} - -double limA1U(double x) { - - if (x < 0.0) { x = 0.0; gteFLAG |= (1<<24); } else - if (x > 32767.0) { x = 32767.0; gteFLAG |= (1<<24); } return (x); -} - -double limA2U(double x) { - - if (x < 0.0) { x = 0.0; gteFLAG |= (1<<23); } else - if (x > 32767.0) { x = 32767.0; gteFLAG |= (1<<23); } return (x); -} - -double limA3U(double x) { - - if (x < 0.0) { x = 0.0; gteFLAG |= (1<<22); } else - if (x > 32767.0) { x = 32767.0; gteFLAG |= (1<<22); } return (x); -} - -double limB1 (double x) { - - if (x < 0.0) { x = 0.0; gteFLAG |= (1<<21); } else - if (x > 255.0) { x = 255.0; gteFLAG |= (1<<21); } return (x); -} - -double limB2 (double x) { - - if (x < 0.0) { x = 0.0; gteFLAG |= (1<<20); } else - if (x > 255.0) { x = 255.0; gteFLAG |= (1<<20); } return (x); -} - -double limB3 (double x) { - - if (x < 0.0) { x = 0.0; gteFLAG |= (1<<19); } else - if (x > 255.0) { x = 255.0; gteFLAG |= (1<<19); } return (x); -} - -double limC (double x) { - - if (x < 0.0) { x = 0.0; gteFLAG |= (1<<18); } else - if (x > 65535.0) { x = 65535.0; gteFLAG |= (1<<18); } return (x); -} - -double limD1 (double x) { - - if (x < 1024.0) { x = 1024.0; gteFLAG |= (1<<14); } else - if (x > 1023.0) { x = 1023.0; gteFLAG |= (1<<14); } return (x); -} - -double limD2 (double x) { - - if (x < 1024.0) { x = 1024.0; gteFLAG |= (1<<13); } else - if (x > 1023.0) { x = 1023.0; gteFLAG |= (1<<13); } return (x); -} - -double limE (double x) { - - if (x < 0.0) { x = 0.0; gteFLAG |= (1<<12); } else - if (x > 4095.0) { x = 4095.0; gteFLAG |= (1<<12); } return (x); -} - -double limG1(double x) { - - if (x > 2147483647.0f) { gteFLAG |= (1<<16); } else - if (x <-2147483648.0f) { gteFLAG |= (1<<15); } - - if (x > 1023.0f) { x = 1023.0f; gteFLAG |= (1<<14); } else - if (x < -1024.0f) { x = -1024.0f; gteFLAG |= (1<<14); } return (x); -} - -double limG2(double x) { - - if (x > 2147483647.0f) { gteFLAG |= (1<<16); } else - if (x <-2147483648.0f) { gteFLAG |= (1<<15); } - - if (x > 1023.0f) { x = 1023.0f; gteFLAG |= (1<<13); } else - if (x < -1024.0f) { x = -1024.0f; gteFLAG |= (1<<13); } return (x); -} - -//********END OF LIMITATIONS**********************************/ - -void gteRTPS() { -// double SSX0,SSY0,SSZ0; -// double SZ; - double DSZ; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif - -#ifdef GTE_LOG - GTE_LOG("GTE_RTPS\n"); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("RTPS", 14); - G_SD(0); - G_SD(1); - - G_SD(16); // Store original fifo - G_SD(17); - G_SD(18); - G_SD(19); - - G_SC(0); - G_SC(1); - G_SC(2); - G_SC(3); - G_SC(4); - G_SC(5); - G_SC(6); - G_SC(7); - - G_SC(24); - G_SC(25); - G_SC(26); - G_SC(27); - G_SC(28); - } -#endif -/* gteFLAG = 0; - - SSX0 = NC_OVERFLOW1((double)gteTRX + ((double)(gteVX0*gteR11) + (double)(gteVY0*gteR12) + (double)(gteVZ0*gteR13))/4096.0); - SSY0 = NC_OVERFLOW2((double)gteTRY + ((double)(gteVX0*gteR21) + (double)(gteVY0*gteR22) + (double)(gteVZ0*gteR23))/4096.0); - SSZ0 = NC_OVERFLOW3((double)gteTRZ + ((double)(gteVX0*gteR31) + (double)(gteVY0*gteR32) + (double)(gteVZ0*gteR33))/4096.0); - - SZ = LIMIT(SSZ0,(double)0,(double)65535,18); - DSZ = ((double)gteH/SZ); - - if ((DSZ>(double)2147483647)) {DSZ=(double)2; gteFLAG|=1<<17;} - - gteSZ0 = gteSZ1; - gteSZ1 = gteSZ2; - gteSZ2 = gteSZx; - gteSZx = (unsigned short)float2int(SZ); - - psxRegs.CP2D.r[12]= psxRegs.CP2D.r[13]; - psxRegs.CP2D.r[13]= psxRegs.CP2D.r[14]; - - gteSX2 = (signed short)float2int(LIMIT((double)(gteOFX)/65536.0f + (LimitAS(SSX0,24)*DSZ),(double)-1024,(double)1024,14)); - gteSY2 = (signed short)float2int(LIMIT((double)(gteOFY)/65536.0f + (LimitAS(SSY0,23)*DSZ),(double)-1024,(double)1024,13)); - - gteMAC1 = (signed long)(SSX0); - gteMAC2 = (signed long)(SSY0); - gteMAC3 = (signed long)(SSZ0); - - MAC2IR(); - - gteMAC0 = (signed long)float2int(OLIMIT((((double)gteDQB/(double)16777216) + (((double)gteDQA/(double)256)*DSZ))*16777216)); - gteIR0 = (signed long)float2int(LIMIT(((((double)gteDQB/(double)16777216) + (((double)gteDQA/(double)256)*DSZ))*4096),(double)0,(double)4095,12)); - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - - gteFLAG = 0; - - gteMAC1 = NC_OVERFLOW1(((signed long)(gteR11*gteVX0 + gteR12*gteVY0 + gteR13*gteVZ0)>>12) + gteTRX); - gteMAC2 = NC_OVERFLOW2(((signed long)(gteR21*gteVX0 + gteR22*gteVY0 + gteR23*gteVZ0)>>12) + gteTRY); - gteMAC3 = NC_OVERFLOW3(((signed long)(gteR31*gteVX0 + gteR32*gteVY0 + gteR33*gteVZ0)>>12) + gteTRZ); - - gteSZx = gteSZ0; - gteSZ0 = gteSZ1; - gteSZ1 = gteSZ2; - gteSZ2 = limC(gteMAC3); - - psxRegs.CP2D.r[12]= psxRegs.CP2D.r[13]; - psxRegs.CP2D.r[13]= psxRegs.CP2D.r[14]; - - DSZ = (double)gteH / gteSZ2; - if (DSZ > 2.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } -// if (DSZ > 2147483647.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } - - gteSX2 = limG1(gteOFX/65536.0 + (limA1S(gteMAC1) * DSZ)); - gteSY2 = limG2(gteOFY/65536.0 + (limA2S(gteMAC2) * DSZ)); - - MAC2IR(); - - gteMAC0 = (gteDQB/16777216.0 + (gteDQA/256.0) * DSZ) * 16777216.0; - gteIR0 = limE((gteDQB/16777216.0 + (gteDQA/256.0) * DSZ) * 4096.0); - - SUM_FLAG; - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(8); - G_GD(9); - G_GD(10); - G_GD(11); - - //G_GD(12); - //G_GD(13); - G_GD(14); - - G_GD(16); - G_GD(17); - G_GD(18); - G_GD(19); - - G_GD(24); - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -void gteRTPT() { -// double SSX0,SSY0,SSZ0; -// double SZ; - double DSZ; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif - -#ifdef GTE_LOG - GTE_LOG("GTE_RTPT\n"); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("RTPT", 22); - G_SD(0); - G_SD(1); - G_SD(2); - G_SD(3); - G_SD(4); - G_SD(5); - - G_SD(16); // Store original fifo - G_SD(17); - G_SD(18); - G_SD(19); - - G_SC(0); - G_SC(1); - G_SC(2); - G_SC(3); - G_SC(4); - G_SC(5); - G_SC(6); - G_SC(7); - - G_SC(24); - G_SC(25); - G_SC(26); - G_SC(27); - G_SC(28); - } -#endif -/* gteFLAG = 0; - - gteSZ0 = gteSZx; - - SSX0 = NC_OVERFLOW1((double)gteTRX + ((double)(gteVX0 * gteR11) + (double)(gteVY0 * gteR12) + (double)(gteVZ0 * gteR13)) / 4096.0); - SSY0 = NC_OVERFLOW2((double)gteTRY + ((double)(gteVX0 * gteR21) + (double)(gteVY0 * gteR22) + (double)(gteVZ0 * gteR23)) / 4096.0); - SSZ0 = NC_OVERFLOW3((double)gteTRZ + ((double)(gteVX0 * gteR31) + (double)(gteVY0 * gteR32) + (double)(gteVZ0 * gteR33)) / 4096.0); - - SZ = LIMIT(SSZ0, (double)0, (double)65535, 18); - DSZ = ((double)gteH / SZ); - - if ((DSZ>(double)2147483647)) {DSZ=(double)2; gteFLAG|=1<<17;} - - gteSZ1 = (unsigned short)float2int(SZ); - gteSX0 = (signed short)float2int(LIMIT((double)(gteOFX)/65536.0f + (LimitAS(SSX0,24)*DSZ),(double)-1024,(double)1023,14)); - gteSY0 = (signed short)float2int(LIMIT((double)(gteOFY)/65536.0f + (LimitAS(SSY0,23)*DSZ),(double)-1024,(double)1023,13)); - - SSX0 = NC_OVERFLOW1((double)gteTRX + ((double)(gteVX1*gteR11) + (double)(gteVY1*gteR12) + (double)(gteVZ1*gteR13))/4096.0); - SSY0 = NC_OVERFLOW2((double)gteTRY + ((double)(gteVX1*gteR21) + (double)(gteVY1*gteR22) + (double)(gteVZ1*gteR23))/4096.0); - SSZ0 = NC_OVERFLOW3((double)gteTRZ + ((double)(gteVX1*gteR31) + (double)(gteVY1*gteR32) + (double)(gteVZ1*gteR33))/4096.0); - - SZ = LIMIT(SSZ0,(double)0,(double)65535,18); - DSZ = ((double)gteH/SZ); - - if ((DSZ>(double)2147483647)) {DSZ=(double)2; gteFLAG|=1<<17;} - - gteSZ2 = (unsigned short)float2int(SZ); - gteSX1 = (signed short)float2int(LIMIT((double)(gteOFX)/65536.0f + (LimitAS(SSX0,24)*DSZ),(double)-1024,(double)1023,14)); - gteSY1 = (signed short)float2int(LIMIT((double)(gteOFY)/65536.0f + (LimitAS(SSY0,23)*DSZ),(double)-1024,(double)1023,13)); - - SSX0 = NC_OVERFLOW1((double)gteTRX + ((double)(gteVX2*gteR11) + (double)(gteVY2*gteR12) + (double)(gteVZ2*gteR13))/4096.0); - SSY0 = NC_OVERFLOW2((double)gteTRY + ((double)(gteVX2*gteR21) + (double)(gteVY2*gteR22) + (double)(gteVZ2*gteR23))/4096.0); - SSZ0 = NC_OVERFLOW3((double)gteTRZ + ((double)(gteVX2*gteR31) + (double)(gteVY2*gteR32) + (double)(gteVZ2*gteR33))/4096.0); - - SZ = LIMIT(SSZ0,(double)0,(double)65535,18); - DSZ = ((double)gteH/SZ); - - if ((DSZ>(double)2147483647)) {DSZ=(double)2; gteFLAG|=1<<17;} - - gteSZx = (unsigned short)float2int(SZ); - gteSX2 = (signed short)float2int(LIMIT((double)(gteOFX)/65536.0f + (LimitAS(SSX0,24)*DSZ),(double)-1024,(double)1023,14)); - gteSY2 = (signed short)float2int(LIMIT((double)(gteOFY)/65536.0f + (LimitAS(SSY0,23)*DSZ),(double)-1024,(double)1023,13)); - - gteMAC1 = (signed long)float2int(SSX0); - gteMAC2 = (signed long)float2int(SSY0); - gteMAC3 = (signed long)float2int(SSZ0); - - MAC2IR(); - - gteMAC0 = (signed long)float2int(OLIMIT((((double)gteDQB/(double)16777216) + (((double)gteDQA/(double)256)*DSZ))*16777216)); - gteIR0 = (signed long)float2int(LIMIT(((((double)gteDQB/(double)16777216) + (((double)gteDQA/(double)256)*DSZ))*4096),(double)0,(double)4095,12)); - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - - /* NC: old - gteFLAG = 0; - - gteSZ0 = gteSZx; - - gteMAC1 = NC_OVERFLOW1(((signed long)(gteR11*gteVX0 + gteR12*gteVY0 + gteR13*gteVZ0)>>12) + gteTRX); - gteMAC2 = NC_OVERFLOW2(((signed long)(gteR21*gteVX0 + gteR22*gteVY0 + gteR23*gteVZ0)>>12) + gteTRY); - gteMAC3 = NC_OVERFLOW3(((signed long)(gteR31*gteVX0 + gteR32*gteVY0 + gteR33*gteVZ0)>>12) + gteTRZ); - - DSZ = gteH / limC(gteMAC3); - if (DSZ > 2147483647.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } - - gteSZ1 = limC(gteMAC3); - - gteSX0 = limG1(gteOFX/65536.0 + (limA1S(gteMAC1) * DSZ)); - gteSY0 = limG2(gteOFY/65536.0 + (limA2S(gteMAC2) * DSZ)); - - gteMAC1 = NC_OVERFLOW1(((signed long)(gteR11*gteVX1 + gteR12*gteVY1 + gteR13*gteVZ1)>>12) + gteTRX); - gteMAC2 = NC_OVERFLOW2(((signed long)(gteR21*gteVX1 + gteR22*gteVY1 + gteR23*gteVZ1)>>12) + gteTRY); - gteMAC3 = NC_OVERFLOW3(((signed long)(gteR31*gteVX1 + gteR32*gteVY1 + gteR33*gteVZ1)>>12) + gteTRZ); - - DSZ = gteH / limC(gteMAC3); - if (DSZ > 2147483647.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } - - gteSZ2 = limC(gteMAC3); - - gteSX1 = limG1(gteOFX/65536.0 + (limA1S(gteMAC1) * DSZ )); - gteSY1 = limG2(gteOFY/65536.0 + (limA2S(gteMAC2) * DSZ )); - - gteMAC1 = NC_OVERFLOW1(((signed long)(gteR11*gteVX2 + gteR12*gteVY2 + gteR13*gteVZ2)>>12) + gteTRX); - gteMAC2 = NC_OVERFLOW2(((signed long)(gteR21*gteVX2 + gteR22*gteVY2 + gteR23*gteVZ2)>>12) + gteTRY); - gteMAC3 = NC_OVERFLOW3(((signed long)(gteR31*gteVX2 + gteR32*gteVY2 + gteR33*gteVZ2)>>12) + gteTRZ); - - DSZ = gteH / limC(gteMAC3); if (DSZ > 2147483647.0f) { DSZ = 2.0f; gteFLAG |= 1<<17; } - - gteSZx = gteSZ2; - - gteSX2 = limG1(gteOFX/65536.0 + (limA1S(gteMAC1) * DSZ )); - gteSY2 = limG2(gteOFY/65536.0 + (limA2S(gteMAC2) * DSZ )); - - MAC2IR(); - - gteMAC0 = (gteDQB/16777216.0 + (gteDQA/256.0) * DSZ ) * 16777216.0; - gteIR0 = limE((gteDQB/16777216.0 + (gteDQA/256.0) * DSZ ) * 4096.0f); - */ - - gteFLAG = 0; - - gteSZx = gteSZ2; - - gteMAC1 = NC_OVERFLOW1(((signed long)(gteR11*gteVX0 + gteR12*gteVY0 + gteR13*gteVZ0)>>12) + gteTRX); - gteMAC2 = NC_OVERFLOW2(((signed long)(gteR21*gteVX0 + gteR22*gteVY0 + gteR23*gteVZ0)>>12) + gteTRY); - gteMAC3 = NC_OVERFLOW3(((signed long)(gteR31*gteVX0 + gteR32*gteVY0 + gteR33*gteVZ0)>>12) + gteTRZ); - - DSZ = gteH / limC(gteMAC3); - if (DSZ > 2.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } -// if (DSZ > 2147483647.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } - - gteSZ0 = limC(gteMAC3); - - gteSX0 = limG1(gteOFX/65536.0 + (limA1S(gteMAC1) * DSZ)); - gteSY0 = limG2(gteOFY/65536.0 + (limA2S(gteMAC2) * DSZ)); - - gteMAC1 = NC_OVERFLOW1(((signed long)(gteR11*gteVX1 + gteR12*gteVY1 + gteR13*gteVZ1)>>12) + gteTRX); - gteMAC2 = NC_OVERFLOW2(((signed long)(gteR21*gteVX1 + gteR22*gteVY1 + gteR23*gteVZ1)>>12) + gteTRY); - gteMAC3 = NC_OVERFLOW3(((signed long)(gteR31*gteVX1 + gteR32*gteVY1 + gteR33*gteVZ1)>>12) + gteTRZ); - - DSZ = gteH / limC(gteMAC3); - if (DSZ > 2.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } -// if (DSZ > 2147483647.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } - - gteSZ1 = limC(gteMAC3); - - gteSX1 = limG1(gteOFX/65536.0 + (limA1S(gteMAC1) * DSZ )); - gteSY1 = limG2(gteOFY/65536.0 + (limA2S(gteMAC2) * DSZ )); - - gteMAC1 = NC_OVERFLOW1(((signed long)(gteR11*gteVX2 + gteR12*gteVY2 + gteR13*gteVZ2)>>12) + gteTRX); - gteMAC2 = NC_OVERFLOW2(((signed long)(gteR21*gteVX2 + gteR22*gteVY2 + gteR23*gteVZ2)>>12) + gteTRY); - gteMAC3 = NC_OVERFLOW3(((signed long)(gteR31*gteVX2 + gteR32*gteVY2 + gteR33*gteVZ2)>>12) + gteTRZ); - - DSZ = gteH / limC(gteMAC3); - if (DSZ > 2.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } -// if (DSZ > 2147483647.0f) { DSZ = 2.0f; gteFLAG |= 1<<17; } - - gteSZ2 = limC(gteMAC3); - - gteSX2 = limG1(gteOFX/65536.0 + (limA1S(gteMAC1) * DSZ )); - gteSY2 = limG2(gteOFY/65536.0 + (limA2S(gteMAC2) * DSZ )); - - MAC2IR(); - - gteMAC0 = (gteDQB/16777216.0 + (gteDQA/256.0) * DSZ ) * 16777216.0; - gteIR0 = limE((gteDQB/16777216.0 + (gteDQA/256.0) * DSZ ) * 4096.0f); - - SUM_FLAG; - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(8); - G_GD(9); - G_GD(10); - G_GD(11); - - G_GD(12); - G_GD(13); - G_GD(14); - - G_GD(16); - G_GD(17); - G_GD(18); - G_GD(19); - - G_GD(24); - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -#define gte_C11 gteLR1 -#define gte_C12 gteLR2 -#define gte_C13 gteLR3 -#define gte_C21 gteLG1 -#define gte_C22 gteLG2 -#define gte_C23 gteLG3 -#define gte_C31 gteLB1 -#define gte_C32 gteLB2 -#define gte_C33 gteLB3 - -#define _MVMVA_FUNC(_v0, _v1, _v2, mx) { \ - SSX = (_v0) * mx##11 + (_v1) * mx##12 + (_v2) * mx##13; \ - SSY = (_v0) * mx##21 + (_v1) * mx##22 + (_v2) * mx##23; \ - SSZ = (_v0) * mx##31 + (_v1) * mx##32 + (_v2) * mx##33; \ -} - -void gteMVMVA() { - double SSX, SSY, SSZ; - -#ifdef GTE_LOG - GTE_LOG("GTE_MVMVA %lx\n", psxRegs.code & 0x1ffffff); -#endif - - switch (psxRegs.code & 0x78000) { - case 0x00000: // V0 * R - _MVMVA_FUNC(gteVX0, gteVY0, gteVZ0, gteR); break; - case 0x08000: // V1 * R - _MVMVA_FUNC(gteVX1, gteVY1, gteVZ1, gteR); break; - case 0x10000: // V2 * R - _MVMVA_FUNC(gteVX2, gteVY2, gteVZ2, gteR); break; - case 0x18000: // IR * R - _MVMVA_FUNC((short)gteIR1, (short)gteIR2, (short)gteIR3, gteR); - break; - case 0x20000: // V0 * L - _MVMVA_FUNC(gteVX0, gteVY0, gteVZ0, gteL); break; - case 0x28000: // V1 * L - _MVMVA_FUNC(gteVX1, gteVY1, gteVZ1, gteL); break; - case 0x30000: // V2 * L - _MVMVA_FUNC(gteVX2, gteVY2, gteVZ2, gteL); break; - case 0x38000: // IR * L - _MVMVA_FUNC((short)gteIR1, (short)gteIR2, (short)gteIR3, gteL); break; - case 0x40000: // V0 * C - _MVMVA_FUNC(gteVX0, gteVY0, gteVZ0, gte_C); break; - case 0x48000: // V1 * C - _MVMVA_FUNC(gteVX1, gteVY1, gteVZ1, gte_C); break; - case 0x50000: // V2 * C - _MVMVA_FUNC(gteVX2, gteVY2, gteVZ2, gte_C); break; - case 0x58000: // IR * C - _MVMVA_FUNC((short)gteIR1, (short)gteIR2, (short)gteIR3, gte_C); break; - default: - SSX = SSY = SSZ = 0; - } - - if (psxRegs.code & 0x80000) { - SSX /= 4096.0; SSY /= 4096.0; SSZ /= 4096.0; - } - - switch (psxRegs.code & 0x6000) { - case 0x0000: // Add TR - SSX+= gteTRX; - SSY+= gteTRY; - SSZ+= gteTRZ; - break; - case 0x2000: // Add BK - SSX+= gteRBK; - SSY+= gteGBK; - SSZ+= gteBBK; - break; - case 0x4000: // Add FC - SSX+= gteRFC; - SSY+= gteGFC; - SSZ+= gteBFC; - break; - } - - gteFLAG = 0; - //gteMAC1 = (long)SSX; - //gteMAC2 = (long)SSY; - //gteMAC3 = (long)SSZ;//okay the follow lines are correct?? - gteMAC1=NC_OVERFLOW1(SSX); - gteMAC2=NC_OVERFLOW2(SSY); - gteMAC3=NC_OVERFLOW3(SSZ); - if (psxRegs.code & 0x400) - MAC2IR1() - else MAC2IR() - - SUM_FLAG; -} - -void gteNCLIP() { -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif - -#ifdef GTE_LOG - GTE_LOG("GTE_NCLIP\n"); -#endif - - //gteLog - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("NCLIP", 8); - G_SD(12); - G_SD(13); - G_SD(14); - } -#endif - -/* gteFLAG = 0; - - gteMAC0 = (signed long)float2int(EDETEC4( - ((double)gteSX0*((double)gteSY1-(double)gteSY2))+ - ((double)gteSX1*((double)gteSY2-(double)gteSY0))+ - ((double)gteSX2*((double)gteSY0-(double)gteSY1)))); - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - gteFLAG = 0; - - - gteMAC0 = gteSX0 * (gteSY1 - gteSY2) + - gteSX1 * (gteSY2 - gteSY0) + - gteSX2 * (gteSY0 - gteSY1); - - //gteMAC0 = (gteSX0 - gteSX1) * (gteSY0 - gteSY2) - (gteSX0 - gteSX2) * (gteSY0 - gteSY1); - - SUM_FLAG; - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(24); - G_GC(31); - } -#endif -} - -void gteAVSZ3() { -// unsigned long SS; -// double SZ1,SZ2,SZ3; -// double ZSF3; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif - -#ifdef GTE_LOG - GTE_LOG("GTE_AVSZ3\n"); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("AVSZ3", 5); - G_SD(16); - G_SD(17); - G_SD(18); - G_SD(19); - G_SC(29); - G_SC(30); - } -#endif - -/* gteFLAG = 0; - - SS = psxRegs.CP2D.r[17] & 0xffff; SZ1 = (double)SS; - SS = psxRegs.CP2D.r[18] & 0xffff; SZ2 = (double)SS; - SS = psxRegs.CP2D.r[19] & 0xffff; SZ3 = (double)SS; - SS = psxRegs.CP2C.r[29] & 0xffff; ZSF3 = (double)SS/(double)4096; - - psxRegs.CP2D.r[24] = (signed long)float2int(EDETEC4(((SZ1+SZ2+SZ3)*ZSF3))); - psxRegs.CP2D.r[7] = (unsigned short)float2int(LimitC(((SZ1+SZ2+SZ3)*ZSF3),18)); - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - - - gteFLAG = 0; - - /* NC: OLD - gteMAC0 = ((gteSZ1 + gteSZ2 + gteSZx) * (gteZSF3/4096.0f)); - - gteOTZ = limC((double)gteMAC0); - */ -/* gteMAC0 = ((gteSZ1 + gteSZ2 + gteSZx) * (gteZSF3)); - - gteOTZ = limC((double)(gteMAC0 >> 12));*/ - gteMAC0 = ((gteSZ0 + gteSZ1 + gteSZ2) * (gteZSF3)) >> 12; - - gteOTZ = limC((double)gteMAC0); - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(7); - G_GD(24); - G_GC(31); - } -#endif -} - -void gteAVSZ4() { -// unsigned long SS; -// double SZ0,SZ1,SZ2,SZ3; -// double ZSF4; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif - -#ifdef GTE_LOG - GTE_LOG("GTE_AVSZ4\n"); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("AVSZ4", 6); - G_SD(16); - G_SD(17); - G_SD(18); - G_SD(19); - G_SC(29); - G_SC(30); - } -#endif - -/* gteFLAG = 0; - - SS = psxRegs.CP2D.r[16] & 0xffff; SZ0 = (double)SS; - SS = psxRegs.CP2D.r[17] & 0xffff; SZ1 = (double)SS; - SS = psxRegs.CP2D.r[18] & 0xffff; SZ2 = (double)SS; - SS = psxRegs.CP2D.r[19] & 0xffff; SZ3 = (double)SS; - SS = psxRegs.CP2C.r[30] & 0xffff; ZSF4 = (double)SS/(double)4096; - - psxRegs.CP2D.r[24] = (signed long)float2int(EDETEC4(((SZ0+SZ1+SZ2+SZ3)*ZSF4))); - psxRegs.CP2D.r[7] = (unsigned short)float2int(LimitC(((SZ0+SZ1+SZ2+SZ3)*ZSF4),18)); - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - gteFLAG = 0; - - /* NC: OLD - gteMAC0 = ((gteSZ0 + gteSZ1 + gteSZ2 + gteSZx) * (gteZSF4/4096.0f)); - - gteOTZ = limC((double)gteMAC0); - */ -/* gteMAC0 = ((gteSZ0 + gteSZ1 + gteSZ2 + gteSZx) * (gteZSF4)); - - gteOTZ = limC((double)(gteMAC0 >> 12)); -*/ - gteMAC0 = ((gteSZx + gteSZ0 + gteSZ1 + gteSZ2) * (gteZSF4))>> 12; - - gteOTZ = limC((double)gteMAC0); - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(7); - G_GD(24); - G_GC(31); - } -#endif -} - -void gteSQR() { - //double SSX0,SSY0,SSZ0; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif - -#ifdef GTE_LOG - GTE_LOG("GTE_SQR %lx\n", psxRegs.code & 0x1ffffff); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("SQR", 5); - G_SD(9); - G_SD(10); - G_SD(11); - } -#endif - -/* gteFLAG = 0; - - SSX0 = (double)gteIR1 * gteIR1; - SSY0 = (double)gteIR2 * gteIR2; - SSZ0 = (double)gteIR3 * gteIR3; - - if (psxRegs.code & 0x80000) { - SSX0 /= 4096.0; SSY0 /= 4096.0; SSZ0 /= 4096.0; - } - - gteMAC1 = (long)SSX0; - gteMAC2 = (long)SSY0; - gteMAC3 = (long)SSZ0; - - MAC2IR1(); - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - gteFLAG = 0; - - if (psxRegs.code & 0x80000) { - - gteMAC1 = NC_OVERFLOW1((gteIR1 * gteIR1) / 4096.0f); - gteMAC2 = NC_OVERFLOW2((gteIR2 * gteIR2) / 4096.0f); - gteMAC3 = NC_OVERFLOW3((gteIR3 * gteIR3) / 4096.0f); - } else { - - gteMAC1 = NC_OVERFLOW1(gteIR1 * gteIR1); - gteMAC2 = NC_OVERFLOW2(gteIR2 * gteIR2); - gteMAC3 = NC_OVERFLOW3(gteIR3 * gteIR3); - } - MAC2IR1(); - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - G_GD(25); - G_GD(26); - G_GD(27); - G_GC(31); - } -#endif -} -/* -#define GTE_NCCS(vn) { \ - RR0 = ((double)gteL11 * gteVX##vn + (double)gteL12 * gteVY##vn + (double)gteL13 * gteVZ##vn)/4096.0; \ - GG0 = ((double)gteL21 * gteVX##vn + (double)gteL22 * gteVY##vn + (double)gteL23 * gteVZ##vn)/4096.0; \ - BB0 = ((double)gteL31 * gteVX##vn + (double)gteL32 * gteVY##vn + (double)gteL33 * gteVZ##vn)/4096.0; \ - t1 = LimitAU(RR0,24); \ - t2 = LimitAU(GG0,23); \ - t3 = LimitAU(BB0,22); \ - \ - RR0 = (double)gteRBK + ((double)gteLR1 * t1 + (double)gteLR2 * t2 + (double)gteLR3 * t3)/4096.0; \ - GG0 = (double)gteGBK + ((double)gteLG1 * t1 + (double)gteLG2 * t2 + (double)gteLG3 * t3)/4096.0; \ - BB0 = (double)gteBBK + ((double)gteLB1 * t1 + (double)gteLB2 * t2 + (double)gteLB3 * t3)/4096.0; \ - t1 = LimitAU(RR0,24); \ - t2 = LimitAU(GG0,23); \ - t3 = LimitAU(BB0,22); \ - \ - RR0 = ((double)gteR * t1)/256.0; \ - GG0 = ((double)gteG * t2)/256.0; \ - BB0 = ((double)gteB * t3)/256.0; \ - \ - gteIR1 = (long)LimitAU(RR0,24); \ - gteIR2 = (long)LimitAU(GG0,23); \ - gteIR3 = (long)LimitAU(BB0,22); \ - \ - gteCODE0 = gteCODE1; gteCODE1 = gteCODE2; gteCODE2 = gteCODE; \ - gteR0 = gteR1; gteR1 = gteR2; gteR2 = (unsigned char)LimitB(RR0/16.0,21); \ - gteG0 = gteG1; gteG1 = gteG2; gteG2 = (unsigned char)LimitB(GG0/16.0,20); \ - gteB0 = gteB1; gteB1 = gteB2; gteB2 = (unsigned char)LimitB(BB0/16.0,19); \ - \ - gteMAC1 = (long)RR0; \ - gteMAC2 = (long)GG0; \ - gteMAC3 = (long)BB0; \ -} -*/ -/* -__forceinline double ncLIM1(double x) -{ - if(x > 8796093022207.0) - { - return 8796093022207.0; - } -} -*/ - - - -/* NC: OLD -#define GTE_NCCS(vn)\ -gte_LL1 = limA1U((gteL11*gteVX##vn + gteL12*gteVY##vn + gteL13*gteVZ##vn)/16777216.0f);\ -gte_LL2 = limA2U((gteL21*gteVX##vn + gteL22*gteVY##vn + gteL23*gteVZ##vn)/16777216.0f);\ -gte_LL3 = limA3U((gteL31*gteVX##vn + gteL32*gteVY##vn + gteL33*gteVZ##vn)/16777216.0f);\ -gte_RRLT= limA1U(gteRBK/4096.0f + (gteLR1/4096.0f*gte_LL1 + gteLR2/4096.0f*gte_LL2 + gteLR3/4096.0f*gte_LL3));\ -gte_GGLT= limA2U(gteGBK/4096.0f + (gteLG1/4096.0f*gte_LL1 + gteLG2/4096.0f*gte_LL2 + gteLG3/4096.0f*gte_LL3));\ -gte_BBLT= limA3U(gteBBK/4096.0f + (gteLB1/4096.0f*gte_LL1 + gteLB2/4096.0f*gte_LL2 + gteLB3/4096.0f*gte_LL3));\ -gte_RR0 = gteR*gte_RRLT;\ -gte_GG0 = gteG*gte_GGLT;\ -gte_BB0 = gteB*gte_BBLT;\ -gteIR1 = (long)limA1U(gte_RR0);\ -gteIR2 = (long)limA2U(gte_GG0);\ -gteIR3 = (long)limA3U(gte_BB0);\ -gteCODE0 = gteCODE1; gteCODE1 = gteCODE2; gteCODE2 = gteCODE;\ -gteR0 = gteR1; gteR1 = gteR2; gteR2 = (unsigned char)limB1(gte_RR0);\ -gteG0 = gteG1; gteG1 = gteG2; gteG2 = (unsigned char)limB2(gte_GG0);\ -gteB0 = gteB1; gteB1 = gteB2; gteB2 = (unsigned char)limB3(gte_BB0);\ -gteMAC1 = (long)gte_RR0;\ -gteMAC2 = (long)gte_GG0;\ -gteMAC3 = (long)gte_BB0;\ -*/ - -#define GTE_NCCS(vn)\ -gte_LL1 = limA1U((gteL11*gteVX##vn + gteL12*gteVY##vn + gteL13*gteVZ##vn)/16777216.0f);\ -gte_LL2 = limA2U((gteL21*gteVX##vn + gteL22*gteVY##vn + gteL23*gteVZ##vn)/16777216.0f);\ -gte_LL3 = limA3U((gteL31*gteVX##vn + gteL32*gteVY##vn + gteL33*gteVZ##vn)/16777216.0f);\ -gte_RRLT= limA1U(gteRBK/4096.0f + (gteLR1/4096.0f*gte_LL1 + gteLR2/4096.0f*gte_LL2 + gteLR3/4096.0f*gte_LL3));\ -gte_GGLT= limA2U(gteGBK/4096.0f + (gteLG1/4096.0f*gte_LL1 + gteLG2/4096.0f*gte_LL2 + gteLG3/4096.0f*gte_LL3));\ -gte_BBLT= limA3U(gteBBK/4096.0f + (gteLB1/4096.0f*gte_LL1 + gteLB2/4096.0f*gte_LL2 + gteLB3/4096.0f*gte_LL3));\ -gteMAC1 = (long)(gteR*gte_RRLT*16);\ -gteMAC2 = (long)(gteG*gte_GGLT*16);\ -gteMAC3 = (long)(gteB*gte_BBLT*16);\ -gteIR1 = (long)limA1U(gteMAC1);\ -gteIR2 = (long)limA2U(gteMAC2);\ -gteIR3 = (long)limA3U(gteMAC3);\ -gte_RR0 = gteMAC1>>4;\ -gte_GG0 = gteMAC2>>4;\ -gte_BB0 = gteMAC3>>4;\ -gteCODE0 = gteCODE1; gteCODE1 = gteCODE2; gteCODE2 = gteCODE;\ -gteR0 = gteR1; gteR1 = gteR2; gteR2 = (unsigned char)limB1(gte_RR0);\ -gteG0 = gteG1; gteG1 = gteG2; gteG2 = (unsigned char)limB2(gte_GG0);\ -gteB0 = gteB1; gteB1 = gteB2; gteB2 = (unsigned char)limB3(gte_BB0);\ - -void gteNCCS() { -// double RR0,GG0,BB0; -// double t1, t2, t3; - - double gte_LL1, gte_RR0, gte_RRLT; - double gte_LL2, gte_GG0, gte_GGLT; - double gte_LL3, gte_BB0, gte_BBLT; - -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif - -#ifdef GTE_LOG - GTE_LOG("GTE_NCCS\n"); -#endif - -/* - gteFLAG = 0; - - GTE_NCCS(0); - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("NCCS", 17); - G_SD(0); - G_SD(1); - G_SD(6); - G_SC(8); - G_SC(9); - G_SC(10); - G_SC(11); - G_SC(12); - G_SC(13); - G_SC(14); - G_SC(15); - G_SC(16); - G_SC(17); - G_SC(18); - G_SC(19); - G_SC(20); - } -#endif - - gteFLAG = 0; - - GTE_NCCS(0); - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - //G_GD(20); - //G_GD(21); - G_GD(22); - - //G_GD(24); Doc must be wrong. PSX does not touch it. - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -void gteNCCT() { -// double RR0,GG0,BB0; -// double t1, t2, t3; - double gte_LL1, gte_RR0, gte_RRLT; - double gte_LL2, gte_GG0, gte_GGLT; - double gte_LL3, gte_BB0, gte_BBLT; - -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif - -#ifdef GTE_LOG - GTE_LOG("GTE_NCCT\n"); -#endif - - - /*gteFLAG = 0; - - GTE_NCCS(0); - GTE_NCCS(1); - GTE_NCCS(2); - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("NCCT", 39); - G_SD(0); - G_SD(1); - G_SD(2); - G_SD(3); - G_SD(4); - G_SD(5); - G_SD(6); - - G_SC(8); - G_SC(9); - G_SC(10); - G_SC(11); - G_SC(12); - G_SC(13); - G_SC(14); - G_SC(15); - G_SC(16); - G_SC(17); - G_SC(18); - G_SC(19); - G_SC(20); - } -#endif - - gteFLAG = 0; - - GTE_NCCS(0); - GTE_NCCS(1); - GTE_NCCS(2); - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - G_GD(20); - G_GD(21); - G_GD(22); - - //G_GD(24); Doc must be wrong. PSX does not touch it. - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -#define GTE_NCDS(vn) \ -gte_LL1 = limA1U((gteL11*gteVX##vn + gteL12*gteVY##vn + gteL13*gteVZ##vn)/16777216.0f);\ -gte_LL2 = limA2U((gteL21*gteVX##vn + gteL22*gteVY##vn + gteL23*gteVZ##vn)/16777216.0f);\ -gte_LL3 = limA3U((gteL31*gteVX##vn + gteL32*gteVY##vn + gteL33*gteVZ##vn)/16777216.0f);\ -gte_RRLT= limA1U(gteRBK/4096.0f + (gteLR1/4096.0f*gte_LL1 + gteLR2/4096.0f*gte_LL2 + gteLR3/4096.0f*gte_LL3));\ -gte_GGLT= limA2U(gteGBK/4096.0f + (gteLG1/4096.0f*gte_LL1 + gteLG2/4096.0f*gte_LL2 + gteLG3/4096.0f*gte_LL3));\ -gte_BBLT= limA3U(gteBBK/4096.0f + (gteLB1/4096.0f*gte_LL1 + gteLB2/4096.0f*gte_LL2 + gteLB3/4096.0f*gte_LL3));\ -gte_RR0 = (gteR*gte_RRLT) + (gteIR0/4096.0f * limA1S(gteRFC/16.0f - (gteR*gte_RRLT)));\ -gte_GG0 = (gteG*gte_GGLT) + (gteIR0/4096.0f * limA2S(gteGFC/16.0f - (gteG*gte_GGLT)));\ -gte_BB0 = (gteB*gte_BBLT) + (gteIR0/4096.0f * limA3S(gteBFC/16.0f - (gteB*gte_BBLT)));\ -gteMAC1= (long)(gte_RR0 * 16.0f); gteIR1 = (long)limA1U(gte_RR0*16.0f);\ -gteMAC2= (long)(gte_GG0 * 16.0f); gteIR2 = (long)limA2U(gte_GG0*16.0f);\ -gteMAC3= (long)(gte_BB0 * 16.0f); gteIR3 = (long)limA3U(gte_BB0*16.0f);\ -gteRGB0 = gteRGB1; \ -gteRGB1 = gteRGB2; \ -gteR2 = limB1(gte_RR0); \ -gteG2 = limB2(gte_GG0); \ -gteB2 = limB3(gte_BB0); gteCODE2 = gteCODE; - -void gteNCDS() { -/* double tRLT,tRRLT; - double tGLT,tGGLT; - double tBLT,tBBLT; - double tRR0,tL1,tLL1; - double tGG0,tL2,tLL2; - double tBB0,tL3,tLL3; - unsigned long C,R,G,B; */ - double gte_LL1, gte_RR0, gte_RRLT; - double gte_LL2, gte_GG0, gte_GGLT; - double gte_LL3, gte_BB0, gte_BBLT; - -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif - -#ifdef GTE_LOG - GTE_LOG("GTE_NCDS\n"); -#endif - -/* gteFLAG = 0; - - R = ((gteRGB)&0xff); - G = ((gteRGB>> 8)&0xff); - B = ((gteRGB>>16)&0xff); - C = ((gteRGB>>24)&0xff); - - tLL1 = (gteL11/4096.0 * gteVX0/4096.0) + (gteL12/4096.0 * gteVY0/4096.0) + (gteL13/4096.0 * gteVZ0/4096.0); - tLL2 = (gteL21/4096.0 * gteVX0/4096.0) + (gteL22/4096.0 * gteVY0/4096.0) + (gteL23/4096.0 * gteVZ0/4096.0); - tLL3 = (gteL31/4096.0 * gteVX0/4096.0) + (gteL32/4096.0 * gteVY0/4096.0) + (gteL33/4096.0 * gteVZ0/4096.0); - - tL1 = LimitAU(tLL1,24); - tL2 = LimitAU(tLL2,23); - tL3 = LimitAU(tLL3,22); - - tRRLT = gteRBK/4096.0 + (gteLR1/4096.0 * tL1) + (gteLR2/4096.0 * tL2) + (gteLR3/4096.0 * tL3); - tGGLT = gteGBK/4096.0 + (gteLG1/4096.0 * tL1) + (gteLG2/4096.0 * tL2) + (gteLG3/4096.0 * tL3); - tBBLT = gteBBK/4096.0 + (gteLB1/4096.0 * tL1) + (gteLB2/4096.0 * tL2) + (gteLB3/4096.0 * tL3); - - tRLT = LimitAU(tRRLT,24); - tGLT = LimitAU(tGGLT,23); - tBLT = LimitAU(tBBLT,22); - - tRR0 = (R * tRLT) + (gteIR0/4096.0 * LimitAS(gteRFC/16.0 - (R * tRLT),24)); - tGG0 = (G * tGLT) + (gteIR0/4096.0 * LimitAS(gteGFC/16.0 - (G * tGLT),23)); - tBB0 = (B * tBLT) + (gteIR0/4096.0 * LimitAS(gteBFC/16.0 - (B * tBLT),22)); - - gteMAC1 = (long)(tRR0 * 16.0); gteIR1 = (long)LimitAU((tRR0*16.0),24); - gteMAC2 = (long)(tGG0 * 16.0); gteIR2 = (long)LimitAU((tGG0*16.0),23); - gteMAC3 = (long)(tBB0 * 16.0); gteIR3 = (long)LimitAU((tBB0*16.0),22); - - R = (unsigned long)LimitB(tRR0,21); if (R>255) R=255; else if (R<0) R=0; - G = (unsigned long)LimitB(tGG0,20); if (G>255) G=255; else if (G<0) G=0; - B = (unsigned long)LimitB(tBB0,19); if (B>255) B=255; else if (B<0) B=0; - - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - gteRGB2 = R|(G<<8)|(B<<16)|(C<<24); - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("NCDS", 19); - G_SD(0); - G_SD(1); - G_SD(6); - G_SD(8); - - G_SC(8); - G_SC(9); - G_SC(10); - G_SC(11); - G_SC(12); - G_SC(13); - G_SC(14); - G_SC(15); - G_SC(16); - G_SC(17); - G_SC(18); - G_SC(19); - G_SC(20); - G_SC(21); - G_SC(22); - G_SC(23); - } -#endif - - gteFLAG = 0; - GTE_NCDS(0); - - SUM_FLAG; - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - //G_GD(20); - //G_GD(21); - G_GD(22); - - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -void gteNCDT() { - /*double tRLT,tRRLT; - double tGLT,tGGLT; - double tBLT,tBBLT; - double tRR0,tL1,tLL1; - double tGG0,tL2,tLL2; - double tBB0,tL3,tLL3; - unsigned long C,R,G,B;*/ - double gte_LL1, gte_RR0, gte_RRLT; - double gte_LL2, gte_GG0, gte_GGLT; - double gte_LL3, gte_BB0, gte_BBLT; - -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif - -#ifdef GTE_LOG - GTE_LOG("GTE_NCDT\n"); -#endif - -/* gteFLAG = 0; - - R = ((gteRGB)&0xff); - G = ((gteRGB>> 8)&0xff); - B = ((gteRGB>>16)&0xff); - C = ((gteRGB>>24)&0xff); - - tLL1 = (gteL11/4096.0 * gteVX0/4096.0) + (gteL12/4096.0 * gteVY0/4096.0) + (gteL13/4096.0 * gteVZ0/4096.0); - tLL2 = (gteL21/4096.0 * gteVX0/4096.0) + (gteL22/4096.0 * gteVY0/4096.0) + (gteL23/4096.0 * gteVZ0/4096.0); - tLL3 = (gteL31/4096.0 * gteVX0/4096.0) + (gteL32/4096.0 * gteVY0/4096.0) + (gteL33/4096.0 * gteVZ0/4096.0); - - tL1 = LimitAU(tLL1,24); - tL2 = LimitAU(tLL2,23); - tL3 = LimitAU(tLL3,22); - - tRRLT = gteRBK/4096.0 + (gteLR1/4096.0 * tL1) + (gteLR2/4096.0 * tL2) + (gteLR3/4096.0 * tL3); - tGGLT = gteGBK/4096.0 + (gteLG1/4096.0 * tL1) + (gteLG2/4096.0 * tL2) + (gteLG3/4096.0 * tL3); - tBBLT = gteBBK/4096.0 + (gteLB1/4096.0 * tL1) + (gteLB2/4096.0 * tL2) + (gteLB3/4096.0 * tL3); - - tRLT = LimitAU(tRRLT,24); - tGLT = LimitAU(tGGLT,23); - tBLT = LimitAU(tBBLT,22); - - tRR0 = (R * tRLT) + (gteIR0/4096.0 * LimitAS(gteRFC/16.0 - (R * tRLT),24)); - tGG0 = (G * tGLT) + (gteIR0/4096.0 * LimitAS(gteGFC/16.0 - (G * tGLT),23)); - tBB0 = (B * tBLT) + (gteIR0/4096.0 * LimitAS(gteBFC/16.0 - (B * tBLT),22)); - - gteMAC1 = (long)(tRR0 * 16.0); gteIR1 = (long)LimitAU((tRR0*16.0),24); - gteMAC2 = (long)(tGG0 * 16.0); gteIR2 = (long)LimitAU((tGG0*16.0),23); - gteMAC3 = (long)(tBB0 * 16.0); gteIR3 = (long)LimitAU((tBB0*16.0),22); - - R = (unsigned long)LimitB(tRR0,21); if (R>255) R=255; else if (R<0) R=0; - G = (unsigned long)LimitB(tGG0,20); if (G>255) G=255; else if (G<0) G=0; - B = (unsigned long)LimitB(tBB0,19); if (B>255) B=255; else if (B<0) B=0; - - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - gteRGB2 = R|(G<<8)|(B<<16)|(C<<24); - - R = ((gteRGB)&0xff); - G = ((gteRGB>> 8)&0xff); - B = ((gteRGB>>16)&0xff); - C = ((gteRGB>>24)&0xff); - - tLL1 = (gteL11/4096.0 * gteVX1/4096.0) + (gteL12/4096.0 * gteVY1/4096.0) + (gteL13/4096.0 * gteVZ1/4096.0); - tLL2 = (gteL21/4096.0 * gteVX1/4096.0) + (gteL22/4096.0 * gteVY1/4096.0) + (gteL23/4096.0 * gteVZ1/4096.0); - tLL3 = (gteL31/4096.0 * gteVX1/4096.0) + (gteL32/4096.0 * gteVY1/4096.0) + (gteL33/4096.0 * gteVZ1/4096.0); - - tL1 = LimitAU(tLL1,24); - tL2 = LimitAU(tLL2,23); - tL3 = LimitAU(tLL3,22); - - tRRLT = gteRBK/4096.0 + (gteLR1/4096.0 * tL1) + (gteLR2/4096.0 * tL2) + (gteLR3/4096.0 * tL3); - tGGLT = gteGBK/4096.0 + (gteLG1/4096.0 * tL1) + (gteLG2/4096.0 * tL2) + (gteLG3/4096.0 * tL3); - tBBLT = gteBBK/4096.0 + (gteLB1/4096.0 * tL1) + (gteLB2/4096.0 * tL2) + (gteLB3/4096.0 * tL3); - - tRLT = LimitAU(tRRLT,24); - tGLT = LimitAU(tGGLT,23); - tBLT = LimitAU(tBBLT,22); - - tRR0 = (R * tRLT) + (gteIR0/4096.0 * LimitAS(gteRFC/16.0 - (R * tRLT),24)); - tGG0 = (G * tGLT) + (gteIR0/4096.0 * LimitAS(gteGFC/16.0 - (G * tGLT),23)); - tBB0 = (B * tBLT) + (gteIR0/4096.0 * LimitAS(gteBFC/16.0 - (B * tBLT),22)); - - gteMAC1 = (long)(tRR0 * 16.0); gteIR1 = (long)LimitAU((tRR0*16.0),24); - gteMAC2 = (long)(tGG0 * 16.0); gteIR2 = (long)LimitAU((tGG0*16.0),23); - gteMAC3 = (long)(tBB0 * 16.0); gteIR3 = (long)LimitAU((tBB0*16.0),22); - - R = (unsigned long)LimitB(tRR0,21); if (R>255) R=255; else if (R<0) R=0; - G = (unsigned long)LimitB(tGG0,20); if (G>255) G=255; else if (G<0) G=0; - B = (unsigned long)LimitB(tBB0,19); if (B>255) B=255; else if (B<0) B=0; - - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - gteRGB2 = R|(G<<8)|(B<<16)|(C<<24); - - R = ((gteRGB)&0xff); - G = ((gteRGB>> 8)&0xff); - B = ((gteRGB>>16)&0xff); - C = ((gteRGB>>24)&0xff); - - tLL1 = (gteL11/4096.0 * gteVX2/4096.0) + (gteL12/4096.0 * gteVY2/4096.0) + (gteL13/4096.0 * gteVZ2/4096.0); - tLL2 = (gteL21/4096.0 * gteVX2/4096.0) + (gteL22/4096.0 * gteVY2/4096.0) + (gteL23/4096.0 * gteVZ2/4096.0); - tLL3 = (gteL31/4096.0 * gteVX2/4096.0) + (gteL32/4096.0 * gteVY2/4096.0) + (gteL33/4096.0 * gteVZ2/4096.0); - - tL1 = LimitAU(tLL1,24); - tL2 = LimitAU(tLL2,23); - tL3 = LimitAU(tLL3,22); - - tRRLT = gteRBK/4096.0 + (gteLR1/4096.0 * tL1) + (gteLR2/4096.0 * tL2) + (gteLR3/4096.0 * tL3); - tGGLT = gteGBK/4096.0 + (gteLG1/4096.0 * tL1) + (gteLG2/4096.0 * tL2) + (gteLG3/4096.0 * tL3); - tBBLT = gteBBK/4096.0 + (gteLB1/4096.0 * tL1) + (gteLB2/4096.0 * tL2) + (gteLB3/4096.0 * tL3); - - tRLT = LimitAU(tRRLT,24); - tGLT = LimitAU(tGGLT,23); - tBLT = LimitAU(tBBLT,22); - - tRR0 = (R * tRLT) + (gteIR0/4096.0 * LimitAS(gteRFC/16.0 - (R * tRLT),24)); - tGG0 = (G * tGLT) + (gteIR0/4096.0 * LimitAS(gteGFC/16.0 - (G * tGLT),23)); - tBB0 = (B * tBLT) + (gteIR0/4096.0 * LimitAS(gteBFC/16.0 - (B * tBLT),22)); - - gteMAC1 = (long)(tRR0 * 16.0); gteIR1 = (long)LimitAU((tRR0*16.0),24); - gteMAC2 = (long)(tGG0 * 16.0); gteIR2 = (long)LimitAU((tGG0*16.0),23); - gteMAC3 = (long)(tBB0 * 16.0); gteIR3 = (long)LimitAU((tBB0*16.0),22); - - R = (unsigned long)LimitB(tRR0,21); if (R>255) R=255; else if (R<0) R=0; - G = (unsigned long)LimitB(tGG0,20); if (G>255) G=255; else if (G<0) G=0; - B = (unsigned long)LimitB(tBB0,19); if (B>255) B=255; else if (B<0) B=0; - - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - gteRGB2 = R|(G<<8)|(B<<16)|(C<<24); - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("NCDT", 44); - G_SD(0); - G_SD(1); - G_SD(2); - G_SD(3); - G_SD(4); - G_SD(5); - G_SD(6); - G_SD(8); - - G_SC(8); - G_SC(9); - G_SC(10); - G_SC(11); - G_SC(12); - G_SC(13); - G_SC(14); - G_SC(15); - G_SC(16); - G_SC(17); - G_SC(18); - G_SC(19); - G_SC(20); - G_SC(21); - G_SC(22); - G_SC(23); - } -#endif - - gteFLAG = 0; - GTE_NCDS(0); - GTE_NCDS(1); - GTE_NCDS(2); - - SUM_FLAG; - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - G_GD(20); - G_GD(21); - G_GD(22); - - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -#define gteD1 (*(short *)>eR11) -#define gteD2 (*(short *)>eR22) -#define gteD3 (*(short *)>eR33) - -void gteOP() { -// double SSX0=0,SSY0=0,SSZ0=0; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif - -#ifdef GTE_LOG - GTE_LOG("GTE_OP %lx\n", psxRegs.code & 0x1ffffff); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("OP", 6); - G_SD(9); - G_SD(10); - G_SD(11); - - G_SC(0); - G_SC(2); - G_SC(4); - } -#endif -/* gteFLAG=0; - - switch (psxRegs.code & 0x1ffffff) { - case 0x178000C://op12 - SSX0 = EDETEC1((gteR22*(short)gteIR3 - gteR33*(short)gteIR2)/(double)4096); - SSY0 = EDETEC2((gteR33*(short)gteIR1 - gteR11*(short)gteIR3)/(double)4096); - SSZ0 = EDETEC3((gteR11*(short)gteIR2 - gteR22*(short)gteIR1)/(double)4096); - break; - case 0x170000C: - SSX0 = EDETEC1((gteR22*(short)gteIR3 - gteR33*(short)gteIR2)); - SSY0 = EDETEC2((gteR33*(short)gteIR1 - gteR11*(short)gteIR3)); - SSZ0 = EDETEC3((gteR11*(short)gteIR2 - gteR22*(short)gteIR1)); - break; - } - - gteMAC1 = (long)float2int(SSX0); - gteMAC2 = (long)float2int(SSY0); - gteMAC3 = (long)float2int(SSZ0); - - MAC2IR(); - - if (gteIR1<0) gteIR1=0; - if (gteIR2<0) gteIR2=0; - if (gteIR3<0) gteIR3=0; - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - gteFLAG = 0; - - if (psxRegs.code & 0x80000) { - - gteMAC1 = NC_OVERFLOW1((gteD2 * gteIR3 - gteD3 * gteIR2) / 4096.0f); - gteMAC2 = NC_OVERFLOW2((gteD3 * gteIR1 - gteD1 * gteIR3) / 4096.0f); - gteMAC3 = NC_OVERFLOW3((gteD1 * gteIR2 - gteD2 * gteIR1) / 4096.0f); - } else { - - gteMAC1 = NC_OVERFLOW1(gteD2 * gteIR3 - gteD3 * gteIR2); - gteMAC2 = NC_OVERFLOW2(gteD3 * gteIR1 - gteD1 * gteIR3); - gteMAC3 = NC_OVERFLOW3(gteD1 * gteIR2 - gteD2 * gteIR1); - } - - /* NC: old - MAC2IR1(); - */ - MAC2IR(); - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -void gteDCPL() { -// unsigned long C,R,G,B; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif -#ifdef GTE_LOG - GTE_LOG("GTE_DCPL\n"); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("DCPL", 8); - G_SD(6); - G_SD(8); - G_SD(9); - G_SD(10); - G_SD(11); - - G_SC(21); - G_SC(22); - G_SC(23); - } -#endif -/* R = ((gteRGB)&0xff); - G = ((gteRGB>> 8)&0xff); - B = ((gteRGB>>16)&0xff); - C = ((gteRGB>>24)&0xff); - - gteMAC1 = (signed long)((double)(R*gteIR1) + (double)(gteIR0*LimitAS(gteRFC-(double)(R*gteIR1),24))/4096.0); - gteMAC2 = (signed long)((double)(G*gteIR2) + (double)(gteIR0*LimitAS(gteGFC-(double)(G*gteIR2),23))/4096.0); - gteMAC3 = (signed long)((double)(B*gteIR3) + (double)(gteIR0*LimitAS(gteBFC-(double)(B*gteIR3),22))/4096.0); - - MAC2IR() - - R = (unsigned long)LimitB(gteMAC1,21); if (R>255) R=255; else if (R<0) R=0; - G = (unsigned long)LimitB(gteMAC2,20); if (G>255) G=255; else if (G<0) G=0; - B = (unsigned long)LimitB(gteMAC3,19); if (B>255) B=255; else if (B<0) B=0; - - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - gteRGB2 = R|(G<<8)|(B<<16)|(C<<24); - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - -/* gteFLAG = 0; - - gteMAC1 = NC_OVERFLOW1((gteR * gteIR1) / 256.0f + (gteIR0 * limA1S(gteRFC - ((gteR * gteIR1) / 256.0f))) / 4096.0f); - gteMAC2 = NC_OVERFLOW2((gteG * gteIR1) / 256.0f + (gteIR0 * limA2S(gteGFC - ((gteG * gteIR1) / 256.0f))) / 4096.0f); - gteMAC3 = NC_OVERFLOW3((gteB * gteIR1) / 256.0f + (gteIR0 * limA3S(gteBFC - ((gteB * gteIR1) / 256.0f))) / 4096.0f); - */ -/* gteMAC1 = ( (signed long)(gteR)*gteIR1 + (gteIR0*(signed short)limA1S(gteRFC - ((gteR*gteIR1)>>12) )) ) >>6; - gteMAC2 = ( (signed long)(gteG)*gteIR2 + (gteIR0*(signed short)limA2S(gteGFC - ((gteG*gteIR2)>>12) )) ) >>6; - gteMAC3 = ( (signed long)(gteB)*gteIR3 + (gteIR0*(signed short)limA3S(gteBFC - ((gteB*gteIR3)>>12) )) ) >>6;*/ - - gteMAC1 = ( (signed long)(gteR)*gteIR1 + (gteIR0*(signed short)limA1S(gteRFC - ((gteR*gteIR1)>>12) )) ) >>8; - gteMAC2 = ( (signed long)(gteG)*gteIR2 + (gteIR0*(signed short)limA2S(gteGFC - ((gteG*gteIR2)>>12) )) ) >>8; - gteMAC3 = ( (signed long)(gteB)*gteIR3 + (gteIR0*(signed short)limA3S(gteBFC - ((gteB*gteIR3)>>12) )) ) >>8; - - gteFLAG=0; - MAC2IR(); - - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - - gteR2 = limB1(gteMAC1 / 16.0f); - gteG2 = limB2(gteMAC2 / 16.0f); - gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - //G_GD(20); - //G_GD(21); - G_GD(22); - - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -void gteGPF() { -// double ipx, ipy, ipz; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif -#ifdef GTE_LOG - GTE_LOG("GTE_GPF %lx\n", psxRegs.code & 0x1ffffff); -#endif -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("GPF", 5); - G_SD(6); - G_SD(8); - G_SD(9); - G_SD(10); - G_SD(11); - } -#endif -/* gteFLAG = 0; - - ipx = (double)((short)gteIR0) * ((short)gteIR1); - ipy = (double)((short)gteIR0) * ((short)gteIR2); - ipz = (double)((short)gteIR0) * ((short)gteIR3); - - // same as mvmva - if (psxRegs.code & 0x80000) { - ipx /= 4096.0; ipy /= 4096.0; ipz /= 4096.0; - } - - gteMAC1 = (long)ipx; - gteMAC2 = (long)ipy; - gteMAC3 = (long)ipz; - - gteIR1 = (long)LimitAS(ipx,24); - gteIR2 = (long)LimitAS(ipy,23); - gteIR3 = (long)LimitAS(ipz,22); - - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - gteC2 = gteCODE; - gteR2 = (unsigned char)LimitB(ipx,21); - gteG2 = (unsigned char)LimitB(ipy,20); - gteB2 = (unsigned char)LimitB(ipz,19);*/ - - gteFLAG = 0; - - if (psxRegs.code & 0x80000) { - gteMAC1 = NC_OVERFLOW1((gteIR0 * gteIR1) / 4096.0f); - gteMAC2 = NC_OVERFLOW2((gteIR0 * gteIR2) / 4096.0f); - gteMAC3 = NC_OVERFLOW3((gteIR0 * gteIR3) / 4096.0f); - } else { - gteMAC1 = NC_OVERFLOW1(gteIR0 * gteIR1); - gteMAC2 = NC_OVERFLOW2(gteIR0 * gteIR2); - gteMAC3 = NC_OVERFLOW3(gteIR0 * gteIR3); - } - MAC2IR(); - - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - - gteR2 = limB1(gteMAC1 / 16.0f); - gteG2 = limB2(gteMAC2 / 16.0f); - gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - //G_GD(20); - //G_GD(21); - G_GD(22); - - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -void gteGPL() { - // double IPX=0,IPY=0,IPZ=0; -// unsigned long C,R,G,B; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif -#ifdef GTE_LOG - GTE_LOG("GTE_GPL %lx\n", psxRegs.code & 0x1ffffff); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("GPL", 5); - G_SD(6); - G_SD(8); - G_SD(9); - G_SD(10); - G_SD(11); - - G_SD(25); - G_SD(26); - G_SD(27); - } -#endif - -/* gteFLAG=0; - switch(psxRegs.code & 0x1ffffff) { - case 0x1A8003E: - IPX = EDETEC1((double)gteMAC1 + ((double)gteIR0*(double)gteIR1)/4096.0f); - IPY = EDETEC2((double)gteMAC2 + ((double)gteIR0*(double)gteIR2)/4096.0f); - IPZ = EDETEC3((double)gteMAC3 + ((double)gteIR0*(double)gteIR3)/4096.0f); - break; - - case 0x1A0003E: - IPX = EDETEC1((double)gteMAC1 + ((double)gteIR0*(double)gteIR1)); - IPY = EDETEC2((double)gteMAC2 + ((double)gteIR0*(double)gteIR2)); - IPZ = EDETEC3((double)gteMAC3 + ((double)gteIR0*(double)gteIR3)); - break; - } - gteIR1 = (short)float2int(LimitAS(IPX,24)); - gteIR2 = (short)float2int(LimitAS(IPY,23)); - gteIR3 = (short)float2int(LimitAS(IPZ,22)); - - gteMAC1 = (int)float2int(IPX); - gteMAC2 = (int)float2int(IPY); - gteMAC3 = (int)float2int(IPZ); - - C = gteRGB & 0xff000000; - R = float2int(ALIMIT(IPX,0,255)); - G = float2int(ALIMIT(IPY,0,255)); - B = float2int(ALIMIT(IPZ,0,255)); - - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - gteRGB2 = C|R|(G<<8)|(B<<16);*/ - gteFLAG = 0; - - if (psxRegs.code & 0x80000) { - - gteMAC1 = NC_OVERFLOW1(gteMAC1 + (gteIR0 * gteIR1) / 4096.0f); - gteMAC2 = NC_OVERFLOW2(gteMAC2 + (gteIR0 * gteIR2) / 4096.0f); - gteMAC3 = NC_OVERFLOW3(gteMAC3 + (gteIR0 * gteIR3) / 4096.0f); - } else { - - gteMAC1 = NC_OVERFLOW1(gteMAC1 + (gteIR0 * gteIR1)); - gteMAC2 = NC_OVERFLOW2(gteMAC2 + (gteIR0 * gteIR2)); - gteMAC3 = NC_OVERFLOW3(gteMAC3 + (gteIR0 * gteIR3)); - } - MAC2IR(); - - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - - gteR2 = limB1(gteMAC1 / 16.0f); - gteG2 = limB2(gteMAC2 / 16.0f); - gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - //G_GD(20); - //G_GD(21); - G_GD(22); - - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -/* -#define GTE_DPCS() { \ - RR0 = (double)R + (gteIR0*LimitAS((double)(gteRFC - R),24))/4096.0; \ - GG0 = (double)G + (gteIR0*LimitAS((double)(gteGFC - G),23))/4096.0; \ - BB0 = (double)B + (gteIR0*LimitAS((double)(gteBFC - B),22))/4096.0; \ - \ - gteIR1 = (long)LimitAS(RR0,24); \ - gteIR2 = (long)LimitAS(GG0,23); \ - gteIR3 = (long)LimitAS(BB0,22); \ - \ - gteRGB0 = gteRGB1; \ - gteRGB1 = gteRGB2; \ - gteC2 = C; \ - gteR2 = (unsigned char)LimitB(RR0/16.0,21); \ - gteG2 = (unsigned char)LimitB(GG0/16.0,20); \ - gteB2 = (unsigned char)LimitB(BB0/16.0,19); \ - \ - gteMAC1 = (long)RR0; \ - gteMAC2 = (long)GG0; \ - gteMAC3 = (long)BB0; \ -} -*/ -void gteDPCS() { -// unsigned long C,R,G,B; -// double RR0,GG0,BB0; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif -#ifdef GTE_LOG - GTE_LOG("GTE_DPCS\n"); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("DPCS", 8); - G_SD(6); - G_SD(8); - - G_SC(21); - G_SC(22); - G_SC(23); - } -#endif - -/* gteFLAG = 0; - - C = gteCODE; - R = gteR * 16.0; - G = gteG * 16.0; - B = gteB * 16.0; - - GTE_DPCS(); - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ -/* gteFLAG = 0; - - gteMAC1 = NC_OVERFLOW1((gteR * 16.0f) + (gteIR0 * limA1S(gteRFC - (gteR * 16.0f))) / 4096.0f); - gteMAC2 = NC_OVERFLOW2((gteG * 16.0f) + (gteIR0 * limA2S(gteGFC - (gteG * 16.0f))) / 4096.0f); - gteMAC3 = NC_OVERFLOW3((gteB * 16.0f) + (gteIR0 * limA3S(gteBFC - (gteB * 16.0f))) / 4096.0f); - */ - gteMAC1 = (gteR<<4) + ( (gteIR0*(signed short)limA1S(gteRFC-(gteR<<4)) ) >>12); - gteMAC2 = (gteG<<4) + ( (gteIR0*(signed short)limA2S(gteGFC-(gteG<<4)) ) >>12); - gteMAC3 = (gteB<<4) + ( (gteIR0*(signed short)limA3S(gteBFC-(gteB<<4)) ) >>12); - - gteFLAG = 0; - MAC2IR(); - - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - - gteR2 = limB1(gteMAC1 / 16.0f); - gteG2 = limB2(gteMAC2 / 16.0f); - gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - //G_GD(20); - //G_GD(21); - G_GD(22); - - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -void gteDPCT() { -// unsigned long C,R,G,B; -// double RR0,GG0,BB0; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif -#ifdef GTE_LOG - GTE_LOG("GTE_DPCT\n"); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("DPCT", 17); - G_SD(8); - - G_SD(20); - G_SD(21); - G_SD(22); - - G_SC(21); - G_SC(22); - G_SC(23); - } -#endif -/* gteFLAG = 0; - - C = gteCODE0; - R = gteR0 * 16.0; - G = gteG0 * 16.0; - B = gteB0 * 16.0; - - GTE_DPCS(); - - C = gteCODE0; - R = gteR0 * 16.0; - G = gteG0 * 16.0; - B = gteB0 * 16.0; - - GTE_DPCS(); - - C = gteCODE0; - R = gteR0 * 16.0; - G = gteG0 * 16.0; - B = gteB0 * 16.0; - - GTE_DPCS(); - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ -/* gteFLAG = 0; - - gteMAC1 = NC_OVERFLOW1((gteR0 * 16.0f) + gteIR0 * limA1S(gteRFC - (gteR0 * 16.0f))); - gteMAC2 = NC_OVERFLOW2((gteG0 * 16.0f) + gteIR0 * limA2S(gteGFC - (gteG0 * 16.0f))); - gteMAC3 = NC_OVERFLOW3((gteB0 * 16.0f) + gteIR0 * limA3S(gteBFC - (gteB0 * 16.0f))); - */ - gteMAC1 = (gteR0<<4) + ( (gteIR0*(signed short)limA1S(gteRFC-(gteR0<<4)) ) >>12); - gteMAC2 = (gteG0<<4) + ( (gteIR0*(signed short)limA2S(gteGFC-(gteG0<<4)) ) >>12); - gteMAC3 = (gteB0<<4) + ( (gteIR0*(signed short)limA3S(gteBFC-(gteB0<<4)) ) >>12); -// MAC2IR(); - - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - - gteR2 = limB1(gteMAC1 / 16.0f); - gteG2 = limB2(gteMAC2 / 16.0f); - gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; - - gteMAC1 = (gteR0<<4) + ( (gteIR0*(signed short)limA1S(gteRFC-(gteR0<<4)) ) >>12); - gteMAC2 = (gteG0<<4) + ( (gteIR0*(signed short)limA2S(gteGFC-(gteG0<<4)) ) >>12); - gteMAC3 = (gteB0<<4) + ( (gteIR0*(signed short)limA3S(gteBFC-(gteB0<<4)) ) >>12); -// MAC2IR(); - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - - gteR2 = limB1(gteMAC1 / 16.0f); - gteG2 = limB2(gteMAC2 / 16.0f); - gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; - - gteMAC1 = (gteR0<<4) + ( (gteIR0*(signed short)limA1S(gteRFC-(gteR0<<4)) ) >>12); - gteMAC2 = (gteG0<<4) + ( (gteIR0*(signed short)limA2S(gteGFC-(gteG0<<4)) ) >>12); - gteMAC3 = (gteB0<<4) + ( (gteIR0*(signed short)limA3S(gteBFC-(gteB0<<4)) ) >>12); - gteFLAG = 0; - MAC2IR(); - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - - gteR2 = limB1(gteMAC1 / 16.0f); - gteG2 = limB2(gteMAC2 / 16.0f); - gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - G_GD(20); - G_GD(21); - G_GD(22); - - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -/* -#define GTE_NCS(vn) { \ - RR0 = ((double)gteVX##vn * gteL11 + (double)gteVY##vn * (double)gteL12 + (double)gteVZ##vn * gteL13) / 4096.0; \ - GG0 = ((double)gteVX##vn * gteL21 + (double)gteVY##vn * (double)gteL22 + (double)gteVZ##vn * gteL23) / 4096.0; \ - BB0 = ((double)gteVX##vn * gteL31 + (double)gteVY##vn * (double)gteL32 + (double)gteVZ##vn * gteL33) / 4096.0; \ - t1 = LimitAU(RR0, 24); \ - t2 = LimitAU(GG0, 23); \ - t3 = LimitAU(BB0, 22); \ - \ - RR0 = (double)gteRBK + ((double)gteLR1 * t1 + (double)gteLR2 * t2 + (double)gteLR3 * t3) / 4096.0; \ - GG0 = (double)gteGBK + ((double)gteLG1 * t1 + (double)gteLG2 * t2 + (double)gteLG3 * t3) / 4096.0; \ - BB0 = (double)gteBBK + ((double)gteLB1 * t1 + (double)gteLB2 * t2 + (double)gteLB3 * t3) / 4096.0; \ - t1 = LimitAU(RR0, 24); \ - t2 = LimitAU(GG0, 23); \ - t3 = LimitAU(BB0, 22); \ - \ - gteRGB0 = gteRGB1; gteRGB1 = gteRGB2; \ - gteR2 = (unsigned char)LimitB(RR0/16.0, 21); \ - gteG2 = (unsigned char)LimitB(GG0/16.0, 20); \ - gteB2 = (unsigned char)LimitB(BB0/16.0, 19); \ - gteCODE2=gteCODE0; \ -}*/ - -#define LOW(a) (((a) < 0) ? 0 : (a)) - -#define GTE_NCS(vn) \ -RR0 = LOW((gteL11*gteVX##vn + gteL12*gteVY##vn + gteL13*gteVZ##vn)/4096.0f); \ -GG0 = LOW((gteL21*gteVX##vn + gteL22*gteVY##vn + gteL23*gteVZ##vn)/4096.0f); \ -BB0 = LOW((gteL31*gteVX##vn + gteL32*gteVY##vn + gteL33*gteVZ##vn)/4096.0f); \ -gteMAC1 = gteRBK + (gteLR1*RR0 + gteLR2*GG0 + gteLR3*BB0)/4096.0f; \ -gteMAC2 = gteGBK + (gteLG1*RR0 + gteLG2*GG0 + gteLG3*BB0)/4096.0f; \ -gteMAC3 = gteBBK + (gteLB1*RR0 + gteLB2*GG0 + gteLB3*BB0)/4096.0f; \ -gteRGB0 = gteRGB1; \ -gteRGB1 = gteRGB2; \ -gteR2 = limB1(gteMAC1 / 16.0f); \ -gteG2 = limB2(gteMAC2 / 16.0f); \ -gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; - -void gteNCS() { - double RR0,GG0,BB0; -// double t1, t2, t3; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif -#ifdef GTE_LOG - GTE_LOG("GTE_NCS\n"); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("NCS", 14); - G_SD(0); - G_SD(1); - G_SD(6); - - G_SC(8); - G_SC(9); - G_SC(10); - G_SC(11); - G_SC(12); - G_SC(13); - G_SC(14); - G_SC(15); - G_SC(16); - G_SC(17); - G_SC(18); - G_SC(19); - G_SC(20); - } -#endif -/* gteFLAG = 0; - - GTE_NCS(0); - - gteMAC1=(long)RR0; - gteMAC2=(long)GG0; - gteMAC3=(long)BB0; - - gteIR1=(long)t1; - gteIR2=(long)t2; - gteIR3=(long)t3; - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - gteFLAG = 0; - - GTE_NCS(0); - - MAC2IR1(); - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - //G_GD(20); - //G_GD(21); - G_GD(22); - - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -void gteNCT() { - double RR0,GG0,BB0; -// double t1, t2, t3; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif -#ifdef GTE_LOG - GTE_LOG("GTE_NCT\n"); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("NCT", 30); - G_SD(0); - G_SD(1); - G_SD(2); - G_SD(3); - G_SD(4); - G_SD(5); - G_SD(6); - - G_SC(8); - G_SC(9); - G_SC(10); - G_SC(11); - G_SC(12); - G_SC(13); - G_SC(14); - G_SC(15); - G_SC(16); - G_SC(17); - G_SC(18); - G_SC(19); - G_SC(20); - } -#endif -/* - gteFLAG = 0; - -//V0 - GTE_NCS(0); -//V1 - GTE_NCS(1); -//V2 - GTE_NCS(2); - - gteMAC1=(long)RR0; - gteMAC2=(long)GG0; - gteMAC3=(long)BB0; - - gteIR1=(long)t1; - gteIR2=(long)t2; - gteIR3=(long)t3; - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - gteFLAG = 0; - - GTE_NCS(0); - GTE_NCS(1); - GTE_NCS(2); - - MAC2IR1(); - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - G_GD(20); - G_GD(21); - G_GD(22); - - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -void gteCC() { - double RR0,GG0,BB0; -// double t1,t2,t3; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif -#ifdef GTE_LOG - GTE_LOG("GTE_CC\n"); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("CC", 11); - G_SD(6); - G_SD(9); - G_SD(10); - G_SD(11); - - G_SC(13); - G_SC(14); - G_SC(15); - G_SC(16); - G_SC(17); - G_SC(18); - G_SC(19); - } -#endif -/* gteFLAG = 0; - - RR0 = (double)gteRBK + ((double)gteLR1 * gteIR1 + (double)gteLR2 * gteIR2 + (double)gteLR3 * gteIR3) / 4096.0; - GG0 = (double)gteGBK + ((double)gteLG1 * gteIR1 + (double)gteLG2 * gteIR2 + (double)gteLG3 * gteIR3) / 4096.0; - BB0 = (double)gteBBK + ((double)gteLB1 * gteIR1 + (double)gteLB2 * gteIR2 + (double)gteLB3 * gteIR3) / 4096.0; - t1 = LimitAU(RR0, 24); - t2 = LimitAU(GG0, 23); - t3 = LimitAU(BB0, 22); - - RR0=((double)gteR * t1)/256.0; - GG0=((double)gteG * t2)/256.0; - BB0=((double)gteB * t3)/256.0; - gteIR1 = (long)LimitAU(RR0,24); - gteIR2 = (long)LimitAU(GG0,23); - gteIR3 = (long)LimitAU(BB0,22); - - gteCODE0=gteCODE1; gteCODE1=gteCODE2; - gteC2 = gteCODE0; - gteR2 = (unsigned char)LimitB(RR0/16.0, 21); - gteG2 = (unsigned char)LimitB(GG0/16.0, 20); - gteB2 = (unsigned char)LimitB(BB0/16.0, 19); - - if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ - gteFLAG = 0; - - RR0 = NC_OVERFLOW1(gteRBK + (gteLR1*gteIR1 + gteLR2*gteIR2 + gteLR3*gteIR3) / 4096.0f); - GG0 = NC_OVERFLOW2(gteGBK + (gteLG1*gteIR1 + gteLG2*gteIR2 + gteLG3*gteIR3) / 4096.0f); - BB0 = NC_OVERFLOW3(gteBBK + (gteLB1*gteIR1 + gteLB2*gteIR2 + gteLB3*gteIR3) / 4096.0f); - - gteMAC1 = gteR * RR0 / 256.0f; - gteMAC2 = gteG * GG0 / 256.0f; - gteMAC3 = gteB * BB0 / 256.0f; - - MAC2IR1(); - - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - - gteR2 = limB1(gteMAC1 / 16.0f); - gteG2 = limB2(gteMAC2 / 16.0f); - gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - //G_GD(20); - //G_GD(21); - G_GD(22); - - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -void gteINTPL() { //test opcode -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif -#ifdef GTE_LOG - GTE_LOG("GTE_INTP\n"); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("INTPL", 8); - G_SD(6); - G_SD(8); - G_SD(9); - G_SD(10); - G_SD(11); - - G_SC(21); - G_SC(22); - G_SC(23); - } -#endif - /* NC: old - gteFLAG=0; - gteMAC1 = gteIR1 + gteIR0*limA1S(gteRFC-gteIR1); - gteMAC2 = gteIR2 + gteIR0*limA2S(gteGFC-gteIR2); - gteMAC3 = gteIR3 + gteIR0*limA3S(gteBFC-gteIR3); - //gteFLAG = 0; - MAC2IR(); - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - - gteR2 = limB1(gteMAC1 / 16.0f); - gteG2 = limB2(gteMAC2 / 16.0f); - gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; - */ - -/* gteFLAG=0; - gteMAC1 = gteIR1 + gteIR0*(gteRFC-gteIR1)/4096.0; - gteMAC2 = gteIR2 + gteIR0*(gteGFC-gteIR2)/4096.0; - gteMAC3 = gteIR3 + gteIR0*(gteBFC-gteIR3)/4096.0; - - //gteMAC3 = (int)((((psxRegs).CP2D).n).ir3+(((psxRegs).CP2D).n).ir0 * ((((psxRegs).CP2C).n).bfc-(((psxRegs).CP2D).n).ir3)/4096.0); - - if(gteMAC3 > gteIR1 && gteMAC3 > gteBFC) - { - gteMAC3 = gteMAC3; - } - //gteFLAG = 0;*/ - //NEW CODE - gteMAC1 = gteIR1 + ((gteIR0*(signed short)limA1S(gteRFC-gteIR1))>>12); - gteMAC2 = gteIR2 + ((gteIR0*(signed short)limA2S(gteGFC-gteIR2))>>12); - gteMAC3 = gteIR3 + ((gteIR0*(signed short)limA3S(gteBFC-gteIR3))>>12); - gteFLAG = 0; - - MAC2IR(); - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - - gteR2 = limB1(gteMAC1 / 16.0f); - gteG2 = limB2(gteMAC2 / 16.0f); - gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - //G_GD(20); - //G_GD(21); - G_GD(22); - - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} - -void gteCDP() { //test opcode - double RR0,GG0,BB0; -#ifdef GTE_DUMP - static int sample = 0; sample++; -#endif -#ifdef GTE_LOG - GTE_LOG("GTE_CDP\n"); -#endif - -#ifdef GTE_DUMP - if(sample < 100) - { - G_OP("CDP", 13); - G_SD(6); - G_SD(8); - G_SD(9); - G_SD(10); - G_SD(11); - - G_SC(13); - G_SC(14); - G_SC(15); - G_SC(16); - G_SC(17); - G_SC(18); - G_SC(19); - G_SC(20); - G_SC(21); - G_SC(22); - G_SC(23); - } -#endif - - gteFLAG = 0; - - RR0 = NC_OVERFLOW1(gteRBK + (gteLR1*gteIR1 +gteLR2*gteIR2 + gteLR3*gteIR3)); - GG0 = NC_OVERFLOW2(gteGBK + (gteLG1*gteIR1 +gteLG2*gteIR2 + gteLG3*gteIR3)); - BB0 = NC_OVERFLOW3(gteBBK + (gteLB1*gteIR1 +gteLB2*gteIR2 + gteLB3*gteIR3)); - gteMAC1 = gteR*RR0 + gteIR0*limA1S(gteRFC-gteR*RR0); - gteMAC2 = gteG*GG0 + gteIR0*limA2S(gteGFC-gteG*GG0); - gteMAC3 = gteB*BB0 + gteIR0*limA3S(gteBFC-gteB*BB0); - MAC2IR1(); - gteRGB0 = gteRGB1; - gteRGB1 = gteRGB2; - - gteR2 = limB1(gteMAC1 / 16.0f); - gteG2 = limB2(gteMAC2 / 16.0f); - gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; - - SUM_FLAG - -#ifdef GTE_DUMP - if(sample < 100) - { - G_GD(9); - G_GD(10); - G_GD(11); - - //G_GD(20); - //G_GD(21); - G_GD(22); - - G_GD(25); - G_GD(26); - G_GD(27); - - G_GC(31); - } -#endif -} +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include +#include "Gte.h" +#include "R3000A.h" + +#ifdef GTE_DUMP +#define G_OP(name,delay) fprintf(gteLog, "* : %08X : %02d : %s\n", psxRegs.code, delay, name); +#define G_SD(reg) fprintf(gteLog, "+D%02d : %08X\n", reg, psxRegs.CP2D.r[reg]); +#define G_SC(reg) fprintf(gteLog, "+C%02d : %08X\n", reg, psxRegs.CP2C.r[reg]); +#define G_GD(reg) fprintf(gteLog, "-D%02d : %08X\n", reg, psxRegs.CP2D.r[reg]); +#define G_GC(reg) fprintf(gteLog, "-C%02d : %08X\n", reg, psxRegs.CP2C.r[reg]); +#else +#define G_OP(name,delay) +#define G_SD(reg) +#define G_SC(reg) +#define G_GD(reg) +#define G_GC(reg) +#endif + +#define SUM_FLAG if(gteFLAG & 0x7F87E000) gteFLAG |= 0x80000000; + +#ifdef __WIN32__ +#pragma warning(disable:4244) +#endif + +#define gteVX0 ((s16*)psxRegs.CP2D.r)[0] +#define gteVY0 ((s16*)psxRegs.CP2D.r)[1] +#define gteVZ0 ((s16*)psxRegs.CP2D.r)[2] +#define gteVX1 ((s16*)psxRegs.CP2D.r)[4] +#define gteVY1 ((s16*)psxRegs.CP2D.r)[5] +#define gteVZ1 ((s16*)psxRegs.CP2D.r)[6] +#define gteVX2 ((s16*)psxRegs.CP2D.r)[8] +#define gteVY2 ((s16*)psxRegs.CP2D.r)[9] +#define gteVZ2 ((s16*)psxRegs.CP2D.r)[10] +#define gteRGB psxRegs.CP2D.r[6] +#define gteOTZ ((s16*)psxRegs.CP2D.r)[7*2] +#define gteIR0 ((s32*)psxRegs.CP2D.r)[8] +#define gteIR1 ((s32*)psxRegs.CP2D.r)[9] +#define gteIR2 ((s32*)psxRegs.CP2D.r)[10] +#define gteIR3 ((s32*)psxRegs.CP2D.r)[11] +#define gteSX0 ((s16*)psxRegs.CP2D.r)[12*2] +#define gteSY0 ((s16*)psxRegs.CP2D.r)[12*2+1] +#define gteSX1 ((s16*)psxRegs.CP2D.r)[13*2] +#define gteSY1 ((s16*)psxRegs.CP2D.r)[13*2+1] +#define gteSX2 ((s16*)psxRegs.CP2D.r)[14*2] +#define gteSY2 ((s16*)psxRegs.CP2D.r)[14*2+1] +#define gteSXP ((s16*)psxRegs.CP2D.r)[15*2] +#define gteSYP ((s16*)psxRegs.CP2D.r)[15*2+1] +#define gteSZx ((u16*)psxRegs.CP2D.r)[16*2] +#define gteSZ0 ((u16*)psxRegs.CP2D.r)[17*2] +#define gteSZ1 ((u16*)psxRegs.CP2D.r)[18*2] +#define gteSZ2 ((u16*)psxRegs.CP2D.r)[19*2] +#define gteRGB0 psxRegs.CP2D.r[20] +#define gteRGB1 psxRegs.CP2D.r[21] +#define gteRGB2 psxRegs.CP2D.r[22] +#define gteMAC0 psxRegs.CP2D.r[24] +#define gteMAC1 ((s32*)psxRegs.CP2D.r)[25] +#define gteMAC2 ((s32*)psxRegs.CP2D.r)[26] +#define gteMAC3 ((s32*)psxRegs.CP2D.r)[27] +#define gteIRGB psxRegs.CP2D.r[28] +#define gteORGB psxRegs.CP2D.r[29] +#define gteLZCS psxRegs.CP2D.r[30] +#define gteLZCR psxRegs.CP2D.r[31] + +#define gteR ((u8 *)psxRegs.CP2D.r)[6*4] +#define gteG ((u8 *)psxRegs.CP2D.r)[6*4+1] +#define gteB ((u8 *)psxRegs.CP2D.r)[6*4+2] +#define gteCODE ((u8 *)psxRegs.CP2D.r)[6*4+3] +#define gteC gteCODE + +#define gteR0 ((u8 *)psxRegs.CP2D.r)[20*4] +#define gteG0 ((u8 *)psxRegs.CP2D.r)[20*4+1] +#define gteB0 ((u8 *)psxRegs.CP2D.r)[20*4+2] +#define gteCODE0 ((u8 *)psxRegs.CP2D.r)[20*4+3] +#define gteC0 gteCODE0 + +#define gteR1 ((u8 *)psxRegs.CP2D.r)[21*4] +#define gteG1 ((u8 *)psxRegs.CP2D.r)[21*4+1] +#define gteB1 ((u8 *)psxRegs.CP2D.r)[21*4+2] +#define gteCODE1 ((u8 *)psxRegs.CP2D.r)[21*4+3] +#define gteC1 gteCODE1 + +#define gteR2 ((u8 *)psxRegs.CP2D.r)[22*4] +#define gteG2 ((u8 *)psxRegs.CP2D.r)[22*4+1] +#define gteB2 ((u8 *)psxRegs.CP2D.r)[22*4+2] +#define gteCODE2 ((u8 *)psxRegs.CP2D.r)[22*4+3] +#define gteC2 gteCODE2 + + + +#define gteR11 ((s16*)psxRegs.CP2C.r)[0] +#define gteR12 ((s16*)psxRegs.CP2C.r)[1] +#define gteR13 ((s16*)psxRegs.CP2C.r)[2] +#define gteR21 ((s16*)psxRegs.CP2C.r)[3] +#define gteR22 ((s16*)psxRegs.CP2C.r)[4] +#define gteR23 ((s16*)psxRegs.CP2C.r)[5] +#define gteR31 ((s16*)psxRegs.CP2C.r)[6] +#define gteR32 ((s16*)psxRegs.CP2C.r)[7] +#define gteR33 ((s16*)psxRegs.CP2C.r)[8] +#define gteTRX ((s32*)psxRegs.CP2C.r)[5] +#define gteTRY ((s32*)psxRegs.CP2C.r)[6] +#define gteTRZ ((s32*)psxRegs.CP2C.r)[7] +#define gteL11 ((s16*)psxRegs.CP2C.r)[16] +#define gteL12 ((s16*)psxRegs.CP2C.r)[17] +#define gteL13 ((s16*)psxRegs.CP2C.r)[18] +#define gteL21 ((s16*)psxRegs.CP2C.r)[19] +#define gteL22 ((s16*)psxRegs.CP2C.r)[20] +#define gteL23 ((s16*)psxRegs.CP2C.r)[21] +#define gteL31 ((s16*)psxRegs.CP2C.r)[22] +#define gteL32 ((s16*)psxRegs.CP2C.r)[23] +#define gteL33 ((s16*)psxRegs.CP2C.r)[24] +#define gteRBK ((s32*)psxRegs.CP2C.r)[13] +#define gteGBK ((s32*)psxRegs.CP2C.r)[14] +#define gteBBK ((s32*)psxRegs.CP2C.r)[15] +#define gteLR1 ((s16*)psxRegs.CP2C.r)[32] +#define gteLR2 ((s16*)psxRegs.CP2C.r)[33] +#define gteLR3 ((s16*)psxRegs.CP2C.r)[34] +#define gteLG1 ((s16*)psxRegs.CP2C.r)[35] +#define gteLG2 ((s16*)psxRegs.CP2C.r)[36] +#define gteLG3 ((s16*)psxRegs.CP2C.r)[37] +#define gteLB1 ((s16*)psxRegs.CP2C.r)[38] +#define gteLB2 ((s16*)psxRegs.CP2C.r)[39] +#define gteLB3 ((s16*)psxRegs.CP2C.r)[40] +#define gteRFC ((s32*)psxRegs.CP2C.r)[21] +#define gteGFC ((s32*)psxRegs.CP2C.r)[22] +#define gteBFC ((s32*)psxRegs.CP2C.r)[23] +#define gteOFX ((s32*)psxRegs.CP2C.r)[24] +#define gteOFY ((s32*)psxRegs.CP2C.r)[25] +#define gteH ((u16*)psxRegs.CP2C.r)[52] +#define gteDQA ((s16*)psxRegs.CP2C.r)[54] +#define gteDQB ((s32*)psxRegs.CP2C.r)[28] +#define gteZSF3 ((s16*)psxRegs.CP2C.r)[58] +#define gteZSF4 ((s16*)psxRegs.CP2C.r)[60] +#define gteFLAG psxRegs.CP2C.r[31] + +__inline unsigned long MFC2(int reg) { + switch(reg) { + case 29: + gteORGB = (gteIR1 ) | + (gteIR2 << 5) | + (gteIR3 << 10); +// gteORGB = ((gteIR1 & 0xf80)>>7) | +// ((gteIR2 & 0xf80)>>2) | +// ((gteIR3 & 0xf80)<<3); + return gteORGB; + + default: + return psxRegs.CP2D.r[reg]; + } +} + +__inline void MTC2(unsigned long value, int reg) { + int a; + + switch(reg) { + case 8: case 9: case 10: case 11: + psxRegs.CP2D.r[reg] = (short)value; + break; + + case 15: + psxRegs.CP2D.r[12] = psxRegs.CP2D.r[13]; + psxRegs.CP2D.r[13] = psxRegs.CP2D.r[14]; + psxRegs.CP2D.r[14] = value; + psxRegs.CP2D.r[15] = value; + break; + + case 16: case 17: case 18: case 19: + psxRegs.CP2D.r[reg] = (value & 0xffff); + break; + + case 28: + psxRegs.CP2D.r[28] = value; + gteIR1 = (value ) & 0x1f; + gteIR2 = (value >> 5) & 0x1f; + gteIR3 = (value >> 10) & 0x1f; +// gteIR1 = ((value ) & 0x1f) << 4; +// gteIR2 = ((value >> 5) & 0x1f) << 4; +// gteIR3 = ((value >> 10) & 0x1f) << 4; + break; + + case 30: + psxRegs.CP2D.r[30] = value; + + a = psxRegs.CP2D.r[30]; +#if defined(__WIN32__) + if (a > 0) { + __asm { + mov eax, a; + bsr eax, eax; + mov a, eax; + } + psxRegs.CP2D.r[31] = 31 - a; + } else if (a < 0) { + __asm { + mov eax, a; + xor eax, 0xffffffff; + bsr eax, eax; + mov a, eax; + } + psxRegs.CP2D.r[31] = 31 - a; + } else { + psxRegs.CP2D.r[31] = 32; + } +#elif defined(__LINUX__) + if (a > 0) { + __asm__ ("bsrl %1, %0\n" : "=r"(a) : "r"(a) ); + psxRegs.CP2D.r[31] = 31 - a; + } else if (a < 0) { + a^= 0xffffffff; + __asm__ ("bsrl %1, %0\n" : "=r"(a) : "r"(a) ); + psxRegs.CP2D.r[31] = 31 - a; + } else { + psxRegs.CP2D.r[31] = 32; + } +#else + if (a > 0) { + int i; + for (i=31; (a & (1 << i)) == 0 && i >= 0; i--); + psxRegs.CP2D.r[31] = 31 - i; + } else if (a < 0) { + int i; + a^= 0xffffffff; + for (i=31; (a & (1 << i)) == 0 && i >= 0; i--); + psxRegs.CP2D.r[31] = 31 - i; + } else { + psxRegs.CP2D.r[31] = 32; + } +#endif + break; + + default: + psxRegs.CP2D.r[reg] = value; + } +} + +void gteMFC2() { + if (!_Rt_) return; + psxRegs.GPR.r[_Rt_] = MFC2(_Rd_); +} + +void gteCFC2() { + if (!_Rt_) return; + psxRegs.GPR.r[_Rt_] = psxRegs.CP2C.r[_Rd_]; +} + +void gteMTC2() { + MTC2(psxRegs.GPR.r[_Rt_], _Rd_); +} + +void gteCTC2() { + psxRegs.CP2C.r[_Rd_] = psxRegs.GPR.r[_Rt_]; +} + +#define _oB_ (psxRegs.GPR.r[_Rs_] + _Imm_) + +void gteLWC2() { + MTC2(psxMemRead32(_oB_), _Rt_); +} + +void gteSWC2() { + psxMemWrite32(_oB_, MFC2(_Rt_)); +} + +/////LIMITATIONS AND OTHER STUFF************************************ +#define MAC2IR() \ +{ \ + if (gteMAC1 < (long)(-32768)) { gteIR1=(long)(-32768); gteFLAG|=1<<24;} \ + else \ + if (gteMAC1 > (long)( 32767)) { gteIR1=(long)( 32767); gteFLAG|=1<<24;} \ + else gteIR1=(long)gteMAC1; \ + if (gteMAC2 < (long)(-32768)) { gteIR2=(long)(-32768); gteFLAG|=1<<23;} \ + else \ + if (gteMAC2 > (long)( 32767)) { gteIR2=(long)( 32767); gteFLAG|=1<<23;} \ + else gteIR2=(long)gteMAC2; \ + if (gteMAC3 < (long)(-32768)) { gteIR3=(long)(-32768); gteFLAG|=1<<22;} \ + else \ + if (gteMAC3 > (long)( 32767)) { gteIR3=(long)( 32767); gteFLAG|=1<<22;} \ + else gteIR3=(long)gteMAC3; \ +} + + +#define MAC2IR1() \ +{ \ + if (gteMAC1 < (long)0) { gteIR1=(long)0; gteFLAG|=1<<24;} \ + else if (gteMAC1 > (long)(32767)) { gteIR1=(long)(32767); gteFLAG|=1<<24;} \ + else gteIR1=(long)gteMAC1; \ + if (gteMAC2 < (long)0) { gteIR2=(long)0; gteFLAG|=1<<23;} \ + else if (gteMAC2 > (long)(32767)) { gteIR2=(long)(32767); gteFLAG|=1<<23;} \ + else gteIR2=(long)gteMAC2; \ + if (gteMAC3 < (long)0) { gteIR3=(long)0; gteFLAG|=1<<22;} \ + else if (gteMAC3 > (long)(32767)) { gteIR3=(long)(32767); gteFLAG|=1<<22;} \ + else gteIR3=(long)gteMAC3; \ +} + + + +/* +#define MAGIC (((65536. * 65536. * 16) + (65536.*.5)) * 65536.) + +static __inline long float2int(double d) +{ + double dtemp = MAGIC + d; + return (*(long *)&dtemp)-0x80000000; +}*/ +__inline double NC_OVERFLOW1(double x) +{ + if (x<-2147483648.0) {gteFLAG |= 1<<29;} + else + if (x> 2147483647.0) {gteFLAG |= 1<<26;} + + return x; +} + +__inline double NC_OVERFLOW2(double x) +{ + if (x<-2147483648.0) {gteFLAG |= 1<<28;} + else + if (x> 2147483647.0) {gteFLAG |= 1<<25;} + + return x; +} + +__inline double NC_OVERFLOW3(double x) +{ + if (x<-2147483648.0) {gteFLAG |= 1<<27;} + else + if (x> 2147483647.0) {gteFLAG |= 1<<24;} + + return x; +} + +__inline double NC_OVERFLOW4(double x) +{ + if (x<-2147483648.0) {gteFLAG |= 1<<16;} + else + if (x> 2147483647.0) {gteFLAG |= 1<<15;} + + return x; +} +/* +__inline double EDETEC1(double data) +{ + if (data<(double)-2147483647) {gteFLAG|=1<<30; return (double)-2147483647;} + else + if (data>(double) 2147483647) {gteFLAG|=1<<27; return (double) 2147483647;} + + else return data; +} + +__inline double EDETEC2(double data) +{ + if (data<(double)-2147483647) {gteFLAG|=1<<29; return (double)-2147483647;} + else + if (data>(double) 2147483647) {gteFLAG|=1<<26; return (double) 2147483647;} + + else return data; +} + +__inline double EDETEC3(double data) +{ + if (data<(double)-2147483647) {gteFLAG|=1<<28; return (double)-2147483647;} + else + if (data>(double) 2147483647) {gteFLAG|=1<<25; return (double) 2147483647;} + + else return data; +} + +__inline double EDETEC4(double data) +{ + if (data<(double)-2147483647) {gteFLAG|=1<<16; return (double)-2147483647;} + else + if (data>(double) 2147483647) {gteFLAG|=1<<15; return (double) 2147483647;} + + else return data; +}*/ +/* +double LimitAU(double fraction,unsigned long bitIndex) { + if (fraction < 0.0) { fraction = 0.0; gteFLAG |= (1< 32767.0) { fraction = 32767.0; gteFLAG |= (1< 32767.0) { fraction = 32767.0; gteFLAG |= (1< 255.0) { fraction = 255.0; gteFLAG |= (1< 65535.0) { fraction = 65535.0; gteFLAG |= (1< 1023.0) { fraction = 1023.0; gteFLAG |= (1< 1023.0) { fraction = 1023.0; gteFLAG |= (1<MAX) {gteFLAG|=1<MAX) return MAX; + + else return data; +} + +double OLIMIT(double data) +{ + data=(data); + + if (data<(double)-2147483647) {return (double)-2147483647;} + else + if (data>(double) 2147483647) {return (double) 2147483647;} + + else return data; +}*/ + +double limA1S(double x) { + + if (x <-32768.0) { x =-32768.0; gteFLAG |= (1<<24); } else + if (x > 32767.0) { x = 32767.0; gteFLAG |= (1<<24); } return (x); +} + +double limA2S(double x) { + + if (x <-32768.0) { x =-32768.0; gteFLAG |= (1<<23); } else + if (x > 32767.0) { x = 32767.0; gteFLAG |= (1<<23); } return (x); +} + +double limA3S(double x) { + + if (x <-32768.0) { x =-32768.0; gteFLAG |= (1<<22); } else + if (x > 32767.0) { x = 32767.0; gteFLAG |= (1<<22); } return (x); +} + +double limA1U(double x) { + + if (x < 0.0) { x = 0.0; gteFLAG |= (1<<24); } else + if (x > 32767.0) { x = 32767.0; gteFLAG |= (1<<24); } return (x); +} + +double limA2U(double x) { + + if (x < 0.0) { x = 0.0; gteFLAG |= (1<<23); } else + if (x > 32767.0) { x = 32767.0; gteFLAG |= (1<<23); } return (x); +} + +double limA3U(double x) { + + if (x < 0.0) { x = 0.0; gteFLAG |= (1<<22); } else + if (x > 32767.0) { x = 32767.0; gteFLAG |= (1<<22); } return (x); +} + +double limB1 (double x) { + + if (x < 0.0) { x = 0.0; gteFLAG |= (1<<21); } else + if (x > 255.0) { x = 255.0; gteFLAG |= (1<<21); } return (x); +} + +double limB2 (double x) { + + if (x < 0.0) { x = 0.0; gteFLAG |= (1<<20); } else + if (x > 255.0) { x = 255.0; gteFLAG |= (1<<20); } return (x); +} + +double limB3 (double x) { + + if (x < 0.0) { x = 0.0; gteFLAG |= (1<<19); } else + if (x > 255.0) { x = 255.0; gteFLAG |= (1<<19); } return (x); +} + +double limC (double x) { + + if (x < 0.0) { x = 0.0; gteFLAG |= (1<<18); } else + if (x > 65535.0) { x = 65535.0; gteFLAG |= (1<<18); } return (x); +} + +double limD1 (double x) { + + if (x < 1024.0) { x = 1024.0; gteFLAG |= (1<<14); } else + if (x > 1023.0) { x = 1023.0; gteFLAG |= (1<<14); } return (x); +} + +double limD2 (double x) { + + if (x < 1024.0) { x = 1024.0; gteFLAG |= (1<<13); } else + if (x > 1023.0) { x = 1023.0; gteFLAG |= (1<<13); } return (x); +} + +double limE (double x) { + + if (x < 0.0) { x = 0.0; gteFLAG |= (1<<12); } else + if (x > 4095.0) { x = 4095.0; gteFLAG |= (1<<12); } return (x); +} + +double limG1(double x) { + + if (x > 2147483647.0f) { gteFLAG |= (1<<16); } else + if (x <-2147483648.0f) { gteFLAG |= (1<<15); } + + if (x > 1023.0f) { x = 1023.0f; gteFLAG |= (1<<14); } else + if (x < -1024.0f) { x = -1024.0f; gteFLAG |= (1<<14); } return (x); +} + +double limG2(double x) { + + if (x > 2147483647.0f) { gteFLAG |= (1<<16); } else + if (x <-2147483648.0f) { gteFLAG |= (1<<15); } + + if (x > 1023.0f) { x = 1023.0f; gteFLAG |= (1<<13); } else + if (x < -1024.0f) { x = -1024.0f; gteFLAG |= (1<<13); } return (x); +} + +//********END OF LIMITATIONS**********************************/ + +void gteRTPS() { +// double SSX0,SSY0,SSZ0; +// double SZ; + double DSZ; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif + +#ifdef GTE_LOG + GTE_LOG("GTE_RTPS\n"); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("RTPS", 14); + G_SD(0); + G_SD(1); + + G_SD(16); // Store original fifo + G_SD(17); + G_SD(18); + G_SD(19); + + G_SC(0); + G_SC(1); + G_SC(2); + G_SC(3); + G_SC(4); + G_SC(5); + G_SC(6); + G_SC(7); + + G_SC(24); + G_SC(25); + G_SC(26); + G_SC(27); + G_SC(28); + } +#endif +/* gteFLAG = 0; + + SSX0 = NC_OVERFLOW1((double)gteTRX + ((double)(gteVX0*gteR11) + (double)(gteVY0*gteR12) + (double)(gteVZ0*gteR13))/4096.0); + SSY0 = NC_OVERFLOW2((double)gteTRY + ((double)(gteVX0*gteR21) + (double)(gteVY0*gteR22) + (double)(gteVZ0*gteR23))/4096.0); + SSZ0 = NC_OVERFLOW3((double)gteTRZ + ((double)(gteVX0*gteR31) + (double)(gteVY0*gteR32) + (double)(gteVZ0*gteR33))/4096.0); + + SZ = LIMIT(SSZ0,(double)0,(double)65535,18); + DSZ = ((double)gteH/SZ); + + if ((DSZ>(double)2147483647)) {DSZ=(double)2; gteFLAG|=1<<17;} + + gteSZ0 = gteSZ1; + gteSZ1 = gteSZ2; + gteSZ2 = gteSZx; + gteSZx = (unsigned short)float2int(SZ); + + psxRegs.CP2D.r[12]= psxRegs.CP2D.r[13]; + psxRegs.CP2D.r[13]= psxRegs.CP2D.r[14]; + + gteSX2 = (signed short)float2int(LIMIT((double)(gteOFX)/65536.0f + (LimitAS(SSX0,24)*DSZ),(double)-1024,(double)1024,14)); + gteSY2 = (signed short)float2int(LIMIT((double)(gteOFY)/65536.0f + (LimitAS(SSY0,23)*DSZ),(double)-1024,(double)1024,13)); + + gteMAC1 = (signed long)(SSX0); + gteMAC2 = (signed long)(SSY0); + gteMAC3 = (signed long)(SSZ0); + + MAC2IR(); + + gteMAC0 = (signed long)float2int(OLIMIT((((double)gteDQB/(double)16777216) + (((double)gteDQA/(double)256)*DSZ))*16777216)); + gteIR0 = (signed long)float2int(LIMIT(((((double)gteDQB/(double)16777216) + (((double)gteDQA/(double)256)*DSZ))*4096),(double)0,(double)4095,12)); + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + + gteFLAG = 0; + + gteMAC1 = NC_OVERFLOW1(((signed long)(gteR11*gteVX0 + gteR12*gteVY0 + gteR13*gteVZ0)>>12) + gteTRX); + gteMAC2 = NC_OVERFLOW2(((signed long)(gteR21*gteVX0 + gteR22*gteVY0 + gteR23*gteVZ0)>>12) + gteTRY); + gteMAC3 = NC_OVERFLOW3(((signed long)(gteR31*gteVX0 + gteR32*gteVY0 + gteR33*gteVZ0)>>12) + gteTRZ); + + gteSZx = gteSZ0; + gteSZ0 = gteSZ1; + gteSZ1 = gteSZ2; + gteSZ2 = limC(gteMAC3); + + psxRegs.CP2D.r[12]= psxRegs.CP2D.r[13]; + psxRegs.CP2D.r[13]= psxRegs.CP2D.r[14]; + + DSZ = (double)gteH / gteSZ2; + if (DSZ > 2.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } +// if (DSZ > 2147483647.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } + + gteSX2 = limG1(gteOFX/65536.0 + (limA1S(gteMAC1) * DSZ)); + gteSY2 = limG2(gteOFY/65536.0 + (limA2S(gteMAC2) * DSZ)); + + MAC2IR(); + + gteMAC0 = (gteDQB/16777216.0 + (gteDQA/256.0) * DSZ) * 16777216.0; + gteIR0 = limE((gteDQB/16777216.0 + (gteDQA/256.0) * DSZ) * 4096.0); + + SUM_FLAG; + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(8); + G_GD(9); + G_GD(10); + G_GD(11); + + //G_GD(12); + //G_GD(13); + G_GD(14); + + G_GD(16); + G_GD(17); + G_GD(18); + G_GD(19); + + G_GD(24); + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +void gteRTPT() { +// double SSX0,SSY0,SSZ0; +// double SZ; + double DSZ; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif + +#ifdef GTE_LOG + GTE_LOG("GTE_RTPT\n"); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("RTPT", 22); + G_SD(0); + G_SD(1); + G_SD(2); + G_SD(3); + G_SD(4); + G_SD(5); + + G_SD(16); // Store original fifo + G_SD(17); + G_SD(18); + G_SD(19); + + G_SC(0); + G_SC(1); + G_SC(2); + G_SC(3); + G_SC(4); + G_SC(5); + G_SC(6); + G_SC(7); + + G_SC(24); + G_SC(25); + G_SC(26); + G_SC(27); + G_SC(28); + } +#endif +/* gteFLAG = 0; + + gteSZ0 = gteSZx; + + SSX0 = NC_OVERFLOW1((double)gteTRX + ((double)(gteVX0 * gteR11) + (double)(gteVY0 * gteR12) + (double)(gteVZ0 * gteR13)) / 4096.0); + SSY0 = NC_OVERFLOW2((double)gteTRY + ((double)(gteVX0 * gteR21) + (double)(gteVY0 * gteR22) + (double)(gteVZ0 * gteR23)) / 4096.0); + SSZ0 = NC_OVERFLOW3((double)gteTRZ + ((double)(gteVX0 * gteR31) + (double)(gteVY0 * gteR32) + (double)(gteVZ0 * gteR33)) / 4096.0); + + SZ = LIMIT(SSZ0, (double)0, (double)65535, 18); + DSZ = ((double)gteH / SZ); + + if ((DSZ>(double)2147483647)) {DSZ=(double)2; gteFLAG|=1<<17;} + + gteSZ1 = (unsigned short)float2int(SZ); + gteSX0 = (signed short)float2int(LIMIT((double)(gteOFX)/65536.0f + (LimitAS(SSX0,24)*DSZ),(double)-1024,(double)1023,14)); + gteSY0 = (signed short)float2int(LIMIT((double)(gteOFY)/65536.0f + (LimitAS(SSY0,23)*DSZ),(double)-1024,(double)1023,13)); + + SSX0 = NC_OVERFLOW1((double)gteTRX + ((double)(gteVX1*gteR11) + (double)(gteVY1*gteR12) + (double)(gteVZ1*gteR13))/4096.0); + SSY0 = NC_OVERFLOW2((double)gteTRY + ((double)(gteVX1*gteR21) + (double)(gteVY1*gteR22) + (double)(gteVZ1*gteR23))/4096.0); + SSZ0 = NC_OVERFLOW3((double)gteTRZ + ((double)(gteVX1*gteR31) + (double)(gteVY1*gteR32) + (double)(gteVZ1*gteR33))/4096.0); + + SZ = LIMIT(SSZ0,(double)0,(double)65535,18); + DSZ = ((double)gteH/SZ); + + if ((DSZ>(double)2147483647)) {DSZ=(double)2; gteFLAG|=1<<17;} + + gteSZ2 = (unsigned short)float2int(SZ); + gteSX1 = (signed short)float2int(LIMIT((double)(gteOFX)/65536.0f + (LimitAS(SSX0,24)*DSZ),(double)-1024,(double)1023,14)); + gteSY1 = (signed short)float2int(LIMIT((double)(gteOFY)/65536.0f + (LimitAS(SSY0,23)*DSZ),(double)-1024,(double)1023,13)); + + SSX0 = NC_OVERFLOW1((double)gteTRX + ((double)(gteVX2*gteR11) + (double)(gteVY2*gteR12) + (double)(gteVZ2*gteR13))/4096.0); + SSY0 = NC_OVERFLOW2((double)gteTRY + ((double)(gteVX2*gteR21) + (double)(gteVY2*gteR22) + (double)(gteVZ2*gteR23))/4096.0); + SSZ0 = NC_OVERFLOW3((double)gteTRZ + ((double)(gteVX2*gteR31) + (double)(gteVY2*gteR32) + (double)(gteVZ2*gteR33))/4096.0); + + SZ = LIMIT(SSZ0,(double)0,(double)65535,18); + DSZ = ((double)gteH/SZ); + + if ((DSZ>(double)2147483647)) {DSZ=(double)2; gteFLAG|=1<<17;} + + gteSZx = (unsigned short)float2int(SZ); + gteSX2 = (signed short)float2int(LIMIT((double)(gteOFX)/65536.0f + (LimitAS(SSX0,24)*DSZ),(double)-1024,(double)1023,14)); + gteSY2 = (signed short)float2int(LIMIT((double)(gteOFY)/65536.0f + (LimitAS(SSY0,23)*DSZ),(double)-1024,(double)1023,13)); + + gteMAC1 = (signed long)float2int(SSX0); + gteMAC2 = (signed long)float2int(SSY0); + gteMAC3 = (signed long)float2int(SSZ0); + + MAC2IR(); + + gteMAC0 = (signed long)float2int(OLIMIT((((double)gteDQB/(double)16777216) + (((double)gteDQA/(double)256)*DSZ))*16777216)); + gteIR0 = (signed long)float2int(LIMIT(((((double)gteDQB/(double)16777216) + (((double)gteDQA/(double)256)*DSZ))*4096),(double)0,(double)4095,12)); + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + + /* NC: old + gteFLAG = 0; + + gteSZ0 = gteSZx; + + gteMAC1 = NC_OVERFLOW1(((signed long)(gteR11*gteVX0 + gteR12*gteVY0 + gteR13*gteVZ0)>>12) + gteTRX); + gteMAC2 = NC_OVERFLOW2(((signed long)(gteR21*gteVX0 + gteR22*gteVY0 + gteR23*gteVZ0)>>12) + gteTRY); + gteMAC3 = NC_OVERFLOW3(((signed long)(gteR31*gteVX0 + gteR32*gteVY0 + gteR33*gteVZ0)>>12) + gteTRZ); + + DSZ = gteH / limC(gteMAC3); + if (DSZ > 2147483647.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } + + gteSZ1 = limC(gteMAC3); + + gteSX0 = limG1(gteOFX/65536.0 + (limA1S(gteMAC1) * DSZ)); + gteSY0 = limG2(gteOFY/65536.0 + (limA2S(gteMAC2) * DSZ)); + + gteMAC1 = NC_OVERFLOW1(((signed long)(gteR11*gteVX1 + gteR12*gteVY1 + gteR13*gteVZ1)>>12) + gteTRX); + gteMAC2 = NC_OVERFLOW2(((signed long)(gteR21*gteVX1 + gteR22*gteVY1 + gteR23*gteVZ1)>>12) + gteTRY); + gteMAC3 = NC_OVERFLOW3(((signed long)(gteR31*gteVX1 + gteR32*gteVY1 + gteR33*gteVZ1)>>12) + gteTRZ); + + DSZ = gteH / limC(gteMAC3); + if (DSZ > 2147483647.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } + + gteSZ2 = limC(gteMAC3); + + gteSX1 = limG1(gteOFX/65536.0 + (limA1S(gteMAC1) * DSZ )); + gteSY1 = limG2(gteOFY/65536.0 + (limA2S(gteMAC2) * DSZ )); + + gteMAC1 = NC_OVERFLOW1(((signed long)(gteR11*gteVX2 + gteR12*gteVY2 + gteR13*gteVZ2)>>12) + gteTRX); + gteMAC2 = NC_OVERFLOW2(((signed long)(gteR21*gteVX2 + gteR22*gteVY2 + gteR23*gteVZ2)>>12) + gteTRY); + gteMAC3 = NC_OVERFLOW3(((signed long)(gteR31*gteVX2 + gteR32*gteVY2 + gteR33*gteVZ2)>>12) + gteTRZ); + + DSZ = gteH / limC(gteMAC3); if (DSZ > 2147483647.0f) { DSZ = 2.0f; gteFLAG |= 1<<17; } + + gteSZx = gteSZ2; + + gteSX2 = limG1(gteOFX/65536.0 + (limA1S(gteMAC1) * DSZ )); + gteSY2 = limG2(gteOFY/65536.0 + (limA2S(gteMAC2) * DSZ )); + + MAC2IR(); + + gteMAC0 = (gteDQB/16777216.0 + (gteDQA/256.0) * DSZ ) * 16777216.0; + gteIR0 = limE((gteDQB/16777216.0 + (gteDQA/256.0) * DSZ ) * 4096.0f); + */ + + gteFLAG = 0; + + gteSZx = gteSZ2; + + gteMAC1 = NC_OVERFLOW1(((signed long)(gteR11*gteVX0 + gteR12*gteVY0 + gteR13*gteVZ0)>>12) + gteTRX); + gteMAC2 = NC_OVERFLOW2(((signed long)(gteR21*gteVX0 + gteR22*gteVY0 + gteR23*gteVZ0)>>12) + gteTRY); + gteMAC3 = NC_OVERFLOW3(((signed long)(gteR31*gteVX0 + gteR32*gteVY0 + gteR33*gteVZ0)>>12) + gteTRZ); + + DSZ = gteH / limC(gteMAC3); + if (DSZ > 2.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } +// if (DSZ > 2147483647.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } + + gteSZ0 = limC(gteMAC3); + + gteSX0 = limG1(gteOFX/65536.0 + (limA1S(gteMAC1) * DSZ)); + gteSY0 = limG2(gteOFY/65536.0 + (limA2S(gteMAC2) * DSZ)); + + gteMAC1 = NC_OVERFLOW1(((signed long)(gteR11*gteVX1 + gteR12*gteVY1 + gteR13*gteVZ1)>>12) + gteTRX); + gteMAC2 = NC_OVERFLOW2(((signed long)(gteR21*gteVX1 + gteR22*gteVY1 + gteR23*gteVZ1)>>12) + gteTRY); + gteMAC3 = NC_OVERFLOW3(((signed long)(gteR31*gteVX1 + gteR32*gteVY1 + gteR33*gteVZ1)>>12) + gteTRZ); + + DSZ = gteH / limC(gteMAC3); + if (DSZ > 2.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } +// if (DSZ > 2147483647.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } + + gteSZ1 = limC(gteMAC3); + + gteSX1 = limG1(gteOFX/65536.0 + (limA1S(gteMAC1) * DSZ )); + gteSY1 = limG2(gteOFY/65536.0 + (limA2S(gteMAC2) * DSZ )); + + gteMAC1 = NC_OVERFLOW1(((signed long)(gteR11*gteVX2 + gteR12*gteVY2 + gteR13*gteVZ2)>>12) + gteTRX); + gteMAC2 = NC_OVERFLOW2(((signed long)(gteR21*gteVX2 + gteR22*gteVY2 + gteR23*gteVZ2)>>12) + gteTRY); + gteMAC3 = NC_OVERFLOW3(((signed long)(gteR31*gteVX2 + gteR32*gteVY2 + gteR33*gteVZ2)>>12) + gteTRZ); + + DSZ = gteH / limC(gteMAC3); + if (DSZ > 2.0) { DSZ = 2.0f; gteFLAG |= 1<<17; } +// if (DSZ > 2147483647.0f) { DSZ = 2.0f; gteFLAG |= 1<<17; } + + gteSZ2 = limC(gteMAC3); + + gteSX2 = limG1(gteOFX/65536.0 + (limA1S(gteMAC1) * DSZ )); + gteSY2 = limG2(gteOFY/65536.0 + (limA2S(gteMAC2) * DSZ )); + + MAC2IR(); + + gteMAC0 = (gteDQB/16777216.0 + (gteDQA/256.0) * DSZ ) * 16777216.0; + gteIR0 = limE((gteDQB/16777216.0 + (gteDQA/256.0) * DSZ ) * 4096.0f); + + SUM_FLAG; + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(8); + G_GD(9); + G_GD(10); + G_GD(11); + + G_GD(12); + G_GD(13); + G_GD(14); + + G_GD(16); + G_GD(17); + G_GD(18); + G_GD(19); + + G_GD(24); + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +#define gte_C11 gteLR1 +#define gte_C12 gteLR2 +#define gte_C13 gteLR3 +#define gte_C21 gteLG1 +#define gte_C22 gteLG2 +#define gte_C23 gteLG3 +#define gte_C31 gteLB1 +#define gte_C32 gteLB2 +#define gte_C33 gteLB3 + +#define _MVMVA_FUNC(_v0, _v1, _v2, mx) { \ + SSX = (_v0) * mx##11 + (_v1) * mx##12 + (_v2) * mx##13; \ + SSY = (_v0) * mx##21 + (_v1) * mx##22 + (_v2) * mx##23; \ + SSZ = (_v0) * mx##31 + (_v1) * mx##32 + (_v2) * mx##33; \ +} + +void gteMVMVA() { + double SSX, SSY, SSZ; + +#ifdef GTE_LOG + GTE_LOG("GTE_MVMVA %lx\n", psxRegs.code & 0x1ffffff); +#endif + + switch (psxRegs.code & 0x78000) { + case 0x00000: // V0 * R + _MVMVA_FUNC(gteVX0, gteVY0, gteVZ0, gteR); break; + case 0x08000: // V1 * R + _MVMVA_FUNC(gteVX1, gteVY1, gteVZ1, gteR); break; + case 0x10000: // V2 * R + _MVMVA_FUNC(gteVX2, gteVY2, gteVZ2, gteR); break; + case 0x18000: // IR * R + _MVMVA_FUNC((short)gteIR1, (short)gteIR2, (short)gteIR3, gteR); + break; + case 0x20000: // V0 * L + _MVMVA_FUNC(gteVX0, gteVY0, gteVZ0, gteL); break; + case 0x28000: // V1 * L + _MVMVA_FUNC(gteVX1, gteVY1, gteVZ1, gteL); break; + case 0x30000: // V2 * L + _MVMVA_FUNC(gteVX2, gteVY2, gteVZ2, gteL); break; + case 0x38000: // IR * L + _MVMVA_FUNC((short)gteIR1, (short)gteIR2, (short)gteIR3, gteL); break; + case 0x40000: // V0 * C + _MVMVA_FUNC(gteVX0, gteVY0, gteVZ0, gte_C); break; + case 0x48000: // V1 * C + _MVMVA_FUNC(gteVX1, gteVY1, gteVZ1, gte_C); break; + case 0x50000: // V2 * C + _MVMVA_FUNC(gteVX2, gteVY2, gteVZ2, gte_C); break; + case 0x58000: // IR * C + _MVMVA_FUNC((short)gteIR1, (short)gteIR2, (short)gteIR3, gte_C); break; + default: + SSX = SSY = SSZ = 0; + } + + if (psxRegs.code & 0x80000) { + SSX /= 4096.0; SSY /= 4096.0; SSZ /= 4096.0; + } + + switch (psxRegs.code & 0x6000) { + case 0x0000: // Add TR + SSX+= gteTRX; + SSY+= gteTRY; + SSZ+= gteTRZ; + break; + case 0x2000: // Add BK + SSX+= gteRBK; + SSY+= gteGBK; + SSZ+= gteBBK; + break; + case 0x4000: // Add FC + SSX+= gteRFC; + SSY+= gteGFC; + SSZ+= gteBFC; + break; + } + + gteFLAG = 0; + //gteMAC1 = (long)SSX; + //gteMAC2 = (long)SSY; + //gteMAC3 = (long)SSZ;//okay the follow lines are correct?? + gteMAC1=NC_OVERFLOW1(SSX); + gteMAC2=NC_OVERFLOW2(SSY); + gteMAC3=NC_OVERFLOW3(SSZ); + if (psxRegs.code & 0x400) + MAC2IR1() + else MAC2IR() + + SUM_FLAG; +} + +void gteNCLIP() { +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif + +#ifdef GTE_LOG + GTE_LOG("GTE_NCLIP\n"); +#endif + + //gteLog + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("NCLIP", 8); + G_SD(12); + G_SD(13); + G_SD(14); + } +#endif + +/* gteFLAG = 0; + + gteMAC0 = (signed long)float2int(EDETEC4( + ((double)gteSX0*((double)gteSY1-(double)gteSY2))+ + ((double)gteSX1*((double)gteSY2-(double)gteSY0))+ + ((double)gteSX2*((double)gteSY0-(double)gteSY1)))); + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + gteFLAG = 0; + + + gteMAC0 = gteSX0 * (gteSY1 - gteSY2) + + gteSX1 * (gteSY2 - gteSY0) + + gteSX2 * (gteSY0 - gteSY1); + + //gteMAC0 = (gteSX0 - gteSX1) * (gteSY0 - gteSY2) - (gteSX0 - gteSX2) * (gteSY0 - gteSY1); + + SUM_FLAG; + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(24); + G_GC(31); + } +#endif +} + +void gteAVSZ3() { +// unsigned long SS; +// double SZ1,SZ2,SZ3; +// double ZSF3; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif + +#ifdef GTE_LOG + GTE_LOG("GTE_AVSZ3\n"); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("AVSZ3", 5); + G_SD(16); + G_SD(17); + G_SD(18); + G_SD(19); + G_SC(29); + G_SC(30); + } +#endif + +/* gteFLAG = 0; + + SS = psxRegs.CP2D.r[17] & 0xffff; SZ1 = (double)SS; + SS = psxRegs.CP2D.r[18] & 0xffff; SZ2 = (double)SS; + SS = psxRegs.CP2D.r[19] & 0xffff; SZ3 = (double)SS; + SS = psxRegs.CP2C.r[29] & 0xffff; ZSF3 = (double)SS/(double)4096; + + psxRegs.CP2D.r[24] = (signed long)float2int(EDETEC4(((SZ1+SZ2+SZ3)*ZSF3))); + psxRegs.CP2D.r[7] = (unsigned short)float2int(LimitC(((SZ1+SZ2+SZ3)*ZSF3),18)); + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + + + gteFLAG = 0; + + /* NC: OLD + gteMAC0 = ((gteSZ1 + gteSZ2 + gteSZx) * (gteZSF3/4096.0f)); + + gteOTZ = limC((double)gteMAC0); + */ +/* gteMAC0 = ((gteSZ1 + gteSZ2 + gteSZx) * (gteZSF3)); + + gteOTZ = limC((double)(gteMAC0 >> 12));*/ + gteMAC0 = ((gteSZ0 + gteSZ1 + gteSZ2) * (gteZSF3)) >> 12; + + gteOTZ = limC((double)gteMAC0); + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(7); + G_GD(24); + G_GC(31); + } +#endif +} + +void gteAVSZ4() { +// unsigned long SS; +// double SZ0,SZ1,SZ2,SZ3; +// double ZSF4; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif + +#ifdef GTE_LOG + GTE_LOG("GTE_AVSZ4\n"); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("AVSZ4", 6); + G_SD(16); + G_SD(17); + G_SD(18); + G_SD(19); + G_SC(29); + G_SC(30); + } +#endif + +/* gteFLAG = 0; + + SS = psxRegs.CP2D.r[16] & 0xffff; SZ0 = (double)SS; + SS = psxRegs.CP2D.r[17] & 0xffff; SZ1 = (double)SS; + SS = psxRegs.CP2D.r[18] & 0xffff; SZ2 = (double)SS; + SS = psxRegs.CP2D.r[19] & 0xffff; SZ3 = (double)SS; + SS = psxRegs.CP2C.r[30] & 0xffff; ZSF4 = (double)SS/(double)4096; + + psxRegs.CP2D.r[24] = (signed long)float2int(EDETEC4(((SZ0+SZ1+SZ2+SZ3)*ZSF4))); + psxRegs.CP2D.r[7] = (unsigned short)float2int(LimitC(((SZ0+SZ1+SZ2+SZ3)*ZSF4),18)); + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + gteFLAG = 0; + + /* NC: OLD + gteMAC0 = ((gteSZ0 + gteSZ1 + gteSZ2 + gteSZx) * (gteZSF4/4096.0f)); + + gteOTZ = limC((double)gteMAC0); + */ +/* gteMAC0 = ((gteSZ0 + gteSZ1 + gteSZ2 + gteSZx) * (gteZSF4)); + + gteOTZ = limC((double)(gteMAC0 >> 12)); +*/ + gteMAC0 = ((gteSZx + gteSZ0 + gteSZ1 + gteSZ2) * (gteZSF4))>> 12; + + gteOTZ = limC((double)gteMAC0); + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(7); + G_GD(24); + G_GC(31); + } +#endif +} + +void gteSQR() { + //double SSX0,SSY0,SSZ0; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif + +#ifdef GTE_LOG + GTE_LOG("GTE_SQR %lx\n", psxRegs.code & 0x1ffffff); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("SQR", 5); + G_SD(9); + G_SD(10); + G_SD(11); + } +#endif + +/* gteFLAG = 0; + + SSX0 = (double)gteIR1 * gteIR1; + SSY0 = (double)gteIR2 * gteIR2; + SSZ0 = (double)gteIR3 * gteIR3; + + if (psxRegs.code & 0x80000) { + SSX0 /= 4096.0; SSY0 /= 4096.0; SSZ0 /= 4096.0; + } + + gteMAC1 = (long)SSX0; + gteMAC2 = (long)SSY0; + gteMAC3 = (long)SSZ0; + + MAC2IR1(); + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + gteFLAG = 0; + + if (psxRegs.code & 0x80000) { + + gteMAC1 = NC_OVERFLOW1((gteIR1 * gteIR1) / 4096.0f); + gteMAC2 = NC_OVERFLOW2((gteIR2 * gteIR2) / 4096.0f); + gteMAC3 = NC_OVERFLOW3((gteIR3 * gteIR3) / 4096.0f); + } else { + + gteMAC1 = NC_OVERFLOW1(gteIR1 * gteIR1); + gteMAC2 = NC_OVERFLOW2(gteIR2 * gteIR2); + gteMAC3 = NC_OVERFLOW3(gteIR3 * gteIR3); + } + MAC2IR1(); + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + G_GD(25); + G_GD(26); + G_GD(27); + G_GC(31); + } +#endif +} +/* +#define GTE_NCCS(vn) { \ + RR0 = ((double)gteL11 * gteVX##vn + (double)gteL12 * gteVY##vn + (double)gteL13 * gteVZ##vn)/4096.0; \ + GG0 = ((double)gteL21 * gteVX##vn + (double)gteL22 * gteVY##vn + (double)gteL23 * gteVZ##vn)/4096.0; \ + BB0 = ((double)gteL31 * gteVX##vn + (double)gteL32 * gteVY##vn + (double)gteL33 * gteVZ##vn)/4096.0; \ + t1 = LimitAU(RR0,24); \ + t2 = LimitAU(GG0,23); \ + t3 = LimitAU(BB0,22); \ + \ + RR0 = (double)gteRBK + ((double)gteLR1 * t1 + (double)gteLR2 * t2 + (double)gteLR3 * t3)/4096.0; \ + GG0 = (double)gteGBK + ((double)gteLG1 * t1 + (double)gteLG2 * t2 + (double)gteLG3 * t3)/4096.0; \ + BB0 = (double)gteBBK + ((double)gteLB1 * t1 + (double)gteLB2 * t2 + (double)gteLB3 * t3)/4096.0; \ + t1 = LimitAU(RR0,24); \ + t2 = LimitAU(GG0,23); \ + t3 = LimitAU(BB0,22); \ + \ + RR0 = ((double)gteR * t1)/256.0; \ + GG0 = ((double)gteG * t2)/256.0; \ + BB0 = ((double)gteB * t3)/256.0; \ + \ + gteIR1 = (long)LimitAU(RR0,24); \ + gteIR2 = (long)LimitAU(GG0,23); \ + gteIR3 = (long)LimitAU(BB0,22); \ + \ + gteCODE0 = gteCODE1; gteCODE1 = gteCODE2; gteCODE2 = gteCODE; \ + gteR0 = gteR1; gteR1 = gteR2; gteR2 = (unsigned char)LimitB(RR0/16.0,21); \ + gteG0 = gteG1; gteG1 = gteG2; gteG2 = (unsigned char)LimitB(GG0/16.0,20); \ + gteB0 = gteB1; gteB1 = gteB2; gteB2 = (unsigned char)LimitB(BB0/16.0,19); \ + \ + gteMAC1 = (long)RR0; \ + gteMAC2 = (long)GG0; \ + gteMAC3 = (long)BB0; \ +} +*/ +/* +__forceinline double ncLIM1(double x) +{ + if(x > 8796093022207.0) + { + return 8796093022207.0; + } +} +*/ + + + +/* NC: OLD +#define GTE_NCCS(vn)\ +gte_LL1 = limA1U((gteL11*gteVX##vn + gteL12*gteVY##vn + gteL13*gteVZ##vn)/16777216.0f);\ +gte_LL2 = limA2U((gteL21*gteVX##vn + gteL22*gteVY##vn + gteL23*gteVZ##vn)/16777216.0f);\ +gte_LL3 = limA3U((gteL31*gteVX##vn + gteL32*gteVY##vn + gteL33*gteVZ##vn)/16777216.0f);\ +gte_RRLT= limA1U(gteRBK/4096.0f + (gteLR1/4096.0f*gte_LL1 + gteLR2/4096.0f*gte_LL2 + gteLR3/4096.0f*gte_LL3));\ +gte_GGLT= limA2U(gteGBK/4096.0f + (gteLG1/4096.0f*gte_LL1 + gteLG2/4096.0f*gte_LL2 + gteLG3/4096.0f*gte_LL3));\ +gte_BBLT= limA3U(gteBBK/4096.0f + (gteLB1/4096.0f*gte_LL1 + gteLB2/4096.0f*gte_LL2 + gteLB3/4096.0f*gte_LL3));\ +gte_RR0 = gteR*gte_RRLT;\ +gte_GG0 = gteG*gte_GGLT;\ +gte_BB0 = gteB*gte_BBLT;\ +gteIR1 = (long)limA1U(gte_RR0);\ +gteIR2 = (long)limA2U(gte_GG0);\ +gteIR3 = (long)limA3U(gte_BB0);\ +gteCODE0 = gteCODE1; gteCODE1 = gteCODE2; gteCODE2 = gteCODE;\ +gteR0 = gteR1; gteR1 = gteR2; gteR2 = (unsigned char)limB1(gte_RR0);\ +gteG0 = gteG1; gteG1 = gteG2; gteG2 = (unsigned char)limB2(gte_GG0);\ +gteB0 = gteB1; gteB1 = gteB2; gteB2 = (unsigned char)limB3(gte_BB0);\ +gteMAC1 = (long)gte_RR0;\ +gteMAC2 = (long)gte_GG0;\ +gteMAC3 = (long)gte_BB0;\ +*/ + +#define GTE_NCCS(vn)\ +gte_LL1 = limA1U((gteL11*gteVX##vn + gteL12*gteVY##vn + gteL13*gteVZ##vn)/16777216.0f);\ +gte_LL2 = limA2U((gteL21*gteVX##vn + gteL22*gteVY##vn + gteL23*gteVZ##vn)/16777216.0f);\ +gte_LL3 = limA3U((gteL31*gteVX##vn + gteL32*gteVY##vn + gteL33*gteVZ##vn)/16777216.0f);\ +gte_RRLT= limA1U(gteRBK/4096.0f + (gteLR1/4096.0f*gte_LL1 + gteLR2/4096.0f*gte_LL2 + gteLR3/4096.0f*gte_LL3));\ +gte_GGLT= limA2U(gteGBK/4096.0f + (gteLG1/4096.0f*gte_LL1 + gteLG2/4096.0f*gte_LL2 + gteLG3/4096.0f*gte_LL3));\ +gte_BBLT= limA3U(gteBBK/4096.0f + (gteLB1/4096.0f*gte_LL1 + gteLB2/4096.0f*gte_LL2 + gteLB3/4096.0f*gte_LL3));\ +gteMAC1 = (long)(gteR*gte_RRLT*16);\ +gteMAC2 = (long)(gteG*gte_GGLT*16);\ +gteMAC3 = (long)(gteB*gte_BBLT*16);\ +gteIR1 = (long)limA1U(gteMAC1);\ +gteIR2 = (long)limA2U(gteMAC2);\ +gteIR3 = (long)limA3U(gteMAC3);\ +gte_RR0 = gteMAC1>>4;\ +gte_GG0 = gteMAC2>>4;\ +gte_BB0 = gteMAC3>>4;\ +gteCODE0 = gteCODE1; gteCODE1 = gteCODE2; gteCODE2 = gteCODE;\ +gteR0 = gteR1; gteR1 = gteR2; gteR2 = (unsigned char)limB1(gte_RR0);\ +gteG0 = gteG1; gteG1 = gteG2; gteG2 = (unsigned char)limB2(gte_GG0);\ +gteB0 = gteB1; gteB1 = gteB2; gteB2 = (unsigned char)limB3(gte_BB0);\ + +void gteNCCS() { +// double RR0,GG0,BB0; +// double t1, t2, t3; + + double gte_LL1, gte_RR0, gte_RRLT; + double gte_LL2, gte_GG0, gte_GGLT; + double gte_LL3, gte_BB0, gte_BBLT; + +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif + +#ifdef GTE_LOG + GTE_LOG("GTE_NCCS\n"); +#endif + +/* + gteFLAG = 0; + + GTE_NCCS(0); + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("NCCS", 17); + G_SD(0); + G_SD(1); + G_SD(6); + G_SC(8); + G_SC(9); + G_SC(10); + G_SC(11); + G_SC(12); + G_SC(13); + G_SC(14); + G_SC(15); + G_SC(16); + G_SC(17); + G_SC(18); + G_SC(19); + G_SC(20); + } +#endif + + gteFLAG = 0; + + GTE_NCCS(0); + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + //G_GD(20); + //G_GD(21); + G_GD(22); + + //G_GD(24); Doc must be wrong. PSX does not touch it. + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +void gteNCCT() { +// double RR0,GG0,BB0; +// double t1, t2, t3; + double gte_LL1, gte_RR0, gte_RRLT; + double gte_LL2, gte_GG0, gte_GGLT; + double gte_LL3, gte_BB0, gte_BBLT; + +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif + +#ifdef GTE_LOG + GTE_LOG("GTE_NCCT\n"); +#endif + + + /*gteFLAG = 0; + + GTE_NCCS(0); + GTE_NCCS(1); + GTE_NCCS(2); + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("NCCT", 39); + G_SD(0); + G_SD(1); + G_SD(2); + G_SD(3); + G_SD(4); + G_SD(5); + G_SD(6); + + G_SC(8); + G_SC(9); + G_SC(10); + G_SC(11); + G_SC(12); + G_SC(13); + G_SC(14); + G_SC(15); + G_SC(16); + G_SC(17); + G_SC(18); + G_SC(19); + G_SC(20); + } +#endif + + gteFLAG = 0; + + GTE_NCCS(0); + GTE_NCCS(1); + GTE_NCCS(2); + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + G_GD(20); + G_GD(21); + G_GD(22); + + //G_GD(24); Doc must be wrong. PSX does not touch it. + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +#define GTE_NCDS(vn) \ +gte_LL1 = limA1U((gteL11*gteVX##vn + gteL12*gteVY##vn + gteL13*gteVZ##vn)/16777216.0f);\ +gte_LL2 = limA2U((gteL21*gteVX##vn + gteL22*gteVY##vn + gteL23*gteVZ##vn)/16777216.0f);\ +gte_LL3 = limA3U((gteL31*gteVX##vn + gteL32*gteVY##vn + gteL33*gteVZ##vn)/16777216.0f);\ +gte_RRLT= limA1U(gteRBK/4096.0f + (gteLR1/4096.0f*gte_LL1 + gteLR2/4096.0f*gte_LL2 + gteLR3/4096.0f*gte_LL3));\ +gte_GGLT= limA2U(gteGBK/4096.0f + (gteLG1/4096.0f*gte_LL1 + gteLG2/4096.0f*gte_LL2 + gteLG3/4096.0f*gte_LL3));\ +gte_BBLT= limA3U(gteBBK/4096.0f + (gteLB1/4096.0f*gte_LL1 + gteLB2/4096.0f*gte_LL2 + gteLB3/4096.0f*gte_LL3));\ +gte_RR0 = (gteR*gte_RRLT) + (gteIR0/4096.0f * limA1S(gteRFC/16.0f - (gteR*gte_RRLT)));\ +gte_GG0 = (gteG*gte_GGLT) + (gteIR0/4096.0f * limA2S(gteGFC/16.0f - (gteG*gte_GGLT)));\ +gte_BB0 = (gteB*gte_BBLT) + (gteIR0/4096.0f * limA3S(gteBFC/16.0f - (gteB*gte_BBLT)));\ +gteMAC1= (long)(gte_RR0 * 16.0f); gteIR1 = (long)limA1U(gte_RR0*16.0f);\ +gteMAC2= (long)(gte_GG0 * 16.0f); gteIR2 = (long)limA2U(gte_GG0*16.0f);\ +gteMAC3= (long)(gte_BB0 * 16.0f); gteIR3 = (long)limA3U(gte_BB0*16.0f);\ +gteRGB0 = gteRGB1; \ +gteRGB1 = gteRGB2; \ +gteR2 = limB1(gte_RR0); \ +gteG2 = limB2(gte_GG0); \ +gteB2 = limB3(gte_BB0); gteCODE2 = gteCODE; + +void gteNCDS() { +/* double tRLT,tRRLT; + double tGLT,tGGLT; + double tBLT,tBBLT; + double tRR0,tL1,tLL1; + double tGG0,tL2,tLL2; + double tBB0,tL3,tLL3; + unsigned long C,R,G,B; */ + double gte_LL1, gte_RR0, gte_RRLT; + double gte_LL2, gte_GG0, gte_GGLT; + double gte_LL3, gte_BB0, gte_BBLT; + +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif + +#ifdef GTE_LOG + GTE_LOG("GTE_NCDS\n"); +#endif + +/* gteFLAG = 0; + + R = ((gteRGB)&0xff); + G = ((gteRGB>> 8)&0xff); + B = ((gteRGB>>16)&0xff); + C = ((gteRGB>>24)&0xff); + + tLL1 = (gteL11/4096.0 * gteVX0/4096.0) + (gteL12/4096.0 * gteVY0/4096.0) + (gteL13/4096.0 * gteVZ0/4096.0); + tLL2 = (gteL21/4096.0 * gteVX0/4096.0) + (gteL22/4096.0 * gteVY0/4096.0) + (gteL23/4096.0 * gteVZ0/4096.0); + tLL3 = (gteL31/4096.0 * gteVX0/4096.0) + (gteL32/4096.0 * gteVY0/4096.0) + (gteL33/4096.0 * gteVZ0/4096.0); + + tL1 = LimitAU(tLL1,24); + tL2 = LimitAU(tLL2,23); + tL3 = LimitAU(tLL3,22); + + tRRLT = gteRBK/4096.0 + (gteLR1/4096.0 * tL1) + (gteLR2/4096.0 * tL2) + (gteLR3/4096.0 * tL3); + tGGLT = gteGBK/4096.0 + (gteLG1/4096.0 * tL1) + (gteLG2/4096.0 * tL2) + (gteLG3/4096.0 * tL3); + tBBLT = gteBBK/4096.0 + (gteLB1/4096.0 * tL1) + (gteLB2/4096.0 * tL2) + (gteLB3/4096.0 * tL3); + + tRLT = LimitAU(tRRLT,24); + tGLT = LimitAU(tGGLT,23); + tBLT = LimitAU(tBBLT,22); + + tRR0 = (R * tRLT) + (gteIR0/4096.0 * LimitAS(gteRFC/16.0 - (R * tRLT),24)); + tGG0 = (G * tGLT) + (gteIR0/4096.0 * LimitAS(gteGFC/16.0 - (G * tGLT),23)); + tBB0 = (B * tBLT) + (gteIR0/4096.0 * LimitAS(gteBFC/16.0 - (B * tBLT),22)); + + gteMAC1 = (long)(tRR0 * 16.0); gteIR1 = (long)LimitAU((tRR0*16.0),24); + gteMAC2 = (long)(tGG0 * 16.0); gteIR2 = (long)LimitAU((tGG0*16.0),23); + gteMAC3 = (long)(tBB0 * 16.0); gteIR3 = (long)LimitAU((tBB0*16.0),22); + + R = (unsigned long)LimitB(tRR0,21); if (R>255) R=255; else if (R<0) R=0; + G = (unsigned long)LimitB(tGG0,20); if (G>255) G=255; else if (G<0) G=0; + B = (unsigned long)LimitB(tBB0,19); if (B>255) B=255; else if (B<0) B=0; + + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + gteRGB2 = R|(G<<8)|(B<<16)|(C<<24); + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("NCDS", 19); + G_SD(0); + G_SD(1); + G_SD(6); + G_SD(8); + + G_SC(8); + G_SC(9); + G_SC(10); + G_SC(11); + G_SC(12); + G_SC(13); + G_SC(14); + G_SC(15); + G_SC(16); + G_SC(17); + G_SC(18); + G_SC(19); + G_SC(20); + G_SC(21); + G_SC(22); + G_SC(23); + } +#endif + + gteFLAG = 0; + GTE_NCDS(0); + + SUM_FLAG; + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + //G_GD(20); + //G_GD(21); + G_GD(22); + + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +void gteNCDT() { + /*double tRLT,tRRLT; + double tGLT,tGGLT; + double tBLT,tBBLT; + double tRR0,tL1,tLL1; + double tGG0,tL2,tLL2; + double tBB0,tL3,tLL3; + unsigned long C,R,G,B;*/ + double gte_LL1, gte_RR0, gte_RRLT; + double gte_LL2, gte_GG0, gte_GGLT; + double gte_LL3, gte_BB0, gte_BBLT; + +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif + +#ifdef GTE_LOG + GTE_LOG("GTE_NCDT\n"); +#endif + +/* gteFLAG = 0; + + R = ((gteRGB)&0xff); + G = ((gteRGB>> 8)&0xff); + B = ((gteRGB>>16)&0xff); + C = ((gteRGB>>24)&0xff); + + tLL1 = (gteL11/4096.0 * gteVX0/4096.0) + (gteL12/4096.0 * gteVY0/4096.0) + (gteL13/4096.0 * gteVZ0/4096.0); + tLL2 = (gteL21/4096.0 * gteVX0/4096.0) + (gteL22/4096.0 * gteVY0/4096.0) + (gteL23/4096.0 * gteVZ0/4096.0); + tLL3 = (gteL31/4096.0 * gteVX0/4096.0) + (gteL32/4096.0 * gteVY0/4096.0) + (gteL33/4096.0 * gteVZ0/4096.0); + + tL1 = LimitAU(tLL1,24); + tL2 = LimitAU(tLL2,23); + tL3 = LimitAU(tLL3,22); + + tRRLT = gteRBK/4096.0 + (gteLR1/4096.0 * tL1) + (gteLR2/4096.0 * tL2) + (gteLR3/4096.0 * tL3); + tGGLT = gteGBK/4096.0 + (gteLG1/4096.0 * tL1) + (gteLG2/4096.0 * tL2) + (gteLG3/4096.0 * tL3); + tBBLT = gteBBK/4096.0 + (gteLB1/4096.0 * tL1) + (gteLB2/4096.0 * tL2) + (gteLB3/4096.0 * tL3); + + tRLT = LimitAU(tRRLT,24); + tGLT = LimitAU(tGGLT,23); + tBLT = LimitAU(tBBLT,22); + + tRR0 = (R * tRLT) + (gteIR0/4096.0 * LimitAS(gteRFC/16.0 - (R * tRLT),24)); + tGG0 = (G * tGLT) + (gteIR0/4096.0 * LimitAS(gteGFC/16.0 - (G * tGLT),23)); + tBB0 = (B * tBLT) + (gteIR0/4096.0 * LimitAS(gteBFC/16.0 - (B * tBLT),22)); + + gteMAC1 = (long)(tRR0 * 16.0); gteIR1 = (long)LimitAU((tRR0*16.0),24); + gteMAC2 = (long)(tGG0 * 16.0); gteIR2 = (long)LimitAU((tGG0*16.0),23); + gteMAC3 = (long)(tBB0 * 16.0); gteIR3 = (long)LimitAU((tBB0*16.0),22); + + R = (unsigned long)LimitB(tRR0,21); if (R>255) R=255; else if (R<0) R=0; + G = (unsigned long)LimitB(tGG0,20); if (G>255) G=255; else if (G<0) G=0; + B = (unsigned long)LimitB(tBB0,19); if (B>255) B=255; else if (B<0) B=0; + + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + gteRGB2 = R|(G<<8)|(B<<16)|(C<<24); + + R = ((gteRGB)&0xff); + G = ((gteRGB>> 8)&0xff); + B = ((gteRGB>>16)&0xff); + C = ((gteRGB>>24)&0xff); + + tLL1 = (gteL11/4096.0 * gteVX1/4096.0) + (gteL12/4096.0 * gteVY1/4096.0) + (gteL13/4096.0 * gteVZ1/4096.0); + tLL2 = (gteL21/4096.0 * gteVX1/4096.0) + (gteL22/4096.0 * gteVY1/4096.0) + (gteL23/4096.0 * gteVZ1/4096.0); + tLL3 = (gteL31/4096.0 * gteVX1/4096.0) + (gteL32/4096.0 * gteVY1/4096.0) + (gteL33/4096.0 * gteVZ1/4096.0); + + tL1 = LimitAU(tLL1,24); + tL2 = LimitAU(tLL2,23); + tL3 = LimitAU(tLL3,22); + + tRRLT = gteRBK/4096.0 + (gteLR1/4096.0 * tL1) + (gteLR2/4096.0 * tL2) + (gteLR3/4096.0 * tL3); + tGGLT = gteGBK/4096.0 + (gteLG1/4096.0 * tL1) + (gteLG2/4096.0 * tL2) + (gteLG3/4096.0 * tL3); + tBBLT = gteBBK/4096.0 + (gteLB1/4096.0 * tL1) + (gteLB2/4096.0 * tL2) + (gteLB3/4096.0 * tL3); + + tRLT = LimitAU(tRRLT,24); + tGLT = LimitAU(tGGLT,23); + tBLT = LimitAU(tBBLT,22); + + tRR0 = (R * tRLT) + (gteIR0/4096.0 * LimitAS(gteRFC/16.0 - (R * tRLT),24)); + tGG0 = (G * tGLT) + (gteIR0/4096.0 * LimitAS(gteGFC/16.0 - (G * tGLT),23)); + tBB0 = (B * tBLT) + (gteIR0/4096.0 * LimitAS(gteBFC/16.0 - (B * tBLT),22)); + + gteMAC1 = (long)(tRR0 * 16.0); gteIR1 = (long)LimitAU((tRR0*16.0),24); + gteMAC2 = (long)(tGG0 * 16.0); gteIR2 = (long)LimitAU((tGG0*16.0),23); + gteMAC3 = (long)(tBB0 * 16.0); gteIR3 = (long)LimitAU((tBB0*16.0),22); + + R = (unsigned long)LimitB(tRR0,21); if (R>255) R=255; else if (R<0) R=0; + G = (unsigned long)LimitB(tGG0,20); if (G>255) G=255; else if (G<0) G=0; + B = (unsigned long)LimitB(tBB0,19); if (B>255) B=255; else if (B<0) B=0; + + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + gteRGB2 = R|(G<<8)|(B<<16)|(C<<24); + + R = ((gteRGB)&0xff); + G = ((gteRGB>> 8)&0xff); + B = ((gteRGB>>16)&0xff); + C = ((gteRGB>>24)&0xff); + + tLL1 = (gteL11/4096.0 * gteVX2/4096.0) + (gteL12/4096.0 * gteVY2/4096.0) + (gteL13/4096.0 * gteVZ2/4096.0); + tLL2 = (gteL21/4096.0 * gteVX2/4096.0) + (gteL22/4096.0 * gteVY2/4096.0) + (gteL23/4096.0 * gteVZ2/4096.0); + tLL3 = (gteL31/4096.0 * gteVX2/4096.0) + (gteL32/4096.0 * gteVY2/4096.0) + (gteL33/4096.0 * gteVZ2/4096.0); + + tL1 = LimitAU(tLL1,24); + tL2 = LimitAU(tLL2,23); + tL3 = LimitAU(tLL3,22); + + tRRLT = gteRBK/4096.0 + (gteLR1/4096.0 * tL1) + (gteLR2/4096.0 * tL2) + (gteLR3/4096.0 * tL3); + tGGLT = gteGBK/4096.0 + (gteLG1/4096.0 * tL1) + (gteLG2/4096.0 * tL2) + (gteLG3/4096.0 * tL3); + tBBLT = gteBBK/4096.0 + (gteLB1/4096.0 * tL1) + (gteLB2/4096.0 * tL2) + (gteLB3/4096.0 * tL3); + + tRLT = LimitAU(tRRLT,24); + tGLT = LimitAU(tGGLT,23); + tBLT = LimitAU(tBBLT,22); + + tRR0 = (R * tRLT) + (gteIR0/4096.0 * LimitAS(gteRFC/16.0 - (R * tRLT),24)); + tGG0 = (G * tGLT) + (gteIR0/4096.0 * LimitAS(gteGFC/16.0 - (G * tGLT),23)); + tBB0 = (B * tBLT) + (gteIR0/4096.0 * LimitAS(gteBFC/16.0 - (B * tBLT),22)); + + gteMAC1 = (long)(tRR0 * 16.0); gteIR1 = (long)LimitAU((tRR0*16.0),24); + gteMAC2 = (long)(tGG0 * 16.0); gteIR2 = (long)LimitAU((tGG0*16.0),23); + gteMAC3 = (long)(tBB0 * 16.0); gteIR3 = (long)LimitAU((tBB0*16.0),22); + + R = (unsigned long)LimitB(tRR0,21); if (R>255) R=255; else if (R<0) R=0; + G = (unsigned long)LimitB(tGG0,20); if (G>255) G=255; else if (G<0) G=0; + B = (unsigned long)LimitB(tBB0,19); if (B>255) B=255; else if (B<0) B=0; + + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + gteRGB2 = R|(G<<8)|(B<<16)|(C<<24); + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("NCDT", 44); + G_SD(0); + G_SD(1); + G_SD(2); + G_SD(3); + G_SD(4); + G_SD(5); + G_SD(6); + G_SD(8); + + G_SC(8); + G_SC(9); + G_SC(10); + G_SC(11); + G_SC(12); + G_SC(13); + G_SC(14); + G_SC(15); + G_SC(16); + G_SC(17); + G_SC(18); + G_SC(19); + G_SC(20); + G_SC(21); + G_SC(22); + G_SC(23); + } +#endif + + gteFLAG = 0; + GTE_NCDS(0); + GTE_NCDS(1); + GTE_NCDS(2); + + SUM_FLAG; + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + G_GD(20); + G_GD(21); + G_GD(22); + + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +#define gteD1 (*(short *)>eR11) +#define gteD2 (*(short *)>eR22) +#define gteD3 (*(short *)>eR33) + +void gteOP() { +// double SSX0=0,SSY0=0,SSZ0=0; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif + +#ifdef GTE_LOG + GTE_LOG("GTE_OP %lx\n", psxRegs.code & 0x1ffffff); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("OP", 6); + G_SD(9); + G_SD(10); + G_SD(11); + + G_SC(0); + G_SC(2); + G_SC(4); + } +#endif +/* gteFLAG=0; + + switch (psxRegs.code & 0x1ffffff) { + case 0x178000C://op12 + SSX0 = EDETEC1((gteR22*(short)gteIR3 - gteR33*(short)gteIR2)/(double)4096); + SSY0 = EDETEC2((gteR33*(short)gteIR1 - gteR11*(short)gteIR3)/(double)4096); + SSZ0 = EDETEC3((gteR11*(short)gteIR2 - gteR22*(short)gteIR1)/(double)4096); + break; + case 0x170000C: + SSX0 = EDETEC1((gteR22*(short)gteIR3 - gteR33*(short)gteIR2)); + SSY0 = EDETEC2((gteR33*(short)gteIR1 - gteR11*(short)gteIR3)); + SSZ0 = EDETEC3((gteR11*(short)gteIR2 - gteR22*(short)gteIR1)); + break; + } + + gteMAC1 = (long)float2int(SSX0); + gteMAC2 = (long)float2int(SSY0); + gteMAC3 = (long)float2int(SSZ0); + + MAC2IR(); + + if (gteIR1<0) gteIR1=0; + if (gteIR2<0) gteIR2=0; + if (gteIR3<0) gteIR3=0; + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + gteFLAG = 0; + + if (psxRegs.code & 0x80000) { + + gteMAC1 = NC_OVERFLOW1((gteD2 * gteIR3 - gteD3 * gteIR2) / 4096.0f); + gteMAC2 = NC_OVERFLOW2((gteD3 * gteIR1 - gteD1 * gteIR3) / 4096.0f); + gteMAC3 = NC_OVERFLOW3((gteD1 * gteIR2 - gteD2 * gteIR1) / 4096.0f); + } else { + + gteMAC1 = NC_OVERFLOW1(gteD2 * gteIR3 - gteD3 * gteIR2); + gteMAC2 = NC_OVERFLOW2(gteD3 * gteIR1 - gteD1 * gteIR3); + gteMAC3 = NC_OVERFLOW3(gteD1 * gteIR2 - gteD2 * gteIR1); + } + + /* NC: old + MAC2IR1(); + */ + MAC2IR(); + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +void gteDCPL() { +// unsigned long C,R,G,B; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif +#ifdef GTE_LOG + GTE_LOG("GTE_DCPL\n"); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("DCPL", 8); + G_SD(6); + G_SD(8); + G_SD(9); + G_SD(10); + G_SD(11); + + G_SC(21); + G_SC(22); + G_SC(23); + } +#endif +/* R = ((gteRGB)&0xff); + G = ((gteRGB>> 8)&0xff); + B = ((gteRGB>>16)&0xff); + C = ((gteRGB>>24)&0xff); + + gteMAC1 = (signed long)((double)(R*gteIR1) + (double)(gteIR0*LimitAS(gteRFC-(double)(R*gteIR1),24))/4096.0); + gteMAC2 = (signed long)((double)(G*gteIR2) + (double)(gteIR0*LimitAS(gteGFC-(double)(G*gteIR2),23))/4096.0); + gteMAC3 = (signed long)((double)(B*gteIR3) + (double)(gteIR0*LimitAS(gteBFC-(double)(B*gteIR3),22))/4096.0); + + MAC2IR() + + R = (unsigned long)LimitB(gteMAC1,21); if (R>255) R=255; else if (R<0) R=0; + G = (unsigned long)LimitB(gteMAC2,20); if (G>255) G=255; else if (G<0) G=0; + B = (unsigned long)LimitB(gteMAC3,19); if (B>255) B=255; else if (B<0) B=0; + + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + gteRGB2 = R|(G<<8)|(B<<16)|(C<<24); + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + +/* gteFLAG = 0; + + gteMAC1 = NC_OVERFLOW1((gteR * gteIR1) / 256.0f + (gteIR0 * limA1S(gteRFC - ((gteR * gteIR1) / 256.0f))) / 4096.0f); + gteMAC2 = NC_OVERFLOW2((gteG * gteIR1) / 256.0f + (gteIR0 * limA2S(gteGFC - ((gteG * gteIR1) / 256.0f))) / 4096.0f); + gteMAC3 = NC_OVERFLOW3((gteB * gteIR1) / 256.0f + (gteIR0 * limA3S(gteBFC - ((gteB * gteIR1) / 256.0f))) / 4096.0f); + */ +/* gteMAC1 = ( (signed long)(gteR)*gteIR1 + (gteIR0*(signed short)limA1S(gteRFC - ((gteR*gteIR1)>>12) )) ) >>6; + gteMAC2 = ( (signed long)(gteG)*gteIR2 + (gteIR0*(signed short)limA2S(gteGFC - ((gteG*gteIR2)>>12) )) ) >>6; + gteMAC3 = ( (signed long)(gteB)*gteIR3 + (gteIR0*(signed short)limA3S(gteBFC - ((gteB*gteIR3)>>12) )) ) >>6;*/ + + gteMAC1 = ( (signed long)(gteR)*gteIR1 + (gteIR0*(signed short)limA1S(gteRFC - ((gteR*gteIR1)>>12) )) ) >>8; + gteMAC2 = ( (signed long)(gteG)*gteIR2 + (gteIR0*(signed short)limA2S(gteGFC - ((gteG*gteIR2)>>12) )) ) >>8; + gteMAC3 = ( (signed long)(gteB)*gteIR3 + (gteIR0*(signed short)limA3S(gteBFC - ((gteB*gteIR3)>>12) )) ) >>8; + + gteFLAG=0; + MAC2IR(); + + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + + gteR2 = limB1(gteMAC1 / 16.0f); + gteG2 = limB2(gteMAC2 / 16.0f); + gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + //G_GD(20); + //G_GD(21); + G_GD(22); + + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +void gteGPF() { +// double ipx, ipy, ipz; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif +#ifdef GTE_LOG + GTE_LOG("GTE_GPF %lx\n", psxRegs.code & 0x1ffffff); +#endif +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("GPF", 5); + G_SD(6); + G_SD(8); + G_SD(9); + G_SD(10); + G_SD(11); + } +#endif +/* gteFLAG = 0; + + ipx = (double)((short)gteIR0) * ((short)gteIR1); + ipy = (double)((short)gteIR0) * ((short)gteIR2); + ipz = (double)((short)gteIR0) * ((short)gteIR3); + + // same as mvmva + if (psxRegs.code & 0x80000) { + ipx /= 4096.0; ipy /= 4096.0; ipz /= 4096.0; + } + + gteMAC1 = (long)ipx; + gteMAC2 = (long)ipy; + gteMAC3 = (long)ipz; + + gteIR1 = (long)LimitAS(ipx,24); + gteIR2 = (long)LimitAS(ipy,23); + gteIR3 = (long)LimitAS(ipz,22); + + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + gteC2 = gteCODE; + gteR2 = (unsigned char)LimitB(ipx,21); + gteG2 = (unsigned char)LimitB(ipy,20); + gteB2 = (unsigned char)LimitB(ipz,19);*/ + + gteFLAG = 0; + + if (psxRegs.code & 0x80000) { + gteMAC1 = NC_OVERFLOW1((gteIR0 * gteIR1) / 4096.0f); + gteMAC2 = NC_OVERFLOW2((gteIR0 * gteIR2) / 4096.0f); + gteMAC3 = NC_OVERFLOW3((gteIR0 * gteIR3) / 4096.0f); + } else { + gteMAC1 = NC_OVERFLOW1(gteIR0 * gteIR1); + gteMAC2 = NC_OVERFLOW2(gteIR0 * gteIR2); + gteMAC3 = NC_OVERFLOW3(gteIR0 * gteIR3); + } + MAC2IR(); + + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + + gteR2 = limB1(gteMAC1 / 16.0f); + gteG2 = limB2(gteMAC2 / 16.0f); + gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + //G_GD(20); + //G_GD(21); + G_GD(22); + + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +void gteGPL() { + // double IPX=0,IPY=0,IPZ=0; +// unsigned long C,R,G,B; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif +#ifdef GTE_LOG + GTE_LOG("GTE_GPL %lx\n", psxRegs.code & 0x1ffffff); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("GPL", 5); + G_SD(6); + G_SD(8); + G_SD(9); + G_SD(10); + G_SD(11); + + G_SD(25); + G_SD(26); + G_SD(27); + } +#endif + +/* gteFLAG=0; + switch(psxRegs.code & 0x1ffffff) { + case 0x1A8003E: + IPX = EDETEC1((double)gteMAC1 + ((double)gteIR0*(double)gteIR1)/4096.0f); + IPY = EDETEC2((double)gteMAC2 + ((double)gteIR0*(double)gteIR2)/4096.0f); + IPZ = EDETEC3((double)gteMAC3 + ((double)gteIR0*(double)gteIR3)/4096.0f); + break; + + case 0x1A0003E: + IPX = EDETEC1((double)gteMAC1 + ((double)gteIR0*(double)gteIR1)); + IPY = EDETEC2((double)gteMAC2 + ((double)gteIR0*(double)gteIR2)); + IPZ = EDETEC3((double)gteMAC3 + ((double)gteIR0*(double)gteIR3)); + break; + } + gteIR1 = (short)float2int(LimitAS(IPX,24)); + gteIR2 = (short)float2int(LimitAS(IPY,23)); + gteIR3 = (short)float2int(LimitAS(IPZ,22)); + + gteMAC1 = (int)float2int(IPX); + gteMAC2 = (int)float2int(IPY); + gteMAC3 = (int)float2int(IPZ); + + C = gteRGB & 0xff000000; + R = float2int(ALIMIT(IPX,0,255)); + G = float2int(ALIMIT(IPY,0,255)); + B = float2int(ALIMIT(IPZ,0,255)); + + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + gteRGB2 = C|R|(G<<8)|(B<<16);*/ + gteFLAG = 0; + + if (psxRegs.code & 0x80000) { + + gteMAC1 = NC_OVERFLOW1(gteMAC1 + (gteIR0 * gteIR1) / 4096.0f); + gteMAC2 = NC_OVERFLOW2(gteMAC2 + (gteIR0 * gteIR2) / 4096.0f); + gteMAC3 = NC_OVERFLOW3(gteMAC3 + (gteIR0 * gteIR3) / 4096.0f); + } else { + + gteMAC1 = NC_OVERFLOW1(gteMAC1 + (gteIR0 * gteIR1)); + gteMAC2 = NC_OVERFLOW2(gteMAC2 + (gteIR0 * gteIR2)); + gteMAC3 = NC_OVERFLOW3(gteMAC3 + (gteIR0 * gteIR3)); + } + MAC2IR(); + + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + + gteR2 = limB1(gteMAC1 / 16.0f); + gteG2 = limB2(gteMAC2 / 16.0f); + gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + //G_GD(20); + //G_GD(21); + G_GD(22); + + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +/* +#define GTE_DPCS() { \ + RR0 = (double)R + (gteIR0*LimitAS((double)(gteRFC - R),24))/4096.0; \ + GG0 = (double)G + (gteIR0*LimitAS((double)(gteGFC - G),23))/4096.0; \ + BB0 = (double)B + (gteIR0*LimitAS((double)(gteBFC - B),22))/4096.0; \ + \ + gteIR1 = (long)LimitAS(RR0,24); \ + gteIR2 = (long)LimitAS(GG0,23); \ + gteIR3 = (long)LimitAS(BB0,22); \ + \ + gteRGB0 = gteRGB1; \ + gteRGB1 = gteRGB2; \ + gteC2 = C; \ + gteR2 = (unsigned char)LimitB(RR0/16.0,21); \ + gteG2 = (unsigned char)LimitB(GG0/16.0,20); \ + gteB2 = (unsigned char)LimitB(BB0/16.0,19); \ + \ + gteMAC1 = (long)RR0; \ + gteMAC2 = (long)GG0; \ + gteMAC3 = (long)BB0; \ +} +*/ +void gteDPCS() { +// unsigned long C,R,G,B; +// double RR0,GG0,BB0; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif +#ifdef GTE_LOG + GTE_LOG("GTE_DPCS\n"); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("DPCS", 8); + G_SD(6); + G_SD(8); + + G_SC(21); + G_SC(22); + G_SC(23); + } +#endif + +/* gteFLAG = 0; + + C = gteCODE; + R = gteR * 16.0; + G = gteG * 16.0; + B = gteB * 16.0; + + GTE_DPCS(); + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ +/* gteFLAG = 0; + + gteMAC1 = NC_OVERFLOW1((gteR * 16.0f) + (gteIR0 * limA1S(gteRFC - (gteR * 16.0f))) / 4096.0f); + gteMAC2 = NC_OVERFLOW2((gteG * 16.0f) + (gteIR0 * limA2S(gteGFC - (gteG * 16.0f))) / 4096.0f); + gteMAC3 = NC_OVERFLOW3((gteB * 16.0f) + (gteIR0 * limA3S(gteBFC - (gteB * 16.0f))) / 4096.0f); + */ + gteMAC1 = (gteR<<4) + ( (gteIR0*(signed short)limA1S(gteRFC-(gteR<<4)) ) >>12); + gteMAC2 = (gteG<<4) + ( (gteIR0*(signed short)limA2S(gteGFC-(gteG<<4)) ) >>12); + gteMAC3 = (gteB<<4) + ( (gteIR0*(signed short)limA3S(gteBFC-(gteB<<4)) ) >>12); + + gteFLAG = 0; + MAC2IR(); + + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + + gteR2 = limB1(gteMAC1 / 16.0f); + gteG2 = limB2(gteMAC2 / 16.0f); + gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + //G_GD(20); + //G_GD(21); + G_GD(22); + + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +void gteDPCT() { +// unsigned long C,R,G,B; +// double RR0,GG0,BB0; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif +#ifdef GTE_LOG + GTE_LOG("GTE_DPCT\n"); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("DPCT", 17); + G_SD(8); + + G_SD(20); + G_SD(21); + G_SD(22); + + G_SC(21); + G_SC(22); + G_SC(23); + } +#endif +/* gteFLAG = 0; + + C = gteCODE0; + R = gteR0 * 16.0; + G = gteG0 * 16.0; + B = gteB0 * 16.0; + + GTE_DPCS(); + + C = gteCODE0; + R = gteR0 * 16.0; + G = gteG0 * 16.0; + B = gteB0 * 16.0; + + GTE_DPCS(); + + C = gteCODE0; + R = gteR0 * 16.0; + G = gteG0 * 16.0; + B = gteB0 * 16.0; + + GTE_DPCS(); + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ +/* gteFLAG = 0; + + gteMAC1 = NC_OVERFLOW1((gteR0 * 16.0f) + gteIR0 * limA1S(gteRFC - (gteR0 * 16.0f))); + gteMAC2 = NC_OVERFLOW2((gteG0 * 16.0f) + gteIR0 * limA2S(gteGFC - (gteG0 * 16.0f))); + gteMAC3 = NC_OVERFLOW3((gteB0 * 16.0f) + gteIR0 * limA3S(gteBFC - (gteB0 * 16.0f))); + */ + gteMAC1 = (gteR0<<4) + ( (gteIR0*(signed short)limA1S(gteRFC-(gteR0<<4)) ) >>12); + gteMAC2 = (gteG0<<4) + ( (gteIR0*(signed short)limA2S(gteGFC-(gteG0<<4)) ) >>12); + gteMAC3 = (gteB0<<4) + ( (gteIR0*(signed short)limA3S(gteBFC-(gteB0<<4)) ) >>12); +// MAC2IR(); + + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + + gteR2 = limB1(gteMAC1 / 16.0f); + gteG2 = limB2(gteMAC2 / 16.0f); + gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; + + gteMAC1 = (gteR0<<4) + ( (gteIR0*(signed short)limA1S(gteRFC-(gteR0<<4)) ) >>12); + gteMAC2 = (gteG0<<4) + ( (gteIR0*(signed short)limA2S(gteGFC-(gteG0<<4)) ) >>12); + gteMAC3 = (gteB0<<4) + ( (gteIR0*(signed short)limA3S(gteBFC-(gteB0<<4)) ) >>12); +// MAC2IR(); + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + + gteR2 = limB1(gteMAC1 / 16.0f); + gteG2 = limB2(gteMAC2 / 16.0f); + gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; + + gteMAC1 = (gteR0<<4) + ( (gteIR0*(signed short)limA1S(gteRFC-(gteR0<<4)) ) >>12); + gteMAC2 = (gteG0<<4) + ( (gteIR0*(signed short)limA2S(gteGFC-(gteG0<<4)) ) >>12); + gteMAC3 = (gteB0<<4) + ( (gteIR0*(signed short)limA3S(gteBFC-(gteB0<<4)) ) >>12); + gteFLAG = 0; + MAC2IR(); + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + + gteR2 = limB1(gteMAC1 / 16.0f); + gteG2 = limB2(gteMAC2 / 16.0f); + gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + G_GD(20); + G_GD(21); + G_GD(22); + + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +/* +#define GTE_NCS(vn) { \ + RR0 = ((double)gteVX##vn * gteL11 + (double)gteVY##vn * (double)gteL12 + (double)gteVZ##vn * gteL13) / 4096.0; \ + GG0 = ((double)gteVX##vn * gteL21 + (double)gteVY##vn * (double)gteL22 + (double)gteVZ##vn * gteL23) / 4096.0; \ + BB0 = ((double)gteVX##vn * gteL31 + (double)gteVY##vn * (double)gteL32 + (double)gteVZ##vn * gteL33) / 4096.0; \ + t1 = LimitAU(RR0, 24); \ + t2 = LimitAU(GG0, 23); \ + t3 = LimitAU(BB0, 22); \ + \ + RR0 = (double)gteRBK + ((double)gteLR1 * t1 + (double)gteLR2 * t2 + (double)gteLR3 * t3) / 4096.0; \ + GG0 = (double)gteGBK + ((double)gteLG1 * t1 + (double)gteLG2 * t2 + (double)gteLG3 * t3) / 4096.0; \ + BB0 = (double)gteBBK + ((double)gteLB1 * t1 + (double)gteLB2 * t2 + (double)gteLB3 * t3) / 4096.0; \ + t1 = LimitAU(RR0, 24); \ + t2 = LimitAU(GG0, 23); \ + t3 = LimitAU(BB0, 22); \ + \ + gteRGB0 = gteRGB1; gteRGB1 = gteRGB2; \ + gteR2 = (unsigned char)LimitB(RR0/16.0, 21); \ + gteG2 = (unsigned char)LimitB(GG0/16.0, 20); \ + gteB2 = (unsigned char)LimitB(BB0/16.0, 19); \ + gteCODE2=gteCODE0; \ +}*/ + +#define LOW(a) (((a) < 0) ? 0 : (a)) + +#define GTE_NCS(vn) \ +RR0 = LOW((gteL11*gteVX##vn + gteL12*gteVY##vn + gteL13*gteVZ##vn)/4096.0f); \ +GG0 = LOW((gteL21*gteVX##vn + gteL22*gteVY##vn + gteL23*gteVZ##vn)/4096.0f); \ +BB0 = LOW((gteL31*gteVX##vn + gteL32*gteVY##vn + gteL33*gteVZ##vn)/4096.0f); \ +gteMAC1 = gteRBK + (gteLR1*RR0 + gteLR2*GG0 + gteLR3*BB0)/4096.0f; \ +gteMAC2 = gteGBK + (gteLG1*RR0 + gteLG2*GG0 + gteLG3*BB0)/4096.0f; \ +gteMAC3 = gteBBK + (gteLB1*RR0 + gteLB2*GG0 + gteLB3*BB0)/4096.0f; \ +gteRGB0 = gteRGB1; \ +gteRGB1 = gteRGB2; \ +gteR2 = limB1(gteMAC1 / 16.0f); \ +gteG2 = limB2(gteMAC2 / 16.0f); \ +gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; + +void gteNCS() { + double RR0,GG0,BB0; +// double t1, t2, t3; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif +#ifdef GTE_LOG + GTE_LOG("GTE_NCS\n"); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("NCS", 14); + G_SD(0); + G_SD(1); + G_SD(6); + + G_SC(8); + G_SC(9); + G_SC(10); + G_SC(11); + G_SC(12); + G_SC(13); + G_SC(14); + G_SC(15); + G_SC(16); + G_SC(17); + G_SC(18); + G_SC(19); + G_SC(20); + } +#endif +/* gteFLAG = 0; + + GTE_NCS(0); + + gteMAC1=(long)RR0; + gteMAC2=(long)GG0; + gteMAC3=(long)BB0; + + gteIR1=(long)t1; + gteIR2=(long)t2; + gteIR3=(long)t3; + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + gteFLAG = 0; + + GTE_NCS(0); + + MAC2IR1(); + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + //G_GD(20); + //G_GD(21); + G_GD(22); + + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +void gteNCT() { + double RR0,GG0,BB0; +// double t1, t2, t3; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif +#ifdef GTE_LOG + GTE_LOG("GTE_NCT\n"); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("NCT", 30); + G_SD(0); + G_SD(1); + G_SD(2); + G_SD(3); + G_SD(4); + G_SD(5); + G_SD(6); + + G_SC(8); + G_SC(9); + G_SC(10); + G_SC(11); + G_SC(12); + G_SC(13); + G_SC(14); + G_SC(15); + G_SC(16); + G_SC(17); + G_SC(18); + G_SC(19); + G_SC(20); + } +#endif +/* + gteFLAG = 0; + +//V0 + GTE_NCS(0); +//V1 + GTE_NCS(1); +//V2 + GTE_NCS(2); + + gteMAC1=(long)RR0; + gteMAC2=(long)GG0; + gteMAC3=(long)BB0; + + gteIR1=(long)t1; + gteIR2=(long)t2; + gteIR3=(long)t3; + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + gteFLAG = 0; + + GTE_NCS(0); + GTE_NCS(1); + GTE_NCS(2); + + MAC2IR1(); + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + G_GD(20); + G_GD(21); + G_GD(22); + + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +void gteCC() { + double RR0,GG0,BB0; +// double t1,t2,t3; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif +#ifdef GTE_LOG + GTE_LOG("GTE_CC\n"); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("CC", 11); + G_SD(6); + G_SD(9); + G_SD(10); + G_SD(11); + + G_SC(13); + G_SC(14); + G_SC(15); + G_SC(16); + G_SC(17); + G_SC(18); + G_SC(19); + } +#endif +/* gteFLAG = 0; + + RR0 = (double)gteRBK + ((double)gteLR1 * gteIR1 + (double)gteLR2 * gteIR2 + (double)gteLR3 * gteIR3) / 4096.0; + GG0 = (double)gteGBK + ((double)gteLG1 * gteIR1 + (double)gteLG2 * gteIR2 + (double)gteLG3 * gteIR3) / 4096.0; + BB0 = (double)gteBBK + ((double)gteLB1 * gteIR1 + (double)gteLB2 * gteIR2 + (double)gteLB3 * gteIR3) / 4096.0; + t1 = LimitAU(RR0, 24); + t2 = LimitAU(GG0, 23); + t3 = LimitAU(BB0, 22); + + RR0=((double)gteR * t1)/256.0; + GG0=((double)gteG * t2)/256.0; + BB0=((double)gteB * t3)/256.0; + gteIR1 = (long)LimitAU(RR0,24); + gteIR2 = (long)LimitAU(GG0,23); + gteIR3 = (long)LimitAU(BB0,22); + + gteCODE0=gteCODE1; gteCODE1=gteCODE2; + gteC2 = gteCODE0; + gteR2 = (unsigned char)LimitB(RR0/16.0, 21); + gteG2 = (unsigned char)LimitB(GG0/16.0, 20); + gteB2 = (unsigned char)LimitB(BB0/16.0, 19); + + if (gteFLAG & 0x7f87e000) gteFLAG|=0x80000000;*/ + gteFLAG = 0; + + RR0 = NC_OVERFLOW1(gteRBK + (gteLR1*gteIR1 + gteLR2*gteIR2 + gteLR3*gteIR3) / 4096.0f); + GG0 = NC_OVERFLOW2(gteGBK + (gteLG1*gteIR1 + gteLG2*gteIR2 + gteLG3*gteIR3) / 4096.0f); + BB0 = NC_OVERFLOW3(gteBBK + (gteLB1*gteIR1 + gteLB2*gteIR2 + gteLB3*gteIR3) / 4096.0f); + + gteMAC1 = gteR * RR0 / 256.0f; + gteMAC2 = gteG * GG0 / 256.0f; + gteMAC3 = gteB * BB0 / 256.0f; + + MAC2IR1(); + + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + + gteR2 = limB1(gteMAC1 / 16.0f); + gteG2 = limB2(gteMAC2 / 16.0f); + gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + //G_GD(20); + //G_GD(21); + G_GD(22); + + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +void gteINTPL() { //test opcode +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif +#ifdef GTE_LOG + GTE_LOG("GTE_INTP\n"); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("INTPL", 8); + G_SD(6); + G_SD(8); + G_SD(9); + G_SD(10); + G_SD(11); + + G_SC(21); + G_SC(22); + G_SC(23); + } +#endif + /* NC: old + gteFLAG=0; + gteMAC1 = gteIR1 + gteIR0*limA1S(gteRFC-gteIR1); + gteMAC2 = gteIR2 + gteIR0*limA2S(gteGFC-gteIR2); + gteMAC3 = gteIR3 + gteIR0*limA3S(gteBFC-gteIR3); + //gteFLAG = 0; + MAC2IR(); + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + + gteR2 = limB1(gteMAC1 / 16.0f); + gteG2 = limB2(gteMAC2 / 16.0f); + gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; + */ + +/* gteFLAG=0; + gteMAC1 = gteIR1 + gteIR0*(gteRFC-gteIR1)/4096.0; + gteMAC2 = gteIR2 + gteIR0*(gteGFC-gteIR2)/4096.0; + gteMAC3 = gteIR3 + gteIR0*(gteBFC-gteIR3)/4096.0; + + //gteMAC3 = (int)((((psxRegs).CP2D).n).ir3+(((psxRegs).CP2D).n).ir0 * ((((psxRegs).CP2C).n).bfc-(((psxRegs).CP2D).n).ir3)/4096.0); + + if(gteMAC3 > gteIR1 && gteMAC3 > gteBFC) + { + gteMAC3 = gteMAC3; + } + //gteFLAG = 0;*/ + //NEW CODE + gteMAC1 = gteIR1 + ((gteIR0*(signed short)limA1S(gteRFC-gteIR1))>>12); + gteMAC2 = gteIR2 + ((gteIR0*(signed short)limA2S(gteGFC-gteIR2))>>12); + gteMAC3 = gteIR3 + ((gteIR0*(signed short)limA3S(gteBFC-gteIR3))>>12); + gteFLAG = 0; + + MAC2IR(); + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + + gteR2 = limB1(gteMAC1 / 16.0f); + gteG2 = limB2(gteMAC2 / 16.0f); + gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + //G_GD(20); + //G_GD(21); + G_GD(22); + + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} + +void gteCDP() { //test opcode + double RR0,GG0,BB0; +#ifdef GTE_DUMP + static int sample = 0; sample++; +#endif +#ifdef GTE_LOG + GTE_LOG("GTE_CDP\n"); +#endif + +#ifdef GTE_DUMP + if(sample < 100) + { + G_OP("CDP", 13); + G_SD(6); + G_SD(8); + G_SD(9); + G_SD(10); + G_SD(11); + + G_SC(13); + G_SC(14); + G_SC(15); + G_SC(16); + G_SC(17); + G_SC(18); + G_SC(19); + G_SC(20); + G_SC(21); + G_SC(22); + G_SC(23); + } +#endif + + gteFLAG = 0; + + RR0 = NC_OVERFLOW1(gteRBK + (gteLR1*gteIR1 +gteLR2*gteIR2 + gteLR3*gteIR3)); + GG0 = NC_OVERFLOW2(gteGBK + (gteLG1*gteIR1 +gteLG2*gteIR2 + gteLG3*gteIR3)); + BB0 = NC_OVERFLOW3(gteBBK + (gteLB1*gteIR1 +gteLB2*gteIR2 + gteLB3*gteIR3)); + gteMAC1 = gteR*RR0 + gteIR0*limA1S(gteRFC-gteR*RR0); + gteMAC2 = gteG*GG0 + gteIR0*limA2S(gteGFC-gteG*GG0); + gteMAC3 = gteB*BB0 + gteIR0*limA3S(gteBFC-gteB*BB0); + MAC2IR1(); + gteRGB0 = gteRGB1; + gteRGB1 = gteRGB2; + + gteR2 = limB1(gteMAC1 / 16.0f); + gteG2 = limB2(gteMAC2 / 16.0f); + gteB2 = limB3(gteMAC3 / 16.0f); gteCODE2 = gteCODE; + + SUM_FLAG + +#ifdef GTE_DUMP + if(sample < 100) + { + G_GD(9); + G_GD(10); + G_GD(11); + + //G_GD(20); + //G_GD(21); + G_GD(22); + + G_GD(25); + G_GD(26); + G_GD(27); + + G_GC(31); + } +#endif +} diff --git a/PcsxSrc/Gte.h b/PcsxSrc/Gte.h index 146dbd0..22f02e0 100644 --- a/PcsxSrc/Gte.h +++ b/PcsxSrc/Gte.h @@ -1,52 +1,52 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __GTE_H__ -#define __GTE_H__ - -void gteMFC2(); -void gteCFC2(); -void gteMTC2(); -void gteCTC2(); -void gteLWC2(); -void gteSWC2(); - -void gteRTPS(); -void gteOP(); -void gteNCLIP(); -void gteDPCS(); -void gteINTPL(); -void gteMVMVA(); -void gteNCDS(); -void gteNCDT(); -void gteCDP(); -void gteNCCS(); -void gteCC(); -void gteNCS(); -void gteNCT(); -void gteSQR(); -void gteDCPL(); -void gteDPCT(); -void gteAVSZ3(); -void gteAVSZ4(); -void gteRTPT(); -void gteGPF(); -void gteGPL(); -void gteNCCT(); - -#endif /* __GTE_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __GTE_H__ +#define __GTE_H__ + +void gteMFC2(); +void gteCFC2(); +void gteMTC2(); +void gteCTC2(); +void gteLWC2(); +void gteSWC2(); + +void gteRTPS(); +void gteOP(); +void gteNCLIP(); +void gteDPCS(); +void gteINTPL(); +void gteMVMVA(); +void gteNCDS(); +void gteNCDT(); +void gteCDP(); +void gteNCCS(); +void gteCC(); +void gteNCS(); +void gteNCT(); +void gteSQR(); +void gteDCPL(); +void gteDPCT(); +void gteAVSZ3(); +void gteAVSZ4(); +void gteRTPT(); +void gteGPF(); +void gteGPL(); +void gteNCCT(); + +#endif /* __GTE_H__ */ diff --git a/PcsxSrc/Linux/Config.c b/PcsxSrc/Linux/Config.c index ef526db..feecefa 100644 --- a/PcsxSrc/Linux/Config.c +++ b/PcsxSrc/Linux/Config.c @@ -1,127 +1,127 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include -#include -#include - -#include "Linux.h" - -#define GetValue(name, var) \ - tmp = strstr(data, name); \ - if (tmp != NULL) { \ - tmp+=strlen(name); \ - while ((*tmp == ' ') || (*tmp == '=')) tmp++; \ - if (*tmp != '\n') sscanf(tmp, "%s", var); \ - } - -#define GetValuel(name, var) \ - tmp = strstr(data, name); \ - if (tmp != NULL) { \ - tmp+=strlen(name); \ - while ((*tmp == ' ') || (*tmp == '=')) tmp++; \ - if (*tmp != '\n') sscanf(tmp, "%lx", &var); \ - } - -#define SetValue(name, var) \ - fprintf (f,"%s = %s\n", name, var); - -#define SetValuel(name, var) \ - fprintf (f,"%s = %lx\n", name, var); - -int LoadConfig(PcsxConfig *Conf) { - struct stat buf; - FILE *f; - int size; - char *data,*tmp; - - if (stat(cfgfile, &buf) == -1) return -1; - size = buf.st_size; - - f = fopen(cfgfile,"r"); - if (f == NULL) return -1; - - data = (char*)malloc(size); - if (data == NULL) return -1; - - fread(data, 1, size, f); - fclose(f); - - GetValue("Bios", Config.Bios); - GetValue("Gpu", Config.Gpu); - GetValue("Spu", Config.Spu); - GetValue("Cdr", Config.Cdr); - GetValue("Pad1", Config.Pad1); - GetValue("Pad2", Config.Pad2); - GetValue("Mcd1", Config.Mcd1); - GetValue("Mcd2", Config.Mcd2); - GetValue("PluginsDir", Config.PluginsDir); - GetValue("BiosDir", Config.BiosDir); - GetValuel("Xa", Config.Xa); - GetValuel("Sio", Config.Sio); - GetValuel("Mdec", Config.Mdec); - GetValuel("PsxAuto", Config.PsxAuto); - GetValuel("PsxType", Config.PsxType); - GetValuel("Cdda", Config.Cdda); - GetValuel("Cpu", Config.Cpu); - GetValuel("Log", Config.Log); - GetValuel("PsxOut", Config.PsxOut); - GetValuel("SpuIrq", Config.SpuIrq); - GetValuel("CdTiming",Config.CdTiming); - - free(data); - - return 0; -} - -///////////////////////////////////////////////////////// - -void SaveConfig() { - FILE *f; - - f = fopen(cfgfile,"w"); - if (f == NULL) return; - - SetValue("Bios", Config.Bios); - SetValue("Gpu", Config.Gpu); - SetValue("Spu", Config.Spu); - SetValue("Cdr", Config.Cdr); - SetValue("Pad1", Config.Pad1); - SetValue("Pad2", Config.Pad2); - SetValue("Mcd1", Config.Mcd1); - SetValue("Mcd2", Config.Mcd2); - SetValue("PluginsDir", Config.PluginsDir); - SetValue("BiosDir", Config.BiosDir); - SetValuel("Xa", Config.Xa); - SetValuel("Sio", Config.Sio); - SetValuel("Mdec", Config.Mdec); - SetValuel("PsxAuto", Config.PsxAuto); - SetValuel("PsxType", Config.PsxType); - SetValuel("Cdda", Config.Cdda); - SetValuel("Cpu", Config.Cpu); - SetValuel("Log", Config.Log); - SetValuel("PsxOut", Config.PsxOut); - SetValuel("SpuIrq", Config.SpuIrq); - SetValuel("CdTiming",Config.CdTiming); - - fclose(f); - - return; -} +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include +#include +#include + +#include "Linux.h" + +#define GetValue(name, var) \ + tmp = strstr(data, name); \ + if (tmp != NULL) { \ + tmp+=strlen(name); \ + while ((*tmp == ' ') || (*tmp == '=')) tmp++; \ + if (*tmp != '\n') sscanf(tmp, "%s", var); \ + } + +#define GetValuel(name, var) \ + tmp = strstr(data, name); \ + if (tmp != NULL) { \ + tmp+=strlen(name); \ + while ((*tmp == ' ') || (*tmp == '=')) tmp++; \ + if (*tmp != '\n') sscanf(tmp, "%lx", &var); \ + } + +#define SetValue(name, var) \ + fprintf (f,"%s = %s\n", name, var); + +#define SetValuel(name, var) \ + fprintf (f,"%s = %lx\n", name, var); + +int LoadConfig(PcsxConfig *Conf) { + struct stat buf; + FILE *f; + int size; + char *data,*tmp; + + if (stat(cfgfile, &buf) == -1) return -1; + size = buf.st_size; + + f = fopen(cfgfile,"r"); + if (f == NULL) return -1; + + data = (char*)malloc(size); + if (data == NULL) return -1; + + fread(data, 1, size, f); + fclose(f); + + GetValue("Bios", Config.Bios); + GetValue("Gpu", Config.Gpu); + GetValue("Spu", Config.Spu); + GetValue("Cdr", Config.Cdr); + GetValue("Pad1", Config.Pad1); + GetValue("Pad2", Config.Pad2); + GetValue("Mcd1", Config.Mcd1); + GetValue("Mcd2", Config.Mcd2); + GetValue("PluginsDir", Config.PluginsDir); + GetValue("BiosDir", Config.BiosDir); + GetValuel("Xa", Config.Xa); + GetValuel("Sio", Config.Sio); + GetValuel("Mdec", Config.Mdec); + GetValuel("PsxAuto", Config.PsxAuto); + GetValuel("PsxType", Config.PsxType); + GetValuel("Cdda", Config.Cdda); + GetValuel("Cpu", Config.Cpu); + GetValuel("Log", Config.Log); + GetValuel("PsxOut", Config.PsxOut); + GetValuel("SpuIrq", Config.SpuIrq); + GetValuel("CdTiming",Config.CdTiming); + + free(data); + + return 0; +} + +///////////////////////////////////////////////////////// + +void SaveConfig() { + FILE *f; + + f = fopen(cfgfile,"w"); + if (f == NULL) return; + + SetValue("Bios", Config.Bios); + SetValue("Gpu", Config.Gpu); + SetValue("Spu", Config.Spu); + SetValue("Cdr", Config.Cdr); + SetValue("Pad1", Config.Pad1); + SetValue("Pad2", Config.Pad2); + SetValue("Mcd1", Config.Mcd1); + SetValue("Mcd2", Config.Mcd2); + SetValue("PluginsDir", Config.PluginsDir); + SetValue("BiosDir", Config.BiosDir); + SetValuel("Xa", Config.Xa); + SetValuel("Sio", Config.Sio); + SetValuel("Mdec", Config.Mdec); + SetValuel("PsxAuto", Config.PsxAuto); + SetValuel("PsxType", Config.PsxType); + SetValuel("Cdda", Config.Cdda); + SetValuel("Cpu", Config.Cpu); + SetValuel("Log", Config.Log); + SetValuel("PsxOut", Config.PsxOut); + SetValuel("SpuIrq", Config.SpuIrq); + SetValuel("CdTiming",Config.CdTiming); + + fclose(f); + + return; +} diff --git a/PcsxSrc/Linux/GladeCalls.c b/PcsxSrc/Linux/GladeCalls.c index 938a8e3..2db68be 100644 --- a/PcsxSrc/Linux/GladeCalls.c +++ b/PcsxSrc/Linux/GladeCalls.c @@ -1,511 +1,511 @@ -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include "GladeCalls.h" -#include "GladeGui.h" -#include "GladeFuncs.h" - - -void -OnDestroy (GtkObject *object, - gpointer user_data) -{ - -} - - -void -OnFile_RunCd (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnFile_RunCdBios (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnFile_RunExe (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnFile_Exit (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnEmu_Run (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnEmu_Reset (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnConf_Conf (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnConf_Gpu (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnConf_Spu (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnConf_Cdr (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnConf_Pads (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnConf_Cpu (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnConf_Mcds (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnHelp_About (GtkMenuItem *menuitem, - gpointer user_data) -{ - -} - - -void -OnHelpAbout_Ok (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_CdrConf (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_CdrTest (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_CdrAbout (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_Pad2Conf (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_Pad2Test (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_Pad2About (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_Pad1Conf (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_Pad1Test (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_Pad1About (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_GpuConf (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_GpuTest (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_GpuAbout (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_SpuConf (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_SpuTest (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_SpuAbout (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_PluginsPath (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_BiosPath (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_Ok (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnConfConf_Cancel (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnCpu_Ok (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnCpu_Cancel (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnMcd_FS1 (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnMcd_Format1 (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnMcd_Reload1 (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnMcd_FS2 (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnMcd_Format2 (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnMcd_Reload2 (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnMcd_Ok (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnMcd_Cancel (GtkButton *button, - gpointer user_data) -{ - -} - - -gboolean -OnList1_KeyPress (GtkWidget *widget, - GdkEventKey *event, - gpointer user_data) -{ - - return FALSE; -} - - -gboolean -OnList2_KeyPress (GtkWidget *widget, - GdkEventKey *event, - gpointer user_data) -{ - - return FALSE; -} - - -void -OnMcd_Copy (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnMcd_Paste (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnMcd_Delete (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnMcd_CopyTo2 (GtkButton *button, - gpointer user_data) -{ - -} - - -void -OnMcd_CopyTo1 (GtkButton *button, - gpointer user_data) -{ - -} - - -GtkDirectionType -OnList1_Focus (GtkContainer *container, - GtkDirectionType direction, - gpointer user_data) -{ - -} - - -void -OnList1_SelectRow (GtkCList *clist, - gint row, - gint column, - GdkEvent *event, - gpointer user_data) -{ - -} - - -void -OnList2_SelectRow (GtkCList *clist, - gint row, - gint column, - GdkEvent *event, - gpointer user_data) -{ - -} - - -void -OnMcd_Delete2 (GtkButton *button, - gpointer user_data) -{ - -} - - -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) -{ - -} - - -gboolean -OnConfConf_Cancel (GtkWidget *widget, - GdkEvent *event, - gpointer user_data) -{ - - return FALSE; -} - +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "GladeCalls.h" +#include "GladeGui.h" +#include "GladeFuncs.h" + + +void +OnDestroy (GtkObject *object, + gpointer user_data) +{ + +} + + +void +OnFile_RunCd (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +OnFile_RunCdBios (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +OnFile_RunExe (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +OnFile_Exit (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +OnEmu_Run (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +OnEmu_Reset (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +OnConf_Conf (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +OnConf_Gpu (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +OnConf_Spu (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +OnConf_Cdr (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +OnConf_Pads (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +OnConf_Cpu (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +OnConf_Mcds (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +OnHelp_About (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +OnHelpAbout_Ok (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_CdrConf (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_CdrTest (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_CdrAbout (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_Pad2Conf (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_Pad2Test (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_Pad2About (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_Pad1Conf (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_Pad1Test (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_Pad1About (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_GpuConf (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_GpuTest (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_GpuAbout (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_SpuConf (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_SpuTest (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_SpuAbout (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_PluginsPath (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_BiosPath (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_Ok (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnConfConf_Cancel (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnCpu_Ok (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnCpu_Cancel (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnMcd_FS1 (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnMcd_Format1 (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnMcd_Reload1 (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnMcd_FS2 (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnMcd_Format2 (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnMcd_Reload2 (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnMcd_Ok (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnMcd_Cancel (GtkButton *button, + gpointer user_data) +{ + +} + + +gboolean +OnList1_KeyPress (GtkWidget *widget, + GdkEventKey *event, + gpointer user_data) +{ + + return FALSE; +} + + +gboolean +OnList2_KeyPress (GtkWidget *widget, + GdkEventKey *event, + gpointer user_data) +{ + + return FALSE; +} + + +void +OnMcd_Copy (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnMcd_Paste (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnMcd_Delete (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnMcd_CopyTo2 (GtkButton *button, + gpointer user_data) +{ + +} + + +void +OnMcd_CopyTo1 (GtkButton *button, + gpointer user_data) +{ + +} + + +GtkDirectionType +OnList1_Focus (GtkContainer *container, + GtkDirectionType direction, + gpointer user_data) +{ + +} + + +void +OnList1_SelectRow (GtkCList *clist, + gint row, + gint column, + GdkEvent *event, + gpointer user_data) +{ + +} + + +void +OnList2_SelectRow (GtkCList *clist, + gint row, + gint column, + GdkEvent *event, + gpointer user_data) +{ + +} + + +void +OnMcd_Delete2 (GtkButton *button, + gpointer user_data) +{ + +} + + +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) +{ + +} + + +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 0eb216d..1b718b7 100644 --- a/PcsxSrc/Linux/GladeCalls.h +++ b/PcsxSrc/Linux/GladeCalls.h @@ -1,251 +1,251 @@ -#include - - -void -OnDestroy (GtkObject *object, - gpointer user_data); - -void -OnFile_RunCd (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnFile_RunCdBios (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnFile_RunExe (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnFile_Exit (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnEmu_Run (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnEmu_Reset (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnConf_Conf (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnConf_Gpu (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnConf_Spu (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnConf_Cdr (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnConf_Pads (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnConf_Cpu (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnConf_Mcds (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnHelp_About (GtkMenuItem *menuitem, - gpointer user_data); - -void -OnHelpAbout_Ok (GtkButton *button, - gpointer user_data); - -void -OnConfConf_CdrConf (GtkButton *button, - gpointer user_data); - -void -OnConfConf_CdrTest (GtkButton *button, - gpointer user_data); - -void -OnConfConf_CdrAbout (GtkButton *button, - gpointer user_data); - -void -OnConfConf_Pad2Conf (GtkButton *button, - gpointer user_data); - -void -OnConfConf_Pad2Test (GtkButton *button, - gpointer user_data); - -void -OnConfConf_Pad2About (GtkButton *button, - gpointer user_data); - -void -OnConfConf_Pad1Conf (GtkButton *button, - gpointer user_data); - -void -OnConfConf_Pad1Test (GtkButton *button, - gpointer user_data); - -void -OnConfConf_Pad1About (GtkButton *button, - gpointer user_data); - -void -OnConfConf_GpuConf (GtkButton *button, - gpointer user_data); - -void -OnConfConf_GpuTest (GtkButton *button, - gpointer user_data); - -void -OnConfConf_GpuAbout (GtkButton *button, - gpointer user_data); - -void -OnConfConf_SpuConf (GtkButton *button, - gpointer user_data); - -void -OnConfConf_SpuTest (GtkButton *button, - gpointer user_data); - -void -OnConfConf_SpuAbout (GtkButton *button, - gpointer user_data); - -void -OnConfConf_PluginsPath (GtkButton *button, - gpointer user_data); - -void -OnConfConf_BiosPath (GtkButton *button, - gpointer user_data); - -void -OnConfConf_Ok (GtkButton *button, - gpointer user_data); - -void -OnConfConf_Cancel (GtkButton *button, - gpointer user_data); - -void -OnCpu_Ok (GtkButton *button, - gpointer user_data); - -void -OnCpu_Cancel (GtkButton *button, - gpointer user_data); - -void -OnMcd_FS1 (GtkButton *button, - gpointer user_data); - -void -OnMcd_Format1 (GtkButton *button, - gpointer user_data); - -void -OnMcd_Reload1 (GtkButton *button, - gpointer user_data); - -void -OnMcd_FS2 (GtkButton *button, - gpointer user_data); - -void -OnMcd_Format2 (GtkButton *button, - gpointer user_data); - -void -OnMcd_Reload2 (GtkButton *button, - gpointer user_data); - -void -OnMcd_Ok (GtkButton *button, - gpointer user_data); - -void -OnMcd_Cancel (GtkButton *button, - gpointer user_data); - -gboolean -OnList1_KeyPress (GtkWidget *widget, - GdkEventKey *event, - gpointer user_data); - -gboolean -OnList2_KeyPress (GtkWidget *widget, - GdkEventKey *event, - gpointer user_data); - -void -OnMcd_Copy (GtkButton *button, - gpointer user_data); - -void -OnMcd_Paste (GtkButton *button, - gpointer user_data); - -void -OnMcd_Delete (GtkButton *button, - gpointer user_data); - -void -OnMcd_CopyTo2 (GtkButton *button, - gpointer user_data); - -void -OnMcd_CopyTo1 (GtkButton *button, - gpointer user_data); - -GtkDirectionType -OnList1_Focus (GtkContainer *container, - GtkDirectionType direction, - gpointer user_data); - -void -OnList1_SelectRow (GtkCList *clist, - gint row, - gint column, - GdkEvent *event, - gpointer user_data); - -void -OnList2_SelectRow (GtkCList *clist, - gint row, - gint column, - GdkEvent *event, - gpointer user_data); - -void -OnMcd_Delete2 (GtkButton *button, - gpointer user_data); - -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); +#include + + +void +OnDestroy (GtkObject *object, + gpointer user_data); + +void +OnFile_RunCd (GtkMenuItem *menuitem, + gpointer user_data); + +void +OnFile_RunCdBios (GtkMenuItem *menuitem, + gpointer user_data); + +void +OnFile_RunExe (GtkMenuItem *menuitem, + gpointer user_data); + +void +OnFile_Exit (GtkMenuItem *menuitem, + gpointer user_data); + +void +OnEmu_Run (GtkMenuItem *menuitem, + gpointer user_data); + +void +OnEmu_Reset (GtkMenuItem *menuitem, + gpointer user_data); + +void +OnConf_Conf (GtkMenuItem *menuitem, + gpointer user_data); + +void +OnConf_Gpu (GtkMenuItem *menuitem, + gpointer user_data); + +void +OnConf_Spu (GtkMenuItem *menuitem, + gpointer user_data); + +void +OnConf_Cdr (GtkMenuItem *menuitem, + gpointer user_data); + +void +OnConf_Pads (GtkMenuItem *menuitem, + gpointer user_data); + +void +OnConf_Cpu (GtkMenuItem *menuitem, + gpointer user_data); + +void +OnConf_Mcds (GtkMenuItem *menuitem, + gpointer user_data); + +void +OnHelp_About (GtkMenuItem *menuitem, + gpointer user_data); + +void +OnHelpAbout_Ok (GtkButton *button, + gpointer user_data); + +void +OnConfConf_CdrConf (GtkButton *button, + gpointer user_data); + +void +OnConfConf_CdrTest (GtkButton *button, + gpointer user_data); + +void +OnConfConf_CdrAbout (GtkButton *button, + gpointer user_data); + +void +OnConfConf_Pad2Conf (GtkButton *button, + gpointer user_data); + +void +OnConfConf_Pad2Test (GtkButton *button, + gpointer user_data); + +void +OnConfConf_Pad2About (GtkButton *button, + gpointer user_data); + +void +OnConfConf_Pad1Conf (GtkButton *button, + gpointer user_data); + +void +OnConfConf_Pad1Test (GtkButton *button, + gpointer user_data); + +void +OnConfConf_Pad1About (GtkButton *button, + gpointer user_data); + +void +OnConfConf_GpuConf (GtkButton *button, + gpointer user_data); + +void +OnConfConf_GpuTest (GtkButton *button, + gpointer user_data); + +void +OnConfConf_GpuAbout (GtkButton *button, + gpointer user_data); + +void +OnConfConf_SpuConf (GtkButton *button, + gpointer user_data); + +void +OnConfConf_SpuTest (GtkButton *button, + gpointer user_data); + +void +OnConfConf_SpuAbout (GtkButton *button, + gpointer user_data); + +void +OnConfConf_PluginsPath (GtkButton *button, + gpointer user_data); + +void +OnConfConf_BiosPath (GtkButton *button, + gpointer user_data); + +void +OnConfConf_Ok (GtkButton *button, + gpointer user_data); + +void +OnConfConf_Cancel (GtkButton *button, + gpointer user_data); + +void +OnCpu_Ok (GtkButton *button, + gpointer user_data); + +void +OnCpu_Cancel (GtkButton *button, + gpointer user_data); + +void +OnMcd_FS1 (GtkButton *button, + gpointer user_data); + +void +OnMcd_Format1 (GtkButton *button, + gpointer user_data); + +void +OnMcd_Reload1 (GtkButton *button, + gpointer user_data); + +void +OnMcd_FS2 (GtkButton *button, + gpointer user_data); + +void +OnMcd_Format2 (GtkButton *button, + gpointer user_data); + +void +OnMcd_Reload2 (GtkButton *button, + gpointer user_data); + +void +OnMcd_Ok (GtkButton *button, + gpointer user_data); + +void +OnMcd_Cancel (GtkButton *button, + gpointer user_data); + +gboolean +OnList1_KeyPress (GtkWidget *widget, + GdkEventKey *event, + gpointer user_data); + +gboolean +OnList2_KeyPress (GtkWidget *widget, + GdkEventKey *event, + gpointer user_data); + +void +OnMcd_Copy (GtkButton *button, + gpointer user_data); + +void +OnMcd_Paste (GtkButton *button, + gpointer user_data); + +void +OnMcd_Delete (GtkButton *button, + gpointer user_data); + +void +OnMcd_CopyTo2 (GtkButton *button, + gpointer user_data); + +void +OnMcd_CopyTo1 (GtkButton *button, + gpointer user_data); + +GtkDirectionType +OnList1_Focus (GtkContainer *container, + GtkDirectionType direction, + gpointer user_data); + +void +OnList1_SelectRow (GtkCList *clist, + gint row, + gint column, + GdkEvent *event, + gpointer user_data); + +void +OnList2_SelectRow (GtkCList *clist, + gint row, + gint column, + GdkEvent *event, + gpointer user_data); + +void +OnMcd_Delete2 (GtkButton *button, + gpointer user_data); + +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); diff --git a/PcsxSrc/Linux/GladeFuncs.c b/PcsxSrc/Linux/GladeFuncs.c index 47dbfc3..f20a9a2 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 -#endif - -#include -#include -#include -#include - -#include - -#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 +#endif + +#include +#include +#include +#include + +#include + +#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 8866159..aee31f9 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 -#endif - -#include - -/* - * 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 +#endif + +#include + +/* + * 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 44ec6c8..0af25dc 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 -#endif - -#include -#include -#include -#include - -#include -#include - -#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 +#endif + +#include +#include +#include +#include + +#include +#include + +#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 ca46235..ff8d9f9 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 7ac46d4..6df431d 100644 --- a/PcsxSrc/Linux/GtkGui.c +++ b/PcsxSrc/Linux/GtkGui.c @@ -1,1326 +1,1326 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Linux.h" -#include "plugins.h" -#include "Sio.h" -#include "GladeGui.h" -#include "GladeFuncs.h" - -extern int UseGui; -long LoadCdBios; -static int needreset = 1; - -PSEgetLibType PSE_getLibType = NULL; -PSEgetLibVersion PSE_getLibVersion = NULL; -PSEgetLibName PSE_getLibName = NULL; - -// Helper Functions -void FindPlugins(); - -// Functions Callbacks -void OnFile_RunExe(); -void OnFile_RunCd(); -void OnFile_RunCdBios(); -void OnFile_Exit(); -void OnEmu_Run(); -void OnEmu_Reset(); -void OnConf_Gpu(); -void OnConf_Spu(); -void OnConf_Cdr(); -void OnConf_Pads(); -void OnConf_Mcds(); -void OnConf_Cpu(); -void OnConf_Conf(); -void OnHelp_Help(); -void OnHelp_About(); - -GtkWidget *Window = NULL; -GtkWidget *ConfDlg; -GtkWidget *DebugDlg; -GtkWidget *AboutDlg; -GtkWidget *FileSel; - -GtkAccelGroup *AccelGroup; - -typedef struct { - GtkWidget *Combo; - GList *glist; - char plist[255][255]; - int plugins; -} PluginConf; - -PluginConf GpuConfS; -PluginConf SpuConfS; -PluginConf CdrConfS; -PluginConf Pad1ConfS; -PluginConf Pad2ConfS; -PluginConf BiosConfS; - -void StartGui() { - Window = create_MainWindow(); - gtk_window_set_title(GTK_WINDOW(Window), "P©SX"); - - gtk_widget_show_all(Window); - gtk_main(); -} - -void RunGui() { - StartGui(); -} - -int destroy=0; - -void OnDestroy() { - if (!destroy) OnFile_Exit(); -} - -void ConfigurePlugins() { - if (!UseGui) return; - OnConf_Conf(); -} - -void ConfigureMemcards() { - OnConf_Mcds(); -} - -void OnRunExe_Ok() { - gchar *File; - char exe[256]; - - File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel)); - strcpy(exe, File); - gtk_widget_destroy(FileSel); - destroy=1; - gtk_widget_destroy(Window); - destroy=0; - gtk_main_quit(); - while (gtk_events_pending()) gtk_main_iteration(); - OpenPlugins(); - SysReset(); - needreset = 0; - Load(exe); - psxCpu->Execute(); -} - -void OnRunExe_Cancel() { - gtk_widget_destroy(FileSel); -} - -void OnFile_RunExe() { - GtkWidget *Ok,*Cancel; - - FileSel = gtk_file_selection_new("Select Psx Exe File"); - - Ok = GTK_FILE_SELECTION(FileSel)->ok_button; - gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnRunExe_Ok), NULL); - gtk_widget_show(Ok); - - Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button; - gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnRunExe_Cancel), NULL); - gtk_widget_show(Cancel); - - gtk_widget_show(FileSel); - gdk_window_raise(FileSel->window); -} - -void OnFile_RunCd() { - LoadCdBios = 0; - destroy=1; - gtk_widget_destroy(Window); - destroy=0; - gtk_main_quit(); - while (gtk_events_pending()) gtk_main_iteration(); - OpenPlugins(); - SysReset(); - needreset = 0; - CheckCdrom(); - if (LoadCdrom() == -1) { - ClosePlugins(); - SysMessage("Could not load Cdrom\n"); - return; - } - psxCpu->Execute(); -} - -void OnFile_RunCdBios() { - LoadCdBios = 1; - destroy=1; - gtk_widget_destroy(Window); - destroy=0; - gtk_main_quit(); - while (gtk_events_pending()) gtk_main_iteration(); - OpenPlugins(); - SysReset(); - needreset = 0; - CheckCdrom(); - psxCpu->Execute(); -} - -void OnFile_Exit() { - DIR *dir; - struct dirent *ent; - void *Handle; - char plugin[256]; - - // with this the problem with plugins that are linked with the pthread - // library is solved - - dir = opendir(Config.PluginsDir); - if (dir != NULL) { - while ((ent = readdir(dir)) != NULL) { - sprintf (plugin, "%s%s", Config.PluginsDir, ent->d_name); - - if (strstr(plugin, ".so") == NULL) continue; - Handle = dlopen(plugin, RTLD_NOW); - if (Handle == NULL) continue; - } - } - - printf ("P©SX Quitting\n"); - if (UseGui) gtk_main_quit(); - SysClose(); - if (UseGui) gtk_exit(0); - else exit(0); -} - -void OnEmu_Run() { - destroy=1; - gtk_widget_destroy(Window); - destroy=0; - gtk_main_quit(); - while (gtk_events_pending()) gtk_main_iteration(); - OpenPlugins(); - if (needreset) { SysReset(); needreset = 0; } - psxCpu->Execute(); -} - -void OnEmu_Reset() { - needreset = 1; -} - -void OnConf_Gpu() { - gtk_widget_set_sensitive(Window, FALSE); - GPU_configure(); - gtk_widget_set_sensitive(Window, TRUE); -} - -void OnConf_Spu() { - gtk_widget_set_sensitive(Window, FALSE); - SPU_configure(); - gtk_widget_set_sensitive(Window, TRUE); -} - -void OnConf_Cdr() { - gtk_widget_set_sensitive(Window, FALSE); - CDR_configure(); - gtk_widget_set_sensitive(Window, TRUE); -} - -void OnConf_Pads() { - gtk_widget_set_sensitive(Window, FALSE); - PAD1_configure(); - if (strcmp(Config.Pad1, Config.Pad2)) PAD2_configure(); - gtk_widget_set_sensitive(Window, TRUE); -} - -GtkWidget *McdDlg; -GtkWidget *Entry1,*Entry2; -GtkWidget *List1,*List2; -GtkWidget *BtnPaste; -GTimer *Gtimer; -int timer; -McdBlock Blocks[2][15]; -int IconC[2][15]; - -void SetIcon(short *icon, GtkWidget *List, int i) { - GdkPixmap *pixmap; - GdkImage *image; - GdkVisual *visual; - GdkGC *gc; - int x, y, c; - - visual = gdk_window_get_visual(McdDlg->window); - - if (visual->depth == 8) return; - - image = gdk_image_new(GDK_IMAGE_NORMAL, visual, 16, 16); - - for (y=0; y<16; y++) { - for (x=0; x<16; x++) { - c = icon[y*16+x]; - c = ((c&0x001f) << 10) | ((c&0x7c00) >> 10) | (c&0x03e0); - if (visual->depth == 16) - c = (c&0x001f) | ((c&0x7c00) << 1) | ((c&0x03e0) << 1); - else if (visual->depth == 24 || visual->depth == 32) - c = ((c&0x001f) << 3) | ((c&0x03e0) << 6) | ((c&0x7c00) << 9); - - gdk_image_put_pixel(image, x, y, c); - } - } - - pixmap = gdk_pixmap_new(McdDlg->window, 16, 16, visual->depth); - - gc = gdk_gc_new(pixmap); - gdk_draw_image(pixmap, gc, image, 0, 0, 0, 0, 16, 16); - gdk_gc_destroy(gc); - gdk_image_destroy(image); - - gtk_clist_set_pixmap(GTK_CLIST(List), i-1, 0, pixmap, NULL); -} - -void LoadListItems(int mcd, GtkWidget *List) { - int i; - - gtk_clist_clear(GTK_CLIST(List)); - - for (i=1; i<16; i++) { - McdBlock *Info; - gchar *text[5]; - - Info = &Blocks[mcd-1][i-1]; - IconC[mcd-1][i-1] = 0; - - if ((Info->Flags & 0xF0) == 0xA0) { - if ((Info->Flags & 0xF) >= 1 && - (Info->Flags & 0xF) <= 3) { - text[2] = "Deleted"; - } else text[2] = "Free"; - } else if ((Info->Flags & 0xF0) == 0x50) - text[2] = "Used"; - else { text[2] = "Free"; } - - text[0] = ""; - text[1] = Info->Title; - text[3] = Info->ID; - text[4] = Info->Name; - - gtk_clist_insert(GTK_CLIST(List), i-1, text); - - if (Info->IconCount == 0) continue; - - SetIcon(Info->Icon, List, i); - } -} - -void UpdateListItems(int mcd, GtkWidget *List) { - int i,j; - - for (i=1; i<16; i++) { - McdBlock *Info; - gchar *text[5]; - - Info = &Blocks[mcd-1][i-1]; - IconC[mcd-1][i-1] = 0; - - if ((Info->Flags & 0xF0) == 0xA0) { - if ((Info->Flags & 0xF) >= 1 && - (Info->Flags & 0xF) <= 3) { - text[2] = "Deleted"; - } else text[2] = "Free"; - } else if ((Info->Flags & 0xF0) == 0x50) - text[2] = "Used"; - else { text[2] = "Free"; } - - text[0] = ""; - text[1] = Info->Title; - text[3] = Info->ID; - text[4] = Info->Name; - - for (j=0; j<5; j++) - gtk_clist_set_text(GTK_CLIST(List), i-1, j, text[j]); - - if (Info->IconCount == 0) continue; - - SetIcon(Info->Icon, List, i); - } -} - -void LoadMcdDlg() { - int i; - - for (i=1; i<16; i++) GetMcdBlockInfo(1, i, &Blocks[0][i-1]); - for (i=1; i<16; i++) GetMcdBlockInfo(2, i, &Blocks[1][i-1]); - LoadListItems(1, List1); - LoadListItems(2, List2); -} - -void UpdateMcdDlg() { - int i; - - for (i=1; i<16; i++) GetMcdBlockInfo(1, i, &Blocks[0][i-1]); - for (i=1; i<16; i++) GetMcdBlockInfo(2, i, &Blocks[1][i-1]); - UpdateListItems(1, List1); - UpdateListItems(2, List2); -} - -void StopTimer() { - g_timer_stop(Gtimer); timer = 0; -} - -void OnMcd_Ok() { - char *tmp; - - StopTimer(); - - tmp = gtk_entry_get_text(GTK_ENTRY(Entry1)); - strcpy(Config.Mcd1, tmp); - tmp = gtk_entry_get_text(GTK_ENTRY(Entry2)); - strcpy(Config.Mcd2, tmp); - - SaveConfig(); - LoadMcds(Config.Mcd1, Config.Mcd2); - - gtk_widget_destroy(McdDlg); - if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); -// gtk_main_quit(); -} - -void OnMcd_Cancel() { - StopTimer(); - - LoadMcds(Config.Mcd1, Config.Mcd2); - - gtk_widget_destroy(McdDlg); - if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); -// gtk_main_quit(); -} - -void OnMcdFS1_Ok() { - gchar *File; - - File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel)); - gtk_entry_set_text(GTK_ENTRY(Entry1), File); - - LoadMcd(1, File); - UpdateMcdDlg(); - - gtk_widget_destroy(FileSel); -} - -void OnMcdFS2_Ok() { - gchar *File; - - File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel)); - gtk_entry_set_text(GTK_ENTRY(Entry2), File); - - LoadMcd(2, File); - UpdateMcdDlg(); - - gtk_widget_destroy(FileSel); -} - -void OnMcdFS_Cancel() { - gtk_widget_destroy(FileSel); -} - -void OnMcd_FS1() { - GtkWidget *Ok,*Cancel; - - FileSel = gtk_file_selection_new("Select Psx Mcd File"); - gtk_file_selection_set_filename(GTK_FILE_SELECTION(FileSel), gtk_entry_get_text(GTK_ENTRY(Entry1))); - - Ok = GTK_FILE_SELECTION(FileSel)->ok_button; - gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMcdFS1_Ok), NULL); - gtk_widget_show(Ok); - - Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button; - gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnMcdFS_Cancel), NULL); - gtk_widget_show(Cancel); - - gtk_widget_show(FileSel); - gdk_window_raise(FileSel->window); -} - -void OnMcd_FS2() { - GtkWidget *Ok,*Cancel; - - FileSel = gtk_file_selection_new("Select Psx Mcd File"); - gtk_file_selection_set_filename(GTK_FILE_SELECTION(FileSel), gtk_entry_get_text(GTK_ENTRY(Entry2))); - - Ok = GTK_FILE_SELECTION(FileSel)->ok_button; - gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMcdFS2_Ok), NULL); - gtk_widget_show(Ok); - - Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button; - gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnMcdFS_Cancel), NULL); - gtk_widget_show(Cancel); - - gtk_widget_show(FileSel); - gdk_window_raise(FileSel->window); -} - -GtkWidget *MsgBoxDlg; -int yes; - -void OnMsgBox_Yes() { - yes = 1; - gtk_widget_destroy(MsgBoxDlg); - gtk_main_quit(); -} - -void OnMsgBox_No() { - yes = 0; - gtk_widget_destroy(MsgBoxDlg); - gtk_main_quit(); -} - -int MessageBox(char *msg, char *title) { - GtkWidget *Ok,*Txt; - GtkWidget *Box,*Box1; - int w; - - if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0; - - w = strlen(msg) * 6 + 20; - - MsgBoxDlg = gtk_window_new (GTK_WINDOW_DIALOG); - gtk_widget_set_usize(MsgBoxDlg, w, 70); - gtk_window_set_position(GTK_WINDOW(MsgBoxDlg), GTK_WIN_POS_CENTER); - gtk_window_set_title(GTK_WINDOW(MsgBoxDlg), title); - gtk_container_set_border_width(GTK_CONTAINER(MsgBoxDlg), 0); - - Box = gtk_vbox_new(0, 0); - gtk_container_add(GTK_CONTAINER(MsgBoxDlg), Box); - gtk_widget_show(Box); - - Txt = gtk_label_new(msg); - - gtk_box_pack_start(GTK_BOX(Box), Txt, FALSE, FALSE, 5); - gtk_widget_show(Txt); - - Box1 = gtk_hbutton_box_new(); - gtk_box_pack_start(GTK_BOX(Box), Box1, FALSE, FALSE, 0); - gtk_widget_show(Box1); - - Ok = gtk_button_new_with_label("Yes"); - gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMsgBox_Yes), NULL); - gtk_container_add(GTK_CONTAINER(Box1), Ok); - GTK_WIDGET_SET_FLAGS(Ok, GTK_CAN_DEFAULT); - gtk_widget_show(Ok); - - Ok = gtk_button_new_with_label("No"); - gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMsgBox_No), NULL); - gtk_container_add(GTK_CONTAINER(Box1), Ok); - GTK_WIDGET_SET_FLAGS(Ok, GTK_CAN_DEFAULT); - gtk_widget_show(Ok); - - gtk_widget_show(MsgBoxDlg); - - gtk_main(); - - return yes; -} - -void OnMcd_Format1() { - char *str; - - if (MessageBox("Are you sure you want to format this Memory Card?", "Confirmation") == 0) return; - str = gtk_entry_get_text(GTK_ENTRY(Entry1)); - CreateMcd(str); - LoadMcd(1, str); - UpdateMcdDlg(); -} - -void OnMcd_Format2() { - char *str; - - if (MessageBox("Are you sure you want to format this Memory Card?", "Confirmation") == 0) return; - str = gtk_entry_get_text(GTK_ENTRY(Entry2)); - CreateMcd(str); - LoadMcd(2, str); - UpdateMcdDlg(); -} - -void OnMcd_Reload1() { - char *str; - - str = gtk_entry_get_text(GTK_ENTRY(Entry1)); - LoadMcd(1, str); - UpdateMcdDlg(); -} - -void OnMcd_Reload2() { - char *str; - - str = gtk_entry_get_text(GTK_ENTRY(Entry2)); - LoadMcd(2, str); - UpdateMcdDlg(); -} - -static int copy = 0, copymcd = 0; - -void OnMcd_CopyTo1() { - int i = GTK_CLIST(List2)->focus_row; - - copy = i; - copymcd = 1; - - gtk_widget_set_sensitive(BtnPaste, TRUE); -} - -void OnMcd_CopyTo2() { - int i = GTK_CLIST(List1)->focus_row; - - copy = i; - copymcd = 2; - - gtk_widget_set_sensitive(BtnPaste, TRUE); -} - -void OnMcd_Paste() { - int i; - char *str; - - if (MessageBox("Are you sure you want to paste this selection?", "Confirmation") == 0) return; - - if (copymcd == 1) { - str = gtk_entry_get_text(GTK_ENTRY(Entry1)); - i = GTK_CLIST(List1)->focus_row; - - // save dir data + save data - memcpy(Mcd1Data + (i+1) * 128, Mcd2Data + (copy+1) * 128, 128); - SaveMcd(str, Mcd1Data, (i+1) * 128, 128); - memcpy(Mcd1Data + (i+1) * 1024 * 8, Mcd2Data + (copy+1) * 1024 * 8, 1024 * 8); - SaveMcd(str, Mcd1Data, (i+1) * 1024 * 8, 1024 * 8); - } else { // 2 - str = gtk_entry_get_text(GTK_ENTRY(Entry2)); - i = GTK_CLIST(List2)->focus_row; - - // save dir data + save data - memcpy(Mcd2Data + (i+1) * 128, Mcd1Data + (copy+1) * 128, 128); - SaveMcd(str, Mcd2Data, (i+1) * 128, 128); - memcpy(Mcd2Data + (i+1) * 1024 * 8, Mcd1Data + (copy+1) * 1024 * 8, 1024 * 8); - SaveMcd(str, Mcd2Data, (i+1) * 1024 * 8, 1024 * 8); - } - - UpdateMcdDlg(); -} - -void OnMcd_Delete1() { - McdBlock *Info; - int mcd = 1; - int i, xor = 0, j; - unsigned char *data, *ptr; - char *str; - - str = gtk_entry_get_text(GTK_ENTRY(Entry1)); - i = GTK_CLIST(List1)->focus_row; - data = Mcd1Data; - - i++; - - ptr = data + i * 128; - - Info = &Blocks[mcd-1][i-1]; - - if ((Info->Flags & 0xF0) == 0xA0) { - if ((Info->Flags & 0xF) >= 1 && - (Info->Flags & 0xF) <= 3) { // deleted - *ptr = 0x50 | (Info->Flags & 0xF); - } else return; - } else if ((Info->Flags & 0xF0) == 0x50) { // used - *ptr = 0xA0 | (Info->Flags & 0xF); - } else { return; } - - for (j=0; j<127; j++) xor^=*ptr++; - *ptr = xor; - - SaveMcd(str, data, i * 128, 128); - UpdateMcdDlg(); -} - -void OnMcd_Delete2() { - McdBlock *Info; - int mcd = 2; - int i, xor = 0, j; - unsigned char *data, *ptr; - char *str; - - str = gtk_entry_get_text(GTK_ENTRY(Entry2)); - i = GTK_CLIST(List2)->focus_row; - data = Mcd2Data; - - i++; - - ptr = data + i * 128; - - Info = &Blocks[mcd-1][i-1]; - - if ((Info->Flags & 0xF0) == 0xA0) { - if ((Info->Flags & 0xF) >= 1 && - (Info->Flags & 0xF) <= 3) { // deleted - *ptr = 0x50 | (Info->Flags & 0xF); - } else return; - } else if ((Info->Flags & 0xF0) == 0x50) { // used - *ptr = 0xA0 | (Info->Flags & 0xF); - } else { return; } - - for (j=0; j<127; j++) xor^=*ptr++; - *ptr = xor; - - SaveMcd(str, data, i * 128, 128); - UpdateMcdDlg(); -} - -void UpdateMcdIcon(int mcd, GtkWidget *List) { - int i; - - for (i=1; i<16; i++) { - McdBlock *Info; - int *count; - - Info = &Blocks[mcd-1][i-1]; - count = &IconC[mcd-1][i-1]; - - if (Info->IconCount <= 1) continue; - - (*count)++; - if (*count == Info->IconCount) *count = 0; - - SetIcon(&Info->Icon[*count*16*16], List, i); - } -} - -void OnConf_Mcds() { - McdDlg = create_McdsDlg(); - gtk_window_set_title(GTK_WINDOW(McdDlg), "P©SX Memcard Manager"); - - Entry1 = lookup_widget(McdDlg, "GtkEntry_Mcd1"); - if (!strlen(Config.Mcd1)) strcpy(Config.Mcd1, "memcards/Mcd001.mcr"); - gtk_entry_set_text(GTK_ENTRY(Entry1), Config.Mcd1); - - Entry2 = lookup_widget(McdDlg, "GtkEntry_Mcd2"); - if (!strlen(Config.Mcd2)) strcpy(Config.Mcd2, "memcards/Mcd002.mcr"); - gtk_entry_set_text(GTK_ENTRY(Entry2), Config.Mcd2); - - List1 = lookup_widget(McdDlg, "GtkCList_McdList1"); - List2 = lookup_widget(McdDlg, "GtkCList_McdList2"); - - BtnPaste = lookup_widget(McdDlg, "GtkButton_McdPaste"); - gtk_widget_set_sensitive(BtnPaste, FALSE); - - gtk_clist_set_column_justification(GTK_CLIST(List1), 0, GTK_JUSTIFY_CENTER); - gtk_clist_set_column_justification(GTK_CLIST(List2), 0, GTK_JUSTIFY_CENTER); - gtk_clist_set_column_justification(GTK_CLIST(List1), 2, GTK_JUSTIFY_CENTER); - gtk_clist_set_column_justification(GTK_CLIST(List2), 2, GTK_JUSTIFY_CENTER); - - gtk_widget_show_all(McdDlg); - - LoadMcdDlg(); - - if (Window != NULL) gtk_widget_set_sensitive(Window, FALSE); - - Gtimer = g_timer_new(); timer = 1; - - while (gtk_events_pending()) gtk_main_iteration(); - - while (timer) { - unsigned long usecs; - - g_timer_elapsed(Gtimer, &usecs); - if (usecs > 250000) { - UpdateMcdIcon(1, List1); - UpdateMcdIcon(2, List2); - g_timer_reset(Gtimer); - } - - while (gtk_events_pending()) gtk_main_iteration(); - } -} - -GtkWidget *CpuDlg; -GtkWidget *PsxCombo; -GList *psxglist; -char *psxtypes[] = { - "NTSC", - "PAL" -}; - -void OnCpu_Ok() { - GtkWidget *Btn; - char *tmp; - long t; - - tmp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(PsxCombo)->entry)); - - if (!strcmp("NTSC",tmp)) Config.PsxType = 0; - else Config.PsxType = 1; // pal - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_Xa"); - Config.Xa = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_Sio"); - Config.Sio = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_Mdec"); - Config.Mdec = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_Cdda"); - Config.Cdda = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_PsxAuto"); - Config.PsxAuto = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); - - t = Config.Cpu; - Btn = lookup_widget(CpuDlg, "GtkCheckButton_Cpu"); - Config.Cpu = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); - if (t != Config.Cpu) { - psxCpu->Shutdown(); - if (Config.Cpu) - psxCpu = &psxInt; - else psxCpu = &psxRec; - if (psxCpu->Init() == -1) { - SysClose(); - exit(1); - } - psxCpu->Reset(); - } - - 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)); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_SpuIrq"); - Config.SpuIrq = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_CdTiming"); - Config.CdTiming = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); - - gtk_widget_destroy(CpuDlg); - - SaveConfig(); - if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); - gtk_main_quit(); -} - -void OnCpu_Cancel() { - gtk_widget_destroy(CpuDlg); - if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); - gtk_main_quit(); -} - - -void OnConf_Cpu() { - GtkWidget *Btn; - int i; - - CpuDlg = create_CpuDlg(); - gtk_window_set_title(GTK_WINDOW(CpuDlg), "P©SX Configuration"); - - psxglist = NULL; - for (i=0;i<2;i++) - psxglist = g_list_append(psxglist, psxtypes[i]); - PsxCombo = lookup_widget(CpuDlg, "GtkCombo_PsxType"); - gtk_combo_set_popdown_strings(GTK_COMBO(PsxCombo), psxglist); - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(PsxCombo)->entry), psxtypes[Config.PsxType]); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_Xa"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Xa); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_Sio"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Sio); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_Mdec"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Mdec); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_Cdda"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Cdda); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_PsxAuto"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.PsxAuto); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_Cpu"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Cpu); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_CpuLog"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Log); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_PsxOut"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.PsxOut); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_SpuIrq"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.SpuIrq); - - Btn = lookup_widget(CpuDlg, "GtkCheckButton_CdTiming"); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.CdTiming); - - gtk_widget_show_all(CpuDlg); - if (Window != NULL) gtk_widget_set_sensitive(Window, FALSE); - gtk_main(); -} - -#define FindComboText(combo,list,conf) \ - if (strlen(conf) > 0) { \ - int i; \ - for (i=2;i<255;i+=2) { \ - if (!strcmp(conf, list[i-2])) { \ - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), list[i-1]); \ - break; \ - } \ - } \ - } - -#define GetComboText(combo,list,conf) \ - { \ - int i; \ - char *tmp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry)); \ - for (i=2;i<255;i+=2) { \ - if (!strcmp(tmp, list[i-1])) { \ - strcpy(conf, list[i-2]); \ - break; \ - } \ - } \ - } - -void OnConfConf_Ok() { - GetComboText(GpuConfS.Combo, GpuConfS.plist, Config.Gpu); - GetComboText(SpuConfS.Combo, SpuConfS.plist, Config.Spu); - GetComboText(CdrConfS.Combo, CdrConfS.plist, Config.Cdr); - GetComboText(Pad1ConfS.Combo, Pad1ConfS.plist, Config.Pad1); - GetComboText(Pad2ConfS.Combo, Pad2ConfS.plist, Config.Pad2); - GetComboText(BiosConfS.Combo, BiosConfS.plist, Config.Bios); - - SaveConfig(); - - ReleasePlugins(); - LoadPlugins(); - - needreset = 1; - gtk_widget_destroy(ConfDlg); - if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); - gtk_main_quit(); -} - -void OnConfConf_Cancel() { - gtk_widget_destroy(ConfDlg); - if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); - gtk_main_quit(); -} - -#define ConfPlugin(src, confs, plugin, name) \ - void *drv; \ - src conf; \ - char file[256]; \ - \ - GetComboText(confs.Combo, confs.plist, plugin); \ - strcpy(file, Config.PluginsDir); \ - strcat(file, plugin); \ - gtk_widget_set_sensitive(ConfDlg, FALSE); \ - drv = SysLoadLibrary(file); \ - if (drv == NULL) return; \ - conf = (src) SysLoadSym(drv, name); \ - if (SysLibError() == NULL) conf(); \ - else SysMessage("Plugin doesn't needs to be configured"); \ - SysCloseLibrary(drv); \ - gtk_widget_set_sensitive(ConfDlg, TRUE); - -#define TestPlugin(src, confs, plugin, name) \ - void *drv; \ - src conf; \ - int ret = 0; \ - char file[256]; \ - \ - GetComboText(confs.Combo, confs.plist, plugin); \ - strcpy(file, Config.PluginsDir); \ - strcat(file, plugin); \ - gtk_widget_set_sensitive(ConfDlg, FALSE); \ - drv = SysLoadLibrary(file); \ - if (drv == NULL) return; \ - conf = (src) SysLoadSym(drv, name); \ - if (SysLibError() == NULL) ret = conf(); \ - SysCloseLibrary(drv); \ - SysMessage("This plugin reports that should %swork correctly", ret == 0 ? "" : "not "); \ - gtk_widget_set_sensitive(ConfDlg, TRUE); - -void OnConfConf_GpuConf() { - ConfPlugin(GPUconfigure, GpuConfS, Config.Gpu, "GPUconfigure"); -} - -void OnConfConf_GpuTest() { - TestPlugin(GPUtest, GpuConfS, Config.Gpu, "GPUtest"); -} - -void OnConfConf_GpuAbout() { - ConfPlugin(GPUabout, GpuConfS, Config.Gpu, "GPUabout"); -} - -void OnConfConf_SpuConf() { - ConfPlugin(SPUconfigure, SpuConfS, Config.Spu, "SPUconfigure"); -} - -void OnConfConf_SpuTest() { - TestPlugin(SPUtest, SpuConfS, Config.Spu, "SPUtest"); -} - -void OnConfConf_SpuAbout() { - ConfPlugin(SPUabout, SpuConfS, Config.Spu, "SPUabout"); -} - -void OnConfConf_CdrConf() { - ConfPlugin(CDRconfigure, CdrConfS, Config.Cdr, "CDRconfigure"); -} - -void OnConfConf_CdrTest() { - TestPlugin(CDRtest, CdrConfS, Config.Cdr, "CDRtest"); -} - -void OnConfConf_CdrAbout() { - ConfPlugin(CDRabout, CdrConfS, Config.Cdr, "CDRabout"); -} - -void OnConfConf_Pad1Conf() { - ConfPlugin(PADconfigure, Pad1ConfS, Config.Pad1, "PADconfigure"); -} - -void OnConfConf_Pad1Test() { - TestPlugin(PADtest, Pad1ConfS, Config.Pad1, "PADtest"); -} - -void OnConfConf_Pad1About() { - ConfPlugin(PADabout, Pad1ConfS, Config.Pad1, "PADabout"); -} - -void OnConfConf_Pad2Conf() { - ConfPlugin(PADconfigure, Pad2ConfS, Config.Pad2, "PADconfigure"); -} - -void OnConfConf_Pad2Test() { - TestPlugin(PADtest, Pad2ConfS, Config.Pad2, "PADtest"); -} - -void OnConfConf_Pad2About() { - ConfPlugin(PADabout, Pad2ConfS, Config.Pad2, "PADabout"); -} - -void OnPluginsPath_Ok() { - gchar *File; - - File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel)); - strcpy(Config.PluginsDir, File); - if (Config.PluginsDir[strlen(Config.PluginsDir)-1] != '/') - strcat(Config.PluginsDir, "/"); - - FindPlugins(); - - gtk_widget_destroy(FileSel); -} - -void OnPluginsPath_Cancel() { - gtk_widget_destroy(FileSel); -} - -void OnConfConf_PluginsPath() { - GtkWidget *Ok,*Cancel; - - FileSel = gtk_file_selection_new("Select Plugins Directory"); - - Ok = GTK_FILE_SELECTION(FileSel)->ok_button; - gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnPluginsPath_Ok), NULL); - gtk_widget_show(Ok); - - Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button; - gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnPluginsPath_Cancel), NULL); - gtk_widget_show(Cancel); - - gtk_widget_show(FileSel); - gdk_window_raise(FileSel->window); -} - -void OnBiosPath_Ok() { - gchar *File; - - File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel)); - strcpy(Config.BiosDir, File); - if (Config.BiosDir[strlen(Config.BiosDir)-1] != '/') - strcat(Config.BiosDir, "/"); - - FindPlugins(); - - gtk_widget_destroy(FileSel); -} - -void OnBiosPath_Cancel() { - gtk_widget_destroy(FileSel); -} - -void OnConfConf_BiosPath() { - GtkWidget *Ok,*Cancel; - - FileSel = gtk_file_selection_new("Select Bios Directory"); - - Ok = GTK_FILE_SELECTION(FileSel)->ok_button; - gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnBiosPath_Ok), NULL); - gtk_widget_show(Ok); - - Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button; - gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnBiosPath_Cancel), NULL); - gtk_widget_show(Cancel); - - gtk_widget_show(FileSel); - gdk_window_raise(FileSel->window); -} - -void OnConf_Conf() { - ConfDlg = create_ConfDlg(); - gtk_window_set_title(GTK_WINDOW(ConfDlg), "P©SX Configuration"); - - FindPlugins(); - - gtk_widget_show_all(ConfDlg); - 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() { - gtk_widget_destroy(DebugDlg); - if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); - gtk_main_quit(); -} - -void OnHelp_Help() { -} - -void OnHelpAbout_Ok() { - gtk_widget_destroy(AboutDlg); - if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); - gtk_main_quit(); -} - -void OnHelp_About() { - GtkWidget *Label; - - AboutDlg = create_AboutDlg(); - gtk_window_set_title(GTK_WINDOW(AboutDlg), "About P©SX"); - - Label = lookup_widget(AboutDlg, "GtkAbout_LabelVersion"); - gtk_label_set_text(GTK_LABEL(Label), - "P©SX For Linux\n" - "Version " PCSX_VERSION); - - Label = lookup_widget(AboutDlg, "GtkAbout_LabelAuthors"); - gtk_label_set_text(GTK_LABEL(Label), - "PCSX a psx emulator\n\n" - "written by:\n" - "main coder: linuzappz\n" - "co-coders: shadow\n" - "ex-coders: Nocomp, Pete Bernett, nik3d\n" - "Webmaster: AkumaX"); - - Label = lookup_widget(AboutDlg, "GtkAbout_LabelGreets"); - gtk_label_set_text(GTK_LABEL(Label), - "Greets to: Duddie, Tratax, Kazzuya, JNS, Bobbi, Psychojak and Shunt\n" - "Special thanks to:\n" - "Twin (we Love you twin0r), Roor (love for you too),\n" - "calb (Thanks for help :) ), now3d (for great help to my psxdev stuff :) )"); - - gtk_widget_show_all(AboutDlg); - if (Window != NULL) gtk_widget_set_sensitive(Window, FALSE); - gtk_main(); -} - -#define ComboAddPlugin(type) { \ - ##type##ConfS.plugins+=2; \ - strcpy(##type##ConfS.plist[##type##ConfS.plugins-1], name); \ - strcpy(##type##ConfS.plist[##type##ConfS.plugins-2], ent->d_name); \ - ##type##ConfS.glist = g_list_append(##type##ConfS.glist, ##type##ConfS.plist[##type##ConfS.plugins-1]); \ -} - -#define ConfCreatePConf(name, type) \ - if (type##ConfS.glist != NULL) { \ - type##ConfS.Combo = lookup_widget(ConfDlg, "GtkCombo_" name); \ - gtk_combo_set_popdown_strings(GTK_COMBO(type##ConfS.Combo), type##ConfS.glist); \ - FindComboText(type##ConfS.Combo, type##ConfS.plist, Config.##type##); \ - } - -void FindPlugins() { - DIR *dir; - struct dirent *ent; - void *Handle; - char plugin[256],name[256]; - - GpuConfS.plugins = 0; SpuConfS.plugins = 0; CdrConfS.plugins = 0; - Pad1ConfS.plugins = 0; Pad2ConfS.plugins = 0; BiosConfS.plugins = 0; - GpuConfS.glist = NULL; SpuConfS.glist = NULL; CdrConfS.glist = NULL; - Pad1ConfS.glist = NULL; Pad2ConfS.glist = NULL; BiosConfS.glist = NULL; - - dir = opendir(Config.PluginsDir); - if (dir == NULL) { - SysMessage("Could not open '%s' directory\n", Config.PluginsDir); - return; - } - while ((ent = readdir(dir)) != NULL) { - long type,v; - - sprintf(plugin, "%s%s", Config.PluginsDir, ent->d_name); - - if (strstr(plugin, ".so") == NULL) continue; - Handle = dlopen(plugin, RTLD_NOW); - if (Handle == NULL) continue; - - PSE_getLibType = (PSEgetLibType) dlsym(Handle, "PSEgetLibType"); - if (dlerror() != NULL) { - if (strstr(plugin, "gpu") != NULL) type = PSE_LT_GPU; - else if (strstr(plugin, "cdr") != NULL) type = PSE_LT_CDR; - else if (strstr(plugin, "spu") != NULL) type = PSE_LT_SPU; - else if (strstr(plugin, "pad") != NULL) type = PSE_LT_PAD; - else continue; - } - else type = PSE_getLibType(); - - PSE_getLibName = (PSEgetLibName) dlsym(Handle, "PSEgetLibName"); - if (dlerror() == NULL) { - sprintf(name, "%s", PSE_getLibName()); - PSE_getLibVersion = (PSEgetLibVersion) dlsym(Handle, "PSEgetLibVersion"); - if (dlerror() == NULL) { - char ver[32]; - - v = PSE_getLibVersion(); - sprintf(ver, " %ld.%ld.%ld",v>>16,(v>>8)&0xff,v&0xff); - strcat(name, ver); - } - } - else strcpy(name, ent->d_name); - - if (type & PSE_LT_CDR) { - ComboAddPlugin(Cdr); - } - if (type & PSE_LT_GPU) { - ComboAddPlugin(Gpu); - } - if (type & PSE_LT_SPU) { - ComboAddPlugin(Spu); - } - if (type & PSE_LT_PAD) { - PADquery query = (PADquery)dlsym(Handle, "PADquery"); - if (query() & 0x1) { - ComboAddPlugin(Pad1); - } - if (query() & 0x2) { - ComboAddPlugin(Pad2); - } - } - } - closedir(dir); - - ConfCreatePConf("Gpu", Gpu); - ConfCreatePConf("Spu", Spu); - ConfCreatePConf("Pad1", Pad1); - ConfCreatePConf("Pad2", Pad2); - ConfCreatePConf("Cdr", Cdr); - - BiosConfS.plugins+=2; - strcpy(BiosConfS.plist[BiosConfS.plugins-1], "Internal HLE Bios"); - strcpy(BiosConfS.plist[BiosConfS.plugins-2], "HLE"); - BiosConfS.glist = g_list_append(BiosConfS.glist, BiosConfS.plist[BiosConfS.plugins-1]); - - dir = opendir(Config.BiosDir); - if (dir == NULL) { - SysMessage("Could not open '%s' directory\n", Config.BiosDir); - return; - } - - while ((ent = readdir(dir)) != NULL) { - struct stat buf; - - sprintf (plugin, "%s%s", Config.BiosDir, ent->d_name); - if (stat(plugin, &buf) == -1) continue; - if (buf.st_size != (1024*512)) continue; - - BiosConfS.plugins+=2; - strcpy(BiosConfS.plist[BiosConfS.plugins-1], ent->d_name); - strcpy(BiosConfS.plist[BiosConfS.plugins-2], ent->d_name); - BiosConfS.glist = g_list_append(BiosConfS.glist, BiosConfS.plist[BiosConfS.plugins-1]); - } - closedir(dir); - - ConfCreatePConf("Bios", Bios); -} - -GtkWidget *MsgDlg; - -void OnMsg_Ok() { - gtk_widget_destroy(MsgDlg); - gtk_main_quit(); -} - -void SysMessage(char *fmt, ...) { - GtkWidget *Ok,*Txt; - GtkWidget *Box,*Box1; - va_list list; - char msg[512]; - - va_start(list, fmt); - vsprintf(msg, fmt, list); - va_end(list); - - if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0; - - if (!UseGui) { printf ("%s\n",msg); return; } - - MsgDlg = gtk_window_new (GTK_WINDOW_DIALOG); - gtk_window_set_position(GTK_WINDOW(MsgDlg), GTK_WIN_POS_CENTER); - gtk_window_set_title(GTK_WINDOW(MsgDlg), "P©SX Msg"); - gtk_container_set_border_width(GTK_CONTAINER(MsgDlg), 5); - - Box = gtk_vbox_new(5, 0); - gtk_container_add(GTK_CONTAINER(MsgDlg), Box); - gtk_widget_show(Box); - - Txt = gtk_label_new(msg); - - gtk_box_pack_start(GTK_BOX(Box), Txt, FALSE, FALSE, 5); - gtk_widget_show(Txt); - - Box1 = gtk_hbutton_box_new(); - gtk_box_pack_start(GTK_BOX(Box), Box1, FALSE, FALSE, 0); - gtk_widget_show(Box1); - - Ok = gtk_button_new_with_label("Ok"); - gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMsg_Ok), NULL); - gtk_container_add(GTK_CONTAINER(Box1), Ok); - GTK_WIDGET_SET_FLAGS(Ok, GTK_CAN_DEFAULT); - gtk_widget_show(Ok); - - gtk_widget_show(MsgDlg); - - gtk_main(); -} - +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Linux.h" +#include "plugins.h" +#include "Sio.h" +#include "GladeGui.h" +#include "GladeFuncs.h" + +extern int UseGui; +long LoadCdBios; +static int needreset = 1; + +PSEgetLibType PSE_getLibType = NULL; +PSEgetLibVersion PSE_getLibVersion = NULL; +PSEgetLibName PSE_getLibName = NULL; + +// Helper Functions +void FindPlugins(); + +// Functions Callbacks +void OnFile_RunExe(); +void OnFile_RunCd(); +void OnFile_RunCdBios(); +void OnFile_Exit(); +void OnEmu_Run(); +void OnEmu_Reset(); +void OnConf_Gpu(); +void OnConf_Spu(); +void OnConf_Cdr(); +void OnConf_Pads(); +void OnConf_Mcds(); +void OnConf_Cpu(); +void OnConf_Conf(); +void OnHelp_Help(); +void OnHelp_About(); + +GtkWidget *Window = NULL; +GtkWidget *ConfDlg; +GtkWidget *DebugDlg; +GtkWidget *AboutDlg; +GtkWidget *FileSel; + +GtkAccelGroup *AccelGroup; + +typedef struct { + GtkWidget *Combo; + GList *glist; + char plist[255][255]; + int plugins; +} PluginConf; + +PluginConf GpuConfS; +PluginConf SpuConfS; +PluginConf CdrConfS; +PluginConf Pad1ConfS; +PluginConf Pad2ConfS; +PluginConf BiosConfS; + +void StartGui() { + Window = create_MainWindow(); + gtk_window_set_title(GTK_WINDOW(Window), "P©SX"); + + gtk_widget_show_all(Window); + gtk_main(); +} + +void RunGui() { + StartGui(); +} + +int destroy=0; + +void OnDestroy() { + if (!destroy) OnFile_Exit(); +} + +void ConfigurePlugins() { + if (!UseGui) return; + OnConf_Conf(); +} + +void ConfigureMemcards() { + OnConf_Mcds(); +} + +void OnRunExe_Ok() { + gchar *File; + char exe[256]; + + File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel)); + strcpy(exe, File); + gtk_widget_destroy(FileSel); + destroy=1; + gtk_widget_destroy(Window); + destroy=0; + gtk_main_quit(); + while (gtk_events_pending()) gtk_main_iteration(); + OpenPlugins(); + SysReset(); + needreset = 0; + Load(exe); + psxCpu->Execute(); +} + +void OnRunExe_Cancel() { + gtk_widget_destroy(FileSel); +} + +void OnFile_RunExe() { + GtkWidget *Ok,*Cancel; + + FileSel = gtk_file_selection_new("Select Psx Exe File"); + + Ok = GTK_FILE_SELECTION(FileSel)->ok_button; + gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnRunExe_Ok), NULL); + gtk_widget_show(Ok); + + Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button; + gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnRunExe_Cancel), NULL); + gtk_widget_show(Cancel); + + gtk_widget_show(FileSel); + gdk_window_raise(FileSel->window); +} + +void OnFile_RunCd() { + LoadCdBios = 0; + destroy=1; + gtk_widget_destroy(Window); + destroy=0; + gtk_main_quit(); + while (gtk_events_pending()) gtk_main_iteration(); + OpenPlugins(); + SysReset(); + needreset = 0; + CheckCdrom(); + if (LoadCdrom() == -1) { + ClosePlugins(); + SysMessage("Could not load Cdrom\n"); + return; + } + psxCpu->Execute(); +} + +void OnFile_RunCdBios() { + LoadCdBios = 1; + destroy=1; + gtk_widget_destroy(Window); + destroy=0; + gtk_main_quit(); + while (gtk_events_pending()) gtk_main_iteration(); + OpenPlugins(); + SysReset(); + needreset = 0; + CheckCdrom(); + psxCpu->Execute(); +} + +void OnFile_Exit() { + DIR *dir; + struct dirent *ent; + void *Handle; + char plugin[256]; + + // with this the problem with plugins that are linked with the pthread + // library is solved + + dir = opendir(Config.PluginsDir); + if (dir != NULL) { + while ((ent = readdir(dir)) != NULL) { + sprintf (plugin, "%s%s", Config.PluginsDir, ent->d_name); + + if (strstr(plugin, ".so") == NULL) continue; + Handle = dlopen(plugin, RTLD_NOW); + if (Handle == NULL) continue; + } + } + + printf ("P©SX Quitting\n"); + if (UseGui) gtk_main_quit(); + SysClose(); + if (UseGui) gtk_exit(0); + else exit(0); +} + +void OnEmu_Run() { + destroy=1; + gtk_widget_destroy(Window); + destroy=0; + gtk_main_quit(); + while (gtk_events_pending()) gtk_main_iteration(); + OpenPlugins(); + if (needreset) { SysReset(); needreset = 0; } + psxCpu->Execute(); +} + +void OnEmu_Reset() { + needreset = 1; +} + +void OnConf_Gpu() { + gtk_widget_set_sensitive(Window, FALSE); + GPU_configure(); + gtk_widget_set_sensitive(Window, TRUE); +} + +void OnConf_Spu() { + gtk_widget_set_sensitive(Window, FALSE); + SPU_configure(); + gtk_widget_set_sensitive(Window, TRUE); +} + +void OnConf_Cdr() { + gtk_widget_set_sensitive(Window, FALSE); + CDR_configure(); + gtk_widget_set_sensitive(Window, TRUE); +} + +void OnConf_Pads() { + gtk_widget_set_sensitive(Window, FALSE); + PAD1_configure(); + if (strcmp(Config.Pad1, Config.Pad2)) PAD2_configure(); + gtk_widget_set_sensitive(Window, TRUE); +} + +GtkWidget *McdDlg; +GtkWidget *Entry1,*Entry2; +GtkWidget *List1,*List2; +GtkWidget *BtnPaste; +GTimer *Gtimer; +int timer; +McdBlock Blocks[2][15]; +int IconC[2][15]; + +void SetIcon(short *icon, GtkWidget *List, int i) { + GdkPixmap *pixmap; + GdkImage *image; + GdkVisual *visual; + GdkGC *gc; + int x, y, c; + + visual = gdk_window_get_visual(McdDlg->window); + + if (visual->depth == 8) return; + + image = gdk_image_new(GDK_IMAGE_NORMAL, visual, 16, 16); + + for (y=0; y<16; y++) { + for (x=0; x<16; x++) { + c = icon[y*16+x]; + c = ((c&0x001f) << 10) | ((c&0x7c00) >> 10) | (c&0x03e0); + if (visual->depth == 16) + c = (c&0x001f) | ((c&0x7c00) << 1) | ((c&0x03e0) << 1); + else if (visual->depth == 24 || visual->depth == 32) + c = ((c&0x001f) << 3) | ((c&0x03e0) << 6) | ((c&0x7c00) << 9); + + gdk_image_put_pixel(image, x, y, c); + } + } + + pixmap = gdk_pixmap_new(McdDlg->window, 16, 16, visual->depth); + + gc = gdk_gc_new(pixmap); + gdk_draw_image(pixmap, gc, image, 0, 0, 0, 0, 16, 16); + gdk_gc_destroy(gc); + gdk_image_destroy(image); + + gtk_clist_set_pixmap(GTK_CLIST(List), i-1, 0, pixmap, NULL); +} + +void LoadListItems(int mcd, GtkWidget *List) { + int i; + + gtk_clist_clear(GTK_CLIST(List)); + + for (i=1; i<16; i++) { + McdBlock *Info; + gchar *text[5]; + + Info = &Blocks[mcd-1][i-1]; + IconC[mcd-1][i-1] = 0; + + if ((Info->Flags & 0xF0) == 0xA0) { + if ((Info->Flags & 0xF) >= 1 && + (Info->Flags & 0xF) <= 3) { + text[2] = "Deleted"; + } else text[2] = "Free"; + } else if ((Info->Flags & 0xF0) == 0x50) + text[2] = "Used"; + else { text[2] = "Free"; } + + text[0] = ""; + text[1] = Info->Title; + text[3] = Info->ID; + text[4] = Info->Name; + + gtk_clist_insert(GTK_CLIST(List), i-1, text); + + if (Info->IconCount == 0) continue; + + SetIcon(Info->Icon, List, i); + } +} + +void UpdateListItems(int mcd, GtkWidget *List) { + int i,j; + + for (i=1; i<16; i++) { + McdBlock *Info; + gchar *text[5]; + + Info = &Blocks[mcd-1][i-1]; + IconC[mcd-1][i-1] = 0; + + if ((Info->Flags & 0xF0) == 0xA0) { + if ((Info->Flags & 0xF) >= 1 && + (Info->Flags & 0xF) <= 3) { + text[2] = "Deleted"; + } else text[2] = "Free"; + } else if ((Info->Flags & 0xF0) == 0x50) + text[2] = "Used"; + else { text[2] = "Free"; } + + text[0] = ""; + text[1] = Info->Title; + text[3] = Info->ID; + text[4] = Info->Name; + + for (j=0; j<5; j++) + gtk_clist_set_text(GTK_CLIST(List), i-1, j, text[j]); + + if (Info->IconCount == 0) continue; + + SetIcon(Info->Icon, List, i); + } +} + +void LoadMcdDlg() { + int i; + + for (i=1; i<16; i++) GetMcdBlockInfo(1, i, &Blocks[0][i-1]); + for (i=1; i<16; i++) GetMcdBlockInfo(2, i, &Blocks[1][i-1]); + LoadListItems(1, List1); + LoadListItems(2, List2); +} + +void UpdateMcdDlg() { + int i; + + for (i=1; i<16; i++) GetMcdBlockInfo(1, i, &Blocks[0][i-1]); + for (i=1; i<16; i++) GetMcdBlockInfo(2, i, &Blocks[1][i-1]); + UpdateListItems(1, List1); + UpdateListItems(2, List2); +} + +void StopTimer() { + g_timer_stop(Gtimer); timer = 0; +} + +void OnMcd_Ok() { + char *tmp; + + StopTimer(); + + tmp = gtk_entry_get_text(GTK_ENTRY(Entry1)); + strcpy(Config.Mcd1, tmp); + tmp = gtk_entry_get_text(GTK_ENTRY(Entry2)); + strcpy(Config.Mcd2, tmp); + + SaveConfig(); + LoadMcds(Config.Mcd1, Config.Mcd2); + + gtk_widget_destroy(McdDlg); + if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); +// gtk_main_quit(); +} + +void OnMcd_Cancel() { + StopTimer(); + + LoadMcds(Config.Mcd1, Config.Mcd2); + + gtk_widget_destroy(McdDlg); + if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); +// gtk_main_quit(); +} + +void OnMcdFS1_Ok() { + gchar *File; + + File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel)); + gtk_entry_set_text(GTK_ENTRY(Entry1), File); + + LoadMcd(1, File); + UpdateMcdDlg(); + + gtk_widget_destroy(FileSel); +} + +void OnMcdFS2_Ok() { + gchar *File; + + File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel)); + gtk_entry_set_text(GTK_ENTRY(Entry2), File); + + LoadMcd(2, File); + UpdateMcdDlg(); + + gtk_widget_destroy(FileSel); +} + +void OnMcdFS_Cancel() { + gtk_widget_destroy(FileSel); +} + +void OnMcd_FS1() { + GtkWidget *Ok,*Cancel; + + FileSel = gtk_file_selection_new("Select Psx Mcd File"); + gtk_file_selection_set_filename(GTK_FILE_SELECTION(FileSel), gtk_entry_get_text(GTK_ENTRY(Entry1))); + + Ok = GTK_FILE_SELECTION(FileSel)->ok_button; + gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMcdFS1_Ok), NULL); + gtk_widget_show(Ok); + + Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button; + gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnMcdFS_Cancel), NULL); + gtk_widget_show(Cancel); + + gtk_widget_show(FileSel); + gdk_window_raise(FileSel->window); +} + +void OnMcd_FS2() { + GtkWidget *Ok,*Cancel; + + FileSel = gtk_file_selection_new("Select Psx Mcd File"); + gtk_file_selection_set_filename(GTK_FILE_SELECTION(FileSel), gtk_entry_get_text(GTK_ENTRY(Entry2))); + + Ok = GTK_FILE_SELECTION(FileSel)->ok_button; + gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMcdFS2_Ok), NULL); + gtk_widget_show(Ok); + + Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button; + gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnMcdFS_Cancel), NULL); + gtk_widget_show(Cancel); + + gtk_widget_show(FileSel); + gdk_window_raise(FileSel->window); +} + +GtkWidget *MsgBoxDlg; +int yes; + +void OnMsgBox_Yes() { + yes = 1; + gtk_widget_destroy(MsgBoxDlg); + gtk_main_quit(); +} + +void OnMsgBox_No() { + yes = 0; + gtk_widget_destroy(MsgBoxDlg); + gtk_main_quit(); +} + +int MessageBox(char *msg, char *title) { + GtkWidget *Ok,*Txt; + GtkWidget *Box,*Box1; + int w; + + if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0; + + w = strlen(msg) * 6 + 20; + + MsgBoxDlg = gtk_window_new (GTK_WINDOW_DIALOG); + gtk_widget_set_usize(MsgBoxDlg, w, 70); + gtk_window_set_position(GTK_WINDOW(MsgBoxDlg), GTK_WIN_POS_CENTER); + gtk_window_set_title(GTK_WINDOW(MsgBoxDlg), title); + gtk_container_set_border_width(GTK_CONTAINER(MsgBoxDlg), 0); + + Box = gtk_vbox_new(0, 0); + gtk_container_add(GTK_CONTAINER(MsgBoxDlg), Box); + gtk_widget_show(Box); + + Txt = gtk_label_new(msg); + + gtk_box_pack_start(GTK_BOX(Box), Txt, FALSE, FALSE, 5); + gtk_widget_show(Txt); + + Box1 = gtk_hbutton_box_new(); + gtk_box_pack_start(GTK_BOX(Box), Box1, FALSE, FALSE, 0); + gtk_widget_show(Box1); + + Ok = gtk_button_new_with_label("Yes"); + gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMsgBox_Yes), NULL); + gtk_container_add(GTK_CONTAINER(Box1), Ok); + GTK_WIDGET_SET_FLAGS(Ok, GTK_CAN_DEFAULT); + gtk_widget_show(Ok); + + Ok = gtk_button_new_with_label("No"); + gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMsgBox_No), NULL); + gtk_container_add(GTK_CONTAINER(Box1), Ok); + GTK_WIDGET_SET_FLAGS(Ok, GTK_CAN_DEFAULT); + gtk_widget_show(Ok); + + gtk_widget_show(MsgBoxDlg); + + gtk_main(); + + return yes; +} + +void OnMcd_Format1() { + char *str; + + if (MessageBox("Are you sure you want to format this Memory Card?", "Confirmation") == 0) return; + str = gtk_entry_get_text(GTK_ENTRY(Entry1)); + CreateMcd(str); + LoadMcd(1, str); + UpdateMcdDlg(); +} + +void OnMcd_Format2() { + char *str; + + if (MessageBox("Are you sure you want to format this Memory Card?", "Confirmation") == 0) return; + str = gtk_entry_get_text(GTK_ENTRY(Entry2)); + CreateMcd(str); + LoadMcd(2, str); + UpdateMcdDlg(); +} + +void OnMcd_Reload1() { + char *str; + + str = gtk_entry_get_text(GTK_ENTRY(Entry1)); + LoadMcd(1, str); + UpdateMcdDlg(); +} + +void OnMcd_Reload2() { + char *str; + + str = gtk_entry_get_text(GTK_ENTRY(Entry2)); + LoadMcd(2, str); + UpdateMcdDlg(); +} + +static int copy = 0, copymcd = 0; + +void OnMcd_CopyTo1() { + int i = GTK_CLIST(List2)->focus_row; + + copy = i; + copymcd = 1; + + gtk_widget_set_sensitive(BtnPaste, TRUE); +} + +void OnMcd_CopyTo2() { + int i = GTK_CLIST(List1)->focus_row; + + copy = i; + copymcd = 2; + + gtk_widget_set_sensitive(BtnPaste, TRUE); +} + +void OnMcd_Paste() { + int i; + char *str; + + if (MessageBox("Are you sure you want to paste this selection?", "Confirmation") == 0) return; + + if (copymcd == 1) { + str = gtk_entry_get_text(GTK_ENTRY(Entry1)); + i = GTK_CLIST(List1)->focus_row; + + // save dir data + save data + memcpy(Mcd1Data + (i+1) * 128, Mcd2Data + (copy+1) * 128, 128); + SaveMcd(str, Mcd1Data, (i+1) * 128, 128); + memcpy(Mcd1Data + (i+1) * 1024 * 8, Mcd2Data + (copy+1) * 1024 * 8, 1024 * 8); + SaveMcd(str, Mcd1Data, (i+1) * 1024 * 8, 1024 * 8); + } else { // 2 + str = gtk_entry_get_text(GTK_ENTRY(Entry2)); + i = GTK_CLIST(List2)->focus_row; + + // save dir data + save data + memcpy(Mcd2Data + (i+1) * 128, Mcd1Data + (copy+1) * 128, 128); + SaveMcd(str, Mcd2Data, (i+1) * 128, 128); + memcpy(Mcd2Data + (i+1) * 1024 * 8, Mcd1Data + (copy+1) * 1024 * 8, 1024 * 8); + SaveMcd(str, Mcd2Data, (i+1) * 1024 * 8, 1024 * 8); + } + + UpdateMcdDlg(); +} + +void OnMcd_Delete1() { + McdBlock *Info; + int mcd = 1; + int i, xor = 0, j; + unsigned char *data, *ptr; + char *str; + + str = gtk_entry_get_text(GTK_ENTRY(Entry1)); + i = GTK_CLIST(List1)->focus_row; + data = Mcd1Data; + + i++; + + ptr = data + i * 128; + + Info = &Blocks[mcd-1][i-1]; + + if ((Info->Flags & 0xF0) == 0xA0) { + if ((Info->Flags & 0xF) >= 1 && + (Info->Flags & 0xF) <= 3) { // deleted + *ptr = 0x50 | (Info->Flags & 0xF); + } else return; + } else if ((Info->Flags & 0xF0) == 0x50) { // used + *ptr = 0xA0 | (Info->Flags & 0xF); + } else { return; } + + for (j=0; j<127; j++) xor^=*ptr++; + *ptr = xor; + + SaveMcd(str, data, i * 128, 128); + UpdateMcdDlg(); +} + +void OnMcd_Delete2() { + McdBlock *Info; + int mcd = 2; + int i, xor = 0, j; + unsigned char *data, *ptr; + char *str; + + str = gtk_entry_get_text(GTK_ENTRY(Entry2)); + i = GTK_CLIST(List2)->focus_row; + data = Mcd2Data; + + i++; + + ptr = data + i * 128; + + Info = &Blocks[mcd-1][i-1]; + + if ((Info->Flags & 0xF0) == 0xA0) { + if ((Info->Flags & 0xF) >= 1 && + (Info->Flags & 0xF) <= 3) { // deleted + *ptr = 0x50 | (Info->Flags & 0xF); + } else return; + } else if ((Info->Flags & 0xF0) == 0x50) { // used + *ptr = 0xA0 | (Info->Flags & 0xF); + } else { return; } + + for (j=0; j<127; j++) xor^=*ptr++; + *ptr = xor; + + SaveMcd(str, data, i * 128, 128); + UpdateMcdDlg(); +} + +void UpdateMcdIcon(int mcd, GtkWidget *List) { + int i; + + for (i=1; i<16; i++) { + McdBlock *Info; + int *count; + + Info = &Blocks[mcd-1][i-1]; + count = &IconC[mcd-1][i-1]; + + if (Info->IconCount <= 1) continue; + + (*count)++; + if (*count == Info->IconCount) *count = 0; + + SetIcon(&Info->Icon[*count*16*16], List, i); + } +} + +void OnConf_Mcds() { + McdDlg = create_McdsDlg(); + gtk_window_set_title(GTK_WINDOW(McdDlg), "P©SX Memcard Manager"); + + Entry1 = lookup_widget(McdDlg, "GtkEntry_Mcd1"); + if (!strlen(Config.Mcd1)) strcpy(Config.Mcd1, "memcards/Mcd001.mcr"); + gtk_entry_set_text(GTK_ENTRY(Entry1), Config.Mcd1); + + Entry2 = lookup_widget(McdDlg, "GtkEntry_Mcd2"); + if (!strlen(Config.Mcd2)) strcpy(Config.Mcd2, "memcards/Mcd002.mcr"); + gtk_entry_set_text(GTK_ENTRY(Entry2), Config.Mcd2); + + List1 = lookup_widget(McdDlg, "GtkCList_McdList1"); + List2 = lookup_widget(McdDlg, "GtkCList_McdList2"); + + BtnPaste = lookup_widget(McdDlg, "GtkButton_McdPaste"); + gtk_widget_set_sensitive(BtnPaste, FALSE); + + gtk_clist_set_column_justification(GTK_CLIST(List1), 0, GTK_JUSTIFY_CENTER); + gtk_clist_set_column_justification(GTK_CLIST(List2), 0, GTK_JUSTIFY_CENTER); + gtk_clist_set_column_justification(GTK_CLIST(List1), 2, GTK_JUSTIFY_CENTER); + gtk_clist_set_column_justification(GTK_CLIST(List2), 2, GTK_JUSTIFY_CENTER); + + gtk_widget_show_all(McdDlg); + + LoadMcdDlg(); + + if (Window != NULL) gtk_widget_set_sensitive(Window, FALSE); + + Gtimer = g_timer_new(); timer = 1; + + while (gtk_events_pending()) gtk_main_iteration(); + + while (timer) { + unsigned long usecs; + + g_timer_elapsed(Gtimer, &usecs); + if (usecs > 250000) { + UpdateMcdIcon(1, List1); + UpdateMcdIcon(2, List2); + g_timer_reset(Gtimer); + } + + while (gtk_events_pending()) gtk_main_iteration(); + } +} + +GtkWidget *CpuDlg; +GtkWidget *PsxCombo; +GList *psxglist; +char *psxtypes[] = { + "NTSC", + "PAL" +}; + +void OnCpu_Ok() { + GtkWidget *Btn; + char *tmp; + long t; + + tmp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(PsxCombo)->entry)); + + if (!strcmp("NTSC",tmp)) Config.PsxType = 0; + else Config.PsxType = 1; // pal + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_Xa"); + Config.Xa = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_Sio"); + Config.Sio = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_Mdec"); + Config.Mdec = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_Cdda"); + Config.Cdda = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_PsxAuto"); + Config.PsxAuto = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); + + t = Config.Cpu; + Btn = lookup_widget(CpuDlg, "GtkCheckButton_Cpu"); + Config.Cpu = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); + if (t != Config.Cpu) { + psxCpu->Shutdown(); + if (Config.Cpu) + psxCpu = &psxInt; + else psxCpu = &psxRec; + if (psxCpu->Init() == -1) { + SysClose(); + exit(1); + } + psxCpu->Reset(); + } + + 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)); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_SpuIrq"); + Config.SpuIrq = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_CdTiming"); + Config.CdTiming = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Btn)); + + gtk_widget_destroy(CpuDlg); + + SaveConfig(); + if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); + gtk_main_quit(); +} + +void OnCpu_Cancel() { + gtk_widget_destroy(CpuDlg); + if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); + gtk_main_quit(); +} + + +void OnConf_Cpu() { + GtkWidget *Btn; + int i; + + CpuDlg = create_CpuDlg(); + gtk_window_set_title(GTK_WINDOW(CpuDlg), "P©SX Configuration"); + + psxglist = NULL; + for (i=0;i<2;i++) + psxglist = g_list_append(psxglist, psxtypes[i]); + PsxCombo = lookup_widget(CpuDlg, "GtkCombo_PsxType"); + gtk_combo_set_popdown_strings(GTK_COMBO(PsxCombo), psxglist); + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(PsxCombo)->entry), psxtypes[Config.PsxType]); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_Xa"); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Xa); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_Sio"); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Sio); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_Mdec"); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Mdec); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_Cdda"); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Cdda); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_PsxAuto"); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.PsxAuto); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_Cpu"); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Cpu); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_CpuLog"); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.Log); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_PsxOut"); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.PsxOut); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_SpuIrq"); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.SpuIrq); + + Btn = lookup_widget(CpuDlg, "GtkCheckButton_CdTiming"); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Btn), Config.CdTiming); + + gtk_widget_show_all(CpuDlg); + if (Window != NULL) gtk_widget_set_sensitive(Window, FALSE); + gtk_main(); +} + +#define FindComboText(combo,list,conf) \ + if (strlen(conf) > 0) { \ + int i; \ + for (i=2;i<255;i+=2) { \ + if (!strcmp(conf, list[i-2])) { \ + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), list[i-1]); \ + break; \ + } \ + } \ + } + +#define GetComboText(combo,list,conf) \ + { \ + int i; \ + char *tmp = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry)); \ + for (i=2;i<255;i+=2) { \ + if (!strcmp(tmp, list[i-1])) { \ + strcpy(conf, list[i-2]); \ + break; \ + } \ + } \ + } + +void OnConfConf_Ok() { + GetComboText(GpuConfS.Combo, GpuConfS.plist, Config.Gpu); + GetComboText(SpuConfS.Combo, SpuConfS.plist, Config.Spu); + GetComboText(CdrConfS.Combo, CdrConfS.plist, Config.Cdr); + GetComboText(Pad1ConfS.Combo, Pad1ConfS.plist, Config.Pad1); + GetComboText(Pad2ConfS.Combo, Pad2ConfS.plist, Config.Pad2); + GetComboText(BiosConfS.Combo, BiosConfS.plist, Config.Bios); + + SaveConfig(); + + ReleasePlugins(); + LoadPlugins(); + + needreset = 1; + gtk_widget_destroy(ConfDlg); + if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); + gtk_main_quit(); +} + +void OnConfConf_Cancel() { + gtk_widget_destroy(ConfDlg); + if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); + gtk_main_quit(); +} + +#define ConfPlugin(src, confs, plugin, name) \ + void *drv; \ + src conf; \ + char file[256]; \ + \ + GetComboText(confs.Combo, confs.plist, plugin); \ + strcpy(file, Config.PluginsDir); \ + strcat(file, plugin); \ + gtk_widget_set_sensitive(ConfDlg, FALSE); \ + drv = SysLoadLibrary(file); \ + if (drv == NULL) return; \ + conf = (src) SysLoadSym(drv, name); \ + if (SysLibError() == NULL) conf(); \ + else SysMessage("Plugin doesn't needs to be configured"); \ + SysCloseLibrary(drv); \ + gtk_widget_set_sensitive(ConfDlg, TRUE); + +#define TestPlugin(src, confs, plugin, name) \ + void *drv; \ + src conf; \ + int ret = 0; \ + char file[256]; \ + \ + GetComboText(confs.Combo, confs.plist, plugin); \ + strcpy(file, Config.PluginsDir); \ + strcat(file, plugin); \ + gtk_widget_set_sensitive(ConfDlg, FALSE); \ + drv = SysLoadLibrary(file); \ + if (drv == NULL) return; \ + conf = (src) SysLoadSym(drv, name); \ + if (SysLibError() == NULL) ret = conf(); \ + SysCloseLibrary(drv); \ + SysMessage("This plugin reports that should %swork correctly", ret == 0 ? "" : "not "); \ + gtk_widget_set_sensitive(ConfDlg, TRUE); + +void OnConfConf_GpuConf() { + ConfPlugin(GPUconfigure, GpuConfS, Config.Gpu, "GPUconfigure"); +} + +void OnConfConf_GpuTest() { + TestPlugin(GPUtest, GpuConfS, Config.Gpu, "GPUtest"); +} + +void OnConfConf_GpuAbout() { + ConfPlugin(GPUabout, GpuConfS, Config.Gpu, "GPUabout"); +} + +void OnConfConf_SpuConf() { + ConfPlugin(SPUconfigure, SpuConfS, Config.Spu, "SPUconfigure"); +} + +void OnConfConf_SpuTest() { + TestPlugin(SPUtest, SpuConfS, Config.Spu, "SPUtest"); +} + +void OnConfConf_SpuAbout() { + ConfPlugin(SPUabout, SpuConfS, Config.Spu, "SPUabout"); +} + +void OnConfConf_CdrConf() { + ConfPlugin(CDRconfigure, CdrConfS, Config.Cdr, "CDRconfigure"); +} + +void OnConfConf_CdrTest() { + TestPlugin(CDRtest, CdrConfS, Config.Cdr, "CDRtest"); +} + +void OnConfConf_CdrAbout() { + ConfPlugin(CDRabout, CdrConfS, Config.Cdr, "CDRabout"); +} + +void OnConfConf_Pad1Conf() { + ConfPlugin(PADconfigure, Pad1ConfS, Config.Pad1, "PADconfigure"); +} + +void OnConfConf_Pad1Test() { + TestPlugin(PADtest, Pad1ConfS, Config.Pad1, "PADtest"); +} + +void OnConfConf_Pad1About() { + ConfPlugin(PADabout, Pad1ConfS, Config.Pad1, "PADabout"); +} + +void OnConfConf_Pad2Conf() { + ConfPlugin(PADconfigure, Pad2ConfS, Config.Pad2, "PADconfigure"); +} + +void OnConfConf_Pad2Test() { + TestPlugin(PADtest, Pad2ConfS, Config.Pad2, "PADtest"); +} + +void OnConfConf_Pad2About() { + ConfPlugin(PADabout, Pad2ConfS, Config.Pad2, "PADabout"); +} + +void OnPluginsPath_Ok() { + gchar *File; + + File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel)); + strcpy(Config.PluginsDir, File); + if (Config.PluginsDir[strlen(Config.PluginsDir)-1] != '/') + strcat(Config.PluginsDir, "/"); + + FindPlugins(); + + gtk_widget_destroy(FileSel); +} + +void OnPluginsPath_Cancel() { + gtk_widget_destroy(FileSel); +} + +void OnConfConf_PluginsPath() { + GtkWidget *Ok,*Cancel; + + FileSel = gtk_file_selection_new("Select Plugins Directory"); + + Ok = GTK_FILE_SELECTION(FileSel)->ok_button; + gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnPluginsPath_Ok), NULL); + gtk_widget_show(Ok); + + Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button; + gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnPluginsPath_Cancel), NULL); + gtk_widget_show(Cancel); + + gtk_widget_show(FileSel); + gdk_window_raise(FileSel->window); +} + +void OnBiosPath_Ok() { + gchar *File; + + File = gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSel)); + strcpy(Config.BiosDir, File); + if (Config.BiosDir[strlen(Config.BiosDir)-1] != '/') + strcat(Config.BiosDir, "/"); + + FindPlugins(); + + gtk_widget_destroy(FileSel); +} + +void OnBiosPath_Cancel() { + gtk_widget_destroy(FileSel); +} + +void OnConfConf_BiosPath() { + GtkWidget *Ok,*Cancel; + + FileSel = gtk_file_selection_new("Select Bios Directory"); + + Ok = GTK_FILE_SELECTION(FileSel)->ok_button; + gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnBiosPath_Ok), NULL); + gtk_widget_show(Ok); + + Cancel = GTK_FILE_SELECTION(FileSel)->cancel_button; + gtk_signal_connect (GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(OnBiosPath_Cancel), NULL); + gtk_widget_show(Cancel); + + gtk_widget_show(FileSel); + gdk_window_raise(FileSel->window); +} + +void OnConf_Conf() { + ConfDlg = create_ConfDlg(); + gtk_window_set_title(GTK_WINDOW(ConfDlg), "P©SX Configuration"); + + FindPlugins(); + + gtk_widget_show_all(ConfDlg); + 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() { + gtk_widget_destroy(DebugDlg); + if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); + gtk_main_quit(); +} + +void OnHelp_Help() { +} + +void OnHelpAbout_Ok() { + gtk_widget_destroy(AboutDlg); + if (Window != NULL) gtk_widget_set_sensitive(Window, TRUE); + gtk_main_quit(); +} + +void OnHelp_About() { + GtkWidget *Label; + + AboutDlg = create_AboutDlg(); + gtk_window_set_title(GTK_WINDOW(AboutDlg), "About P©SX"); + + Label = lookup_widget(AboutDlg, "GtkAbout_LabelVersion"); + gtk_label_set_text(GTK_LABEL(Label), + "P©SX For Linux\n" + "Version " PCSX_VERSION); + + Label = lookup_widget(AboutDlg, "GtkAbout_LabelAuthors"); + gtk_label_set_text(GTK_LABEL(Label), + "PCSX a psx emulator\n\n" + "written by:\n" + "main coder: linuzappz\n" + "co-coders: shadow\n" + "ex-coders: Nocomp, Pete Bernett, nik3d\n" + "Webmaster: AkumaX"); + + Label = lookup_widget(AboutDlg, "GtkAbout_LabelGreets"); + gtk_label_set_text(GTK_LABEL(Label), + "Greets to: Duddie, Tratax, Kazzuya, JNS, Bobbi, Psychojak and Shunt\n" + "Special thanks to:\n" + "Twin (we Love you twin0r), Roor (love for you too),\n" + "calb (Thanks for help :) ), now3d (for great help to my psxdev stuff :) )"); + + gtk_widget_show_all(AboutDlg); + if (Window != NULL) gtk_widget_set_sensitive(Window, FALSE); + gtk_main(); +} + +#define ComboAddPlugin(type) { \ + ##type##ConfS.plugins+=2; \ + strcpy(##type##ConfS.plist[##type##ConfS.plugins-1], name); \ + strcpy(##type##ConfS.plist[##type##ConfS.plugins-2], ent->d_name); \ + ##type##ConfS.glist = g_list_append(##type##ConfS.glist, ##type##ConfS.plist[##type##ConfS.plugins-1]); \ +} + +#define ConfCreatePConf(name, type) \ + if (type##ConfS.glist != NULL) { \ + type##ConfS.Combo = lookup_widget(ConfDlg, "GtkCombo_" name); \ + gtk_combo_set_popdown_strings(GTK_COMBO(type##ConfS.Combo), type##ConfS.glist); \ + FindComboText(type##ConfS.Combo, type##ConfS.plist, Config.##type##); \ + } + +void FindPlugins() { + DIR *dir; + struct dirent *ent; + void *Handle; + char plugin[256],name[256]; + + GpuConfS.plugins = 0; SpuConfS.plugins = 0; CdrConfS.plugins = 0; + Pad1ConfS.plugins = 0; Pad2ConfS.plugins = 0; BiosConfS.plugins = 0; + GpuConfS.glist = NULL; SpuConfS.glist = NULL; CdrConfS.glist = NULL; + Pad1ConfS.glist = NULL; Pad2ConfS.glist = NULL; BiosConfS.glist = NULL; + + dir = opendir(Config.PluginsDir); + if (dir == NULL) { + SysMessage("Could not open '%s' directory\n", Config.PluginsDir); + return; + } + while ((ent = readdir(dir)) != NULL) { + long type,v; + + sprintf(plugin, "%s%s", Config.PluginsDir, ent->d_name); + + if (strstr(plugin, ".so") == NULL) continue; + Handle = dlopen(plugin, RTLD_NOW); + if (Handle == NULL) continue; + + PSE_getLibType = (PSEgetLibType) dlsym(Handle, "PSEgetLibType"); + if (dlerror() != NULL) { + if (strstr(plugin, "gpu") != NULL) type = PSE_LT_GPU; + else if (strstr(plugin, "cdr") != NULL) type = PSE_LT_CDR; + else if (strstr(plugin, "spu") != NULL) type = PSE_LT_SPU; + else if (strstr(plugin, "pad") != NULL) type = PSE_LT_PAD; + else continue; + } + else type = PSE_getLibType(); + + PSE_getLibName = (PSEgetLibName) dlsym(Handle, "PSEgetLibName"); + if (dlerror() == NULL) { + sprintf(name, "%s", PSE_getLibName()); + PSE_getLibVersion = (PSEgetLibVersion) dlsym(Handle, "PSEgetLibVersion"); + if (dlerror() == NULL) { + char ver[32]; + + v = PSE_getLibVersion(); + sprintf(ver, " %ld.%ld.%ld",v>>16,(v>>8)&0xff,v&0xff); + strcat(name, ver); + } + } + else strcpy(name, ent->d_name); + + if (type & PSE_LT_CDR) { + ComboAddPlugin(Cdr); + } + if (type & PSE_LT_GPU) { + ComboAddPlugin(Gpu); + } + if (type & PSE_LT_SPU) { + ComboAddPlugin(Spu); + } + if (type & PSE_LT_PAD) { + PADquery query = (PADquery)dlsym(Handle, "PADquery"); + if (query() & 0x1) { + ComboAddPlugin(Pad1); + } + if (query() & 0x2) { + ComboAddPlugin(Pad2); + } + } + } + closedir(dir); + + ConfCreatePConf("Gpu", Gpu); + ConfCreatePConf("Spu", Spu); + ConfCreatePConf("Pad1", Pad1); + ConfCreatePConf("Pad2", Pad2); + ConfCreatePConf("Cdr", Cdr); + + BiosConfS.plugins+=2; + strcpy(BiosConfS.plist[BiosConfS.plugins-1], "Internal HLE Bios"); + strcpy(BiosConfS.plist[BiosConfS.plugins-2], "HLE"); + BiosConfS.glist = g_list_append(BiosConfS.glist, BiosConfS.plist[BiosConfS.plugins-1]); + + dir = opendir(Config.BiosDir); + if (dir == NULL) { + SysMessage("Could not open '%s' directory\n", Config.BiosDir); + return; + } + + while ((ent = readdir(dir)) != NULL) { + struct stat buf; + + sprintf (plugin, "%s%s", Config.BiosDir, ent->d_name); + if (stat(plugin, &buf) == -1) continue; + if (buf.st_size != (1024*512)) continue; + + BiosConfS.plugins+=2; + strcpy(BiosConfS.plist[BiosConfS.plugins-1], ent->d_name); + strcpy(BiosConfS.plist[BiosConfS.plugins-2], ent->d_name); + BiosConfS.glist = g_list_append(BiosConfS.glist, BiosConfS.plist[BiosConfS.plugins-1]); + } + closedir(dir); + + ConfCreatePConf("Bios", Bios); +} + +GtkWidget *MsgDlg; + +void OnMsg_Ok() { + gtk_widget_destroy(MsgDlg); + gtk_main_quit(); +} + +void SysMessage(char *fmt, ...) { + GtkWidget *Ok,*Txt; + GtkWidget *Box,*Box1; + va_list list; + char msg[512]; + + va_start(list, fmt); + vsprintf(msg, fmt, list); + va_end(list); + + if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0; + + if (!UseGui) { printf ("%s\n",msg); return; } + + MsgDlg = gtk_window_new (GTK_WINDOW_DIALOG); + gtk_window_set_position(GTK_WINDOW(MsgDlg), GTK_WIN_POS_CENTER); + gtk_window_set_title(GTK_WINDOW(MsgDlg), "P©SX Msg"); + gtk_container_set_border_width(GTK_CONTAINER(MsgDlg), 5); + + Box = gtk_vbox_new(5, 0); + gtk_container_add(GTK_CONTAINER(MsgDlg), Box); + gtk_widget_show(Box); + + Txt = gtk_label_new(msg); + + gtk_box_pack_start(GTK_BOX(Box), Txt, FALSE, FALSE, 5); + gtk_widget_show(Txt); + + Box1 = gtk_hbutton_box_new(); + gtk_box_pack_start(GTK_BOX(Box), Box1, FALSE, FALSE, 0); + gtk_widget_show(Box1); + + Ok = gtk_button_new_with_label("Ok"); + gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMsg_Ok), NULL); + gtk_container_add(GTK_CONTAINER(Box1), Ok); + GTK_WIDGET_SET_FLAGS(Ok, GTK_CAN_DEFAULT); + gtk_widget_show(Ok); + + gtk_widget_show(MsgDlg); + + gtk_main(); +} + diff --git a/PcsxSrc/Linux/Linux.h b/PcsxSrc/Linux/Linux.h index 57a0d8c..581e008 100644 --- a/PcsxSrc/Linux/Linux.h +++ b/PcsxSrc/Linux/Linux.h @@ -1,39 +1,39 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __LINUX_H__ -#define __LINUX_H__ - -#include "PsxCommon.h" -#include "Plugin.h" - -extern int UseGui; -char cfgfile[256]; - -int LoadConfig(); -void SaveConfig(); - -void StartGui(); -void RunGui(); - -void ConfigurePlugins(); -void ConfigureMemcards(); - -void PADhandleKey(int key); - -#endif /* __LINUX_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __LINUX_H__ +#define __LINUX_H__ + +#include "PsxCommon.h" +#include "Plugin.h" + +extern int UseGui; +char cfgfile[256]; + +int LoadConfig(); +void SaveConfig(); + +void StartGui(); +void RunGui(); + +void ConfigurePlugins(); +void ConfigureMemcards(); + +void PADhandleKey(int key); + +#endif /* __LINUX_H__ */ diff --git a/PcsxSrc/Linux/LnxMain.c b/PcsxSrc/Linux/LnxMain.c index e0012f6..ff3e065 100644 --- a/PcsxSrc/Linux/LnxMain.c +++ b/PcsxSrc/Linux/LnxMain.c @@ -1,197 +1,197 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Linux.h" -#include "Sio.h" - -static char PcsxHelp[] = { - "Pcsx " PCSX_VERSION "\n" - " pcsx [options] [file]\n" - "\toptions:\n" - "\t-runcd\t\tRuns CdRom\n" - "\t-runcdbios\tRuns CdRom Through Bios\n" - "\t-nogui\t\tDon't open GtkGui\n" - "\t-cfg FILE\tLoads desired configuration file (def:Pcsx.cfg)\n" - "\t-psxout\t\tEnable psx output\n" - "\t-load STATENUM\tLoads savestate STATENUM (1-5)\n" - "\t-h -help\tThis help\n" - "\tfile\t\tLoads file\n" -}; - -int UseGui = 1; - -int main(int argc, char *argv[]) { - char *file = NULL; - int runcd = 0; - int loadst = 0; - int i; - - strcpy(cfgfile, "Pcsx.cfg"); - - for (i=1; iExecute(); - - return 0; -} - -int SysInit() { - -#ifdef GTE_DUMP - gteLog = fopen("gteLog.txt","wb"); - setvbuf(gteLog, NULL, _IONBF, 0); -#endif - -#ifdef EMU_LOG -#ifndef LOG_STDOUT - emuLog = fopen("emuLog.txt","wb"); -#else - emuLog = stdout; -#endif - setvbuf(emuLog, NULL, _IONBF, 0); -#endif - - psxInit(); - - LoadPlugins(); - LoadMcds(Config.Mcd1, Config.Mcd2); - - return 0; -} - -void SysReset() { - psxReset(); -} - -void SysClose() { - psxShutdown(); - ReleasePlugins(); - - if (emuLog != NULL) fclose(emuLog); -} - -void SysPrintf(char *fmt, ...) { - va_list list; - char msg[512]; - - va_start(list, fmt); - vsprintf(msg, fmt, list); - va_end(list); - - if (Config.PsxOut) printf ("%s", msg); -#ifdef EMU_LOG - fprintf(emuLog, "%s", msg); -#endif -} - -void *SysLoadLibrary(char *lib) { - return dlopen(lib, RTLD_NOW); -} - -void *SysLoadSym(void *lib, char *sym) { - return dlsym(lib, sym); -} - -char *SysLibError() { - return dlerror(); -} - -void SysCloseLibrary(void *lib) { - dlclose(lib); -} - -void SysUpdate() { - PADhandleKey(PAD1_keypressed()); - PADhandleKey(PAD2_keypressed()); -} - -void SysRunGui() { - RunGui(); +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Linux.h" +#include "Sio.h" + +static char PcsxHelp[] = { + "Pcsx " PCSX_VERSION "\n" + " pcsx [options] [file]\n" + "\toptions:\n" + "\t-runcd\t\tRuns CdRom\n" + "\t-runcdbios\tRuns CdRom Through Bios\n" + "\t-nogui\t\tDon't open GtkGui\n" + "\t-cfg FILE\tLoads desired configuration file (def:Pcsx.cfg)\n" + "\t-psxout\t\tEnable psx output\n" + "\t-load STATENUM\tLoads savestate STATENUM (1-5)\n" + "\t-h -help\tThis help\n" + "\tfile\t\tLoads file\n" +}; + +int UseGui = 1; + +int main(int argc, char *argv[]) { + char *file = NULL; + int runcd = 0; + int loadst = 0; + int i; + + strcpy(cfgfile, "Pcsx.cfg"); + + for (i=1; iExecute(); + + return 0; +} + +int SysInit() { + +#ifdef GTE_DUMP + gteLog = fopen("gteLog.txt","wb"); + setvbuf(gteLog, NULL, _IONBF, 0); +#endif + +#ifdef EMU_LOG +#ifndef LOG_STDOUT + emuLog = fopen("emuLog.txt","wb"); +#else + emuLog = stdout; +#endif + setvbuf(emuLog, NULL, _IONBF, 0); +#endif + + psxInit(); + + LoadPlugins(); + LoadMcds(Config.Mcd1, Config.Mcd2); + + return 0; +} + +void SysReset() { + psxReset(); +} + +void SysClose() { + psxShutdown(); + ReleasePlugins(); + + if (emuLog != NULL) fclose(emuLog); +} + +void SysPrintf(char *fmt, ...) { + va_list list; + char msg[512]; + + va_start(list, fmt); + vsprintf(msg, fmt, list); + va_end(list); + + if (Config.PsxOut) printf ("%s", msg); +#ifdef EMU_LOG + fprintf(emuLog, "%s", msg); +#endif +} + +void *SysLoadLibrary(char *lib) { + return dlopen(lib, RTLD_NOW); +} + +void *SysLoadSym(void *lib, char *sym) { + return dlsym(lib, sym); +} + +char *SysLibError() { + return dlerror(); +} + +void SysCloseLibrary(void *lib) { + dlclose(lib); +} + +void SysUpdate() { + PADhandleKey(PAD1_keypressed()); + PADhandleKey(PAD2_keypressed()); +} + +void SysRunGui() { + RunGui(); } \ No newline at end of file diff --git a/PcsxSrc/Linux/Plugin.c b/PcsxSrc/Linux/Plugin.c index c305950..a1cbb2b 100644 --- a/PcsxSrc/Linux/Plugin.c +++ b/PcsxSrc/Linux/Plugin.c @@ -1,208 +1,208 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include -#include -#include - -#include "Linux.h" -#include "plugins.h" -#include "Spu.h" - -void RunGui(); -void OnFile_Exit(); - -extern GPUopen GPU_open; - -unsigned long gpuDisp; - -extern CDRplay CDR_play; -extern CDRstop CDR_stop; - -extern SPUopen SPU_open; - -long SPU__open(void) { - return SPU_open(); -} - -extern PADopen PAD1_open; -extern PADreadPort1 PAD1_readPort1; -extern PADopen PAD2_open; -extern PADreadPort2 PAD2_readPort2; - -int StatesC = 0; -extern char CdromId[256]; -extern int UseGui; -int cdOpenCase = 0; - -void PADhandleKey(int key) { - char Text[255]; - int ret; - - switch (key) { - case 0: break; - case XK_F1: - sprintf (Text, "sstates/%s.%3.3d", CdromId, StatesC); - GPU_freeze(2, (GPUFreeze_t *)&StatesC); - ret = SaveState(Text); - sprintf (Text, "*PCSX*: %s State %d", !ret ? "Saved" : "Error Saving", StatesC+1); - GPU_displayText(Text); - break; - case XK_F2: - if (StatesC < 4) StatesC++; - else StatesC = 0; - GPU_freeze(2, (GPUFreeze_t *)&StatesC); - break; - case XK_F3: - sprintf (Text, "sstates/%s.%3.3d", CdromId, StatesC); - ret = LoadState(Text); - sprintf (Text, "*PCSX*: %s State %d", !ret ? "Loaded" : "Error Loading", StatesC+1); - GPU_displayText(Text); - break; - case XK_F4: - { - gzFile f; - static int ShowPic; - - if (!ShowPic) { - unsigned char *pMem; - - sprintf (Text, "sstates/%s.%3.3d", CdromId, StatesC); - f = gzopen(Text, "rb"); - if (f == NULL) break; - - gzseek(f, 32, SEEK_SET); // skip header - - pMem = (unsigned char *) malloc(128*96*3); - gzread(f, pMem, 128*96*3); - gzclose(f); - GPU_freeze(2, (GPUFreeze_t *)&StatesC); - GPU_showScreenPic(pMem); - free(pMem); - ShowPic = 1; - } - else { GPU_showScreenPic(NULL); ShowPic = 0; } - } - break; - case XK_F5: - Config.Sio ^= 0x1; - sprintf (Text, "*PCSX*: Sio Irq %sAlways Enabled", Config.Sio ? "" : "Not "); - GPU_displayText(Text); - break; - case XK_F6: - Config.Mdec ^= 0x1; - sprintf (Text, "*PCSX*: Black&White Mdecs Only %sabled", Config.Mdec ? "En" : "Dis"); - GPU_displayText(Text); - break; - case XK_F7: - Config.Xa ^= 0x1; - sprintf (Text, "*PCSX*: Xa %sabled", !Config.Xa ? "En" : "Dis"); - GPU_displayText(Text); - break; - case XK_F8: - GPU_makeSnapshot(); - break; - case XK_F9: - cdOpenCase = 1; - break; - case XK_F10: - cdOpenCase = 0; - break; - case XK_Escape: - ClosePlugins(); - if (!UseGui) OnFile_Exit(); - RunGui(); - break; - default: GPU_keypressed(key); - } -} - -long PAD1__open(void) { - return PAD1_open(&gpuDisp); -} - -long PAD2__open(void) { - return PAD2_open(&gpuDisp); -} - -void OnFile_Exit(); - -void SignalExit(int sig) { - ClosePlugins(); - OnFile_Exit(); -} - -void SPUirq(void); - -void OpenPlugins() { - int ret; - - signal(SIGINT, SignalExit); - signal(SIGPIPE, SignalExit); - ret = CDR_open(); - if (ret != 0) { SysMessage ("Error Opening CDR Plugin\n"); exit(1); } - ret = SPU_open(); - if (ret != 0) { SysMessage ("Error Opening SPU Plugin\n"); exit(1); } - SPU_registerCallback(SPUirq); - ret = GPU_open(&gpuDisp, "P©SX", NULL); - if (ret != 0) { SysMessage ("Error Opening GPU Plugin\n"); exit(1); } - ret = PAD1_open(&gpuDisp); - if (ret != 0) { SysMessage ("Error Opening PAD1 Plugin\n"); exit(1); } - ret = PAD2_open(&gpuDisp); - if (ret != 0) { SysMessage ("Error Opening PAD2 Plugin\n"); exit(1); } -} - -void ClosePlugins() { - int ret; - - signal(SIGINT, SIG_DFL); - signal(SIGPIPE, SIG_DFL); - ret = CDR_close(); - if (ret != 0) { SysMessage ("Error Closing CDR Plugin\n"); exit(1); } - ret = SPU_close(); - if (ret != 0) { SysMessage ("Error Closing SPU Plugin\n"); exit(1); } - ret = PAD1_close(); - if (ret != 0) { SysMessage ("Error Closing PAD1 Plugin\n"); exit(1); } - ret = PAD2_close(); - if (ret != 0) { SysMessage ("Error Closing PAD2 Plugin\n"); exit(1); } - ret = GPU_close(); - if (ret != 0) { SysMessage ("Error Closing GPU Plugin\n"); exit(1); } -} - -void ResetPlugins() { - int ret; - - CDR_shutdown(); - GPU_shutdown(); - SPU_shutdown(); - PAD1_shutdown(); - PAD2_shutdown(); - - ret = CDR_init(); - if (ret != 0) { SysMessage ("CDRinit error : %d\n",ret); exit(1); } - ret = GPU_init(); - if (ret != 0) { SysMessage ("GPUinit error : %d\n",ret); exit(1); } - ret = SPU_init(); - if (ret != 0) { SysMessage ("SPUinit error : %d\n",ret); exit(1); } - ret = PAD1_init(1); - if (ret != 0) { SysMessage ("PAD1init error : %d\n",ret); exit(1); } - ret = PAD2_init(2); - if (ret != 0) { SysMessage ("PAD2init error : %d\n",ret); exit(1); } -} +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include +#include +#include + +#include "Linux.h" +#include "plugins.h" +#include "Spu.h" + +void RunGui(); +void OnFile_Exit(); + +extern GPUopen GPU_open; + +unsigned long gpuDisp; + +extern CDRplay CDR_play; +extern CDRstop CDR_stop; + +extern SPUopen SPU_open; + +long SPU__open(void) { + return SPU_open(); +} + +extern PADopen PAD1_open; +extern PADreadPort1 PAD1_readPort1; +extern PADopen PAD2_open; +extern PADreadPort2 PAD2_readPort2; + +int StatesC = 0; +extern char CdromId[256]; +extern int UseGui; +int cdOpenCase = 0; + +void PADhandleKey(int key) { + char Text[255]; + int ret; + + switch (key) { + case 0: break; + case XK_F1: + sprintf (Text, "sstates/%s.%3.3d", CdromId, StatesC); + GPU_freeze(2, (GPUFreeze_t *)&StatesC); + ret = SaveState(Text); + sprintf (Text, "*PCSX*: %s State %d", !ret ? "Saved" : "Error Saving", StatesC+1); + GPU_displayText(Text); + break; + case XK_F2: + if (StatesC < 4) StatesC++; + else StatesC = 0; + GPU_freeze(2, (GPUFreeze_t *)&StatesC); + break; + case XK_F3: + sprintf (Text, "sstates/%s.%3.3d", CdromId, StatesC); + ret = LoadState(Text); + sprintf (Text, "*PCSX*: %s State %d", !ret ? "Loaded" : "Error Loading", StatesC+1); + GPU_displayText(Text); + break; + case XK_F4: + { + gzFile f; + static int ShowPic; + + if (!ShowPic) { + unsigned char *pMem; + + sprintf (Text, "sstates/%s.%3.3d", CdromId, StatesC); + f = gzopen(Text, "rb"); + if (f == NULL) break; + + gzseek(f, 32, SEEK_SET); // skip header + + pMem = (unsigned char *) malloc(128*96*3); + gzread(f, pMem, 128*96*3); + gzclose(f); + GPU_freeze(2, (GPUFreeze_t *)&StatesC); + GPU_showScreenPic(pMem); + free(pMem); + ShowPic = 1; + } + else { GPU_showScreenPic(NULL); ShowPic = 0; } + } + break; + case XK_F5: + Config.Sio ^= 0x1; + sprintf (Text, "*PCSX*: Sio Irq %sAlways Enabled", Config.Sio ? "" : "Not "); + GPU_displayText(Text); + break; + case XK_F6: + Config.Mdec ^= 0x1; + sprintf (Text, "*PCSX*: Black&White Mdecs Only %sabled", Config.Mdec ? "En" : "Dis"); + GPU_displayText(Text); + break; + case XK_F7: + Config.Xa ^= 0x1; + sprintf (Text, "*PCSX*: Xa %sabled", !Config.Xa ? "En" : "Dis"); + GPU_displayText(Text); + break; + case XK_F8: + GPU_makeSnapshot(); + break; + case XK_F9: + cdOpenCase = 1; + break; + case XK_F10: + cdOpenCase = 0; + break; + case XK_Escape: + ClosePlugins(); + if (!UseGui) OnFile_Exit(); + RunGui(); + break; + default: GPU_keypressed(key); + } +} + +long PAD1__open(void) { + return PAD1_open(&gpuDisp); +} + +long PAD2__open(void) { + return PAD2_open(&gpuDisp); +} + +void OnFile_Exit(); + +void SignalExit(int sig) { + ClosePlugins(); + OnFile_Exit(); +} + +void SPUirq(void); + +void OpenPlugins() { + int ret; + + signal(SIGINT, SignalExit); + signal(SIGPIPE, SignalExit); + ret = CDR_open(); + if (ret != 0) { SysMessage ("Error Opening CDR Plugin\n"); exit(1); } + ret = SPU_open(); + if (ret != 0) { SysMessage ("Error Opening SPU Plugin\n"); exit(1); } + SPU_registerCallback(SPUirq); + ret = GPU_open(&gpuDisp, "P©SX", NULL); + if (ret != 0) { SysMessage ("Error Opening GPU Plugin\n"); exit(1); } + ret = PAD1_open(&gpuDisp); + if (ret != 0) { SysMessage ("Error Opening PAD1 Plugin\n"); exit(1); } + ret = PAD2_open(&gpuDisp); + if (ret != 0) { SysMessage ("Error Opening PAD2 Plugin\n"); exit(1); } +} + +void ClosePlugins() { + int ret; + + signal(SIGINT, SIG_DFL); + signal(SIGPIPE, SIG_DFL); + ret = CDR_close(); + if (ret != 0) { SysMessage ("Error Closing CDR Plugin\n"); exit(1); } + ret = SPU_close(); + if (ret != 0) { SysMessage ("Error Closing SPU Plugin\n"); exit(1); } + ret = PAD1_close(); + if (ret != 0) { SysMessage ("Error Closing PAD1 Plugin\n"); exit(1); } + ret = PAD2_close(); + if (ret != 0) { SysMessage ("Error Closing PAD2 Plugin\n"); exit(1); } + ret = GPU_close(); + if (ret != 0) { SysMessage ("Error Closing GPU Plugin\n"); exit(1); } +} + +void ResetPlugins() { + int ret; + + CDR_shutdown(); + GPU_shutdown(); + SPU_shutdown(); + PAD1_shutdown(); + PAD2_shutdown(); + + ret = CDR_init(); + if (ret != 0) { SysMessage ("CDRinit error : %d\n",ret); exit(1); } + ret = GPU_init(); + if (ret != 0) { SysMessage ("GPUinit error : %d\n",ret); exit(1); } + ret = SPU_init(); + if (ret != 0) { SysMessage ("SPUinit error : %d\n",ret); exit(1); } + ret = PAD1_init(1); + if (ret != 0) { SysMessage ("PAD1init error : %d\n",ret); exit(1); } + ret = PAD2_init(2); + if (ret != 0) { SysMessage ("PAD2init error : %d\n",ret); exit(1); } +} diff --git a/PcsxSrc/Linux/Plugin.h b/PcsxSrc/Linux/Plugin.h index ddda195..8d39e64 100644 --- a/PcsxSrc/Linux/Plugin.h +++ b/PcsxSrc/Linux/Plugin.h @@ -1,38 +1,38 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -// Linux Specifyc Plugin Functions - -#ifndef __PLUGIN_H__ -#define __PLUGIN_H__ - -typedef long (* GPUopen)(unsigned long *, char *, char *); - -long GPU__open(void); - -typedef long (* SPUopen)(void); - -long SPU__open(void); - -typedef long (* PADopen)(unsigned long *); - -long PAD1__open(void); - -long PAD2__open(void); - -#endif /* __PLUGIN_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +// Linux Specifyc Plugin Functions + +#ifndef __PLUGIN_H__ +#define __PLUGIN_H__ + +typedef long (* GPUopen)(unsigned long *, char *, char *); + +long GPU__open(void); + +typedef long (* SPUopen)(void); + +long SPU__open(void); + +typedef long (* PADopen)(unsigned long *); + +long PAD1__open(void); + +long PAD2__open(void); + +#endif /* __PLUGIN_H__ */ diff --git a/PcsxSrc/Mdec.c b/PcsxSrc/Mdec.c index 7a6a5c7..cebf285 100644 --- a/PcsxSrc/Mdec.c +++ b/PcsxSrc/Mdec.c @@ -1,587 +1,587 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -/* This code was based on the FPSE v0.08 Mdec decoder*/ - -#include -#include - -#include "PsxCommon.h" -#include "Mdec.h" - -#define FIXED - -#define CONST_BITS 8 -#define PASS1_BITS 2 - -#define FIX_1_082392200 (277) -#define FIX_1_414213562 (362) -#define FIX_1_847759065 (473) -#define FIX_2_613125930 (669) - -#define MULTIPLY(var,const) (DESCALE((var) * (const), CONST_BITS)) - -#define DEQUANTIZE(coef,quantval) (coef) - -#define DESCALE(x,n) ((x)>>(n)) -#define RANGE(n) (n) - -#define DCTSIZE 8 -#define DCTSIZE2 64 - -static void idct1(int *block) -{ - int val = RANGE(DESCALE(block[0], PASS1_BITS+3)); - int i; - for(i=0;i>16)*(bcr&0xffff); - - if (cmd==0x60000000) { - } else - if (cmd==0x40000001) { - u8 *p = (u8*)PSXM(adr); - iqtab_init(iq_y,p); - iqtab_init(iq_uv,p+64); - } else - if ((cmd&0xf5ff0000)==0x30000000) { - mdec.rl = (u16*)PSXM(adr); - } - else { - } -} - -void psxDma1(u32 adr, u32 bcr, u32 chcr) { - int blk[DCTSIZE2*6]; - unsigned short *image; - int size; - -#ifdef CDR_LOG - CDR_LOG("DMA1 %lx %lx %lx (cmd = %lx)\n", adr, bcr, chcr, mdec.command); -#endif - - if (chcr!=0x01000200) return; - - size = (bcr>>16)*(bcr&0xffff); - image = (u16*)PSXM(adr); - if (mdec.command&0x08000000) { - for (;size>0;size-=(16*16)/2,image+=(16*16)) { - mdec.rl = rl2blk(blk,mdec.rl); - yuv2rgb15(blk,image); - } - } else { - for (;size>0;size-=(24*16)/2,image+=(24*16)) { - mdec.rl = rl2blk(blk,mdec.rl); - yuv2rgb24(blk,(u8 *)image); - } - } -} - - -#define RUNOF(a) ((a)>>10) -#define VALOF(a) (((int)(a)<<(32-10))>>(32-10)) - -static int 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 int aanscales[DCTSIZE2] = { - 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 -}; - -void iqtab_init(int *iqtab,unsigned char *iq_y) -{ -#define CONST_BITS14 14 -#define IFAST_SCALE_BITS 2 - int i; - - for(i=0;i>(CONST_BITS14-IFAST_SCALE_BITS); - } -} - -/* // From Filefrmt.pdf - - RL data syntax: - header - macroblock - ... - macroblock - footer - - header: - 16bit: magic (0x3800) - 16bit: size - - macroblock: - Cb block - Cr block - Y1 block - Y2 block - Y3 block - Y4 block - - block: - 5bit: quant, 10bit: dc - 5bit: run, 10bit: level - ... - 5bit: run, 10bit: level - nop (0xfe00) - - footer: - nop - - block conversion: - zigzag -> dequantize -> idct -> yuv2rgb - - zigzag transformation: - - the blk_zig value is the level value of the block - - blk_zig[0] = blk_dct[0]/iq_tab[0]; - for (i = 1; i < 64; i++) { - j = zscan[i]; - blk_zig[i] = blk_dct[j]*16/(iqtab[j]*q_scale); - } - - reverse it: - blk_dct[0] = blk_zig[0]*iq_tab[0]; - for (i = 1; i < 64; i++) { - j = zscan[i]; - blk_dct[j] = blk_zig[i]/(16/(iqtab[j]*q_scale)); - } - - (run, level) (the number of zeros preceding level, value of the element) - - run-level example: - -229 -19 0 -2 0 0 1 0 - (0,-229) (0,-19) (1,-2) (2,1) nop - - dequantization: - - quant = q_scale - - y[0] = x[0] * 16 / (iqtab[0] * 8); - for (i = 1; i < 64; i++) - y[i] = x[i] / (quant * Qtable[i]); - - reverse it: - x[0] = y[0] / (16 / (iqtab[0] * 8)); - for (i = 1; i < 64; i++) - x[i] = y[i] * (quant * Qtable[i]); - - idct: - - yuv2rgb: - - R = Y * 1.0 + Cb * 0 + Cr * 1.402 - G = Y * 1.0 + Cb * -0.3437 + Cr * -0.7143 - B = Y * 1.0 + Cb * 1.772 + Cr * 0 -*/ -#define NOP 0xfe00 -unsigned short* rl2blk(int *blk,unsigned short *mdec_rl) { - int i,k,q_scale,rl; - int *iqtab; - - memset (blk, 0, 6*DCTSIZE2*4); - iqtab = iq_uv; - for(i=0;i<6;i++) { // decode blocks (Cr,Cb,Y1,Y2,Y3,Y4) - if (i>1) iqtab = iq_y; - - // zigzag transformation - rl = *mdec_rl++; - q_scale = RUNOF(rl); - blk[0] = iqtab[0]*VALOF(rl); - for(k = 0;;) { - rl = *mdec_rl++; - if (rl==NOP) break; - k += RUNOF(rl)+1; // skip level zero-coefficients - if (k > 63) break; - blk[zscan[k]] = (VALOF(rl) * iqtab[k] * q_scale) / 8; // / 16; - } -// blk[0] = (blk[0] * iq_t[0] * 8) / 16; -// for(int j=1;j<64;j++) -// blk[j] = blk[j] * iq_t[j] * q_scale; - - // idct - idct(blk,k+1); - - blk+=DCTSIZE2; - } - return mdec_rl; -} - -#ifdef FIXED -#define MULR(a) ((((int)0x0000059B) * (a)) >> 10) -#define MULG(a) ((((int)0xFFFFFEA1) * (a)) >> 10) -#define MULG2(a) ((((int)0xFFFFFD25) * (a)) >> 10) -#define MULB(a) ((((int)0x00000716) * (a)) >> 10) -#else -#define MULR(a) ((int)((float)1.40200 * (a))) -#define MULG(a) ((int)((float)-0.3437 * (a))) -#define MULG2(a) ((int)((float)-0.7143 * (a))) -#define MULB(a) ((int)((float)1.77200 * (a))) -#endif - -#define MAKERGB15(r,g,b) ( (((r)>>3)<<10)|(((g)>>3)<<5)|((b)>>3) ) -#define ROUND(c) roundtbl[((c)+128+256)]//&0x3ff] -/*#define ROUND(c) round(c+128) -int round(int r) { - if (r<0) return 0; - if (r>255) return 255; - return r; -}*/ - -#define RGB15(n, Y) \ - image[n] = MAKERGB15(ROUND(Y + R),ROUND(Y + G),ROUND(Y + B)); - -#define RGB15BW(n, Y) \ - image[n] = MAKERGB15(ROUND(Y),ROUND(Y),ROUND(Y)); - -#define RGB24(n, Y) \ - image[n+2] = ROUND(Y + R); \ - image[n+1] = ROUND(Y + G); \ - image[n+0] = ROUND(Y + B); - -#define RGB24BW(n, Y) \ - image[n+2] = ROUND(Y); \ - image[n+1] = ROUND(Y); \ - image[n+0] = ROUND(Y); - -unsigned char roundtbl[256*3]; - -void round_init(void) { - int i; - for(i=0;i<256;i++) { - roundtbl[i]=0; - roundtbl[i+256]=i; - roundtbl[i+512]=255; - } -} - -void yuv2rgb15(int *blk,unsigned short *image) { - int x,y; - int *Yblk = blk+DCTSIZE2*2; - int Cb,Cr,R,G,B; - int *Cbblk = blk; - int *Crblk = blk+DCTSIZE2; - - if (!(Config.Mdec&0x1)) - for (y=0;y<16;y+=2,Crblk+=4,Cbblk+=4,Yblk+=8,image+=24) { - if (y==8) Yblk+=DCTSIZE2; - for (x=0;x<4;x++,image+=2,Crblk++,Cbblk++,Yblk+=2) { - Cr = *Crblk; - Cb = *Cbblk; - R = MULR(Cr); - G = MULG(Cb) + MULG2(Cr); - B = MULB(Cb); - - RGB15(0, Yblk[0]); - RGB15(1, Yblk[1]); - RGB15(16, Yblk[8]); - RGB15(17, Yblk[9]); - - Cr = *(Crblk+4); - Cb = *(Cbblk+4); - R = MULR(Cr); - G = MULG(Cb) + MULG2(Cr); - B = MULB(Cb); - - RGB15(8, Yblk[DCTSIZE2+0]); - RGB15(9, Yblk[DCTSIZE2+1]); - RGB15(24, Yblk[DCTSIZE2+8]); - RGB15(25, Yblk[DCTSIZE2+9]); - } - } else - for (y=0;y<16;y+=2,Yblk+=8,image+=24) { - if (y==8) Yblk+=DCTSIZE2; - for (x=0;x<4;x++,image+=2,Yblk+=2) { - RGB15BW(0, Yblk[0]); - RGB15BW(1, Yblk[1]); - RGB15BW(16, Yblk[8]); - RGB15BW(17, Yblk[9]); - - RGB15BW(8, Yblk[DCTSIZE2+0]); - RGB15BW(9, Yblk[DCTSIZE2+1]); - RGB15BW(24, Yblk[DCTSIZE2+8]); - RGB15BW(25, Yblk[DCTSIZE2+9]); - } - } -} - -void yuv2rgb24(int *blk,unsigned char *image) { - int x,y; - int *Yblk = blk+DCTSIZE2*2; - int Cb,Cr,R,G,B; - int *Cbblk = blk; - int *Crblk = blk+DCTSIZE2; - - if (!(Config.Mdec&0x1)) - for (y=0;y<16;y+=2,Crblk+=4,Cbblk+=4,Yblk+=8,image+=24*3) { - if (y==8) Yblk+=DCTSIZE2; - for (x=0;x<4;x++,image+=6,Crblk++,Cbblk++,Yblk+=2) { - Cr = *Crblk; - Cb = *Cbblk; - R = MULR(Cr); - G = MULG(Cb) + MULG2(Cr); - B = MULB(Cb); - - RGB24(0, Yblk[0]); - RGB24(1*3, Yblk[1]); - RGB24(16*3, Yblk[8]); - RGB24(17*3, Yblk[9]); - - Cr = *(Crblk+4); - Cb = *(Cbblk+4); - R = MULR(Cr); - G = MULG(Cb) + MULG2(Cr); - B = MULB(Cb); - - RGB24(8*3, Yblk[DCTSIZE2+0]); - RGB24(9*3, Yblk[DCTSIZE2+1]); - RGB24(24*3, Yblk[DCTSIZE2+8]); - RGB24(25*3, Yblk[DCTSIZE2+9]); - } - } else - for (y=0;y<16;y+=2,Yblk+=8,image+=24*3) { - if (y==8) Yblk+=DCTSIZE2; - for (x=0;x<4;x++,image+=6,Yblk+=2) { - RGB24BW(0, Yblk[0]); - RGB24BW(1*3, Yblk[1]); - RGB24BW(16*3, Yblk[8]); - RGB24BW(17*3, Yblk[9]); - - RGB24BW(8*3, Yblk[DCTSIZE2+0]); - RGB24BW(9*3, Yblk[DCTSIZE2+1]); - RGB24BW(24*3, Yblk[DCTSIZE2+8]); - RGB24BW(25*3, Yblk[DCTSIZE2+9]); - } - } -} - -int mdecFreeze(gzFile f, int Mode) { - char Unused[4096]; - - gzfreeze(&mdec, sizeof(mdec)); - gzfreezel(iq_y); - gzfreezel(iq_uv); - gzfreezel(Unused); - - return 0; -} - +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +/* This code was based on the FPSE v0.08 Mdec decoder*/ + +#include +#include + +#include "PsxCommon.h" +#include "Mdec.h" + +#define FIXED + +#define CONST_BITS 8 +#define PASS1_BITS 2 + +#define FIX_1_082392200 (277) +#define FIX_1_414213562 (362) +#define FIX_1_847759065 (473) +#define FIX_2_613125930 (669) + +#define MULTIPLY(var,const) (DESCALE((var) * (const), CONST_BITS)) + +#define DEQUANTIZE(coef,quantval) (coef) + +#define DESCALE(x,n) ((x)>>(n)) +#define RANGE(n) (n) + +#define DCTSIZE 8 +#define DCTSIZE2 64 + +static void idct1(int *block) +{ + int val = RANGE(DESCALE(block[0], PASS1_BITS+3)); + int i; + for(i=0;i>16)*(bcr&0xffff); + + if (cmd==0x60000000) { + } else + if (cmd==0x40000001) { + u8 *p = (u8*)PSXM(adr); + iqtab_init(iq_y,p); + iqtab_init(iq_uv,p+64); + } else + if ((cmd&0xf5ff0000)==0x30000000) { + mdec.rl = (u16*)PSXM(adr); + } + else { + } +} + +void psxDma1(u32 adr, u32 bcr, u32 chcr) { + int blk[DCTSIZE2*6]; + unsigned short *image; + int size; + +#ifdef CDR_LOG + CDR_LOG("DMA1 %lx %lx %lx (cmd = %lx)\n", adr, bcr, chcr, mdec.command); +#endif + + if (chcr!=0x01000200) return; + + size = (bcr>>16)*(bcr&0xffff); + image = (u16*)PSXM(adr); + if (mdec.command&0x08000000) { + for (;size>0;size-=(16*16)/2,image+=(16*16)) { + mdec.rl = rl2blk(blk,mdec.rl); + yuv2rgb15(blk,image); + } + } else { + for (;size>0;size-=(24*16)/2,image+=(24*16)) { + mdec.rl = rl2blk(blk,mdec.rl); + yuv2rgb24(blk,(u8 *)image); + } + } +} + + +#define RUNOF(a) ((a)>>10) +#define VALOF(a) (((int)(a)<<(32-10))>>(32-10)) + +static int 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 int aanscales[DCTSIZE2] = { + 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 +}; + +void iqtab_init(int *iqtab,unsigned char *iq_y) +{ +#define CONST_BITS14 14 +#define IFAST_SCALE_BITS 2 + int i; + + for(i=0;i>(CONST_BITS14-IFAST_SCALE_BITS); + } +} + +/* // From Filefrmt.pdf + + RL data syntax: + header + macroblock + ... + macroblock + footer + + header: + 16bit: magic (0x3800) + 16bit: size + + macroblock: + Cb block + Cr block + Y1 block + Y2 block + Y3 block + Y4 block + + block: + 5bit: quant, 10bit: dc + 5bit: run, 10bit: level + ... + 5bit: run, 10bit: level + nop (0xfe00) + + footer: + nop + + block conversion: + zigzag -> dequantize -> idct -> yuv2rgb + + zigzag transformation: + + the blk_zig value is the level value of the block + + blk_zig[0] = blk_dct[0]/iq_tab[0]; + for (i = 1; i < 64; i++) { + j = zscan[i]; + blk_zig[i] = blk_dct[j]*16/(iqtab[j]*q_scale); + } + + reverse it: + blk_dct[0] = blk_zig[0]*iq_tab[0]; + for (i = 1; i < 64; i++) { + j = zscan[i]; + blk_dct[j] = blk_zig[i]/(16/(iqtab[j]*q_scale)); + } + + (run, level) (the number of zeros preceding level, value of the element) + + run-level example: + -229 -19 0 -2 0 0 1 0 + (0,-229) (0,-19) (1,-2) (2,1) nop + + dequantization: + + quant = q_scale + + y[0] = x[0] * 16 / (iqtab[0] * 8); + for (i = 1; i < 64; i++) + y[i] = x[i] / (quant * Qtable[i]); + + reverse it: + x[0] = y[0] / (16 / (iqtab[0] * 8)); + for (i = 1; i < 64; i++) + x[i] = y[i] * (quant * Qtable[i]); + + idct: + + yuv2rgb: + + R = Y * 1.0 + Cb * 0 + Cr * 1.402 + G = Y * 1.0 + Cb * -0.3437 + Cr * -0.7143 + B = Y * 1.0 + Cb * 1.772 + Cr * 0 +*/ +#define NOP 0xfe00 +unsigned short* rl2blk(int *blk,unsigned short *mdec_rl) { + int i,k,q_scale,rl; + int *iqtab; + + memset (blk, 0, 6*DCTSIZE2*4); + iqtab = iq_uv; + for(i=0;i<6;i++) { // decode blocks (Cr,Cb,Y1,Y2,Y3,Y4) + if (i>1) iqtab = iq_y; + + // zigzag transformation + rl = *mdec_rl++; + q_scale = RUNOF(rl); + blk[0] = iqtab[0]*VALOF(rl); + for(k = 0;;) { + rl = *mdec_rl++; + if (rl==NOP) break; + k += RUNOF(rl)+1; // skip level zero-coefficients + if (k > 63) break; + blk[zscan[k]] = (VALOF(rl) * iqtab[k] * q_scale) / 8; // / 16; + } +// blk[0] = (blk[0] * iq_t[0] * 8) / 16; +// for(int j=1;j<64;j++) +// blk[j] = blk[j] * iq_t[j] * q_scale; + + // idct + idct(blk,k+1); + + blk+=DCTSIZE2; + } + return mdec_rl; +} + +#ifdef FIXED +#define MULR(a) ((((int)0x0000059B) * (a)) >> 10) +#define MULG(a) ((((int)0xFFFFFEA1) * (a)) >> 10) +#define MULG2(a) ((((int)0xFFFFFD25) * (a)) >> 10) +#define MULB(a) ((((int)0x00000716) * (a)) >> 10) +#else +#define MULR(a) ((int)((float)1.40200 * (a))) +#define MULG(a) ((int)((float)-0.3437 * (a))) +#define MULG2(a) ((int)((float)-0.7143 * (a))) +#define MULB(a) ((int)((float)1.77200 * (a))) +#endif + +#define MAKERGB15(r,g,b) ( (((r)>>3)<<10)|(((g)>>3)<<5)|((b)>>3) ) +#define ROUND(c) roundtbl[((c)+128+256)]//&0x3ff] +/*#define ROUND(c) round(c+128) +int round(int r) { + if (r<0) return 0; + if (r>255) return 255; + return r; +}*/ + +#define RGB15(n, Y) \ + image[n] = MAKERGB15(ROUND(Y + R),ROUND(Y + G),ROUND(Y + B)); + +#define RGB15BW(n, Y) \ + image[n] = MAKERGB15(ROUND(Y),ROUND(Y),ROUND(Y)); + +#define RGB24(n, Y) \ + image[n+2] = ROUND(Y + R); \ + image[n+1] = ROUND(Y + G); \ + image[n+0] = ROUND(Y + B); + +#define RGB24BW(n, Y) \ + image[n+2] = ROUND(Y); \ + image[n+1] = ROUND(Y); \ + image[n+0] = ROUND(Y); + +unsigned char roundtbl[256*3]; + +void round_init(void) { + int i; + for(i=0;i<256;i++) { + roundtbl[i]=0; + roundtbl[i+256]=i; + roundtbl[i+512]=255; + } +} + +void yuv2rgb15(int *blk,unsigned short *image) { + int x,y; + int *Yblk = blk+DCTSIZE2*2; + int Cb,Cr,R,G,B; + int *Cbblk = blk; + int *Crblk = blk+DCTSIZE2; + + if (!(Config.Mdec&0x1)) + for (y=0;y<16;y+=2,Crblk+=4,Cbblk+=4,Yblk+=8,image+=24) { + if (y==8) Yblk+=DCTSIZE2; + for (x=0;x<4;x++,image+=2,Crblk++,Cbblk++,Yblk+=2) { + Cr = *Crblk; + Cb = *Cbblk; + R = MULR(Cr); + G = MULG(Cb) + MULG2(Cr); + B = MULB(Cb); + + RGB15(0, Yblk[0]); + RGB15(1, Yblk[1]); + RGB15(16, Yblk[8]); + RGB15(17, Yblk[9]); + + Cr = *(Crblk+4); + Cb = *(Cbblk+4); + R = MULR(Cr); + G = MULG(Cb) + MULG2(Cr); + B = MULB(Cb); + + RGB15(8, Yblk[DCTSIZE2+0]); + RGB15(9, Yblk[DCTSIZE2+1]); + RGB15(24, Yblk[DCTSIZE2+8]); + RGB15(25, Yblk[DCTSIZE2+9]); + } + } else + for (y=0;y<16;y+=2,Yblk+=8,image+=24) { + if (y==8) Yblk+=DCTSIZE2; + for (x=0;x<4;x++,image+=2,Yblk+=2) { + RGB15BW(0, Yblk[0]); + RGB15BW(1, Yblk[1]); + RGB15BW(16, Yblk[8]); + RGB15BW(17, Yblk[9]); + + RGB15BW(8, Yblk[DCTSIZE2+0]); + RGB15BW(9, Yblk[DCTSIZE2+1]); + RGB15BW(24, Yblk[DCTSIZE2+8]); + RGB15BW(25, Yblk[DCTSIZE2+9]); + } + } +} + +void yuv2rgb24(int *blk,unsigned char *image) { + int x,y; + int *Yblk = blk+DCTSIZE2*2; + int Cb,Cr,R,G,B; + int *Cbblk = blk; + int *Crblk = blk+DCTSIZE2; + + if (!(Config.Mdec&0x1)) + for (y=0;y<16;y+=2,Crblk+=4,Cbblk+=4,Yblk+=8,image+=24*3) { + if (y==8) Yblk+=DCTSIZE2; + for (x=0;x<4;x++,image+=6,Crblk++,Cbblk++,Yblk+=2) { + Cr = *Crblk; + Cb = *Cbblk; + R = MULR(Cr); + G = MULG(Cb) + MULG2(Cr); + B = MULB(Cb); + + RGB24(0, Yblk[0]); + RGB24(1*3, Yblk[1]); + RGB24(16*3, Yblk[8]); + RGB24(17*3, Yblk[9]); + + Cr = *(Crblk+4); + Cb = *(Cbblk+4); + R = MULR(Cr); + G = MULG(Cb) + MULG2(Cr); + B = MULB(Cb); + + RGB24(8*3, Yblk[DCTSIZE2+0]); + RGB24(9*3, Yblk[DCTSIZE2+1]); + RGB24(24*3, Yblk[DCTSIZE2+8]); + RGB24(25*3, Yblk[DCTSIZE2+9]); + } + } else + for (y=0;y<16;y+=2,Yblk+=8,image+=24*3) { + if (y==8) Yblk+=DCTSIZE2; + for (x=0;x<4;x++,image+=6,Yblk+=2) { + RGB24BW(0, Yblk[0]); + RGB24BW(1*3, Yblk[1]); + RGB24BW(16*3, Yblk[8]); + RGB24BW(17*3, Yblk[9]); + + RGB24BW(8*3, Yblk[DCTSIZE2+0]); + RGB24BW(9*3, Yblk[DCTSIZE2+1]); + RGB24BW(24*3, Yblk[DCTSIZE2+8]); + RGB24BW(25*3, Yblk[DCTSIZE2+9]); + } + } +} + +int mdecFreeze(gzFile f, int Mode) { + char Unused[4096]; + + gzfreeze(&mdec, sizeof(mdec)); + gzfreezel(iq_y); + gzfreezel(iq_uv); + gzfreezel(Unused); + + return 0; +} + diff --git a/PcsxSrc/Mdec.h b/PcsxSrc/Mdec.h index 5d4e70d..237789d 100644 --- a/PcsxSrc/Mdec.h +++ b/PcsxSrc/Mdec.h @@ -1,31 +1,31 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __MDEC_H__ -#define __MDEC_H__ - -void mdecInit(); -void mdecWrite0(u32 data); -void mdecWrite1(u32 data); -u32 mdecRead0(); -u32 mdecRead1(); -void psxDma0(u32 madr, u32 bcr, u32 chcr); -void psxDma1(u32 madr, u32 bcr, u32 chcr); -int mdecFreeze(gzFile f, int Mode); - -#endif /* __MDEC_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __MDEC_H__ +#define __MDEC_H__ + +void mdecInit(); +void mdecWrite0(u32 data); +void mdecWrite1(u32 data); +u32 mdecRead0(); +u32 mdecRead1(); +void psxDma0(u32 madr, u32 bcr, u32 chcr); +void psxDma1(u32 madr, u32 bcr, u32 chcr); +int mdecFreeze(gzFile f, int Mode); + +#endif /* __MDEC_H__ */ diff --git a/PcsxSrc/Misc.c b/PcsxSrc/Misc.c index d3d4128..dc140b2 100644 --- a/PcsxSrc/Misc.c +++ b/PcsxSrc/Misc.c @@ -1,451 +1,451 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include -#include -#ifdef __LINUX__ -#define strnicmp strncasecmp -#endif - -#include "Coff.h" -#include "PsxCommon.h" -#include "plugins.h" - -int Log = 0; - -// LOAD STUFF - -typedef struct { - unsigned char id[8]; - unsigned long text; - unsigned long data; - unsigned long pc0; - unsigned long gp0; - unsigned long t_addr; - unsigned long t_size; - unsigned long d_addr; - unsigned long d_size; - unsigned long b_addr; - unsigned long b_size; - unsigned long S_addr;//normal must a s not a S but error (???) - unsigned long s_size; - unsigned long SavedSP; - unsigned long SavedFP; - unsigned long SavedGP; - unsigned long SavedRA; - unsigned long SavedS0; -} EXE_HEADER; - -#define ISODCL(from, to) (to - from + 1) - -struct iso_directory_record { - char length [ISODCL (1, 1)]; /* 711 */ - char ext_attr_length [ISODCL (2, 2)]; /* 711 */ - char extent [ISODCL (3, 10)]; /* 733 */ - char size [ISODCL (11, 18)]; /* 733 */ - char date [ISODCL (19, 25)]; /* 7 by 711 */ - char flags [ISODCL (26, 26)]; - char file_unit_size [ISODCL (27, 27)]; /* 711 */ - char interleave [ISODCL (28, 28)]; /* 711 */ - char volume_sequence_number [ISODCL (29, 32)]; /* 723 */ - unsigned char name_len [ISODCL (33, 33)]; /* 711 */ - char name [1]; -}; - -#define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */ -#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */ - -void mmssdd( int block, char *p ) - { - int m, s, d; - - block += 150; - m = block / 4500; // minuten - block = block - m * 4500; // minuten rest - s = block / 75; // sekunden - d = block - s * 75; // sekunden rest - - m = ( ( m / 10 ) << 4 ) | m % 10; - s = ( ( s / 10 ) << 4 ) | s % 10; - d = ( ( d / 10 ) << 4 ) | d % 10; - - p[0] = m; - p[1] = s; - p[2] = d; -} - -int GetCdromFile(unsigned char *buf, unsigned char *time, char * filename) { - struct iso_directory_record *dir; - int i; - - i = 0; - while (i < 4096) { - dir = (struct iso_directory_record*) &buf[i]; - if (dir->length[0] == 0) { - return -1; - } - i += dir->length[0]; - - if (!strnicmp((char*)&dir->name[0],filename,strlen(filename))) { - mmssdd(*((int *)dir->extent), (char*)time); - break; - } - } - return 0; -} - -#define incTime() \ - time[0] = btoi(time[0]); time[1] = btoi(time[1]); time[2] = btoi(time[2]); \ - time[2]++; \ - if(time[2] == 75) { \ - time[2] = 0; \ - time[1]++; \ - if (time[1] == 60) { \ - time[1] = 0; \ - time[0]++; \ - } \ - } \ - time[0] = itob(time[0]); time[1] = itob(time[1]); time[2] = itob(time[2]); - -int LoadCdrom() { - EXE_HEADER tmpHead; - struct iso_directory_record *dir; - unsigned char time[4],*buf; - unsigned char mdir[4096]; - char exename[256]; - int i; - - if (!Config.HLE) { - psxRegs.pc = psxRegs.GPR.n.ra; - return 0; - } - - time[0] = itob(0); time[1] = itob(2); time[2] = itob(0x10); - - if (CDR_readTrack(time) == -1) return -1; - buf = CDR_getBuffer(); - - // skip head and sub, and go to the root directory record - dir = (struct iso_directory_record*) &buf[12+156]; - - mmssdd(*((int *)dir->extent), (char*)time); - - if (CDR_readTrack(time) == -1) return -1; - buf = CDR_getBuffer(); - memcpy(mdir, buf+12, 2048); - - incTime(); - if (CDR_readTrack(time) == -1) return -1; - buf = CDR_getBuffer(); - memcpy(mdir+2048, buf+12, 2048); - - if (GetCdromFile(mdir, time, "SYSTEM.CNF") == -1) { - if (GetCdromFile(mdir, time, "PSX.EXE") == -1) return -1; - - if (CDR_readTrack(time) == -1) return -1; - buf = CDR_getBuffer(); - } - else { - if (CDR_readTrack(time) == -1) return -1; - buf = CDR_getBuffer(); - - sscanf((char*)buf+12, "BOOT = cdrom:\\%s;2", exename); - if (GetCdromFile(mdir, time, exename) == -1) { - sscanf((char*)buf+12, "BOOT = cdrom:%s;2", exename); - if (GetCdromFile(mdir, time, exename) == -1) { - char *ptr = strstr(buf+12, "cdrom:"); - for (i=0; i<32; i++) { - if (ptr[i] == ' ') continue; - if (ptr[i] == '\\') continue; - } - strcpy(exename, ptr); - if (GetCdromFile(mdir, time, exename) == -1) - return -1; - } - } - - if (CDR_readTrack(time) == -1) return -1; - buf = CDR_getBuffer(); - } - - memcpy(&tmpHead, buf+12, sizeof(EXE_HEADER)); - - psxRegs.pc = tmpHead.pc0; - psxRegs.GPR.n.gp = tmpHead.gp0; - psxRegs.GPR.n.sp = tmpHead.S_addr; - if (psxRegs.GPR.n.sp == 0) psxRegs.GPR.n.sp = 0x801fff00; - - while (tmpHead.t_size) { - incTime(); - if (CDR_readTrack(time) == -1) return -1; - buf = CDR_getBuffer(); - - memcpy((void *)PSXM(tmpHead.t_addr), buf+12, 2048); - - tmpHead.t_size -= 2048; - tmpHead.t_addr += 2048; - } - - return 0; -} - -int CheckCdrom() { - struct iso_directory_record *dir; - unsigned char time[4],*buf; - unsigned char mdir[4096]; - char exename[256]; - int i; - - time[0] = itob(0); time[1] = itob(2); time[2] = itob(0x10); - - if (CDR_readTrack(time) == -1) return -1; - buf = CDR_getBuffer(); - - strncpy(CdromId, buf+52, 10); - - // skip head and sub, and go to the root directory record - dir = (struct iso_directory_record*) &buf[12+156]; - - mmssdd(*((int *)dir->extent), (char*)time); - - if (CDR_readTrack(time) == -1) return 0; - buf = CDR_getBuffer(); - memcpy(mdir, buf+12, 2048); - - incTime(); - if (CDR_readTrack(time) == -1) return 0; - buf = CDR_getBuffer(); - memcpy(mdir+2048, buf+12, 2048); - - if (GetCdromFile(mdir, time, "SYSTEM.CNF") != -1) { - if (CDR_readTrack(time) == -1) return 0; - buf = CDR_getBuffer(); - - sscanf((char*)buf+12, "BOOT = cdrom:\\%s;2", exename); - if (GetCdromFile(mdir, time, exename) == -1) { - sscanf((char*)buf+12, "BOOT = cdrom:%s;2", exename); - if (GetCdromFile(mdir, time, exename) == -1) { - char *ptr = strstr(buf+12, "cdrom:"); - for (i=0; i<32; i++) { - if (ptr[i] == ' ') continue; - if (ptr[i] == '\\') continue; - } - strcpy(exename, ptr); - if (GetCdromFile(mdir, time, exename) == -1) - return 0; - } - } - } - - if (Config.PsxAuto) { // autodetect system (pal or ntsc) - if (strstr(exename, "ES") != NULL) - Config.PsxType = 1; // pal - else Config.PsxType = 0; // ntsc - } - UpdateVSyncRate(); - - return 0; -} - -#define PSX_EXE 1 -#define CPE_EXE 2 -#define COFF_EXE 3 -#define INVALID_EXE 4 - -static int PSXGetFileType(FILE *f) { - unsigned long current; - unsigned long mybuf[2048]; - EXE_HEADER *exe_hdr; - FILHDR *coff_hdr; - - current = ftell(f); - fseek(f,0L,SEEK_SET); - fread(mybuf,2048,1,f); - fseek(f,current,SEEK_SET); - - exe_hdr = (EXE_HEADER *)mybuf; - if (memcmp(exe_hdr->id,"PS-X EXE",8)==0) - return PSX_EXE; - - if (mybuf[0]=='C' && mybuf[1]=='P' && mybuf[2]=='E') - return CPE_EXE; - - coff_hdr = (FILHDR *)mybuf; - if (coff_hdr->f_magic == 0x0162) - return COFF_EXE; - - return INVALID_EXE; -} - -int Load(char *ExePath) { - FILE *tmpFile; - EXE_HEADER tmpHead; - int type; - - strcpy(CdromId, "SLUS_999.99"); - - tmpFile = fopen(ExePath,"rb"); - if (tmpFile == NULL) { SysMessage("Error opening file: %s", ExePath); return 0; } - - type = PSXGetFileType(tmpFile); - switch (type) { - case PSX_EXE: - fread(&tmpHead,sizeof(EXE_HEADER),1,tmpFile); - fseek(tmpFile, 0x800, SEEK_SET); - fread((void *)PSXM(tmpHead.t_addr), tmpHead.t_size,1,tmpFile); - fclose(tmpFile); - psxRegs.pc = tmpHead.pc0; - psxRegs.GPR.n.gp = tmpHead.gp0; - psxRegs.GPR.n.sp = tmpHead.S_addr; - if (psxRegs.GPR.n.sp == 0) psxRegs.GPR.n.sp = 0x801fff00; - break; - case CPE_EXE: - SysMessage("Pcsx found that you wanna use a CPE file. CPE files not support yet"); - break; - case COFF_EXE: - SysMessage("Pcsx found that you wanna use a COFF file.COFF files not support yet"); - break; - case INVALID_EXE: - SysMessage("This file is not a psx file"); - break; - } - return 1; -} - -// STATES - -static const char PcsxHeader[32] = "STv3 PCSX v" PCSX_VERSION; - -int SaveState(char *file) { - gzFile f; - GPUFreeze_t *gpufP; - SPUFreeze_t *spufP; - int Size; - unsigned char *pMem; - - f = gzopen(file, "wb"); - if (f == NULL) return -1; - - gzwrite(f, (void*)PcsxHeader, 32); - - pMem = (unsigned char *) malloc(128*96*3); - if (pMem == NULL) return -1; - GPU_getScreenPic(pMem); - gzwrite(f, pMem, 128*96*3); - free(pMem); - - gzwrite(f, psxM, 0x00200000); - if (Config.HLE) psxBiosFreeze(1); - gzwrite(f, psxR, 0x00080000); - gzwrite(f, psxH, 0x00010000); - gzwrite(f, (void*)&psxRegs, sizeof(psxRegs)); - - // gpu - gpufP = (GPUFreeze_t *) malloc(sizeof(GPUFreeze_t)); - gpufP->ulFreezeVersion = 1; - GPU_freeze(1, gpufP); - gzwrite(f, gpufP, sizeof(GPUFreeze_t)); - free(gpufP); - - // spu - spufP = (SPUFreeze_t *) malloc(16); - SPU_freeze(2, spufP); - Size = spufP->Size; gzwrite(f, &Size, 4); - free(spufP); - spufP = (SPUFreeze_t *) malloc(Size); - SPU_freeze(1, spufP); - gzwrite(f, spufP, Size); - free(spufP); - - sioFreeze(f, 1); - cdrFreeze(f, 1); - psxHwFreeze(f, 1); - psxRcntFreeze(f, 1); - mdecFreeze(f, 1); - - gzclose(f); - - return 0; -} - - -int LoadState(char *file) { - gzFile f; - GPUFreeze_t *gpufP; - SPUFreeze_t *spufP; - int Size; - char header[32]; - - f = gzopen(file, "rb"); - if (f == NULL) return -1; - - psxCpu->Reset(); - - gzread(f, header, 32); - - if (strncmp("STv3 PCSX", header, 9)) return -1; - - gzseek(f, 128*96*3, SEEK_CUR); - - gzread(f, psxM, 0x00200000); - gzread(f, psxR, 0x00080000); - if (Config.HLE) psxBiosFreeze(0); - gzread(f, psxH, 0x00010000); - gzread(f, (void*)&psxRegs, sizeof(psxRegs)); - - // gpu - gpufP = (GPUFreeze_t *) malloc (sizeof(GPUFreeze_t)); - gzread(f, gpufP, sizeof(GPUFreeze_t)); - GPU_freeze(0, gpufP); - free(gpufP); - - // spu - gzread(f, &Size, 4); - spufP = (SPUFreeze_t *) malloc (Size); - gzread(f, spufP, Size); - SPU_freeze(0, spufP); - free(spufP); - - sioFreeze(f, 0); - cdrFreeze(f, 0); - psxHwFreeze(f, 0); - psxRcntFreeze(f, 0); - mdecFreeze(f, 0); - - gzclose(f); - - return 0; -} - -void __Log(char *fmt, ...) { - va_list list; -#ifdef LOG_STDOUT - char tmp[1024]; -#endif - - va_start(list, fmt); -#ifndef LOG_STDOUT - vfprintf(emuLog, fmt, list); -#else - vsprintf(tmp, fmt, list); - SysPrintf(tmp); -#endif - va_end(list); +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include +#include +#ifdef __LINUX__ +#define strnicmp strncasecmp +#endif + +#include "Coff.h" +#include "PsxCommon.h" +#include "plugins.h" + +int Log = 0; + +// LOAD STUFF + +typedef struct { + unsigned char id[8]; + unsigned long text; + unsigned long data; + unsigned long pc0; + unsigned long gp0; + unsigned long t_addr; + unsigned long t_size; + unsigned long d_addr; + unsigned long d_size; + unsigned long b_addr; + unsigned long b_size; + unsigned long S_addr;//normal must a s not a S but error (???) + unsigned long s_size; + unsigned long SavedSP; + unsigned long SavedFP; + unsigned long SavedGP; + unsigned long SavedRA; + unsigned long SavedS0; +} EXE_HEADER; + +#define ISODCL(from, to) (to - from + 1) + +struct iso_directory_record { + char length [ISODCL (1, 1)]; /* 711 */ + char ext_attr_length [ISODCL (2, 2)]; /* 711 */ + char extent [ISODCL (3, 10)]; /* 733 */ + char size [ISODCL (11, 18)]; /* 733 */ + char date [ISODCL (19, 25)]; /* 7 by 711 */ + char flags [ISODCL (26, 26)]; + char file_unit_size [ISODCL (27, 27)]; /* 711 */ + char interleave [ISODCL (28, 28)]; /* 711 */ + char volume_sequence_number [ISODCL (29, 32)]; /* 723 */ + unsigned char name_len [ISODCL (33, 33)]; /* 711 */ + char name [1]; +}; + +#define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */ +#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */ + +void mmssdd( int block, char *p ) + { + int m, s, d; + + block += 150; + m = block / 4500; // minuten + block = block - m * 4500; // minuten rest + s = block / 75; // sekunden + d = block - s * 75; // sekunden rest + + m = ( ( m / 10 ) << 4 ) | m % 10; + s = ( ( s / 10 ) << 4 ) | s % 10; + d = ( ( d / 10 ) << 4 ) | d % 10; + + p[0] = m; + p[1] = s; + p[2] = d; +} + +int GetCdromFile(unsigned char *buf, unsigned char *time, char * filename) { + struct iso_directory_record *dir; + int i; + + i = 0; + while (i < 4096) { + dir = (struct iso_directory_record*) &buf[i]; + if (dir->length[0] == 0) { + return -1; + } + i += dir->length[0]; + + if (!strnicmp((char*)&dir->name[0],filename,strlen(filename))) { + mmssdd(*((int *)dir->extent), (char*)time); + break; + } + } + return 0; +} + +#define incTime() \ + time[0] = btoi(time[0]); time[1] = btoi(time[1]); time[2] = btoi(time[2]); \ + time[2]++; \ + if(time[2] == 75) { \ + time[2] = 0; \ + time[1]++; \ + if (time[1] == 60) { \ + time[1] = 0; \ + time[0]++; \ + } \ + } \ + time[0] = itob(time[0]); time[1] = itob(time[1]); time[2] = itob(time[2]); + +int LoadCdrom() { + EXE_HEADER tmpHead; + struct iso_directory_record *dir; + unsigned char time[4],*buf; + unsigned char mdir[4096]; + char exename[256]; + int i; + + if (!Config.HLE) { + psxRegs.pc = psxRegs.GPR.n.ra; + return 0; + } + + time[0] = itob(0); time[1] = itob(2); time[2] = itob(0x10); + + if (CDR_readTrack(time) == -1) return -1; + buf = CDR_getBuffer(); + + // skip head and sub, and go to the root directory record + dir = (struct iso_directory_record*) &buf[12+156]; + + mmssdd(*((int *)dir->extent), (char*)time); + + if (CDR_readTrack(time) == -1) return -1; + buf = CDR_getBuffer(); + memcpy(mdir, buf+12, 2048); + + incTime(); + if (CDR_readTrack(time) == -1) return -1; + buf = CDR_getBuffer(); + memcpy(mdir+2048, buf+12, 2048); + + if (GetCdromFile(mdir, time, "SYSTEM.CNF") == -1) { + if (GetCdromFile(mdir, time, "PSX.EXE") == -1) return -1; + + if (CDR_readTrack(time) == -1) return -1; + buf = CDR_getBuffer(); + } + else { + if (CDR_readTrack(time) == -1) return -1; + buf = CDR_getBuffer(); + + sscanf((char*)buf+12, "BOOT = cdrom:\\%s;2", exename); + if (GetCdromFile(mdir, time, exename) == -1) { + sscanf((char*)buf+12, "BOOT = cdrom:%s;2", exename); + if (GetCdromFile(mdir, time, exename) == -1) { + char *ptr = strstr(buf+12, "cdrom:"); + for (i=0; i<32; i++) { + if (ptr[i] == ' ') continue; + if (ptr[i] == '\\') continue; + } + strcpy(exename, ptr); + if (GetCdromFile(mdir, time, exename) == -1) + return -1; + } + } + + if (CDR_readTrack(time) == -1) return -1; + buf = CDR_getBuffer(); + } + + memcpy(&tmpHead, buf+12, sizeof(EXE_HEADER)); + + psxRegs.pc = tmpHead.pc0; + psxRegs.GPR.n.gp = tmpHead.gp0; + psxRegs.GPR.n.sp = tmpHead.S_addr; + if (psxRegs.GPR.n.sp == 0) psxRegs.GPR.n.sp = 0x801fff00; + + while (tmpHead.t_size) { + incTime(); + if (CDR_readTrack(time) == -1) return -1; + buf = CDR_getBuffer(); + + memcpy((void *)PSXM(tmpHead.t_addr), buf+12, 2048); + + tmpHead.t_size -= 2048; + tmpHead.t_addr += 2048; + } + + return 0; +} + +int CheckCdrom() { + struct iso_directory_record *dir; + unsigned char time[4],*buf; + unsigned char mdir[4096]; + char exename[256]; + int i; + + time[0] = itob(0); time[1] = itob(2); time[2] = itob(0x10); + + if (CDR_readTrack(time) == -1) return -1; + buf = CDR_getBuffer(); + + strncpy(CdromId, buf+52, 10); + + // skip head and sub, and go to the root directory record + dir = (struct iso_directory_record*) &buf[12+156]; + + mmssdd(*((int *)dir->extent), (char*)time); + + if (CDR_readTrack(time) == -1) return 0; + buf = CDR_getBuffer(); + memcpy(mdir, buf+12, 2048); + + incTime(); + if (CDR_readTrack(time) == -1) return 0; + buf = CDR_getBuffer(); + memcpy(mdir+2048, buf+12, 2048); + + if (GetCdromFile(mdir, time, "SYSTEM.CNF") != -1) { + if (CDR_readTrack(time) == -1) return 0; + buf = CDR_getBuffer(); + + sscanf((char*)buf+12, "BOOT = cdrom:\\%s;2", exename); + if (GetCdromFile(mdir, time, exename) == -1) { + sscanf((char*)buf+12, "BOOT = cdrom:%s;2", exename); + if (GetCdromFile(mdir, time, exename) == -1) { + char *ptr = strstr(buf+12, "cdrom:"); + for (i=0; i<32; i++) { + if (ptr[i] == ' ') continue; + if (ptr[i] == '\\') continue; + } + strcpy(exename, ptr); + if (GetCdromFile(mdir, time, exename) == -1) + return 0; + } + } + } + + if (Config.PsxAuto) { // autodetect system (pal or ntsc) + if (strstr(exename, "ES") != NULL) + Config.PsxType = 1; // pal + else Config.PsxType = 0; // ntsc + } + UpdateVSyncRate(); + + return 0; +} + +#define PSX_EXE 1 +#define CPE_EXE 2 +#define COFF_EXE 3 +#define INVALID_EXE 4 + +static int PSXGetFileType(FILE *f) { + unsigned long current; + unsigned long mybuf[2048]; + EXE_HEADER *exe_hdr; + FILHDR *coff_hdr; + + current = ftell(f); + fseek(f,0L,SEEK_SET); + fread(mybuf,2048,1,f); + fseek(f,current,SEEK_SET); + + exe_hdr = (EXE_HEADER *)mybuf; + if (memcmp(exe_hdr->id,"PS-X EXE",8)==0) + return PSX_EXE; + + if (mybuf[0]=='C' && mybuf[1]=='P' && mybuf[2]=='E') + return CPE_EXE; + + coff_hdr = (FILHDR *)mybuf; + if (coff_hdr->f_magic == 0x0162) + return COFF_EXE; + + return INVALID_EXE; +} + +int Load(char *ExePath) { + FILE *tmpFile; + EXE_HEADER tmpHead; + int type; + + strcpy(CdromId, "SLUS_999.99"); + + tmpFile = fopen(ExePath,"rb"); + if (tmpFile == NULL) { SysMessage("Error opening file: %s", ExePath); return 0; } + + type = PSXGetFileType(tmpFile); + switch (type) { + case PSX_EXE: + fread(&tmpHead,sizeof(EXE_HEADER),1,tmpFile); + fseek(tmpFile, 0x800, SEEK_SET); + fread((void *)PSXM(tmpHead.t_addr), tmpHead.t_size,1,tmpFile); + fclose(tmpFile); + psxRegs.pc = tmpHead.pc0; + psxRegs.GPR.n.gp = tmpHead.gp0; + psxRegs.GPR.n.sp = tmpHead.S_addr; + if (psxRegs.GPR.n.sp == 0) psxRegs.GPR.n.sp = 0x801fff00; + break; + case CPE_EXE: + SysMessage("Pcsx found that you wanna use a CPE file. CPE files not support yet"); + break; + case COFF_EXE: + SysMessage("Pcsx found that you wanna use a COFF file.COFF files not support yet"); + break; + case INVALID_EXE: + SysMessage("This file is not a psx file"); + break; + } + return 1; +} + +// STATES + +static const char PcsxHeader[32] = "STv3 PCSX v" PCSX_VERSION; + +int SaveState(char *file) { + gzFile f; + GPUFreeze_t *gpufP; + SPUFreeze_t *spufP; + int Size; + unsigned char *pMem; + + f = gzopen(file, "wb"); + if (f == NULL) return -1; + + gzwrite(f, (void*)PcsxHeader, 32); + + pMem = (unsigned char *) malloc(128*96*3); + if (pMem == NULL) return -1; + GPU_getScreenPic(pMem); + gzwrite(f, pMem, 128*96*3); + free(pMem); + + gzwrite(f, psxM, 0x00200000); + if (Config.HLE) psxBiosFreeze(1); + gzwrite(f, psxR, 0x00080000); + gzwrite(f, psxH, 0x00010000); + gzwrite(f, (void*)&psxRegs, sizeof(psxRegs)); + + // gpu + gpufP = (GPUFreeze_t *) malloc(sizeof(GPUFreeze_t)); + gpufP->ulFreezeVersion = 1; + GPU_freeze(1, gpufP); + gzwrite(f, gpufP, sizeof(GPUFreeze_t)); + free(gpufP); + + // spu + spufP = (SPUFreeze_t *) malloc(16); + SPU_freeze(2, spufP); + Size = spufP->Size; gzwrite(f, &Size, 4); + free(spufP); + spufP = (SPUFreeze_t *) malloc(Size); + SPU_freeze(1, spufP); + gzwrite(f, spufP, Size); + free(spufP); + + sioFreeze(f, 1); + cdrFreeze(f, 1); + psxHwFreeze(f, 1); + psxRcntFreeze(f, 1); + mdecFreeze(f, 1); + + gzclose(f); + + return 0; +} + + +int LoadState(char *file) { + gzFile f; + GPUFreeze_t *gpufP; + SPUFreeze_t *spufP; + int Size; + char header[32]; + + f = gzopen(file, "rb"); + if (f == NULL) return -1; + + psxCpu->Reset(); + + gzread(f, header, 32); + + if (strncmp("STv3 PCSX", header, 9)) return -1; + + gzseek(f, 128*96*3, SEEK_CUR); + + gzread(f, psxM, 0x00200000); + gzread(f, psxR, 0x00080000); + if (Config.HLE) psxBiosFreeze(0); + gzread(f, psxH, 0x00010000); + gzread(f, (void*)&psxRegs, sizeof(psxRegs)); + + // gpu + gpufP = (GPUFreeze_t *) malloc (sizeof(GPUFreeze_t)); + gzread(f, gpufP, sizeof(GPUFreeze_t)); + GPU_freeze(0, gpufP); + free(gpufP); + + // spu + gzread(f, &Size, 4); + spufP = (SPUFreeze_t *) malloc (Size); + gzread(f, spufP, Size); + SPU_freeze(0, spufP); + free(spufP); + + sioFreeze(f, 0); + cdrFreeze(f, 0); + psxHwFreeze(f, 0); + psxRcntFreeze(f, 0); + mdecFreeze(f, 0); + + gzclose(f); + + return 0; +} + +void __Log(char *fmt, ...) { + va_list list; +#ifdef LOG_STDOUT + char tmp[1024]; +#endif + + va_start(list, fmt); +#ifndef LOG_STDOUT + vfprintf(emuLog, fmt, list); +#else + vsprintf(tmp, fmt, list); + SysPrintf(tmp); +#endif + va_end(list); } \ No newline at end of file diff --git a/PcsxSrc/Misc.h b/PcsxSrc/Misc.h index 1dd2480..c9e0343 100644 --- a/PcsxSrc/Misc.h +++ b/PcsxSrc/Misc.h @@ -1,31 +1,31 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __MISC_H__ -#define __MISC_H__ - -char CdromId[256]; - -int LoadCdrom(); -int CheckCdrom(); -int Load(char *ExePath); - -int SaveState(char *file); -int LoadState(char *file); - -#endif /* __MISC_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __MISC_H__ +#define __MISC_H__ + +char CdromId[256]; + +int LoadCdrom(); +int CheckCdrom(); +int Load(char *ExePath); + +int SaveState(char *file); +int LoadState(char *file); + +#endif /* __MISC_H__ */ diff --git a/PcsxSrc/PSEmu_Plugin_Defs.h b/PcsxSrc/PSEmu_Plugin_Defs.h index 47a1f55..9c5be1a 100644 --- a/PcsxSrc/PSEmu_Plugin_Defs.h +++ b/PcsxSrc/PSEmu_Plugin_Defs.h @@ -1,247 +1,247 @@ -/* - PSEmu Plugin Developer Kit Header definition - - (C)1998 Vision Thing - - This file can be used only to develop PSEmu Plugins - Other usage is highly prohibited. -*/ - - -// IMPORTANT!!! - -// if you want to add return codes (any errors or warnings) just drop mail to -// plugin@psemu.com - -#ifndef _PSEMU_PLUGIN_DEFS_H -#define _PSEMU_PLUGIN_DEFS_H - - -// header version -#define _PPDK_HEADER_VERSION 3 - -#define PLUGIN_VERSION 1 - -// plugin type returned by PSEgetLibType (types can be merged if plugin is multi type!) -#define PSE_LT_CDR 1 -#define PSE_LT_GPU 2 -#define PSE_LT_SPU 4 -#define PSE_LT_PAD 8 - - -// every function in DLL if completed sucessfully should return this value -#define PSE_ERR_SUCCESS 0 - -// undefined error but fatal one, that kills all functionality -#define PSE_ERR_FATAL -1 - - - -// XXX_Init return values -// Those return values apply to all libraries -// currently obsolete - preserved for compatibilty - - -// initialization went OK -#define PSE_INIT_ERR_SUCCESS 0 - -// this driver is not configured -#define PSE_INIT_ERR_NOTCONFIGURED -2 - -// this driver can not operate properly on this hardware or hardware is not detected -#define PSE_INIT_ERR_NOHARDWARE -3 - - - -/* GPU PlugIn */ - - -// GPU_Test return values - -// sucess, everything configured, and went OK. -#define PSE_GPU_ERR_SUCCESS 0 - -// ERRORS -// this error might be returned as critical error but none of below -#define PSE_GPU_ERR -20 - - -// this driver is not configured -#define PSE_GPU_ERR_NOTCONFIGURED PSE_GPU_ERR - 1 -// this driver failed Init -#define PSE_GPU_ERR_INIT PSE_GPU_ERR - 2 - -// WARNINGS -// this warning might be returned as undefined warning but allowing driver to continue -#define PSE_GPU_WARN 20 - - - - -// GPU_Query - will be implemented soon - -typedef struct -{ - unsigned long flags; - unsigned long status; - HWND window; - unsigned char reserved[100]; -} gpuQueryS; - -// gpuQueryS.flags -// if driver can operate in both modes it must support GPU_changeMode(); -// this driver can operate in fullscreen mode -#define PSE_GPU_FLAGS_FULLSCREEN 1 -// this driver can operate in windowed mode -#define PSE_GPU_FLAGS_WINDOWED 2 - - -// gpuQueryS.status -// this driver cannot operate in this windowed mode -#define PSE_GPU_STATUS_WINDOWWRONG 1 - -// GPU_Query End - will be implemented in v2 - - - - -/* CDR PlugIn */ - -// CDR_Test return values - -// sucess, everything configured, and went OK. -#define PSE_CDR_ERR_SUCCESS 0 - -// general failure (error undefined) -#define PSE_CDR_ERR_FAILURE -1 - -// ERRORS -#define PSE_CDR_ERR -40 -// this driver is not configured -#define PSE_CDR_ERR_NOTCONFIGURED PSE_CDR_ERR - 0 -// if this driver is unable to read data from medium -#define PSE_CDR_ERR_NOREAD PSE_CDR_ERR - 1 - -// WARNINGS -#define PSE_CDR_WARN 40 -// if this driver emulates lame mode ie. can read only 2048 tracks and sector header is emulated -// this might happen to CDROMS that do not support RAW mode reading - surelly it will kill many games -#define PSE_CDR_WARN_LAMECD PSE_CDR_WARN + 0 - - - - -/* SPU PlugIn */ - -// some info retricted (now!) - -// sucess, everything configured, and went OK. -#define PSE_SPU_ERR_SUCCESS 0 - -// ERRORS -// this error might be returned as critical error but none of below -#define PSE_SPU_ERR -60 - -// this driver is not configured -#define PSE_SPU_ERR_NOTCONFIGURED PSE_SPU_ERR - 1 -// this driver failed Init -#define PSE_SPU_ERR_INIT PSE_SPU_ERR - 2 - - -// WARNINGS -// this warning might be returned as undefined warning but allowing driver to continue -#define PSE_SPU_WARN 60 - - - - -/* PAD PlugIn */ - -/* - - functions that must be exported from PAD Plugin - - long PADinit(long flags); // called only once when PSEmu Starts - void PADshutdown(void); // called when PSEmu exits - long PADopen(PadInitS *); // called when PSEmu is running program - long PADclose(void); - long PADconfigure(void); - void PADabout(void); - long PADtest(void); // called from Configure Dialog and after PADopen(); - long PADquery(void); - - long PADreadPort1(PadDataS *); - long PADreadPort2(PadDataS *); - -*/ - -// PADquery responses (notice - values ORed) -// PSEmu will use them also in PADinit to tell Plugin which Ports will use -// notice that PSEmu will call PADinit and PADopen only once when they are from -// same plugin - -// might be used in port 1 (must support PADreadPort1() function) -#define PSE_PAD_USE_PORT1 1 -// might be used in port 2 (must support PADreadPort2() function) -#define PSE_PAD_USE_PORT2 2 - - - -// MOUSE SCPH-1030 -#define PSE_PAD_TYPE_MOUSE 1 -// NEGCON - 16 button analog controller SLPH-00001 -#define PSE_PAD_TYPE_NEGCON 2 -// GUN CONTROLLER - gun controller SLPH-00014 from Konami -#define PSE_PAD_TYPE_GUN 3 -// STANDARD PAD SCPH-1080, SCPH-1150 -#define PSE_PAD_TYPE_STANDARD 4 -// ANALOG JOYSTICK SCPH-1110 -#define PSE_PAD_TYPE_ANALOGJOY 5 -// GUNCON - gun controller SLPH-00034 from Namco -#define PSE_PAD_TYPE_GUNCON 6 -// ANALOG CONTROLLER SCPH-1150 -#define PSE_PAD_TYPE_ANALOGPAD 7 - - -// sucess, everything configured, and went OK. -#define PSE_PAD_ERR_SUCCESS 0 -// general plugin failure (undefined error) -#define PSE_PAD_ERR_FAILURE -1 - - -// ERRORS -// this error might be returned as critical error but none of below -#define PSE_PAD_ERR -80 -// this driver is not configured -#define PSE_PAD_ERR_NOTCONFIGURED PSE_PAD_ERR - 1 -// this driver failed Init -#define PSE_PAD_ERR_INIT PSE_PAD_ERR - 2 - - -// WARNINGS -// this warning might be returned as undefined warning but allowing driver to continue -#define PSE_PAD_WARN 80 - - -typedef struct -{ - // controler type - fill it withe predefined values above - unsigned char controllerType; - - // status of buttons - every controller fills this field - unsigned short buttonStatus; - - // for analog pad fill those next 4 bytes - // values are analog in range 0-255 where 128 is center position - unsigned char rightJoyX, rightJoyY, leftJoyX, leftJoyY; - - // for mouse fill those next 2 bytes - // values are in range -128 - 127 - unsigned char moveX, moveY; - - unsigned char reserved[91]; - -} PadDataS; - - -#endif // _PSEMU_PLUGIN_DEFS_H +/* + PSEmu Plugin Developer Kit Header definition + + (C)1998 Vision Thing + + This file can be used only to develop PSEmu Plugins + Other usage is highly prohibited. +*/ + + +// IMPORTANT!!! + +// if you want to add return codes (any errors or warnings) just drop mail to +// plugin@psemu.com + +#ifndef _PSEMU_PLUGIN_DEFS_H +#define _PSEMU_PLUGIN_DEFS_H + + +// header version +#define _PPDK_HEADER_VERSION 3 + +#define PLUGIN_VERSION 1 + +// plugin type returned by PSEgetLibType (types can be merged if plugin is multi type!) +#define PSE_LT_CDR 1 +#define PSE_LT_GPU 2 +#define PSE_LT_SPU 4 +#define PSE_LT_PAD 8 + + +// every function in DLL if completed sucessfully should return this value +#define PSE_ERR_SUCCESS 0 + +// undefined error but fatal one, that kills all functionality +#define PSE_ERR_FATAL -1 + + + +// XXX_Init return values +// Those return values apply to all libraries +// currently obsolete - preserved for compatibilty + + +// initialization went OK +#define PSE_INIT_ERR_SUCCESS 0 + +// this driver is not configured +#define PSE_INIT_ERR_NOTCONFIGURED -2 + +// this driver can not operate properly on this hardware or hardware is not detected +#define PSE_INIT_ERR_NOHARDWARE -3 + + + +/* GPU PlugIn */ + + +// GPU_Test return values + +// sucess, everything configured, and went OK. +#define PSE_GPU_ERR_SUCCESS 0 + +// ERRORS +// this error might be returned as critical error but none of below +#define PSE_GPU_ERR -20 + + +// this driver is not configured +#define PSE_GPU_ERR_NOTCONFIGURED PSE_GPU_ERR - 1 +// this driver failed Init +#define PSE_GPU_ERR_INIT PSE_GPU_ERR - 2 + +// WARNINGS +// this warning might be returned as undefined warning but allowing driver to continue +#define PSE_GPU_WARN 20 + + + + +// GPU_Query - will be implemented soon + +typedef struct +{ + unsigned long flags; + unsigned long status; + HWND window; + unsigned char reserved[100]; +} gpuQueryS; + +// gpuQueryS.flags +// if driver can operate in both modes it must support GPU_changeMode(); +// this driver can operate in fullscreen mode +#define PSE_GPU_FLAGS_FULLSCREEN 1 +// this driver can operate in windowed mode +#define PSE_GPU_FLAGS_WINDOWED 2 + + +// gpuQueryS.status +// this driver cannot operate in this windowed mode +#define PSE_GPU_STATUS_WINDOWWRONG 1 + +// GPU_Query End - will be implemented in v2 + + + + +/* CDR PlugIn */ + +// CDR_Test return values + +// sucess, everything configured, and went OK. +#define PSE_CDR_ERR_SUCCESS 0 + +// general failure (error undefined) +#define PSE_CDR_ERR_FAILURE -1 + +// ERRORS +#define PSE_CDR_ERR -40 +// this driver is not configured +#define PSE_CDR_ERR_NOTCONFIGURED PSE_CDR_ERR - 0 +// if this driver is unable to read data from medium +#define PSE_CDR_ERR_NOREAD PSE_CDR_ERR - 1 + +// WARNINGS +#define PSE_CDR_WARN 40 +// if this driver emulates lame mode ie. can read only 2048 tracks and sector header is emulated +// this might happen to CDROMS that do not support RAW mode reading - surelly it will kill many games +#define PSE_CDR_WARN_LAMECD PSE_CDR_WARN + 0 + + + + +/* SPU PlugIn */ + +// some info retricted (now!) + +// sucess, everything configured, and went OK. +#define PSE_SPU_ERR_SUCCESS 0 + +// ERRORS +// this error might be returned as critical error but none of below +#define PSE_SPU_ERR -60 + +// this driver is not configured +#define PSE_SPU_ERR_NOTCONFIGURED PSE_SPU_ERR - 1 +// this driver failed Init +#define PSE_SPU_ERR_INIT PSE_SPU_ERR - 2 + + +// WARNINGS +// this warning might be returned as undefined warning but allowing driver to continue +#define PSE_SPU_WARN 60 + + + + +/* PAD PlugIn */ + +/* + + functions that must be exported from PAD Plugin + + long PADinit(long flags); // called only once when PSEmu Starts + void PADshutdown(void); // called when PSEmu exits + long PADopen(PadInitS *); // called when PSEmu is running program + long PADclose(void); + long PADconfigure(void); + void PADabout(void); + long PADtest(void); // called from Configure Dialog and after PADopen(); + long PADquery(void); + + long PADreadPort1(PadDataS *); + long PADreadPort2(PadDataS *); + +*/ + +// PADquery responses (notice - values ORed) +// PSEmu will use them also in PADinit to tell Plugin which Ports will use +// notice that PSEmu will call PADinit and PADopen only once when they are from +// same plugin + +// might be used in port 1 (must support PADreadPort1() function) +#define PSE_PAD_USE_PORT1 1 +// might be used in port 2 (must support PADreadPort2() function) +#define PSE_PAD_USE_PORT2 2 + + + +// MOUSE SCPH-1030 +#define PSE_PAD_TYPE_MOUSE 1 +// NEGCON - 16 button analog controller SLPH-00001 +#define PSE_PAD_TYPE_NEGCON 2 +// GUN CONTROLLER - gun controller SLPH-00014 from Konami +#define PSE_PAD_TYPE_GUN 3 +// STANDARD PAD SCPH-1080, SCPH-1150 +#define PSE_PAD_TYPE_STANDARD 4 +// ANALOG JOYSTICK SCPH-1110 +#define PSE_PAD_TYPE_ANALOGJOY 5 +// GUNCON - gun controller SLPH-00034 from Namco +#define PSE_PAD_TYPE_GUNCON 6 +// ANALOG CONTROLLER SCPH-1150 +#define PSE_PAD_TYPE_ANALOGPAD 7 + + +// sucess, everything configured, and went OK. +#define PSE_PAD_ERR_SUCCESS 0 +// general plugin failure (undefined error) +#define PSE_PAD_ERR_FAILURE -1 + + +// ERRORS +// this error might be returned as critical error but none of below +#define PSE_PAD_ERR -80 +// this driver is not configured +#define PSE_PAD_ERR_NOTCONFIGURED PSE_PAD_ERR - 1 +// this driver failed Init +#define PSE_PAD_ERR_INIT PSE_PAD_ERR - 2 + + +// WARNINGS +// this warning might be returned as undefined warning but allowing driver to continue +#define PSE_PAD_WARN 80 + + +typedef struct +{ + // controler type - fill it withe predefined values above + unsigned char controllerType; + + // status of buttons - every controller fills this field + unsigned short buttonStatus; + + // for analog pad fill those next 4 bytes + // values are analog in range 0-255 where 128 is center position + unsigned char rightJoyX, rightJoyY, leftJoyX, leftJoyY; + + // for mouse fill those next 2 bytes + // values are in range -128 - 127 + unsigned char moveX, moveY; + + unsigned char reserved[91]; + +} PadDataS; + + +#endif // _PSEMU_PLUGIN_DEFS_H diff --git a/PcsxSrc/PsxBios.c b/PcsxSrc/PsxBios.c index 5494a20..5f1145b 100644 --- a/PcsxSrc/PsxBios.c +++ b/PcsxSrc/PsxBios.c @@ -1,2164 +1,2164 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include -#include -#include - -#include "PsxCommon.h" -//We try to emulate bios :) HELP US :P - -char *biosA0n[256] = { -// 0x00 - "open", "lseek", "read", "write", - "close", "ioctl", "exit", "sys_a0_07", - "getc", "putc", "todigit", "atof", - "strtoul", "strtol", "abs", "labs", -// 0x10 - "atoi", "atol", "atob", "setjmp", - "longjmp", "strcat", "strncat", "strcmp", - "strncmp", "strcpy", "strncpy", "strlen", - "index", "rindex", "strchr", "strrchr", -// 0x20 - "strpbrk", "strspn", "strcspn", "strtok", - "strstr", "toupper", "tolower", "bcopy", - "bzero", "bcmp", "memcpy", "memset", - "memmove", "memcmp", "memchr", "rand", -// 0x30 - "srand", "qsort", "strtod", "malloc", - "free", "lsearch", "bsearch", "calloc", - "realloc", "InitHeap", "_exit", "getchar", - "putchar", "gets", "puts", "printf", -// 0x40 - "sys_a0_40", "LoadTest", "Load", "Exec", - "FlushCache", "InstallInterruptHandler", "GPU_dw", "mem2vram", - "SendGPUStatus", "GPU_cw", "GPU_cwb", "SendPackets", - "sys_a0_4c", "GetGPUStatus", "GPU_sync", "sys_a0_4f", -// 0x50 - "sys_a0_50", "LoadExec", "GetSysSp", "sys_a0_53", - "_96_init()", "_bu_init()", "_96_remove()", "sys_a0_57", - "sys_a0_58", "sys_a0_59", "sys_a0_5a", "dev_tty_init", - "dev_tty_open", "sys_a0_5d", "dev_tty_ioctl","dev_cd_open", -// 0x60 - "dev_cd_read", "dev_cd_close", "dev_cd_firstfile", "dev_cd_nextfile", - "dev_cd_chdir", "dev_card_open", "dev_card_read", "dev_card_write", - "dev_card_close", "dev_card_firstfile", "dev_card_nextfile","dev_card_erase", - "dev_card_undelete","dev_card_format", "dev_card_rename", "dev_card_6f", -// 0x70 - "_bu_init", "_96_init", "_96_remove", "sys_a0_73", - "sys_a0_74", "sys_a0_75", "sys_a0_76", "sys_a0_77", - "_96_CdSeekL", "sys_a0_79", "sys_a0_7a", "sys_a0_7b", - "_96_CdGetStatus", "sys_a0_7d", "_96_CdRead", "sys_a0_7f", -// 0x80 - "sys_a0_80", "sys_a0_81", "sys_a0_82", "sys_a0_83", - "sys_a0_84", "_96_CdStop", "sys_a0_86", "sys_a0_87", - "sys_a0_88", "sys_a0_89", "sys_a0_8a", "sys_a0_8b", - "sys_a0_8c", "sys_a0_8d", "sys_a0_8e", "sys_a0_8f", -// 0x90 - "sys_a0_90", "sys_a0_91", "sys_a0_92", "sys_a0_93", - "sys_a0_94", "sys_a0_95", "AddCDROMDevice", "AddMemCardDevide", - "DisableKernelIORedirection", "EnableKernelIORedirection", "sys_a0_9a", "sys_a0_9b", - "SetConf", "GetConf", "sys_a0_9e", "SetMem", -// 0xa0 - "_boot", "SystemError", "EnqueueCdIntr", "DequeueCdIntr", - "sys_a0_a4", "ReadSector", "get_cd_status", "bufs_cb_0", - "bufs_cb_1", "bufs_cb_2", "bufs_cb_3", "_card_info", - "_card_load", "_card_auto", "bufs_cd_4", "sys_a0_af", -// 0xb0 - "sys_a0_b0", "sys_a0_b1", "do_a_long_jmp", "sys_a0_b3", - "?? sub_function", -}; - -char *biosB0n[256] = { -// 0x00 - "SysMalloc", "sys_b0_01", "sys_b0_02", "sys_b0_03", - "sys_b0_04", "sys_b0_05", "sys_b0_06", "DeliverEvent", - "OpenEvent", "CloseEvent", "WaitEvent", "TestEvent", - "EnableEvent", "DisableEvent", "OpenTh", "CloseTh", -// 0x10 - "ChangeTh", "sys_b0_11", "InitPAD", "StartPAD", - "StopPAD", "PAD_init", "PAD_dr", "ReturnFromExecption", - "ResetEntryInt", "HookEntryInt", "sys_b0_1a", "sys_b0_1b", - "sys_b0_1c", "sys_b0_1d", "sys_b0_1e", "sys_b0_1f", -// 0x20 - "UnDeliverEvent", "sys_b0_21", "sys_b0_22", "sys_b0_23", - "sys_b0_24", "sys_b0_25", "sys_b0_26", "sys_b0_27", - "sys_b0_28", "sys_b0_29", "sys_b0_2a", "sys_b0_2b", - "sys_b0_2c", "sys_b0_2d", "sys_b0_2e", "sys_b0_2f", -// 0x30 - "sys_b0_30", "sys_b0_31", "open", "lseek", - "read", "write", "close", "ioctl", - "exit", "sys_b0_39", "getc", "putc", - "getchar", "putchar", "gets", "puts", -// 0x40 - "cd", "format", "firstfile", "nextfile", - "rename", "delete", "undelete", "AddDevice", - "RemoteDevice", "PrintInstalledDevices", "InitCARD", "StartCARD", - "StopCARD", "sys_b0_4d", "_card_write", "_card_read", -// 0x50 - "_new_card", "Krom2RawAdd", "sys_b0_52", "sys_b0_53", - "_get_errno", "_get_error", "GetC0Table", "GetB0Table", - "_card_chan", "sys_b0_59", "sys_b0_5a", "ChangeClearPAD", - "_card_status", "_card_wait", -}; - -char *biosC0n[256] = { -// 0x00 - "InitRCnt", "InitException", "SysEnqIntRP", "SysDeqIntRP", - "get_free_EvCB_slot", "get_free_TCB_slot", "ExceptionHandler", "InstallExeptionHandler", - "SysInitMemory", "SysInitKMem", "ChangeClearRCnt", "SystemError", - "InitDefInt", "sys_c0_0d", "sys_c0_0e", "sys_c0_0f", -// 0x10 - "sys_c0_10", "sys_c0_11", "InstallDevices", "FlushStfInOutPut", - "sys_c0_14", "_cdevinput", "_cdevscan", "_circgetc", - "_circputc", "ioabort", "sys_c0_1a", "KernelRedirect", - "PatchAOTable", -}; - -//#define r0 (psxRegs.GPR.n.r0) -#define at (psxRegs.GPR.n.at) -#define v0 (psxRegs.GPR.n.v0) -#define v1 (psxRegs.GPR.n.v1) -#define a0 (psxRegs.GPR.n.a0) -#define a1 (psxRegs.GPR.n.a1) -#define a2 (psxRegs.GPR.n.a2) -#define a3 (psxRegs.GPR.n.a3) -#define t0 (psxRegs.GPR.n.t0) -#define t1 (psxRegs.GPR.n.t1) -#define t2 (psxRegs.GPR.n.t2) -#define t3 (psxRegs.GPR.n.t3) -#define t4 (psxRegs.GPR.n.t4) -#define t5 (psxRegs.GPR.n.t5) -#define t6 (psxRegs.GPR.n.t6) -#define t7 (psxRegs.GPR.n.t7) -#define s0 (psxRegs.GPR.n.s0) -#define s1 (psxRegs.GPR.n.s1) -#define s2 (psxRegs.GPR.n.s2) -#define s3 (psxRegs.GPR.n.s3) -#define s4 (psxRegs.GPR.n.s4) -#define s5 (psxRegs.GPR.n.s5) -#define s6 (psxRegs.GPR.n.s6) -#define s7 (psxRegs.GPR.n.s7) -#define t8 (psxRegs.GPR.n.t6) -#define t9 (psxRegs.GPR.n.t7) -#define k0 (psxRegs.GPR.n.k0) -#define k1 (psxRegs.GPR.n.k1) -#define gp (psxRegs.GPR.n.gp) -#define sp (psxRegs.GPR.n.sp) -#define fp (psxRegs.GPR.n.s8) -#define ra (psxRegs.GPR.n.ra) -#define pc0 (psxRegs.pc) - -#define Ra0 ((char*)PSXM(a0)) -#define Ra1 ((char*)PSXM(a1)) -#define Ra2 ((char*)PSXM(a2)) -#define Ra3 ((char*)PSXM(a3)) -#define Rv0 ((char*)PSXM(v0)) -#define Rsp ((char*)PSXM(sp)) - - - -typedef struct _malloc_chunk { - unsigned long stat; - unsigned long size; - struct _malloc_chunk *fd; - struct _malloc_chunk *bk; -} malloc_chunk; - -#define INUSE 0x1 - -typedef struct { - u32 desc; - s32 status; - s32 mode; - u32 fhandler; -} EvCB[32]; - -#define EvStUNUSED 0x0000 -#define EvStWAIT 0x1000 -#define EvStACTIVE 0x2000 -#define EvStALREADY 0x4000 - -#define EvMdINTR 0x1000 -#define EvMdNOINTR 0x2000 - -typedef struct { - long next; - long func1; - long func2; - long pad; -} SysRPst; - -typedef struct { - s32 status; - s32 mode; - u32 reg[32]; - u32 func; -} TCB; - -typedef struct { - unsigned long _pc0; - unsigned long gp0; - unsigned long t_addr; - unsigned long t_size; - unsigned long d_addr; - unsigned long d_size; - unsigned long b_addr; - unsigned long b_size; - unsigned long S_addr; - unsigned long s_size; - unsigned long _sp,_fp,_gp,ret,base; -} EXEC; - -struct DIRENTRY { - char name[20]; - long attr; - long size; - struct DIRENTRY *next; - long head; - char system[4]; -}; - -typedef struct { - char name[32]; - u32 mode; - u32 offset; - u32 size; - u32 mcfile; -} FileDesc; - -static unsigned long *jmp_int = NULL; -static int *pad_buf = NULL; -static char *pad_buf1,*pad_buf2;//shadow add -static int pad_buf1len,pad_buf2len;//shadow add - - -static u32 regs[35]; -static EvCB *Event; -static EvCB *HwEV; // 0xf0 -static EvCB *EvEV; // 0xf1 -static EvCB *RcEV; // 0xf2 -static EvCB *UeEV; // 0xf3 -static EvCB *SwEV; // 0xf4 -static EvCB *ThEV; // 0xff -static u32 *heap_addr = NULL; -static u32 SysIntRP[8]; -static int CardState = -1; -static TCB Thread[8]; -static int CurThread = 0; -static FileDesc FDesc[32]; - -static __inline void softCall(u32 pc) { - pc0 = pc; - ra = 0x80001000; - while (pc0 != 0x80001000) psxCpu->ExecuteBlock(); -} - -static __inline void softCall2(u32 pc) { - u32 sra = ra; - pc0 = pc; - ra = 0x80001000; - while (pc0 != 0x80001000) psxCpu->ExecuteBlock(); - ra = sra; -} - -static __inline void DeliverEvent(u32 ev, u32 spec) { - if (Event[ev][spec].status != EvStACTIVE) return; - -// Event[ev][spec].status = EvStALREADY; - if (Event[ev][spec].mode == EvMdINTR) { - softCall2(Event[ev][spec].fhandler); - } else Event[ev][spec].status = EvStALREADY; -} - -/* * -// * -// * -// System calls A0 */ - - -void bios_abs() { // 0x0e - v0 = abs(a0); - pc0 = ra; -} - -void bios_labs() { // 0x0f - v0 = labs(a0); - pc0 = ra; -} - -void bios_atoi() { // 0x10 - v0 = atoi((char *)Ra0); - pc0 = ra; -} - -void bios_atol() { // 0x11 - v0 = atoi((char *)Ra0); - pc0 = ra; -} - -void bios_setjmp() { // 13 - u32 *jmp_buf= (u32*)Ra0; - int i; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosA0n[0x13]); -#endif - - jmp_buf[0] = ra; - jmp_buf[1] = sp; - jmp_buf[2] = fp; - for (i=0; i<8; i++) // s0-s7 - jmp_buf[3+i] = psxRegs.GPR.r[16+i]; - jmp_buf[11] = gp; - - v0 = 0; pc0 = ra; -} - -void bios_longjmp() { //14 - u32 *jmp_buf= (u32*)Ra0; - int i; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosA0n[0x14]); -#endif - - ra = jmp_buf[0]; /* ra */ - sp = jmp_buf[1]; /* sp */ - fp = jmp_buf[2]; /* fp */ - for (i=0; i<8; i++) // s0-s7 - psxRegs.GPR.r[16+i] = jmp_buf[3+i]; - gp = jmp_buf[11]; /* gp */ - - v0 = a1; pc0 = ra; -} - -void bios_strcat() { // 0x15 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %s, %s\n", biosA0n[0x15], Ra0, Ra1); -#endif - - strcat(Ra0, Ra1); - v0 = a0; pc0 = ra; -} - -/*0x16*/void bios_strncat() { strncat(Ra0, Ra1, a2); v0 = a0; pc0 = ra;} - -void bios_strcmp() { // 0x17 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %s (%lx), %s (%lx)\n", biosA0n[0x17], Ra0, a0, Ra1, a1); -#endif - - v0 = strcmp(Ra0, Ra1); - pc0 = ra; -} - -void bios_strncmp() { // 0x18 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %s (%lx), %s (%lx), %d\n", biosA0n[0x18], Ra0, a0, Ra1, a1, a2); -#endif - - v0 = strncmp(Ra0, Ra1, a2); - pc0 = ra; -} - -/*0x19*/void bios_strcpy() { strcpy(Ra0, Ra1); v0 = a0; pc0 = ra;} -/*0x1a*/void bios_strncpy() { strncpy(Ra0, Ra1, a2); v0 = a0; pc0 = ra;} -/*0x1b*/void bios_strlen() { v0 = strlen(Ra0); pc0 = ra;} - -void bios_index() { // 0x1c - char *pcA0 = (char *)Ra0; - char *pcRet = strchr(pcA0, a1); - if(pcRet) - v0 = a0 + pcRet - pcA0; - else - v0 = 0; - pc0 = ra; -} - -void bios_rindex() { // 0x1d - char *pcA0 = (char *)Ra0; - char *pcRet = strrchr(pcA0, a1); - if(pcRet) - v0 = a0 + pcRet - pcA0; - else - v0 = 0; - pc0 = ra; -} - -void bios_strchr() { // 0x1e - char *pcA0 = (char *)Ra0; - char *pcRet = strchr(pcA0, a1); - if(pcRet) - v0 = a0 + pcRet - pcA0; - else - v0 = 0; - pc0 = ra; -} - -void bios_strrchr() { // 0x1f - char *pcA0 = (char *)Ra0; - char *pcRet = strrchr(pcA0, a1); - if(pcRet) - v0 = a0 + pcRet - pcA0; - else - v0 = 0; - pc0 = ra; -} - -void bios_strpbrk() { // 0x20 - char *pcA0 = (char *)Ra0; - char *pcRet = strpbrk(pcA0, (char *)Ra1); - if(pcRet) - v0 = a0 + pcRet - pcA0; - else - v0 = 0; - pc0 = ra; -} - -void bios_strspn() { v0 = strspn ((char *)Ra0, (char *)Ra1); pc0 = ra;}/*21*/ -void bios_strcspn() { v0 = strcspn((char *)Ra0, (char *)Ra1); pc0 = ra;}/*22*/ - -void bios_strtok() { // 0x23 - char *pcA0 = (char *)Ra0; - char *pcRet = strtok(pcA0, (char *)Ra1); - if(pcRet) - v0 = a0 + pcRet - pcA0; - else - v0 = 0; - pc0 = ra; -} - -void bios_strstr() { // 0x24 - char *pcA0 = (char *)Ra0; - char *pcRet = strstr(pcA0, (char *)Ra1); - if(pcRet) - v0 = a0 + pcRet - pcA0; - else - v0 = 0; - pc0 = ra; -} - -/*0x25*/void bios_toupper() {v0 = toupper(a0); pc0 = ra;} -/*0x26*/void bios_tolower() {v0 = tolower(a0); pc0 = ra;} -/*0x27*/void bios_bcopy() {memcpy(Ra1,Ra0,a2); pc0=ra;} -/*0x28*/void bios_bzero() {memset(Ra0,0,a1); pc0=ra;} -/*0x29*/void bios_bcmp() {v0 = memcmp(Ra0,Ra1,a2); pc0=ra; } -/*0x2a*/void bios_memcpy() {memcpy(Ra0, Ra1, a2); v0 = a0; pc0 = ra;} -/*0x2b*/void bios_memset() {memset(Ra0, a1, a2); v0 = a0; pc0 = ra;} -/*0x2c*/void bios_memmove() {memmove(Ra0, Ra1, a2); v0 = a0; pc0 = ra;} -/*0x2d*/void bios_memcmp() {v0 = memcmp(Ra0, Ra1, a2); pc0 = ra;} - -void bios_memchr() { // 2e - void *ret = memchr(Ra0, a1, a2); - if (ret != NULL) v0 = (unsigned long)((char*)ret - Ra0) + a0; - else v0 = 0; - pc0 = ra; -} - -void bios_rand() { // 2f - v0 = 1+(int) (32767.0*rand()/(RAND_MAX+1.0)); - pc0 = ra; -} - -void bios_srand() { // 30 - srand(a0); pc0 = ra; -} - -void bios_malloc() { // 33 - malloc_chunk *chunk; - malloc_chunk *fd; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosA0n[0x33]); -#endif - - chunk = (malloc_chunk *)heap_addr; - if (chunk == NULL) { v0 = 0; return; } - - for (; ((a0 > chunk->size) || (chunk->stat == INUSE)) || (chunk->fd != NULL); chunk = chunk->fd); -//printf ("chunk %lx\n",chunk->size); - /* split free chunk */ - fd = chunk + sizeof(malloc_chunk) + a0; - fd->stat = chunk->stat; - fd->size = chunk->size - a0; - fd->fd = chunk->fd; - fd->bk = chunk; - - /* set new chunk */ - chunk->stat = INUSE; - chunk->size = a0; - chunk->fd = fd; - - v0 = ((unsigned long)chunk - (unsigned long)psxM) + sizeof(malloc_chunk); - v0|= 0x80000000; -// printf ("malloc %lx,%lx\n", v0, a0); - pc0 = ra; -} - -void bios_InitHeap() { // 39 - malloc_chunk *chunk; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosA0n[0x39]); -#endif - - heap_addr = (u32*)Ra0; - - chunk = (malloc_chunk *)heap_addr; - chunk->stat = 0; - if (((a0 & 0x1fffff) + a1)>= 0x200000) chunk->size = 0x1ffffc - (a0 & 0x1fffff); - else chunk->size = a1; - chunk->fd = NULL; - chunk->bk = NULL; - - SysPrintf("InitHeap %lx,%lx : %lx\n",a0,a1,chunk->size); - - pc0 = ra; -} - -void bios_getchar(){ v0 = getchar(); pc0=ra;} //0x3b - -void bios_printf() { // 3f - char tmp[1024]; - char tmp2[1024]; - unsigned long save[4]; - char *ptmp = tmp; - int n=1, i=0, j; - - memcpy(save, (char*)PSXM(sp), 4*4); - psxMu32(sp) = a0; - psxMu32(sp + 4) = a1; - psxMu32(sp + 8) = a2; - psxMu32(sp + 12) = a3; - - while (Ra0[i]) { - switch (Ra0[i]) { - case '%': - j = 0; - tmp2[j++] = '%'; -_start: - switch (Ra0[++i]) { - case '.': - case 'l': - tmp2[j++] = Ra0[i]; goto _start; - default: - if (Ra0[i] >= '0' && Ra0[i] <= '9') { - tmp2[j++] = Ra0[i]; - goto _start; - } - break; - } - tmp2[j++] = Ra0[i]; - tmp2[j] = 0; - - switch (Ra0[i]) { - case 'f': case 'F': - ptmp+= sprintf(ptmp, tmp2, (float)psxMu32(sp + n * 4)); n++; break; - case 'a': case 'A': - case 'e': case 'E': - case 'g': case 'G': - ptmp+= sprintf(ptmp, tmp2, (double)psxMu32(sp + n * 4)); n++; break; - case 'p': - case 'i': - case 'd': case 'D': - case 'o': case 'O': - case 'x': case 'X': - ptmp+= sprintf(ptmp, tmp2, (unsigned int)psxMu32(sp + n * 4)); n++; break; - case 'c': - ptmp+= sprintf(ptmp, tmp2, (unsigned char)psxMu32(sp + n * 4)); n++; break; - case 's': - ptmp+= sprintf(ptmp, tmp2, (char*)PSXM(psxMu32(sp + n * 4))); n++; break; - case '%': - *ptmp++ = Ra0[i]; break; - } - i++; - break; - default: - *ptmp++ = Ra0[i++]; - } - } - *ptmp = 0; - - memcpy((char*)PSXM(sp), save, 4*4); - - SysPrintf(tmp); - - pc0 = ra; -} - -/* - * int Exec(struct EXEC *header , int argc , char **argv); - */ - -void bios_Exec() { // 43 - EXEC *header = (EXEC*)Ra0; - u32 tmp; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x, %x, %x\n", biosA0n[0x43], a0, a1, a2); -#endif - - header->_sp = sp; - header->_fp = fp; - header->_sp = sp; - header->_gp = gp; - header->ret = ra; - header->base = s0; - - if (header->S_addr != 0) { - tmp = header->S_addr + header->s_size; - sp = tmp; - fp = sp; - } - - gp = header->gp0; - - s0 = a0; - - a0 = a1; - a1 = a2; - - ra = 0x8000; - pc0 = header->_pc0; -} - -void bios_FlushCache() { // 44 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosA0n[0x44]); -#endif - - pc0 = ra; -} - -void bios_GPU_dw() { // 0x46 - int size; - long *ptr; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosA0n[0x46]); -#endif - - GPU_writeData(0xa0000000); - GPU_writeData((a1<<16)|(a0&0xffff)); - GPU_writeData((a3<<16)|(a2&0xffff)); - size = (a2*a3+1)/2; - ptr = (long*)PSXM(Rsp[4]); //that is correct? - do { - GPU_writeData(*ptr++); - } while(--size); - - pc0 = ra; -} - -void bios_mem2vram() { // 0x47 - int size; - - GPU_writeData(0xa0000000); - GPU_writeData((a1<<16)|(a0&0xffff)); - GPU_writeData((a3<<16)|(a2&0xffff)); - size = (a2*a3+1)/2; - GPU_writeStatus(0x04000002); - psxHwWrite32(0x1f8010f4,0); - psxHwWrite32(0x1f8010f0,psxHwRead32(0x1f8010f0)|0x800); - psxHwWrite32(0x1f8010a0,Rsp[4]);//might have a buggy... - psxHwWrite32(0x1f8010a4,((size/16)<<16)|16); - psxHwWrite32(0x1f8010a8,0x01000201); - - pc0 = ra; -} - -void bios_SendGPU() { // 0x48 - GPU_writeStatus(a0); - pc0 = ra; -} - -void bios_GPU_cw() { // 0x49 - GPU_writeData(a0); - pc0 = ra; -} - -void bios_GPU_cwb() { // 0x4a - long *ptr = (long*)Ra0; - int size = a1; - while(size--) { - GPU_writeData(*ptr++); - } - - pc0 = ra; -} - -void bios_GPU_SendPackets() { //4b: - GPU_writeStatus(0x04000002); - psxHwWrite32(0x1f8010f4,0); - psxHwWrite32(0x1f8010f0,psxHwRead32(0x1f8010f0)|0x800); - psxHwWrite32(0x1f8010a0,a0); - psxHwWrite32(0x1f8010a4,0); - psxHwWrite32(0x1f8010a8,0x010000401); - pc0 = ra; -} - -void bios_sys_a0_4c() { // 0x4c GPU relate - psxHwWrite32(0x1f8010a8,0x00000401); - GPU_writeData(0x0400000); - GPU_writeData(0x0200000); - GPU_writeData(0x0100000); - - pc0 = ra; -} - -void bios_GPU_GetGPUStatus() { // 0x4d - v0 = GPU_readStatus(); - pc0 = ra; -} - -void bios__bu_init() { // 70 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosA0n[0x70]); -#endif - - DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 - DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 - - pc0 = ra; -} - -void bios__96_remove() { // 72 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosA0n[0x72]); -#endif - - pc0 = ra; -} - -void bios__card_info() { // ab -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x\n", biosA0n[0xab], a0); -#endif - -// DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 - DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 - - v0 = 1; pc0 = ra; -} - -void bios__card_load() { // ac -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x\n", biosA0n[0xac], a0); -#endif - -// DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 - DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 - - v0 = 1; pc0 = ra; -} - -/* System calls B0 */ - -void bios_SetRCnt() { // 02 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x02]); -#endif - - a0&= 0x3; - if (a0 != 3) { - unsigned long mode=0; - - psxRcntWtarget(a0, a1); - if (a2&0x1000) mode|= 0x050; // Interrupt Mode - if (a2&0x0100) mode|= 0x008; // Count to 0xffff - if (a2&0x0010) mode|= 0x001; // Timer stop mode - if (a0 == 2) { if (a2&0x0001) mode|= 0x200; } // System Clock mode - else { if (a2&0x0001) mode|= 0x100; } // System Clock mode - - psxRcntWmode(a0, mode); - } - pc0 = ra; -} - -void bios_GetRCnt() { // 03 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x03]); -#endif - - a0&= 0x3; - if (a0 != 3) v0 = psxRcntRcount(a0); - else v0 = 0; - pc0 = ra; -} - -void bios_StartRCnt() { // 04 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x04]); -#endif - - a0&= 0x3; - if (a0 != 3) psxHu32(0x1074)|= (1<<(a0+4)); - else psxHu32(0x1074)|= 0x1; - v0 = 1; pc0 = ra; -} - -void bios_StopRCnt() { // 05 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x05]); -#endif - - a0&= 0x3; - if (a0 != 3) psxHu32(0x1074)&= ~(1<<(a0+4)); - else psxHu32(0x1074)&= ~0x1; - pc0 = ra; -} - -void bios_ResetRCnt() { // 06 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x06]); -#endif - - a0&= 0x3; - if (a0 != 3) { - psxRcntWmode(a0, 0); - psxRcntWtarget(a0, 0); - psxRcntWcount(a0, 0); - } - pc0 = ra; -} - - -/* gets ev for use with Event */ -#define GetEv() \ - ev = (a0 >> 24) & 0xf; \ - if (ev == 0xf) ev = 0x5; \ - ev*= 32; \ - ev+= a0&0x1f; - -/* gets spec for use with Event */ -#define GetSpec() \ - spec = 0; \ - switch (a1) { \ - case 0x0301: spec = 16; break; \ - case 0x0302: spec = 17; break; \ - default: \ - for (i=0; i<16; i++) if (a1 & (1 << i)) { spec = i; break; } \ - break; \ - } - -void bios_DeliverEvent() { // 07 - int ev, spec; - int i; - - GetEv(); - GetSpec(); - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s %x,%x\n", biosB0n[0x07], ev, spec); -#endif - - DeliverEvent(ev, spec); - - pc0 = ra; -} - -void bios_OpenEvent() { // 08 - int ev, spec; - int i; - - GetEv(); - GetSpec(); - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s %x,%x (class:%lx, spec:%lx, mode:%lx, func:%lx)\n", biosB0n[0x08], ev, spec, a0, a1, a2, a3); -#endif - - Event[ev][spec].status = EvStWAIT; - Event[ev][spec].mode = a2; - Event[ev][spec].fhandler = a3; - - v0 = ev | (spec << 8); - pc0 = ra; -} - -void bios_CloseEvent() { // 09 - int ev, spec; - - ev = a0 & 0xff; - spec = (a0 >> 8) & 0xff; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s %x,%x\n", biosB0n[0x09], ev, spec); -#endif - - Event[ev][spec].status = EvStUNUSED; - - v0 = 1; pc0 = ra; -} - -void bios_WaitEvent() { // 0a - int ev, spec; - - ev = a0 & 0xff; - spec = (a0 >> 8) & 0xff; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s %x,%x\n", biosB0n[0x0a], ev, spec); -#endif - - Event[ev][spec].status = EvStACTIVE; - - v0 = 1; pc0 = ra; -} - -void bios_TestEvent() { // 0b - int ev, spec; - - ev = a0 & 0xff; - spec = (a0 >> 8) & 0xff; - - if (Event[ev][spec].status == EvStALREADY) { - Event[ev][spec].status = EvStACTIVE; v0 = 1; - } else v0 = 0; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s %x,%x: %x\n", biosB0n[0x0b], ev, spec, v0); -#endif - - pc0 = ra; -} - -void bios_EnableEvent() { // 0c - int ev, spec; - - ev = a0 & 0xff; - spec = (a0 >> 8) & 0xff; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s %x,%x\n", biosB0n[0x0c], ev, spec); -#endif - - Event[ev][spec].status = EvStACTIVE; - - v0 = 1; pc0 = ra; -} - -void bios_DisableEvent() { // 0d - int ev, spec; - - ev = a0 & 0xff; - spec = (a0 >> 8) & 0xff; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s %x,%x\n", biosB0n[0x0d], ev, spec); -#endif - - Event[ev][spec].status = EvStWAIT; - - v0 = 1; pc0 = ra; -} - -/* - * long OpenTh(long (*func)(), unsigned long sp, unsigned long gp); - */ - -void bios_OpenTh() { // 0e - int th; - - for (th=1; th<8; th++) - if (Thread[th].status == 0) break; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x\n", biosB0n[0x0e], th); -#endif - - Thread[th].status = 1; - Thread[th].func = a0; - Thread[th].reg[29] = a1; - Thread[th].reg[28] = a2; - - v0 = th; pc0 = ra; -} - -/* - * int CloseTh(long thread); - */ - -void bios_CloseTh() { // 0f - int th = a0 & 0xff; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x\n", biosB0n[0x0f], th); -#endif - - if (Thread[th].status == 0) { - v0 = 0; - } else { - Thread[th].status = 0; - v0 = 1; - } - - pc0 = ra; -} - -/* - * int ChangeTh(long thread); - */ - -void bios_ChangeTh() { // 10 - int th = a0 & 0xff; - -#ifdef PSXBIOS_LOG -// PSXBIOS_LOG("bios_%s: %x\n", biosB0n[0x10], th); -#endif - - if (Thread[th].status == 0 || CurThread == th) { - v0 = 0; - - pc0 = ra; - } else { - v0 = 1; - - if (Thread[CurThread].status == 2) { - Thread[CurThread].status = 1; - Thread[CurThread].func = ra; - memcpy(Thread[CurThread].reg, psxRegs.GPR.r, 32*4); - } - - memcpy(psxRegs.GPR.r, Thread[th].reg, 32*4); - pc0 = Thread[th].func; - Thread[th].status = 2; - CurThread = th; - } -} - -void bios_InitPAD() { // 0x12 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x12]); -#endif - - pad_buf1 = (char*)Ra0; - pad_buf1len = a1; - pad_buf2 = (char*)Ra2; - pad_buf2len = a3; - - v0 = 1; pc0 = ra; -} - -void bios_StartPAD() { // 13 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x13]); -#endif - - psxHwWrite16(0x1f801074, (unsigned short)(psxHwRead16(0x1f801074) | 0x1)); - psxRegs.CP0.n.Status |= 0x401; - pc0 = ra; -} - -void bios_StopPAD() { // 14 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x14]); -#endif - - pad_buf1 = NULL; - pad_buf2 = NULL; - pc0 = ra; -} - -void bios_PAD_init() { // 15 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x15]); -#endif - - psxHwWrite16(0x1f801074, (u16)(psxHwRead16(0x1f801074) | 0x1)); - pad_buf = (int*)Ra1; - *pad_buf = -1; - psxRegs.CP0.n.Status |= 0x401; - pc0 = ra; -} - -void bios_PAD_dr() { // 16 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x16]); -#endif - - v0 = -1; pc0 = ra; -} - -void bios_ReturnFromException() { // 17 - memcpy(psxRegs.GPR.r, regs, 32*4); - psxRegs.GPR.n.lo = regs[32]; - psxRegs.GPR.n.hi = regs[33]; - - pc0 = psxRegs.CP0.n.EPC; - if (psxRegs.CP0.n.Cause & 0x80000000) pc0+=4; - - psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status & 0xfffffff0) | - ((psxRegs.CP0.n.Status & 0x3c) >> 2); -} - -void bios_ResetEntryInt() { // 18 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x18]); -#endif - - jmp_int = NULL; - pc0 = ra; -} - -void bios_HookEntryInt() { // 19 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x19]); -#endif - - jmp_int = (u32*)Ra0; - pc0 = ra; -} - -void bios_UnDeliverEvent() { // 0x20 - int ev, spec; - int i; - - GetEv(); - GetSpec(); - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s %x,%x\n", biosB0n[0x07], ev, spec); -#endif - - if (Event[ev][spec].status == EvStALREADY && - Event[ev][spec].mode == EvMdNOINTR) - Event[ev][spec].status = EvStACTIVE; - - pc0 = ra; -} - -#define buopen(mcd) { \ - strcpy(FDesc[1 + mcd].name, Ra0+5); \ - FDesc[1 + mcd].offset = 0; \ - FDesc[1 + mcd].mode = a1; \ - \ - for (i=1; i<16; i++) { \ - ptr = Mcd##mcd##Data + 128 * i; \ - if ((*ptr & 0xF0) != 0x50) continue; \ - if (strcmp(FDesc[1 + mcd].name, ptr+0xa)) continue; \ - FDesc[1 + mcd].mcfile = i; \ - SysPrintf("open %s\n", ptr+0xa); \ - v0 = 1 + mcd; \ - break; \ - } \ - if (a1 & 0x200 && v0 == -1) { /* FCREAT */ \ - for (i=1; i<16; i++) { \ - int j, xor = 0; \ - \ - ptr = Mcd##mcd##Data + 128 * i; \ - if ((*ptr & 0xF0) == 0x50) continue; \ - ptr[0] = 0x50 | (u8)(a1 >> 16); \ - ptr[4] = 0x00; \ - ptr[5] = 0x20; \ - ptr[6] = 0x00; \ - ptr[7] = 0x00; \ - ptr[8] = 'B'; \ - ptr[9] = 'I'; \ - strcpy(ptr+0xa, FDesc[1 + mcd].name); \ - for (j=0; j<127; j++) xor^= ptr[j]; \ - ptr[127] = xor; \ - FDesc[1 + mcd].mcfile = i; \ - SysPrintf("openC %s\n", ptr); \ - v0 = 1 + mcd; \ - break; \ - } \ - } \ -} - -/* - * int open(char *name , int mode); - */ - -void bios_open() { // 0x32 - int i; - char *ptr; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %s,%x\n", biosB0n[0x32], Ra0, a1); -#endif - - v0 = -1; - - if (!strncmp(Ra0, "bu00", 4)) { - buopen(1); - } - - if (!strncmp(Ra0, "bu10", 4)) { - buopen(2); - } - - pc0 = ra; -} - -/* - * int lseek(int fd , int offset , int whence); - */ - -void bios_lseek() { // 0x33 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x, %x, %x\n", biosB0n[0x33], a0, a1, a2); -#endif - - switch (a2) { - case 0: // SEEK_SET - FDesc[a0].offset = a1; - v0 = a1; -// DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 -// DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 - break; - - case 1: // SEEK_CUR - FDesc[a0].offset+= a1; - v0 = FDesc[a0].offset; - break; - } - - pc0 = ra; -} - -#define buread(mcd) { \ - SysPrintf("read %d: %x,%x (%s)\n", FDesc[1 + mcd].mcfile, FDesc[1 + mcd].offset, a2, Mcd##mcd##Data + 128 * FDesc[1 + mcd].mcfile + 0xa); \ - ptr = Mcd##mcd##Data + 8192 * FDesc[1 + mcd].mcfile + FDesc[1 + mcd].offset; \ - memcpy(Ra1, ptr, a2); \ - if (FDesc[1 + mcd].mode & 0x8000) v0 = 0; \ - else v0 = a2; \ - DeliverEvent(0x11, 0x2); /* 0xf0000011, 0x0004 */ \ - DeliverEvent(0x81, 0x2); /* 0xf4000001, 0x0004 */ \ -} - -/* - * int read(int fd , void *buf , int nbytes); - */ - -void bios_read() { // 0x34 - char *ptr; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x, %x, %x\n", biosB0n[0x34], a0, a1, a2); -#endif - - v0 = -1; - - switch (a0) { - case 2: buread(1); break; - case 3: buread(2); break; - } - - pc0 = ra; -} - -#define buwrite(mcd) { \ - u32 offset = + 8192 * FDesc[1 + mcd].mcfile + FDesc[1 + mcd].offset; \ - SysPrintf("write %d: %x,%x\n", FDesc[1 + mcd].mcfile, FDesc[1 + mcd].offset, a2); \ - ptr = Mcd##mcd##Data + offset; \ - memcpy(ptr, Ra1, a2); \ - SaveMcd(Config.Mcd##mcd, Mcd##mcd##Data, offset, a2); \ - if (FDesc[1 + mcd].mode & 0x8000) v0 = 0; \ - else v0 = a2; \ - DeliverEvent(0x11, 0x2); /* 0xf0000011, 0x0004 */ \ - DeliverEvent(0x81, 0x2); /* 0xf4000001, 0x0004 */ \ -} - -/* - * int write(int fd , void *buf , int nbytes); - */ - -void bios_write() { // 0x35/0x03 - char *ptr; - - if (a0 == 1) { // stdout - char buf[1024]; - - memcpy(buf, Ra1, a2); - buf[a2] = 0; - SysPrintf(buf); - pc0 = ra; return; - } -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x,%x,%x\n", biosB0n[0x35], a0, a1, a2); -#endif - - v0 = -1; - - switch (a0) { - case 2: buwrite(1); break; - case 3: buwrite(2); break; - } - - pc0 = ra; -} - -/* - * int close(int fd); - */ - -void bios_close() { // 0x36 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x\n", biosB0n[0x36], a0); -#endif - - v0 = a0; pc0 = ra; -} - -void bios_putchar () { // 3d - char tmp[12]; - - sprintf (tmp,"%c",(char)a0); - SysPrintf(tmp); - - pc0 = ra; -} - -void bios_puts () { // 3e/3f - SysPrintf(Ra0); - - pc0 = ra; -} - -char ffile[64], *pfile; -int nfile; - -#define bufile(mcd) { \ - while (nfile < 16) { \ - int match=1; \ - \ - ptr = Mcd##mcd##Data + 128 * nfile; \ - nfile++; \ - if ((*ptr & 0xF0) != 0x50) continue; \ - ptr+= 0xa; \ - for (i=0; i<20; i++) { \ - if (pfile[i] == ptr[i]) { \ - dir->name[i] = ptr[i]; \ - if (ptr[i] == 0) break; else continue; } \ - if (pfile[i] == '?') { \ - dir->name[i] = ptr[i]; continue; } \ - if (pfile[i] == '*') { \ - strcpy(dir->name+i, ptr+i); break; } \ - match = 0; break; \ - } \ - SysPrintf("%d : %s = %s + %s (match=%d)\n", nfile, dir->name, pfile, ptr, match); \ - if (match == 0) continue; \ - dir->size = 8192; \ - v0 = _dir; \ - break; \ - } \ -} - -/* - * struct DIRENTRY* firstfile(char *name,struct DIRENTRY *dir); - */ - -void bios_firstfile() { // 42 - struct DIRENTRY *dir = (struct DIRENTRY *)Ra1; - u32 _dir = a1; - char *ptr; - int i; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %s\n", biosB0n[0x42], Ra0); -#endif - - v0 = 0; - - strcpy(ffile, Ra0); - pfile = ffile+5; - nfile = 1; - if (!strncmp(Ra0, "bu00", 4)) { - bufile(1); - } - - if (!strncmp(Ra0, "bu10", 4)) { - bufile(2); - } - - pc0 = ra; -} - -/* - * struct DIRENTRY* nextfile(struct DIRENTRY *dir); - */ - -void bios_nextfile() { // 43 - struct DIRENTRY *dir = (struct DIRENTRY *)Ra0; - u32 _dir = a0; - char *ptr; - int i; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %s\n", biosB0n[0x43], dir->name); -#endif - - v0 = 0; - - if (!strncmp(ffile, "bu00", 4)) { - bufile(1); - } - - if (!strncmp(ffile, "bu10", 4)) { - bufile(2); - } - - pc0 = ra; -} - -#define budelete(mcd) { \ - for (i=1; i<16; i++) { \ - ptr = Mcd##mcd##Data + 128 * i; \ - if ((*ptr & 0xF0) != 0x50) continue; \ - if (strcmp(Ra0+5, ptr+0xa)) continue; \ - *ptr = (*ptr & 0xf) | 0xA0; \ - SysPrintf("delete %s\n", ptr+0xa); \ - v0 = 1; \ - break; \ - } \ -} - -/* - * int delete(char *name); - */ - -void bios_delete() { // 45 - char *ptr; - int i; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %s\n", biosB0n[0x45], Ra0); -#endif - - v0 = 0; - - if (!strncmp(Ra0, "bu00", 4)) { - budelete(1); - } - - if (!strncmp(Ra0, "bu10", 4)) { - budelete(2); - } - - pc0 = ra; -} - -void bios_InitCARD() { // 4a -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x\n", biosB0n[0x4a], a0); -#endif - - CardState = 0; - - pc0 = ra; -} - -void bios_StartCARD() { // 4b -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x4b]); -#endif - - if (CardState == 0) CardState = 1; - - pc0 = ra; -} - -void bios_StopCARD() { // 4c -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x4c]); -#endif - - if (CardState == 1) CardState = 0; - - pc0 = ra; -} - -void bios__card_write() { // 0x4e - int port; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x,%x,%x\n", biosB0n[0x4e], a0, a1, a2); -#endif - - port = a0 >> 4; - - if (port == 0) { - memcpy(Mcd1Data + a1 * 128, Ra2, 128); - SaveMcd(Config.Mcd1, Mcd1Data, a1 * 128, 128); - } else { - memcpy(Mcd2Data + a1 * 128, Ra2, 128); - SaveMcd(Config.Mcd2, Mcd2Data, a1 * 128, 128); - } - - DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 -// DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 - - v0 = 1; pc0 = ra; -} - -void bios__card_read() { // 0x4f - int port; - -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x4f]); -#endif - - port = a0 >> 4; - - if (port == 0) { - memcpy(Ra2, Mcd1Data + a1 * 128, 128); - } else { - memcpy(Ra2, Mcd2Data + a1 * 128, 128); - } - - DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 -// DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 - - v0 = 1; pc0 = ra; -} - -void bios__new_card() { // 0x50 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x50]); -#endif - - pc0 = ra; -} - -void bios_GetC0Table() { // 56 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x56]); -#endif - - v0 = 0x674; pc0 = ra; -} - -void bios_GetB0Table() { // 57 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s\n", biosB0n[0x57]); -#endif - - v0 = 0x874; pc0 = ra; -} - -void bios_ChangeClearPad() { // 5b -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x\n", biosB0n[0x5b], a0); -#endif - - pc0 = ra; -} - -/* System calls C0 */ - -/* - * int SysEnqIntRP(int index , long *queue); - */ - -void bios_SysEnqIntRP() { // 02 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x\n", biosC0n[0x02] ,a0); -#endif - - SysIntRP[a0] = a1; - - v0 = 0; pc0 = ra; -} - -/* - * int SysDeqIntRP(int index , long *queue); - */ - -void bios_SysDeqIntRP() { // 03 -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x\n", biosC0n[0x03] ,a0); -#endif - - SysIntRP[a0] = 0; - - v0 = 0; pc0 = ra; -} - -void bios_ChangeClearRCnt() { // 0a -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("bios_%s: %x\n", biosC0n[0x0a] ,a0); -#endif - - psxRegs.CP0.n.Status|= 0x404; - pc0 = ra; -} - -void bios_dummy() { -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("unk %lx call: %lx\n", pc0 & 0x1fffff, t1); -#endif - pc0 = ra; -} - -void (*biosA0[256])(); -void (*biosB0[256])(); -void (*biosC0[256])(); - -void psxBiosInit() { - u32 base, size; - u32 *ptr; - int i; - - for(i = 0; i < 256; i++) { - biosA0[i] = NULL; - biosB0[i] = NULL; - biosC0[i] = NULL; - } - biosA0[0x3e] = bios_puts; - biosA0[0x3f] = bios_printf; - - biosB0[0x3d] = bios_putchar; - biosB0[0x3f] = bios_puts; - - if (!Config.HLE) return; - - for(i = 0; i < 256; i++) { - if (biosA0[i] == NULL) biosA0[i] = bios_dummy; - if (biosB0[i] == NULL) biosB0[i] = bios_dummy; - if (biosC0[i] == NULL) biosC0[i] = bios_dummy; - } - - biosA0[0x00] = bios_open; - biosA0[0x01] = bios_lseek; - biosA0[0x02] = bios_read; - biosA0[0x03] = bios_write; - biosA0[0x04] = bios_close; - //biosA0[0x05] = bios_ioctl; - //biosA0[0x06] = bios_exit; - //biosA0[0x07] = bios_sys_a0_07; - //biosA0[0x08] = bios_getc; - //biosA0[0x09] = bios_putc; - //biosA0[0x0a] = bios_todigit; - //biosA0[0x0b] = bios_atof; - //biosA0[0x0c] = bios_strtoul; - //biosA0[0x0d] = bios_strtol; - biosA0[0x0e] = bios_abs; - biosA0[0x0f] = bios_labs; - biosA0[0x10] = bios_atoi; - biosA0[0x11] = bios_atol; - //biosA0[0x12] = bios_atob; - biosA0[0x13] = bios_setjmp; - biosA0[0x14] = bios_longjmp; - biosA0[0x15] = bios_strcat; - biosA0[0x16] = bios_strncat; - biosA0[0x17] = bios_strcmp; - biosA0[0x18] = bios_strncmp; - biosA0[0x19] = bios_strcpy; - biosA0[0x1a] = bios_strncpy; - biosA0[0x1b] = bios_strlen; - biosA0[0x1c] = bios_index; - biosA0[0x1d] = bios_rindex; - biosA0[0x1e] = bios_strchr; - biosA0[0x1f] = bios_strrchr; - biosA0[0x20] = bios_strpbrk; - biosA0[0x21] = bios_strspn; - biosA0[0x22] = bios_strcspn; - biosA0[0x23] = bios_strtok; - biosA0[0x24] = bios_strstr; - biosA0[0x25] = bios_toupper; - biosA0[0x26] = bios_tolower; - biosA0[0x27] = bios_bcopy; - biosA0[0x28] = bios_bzero; - biosA0[0x29] = bios_bcmp; - biosA0[0x2a] = bios_memcpy; - biosA0[0x2b] = bios_memset; - biosA0[0x2c] = bios_memmove; - biosA0[0x2d] = bios_memcmp; - biosA0[0x2e] = bios_memchr; - biosA0[0x2f] = bios_rand; - biosA0[0x30] = bios_srand; - //biosA0[0x31] = bios_qsort; - //biosA0[0x32] = bios_strtod; - biosA0[0x33] = bios_malloc; - //biosA0[0x34] = bios_free; - //biosA0[0x35] = bios_lsearch; - //biosA0[0x36] = bios_bsearch; - //biosA0[0x37] = bios_calloc; - //biosA0[0x38] = bios_realloc; - biosA0[0x39] = bios_InitHeap; - //biosA0[0x3a] = bios__exit; - biosA0[0x3b] = bios_getchar; - biosA0[0x3c] = bios_putchar; - //biosA0[0x3d] = bios_gets; - //biosA0[0x40] = bios_sys_a0_40; - //biosA0[0x41] = bios_LoadTest; - //biosA0[0x42] = bios_Load; - biosA0[0x43] = bios_Exec; - biosA0[0x44] = bios_FlushCache; - //biosA0[0x45] = bios_InstallInterruptHandler; - biosA0[0x46] = bios_GPU_dw; - biosA0[0x47] = bios_mem2vram; - biosA0[0x48] = bios_SendGPU; - biosA0[0x49] = bios_GPU_cw; - biosA0[0x4a] = bios_GPU_cwb; - biosA0[0x4b] = bios_GPU_SendPackets; - biosA0[0x4c] = bios_sys_a0_4c; - biosA0[0x4d] = bios_GPU_GetGPUStatus; - //biosA0[0x4e] = bios_GPU_sync; - //biosA0[0x4f] = bios_sys_a0_4f; - //biosA0[0x50] = bios_sys_a0_50; - //biosA0[0x51] = bios_LoadExec; - //biosA0[0x52] = bios_GetSysSp; - //biosA0[0x53] = bios_sys_a0_53; - //biosA0[0x54] = bios__96_init_a54; - //biosA0[0x55] = bios__bu_init_a55; - //biosA0[0x56] = bios__96_remove_a56; - //biosA0[0x57] = bios_sys_a0_57; - //biosA0[0x58] = bios_sys_a0_58; - //biosA0[0x59] = bios_sys_a0_59; - //biosA0[0x5a] = bios_sys_a0_5a; - //biosA0[0x5b] = bios_dev_tty_init; - //biosA0[0x5c] = bios_dev_tty_open; - //biosA0[0x5d] = bios_sys_a0_5d; - //biosA0[0x5e] = bios_dev_tty_ioctl; - //biosA0[0x5f] = bios_dev_cd_open; - //biosA0[0x60] = bios_dev_cd_read; - //biosA0[0x61] = bios_dev_cd_close; - //biosA0[0x62] = bios_dev_cd_firstfile; - //biosA0[0x63] = bios_dev_cd_nextfile; - //biosA0[0x64] = bios_dev_cd_chdir; - //biosA0[0x65] = bios_dev_card_open; - //biosA0[0x66] = bios_dev_card_read; - //biosA0[0x67] = bios_dev_card_write; - //biosA0[0x68] = bios_dev_card_close; - //biosA0[0x69] = bios_dev_card_firstfile; - //biosA0[0x6a] = bios_dev_card_nextfile; - //biosA0[0x6b] = bios_dev_card_erase; - //biosA0[0x6c] = bios_dev_card_undelete; - //biosA0[0x6d] = bios_dev_card_format; - //biosA0[0x6e] = bios_dev_card_rename; - //biosA0[0x6f] = bios_dev_card_6f; - biosA0[0x70] = bios__bu_init; - //biosA0[0x71] = bios__96_init; - biosA0[0x72] = bios__96_remove; - //biosA0[0x73] = bios_sys_a0_73; - //biosA0[0x74] = bios_sys_a0_74; - //biosA0[0x75] = bios_sys_a0_75; - //biosA0[0x76] = bios_sys_a0_76; - //biosA0[0x77] = bios_sys_a0_77; - //biosA0[0x78] = bios__96_CdSeekL; - //biosA0[0x79] = bios_sys_a0_79; - //biosA0[0x7a] = bios_sys_a0_7a; - //biosA0[0x7b] = bios_sys_a0_7b; - //biosA0[0x7c] = bios__96_CdGetStatus; - //biosA0[0x7d] = bios_sys_a0_7d; - //biosA0[0x7e] = bios__96_CdRead; - //biosA0[0x7f] = bios_sys_a0_7f; - //biosA0[0x80] = bios_sys_a0_80; - //biosA0[0x81] = bios_sys_a0_81; - //biosA0[0x82] = bios_sys_a0_82; - //biosA0[0x83] = bios_sys_a0_83; - //biosA0[0x84] = bios_sys_a0_84; - //biosA0[0x85] = bios__96_CdStop; - //biosA0[0x86] = bios_sys_a0_86; - //biosA0[0x87] = bios_sys_a0_87; - //biosA0[0x88] = bios_sys_a0_88; - //biosA0[0x89] = bios_sys_a0_89; - //biosA0[0x8a] = bios_sys_a0_8a; - //biosA0[0x8b] = bios_sys_a0_8b; - //biosA0[0x8c] = bios_sys_a0_8c; - //biosA0[0x8d] = bios_sys_a0_8d; - //biosA0[0x8e] = bios_sys_a0_8e; - //biosA0[0x8f] = bios_sys_a0_8f; - //biosA0[0x90] = bios_sys_a0_90; - //biosA0[0x91] = bios_sys_a0_91; - //biosA0[0x92] = bios_sys_a0_92; - //biosA0[0x93] = bios_sys_a0_93; - //biosA0[0x94] = bios_sys_a0_94; - //biosA0[0x95] = bios_sys_a0_95; - //biosA0[0x96] = bios_AddCDROMDevice; - //biosA0[0x97] = bios_AddMemCardDevide; - //biosA0[0x98] = bios_DisableKernelIORedirection; - //biosA0[0x99] = bios_EnableKernelIORedirection; - //biosA0[0x9a] = bios_sys_a0_9a; - //biosA0[0x9b] = bios_sys_a0_9b; - //biosA0[0x9c] = bios_SetConf; - //biosA0[0x9d] = bios_GetConf; - //biosA0[0x9e] = bios_sys_a0_9e; - //biosA0[0x9f] = bios_SetMem; - //biosA0[0xa0] = bios__boot; - //biosA0[0xa1] = bios_SystemError; - //biosA0[0xa2] = bios_EnqueueCdIntr; - //biosA0[0xa3] = bios_DequeueCdIntr; - //biosA0[0xa4] = bios_sys_a0_a4; - //biosA0[0xa5] = bios_ReadSector; - //biosA0[0xa6] = bios_get_cd_status; - //biosA0[0xa7] = bios_bufs_cb_0; - //biosA0[0xa8] = bios_bufs_cb_1; - //biosA0[0xa9] = bios_bufs_cb_2; - //biosA0[0xaa] = bios_bufs_cb_3; - biosA0[0xab] = bios__card_info; - biosA0[0xac] = bios__card_load; - //biosA0[0axd] = bios__card_auto; - //biosA0[0xae] = bios_bufs_cd_4; - //biosA0[0xaf] = bios_sys_a0_af; - //biosA0[0xb0] = bios_sys_a0_b0; - //biosA0[0xb1] = bios_sys_a0_b1; - //biosA0[0xb2] = bios_do_a_long_jmp - //biosA0[0xb3] = bios_sys_a0_b3; - //biosA0[0xb4] = bios_sub_function; -//*******************B0 CALLS**************************** - //biosB0[0x00] = bios_SysMalloc; - //biosB0[0x01] = bios_sys_b0_01; - biosB0[0x02] = bios_SetRCnt; - biosB0[0x03] = bios_GetRCnt; - biosB0[0x04] = bios_StartRCnt; - biosB0[0x05] = bios_StopRCnt; - biosB0[0x06] = bios_ResetRCnt; - biosB0[0x07] = bios_DeliverEvent; - biosB0[0x08] = bios_OpenEvent; - biosB0[0x09] = bios_CloseEvent; - biosB0[0x0a] = bios_WaitEvent; - biosB0[0x0b] = bios_TestEvent; - biosB0[0x0c] = bios_EnableEvent; - biosB0[0x0d] = bios_DisableEvent; - biosB0[0x0e] = bios_OpenTh; - biosB0[0x0f] = bios_CloseTh; - biosB0[0x10] = bios_ChangeTh; - //biosB0[0x11] = bios_bios_b0_11; - biosB0[0x12] = bios_InitPAD; - biosB0[0x13] = bios_StartPAD; - biosB0[0x14] = bios_StopPAD; - biosB0[0x15] = bios_PAD_init; - biosB0[0x16] = bios_PAD_dr; - biosB0[0x17] = bios_ReturnFromException; - biosB0[0x18] = bios_ResetEntryInt; - biosB0[0x19] = bios_HookEntryInt; - //biosB0[0x1a] = bios_sys_b0_1a; - //biosB0[0x1b] = bios_sys_b0_1b; - //biosB0[0x1c] = bios_sys_b0_1c; - //biosB0[0x1d] = bios_sys_b0_1d; - //biosB0[0x1e] = bios_sys_b0_1e; - //biosB0[0x1f] = bios_sys_b0_1f; - biosB0[0x20] = bios_UnDeliverEvent; - //biosB0[0x21] = bios_sys_b0_21; - //biosB0[0x22] = bios_sys_b0_22; - //biosB0[0x23] = bios_sys_b0_23; - //biosB0[0x24] = bios_sys_b0_24; - //biosB0[0x25] = bios_sys_b0_25; - //biosB0[0x26] = bios_sys_b0_26; - //biosB0[0x27] = bios_sys_b0_27; - //biosB0[0x28] = bios_sys_b0_28; - //biosB0[0x29] = bios_sys_b0_29; - //biosB0[0x2a] = bios_sys_b0_2a; - //biosB0[0x2b] = bios_sys_b0_2b; - //biosB0[0x2c] = bios_sys_b0_2c; - //biosB0[0x2d] = bios_sys_b0_2d; - //biosB0[0x2e] = bios_sys_b0_2e; - //biosB0[0x2f] = bios_sys_b0_2f; - //biosB0[0x30] = bios_sys_b0_30; - //biosB0[0x31] = bios_sys_b0_31; - biosB0[0x32] = bios_open; - biosB0[0x33] = bios_lseek; - biosB0[0x34] = bios_read; - biosB0[0x35] = bios_write; - biosB0[0x36] = bios_close; - //biosB0[0x37] = bios_ioctl; - //biosB0[0x38] = bios_exit; - //biosB0[0x39] = bios_sys_b0_39; - //biosB0[0x3a] = bios_getc; - //biosB0[0x3b] = bios_putc; - biosB0[0x3c] = bios_getchar; - //biosB0[0x3e] = bios_gets; - //biosB0[0x40] = bios_cd; - //biosB0[0x41] = bios_format; - biosB0[0x42] = bios_firstfile; - biosB0[0x43] = bios_nextfile; - //biosB0[0x44] = bios_rename; - biosB0[0x45] = bios_delete; - //biosB0[0x46] = bios_undelete; - //biosB0[0x47] = bios_AddDevice; - //biosB0[0x48] = bios_RemoteDevice; - //biosB0[0x49] = bios_PrintInstalledDevices; - biosB0[0x4a] = bios_InitCARD; - biosB0[0x4b] = bios_StartCARD; - biosB0[0x4c] = bios_StopCARD; - //biosB0[0x4d] = bios_sys_b0_4d; - biosB0[0x4e] = bios__card_write; - biosB0[0x4f] = bios__card_read; - biosB0[0x50] = bios__new_card; - //biosB0[0x51] = bios_Krom2RawAdd; - //biosB0[0x52] = bios_sys_b0_52; - //biosB0[0x53] = bios_sys_b0_53; - //biosB0[0x54] = bios__get_errno; - //biosB0[0x55] = bios__get_error; - biosB0[0x56] = bios_GetC0Table; - biosB0[0x57] = bios_GetB0Table; - //biosB0[0x58] = bios__card_chan; - //biosB0[0x59] = bios_sys_b0_59; - //biosB0[0x5a] = bios_sys_b0_5a; - biosB0[0x5b] = bios_ChangeClearPad; - //biosB0[0x5c] = bios__card_status; - //biosB0[0x5d] = bios__card_wait; -//*******************C0 CALLS**************************** - //biosC0[0x00] = bios_InitRCnt; - //biosC0[0x01] = bios_InitException; - biosC0[0x02] = bios_SysEnqIntRP; - biosC0[0x03] = bios_SysDeqIntRP; - //biosC0[0x04] = bios_get_free_EvCB_slot; - //biosC0[0x05] = bios_get_free_TCB_slot; - //biosC0[0x06] = bios_ExceptionHandler; - //biosC0[0x07] = bios_InstallExeptionHandler; - //biosC0[0x08] = bios_SysInitMemory; - //biosC0[0x09] = bios_SysInitKMem; - biosC0[0x0a] = bios_ChangeClearRCnt; - //biosC0[0x0b] = bios_SystemError; - //biosC0[0x0c] = bios_InitDefInt; - //biosC0[0x0d] = bios_sys_c0_0d; - //biosC0[0x0e] = bios_sys_c0_0e; - //biosC0[0x0f] = bios_sys_c0_0f; - //biosC0[0x10] = bios_sys_c0_10; - //biosC0[0x11] = bios_sys_c0_11; - //biosC0[0x12] = bios_InstallDevices; - //biosC0[0x13] = bios_FlushStfInOutPut; - //biosC0[0x14] = bios_sys_c0_14; - //biosC0[0x15] = bios__cdevinput; - //biosC0[0x16] = bios__cdevscan; - //biosC0[0x17] = bios__circgetc; - //biosC0[0x18] = bios__circputc; - //biosC0[0x19] = bios_ioabort; - //biosC0[0x1a] = bios_sys_c0_1a - //biosC0[0x1b] = bios_KernelRedirect; - //biosC0[0x1c] = bios_PatchAOTable; -//************** THE END *************************************** - - base = 0x1000; - size = sizeof(EvCB) * 32; - Event = (void *)&psxR[base]; base+= size*6; - memset(Event, 0, size * 6); - HwEV = Event; - EvEV = Event + 32; - RcEV = Event + 32*2; - UeEV = Event + 32*3; - SwEV = Event + 32*4; - ThEV = Event + 32*5; - - ptr = (u32*)&psxM[0x0874]; // b0 table - ptr[0] = 0x4c54 - 0x884; - - ptr = (u32*)&psxM[0x0674]; // c0 table - ptr[6] = 0xc80; - - memset(SysIntRP, 0, sizeof(SysIntRP)); - memset(Thread, 0, sizeof(Thread)); - Thread[0].status = 2; // main thread - - psxMu32(0x0150) = 0x160; - psxMu32(0x0154) = 0x320; - psxMu32(0x0160) = 0x248; - strcpy(&psxM[0x248], "bu"); - - // opcode HLE - psxRu32(0x0000) = (0x3b << 26) | 4; - psxMu32(0x0000) = (0x3b << 26) | 0; - psxMu32(0x00a0) = (0x3b << 26) | 1; - psxMu32(0x00b0) = (0x3b << 26) | 2; - psxMu32(0x00c0) = (0x3b << 26) | 3; - psxMu32(0x4c54) = (0x3b << 26) | 0; - psxMu32(0x8000) = (0x3b << 26) | 5; - psxMu32(0x07a0) = (0x3b << 26) | 0; - psxMu32(0x0884) = (0x3b << 26) | 0; - psxMu32(0x0894) = (0x3b << 26) | 0; -} - -void psxBiosShutdown() { -} - -__inline void SaveRegs() { - memcpy(regs, psxRegs.GPR.r, 32*4); - regs[32] = psxRegs.GPR.n.lo; - regs[33] = psxRegs.GPR.n.hi; - regs[34] = psxRegs.pc; -} - -__inline void LoadRegs() { - memcpy(psxRegs.GPR.r, regs, 32*4); - psxRegs.GPR.n.lo = regs[32]; - psxRegs.GPR.n.hi = regs[33]; -} - -#define bios_PADpoll(pad) { \ - PAD##pad##_startPoll(pad); \ - pad_buf##pad[0] = 0; \ - pad_buf##pad[1] = PAD##pad##_poll(0x42); \ - if (!(pad_buf##pad[1] & 0x0f)) { \ - bufcount = 32; \ - } else { \ - bufcount = (pad_buf##pad[1] & 0x0f) * 2; \ - } \ - PAD##pad##_poll(0); \ - i = 2; \ - while (bufcount--) { \ - pad_buf##pad[i++] = PAD##pad##_poll(0); \ - } \ -} - -void biosInterrupt() { - int i, bufcount; - - if ((psxRegs.CP0.n.Status & 0x404) != 0x404) return; - -// if (psxHu32(0x1070) & 0x1) { // Vsync - if (pad_buf) { - PAD1_startPoll(1); - PAD1_poll(0x42); - PAD1_poll(0); - *pad_buf = PAD1_poll(0) << 8; - *pad_buf|= PAD1_poll(0); - PAD2_startPoll(2); - PAD2_poll(0x42); - PAD2_poll(0); - *pad_buf|= PAD2_poll(0) << 24; - *pad_buf|= PAD2_poll(0) << 16; - } - if (pad_buf1) { - bios_PADpoll(1); - } - - if (pad_buf2) { - bios_PADpoll(2); - } - - if (psxHu32(0x1070) & 0x1) { // Vsync - if (RcEV[3][1].status == EvStACTIVE) { - softCall(RcEV[3][1].fhandler); -// hwWrite32(0x1f801070, ~(1)); - } - } - - if (psxHu32(0x1070) & 0x70) { // Rcnt 0,1,2 - int i; - - for (i=0; i<3; i++) { - if (psxHu32(0x1070) & (1 << (i+4)) && psxCounters[i].mode & 0x50) { - if (RcEV[i][1].status == EvStACTIVE) { - softCall(RcEV[i][1].fhandler); - } - psxHwWrite32(0x1f801070, ~(1 << (i+4))); - } - } - } -} - -void psxBiosException() { - int i; - - switch ((psxRegs.CP0.n.Cause & 0x3c) >> 2) { - case 0: // Interrupt -#ifdef PSXCPU_LOG -// PSXCPU_LOG("interrupt\n"); -#endif - SaveRegs(); - - biosInterrupt(); - - for (i=0; i<8; i++) { - if (SysIntRP[i]) { - u32 *queue = (u32*)PSXM(SysIntRP[i]); - - s0 = queue[2]; - softCall(queue[1]); - } - } - - if (jmp_int != NULL) { - int i; - - psxHwWrite32(0x1f801070, 0xffffffff); - - ra = jmp_int[0]; - sp = jmp_int[1]; - fp = jmp_int[2]; - for (i=0; i<8; i++) // s0-s7 - psxRegs.GPR.r[16+i] = jmp_int[3+i]; - gp = jmp_int[11]; - - v0 = 1; - pc0 = ra; - return; - } - psxHwWrite16(0x1f801070, 0); - break; - case 8: // Syscall -#ifdef PSXCPU_LOG -// PSXCPU_LOG("syscall exp %x\n", a0); -#endif - switch (a0) { - case 1: // EnterCritical - disable irq's - psxRegs.CP0.n.Status&=~0x404; break; - case 2: // ExitCritical - enable irq's - psxRegs.CP0.n.Status|= 0x404; break; - } - pc0 = psxRegs.CP0.n.EPC + 4; - - psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status & 0xfffffff0) | - ((psxRegs.CP0.n.Status & 0x3c) >> 2); - return; - default: -#ifdef PSXCPU_LOG - PSXCPU_LOG("unk exp\n"); -#endif - break; - } - - pc0 = psxRegs.CP0.n.EPC; - if (psxRegs.CP0.n.Cause & 0x80000000) pc0+=4; - - psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status & 0xfffffff0) | - ((psxRegs.CP0.n.Status & 0x3c) >> 2); -} - -#define bfreeze(ptr, size) \ - if (Mode == 1) memcpy(&psxR[base], ptr, size); \ - if (Mode == 0) memcpy(ptr, &psxR[base], size); \ - base+=size; - -#define bfreezes(ptr) bfreeze(ptr, sizeof(ptr)) -#define bfreezel(ptr) bfreeze(ptr, 4) - -#define bfreezepsxMptr(ptr) \ - if (Mode == 1) { \ - if (ptr) psxRu32(base) = (u32)ptr - (u32)psxM; \ - else psxRu32(base) = 0; \ - } else { \ - if (psxRu32(base)) (u8*)ptr = (u8*)(psxM + psxRu32(base)); \ - else ptr = NULL; \ - } \ - base+=4; - -void psxBiosFreeze(int Mode) { - u32 base = 0x40000; - - bfreezepsxMptr(jmp_int); - bfreezepsxMptr(pad_buf); - bfreezepsxMptr(pad_buf1); - bfreezepsxMptr(pad_buf2); - bfreezepsxMptr(heap_addr); - bfreezel(&pad_buf1len); - bfreezel(&pad_buf2len); - bfreezes(regs); - bfreezes(SysIntRP); - bfreezel(&CardState); - bfreezes(Thread); - bfreezel(&CurThread); - bfreezes(FDesc); +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include +#include +#include + +#include "PsxCommon.h" +//We try to emulate bios :) HELP US :P + +char *biosA0n[256] = { +// 0x00 + "open", "lseek", "read", "write", + "close", "ioctl", "exit", "sys_a0_07", + "getc", "putc", "todigit", "atof", + "strtoul", "strtol", "abs", "labs", +// 0x10 + "atoi", "atol", "atob", "setjmp", + "longjmp", "strcat", "strncat", "strcmp", + "strncmp", "strcpy", "strncpy", "strlen", + "index", "rindex", "strchr", "strrchr", +// 0x20 + "strpbrk", "strspn", "strcspn", "strtok", + "strstr", "toupper", "tolower", "bcopy", + "bzero", "bcmp", "memcpy", "memset", + "memmove", "memcmp", "memchr", "rand", +// 0x30 + "srand", "qsort", "strtod", "malloc", + "free", "lsearch", "bsearch", "calloc", + "realloc", "InitHeap", "_exit", "getchar", + "putchar", "gets", "puts", "printf", +// 0x40 + "sys_a0_40", "LoadTest", "Load", "Exec", + "FlushCache", "InstallInterruptHandler", "GPU_dw", "mem2vram", + "SendGPUStatus", "GPU_cw", "GPU_cwb", "SendPackets", + "sys_a0_4c", "GetGPUStatus", "GPU_sync", "sys_a0_4f", +// 0x50 + "sys_a0_50", "LoadExec", "GetSysSp", "sys_a0_53", + "_96_init()", "_bu_init()", "_96_remove()", "sys_a0_57", + "sys_a0_58", "sys_a0_59", "sys_a0_5a", "dev_tty_init", + "dev_tty_open", "sys_a0_5d", "dev_tty_ioctl","dev_cd_open", +// 0x60 + "dev_cd_read", "dev_cd_close", "dev_cd_firstfile", "dev_cd_nextfile", + "dev_cd_chdir", "dev_card_open", "dev_card_read", "dev_card_write", + "dev_card_close", "dev_card_firstfile", "dev_card_nextfile","dev_card_erase", + "dev_card_undelete","dev_card_format", "dev_card_rename", "dev_card_6f", +// 0x70 + "_bu_init", "_96_init", "_96_remove", "sys_a0_73", + "sys_a0_74", "sys_a0_75", "sys_a0_76", "sys_a0_77", + "_96_CdSeekL", "sys_a0_79", "sys_a0_7a", "sys_a0_7b", + "_96_CdGetStatus", "sys_a0_7d", "_96_CdRead", "sys_a0_7f", +// 0x80 + "sys_a0_80", "sys_a0_81", "sys_a0_82", "sys_a0_83", + "sys_a0_84", "_96_CdStop", "sys_a0_86", "sys_a0_87", + "sys_a0_88", "sys_a0_89", "sys_a0_8a", "sys_a0_8b", + "sys_a0_8c", "sys_a0_8d", "sys_a0_8e", "sys_a0_8f", +// 0x90 + "sys_a0_90", "sys_a0_91", "sys_a0_92", "sys_a0_93", + "sys_a0_94", "sys_a0_95", "AddCDROMDevice", "AddMemCardDevide", + "DisableKernelIORedirection", "EnableKernelIORedirection", "sys_a0_9a", "sys_a0_9b", + "SetConf", "GetConf", "sys_a0_9e", "SetMem", +// 0xa0 + "_boot", "SystemError", "EnqueueCdIntr", "DequeueCdIntr", + "sys_a0_a4", "ReadSector", "get_cd_status", "bufs_cb_0", + "bufs_cb_1", "bufs_cb_2", "bufs_cb_3", "_card_info", + "_card_load", "_card_auto", "bufs_cd_4", "sys_a0_af", +// 0xb0 + "sys_a0_b0", "sys_a0_b1", "do_a_long_jmp", "sys_a0_b3", + "?? sub_function", +}; + +char *biosB0n[256] = { +// 0x00 + "SysMalloc", "sys_b0_01", "sys_b0_02", "sys_b0_03", + "sys_b0_04", "sys_b0_05", "sys_b0_06", "DeliverEvent", + "OpenEvent", "CloseEvent", "WaitEvent", "TestEvent", + "EnableEvent", "DisableEvent", "OpenTh", "CloseTh", +// 0x10 + "ChangeTh", "sys_b0_11", "InitPAD", "StartPAD", + "StopPAD", "PAD_init", "PAD_dr", "ReturnFromExecption", + "ResetEntryInt", "HookEntryInt", "sys_b0_1a", "sys_b0_1b", + "sys_b0_1c", "sys_b0_1d", "sys_b0_1e", "sys_b0_1f", +// 0x20 + "UnDeliverEvent", "sys_b0_21", "sys_b0_22", "sys_b0_23", + "sys_b0_24", "sys_b0_25", "sys_b0_26", "sys_b0_27", + "sys_b0_28", "sys_b0_29", "sys_b0_2a", "sys_b0_2b", + "sys_b0_2c", "sys_b0_2d", "sys_b0_2e", "sys_b0_2f", +// 0x30 + "sys_b0_30", "sys_b0_31", "open", "lseek", + "read", "write", "close", "ioctl", + "exit", "sys_b0_39", "getc", "putc", + "getchar", "putchar", "gets", "puts", +// 0x40 + "cd", "format", "firstfile", "nextfile", + "rename", "delete", "undelete", "AddDevice", + "RemoteDevice", "PrintInstalledDevices", "InitCARD", "StartCARD", + "StopCARD", "sys_b0_4d", "_card_write", "_card_read", +// 0x50 + "_new_card", "Krom2RawAdd", "sys_b0_52", "sys_b0_53", + "_get_errno", "_get_error", "GetC0Table", "GetB0Table", + "_card_chan", "sys_b0_59", "sys_b0_5a", "ChangeClearPAD", + "_card_status", "_card_wait", +}; + +char *biosC0n[256] = { +// 0x00 + "InitRCnt", "InitException", "SysEnqIntRP", "SysDeqIntRP", + "get_free_EvCB_slot", "get_free_TCB_slot", "ExceptionHandler", "InstallExeptionHandler", + "SysInitMemory", "SysInitKMem", "ChangeClearRCnt", "SystemError", + "InitDefInt", "sys_c0_0d", "sys_c0_0e", "sys_c0_0f", +// 0x10 + "sys_c0_10", "sys_c0_11", "InstallDevices", "FlushStfInOutPut", + "sys_c0_14", "_cdevinput", "_cdevscan", "_circgetc", + "_circputc", "ioabort", "sys_c0_1a", "KernelRedirect", + "PatchAOTable", +}; + +//#define r0 (psxRegs.GPR.n.r0) +#define at (psxRegs.GPR.n.at) +#define v0 (psxRegs.GPR.n.v0) +#define v1 (psxRegs.GPR.n.v1) +#define a0 (psxRegs.GPR.n.a0) +#define a1 (psxRegs.GPR.n.a1) +#define a2 (psxRegs.GPR.n.a2) +#define a3 (psxRegs.GPR.n.a3) +#define t0 (psxRegs.GPR.n.t0) +#define t1 (psxRegs.GPR.n.t1) +#define t2 (psxRegs.GPR.n.t2) +#define t3 (psxRegs.GPR.n.t3) +#define t4 (psxRegs.GPR.n.t4) +#define t5 (psxRegs.GPR.n.t5) +#define t6 (psxRegs.GPR.n.t6) +#define t7 (psxRegs.GPR.n.t7) +#define s0 (psxRegs.GPR.n.s0) +#define s1 (psxRegs.GPR.n.s1) +#define s2 (psxRegs.GPR.n.s2) +#define s3 (psxRegs.GPR.n.s3) +#define s4 (psxRegs.GPR.n.s4) +#define s5 (psxRegs.GPR.n.s5) +#define s6 (psxRegs.GPR.n.s6) +#define s7 (psxRegs.GPR.n.s7) +#define t8 (psxRegs.GPR.n.t6) +#define t9 (psxRegs.GPR.n.t7) +#define k0 (psxRegs.GPR.n.k0) +#define k1 (psxRegs.GPR.n.k1) +#define gp (psxRegs.GPR.n.gp) +#define sp (psxRegs.GPR.n.sp) +#define fp (psxRegs.GPR.n.s8) +#define ra (psxRegs.GPR.n.ra) +#define pc0 (psxRegs.pc) + +#define Ra0 ((char*)PSXM(a0)) +#define Ra1 ((char*)PSXM(a1)) +#define Ra2 ((char*)PSXM(a2)) +#define Ra3 ((char*)PSXM(a3)) +#define Rv0 ((char*)PSXM(v0)) +#define Rsp ((char*)PSXM(sp)) + + + +typedef struct _malloc_chunk { + unsigned long stat; + unsigned long size; + struct _malloc_chunk *fd; + struct _malloc_chunk *bk; +} malloc_chunk; + +#define INUSE 0x1 + +typedef struct { + u32 desc; + s32 status; + s32 mode; + u32 fhandler; +} EvCB[32]; + +#define EvStUNUSED 0x0000 +#define EvStWAIT 0x1000 +#define EvStACTIVE 0x2000 +#define EvStALREADY 0x4000 + +#define EvMdINTR 0x1000 +#define EvMdNOINTR 0x2000 + +typedef struct { + long next; + long func1; + long func2; + long pad; +} SysRPst; + +typedef struct { + s32 status; + s32 mode; + u32 reg[32]; + u32 func; +} TCB; + +typedef struct { + unsigned long _pc0; + unsigned long gp0; + unsigned long t_addr; + unsigned long t_size; + unsigned long d_addr; + unsigned long d_size; + unsigned long b_addr; + unsigned long b_size; + unsigned long S_addr; + unsigned long s_size; + unsigned long _sp,_fp,_gp,ret,base; +} EXEC; + +struct DIRENTRY { + char name[20]; + long attr; + long size; + struct DIRENTRY *next; + long head; + char system[4]; +}; + +typedef struct { + char name[32]; + u32 mode; + u32 offset; + u32 size; + u32 mcfile; +} FileDesc; + +static unsigned long *jmp_int = NULL; +static int *pad_buf = NULL; +static char *pad_buf1,*pad_buf2;//shadow add +static int pad_buf1len,pad_buf2len;//shadow add + + +static u32 regs[35]; +static EvCB *Event; +static EvCB *HwEV; // 0xf0 +static EvCB *EvEV; // 0xf1 +static EvCB *RcEV; // 0xf2 +static EvCB *UeEV; // 0xf3 +static EvCB *SwEV; // 0xf4 +static EvCB *ThEV; // 0xff +static u32 *heap_addr = NULL; +static u32 SysIntRP[8]; +static int CardState = -1; +static TCB Thread[8]; +static int CurThread = 0; +static FileDesc FDesc[32]; + +static __inline void softCall(u32 pc) { + pc0 = pc; + ra = 0x80001000; + while (pc0 != 0x80001000) psxCpu->ExecuteBlock(); +} + +static __inline void softCall2(u32 pc) { + u32 sra = ra; + pc0 = pc; + ra = 0x80001000; + while (pc0 != 0x80001000) psxCpu->ExecuteBlock(); + ra = sra; +} + +static __inline void DeliverEvent(u32 ev, u32 spec) { + if (Event[ev][spec].status != EvStACTIVE) return; + +// Event[ev][spec].status = EvStALREADY; + if (Event[ev][spec].mode == EvMdINTR) { + softCall2(Event[ev][spec].fhandler); + } else Event[ev][spec].status = EvStALREADY; +} + +/* * +// * +// * +// System calls A0 */ + + +void bios_abs() { // 0x0e + v0 = abs(a0); + pc0 = ra; +} + +void bios_labs() { // 0x0f + v0 = labs(a0); + pc0 = ra; +} + +void bios_atoi() { // 0x10 + v0 = atoi((char *)Ra0); + pc0 = ra; +} + +void bios_atol() { // 0x11 + v0 = atoi((char *)Ra0); + pc0 = ra; +} + +void bios_setjmp() { // 13 + u32 *jmp_buf= (u32*)Ra0; + int i; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosA0n[0x13]); +#endif + + jmp_buf[0] = ra; + jmp_buf[1] = sp; + jmp_buf[2] = fp; + for (i=0; i<8; i++) // s0-s7 + jmp_buf[3+i] = psxRegs.GPR.r[16+i]; + jmp_buf[11] = gp; + + v0 = 0; pc0 = ra; +} + +void bios_longjmp() { //14 + u32 *jmp_buf= (u32*)Ra0; + int i; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosA0n[0x14]); +#endif + + ra = jmp_buf[0]; /* ra */ + sp = jmp_buf[1]; /* sp */ + fp = jmp_buf[2]; /* fp */ + for (i=0; i<8; i++) // s0-s7 + psxRegs.GPR.r[16+i] = jmp_buf[3+i]; + gp = jmp_buf[11]; /* gp */ + + v0 = a1; pc0 = ra; +} + +void bios_strcat() { // 0x15 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %s, %s\n", biosA0n[0x15], Ra0, Ra1); +#endif + + strcat(Ra0, Ra1); + v0 = a0; pc0 = ra; +} + +/*0x16*/void bios_strncat() { strncat(Ra0, Ra1, a2); v0 = a0; pc0 = ra;} + +void bios_strcmp() { // 0x17 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %s (%lx), %s (%lx)\n", biosA0n[0x17], Ra0, a0, Ra1, a1); +#endif + + v0 = strcmp(Ra0, Ra1); + pc0 = ra; +} + +void bios_strncmp() { // 0x18 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %s (%lx), %s (%lx), %d\n", biosA0n[0x18], Ra0, a0, Ra1, a1, a2); +#endif + + v0 = strncmp(Ra0, Ra1, a2); + pc0 = ra; +} + +/*0x19*/void bios_strcpy() { strcpy(Ra0, Ra1); v0 = a0; pc0 = ra;} +/*0x1a*/void bios_strncpy() { strncpy(Ra0, Ra1, a2); v0 = a0; pc0 = ra;} +/*0x1b*/void bios_strlen() { v0 = strlen(Ra0); pc0 = ra;} + +void bios_index() { // 0x1c + char *pcA0 = (char *)Ra0; + char *pcRet = strchr(pcA0, a1); + if(pcRet) + v0 = a0 + pcRet - pcA0; + else + v0 = 0; + pc0 = ra; +} + +void bios_rindex() { // 0x1d + char *pcA0 = (char *)Ra0; + char *pcRet = strrchr(pcA0, a1); + if(pcRet) + v0 = a0 + pcRet - pcA0; + else + v0 = 0; + pc0 = ra; +} + +void bios_strchr() { // 0x1e + char *pcA0 = (char *)Ra0; + char *pcRet = strchr(pcA0, a1); + if(pcRet) + v0 = a0 + pcRet - pcA0; + else + v0 = 0; + pc0 = ra; +} + +void bios_strrchr() { // 0x1f + char *pcA0 = (char *)Ra0; + char *pcRet = strrchr(pcA0, a1); + if(pcRet) + v0 = a0 + pcRet - pcA0; + else + v0 = 0; + pc0 = ra; +} + +void bios_strpbrk() { // 0x20 + char *pcA0 = (char *)Ra0; + char *pcRet = strpbrk(pcA0, (char *)Ra1); + if(pcRet) + v0 = a0 + pcRet - pcA0; + else + v0 = 0; + pc0 = ra; +} + +void bios_strspn() { v0 = strspn ((char *)Ra0, (char *)Ra1); pc0 = ra;}/*21*/ +void bios_strcspn() { v0 = strcspn((char *)Ra0, (char *)Ra1); pc0 = ra;}/*22*/ + +void bios_strtok() { // 0x23 + char *pcA0 = (char *)Ra0; + char *pcRet = strtok(pcA0, (char *)Ra1); + if(pcRet) + v0 = a0 + pcRet - pcA0; + else + v0 = 0; + pc0 = ra; +} + +void bios_strstr() { // 0x24 + char *pcA0 = (char *)Ra0; + char *pcRet = strstr(pcA0, (char *)Ra1); + if(pcRet) + v0 = a0 + pcRet - pcA0; + else + v0 = 0; + pc0 = ra; +} + +/*0x25*/void bios_toupper() {v0 = toupper(a0); pc0 = ra;} +/*0x26*/void bios_tolower() {v0 = tolower(a0); pc0 = ra;} +/*0x27*/void bios_bcopy() {memcpy(Ra1,Ra0,a2); pc0=ra;} +/*0x28*/void bios_bzero() {memset(Ra0,0,a1); pc0=ra;} +/*0x29*/void bios_bcmp() {v0 = memcmp(Ra0,Ra1,a2); pc0=ra; } +/*0x2a*/void bios_memcpy() {memcpy(Ra0, Ra1, a2); v0 = a0; pc0 = ra;} +/*0x2b*/void bios_memset() {memset(Ra0, a1, a2); v0 = a0; pc0 = ra;} +/*0x2c*/void bios_memmove() {memmove(Ra0, Ra1, a2); v0 = a0; pc0 = ra;} +/*0x2d*/void bios_memcmp() {v0 = memcmp(Ra0, Ra1, a2); pc0 = ra;} + +void bios_memchr() { // 2e + void *ret = memchr(Ra0, a1, a2); + if (ret != NULL) v0 = (unsigned long)((char*)ret - Ra0) + a0; + else v0 = 0; + pc0 = ra; +} + +void bios_rand() { // 2f + v0 = 1+(int) (32767.0*rand()/(RAND_MAX+1.0)); + pc0 = ra; +} + +void bios_srand() { // 30 + srand(a0); pc0 = ra; +} + +void bios_malloc() { // 33 + malloc_chunk *chunk; + malloc_chunk *fd; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosA0n[0x33]); +#endif + + chunk = (malloc_chunk *)heap_addr; + if (chunk == NULL) { v0 = 0; return; } + + for (; ((a0 > chunk->size) || (chunk->stat == INUSE)) || (chunk->fd != NULL); chunk = chunk->fd); +//printf ("chunk %lx\n",chunk->size); + /* split free chunk */ + fd = chunk + sizeof(malloc_chunk) + a0; + fd->stat = chunk->stat; + fd->size = chunk->size - a0; + fd->fd = chunk->fd; + fd->bk = chunk; + + /* set new chunk */ + chunk->stat = INUSE; + chunk->size = a0; + chunk->fd = fd; + + v0 = ((unsigned long)chunk - (unsigned long)psxM) + sizeof(malloc_chunk); + v0|= 0x80000000; +// printf ("malloc %lx,%lx\n", v0, a0); + pc0 = ra; +} + +void bios_InitHeap() { // 39 + malloc_chunk *chunk; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosA0n[0x39]); +#endif + + heap_addr = (u32*)Ra0; + + chunk = (malloc_chunk *)heap_addr; + chunk->stat = 0; + if (((a0 & 0x1fffff) + a1)>= 0x200000) chunk->size = 0x1ffffc - (a0 & 0x1fffff); + else chunk->size = a1; + chunk->fd = NULL; + chunk->bk = NULL; + + SysPrintf("InitHeap %lx,%lx : %lx\n",a0,a1,chunk->size); + + pc0 = ra; +} + +void bios_getchar(){ v0 = getchar(); pc0=ra;} //0x3b + +void bios_printf() { // 3f + char tmp[1024]; + char tmp2[1024]; + unsigned long save[4]; + char *ptmp = tmp; + int n=1, i=0, j; + + memcpy(save, (char*)PSXM(sp), 4*4); + psxMu32(sp) = a0; + psxMu32(sp + 4) = a1; + psxMu32(sp + 8) = a2; + psxMu32(sp + 12) = a3; + + while (Ra0[i]) { + switch (Ra0[i]) { + case '%': + j = 0; + tmp2[j++] = '%'; +_start: + switch (Ra0[++i]) { + case '.': + case 'l': + tmp2[j++] = Ra0[i]; goto _start; + default: + if (Ra0[i] >= '0' && Ra0[i] <= '9') { + tmp2[j++] = Ra0[i]; + goto _start; + } + break; + } + tmp2[j++] = Ra0[i]; + tmp2[j] = 0; + + switch (Ra0[i]) { + case 'f': case 'F': + ptmp+= sprintf(ptmp, tmp2, (float)psxMu32(sp + n * 4)); n++; break; + case 'a': case 'A': + case 'e': case 'E': + case 'g': case 'G': + ptmp+= sprintf(ptmp, tmp2, (double)psxMu32(sp + n * 4)); n++; break; + case 'p': + case 'i': + case 'd': case 'D': + case 'o': case 'O': + case 'x': case 'X': + ptmp+= sprintf(ptmp, tmp2, (unsigned int)psxMu32(sp + n * 4)); n++; break; + case 'c': + ptmp+= sprintf(ptmp, tmp2, (unsigned char)psxMu32(sp + n * 4)); n++; break; + case 's': + ptmp+= sprintf(ptmp, tmp2, (char*)PSXM(psxMu32(sp + n * 4))); n++; break; + case '%': + *ptmp++ = Ra0[i]; break; + } + i++; + break; + default: + *ptmp++ = Ra0[i++]; + } + } + *ptmp = 0; + + memcpy((char*)PSXM(sp), save, 4*4); + + SysPrintf(tmp); + + pc0 = ra; +} + +/* + * int Exec(struct EXEC *header , int argc , char **argv); + */ + +void bios_Exec() { // 43 + EXEC *header = (EXEC*)Ra0; + u32 tmp; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x, %x, %x\n", biosA0n[0x43], a0, a1, a2); +#endif + + header->_sp = sp; + header->_fp = fp; + header->_sp = sp; + header->_gp = gp; + header->ret = ra; + header->base = s0; + + if (header->S_addr != 0) { + tmp = header->S_addr + header->s_size; + sp = tmp; + fp = sp; + } + + gp = header->gp0; + + s0 = a0; + + a0 = a1; + a1 = a2; + + ra = 0x8000; + pc0 = header->_pc0; +} + +void bios_FlushCache() { // 44 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosA0n[0x44]); +#endif + + pc0 = ra; +} + +void bios_GPU_dw() { // 0x46 + int size; + long *ptr; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosA0n[0x46]); +#endif + + GPU_writeData(0xa0000000); + GPU_writeData((a1<<16)|(a0&0xffff)); + GPU_writeData((a3<<16)|(a2&0xffff)); + size = (a2*a3+1)/2; + ptr = (long*)PSXM(Rsp[4]); //that is correct? + do { + GPU_writeData(*ptr++); + } while(--size); + + pc0 = ra; +} + +void bios_mem2vram() { // 0x47 + int size; + + GPU_writeData(0xa0000000); + GPU_writeData((a1<<16)|(a0&0xffff)); + GPU_writeData((a3<<16)|(a2&0xffff)); + size = (a2*a3+1)/2; + GPU_writeStatus(0x04000002); + psxHwWrite32(0x1f8010f4,0); + psxHwWrite32(0x1f8010f0,psxHwRead32(0x1f8010f0)|0x800); + psxHwWrite32(0x1f8010a0,Rsp[4]);//might have a buggy... + psxHwWrite32(0x1f8010a4,((size/16)<<16)|16); + psxHwWrite32(0x1f8010a8,0x01000201); + + pc0 = ra; +} + +void bios_SendGPU() { // 0x48 + GPU_writeStatus(a0); + pc0 = ra; +} + +void bios_GPU_cw() { // 0x49 + GPU_writeData(a0); + pc0 = ra; +} + +void bios_GPU_cwb() { // 0x4a + long *ptr = (long*)Ra0; + int size = a1; + while(size--) { + GPU_writeData(*ptr++); + } + + pc0 = ra; +} + +void bios_GPU_SendPackets() { //4b: + GPU_writeStatus(0x04000002); + psxHwWrite32(0x1f8010f4,0); + psxHwWrite32(0x1f8010f0,psxHwRead32(0x1f8010f0)|0x800); + psxHwWrite32(0x1f8010a0,a0); + psxHwWrite32(0x1f8010a4,0); + psxHwWrite32(0x1f8010a8,0x010000401); + pc0 = ra; +} + +void bios_sys_a0_4c() { // 0x4c GPU relate + psxHwWrite32(0x1f8010a8,0x00000401); + GPU_writeData(0x0400000); + GPU_writeData(0x0200000); + GPU_writeData(0x0100000); + + pc0 = ra; +} + +void bios_GPU_GetGPUStatus() { // 0x4d + v0 = GPU_readStatus(); + pc0 = ra; +} + +void bios__bu_init() { // 70 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosA0n[0x70]); +#endif + + DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 + DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 + + pc0 = ra; +} + +void bios__96_remove() { // 72 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosA0n[0x72]); +#endif + + pc0 = ra; +} + +void bios__card_info() { // ab +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x\n", biosA0n[0xab], a0); +#endif + +// DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 + DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 + + v0 = 1; pc0 = ra; +} + +void bios__card_load() { // ac +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x\n", biosA0n[0xac], a0); +#endif + +// DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 + DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 + + v0 = 1; pc0 = ra; +} + +/* System calls B0 */ + +void bios_SetRCnt() { // 02 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x02]); +#endif + + a0&= 0x3; + if (a0 != 3) { + unsigned long mode=0; + + psxRcntWtarget(a0, a1); + if (a2&0x1000) mode|= 0x050; // Interrupt Mode + if (a2&0x0100) mode|= 0x008; // Count to 0xffff + if (a2&0x0010) mode|= 0x001; // Timer stop mode + if (a0 == 2) { if (a2&0x0001) mode|= 0x200; } // System Clock mode + else { if (a2&0x0001) mode|= 0x100; } // System Clock mode + + psxRcntWmode(a0, mode); + } + pc0 = ra; +} + +void bios_GetRCnt() { // 03 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x03]); +#endif + + a0&= 0x3; + if (a0 != 3) v0 = psxRcntRcount(a0); + else v0 = 0; + pc0 = ra; +} + +void bios_StartRCnt() { // 04 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x04]); +#endif + + a0&= 0x3; + if (a0 != 3) psxHu32(0x1074)|= (1<<(a0+4)); + else psxHu32(0x1074)|= 0x1; + v0 = 1; pc0 = ra; +} + +void bios_StopRCnt() { // 05 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x05]); +#endif + + a0&= 0x3; + if (a0 != 3) psxHu32(0x1074)&= ~(1<<(a0+4)); + else psxHu32(0x1074)&= ~0x1; + pc0 = ra; +} + +void bios_ResetRCnt() { // 06 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x06]); +#endif + + a0&= 0x3; + if (a0 != 3) { + psxRcntWmode(a0, 0); + psxRcntWtarget(a0, 0); + psxRcntWcount(a0, 0); + } + pc0 = ra; +} + + +/* gets ev for use with Event */ +#define GetEv() \ + ev = (a0 >> 24) & 0xf; \ + if (ev == 0xf) ev = 0x5; \ + ev*= 32; \ + ev+= a0&0x1f; + +/* gets spec for use with Event */ +#define GetSpec() \ + spec = 0; \ + switch (a1) { \ + case 0x0301: spec = 16; break; \ + case 0x0302: spec = 17; break; \ + default: \ + for (i=0; i<16; i++) if (a1 & (1 << i)) { spec = i; break; } \ + break; \ + } + +void bios_DeliverEvent() { // 07 + int ev, spec; + int i; + + GetEv(); + GetSpec(); + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s %x,%x\n", biosB0n[0x07], ev, spec); +#endif + + DeliverEvent(ev, spec); + + pc0 = ra; +} + +void bios_OpenEvent() { // 08 + int ev, spec; + int i; + + GetEv(); + GetSpec(); + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s %x,%x (class:%lx, spec:%lx, mode:%lx, func:%lx)\n", biosB0n[0x08], ev, spec, a0, a1, a2, a3); +#endif + + Event[ev][spec].status = EvStWAIT; + Event[ev][spec].mode = a2; + Event[ev][spec].fhandler = a3; + + v0 = ev | (spec << 8); + pc0 = ra; +} + +void bios_CloseEvent() { // 09 + int ev, spec; + + ev = a0 & 0xff; + spec = (a0 >> 8) & 0xff; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s %x,%x\n", biosB0n[0x09], ev, spec); +#endif + + Event[ev][spec].status = EvStUNUSED; + + v0 = 1; pc0 = ra; +} + +void bios_WaitEvent() { // 0a + int ev, spec; + + ev = a0 & 0xff; + spec = (a0 >> 8) & 0xff; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s %x,%x\n", biosB0n[0x0a], ev, spec); +#endif + + Event[ev][spec].status = EvStACTIVE; + + v0 = 1; pc0 = ra; +} + +void bios_TestEvent() { // 0b + int ev, spec; + + ev = a0 & 0xff; + spec = (a0 >> 8) & 0xff; + + if (Event[ev][spec].status == EvStALREADY) { + Event[ev][spec].status = EvStACTIVE; v0 = 1; + } else v0 = 0; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s %x,%x: %x\n", biosB0n[0x0b], ev, spec, v0); +#endif + + pc0 = ra; +} + +void bios_EnableEvent() { // 0c + int ev, spec; + + ev = a0 & 0xff; + spec = (a0 >> 8) & 0xff; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s %x,%x\n", biosB0n[0x0c], ev, spec); +#endif + + Event[ev][spec].status = EvStACTIVE; + + v0 = 1; pc0 = ra; +} + +void bios_DisableEvent() { // 0d + int ev, spec; + + ev = a0 & 0xff; + spec = (a0 >> 8) & 0xff; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s %x,%x\n", biosB0n[0x0d], ev, spec); +#endif + + Event[ev][spec].status = EvStWAIT; + + v0 = 1; pc0 = ra; +} + +/* + * long OpenTh(long (*func)(), unsigned long sp, unsigned long gp); + */ + +void bios_OpenTh() { // 0e + int th; + + for (th=1; th<8; th++) + if (Thread[th].status == 0) break; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x\n", biosB0n[0x0e], th); +#endif + + Thread[th].status = 1; + Thread[th].func = a0; + Thread[th].reg[29] = a1; + Thread[th].reg[28] = a2; + + v0 = th; pc0 = ra; +} + +/* + * int CloseTh(long thread); + */ + +void bios_CloseTh() { // 0f + int th = a0 & 0xff; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x\n", biosB0n[0x0f], th); +#endif + + if (Thread[th].status == 0) { + v0 = 0; + } else { + Thread[th].status = 0; + v0 = 1; + } + + pc0 = ra; +} + +/* + * int ChangeTh(long thread); + */ + +void bios_ChangeTh() { // 10 + int th = a0 & 0xff; + +#ifdef PSXBIOS_LOG +// PSXBIOS_LOG("bios_%s: %x\n", biosB0n[0x10], th); +#endif + + if (Thread[th].status == 0 || CurThread == th) { + v0 = 0; + + pc0 = ra; + } else { + v0 = 1; + + if (Thread[CurThread].status == 2) { + Thread[CurThread].status = 1; + Thread[CurThread].func = ra; + memcpy(Thread[CurThread].reg, psxRegs.GPR.r, 32*4); + } + + memcpy(psxRegs.GPR.r, Thread[th].reg, 32*4); + pc0 = Thread[th].func; + Thread[th].status = 2; + CurThread = th; + } +} + +void bios_InitPAD() { // 0x12 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x12]); +#endif + + pad_buf1 = (char*)Ra0; + pad_buf1len = a1; + pad_buf2 = (char*)Ra2; + pad_buf2len = a3; + + v0 = 1; pc0 = ra; +} + +void bios_StartPAD() { // 13 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x13]); +#endif + + psxHwWrite16(0x1f801074, (unsigned short)(psxHwRead16(0x1f801074) | 0x1)); + psxRegs.CP0.n.Status |= 0x401; + pc0 = ra; +} + +void bios_StopPAD() { // 14 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x14]); +#endif + + pad_buf1 = NULL; + pad_buf2 = NULL; + pc0 = ra; +} + +void bios_PAD_init() { // 15 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x15]); +#endif + + psxHwWrite16(0x1f801074, (u16)(psxHwRead16(0x1f801074) | 0x1)); + pad_buf = (int*)Ra1; + *pad_buf = -1; + psxRegs.CP0.n.Status |= 0x401; + pc0 = ra; +} + +void bios_PAD_dr() { // 16 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x16]); +#endif + + v0 = -1; pc0 = ra; +} + +void bios_ReturnFromException() { // 17 + memcpy(psxRegs.GPR.r, regs, 32*4); + psxRegs.GPR.n.lo = regs[32]; + psxRegs.GPR.n.hi = regs[33]; + + pc0 = psxRegs.CP0.n.EPC; + if (psxRegs.CP0.n.Cause & 0x80000000) pc0+=4; + + psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status & 0xfffffff0) | + ((psxRegs.CP0.n.Status & 0x3c) >> 2); +} + +void bios_ResetEntryInt() { // 18 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x18]); +#endif + + jmp_int = NULL; + pc0 = ra; +} + +void bios_HookEntryInt() { // 19 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x19]); +#endif + + jmp_int = (u32*)Ra0; + pc0 = ra; +} + +void bios_UnDeliverEvent() { // 0x20 + int ev, spec; + int i; + + GetEv(); + GetSpec(); + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s %x,%x\n", biosB0n[0x07], ev, spec); +#endif + + if (Event[ev][spec].status == EvStALREADY && + Event[ev][spec].mode == EvMdNOINTR) + Event[ev][spec].status = EvStACTIVE; + + pc0 = ra; +} + +#define buopen(mcd) { \ + strcpy(FDesc[1 + mcd].name, Ra0+5); \ + FDesc[1 + mcd].offset = 0; \ + FDesc[1 + mcd].mode = a1; \ + \ + for (i=1; i<16; i++) { \ + ptr = Mcd##mcd##Data + 128 * i; \ + if ((*ptr & 0xF0) != 0x50) continue; \ + if (strcmp(FDesc[1 + mcd].name, ptr+0xa)) continue; \ + FDesc[1 + mcd].mcfile = i; \ + SysPrintf("open %s\n", ptr+0xa); \ + v0 = 1 + mcd; \ + break; \ + } \ + if (a1 & 0x200 && v0 == -1) { /* FCREAT */ \ + for (i=1; i<16; i++) { \ + int j, xor = 0; \ + \ + ptr = Mcd##mcd##Data + 128 * i; \ + if ((*ptr & 0xF0) == 0x50) continue; \ + ptr[0] = 0x50 | (u8)(a1 >> 16); \ + ptr[4] = 0x00; \ + ptr[5] = 0x20; \ + ptr[6] = 0x00; \ + ptr[7] = 0x00; \ + ptr[8] = 'B'; \ + ptr[9] = 'I'; \ + strcpy(ptr+0xa, FDesc[1 + mcd].name); \ + for (j=0; j<127; j++) xor^= ptr[j]; \ + ptr[127] = xor; \ + FDesc[1 + mcd].mcfile = i; \ + SysPrintf("openC %s\n", ptr); \ + v0 = 1 + mcd; \ + break; \ + } \ + } \ +} + +/* + * int open(char *name , int mode); + */ + +void bios_open() { // 0x32 + int i; + char *ptr; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %s,%x\n", biosB0n[0x32], Ra0, a1); +#endif + + v0 = -1; + + if (!strncmp(Ra0, "bu00", 4)) { + buopen(1); + } + + if (!strncmp(Ra0, "bu10", 4)) { + buopen(2); + } + + pc0 = ra; +} + +/* + * int lseek(int fd , int offset , int whence); + */ + +void bios_lseek() { // 0x33 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x, %x, %x\n", biosB0n[0x33], a0, a1, a2); +#endif + + switch (a2) { + case 0: // SEEK_SET + FDesc[a0].offset = a1; + v0 = a1; +// DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 +// DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 + break; + + case 1: // SEEK_CUR + FDesc[a0].offset+= a1; + v0 = FDesc[a0].offset; + break; + } + + pc0 = ra; +} + +#define buread(mcd) { \ + SysPrintf("read %d: %x,%x (%s)\n", FDesc[1 + mcd].mcfile, FDesc[1 + mcd].offset, a2, Mcd##mcd##Data + 128 * FDesc[1 + mcd].mcfile + 0xa); \ + ptr = Mcd##mcd##Data + 8192 * FDesc[1 + mcd].mcfile + FDesc[1 + mcd].offset; \ + memcpy(Ra1, ptr, a2); \ + if (FDesc[1 + mcd].mode & 0x8000) v0 = 0; \ + else v0 = a2; \ + DeliverEvent(0x11, 0x2); /* 0xf0000011, 0x0004 */ \ + DeliverEvent(0x81, 0x2); /* 0xf4000001, 0x0004 */ \ +} + +/* + * int read(int fd , void *buf , int nbytes); + */ + +void bios_read() { // 0x34 + char *ptr; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x, %x, %x\n", biosB0n[0x34], a0, a1, a2); +#endif + + v0 = -1; + + switch (a0) { + case 2: buread(1); break; + case 3: buread(2); break; + } + + pc0 = ra; +} + +#define buwrite(mcd) { \ + u32 offset = + 8192 * FDesc[1 + mcd].mcfile + FDesc[1 + mcd].offset; \ + SysPrintf("write %d: %x,%x\n", FDesc[1 + mcd].mcfile, FDesc[1 + mcd].offset, a2); \ + ptr = Mcd##mcd##Data + offset; \ + memcpy(ptr, Ra1, a2); \ + SaveMcd(Config.Mcd##mcd, Mcd##mcd##Data, offset, a2); \ + if (FDesc[1 + mcd].mode & 0x8000) v0 = 0; \ + else v0 = a2; \ + DeliverEvent(0x11, 0x2); /* 0xf0000011, 0x0004 */ \ + DeliverEvent(0x81, 0x2); /* 0xf4000001, 0x0004 */ \ +} + +/* + * int write(int fd , void *buf , int nbytes); + */ + +void bios_write() { // 0x35/0x03 + char *ptr; + + if (a0 == 1) { // stdout + char buf[1024]; + + memcpy(buf, Ra1, a2); + buf[a2] = 0; + SysPrintf(buf); + pc0 = ra; return; + } +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x,%x,%x\n", biosB0n[0x35], a0, a1, a2); +#endif + + v0 = -1; + + switch (a0) { + case 2: buwrite(1); break; + case 3: buwrite(2); break; + } + + pc0 = ra; +} + +/* + * int close(int fd); + */ + +void bios_close() { // 0x36 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x\n", biosB0n[0x36], a0); +#endif + + v0 = a0; pc0 = ra; +} + +void bios_putchar () { // 3d + char tmp[12]; + + sprintf (tmp,"%c",(char)a0); + SysPrintf(tmp); + + pc0 = ra; +} + +void bios_puts () { // 3e/3f + SysPrintf(Ra0); + + pc0 = ra; +} + +char ffile[64], *pfile; +int nfile; + +#define bufile(mcd) { \ + while (nfile < 16) { \ + int match=1; \ + \ + ptr = Mcd##mcd##Data + 128 * nfile; \ + nfile++; \ + if ((*ptr & 0xF0) != 0x50) continue; \ + ptr+= 0xa; \ + for (i=0; i<20; i++) { \ + if (pfile[i] == ptr[i]) { \ + dir->name[i] = ptr[i]; \ + if (ptr[i] == 0) break; else continue; } \ + if (pfile[i] == '?') { \ + dir->name[i] = ptr[i]; continue; } \ + if (pfile[i] == '*') { \ + strcpy(dir->name+i, ptr+i); break; } \ + match = 0; break; \ + } \ + SysPrintf("%d : %s = %s + %s (match=%d)\n", nfile, dir->name, pfile, ptr, match); \ + if (match == 0) continue; \ + dir->size = 8192; \ + v0 = _dir; \ + break; \ + } \ +} + +/* + * struct DIRENTRY* firstfile(char *name,struct DIRENTRY *dir); + */ + +void bios_firstfile() { // 42 + struct DIRENTRY *dir = (struct DIRENTRY *)Ra1; + u32 _dir = a1; + char *ptr; + int i; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %s\n", biosB0n[0x42], Ra0); +#endif + + v0 = 0; + + strcpy(ffile, Ra0); + pfile = ffile+5; + nfile = 1; + if (!strncmp(Ra0, "bu00", 4)) { + bufile(1); + } + + if (!strncmp(Ra0, "bu10", 4)) { + bufile(2); + } + + pc0 = ra; +} + +/* + * struct DIRENTRY* nextfile(struct DIRENTRY *dir); + */ + +void bios_nextfile() { // 43 + struct DIRENTRY *dir = (struct DIRENTRY *)Ra0; + u32 _dir = a0; + char *ptr; + int i; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %s\n", biosB0n[0x43], dir->name); +#endif + + v0 = 0; + + if (!strncmp(ffile, "bu00", 4)) { + bufile(1); + } + + if (!strncmp(ffile, "bu10", 4)) { + bufile(2); + } + + pc0 = ra; +} + +#define budelete(mcd) { \ + for (i=1; i<16; i++) { \ + ptr = Mcd##mcd##Data + 128 * i; \ + if ((*ptr & 0xF0) != 0x50) continue; \ + if (strcmp(Ra0+5, ptr+0xa)) continue; \ + *ptr = (*ptr & 0xf) | 0xA0; \ + SysPrintf("delete %s\n", ptr+0xa); \ + v0 = 1; \ + break; \ + } \ +} + +/* + * int delete(char *name); + */ + +void bios_delete() { // 45 + char *ptr; + int i; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %s\n", biosB0n[0x45], Ra0); +#endif + + v0 = 0; + + if (!strncmp(Ra0, "bu00", 4)) { + budelete(1); + } + + if (!strncmp(Ra0, "bu10", 4)) { + budelete(2); + } + + pc0 = ra; +} + +void bios_InitCARD() { // 4a +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x\n", biosB0n[0x4a], a0); +#endif + + CardState = 0; + + pc0 = ra; +} + +void bios_StartCARD() { // 4b +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x4b]); +#endif + + if (CardState == 0) CardState = 1; + + pc0 = ra; +} + +void bios_StopCARD() { // 4c +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x4c]); +#endif + + if (CardState == 1) CardState = 0; + + pc0 = ra; +} + +void bios__card_write() { // 0x4e + int port; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x,%x,%x\n", biosB0n[0x4e], a0, a1, a2); +#endif + + port = a0 >> 4; + + if (port == 0) { + memcpy(Mcd1Data + a1 * 128, Ra2, 128); + SaveMcd(Config.Mcd1, Mcd1Data, a1 * 128, 128); + } else { + memcpy(Mcd2Data + a1 * 128, Ra2, 128); + SaveMcd(Config.Mcd2, Mcd2Data, a1 * 128, 128); + } + + DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 +// DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 + + v0 = 1; pc0 = ra; +} + +void bios__card_read() { // 0x4f + int port; + +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x4f]); +#endif + + port = a0 >> 4; + + if (port == 0) { + memcpy(Ra2, Mcd1Data + a1 * 128, 128); + } else { + memcpy(Ra2, Mcd2Data + a1 * 128, 128); + } + + DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 +// DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 + + v0 = 1; pc0 = ra; +} + +void bios__new_card() { // 0x50 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x50]); +#endif + + pc0 = ra; +} + +void bios_GetC0Table() { // 56 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x56]); +#endif + + v0 = 0x674; pc0 = ra; +} + +void bios_GetB0Table() { // 57 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s\n", biosB0n[0x57]); +#endif + + v0 = 0x874; pc0 = ra; +} + +void bios_ChangeClearPad() { // 5b +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x\n", biosB0n[0x5b], a0); +#endif + + pc0 = ra; +} + +/* System calls C0 */ + +/* + * int SysEnqIntRP(int index , long *queue); + */ + +void bios_SysEnqIntRP() { // 02 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x\n", biosC0n[0x02] ,a0); +#endif + + SysIntRP[a0] = a1; + + v0 = 0; pc0 = ra; +} + +/* + * int SysDeqIntRP(int index , long *queue); + */ + +void bios_SysDeqIntRP() { // 03 +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x\n", biosC0n[0x03] ,a0); +#endif + + SysIntRP[a0] = 0; + + v0 = 0; pc0 = ra; +} + +void bios_ChangeClearRCnt() { // 0a +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("bios_%s: %x\n", biosC0n[0x0a] ,a0); +#endif + + psxRegs.CP0.n.Status|= 0x404; + pc0 = ra; +} + +void bios_dummy() { +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("unk %lx call: %lx\n", pc0 & 0x1fffff, t1); +#endif + pc0 = ra; +} + +void (*biosA0[256])(); +void (*biosB0[256])(); +void (*biosC0[256])(); + +void psxBiosInit() { + u32 base, size; + u32 *ptr; + int i; + + for(i = 0; i < 256; i++) { + biosA0[i] = NULL; + biosB0[i] = NULL; + biosC0[i] = NULL; + } + biosA0[0x3e] = bios_puts; + biosA0[0x3f] = bios_printf; + + biosB0[0x3d] = bios_putchar; + biosB0[0x3f] = bios_puts; + + if (!Config.HLE) return; + + for(i = 0; i < 256; i++) { + if (biosA0[i] == NULL) biosA0[i] = bios_dummy; + if (biosB0[i] == NULL) biosB0[i] = bios_dummy; + if (biosC0[i] == NULL) biosC0[i] = bios_dummy; + } + + biosA0[0x00] = bios_open; + biosA0[0x01] = bios_lseek; + biosA0[0x02] = bios_read; + biosA0[0x03] = bios_write; + biosA0[0x04] = bios_close; + //biosA0[0x05] = bios_ioctl; + //biosA0[0x06] = bios_exit; + //biosA0[0x07] = bios_sys_a0_07; + //biosA0[0x08] = bios_getc; + //biosA0[0x09] = bios_putc; + //biosA0[0x0a] = bios_todigit; + //biosA0[0x0b] = bios_atof; + //biosA0[0x0c] = bios_strtoul; + //biosA0[0x0d] = bios_strtol; + biosA0[0x0e] = bios_abs; + biosA0[0x0f] = bios_labs; + biosA0[0x10] = bios_atoi; + biosA0[0x11] = bios_atol; + //biosA0[0x12] = bios_atob; + biosA0[0x13] = bios_setjmp; + biosA0[0x14] = bios_longjmp; + biosA0[0x15] = bios_strcat; + biosA0[0x16] = bios_strncat; + biosA0[0x17] = bios_strcmp; + biosA0[0x18] = bios_strncmp; + biosA0[0x19] = bios_strcpy; + biosA0[0x1a] = bios_strncpy; + biosA0[0x1b] = bios_strlen; + biosA0[0x1c] = bios_index; + biosA0[0x1d] = bios_rindex; + biosA0[0x1e] = bios_strchr; + biosA0[0x1f] = bios_strrchr; + biosA0[0x20] = bios_strpbrk; + biosA0[0x21] = bios_strspn; + biosA0[0x22] = bios_strcspn; + biosA0[0x23] = bios_strtok; + biosA0[0x24] = bios_strstr; + biosA0[0x25] = bios_toupper; + biosA0[0x26] = bios_tolower; + biosA0[0x27] = bios_bcopy; + biosA0[0x28] = bios_bzero; + biosA0[0x29] = bios_bcmp; + biosA0[0x2a] = bios_memcpy; + biosA0[0x2b] = bios_memset; + biosA0[0x2c] = bios_memmove; + biosA0[0x2d] = bios_memcmp; + biosA0[0x2e] = bios_memchr; + biosA0[0x2f] = bios_rand; + biosA0[0x30] = bios_srand; + //biosA0[0x31] = bios_qsort; + //biosA0[0x32] = bios_strtod; + biosA0[0x33] = bios_malloc; + //biosA0[0x34] = bios_free; + //biosA0[0x35] = bios_lsearch; + //biosA0[0x36] = bios_bsearch; + //biosA0[0x37] = bios_calloc; + //biosA0[0x38] = bios_realloc; + biosA0[0x39] = bios_InitHeap; + //biosA0[0x3a] = bios__exit; + biosA0[0x3b] = bios_getchar; + biosA0[0x3c] = bios_putchar; + //biosA0[0x3d] = bios_gets; + //biosA0[0x40] = bios_sys_a0_40; + //biosA0[0x41] = bios_LoadTest; + //biosA0[0x42] = bios_Load; + biosA0[0x43] = bios_Exec; + biosA0[0x44] = bios_FlushCache; + //biosA0[0x45] = bios_InstallInterruptHandler; + biosA0[0x46] = bios_GPU_dw; + biosA0[0x47] = bios_mem2vram; + biosA0[0x48] = bios_SendGPU; + biosA0[0x49] = bios_GPU_cw; + biosA0[0x4a] = bios_GPU_cwb; + biosA0[0x4b] = bios_GPU_SendPackets; + biosA0[0x4c] = bios_sys_a0_4c; + biosA0[0x4d] = bios_GPU_GetGPUStatus; + //biosA0[0x4e] = bios_GPU_sync; + //biosA0[0x4f] = bios_sys_a0_4f; + //biosA0[0x50] = bios_sys_a0_50; + //biosA0[0x51] = bios_LoadExec; + //biosA0[0x52] = bios_GetSysSp; + //biosA0[0x53] = bios_sys_a0_53; + //biosA0[0x54] = bios__96_init_a54; + //biosA0[0x55] = bios__bu_init_a55; + //biosA0[0x56] = bios__96_remove_a56; + //biosA0[0x57] = bios_sys_a0_57; + //biosA0[0x58] = bios_sys_a0_58; + //biosA0[0x59] = bios_sys_a0_59; + //biosA0[0x5a] = bios_sys_a0_5a; + //biosA0[0x5b] = bios_dev_tty_init; + //biosA0[0x5c] = bios_dev_tty_open; + //biosA0[0x5d] = bios_sys_a0_5d; + //biosA0[0x5e] = bios_dev_tty_ioctl; + //biosA0[0x5f] = bios_dev_cd_open; + //biosA0[0x60] = bios_dev_cd_read; + //biosA0[0x61] = bios_dev_cd_close; + //biosA0[0x62] = bios_dev_cd_firstfile; + //biosA0[0x63] = bios_dev_cd_nextfile; + //biosA0[0x64] = bios_dev_cd_chdir; + //biosA0[0x65] = bios_dev_card_open; + //biosA0[0x66] = bios_dev_card_read; + //biosA0[0x67] = bios_dev_card_write; + //biosA0[0x68] = bios_dev_card_close; + //biosA0[0x69] = bios_dev_card_firstfile; + //biosA0[0x6a] = bios_dev_card_nextfile; + //biosA0[0x6b] = bios_dev_card_erase; + //biosA0[0x6c] = bios_dev_card_undelete; + //biosA0[0x6d] = bios_dev_card_format; + //biosA0[0x6e] = bios_dev_card_rename; + //biosA0[0x6f] = bios_dev_card_6f; + biosA0[0x70] = bios__bu_init; + //biosA0[0x71] = bios__96_init; + biosA0[0x72] = bios__96_remove; + //biosA0[0x73] = bios_sys_a0_73; + //biosA0[0x74] = bios_sys_a0_74; + //biosA0[0x75] = bios_sys_a0_75; + //biosA0[0x76] = bios_sys_a0_76; + //biosA0[0x77] = bios_sys_a0_77; + //biosA0[0x78] = bios__96_CdSeekL; + //biosA0[0x79] = bios_sys_a0_79; + //biosA0[0x7a] = bios_sys_a0_7a; + //biosA0[0x7b] = bios_sys_a0_7b; + //biosA0[0x7c] = bios__96_CdGetStatus; + //biosA0[0x7d] = bios_sys_a0_7d; + //biosA0[0x7e] = bios__96_CdRead; + //biosA0[0x7f] = bios_sys_a0_7f; + //biosA0[0x80] = bios_sys_a0_80; + //biosA0[0x81] = bios_sys_a0_81; + //biosA0[0x82] = bios_sys_a0_82; + //biosA0[0x83] = bios_sys_a0_83; + //biosA0[0x84] = bios_sys_a0_84; + //biosA0[0x85] = bios__96_CdStop; + //biosA0[0x86] = bios_sys_a0_86; + //biosA0[0x87] = bios_sys_a0_87; + //biosA0[0x88] = bios_sys_a0_88; + //biosA0[0x89] = bios_sys_a0_89; + //biosA0[0x8a] = bios_sys_a0_8a; + //biosA0[0x8b] = bios_sys_a0_8b; + //biosA0[0x8c] = bios_sys_a0_8c; + //biosA0[0x8d] = bios_sys_a0_8d; + //biosA0[0x8e] = bios_sys_a0_8e; + //biosA0[0x8f] = bios_sys_a0_8f; + //biosA0[0x90] = bios_sys_a0_90; + //biosA0[0x91] = bios_sys_a0_91; + //biosA0[0x92] = bios_sys_a0_92; + //biosA0[0x93] = bios_sys_a0_93; + //biosA0[0x94] = bios_sys_a0_94; + //biosA0[0x95] = bios_sys_a0_95; + //biosA0[0x96] = bios_AddCDROMDevice; + //biosA0[0x97] = bios_AddMemCardDevide; + //biosA0[0x98] = bios_DisableKernelIORedirection; + //biosA0[0x99] = bios_EnableKernelIORedirection; + //biosA0[0x9a] = bios_sys_a0_9a; + //biosA0[0x9b] = bios_sys_a0_9b; + //biosA0[0x9c] = bios_SetConf; + //biosA0[0x9d] = bios_GetConf; + //biosA0[0x9e] = bios_sys_a0_9e; + //biosA0[0x9f] = bios_SetMem; + //biosA0[0xa0] = bios__boot; + //biosA0[0xa1] = bios_SystemError; + //biosA0[0xa2] = bios_EnqueueCdIntr; + //biosA0[0xa3] = bios_DequeueCdIntr; + //biosA0[0xa4] = bios_sys_a0_a4; + //biosA0[0xa5] = bios_ReadSector; + //biosA0[0xa6] = bios_get_cd_status; + //biosA0[0xa7] = bios_bufs_cb_0; + //biosA0[0xa8] = bios_bufs_cb_1; + //biosA0[0xa9] = bios_bufs_cb_2; + //biosA0[0xaa] = bios_bufs_cb_3; + biosA0[0xab] = bios__card_info; + biosA0[0xac] = bios__card_load; + //biosA0[0axd] = bios__card_auto; + //biosA0[0xae] = bios_bufs_cd_4; + //biosA0[0xaf] = bios_sys_a0_af; + //biosA0[0xb0] = bios_sys_a0_b0; + //biosA0[0xb1] = bios_sys_a0_b1; + //biosA0[0xb2] = bios_do_a_long_jmp + //biosA0[0xb3] = bios_sys_a0_b3; + //biosA0[0xb4] = bios_sub_function; +//*******************B0 CALLS**************************** + //biosB0[0x00] = bios_SysMalloc; + //biosB0[0x01] = bios_sys_b0_01; + biosB0[0x02] = bios_SetRCnt; + biosB0[0x03] = bios_GetRCnt; + biosB0[0x04] = bios_StartRCnt; + biosB0[0x05] = bios_StopRCnt; + biosB0[0x06] = bios_ResetRCnt; + biosB0[0x07] = bios_DeliverEvent; + biosB0[0x08] = bios_OpenEvent; + biosB0[0x09] = bios_CloseEvent; + biosB0[0x0a] = bios_WaitEvent; + biosB0[0x0b] = bios_TestEvent; + biosB0[0x0c] = bios_EnableEvent; + biosB0[0x0d] = bios_DisableEvent; + biosB0[0x0e] = bios_OpenTh; + biosB0[0x0f] = bios_CloseTh; + biosB0[0x10] = bios_ChangeTh; + //biosB0[0x11] = bios_bios_b0_11; + biosB0[0x12] = bios_InitPAD; + biosB0[0x13] = bios_StartPAD; + biosB0[0x14] = bios_StopPAD; + biosB0[0x15] = bios_PAD_init; + biosB0[0x16] = bios_PAD_dr; + biosB0[0x17] = bios_ReturnFromException; + biosB0[0x18] = bios_ResetEntryInt; + biosB0[0x19] = bios_HookEntryInt; + //biosB0[0x1a] = bios_sys_b0_1a; + //biosB0[0x1b] = bios_sys_b0_1b; + //biosB0[0x1c] = bios_sys_b0_1c; + //biosB0[0x1d] = bios_sys_b0_1d; + //biosB0[0x1e] = bios_sys_b0_1e; + //biosB0[0x1f] = bios_sys_b0_1f; + biosB0[0x20] = bios_UnDeliverEvent; + //biosB0[0x21] = bios_sys_b0_21; + //biosB0[0x22] = bios_sys_b0_22; + //biosB0[0x23] = bios_sys_b0_23; + //biosB0[0x24] = bios_sys_b0_24; + //biosB0[0x25] = bios_sys_b0_25; + //biosB0[0x26] = bios_sys_b0_26; + //biosB0[0x27] = bios_sys_b0_27; + //biosB0[0x28] = bios_sys_b0_28; + //biosB0[0x29] = bios_sys_b0_29; + //biosB0[0x2a] = bios_sys_b0_2a; + //biosB0[0x2b] = bios_sys_b0_2b; + //biosB0[0x2c] = bios_sys_b0_2c; + //biosB0[0x2d] = bios_sys_b0_2d; + //biosB0[0x2e] = bios_sys_b0_2e; + //biosB0[0x2f] = bios_sys_b0_2f; + //biosB0[0x30] = bios_sys_b0_30; + //biosB0[0x31] = bios_sys_b0_31; + biosB0[0x32] = bios_open; + biosB0[0x33] = bios_lseek; + biosB0[0x34] = bios_read; + biosB0[0x35] = bios_write; + biosB0[0x36] = bios_close; + //biosB0[0x37] = bios_ioctl; + //biosB0[0x38] = bios_exit; + //biosB0[0x39] = bios_sys_b0_39; + //biosB0[0x3a] = bios_getc; + //biosB0[0x3b] = bios_putc; + biosB0[0x3c] = bios_getchar; + //biosB0[0x3e] = bios_gets; + //biosB0[0x40] = bios_cd; + //biosB0[0x41] = bios_format; + biosB0[0x42] = bios_firstfile; + biosB0[0x43] = bios_nextfile; + //biosB0[0x44] = bios_rename; + biosB0[0x45] = bios_delete; + //biosB0[0x46] = bios_undelete; + //biosB0[0x47] = bios_AddDevice; + //biosB0[0x48] = bios_RemoteDevice; + //biosB0[0x49] = bios_PrintInstalledDevices; + biosB0[0x4a] = bios_InitCARD; + biosB0[0x4b] = bios_StartCARD; + biosB0[0x4c] = bios_StopCARD; + //biosB0[0x4d] = bios_sys_b0_4d; + biosB0[0x4e] = bios__card_write; + biosB0[0x4f] = bios__card_read; + biosB0[0x50] = bios__new_card; + //biosB0[0x51] = bios_Krom2RawAdd; + //biosB0[0x52] = bios_sys_b0_52; + //biosB0[0x53] = bios_sys_b0_53; + //biosB0[0x54] = bios__get_errno; + //biosB0[0x55] = bios__get_error; + biosB0[0x56] = bios_GetC0Table; + biosB0[0x57] = bios_GetB0Table; + //biosB0[0x58] = bios__card_chan; + //biosB0[0x59] = bios_sys_b0_59; + //biosB0[0x5a] = bios_sys_b0_5a; + biosB0[0x5b] = bios_ChangeClearPad; + //biosB0[0x5c] = bios__card_status; + //biosB0[0x5d] = bios__card_wait; +//*******************C0 CALLS**************************** + //biosC0[0x00] = bios_InitRCnt; + //biosC0[0x01] = bios_InitException; + biosC0[0x02] = bios_SysEnqIntRP; + biosC0[0x03] = bios_SysDeqIntRP; + //biosC0[0x04] = bios_get_free_EvCB_slot; + //biosC0[0x05] = bios_get_free_TCB_slot; + //biosC0[0x06] = bios_ExceptionHandler; + //biosC0[0x07] = bios_InstallExeptionHandler; + //biosC0[0x08] = bios_SysInitMemory; + //biosC0[0x09] = bios_SysInitKMem; + biosC0[0x0a] = bios_ChangeClearRCnt; + //biosC0[0x0b] = bios_SystemError; + //biosC0[0x0c] = bios_InitDefInt; + //biosC0[0x0d] = bios_sys_c0_0d; + //biosC0[0x0e] = bios_sys_c0_0e; + //biosC0[0x0f] = bios_sys_c0_0f; + //biosC0[0x10] = bios_sys_c0_10; + //biosC0[0x11] = bios_sys_c0_11; + //biosC0[0x12] = bios_InstallDevices; + //biosC0[0x13] = bios_FlushStfInOutPut; + //biosC0[0x14] = bios_sys_c0_14; + //biosC0[0x15] = bios__cdevinput; + //biosC0[0x16] = bios__cdevscan; + //biosC0[0x17] = bios__circgetc; + //biosC0[0x18] = bios__circputc; + //biosC0[0x19] = bios_ioabort; + //biosC0[0x1a] = bios_sys_c0_1a + //biosC0[0x1b] = bios_KernelRedirect; + //biosC0[0x1c] = bios_PatchAOTable; +//************** THE END *************************************** + + base = 0x1000; + size = sizeof(EvCB) * 32; + Event = (void *)&psxR[base]; base+= size*6; + memset(Event, 0, size * 6); + HwEV = Event; + EvEV = Event + 32; + RcEV = Event + 32*2; + UeEV = Event + 32*3; + SwEV = Event + 32*4; + ThEV = Event + 32*5; + + ptr = (u32*)&psxM[0x0874]; // b0 table + ptr[0] = 0x4c54 - 0x884; + + ptr = (u32*)&psxM[0x0674]; // c0 table + ptr[6] = 0xc80; + + memset(SysIntRP, 0, sizeof(SysIntRP)); + memset(Thread, 0, sizeof(Thread)); + Thread[0].status = 2; // main thread + + psxMu32(0x0150) = 0x160; + psxMu32(0x0154) = 0x320; + psxMu32(0x0160) = 0x248; + strcpy(&psxM[0x248], "bu"); + + // opcode HLE + psxRu32(0x0000) = (0x3b << 26) | 4; + psxMu32(0x0000) = (0x3b << 26) | 0; + psxMu32(0x00a0) = (0x3b << 26) | 1; + psxMu32(0x00b0) = (0x3b << 26) | 2; + psxMu32(0x00c0) = (0x3b << 26) | 3; + psxMu32(0x4c54) = (0x3b << 26) | 0; + psxMu32(0x8000) = (0x3b << 26) | 5; + psxMu32(0x07a0) = (0x3b << 26) | 0; + psxMu32(0x0884) = (0x3b << 26) | 0; + psxMu32(0x0894) = (0x3b << 26) | 0; +} + +void psxBiosShutdown() { +} + +__inline void SaveRegs() { + memcpy(regs, psxRegs.GPR.r, 32*4); + regs[32] = psxRegs.GPR.n.lo; + regs[33] = psxRegs.GPR.n.hi; + regs[34] = psxRegs.pc; +} + +__inline void LoadRegs() { + memcpy(psxRegs.GPR.r, regs, 32*4); + psxRegs.GPR.n.lo = regs[32]; + psxRegs.GPR.n.hi = regs[33]; +} + +#define bios_PADpoll(pad) { \ + PAD##pad##_startPoll(pad); \ + pad_buf##pad[0] = 0; \ + pad_buf##pad[1] = PAD##pad##_poll(0x42); \ + if (!(pad_buf##pad[1] & 0x0f)) { \ + bufcount = 32; \ + } else { \ + bufcount = (pad_buf##pad[1] & 0x0f) * 2; \ + } \ + PAD##pad##_poll(0); \ + i = 2; \ + while (bufcount--) { \ + pad_buf##pad[i++] = PAD##pad##_poll(0); \ + } \ +} + +void biosInterrupt() { + int i, bufcount; + + if ((psxRegs.CP0.n.Status & 0x404) != 0x404) return; + +// if (psxHu32(0x1070) & 0x1) { // Vsync + if (pad_buf) { + PAD1_startPoll(1); + PAD1_poll(0x42); + PAD1_poll(0); + *pad_buf = PAD1_poll(0) << 8; + *pad_buf|= PAD1_poll(0); + PAD2_startPoll(2); + PAD2_poll(0x42); + PAD2_poll(0); + *pad_buf|= PAD2_poll(0) << 24; + *pad_buf|= PAD2_poll(0) << 16; + } + if (pad_buf1) { + bios_PADpoll(1); + } + + if (pad_buf2) { + bios_PADpoll(2); + } + + if (psxHu32(0x1070) & 0x1) { // Vsync + if (RcEV[3][1].status == EvStACTIVE) { + softCall(RcEV[3][1].fhandler); +// hwWrite32(0x1f801070, ~(1)); + } + } + + if (psxHu32(0x1070) & 0x70) { // Rcnt 0,1,2 + int i; + + for (i=0; i<3; i++) { + if (psxHu32(0x1070) & (1 << (i+4)) && psxCounters[i].mode & 0x50) { + if (RcEV[i][1].status == EvStACTIVE) { + softCall(RcEV[i][1].fhandler); + } + psxHwWrite32(0x1f801070, ~(1 << (i+4))); + } + } + } +} + +void psxBiosException() { + int i; + + switch ((psxRegs.CP0.n.Cause & 0x3c) >> 2) { + case 0: // Interrupt +#ifdef PSXCPU_LOG +// PSXCPU_LOG("interrupt\n"); +#endif + SaveRegs(); + + biosInterrupt(); + + for (i=0; i<8; i++) { + if (SysIntRP[i]) { + u32 *queue = (u32*)PSXM(SysIntRP[i]); + + s0 = queue[2]; + softCall(queue[1]); + } + } + + if (jmp_int != NULL) { + int i; + + psxHwWrite32(0x1f801070, 0xffffffff); + + ra = jmp_int[0]; + sp = jmp_int[1]; + fp = jmp_int[2]; + for (i=0; i<8; i++) // s0-s7 + psxRegs.GPR.r[16+i] = jmp_int[3+i]; + gp = jmp_int[11]; + + v0 = 1; + pc0 = ra; + return; + } + psxHwWrite16(0x1f801070, 0); + break; + case 8: // Syscall +#ifdef PSXCPU_LOG +// PSXCPU_LOG("syscall exp %x\n", a0); +#endif + switch (a0) { + case 1: // EnterCritical - disable irq's + psxRegs.CP0.n.Status&=~0x404; break; + case 2: // ExitCritical - enable irq's + psxRegs.CP0.n.Status|= 0x404; break; + } + pc0 = psxRegs.CP0.n.EPC + 4; + + psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status & 0xfffffff0) | + ((psxRegs.CP0.n.Status & 0x3c) >> 2); + return; + default: +#ifdef PSXCPU_LOG + PSXCPU_LOG("unk exp\n"); +#endif + break; + } + + pc0 = psxRegs.CP0.n.EPC; + if (psxRegs.CP0.n.Cause & 0x80000000) pc0+=4; + + psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status & 0xfffffff0) | + ((psxRegs.CP0.n.Status & 0x3c) >> 2); +} + +#define bfreeze(ptr, size) \ + if (Mode == 1) memcpy(&psxR[base], ptr, size); \ + if (Mode == 0) memcpy(ptr, &psxR[base], size); \ + base+=size; + +#define bfreezes(ptr) bfreeze(ptr, sizeof(ptr)) +#define bfreezel(ptr) bfreeze(ptr, 4) + +#define bfreezepsxMptr(ptr) \ + if (Mode == 1) { \ + if (ptr) psxRu32(base) = (u32)ptr - (u32)psxM; \ + else psxRu32(base) = 0; \ + } else { \ + if (psxRu32(base)) (u8*)ptr = (u8*)(psxM + psxRu32(base)); \ + else ptr = NULL; \ + } \ + base+=4; + +void psxBiosFreeze(int Mode) { + u32 base = 0x40000; + + bfreezepsxMptr(jmp_int); + bfreezepsxMptr(pad_buf); + bfreezepsxMptr(pad_buf1); + bfreezepsxMptr(pad_buf2); + bfreezepsxMptr(heap_addr); + bfreezel(&pad_buf1len); + bfreezel(&pad_buf2len); + bfreezes(regs); + bfreezes(SysIntRP); + bfreezel(&CardState); + bfreezes(Thread); + bfreezel(&CurThread); + bfreezes(FDesc); } \ No newline at end of file diff --git a/PcsxSrc/PsxBios.h b/PcsxSrc/PsxBios.h index 47db9bc..1a6aa17 100644 --- a/PcsxSrc/PsxBios.h +++ b/PcsxSrc/PsxBios.h @@ -1,35 +1,35 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __PSXBIOS_H__ -#define __PSXBIOS_H__ - -extern char *biosA0n[256]; -extern char *biosB0n[256]; -extern char *biosC0n[256]; - -void psxBiosInit(); -void psxBiosShutdown(); -void psxBiosException(); -void psxBiosFreeze(int Mode); - -extern void (*biosA0[256])(); -extern void (*biosB0[256])(); -extern void (*biosC0[256])(); - -#endif /* __PSXBIOS_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __PSXBIOS_H__ +#define __PSXBIOS_H__ + +extern char *biosA0n[256]; +extern char *biosB0n[256]; +extern char *biosC0n[256]; + +void psxBiosInit(); +void psxBiosShutdown(); +void psxBiosException(); +void psxBiosFreeze(int Mode); + +extern void (*biosA0[256])(); +extern void (*biosB0[256])(); +extern void (*biosC0[256])(); + +#endif /* __PSXBIOS_H__ */ diff --git a/PcsxSrc/PsxCommon.h b/PcsxSrc/PsxCommon.h index 0a70656..c76fadb 100644 --- a/PcsxSrc/PsxCommon.h +++ b/PcsxSrc/PsxCommon.h @@ -1,132 +1,132 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __PSXCOMMON_H__ -#define __PSXCOMMON_H__ - -#include "System.h" -#include - -#if defined(__WIN32__) - -#include - -typedef struct { - HWND hWnd; // Main window handle - HINSTANCE hInstance; // Application instance - HMENU hMenu; // Main window menu -} AppData; - -#elif defined (__LINUX__) - -#include - -#define __inline inline - -#endif - -// Basic types -#if defined(__WIN32__) - -typedef __int8 s8; -typedef __int16 s16; -typedef __int32 s32; -typedef __int64 s64; - -typedef unsigned __int8 u8; -typedef unsigned __int16 u16; -typedef unsigned __int32 u32; -typedef unsigned __int64 u64; - -#elif defined(__LINUX__) - -typedef char s8; -typedef short s16; -typedef long s32; -typedef long long s64; - -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned long u32; -typedef unsigned long long u64; - -#endif - -extern int Log; -void __Log(char *fmt, ...); - -typedef struct { - char Gpu[256]; - char Spu[256]; - char Cdr[256]; - char Pad1[256]; - char Pad2[256]; - char Mcd1[256]; - char Mcd2[256]; - char Bios[256]; - char BiosDir[256]; - char PluginsDir[256]; - long Xa; - long Sio; - long Mdec; - long PsxAuto; - long PsxType; // ntsc - 0 | pal - 1 - long QKeys; - long Cdda; - long HLE; - long Cpu; - long Log; - long PsxOut; - long SpuIrq; - long CdTiming; -} PcsxConfig; - -PcsxConfig Config; - -extern long LoadCdBios; -extern int StatesC; -extern char CdromId[256]; -extern int cdOpenCase; - -#define gzfreeze(ptr, size) \ - if (Mode == 1) gzwrite(f, ptr, size); \ - if (Mode == 0) gzread(f, ptr, size); - -#define gzfreezel(ptr) gzfreeze(ptr, sizeof(ptr)) - -#define BIAS 4 -#define PSXCLK 33868800 /* 33.8688 Mhz */ - -#include "R3000A.h" -#include "PsxMem.h" -#include "PsxHw.h" -#include "PsxBios.h" -#include "PsxDma.h" -#include "PsxCounters.h" -#include "PsxHLE.h" -#include "Mdec.h" -#include "CdRom.h" -#include "Sio.h" -#include "Spu.h" -#include "plugins.h" -#include "Decode_XA.h" -#include "Misc.h" -#include "Debug.h" -#include "Gte.h" - -#endif /* __PSXCOMMON_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __PSXCOMMON_H__ +#define __PSXCOMMON_H__ + +#include "System.h" +#include + +#if defined(__WIN32__) + +#include + +typedef struct { + HWND hWnd; // Main window handle + HINSTANCE hInstance; // Application instance + HMENU hMenu; // Main window menu +} AppData; + +#elif defined (__LINUX__) + +#include + +#define __inline inline + +#endif + +// Basic types +#if defined(__WIN32__) + +typedef __int8 s8; +typedef __int16 s16; +typedef __int32 s32; +typedef __int64 s64; + +typedef unsigned __int8 u8; +typedef unsigned __int16 u16; +typedef unsigned __int32 u32; +typedef unsigned __int64 u64; + +#elif defined(__LINUX__) + +typedef char s8; +typedef short s16; +typedef long s32; +typedef long long s64; + +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned long u32; +typedef unsigned long long u64; + +#endif + +extern int Log; +void __Log(char *fmt, ...); + +typedef struct { + char Gpu[256]; + char Spu[256]; + char Cdr[256]; + char Pad1[256]; + char Pad2[256]; + char Mcd1[256]; + char Mcd2[256]; + char Bios[256]; + char BiosDir[256]; + char PluginsDir[256]; + long Xa; + long Sio; + long Mdec; + long PsxAuto; + long PsxType; // ntsc - 0 | pal - 1 + long QKeys; + long Cdda; + long HLE; + long Cpu; + long Log; + long PsxOut; + long SpuIrq; + long CdTiming; +} PcsxConfig; + +PcsxConfig Config; + +extern long LoadCdBios; +extern int StatesC; +extern char CdromId[256]; +extern int cdOpenCase; + +#define gzfreeze(ptr, size) \ + if (Mode == 1) gzwrite(f, ptr, size); \ + if (Mode == 0) gzread(f, ptr, size); + +#define gzfreezel(ptr) gzfreeze(ptr, sizeof(ptr)) + +#define BIAS 4 +#define PSXCLK 33868800 /* 33.8688 Mhz */ + +#include "R3000A.h" +#include "PsxMem.h" +#include "PsxHw.h" +#include "PsxBios.h" +#include "PsxDma.h" +#include "PsxCounters.h" +#include "PsxHLE.h" +#include "Mdec.h" +#include "CdRom.h" +#include "Sio.h" +#include "Spu.h" +#include "plugins.h" +#include "Decode_XA.h" +#include "Misc.h" +#include "Debug.h" +#include "Gte.h" + +#endif /* __PSXCOMMON_H__ */ diff --git a/PcsxSrc/PsxCounters.c b/PcsxSrc/PsxCounters.c index a9bdabf..39a8a41 100644 --- a/PcsxSrc/PsxCounters.c +++ b/PcsxSrc/PsxCounters.c @@ -1,202 +1,202 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - -#include "PsxCommon.h" - -static int cnts = 4; - -static void psxRcntUpd(unsigned long index) { - psxCounters[index].sCycle = psxRegs.cycle; - if ((!(psxCounters[index].mode & 1)) || (index!=2)) { - if (psxCounters[index].mode & 0x08) { // Count to target - psxCounters[index].Cycle = ((psxCounters[index].target - psxCounters[index].count) * psxCounters[index].rate) / BIAS; - } - else { // Count to 0xffff - psxCounters[index].Cycle = ((0xffff - psxCounters[index].count) * psxCounters[index].rate) / BIAS; - } - } else psxCounters[index].Cycle = 0xffffffff; -} - -static void psxRcntReset(unsigned long index) { - psxCounters[index].count = 0; - psxRcntUpd(index); - - if ((psxCounters[index].mode & 0x50) == 0x50) psxHu32(0x1070)|= psxCounters[index].interrupt; -} - -static void psxRcntSet() { - int i; - - psxNextCounter = 0x7fffffff; - psxNextsCounter = psxRegs.cycle; - - for (i=0; i= psxCounters[3].Cycle) { - psxRcntReset(3); - GPU_updateLace(); // updateGPU - SysUpdate(); -#ifdef GTE_LOG - GTE_LOG("VSync\n"); -#endif - } - - if ((psxRegs.cycle - psxCounters[0].sCycle) >= psxCounters[0].Cycle) { - psxRcntReset(0); - } - - if ((psxRegs.cycle - psxCounters[1].sCycle) >= psxCounters[1].Cycle) { - psxRcntReset(1); - } - - if ((psxRegs.cycle - psxCounters[2].sCycle) >= psxCounters[2].Cycle) { - psxRcntReset(2); - } - - if (cnts >= 5) { - if ((psxRegs.cycle - psxCounters[4].sCycle) >= psxCounters[4].Cycle) { - if (SPU_update != NULL) - SPU_update(); - if (SPU_async != NULL) - SPU_async((psxRegs.cycle - psxCounters[4].sCycle) * BIAS); - psxRcntReset(4); - } - } - - psxRcntSet(); -} - -void psxRcntWcount(unsigned long index, unsigned long value) { -// SysPrintf("writeCcount[%d] = %x\n", index, value); -// PSXCPU_LOG("writeCcount[%d] = %x\n", index, value); - psxCounters[index].count = value; - psxRcntUpd(index); - psxRcntSet(); -} - -void psxRcntWmode(unsigned long index, unsigned long value) { -// SysPrintf("writeCmode[%ld] = %lx\n", index, value); - psxCounters[index].mode = value; - if(index == 0) { - switch (value & 0x300) { - case 0x100: - psxCounters[index].rate = ((psxCounters[3].rate /** BIAS*/) / 386) / 262; // seems ok - break; - default: - psxCounters[index].rate = 1; - } - } - else if(index == 1) { - switch (value & 0x300) { - case 0x100: - psxCounters[index].rate = (psxCounters[3].rate /** BIAS*/) / 262; // seems ok - break; - default: - psxCounters[index].rate = 1; - } - } - else if(index == 2) { - switch (value & 0x300) { - case 0x200: - psxCounters[index].rate = 8; // 1/8 speed - break; - default: - psxCounters[index].rate = 1; // normal speed - } - } - - // Need to set a rate and target - psxRcntUpd(index); - psxRcntSet(); -} - -void psxRcntWtarget(unsigned long index, unsigned long value) { -// SysPrintf("writeCtarget[%ld] = %lx\n", index, value); - psxCounters[index].target = value; - psxRcntUpd(index); - psxRcntSet(); -} - -unsigned long psxRcntRcount(unsigned long index) { -// if ((!(psxCounters[index].mode & 1)) || (index!=2)) { - return (psxCounters[index].count + BIAS * (psxRegs.cycle - psxCounters[index].sCycle) / psxCounters[index].rate) & 0xffff; -// } else return 0; -} - -int psxRcntFreeze(gzFile f, int Mode) { - char Unused[4096 - sizeof(psxCounter)]; - - gzfreezel(psxCounters); - gzfreezel(Unused); - - return 0; -} +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + +#include "PsxCommon.h" + +static int cnts = 4; + +static void psxRcntUpd(unsigned long index) { + psxCounters[index].sCycle = psxRegs.cycle; + if ((!(psxCounters[index].mode & 1)) || (index!=2)) { + if (psxCounters[index].mode & 0x08) { // Count to target + psxCounters[index].Cycle = ((psxCounters[index].target - psxCounters[index].count) * psxCounters[index].rate) / BIAS; + } + else { // Count to 0xffff + psxCounters[index].Cycle = ((0xffff - psxCounters[index].count) * psxCounters[index].rate) / BIAS; + } + } else psxCounters[index].Cycle = 0xffffffff; +} + +static void psxRcntReset(unsigned long index) { + psxCounters[index].count = 0; + psxRcntUpd(index); + + if ((psxCounters[index].mode & 0x50) == 0x50) psxHu32(0x1070)|= psxCounters[index].interrupt; +} + +static void psxRcntSet() { + int i; + + psxNextCounter = 0x7fffffff; + psxNextsCounter = psxRegs.cycle; + + for (i=0; i= psxCounters[3].Cycle) { + psxRcntReset(3); + GPU_updateLace(); // updateGPU + SysUpdate(); +#ifdef GTE_LOG + GTE_LOG("VSync\n"); +#endif + } + + if ((psxRegs.cycle - psxCounters[0].sCycle) >= psxCounters[0].Cycle) { + psxRcntReset(0); + } + + if ((psxRegs.cycle - psxCounters[1].sCycle) >= psxCounters[1].Cycle) { + psxRcntReset(1); + } + + if ((psxRegs.cycle - psxCounters[2].sCycle) >= psxCounters[2].Cycle) { + psxRcntReset(2); + } + + if (cnts >= 5) { + if ((psxRegs.cycle - psxCounters[4].sCycle) >= psxCounters[4].Cycle) { + if (SPU_update != NULL) + SPU_update(); + if (SPU_async != NULL) + SPU_async((psxRegs.cycle - psxCounters[4].sCycle) * BIAS); + psxRcntReset(4); + } + } + + psxRcntSet(); +} + +void psxRcntWcount(unsigned long index, unsigned long value) { +// SysPrintf("writeCcount[%d] = %x\n", index, value); +// PSXCPU_LOG("writeCcount[%d] = %x\n", index, value); + psxCounters[index].count = value; + psxRcntUpd(index); + psxRcntSet(); +} + +void psxRcntWmode(unsigned long index, unsigned long value) { +// SysPrintf("writeCmode[%ld] = %lx\n", index, value); + psxCounters[index].mode = value; + if(index == 0) { + switch (value & 0x300) { + case 0x100: + psxCounters[index].rate = ((psxCounters[3].rate /** BIAS*/) / 386) / 262; // seems ok + break; + default: + psxCounters[index].rate = 1; + } + } + else if(index == 1) { + switch (value & 0x300) { + case 0x100: + psxCounters[index].rate = (psxCounters[3].rate /** BIAS*/) / 262; // seems ok + break; + default: + psxCounters[index].rate = 1; + } + } + else if(index == 2) { + switch (value & 0x300) { + case 0x200: + psxCounters[index].rate = 8; // 1/8 speed + break; + default: + psxCounters[index].rate = 1; // normal speed + } + } + + // Need to set a rate and target + psxRcntUpd(index); + psxRcntSet(); +} + +void psxRcntWtarget(unsigned long index, unsigned long value) { +// SysPrintf("writeCtarget[%ld] = %lx\n", index, value); + psxCounters[index].target = value; + psxRcntUpd(index); + psxRcntSet(); +} + +unsigned long psxRcntRcount(unsigned long index) { +// if ((!(psxCounters[index].mode & 1)) || (index!=2)) { + return (psxCounters[index].count + BIAS * (psxRegs.cycle - psxCounters[index].sCycle) / psxCounters[index].rate) & 0xffff; +// } else return 0; +} + +int psxRcntFreeze(gzFile f, int Mode) { + char Unused[4096 - sizeof(psxCounter)]; + + gzfreezel(psxCounters); + gzfreezel(Unused); + + return 0; +} diff --git a/PcsxSrc/PsxCounters.h b/PcsxSrc/PsxCounters.h index 23d1235..43e0399 100644 --- a/PcsxSrc/PsxCounters.h +++ b/PcsxSrc/PsxCounters.h @@ -1,41 +1,41 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __PSXCOUNTERS_H__ -#define __PSXCOUNTERS_H__ - -typedef struct { - unsigned long count, mode, target; - unsigned long sCycle, Cycle, rate, interrupt; -} psxCounter; - -psxCounter psxCounters[5]; - -unsigned long psxNextCounter, psxNextsCounter; - -void psxRcntInit(); -void psxRcntUpdate(); -void psxRcntWcount(unsigned long index, unsigned long value); -void psxRcntWmode(unsigned long index, unsigned long value); -void psxRcntWtarget(unsigned long index, unsigned long value); -unsigned long psxRcntRcount(unsigned long index); -int psxRcntFreeze(gzFile f, int Mode); - -void UpdateVSyncRate(); - -#endif /* __PSXCOUNTERS_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __PSXCOUNTERS_H__ +#define __PSXCOUNTERS_H__ + +typedef struct { + unsigned long count, mode, target; + unsigned long sCycle, Cycle, rate, interrupt; +} psxCounter; + +psxCounter psxCounters[5]; + +unsigned long psxNextCounter, psxNextsCounter; + +void psxRcntInit(); +void psxRcntUpdate(); +void psxRcntWcount(unsigned long index, unsigned long value); +void psxRcntWmode(unsigned long index, unsigned long value); +void psxRcntWtarget(unsigned long index, unsigned long value); +unsigned long psxRcntRcount(unsigned long index); +int psxRcntFreeze(gzFile f, int Mode); + +void UpdateVSyncRate(); + +#endif /* __PSXCOUNTERS_H__ */ diff --git a/PcsxSrc/PsxDma.c b/PcsxSrc/PsxDma.c index c765884..61d002e 100644 --- a/PcsxSrc/PsxDma.c +++ b/PcsxSrc/PsxDma.c @@ -1,96 +1,96 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 "PsxCommon.h" - -// Dma0/1 in Mdec.c -// Dma3 in CdRom.c - -void psxDma4(u32 madr, u32 bcr, u32 chcr) { // SPU - switch (chcr) { - case 0x01000201: //cpu to spu transfer -#ifdef PSXDMA_LOG - PSXDMA_LOG("*** DMA 4 - SPU mem2spu *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif - SPU_writeDMAMem((u16 *)PSXM(madr), (bcr >> 16) * (bcr & 0xffff) * 2); - break; - case 0x01000200: //spu to cpu transfer -#ifdef PSXDMA_LOG - PSXDMA_LOG("*** DMA 4 - SPU spu2mem *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif - SPU_readDMAMem ((u16 *)PSXM(madr), (bcr >> 16) * (bcr & 0xffff) * 2); - break; -#ifdef PSXDMA_LOG - default: - PSXDMA_LOG("*** DMA 4 - SPU unknown *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); - break; -#endif - } -} - -void psxDma2(u32 madr, u32 bcr, u32 chcr) { // GPU - switch(chcr) { - case 0x01000200: // vram2mem -#ifdef PSXDMA_LOG - PSXDMA_LOG("*** DMA 2 - GPU vram2mem *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif - GPU_readDataMem((u32 *)PSXM(madr), (bcr >> 16) * (bcr & 0xffff)); - psxCpu->Clear(madr, ((bcr >> 16) * (bcr & 0xffff)) / 4); - break; - - case 0x01000201: // mem2vram -#ifdef PSXDMA_LOG - PSXDMA_LOG("*** DMA 2 - GPU mem2vram *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif - GPU_writeDataMem((u32 *)PSXM(madr), (bcr >> 16) * (bcr & 0xffff)); - break; - - case 0x01000401: // dma chain -#ifdef PSXDMA_LOG - PSXDMA_LOG("*** DMA 2 - GPU dma chain *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif - GPU_dmaChain((u32 *)psxM, madr & 0x1fffff); - break; -#ifdef PSXDMA_LOG - default: - PSXDMA_LOG("*** DMA 2 - GPU unknown *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); - break; -#endif - } -} - -void psxDma6(u32 madr, u32 bcr, u32 chcr) { - u32 *mem = (u32 *)PSXM(madr); - -#ifdef PSXDMA_LOG - PSXDMA_LOG("*** DMA 6 - OT *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif - - if (chcr == 0x11000002) { - while (bcr--) { - *mem-- = (madr - 4) & 0xffffff; - madr -= 4; - } - mem++; *mem = 0xffffff; - } else { - // Unknown option -#ifdef PSXDMA_LOG - PSXDMA_LOG("*** DMA 6 - OT unknown *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif - } -} +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 "PsxCommon.h" + +// Dma0/1 in Mdec.c +// Dma3 in CdRom.c + +void psxDma4(u32 madr, u32 bcr, u32 chcr) { // SPU + switch (chcr) { + case 0x01000201: //cpu to spu transfer +#ifdef PSXDMA_LOG + PSXDMA_LOG("*** DMA 4 - SPU mem2spu *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); +#endif + SPU_writeDMAMem((u16 *)PSXM(madr), (bcr >> 16) * (bcr & 0xffff) * 2); + break; + case 0x01000200: //spu to cpu transfer +#ifdef PSXDMA_LOG + PSXDMA_LOG("*** DMA 4 - SPU spu2mem *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); +#endif + SPU_readDMAMem ((u16 *)PSXM(madr), (bcr >> 16) * (bcr & 0xffff) * 2); + break; +#ifdef PSXDMA_LOG + default: + PSXDMA_LOG("*** DMA 4 - SPU unknown *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); + break; +#endif + } +} + +void psxDma2(u32 madr, u32 bcr, u32 chcr) { // GPU + switch(chcr) { + case 0x01000200: // vram2mem +#ifdef PSXDMA_LOG + PSXDMA_LOG("*** DMA 2 - GPU vram2mem *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); +#endif + GPU_readDataMem((u32 *)PSXM(madr), (bcr >> 16) * (bcr & 0xffff)); + psxCpu->Clear(madr, ((bcr >> 16) * (bcr & 0xffff)) / 4); + break; + + case 0x01000201: // mem2vram +#ifdef PSXDMA_LOG + PSXDMA_LOG("*** DMA 2 - GPU mem2vram *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); +#endif + GPU_writeDataMem((u32 *)PSXM(madr), (bcr >> 16) * (bcr & 0xffff)); + break; + + case 0x01000401: // dma chain +#ifdef PSXDMA_LOG + PSXDMA_LOG("*** DMA 2 - GPU dma chain *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); +#endif + GPU_dmaChain((u32 *)psxM, madr & 0x1fffff); + break; +#ifdef PSXDMA_LOG + default: + PSXDMA_LOG("*** DMA 2 - GPU unknown *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); + break; +#endif + } +} + +void psxDma6(u32 madr, u32 bcr, u32 chcr) { + u32 *mem = (u32 *)PSXM(madr); + +#ifdef PSXDMA_LOG + PSXDMA_LOG("*** DMA 6 - OT *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); +#endif + + if (chcr == 0x11000002) { + while (bcr--) { + *mem-- = (madr - 4) & 0xffffff; + madr -= 4; + } + mem++; *mem = 0xffffff; + } else { + // Unknown option +#ifdef PSXDMA_LOG + PSXDMA_LOG("*** DMA 6 - OT unknown *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); +#endif + } +} diff --git a/PcsxSrc/PsxDma.h b/PcsxSrc/PsxDma.h index 0107f53..bb24d89 100644 --- a/PcsxSrc/PsxDma.h +++ b/PcsxSrc/PsxDma.h @@ -1,27 +1,27 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __PSXDMA_H__ -#define __PSXDMA_H__ - -void psxDma2(u32 madr, u32 bcr, u32 chcr); -void psxDma3(u32 madr, u32 bcr, u32 chcr); -void psxDma4(u32 madr, u32 bcr, u32 chcr); -void psxDma6(u32 madr, u32 bcr, u32 chcr); - -#endif /* __PSXDMA_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __PSXDMA_H__ +#define __PSXDMA_H__ + +void psxDma2(u32 madr, u32 bcr, u32 chcr); +void psxDma3(u32 madr, u32 bcr, u32 chcr); +void psxDma4(u32 madr, u32 bcr, u32 chcr); +void psxDma6(u32 madr, u32 bcr, u32 chcr); + +#endif /* __PSXDMA_H__ */ diff --git a/PcsxSrc/PsxHLE.c b/PcsxSrc/PsxHLE.c index 17fb6bb..985306c 100644 --- a/PcsxSrc/PsxHLE.c +++ b/PcsxSrc/PsxHLE.c @@ -1,91 +1,91 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 "PsxCommon.h" - -static void hleDummy() { - psxRegs.pc = psxRegs.GPR.n.ra; - - psxBranchTest(); -} - -static void hleA0() { - u32 call = psxRegs.GPR.n.t1 & 0xff; - - if (biosA0[call]) biosA0[call](); - - psxBranchTest(); -} - -static void hleB0() { - u32 call = psxRegs.GPR.n.t1 & 0xff; - - if (biosB0[call]) biosB0[call](); - - psxBranchTest(); -} - -static void hleC0() { - u32 call = psxRegs.GPR.n.t1 & 0xff; - - if (biosC0[call]) biosC0[call](); - - psxBranchTest(); -} - -static void hleBootstrap() { // 0xbfc00000 - SysPrintf("hleBootstrap\n"); - CheckCdrom(); - LoadCdrom(); - SysPrintf("CdromId: \"%s\": PC = %8.8lx (SP = %8.8lx)\n", CdromId, psxRegs.pc, psxRegs.GPR.n.sp); -} - -typedef struct { - unsigned long _pc0; - unsigned long gp0; - unsigned long t_addr; - unsigned long t_size; - unsigned long d_addr; - unsigned long d_size; - unsigned long b_addr; - unsigned long b_size; - unsigned long S_addr; - unsigned long s_size; - unsigned long _sp,_fp,_gp,ret,base; -} EXEC; - -static void hleExecRet() { - EXEC *header = (EXEC*)PSXM(psxRegs.GPR.n.s0); - - SysPrintf("ExecRet %x: %x\n", psxRegs.GPR.n.s0, header->ret); - - psxRegs.GPR.n.ra = header->ret; - psxRegs.GPR.n.sp = header->_sp; - psxRegs.GPR.n.s8 = header->_fp; - psxRegs.GPR.n.gp = header->_gp; - psxRegs.GPR.n.s0 = header->base; - - psxRegs.GPR.n.v0 = 1; - psxRegs.pc = psxRegs.GPR.n.ra; -} - -void (*psxHLEt[256])() = { - hleDummy, hleA0, hleB0, hleC0, - hleBootstrap, hleExecRet -}; +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 "PsxCommon.h" + +static void hleDummy() { + psxRegs.pc = psxRegs.GPR.n.ra; + + psxBranchTest(); +} + +static void hleA0() { + u32 call = psxRegs.GPR.n.t1 & 0xff; + + if (biosA0[call]) biosA0[call](); + + psxBranchTest(); +} + +static void hleB0() { + u32 call = psxRegs.GPR.n.t1 & 0xff; + + if (biosB0[call]) biosB0[call](); + + psxBranchTest(); +} + +static void hleC0() { + u32 call = psxRegs.GPR.n.t1 & 0xff; + + if (biosC0[call]) biosC0[call](); + + psxBranchTest(); +} + +static void hleBootstrap() { // 0xbfc00000 + SysPrintf("hleBootstrap\n"); + CheckCdrom(); + LoadCdrom(); + SysPrintf("CdromId: \"%s\": PC = %8.8lx (SP = %8.8lx)\n", CdromId, psxRegs.pc, psxRegs.GPR.n.sp); +} + +typedef struct { + unsigned long _pc0; + unsigned long gp0; + unsigned long t_addr; + unsigned long t_size; + unsigned long d_addr; + unsigned long d_size; + unsigned long b_addr; + unsigned long b_size; + unsigned long S_addr; + unsigned long s_size; + unsigned long _sp,_fp,_gp,ret,base; +} EXEC; + +static void hleExecRet() { + EXEC *header = (EXEC*)PSXM(psxRegs.GPR.n.s0); + + SysPrintf("ExecRet %x: %x\n", psxRegs.GPR.n.s0, header->ret); + + psxRegs.GPR.n.ra = header->ret; + psxRegs.GPR.n.sp = header->_sp; + psxRegs.GPR.n.s8 = header->_fp; + psxRegs.GPR.n.gp = header->_gp; + psxRegs.GPR.n.s0 = header->base; + + psxRegs.GPR.n.v0 = 1; + psxRegs.pc = psxRegs.GPR.n.ra; +} + +void (*psxHLEt[256])() = { + hleDummy, hleA0, hleB0, hleC0, + hleBootstrap, hleExecRet +}; diff --git a/PcsxSrc/PsxHLE.h b/PcsxSrc/PsxHLE.h index 2cd7443..745e1ea 100644 --- a/PcsxSrc/PsxHLE.h +++ b/PcsxSrc/PsxHLE.h @@ -1,24 +1,24 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __PSXHLE_H__ -#define __PSXHLE_H__ - -extern void (*psxHLEt[256])(); - -#endif /* __PSXHLE_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __PSXHLE_H__ +#define __PSXHLE_H__ + +extern void (*psxHLEt[256])(); + +#endif /* __PSXHLE_H__ */ diff --git a/PcsxSrc/PsxHw.c b/PcsxSrc/PsxHw.c index dbfc6da..7a65447 100644 --- a/PcsxSrc/PsxHw.c +++ b/PcsxSrc/PsxHw.c @@ -1,756 +1,756 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include - -#include "PsxCommon.h" - -#ifdef __WIN32__ -#pragma warning(disable:4244) -#endif - -#define HW_DMA0_MADR (psxHu32(0x1080)) // MDEC in DMA -#define HW_DMA0_BCR (psxHu32(0x1084)) -#define HW_DMA0_CHCR (psxHu32(0x1088)) - -#define HW_DMA1_MADR (psxHu32(0x1090)) // MDEC out DMA -#define HW_DMA1_BCR (psxHu32(0x1094)) -#define HW_DMA1_CHCR (psxHu32(0x1098)) - -#define HW_DMA2_MADR (psxHu32(0x10a0)) // GPU DMA -#define HW_DMA2_BCR (psxHu32(0x10a4)) -#define HW_DMA2_CHCR (psxHu32(0x10a8)) - -#define HW_DMA3_MADR (psxHu32(0x10b0)) // CDROM DMA -#define HW_DMA3_BCR (psxHu32(0x10b4)) -#define HW_DMA3_CHCR (psxHu32(0x10b8)) - -#define HW_DMA4_MADR (psxHu32(0x10c0)) // SPU DMA -#define HW_DMA4_BCR (psxHu32(0x10c4)) -#define HW_DMA4_CHCR (psxHu32(0x10c8)) - -#define HW_DMA6_MADR (psxHu32(0x10e0)) // GPU DMA (OT) -#define HW_DMA6_BCR (psxHu32(0x10e4)) -#define HW_DMA6_CHCR (psxHu32(0x10e8)) - -#define HW_DMA_PCR (psxHu32(0x10f0)) -#define HW_DMA_ICR (psxHu32(0x10f4)) - -void psxHwReset() { - if (Config.Sio) psxHu32(0x1070) |= 0x80; - if (Config.SpuIrq) psxHu32(0x1070) |= 0x200; - - memset(psxH, 0, 0x10000); - - mdecInit(); //intialize mdec decoder - cdrReset(); - psxRcntInit(); -} - -u8 psxHwRead8(u32 add) { - unsigned char hard; - - switch (add) { - case 0x1f801040: hard = sioRead8();break; - // case 0x1f801050: hard = serial_read8(); break;//for use of serial port ignore for now - case 0x1f801800: hard = cdrRead0(); break; - case 0x1f801801: hard = cdrRead1(); break; - case 0x1f801802: hard = cdrRead2(); break; - case 0x1f801803: hard = cdrRead3(); break; - default: - hard = psxHu8(add); -#ifdef PSXHW_LOG - PSXHW_LOG("*Unkwnown 8bit read at address %lx\n", add); -#endif - return hard; - } - -#ifdef PSXHW_LOG - PSXHW_LOG("*Known 8bit read at address %lx value %x\n", add, hard); -#endif - return hard; -} - -u16 psxHwRead16(u32 add) { - unsigned short hard; - - switch (add) { -#ifdef PSXHW_LOG - case 0x1f801070: PSXHW_LOG("IREG 16bit read %x\n", psxHu16(0x1070)); - return psxHu16(0x1070); -#endif -#ifdef PSXHW_LOG - case 0x1f801074: PSXHW_LOG("IMASK 16bit read %x\n", psxHu16(0x1074)); - return psxHu16(0x1074); -#endif - - case 0x1f801040: - hard = sioRead8(); - hard|= sioRead8() << 8; -#ifdef PAD_LOG - PAD_LOG("sio read16 %lx; ret = %x\n", add&0xf, hard); -#endif - return hard; - case 0x1f801044: - hard = StatReg; -#ifdef PAD_LOG - PAD_LOG("sio read16 %lx; ret = %x\n", add&0xf, hard); -#endif - return hard; - case 0x1f801048: - hard = ModeReg; -#ifdef PAD_LOG - PAD_LOG("sio read16 %lx; ret = %x\n", add&0xf, hard); -#endif - return hard; - case 0x1f80104a: - hard = CtrlReg; -#ifdef PAD_LOG - PAD_LOG("sio read16 %lx; ret = %x\n", add&0xf, hard); -#endif - return hard; - case 0x1f80104e: - hard = BaudReg; -#ifdef PAD_LOG - PAD_LOG("sio read16 %lx; ret = %x\n", add&0xf, hard); -#endif - return hard; - - //Serial port stuff not support now ;P - // case 0x1f801050: hard = serial_read16(); break; - // case 0x1f801054: hard = serial_status_read(); break; - // case 0x1f80105a: hard = serial_control_read(); break; - // case 0x1f80105e: hard = serial_baud_read(); break; - - case 0x1f801100: - hard = psxRcntRcount(0); -#ifdef PSXHW_LOG - PSXHW_LOG("T0 count read16: %x\n", hard); -#endif - return hard; - case 0x1f801104: - hard = psxCounters[0].mode; -#ifdef PSXHW_LOG - PSXHW_LOG("T0 mode read16: %x\n", hard); -#endif - return hard; - case 0x1f801108: - hard = psxCounters[0].target; -#ifdef PSXHW_LOG - PSXHW_LOG("T0 target read16: %x\n", hard); -#endif - return hard; - case 0x1f801110: - hard = psxRcntRcount(1); -#ifdef PSXHW_LOG - PSXHW_LOG("T1 count read16: %x\n", hard); -#endif - return hard; - case 0x1f801114: - hard = psxCounters[1].mode; -#ifdef PSXHW_LOG - PSXHW_LOG("T1 mode read16: %x\n", hard); -#endif - return hard; - case 0x1f801118: - hard = psxCounters[1].target; -#ifdef PSXHW_LOG - PSXHW_LOG("T1 target read16: %x\n", hard); -#endif - return hard; - case 0x1f801120: - hard = psxRcntRcount(2); -#ifdef PSXHW_LOG - PSXHW_LOG("T2 count read16: %x\n", hard); -#endif - return hard; - case 0x1f801124: - hard = psxCounters[2].mode; -#ifdef PSXHW_LOG - PSXHW_LOG("T2 mode read16: %x\n", hard); -#endif - return hard; - case 0x1f801128: - hard = psxCounters[2].target; -#ifdef PSXHW_LOG - PSXHW_LOG("T2 target read16: %x\n", hard); -#endif - return hard; - - //case 0x1f802030: hard = //int_2000???? - //case 0x1f802040: hard =//dip switches...?? - - default: - if (add>=0x1f801c00 && add<0x1f801e00) { - hard = SPU_readRegister(add); - } else { - hard = psxHu16(add); -#ifdef PSXHW_LOG - PSXHW_LOG("*Unkwnown 16bit read at address %lx\n", add); -#endif - } - return hard; - } - -#ifdef PSXHW_LOG - PSXHW_LOG("*Known 16bit read at address %lx value %x\n", add, hard); -#endif - return hard; -} - -u32 psxHwRead32(u32 add) { - u32 hard; - - switch (add) { - case 0x1f801040: - hard = sioRead8(); - hard|= sioRead8() << 8; - hard|= sioRead8() << 16; - hard|= sioRead8() << 24; -#ifdef PAD_LOG - PAD_LOG("sio read32 ;ret = %lx\n", hard); -#endif - return hard; - - // case 0x1f801050: hard = serial_read32(); break;//serial port -#ifdef PSXHW_LOG - case 0x1f801060: - PSXHW_LOG("RAM size read %lx\n", psxHu32(0x1060)); - return psxHu32(0x1060); -#endif -#ifdef PSXHW_LOG - case 0x1f801070: PSXHW_LOG("IREG 32bit read %x\n", psxHu32(0x1070)); - return psxHu32(0x1070); -#endif -#ifdef PSXHW_LOG - case 0x1f801074: PSXHW_LOG("IMASK 32bit read %x\n", psxHu32(0x1074)); - return psxHu32(0x1074); -#endif - - case 0x1f801810: - hard = GPU_readData(); -#ifdef PSXHW_LOG - PSXHW_LOG("GPU DATA 32bit read %lx\n", hard); -#endif - return hard; - case 0x1f801814: - hard = GPU_readStatus(); -#ifdef PSXHW_LOG - PSXHW_LOG("GPU STATUS 32bit read %lx\n", hard); -#endif - return hard; - - case 0x1f801820: hard = mdecRead0(); break; - case 0x1f801824: hard = mdecRead1(); break; - -#ifdef PSXHW_LOG - case 0x1f8010a0: - PSXHW_LOG("DMA2 MADR 32bit read %lx\n", psxHu32(0x10a0)); - return HW_DMA2_MADR; - case 0x1f8010a4: - PSXHW_LOG("DMA2 BCR 32bit read %lx\n", psxHu32(0x10a4)); - return HW_DMA2_BCR; - case 0x1f8010a8: - PSXHW_LOG("DMA2 CHCR 32bit read %lx\n", psxHu32(0x10a8)); - return HW_DMA2_CHCR; -#endif - -#ifdef PSXHW_LOG - case 0x1f8010b0: - PSXHW_LOG("DMA3 MADR 32bit read %lx\n", psxHu32(0x10b0)); - return HW_DMA3_MADR; - case 0x1f8010b4: - PSXHW_LOG("DMA3 BCR 32bit read %lx\n", psxHu32(0x10b4)); - return HW_DMA3_BCR; - case 0x1f8010b8: - PSXHW_LOG("DMA3 CHCR 32bit read %lx\n", psxHu32(0x10b8)); - return HW_DMA3_CHCR; -#endif - -#ifdef PSXHW_LOG -/* case 0x1f8010f0: - PSXHW_LOG("DMA PCR 32bit read %x\n", psxHu32(0x10f0)); - return HW_DMA_PCR; // dma rest channel - case 0x1f8010f4: - PSXHW_LOG("DMA ICR 32bit read %x\n", psxHu32(0x10f4)); - return HW_DMA_ICR; // interrupt enabler?*/ -#endif - - // time for rootcounters :) - case 0x1f801100: - hard = psxRcntRcount(0); -#ifdef PSXHW_LOG - PSXHW_LOG("T0 count read32: %lx\n", hard); -#endif - return hard; - case 0x1f801104: - hard = psxCounters[0].mode; -#ifdef PSXHW_LOG - PSXHW_LOG("T0 mode read32: %lx\n", hard); -#endif - return hard; - case 0x1f801108: - hard = psxCounters[0].target; -#ifdef PSXHW_LOG - PSXHW_LOG("T0 target read32: %lx\n", hard); -#endif - return hard; - case 0x1f801110: - hard = psxRcntRcount(1); -#ifdef PSXHW_LOG - PSXHW_LOG("T1 count read32: %lx\n", hard); -#endif - return hard; - case 0x1f801114: - hard = psxCounters[1].mode; -#ifdef PSXHW_LOG - PSXHW_LOG("T1 mode read32: %lx\n", hard); -#endif - return hard; - case 0x1f801118: - hard = psxCounters[1].target; -#ifdef PSXHW_LOG - PSXHW_LOG("T1 target read32: %lx\n", hard); -#endif - return hard; - case 0x1f801120: - hard = psxRcntRcount(2); -#ifdef PSXHW_LOG - PSXHW_LOG("T2 count read32: %lx\n", hard); -#endif - return hard; - case 0x1f801124: - hard = psxCounters[2].mode; -#ifdef PSXHW_LOG - PSXHW_LOG("T2 mode read32: %lx\n", hard); -#endif - return hard; - case 0x1f801128: - hard = psxCounters[2].target; -#ifdef PSXHW_LOG - PSXHW_LOG("T2 target read32: %lx\n", hard); -#endif - return hard; - - default: - hard = psxHu32(add); -#ifdef PSXHW_LOG - PSXHW_LOG("*Unkwnown 32bit read at address %lx\n", add); -#endif - return hard; - } -#ifdef PSXHW_LOG - PSXHW_LOG("*Known 32bit read at address %lx\n", add); -#endif - return hard; -} - -void psxHwWrite8(u32 add, u8 value) { - switch (add) { - case 0x1f801040: sioWrite8(value); break; - // case 0x1f801050: serial_write8(value); break;//serial port - case 0x1f801800: cdrWrite0(value); break; - case 0x1f801801: cdrWrite1(value); break; - case 0x1f801802: cdrWrite2(value); break; - case 0x1f801803: cdrWrite3(value); break; - - default: - psxHu8(add) = value; -#ifdef PSXHW_LOG - PSXHW_LOG("*Unknown 8bit write at address %lx value %x\n", add, value); -#endif - return; - } - psxHu8(add) = value; -#ifdef PSXHW_LOG - PSXHW_LOG("*Known 8bit write at address %lx value %x\n", add, value); -#endif -} - -void psxHwWrite16(u32 add, u16 value) { - switch (add) { - case 0x1f801040: - sioWrite8((unsigned char)value); - sioWrite8((unsigned char)(value>>8)); -#ifdef PAD_LOG - PAD_LOG ("sio write16 %lx, %x\n", add&0xf, value); -#endif - return; - case 0x1f801044: -#ifdef PAD_LOG - PAD_LOG ("sio write16 %lx, %x\n", add&0xf, value); -#endif - return; - case 0x1f801048: - ModeReg = value; -#ifdef PAD_LOG - PAD_LOG ("sio write16 %lx, %x\n", add&0xf, value); -#endif - return; - case 0x1f80104a: // control register - sioWriteCtrl16(value); -#ifdef PAD_LOG - PAD_LOG ("sio write16 %lx, %x\n", add&0xf, value); -#endif - return; - case 0x1f80104e: // baudrate register - BaudReg = value; -#ifdef PAD_LOG - PAD_LOG ("sio write16 %lx, %x\n", add&0xf, value); -#endif - return; - - //serial port ;P - // case 0x1f801050: serial_write16(value); break; - // case 0x1f80105a: serial_control_write(value);break; - // case 0x1f80105e: serial_baud_write(value); break; - // case 0x1f801054: serial_status_write(value); break; - - case 0x1f801070: -#ifdef PSXHW_LOG - PSXHW_LOG("IREG 16bit write %x\n", value); -#endif - if (Config.Sio) psxHu16(0x1070) |= 0x80; - if (Config.SpuIrq) psxHu16(0x1070) |= 0x200; - psxHu16(0x1070) &= (psxHu16(0x1074) & value); - return; -#ifdef PSXHW_LOG - case 0x1f801074: PSXHW_LOG("IMASK 16bit write %x\n", value); - psxHu16(0x1074) = value; - return; -#endif - - case 0x1f801100: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 0 COUNT 16bit write %x\n", value); -#endif - psxRcntWcount(0, value); return; - case 0x1f801104: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 0 MODE 16bit write %x\n", value); -#endif - psxRcntWmode(0, value); return; - case 0x1f801108: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 0 TARGET 16bit write %x\n", value); -#endif - psxRcntWtarget(0, value); return; - - case 0x1f801110: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 1 COUNT 16bit write %x\n", value); -#endif - psxRcntWcount(1, value); return; - case 0x1f801114: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 1 MODE 16bit write %x\n", value); -#endif - psxRcntWmode(1, value); return; - case 0x1f801118: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 1 TARGET 16bit write %x\n", value); -#endif - psxRcntWtarget(1, value); return; - - case 0x1f801120: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 2 COUNT 16bit write %x\n", value); -#endif - psxRcntWcount(2, value); return; - case 0x1f801124: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 2 MODE 16bit write %x\n", value); -#endif - psxRcntWmode(2, value); return; - case 0x1f801128: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 2 TARGET 16bit write %x\n", value); -#endif - psxRcntWtarget(2, value); return; - - default: - if (add>=0x1f801c00 && add<0x1f801e00) { - SPU_writeRegister(add, value); - return; - } - - psxHu16(add) = value; -#ifdef PSXHW_LOG - PSXHW_LOG("*Unknown 16bit write at address %lx value %x\n", add, value); -#endif - return; - } - psxHu16(add) = value; -#ifdef PSXHW_LOG - PSXHW_LOG("*Known 16bit write at address %lx value %x\n", add, value); -#endif -} - -#define DMA_INTERRUPT(n) \ - if (HW_DMA_ICR & (1 << (16 + n))) { \ - HW_DMA_ICR|= (1 << (24 + n)); \ - psxHu32(0x1070) |= 8; \ - } - -#define DmaExec(n) { \ - if (HW_DMA##n##_CHCR & 0x01000000 && HW_DMA_PCR & (8 << (n * 4))) { \ - psxDma##n##(HW_DMA##n##_MADR, HW_DMA##n##_BCR, HW_DMA##n##_CHCR); \ - HW_DMA##n##_CHCR &= ~0x01000000; \ - DMA_INTERRUPT(n); \ - } \ -} - -void psxHwWrite32(u32 add, u32 value) { - switch (add) { - case 0x1f801040: - sioWrite8((unsigned char)value); - sioWrite8((unsigned char)((value&0xff) >> 8)); - sioWrite8((unsigned char)((value&0xff) >> 16)); - sioWrite8((unsigned char)((value&0xff) >> 24)); -#ifdef PAD_LOG - PAD_LOG("sio write32 %lx\n", value); -#endif - return; - // case 0x1f801050: serial_write32(value); break;//serial port -#ifdef PSXHW_LOG - case 0x1f801060: - PSXHW_LOG("RAM size write %lx\n", value); - psxHu32(add) = value; - return; // Ram size -#endif - - case 0x1f801070: -#ifdef PSXHW_LOG - PSXHW_LOG("IREG 32bit write %lx\n", value); -#endif - if (Config.Sio) psxHu32(0x1070) |= 0x80; - if (Config.SpuIrq) psxHu32(0x1070) |= 0x200; - psxHu32(0x1070) &= (psxHu32(0x1074) & value); - return; -#ifdef PSXHW_LOG - case 0x1f801074: - PSXHW_LOG("IMASK 32bit write %lx\n", value); - psxHu32(0x1074) = value; - return; -#endif - -#ifdef PSXHW_LOG - case 0x1f801080: - PSXHW_LOG("DMA0 MADR 32bit write %lx\n", value); - HW_DMA0_MADR = value; return; // DMA0 madr - case 0x1f801084: - PSXHW_LOG("DMA0 BCR 32bit write %lx\n", value); - HW_DMA0_BCR = value; return; // DMA0 bcr -#endif - case 0x1f801088: -#ifdef PSXHW_LOG - PSXHW_LOG("DMA0 CHCR 32bit write %lx\n", value); -#endif - HW_DMA0_CHCR = value; // DMA0 chcr (MDEC in DMA) - DmaExec(0); - return; - -#ifdef PSXHW_LOG - case 0x1f801090: - PSXHW_LOG("DMA1 MADR 32bit write %lx\n", value); - HW_DMA1_MADR = value; return; // DMA1 madr - case 0x1f801094: - PSXHW_LOG("DMA1 BCR 32bit write %lx\n", value); - HW_DMA1_BCR = value; return; // DMA1 bcr -#endif - case 0x1f801098: -#ifdef PSXHW_LOG - PSXHW_LOG("DMA1 CHCR 32bit write %lx\n", value); -#endif - HW_DMA1_CHCR = value; // DMA1 chcr (MDEC out DMA) - DmaExec(1); - return; - -#ifdef PSXHW_LOG - case 0x1f8010a0: - PSXHW_LOG("DMA2 MADR 32bit write %lx\n", value); - HW_DMA2_MADR = value; return; // DMA2 madr - case 0x1f8010a4: - PSXHW_LOG("DMA2 BCR 32bit write %lx\n", value); - HW_DMA2_BCR = value; return; // DMA2 bcr -#endif - case 0x1f8010a8: -#ifdef PSXHW_LOG - PSXHW_LOG("DMA2 CHCR 32bit write %lx\n", value); -#endif - HW_DMA2_CHCR = value; // DMA2 chcr (GPU DMA) - DmaExec(2); - return; - -#ifdef PSXHW_LOG - case 0x1f8010b0: - PSXHW_LOG("DMA3 MADR 32bit write %lx\n", value); - HW_DMA3_MADR = value; return; // DMA3 madr - case 0x1f8010b4: - PSXHW_LOG("DMA3 BCR 32bit write %lx\n", value); - HW_DMA3_BCR = value; return; // DMA3 bcr -#endif - case 0x1f8010b8: -#ifdef PSXHW_LOG - PSXHW_LOG("DMA3 CHCR 32bit write %lx\n", value); -#endif - HW_DMA3_CHCR = value; // DMA3 chcr (CDROM DMA) - DmaExec(3); - - return; - -#ifdef PSXHW_LOG - case 0x1f8010c0: - PSXHW_LOG("DMA4 MADR 32bit write %lx\n", value); - HW_DMA4_MADR = value; return; // DMA4 madr - case 0x1f8010c4: - PSXHW_LOG("DMA4 BCR 32bit write %lx\n", value); - HW_DMA4_BCR = value; return; // DMA4 bcr -#endif - case 0x1f8010c8: -#ifdef PSXHW_LOG - PSXHW_LOG("DMA4 CHCR 32bit write %lx\n", value); -#endif - HW_DMA4_CHCR = value; // DMA4 chcr (SPU DMA) - DmaExec(4); - return; - -#if 0 - case 0x1f8010d0: break; //DMA5write_madr(); - case 0x1f8010d4: break; //DMA5write_bcr(); - case 0x1f8010d8: break; //DMA5write_chcr(); // Not yet needed?? -#endif - -#ifdef PSXHW_LOG - case 0x1f8010e0: - PSXHW_LOG("DMA6 MADR 32bit write %lx\n", value); - HW_DMA6_MADR = value; return; // DMA6 bcr - case 0x1f8010e4: - PSXHW_LOG("DMA6 BCR 32bit write %lx\n", value); - HW_DMA6_BCR = value; return; // DMA6 bcr -#endif - case 0x1f8010e8: -#ifdef PSXHW_LOG - PSXHW_LOG("DMA6 CHCR 32bit write %lx\n", value); -#endif - HW_DMA6_CHCR = value; // DMA6 chcr (OT clear) - DmaExec(6); - return; - -#ifdef PSXHW_LOG - case 0x1f8010f0: - PSXHW_LOG("DMA PCR 32bit write %lx\n", value); - HW_DMA_PCR = value; - return; -#endif - - case 0x1f8010f4: -#ifdef PSXHW_LOG - PSXHW_LOG("DMA ICR 32bit write %lx\n", value); -#endif - { - u32 tmp = (~value) & HW_DMA_ICR; - HW_DMA_ICR = ((tmp ^ value) & 0xffffff) ^ tmp; - return; - } - - case 0x1f801810: -#ifdef PSXHW_LOG - PSXHW_LOG("GPU DATA 32bit write %lx\n", value); -#endif - GPU_writeData(value); return; - case 0x1f801814: -#ifdef PSXHW_LOG - PSXHW_LOG("GPU STATUS 32bit write %lx\n", value); -#endif - GPU_writeStatus(value); return; - - case 0x1f801820: - mdecWrite0(value); break; - case 0x1f801824: - mdecWrite1(value); break; - - case 0x1f801100: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 0 COUNT 32bit write %lx\n", value); -#endif - psxRcntWcount(0, value & 0xffff); return; - case 0x1f801104: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 0 MODE 32bit write %lx\n", value); -#endif - psxRcntWmode(0, value); return; - case 0x1f801108: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 0 TARGET 32bit write %lx\n", value); -#endif - psxRcntWtarget(0, value & 0xffff); return; // HW_DMA_ICR&= (~value)&0xff000000; - - case 0x1f801110: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 1 COUNT 32bit write %lx\n", value); -#endif - psxRcntWcount(1, value & 0xffff); return; - case 0x1f801114: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 1 MODE 32bit write %lx\n", value); -#endif - psxRcntWmode(1, value); return; - case 0x1f801118: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 1 TARGET 32bit write %lx\n", value); -#endif - psxRcntWtarget(1, value & 0xffff); return; - - case 0x1f801120: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 2 COUNT 32bit write %lx\n", value); -#endif - psxRcntWcount(2, value & 0xffff); return; - case 0x1f801124: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 2 MODE 32bit write %lx\n", value); -#endif - psxRcntWmode(2, value); return; - case 0x1f801128: -#ifdef PSXHW_LOG - PSXHW_LOG("COUNTER 2 TARGET 32bit write %lx\n", value); -#endif - psxRcntWtarget(2, value & 0xffff); return; - - default: - psxHu32(add) = value; -#ifdef PSXHW_LOG - PSXHW_LOG("*Unknown 32bit write at address %lx value %lx\n", add, value); -#endif - return; - } - psxHu32(add) = value; -#ifdef PSXHW_LOG - PSXHW_LOG("*Known 32bit write at address %lx value %lx\n", add, value); -#endif -} - -int psxHwFreeze(gzFile f, int Mode) { - char Unused[4096]; - - gzfreezel(Unused); - - return 0; -} +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include + +#include "PsxCommon.h" + +#ifdef __WIN32__ +#pragma warning(disable:4244) +#endif + +#define HW_DMA0_MADR (psxHu32(0x1080)) // MDEC in DMA +#define HW_DMA0_BCR (psxHu32(0x1084)) +#define HW_DMA0_CHCR (psxHu32(0x1088)) + +#define HW_DMA1_MADR (psxHu32(0x1090)) // MDEC out DMA +#define HW_DMA1_BCR (psxHu32(0x1094)) +#define HW_DMA1_CHCR (psxHu32(0x1098)) + +#define HW_DMA2_MADR (psxHu32(0x10a0)) // GPU DMA +#define HW_DMA2_BCR (psxHu32(0x10a4)) +#define HW_DMA2_CHCR (psxHu32(0x10a8)) + +#define HW_DMA3_MADR (psxHu32(0x10b0)) // CDROM DMA +#define HW_DMA3_BCR (psxHu32(0x10b4)) +#define HW_DMA3_CHCR (psxHu32(0x10b8)) + +#define HW_DMA4_MADR (psxHu32(0x10c0)) // SPU DMA +#define HW_DMA4_BCR (psxHu32(0x10c4)) +#define HW_DMA4_CHCR (psxHu32(0x10c8)) + +#define HW_DMA6_MADR (psxHu32(0x10e0)) // GPU DMA (OT) +#define HW_DMA6_BCR (psxHu32(0x10e4)) +#define HW_DMA6_CHCR (psxHu32(0x10e8)) + +#define HW_DMA_PCR (psxHu32(0x10f0)) +#define HW_DMA_ICR (psxHu32(0x10f4)) + +void psxHwReset() { + if (Config.Sio) psxHu32(0x1070) |= 0x80; + if (Config.SpuIrq) psxHu32(0x1070) |= 0x200; + + memset(psxH, 0, 0x10000); + + mdecInit(); //intialize mdec decoder + cdrReset(); + psxRcntInit(); +} + +u8 psxHwRead8(u32 add) { + unsigned char hard; + + switch (add) { + case 0x1f801040: hard = sioRead8();break; + // case 0x1f801050: hard = serial_read8(); break;//for use of serial port ignore for now + case 0x1f801800: hard = cdrRead0(); break; + case 0x1f801801: hard = cdrRead1(); break; + case 0x1f801802: hard = cdrRead2(); break; + case 0x1f801803: hard = cdrRead3(); break; + default: + hard = psxHu8(add); +#ifdef PSXHW_LOG + PSXHW_LOG("*Unkwnown 8bit read at address %lx\n", add); +#endif + return hard; + } + +#ifdef PSXHW_LOG + PSXHW_LOG("*Known 8bit read at address %lx value %x\n", add, hard); +#endif + return hard; +} + +u16 psxHwRead16(u32 add) { + unsigned short hard; + + switch (add) { +#ifdef PSXHW_LOG + case 0x1f801070: PSXHW_LOG("IREG 16bit read %x\n", psxHu16(0x1070)); + return psxHu16(0x1070); +#endif +#ifdef PSXHW_LOG + case 0x1f801074: PSXHW_LOG("IMASK 16bit read %x\n", psxHu16(0x1074)); + return psxHu16(0x1074); +#endif + + case 0x1f801040: + hard = sioRead8(); + hard|= sioRead8() << 8; +#ifdef PAD_LOG + PAD_LOG("sio read16 %lx; ret = %x\n", add&0xf, hard); +#endif + return hard; + case 0x1f801044: + hard = StatReg; +#ifdef PAD_LOG + PAD_LOG("sio read16 %lx; ret = %x\n", add&0xf, hard); +#endif + return hard; + case 0x1f801048: + hard = ModeReg; +#ifdef PAD_LOG + PAD_LOG("sio read16 %lx; ret = %x\n", add&0xf, hard); +#endif + return hard; + case 0x1f80104a: + hard = CtrlReg; +#ifdef PAD_LOG + PAD_LOG("sio read16 %lx; ret = %x\n", add&0xf, hard); +#endif + return hard; + case 0x1f80104e: + hard = BaudReg; +#ifdef PAD_LOG + PAD_LOG("sio read16 %lx; ret = %x\n", add&0xf, hard); +#endif + return hard; + + //Serial port stuff not support now ;P + // case 0x1f801050: hard = serial_read16(); break; + // case 0x1f801054: hard = serial_status_read(); break; + // case 0x1f80105a: hard = serial_control_read(); break; + // case 0x1f80105e: hard = serial_baud_read(); break; + + case 0x1f801100: + hard = psxRcntRcount(0); +#ifdef PSXHW_LOG + PSXHW_LOG("T0 count read16: %x\n", hard); +#endif + return hard; + case 0x1f801104: + hard = psxCounters[0].mode; +#ifdef PSXHW_LOG + PSXHW_LOG("T0 mode read16: %x\n", hard); +#endif + return hard; + case 0x1f801108: + hard = psxCounters[0].target; +#ifdef PSXHW_LOG + PSXHW_LOG("T0 target read16: %x\n", hard); +#endif + return hard; + case 0x1f801110: + hard = psxRcntRcount(1); +#ifdef PSXHW_LOG + PSXHW_LOG("T1 count read16: %x\n", hard); +#endif + return hard; + case 0x1f801114: + hard = psxCounters[1].mode; +#ifdef PSXHW_LOG + PSXHW_LOG("T1 mode read16: %x\n", hard); +#endif + return hard; + case 0x1f801118: + hard = psxCounters[1].target; +#ifdef PSXHW_LOG + PSXHW_LOG("T1 target read16: %x\n", hard); +#endif + return hard; + case 0x1f801120: + hard = psxRcntRcount(2); +#ifdef PSXHW_LOG + PSXHW_LOG("T2 count read16: %x\n", hard); +#endif + return hard; + case 0x1f801124: + hard = psxCounters[2].mode; +#ifdef PSXHW_LOG + PSXHW_LOG("T2 mode read16: %x\n", hard); +#endif + return hard; + case 0x1f801128: + hard = psxCounters[2].target; +#ifdef PSXHW_LOG + PSXHW_LOG("T2 target read16: %x\n", hard); +#endif + return hard; + + //case 0x1f802030: hard = //int_2000???? + //case 0x1f802040: hard =//dip switches...?? + + default: + if (add>=0x1f801c00 && add<0x1f801e00) { + hard = SPU_readRegister(add); + } else { + hard = psxHu16(add); +#ifdef PSXHW_LOG + PSXHW_LOG("*Unkwnown 16bit read at address %lx\n", add); +#endif + } + return hard; + } + +#ifdef PSXHW_LOG + PSXHW_LOG("*Known 16bit read at address %lx value %x\n", add, hard); +#endif + return hard; +} + +u32 psxHwRead32(u32 add) { + u32 hard; + + switch (add) { + case 0x1f801040: + hard = sioRead8(); + hard|= sioRead8() << 8; + hard|= sioRead8() << 16; + hard|= sioRead8() << 24; +#ifdef PAD_LOG + PAD_LOG("sio read32 ;ret = %lx\n", hard); +#endif + return hard; + + // case 0x1f801050: hard = serial_read32(); break;//serial port +#ifdef PSXHW_LOG + case 0x1f801060: + PSXHW_LOG("RAM size read %lx\n", psxHu32(0x1060)); + return psxHu32(0x1060); +#endif +#ifdef PSXHW_LOG + case 0x1f801070: PSXHW_LOG("IREG 32bit read %x\n", psxHu32(0x1070)); + return psxHu32(0x1070); +#endif +#ifdef PSXHW_LOG + case 0x1f801074: PSXHW_LOG("IMASK 32bit read %x\n", psxHu32(0x1074)); + return psxHu32(0x1074); +#endif + + case 0x1f801810: + hard = GPU_readData(); +#ifdef PSXHW_LOG + PSXHW_LOG("GPU DATA 32bit read %lx\n", hard); +#endif + return hard; + case 0x1f801814: + hard = GPU_readStatus(); +#ifdef PSXHW_LOG + PSXHW_LOG("GPU STATUS 32bit read %lx\n", hard); +#endif + return hard; + + case 0x1f801820: hard = mdecRead0(); break; + case 0x1f801824: hard = mdecRead1(); break; + +#ifdef PSXHW_LOG + case 0x1f8010a0: + PSXHW_LOG("DMA2 MADR 32bit read %lx\n", psxHu32(0x10a0)); + return HW_DMA2_MADR; + case 0x1f8010a4: + PSXHW_LOG("DMA2 BCR 32bit read %lx\n", psxHu32(0x10a4)); + return HW_DMA2_BCR; + case 0x1f8010a8: + PSXHW_LOG("DMA2 CHCR 32bit read %lx\n", psxHu32(0x10a8)); + return HW_DMA2_CHCR; +#endif + +#ifdef PSXHW_LOG + case 0x1f8010b0: + PSXHW_LOG("DMA3 MADR 32bit read %lx\n", psxHu32(0x10b0)); + return HW_DMA3_MADR; + case 0x1f8010b4: + PSXHW_LOG("DMA3 BCR 32bit read %lx\n", psxHu32(0x10b4)); + return HW_DMA3_BCR; + case 0x1f8010b8: + PSXHW_LOG("DMA3 CHCR 32bit read %lx\n", psxHu32(0x10b8)); + return HW_DMA3_CHCR; +#endif + +#ifdef PSXHW_LOG +/* case 0x1f8010f0: + PSXHW_LOG("DMA PCR 32bit read %x\n", psxHu32(0x10f0)); + return HW_DMA_PCR; // dma rest channel + case 0x1f8010f4: + PSXHW_LOG("DMA ICR 32bit read %x\n", psxHu32(0x10f4)); + return HW_DMA_ICR; // interrupt enabler?*/ +#endif + + // time for rootcounters :) + case 0x1f801100: + hard = psxRcntRcount(0); +#ifdef PSXHW_LOG + PSXHW_LOG("T0 count read32: %lx\n", hard); +#endif + return hard; + case 0x1f801104: + hard = psxCounters[0].mode; +#ifdef PSXHW_LOG + PSXHW_LOG("T0 mode read32: %lx\n", hard); +#endif + return hard; + case 0x1f801108: + hard = psxCounters[0].target; +#ifdef PSXHW_LOG + PSXHW_LOG("T0 target read32: %lx\n", hard); +#endif + return hard; + case 0x1f801110: + hard = psxRcntRcount(1); +#ifdef PSXHW_LOG + PSXHW_LOG("T1 count read32: %lx\n", hard); +#endif + return hard; + case 0x1f801114: + hard = psxCounters[1].mode; +#ifdef PSXHW_LOG + PSXHW_LOG("T1 mode read32: %lx\n", hard); +#endif + return hard; + case 0x1f801118: + hard = psxCounters[1].target; +#ifdef PSXHW_LOG + PSXHW_LOG("T1 target read32: %lx\n", hard); +#endif + return hard; + case 0x1f801120: + hard = psxRcntRcount(2); +#ifdef PSXHW_LOG + PSXHW_LOG("T2 count read32: %lx\n", hard); +#endif + return hard; + case 0x1f801124: + hard = psxCounters[2].mode; +#ifdef PSXHW_LOG + PSXHW_LOG("T2 mode read32: %lx\n", hard); +#endif + return hard; + case 0x1f801128: + hard = psxCounters[2].target; +#ifdef PSXHW_LOG + PSXHW_LOG("T2 target read32: %lx\n", hard); +#endif + return hard; + + default: + hard = psxHu32(add); +#ifdef PSXHW_LOG + PSXHW_LOG("*Unkwnown 32bit read at address %lx\n", add); +#endif + return hard; + } +#ifdef PSXHW_LOG + PSXHW_LOG("*Known 32bit read at address %lx\n", add); +#endif + return hard; +} + +void psxHwWrite8(u32 add, u8 value) { + switch (add) { + case 0x1f801040: sioWrite8(value); break; + // case 0x1f801050: serial_write8(value); break;//serial port + case 0x1f801800: cdrWrite0(value); break; + case 0x1f801801: cdrWrite1(value); break; + case 0x1f801802: cdrWrite2(value); break; + case 0x1f801803: cdrWrite3(value); break; + + default: + psxHu8(add) = value; +#ifdef PSXHW_LOG + PSXHW_LOG("*Unknown 8bit write at address %lx value %x\n", add, value); +#endif + return; + } + psxHu8(add) = value; +#ifdef PSXHW_LOG + PSXHW_LOG("*Known 8bit write at address %lx value %x\n", add, value); +#endif +} + +void psxHwWrite16(u32 add, u16 value) { + switch (add) { + case 0x1f801040: + sioWrite8((unsigned char)value); + sioWrite8((unsigned char)(value>>8)); +#ifdef PAD_LOG + PAD_LOG ("sio write16 %lx, %x\n", add&0xf, value); +#endif + return; + case 0x1f801044: +#ifdef PAD_LOG + PAD_LOG ("sio write16 %lx, %x\n", add&0xf, value); +#endif + return; + case 0x1f801048: + ModeReg = value; +#ifdef PAD_LOG + PAD_LOG ("sio write16 %lx, %x\n", add&0xf, value); +#endif + return; + case 0x1f80104a: // control register + sioWriteCtrl16(value); +#ifdef PAD_LOG + PAD_LOG ("sio write16 %lx, %x\n", add&0xf, value); +#endif + return; + case 0x1f80104e: // baudrate register + BaudReg = value; +#ifdef PAD_LOG + PAD_LOG ("sio write16 %lx, %x\n", add&0xf, value); +#endif + return; + + //serial port ;P + // case 0x1f801050: serial_write16(value); break; + // case 0x1f80105a: serial_control_write(value);break; + // case 0x1f80105e: serial_baud_write(value); break; + // case 0x1f801054: serial_status_write(value); break; + + case 0x1f801070: +#ifdef PSXHW_LOG + PSXHW_LOG("IREG 16bit write %x\n", value); +#endif + if (Config.Sio) psxHu16(0x1070) |= 0x80; + if (Config.SpuIrq) psxHu16(0x1070) |= 0x200; + psxHu16(0x1070) &= (psxHu16(0x1074) & value); + return; +#ifdef PSXHW_LOG + case 0x1f801074: PSXHW_LOG("IMASK 16bit write %x\n", value); + psxHu16(0x1074) = value; + return; +#endif + + case 0x1f801100: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 0 COUNT 16bit write %x\n", value); +#endif + psxRcntWcount(0, value); return; + case 0x1f801104: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 0 MODE 16bit write %x\n", value); +#endif + psxRcntWmode(0, value); return; + case 0x1f801108: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 0 TARGET 16bit write %x\n", value); +#endif + psxRcntWtarget(0, value); return; + + case 0x1f801110: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 1 COUNT 16bit write %x\n", value); +#endif + psxRcntWcount(1, value); return; + case 0x1f801114: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 1 MODE 16bit write %x\n", value); +#endif + psxRcntWmode(1, value); return; + case 0x1f801118: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 1 TARGET 16bit write %x\n", value); +#endif + psxRcntWtarget(1, value); return; + + case 0x1f801120: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 2 COUNT 16bit write %x\n", value); +#endif + psxRcntWcount(2, value); return; + case 0x1f801124: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 2 MODE 16bit write %x\n", value); +#endif + psxRcntWmode(2, value); return; + case 0x1f801128: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 2 TARGET 16bit write %x\n", value); +#endif + psxRcntWtarget(2, value); return; + + default: + if (add>=0x1f801c00 && add<0x1f801e00) { + SPU_writeRegister(add, value); + return; + } + + psxHu16(add) = value; +#ifdef PSXHW_LOG + PSXHW_LOG("*Unknown 16bit write at address %lx value %x\n", add, value); +#endif + return; + } + psxHu16(add) = value; +#ifdef PSXHW_LOG + PSXHW_LOG("*Known 16bit write at address %lx value %x\n", add, value); +#endif +} + +#define DMA_INTERRUPT(n) \ + if (HW_DMA_ICR & (1 << (16 + n))) { \ + HW_DMA_ICR|= (1 << (24 + n)); \ + psxHu32(0x1070) |= 8; \ + } + +#define DmaExec(n) { \ + if (HW_DMA##n##_CHCR & 0x01000000 && HW_DMA_PCR & (8 << (n * 4))) { \ + psxDma##n##(HW_DMA##n##_MADR, HW_DMA##n##_BCR, HW_DMA##n##_CHCR); \ + HW_DMA##n##_CHCR &= ~0x01000000; \ + DMA_INTERRUPT(n); \ + } \ +} + +void psxHwWrite32(u32 add, u32 value) { + switch (add) { + case 0x1f801040: + sioWrite8((unsigned char)value); + sioWrite8((unsigned char)((value&0xff) >> 8)); + sioWrite8((unsigned char)((value&0xff) >> 16)); + sioWrite8((unsigned char)((value&0xff) >> 24)); +#ifdef PAD_LOG + PAD_LOG("sio write32 %lx\n", value); +#endif + return; + // case 0x1f801050: serial_write32(value); break;//serial port +#ifdef PSXHW_LOG + case 0x1f801060: + PSXHW_LOG("RAM size write %lx\n", value); + psxHu32(add) = value; + return; // Ram size +#endif + + case 0x1f801070: +#ifdef PSXHW_LOG + PSXHW_LOG("IREG 32bit write %lx\n", value); +#endif + if (Config.Sio) psxHu32(0x1070) |= 0x80; + if (Config.SpuIrq) psxHu32(0x1070) |= 0x200; + psxHu32(0x1070) &= (psxHu32(0x1074) & value); + return; +#ifdef PSXHW_LOG + case 0x1f801074: + PSXHW_LOG("IMASK 32bit write %lx\n", value); + psxHu32(0x1074) = value; + return; +#endif + +#ifdef PSXHW_LOG + case 0x1f801080: + PSXHW_LOG("DMA0 MADR 32bit write %lx\n", value); + HW_DMA0_MADR = value; return; // DMA0 madr + case 0x1f801084: + PSXHW_LOG("DMA0 BCR 32bit write %lx\n", value); + HW_DMA0_BCR = value; return; // DMA0 bcr +#endif + case 0x1f801088: +#ifdef PSXHW_LOG + PSXHW_LOG("DMA0 CHCR 32bit write %lx\n", value); +#endif + HW_DMA0_CHCR = value; // DMA0 chcr (MDEC in DMA) + DmaExec(0); + return; + +#ifdef PSXHW_LOG + case 0x1f801090: + PSXHW_LOG("DMA1 MADR 32bit write %lx\n", value); + HW_DMA1_MADR = value; return; // DMA1 madr + case 0x1f801094: + PSXHW_LOG("DMA1 BCR 32bit write %lx\n", value); + HW_DMA1_BCR = value; return; // DMA1 bcr +#endif + case 0x1f801098: +#ifdef PSXHW_LOG + PSXHW_LOG("DMA1 CHCR 32bit write %lx\n", value); +#endif + HW_DMA1_CHCR = value; // DMA1 chcr (MDEC out DMA) + DmaExec(1); + return; + +#ifdef PSXHW_LOG + case 0x1f8010a0: + PSXHW_LOG("DMA2 MADR 32bit write %lx\n", value); + HW_DMA2_MADR = value; return; // DMA2 madr + case 0x1f8010a4: + PSXHW_LOG("DMA2 BCR 32bit write %lx\n", value); + HW_DMA2_BCR = value; return; // DMA2 bcr +#endif + case 0x1f8010a8: +#ifdef PSXHW_LOG + PSXHW_LOG("DMA2 CHCR 32bit write %lx\n", value); +#endif + HW_DMA2_CHCR = value; // DMA2 chcr (GPU DMA) + DmaExec(2); + return; + +#ifdef PSXHW_LOG + case 0x1f8010b0: + PSXHW_LOG("DMA3 MADR 32bit write %lx\n", value); + HW_DMA3_MADR = value; return; // DMA3 madr + case 0x1f8010b4: + PSXHW_LOG("DMA3 BCR 32bit write %lx\n", value); + HW_DMA3_BCR = value; return; // DMA3 bcr +#endif + case 0x1f8010b8: +#ifdef PSXHW_LOG + PSXHW_LOG("DMA3 CHCR 32bit write %lx\n", value); +#endif + HW_DMA3_CHCR = value; // DMA3 chcr (CDROM DMA) + DmaExec(3); + + return; + +#ifdef PSXHW_LOG + case 0x1f8010c0: + PSXHW_LOG("DMA4 MADR 32bit write %lx\n", value); + HW_DMA4_MADR = value; return; // DMA4 madr + case 0x1f8010c4: + PSXHW_LOG("DMA4 BCR 32bit write %lx\n", value); + HW_DMA4_BCR = value; return; // DMA4 bcr +#endif + case 0x1f8010c8: +#ifdef PSXHW_LOG + PSXHW_LOG("DMA4 CHCR 32bit write %lx\n", value); +#endif + HW_DMA4_CHCR = value; // DMA4 chcr (SPU DMA) + DmaExec(4); + return; + +#if 0 + case 0x1f8010d0: break; //DMA5write_madr(); + case 0x1f8010d4: break; //DMA5write_bcr(); + case 0x1f8010d8: break; //DMA5write_chcr(); // Not yet needed?? +#endif + +#ifdef PSXHW_LOG + case 0x1f8010e0: + PSXHW_LOG("DMA6 MADR 32bit write %lx\n", value); + HW_DMA6_MADR = value; return; // DMA6 bcr + case 0x1f8010e4: + PSXHW_LOG("DMA6 BCR 32bit write %lx\n", value); + HW_DMA6_BCR = value; return; // DMA6 bcr +#endif + case 0x1f8010e8: +#ifdef PSXHW_LOG + PSXHW_LOG("DMA6 CHCR 32bit write %lx\n", value); +#endif + HW_DMA6_CHCR = value; // DMA6 chcr (OT clear) + DmaExec(6); + return; + +#ifdef PSXHW_LOG + case 0x1f8010f0: + PSXHW_LOG("DMA PCR 32bit write %lx\n", value); + HW_DMA_PCR = value; + return; +#endif + + case 0x1f8010f4: +#ifdef PSXHW_LOG + PSXHW_LOG("DMA ICR 32bit write %lx\n", value); +#endif + { + u32 tmp = (~value) & HW_DMA_ICR; + HW_DMA_ICR = ((tmp ^ value) & 0xffffff) ^ tmp; + return; + } + + case 0x1f801810: +#ifdef PSXHW_LOG + PSXHW_LOG("GPU DATA 32bit write %lx\n", value); +#endif + GPU_writeData(value); return; + case 0x1f801814: +#ifdef PSXHW_LOG + PSXHW_LOG("GPU STATUS 32bit write %lx\n", value); +#endif + GPU_writeStatus(value); return; + + case 0x1f801820: + mdecWrite0(value); break; + case 0x1f801824: + mdecWrite1(value); break; + + case 0x1f801100: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 0 COUNT 32bit write %lx\n", value); +#endif + psxRcntWcount(0, value & 0xffff); return; + case 0x1f801104: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 0 MODE 32bit write %lx\n", value); +#endif + psxRcntWmode(0, value); return; + case 0x1f801108: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 0 TARGET 32bit write %lx\n", value); +#endif + psxRcntWtarget(0, value & 0xffff); return; // HW_DMA_ICR&= (~value)&0xff000000; + + case 0x1f801110: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 1 COUNT 32bit write %lx\n", value); +#endif + psxRcntWcount(1, value & 0xffff); return; + case 0x1f801114: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 1 MODE 32bit write %lx\n", value); +#endif + psxRcntWmode(1, value); return; + case 0x1f801118: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 1 TARGET 32bit write %lx\n", value); +#endif + psxRcntWtarget(1, value & 0xffff); return; + + case 0x1f801120: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 2 COUNT 32bit write %lx\n", value); +#endif + psxRcntWcount(2, value & 0xffff); return; + case 0x1f801124: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 2 MODE 32bit write %lx\n", value); +#endif + psxRcntWmode(2, value); return; + case 0x1f801128: +#ifdef PSXHW_LOG + PSXHW_LOG("COUNTER 2 TARGET 32bit write %lx\n", value); +#endif + psxRcntWtarget(2, value & 0xffff); return; + + default: + psxHu32(add) = value; +#ifdef PSXHW_LOG + PSXHW_LOG("*Unknown 32bit write at address %lx value %lx\n", add, value); +#endif + return; + } + psxHu32(add) = value; +#ifdef PSXHW_LOG + PSXHW_LOG("*Known 32bit write at address %lx value %lx\n", add, value); +#endif +} + +int psxHwFreeze(gzFile f, int Mode) { + char Unused[4096]; + + gzfreezel(Unused); + + return 0; +} diff --git a/PcsxSrc/PsxHw.h b/PcsxSrc/PsxHw.h index a27ec9c..4f104ed 100644 --- a/PcsxSrc/PsxHw.h +++ b/PcsxSrc/PsxHw.h @@ -1,31 +1,31 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __PSXHW_H__ -#define __PSXHW_H__ - -void psxHwReset(); -u8 psxHwRead8 (u32 add); -u16 psxHwRead16(u32 add); -u32 psxHwRead32(u32 add); -void psxHwWrite8 (u32 add, u8 value); -void psxHwWrite16(u32 add, u16 value); -void psxHwWrite32(u32 add, u32 value); -int psxHwFreeze(gzFile f, int Mode); - -#endif /* __PSXHW_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __PSXHW_H__ +#define __PSXHW_H__ + +void psxHwReset(); +u8 psxHwRead8 (u32 add); +u16 psxHwRead16(u32 add); +u32 psxHwRead32(u32 add); +void psxHwWrite8 (u32 add, u8 value); +void psxHwWrite16(u32 add, u16 value); +void psxHwWrite32(u32 add, u32 value); +int psxHwFreeze(gzFile f, int Mode); + +#endif /* __PSXHW_H__ */ diff --git a/PcsxSrc/PsxInterpreter.c b/PcsxSrc/PsxInterpreter.c index cfed203..ae41a29 100644 --- a/PcsxSrc/PsxInterpreter.c +++ b/PcsxSrc/PsxInterpreter.c @@ -1,471 +1,471 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - -#include "PsxCommon.h" - -static int branch = 0; -static int branch2 = 0; -static u32 branchPC; - -// These macros are used to assemble the repassembler functions - -#ifdef PSXCPU_LOG -#define debugI() \ - if (Config.Log) { \ - PSXCPU_LOG("CPU: %s\n", disR3000AF(psxRegs.code, psxRegs.pc)); \ - } -#else -#define debugI() -#endif - -#define execI() { \ - psxRegs.code = PSXMu32(psxRegs.pc); \ - \ - debugI(); \ - \ - psxRegs.pc+= 4; \ - psxRegs.cycle++; \ - \ - psxBSC[psxRegs.code >> 26](); \ -} - -#define doBranch(tar) { \ - branch2 = branch = 1; \ - branchPC = tar; \ - execI(); \ - branch = 0; \ - psxRegs.pc = branchPC; \ - \ - psxBranchTest(); \ -} - -// Subsets -void (*psxBSC[64])(); -void (*psxSPC[64])(); -void (*psxREG[32])(); -void (*psxCP0[32])(); -void (*psxCP2[64])(); -void (*psxCP2BSC[32])(); - -/********************************************************* -* Arithmetic with immediate operand * -* Format: OP rt, rs, immediate * -*********************************************************/ -void psxADDI() { if (!_Rt_) return; _rRt_ = _u32(_rRs_) + _Imm_ ; } // Rt = Rs + Im (Exception on Integer Overflow) -void psxADDIU() { if (!_Rt_) return; _rRt_ = _u32(_rRs_) + _Imm_ ; } // Rt = Rs + Im -void psxANDI() { if (!_Rt_) return; _rRt_ = _u32(_rRs_) & _ImmU_; } // Rt = Rs And Im -void psxORI() { if (!_Rt_) return; _rRt_ = _u32(_rRs_) | _ImmU_; } // Rt = Rs Or Im -void psxXORI() { if (!_Rt_) return; _rRt_ = _u32(_rRs_) ^ _ImmU_; } // Rt = Rs Xor Im -void psxSLTI() { if (!_Rt_) return; _rRt_ = _i32(_rRs_) < _Imm_ ; } // Rt = Rs < Im (Signed) -void psxSLTIU() { if (!_Rt_) return; _rRt_ = _u32(_rRs_) < _ImmU_; } // Rt = Rs < Im (Unsigned) - -/********************************************************* -* Register arithmetic * -* Format: OP rd, rs, rt * -*********************************************************/ -void psxADD() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) + _u32(_rRt_); } // Rd = Rs + Rt (Exception on Integer Overflow) -void psxADDU() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) + _u32(_rRt_); } // Rd = Rs + Rt -void psxSUB() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) - _u32(_rRt_); } // Rd = Rs - Rt (Exception on Integer Overflow) -void psxSUBU() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) - _u32(_rRt_); } // Rd = Rs - Rt -void psxAND() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) & _u32(_rRt_); } // Rd = Rs And Rt -void psxOR() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) | _u32(_rRt_); } // Rd = Rs Or Rt -void psxXOR() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) ^ _u32(_rRt_); } // Rd = Rs Xor Rt -void psxNOR() { if (!_Rd_) return; _rRd_ =~(_u32(_rRs_) | _u32(_rRt_)); }// Rd = Rs Nor Rt -void psxSLT() { if (!_Rd_) return; _rRd_ = _i32(_rRs_) < _i32(_rRt_); } // Rd = Rs < Rt (Signed) -void psxSLTU() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) < _u32(_rRt_); } // Rd = Rs < Rt (Unsigned) - -/********************************************************* -* Register mult/div & Register trap logic * -* Format: OP rs, rt * -*********************************************************/ -void psxDIV() { - if (_i32(_rRt_) != 0) { - _i32(_rLo_) = _i32(_rRs_) / _i32(_rRt_); - _i32(_rHi_) = _i32(_rRs_) % _i32(_rRt_); - } -} - -void psxDIVU() { - if (_rRt_ != 0) { - _rLo_ = _rRs_ / _rRt_; - _rHi_ = _rRs_ % _rRt_; - } -} - -void psxMULT() { - u64 res = (s64)((s64)_i32(_rRs_) * (s64)_i32(_rRt_)); - - psxRegs.GPR.n.lo = (unsigned long)(res & 0xffffffff); - psxRegs.GPR.n.hi = (unsigned long)((res >> 32) & 0xffffffff); -} - -void psxMULTU() { - u64 res = (u64)((u64)_u32(_rRs_) * (u64)_u32(_rRt_)); - - psxRegs.GPR.n.lo = (unsigned long)(res & 0xffffffff); - psxRegs.GPR.n.hi = (unsigned long)((res >> 32) & 0xffffffff); -} - -/********************************************************* -* Register branch logic * -* Format: OP rs, offset * -*********************************************************/ -#define RepZBranchi32(op) if(_i32(_rRs_) op 0) doBranch(_BranchTarget_); -#define RepZBranchLinki32(op) if(_i32(_rRs_) op 0) { _SetLink(31); doBranch(_BranchTarget_); } - -void psxBGEZ() { RepZBranchi32(>=) } // Branch if Rs >= 0 -void psxBGEZAL() { RepZBranchLinki32(>=) } // Branch if Rs >= 0 and link -void psxBGTZ() { RepZBranchi32(>) } // Branch if Rs > 0 -void psxBLEZ() { RepZBranchi32(<=) } // Branch if Rs <= 0 -void psxBLTZ() { RepZBranchi32(<) } // Branch if Rs < 0 -void psxBLTZAL() { RepZBranchLinki32(<) } // Branch if Rs < 0 and link - -/********************************************************* -* Shift arithmetic with constant shift * -* Format: OP rd, rt, sa * -*********************************************************/ -void psxSLL() { if (!_Rd_) return; _u32(_rRd_) = _u32(_rRt_) << _Sa_; } // Rd = Rt << sa -void psxSRA() { if (!_Rd_) return; _i32(_rRd_) = _i32(_rRt_) >> _Sa_; } // Rd = Rt >> sa (arithmetic) -void psxSRL() { if (!_Rd_) return; _u32(_rRd_) = _u32(_rRt_) >> _Sa_; } // Rd = Rt >> sa (logical) - -/********************************************************* -* Shift arithmetic with variant register shift * -* Format: OP rd, rt, rs * -*********************************************************/ -void psxSLLV() { if (!_Rd_) return; _u32(_rRd_) = _u32(_rRt_) << _u32(_rRs_); } // Rd = Rt << rs -void psxSRAV() { if (!_Rd_) return; _i32(_rRd_) = _i32(_rRt_) >> _u32(_rRs_); } // Rd = Rt >> rs (arithmetic) -void psxSRLV() { if (!_Rd_) return; _u32(_rRd_) = _u32(_rRt_) >> _u32(_rRs_); } // Rd = Rt >> rs (logical) - -/********************************************************* -* Load higher 16 bits of the first word in GPR with imm * -* Format: OP rt, immediate * -*********************************************************/ -void psxLUI() { if (!_Rt_) return; _u32(_rRt_) = psxRegs.code << 16; } // Upper halfword of Rt = Im - -/********************************************************* -* Move from HI/LO to GPR * -* Format: OP rd * -*********************************************************/ -void psxMFHI() { if (!_Rd_) return; _rRd_ = _rHi_; } // Rd = Hi -void psxMFLO() { if (!_Rd_) return; _rRd_ = _rLo_; } // Rd = Lo - -/********************************************************* -* Move to GPR to HI/LO & Register jump * -* Format: OP rs * -*********************************************************/ -void psxMTHI() { _rHi_ = _rRs_; } // Hi = Rs -void psxMTLO() { _rLo_ = _rRs_; } // Lo = Rs - -/********************************************************* -* Special purpose instructions * -* Format: OP * -*********************************************************/ -void psxBREAK() { - // Break exception - psx rom doens't handles this -} - -void psxSYSCALL() { - psxRegs.pc -= 4; - psxException(0x20, branch); -} - -void psxRFE() { - psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status & 0xfffffff0) | - ((psxRegs.CP0.n.Status & 0x3c) >> 2); -} - -/********************************************************* -* Register branch logic * -* Format: OP rs, rt, offset * -*********************************************************/ -#define RepBranchi32(op) if(_i32(_rRs_) op _i32(_rRt_)) doBranch(_BranchTarget_); - -void psxBEQ() { RepBranchi32(==) } // Branch if Rs == Rt -void psxBNE() { RepBranchi32(!=) } // Branch if Rs != Rt - -/********************************************************* -* Jump to target * -* Format: OP target * -*********************************************************/ -void psxJ() { doBranch(_JumpTarget_); } -void psxJAL() { _SetLink(31); doBranch(_JumpTarget_); } - -/********************************************************* -* Register jump * -* Format: OP rs, rd * -*********************************************************/ -void psxJR() { doBranch(_u32(_rRs_)); } -void psxJALR() { if (_Rd_) { _SetLink(_Rd_); } doBranch(_u32(_rRs_)); } - -/********************************************************* -* Load and store for GPR * -* Format: OP rt, offset(base) * -*********************************************************/ - -#define _oB_ (_u32(_rRs_) + _Imm_) - -void psxLB() { - if (_Rt_) { - _i32(_rRt_) = (char)psxMemRead8(_oB_); - } else { - psxMemRead8(_oB_); - } -} - -void psxLBU() { - if (_Rt_) { - _u32(_rRt_) = psxMemRead8(_oB_); - } else { - psxMemRead8(_oB_); - } -} - -void psxLH() { - if (_Rt_) { - _i32(_rRt_) = (short)psxMemRead16(_oB_); - } else { - psxMemRead16(_oB_); - } -} - -void psxLHU() { - if (_Rt_) { - _u32(_rRt_) = psxMemRead16(_oB_); - } else { - psxMemRead16(_oB_); - } -} - -void psxLW() { - if (_Rt_) { - _u32(_rRt_) = psxMemRead32(_oB_); - } else { - psxMemRead32(_oB_); - } -} - -void psxLWL() { - u32 shift = (_oB_ & 3) << 3; - u32 mem = psxMemRead32(_oB_ & 0xfffffffc); - - if (!_Rt_) return; - _u32(_rRt_) = ( _u32(_rRt_) & (0x00ffffff >> shift) ) | - ( mem << (24 - shift) ); - - /* - Mem = 1234. Reg = abcd - - 0 4bcd (mem << 24) | (reg & 0x00ffffff) - 1 34cd (mem << 16) | (reg & 0x0000ffff) - 2 234d (mem << 8) | (reg & 0x000000ff) - 3 1234 (mem ) | (reg & 0x00000000) - - */ -} - -void psxLWR() { - u32 shift = (_oB_ & 3) << 3; - u32 mem = psxMemRead32(_oB_ & 0xfffffffc); - - if (!_Rt_) return; - _u32(_rRt_) = ( _u32(_rRt_) & (0xffffff00 << (24 - shift)) ) | - ( mem >> shift ); - - /* - Mem = 1234. Reg = abcd - - 0 1234 (mem ) | (reg & 0x00000000) - 1 a123 (mem >> 8) | (reg & 0xff000000) - 2 ab12 (mem >> 16) | (reg & 0xffff0000) - 3 abc1 (mem >> 24) | (reg & 0xffffff00) - - */ -} - -void psxSB() { psxMemWrite8 (_oB_, _u8 (_rRt_)); } -void psxSH() { psxMemWrite16(_oB_, _u16(_rRt_)); } -void psxSW() { psxMemWrite32(_oB_, _u32(_rRt_)); } - -void psxSWL() { - u32 shift = (_oB_ & 3) << 3; - u32 mem = psxMemRead32(_oB_ & 0xfffffffc); - - psxMemWrite32((_oB_ & 0xfffffffc), ( ( _u32(_rRt_) >> (24 - shift) ) ) | - ( mem & (0xffffff00 << shift) )); - /* - Mem = 1234. Reg = abcd - - 0 123a (reg >> 24) | (mem & 0xffffff00) - 1 12ab (reg >> 16) | (mem & 0xffff0000) - 2 1abc (reg >> 8) | (mem & 0xff000000) - 3 abcd (reg ) | (mem & 0x00000000) - - */ -} - -void psxSWR() { - u32 shift = (_oB_ & 3) << 3; - u32 mem = psxMemRead32(_oB_ & 0xfffffffc); - - psxMemWrite32((_oB_ & 0xfffffffc), ( ( _u32(_rRt_) << shift ) | - (mem & (0x00ffffff >> (24 - shift)) ) ) ); - /* - Mem = 1234. Reg = abcd - - 0 abcd (reg ) | (mem & 0x00000000) - 1 bcd4 (reg << 8) | (mem & 0x000000ff) - 2 cd34 (reg << 16) | (mem & 0x0000ffff) - 3 d234 (reg << 24) | (mem & 0x00ffffff) - - */ -} - -/********************************************************* -* Moves between GPR and COPx * -* Format: OP rt, fs * -*********************************************************/ -void psxMFC0() { if (!_Rt_) return; _i32(_rRt_) = (int)_rFs_; } -void psxCFC0() { if (!_Rt_) return; _i32(_rRt_) = (int)_rFs_; } - -void psxMTC0() { _rFs_ = _u32(_rRt_); } -void psxCTC0() { _rFs_ = _u32(_rRt_); } - -/********************************************************* -* Unknow instruction (would generate an exception) * -* Format: ? * -*********************************************************/ -void psxNULL() { -#ifdef PSXCPU_LOG - PSXCPU_LOG("psx: Unimplemented op %x\n", psxRegs.code); -#endif -} - -void psxSPECIAL() { - psxSPC[_Funct_](); -} - -void psxREGIMM() { - psxREG[_Rt_](); -} - -void psxCOP0() { - psxCP0[_Rs_](); -} - -void psxCOP2() { - psxCP2[_Funct_](); -} - -void psxBASIC() { - psxCP2BSC[_Rs_](); -} - -void psxHLE() { - psxHLEt[psxRegs.code & 0xff](); -} - -void (*psxBSC[64])() = { - psxSPECIAL, psxREGIMM, psxJ , psxJAL , psxBEQ , psxBNE , psxBLEZ, psxBGTZ, - psxADDI , psxADDIU , psxSLTI, psxSLTIU, psxANDI, psxORI , psxXORI, psxLUI , - psxCOP0 , psxNULL , psxCOP2, psxNULL , psxNULL, psxNULL, psxNULL, psxNULL, - psxNULL , psxNULL , psxNULL, psxNULL , psxNULL, psxNULL, psxNULL, psxNULL, - psxLB , psxLH , psxLWL , psxLW , psxLBU , psxLHU , psxLWR , psxNULL, - psxSB , psxSH , psxSWL , psxSW , psxNULL, psxNULL, psxSWR , psxNULL, - psxNULL , psxNULL , gteLWC2, psxNULL , psxNULL, psxNULL, psxNULL, psxNULL, - psxNULL , psxNULL , gteSWC2, psxHLE , psxNULL, psxNULL, psxNULL, psxNULL -}; - - -void (*psxSPC[64])() = { - psxSLL , psxNULL , psxSRL , psxSRA , psxSLLV , psxNULL , psxSRLV, psxSRAV, - psxJR , psxJALR , psxNULL, psxNULL, psxSYSCALL, psxBREAK, psxNULL, psxNULL, - psxMFHI, psxMTHI , psxMFLO, psxMTLO, psxNULL , psxNULL , psxNULL, psxNULL, - psxMULT, psxMULTU, psxDIV , psxDIVU, psxNULL , psxNULL , psxNULL, psxNULL, - psxADD , psxADDU , psxSUB , psxSUBU, psxAND , psxOR , psxXOR , psxNOR , - psxNULL, psxNULL , psxSLT , psxSLTU, psxNULL , psxNULL , psxNULL, psxNULL, - psxNULL, psxNULL , psxNULL, psxNULL, psxNULL , psxNULL , psxNULL, psxNULL, - psxNULL, psxNULL , psxNULL, psxNULL, psxNULL , psxNULL , psxNULL, psxNULL -}; - -void (*psxREG[32])() = { - psxBLTZ , psxBGEZ , psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, - psxNULL , psxNULL , psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, - psxBLTZAL, psxBGEZAL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, - psxNULL , psxNULL , psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL -}; - -void (*psxCP0[32])() = { - psxMFC0, psxNULL, psxCFC0, psxNULL, psxMTC0, psxNULL, psxCTC0, psxNULL, - psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, - psxRFE , psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, - psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL -}; - -void (*psxCP2[64])() = { - psxBASIC, gteRTPS , psxNULL , psxNULL, psxNULL, psxNULL , gteNCLIP, psxNULL, // 00 - psxNULL , psxNULL , psxNULL , psxNULL, gteOP , psxNULL , psxNULL , psxNULL, // 08 - gteDPCS , gteINTPL, gteMVMVA, gteNCDS, gteCDP , psxNULL , gteNCDT , psxNULL, // 10 - psxNULL , psxNULL , psxNULL , gteNCCS, gteCC , psxNULL , gteNCS , psxNULL, // 18 - gteNCT , psxNULL , psxNULL , psxNULL, psxNULL, psxNULL , psxNULL , psxNULL, // 20 - gteSQR , gteDCPL , gteDPCT , psxNULL, psxNULL, gteAVSZ3, gteAVSZ4, psxNULL, // 28 - gteRTPT , psxNULL , psxNULL , psxNULL, psxNULL, psxNULL , psxNULL , psxNULL, // 30 - psxNULL , psxNULL , psxNULL , psxNULL, psxNULL, gteGPF , gteGPL , gteNCCT // 38 -}; - -void (*psxCP2BSC[32])() = { - gteMFC2, psxNULL, gteCFC2, psxNULL, gteMTC2, psxNULL, gteCTC2, psxNULL, - psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, - psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, - psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL -}; - - -/////////////////////////////////////////// - -static int intInit() { - return 0; -} - -static void intReset() { -} - -static void intExecute() { - for (;;) execI(); -} - -static void intExecuteBlock() { - branch2 = 0; - while (!branch2) execI(); -} - -static void intClear(u32 Addr, u32 Size) { -} - -static void intShutdown() { -} - -R3000Acpu psxInt = { - intInit, - intReset, - intExecute, - intExecuteBlock, - intClear, - intShutdown -}; +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + +#include "PsxCommon.h" + +static int branch = 0; +static int branch2 = 0; +static u32 branchPC; + +// These macros are used to assemble the repassembler functions + +#ifdef PSXCPU_LOG +#define debugI() \ + if (Config.Log) { \ + PSXCPU_LOG("CPU: %s\n", disR3000AF(psxRegs.code, psxRegs.pc)); \ + } +#else +#define debugI() +#endif + +#define execI() { \ + psxRegs.code = PSXMu32(psxRegs.pc); \ + \ + debugI(); \ + \ + psxRegs.pc+= 4; \ + psxRegs.cycle++; \ + \ + psxBSC[psxRegs.code >> 26](); \ +} + +#define doBranch(tar) { \ + branch2 = branch = 1; \ + branchPC = tar; \ + execI(); \ + branch = 0; \ + psxRegs.pc = branchPC; \ + \ + psxBranchTest(); \ +} + +// Subsets +void (*psxBSC[64])(); +void (*psxSPC[64])(); +void (*psxREG[32])(); +void (*psxCP0[32])(); +void (*psxCP2[64])(); +void (*psxCP2BSC[32])(); + +/********************************************************* +* Arithmetic with immediate operand * +* Format: OP rt, rs, immediate * +*********************************************************/ +void psxADDI() { if (!_Rt_) return; _rRt_ = _u32(_rRs_) + _Imm_ ; } // Rt = Rs + Im (Exception on Integer Overflow) +void psxADDIU() { if (!_Rt_) return; _rRt_ = _u32(_rRs_) + _Imm_ ; } // Rt = Rs + Im +void psxANDI() { if (!_Rt_) return; _rRt_ = _u32(_rRs_) & _ImmU_; } // Rt = Rs And Im +void psxORI() { if (!_Rt_) return; _rRt_ = _u32(_rRs_) | _ImmU_; } // Rt = Rs Or Im +void psxXORI() { if (!_Rt_) return; _rRt_ = _u32(_rRs_) ^ _ImmU_; } // Rt = Rs Xor Im +void psxSLTI() { if (!_Rt_) return; _rRt_ = _i32(_rRs_) < _Imm_ ; } // Rt = Rs < Im (Signed) +void psxSLTIU() { if (!_Rt_) return; _rRt_ = _u32(_rRs_) < _ImmU_; } // Rt = Rs < Im (Unsigned) + +/********************************************************* +* Register arithmetic * +* Format: OP rd, rs, rt * +*********************************************************/ +void psxADD() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) + _u32(_rRt_); } // Rd = Rs + Rt (Exception on Integer Overflow) +void psxADDU() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) + _u32(_rRt_); } // Rd = Rs + Rt +void psxSUB() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) - _u32(_rRt_); } // Rd = Rs - Rt (Exception on Integer Overflow) +void psxSUBU() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) - _u32(_rRt_); } // Rd = Rs - Rt +void psxAND() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) & _u32(_rRt_); } // Rd = Rs And Rt +void psxOR() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) | _u32(_rRt_); } // Rd = Rs Or Rt +void psxXOR() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) ^ _u32(_rRt_); } // Rd = Rs Xor Rt +void psxNOR() { if (!_Rd_) return; _rRd_ =~(_u32(_rRs_) | _u32(_rRt_)); }// Rd = Rs Nor Rt +void psxSLT() { if (!_Rd_) return; _rRd_ = _i32(_rRs_) < _i32(_rRt_); } // Rd = Rs < Rt (Signed) +void psxSLTU() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) < _u32(_rRt_); } // Rd = Rs < Rt (Unsigned) + +/********************************************************* +* Register mult/div & Register trap logic * +* Format: OP rs, rt * +*********************************************************/ +void psxDIV() { + if (_i32(_rRt_) != 0) { + _i32(_rLo_) = _i32(_rRs_) / _i32(_rRt_); + _i32(_rHi_) = _i32(_rRs_) % _i32(_rRt_); + } +} + +void psxDIVU() { + if (_rRt_ != 0) { + _rLo_ = _rRs_ / _rRt_; + _rHi_ = _rRs_ % _rRt_; + } +} + +void psxMULT() { + u64 res = (s64)((s64)_i32(_rRs_) * (s64)_i32(_rRt_)); + + psxRegs.GPR.n.lo = (unsigned long)(res & 0xffffffff); + psxRegs.GPR.n.hi = (unsigned long)((res >> 32) & 0xffffffff); +} + +void psxMULTU() { + u64 res = (u64)((u64)_u32(_rRs_) * (u64)_u32(_rRt_)); + + psxRegs.GPR.n.lo = (unsigned long)(res & 0xffffffff); + psxRegs.GPR.n.hi = (unsigned long)((res >> 32) & 0xffffffff); +} + +/********************************************************* +* Register branch logic * +* Format: OP rs, offset * +*********************************************************/ +#define RepZBranchi32(op) if(_i32(_rRs_) op 0) doBranch(_BranchTarget_); +#define RepZBranchLinki32(op) if(_i32(_rRs_) op 0) { _SetLink(31); doBranch(_BranchTarget_); } + +void psxBGEZ() { RepZBranchi32(>=) } // Branch if Rs >= 0 +void psxBGEZAL() { RepZBranchLinki32(>=) } // Branch if Rs >= 0 and link +void psxBGTZ() { RepZBranchi32(>) } // Branch if Rs > 0 +void psxBLEZ() { RepZBranchi32(<=) } // Branch if Rs <= 0 +void psxBLTZ() { RepZBranchi32(<) } // Branch if Rs < 0 +void psxBLTZAL() { RepZBranchLinki32(<) } // Branch if Rs < 0 and link + +/********************************************************* +* Shift arithmetic with constant shift * +* Format: OP rd, rt, sa * +*********************************************************/ +void psxSLL() { if (!_Rd_) return; _u32(_rRd_) = _u32(_rRt_) << _Sa_; } // Rd = Rt << sa +void psxSRA() { if (!_Rd_) return; _i32(_rRd_) = _i32(_rRt_) >> _Sa_; } // Rd = Rt >> sa (arithmetic) +void psxSRL() { if (!_Rd_) return; _u32(_rRd_) = _u32(_rRt_) >> _Sa_; } // Rd = Rt >> sa (logical) + +/********************************************************* +* Shift arithmetic with variant register shift * +* Format: OP rd, rt, rs * +*********************************************************/ +void psxSLLV() { if (!_Rd_) return; _u32(_rRd_) = _u32(_rRt_) << _u32(_rRs_); } // Rd = Rt << rs +void psxSRAV() { if (!_Rd_) return; _i32(_rRd_) = _i32(_rRt_) >> _u32(_rRs_); } // Rd = Rt >> rs (arithmetic) +void psxSRLV() { if (!_Rd_) return; _u32(_rRd_) = _u32(_rRt_) >> _u32(_rRs_); } // Rd = Rt >> rs (logical) + +/********************************************************* +* Load higher 16 bits of the first word in GPR with imm * +* Format: OP rt, immediate * +*********************************************************/ +void psxLUI() { if (!_Rt_) return; _u32(_rRt_) = psxRegs.code << 16; } // Upper halfword of Rt = Im + +/********************************************************* +* Move from HI/LO to GPR * +* Format: OP rd * +*********************************************************/ +void psxMFHI() { if (!_Rd_) return; _rRd_ = _rHi_; } // Rd = Hi +void psxMFLO() { if (!_Rd_) return; _rRd_ = _rLo_; } // Rd = Lo + +/********************************************************* +* Move to GPR to HI/LO & Register jump * +* Format: OP rs * +*********************************************************/ +void psxMTHI() { _rHi_ = _rRs_; } // Hi = Rs +void psxMTLO() { _rLo_ = _rRs_; } // Lo = Rs + +/********************************************************* +* Special purpose instructions * +* Format: OP * +*********************************************************/ +void psxBREAK() { + // Break exception - psx rom doens't handles this +} + +void psxSYSCALL() { + psxRegs.pc -= 4; + psxException(0x20, branch); +} + +void psxRFE() { + psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status & 0xfffffff0) | + ((psxRegs.CP0.n.Status & 0x3c) >> 2); +} + +/********************************************************* +* Register branch logic * +* Format: OP rs, rt, offset * +*********************************************************/ +#define RepBranchi32(op) if(_i32(_rRs_) op _i32(_rRt_)) doBranch(_BranchTarget_); + +void psxBEQ() { RepBranchi32(==) } // Branch if Rs == Rt +void psxBNE() { RepBranchi32(!=) } // Branch if Rs != Rt + +/********************************************************* +* Jump to target * +* Format: OP target * +*********************************************************/ +void psxJ() { doBranch(_JumpTarget_); } +void psxJAL() { _SetLink(31); doBranch(_JumpTarget_); } + +/********************************************************* +* Register jump * +* Format: OP rs, rd * +*********************************************************/ +void psxJR() { doBranch(_u32(_rRs_)); } +void psxJALR() { if (_Rd_) { _SetLink(_Rd_); } doBranch(_u32(_rRs_)); } + +/********************************************************* +* Load and store for GPR * +* Format: OP rt, offset(base) * +*********************************************************/ + +#define _oB_ (_u32(_rRs_) + _Imm_) + +void psxLB() { + if (_Rt_) { + _i32(_rRt_) = (char)psxMemRead8(_oB_); + } else { + psxMemRead8(_oB_); + } +} + +void psxLBU() { + if (_Rt_) { + _u32(_rRt_) = psxMemRead8(_oB_); + } else { + psxMemRead8(_oB_); + } +} + +void psxLH() { + if (_Rt_) { + _i32(_rRt_) = (short)psxMemRead16(_oB_); + } else { + psxMemRead16(_oB_); + } +} + +void psxLHU() { + if (_Rt_) { + _u32(_rRt_) = psxMemRead16(_oB_); + } else { + psxMemRead16(_oB_); + } +} + +void psxLW() { + if (_Rt_) { + _u32(_rRt_) = psxMemRead32(_oB_); + } else { + psxMemRead32(_oB_); + } +} + +void psxLWL() { + u32 shift = (_oB_ & 3) << 3; + u32 mem = psxMemRead32(_oB_ & 0xfffffffc); + + if (!_Rt_) return; + _u32(_rRt_) = ( _u32(_rRt_) & (0x00ffffff >> shift) ) | + ( mem << (24 - shift) ); + + /* + Mem = 1234. Reg = abcd + + 0 4bcd (mem << 24) | (reg & 0x00ffffff) + 1 34cd (mem << 16) | (reg & 0x0000ffff) + 2 234d (mem << 8) | (reg & 0x000000ff) + 3 1234 (mem ) | (reg & 0x00000000) + + */ +} + +void psxLWR() { + u32 shift = (_oB_ & 3) << 3; + u32 mem = psxMemRead32(_oB_ & 0xfffffffc); + + if (!_Rt_) return; + _u32(_rRt_) = ( _u32(_rRt_) & (0xffffff00 << (24 - shift)) ) | + ( mem >> shift ); + + /* + Mem = 1234. Reg = abcd + + 0 1234 (mem ) | (reg & 0x00000000) + 1 a123 (mem >> 8) | (reg & 0xff000000) + 2 ab12 (mem >> 16) | (reg & 0xffff0000) + 3 abc1 (mem >> 24) | (reg & 0xffffff00) + + */ +} + +void psxSB() { psxMemWrite8 (_oB_, _u8 (_rRt_)); } +void psxSH() { psxMemWrite16(_oB_, _u16(_rRt_)); } +void psxSW() { psxMemWrite32(_oB_, _u32(_rRt_)); } + +void psxSWL() { + u32 shift = (_oB_ & 3) << 3; + u32 mem = psxMemRead32(_oB_ & 0xfffffffc); + + psxMemWrite32((_oB_ & 0xfffffffc), ( ( _u32(_rRt_) >> (24 - shift) ) ) | + ( mem & (0xffffff00 << shift) )); + /* + Mem = 1234. Reg = abcd + + 0 123a (reg >> 24) | (mem & 0xffffff00) + 1 12ab (reg >> 16) | (mem & 0xffff0000) + 2 1abc (reg >> 8) | (mem & 0xff000000) + 3 abcd (reg ) | (mem & 0x00000000) + + */ +} + +void psxSWR() { + u32 shift = (_oB_ & 3) << 3; + u32 mem = psxMemRead32(_oB_ & 0xfffffffc); + + psxMemWrite32((_oB_ & 0xfffffffc), ( ( _u32(_rRt_) << shift ) | + (mem & (0x00ffffff >> (24 - shift)) ) ) ); + /* + Mem = 1234. Reg = abcd + + 0 abcd (reg ) | (mem & 0x00000000) + 1 bcd4 (reg << 8) | (mem & 0x000000ff) + 2 cd34 (reg << 16) | (mem & 0x0000ffff) + 3 d234 (reg << 24) | (mem & 0x00ffffff) + + */ +} + +/********************************************************* +* Moves between GPR and COPx * +* Format: OP rt, fs * +*********************************************************/ +void psxMFC0() { if (!_Rt_) return; _i32(_rRt_) = (int)_rFs_; } +void psxCFC0() { if (!_Rt_) return; _i32(_rRt_) = (int)_rFs_; } + +void psxMTC0() { _rFs_ = _u32(_rRt_); } +void psxCTC0() { _rFs_ = _u32(_rRt_); } + +/********************************************************* +* Unknow instruction (would generate an exception) * +* Format: ? * +*********************************************************/ +void psxNULL() { +#ifdef PSXCPU_LOG + PSXCPU_LOG("psx: Unimplemented op %x\n", psxRegs.code); +#endif +} + +void psxSPECIAL() { + psxSPC[_Funct_](); +} + +void psxREGIMM() { + psxREG[_Rt_](); +} + +void psxCOP0() { + psxCP0[_Rs_](); +} + +void psxCOP2() { + psxCP2[_Funct_](); +} + +void psxBASIC() { + psxCP2BSC[_Rs_](); +} + +void psxHLE() { + psxHLEt[psxRegs.code & 0xff](); +} + +void (*psxBSC[64])() = { + psxSPECIAL, psxREGIMM, psxJ , psxJAL , psxBEQ , psxBNE , psxBLEZ, psxBGTZ, + psxADDI , psxADDIU , psxSLTI, psxSLTIU, psxANDI, psxORI , psxXORI, psxLUI , + psxCOP0 , psxNULL , psxCOP2, psxNULL , psxNULL, psxNULL, psxNULL, psxNULL, + psxNULL , psxNULL , psxNULL, psxNULL , psxNULL, psxNULL, psxNULL, psxNULL, + psxLB , psxLH , psxLWL , psxLW , psxLBU , psxLHU , psxLWR , psxNULL, + psxSB , psxSH , psxSWL , psxSW , psxNULL, psxNULL, psxSWR , psxNULL, + psxNULL , psxNULL , gteLWC2, psxNULL , psxNULL, psxNULL, psxNULL, psxNULL, + psxNULL , psxNULL , gteSWC2, psxHLE , psxNULL, psxNULL, psxNULL, psxNULL +}; + + +void (*psxSPC[64])() = { + psxSLL , psxNULL , psxSRL , psxSRA , psxSLLV , psxNULL , psxSRLV, psxSRAV, + psxJR , psxJALR , psxNULL, psxNULL, psxSYSCALL, psxBREAK, psxNULL, psxNULL, + psxMFHI, psxMTHI , psxMFLO, psxMTLO, psxNULL , psxNULL , psxNULL, psxNULL, + psxMULT, psxMULTU, psxDIV , psxDIVU, psxNULL , psxNULL , psxNULL, psxNULL, + psxADD , psxADDU , psxSUB , psxSUBU, psxAND , psxOR , psxXOR , psxNOR , + psxNULL, psxNULL , psxSLT , psxSLTU, psxNULL , psxNULL , psxNULL, psxNULL, + psxNULL, psxNULL , psxNULL, psxNULL, psxNULL , psxNULL , psxNULL, psxNULL, + psxNULL, psxNULL , psxNULL, psxNULL, psxNULL , psxNULL , psxNULL, psxNULL +}; + +void (*psxREG[32])() = { + psxBLTZ , psxBGEZ , psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, + psxNULL , psxNULL , psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, + psxBLTZAL, psxBGEZAL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, + psxNULL , psxNULL , psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL +}; + +void (*psxCP0[32])() = { + psxMFC0, psxNULL, psxCFC0, psxNULL, psxMTC0, psxNULL, psxCTC0, psxNULL, + psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, + psxRFE , psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, + psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL +}; + +void (*psxCP2[64])() = { + psxBASIC, gteRTPS , psxNULL , psxNULL, psxNULL, psxNULL , gteNCLIP, psxNULL, // 00 + psxNULL , psxNULL , psxNULL , psxNULL, gteOP , psxNULL , psxNULL , psxNULL, // 08 + gteDPCS , gteINTPL, gteMVMVA, gteNCDS, gteCDP , psxNULL , gteNCDT , psxNULL, // 10 + psxNULL , psxNULL , psxNULL , gteNCCS, gteCC , psxNULL , gteNCS , psxNULL, // 18 + gteNCT , psxNULL , psxNULL , psxNULL, psxNULL, psxNULL , psxNULL , psxNULL, // 20 + gteSQR , gteDCPL , gteDPCT , psxNULL, psxNULL, gteAVSZ3, gteAVSZ4, psxNULL, // 28 + gteRTPT , psxNULL , psxNULL , psxNULL, psxNULL, psxNULL , psxNULL , psxNULL, // 30 + psxNULL , psxNULL , psxNULL , psxNULL, psxNULL, gteGPF , gteGPL , gteNCCT // 38 +}; + +void (*psxCP2BSC[32])() = { + gteMFC2, psxNULL, gteCFC2, psxNULL, gteMTC2, psxNULL, gteCTC2, psxNULL, + psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, + psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, + psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL, psxNULL +}; + + +/////////////////////////////////////////// + +static int intInit() { + return 0; +} + +static void intReset() { +} + +static void intExecute() { + for (;;) execI(); +} + +static void intExecuteBlock() { + branch2 = 0; + while (!branch2) execI(); +} + +static void intClear(u32 Addr, u32 Size) { +} + +static void intShutdown() { +} + +R3000Acpu psxInt = { + intInit, + intReset, + intExecute, + intExecuteBlock, + intClear, + intShutdown +}; diff --git a/PcsxSrc/PsxMem.c b/PcsxSrc/PsxMem.c index b30aa22..3905b60 100644 --- a/PcsxSrc/PsxMem.c +++ b/PcsxSrc/PsxMem.c @@ -1,250 +1,250 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include - -#include "PsxCommon.h" - - -int psxMemInit() { - int i; - - psxMemLUT = (long*)malloc(0x10000 * 4); - memset(psxMemLUT, 0, 0x10000 * 4); - - psxM = (char*)malloc(0x00200000); - psxP = (char*)malloc(0x00010000); - psxH = (char*)malloc(0x00010000); - psxR = (char*)malloc(0x00080000); - if (psxMemLUT == NULL || psxM == NULL || psxP == NULL || psxH == NULL || psxR == NULL) { - SysMessage("Error allocating memory"); return -1; - } - - for (i=0; i<0x80; i++) psxMemLUT[i + 0x0000] = (u32)&psxM[(i & 0x1f) << 16]; - memcpy(psxMemLUT + 0x8000, psxMemLUT, 0x80 * 4); - memcpy(psxMemLUT + 0xa000, psxMemLUT, 0x80 * 4); - - for (i=0; i<0x01; i++) psxMemLUT[i + 0x1f00] = (u32)&psxP[i << 16]; - - for (i=0; i<0x01; i++) psxMemLUT[i + 0x1f80] = (u32)&psxH[i << 16]; - - for (i=0; i<0x08; i++) psxMemLUT[i + 0xbfc0] = (u32)&psxR[i << 16]; - - return 0; -} - -void psxMemReset() { - FILE *f = NULL; - char Bios[256]; - - memset(psxM, 0, 0x00200000); - memset(psxP, 0, 0x00010000); - - if (strcmp(Config.Bios, "HLE")) { - sprintf(Bios, "%s%s", Config.BiosDir, Config.Bios); - f = fopen(Bios, "rb"); - - if (f == NULL) { - SysMessage ("Could not open bios:\"%s\". Enabling HLE Bios\n", Bios); - memset(psxR, 0, 0x80000); - Config.HLE = 1; - } - else { - fread(psxR, 1, 0x80000, f); - fclose(f); - Config.HLE = 0; - } - } else Config.HLE = 1; -} - -void psxMemShutdown() { - free(psxM); - free(psxP); - free(psxH); - free(psxR); - free(psxMemLUT); -} - -static int writeok=1; - -u8 psxMemRead8(u32 mem) { - char *p; - u32 t; - - t = mem >> 16; - if (t == 0x1f80) { - if (mem < 0x1f801000) - return psxHu8(mem); - else - return psxHwRead8(mem); - } else { - p = (char *)(psxMemLUT[t]); - if (p != NULL) { - return *(u8 *)(p + (mem & 0xffff)); - } else { -#ifdef PSXMEM_LOG - PSXMEM_LOG("err lb %8.8lx\n", mem); -#endif - return 0; - } - } -} - -u16 psxMemRead16(u32 mem) { - char *p; - u32 t; - - t = mem >> 16; - if (t == 0x1f80) { - if (mem < 0x1f801000) - return psxHu16(mem); - else - return psxHwRead16(mem); - } else { - p = (char *)(psxMemLUT[t]); - if (p != NULL) { - return *(u16 *)(p + (mem & 0xffff)); - } else { -#ifdef PSXMEM_LOG - PSXMEM_LOG("err lh %8.8lx\n", mem); -#endif - return 0; - } - } -} - -u32 psxMemRead32(u32 mem) { - char *p; - u32 t; - - t = mem >> 16; - if (t == 0x1f80) { - if (mem < 0x1f801000) - return psxHu32(mem); - else - return psxHwRead32(mem); - } else { - p = (char *)(psxMemLUT[t]); - if (p != NULL) { - return *(u32 *)(p + (mem & 0xffff)); - } else { -#ifdef PSXMEM_LOG - if (writeok) PSXMEM_LOG("err lw %8.8lx\n", mem); -#endif - return 0; - } - } -} - -void psxMemWrite8(u32 mem, u8 value) { - char *p; - u32 t; - - t = mem >> 16; - if (t == 0x1f80) { - if (mem < 0x1f801000) - psxHu8(mem) = value; - else - psxHwWrite8(mem, value); - } else { - p = (char *)(psxMemLUT[t]); - if (p != NULL) { - *(u8 *)(p + (mem & 0xffff)) = value; - psxCpu->Clear(mem, 1); - } else { -#ifdef PSXMEM_LOG - PSXMEM_LOG("err sb %8.8lx\n", mem); -#endif - } - } -} - -void psxMemWrite16(u32 mem, u16 value) { - char *p; - u32 t; - - t = mem >> 16; - if (t == 0x1f80) { - if (mem < 0x1f801000) - psxHu16(mem) = value; - else - psxHwWrite16(mem, value); - } else { - p = (char *)(psxMemLUT[t]); - if (p != NULL) { - *(u16 *)(p + (mem & 0xffff)) = value; - psxCpu->Clear(mem, 1); - } else { -#ifdef PSXMEM_LOG - PSXMEM_LOG("err sh %8.8lx\n", mem); -#endif - } - } -} - -void psxMemWrite32(u32 mem, u32 value) { - char *p; - u32 t; - - t = mem >> 16; - if (t == 0x1f80) { - if (mem < 0x1f801000) - psxHu32(mem) = value; - else - psxHwWrite32(mem, value); - } else { - p = (char *)(psxMemLUT[t]); - if (p != NULL) { - *(u32 *)(p + (mem & 0xffff)) = value; - psxCpu->Clear(mem, 1); - } else { - if (mem != 0xfffe0130) { - if (!writeok) psxCpu->Clear(mem, 1); -#ifdef PSXMEM_LOG - if (writeok) { PSXMEM_LOG("err sw %8.8lx\n", mem); } -#endif - } else { - int i; - - switch (value) { - case 0x800: case 0x804: - if (writeok == 0) break; - writeok = 0; - memset(psxMemLUT + 0x0000, 0, 0x80 * 4); - memset(psxMemLUT + 0x8000, 0, 0x80 * 4); - memset(psxMemLUT + 0xa000, 0, 0x80 * 4); - break; - case 0x1e988: - if (writeok == 1) break; - writeok = 1; - for (i=0; i<0x80; i++) psxMemLUT[i + 0x0000] = (u32)&psxM[(i & 0x1f) << 16]; - memcpy(psxMemLUT + 0x8000, psxMemLUT, 0x80 * 4); - memcpy(psxMemLUT + 0xa000, psxMemLUT, 0x80 * 4); - break; - default: -#ifdef PSXMEM_LOG - PSXMEM_LOG("unk %8.8lx = %x\n", mem, value); -#endif - break; - } - } - } - } -} - +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include + +#include "PsxCommon.h" + + +int psxMemInit() { + int i; + + psxMemLUT = (long*)malloc(0x10000 * 4); + memset(psxMemLUT, 0, 0x10000 * 4); + + psxM = (char*)malloc(0x00200000); + psxP = (char*)malloc(0x00010000); + psxH = (char*)malloc(0x00010000); + psxR = (char*)malloc(0x00080000); + if (psxMemLUT == NULL || psxM == NULL || psxP == NULL || psxH == NULL || psxR == NULL) { + SysMessage("Error allocating memory"); return -1; + } + + for (i=0; i<0x80; i++) psxMemLUT[i + 0x0000] = (u32)&psxM[(i & 0x1f) << 16]; + memcpy(psxMemLUT + 0x8000, psxMemLUT, 0x80 * 4); + memcpy(psxMemLUT + 0xa000, psxMemLUT, 0x80 * 4); + + for (i=0; i<0x01; i++) psxMemLUT[i + 0x1f00] = (u32)&psxP[i << 16]; + + for (i=0; i<0x01; i++) psxMemLUT[i + 0x1f80] = (u32)&psxH[i << 16]; + + for (i=0; i<0x08; i++) psxMemLUT[i + 0xbfc0] = (u32)&psxR[i << 16]; + + return 0; +} + +void psxMemReset() { + FILE *f = NULL; + char Bios[256]; + + memset(psxM, 0, 0x00200000); + memset(psxP, 0, 0x00010000); + + if (strcmp(Config.Bios, "HLE")) { + sprintf(Bios, "%s%s", Config.BiosDir, Config.Bios); + f = fopen(Bios, "rb"); + + if (f == NULL) { + SysMessage ("Could not open bios:\"%s\". Enabling HLE Bios\n", Bios); + memset(psxR, 0, 0x80000); + Config.HLE = 1; + } + else { + fread(psxR, 1, 0x80000, f); + fclose(f); + Config.HLE = 0; + } + } else Config.HLE = 1; +} + +void psxMemShutdown() { + free(psxM); + free(psxP); + free(psxH); + free(psxR); + free(psxMemLUT); +} + +static int writeok=1; + +u8 psxMemRead8(u32 mem) { + char *p; + u32 t; + + t = mem >> 16; + if (t == 0x1f80) { + if (mem < 0x1f801000) + return psxHu8(mem); + else + return psxHwRead8(mem); + } else { + p = (char *)(psxMemLUT[t]); + if (p != NULL) { + return *(u8 *)(p + (mem & 0xffff)); + } else { +#ifdef PSXMEM_LOG + PSXMEM_LOG("err lb %8.8lx\n", mem); +#endif + return 0; + } + } +} + +u16 psxMemRead16(u32 mem) { + char *p; + u32 t; + + t = mem >> 16; + if (t == 0x1f80) { + if (mem < 0x1f801000) + return psxHu16(mem); + else + return psxHwRead16(mem); + } else { + p = (char *)(psxMemLUT[t]); + if (p != NULL) { + return *(u16 *)(p + (mem & 0xffff)); + } else { +#ifdef PSXMEM_LOG + PSXMEM_LOG("err lh %8.8lx\n", mem); +#endif + return 0; + } + } +} + +u32 psxMemRead32(u32 mem) { + char *p; + u32 t; + + t = mem >> 16; + if (t == 0x1f80) { + if (mem < 0x1f801000) + return psxHu32(mem); + else + return psxHwRead32(mem); + } else { + p = (char *)(psxMemLUT[t]); + if (p != NULL) { + return *(u32 *)(p + (mem & 0xffff)); + } else { +#ifdef PSXMEM_LOG + if (writeok) PSXMEM_LOG("err lw %8.8lx\n", mem); +#endif + return 0; + } + } +} + +void psxMemWrite8(u32 mem, u8 value) { + char *p; + u32 t; + + t = mem >> 16; + if (t == 0x1f80) { + if (mem < 0x1f801000) + psxHu8(mem) = value; + else + psxHwWrite8(mem, value); + } else { + p = (char *)(psxMemLUT[t]); + if (p != NULL) { + *(u8 *)(p + (mem & 0xffff)) = value; + psxCpu->Clear(mem, 1); + } else { +#ifdef PSXMEM_LOG + PSXMEM_LOG("err sb %8.8lx\n", mem); +#endif + } + } +} + +void psxMemWrite16(u32 mem, u16 value) { + char *p; + u32 t; + + t = mem >> 16; + if (t == 0x1f80) { + if (mem < 0x1f801000) + psxHu16(mem) = value; + else + psxHwWrite16(mem, value); + } else { + p = (char *)(psxMemLUT[t]); + if (p != NULL) { + *(u16 *)(p + (mem & 0xffff)) = value; + psxCpu->Clear(mem, 1); + } else { +#ifdef PSXMEM_LOG + PSXMEM_LOG("err sh %8.8lx\n", mem); +#endif + } + } +} + +void psxMemWrite32(u32 mem, u32 value) { + char *p; + u32 t; + + t = mem >> 16; + if (t == 0x1f80) { + if (mem < 0x1f801000) + psxHu32(mem) = value; + else + psxHwWrite32(mem, value); + } else { + p = (char *)(psxMemLUT[t]); + if (p != NULL) { + *(u32 *)(p + (mem & 0xffff)) = value; + psxCpu->Clear(mem, 1); + } else { + if (mem != 0xfffe0130) { + if (!writeok) psxCpu->Clear(mem, 1); +#ifdef PSXMEM_LOG + if (writeok) { PSXMEM_LOG("err sw %8.8lx\n", mem); } +#endif + } else { + int i; + + switch (value) { + case 0x800: case 0x804: + if (writeok == 0) break; + writeok = 0; + memset(psxMemLUT + 0x0000, 0, 0x80 * 4); + memset(psxMemLUT + 0x8000, 0, 0x80 * 4); + memset(psxMemLUT + 0xa000, 0, 0x80 * 4); + break; + case 0x1e988: + if (writeok == 1) break; + writeok = 1; + for (i=0; i<0x80; i++) psxMemLUT[i + 0x0000] = (u32)&psxM[(i & 0x1f) << 16]; + memcpy(psxMemLUT + 0x8000, psxMemLUT, 0x80 * 4); + memcpy(psxMemLUT + 0xa000, psxMemLUT, 0x80 * 4); + break; + default: +#ifdef PSXMEM_LOG + PSXMEM_LOG("unk %8.8lx = %x\n", mem, value); +#endif + break; + } + } + } + } +} + diff --git a/PcsxSrc/PsxMem.h b/PcsxSrc/PsxMem.h index c8608da..521d919 100644 --- a/PcsxSrc/PsxMem.h +++ b/PcsxSrc/PsxMem.h @@ -1,75 +1,75 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __PSXMEMORY_H__ -#define __PSXMEMORY_H__ - -s8 *psxM; -#define psxMs8(mem) psxM[(mem) & 0x1fffff] -#define psxMs16(mem) (*(s16*)&psxM[(mem) & 0x1fffff]) -#define psxMs32(mem) (*(s32*)&psxM[(mem) & 0x1fffff]) -#define psxMu8(mem) (*(u8*) &psxM[(mem) & 0x1fffff]) -#define psxMu16(mem) (*(u16*)&psxM[(mem) & 0x1fffff]) -#define psxMu32(mem) (*(u32*)&psxM[(mem) & 0x1fffff]) - -s8 *psxP; -#define psxPs8(mem) psxP[(mem) & 0xffff] -#define psxPs16(mem) (*(s16*)&psxP[(mem) & 0xffff]) -#define psxPs32(mem) (*(s32*)&psxP[(mem) & 0xffff]) -#define psxPu8(mem) (*(u8*) &psxP[(mem) & 0xffff]) -#define psxPu16(mem) (*(u16*)&psxP[(mem) & 0xffff]) -#define psxPu32(mem) (*(u32*)&psxP[(mem) & 0xffff]) - -s8 *psxR; -#define psxRs8(mem) psxR[(mem) & 0x7ffff] -#define psxRs16(mem) (*(s16*)&psxR[(mem) & 0x7ffff]) -#define psxRs32(mem) (*(s32*)&psxR[(mem) & 0x7ffff]) -#define psxRu8(mem) (*(u8* )&psxR[(mem) & 0x7ffff]) -#define psxRu16(mem) (*(u16*)&psxR[(mem) & 0x7ffff]) -#define psxRu32(mem) (*(u32*)&psxR[(mem) & 0x7ffff]) - -s8 *psxH; -#define psxHs8(mem) psxH[(mem) & 0xffff] -#define psxHs16(mem) (*(s16*)&psxH[(mem) & 0xffff]) -#define psxHs32(mem) (*(s32*)&psxH[(mem) & 0xffff]) -#define psxHu8(mem) (*(u8*) &psxH[(mem) & 0xffff]) -#define psxHu16(mem) (*(u16*)&psxH[(mem) & 0xffff]) -#define psxHu32(mem) (*(u32*)&psxH[(mem) & 0xffff]) - -u32 *psxMemLUT; - -#define PSXM(mem) (psxMemLUT[(mem) >> 16] == 0 ? NULL : (void*)(psxMemLUT[(mem) >> 16] + ((mem) & 0xffff))) -#define PSXMs8(mem) (*(s8 *)PSXM(mem)) -#define PSXMs16(mem) (*(s16*)PSXM(mem)) -#define PSXMs32(mem) (*(s32*)PSXM(mem)) -#define PSXMu8(mem) (*(u8 *)PSXM(mem)) -#define PSXMu16(mem) (*(u16*)PSXM(mem)) -#define PSXMu32(mem) (*(u32*)PSXM(mem)) - -int psxMemInit(); -void psxMemReset(); -void psxMemShutdown(); - -u8 psxMemRead8 (u32 mem); -u16 psxMemRead16(u32 mem); -u32 psxMemRead32(u32 mem); -void psxMemWrite8 (u32 mem, u8 value); -void psxMemWrite16(u32 mem, u16 value); -void psxMemWrite32(u32 mem, u32 value); - -#endif /* __PSXMEMORY_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __PSXMEMORY_H__ +#define __PSXMEMORY_H__ + +s8 *psxM; +#define psxMs8(mem) psxM[(mem) & 0x1fffff] +#define psxMs16(mem) (*(s16*)&psxM[(mem) & 0x1fffff]) +#define psxMs32(mem) (*(s32*)&psxM[(mem) & 0x1fffff]) +#define psxMu8(mem) (*(u8*) &psxM[(mem) & 0x1fffff]) +#define psxMu16(mem) (*(u16*)&psxM[(mem) & 0x1fffff]) +#define psxMu32(mem) (*(u32*)&psxM[(mem) & 0x1fffff]) + +s8 *psxP; +#define psxPs8(mem) psxP[(mem) & 0xffff] +#define psxPs16(mem) (*(s16*)&psxP[(mem) & 0xffff]) +#define psxPs32(mem) (*(s32*)&psxP[(mem) & 0xffff]) +#define psxPu8(mem) (*(u8*) &psxP[(mem) & 0xffff]) +#define psxPu16(mem) (*(u16*)&psxP[(mem) & 0xffff]) +#define psxPu32(mem) (*(u32*)&psxP[(mem) & 0xffff]) + +s8 *psxR; +#define psxRs8(mem) psxR[(mem) & 0x7ffff] +#define psxRs16(mem) (*(s16*)&psxR[(mem) & 0x7ffff]) +#define psxRs32(mem) (*(s32*)&psxR[(mem) & 0x7ffff]) +#define psxRu8(mem) (*(u8* )&psxR[(mem) & 0x7ffff]) +#define psxRu16(mem) (*(u16*)&psxR[(mem) & 0x7ffff]) +#define psxRu32(mem) (*(u32*)&psxR[(mem) & 0x7ffff]) + +s8 *psxH; +#define psxHs8(mem) psxH[(mem) & 0xffff] +#define psxHs16(mem) (*(s16*)&psxH[(mem) & 0xffff]) +#define psxHs32(mem) (*(s32*)&psxH[(mem) & 0xffff]) +#define psxHu8(mem) (*(u8*) &psxH[(mem) & 0xffff]) +#define psxHu16(mem) (*(u16*)&psxH[(mem) & 0xffff]) +#define psxHu32(mem) (*(u32*)&psxH[(mem) & 0xffff]) + +u32 *psxMemLUT; + +#define PSXM(mem) (psxMemLUT[(mem) >> 16] == 0 ? NULL : (void*)(psxMemLUT[(mem) >> 16] + ((mem) & 0xffff))) +#define PSXMs8(mem) (*(s8 *)PSXM(mem)) +#define PSXMs16(mem) (*(s16*)PSXM(mem)) +#define PSXMs32(mem) (*(s32*)PSXM(mem)) +#define PSXMu8(mem) (*(u8 *)PSXM(mem)) +#define PSXMu16(mem) (*(u16*)PSXM(mem)) +#define PSXMu32(mem) (*(u32*)PSXM(mem)) + +int psxMemInit(); +void psxMemReset(); +void psxMemShutdown(); + +u8 psxMemRead8 (u32 mem); +u16 psxMemRead16(u32 mem); +u32 psxMemRead32(u32 mem); +void psxMemWrite8 (u32 mem, u8 value); +void psxMemWrite16(u32 mem, u16 value); +void psxMemWrite32(u32 mem, u32 value); + +#endif /* __PSXMEMORY_H__ */ diff --git a/PcsxSrc/R3000A.c b/PcsxSrc/R3000A.c index 4dcfcd9..e896c11 100644 --- a/PcsxSrc/R3000A.c +++ b/PcsxSrc/R3000A.c @@ -1,165 +1,165 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include - -#include "PsxCommon.h" - -int psxInit() { - - if (Config.Cpu) psxCpu = &psxInt; -#ifdef __i386__ - else psxCpu = &psxRec; -#endif - if (psxMemInit() == -1) return -1; - - return psxCpu->Init(); -} - -void psxReset() { - - psxCpu->Reset(); - - psxMemReset(); - - memset(&psxRegs, 0, sizeof(psxRegs)); - - psxRegs.pc = 0xbfc00000; // Start in bootstrap - - psxRegs.CP0.r[12] = 0x10900000; // COP0 enabled | BEV = 1 | TS = 1 - psxRegs.CP0.r[15] = 0x00000002; // PRevID = Revision ID, same as R3000A - - psxHwReset(); - psxBiosInit(); - - if (!Config.HLE) psxExecuteBios(); - -#ifdef PSX_LOG - PSX_LOG("*BIOS END*\n"); -#endif -} - -void psxShutdown() { - psxMemShutdown(); - psxBiosShutdown(); - - psxCpu->Shutdown(); -} - -void psxException(u32 code, u32 bd) { - // Set the Cause - psxRegs.CP0.n.Cause = code; - -#ifdef PSXCPU_LOG - if (bd) PSXCPU_LOG("bd set\n"); -#endif - // Set the EPC & PC - if (bd) { - psxRegs.CP0.n.Cause|= 0x80000000; - psxRegs.CP0.n.EPC = (psxRegs.pc - 4); - } else - psxRegs.CP0.n.EPC = (psxRegs.pc); - - if (psxRegs.CP0.n.Status & 0x400000) - psxRegs.pc = 0xbfc00180; - else - psxRegs.pc = 0x80000080; - - // Set the Status - psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status &~0x3f) | - ((psxRegs.CP0.n.Status & 0xf) << 2); - - if (!Config.HLE && (((PSXMu32(psxRegs.CP0.n.EPC) >> 24) & 0xfe) == 0x4a)) { - // "hokuto no ken" / "Crash Bandicot 2" ... fix - PSXMu32(psxRegs.CP0.n.EPC)&= ~0x02000000; - } - - if (Config.HLE) psxBiosException(); -} - -void psxBranchTest() { - if ((psxRegs.cycle - psxNextsCounter) >= psxNextCounter) - psxRcntUpdate(); - - if (psxRegs.interrupt) { - if ((psxRegs.interrupt & 0x80) && (!Config.Sio)) { // sio - if ((psxRegs.cycle - psxRegs.intCycle[7]) >= psxRegs.intCycle[7+1]) { - psxRegs.interrupt&=~0x80; - sioInterrupt(); - } - } - if (psxRegs.interrupt & 0x04) { // cdr - if ((psxRegs.cycle - psxRegs.intCycle[2]) >= psxRegs.intCycle[2+1]) { - psxRegs.interrupt&=~0x04; - cdrInterrupt(); - } - } - if (psxRegs.interrupt & 0x040000) { // cdr read - if ((psxRegs.cycle - psxRegs.intCycle[2+16]) >= psxRegs.intCycle[2+16+1]) { - psxRegs.interrupt&=~0x040000; - cdrReadInterrupt(); - } - } - } - - if (psxHu32(0x1070) & psxHu32(0x1074)) { - if ((psxRegs.CP0.n.Status & 0x401) == 0x401) { -#ifdef PSXCPU_LOG -// PSXCPU_LOG("Interrupt: %x %x\n", HWMu32(0x1070), HWMu32(0x1074)); -#endif - psxException(0x400, 0); - } - } - - if (!Config.HLE && Config.PsxOut) { - u32 call = psxRegs.GPR.n.t1 & 0xff; - switch (psxRegs.pc & 0x1fffff) { - case 0xa0: -#ifdef PSXBIOS_LOG - if (call != 0x28 && call != 0xe) { - PSXBIOS_LOG("Bios call a0: %s (%x) %x,%x,%x,%x\n", biosA0n[call], call, psxRegs.GPR.n.a0, psxRegs.GPR.n.a1, psxRegs.GPR.n.a2, psxRegs.GPR.n.a3); } -#endif - if (biosA0[call]) - biosA0[call](); - break; - case 0xb0: -#ifdef PSXBIOS_LOG - if (call != 0x17 && call != 0xb) { - PSXBIOS_LOG("Bios call b0: %s (%x) %x,%x,%x,%x\n", biosB0n[call], call, psxRegs.GPR.n.a0, psxRegs.GPR.n.a1, psxRegs.GPR.n.a2, psxRegs.GPR.n.a3); } -#endif - if (biosB0[call]) - biosB0[call](); - break; - case 0xc0: -#ifdef PSXBIOS_LOG - PSXBIOS_LOG("Bios call c0: %s (%x) %x,%x,%x,%x\n", biosC0n[call], call, psxRegs.GPR.n.a0, psxRegs.GPR.n.a1, psxRegs.GPR.n.a2, psxRegs.GPR.n.a3); -#endif - if (biosC0[call]) - biosC0[call](); - break; - } - } -} - -void psxExecuteBios() { - while (psxRegs.pc != 0x80030000) - psxCpu->ExecuteBlock(); -} - +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include + +#include "PsxCommon.h" + +int psxInit() { + + if (Config.Cpu) psxCpu = &psxInt; +#ifdef __i386__ + else psxCpu = &psxRec; +#endif + if (psxMemInit() == -1) return -1; + + return psxCpu->Init(); +} + +void psxReset() { + + psxCpu->Reset(); + + psxMemReset(); + + memset(&psxRegs, 0, sizeof(psxRegs)); + + psxRegs.pc = 0xbfc00000; // Start in bootstrap + + psxRegs.CP0.r[12] = 0x10900000; // COP0 enabled | BEV = 1 | TS = 1 + psxRegs.CP0.r[15] = 0x00000002; // PRevID = Revision ID, same as R3000A + + psxHwReset(); + psxBiosInit(); + + if (!Config.HLE) psxExecuteBios(); + +#ifdef PSX_LOG + PSX_LOG("*BIOS END*\n"); +#endif +} + +void psxShutdown() { + psxMemShutdown(); + psxBiosShutdown(); + + psxCpu->Shutdown(); +} + +void psxException(u32 code, u32 bd) { + // Set the Cause + psxRegs.CP0.n.Cause = code; + +#ifdef PSXCPU_LOG + if (bd) PSXCPU_LOG("bd set\n"); +#endif + // Set the EPC & PC + if (bd) { + psxRegs.CP0.n.Cause|= 0x80000000; + psxRegs.CP0.n.EPC = (psxRegs.pc - 4); + } else + psxRegs.CP0.n.EPC = (psxRegs.pc); + + if (psxRegs.CP0.n.Status & 0x400000) + psxRegs.pc = 0xbfc00180; + else + psxRegs.pc = 0x80000080; + + // Set the Status + psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status &~0x3f) | + ((psxRegs.CP0.n.Status & 0xf) << 2); + + if (!Config.HLE && (((PSXMu32(psxRegs.CP0.n.EPC) >> 24) & 0xfe) == 0x4a)) { + // "hokuto no ken" / "Crash Bandicot 2" ... fix + PSXMu32(psxRegs.CP0.n.EPC)&= ~0x02000000; + } + + if (Config.HLE) psxBiosException(); +} + +void psxBranchTest() { + if ((psxRegs.cycle - psxNextsCounter) >= psxNextCounter) + psxRcntUpdate(); + + if (psxRegs.interrupt) { + if ((psxRegs.interrupt & 0x80) && (!Config.Sio)) { // sio + if ((psxRegs.cycle - psxRegs.intCycle[7]) >= psxRegs.intCycle[7+1]) { + psxRegs.interrupt&=~0x80; + sioInterrupt(); + } + } + if (psxRegs.interrupt & 0x04) { // cdr + if ((psxRegs.cycle - psxRegs.intCycle[2]) >= psxRegs.intCycle[2+1]) { + psxRegs.interrupt&=~0x04; + cdrInterrupt(); + } + } + if (psxRegs.interrupt & 0x040000) { // cdr read + if ((psxRegs.cycle - psxRegs.intCycle[2+16]) >= psxRegs.intCycle[2+16+1]) { + psxRegs.interrupt&=~0x040000; + cdrReadInterrupt(); + } + } + } + + if (psxHu32(0x1070) & psxHu32(0x1074)) { + if ((psxRegs.CP0.n.Status & 0x401) == 0x401) { +#ifdef PSXCPU_LOG +// PSXCPU_LOG("Interrupt: %x %x\n", HWMu32(0x1070), HWMu32(0x1074)); +#endif + psxException(0x400, 0); + } + } + + if (!Config.HLE && Config.PsxOut) { + u32 call = psxRegs.GPR.n.t1 & 0xff; + switch (psxRegs.pc & 0x1fffff) { + case 0xa0: +#ifdef PSXBIOS_LOG + if (call != 0x28 && call != 0xe) { + PSXBIOS_LOG("Bios call a0: %s (%x) %x,%x,%x,%x\n", biosA0n[call], call, psxRegs.GPR.n.a0, psxRegs.GPR.n.a1, psxRegs.GPR.n.a2, psxRegs.GPR.n.a3); } +#endif + if (biosA0[call]) + biosA0[call](); + break; + case 0xb0: +#ifdef PSXBIOS_LOG + if (call != 0x17 && call != 0xb) { + PSXBIOS_LOG("Bios call b0: %s (%x) %x,%x,%x,%x\n", biosB0n[call], call, psxRegs.GPR.n.a0, psxRegs.GPR.n.a1, psxRegs.GPR.n.a2, psxRegs.GPR.n.a3); } +#endif + if (biosB0[call]) + biosB0[call](); + break; + case 0xc0: +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("Bios call c0: %s (%x) %x,%x,%x,%x\n", biosC0n[call], call, psxRegs.GPR.n.a0, psxRegs.GPR.n.a1, psxRegs.GPR.n.a2, psxRegs.GPR.n.a3); +#endif + if (biosC0[call]) + biosC0[call](); + break; + } + } +} + +void psxExecuteBios() { + while (psxRegs.pc != 0x80030000) + psxCpu->ExecuteBlock(); +} + diff --git a/PcsxSrc/R3000A.h b/PcsxSrc/R3000A.h index 67c4cc6..bd5f689 100644 --- a/PcsxSrc/R3000A.h +++ b/PcsxSrc/R3000A.h @@ -1,186 +1,186 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __R3000A_H__ -#define __R3000A_H__ - -#include - -#include "PsxCommon.h" - -typedef struct { - int (*Init)(); - void (*Reset)(); - void (*Execute)(); /* executes up to a break */ - void (*ExecuteBlock)(); /* executes up to a jump */ - void (*Clear)(u32 Addr, u32 Size); - void (*Shutdown)(); -} R3000Acpu; - -R3000Acpu *psxCpu; -extern R3000Acpu psxInt; -#ifdef __i386__ -extern R3000Acpu psxRec; -#endif - -typedef union { - struct { - unsigned long r0, 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, s8, ra, lo, hi; - } n; - unsigned long r[34]; /* Lo, Hi in r[33] and r[34] */ -} psxGPRRegs; - -typedef union { - struct { - unsigned long Index, Random, EntryLo0, EntryLo1, - Context, PageMask, Wired, Reserved0, - BadVAddr, Count, EntryHi, Compare, - Status, Cause, EPC, PRid, - Config, LLAddr, WatchLO, WatchHI, - XContext, Reserved1, Reserved2, Reserved3, - Reserved4, Reserved5, ECC, CacheErr, - TagLo, TagHi, ErrorEPC, Reserved6; - } n; - unsigned long r[32]; -} psxCP0Regs; - -typedef struct { - short x, y; -} SVector2D; - -typedef struct { - short z, pad; -} SVector2Dz; - -typedef struct { - short x, y, z, pad; -} SVector3D; - -typedef struct { - short x, y, z, pad; -} LVector3D; - -typedef struct { - unsigned char r, g, b, c; -} CBGR; - -typedef struct { - short m11, m12, m13, m21, m22, m23, m31, m32, m33, pad; -} SMatrix3D; - -typedef union { - struct { - SVector3D v0, v1, v2; - CBGR rgb; - long otz; - long ir0, ir1, ir2, ir3; - SVector2D sxy0, sxy1, sxy2, sxyp; - SVector2Dz sz0, sz1, sz2, sz3; - CBGR rgb0, rgb1, rgb2; - long reserved; - long mac0, mac1, mac2, mac3; - unsigned long irgb, orgb; - long lzcs, lzcr; - } n; - unsigned long r[32]; -} psxCP2Data; - -typedef union { - struct { - SMatrix3D rMatrix; - long trX, trY, trZ; - SMatrix3D lMatrix; - long rbk, gbk, bbk; - SMatrix3D cMatrix; - long rfc, gfc, bfc; - long ofx, ofy; - long h; - long dqa, dqb; - long zsf3, zsf4; - long flag; - } n; - unsigned long r[32]; -} psxCP2Ctrl; - -typedef struct { - psxGPRRegs GPR; /* General Purpose Registers */ - psxCP0Regs CP0; /* Coprocessor0 Registers */ - psxCP2Data CP2D; /* Cop2 data registers */ - psxCP2Ctrl CP2C; /* Cop2 control registers */ - u32 pc; /* Program counter */ - u32 code; /* The instruction */ - u32 cycle; - u32 interrupt; - u32 intCycle[32]; -} psxRegisters; - -psxRegisters psxRegs; - -#define _i32(x) (long)x -#define _u32(x) x - -#define _i16(x) (short)x -#define _u16(x) (unsigned short)x - -#define _i8(x) (char)x -#define _u8(x) (unsigned char)x - -/**** R3000A Instruction Macros ****/ -#define _PC_ psxRegs.pc // The next PC to be executed - -#define _Funct_ ((psxRegs.code ) & 0x3F) // The funct part of the instruction register -#define _Rd_ ((psxRegs.code >> 11) & 0x1F) // The rd part of the instruction register -#define _Rt_ ((psxRegs.code >> 16) & 0x1F) // The rt part of the instruction register -#define _Rs_ ((psxRegs.code >> 21) & 0x1F) // The rs part of the instruction register -#define _Sa_ ((psxRegs.code >> 6) & 0x1F) // The sa part of the instruction register -#define _Im_ ((u16)psxRegs.code) // The immediate part of the instruction register -#define _Target_ (psxRegs.code & 0x03ffffff) // The target part of the instruction register - -#define _Imm_ ((s16)psxRegs.code) // sign-extended immediate -#define _ImmU_ (psxRegs.code&0xffff) // zero-extended immediate - -#define _rRs_ psxRegs.GPR.r[_Rs_] // Rs register -#define _rRt_ psxRegs.GPR.r[_Rt_] // Rt register -#define _rRd_ psxRegs.GPR.r[_Rd_] // Rd register -#define _rSa_ psxRegs.GPR.r[_Sa_] // Sa register -#define _rFs_ psxRegs.CP0.r[_Rd_] // Fs register - -#define _c2dRs_ psxRegs.CP2D.r[_Rs_] // Rs cop2 data register -#define _c2dRt_ psxRegs.CP2D.r[_Rt_] // Rt cop2 data register -#define _c2dRd_ psxRegs.CP2D.r[_Rd_] // Rd cop2 data register -#define _c2dSa_ psxRegs.CP2D.r[_Sa_] // Sa cop2 data register - -#define _rHi_ psxRegs.GPR.n.hi // The HI register -#define _rLo_ psxRegs.GPR.n.lo // The LO register - -#define _JumpTarget_ ((_Target_ * 4) + (_PC_ & 0xf0000000)) // Calculates the target during a jump instruction -#define _BranchTarget_ ((s16)_Im_ * 4 + _PC_) // Calculates the target during a branch instruction - -#define _SetLink(x) psxRegs.GPR.r[x] = _PC_ + 4; // Sets the return address in the link register - -int psxInit(); -void psxReset(); -void psxShutdown(); -void psxException(u32 code, u32 bd); -void psxBranchTest(); -void psxExecuteBios(); - -#endif /* __R3000A_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __R3000A_H__ +#define __R3000A_H__ + +#include + +#include "PsxCommon.h" + +typedef struct { + int (*Init)(); + void (*Reset)(); + void (*Execute)(); /* executes up to a break */ + void (*ExecuteBlock)(); /* executes up to a jump */ + void (*Clear)(u32 Addr, u32 Size); + void (*Shutdown)(); +} R3000Acpu; + +R3000Acpu *psxCpu; +extern R3000Acpu psxInt; +#ifdef __i386__ +extern R3000Acpu psxRec; +#endif + +typedef union { + struct { + unsigned long r0, 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, s8, ra, lo, hi; + } n; + unsigned long r[34]; /* Lo, Hi in r[33] and r[34] */ +} psxGPRRegs; + +typedef union { + struct { + unsigned long Index, Random, EntryLo0, EntryLo1, + Context, PageMask, Wired, Reserved0, + BadVAddr, Count, EntryHi, Compare, + Status, Cause, EPC, PRid, + Config, LLAddr, WatchLO, WatchHI, + XContext, Reserved1, Reserved2, Reserved3, + Reserved4, Reserved5, ECC, CacheErr, + TagLo, TagHi, ErrorEPC, Reserved6; + } n; + unsigned long r[32]; +} psxCP0Regs; + +typedef struct { + short x, y; +} SVector2D; + +typedef struct { + short z, pad; +} SVector2Dz; + +typedef struct { + short x, y, z, pad; +} SVector3D; + +typedef struct { + short x, y, z, pad; +} LVector3D; + +typedef struct { + unsigned char r, g, b, c; +} CBGR; + +typedef struct { + short m11, m12, m13, m21, m22, m23, m31, m32, m33, pad; +} SMatrix3D; + +typedef union { + struct { + SVector3D v0, v1, v2; + CBGR rgb; + long otz; + long ir0, ir1, ir2, ir3; + SVector2D sxy0, sxy1, sxy2, sxyp; + SVector2Dz sz0, sz1, sz2, sz3; + CBGR rgb0, rgb1, rgb2; + long reserved; + long mac0, mac1, mac2, mac3; + unsigned long irgb, orgb; + long lzcs, lzcr; + } n; + unsigned long r[32]; +} psxCP2Data; + +typedef union { + struct { + SMatrix3D rMatrix; + long trX, trY, trZ; + SMatrix3D lMatrix; + long rbk, gbk, bbk; + SMatrix3D cMatrix; + long rfc, gfc, bfc; + long ofx, ofy; + long h; + long dqa, dqb; + long zsf3, zsf4; + long flag; + } n; + unsigned long r[32]; +} psxCP2Ctrl; + +typedef struct { + psxGPRRegs GPR; /* General Purpose Registers */ + psxCP0Regs CP0; /* Coprocessor0 Registers */ + psxCP2Data CP2D; /* Cop2 data registers */ + psxCP2Ctrl CP2C; /* Cop2 control registers */ + u32 pc; /* Program counter */ + u32 code; /* The instruction */ + u32 cycle; + u32 interrupt; + u32 intCycle[32]; +} psxRegisters; + +psxRegisters psxRegs; + +#define _i32(x) (long)x +#define _u32(x) x + +#define _i16(x) (short)x +#define _u16(x) (unsigned short)x + +#define _i8(x) (char)x +#define _u8(x) (unsigned char)x + +/**** R3000A Instruction Macros ****/ +#define _PC_ psxRegs.pc // The next PC to be executed + +#define _Funct_ ((psxRegs.code ) & 0x3F) // The funct part of the instruction register +#define _Rd_ ((psxRegs.code >> 11) & 0x1F) // The rd part of the instruction register +#define _Rt_ ((psxRegs.code >> 16) & 0x1F) // The rt part of the instruction register +#define _Rs_ ((psxRegs.code >> 21) & 0x1F) // The rs part of the instruction register +#define _Sa_ ((psxRegs.code >> 6) & 0x1F) // The sa part of the instruction register +#define _Im_ ((u16)psxRegs.code) // The immediate part of the instruction register +#define _Target_ (psxRegs.code & 0x03ffffff) // The target part of the instruction register + +#define _Imm_ ((s16)psxRegs.code) // sign-extended immediate +#define _ImmU_ (psxRegs.code&0xffff) // zero-extended immediate + +#define _rRs_ psxRegs.GPR.r[_Rs_] // Rs register +#define _rRt_ psxRegs.GPR.r[_Rt_] // Rt register +#define _rRd_ psxRegs.GPR.r[_Rd_] // Rd register +#define _rSa_ psxRegs.GPR.r[_Sa_] // Sa register +#define _rFs_ psxRegs.CP0.r[_Rd_] // Fs register + +#define _c2dRs_ psxRegs.CP2D.r[_Rs_] // Rs cop2 data register +#define _c2dRt_ psxRegs.CP2D.r[_Rt_] // Rt cop2 data register +#define _c2dRd_ psxRegs.CP2D.r[_Rd_] // Rd cop2 data register +#define _c2dSa_ psxRegs.CP2D.r[_Sa_] // Sa cop2 data register + +#define _rHi_ psxRegs.GPR.n.hi // The HI register +#define _rLo_ psxRegs.GPR.n.lo // The LO register + +#define _JumpTarget_ ((_Target_ * 4) + (_PC_ & 0xf0000000)) // Calculates the target during a jump instruction +#define _BranchTarget_ ((s16)_Im_ * 4 + _PC_) // Calculates the target during a branch instruction + +#define _SetLink(x) psxRegs.GPR.r[x] = _PC_ + 4; // Sets the return address in the link register + +int psxInit(); +void psxReset(); +void psxShutdown(); +void psxException(u32 code, u32 bd); +void psxBranchTest(); +void psxExecuteBios(); + +#endif /* __R3000A_H__ */ diff --git a/PcsxSrc/Sio.c b/PcsxSrc/Sio.c index b7cb516..a2cb2a1 100644 --- a/PcsxSrc/Sio.c +++ b/PcsxSrc/Sio.c @@ -1,588 +1,588 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include -#include - -#include "PsxCommon.h" - -#ifdef __WIN32__ -#pragma warning(disable:4244) -#endif - -// *** FOR WORKS ON PADS AND MEMORY CARDS ***** - -static unsigned char buf[256]; -unsigned char cardh[4] = { 0x00, 0x00, 0x5a, 0x5d }; - -//static unsigned short StatReg = 0x002b; -// Transfer(?) Ready and the Buffer is Empty -unsigned short StatReg = TX_RDY | TX_EMPTY; -unsigned short ModeReg; -unsigned short CtrlReg; -unsigned short BaudReg; - -static unsigned long bufcount; -static unsigned long parp; -static unsigned long mcdst,rdwr; -static unsigned char adrH,adrL; -static unsigned long padst; - -PadDataS pad; - -#ifndef strlwr -#include -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 -// 4us * 8bits = ((PSXCLK / 1000000) * 32) / BIAS; (linuzappz) -#define SIO_INT() { \ - if (!Config.Sio) { \ - psxRegs.interrupt |= 0x80; \ - psxRegs.intCycle[7+1] = 200; /*270;*/ \ - psxRegs.intCycle[7] = psxRegs.cycle; \ - } \ -} - -unsigned char sioRead8() { - unsigned char ret = 0; - - if ((StatReg & RX_RDY)/* && (CtrlReg & RX_PERM)*/) { -// StatReg &= ~RX_OVERRUN; - ret = buf[parp]; - if (parp == bufcount) { - StatReg &= ~RX_RDY; // Receive is not Ready now? - StatReg |= TX_EMPTY; // Buffer is Empty - if (mcdst == 5) { - mcdst = 0; - if (rdwr == 2) { - switch (CtrlReg&0x2002) { - case 0x0002: - memcpy(Mcd1Data + (adrL | (adrH << 8)) * 128, &buf[1], 128); - SaveMcd(Config.Mcd1, Mcd1Data, (adrL | (adrH << 8)) * 128, 128); - break; - case 0x2002: - memcpy(Mcd2Data + (adrL | (adrH << 8)) * 128, &buf[1], 128); - SaveMcd(Config.Mcd2, Mcd2Data, (adrL | (adrH << 8)) * 128, 128); - break; - } - } - } - if (padst == 2) padst = 0; - if (mcdst == 1) { - mcdst = 2; - StatReg&= ~TX_EMPTY; - StatReg|= RX_RDY; - } - } - } - -#ifdef PAD_LOG - PAD_LOG("sio read8 ;ret = %x\n", ret); -#endif - return ret; -} - -void sioWrite8(unsigned char value) { -#ifdef PAD_LOG - PAD_LOG("sio write8 %x\n", value); -#endif - switch (padst) { - case 1: SIO_INT(); - if ((value&0x40) == 0x40) { - padst = 2; parp = 1; - switch (CtrlReg&0x2002) { - case 0x0002: - buf[parp] = PAD1_poll(value); - break; - case 0x2002: - buf[parp] = PAD2_poll(value); - break; - } - if (!(buf[parp] & 0x0f)) { - bufcount = 2 + 32; - } else { - bufcount = 2 + (buf[parp] & 0x0f) * 2; - } - if (buf[parp] == 0x41) { - switch (value) { - case 0x43: - buf[1] = 0x43; - break; - case 0x45: - buf[1] = 0xf3; - break; - } - } - } - else padst = 0; - return; - case 2: - parp++; -/* if (buf[1] == 0x45) { - buf[parp] = 0; - SIO_INT(); - return; - }*/ - switch (CtrlReg&0x2002) { - case 0x0002: buf[parp] = PAD1_poll(value); break; - case 0x2002: buf[parp] = PAD2_poll(value); break; - } - if (parp == bufcount) { padst = 0; return; } - SIO_INT(); - return; - } - - switch (mcdst) { - case 1: - SIO_INT(); - if (rdwr) { parp++; return; } - parp = 1; - switch (value) { - case 0x52: rdwr = 1; break; - case 0x57: rdwr = 2; break; - default: mcdst = 0; - } - return; - case 2: // address H - SIO_INT(); - adrH = value; - *buf = 0; - parp = 0; - bufcount = 1; - mcdst = 3; - return; - case 3: // address L - SIO_INT(); - adrL = value; - *buf = adrH; - parp = 0; - bufcount = 1; - mcdst = 4; - return; - case 4: - SIO_INT(); - parp = 0; - switch (rdwr) { - case 1: // read - buf[0] = 0x5c; - buf[1] = 0x5d; - buf[2] = adrH; - buf[3] = adrL; - switch (CtrlReg&0x2002) { - case 0x0002: - memcpy(&buf[4], Mcd1Data + (adrL | (adrH << 8)) * 128, 128); - break; - case 0x2002: - memcpy(&buf[4], Mcd2Data + (adrL | (adrH << 8)) * 128, 128); - break; - } - { - char xor = 0; - int i; - for (i=2;i<128+4;i++) - xor^=buf[i]; - buf[132] = xor; - } - buf[133] = 0x47; - bufcount = 133; - break; - case 2: // write - buf[0] = adrL; - buf[1] = value; - buf[129] = 0x5c; - buf[130] = 0x5d; - buf[131] = 0x47; - bufcount = 131; - break; - } - mcdst = 5; - return; - case 5: - parp++; - if (rdwr == 2) { - if (parp < 128) buf[parp+1] = value; - } - SIO_INT(); - return; - } - - switch (value) { - case 0x01: // start pad - StatReg &= ~TX_EMPTY; // Now the Buffer is not empty - StatReg |= RX_RDY; // Transfer is Ready - - switch (CtrlReg&0x2002) { - case 0x0002: buf[0] = PAD1_startPoll(1); break; - case 0x2002: buf[0] = PAD2_startPoll(2); break; - } - - bufcount = 2; - parp = 0; - padst = 1; - SIO_INT(); - return; - case 0x81: // start memcard - StatReg &= ~TX_EMPTY; - StatReg |= RX_RDY; - memcpy(buf, cardh, 4); - parp = 0; - bufcount = 3; - mcdst = 1; - rdwr = 0; - SIO_INT(); - return; - } -} - -void sioWriteCtrl16(unsigned short value) { - CtrlReg = value & ~RESET_ERR; - if (value & RESET_ERR) StatReg &= ~IRQ; - if ((CtrlReg & SIO_RESET) || (!CtrlReg)) { - padst = 0; mcdst = 0; parp = 0; - StatReg = TX_RDY | TX_EMPTY; - psxRegs.interrupt&=~0x80; - } -} - -void sioInterrupt() { -#ifdef PAD_LOG - PAD_LOG("Sio Interrupt\n"); -#endif - StatReg|= IRQ; - psxHu32(0x1070)|=0x80; -} - -void LoadMcd(int mcd, char *str) { - FILE *f; - char *data = NULL; - - if (mcd == 1) data = Mcd1Data; - if (mcd == 2) data = Mcd2Data; - - if (*str == 0) sprintf(str, "memcards/Mcd00%d.mcr", mcd); - f = fopen(str, "rb"); - if (f == NULL) { - CreateMcd(str); - f = fopen(str, "rb"); - if (f != NULL) { - struct stat buf; - - if (stat(str, &buf) != -1) { - if (buf.st_size == MCD_SIZE + 64) - fseek(f, 64, SEEK_SET); - else if(buf.st_size == MCD_SIZE + 3904) - fseek(f, 3904, SEEK_SET); - } - fread(data, 1, MCD_SIZE, f); - fclose(f); - } - else SysMessage ("Failed loading MemCard %s\n", str); - } - else { - struct stat buf; - - if (stat(str, &buf) != -1) { - if (buf.st_size == MCD_SIZE + 64) - fseek(f, 64, SEEK_SET); - else if(buf.st_size == MCD_SIZE + 3904) - fseek(f, 3904, SEEK_SET); - } - fread(data, 1, MCD_SIZE, f); - fclose(f); - } -} - -void LoadMcds(char *mcd1, char *mcd2) { - LoadMcd(1, mcd1); - LoadMcd(2, mcd2); -} - -void SaveMcd(char *mcd, char *data, unsigned long adr, int size) { - FILE *f; - - f = fopen(mcd, "r+b"); - if (f != NULL) { - struct stat buf; - - if (stat(mcd, &buf) != -1) { - if (buf.st_size == MCD_SIZE + 64) - fseek(f, adr + 64, SEEK_SET); - else if (buf.st_size == MCD_SIZE + 3904) - fseek(f, adr + 3904, SEEK_SET); - else - fseek(f, adr, SEEK_SET); - } else fseek(f, adr, SEEK_SET); - - fwrite(data + adr, 1, size, f); - fclose(f); - return; - } - - // try to create it again if we can't open it - /*f = fopen(mcd, "wb"); - if (f != NULL) { - fwrite(data, 1, MCD_SIZE, f); - fclose(f); - }*/ - ConvertMcd(mcd, data); -} - -void CreateMcd(char *mcd) { - FILE *f; - struct stat buf; - int s = MCD_SIZE; - int i=0; - strlwr(mcd); - - f = fopen(mcd, "wb"); - if (f == NULL) return; - - if(stat(mcd, &buf)!=-1) { - if ((buf.st_size == MCD_SIZE + 3904) || strstr(mcd, ".gme")) { - s = s + 3904; - fputc('1', f); s--; - fputc('2', f); s--; - fputc('3', f); s--; - fputc('-', f); s--; - fputc('4', f); s--; - fputc('5', f); s--; - fputc('6', f); s--; - fputc('-', f); s--; - fputc('S', f); s--; - fputc('T', f); s--; - fputc('D', f); s--; - for(i=0;i<7;i++) { - fputc(0, f); s--; - } - fputc(1, f); s--; - fputc(0, f); s--; - fputc(1, f); s--; - fputc('M', f); s--; - fputc('Q', f); s--; - for(i=0;i<14;i++) { - fputc(0xa0, f); s--; - } - fputc(0, f); s--; - fputc(0xff, f); - while (s-- > (MCD_SIZE+1)) fputc(0, f); - } else if ((buf.st_size == MCD_SIZE + 64) || strstr(mcd, ".mem") || strstr(mcd, ".vgs")) { - s = s + 64; - fputc('V', f); s--; - fputc('g', f); s--; - fputc('s', f); s--; - fputc('M', f); s--; - for(i=0;i<3;i++) { - fputc(1, f); s--; - fputc(0, f); s--; - fputc(0, f); s--; - fputc(0, f); s--; - } - fputc(0, f); s--; - fputc(2, f); - while (s-- > (MCD_SIZE+1)) fputc(0, f); - } - } - fputc('M', f); s--; - fputc('C', f); s--; - while (s-- > (MCD_SIZE-127)) fputc(0, f); - fputc(0xe, f); s--; - while ((s--)>=0) - fputc(0, f); - fclose(f); -} - -void ConvertMcd(char *mcd, char *data) { - FILE *f; - int i=0; - int s = MCD_SIZE; - strlwr(mcd); - - if (strstr(mcd, ".gme")) { - f = fopen(mcd, "wb"); - if (f != NULL) { - fwrite(data-3904, 1, MCD_SIZE+3904, f); - fclose(f); - } - f = fopen(mcd, "r+"); - s = s + 3904; - fputc('1', f); s--; - fputc('2', f); s--; - fputc('3', f); s--; - fputc('-', f); s--; - fputc('4', f); s--; - fputc('5', f); s--; - fputc('6', f); s--; - fputc('-', f); s--; - fputc('S', f); s--; - fputc('T', f); s--; - fputc('D', f); s--; - for(i=0;i<7;i++) { - fputc(0, f); s--; - } - fputc(1, f); s--; - fputc(0, f); s--; - fputc(1, f); s--; - fputc('M', f); s--; - fputc('Q', f); s--; - for(i=0;i<14;i++) { - fputc(0xa0, f); s--; - } - fputc(0, f); s--; - fputc(0xff, f); - while (s-- > (MCD_SIZE+1)) fputc(0, f); - fclose(f); - } else if(strstr(mcd, ".mem") || strstr(mcd,".vgs")) { - f = fopen(mcd, "wb"); - if (f != NULL) { - fwrite(data-64, 1, MCD_SIZE+64, f); - fclose(f); - } - f = fopen(mcd, "r+"); - s = s + 64; - fputc('V', f); s--; - fputc('g', f); s--; - fputc('s', f); s--; - fputc('M', f); s--; - for(i=0;i<3;i++) { - fputc(1, f); s--; - fputc(0, f); s--; - fputc(0, f); s--; - fputc(0, f); s--; - } - fputc(0, f); s--; - fputc(2, f); - while (s-- > (MCD_SIZE+1)) fputc(0, f); - fclose(f); - } else { - f = fopen(mcd, "wb"); - if (f != NULL) { - fwrite(data, 1, MCD_SIZE, f); - fclose(f); - } - } -} - -void GetMcdBlockInfo(int mcd, int block, McdBlock *Info) { - unsigned char *data = NULL, *ptr, *str; - unsigned short clut[16]; - unsigned short c; - int i, x; - - memset(Info, 0, sizeof(McdBlock)); - - str = Info->Title; - - if (mcd == 1) data = Mcd1Data; - if (mcd == 2) data = Mcd2Data; - - ptr = data + block * 8192 + 2; - - Info->IconCount = *ptr & 0x3; - - ptr+= 2; - - i=0; - - for (i=0; i < 48; i++) { - c = *(ptr) << 8; - c|= *(ptr+1); - if (!c) break; - - - if (c >= 0x8281 && c <= 0x8298) - c = (c - 0x8281) + 'a'; - else if (c >= 0x824F && c <= 0x827A) - c = (c - 0x824F) + '0'; - else if (c == 0x8144) c = '.'; - else if (c == 0x8146) c = ':'; - else if (c == 0x8168) c = '"'; - else if (c == 0x8169) c = '('; - else if (c == 0x816A) c = ')'; - else if (c == 0x816D) c = '['; - else if (c == 0x816E) c = ']'; - else if (c == 0x817C) c = '-'; - else { - c = ' '; - } - - str[i] = c; - ptr+=2; - } - str[i] = 0; - - ptr = data + block * 8192 + 0x60; // icon palete data - - for (i=0; i<16; i++) { - clut[i] = *((unsigned short*)ptr); - ptr+=2; - } - - for (i=0; iIconCount; i++) { - short *icon = &Info->Icon[i*16*16]; - - ptr = data + block * 8192 + 128 + 128 * i; // icon data - - for (x=0; x<16*16; x++) { - icon[x++] = clut[*ptr & 0xf]; - icon[x] = clut[*ptr >> 4]; - ptr++; - } - } - - ptr = data + block * 128; - - Info->Flags = *ptr; - - ptr+= 0xa; - strncpy(Info->ID, ptr, 12); - Info->ID[12] = 0; - ptr+= 12; - strcpy(Info->Name, ptr); -} - -int sioFreeze(gzFile f, int Mode) { - char Unused[4096]; - - gzfreezel(buf); - gzfreezel(&StatReg); - gzfreezel(&ModeReg); - gzfreezel(&CtrlReg); - gzfreezel(&BaudReg); - gzfreezel(&bufcount); - gzfreezel(&parp); - gzfreezel(&mcdst); - gzfreezel(&rdwr); - gzfreezel(&adrH); - gzfreezel(&adrL); - gzfreezel(&padst); - gzfreezel(Unused); - - return 0; -} +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include +#include + +#include "PsxCommon.h" + +#ifdef __WIN32__ +#pragma warning(disable:4244) +#endif + +// *** FOR WORKS ON PADS AND MEMORY CARDS ***** + +static unsigned char buf[256]; +unsigned char cardh[4] = { 0x00, 0x00, 0x5a, 0x5d }; + +//static unsigned short StatReg = 0x002b; +// Transfer(?) Ready and the Buffer is Empty +unsigned short StatReg = TX_RDY | TX_EMPTY; +unsigned short ModeReg; +unsigned short CtrlReg; +unsigned short BaudReg; + +static unsigned long bufcount; +static unsigned long parp; +static unsigned long mcdst,rdwr; +static unsigned char adrH,adrL; +static unsigned long padst; + +PadDataS pad; + +#ifndef strlwr +#include +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 +// 4us * 8bits = ((PSXCLK / 1000000) * 32) / BIAS; (linuzappz) +#define SIO_INT() { \ + if (!Config.Sio) { \ + psxRegs.interrupt |= 0x80; \ + psxRegs.intCycle[7+1] = 200; /*270;*/ \ + psxRegs.intCycle[7] = psxRegs.cycle; \ + } \ +} + +unsigned char sioRead8() { + unsigned char ret = 0; + + if ((StatReg & RX_RDY)/* && (CtrlReg & RX_PERM)*/) { +// StatReg &= ~RX_OVERRUN; + ret = buf[parp]; + if (parp == bufcount) { + StatReg &= ~RX_RDY; // Receive is not Ready now? + StatReg |= TX_EMPTY; // Buffer is Empty + if (mcdst == 5) { + mcdst = 0; + if (rdwr == 2) { + switch (CtrlReg&0x2002) { + case 0x0002: + memcpy(Mcd1Data + (adrL | (adrH << 8)) * 128, &buf[1], 128); + SaveMcd(Config.Mcd1, Mcd1Data, (adrL | (adrH << 8)) * 128, 128); + break; + case 0x2002: + memcpy(Mcd2Data + (adrL | (adrH << 8)) * 128, &buf[1], 128); + SaveMcd(Config.Mcd2, Mcd2Data, (adrL | (adrH << 8)) * 128, 128); + break; + } + } + } + if (padst == 2) padst = 0; + if (mcdst == 1) { + mcdst = 2; + StatReg&= ~TX_EMPTY; + StatReg|= RX_RDY; + } + } + } + +#ifdef PAD_LOG + PAD_LOG("sio read8 ;ret = %x\n", ret); +#endif + return ret; +} + +void sioWrite8(unsigned char value) { +#ifdef PAD_LOG + PAD_LOG("sio write8 %x\n", value); +#endif + switch (padst) { + case 1: SIO_INT(); + if ((value&0x40) == 0x40) { + padst = 2; parp = 1; + switch (CtrlReg&0x2002) { + case 0x0002: + buf[parp] = PAD1_poll(value); + break; + case 0x2002: + buf[parp] = PAD2_poll(value); + break; + } + if (!(buf[parp] & 0x0f)) { + bufcount = 2 + 32; + } else { + bufcount = 2 + (buf[parp] & 0x0f) * 2; + } + if (buf[parp] == 0x41) { + switch (value) { + case 0x43: + buf[1] = 0x43; + break; + case 0x45: + buf[1] = 0xf3; + break; + } + } + } + else padst = 0; + return; + case 2: + parp++; +/* if (buf[1] == 0x45) { + buf[parp] = 0; + SIO_INT(); + return; + }*/ + switch (CtrlReg&0x2002) { + case 0x0002: buf[parp] = PAD1_poll(value); break; + case 0x2002: buf[parp] = PAD2_poll(value); break; + } + if (parp == bufcount) { padst = 0; return; } + SIO_INT(); + return; + } + + switch (mcdst) { + case 1: + SIO_INT(); + if (rdwr) { parp++; return; } + parp = 1; + switch (value) { + case 0x52: rdwr = 1; break; + case 0x57: rdwr = 2; break; + default: mcdst = 0; + } + return; + case 2: // address H + SIO_INT(); + adrH = value; + *buf = 0; + parp = 0; + bufcount = 1; + mcdst = 3; + return; + case 3: // address L + SIO_INT(); + adrL = value; + *buf = adrH; + parp = 0; + bufcount = 1; + mcdst = 4; + return; + case 4: + SIO_INT(); + parp = 0; + switch (rdwr) { + case 1: // read + buf[0] = 0x5c; + buf[1] = 0x5d; + buf[2] = adrH; + buf[3] = adrL; + switch (CtrlReg&0x2002) { + case 0x0002: + memcpy(&buf[4], Mcd1Data + (adrL | (adrH << 8)) * 128, 128); + break; + case 0x2002: + memcpy(&buf[4], Mcd2Data + (adrL | (adrH << 8)) * 128, 128); + break; + } + { + char xor = 0; + int i; + for (i=2;i<128+4;i++) + xor^=buf[i]; + buf[132] = xor; + } + buf[133] = 0x47; + bufcount = 133; + break; + case 2: // write + buf[0] = adrL; + buf[1] = value; + buf[129] = 0x5c; + buf[130] = 0x5d; + buf[131] = 0x47; + bufcount = 131; + break; + } + mcdst = 5; + return; + case 5: + parp++; + if (rdwr == 2) { + if (parp < 128) buf[parp+1] = value; + } + SIO_INT(); + return; + } + + switch (value) { + case 0x01: // start pad + StatReg &= ~TX_EMPTY; // Now the Buffer is not empty + StatReg |= RX_RDY; // Transfer is Ready + + switch (CtrlReg&0x2002) { + case 0x0002: buf[0] = PAD1_startPoll(1); break; + case 0x2002: buf[0] = PAD2_startPoll(2); break; + } + + bufcount = 2; + parp = 0; + padst = 1; + SIO_INT(); + return; + case 0x81: // start memcard + StatReg &= ~TX_EMPTY; + StatReg |= RX_RDY; + memcpy(buf, cardh, 4); + parp = 0; + bufcount = 3; + mcdst = 1; + rdwr = 0; + SIO_INT(); + return; + } +} + +void sioWriteCtrl16(unsigned short value) { + CtrlReg = value & ~RESET_ERR; + if (value & RESET_ERR) StatReg &= ~IRQ; + if ((CtrlReg & SIO_RESET) || (!CtrlReg)) { + padst = 0; mcdst = 0; parp = 0; + StatReg = TX_RDY | TX_EMPTY; + psxRegs.interrupt&=~0x80; + } +} + +void sioInterrupt() { +#ifdef PAD_LOG + PAD_LOG("Sio Interrupt\n"); +#endif + StatReg|= IRQ; + psxHu32(0x1070)|=0x80; +} + +void LoadMcd(int mcd, char *str) { + FILE *f; + char *data = NULL; + + if (mcd == 1) data = Mcd1Data; + if (mcd == 2) data = Mcd2Data; + + if (*str == 0) sprintf(str, "memcards/Mcd00%d.mcr", mcd); + f = fopen(str, "rb"); + if (f == NULL) { + CreateMcd(str); + f = fopen(str, "rb"); + if (f != NULL) { + struct stat buf; + + if (stat(str, &buf) != -1) { + if (buf.st_size == MCD_SIZE + 64) + fseek(f, 64, SEEK_SET); + else if(buf.st_size == MCD_SIZE + 3904) + fseek(f, 3904, SEEK_SET); + } + fread(data, 1, MCD_SIZE, f); + fclose(f); + } + else SysMessage ("Failed loading MemCard %s\n", str); + } + else { + struct stat buf; + + if (stat(str, &buf) != -1) { + if (buf.st_size == MCD_SIZE + 64) + fseek(f, 64, SEEK_SET); + else if(buf.st_size == MCD_SIZE + 3904) + fseek(f, 3904, SEEK_SET); + } + fread(data, 1, MCD_SIZE, f); + fclose(f); + } +} + +void LoadMcds(char *mcd1, char *mcd2) { + LoadMcd(1, mcd1); + LoadMcd(2, mcd2); +} + +void SaveMcd(char *mcd, char *data, unsigned long adr, int size) { + FILE *f; + + f = fopen(mcd, "r+b"); + if (f != NULL) { + struct stat buf; + + if (stat(mcd, &buf) != -1) { + if (buf.st_size == MCD_SIZE + 64) + fseek(f, adr + 64, SEEK_SET); + else if (buf.st_size == MCD_SIZE + 3904) + fseek(f, adr + 3904, SEEK_SET); + else + fseek(f, adr, SEEK_SET); + } else fseek(f, adr, SEEK_SET); + + fwrite(data + adr, 1, size, f); + fclose(f); + return; + } + + // try to create it again if we can't open it + /*f = fopen(mcd, "wb"); + if (f != NULL) { + fwrite(data, 1, MCD_SIZE, f); + fclose(f); + }*/ + ConvertMcd(mcd, data); +} + +void CreateMcd(char *mcd) { + FILE *f; + struct stat buf; + int s = MCD_SIZE; + int i=0; + strlwr(mcd); + + f = fopen(mcd, "wb"); + if (f == NULL) return; + + if(stat(mcd, &buf)!=-1) { + if ((buf.st_size == MCD_SIZE + 3904) || strstr(mcd, ".gme")) { + s = s + 3904; + fputc('1', f); s--; + fputc('2', f); s--; + fputc('3', f); s--; + fputc('-', f); s--; + fputc('4', f); s--; + fputc('5', f); s--; + fputc('6', f); s--; + fputc('-', f); s--; + fputc('S', f); s--; + fputc('T', f); s--; + fputc('D', f); s--; + for(i=0;i<7;i++) { + fputc(0, f); s--; + } + fputc(1, f); s--; + fputc(0, f); s--; + fputc(1, f); s--; + fputc('M', f); s--; + fputc('Q', f); s--; + for(i=0;i<14;i++) { + fputc(0xa0, f); s--; + } + fputc(0, f); s--; + fputc(0xff, f); + while (s-- > (MCD_SIZE+1)) fputc(0, f); + } else if ((buf.st_size == MCD_SIZE + 64) || strstr(mcd, ".mem") || strstr(mcd, ".vgs")) { + s = s + 64; + fputc('V', f); s--; + fputc('g', f); s--; + fputc('s', f); s--; + fputc('M', f); s--; + for(i=0;i<3;i++) { + fputc(1, f); s--; + fputc(0, f); s--; + fputc(0, f); s--; + fputc(0, f); s--; + } + fputc(0, f); s--; + fputc(2, f); + while (s-- > (MCD_SIZE+1)) fputc(0, f); + } + } + fputc('M', f); s--; + fputc('C', f); s--; + while (s-- > (MCD_SIZE-127)) fputc(0, f); + fputc(0xe, f); s--; + while ((s--)>=0) + fputc(0, f); + fclose(f); +} + +void ConvertMcd(char *mcd, char *data) { + FILE *f; + int i=0; + int s = MCD_SIZE; + strlwr(mcd); + + if (strstr(mcd, ".gme")) { + f = fopen(mcd, "wb"); + if (f != NULL) { + fwrite(data-3904, 1, MCD_SIZE+3904, f); + fclose(f); + } + f = fopen(mcd, "r+"); + s = s + 3904; + fputc('1', f); s--; + fputc('2', f); s--; + fputc('3', f); s--; + fputc('-', f); s--; + fputc('4', f); s--; + fputc('5', f); s--; + fputc('6', f); s--; + fputc('-', f); s--; + fputc('S', f); s--; + fputc('T', f); s--; + fputc('D', f); s--; + for(i=0;i<7;i++) { + fputc(0, f); s--; + } + fputc(1, f); s--; + fputc(0, f); s--; + fputc(1, f); s--; + fputc('M', f); s--; + fputc('Q', f); s--; + for(i=0;i<14;i++) { + fputc(0xa0, f); s--; + } + fputc(0, f); s--; + fputc(0xff, f); + while (s-- > (MCD_SIZE+1)) fputc(0, f); + fclose(f); + } else if(strstr(mcd, ".mem") || strstr(mcd,".vgs")) { + f = fopen(mcd, "wb"); + if (f != NULL) { + fwrite(data-64, 1, MCD_SIZE+64, f); + fclose(f); + } + f = fopen(mcd, "r+"); + s = s + 64; + fputc('V', f); s--; + fputc('g', f); s--; + fputc('s', f); s--; + fputc('M', f); s--; + for(i=0;i<3;i++) { + fputc(1, f); s--; + fputc(0, f); s--; + fputc(0, f); s--; + fputc(0, f); s--; + } + fputc(0, f); s--; + fputc(2, f); + while (s-- > (MCD_SIZE+1)) fputc(0, f); + fclose(f); + } else { + f = fopen(mcd, "wb"); + if (f != NULL) { + fwrite(data, 1, MCD_SIZE, f); + fclose(f); + } + } +} + +void GetMcdBlockInfo(int mcd, int block, McdBlock *Info) { + unsigned char *data = NULL, *ptr, *str; + unsigned short clut[16]; + unsigned short c; + int i, x; + + memset(Info, 0, sizeof(McdBlock)); + + str = Info->Title; + + if (mcd == 1) data = Mcd1Data; + if (mcd == 2) data = Mcd2Data; + + ptr = data + block * 8192 + 2; + + Info->IconCount = *ptr & 0x3; + + ptr+= 2; + + i=0; + + for (i=0; i < 48; i++) { + c = *(ptr) << 8; + c|= *(ptr+1); + if (!c) break; + + + if (c >= 0x8281 && c <= 0x8298) + c = (c - 0x8281) + 'a'; + else if (c >= 0x824F && c <= 0x827A) + c = (c - 0x824F) + '0'; + else if (c == 0x8144) c = '.'; + else if (c == 0x8146) c = ':'; + else if (c == 0x8168) c = '"'; + else if (c == 0x8169) c = '('; + else if (c == 0x816A) c = ')'; + else if (c == 0x816D) c = '['; + else if (c == 0x816E) c = ']'; + else if (c == 0x817C) c = '-'; + else { + c = ' '; + } + + str[i] = c; + ptr+=2; + } + str[i] = 0; + + ptr = data + block * 8192 + 0x60; // icon palete data + + for (i=0; i<16; i++) { + clut[i] = *((unsigned short*)ptr); + ptr+=2; + } + + for (i=0; iIconCount; i++) { + short *icon = &Info->Icon[i*16*16]; + + ptr = data + block * 8192 + 128 + 128 * i; // icon data + + for (x=0; x<16*16; x++) { + icon[x++] = clut[*ptr & 0xf]; + icon[x] = clut[*ptr >> 4]; + ptr++; + } + } + + ptr = data + block * 128; + + Info->Flags = *ptr; + + ptr+= 0xa; + strncpy(Info->ID, ptr, 12); + Info->ID[12] = 0; + ptr+= 12; + strcpy(Info->Name, ptr); +} + +int sioFreeze(gzFile f, int Mode) { + char Unused[4096]; + + gzfreezel(buf); + gzfreezel(&StatReg); + gzfreezel(&ModeReg); + gzfreezel(&CtrlReg); + gzfreezel(&BaudReg); + gzfreezel(&bufcount); + gzfreezel(&parp); + gzfreezel(&mcdst); + gzfreezel(&rdwr); + gzfreezel(&adrH); + gzfreezel(&adrL); + gzfreezel(&padst); + gzfreezel(Unused); + + return 0; +} diff --git a/PcsxSrc/Sio.h b/PcsxSrc/Sio.h index d458609..99232a6 100644 --- a/PcsxSrc/Sio.h +++ b/PcsxSrc/Sio.h @@ -1,76 +1,76 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - - -#ifndef _SIO_H_ -#define _SIO_H_ - -#define MCD_SIZE (1024 * 8 * 16) - -// Status Flags -#define TX_RDY 0x0001 -#define RX_RDY 0x0002 -#define TX_EMPTY 0x0004 -#define PARITY_ERR 0x0008 -#define RX_OVERRUN 0x0010 -#define FRAMING_ERR 0x0020 -#define SYNC_DETECT 0x0040 -#define DSR 0x0080 -#define CTS 0x0100 -#define IRQ 0x0200 - -// Control Flags -#define TX_PERM 0x0001 -#define DTR 0x0002 -#define RX_PERM 0x0004 -#define BREAK 0x0008 -#define RESET_ERR 0x0010 -#define RTS 0x0020 -#define SIO_RESET 0x0040 - -extern unsigned short StatReg; -extern unsigned short ModeReg; -extern unsigned short CtrlReg; -extern unsigned short BaudReg; - -extern char Mcd1Data[MCD_SIZE], Mcd2Data[MCD_SIZE]; - -unsigned char sioRead8(); -void sioWrite8(unsigned char value); -void sioWriteCtrl16(unsigned short value); -void sioInterrupt(); -int sioFreeze(gzFile f, int Mode); - -void LoadMcd(int mcd, char *str); -void LoadMcds(char *mcd1, char *mcd2); -void SaveMcd(char *mcd, char *data, unsigned long adr, int size); -void CreateMcd(char *mcd); -void ConvertMcd(char *mcd, char *data); - -typedef struct { - char Title[48]; - char ID[14]; - char Name[16]; - int IconCount; - short Icon[16*16*3]; - unsigned char Flags; -} McdBlock; - -void GetMcdBlockInfo(int mcd, int block, McdBlock *info); - -#endif +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + + +#ifndef _SIO_H_ +#define _SIO_H_ + +#define MCD_SIZE (1024 * 8 * 16) + +// Status Flags +#define TX_RDY 0x0001 +#define RX_RDY 0x0002 +#define TX_EMPTY 0x0004 +#define PARITY_ERR 0x0008 +#define RX_OVERRUN 0x0010 +#define FRAMING_ERR 0x0020 +#define SYNC_DETECT 0x0040 +#define DSR 0x0080 +#define CTS 0x0100 +#define IRQ 0x0200 + +// Control Flags +#define TX_PERM 0x0001 +#define DTR 0x0002 +#define RX_PERM 0x0004 +#define BREAK 0x0008 +#define RESET_ERR 0x0010 +#define RTS 0x0020 +#define SIO_RESET 0x0040 + +extern unsigned short StatReg; +extern unsigned short ModeReg; +extern unsigned short CtrlReg; +extern unsigned short BaudReg; + +extern char Mcd1Data[MCD_SIZE], Mcd2Data[MCD_SIZE]; + +unsigned char sioRead8(); +void sioWrite8(unsigned char value); +void sioWriteCtrl16(unsigned short value); +void sioInterrupt(); +int sioFreeze(gzFile f, int Mode); + +void LoadMcd(int mcd, char *str); +void LoadMcds(char *mcd1, char *mcd2); +void SaveMcd(char *mcd, char *data, unsigned long adr, int size); +void CreateMcd(char *mcd); +void ConvertMcd(char *mcd, char *data); + +typedef struct { + char Title[48]; + char ID[14]; + char Name[16]; + int IconCount; + short Icon[16*16*3]; + unsigned char Flags; +} McdBlock; + +void GetMcdBlockInfo(int mcd, int block, McdBlock *info); + +#endif diff --git a/PcsxSrc/Spu.c b/PcsxSrc/Spu.c index 1ecae13..4622116 100644 --- a/PcsxSrc/Spu.c +++ b/PcsxSrc/Spu.c @@ -1,23 +1,23 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 "PsxCommon.h" - -void CALLBACK SPUirq(void) { - psxHu32(0x1070)|=0x200; -} +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 "PsxCommon.h" + +void CALLBACK SPUirq(void) { + psxHu32(0x1070)|=0x200; +} diff --git a/PcsxSrc/Spu.h b/PcsxSrc/Spu.h index ea620ca..58e884a 100644 --- a/PcsxSrc/Spu.h +++ b/PcsxSrc/Spu.h @@ -1,36 +1,36 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __SPU_H__ -#define __SPU_H__ - -#include "plugins.h" - -#define H_SPUirqAddr 0x0da4 -#define H_SPUaddr 0x0da6 -#define H_SPUdata 0x0da8 -#define H_SPUctrl 0x0daa -#define H_SPUstat 0x0dae -#define H_SPUon1 0x0d88 -#define H_SPUon2 0x0d8a -#define H_SPUoff1 0x0d8c -#define H_SPUoff2 0x0d8e - -void CALLBACK SPUirq(void); - -#endif /* __SPU_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __SPU_H__ +#define __SPU_H__ + +#include "plugins.h" + +#define H_SPUirqAddr 0x0da4 +#define H_SPUaddr 0x0da6 +#define H_SPUdata 0x0da8 +#define H_SPUctrl 0x0daa +#define H_SPUstat 0x0dae +#define H_SPUon1 0x0d88 +#define H_SPUon2 0x0d8a +#define H_SPUoff1 0x0d8c +#define H_SPUoff2 0x0d8e + +void CALLBACK SPUirq(void); + +#endif /* __SPU_H__ */ diff --git a/PcsxSrc/System.h b/PcsxSrc/System.h index 383ca58..52d7573 100644 --- a/PcsxSrc/System.h +++ b/PcsxSrc/System.h @@ -1,34 +1,34 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __SYSTEM_H__ -#define __SYSTEM_H__ - -int SysInit(); // Init mem and plugins -void SysReset(); // Resets mem -void SysPrintf(char *fmt, ...); // Printf used by bios syscalls -void SysMessage(char *fmt, ...); // Message used to print msg to users -void *SysLoadLibrary(char *lib); // Loads Library -void *SysLoadSym(void *lib, char *sym); // Loads Symbol from Library -char *SysLibError(); // Gets previous error loading sysbols -void SysCloseLibrary(void *lib); // Closes Library -void SysUpdate(); // Called on VBlank (to update i.e. pads) -void SysRunGui(); // Returns to the Gui -void SysClose(); // Close mem and plugins - -#endif /* __SYSTEM_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __SYSTEM_H__ +#define __SYSTEM_H__ + +int SysInit(); // Init mem and plugins +void SysReset(); // Resets mem +void SysPrintf(char *fmt, ...); // Printf used by bios syscalls +void SysMessage(char *fmt, ...); // Message used to print msg to users +void *SysLoadLibrary(char *lib); // Loads Library +void *SysLoadSym(void *lib, char *sym); // Loads Symbol from Library +char *SysLibError(); // Gets previous error loading sysbols +void SysCloseLibrary(void *lib); // Closes Library +void SysUpdate(); // Called on VBlank (to update i.e. pads) +void SysRunGui(); // Returns to the Gui +void SysClose(); // Close mem and plugins + +#endif /* __SYSTEM_H__ */ diff --git a/PcsxSrc/Win32/AboutDlg.c b/PcsxSrc/Win32/AboutDlg.c index 0a93fae..b476396 100644 --- a/PcsxSrc/Win32/AboutDlg.c +++ b/PcsxSrc/Win32/AboutDlg.c @@ -1,44 +1,44 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include "resource.h" -#include "AboutDlg.h" - -LRESULT WINAPI AboutDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - switch(uMsg) - { - case WM_INITDIALOG: - { - Static_SetText(GetDlgItem(hDlg, IDC_PCSX_ABOUT_TEXT), "P©SX EMU\nVersion " PCSX_VERSION); - return TRUE; - } - - case WM_COMMAND: - switch(wParam) - { - case IDOK: - EndDialog(hDlg, TRUE ); - return TRUE; - } - break; - } - return FALSE; -} +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include "resource.h" +#include "AboutDlg.h" + +LRESULT WINAPI AboutDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch(uMsg) + { + case WM_INITDIALOG: + { + Static_SetText(GetDlgItem(hDlg, IDC_PCSX_ABOUT_TEXT), "P©SX EMU\nVersion " PCSX_VERSION); + return TRUE; + } + + case WM_COMMAND: + switch(wParam) + { + case IDOK: + EndDialog(hDlg, TRUE ); + return TRUE; + } + break; + } + return FALSE; +} diff --git a/PcsxSrc/Win32/AboutDlg.h b/PcsxSrc/Win32/AboutDlg.h index 4c71245..c85456d 100644 --- a/PcsxSrc/Win32/AboutDlg.h +++ b/PcsxSrc/Win32/AboutDlg.h @@ -1,24 +1,24 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef _PCSX_ABOUTDLG_H_ -#define _PCSX_ABOUTDLG_H_ - -LRESULT WINAPI AboutDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); - +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef _PCSX_ABOUTDLG_H_ +#define _PCSX_ABOUTDLG_H_ + +LRESULT WINAPI AboutDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); + #endif \ No newline at end of file diff --git a/PcsxSrc/Win32/ConfigurePlugins.c b/PcsxSrc/Win32/ConfigurePlugins.c index 5399dc1..76cb189 100644 --- a/PcsxSrc/Win32/ConfigurePlugins.c +++ b/PcsxSrc/Win32/ConfigurePlugins.c @@ -1,471 +1,471 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include -#include "PsxCommon.h" -#include "plugin.h" -#include "resource.h" -#include "Win32.h" - -#define QueryKeyV(s, name, var) \ - size = s; \ - if (RegQueryValueEx(myKey, name, 0, &type, (LPBYTE) var, &size) != 0) { if (err) { RegCloseKey(myKey); return -1; } } - -#define SetKeyV(name, var, s, t) \ - RegSetValueEx(myKey, name, 0, t, (LPBYTE) var, s); - -int LoadConfig() { - HKEY myKey; - DWORD type,size; - PcsxConfig *Conf = &Config; - int err; - - if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Pcsx",0,KEY_ALL_ACCESS,&myKey)!=ERROR_SUCCESS) return -1; - - err = 1; - QueryKeyV(256, "Bios", Conf->Bios); - QueryKeyV(256, "Gpu", Conf->Gpu); - QueryKeyV(256, "Spu", Conf->Spu); - QueryKeyV(256, "Cdr", Conf->Cdr); - QueryKeyV(256, "Pad1", Conf->Pad1); - QueryKeyV(256, "Pad2", Conf->Pad2); - QueryKeyV(256, "Mcd1", Conf->Mcd1); - QueryKeyV(256, "Mcd2", Conf->Mcd2); - QueryKeyV(256, "PluginsDir", Conf->PluginsDir); - QueryKeyV(256, "BiosDir", Conf->BiosDir); - err = 0; - QueryKeyV(sizeof(Conf->Xa), "Xa", &Conf->Xa); - QueryKeyV(sizeof(Conf->Sio), "Sio", &Conf->Sio); - QueryKeyV(sizeof(Conf->Mdec), "Mdec", &Conf->Mdec); - QueryKeyV(sizeof(Conf->PsxAuto), "PsxAuto", &Conf->PsxAuto); - QueryKeyV(sizeof(Conf->PsxType), "PsxType", &Conf->PsxType); - QueryKeyV(sizeof(Conf->QKeys), "QKeys", &Conf->QKeys); - QueryKeyV(sizeof(Conf->Cdda), "Cdda", &Conf->Cdda); - QueryKeyV(sizeof(Conf->Cpu), "Cpu", &Conf->Cpu); - QueryKeyV(sizeof(Conf->PsxOut), "PsxOut", &Conf->PsxOut); - QueryKeyV(sizeof(Conf->SpuIrq), "SpuIrq", &Conf->SpuIrq); - QueryKeyV(sizeof(Conf->CdTiming),"CdTiming",&Conf->CdTiming); - - RegCloseKey(myKey); - - return 0; -} - -///////////////////////////////////////////////////////// - -void SaveConfig() { - HKEY myKey; - DWORD myDisp; - PcsxConfig *Conf = &Config; - - RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Pcsx",0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&myKey,&myDisp); - - SetKeyV("Bios", Conf->Bios, strlen(Conf->Bios), REG_SZ); - SetKeyV("Gpu", Conf->Gpu, strlen(Conf->Gpu), REG_SZ); - SetKeyV("Spu", Conf->Spu, strlen(Conf->Spu), REG_SZ); - SetKeyV("Cdr", Conf->Cdr, strlen(Conf->Cdr), REG_SZ); - SetKeyV("Pad1", Conf->Pad1, strlen(Conf->Pad1), REG_SZ); - SetKeyV("Pad2", Conf->Pad2, strlen(Conf->Pad2), REG_SZ); - SetKeyV("Mcd1", Conf->Mcd1, strlen(Conf->Mcd1), REG_SZ); - SetKeyV("Mcd2", Conf->Mcd2, strlen(Conf->Mcd2), REG_SZ); - SetKeyV("PluginsDir", Conf->PluginsDir, strlen(Conf->PluginsDir), REG_SZ); - SetKeyV("BiosDir", Conf->BiosDir, strlen(Conf->BiosDir), REG_SZ); - SetKeyV("Xa", &Conf->Xa, sizeof(Conf->Xa), REG_DWORD); - SetKeyV("Sio", &Conf->Sio, sizeof(Conf->Sio), REG_DWORD); - SetKeyV("Mdec", &Conf->Mdec, sizeof(Conf->Mdec), REG_DWORD); - SetKeyV("PsxAuto", &Conf->PsxAuto, sizeof(Conf->PsxAuto), REG_DWORD); - SetKeyV("PsxType", &Conf->PsxType, sizeof(Conf->PsxType), REG_DWORD); - SetKeyV("QKeys", &Conf->QKeys, sizeof(Conf->QKeys), REG_DWORD); - SetKeyV("Cdda", &Conf->Cdda, sizeof(Conf->Cdda), REG_DWORD); - SetKeyV("Cpu", &Conf->Cpu, sizeof(Conf->Cpu), REG_DWORD); - SetKeyV("PsxOut", &Conf->PsxOut, sizeof(Conf->PsxOut), REG_DWORD); - SetKeyV("SpuIrq", &Conf->SpuIrq, sizeof(Conf->SpuIrq), REG_DWORD); - SetKeyV("CdTiming",&Conf->CdTiming,sizeof(Conf->SpuIrq), REG_DWORD); - - RegCloseKey(myKey); -} - -///////////////////////////////////////////////////////// - -#define ComboAddPlugin(hw, str) { \ - lp = (char *)malloc(strlen(FindData.cFileName)+8); \ - sprintf(lp, "%s", FindData.cFileName); \ - i = ComboBox_AddString(hw, tmpStr); \ - ComboBox_SetItemData(hw, i, lp); \ - if (stricmp(str, lp)==0) \ - ComboBox_SetCurSel(hw, i); \ -} - -BOOL OnConfigurePluginsDialog(HWND hW) { - WIN32_FIND_DATA FindData; - HANDLE Find; - HANDLE Lib; - PSEgetLibType PSE_GetLibType; - PSEgetLibName PSE_GetLibName; - PSEgetLibVersion PSE_GetLibVersion; - HWND hWC_GPU=GetDlgItem(hW,IDC_LISTGPU); - HWND hWC_SPU=GetDlgItem(hW,IDC_LISTSPU); - HWND hWC_CDR=GetDlgItem(hW,IDC_LISTCDR); - HWND hWC_PAD1=GetDlgItem(hW,IDC_LISTPAD1); - HWND hWC_PAD2=GetDlgItem(hW,IDC_LISTPAD2); - HWND hWC_BIOS=GetDlgItem(hW,IDC_LISTBIOS); - char tmpStr[256]; - char *lp; - int i; - - strcpy(tmpStr, Config.PluginsDir); - strcat(tmpStr, "*.dll"); - Find = FindFirstFile(tmpStr, &FindData); - - do { - if (Find==INVALID_HANDLE_VALUE) break; - sprintf(tmpStr,"%s%s", Config.PluginsDir, FindData.cFileName); - Lib = LoadLibrary(tmpStr); - if (Lib!=NULL) { - PSE_GetLibType = (PSEgetLibType) GetProcAddress((HMODULE)Lib,"PSEgetLibType"); - PSE_GetLibName = (PSEgetLibName) GetProcAddress((HMODULE)Lib,"PSEgetLibName"); - PSE_GetLibVersion = (PSEgetLibVersion) GetProcAddress((HMODULE)Lib,"PSEgetLibVersion"); - - if (PSE_GetLibType != NULL && PSE_GetLibName != NULL && PSE_GetLibVersion != NULL) { - unsigned long version = PSE_GetLibVersion(); - long type; - - sprintf(tmpStr, "%s %d.%d", PSE_GetLibName(), (version>>8)&0xff, version&0xff); - type = PSE_GetLibType(); - if (type & PSE_LT_CDR) { - ComboAddPlugin(hWC_CDR, Config.Cdr); - } - - if (type & PSE_LT_SPU) { - ComboAddPlugin(hWC_SPU, Config.Spu); - } - - if (type & PSE_LT_GPU) { - ComboAddPlugin(hWC_GPU, Config.Gpu); - } - - if (type & PSE_LT_PAD) { - PADquery query; - - query = (PADquery)GetProcAddress((HMODULE)Lib, "PADquery"); - if (query() & 0x1) - ComboAddPlugin(hWC_PAD1, Config.Pad1); - if (query() & 0x2) - ComboAddPlugin(hWC_PAD2, Config.Pad2); - } - } - } - } while (FindNextFile(Find,&FindData)); - - if (Find!=INVALID_HANDLE_VALUE) FindClose(Find); - -// BIOS - - lp=(char *)malloc(strlen("HLE") + 1); - sprintf(lp, "HLE"); - i=ComboBox_AddString(hWC_BIOS, "Internal HLE Bios"); - ComboBox_SetItemData(hWC_BIOS, i, lp); - if (stricmp(Config.Bios, lp)==0) - ComboBox_SetCurSel(hWC_BIOS, i); - - strcpy(tmpStr, Config.BiosDir); - strcat(tmpStr, "*"); - Find=FindFirstFile(tmpStr, &FindData); - - do { - if (Find==INVALID_HANDLE_VALUE) break; - if (!strcmp(FindData.cFileName, ".")) continue; - if (!strcmp(FindData.cFileName, "..")) continue; - if (FindData.nFileSizeLow != 1024 * 512) continue; - lp = (char *)malloc(strlen(FindData.cFileName)+8); - sprintf(lp, "%s", (char *)FindData.cFileName); - i = ComboBox_AddString(hWC_BIOS, FindData.cFileName); - ComboBox_SetItemData(hWC_BIOS, i, lp); - if (stricmp(Config.Bios, FindData.cFileName)==0) - ComboBox_SetCurSel(hWC_BIOS, i); - } while (FindNextFile(Find,&FindData)); - - if (Find!=INVALID_HANDLE_VALUE) FindClose(Find); - - if (ComboBox_GetCurSel(hWC_CDR ) == -1) - ComboBox_SetCurSel(hWC_CDR, 0); - if (ComboBox_GetCurSel(hWC_GPU ) == -1) - ComboBox_SetCurSel(hWC_GPU, 0); - if (ComboBox_GetCurSel(hWC_SPU ) == -1) - ComboBox_SetCurSel(hWC_SPU, 0); - if (ComboBox_GetCurSel(hWC_PAD1) == -1) - ComboBox_SetCurSel(hWC_PAD1, 0); - if (ComboBox_GetCurSel(hWC_PAD2) == -1) - ComboBox_SetCurSel(hWC_PAD2, 0); - if (ComboBox_GetCurSel(hWC_BIOS) == -1) - ComboBox_SetCurSel(hWC_BIOS, 0); - - return TRUE; -} - -#define CleanCombo(item) \ - hWC = GetDlgItem(hW, item); \ - iCnt = ComboBox_GetCount(hWC); \ - for (i=0; i - -int SelectPath(HWND hW, char *Title, char *Path) { - LPITEMIDLIST pidl; - BROWSEINFO bi; - char Buffer[256]; - - bi.hwndOwner = hW; - bi.pidlRoot = NULL; - bi.pszDisplayName = Buffer; - bi.lpszTitle = Title; - bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS; - bi.lpfn = NULL; - bi.lParam = 0; - if ((pidl = SHBrowseForFolder(&bi)) != NULL) { - if (SHGetPathFromIDList(pidl, Path)) { - int len = strlen(Path); - - if (Path[len - 1] != '\\') { strcat(Path,"\\"); } - return 0; - } - } - return -1; -} - -void SetPluginsDir(HWND hW) { - char Path[256]; - - if (SelectPath(hW, "Select Plugins Directory", Path) == -1) return; - strcpy(Config.PluginsDir, Path); - CleanUpCombos(hW); - OnConfigurePluginsDialog(hW); -} - -void SetBiosDir(HWND hW) { - char Path[256]; - - if (SelectPath(hW, "Select Bios Directory", Path) == -1) return; - strcpy(Config.BiosDir, Path); - CleanUpCombos(hW); - OnConfigurePluginsDialog(hW); -} - -BOOL CALLBACK ConfigurePluginsDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch(uMsg) { - case WM_INITDIALOG: - return OnConfigurePluginsDialog(hW); - - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_CONFIGGPU: ConfigureGPU(hW); return TRUE; - case IDC_CONFIGSPU: ConfigureSPU(hW); return TRUE; - case IDC_CONFIGCDR: ConfigureCDR(hW); return TRUE; - case IDC_CONFIGPAD1: ConfigurePAD1(hW); return TRUE; - case IDC_CONFIGPAD2: ConfigurePAD2(hW); return TRUE; - - case IDC_TESTGPU: TestGPU(hW); return TRUE; - case IDC_TESTSPU: TestSPU(hW); return TRUE; - case IDC_TESTCDR: TestCDR(hW); return TRUE; - case IDC_TESTPAD1: TestPAD1(hW); return TRUE; - case IDC_TESTPAD2: TestPAD2(hW); return TRUE; - - case IDC_ABOUTGPU: AboutGPU(hW); return TRUE; - case IDC_ABOUTSPU: AboutSPU(hW); return TRUE; - case IDC_ABOUTCDR: AboutCDR(hW); return TRUE; - case IDC_ABOUTPAD1: AboutPAD1(hW); return TRUE; - case IDC_ABOUTPAD2: AboutPAD2(hW); return TRUE; - - case IDC_PLUGINSDIR: SetPluginsDir(hW); return TRUE; - case IDC_BIOSDIR: SetBiosDir(hW); return TRUE; - - case IDCANCEL: OnCancel(hW); return TRUE; - case IDOK: OnOK(hW); return TRUE; - } - } - return FALSE; -} - - -void ConfigurePlugins(HWND hWnd) { - DialogBox(gApp.hInstance, - MAKEINTRESOURCE(IDD_CONFIG), - hWnd, - (DLGPROC)ConfigurePluginsDlgProc); -} - +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include +#include "PsxCommon.h" +#include "plugin.h" +#include "resource.h" +#include "Win32.h" + +#define QueryKeyV(s, name, var) \ + size = s; \ + if (RegQueryValueEx(myKey, name, 0, &type, (LPBYTE) var, &size) != 0) { if (err) { RegCloseKey(myKey); return -1; } } + +#define SetKeyV(name, var, s, t) \ + RegSetValueEx(myKey, name, 0, t, (LPBYTE) var, s); + +int LoadConfig() { + HKEY myKey; + DWORD type,size; + PcsxConfig *Conf = &Config; + int err; + + if (RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Pcsx",0,KEY_ALL_ACCESS,&myKey)!=ERROR_SUCCESS) return -1; + + err = 1; + QueryKeyV(256, "Bios", Conf->Bios); + QueryKeyV(256, "Gpu", Conf->Gpu); + QueryKeyV(256, "Spu", Conf->Spu); + QueryKeyV(256, "Cdr", Conf->Cdr); + QueryKeyV(256, "Pad1", Conf->Pad1); + QueryKeyV(256, "Pad2", Conf->Pad2); + QueryKeyV(256, "Mcd1", Conf->Mcd1); + QueryKeyV(256, "Mcd2", Conf->Mcd2); + QueryKeyV(256, "PluginsDir", Conf->PluginsDir); + QueryKeyV(256, "BiosDir", Conf->BiosDir); + err = 0; + QueryKeyV(sizeof(Conf->Xa), "Xa", &Conf->Xa); + QueryKeyV(sizeof(Conf->Sio), "Sio", &Conf->Sio); + QueryKeyV(sizeof(Conf->Mdec), "Mdec", &Conf->Mdec); + QueryKeyV(sizeof(Conf->PsxAuto), "PsxAuto", &Conf->PsxAuto); + QueryKeyV(sizeof(Conf->PsxType), "PsxType", &Conf->PsxType); + QueryKeyV(sizeof(Conf->QKeys), "QKeys", &Conf->QKeys); + QueryKeyV(sizeof(Conf->Cdda), "Cdda", &Conf->Cdda); + QueryKeyV(sizeof(Conf->Cpu), "Cpu", &Conf->Cpu); + QueryKeyV(sizeof(Conf->PsxOut), "PsxOut", &Conf->PsxOut); + QueryKeyV(sizeof(Conf->SpuIrq), "SpuIrq", &Conf->SpuIrq); + QueryKeyV(sizeof(Conf->CdTiming),"CdTiming",&Conf->CdTiming); + + RegCloseKey(myKey); + + return 0; +} + +///////////////////////////////////////////////////////// + +void SaveConfig() { + HKEY myKey; + DWORD myDisp; + PcsxConfig *Conf = &Config; + + RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Pcsx",0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&myKey,&myDisp); + + SetKeyV("Bios", Conf->Bios, strlen(Conf->Bios), REG_SZ); + SetKeyV("Gpu", Conf->Gpu, strlen(Conf->Gpu), REG_SZ); + SetKeyV("Spu", Conf->Spu, strlen(Conf->Spu), REG_SZ); + SetKeyV("Cdr", Conf->Cdr, strlen(Conf->Cdr), REG_SZ); + SetKeyV("Pad1", Conf->Pad1, strlen(Conf->Pad1), REG_SZ); + SetKeyV("Pad2", Conf->Pad2, strlen(Conf->Pad2), REG_SZ); + SetKeyV("Mcd1", Conf->Mcd1, strlen(Conf->Mcd1), REG_SZ); + SetKeyV("Mcd2", Conf->Mcd2, strlen(Conf->Mcd2), REG_SZ); + SetKeyV("PluginsDir", Conf->PluginsDir, strlen(Conf->PluginsDir), REG_SZ); + SetKeyV("BiosDir", Conf->BiosDir, strlen(Conf->BiosDir), REG_SZ); + SetKeyV("Xa", &Conf->Xa, sizeof(Conf->Xa), REG_DWORD); + SetKeyV("Sio", &Conf->Sio, sizeof(Conf->Sio), REG_DWORD); + SetKeyV("Mdec", &Conf->Mdec, sizeof(Conf->Mdec), REG_DWORD); + SetKeyV("PsxAuto", &Conf->PsxAuto, sizeof(Conf->PsxAuto), REG_DWORD); + SetKeyV("PsxType", &Conf->PsxType, sizeof(Conf->PsxType), REG_DWORD); + SetKeyV("QKeys", &Conf->QKeys, sizeof(Conf->QKeys), REG_DWORD); + SetKeyV("Cdda", &Conf->Cdda, sizeof(Conf->Cdda), REG_DWORD); + SetKeyV("Cpu", &Conf->Cpu, sizeof(Conf->Cpu), REG_DWORD); + SetKeyV("PsxOut", &Conf->PsxOut, sizeof(Conf->PsxOut), REG_DWORD); + SetKeyV("SpuIrq", &Conf->SpuIrq, sizeof(Conf->SpuIrq), REG_DWORD); + SetKeyV("CdTiming",&Conf->CdTiming,sizeof(Conf->SpuIrq), REG_DWORD); + + RegCloseKey(myKey); +} + +///////////////////////////////////////////////////////// + +#define ComboAddPlugin(hw, str) { \ + lp = (char *)malloc(strlen(FindData.cFileName)+8); \ + sprintf(lp, "%s", FindData.cFileName); \ + i = ComboBox_AddString(hw, tmpStr); \ + ComboBox_SetItemData(hw, i, lp); \ + if (stricmp(str, lp)==0) \ + ComboBox_SetCurSel(hw, i); \ +} + +BOOL OnConfigurePluginsDialog(HWND hW) { + WIN32_FIND_DATA FindData; + HANDLE Find; + HANDLE Lib; + PSEgetLibType PSE_GetLibType; + PSEgetLibName PSE_GetLibName; + PSEgetLibVersion PSE_GetLibVersion; + HWND hWC_GPU=GetDlgItem(hW,IDC_LISTGPU); + HWND hWC_SPU=GetDlgItem(hW,IDC_LISTSPU); + HWND hWC_CDR=GetDlgItem(hW,IDC_LISTCDR); + HWND hWC_PAD1=GetDlgItem(hW,IDC_LISTPAD1); + HWND hWC_PAD2=GetDlgItem(hW,IDC_LISTPAD2); + HWND hWC_BIOS=GetDlgItem(hW,IDC_LISTBIOS); + char tmpStr[256]; + char *lp; + int i; + + strcpy(tmpStr, Config.PluginsDir); + strcat(tmpStr, "*.dll"); + Find = FindFirstFile(tmpStr, &FindData); + + do { + if (Find==INVALID_HANDLE_VALUE) break; + sprintf(tmpStr,"%s%s", Config.PluginsDir, FindData.cFileName); + Lib = LoadLibrary(tmpStr); + if (Lib!=NULL) { + PSE_GetLibType = (PSEgetLibType) GetProcAddress((HMODULE)Lib,"PSEgetLibType"); + PSE_GetLibName = (PSEgetLibName) GetProcAddress((HMODULE)Lib,"PSEgetLibName"); + PSE_GetLibVersion = (PSEgetLibVersion) GetProcAddress((HMODULE)Lib,"PSEgetLibVersion"); + + if (PSE_GetLibType != NULL && PSE_GetLibName != NULL && PSE_GetLibVersion != NULL) { + unsigned long version = PSE_GetLibVersion(); + long type; + + sprintf(tmpStr, "%s %d.%d", PSE_GetLibName(), (version>>8)&0xff, version&0xff); + type = PSE_GetLibType(); + if (type & PSE_LT_CDR) { + ComboAddPlugin(hWC_CDR, Config.Cdr); + } + + if (type & PSE_LT_SPU) { + ComboAddPlugin(hWC_SPU, Config.Spu); + } + + if (type & PSE_LT_GPU) { + ComboAddPlugin(hWC_GPU, Config.Gpu); + } + + if (type & PSE_LT_PAD) { + PADquery query; + + query = (PADquery)GetProcAddress((HMODULE)Lib, "PADquery"); + if (query() & 0x1) + ComboAddPlugin(hWC_PAD1, Config.Pad1); + if (query() & 0x2) + ComboAddPlugin(hWC_PAD2, Config.Pad2); + } + } + } + } while (FindNextFile(Find,&FindData)); + + if (Find!=INVALID_HANDLE_VALUE) FindClose(Find); + +// BIOS + + lp=(char *)malloc(strlen("HLE") + 1); + sprintf(lp, "HLE"); + i=ComboBox_AddString(hWC_BIOS, "Internal HLE Bios"); + ComboBox_SetItemData(hWC_BIOS, i, lp); + if (stricmp(Config.Bios, lp)==0) + ComboBox_SetCurSel(hWC_BIOS, i); + + strcpy(tmpStr, Config.BiosDir); + strcat(tmpStr, "*"); + Find=FindFirstFile(tmpStr, &FindData); + + do { + if (Find==INVALID_HANDLE_VALUE) break; + if (!strcmp(FindData.cFileName, ".")) continue; + if (!strcmp(FindData.cFileName, "..")) continue; + if (FindData.nFileSizeLow != 1024 * 512) continue; + lp = (char *)malloc(strlen(FindData.cFileName)+8); + sprintf(lp, "%s", (char *)FindData.cFileName); + i = ComboBox_AddString(hWC_BIOS, FindData.cFileName); + ComboBox_SetItemData(hWC_BIOS, i, lp); + if (stricmp(Config.Bios, FindData.cFileName)==0) + ComboBox_SetCurSel(hWC_BIOS, i); + } while (FindNextFile(Find,&FindData)); + + if (Find!=INVALID_HANDLE_VALUE) FindClose(Find); + + if (ComboBox_GetCurSel(hWC_CDR ) == -1) + ComboBox_SetCurSel(hWC_CDR, 0); + if (ComboBox_GetCurSel(hWC_GPU ) == -1) + ComboBox_SetCurSel(hWC_GPU, 0); + if (ComboBox_GetCurSel(hWC_SPU ) == -1) + ComboBox_SetCurSel(hWC_SPU, 0); + if (ComboBox_GetCurSel(hWC_PAD1) == -1) + ComboBox_SetCurSel(hWC_PAD1, 0); + if (ComboBox_GetCurSel(hWC_PAD2) == -1) + ComboBox_SetCurSel(hWC_PAD2, 0); + if (ComboBox_GetCurSel(hWC_BIOS) == -1) + ComboBox_SetCurSel(hWC_BIOS, 0); + + return TRUE; +} + +#define CleanCombo(item) \ + hWC = GetDlgItem(hW, item); \ + iCnt = ComboBox_GetCount(hWC); \ + for (i=0; i + +int SelectPath(HWND hW, char *Title, char *Path) { + LPITEMIDLIST pidl; + BROWSEINFO bi; + char Buffer[256]; + + bi.hwndOwner = hW; + bi.pidlRoot = NULL; + bi.pszDisplayName = Buffer; + bi.lpszTitle = Title; + bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS; + bi.lpfn = NULL; + bi.lParam = 0; + if ((pidl = SHBrowseForFolder(&bi)) != NULL) { + if (SHGetPathFromIDList(pidl, Path)) { + int len = strlen(Path); + + if (Path[len - 1] != '\\') { strcat(Path,"\\"); } + return 0; + } + } + return -1; +} + +void SetPluginsDir(HWND hW) { + char Path[256]; + + if (SelectPath(hW, "Select Plugins Directory", Path) == -1) return; + strcpy(Config.PluginsDir, Path); + CleanUpCombos(hW); + OnConfigurePluginsDialog(hW); +} + +void SetBiosDir(HWND hW) { + char Path[256]; + + if (SelectPath(hW, "Select Bios Directory", Path) == -1) return; + strcpy(Config.BiosDir, Path); + CleanUpCombos(hW); + OnConfigurePluginsDialog(hW); +} + +BOOL CALLBACK ConfigurePluginsDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { + switch(uMsg) { + case WM_INITDIALOG: + return OnConfigurePluginsDialog(hW); + + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDC_CONFIGGPU: ConfigureGPU(hW); return TRUE; + case IDC_CONFIGSPU: ConfigureSPU(hW); return TRUE; + case IDC_CONFIGCDR: ConfigureCDR(hW); return TRUE; + case IDC_CONFIGPAD1: ConfigurePAD1(hW); return TRUE; + case IDC_CONFIGPAD2: ConfigurePAD2(hW); return TRUE; + + case IDC_TESTGPU: TestGPU(hW); return TRUE; + case IDC_TESTSPU: TestSPU(hW); return TRUE; + case IDC_TESTCDR: TestCDR(hW); return TRUE; + case IDC_TESTPAD1: TestPAD1(hW); return TRUE; + case IDC_TESTPAD2: TestPAD2(hW); return TRUE; + + case IDC_ABOUTGPU: AboutGPU(hW); return TRUE; + case IDC_ABOUTSPU: AboutSPU(hW); return TRUE; + case IDC_ABOUTCDR: AboutCDR(hW); return TRUE; + case IDC_ABOUTPAD1: AboutPAD1(hW); return TRUE; + case IDC_ABOUTPAD2: AboutPAD2(hW); return TRUE; + + case IDC_PLUGINSDIR: SetPluginsDir(hW); return TRUE; + case IDC_BIOSDIR: SetBiosDir(hW); return TRUE; + + case IDCANCEL: OnCancel(hW); return TRUE; + case IDOK: OnOK(hW); return TRUE; + } + } + return FALSE; +} + + +void ConfigurePlugins(HWND hWnd) { + DialogBox(gApp.hInstance, + MAKEINTRESOURCE(IDD_CONFIG), + hWnd, + (DLGPROC)ConfigurePluginsDlgProc); +} + diff --git a/PcsxSrc/Win32/Win32.h b/PcsxSrc/Win32/Win32.h index 77954ad..75e35f9 100644 --- a/PcsxSrc/Win32/Win32.h +++ b/PcsxSrc/Win32/Win32.h @@ -1,48 +1,48 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __WIN32_H__ -#define __WIN32_H__ - -AppData gApp; -HANDLE hConsole; - -long LoadCdBios; -extern int StatesC; -extern int AccBreak; -extern int NeedReset; -extern int ConfPlug; -int Running; -char PcsxDir[256]; - -LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM); -BOOL CALLBACK ConfigureMcdsDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam); -BOOL CALLBACK ConfigureCpuDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam); - -void ConfigurePlugins(HWND hWnd); - -int Open_File_Proc(char *file); -void Open_Mcd_Proc(HWND hW, int MCDID); -void CreateMainWindow(int nCmdShow); -void RunGui(); -void PADhandleKey(int key); - -int LoadConfig(); -void SaveConfig(); - +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __WIN32_H__ +#define __WIN32_H__ + +AppData gApp; +HANDLE hConsole; + +long LoadCdBios; +extern int StatesC; +extern int AccBreak; +extern int NeedReset; +extern int ConfPlug; +int Running; +char PcsxDir[256]; + +LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM); +BOOL CALLBACK ConfigureMcdsDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam); +BOOL CALLBACK ConfigureCpuDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam); + +void ConfigurePlugins(HWND hWnd); + +int Open_File_Proc(char *file); +void Open_Mcd_Proc(HWND hW, int MCDID); +void CreateMainWindow(int nCmdShow); +void RunGui(); +void PADhandleKey(int key); + +int LoadConfig(); +void SaveConfig(); + #endif /* __WIN32_H__ */ \ No newline at end of file diff --git a/PcsxSrc/Win32/WndMain.c b/PcsxSrc/Win32/WndMain.c index eaeab13..dde28da 100644 --- a/PcsxSrc/Win32/WndMain.c +++ b/PcsxSrc/Win32/WndMain.c @@ -1,1044 +1,1044 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include -#include -#include -#include -#include - -#include "resource.h" -#include "AboutDlg.h" - -#include "PsxCommon.h" -#include "plugin.h" -#include "Debug.h" -#include "Win32.h" - -int AccBreak=0; -int ConfPlug=0; -int StatesC=0; -int NeedReset=1; -int cdOpenCase=0; - -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - gApp.hInstance = hInstance; - - Running=0; - - GetCurrentDirectory(256, PcsxDir); - - memset(&Config, 0, sizeof(PcsxConfig)); - if (LoadConfig() == -1) { - Config.PsxAuto = 1; - strcpy(Config.PluginsDir, "Plugin\\"); - strcpy(Config.BiosDir, "Bios\\"); - SysMessage("Pcsx needs to be configured"); - ConfPlug=1; - ConfigurePlugins(gApp.hWnd); - DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_MCDCONF), gApp.hWnd, (DLGPROC)ConfigureMcdsDlgProc); - SysMessage("Pcsx now will quit, restart it"); - return 0; - } - - if (SysInit() == -1) return 1; - - CreateMainWindow(nCmdShow); - - RunGui(); - - return 0; -} - -void RunGui() { - MSG msg; - - PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE); - - for (;;) { - if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } -} - -void OpenConsole() { - if (hConsole) return; - AllocConsole(); - SetConsoleTitle("Psx Output"); - hConsole = GetStdHandle(STD_OUTPUT_HANDLE); -} - -void CloseConsole() { - FreeConsole(); hConsole = NULL; -} - -LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - char File[256]; - - switch (msg) { - case WM_COMMAND: - switch (LOWORD(wParam)) { - case ID_FILE_EXIT: - SysClose(); - PostQuitMessage(0); - exit(0); - return TRUE; - - case ID_FILE_RUN_CD: - LoadCdBios = 0; - SetMenu(hWnd, NULL); - OpenPlugins(hWnd); - SysReset(); - NeedReset = 0; - CheckCdrom(); - if (LoadCdrom() == -1) { - ClosePlugins(); - AccBreak = 1; - DestroyWindow(gApp.hWnd); - CreateMainWindow(SW_SHOWNORMAL); - SetMenu(gApp.hWnd, gApp.hMenu); - SetCursor(LoadCursor(gApp.hInstance, IDC_ARROW)); - ShowCursor(TRUE); - SysMessage("Could not load Cdrom\n"); - return TRUE; - } - ShowCursor(FALSE); - Running = 1; - psxCpu->Execute(); - return TRUE; - - case ID_FILE_RUNCDBIOS: - LoadCdBios = 1; - SetMenu(hWnd, NULL); - OpenPlugins(hWnd); - ShowCursor(FALSE); - CheckCdrom(); - SysReset(); - NeedReset = 0; - Running = 1; - psxCpu->Execute(); - return TRUE; - - case ID_FILE_RUN_EXE: - if (!Open_File_Proc(File)) return TRUE; - SetMenu(hWnd, NULL); - OpenPlugins(hWnd); - SysReset(); - NeedReset = 0; - Load(File); - Running = 1; - psxCpu->Execute(); - return TRUE; - - case ID_EMULATOR_RUN: - SetMenu(hWnd, NULL); - OpenPlugins(hWnd); - ShowCursor(FALSE); - if (NeedReset) { SysReset(); NeedReset = 0; } - Running = 1; - psxCpu->Execute(); - return TRUE; - - case ID_EMULATOR_RESET: - NeedReset = 1; - return TRUE; - - case ID_CONFIGURATION_GRAPHICS: - GPU_configure(); - return TRUE; - - case ID_CONFIGURATION_SOUND: - SPU_configure(); - return TRUE; - - case ID_CONFIGURATION_CONTROLLERS: - PAD1_configure(); - if (strcmp(Config.Pad1, Config.Pad2)) PAD2_configure(); - return TRUE; - - case ID_CONFIGURATION_CDROM: - CDR_configure(); - return TRUE; - - case ID_CONFIGURATION_MEMORYCARDMANAGER: - DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_MCDCONF), hWnd, (DLGPROC)ConfigureMcdsDlgProc); - return TRUE; - - case ID_CONFIGURATION_CPU: - DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_CPUCONF), hWnd, (DLGPROC)ConfigureCpuDlgProc); - return TRUE; - - case ID_CONFIGURATION: - ConfigurePlugins(hWnd); - return TRUE; - - case ID_HELP_HELP: - ShellExecute(NULL, "open", "Readme.txt", NULL, NULL, SW_SHOWNORMAL); - return TRUE; - - case ID_HELP_ABOUT: - DialogBox(gApp.hInstance, MAKEINTRESOURCE(ABOUT_DIALOG), hWnd, (DLGPROC)AboutDlgProc); - return TRUE; - } - break; - - case WM_SYSKEYDOWN: - if (wParam != VK_F10) - return DefWindowProc(hWnd, msg, wParam, lParam); - case WM_KEYDOWN: - PADhandleKey(wParam); - return TRUE; - - case WM_DESTROY: - if (!AccBreak) { - if (Running) ClosePlugins(); - SysClose(); - PostQuitMessage(0); - exit(0); - } - else AccBreak = 0; - - return TRUE; - - case WM_CREATE: - gApp.hMenu = LoadMenu(gApp.hInstance, MAKEINTRESOURCE(IDR_MENU1)); - SetMenu(hWnd, gApp.hMenu); - break; - - case WM_QUIT: - exit(0); - break; - - default: - return DefWindowProc(hWnd, msg, wParam, lParam); - } - - return FALSE; -} - -HWND mcdDlg; -McdBlock Blocks[2][15]; -int IconC[2][15]; -HIMAGELIST Iiml[2]; -HICON eICON; - -void CreateListView(int idc) { - HWND List; - LV_COLUMN col; - - List = GetDlgItem(mcdDlg, idc); - - col.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; - col.fmt = LVCFMT_LEFT; - - col.pszText = "Title"; - col.cx = 170; - col.iSubItem = 0; - - ListView_InsertColumn(List, 0, &col); - - col.pszText = "Status"; - col.cx = 50; - col.iSubItem = 1; - - ListView_InsertColumn(List, 1, &col); - - col.pszText = "Game ID"; - col.cx = 90; - col.iSubItem = 2; - - ListView_InsertColumn(List, 2, &col); - - col.pszText = "Game"; - col.cx = 80; - col.iSubItem = 3; - - ListView_InsertColumn(List, 3, &col); -} - -int GetRGB() { - HDC scrDC, memDC; - HBITMAP oldBmp = NULL; - HBITMAP curBmp = NULL; - COLORREF oldColor; - COLORREF curColor = RGB(255,255,255); - int i, R, G, B; - - R = G = B = 1; - - scrDC = CreateDC("DISPLAY", NULL, NULL, NULL); - memDC = CreateCompatibleDC(NULL); - curBmp = CreateCompatibleBitmap(scrDC, 1, 1); - oldBmp = (HBITMAP)SelectObject(memDC, curBmp); - - for (i = 255; i >= 0; --i) { - oldColor = curColor; - curColor = SetPixel(memDC, 0, 0, RGB(i, i, i)); - - if (GetRValue(curColor) < GetRValue(oldColor)) ++R; - if (GetGValue(curColor) < GetGValue(oldColor)) ++G; - if (GetBValue(curColor) < GetBValue(oldColor)) ++B; - } - - DeleteObject(oldBmp); - DeleteObject(curBmp); - DeleteDC(scrDC); - DeleteDC(memDC); - - return (R * G * B); -} - -HICON GetIcon(short *icon) { - ICONINFO iInfo; - HDC hDC; - char mask[16*16]; - int x, y, c, Depth; - - hDC = CreateIC("DISPLAY",NULL,NULL,NULL); - Depth=GetDeviceCaps(hDC, BITSPIXEL); - DeleteDC(hDC); - - if (Depth == 16) { - if (GetRGB() == (32 * 32 * 32)) - Depth = 15; - } - - for (y=0; y<16; y++) { - for (x=0; x<16; x++) { - c = icon[y*16+x]; - if (Depth == 15) - c = ((c&0x001f) << 10) | ((c&0x7c00) >> 10) | (c&0x03e0); - else - c = (c&0x001f) | ((c&0x7c00) << 1) | ((c&0x03e0) << 1); - - icon[y*16+x] = c; - } - } - - iInfo.fIcon = TRUE; - memset(mask, 0, 16*16); - iInfo.hbmMask = CreateBitmap(16, 16, 1, 1, mask); - iInfo.hbmColor = CreateBitmap(16, 16, 1, 16, icon); - - return CreateIconIndirect(&iInfo); -} - -HICON hICON[2][3][15]; -int aIover[2]; -int ani[2]; - -void LoadMcdItems(int mcd, int idc) { - HWND List = GetDlgItem(mcdDlg, idc); - LV_ITEM item; - HIMAGELIST iml = Iiml[mcd-1]; - int i, j; - HICON hIcon; - McdBlock *Info; - - aIover[mcd-1]=0; - ani[mcd-1]=0; - - ListView_DeleteAllItems(List); - - for (i=0; i<15; i++) { - - item.mask = LVIF_TEXT | LVIF_IMAGE; - item.iItem = i; - item.iImage = i; - item.pszText = LPSTR_TEXTCALLBACK; - item.iSubItem = 0; - - IconC[mcd-1][i] = 0; - Info = &Blocks[mcd-1][i]; - - if ((Info->Flags & 0xF) == 1 && Info->IconCount != 0) { - hIcon = GetIcon(Info->Icon); - - if (Info->IconCount > 1) { - for(j = 0; j < 3; j++) - hICON[mcd-1][j][i]=hIcon; - } - } else { - hIcon = eICON; - } - - ImageList_ReplaceIcon(iml, -1, hIcon); - ListView_InsertItem(List, &item); - } -} - -void UpdateMcdItems(int mcd, int idc) { - HWND List = GetDlgItem(mcdDlg, idc); - LV_ITEM item; - HIMAGELIST iml = Iiml[mcd-1]; - int i, j; - McdBlock *Info; - HICON hIcon; - - aIover[mcd-1]=0; - ani[mcd-1]=0; - - for (i=0; i<15; i++) { - - item.mask = LVIF_TEXT | LVIF_IMAGE; - item.iItem = i; - item.iImage = i; - item.pszText = LPSTR_TEXTCALLBACK; - item.iSubItem = 0; - - IconC[mcd-1][i] = 0; - Info = &Blocks[mcd-1][i]; - - if ((Info->Flags & 0xF) == 1 && Info->IconCount != 0) { - hIcon = GetIcon(Info->Icon); - - if (Info->IconCount > 1) { - for(j = 0; j < 3; j++) - hICON[mcd-1][j][i]=hIcon; - } - } else { - hIcon = eICON; - } - - ImageList_ReplaceIcon(iml, i, hIcon); - ListView_SetItem(List, &item); - } - ListView_Update(List, -1); -} - -void McdListGetDispInfo(int mcd, int idc, LPNMHDR pnmh) { - LV_DISPINFO *lpdi = (LV_DISPINFO *)pnmh; - McdBlock *Info; - - Info = &Blocks[mcd-1][lpdi->item.iItem]; - - switch (lpdi->item.iSubItem) { - case 0: - switch (Info->Flags & 0xF) { - case 1: - lpdi->item.pszText = Info->Title; - break; - case 2: - lpdi->item.pszText = "mid link block"; - break; - case 3: - lpdi->item.pszText = "terminiting link block"; - break; - } - break; - case 1: - if ((Info->Flags & 0xF0) == 0xA0) { - if ((Info->Flags & 0xF) >= 1 && - (Info->Flags & 0xF) <= 3) { - lpdi->item.pszText = "Deleted"; - } else lpdi->item.pszText = "Free"; - } else if ((Info->Flags & 0xF0) == 0x50) - lpdi->item.pszText = "Used"; - else { lpdi->item.pszText = "Free"; } - break; - case 2: - if((Info->Flags & 0xF)==1) - lpdi->item.pszText = Info->ID; - break; - case 3: - if((Info->Flags & 0xF)==1) - lpdi->item.pszText = Info->Name; - break; - } -} - -void McdListNotify(int mcd, int idc, LPNMHDR pnmh) { - switch (pnmh->code) { - case LVN_GETDISPINFO: McdListGetDispInfo(mcd, idc, pnmh); break; - } -} - -void UpdateMcdDlg() { - int i; - - for (i=1; i<16; i++) GetMcdBlockInfo(1, i, &Blocks[0][i-1]); - for (i=1; i<16; i++) GetMcdBlockInfo(2, i, &Blocks[1][i-1]); - UpdateMcdItems(1, IDC_LIST1); - UpdateMcdItems(2, IDC_LIST2); -} - -void LoadMcdDlg() { - int i; - - for (i=1; i<16; i++) GetMcdBlockInfo(1, i, &Blocks[0][i-1]); - for (i=1; i<16; i++) GetMcdBlockInfo(2, i, &Blocks[1][i-1]); - LoadMcdItems(1, IDC_LIST1); - LoadMcdItems(2, IDC_LIST2); -} - -void UpdateMcdIcon(int mcd, int idc) { - HWND List = GetDlgItem(mcdDlg, idc); - HIMAGELIST iml = Iiml[mcd-1]; - int i; - McdBlock *Info; - int *count; - - if(!aIover[mcd-1]) { - ani[mcd-1]++; - - for (i=0; i<15; i++) { - Info = &Blocks[mcd-1][i]; - count = &IconC[mcd-1][i]; - - if ((Info->Flags & 0xF) != 1) continue; - if (Info->IconCount <= 1) continue; - - if (*count < Info->IconCount) { - (*count)++; - aIover[mcd-1]=0; - - if(ani[mcd-1] <= (Info->IconCount-1)) // last frame and below... - hICON[mcd-1][ani[mcd-1]][i] = GetIcon(&Info->Icon[(*count)*16*16]); - } else { - aIover[mcd-1]=1; - } - } - - } else { - - if (ani[mcd-1] > 1) ani[mcd-1] = 0; // 1st frame - else ani[mcd-1]++; // 2nd, 3rd frame - - for(i=0;i<15;i++) { -// RECT rect, hrect; - - Info = &Blocks[mcd-1][i]; - - if (((Info->Flags & 0xF) == 1) && (Info->IconCount > 1)) - ImageList_ReplaceIcon(iml, i, hICON[mcd-1][ani[mcd-1]][i]); - -/* GetWindowRect(List, &hrect); - ListView_GetItemRect(List, i, &rect, LVIR_ICON); - rect.left+= hrect.left; rect.right+= hrect.left; - rect.top+= hrect.top; rect.bottom+= hrect.top; - -// rect.left-= 12; rect.right-= 12; // quick fix - - InvalidateRect(mcdDlg, &rect, FALSE);*/ - } - ListView_Update(List, 0); - } -} - -static int copy = 0, copymcd = 0; -static int listsel = 0; - -BOOL CALLBACK ConfigureMcdsDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { - char str[256]; - LPBYTE lpAND, lpXOR; - LPBYTE lpA, lpX; - int i, j; - - switch(uMsg) { - case WM_INITDIALOG: - mcdDlg = hW; - - lpA=lpAND=(LPBYTE)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(16*16)); - lpX=lpXOR=(LPBYTE)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(16*16)); - - for(i=0;i<16;i++) - { - for(j=0;j<16;j++) - { - *lpA++=0xff; - *lpX++=0; - } - } - eICON=CreateIcon(gApp.hInstance,16,16,1,1,lpAND,lpXOR); - - HeapFree(GetProcessHeap(),0,lpAND); - HeapFree(GetProcessHeap(),0,lpXOR); - - if (!strlen(Config.Mcd1)) strcpy(Config.Mcd1, "memcards\\Mcd001.mcr"); - if (!strlen(Config.Mcd2)) strcpy(Config.Mcd2, "memcards\\Mcd002.mcr"); - Edit_SetText(GetDlgItem(hW,IDC_MCD1), Config.Mcd1); - Edit_SetText(GetDlgItem(hW,IDC_MCD2), Config.Mcd2); - - CreateListView(IDC_LIST1); - CreateListView(IDC_LIST2); - - Iiml[0] = ImageList_Create(16, 16, ILC_COLOR16, 0, 0); - Iiml[1] = ImageList_Create(16, 16, ILC_COLOR16, 0, 0); - - ListView_SetImageList(GetDlgItem(mcdDlg, IDC_LIST1), Iiml[0], LVSIL_SMALL); - ListView_SetImageList(GetDlgItem(mcdDlg, IDC_LIST2), Iiml[1], LVSIL_SMALL); - - Button_Enable(GetDlgItem(hW, IDC_PASTE), FALSE); - - LoadMcdDlg(); - - SetTimer(hW, 1, 250, NULL); - - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_COPYTO1: - copy = ListView_GetSelectionMark(GetDlgItem(mcdDlg, IDC_LIST2)); - copymcd = 1; - - Button_Enable(GetDlgItem(hW, IDC_PASTE), TRUE); - return TRUE; - case IDC_COPYTO2: - copy = ListView_GetSelectionMark(GetDlgItem(mcdDlg, IDC_LIST1)); - copymcd = 2; - - Button_Enable(GetDlgItem(hW, IDC_PASTE), TRUE); - return TRUE; - case IDC_PASTE: - if (MessageBox(hW, "Are you sure you want to paste this selection?", "Confirmation", MB_YESNO) == IDNO) return TRUE; - - if (copymcd == 1) { - Edit_GetText(GetDlgItem(hW,IDC_MCD1), str, 256); - i = ListView_GetSelectionMark(GetDlgItem(mcdDlg, IDC_LIST1)); - - // save dir data + save data - memcpy(Mcd1Data + (i+1) * 128, Mcd2Data + (copy+1) * 128, 128); - SaveMcd(str, Mcd1Data, (i+1) * 128, 128); - memcpy(Mcd1Data + (i+1) * 1024 * 8, Mcd2Data + (copy+1) * 1024 * 8, 1024 * 8); - SaveMcd(str, Mcd1Data, (i+1) * 1024 * 8, 1024 * 8); - } else { // 2 - Edit_GetText(GetDlgItem(hW,IDC_MCD2), str, 256); - i = ListView_GetSelectionMark(GetDlgItem(mcdDlg, IDC_LIST2)); - - // save dir data + save data - memcpy(Mcd2Data + (i+1) * 128, Mcd1Data + (copy+1) * 128, 128); - SaveMcd(str, Mcd2Data, (i+1) * 128, 128); - memcpy(Mcd2Data + (i+1) * 1024 * 8, Mcd1Data + (copy+1) * 1024 * 8, 1024 * 8); - SaveMcd(str, Mcd2Data, (i+1) * 1024 * 8, 1024 * 8); - } - - UpdateMcdDlg(); - - return TRUE; - case IDC_DELETE1: - { - McdBlock *Info; - int mcd = 1; - int i, xor = 0, j; - unsigned char *data, *ptr; - - Edit_GetText(GetDlgItem(hW,IDC_MCD1), str, 256); - i = ListView_GetSelectionMark(GetDlgItem(mcdDlg, IDC_LIST1)); - data = Mcd1Data; - - i++; - - ptr = data + i * 128; - - Info = &Blocks[mcd-1][i-1]; - - if ((Info->Flags & 0xF0) == 0xA0) { - if ((Info->Flags & 0xF) >= 1 && - (Info->Flags & 0xF) <= 3) { // deleted - *ptr = 0x50 | (Info->Flags & 0xF); - } else return TRUE; - } else if ((Info->Flags & 0xF0) == 0x50) { // used - *ptr = 0xA0 | (Info->Flags & 0xF); - } else { return TRUE; } - - for (j=0; j<127; j++) xor^=*ptr++; - *ptr = xor; - - SaveMcd(str, data, i * 128, 128); - UpdateMcdDlg(); - } - - return TRUE; - case IDC_DELETE2: - { - McdBlock *Info; - int mcd = 2; - int i, xor = 0, j; - unsigned char *data, *ptr; - - Edit_GetText(GetDlgItem(hW,IDC_MCD2), str, 256); - i = ListView_GetSelectionMark(GetDlgItem(mcdDlg, IDC_LIST2)); - data = Mcd2Data; - - i++; - - ptr = data + i * 128; - - Info = &Blocks[mcd-1][i-1]; - - if ((Info->Flags & 0xF0) == 0xA0) { - if ((Info->Flags & 0xF) >= 1 && - (Info->Flags & 0xF) <= 3) { // deleted - *ptr = 0x50 | (Info->Flags & 0xF); - } else return TRUE; - } else if ((Info->Flags & 0xF0) == 0x50) { // used - *ptr = 0xA0 | (Info->Flags & 0xF); - } else { return TRUE; } - - for (j=0; j<127; j++) xor^=*ptr++; - *ptr = xor; - - SaveMcd(str, data, i * 128, 128); - UpdateMcdDlg(); - } - - return TRUE; - - case IDC_MCDSEL1: - Open_Mcd_Proc(hW, 1); - return TRUE; - case IDC_MCDSEL2: - Open_Mcd_Proc(hW, 2); - return TRUE; - case IDC_RELOAD1: - Edit_GetText(GetDlgItem(hW,IDC_MCD1), str, 256); - LoadMcd(1, str); - UpdateMcdDlg(); - return TRUE; - case IDC_RELOAD2: - Edit_GetText(GetDlgItem(hW,IDC_MCD2), str, 256); - LoadMcd(2, str); - UpdateMcdDlg(); - return TRUE; - case IDC_FORMAT1: - if (MessageBox(hW, "Are you sure you want to format this Memory Card?", "Confirmation", MB_YESNO) == IDNO) return TRUE; - Edit_GetText(GetDlgItem(hW,IDC_MCD1), str, 256); - CreateMcd(str); - LoadMcd(1, str); - UpdateMcdDlg(); - return TRUE; - case IDC_FORMAT2: - if (MessageBox(hW, "Are you sure you want to format this Memory Card?", "Confirmation", MB_YESNO) == IDNO) return TRUE; - Edit_GetText(GetDlgItem(hW,IDC_MCD2), str, 256); - CreateMcd(str); - LoadMcd(2, str); - UpdateMcdDlg(); - return TRUE; - case IDCANCEL: - LoadMcds(Config.Mcd1, Config.Mcd2); - - EndDialog(hW,FALSE); - - return TRUE; - case IDOK: - Edit_GetText(GetDlgItem(hW,IDC_MCD1), Config.Mcd1, 256); - Edit_GetText(GetDlgItem(hW,IDC_MCD2), Config.Mcd2, 256); - - LoadMcds(Config.Mcd1, Config.Mcd2); - SaveConfig(); - - EndDialog(hW,TRUE); - - return TRUE; - } - case WM_NOTIFY: - switch (wParam) { - case IDC_LIST1: McdListNotify(1, IDC_LIST1, (LPNMHDR)lParam); break; - case IDC_LIST2: McdListNotify(2, IDC_LIST2, (LPNMHDR)lParam); break; - } - return TRUE; - case WM_TIMER: - UpdateMcdIcon(1, IDC_LIST1); - UpdateMcdIcon(2, IDC_LIST2); - return TRUE; - case WM_DESTROY: - DestroyIcon(eICON); - //KillTimer(hW, 1); - return TRUE; - } - return FALSE; -} - -BOOL CALLBACK ConfigureCpuDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { - long tmp; - - switch(uMsg) { - case WM_INITDIALOG: - Button_SetCheck(GetDlgItem(hW,IDC_XA), Config.Xa); - Button_SetCheck(GetDlgItem(hW,IDC_SIO), Config.Sio); - Button_SetCheck(GetDlgItem(hW,IDC_MDEC), Config.Mdec); - Button_SetCheck(GetDlgItem(hW,IDC_QKEYS), Config.QKeys); - Button_SetCheck(GetDlgItem(hW,IDC_CDDA), Config.Cdda); - Button_SetCheck(GetDlgItem(hW,IDC_PSXAUTO), Config.PsxAuto); - Button_SetCheck(GetDlgItem(hW,IDC_CPU), Config.Cpu); - Button_SetCheck(GetDlgItem(hW,IDC_PSXOUT), Config.PsxOut); - Button_SetCheck(GetDlgItem(hW,IDC_SPUIRQ), Config.SpuIrq); - Button_SetCheck(GetDlgItem(hW,IDC_CDTIMING),Config.CdTiming); - ComboBox_AddString(GetDlgItem(hW,IDC_PSXTYPES),"NTSC"); - ComboBox_AddString(GetDlgItem(hW,IDC_PSXTYPES),"PAL"); - ComboBox_SetCurSel(GetDlgItem(hW,IDC_PSXTYPES),Config.PsxType); - - case WM_COMMAND: { - switch (LOWORD(wParam)) { - case IDCANCEL: EndDialog(hW,FALSE); return TRUE; - case IDOK: - tmp = ComboBox_GetCurSel(GetDlgItem(hW,IDC_PSXTYPES)); - if (tmp == 0) Config.PsxType = 0; - else Config.PsxType = 1; - - Config.Xa = Button_GetCheck(GetDlgItem(hW,IDC_XA)); - Config.Sio = Button_GetCheck(GetDlgItem(hW,IDC_SIO)); - Config.Mdec = Button_GetCheck(GetDlgItem(hW,IDC_MDEC)); - Config.QKeys = Button_GetCheck(GetDlgItem(hW,IDC_QKEYS)); - Config.Cdda = Button_GetCheck(GetDlgItem(hW,IDC_CDDA)); - Config.PsxAuto = Button_GetCheck(GetDlgItem(hW,IDC_PSXAUTO)); - tmp = Config.Cpu; - Config.Cpu = Button_GetCheck(GetDlgItem(hW,IDC_CPU)); - if (tmp != Config.Cpu) { - psxCpu->Shutdown(); - if (Config.Cpu) - psxCpu = &psxInt; - else psxCpu = &psxRec; - if (psxCpu->Init() == -1) { - SysClose(); - exit(1); - } - psxCpu->Reset(); - } - Config.PsxOut = Button_GetCheck(GetDlgItem(hW,IDC_PSXOUT)); - Config.SpuIrq = Button_GetCheck(GetDlgItem(hW,IDC_SPUIRQ)); - Config.CdTiming= Button_GetCheck(GetDlgItem(hW,IDC_CDTIMING)); - - SaveConfig(); - - EndDialog(hW,TRUE); - - if (Config.PsxOut) OpenConsole(); - else CloseConsole(); - - return TRUE; - } - } - } - return FALSE; -} - -#define MAXFILENAME 256 - -void Open_Mcd_Proc(HWND hW, int mcd) { - OPENFILENAME ofn; - char szFileName[MAXFILENAME]; - char szFileTitle[MAXFILENAME]; - - memset(&szFileName, 0, sizeof(szFileName)); - memset(&szFileTitle, 0, sizeof(szFileTitle)); - - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = hW; - ofn.lpstrFilter = "Psx Mcd Format (*.mcr;*.mc;*.mem;*.vgs;*.mcd;*.gme;*.ddf)\0*.mcr;*.mcd;*.mem;*.gme;*.mc;*.ddf\0Psx Memory Card (*.mcr;*.mc)\0*.mcr;0*.mc\0CVGS Memory Card (*.mem;*.vgs)\0*.mem;*.vgs\0Bleem Memory Card (*.mcd)\0*.mcd\0DexDrive Memory Card (*.gme)\0*.gme\0DataDeck Memory Card (*.ddf)\0*.ddf\0";; - ofn.lpstrCustomFilter = NULL; - ofn.nMaxCustFilter = 0; - ofn.nFilterIndex = 1; - ofn.lpstrFile = szFileName; - ofn.nMaxFile = MAXFILENAME; - ofn.lpstrInitialDir = "memcards"; - ofn.lpstrFileTitle = szFileTitle; - ofn.nMaxFileTitle = MAXFILENAME; - ofn.lpstrTitle = NULL; - ofn.lpstrDefExt = "MCR"; - ofn.Flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR; - - if (GetOpenFileName ((LPOPENFILENAME)&ofn)) { - Edit_SetText(GetDlgItem(hW,mcd == 1 ? IDC_MCD1 : IDC_MCD2), szFileName); - LoadMcd(mcd, szFileName); - UpdateMcdDlg(); - } -} - -int Open_File_Proc(char *file) { - OPENFILENAME ofn; - char szFileName[MAXFILENAME]; - char szFileTitle[MAXFILENAME]; - - memset(&szFileName, 0, sizeof(szFileName)); - memset(&szFileTitle, 0, sizeof(szFileTitle)); - - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = gApp.hWnd; - ofn.lpstrFilter = "Psx Exe Format\0*.*;*.*\0"; - ofn.lpstrCustomFilter = NULL; - ofn.nMaxCustFilter = 0; - ofn.nFilterIndex = 1; - ofn.lpstrFile = szFileName; - ofn.nMaxFile = MAXFILENAME; - ofn.lpstrInitialDir = NULL; - ofn.lpstrFileTitle = szFileTitle; - ofn.nMaxFileTitle = MAXFILENAME; - ofn.lpstrTitle = NULL; - ofn.lpstrDefExt = "EXE"; - ofn.Flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR; - - if (GetOpenFileName ((LPOPENFILENAME)&ofn)) { - strcpy(file, szFileName); - return 1; - } else - return 0; -} - -void CreateMainWindow(int nCmdShow) { - char strTitle[20]; - WNDCLASS wc; - HWND hWnd; - HDC hdc; - HPEN hpen; - - LoadString(gApp.hInstance, IDS_TITLE, strTitle, 20); - - wc.lpszClassName = "P©SX Main"; - wc.lpfnWndProc = MainWndProc; - wc.style = 0; - wc.hInstance = gApp.hInstance; - wc.hIcon = LoadIcon(gApp.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); - wc.hCursor = NULL; - wc.hbrBackground = (HBRUSH)(COLOR_MENUTEXT); - wc.lpszMenuName = 0; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - - RegisterClass(&wc); - - hWnd = CreateWindow("P©SX Main", - strTitle, - WS_OVERLAPPED | WS_SYSMENU, - 20, - 20, - 320, - 240, - NULL, - NULL, - gApp.hInstance, - NULL); - - gApp.hWnd = hWnd; - - hdc = GetDC(hWnd); - hpen = CreatePen(PS_SOLID, 0, 0xffffff); - - SelectObject(hdc, hpen); - - ShowWindow(hWnd, nCmdShow); -} - -int SysInit() { - if (Config.PsxOut) OpenConsole(); - - if (psxInit() == -1) return -1; - - #ifdef GTE_DUMP - gteLog = fopen("gteLog.txt","w"); - #endif - -#ifdef EMU_LOG - emuLog = fopen("emuLog.txt","w"); - setvbuf(emuLog, NULL, _IONBF, 0); -#endif - - LoadPlugins(); - LoadMcds(Config.Mcd1, Config.Mcd2); - - return 0; -} - -void SysReset() { - psxReset(); -} - - -void SysClose() { - psxShutdown(); - ReleasePlugins(); - - if (Config.PsxOut) CloseConsole(); - - if (emuLog != NULL) fclose(emuLog); - #ifdef GTE_DUMP - if (gteLog != NULL) fclose(gteLog); - #endif -} - -void SysPrintf(char *fmt, ...) { - va_list list; - char msg[512]; - DWORD tmp; - - if (!hConsole) return; - - va_start(list,fmt); - vsprintf(msg,fmt,list); - va_end(list); - - WriteConsole(hConsole, msg, (DWORD)strlen(msg), &tmp, 0); -#ifdef EMU_LOG -#ifndef LOG_STDOUT - fprintf(emuLog, "%s", msg); -#endif -#endif -} - -void SysMessage(char *fmt, ...) { - va_list list; - char tmp[512]; - - va_start(list,fmt); - vsprintf(tmp,fmt,list); - va_end(list); - MessageBox(0, tmp, "Pcsx Msg", 0); -} - -static char *err = "Error Loading Symbol"; -static int errval; - -void *SysLoadLibrary(char *lib) { - return LoadLibrary(lib); -} - -void *SysLoadSym(void *lib, char *sym) { - void *tmp = GetProcAddress((HINSTANCE)lib, sym); - if (tmp == NULL) errval = 1; - else errval = 0; - return tmp; -} - -char *SysLibError() { - if (errval) { errval = 0; return err; } - return NULL; -} - -void SysCloseLibrary(void *lib) { - FreeLibrary((HINSTANCE)lib); -} - -void SysUpdate() { - MSG msg; - - PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE); - - while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } -} - -void SysRunGui() { - RunGui(); +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include +#include +#include +#include +#include + +#include "resource.h" +#include "AboutDlg.h" + +#include "PsxCommon.h" +#include "plugin.h" +#include "Debug.h" +#include "Win32.h" + +int AccBreak=0; +int ConfPlug=0; +int StatesC=0; +int NeedReset=1; +int cdOpenCase=0; + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { + gApp.hInstance = hInstance; + + Running=0; + + GetCurrentDirectory(256, PcsxDir); + + memset(&Config, 0, sizeof(PcsxConfig)); + if (LoadConfig() == -1) { + Config.PsxAuto = 1; + strcpy(Config.PluginsDir, "Plugin\\"); + strcpy(Config.BiosDir, "Bios\\"); + SysMessage("Pcsx needs to be configured"); + ConfPlug=1; + ConfigurePlugins(gApp.hWnd); + DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_MCDCONF), gApp.hWnd, (DLGPROC)ConfigureMcdsDlgProc); + SysMessage("Pcsx now will quit, restart it"); + return 0; + } + + if (SysInit() == -1) return 1; + + CreateMainWindow(nCmdShow); + + RunGui(); + + return 0; +} + +void RunGui() { + MSG msg; + + PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE); + + for (;;) { + if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } +} + +void OpenConsole() { + if (hConsole) return; + AllocConsole(); + SetConsoleTitle("Psx Output"); + hConsole = GetStdHandle(STD_OUTPUT_HANDLE); +} + +void CloseConsole() { + FreeConsole(); hConsole = NULL; +} + +LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { + char File[256]; + + switch (msg) { + case WM_COMMAND: + switch (LOWORD(wParam)) { + case ID_FILE_EXIT: + SysClose(); + PostQuitMessage(0); + exit(0); + return TRUE; + + case ID_FILE_RUN_CD: + LoadCdBios = 0; + SetMenu(hWnd, NULL); + OpenPlugins(hWnd); + SysReset(); + NeedReset = 0; + CheckCdrom(); + if (LoadCdrom() == -1) { + ClosePlugins(); + AccBreak = 1; + DestroyWindow(gApp.hWnd); + CreateMainWindow(SW_SHOWNORMAL); + SetMenu(gApp.hWnd, gApp.hMenu); + SetCursor(LoadCursor(gApp.hInstance, IDC_ARROW)); + ShowCursor(TRUE); + SysMessage("Could not load Cdrom\n"); + return TRUE; + } + ShowCursor(FALSE); + Running = 1; + psxCpu->Execute(); + return TRUE; + + case ID_FILE_RUNCDBIOS: + LoadCdBios = 1; + SetMenu(hWnd, NULL); + OpenPlugins(hWnd); + ShowCursor(FALSE); + CheckCdrom(); + SysReset(); + NeedReset = 0; + Running = 1; + psxCpu->Execute(); + return TRUE; + + case ID_FILE_RUN_EXE: + if (!Open_File_Proc(File)) return TRUE; + SetMenu(hWnd, NULL); + OpenPlugins(hWnd); + SysReset(); + NeedReset = 0; + Load(File); + Running = 1; + psxCpu->Execute(); + return TRUE; + + case ID_EMULATOR_RUN: + SetMenu(hWnd, NULL); + OpenPlugins(hWnd); + ShowCursor(FALSE); + if (NeedReset) { SysReset(); NeedReset = 0; } + Running = 1; + psxCpu->Execute(); + return TRUE; + + case ID_EMULATOR_RESET: + NeedReset = 1; + return TRUE; + + case ID_CONFIGURATION_GRAPHICS: + GPU_configure(); + return TRUE; + + case ID_CONFIGURATION_SOUND: + SPU_configure(); + return TRUE; + + case ID_CONFIGURATION_CONTROLLERS: + PAD1_configure(); + if (strcmp(Config.Pad1, Config.Pad2)) PAD2_configure(); + return TRUE; + + case ID_CONFIGURATION_CDROM: + CDR_configure(); + return TRUE; + + case ID_CONFIGURATION_MEMORYCARDMANAGER: + DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_MCDCONF), hWnd, (DLGPROC)ConfigureMcdsDlgProc); + return TRUE; + + case ID_CONFIGURATION_CPU: + DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_CPUCONF), hWnd, (DLGPROC)ConfigureCpuDlgProc); + return TRUE; + + case ID_CONFIGURATION: + ConfigurePlugins(hWnd); + return TRUE; + + case ID_HELP_HELP: + ShellExecute(NULL, "open", "Readme.txt", NULL, NULL, SW_SHOWNORMAL); + return TRUE; + + case ID_HELP_ABOUT: + DialogBox(gApp.hInstance, MAKEINTRESOURCE(ABOUT_DIALOG), hWnd, (DLGPROC)AboutDlgProc); + return TRUE; + } + break; + + case WM_SYSKEYDOWN: + if (wParam != VK_F10) + return DefWindowProc(hWnd, msg, wParam, lParam); + case WM_KEYDOWN: + PADhandleKey(wParam); + return TRUE; + + case WM_DESTROY: + if (!AccBreak) { + if (Running) ClosePlugins(); + SysClose(); + PostQuitMessage(0); + exit(0); + } + else AccBreak = 0; + + return TRUE; + + case WM_CREATE: + gApp.hMenu = LoadMenu(gApp.hInstance, MAKEINTRESOURCE(IDR_MENU1)); + SetMenu(hWnd, gApp.hMenu); + break; + + case WM_QUIT: + exit(0); + break; + + default: + return DefWindowProc(hWnd, msg, wParam, lParam); + } + + return FALSE; +} + +HWND mcdDlg; +McdBlock Blocks[2][15]; +int IconC[2][15]; +HIMAGELIST Iiml[2]; +HICON eICON; + +void CreateListView(int idc) { + HWND List; + LV_COLUMN col; + + List = GetDlgItem(mcdDlg, idc); + + col.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + col.fmt = LVCFMT_LEFT; + + col.pszText = "Title"; + col.cx = 170; + col.iSubItem = 0; + + ListView_InsertColumn(List, 0, &col); + + col.pszText = "Status"; + col.cx = 50; + col.iSubItem = 1; + + ListView_InsertColumn(List, 1, &col); + + col.pszText = "Game ID"; + col.cx = 90; + col.iSubItem = 2; + + ListView_InsertColumn(List, 2, &col); + + col.pszText = "Game"; + col.cx = 80; + col.iSubItem = 3; + + ListView_InsertColumn(List, 3, &col); +} + +int GetRGB() { + HDC scrDC, memDC; + HBITMAP oldBmp = NULL; + HBITMAP curBmp = NULL; + COLORREF oldColor; + COLORREF curColor = RGB(255,255,255); + int i, R, G, B; + + R = G = B = 1; + + scrDC = CreateDC("DISPLAY", NULL, NULL, NULL); + memDC = CreateCompatibleDC(NULL); + curBmp = CreateCompatibleBitmap(scrDC, 1, 1); + oldBmp = (HBITMAP)SelectObject(memDC, curBmp); + + for (i = 255; i >= 0; --i) { + oldColor = curColor; + curColor = SetPixel(memDC, 0, 0, RGB(i, i, i)); + + if (GetRValue(curColor) < GetRValue(oldColor)) ++R; + if (GetGValue(curColor) < GetGValue(oldColor)) ++G; + if (GetBValue(curColor) < GetBValue(oldColor)) ++B; + } + + DeleteObject(oldBmp); + DeleteObject(curBmp); + DeleteDC(scrDC); + DeleteDC(memDC); + + return (R * G * B); +} + +HICON GetIcon(short *icon) { + ICONINFO iInfo; + HDC hDC; + char mask[16*16]; + int x, y, c, Depth; + + hDC = CreateIC("DISPLAY",NULL,NULL,NULL); + Depth=GetDeviceCaps(hDC, BITSPIXEL); + DeleteDC(hDC); + + if (Depth == 16) { + if (GetRGB() == (32 * 32 * 32)) + Depth = 15; + } + + for (y=0; y<16; y++) { + for (x=0; x<16; x++) { + c = icon[y*16+x]; + if (Depth == 15) + c = ((c&0x001f) << 10) | ((c&0x7c00) >> 10) | (c&0x03e0); + else + c = (c&0x001f) | ((c&0x7c00) << 1) | ((c&0x03e0) << 1); + + icon[y*16+x] = c; + } + } + + iInfo.fIcon = TRUE; + memset(mask, 0, 16*16); + iInfo.hbmMask = CreateBitmap(16, 16, 1, 1, mask); + iInfo.hbmColor = CreateBitmap(16, 16, 1, 16, icon); + + return CreateIconIndirect(&iInfo); +} + +HICON hICON[2][3][15]; +int aIover[2]; +int ani[2]; + +void LoadMcdItems(int mcd, int idc) { + HWND List = GetDlgItem(mcdDlg, idc); + LV_ITEM item; + HIMAGELIST iml = Iiml[mcd-1]; + int i, j; + HICON hIcon; + McdBlock *Info; + + aIover[mcd-1]=0; + ani[mcd-1]=0; + + ListView_DeleteAllItems(List); + + for (i=0; i<15; i++) { + + item.mask = LVIF_TEXT | LVIF_IMAGE; + item.iItem = i; + item.iImage = i; + item.pszText = LPSTR_TEXTCALLBACK; + item.iSubItem = 0; + + IconC[mcd-1][i] = 0; + Info = &Blocks[mcd-1][i]; + + if ((Info->Flags & 0xF) == 1 && Info->IconCount != 0) { + hIcon = GetIcon(Info->Icon); + + if (Info->IconCount > 1) { + for(j = 0; j < 3; j++) + hICON[mcd-1][j][i]=hIcon; + } + } else { + hIcon = eICON; + } + + ImageList_ReplaceIcon(iml, -1, hIcon); + ListView_InsertItem(List, &item); + } +} + +void UpdateMcdItems(int mcd, int idc) { + HWND List = GetDlgItem(mcdDlg, idc); + LV_ITEM item; + HIMAGELIST iml = Iiml[mcd-1]; + int i, j; + McdBlock *Info; + HICON hIcon; + + aIover[mcd-1]=0; + ani[mcd-1]=0; + + for (i=0; i<15; i++) { + + item.mask = LVIF_TEXT | LVIF_IMAGE; + item.iItem = i; + item.iImage = i; + item.pszText = LPSTR_TEXTCALLBACK; + item.iSubItem = 0; + + IconC[mcd-1][i] = 0; + Info = &Blocks[mcd-1][i]; + + if ((Info->Flags & 0xF) == 1 && Info->IconCount != 0) { + hIcon = GetIcon(Info->Icon); + + if (Info->IconCount > 1) { + for(j = 0; j < 3; j++) + hICON[mcd-1][j][i]=hIcon; + } + } else { + hIcon = eICON; + } + + ImageList_ReplaceIcon(iml, i, hIcon); + ListView_SetItem(List, &item); + } + ListView_Update(List, -1); +} + +void McdListGetDispInfo(int mcd, int idc, LPNMHDR pnmh) { + LV_DISPINFO *lpdi = (LV_DISPINFO *)pnmh; + McdBlock *Info; + + Info = &Blocks[mcd-1][lpdi->item.iItem]; + + switch (lpdi->item.iSubItem) { + case 0: + switch (Info->Flags & 0xF) { + case 1: + lpdi->item.pszText = Info->Title; + break; + case 2: + lpdi->item.pszText = "mid link block"; + break; + case 3: + lpdi->item.pszText = "terminiting link block"; + break; + } + break; + case 1: + if ((Info->Flags & 0xF0) == 0xA0) { + if ((Info->Flags & 0xF) >= 1 && + (Info->Flags & 0xF) <= 3) { + lpdi->item.pszText = "Deleted"; + } else lpdi->item.pszText = "Free"; + } else if ((Info->Flags & 0xF0) == 0x50) + lpdi->item.pszText = "Used"; + else { lpdi->item.pszText = "Free"; } + break; + case 2: + if((Info->Flags & 0xF)==1) + lpdi->item.pszText = Info->ID; + break; + case 3: + if((Info->Flags & 0xF)==1) + lpdi->item.pszText = Info->Name; + break; + } +} + +void McdListNotify(int mcd, int idc, LPNMHDR pnmh) { + switch (pnmh->code) { + case LVN_GETDISPINFO: McdListGetDispInfo(mcd, idc, pnmh); break; + } +} + +void UpdateMcdDlg() { + int i; + + for (i=1; i<16; i++) GetMcdBlockInfo(1, i, &Blocks[0][i-1]); + for (i=1; i<16; i++) GetMcdBlockInfo(2, i, &Blocks[1][i-1]); + UpdateMcdItems(1, IDC_LIST1); + UpdateMcdItems(2, IDC_LIST2); +} + +void LoadMcdDlg() { + int i; + + for (i=1; i<16; i++) GetMcdBlockInfo(1, i, &Blocks[0][i-1]); + for (i=1; i<16; i++) GetMcdBlockInfo(2, i, &Blocks[1][i-1]); + LoadMcdItems(1, IDC_LIST1); + LoadMcdItems(2, IDC_LIST2); +} + +void UpdateMcdIcon(int mcd, int idc) { + HWND List = GetDlgItem(mcdDlg, idc); + HIMAGELIST iml = Iiml[mcd-1]; + int i; + McdBlock *Info; + int *count; + + if(!aIover[mcd-1]) { + ani[mcd-1]++; + + for (i=0; i<15; i++) { + Info = &Blocks[mcd-1][i]; + count = &IconC[mcd-1][i]; + + if ((Info->Flags & 0xF) != 1) continue; + if (Info->IconCount <= 1) continue; + + if (*count < Info->IconCount) { + (*count)++; + aIover[mcd-1]=0; + + if(ani[mcd-1] <= (Info->IconCount-1)) // last frame and below... + hICON[mcd-1][ani[mcd-1]][i] = GetIcon(&Info->Icon[(*count)*16*16]); + } else { + aIover[mcd-1]=1; + } + } + + } else { + + if (ani[mcd-1] > 1) ani[mcd-1] = 0; // 1st frame + else ani[mcd-1]++; // 2nd, 3rd frame + + for(i=0;i<15;i++) { +// RECT rect, hrect; + + Info = &Blocks[mcd-1][i]; + + if (((Info->Flags & 0xF) == 1) && (Info->IconCount > 1)) + ImageList_ReplaceIcon(iml, i, hICON[mcd-1][ani[mcd-1]][i]); + +/* GetWindowRect(List, &hrect); + ListView_GetItemRect(List, i, &rect, LVIR_ICON); + rect.left+= hrect.left; rect.right+= hrect.left; + rect.top+= hrect.top; rect.bottom+= hrect.top; + +// rect.left-= 12; rect.right-= 12; // quick fix + + InvalidateRect(mcdDlg, &rect, FALSE);*/ + } + ListView_Update(List, 0); + } +} + +static int copy = 0, copymcd = 0; +static int listsel = 0; + +BOOL CALLBACK ConfigureMcdsDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { + char str[256]; + LPBYTE lpAND, lpXOR; + LPBYTE lpA, lpX; + int i, j; + + switch(uMsg) { + case WM_INITDIALOG: + mcdDlg = hW; + + lpA=lpAND=(LPBYTE)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(16*16)); + lpX=lpXOR=(LPBYTE)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(16*16)); + + for(i=0;i<16;i++) + { + for(j=0;j<16;j++) + { + *lpA++=0xff; + *lpX++=0; + } + } + eICON=CreateIcon(gApp.hInstance,16,16,1,1,lpAND,lpXOR); + + HeapFree(GetProcessHeap(),0,lpAND); + HeapFree(GetProcessHeap(),0,lpXOR); + + if (!strlen(Config.Mcd1)) strcpy(Config.Mcd1, "memcards\\Mcd001.mcr"); + if (!strlen(Config.Mcd2)) strcpy(Config.Mcd2, "memcards\\Mcd002.mcr"); + Edit_SetText(GetDlgItem(hW,IDC_MCD1), Config.Mcd1); + Edit_SetText(GetDlgItem(hW,IDC_MCD2), Config.Mcd2); + + CreateListView(IDC_LIST1); + CreateListView(IDC_LIST2); + + Iiml[0] = ImageList_Create(16, 16, ILC_COLOR16, 0, 0); + Iiml[1] = ImageList_Create(16, 16, ILC_COLOR16, 0, 0); + + ListView_SetImageList(GetDlgItem(mcdDlg, IDC_LIST1), Iiml[0], LVSIL_SMALL); + ListView_SetImageList(GetDlgItem(mcdDlg, IDC_LIST2), Iiml[1], LVSIL_SMALL); + + Button_Enable(GetDlgItem(hW, IDC_PASTE), FALSE); + + LoadMcdDlg(); + + SetTimer(hW, 1, 250, NULL); + + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_COPYTO1: + copy = ListView_GetSelectionMark(GetDlgItem(mcdDlg, IDC_LIST2)); + copymcd = 1; + + Button_Enable(GetDlgItem(hW, IDC_PASTE), TRUE); + return TRUE; + case IDC_COPYTO2: + copy = ListView_GetSelectionMark(GetDlgItem(mcdDlg, IDC_LIST1)); + copymcd = 2; + + Button_Enable(GetDlgItem(hW, IDC_PASTE), TRUE); + return TRUE; + case IDC_PASTE: + if (MessageBox(hW, "Are you sure you want to paste this selection?", "Confirmation", MB_YESNO) == IDNO) return TRUE; + + if (copymcd == 1) { + Edit_GetText(GetDlgItem(hW,IDC_MCD1), str, 256); + i = ListView_GetSelectionMark(GetDlgItem(mcdDlg, IDC_LIST1)); + + // save dir data + save data + memcpy(Mcd1Data + (i+1) * 128, Mcd2Data + (copy+1) * 128, 128); + SaveMcd(str, Mcd1Data, (i+1) * 128, 128); + memcpy(Mcd1Data + (i+1) * 1024 * 8, Mcd2Data + (copy+1) * 1024 * 8, 1024 * 8); + SaveMcd(str, Mcd1Data, (i+1) * 1024 * 8, 1024 * 8); + } else { // 2 + Edit_GetText(GetDlgItem(hW,IDC_MCD2), str, 256); + i = ListView_GetSelectionMark(GetDlgItem(mcdDlg, IDC_LIST2)); + + // save dir data + save data + memcpy(Mcd2Data + (i+1) * 128, Mcd1Data + (copy+1) * 128, 128); + SaveMcd(str, Mcd2Data, (i+1) * 128, 128); + memcpy(Mcd2Data + (i+1) * 1024 * 8, Mcd1Data + (copy+1) * 1024 * 8, 1024 * 8); + SaveMcd(str, Mcd2Data, (i+1) * 1024 * 8, 1024 * 8); + } + + UpdateMcdDlg(); + + return TRUE; + case IDC_DELETE1: + { + McdBlock *Info; + int mcd = 1; + int i, xor = 0, j; + unsigned char *data, *ptr; + + Edit_GetText(GetDlgItem(hW,IDC_MCD1), str, 256); + i = ListView_GetSelectionMark(GetDlgItem(mcdDlg, IDC_LIST1)); + data = Mcd1Data; + + i++; + + ptr = data + i * 128; + + Info = &Blocks[mcd-1][i-1]; + + if ((Info->Flags & 0xF0) == 0xA0) { + if ((Info->Flags & 0xF) >= 1 && + (Info->Flags & 0xF) <= 3) { // deleted + *ptr = 0x50 | (Info->Flags & 0xF); + } else return TRUE; + } else if ((Info->Flags & 0xF0) == 0x50) { // used + *ptr = 0xA0 | (Info->Flags & 0xF); + } else { return TRUE; } + + for (j=0; j<127; j++) xor^=*ptr++; + *ptr = xor; + + SaveMcd(str, data, i * 128, 128); + UpdateMcdDlg(); + } + + return TRUE; + case IDC_DELETE2: + { + McdBlock *Info; + int mcd = 2; + int i, xor = 0, j; + unsigned char *data, *ptr; + + Edit_GetText(GetDlgItem(hW,IDC_MCD2), str, 256); + i = ListView_GetSelectionMark(GetDlgItem(mcdDlg, IDC_LIST2)); + data = Mcd2Data; + + i++; + + ptr = data + i * 128; + + Info = &Blocks[mcd-1][i-1]; + + if ((Info->Flags & 0xF0) == 0xA0) { + if ((Info->Flags & 0xF) >= 1 && + (Info->Flags & 0xF) <= 3) { // deleted + *ptr = 0x50 | (Info->Flags & 0xF); + } else return TRUE; + } else if ((Info->Flags & 0xF0) == 0x50) { // used + *ptr = 0xA0 | (Info->Flags & 0xF); + } else { return TRUE; } + + for (j=0; j<127; j++) xor^=*ptr++; + *ptr = xor; + + SaveMcd(str, data, i * 128, 128); + UpdateMcdDlg(); + } + + return TRUE; + + case IDC_MCDSEL1: + Open_Mcd_Proc(hW, 1); + return TRUE; + case IDC_MCDSEL2: + Open_Mcd_Proc(hW, 2); + return TRUE; + case IDC_RELOAD1: + Edit_GetText(GetDlgItem(hW,IDC_MCD1), str, 256); + LoadMcd(1, str); + UpdateMcdDlg(); + return TRUE; + case IDC_RELOAD2: + Edit_GetText(GetDlgItem(hW,IDC_MCD2), str, 256); + LoadMcd(2, str); + UpdateMcdDlg(); + return TRUE; + case IDC_FORMAT1: + if (MessageBox(hW, "Are you sure you want to format this Memory Card?", "Confirmation", MB_YESNO) == IDNO) return TRUE; + Edit_GetText(GetDlgItem(hW,IDC_MCD1), str, 256); + CreateMcd(str); + LoadMcd(1, str); + UpdateMcdDlg(); + return TRUE; + case IDC_FORMAT2: + if (MessageBox(hW, "Are you sure you want to format this Memory Card?", "Confirmation", MB_YESNO) == IDNO) return TRUE; + Edit_GetText(GetDlgItem(hW,IDC_MCD2), str, 256); + CreateMcd(str); + LoadMcd(2, str); + UpdateMcdDlg(); + return TRUE; + case IDCANCEL: + LoadMcds(Config.Mcd1, Config.Mcd2); + + EndDialog(hW,FALSE); + + return TRUE; + case IDOK: + Edit_GetText(GetDlgItem(hW,IDC_MCD1), Config.Mcd1, 256); + Edit_GetText(GetDlgItem(hW,IDC_MCD2), Config.Mcd2, 256); + + LoadMcds(Config.Mcd1, Config.Mcd2); + SaveConfig(); + + EndDialog(hW,TRUE); + + return TRUE; + } + case WM_NOTIFY: + switch (wParam) { + case IDC_LIST1: McdListNotify(1, IDC_LIST1, (LPNMHDR)lParam); break; + case IDC_LIST2: McdListNotify(2, IDC_LIST2, (LPNMHDR)lParam); break; + } + return TRUE; + case WM_TIMER: + UpdateMcdIcon(1, IDC_LIST1); + UpdateMcdIcon(2, IDC_LIST2); + return TRUE; + case WM_DESTROY: + DestroyIcon(eICON); + //KillTimer(hW, 1); + return TRUE; + } + return FALSE; +} + +BOOL CALLBACK ConfigureCpuDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { + long tmp; + + switch(uMsg) { + case WM_INITDIALOG: + Button_SetCheck(GetDlgItem(hW,IDC_XA), Config.Xa); + Button_SetCheck(GetDlgItem(hW,IDC_SIO), Config.Sio); + Button_SetCheck(GetDlgItem(hW,IDC_MDEC), Config.Mdec); + Button_SetCheck(GetDlgItem(hW,IDC_QKEYS), Config.QKeys); + Button_SetCheck(GetDlgItem(hW,IDC_CDDA), Config.Cdda); + Button_SetCheck(GetDlgItem(hW,IDC_PSXAUTO), Config.PsxAuto); + Button_SetCheck(GetDlgItem(hW,IDC_CPU), Config.Cpu); + Button_SetCheck(GetDlgItem(hW,IDC_PSXOUT), Config.PsxOut); + Button_SetCheck(GetDlgItem(hW,IDC_SPUIRQ), Config.SpuIrq); + Button_SetCheck(GetDlgItem(hW,IDC_CDTIMING),Config.CdTiming); + ComboBox_AddString(GetDlgItem(hW,IDC_PSXTYPES),"NTSC"); + ComboBox_AddString(GetDlgItem(hW,IDC_PSXTYPES),"PAL"); + ComboBox_SetCurSel(GetDlgItem(hW,IDC_PSXTYPES),Config.PsxType); + + case WM_COMMAND: { + switch (LOWORD(wParam)) { + case IDCANCEL: EndDialog(hW,FALSE); return TRUE; + case IDOK: + tmp = ComboBox_GetCurSel(GetDlgItem(hW,IDC_PSXTYPES)); + if (tmp == 0) Config.PsxType = 0; + else Config.PsxType = 1; + + Config.Xa = Button_GetCheck(GetDlgItem(hW,IDC_XA)); + Config.Sio = Button_GetCheck(GetDlgItem(hW,IDC_SIO)); + Config.Mdec = Button_GetCheck(GetDlgItem(hW,IDC_MDEC)); + Config.QKeys = Button_GetCheck(GetDlgItem(hW,IDC_QKEYS)); + Config.Cdda = Button_GetCheck(GetDlgItem(hW,IDC_CDDA)); + Config.PsxAuto = Button_GetCheck(GetDlgItem(hW,IDC_PSXAUTO)); + tmp = Config.Cpu; + Config.Cpu = Button_GetCheck(GetDlgItem(hW,IDC_CPU)); + if (tmp != Config.Cpu) { + psxCpu->Shutdown(); + if (Config.Cpu) + psxCpu = &psxInt; + else psxCpu = &psxRec; + if (psxCpu->Init() == -1) { + SysClose(); + exit(1); + } + psxCpu->Reset(); + } + Config.PsxOut = Button_GetCheck(GetDlgItem(hW,IDC_PSXOUT)); + Config.SpuIrq = Button_GetCheck(GetDlgItem(hW,IDC_SPUIRQ)); + Config.CdTiming= Button_GetCheck(GetDlgItem(hW,IDC_CDTIMING)); + + SaveConfig(); + + EndDialog(hW,TRUE); + + if (Config.PsxOut) OpenConsole(); + else CloseConsole(); + + return TRUE; + } + } + } + return FALSE; +} + +#define MAXFILENAME 256 + +void Open_Mcd_Proc(HWND hW, int mcd) { + OPENFILENAME ofn; + char szFileName[MAXFILENAME]; + char szFileTitle[MAXFILENAME]; + + memset(&szFileName, 0, sizeof(szFileName)); + memset(&szFileTitle, 0, sizeof(szFileTitle)); + + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = hW; + ofn.lpstrFilter = "Psx Mcd Format (*.mcr;*.mc;*.mem;*.vgs;*.mcd;*.gme;*.ddf)\0*.mcr;*.mcd;*.mem;*.gme;*.mc;*.ddf\0Psx Memory Card (*.mcr;*.mc)\0*.mcr;0*.mc\0CVGS Memory Card (*.mem;*.vgs)\0*.mem;*.vgs\0Bleem Memory Card (*.mcd)\0*.mcd\0DexDrive Memory Card (*.gme)\0*.gme\0DataDeck Memory Card (*.ddf)\0*.ddf\0";; + ofn.lpstrCustomFilter = NULL; + ofn.nMaxCustFilter = 0; + ofn.nFilterIndex = 1; + ofn.lpstrFile = szFileName; + ofn.nMaxFile = MAXFILENAME; + ofn.lpstrInitialDir = "memcards"; + ofn.lpstrFileTitle = szFileTitle; + ofn.nMaxFileTitle = MAXFILENAME; + ofn.lpstrTitle = NULL; + ofn.lpstrDefExt = "MCR"; + ofn.Flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR; + + if (GetOpenFileName ((LPOPENFILENAME)&ofn)) { + Edit_SetText(GetDlgItem(hW,mcd == 1 ? IDC_MCD1 : IDC_MCD2), szFileName); + LoadMcd(mcd, szFileName); + UpdateMcdDlg(); + } +} + +int Open_File_Proc(char *file) { + OPENFILENAME ofn; + char szFileName[MAXFILENAME]; + char szFileTitle[MAXFILENAME]; + + memset(&szFileName, 0, sizeof(szFileName)); + memset(&szFileTitle, 0, sizeof(szFileTitle)); + + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = gApp.hWnd; + ofn.lpstrFilter = "Psx Exe Format\0*.*;*.*\0"; + ofn.lpstrCustomFilter = NULL; + ofn.nMaxCustFilter = 0; + ofn.nFilterIndex = 1; + ofn.lpstrFile = szFileName; + ofn.nMaxFile = MAXFILENAME; + ofn.lpstrInitialDir = NULL; + ofn.lpstrFileTitle = szFileTitle; + ofn.nMaxFileTitle = MAXFILENAME; + ofn.lpstrTitle = NULL; + ofn.lpstrDefExt = "EXE"; + ofn.Flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR; + + if (GetOpenFileName ((LPOPENFILENAME)&ofn)) { + strcpy(file, szFileName); + return 1; + } else + return 0; +} + +void CreateMainWindow(int nCmdShow) { + char strTitle[20]; + WNDCLASS wc; + HWND hWnd; + HDC hdc; + HPEN hpen; + + LoadString(gApp.hInstance, IDS_TITLE, strTitle, 20); + + wc.lpszClassName = "P©SX Main"; + wc.lpfnWndProc = MainWndProc; + wc.style = 0; + wc.hInstance = gApp.hInstance; + wc.hIcon = LoadIcon(gApp.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); + wc.hCursor = NULL; + wc.hbrBackground = (HBRUSH)(COLOR_MENUTEXT); + wc.lpszMenuName = 0; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + + RegisterClass(&wc); + + hWnd = CreateWindow("P©SX Main", + strTitle, + WS_OVERLAPPED | WS_SYSMENU, + 20, + 20, + 320, + 240, + NULL, + NULL, + gApp.hInstance, + NULL); + + gApp.hWnd = hWnd; + + hdc = GetDC(hWnd); + hpen = CreatePen(PS_SOLID, 0, 0xffffff); + + SelectObject(hdc, hpen); + + ShowWindow(hWnd, nCmdShow); +} + +int SysInit() { + if (Config.PsxOut) OpenConsole(); + + if (psxInit() == -1) return -1; + + #ifdef GTE_DUMP + gteLog = fopen("gteLog.txt","w"); + #endif + +#ifdef EMU_LOG + emuLog = fopen("emuLog.txt","w"); + setvbuf(emuLog, NULL, _IONBF, 0); +#endif + + LoadPlugins(); + LoadMcds(Config.Mcd1, Config.Mcd2); + + return 0; +} + +void SysReset() { + psxReset(); +} + + +void SysClose() { + psxShutdown(); + ReleasePlugins(); + + if (Config.PsxOut) CloseConsole(); + + if (emuLog != NULL) fclose(emuLog); + #ifdef GTE_DUMP + if (gteLog != NULL) fclose(gteLog); + #endif +} + +void SysPrintf(char *fmt, ...) { + va_list list; + char msg[512]; + DWORD tmp; + + if (!hConsole) return; + + va_start(list,fmt); + vsprintf(msg,fmt,list); + va_end(list); + + WriteConsole(hConsole, msg, (DWORD)strlen(msg), &tmp, 0); +#ifdef EMU_LOG +#ifndef LOG_STDOUT + fprintf(emuLog, "%s", msg); +#endif +#endif +} + +void SysMessage(char *fmt, ...) { + va_list list; + char tmp[512]; + + va_start(list,fmt); + vsprintf(tmp,fmt,list); + va_end(list); + MessageBox(0, tmp, "Pcsx Msg", 0); +} + +static char *err = "Error Loading Symbol"; +static int errval; + +void *SysLoadLibrary(char *lib) { + return LoadLibrary(lib); +} + +void *SysLoadSym(void *lib, char *sym) { + void *tmp = GetProcAddress((HINSTANCE)lib, sym); + if (tmp == NULL) errval = 1; + else errval = 0; + return tmp; +} + +char *SysLibError() { + if (errval) { errval = 0; return err; } + return NULL; +} + +void SysCloseLibrary(void *lib) { + FreeLibrary((HINSTANCE)lib); +} + +void SysUpdate() { + MSG msg; + + PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE); + + while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } +} + +void SysRunGui() { + RunGui(); } \ No newline at end of file diff --git a/PcsxSrc/Win32/plugin.c b/PcsxSrc/Win32/plugin.c index 018257e..4b7f265 100644 --- a/PcsxSrc/Win32/plugin.c +++ b/PcsxSrc/Win32/plugin.c @@ -1,201 +1,201 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include "plugins.h" -#include "resource.h" -#include -#include -#include "R3000A.h" -#include "Win32.h" - -void PADhandleKey(int key) { - char Text[255]; - int ret; - - if (Running == 0) return; - switch (key) { - case 0: break; - case VK_F1: - sprintf (Text, "sstates/%s.%3.3d", CdromId, StatesC); - GPU_freeze(2, (GPUFreeze_t *)&StatesC); - ret = SaveState(Text); - sprintf (Text, "*PCSX*: %s State %d", !ret ? "Saved" : "Error Saving", StatesC+1); - GPU_displayText(Text); - return; - - case VK_F2: - if (StatesC < 4) StatesC++; - else StatesC = 0; - GPU_freeze(2, (GPUFreeze_t *)&StatesC); - return; - - case VK_F3: - sprintf (Text, "sstates/%s.%3.3d", CdromId, StatesC); - ret = LoadState(Text); - sprintf (Text, "*PCSX*: %s State %d", !ret ? "Loaded" : "Error Loading", StatesC+1); - GPU_displayText(Text); - return; - - case VK_F4: - { - gzFile f; - static int ShowPic; - static unsigned char *pMem; - - if (!ShowPic) { - sprintf (Text, "sstates/%s.%3.3d", CdromId, StatesC); - f = gzopen(Text, "rb"); - if (f == NULL) return; - - gzseek(f, 32, SEEK_SET); // skip header - - pMem = (unsigned char *) malloc(128*96*3); - gzread(f, pMem, 128*96*3); - gzclose(f); - GPU_freeze(2, (GPUFreeze_t *)&StatesC); - GPU_showScreenPic(pMem); - free(pMem); - ShowPic = 1; - } - else { - GPU_showScreenPic(NULL); - ShowPic = 0; - } - - } - return; - - case VK_F5: - if (Config.QKeys) break; - Config.Sio ^= 0x1; - sprintf (Text, "*PCSX*: Sio Irq %sAlways Enabled", Config.Sio ? "" : "Not "); - GPU_displayText(Text); - return; - - case VK_F6: - if (Config.QKeys) break; - Config.Mdec ^= 0x1; - sprintf (Text, "*PCSX*: Black&White Only Mdecs %sabled", Config.Mdec ? "En" : "Dis"); - GPU_displayText(Text); - return; - - case VK_F7: - if (Config.QKeys) break; - Config.Xa ^= 0x1; - sprintf (Text, "*PCSX*: Xa %sabled", !Config.Xa ? "En" : "Dis"); - GPU_displayText(Text); - return; - - case VK_F8: - if (Config.QKeys) break; - GPU_makeSnapshot(); - return; - - case VK_F9: - GPU_displayText("*PCSX*: CdRom Case Opened"); - cdOpenCase = 1; - return; - - case VK_F10: - GPU_displayText("*PCSX*: CdRom Case Closed"); - 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_ESCAPE: - Running = 0; - ClosePlugins(); - AccBreak = 1; - DestroyWindow(gApp.hWnd); - CreateMainWindow(SW_SHOWNORMAL); - SetMenu(gApp.hWnd, gApp.hMenu); - SetCursor(LoadCursor(gApp.hInstance, IDC_ARROW)); - ShowCursor(TRUE); - RunGui(); - return; - } -} - -void CALLBACK SPUirq(void); - -void OpenPlugins(HWND hWnd) { - int ret; - - ret = CDR_open(); - if (ret != 0) { SysMessage ("Error Opening CDR Plugin\n"); exit(1); } - ShowCursor(FALSE); - ret = GPU_open(hWnd); - if (ret != 0) { SysMessage ("Error Opening GPU Plugin\n"); exit(1); } - ret = SPU_open(hWnd); - if (ret != 0) { SysMessage ("Error Opening SPU Plugin\n"); exit(1); } - SPU_registerCallback(SPUirq); - ret = PAD1_open(hWnd); - if (ret != 0) { SysMessage ("Error Opening PAD1 Plugin\n"); exit(1); } - ret = PAD2_open(hWnd); - if (ret != 0) { SysMessage ("Error Opening PAD2 Plugin\n"); exit(1); } - SetCurrentDirectory(PcsxDir); -} - -void ClosePlugins() { - int ret; - - ret = CDR_close(); - if (ret != 0) { SysMessage ("Error Closing CDR Plugin\n"); exit(1); } - ret = GPU_close(); - if (ret != 0) { SysMessage ("Error Closing GPU Plugin\n"); exit(1); } - ret = SPU_close(); - if (ret != 0) { SysMessage ("Error Closing SPU Plugin\n"); exit(1); } - ret = PAD1_close(); - if (ret != 0) { SysMessage ("Error Closing PAD1 Plugin\n"); exit(1); } - ret = PAD2_close(); - if (ret != 0) { SysMessage ("Error Closing PAD2 Plugin\n"); exit(1); } - ShowCursor(TRUE); -} - -void ResetPlugins() { - int ret; - - CDR_shutdown(); - GPU_shutdown(); - SPU_shutdown(); - PAD1_shutdown(); - PAD2_shutdown(); - ret = CDR_init(); - if (ret != 0) { SysMessage ("CDRinit error : %d\n",ret); exit(1); } - ret = GPU_init(); - if (ret != 0) { SysMessage ("GPUinit error : %d\n",ret); exit(1); } - ret = SPU_init(); - if (ret != 0) { SysMessage ("SPUinit error : %d\n",ret); exit(1); } - ret = PAD1_init(1); - if (ret != 0) { SysMessage ("PAD1init error : %d\n",ret); exit(1); } - ret = PAD2_init(2); - if (ret != 0) { SysMessage ("PAD2init error : %d\n",ret); exit(1); } -} - - +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include "plugins.h" +#include "resource.h" +#include +#include +#include "R3000A.h" +#include "Win32.h" + +void PADhandleKey(int key) { + char Text[255]; + int ret; + + if (Running == 0) return; + switch (key) { + case 0: break; + case VK_F1: + sprintf (Text, "sstates/%s.%3.3d", CdromId, StatesC); + GPU_freeze(2, (GPUFreeze_t *)&StatesC); + ret = SaveState(Text); + sprintf (Text, "*PCSX*: %s State %d", !ret ? "Saved" : "Error Saving", StatesC+1); + GPU_displayText(Text); + return; + + case VK_F2: + if (StatesC < 4) StatesC++; + else StatesC = 0; + GPU_freeze(2, (GPUFreeze_t *)&StatesC); + return; + + case VK_F3: + sprintf (Text, "sstates/%s.%3.3d", CdromId, StatesC); + ret = LoadState(Text); + sprintf (Text, "*PCSX*: %s State %d", !ret ? "Loaded" : "Error Loading", StatesC+1); + GPU_displayText(Text); + return; + + case VK_F4: + { + gzFile f; + static int ShowPic; + static unsigned char *pMem; + + if (!ShowPic) { + sprintf (Text, "sstates/%s.%3.3d", CdromId, StatesC); + f = gzopen(Text, "rb"); + if (f == NULL) return; + + gzseek(f, 32, SEEK_SET); // skip header + + pMem = (unsigned char *) malloc(128*96*3); + gzread(f, pMem, 128*96*3); + gzclose(f); + GPU_freeze(2, (GPUFreeze_t *)&StatesC); + GPU_showScreenPic(pMem); + free(pMem); + ShowPic = 1; + } + else { + GPU_showScreenPic(NULL); + ShowPic = 0; + } + + } + return; + + case VK_F5: + if (Config.QKeys) break; + Config.Sio ^= 0x1; + sprintf (Text, "*PCSX*: Sio Irq %sAlways Enabled", Config.Sio ? "" : "Not "); + GPU_displayText(Text); + return; + + case VK_F6: + if (Config.QKeys) break; + Config.Mdec ^= 0x1; + sprintf (Text, "*PCSX*: Black&White Only Mdecs %sabled", Config.Mdec ? "En" : "Dis"); + GPU_displayText(Text); + return; + + case VK_F7: + if (Config.QKeys) break; + Config.Xa ^= 0x1; + sprintf (Text, "*PCSX*: Xa %sabled", !Config.Xa ? "En" : "Dis"); + GPU_displayText(Text); + return; + + case VK_F8: + if (Config.QKeys) break; + GPU_makeSnapshot(); + return; + + case VK_F9: + GPU_displayText("*PCSX*: CdRom Case Opened"); + cdOpenCase = 1; + return; + + case VK_F10: + GPU_displayText("*PCSX*: CdRom Case Closed"); + 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_ESCAPE: + Running = 0; + ClosePlugins(); + AccBreak = 1; + DestroyWindow(gApp.hWnd); + CreateMainWindow(SW_SHOWNORMAL); + SetMenu(gApp.hWnd, gApp.hMenu); + SetCursor(LoadCursor(gApp.hInstance, IDC_ARROW)); + ShowCursor(TRUE); + RunGui(); + return; + } +} + +void CALLBACK SPUirq(void); + +void OpenPlugins(HWND hWnd) { + int ret; + + ret = CDR_open(); + if (ret != 0) { SysMessage ("Error Opening CDR Plugin\n"); exit(1); } + ShowCursor(FALSE); + ret = GPU_open(hWnd); + if (ret != 0) { SysMessage ("Error Opening GPU Plugin\n"); exit(1); } + ret = SPU_open(hWnd); + if (ret != 0) { SysMessage ("Error Opening SPU Plugin\n"); exit(1); } + SPU_registerCallback(SPUirq); + ret = PAD1_open(hWnd); + if (ret != 0) { SysMessage ("Error Opening PAD1 Plugin\n"); exit(1); } + ret = PAD2_open(hWnd); + if (ret != 0) { SysMessage ("Error Opening PAD2 Plugin\n"); exit(1); } + SetCurrentDirectory(PcsxDir); +} + +void ClosePlugins() { + int ret; + + ret = CDR_close(); + if (ret != 0) { SysMessage ("Error Closing CDR Plugin\n"); exit(1); } + ret = GPU_close(); + if (ret != 0) { SysMessage ("Error Closing GPU Plugin\n"); exit(1); } + ret = SPU_close(); + if (ret != 0) { SysMessage ("Error Closing SPU Plugin\n"); exit(1); } + ret = PAD1_close(); + if (ret != 0) { SysMessage ("Error Closing PAD1 Plugin\n"); exit(1); } + ret = PAD2_close(); + if (ret != 0) { SysMessage ("Error Closing PAD2 Plugin\n"); exit(1); } + ShowCursor(TRUE); +} + +void ResetPlugins() { + int ret; + + CDR_shutdown(); + GPU_shutdown(); + SPU_shutdown(); + PAD1_shutdown(); + PAD2_shutdown(); + ret = CDR_init(); + if (ret != 0) { SysMessage ("CDRinit error : %d\n",ret); exit(1); } + ret = GPU_init(); + if (ret != 0) { SysMessage ("GPUinit error : %d\n",ret); exit(1); } + ret = SPU_init(); + if (ret != 0) { SysMessage ("SPUinit error : %d\n",ret); exit(1); } + ret = PAD1_init(1); + if (ret != 0) { SysMessage ("PAD1init error : %d\n",ret); exit(1); } + ret = PAD2_init(2); + if (ret != 0) { SysMessage ("PAD2init error : %d\n",ret); exit(1); } +} + + diff --git a/PcsxSrc/Win32/plugin.h b/PcsxSrc/Win32/plugin.h index bec7f7f..22f38b1 100644 --- a/PcsxSrc/Win32/plugin.h +++ b/PcsxSrc/Win32/plugin.h @@ -1,29 +1,29 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -// Windows Specifyc Plugin Functions -#ifndef __PLUGIN_H__ -#define __PLUGIN_H__ - -typedef long (CALLBACK* GPUopen)(HWND); - -typedef long (CALLBACK* SPUopen)(HWND); - -typedef long (CALLBACK* PADopen)(HWND); - +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +// Windows Specifyc Plugin Functions +#ifndef __PLUGIN_H__ +#define __PLUGIN_H__ + +typedef long (CALLBACK* GPUopen)(HWND); + +typedef long (CALLBACK* SPUopen)(HWND); + +typedef long (CALLBACK* PADopen)(HWND); + #endif /* __PLUGIN_H__ */ \ No newline at end of file diff --git a/PcsxSrc/Win32/resource.h b/PcsxSrc/Win32/resource.h index 464846e..6ed9ee6 100644 --- a/PcsxSrc/Win32/resource.h +++ b/PcsxSrc/Win32/resource.h @@ -1,266 +1,266 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by pcsx.rc -// -#define IDS_TITLE 1 -#define IDR_MENU1 101 -#define IDI_APP_ICON 102 -#define IDD_MCDCONF 102 -#define DEBUG_DIALOG 103 -#define ABOUT_DIALOG 104 -#define IDD_CPUCONF 105 -#define SPLASH_LOGO 113 -#define IDD_GPREGS 114 -#define IDD_CP0REGS 115 -#define IDD_COP2D 116 -#define IDD_COP2C 117 -#define IDD_CONFIG 120 -#define IDD_MEMVIEW 136 -#define IDC_EDIT2 1001 -#define IDC_MCD2 1004 -#define IDC_ASMCHECK1 1005 -#define IDC_MCD1 1005 -#define IDC_MCDSEL1 1006 -#define IDC_STEP 1007 -#define IDC_MCDSEL2 1007 -#define IDC_XA 1007 -#define IDC_SIO 1008 -#define IDC_SKIP 1009 -#define IDC_MDEC 1009 -#define IDC_RESET 1010 -#define IDC_PSXAUTO 1010 -#define IDC_GO 1011 -#define IDC_PSXTYPES 1011 -#define IDC_BREAK 1012 -#define IDC_DISCPUQKEYS 1012 -#define IDC_QKEYS 1012 -#define IDC_EDIT1 1013 -#define IDC_CDDA 1013 -#define IDC_CLOSE 1014 -#define IDC_PCSX_ABOUT_TEXT 1014 -#define IDC_PSXOUT 1014 -#define IDC_ASM_SCROLL 1015 -#define IDC_CPU 1015 -#define IDC_ASMCHECK2 1016 -#define IDC_SPUIRQ 1016 -#define IDC_ASMCHECK3 1017 -#define IDC_MDEC2 1017 -#define IDC_CDTIMING 1017 -#define IDC_ASMCHECK4 1018 -#define IDC_ASMCHECK5 1019 -#define IDC_RELOAD1 1019 -#define IDC_CP07 1020 -#define IDC_ASMCHECK6 1020 -#define IDC_RELOAD2 1020 -#define IDC_ASMCHECK7 1021 -#define IDC_COPYTO2 1021 -#define IDC_ASMCHECK8 1022 -#define IDC_COPYTO1 1022 -#define IDC_ASMCHECK9 1023 -#define IDC_PASTE 1023 -#define IDC_ASMCHECK10 1024 -#define IDC_DELETE1 1024 -#define IDC_ASMCHECK11 1025 -#define IDC_DELETE2 1025 -#define IDC_ASMCHECK12 1026 -#define IDC_LIST1 1027 -#define IDC_ASMCHECK13 1027 -#define IDC_ASMCHECK14 1028 -#define IDC_LIST2 1028 -#define IDC_ASMCHECK15 1029 -#define IDC_ASMCHECK16 1030 -#define IDC_ASMCHECK17 1031 -#define IDC_ASMCHECK18 1032 -#define IDC_ASMCHECK19 1033 -#define IDC_CP021 1034 -#define IDC_ASMCHECK20 1034 -#define IDC_CP022 1035 -#define IDC_ASMCHECK21 1035 -#define IDC_CP023 1036 -#define IDC_ASMCHECK22 1036 -#define IDC_CP024 1037 -#define IDC_ASMCHECK23 1037 -#define IDC_CP025 1038 -#define IDC_ASMCHECK24 1038 -#define IDC_CP031 1044 -#define IDC_GPR0 1047 -#define IDC_GPR1 1048 -#define IDC_GPR2 1049 -#define IDC_GPR3 1050 -#define IDC_GPR4 1051 -#define IDC_GPR5 1052 -#define IDC_LISTGPU 1052 -#define IDC_GPR6 1053 -#define IDC_LISTSPU 1053 -#define IDC_GPR7 1054 -#define IDC_LISTCDR 1054 -#define IDC_GPR8 1055 -#define IDC_LISTBIOS 1055 -#define IDC_GPR9 1056 -#define IDC_CONFIGGPU 1056 -#define IDC_GPR10 1057 -#define IDC_TESTGPU 1057 -#define IDC_ABOUTGPU 1058 -#define IDC_CONFIGSPU 1059 -#define IDC_TESTSPU 1060 -#define IDC_ABOUTSPU 1061 -#define IDC_CONFIGCDR 1062 -#define IDC_GPR11 1063 -#define IDC_TESTCDR 1063 -#define IDC_ABOUTCDR 1064 -#define IDC_COMBODRIVE 1065 -#define IDC_LISTPAD1 1066 -#define IDC_CONFIGPAD1 1067 -#define IDC_GPR12 1068 -#define IDC_TESTPAD1 1068 -#define IDC_GPR13 1069 -#define IDC_ABOUTPAD1 1069 -#define IDC_GPR14 1070 -#define IDC_LISTPAD2 1070 -#define IDC_GPR15 1071 -#define IDC_CONFIGPAD2 1071 -#define IDC_GPR16 1072 -#define IDC_TESTPAD2 1072 -#define IDC_GPR17 1073 -#define IDC_ABOUTPAD2 1073 -#define IDC_GPR18 1074 -#define IDC_GPR19 1075 -#define IDC_GPR20 1076 -#define IDC_GPR21 1077 -#define IDC_GPR22 1078 -#define IDC_GPR23 1079 -#define IDC_GPR24 1080 -#define IDC_GPR25 1081 -#define IDC_GPR26 1082 -#define IDC_GPR27 1083 -#define IDC_GPR28 1084 -#define IDC_GPR29 1085 -#define IDC_GPR30 1086 -#define IDC_GPR31 1087 -#define IDC_GPR_PC 1089 -#define IDC_GPR_HI 1091 -#define IDC_GPR_LO 1092 -#define IDC_CP00 1093 -#define IDC_CP01 1094 -#define IDC_CP02 1095 -#define IDC_CP03 1096 -#define IDC_CP04 1097 -#define IDC_CP05 1098 -#define IDC_CP06 1099 -#define IDC_CP08 1100 -#define IDC_CP09 1101 -#define IDC_CP010 1102 -#define IDC_CP011 1103 -#define IDC_CP012 1104 -#define IDC_CP013 1105 -#define IDC_CP014 1106 -#define IDC_CP015 1107 -#define IDC_CP016 1108 -#define IDC_CP017 1109 -#define IDC_CP018 1110 -#define IDC_CP019 1111 -#define IDC_CP020 1112 -#define IDC_CP026 1113 -#define IDC_CP027 1114 -#define IDC_CP028 1115 -#define IDC_CP029 1116 -#define IDC_CP030 1117 -#define IDC_COP2D0 1118 -#define IDC_COP2D1 1119 -#define IDC_COP2D2 1120 -#define IDC_COP2D3 1121 -#define IDC_COP2D4 1122 -#define IDC_COP2D5 1123 -#define IDC_COP2D6 1124 -#define IDC_COP2D7 1125 -#define IDC_COP2D8 1126 -#define IDC_COP2D9 1127 -#define IDC_COP2D10 1128 -#define IDC_COP2D11 1129 -#define IDC_COP2D12 1130 -#define IDC_COP2D13 1131 -#define IDC_COP2D14 1132 -#define IDC_COP2D15 1133 -#define IDC_COP2D16 1134 -#define IDC_COP2D17 1135 -#define IDC_COP2D18 1136 -#define IDC_COP2D19 1137 -#define IDC_COP2D20 1138 -#define IDC_COP2D21 1139 -#define IDC_COP2D22 1140 -#define IDC_COP2D23 1141 -#define IDC_COP2D24 1142 -#define IDC_COP2D25 1143 -#define IDC_COP2D26 1144 -#define IDC_COP2D27 1145 -#define IDC_COP2D28 1146 -#define IDC_COP2D29 1147 -#define IDC_COP2D30 1148 -#define IDC_COP2D31 1149 -#define IDC_COP2C0 1152 -#define IDC_COP2C1 1153 -#define IDC_COP2C2 1154 -#define IDC_COP2C3 1155 -#define IDC_COP2C4 1156 -#define IDC_COP2C5 1157 -#define IDC_COP2C6 1158 -#define IDC_COP2C7 1159 -#define IDC_COP2C8 1160 -#define IDC_COP2C9 1161 -#define IDC_COP2C10 1162 -#define IDC_COP2C11 1163 -#define IDC_COP2C12 1164 -#define IDC_COP2C13 1165 -#define IDC_COP2C14 1166 -#define IDC_COP2C15 1167 -#define IDC_COP2C16 1168 -#define IDC_COP2C17 1169 -#define IDC_COP2C18 1170 -#define IDC_COP2C19 1171 -#define IDC_COP2C20 1172 -#define IDC_COP2C21 1173 -#define IDC_COP2C22 1174 -#define IDC_COP2C23 1175 -#define IDC_COP2C24 1176 -#define IDC_COP2C25 1177 -#define IDC_COP2C26 1178 -#define IDC_COP2C27 1179 -#define IDC_COP2C28 1180 -#define IDC_COP2C29 1181 -#define IDC_COP2C30 1182 -#define IDC_COP2C31 1183 -#define IDC_BUTTON1 1254 -#define IDC_BIOSDIR 1254 -#define IDC_FORMAT1 1254 -#define IDC_PLUGINSDIR 1255 -#define IDC_FORMAT2 1255 -#define ID_FILE_EXIT 40001 -#define ID_HELP_ABOUT 40002 -#define ID_FILE_RUN_CD 40003 -#define ID_FILE_RUN_EXE 40004 -#define ID_EMULATOR_PAUSE 40005 -#define ID_EMULATOR_RESET 40006 -#define ID_HELP_HELP 40007 -#define ID_DEBUG_ENABLE_DEBUGGER 40008 -#define ID_CONFIGURATION_GRAPHICS 40009 -#define ID_CONFIGURATION_SOUND 40010 -#define ID_CONFIGURATION_CDROM 40011 -#define ID_CONFIGURATION_MEMORYCARDMANAGER 40012 -#define ID_CONFIGURATION_CPU 40013 -#define ID_EMULATOR_RUN 40014 -#define ID_DEBUGREG 40015 -#define ID_DEBUG_MESSAGES 40015 -#define ID_CONFIGURATION_CONTROLLERS 40017 -#define ID_CONFIGURATION 40018 -#define ID_FILE_RUNCDBIOS 40026 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 108 -#define _APS_NEXT_COMMAND_VALUE 40028 -#define _APS_NEXT_CONTROL_VALUE 1022 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by pcsx.rc +// +#define IDS_TITLE 1 +#define IDR_MENU1 101 +#define IDI_APP_ICON 102 +#define IDD_MCDCONF 102 +#define DEBUG_DIALOG 103 +#define ABOUT_DIALOG 104 +#define IDD_CPUCONF 105 +#define SPLASH_LOGO 113 +#define IDD_GPREGS 114 +#define IDD_CP0REGS 115 +#define IDD_COP2D 116 +#define IDD_COP2C 117 +#define IDD_CONFIG 120 +#define IDD_MEMVIEW 136 +#define IDC_EDIT2 1001 +#define IDC_MCD2 1004 +#define IDC_ASMCHECK1 1005 +#define IDC_MCD1 1005 +#define IDC_MCDSEL1 1006 +#define IDC_STEP 1007 +#define IDC_MCDSEL2 1007 +#define IDC_XA 1007 +#define IDC_SIO 1008 +#define IDC_SKIP 1009 +#define IDC_MDEC 1009 +#define IDC_RESET 1010 +#define IDC_PSXAUTO 1010 +#define IDC_GO 1011 +#define IDC_PSXTYPES 1011 +#define IDC_BREAK 1012 +#define IDC_DISCPUQKEYS 1012 +#define IDC_QKEYS 1012 +#define IDC_EDIT1 1013 +#define IDC_CDDA 1013 +#define IDC_CLOSE 1014 +#define IDC_PCSX_ABOUT_TEXT 1014 +#define IDC_PSXOUT 1014 +#define IDC_ASM_SCROLL 1015 +#define IDC_CPU 1015 +#define IDC_ASMCHECK2 1016 +#define IDC_SPUIRQ 1016 +#define IDC_ASMCHECK3 1017 +#define IDC_MDEC2 1017 +#define IDC_CDTIMING 1017 +#define IDC_ASMCHECK4 1018 +#define IDC_ASMCHECK5 1019 +#define IDC_RELOAD1 1019 +#define IDC_CP07 1020 +#define IDC_ASMCHECK6 1020 +#define IDC_RELOAD2 1020 +#define IDC_ASMCHECK7 1021 +#define IDC_COPYTO2 1021 +#define IDC_ASMCHECK8 1022 +#define IDC_COPYTO1 1022 +#define IDC_ASMCHECK9 1023 +#define IDC_PASTE 1023 +#define IDC_ASMCHECK10 1024 +#define IDC_DELETE1 1024 +#define IDC_ASMCHECK11 1025 +#define IDC_DELETE2 1025 +#define IDC_ASMCHECK12 1026 +#define IDC_LIST1 1027 +#define IDC_ASMCHECK13 1027 +#define IDC_ASMCHECK14 1028 +#define IDC_LIST2 1028 +#define IDC_ASMCHECK15 1029 +#define IDC_ASMCHECK16 1030 +#define IDC_ASMCHECK17 1031 +#define IDC_ASMCHECK18 1032 +#define IDC_ASMCHECK19 1033 +#define IDC_CP021 1034 +#define IDC_ASMCHECK20 1034 +#define IDC_CP022 1035 +#define IDC_ASMCHECK21 1035 +#define IDC_CP023 1036 +#define IDC_ASMCHECK22 1036 +#define IDC_CP024 1037 +#define IDC_ASMCHECK23 1037 +#define IDC_CP025 1038 +#define IDC_ASMCHECK24 1038 +#define IDC_CP031 1044 +#define IDC_GPR0 1047 +#define IDC_GPR1 1048 +#define IDC_GPR2 1049 +#define IDC_GPR3 1050 +#define IDC_GPR4 1051 +#define IDC_GPR5 1052 +#define IDC_LISTGPU 1052 +#define IDC_GPR6 1053 +#define IDC_LISTSPU 1053 +#define IDC_GPR7 1054 +#define IDC_LISTCDR 1054 +#define IDC_GPR8 1055 +#define IDC_LISTBIOS 1055 +#define IDC_GPR9 1056 +#define IDC_CONFIGGPU 1056 +#define IDC_GPR10 1057 +#define IDC_TESTGPU 1057 +#define IDC_ABOUTGPU 1058 +#define IDC_CONFIGSPU 1059 +#define IDC_TESTSPU 1060 +#define IDC_ABOUTSPU 1061 +#define IDC_CONFIGCDR 1062 +#define IDC_GPR11 1063 +#define IDC_TESTCDR 1063 +#define IDC_ABOUTCDR 1064 +#define IDC_COMBODRIVE 1065 +#define IDC_LISTPAD1 1066 +#define IDC_CONFIGPAD1 1067 +#define IDC_GPR12 1068 +#define IDC_TESTPAD1 1068 +#define IDC_GPR13 1069 +#define IDC_ABOUTPAD1 1069 +#define IDC_GPR14 1070 +#define IDC_LISTPAD2 1070 +#define IDC_GPR15 1071 +#define IDC_CONFIGPAD2 1071 +#define IDC_GPR16 1072 +#define IDC_TESTPAD2 1072 +#define IDC_GPR17 1073 +#define IDC_ABOUTPAD2 1073 +#define IDC_GPR18 1074 +#define IDC_GPR19 1075 +#define IDC_GPR20 1076 +#define IDC_GPR21 1077 +#define IDC_GPR22 1078 +#define IDC_GPR23 1079 +#define IDC_GPR24 1080 +#define IDC_GPR25 1081 +#define IDC_GPR26 1082 +#define IDC_GPR27 1083 +#define IDC_GPR28 1084 +#define IDC_GPR29 1085 +#define IDC_GPR30 1086 +#define IDC_GPR31 1087 +#define IDC_GPR_PC 1089 +#define IDC_GPR_HI 1091 +#define IDC_GPR_LO 1092 +#define IDC_CP00 1093 +#define IDC_CP01 1094 +#define IDC_CP02 1095 +#define IDC_CP03 1096 +#define IDC_CP04 1097 +#define IDC_CP05 1098 +#define IDC_CP06 1099 +#define IDC_CP08 1100 +#define IDC_CP09 1101 +#define IDC_CP010 1102 +#define IDC_CP011 1103 +#define IDC_CP012 1104 +#define IDC_CP013 1105 +#define IDC_CP014 1106 +#define IDC_CP015 1107 +#define IDC_CP016 1108 +#define IDC_CP017 1109 +#define IDC_CP018 1110 +#define IDC_CP019 1111 +#define IDC_CP020 1112 +#define IDC_CP026 1113 +#define IDC_CP027 1114 +#define IDC_CP028 1115 +#define IDC_CP029 1116 +#define IDC_CP030 1117 +#define IDC_COP2D0 1118 +#define IDC_COP2D1 1119 +#define IDC_COP2D2 1120 +#define IDC_COP2D3 1121 +#define IDC_COP2D4 1122 +#define IDC_COP2D5 1123 +#define IDC_COP2D6 1124 +#define IDC_COP2D7 1125 +#define IDC_COP2D8 1126 +#define IDC_COP2D9 1127 +#define IDC_COP2D10 1128 +#define IDC_COP2D11 1129 +#define IDC_COP2D12 1130 +#define IDC_COP2D13 1131 +#define IDC_COP2D14 1132 +#define IDC_COP2D15 1133 +#define IDC_COP2D16 1134 +#define IDC_COP2D17 1135 +#define IDC_COP2D18 1136 +#define IDC_COP2D19 1137 +#define IDC_COP2D20 1138 +#define IDC_COP2D21 1139 +#define IDC_COP2D22 1140 +#define IDC_COP2D23 1141 +#define IDC_COP2D24 1142 +#define IDC_COP2D25 1143 +#define IDC_COP2D26 1144 +#define IDC_COP2D27 1145 +#define IDC_COP2D28 1146 +#define IDC_COP2D29 1147 +#define IDC_COP2D30 1148 +#define IDC_COP2D31 1149 +#define IDC_COP2C0 1152 +#define IDC_COP2C1 1153 +#define IDC_COP2C2 1154 +#define IDC_COP2C3 1155 +#define IDC_COP2C4 1156 +#define IDC_COP2C5 1157 +#define IDC_COP2C6 1158 +#define IDC_COP2C7 1159 +#define IDC_COP2C8 1160 +#define IDC_COP2C9 1161 +#define IDC_COP2C10 1162 +#define IDC_COP2C11 1163 +#define IDC_COP2C12 1164 +#define IDC_COP2C13 1165 +#define IDC_COP2C14 1166 +#define IDC_COP2C15 1167 +#define IDC_COP2C16 1168 +#define IDC_COP2C17 1169 +#define IDC_COP2C18 1170 +#define IDC_COP2C19 1171 +#define IDC_COP2C20 1172 +#define IDC_COP2C21 1173 +#define IDC_COP2C22 1174 +#define IDC_COP2C23 1175 +#define IDC_COP2C24 1176 +#define IDC_COP2C25 1177 +#define IDC_COP2C26 1178 +#define IDC_COP2C27 1179 +#define IDC_COP2C28 1180 +#define IDC_COP2C29 1181 +#define IDC_COP2C30 1182 +#define IDC_COP2C31 1183 +#define IDC_BUTTON1 1254 +#define IDC_BIOSDIR 1254 +#define IDC_FORMAT1 1254 +#define IDC_PLUGINSDIR 1255 +#define IDC_FORMAT2 1255 +#define ID_FILE_EXIT 40001 +#define ID_HELP_ABOUT 40002 +#define ID_FILE_RUN_CD 40003 +#define ID_FILE_RUN_EXE 40004 +#define ID_EMULATOR_PAUSE 40005 +#define ID_EMULATOR_RESET 40006 +#define ID_HELP_HELP 40007 +#define ID_DEBUG_ENABLE_DEBUGGER 40008 +#define ID_CONFIGURATION_GRAPHICS 40009 +#define ID_CONFIGURATION_SOUND 40010 +#define ID_CONFIGURATION_CDROM 40011 +#define ID_CONFIGURATION_MEMORYCARDMANAGER 40012 +#define ID_CONFIGURATION_CPU 40013 +#define ID_EMULATOR_RUN 40014 +#define ID_DEBUGREG 40015 +#define ID_DEBUG_MESSAGES 40015 +#define ID_CONFIGURATION_CONTROLLERS 40017 +#define ID_CONFIGURATION 40018 +#define ID_FILE_RUNCDBIOS 40026 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 108 +#define _APS_NEXT_COMMAND_VALUE 40028 +#define _APS_NEXT_CONTROL_VALUE 1022 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/PcsxSrc/ix86/iR3000A.c b/PcsxSrc/ix86/iR3000A.c index c6ff128..2586ca0 100644 --- a/PcsxSrc/ix86/iR3000A.c +++ b/PcsxSrc/ix86/iR3000A.c @@ -1,1236 +1,1236 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifdef __WIN32__ -#pragma warning(disable:4244) -#pragma warning(disable:4761) -#endif -#include -#include -#include - -#include "PsxCommon.h" -#include "ix86.h" - -static u32 *recLUT; - -#define PC_REC(x) (recLUT[x >> 16] + (x & 0xffff)) -#define PC_REC8(x) (*(u8 *)PC_REC(x)) -#define PC_REC16(x) (*(u16*)PC_REC(x)) -#define PC_REC32(x) (*(u32*)PC_REC(x)) - -#define RECMEM_SIZE (8*1024*1024) - -static char *recMem; /* the recompiled blocks will be here */ -static char *recRAM; /* and the ptr to the blocks here */ -static char *recROM; /* and here */ - -static u32 pc; /* recompiler pc */ -static int count; /* recompiler intruction count */ -static int branch; /* set for branch */ -static u32 target; /* branch target */ - -static void (*recBSC[64])(); -static void (*recSPC[64])(); -static void (*recREG[32])(); -static void (*recCP0[32])(); -static void (*recCP2[64])(); -static void (*recCP2BSC[32])(); - -/* set a pending branch */ -#define SetBranch() { \ - branch = 1; \ - psxRegs.code = PSXMu32(pc); \ - pc+=4; count++; \ - recBSC[psxRegs.code>>26](); \ - \ - MOV32MtoR(EAX, (u32)&target); \ - MOV32RtoM((u32)&psxRegs.pc, EAX); \ - CALLFunc((u32)psxBranchTest); \ -} - -#define REC_FUNC(f) \ -void psx##f(); \ -static void rec##f() { \ - MOV32ItoM((u32)&psxRegs.code, (u32)psxRegs.code); \ - MOV32ItoM((u32)&psxRegs.pc, (u32)pc); \ - CALLFunc((u32)psx##f); \ -/* branch = 2; */\ -} - -#define REC_SYS(f) \ -void psx##f(); \ -static void rec##f() { \ - MOV32ItoM((u32)&psxRegs.code, (u32)psxRegs.code); \ - MOV32ItoM((u32)&psxRegs.pc, (u32)pc); \ - CALLFunc((u32)psx##f); \ - branch = 2; \ -} - -#define REC_BRANCH(f) \ -void psx##f(); \ -static void rec##f() { \ - MOV32ItoM((u32)&psxRegs.code, (u32)psxRegs.code); \ - MOV32ItoM((u32)&psxRegs.pc, (u32)pc); \ - CALLFunc((u32)psx##f); \ - branch = 2; \ - count++; \ -} - -static void recRecompile(); - -static int recInit() { - int i; - - recLUT = (u32*) malloc(0x010000 * 4); - - recMem = (char*) malloc(RECMEM_SIZE); - recRAM = (char*) malloc(0x200000); - recROM = (char*) malloc(0x080000); - if (recRAM == NULL || recROM == NULL || recMem == NULL || recLUT == NULL) { - SysMessage("Error allocating memory"); return -1; - } - - for (i=0; i<0x80; i++) recLUT[i + 0x0000] = (u32)&recRAM[(i & 0x1f) << 16]; - memcpy(recLUT + 0x8000, recLUT, 0x80 * 4); - memcpy(recLUT + 0xa000, recLUT, 0x80 * 4); - - for (i=0; i<0x08; i++) recLUT[i + 0xbfc0] = (u32)&recROM[i << 16]; - - return 0; -} - -static void recReset() { - memset(recRAM, 0, 0x200000); - memset(recROM, 0, 0x080000); - - x86Init(recMem); - branch = 0; -} - -static void recShutdown() { - if (recMem == NULL) return; - free(recLUT); - free(recMem); - free(recRAM); - free(recROM); -} - -static void recError() { - SysReset(); - ClosePlugins(); - SysMessage("Unrecoverable error while running recompiler\n"); - SysRunGui(); -} - -#define execute() { \ - void (**recFunc)(); \ - char *p; \ - \ - p = (char*)PC_REC(psxRegs.pc); \ - if (p != NULL) recFunc = (void (**)()) (u32)p; \ - else { recError(); return; } \ - \ - if (*recFunc == 0) { \ - recRecompile(); \ - } \ - (*recFunc)(); \ -} - -static void DumpRegs() { - int i, j; - - printf("%lx %lx\n", psxRegs.pc, psxRegs.cycle); - for (i=0; i<4; i++) { - for (j=0; j<8; j++) - printf("%lx ", psxRegs.GPR.r[j*i]); - printf("\n"); - } -} - -static void recExecuteBios() { - while (psxRegs.pc != 0x80030000) { - execute(); - } -} - -static void recExecute() { - for (;;) execute(); -} - -static void recExecuteBlock() { - execute(); -} - -static void recClear(u32 Addr, u32 Size) { - memset((void*)PC_REC(Addr), 0, Size * 4); -} - -static void recNULL() { -// SysMessage("recUNK: %8.8x\n", psxRegs.code); -} - -/********************************************************* -* goes to opcodes tables... * -* Format: table[something....] * -*********************************************************/ - -//REC_SYS(SPECIAL); -static void recSPECIAL() { - recSPC[_Funct_](); -} - -static void recREGIMM() { - recREG[_Rt_](); -} - -static void recCOP0() { - recCP0[_Rs_](); -} - -//REC_SYS(COP2); -static void recCOP2() { - recCP2[_Funct_](); -} - -static void recBASIC() { - recCP2BSC[_Rs_](); -} - -//end of Tables opcodes... - -/********************************************************* -* Arithmetic with immediate operand * -* Format: OP rt, rs, immediate * -*********************************************************/ -/* -REC_FUNC(ADDI); -REC_FUNC(ADDIU); -REC_FUNC(ANDI); -REC_FUNC(ORI); -REC_FUNC(XORI); -REC_FUNC(SLTI); -REC_FUNC(SLTIU); -#if 0*/ -static void recADDIU() { -// Rt = Rs + Im - if (!_Rt_) return; - - if (_Rs_) { - if (_Rs_ == _Rt_) { - ADD32ItoM((u32)&psxRegs.GPR.r[_Rt_], _Imm_); - } else { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - if (_Imm_) ADD32ItoR(EAX, _Imm_); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); - } - } else { - MOV32ItoM((u32)&psxRegs.GPR.r[_Rt_], _Imm_); - } -} - -static void recADDI() { -// Rt = Rs + Im - recADDIU(); -} - -static void recSLTI() { -// Rt = Rs < Im (signed) - if (!_Rt_) return; - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - CMP32ItoR(EAX, _Imm_); - SETL8R (EAX); - AND32ItoR(EAX, 0xff); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); -} - -static void recSLTIU() { -// Rt = Rs < Im (unsigned) - if (!_Rt_) return; - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - CMP32ItoR(EAX, _Imm_); - SETB8R (EAX); - AND32ItoR(EAX, 0xff); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); -} - -static void recANDI() { -// Rt = Rs And Im - if (!_Rt_) return; - - if (_Rs_ && _ImmU_) { - if (_Rs_ == _Rt_) { - AND32ItoM((u32)&psxRegs.GPR.r[_Rt_], _ImmU_); - } else { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - AND32ItoR(EAX, _ImmU_); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); - } - } else { - XOR32RtoR(EAX, EAX); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); - } -} - -static void recORI() { -// Rt = Rs Or Im - if (!_Rt_) return; - - if (_Rs_) { - if (_Rs_ == _Rt_) { - OR32ItoM((u32)&psxRegs.GPR.r[_Rt_], _ImmU_); - } else { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - if (_ImmU_) OR32ItoR (EAX, _ImmU_); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); - } - } else { - MOV32ItoM((u32)&psxRegs.GPR.r[_Rt_], _ImmU_); - } -} - -static void recXORI() { -// Rt = Rs Xor Im - if (!_Rt_) return; - - if (_Rs_) { - if (_Rs_ == _Rt_) { - XOR32ItoM((u32)&psxRegs.GPR.r[_Rt_], _ImmU_); - } else { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - XOR32ItoR(EAX, _ImmU_); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); - } - } else { - MOV32ItoR(EAX, _ImmU_ ^ 0); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); - } -} -//#endif -//end of * Arithmetic with immediate operand - -/********************************************************* -* Load higher 16 bits of the first word in GPR with imm * -* Format: OP rt, immediate * -*********************************************************/ -/*REC_FUNC(LUI); -#if 0*/ -static void recLUI() { -// Rt = Imm << 16 - if (!_Rt_) return; - - MOV32ItoM((u32)&psxRegs.GPR.r[_Rt_], psxRegs.code << 16); -} -//#endif -//End of Load Higher ..... - - -/********************************************************* -* Register arithmetic * -* Format: OP rd, rs, rt * -*********************************************************/ -/* -REC_FUNC(ADD); -REC_FUNC(ADDU); -REC_FUNC(SUB); -REC_FUNC(SUBU); -REC_FUNC(AND); -REC_FUNC(OR); -REC_FUNC(XOR); -REC_FUNC(NOR); -REC_FUNC(SLT); -REC_FUNC(SLTU); - -#if 0*/ -static void recADDU() { -// Rd = Rs + Rt - if (!_Rd_) return; - - if (_Rs_ && _Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - ADD32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - } else if (_Rs_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - } else if (_Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - } else { - XOR32RtoR(EAX, EAX); - } - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); -} - -static void recADD() { -// Rd = Rs + Rt - recADDU(); -} - -static void recSUBU() { -// Rd = Rs - Rt - if (!_Rd_) return; - - if (_Rs_ || _Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - SUB32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - } else { - XOR32RtoR(EAX, EAX); - } - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); -} - -static void recSUB() { -// Rd = Rs - Rt - recSUBU(); -} - -static void recAND() { -// Rd = Rs And Rt - if (!_Rd_) return; - - if (_Rs_ && _Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - AND32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - } else { - XOR32RtoR(EAX, EAX); - } - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); -} - -static void recOR() { -// Rd = Rs Or Rt - if (!_Rd_) return; - - if (_Rs_ && _Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - OR32MtoR (EAX, (u32)&psxRegs.GPR.r[_Rt_]); - } else if (_Rs_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - } else if (_Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - } else { - XOR32RtoR(EAX, EAX); - } - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); -} - -static void recXOR() { -// Rd = Rs Xor Rt - if (!_Rd_) return; - - if (_Rs_ && _Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - XOR32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - } else if (_Rs_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - XOR32ItoR(EAX, 0); - } else if (_Rt_) { - XOR32RtoR(EAX, EAX); - XOR32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - } else { - XOR32RtoR(EAX, EAX); - } - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); -} - -static void recNOR() { -// Rd = Rs Nor Rt - if (!_Rd_) return; - - if (_Rs_ && _Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - OR32MtoR (EAX, (u32)&psxRegs.GPR.r[_Rt_]); - NOT32R (EAX); - } else if (_Rs_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - NOT32R (EAX); - } else if (_Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - NOT32R (EAX); - } else { - MOV32ItoR(EAX, ~0); - } - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); -} - -static void recSLT() { -// Rd = Rs < Rt (signed) - if (!_Rd_) return; - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - CMP32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - SETL8R (EAX); - AND32ItoR(EAX, 0xff); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); -} - -static void recSLTU() { -// Rd = Rs < Rt (unsigned) - if (!_Rd_) return; - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - CMP32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - SBB32RtoR(EAX, EAX); - NEG32R (EAX); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); -} -//#endif -//End of * Register arithmetic - -/********************************************************* -* Register mult/div & Register trap logic * -* Format: OP rs, rt * -*********************************************************/ - -/*REC_FUNC(MULT); -REC_FUNC(MULTU); -REC_FUNC(DIV); -REC_FUNC(DIVU); -#if 0*/ -static void recMULT() { -// Lo/Hi = Rs * Rt (signed) - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - IMUL32M ((u32)&psxRegs.GPR.r[_Rt_]); - MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); - MOV32RtoM((u32)&psxRegs.GPR.n.hi, EDX); -} - -static void recMULTU() { -// Lo/Hi = Rs * Rt (unsigned) - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - MUL32M ((u32)&psxRegs.GPR.r[_Rt_]); - MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); - MOV32RtoM((u32)&psxRegs.GPR.n.hi, EDX); -} - -static void recDIV() { -// Lo/Hi = Rs / Rt (signed) - - MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rt_]); - CMP32ItoR(ECX, 0); - j8Ptr[0] = JE8(0); - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - CDQ(); - IDIV32R (ECX); - MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); - MOV32RtoM((u32)&psxRegs.GPR.n.hi, EDX); - x86SetJ8(j8Ptr[0]); -} - -static void recDIVU() { -// Lo/Hi = Rs / Rt (unsigned) - - MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rt_]); - CMP32ItoR(ECX, 0); - j8Ptr[0] = JE8(0); - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - XOR32RtoR(EDX, EDX); - DIV32R (ECX); - MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); - MOV32RtoM((u32)&psxRegs.GPR.n.hi, EDX); - x86SetJ8(j8Ptr[0]); -} -//#endif -//End of * Register mult/div & Register trap logic - -/*REC_FUNC(LB); -REC_FUNC(LBU); -REC_FUNC(LH); -REC_FUNC(LHU); -REC_FUNC(LW); - -REC_FUNC(SB); -REC_FUNC(SH); -REC_FUNC(SW);*/ - -REC_FUNC(LWL); -REC_FUNC(LWR); -REC_FUNC(SWL); -REC_FUNC(SWR); -//#if 0 -static void recLB() { -// Rt = mem[Rs + Im] (signed) - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - if (_Imm_) ADD32ItoR(EAX, _Imm_); - PUSH32R (EAX); - CALLFunc((u32)psxMemRead8); - if (_Rt_) { - MOVSX32R8toR(EAX, EAX); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); - } - ADD32ItoR(ESP, 4); -} - -static void recLBU() { -// Rt = mem[Rs + Im] (unsigned) - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - if (_Imm_) ADD32ItoR(EAX, _Imm_); - PUSH32R (EAX); - CALLFunc((u32)psxMemRead8); - if (_Rt_) { - MOVZX32R8toR(EAX, EAX); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); - } - ADD32ItoR(ESP, 4); -} - -static void recLH() { -// Rt = mem[Rs + Im] (signed) - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - if (_Imm_) ADD32ItoR(EAX, _Imm_); - PUSH32R (EAX); - CALLFunc((u32)psxMemRead16); - if (_Rt_) { - MOVSX32R16toR(EAX, EAX); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); - } - ADD32ItoR(ESP, 4); -} - -static void recLHU() { -// Rt = mem[Rs + Im] (unsigned) - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - if (_Imm_) ADD32ItoR(EAX, _Imm_); - PUSH32R (EAX); - CALLFunc((u32)psxMemRead16); - if (_Rt_) { - MOVZX32R16toR(EAX, EAX); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); - } - ADD32ItoR(ESP, 4); -} - -static void recLW() { -// Rt = mem[Rs + Im] (unsigned) - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - if (_Imm_) ADD32ItoR(EAX, _Imm_); - PUSH32R (EAX); - CALLFunc((u32)psxMemRead32); - if (_Rt_) { - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); - } - ADD32ItoR(ESP, 4); -} -/* -void recLWL() { -} - -void recLWR() { -} -*/ -static void recSB() { -// mem[Rs + Im] = Rt - - PUSH32M ((u32)&psxRegs.GPR.r[_Rt_]); - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - if (_Imm_) ADD32ItoR(EAX, _Imm_); - PUSH32R (EAX); - CALLFunc((u32)psxMemWrite8); - ADD32ItoR(ESP, 8); -} - -static void recSH() { -// mem[Rs + Im] = Rt - - PUSH32M ((u32)&psxRegs.GPR.r[_Rt_]); - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - if (_Imm_) ADD32ItoR(EAX, _Imm_); - PUSH32R (EAX); - CALLFunc((u32)psxMemWrite16); - ADD32ItoR(ESP, 8); -} - -static void recSW() { -// mem[Rs + Im] = Rt - - PUSH32M ((u32)&psxRegs.GPR.r[_Rt_]); - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - if (_Imm_) ADD32ItoR(EAX, _Imm_); - PUSH32R (EAX); - CALLFunc((u32)psxMemWrite32); - ADD32ItoR(ESP, 8); -} -//#endif -/* -void recSWL() { -} - -void recSWR() { -} -*/ -/*REC_FUNC(SLL); -REC_FUNC(SRL); -REC_FUNC(SRA); -#if 0*/ -static void recSLL() { -// Rd = Rt << Sa - if (!_Rd_) return; - - if (_Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - if (_Sa_) SHL32ItoR(EAX, _Sa_); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); - } else { - XOR32RtoR(EAX, EAX); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); - } -} - -static void recSRL() { -// Rd = Rt >> Sa - if (!_Rd_) return; - - if (_Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - if (_Sa_) SHR32ItoR(EAX, _Sa_); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); - } else { - XOR32RtoR(EAX, EAX); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); - } -} - -static void recSRA() { -// Rd = Rt >> Sa - if (!_Rd_) return; - - if (_Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - if (_Sa_) SAR32ItoR(EAX, _Sa_); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); - } else { - XOR32RtoR(EAX, EAX); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); - } -} -//#endif - -/*REC_FUNC(SLLV); -REC_FUNC(SRLV); -REC_FUNC(SRAV); -#if 0*/ -static void recSLLV() { -// Rd = Rt << Rs - if (!_Rd_) return; - - if (_Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - if (_Rs_) { - MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rs_]); - SHL32CLtoR(EAX); - } - } - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); -} - -static void recSRLV() { -// Rd = Rt >> Rs - if (!_Rd_) return; - - if (_Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - if (_Rs_) { - MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rs_]); - SHR32CLtoR(EAX); - } - } - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); -} - -static void recSRAV() { -// Rd = Rt >> Rs - if (!_Rd_) return; - - if (_Rt_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - if (_Rs_) { - MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rs_]); - SAR32CLtoR(EAX); - } - } - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); -} -//#endif - -/*REC_SYS(SYSCALL); -REC_SYS(BREAK); - -#if 0*/ -static void recSYSCALL() { - MOV32ItoR(EAX, pc - 4); - MOV32RtoM((u32)&psxRegs.pc, EAX); - PUSH32I (branch == 1 ? 1 : 0); - PUSH32I (0x20); - CALLFunc ((u32)psxException); - ADD32ItoR(ESP, 8); - - if (!branch) branch = 2; -} - -static void recBREAK() { -} -//#endif -/* -REC_FUNC(MFHI); -REC_FUNC(MTHI); -REC_FUNC(MFLO); -REC_FUNC(MTLO); -#if 0*/ -static void recMFHI() { -// Rd = Hi - if (!_Rd_) return; - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.n.hi); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); -} - -static void recMTHI() { -// Hi = Rs - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - MOV32RtoM((u32)&psxRegs.GPR.n.hi, EAX); -} - -static void recMFLO() { -// Rd = Lo - if (!_Rd_) return; - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.n.lo); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); -} - -static void recMTLO() { -// Lo = Rs - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); -} -//#endif - -/*REC_BRANCH(J); -REC_BRANCH(JR); -REC_BRANCH(JAL); -REC_BRANCH(JALR); -REC_BRANCH(BLTZ); -REC_BRANCH(BGTZ); -REC_BRANCH(BLTZAL); -REC_BRANCH(BGEZAL); -REC_BRANCH(BNE); -REC_BRANCH(BEQ); -REC_BRANCH(BLEZ); -REC_BRANCH(BGEZ); - -#if 0*/ -static void recBLTZ() { -// Branch if Rs < 0 - - CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0); - j8Ptr[0] = JL8(0); - - MOV32ItoM((u32)&target, pc+4); - j8Ptr[1] = JMP8(0); - - x86SetJ8(j8Ptr[0]); - - MOV32ItoM((u32)&target, _Imm_ * 4 + pc); - - x86SetJ8(j8Ptr[1]); - - SetBranch(); -} - -static void recBGEZ() { -// Branch if Rs >= 0 - - CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0); - j8Ptr[0] = JGE8(0); - - MOV32ItoM((u32)&target, pc+4); - j8Ptr[1] = JMP8(0); - - x86SetJ8(j8Ptr[0]); - - MOV32ItoM((u32)&target, _Imm_ * 4 + pc); - - x86SetJ8(j8Ptr[1]); - - SetBranch(); -} - -static void recBLTZAL() { -// Branch if Rs < 0 - - CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0); - j8Ptr[0] = JL8(0); - - MOV32ItoM((u32)&target, pc+4); - j8Ptr[1] = JMP8(0); - - x86SetJ8(j8Ptr[0]); - - MOV32ItoM((u32)&target, _Imm_ * 4 + pc); - MOV32ItoM((u32)&psxRegs.GPR.r[31], pc + 4); - - x86SetJ8(j8Ptr[1]); - - SetBranch(); -} - -static void recBGEZAL() { -// Branch if Rs >= 0 - - CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0); - j8Ptr[0] = JGE8(0); - - MOV32ItoM((u32)&target, pc+4); - j8Ptr[1] = JMP8(0); - - x86SetJ8(j8Ptr[0]); - - MOV32ItoM((u32)&target, _Imm_ * 4 + pc); - MOV32ItoM((u32)&psxRegs.GPR.r[31], pc + 4); - - x86SetJ8(j8Ptr[1]); - - SetBranch(); -} - -static void recJ() { -// j target - MOV32ItoM((u32)&target, _Target_ * 4 + (pc & 0xf0000000)); - - SetBranch(); -} - -static void recJAL() { -// jal target - - MOV32ItoM((u32)&target, _Target_ * 4 + (pc & 0xf0000000)); - MOV32ItoM((u32)&psxRegs.GPR.r[31], pc + 4); - - SetBranch(); -} - -static void recJR() { -// jr Rs - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - MOV32RtoM((u32)&target, EAX); - - SetBranch(); -} - -static void recJALR() { -// jalr Rs - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - MOV32RtoM((u32)&target, EAX); - - if (_Rd_) { - MOV32ItoM((u32)&psxRegs.GPR.r[_Rd_], pc + 4); - } - - SetBranch(); -} - -static void recBEQ() { -// Branch if Rs == Rt - - if (_Rs_ == _Rt_) { - MOV32ItoM((u32)&target, _Imm_ * 4 + pc); - } else { - if (_Rs_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - } else { - XOR32RtoR(EAX, EAX); - } - CMP32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - j8Ptr[0] = JE8(0); - - MOV32ItoM((u32)&target, pc+4); - j8Ptr[1] = JMP8(0); - - x86SetJ8(j8Ptr[0]); - - MOV32ItoM((u32)&target, _Imm_ * 4 + pc); - - x86SetJ8(j8Ptr[1]); - } - - SetBranch(); -} - -static void recBNE() { -// Branch if Rs != Rt - - if (_Rs_) { - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); - } else { - XOR32RtoR(EAX, EAX); - } - CMP32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - j8Ptr[0] = JNE8(0); - - MOV32ItoM((u32)&target, pc+4); - j8Ptr[1] = JMP8(0); - - x86SetJ8(j8Ptr[0]); - - MOV32ItoM((u32)&target, _Imm_ * 4 + pc); - - x86SetJ8(j8Ptr[1]); - - SetBranch(); -} - -static void recBLEZ() { -// Branch if Rs <= 0 - - CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0); - j8Ptr[0] = JLE8(0); - - MOV32ItoM((u32)&target, pc+4); - j8Ptr[1] = JMP8(0); - - x86SetJ8(j8Ptr[0]); - - MOV32ItoM((u32)&target, _Imm_ * 4 + pc); - - x86SetJ8(j8Ptr[1]); - - SetBranch(); -} - -static void recBGTZ() { -// Branch if Rs > 0 - - CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0); - j8Ptr[0] = JG8(0); - - MOV32ItoM((u32)&target, pc+4); - j8Ptr[1] = JMP8(0); - - x86SetJ8(j8Ptr[0]); - - MOV32ItoM((u32)&target, _Imm_ * 4 + pc); - - x86SetJ8(j8Ptr[1]); - - SetBranch(); -} -//#endif - -/*REC_FUNC(MFC0); -REC_FUNC(MTC0); -REC_FUNC(CFC0); -REC_FUNC(CTC0); -REC_FUNC(RFE); -#if 0*/ -static void recMFC0() { -// Rt = Cop0->Rd - if (!_Rt_) return; - - MOV32MtoR(EAX, (u32)&psxRegs.CP0.r[_Rd_]); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); -} - -static void recCFC0() { -// Rt = Cop0->Rd - if (!_Rt_) return; - - MOV32MtoR(EAX, (u32)&psxRegs.CP0.r[_Rd_]); - MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); -} - -static void recMTC0() { -// Cop0->Rd = Rt - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - MOV32RtoM((u32)&psxRegs.CP0.r[_Rd_], EAX); -} - -static void recCTC0() { -// Cop0->Rd = Rt - - MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); - MOV32RtoM((u32)&psxRegs.CP0.r[_Rd_], EAX); -} - -static void recRFE() { - MOV32MtoR(EAX, (u32)&psxRegs.CP0.n.Status); - MOV32RtoR(ECX, EAX); - AND32ItoR(EAX, 0xfffffff0); - AND32ItoR(ECX, 0x3c); - SHR32ItoR(ECX, 2); - OR32RtoR (EAX, ECX); - MOV32RtoM((u32)&psxRegs.CP0.n.Status, EAX); -} -//#endif - -#define CP2_FUNC(f) \ -void gte##f(); \ -static void rec##f() { \ - MOV32ItoM((u32)&psxRegs.code, (u32)psxRegs.code); \ - MOV32ItoM((u32)&psxRegs.pc, (u32)pc); \ - CALLFunc ((u32)gte##f); \ -/* branch = 2; */\ -} - -CP2_FUNC(MFC2); -CP2_FUNC(MTC2); -CP2_FUNC(CFC2); -CP2_FUNC(CTC2); -CP2_FUNC(LWC2); -CP2_FUNC(SWC2); - -CP2_FUNC(RTPS); -CP2_FUNC(OP); -CP2_FUNC(NCLIP); -CP2_FUNC(DPCS); -CP2_FUNC(INTPL); -CP2_FUNC(MVMVA); -CP2_FUNC(NCDS); -CP2_FUNC(NCDT); -CP2_FUNC(CDP); -CP2_FUNC(NCCS); -CP2_FUNC(CC); -CP2_FUNC(NCS); -CP2_FUNC(NCT); -CP2_FUNC(SQR); -CP2_FUNC(DCPL); -CP2_FUNC(DPCT); -CP2_FUNC(AVSZ3); -CP2_FUNC(AVSZ4); -CP2_FUNC(RTPT); -CP2_FUNC(GPF); -CP2_FUNC(GPL); -CP2_FUNC(NCCT); - -static void recHLE() { - MOV32ItoR(EAX, (u32)psxHLEt[psxRegs.code & 0xff]); - CALL32R(EAX); - branch = 2; -} - -// - -static void (*recBSC[64])() = { - recSPECIAL, recREGIMM, recJ , recJAL , recBEQ , recBNE , recBLEZ, recBGTZ, - recADDI , recADDIU , recSLTI, recSLTIU, recANDI, recORI , recXORI, recLUI , - recCOP0 , recNULL , recCOP2, recNULL , recNULL, recNULL, recNULL, recNULL, - recNULL , recNULL , recNULL, recNULL , recNULL, recNULL, recNULL, recNULL, - recLB , recLH , recLWL , recLW , recLBU , recLHU , recLWR , recNULL, - recSB , recSH , recSWL , recSW , recNULL, recNULL, recSWR , recNULL, - recNULL , recNULL , recLWC2, recNULL , recNULL, recNULL, recNULL, recNULL, - recNULL , recNULL , recSWC2, recHLE , recNULL, recNULL, recNULL, recNULL -}; - -static void (*recSPC[64])() = { - recSLL , recNULL, recSRL , recSRA , recSLLV , recNULL , recSRLV, recSRAV, - recJR , recJALR, recNULL, recNULL, recSYSCALL, recBREAK, recNULL, recNULL, - recMFHI, recMTHI, recMFLO, recMTLO, recNULL , recNULL , recNULL, recNULL, - recMULT, recMULTU, recDIV, recDIVU, recNULL , recNULL , recNULL, recNULL, - recADD , recADDU, recSUB , recSUBU, recAND , recOR , recXOR , recNOR , - recNULL, recNULL, recSLT , recSLTU, recNULL , recNULL , recNULL, recNULL, - recNULL, recNULL, recNULL, recNULL, recNULL , recNULL , recNULL, recNULL, - recNULL, recNULL, recNULL, recNULL, recNULL , recNULL , recNULL, recNULL -}; - -static void (*recREG[32])() = { - recBLTZ , recBGEZ , recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, - recNULL , recNULL , recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, - recBLTZAL, recBGEZAL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, - recNULL , recNULL , recNULL, recNULL, recNULL, recNULL, recNULL, recNULL -}; - -static void (*recCP0[32])() = { - recMFC0, recNULL, recCFC0, recNULL, recMTC0, recNULL, recCTC0, recNULL, - recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, - recRFE , recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, - recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL -}; - -static void (*recCP2[64])() = { - recBASIC, recRTPS , recNULL , recNULL, recNULL, recNULL , recNCLIP, recNULL, // 00 - recNULL , recNULL , recNULL , recNULL, recOP , recNULL , recNULL , recNULL, // 08 - recDPCS , recINTPL, recMVMVA, recNCDS, recCDP , recNULL , recNCDT , recNULL, // 10 - recNULL , recNULL , recNULL , recNCCS, recCC , recNULL , recNCS , recNULL, // 18 - recNCT , recNULL , recNULL , recNULL, recNULL, recNULL , recNULL , recNULL, // 20 - recSQR , recDCPL , recDPCT , recNULL, recNULL, recAVSZ3, recAVSZ4, recNULL, // 28 - recRTPT , recNULL , recNULL , recNULL, recNULL, recNULL , recNULL , recNULL, // 30 - recNULL , recNULL , recNULL , recNULL, recNULL, recGPF , recGPL , recNCCT // 38 -}; - -static void (*recCP2BSC[32])() = { - recMFC2, recNULL, recCFC2, recNULL, recMTC2, recNULL, recCTC2, recNULL, - recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, - recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, - recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL -}; - -static void recRecompile() { - /* if x86Ptr reached the mem limit reset whole mem */ - if (((u32)x86Ptr - (u32)recMem) >= (RECMEM_SIZE - 0x10000)) - recReset(); - - PC_REC32(psxRegs.pc) = (u32)x86Ptr; - pc = psxRegs.pc; - - for (count=0; count<500;) { - char *p; - - p = (char *)PSXM(pc); - if (p == NULL) recError(); - psxRegs.code = *(u32 *)p; - - pc+=4; count++; - recBSC[psxRegs.code>>26](); - - if (branch) { - break; - } - } - - if (!branch) { - MOV32ItoM((u32)&psxRegs.pc, pc); - } - - /* store cycle */ - ADD32ItoM((u32)&psxRegs.cycle, count); - - branch = 0; - - RET(); -} - - -R3000Acpu psxRec = { - recInit, - recReset, - recExecute, - recExecuteBlock, - recClear, - recShutdown -}; +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifdef __WIN32__ +#pragma warning(disable:4244) +#pragma warning(disable:4761) +#endif +#include +#include +#include + +#include "PsxCommon.h" +#include "ix86.h" + +static u32 *recLUT; + +#define PC_REC(x) (recLUT[x >> 16] + (x & 0xffff)) +#define PC_REC8(x) (*(u8 *)PC_REC(x)) +#define PC_REC16(x) (*(u16*)PC_REC(x)) +#define PC_REC32(x) (*(u32*)PC_REC(x)) + +#define RECMEM_SIZE (8*1024*1024) + +static char *recMem; /* the recompiled blocks will be here */ +static char *recRAM; /* and the ptr to the blocks here */ +static char *recROM; /* and here */ + +static u32 pc; /* recompiler pc */ +static int count; /* recompiler intruction count */ +static int branch; /* set for branch */ +static u32 target; /* branch target */ + +static void (*recBSC[64])(); +static void (*recSPC[64])(); +static void (*recREG[32])(); +static void (*recCP0[32])(); +static void (*recCP2[64])(); +static void (*recCP2BSC[32])(); + +/* set a pending branch */ +#define SetBranch() { \ + branch = 1; \ + psxRegs.code = PSXMu32(pc); \ + pc+=4; count++; \ + recBSC[psxRegs.code>>26](); \ + \ + MOV32MtoR(EAX, (u32)&target); \ + MOV32RtoM((u32)&psxRegs.pc, EAX); \ + CALLFunc((u32)psxBranchTest); \ +} + +#define REC_FUNC(f) \ +void psx##f(); \ +static void rec##f() { \ + MOV32ItoM((u32)&psxRegs.code, (u32)psxRegs.code); \ + MOV32ItoM((u32)&psxRegs.pc, (u32)pc); \ + CALLFunc((u32)psx##f); \ +/* branch = 2; */\ +} + +#define REC_SYS(f) \ +void psx##f(); \ +static void rec##f() { \ + MOV32ItoM((u32)&psxRegs.code, (u32)psxRegs.code); \ + MOV32ItoM((u32)&psxRegs.pc, (u32)pc); \ + CALLFunc((u32)psx##f); \ + branch = 2; \ +} + +#define REC_BRANCH(f) \ +void psx##f(); \ +static void rec##f() { \ + MOV32ItoM((u32)&psxRegs.code, (u32)psxRegs.code); \ + MOV32ItoM((u32)&psxRegs.pc, (u32)pc); \ + CALLFunc((u32)psx##f); \ + branch = 2; \ + count++; \ +} + +static void recRecompile(); + +static int recInit() { + int i; + + recLUT = (u32*) malloc(0x010000 * 4); + + recMem = (char*) malloc(RECMEM_SIZE); + recRAM = (char*) malloc(0x200000); + recROM = (char*) malloc(0x080000); + if (recRAM == NULL || recROM == NULL || recMem == NULL || recLUT == NULL) { + SysMessage("Error allocating memory"); return -1; + } + + for (i=0; i<0x80; i++) recLUT[i + 0x0000] = (u32)&recRAM[(i & 0x1f) << 16]; + memcpy(recLUT + 0x8000, recLUT, 0x80 * 4); + memcpy(recLUT + 0xa000, recLUT, 0x80 * 4); + + for (i=0; i<0x08; i++) recLUT[i + 0xbfc0] = (u32)&recROM[i << 16]; + + return 0; +} + +static void recReset() { + memset(recRAM, 0, 0x200000); + memset(recROM, 0, 0x080000); + + x86Init(recMem); + branch = 0; +} + +static void recShutdown() { + if (recMem == NULL) return; + free(recLUT); + free(recMem); + free(recRAM); + free(recROM); +} + +static void recError() { + SysReset(); + ClosePlugins(); + SysMessage("Unrecoverable error while running recompiler\n"); + SysRunGui(); +} + +#define execute() { \ + void (**recFunc)(); \ + char *p; \ + \ + p = (char*)PC_REC(psxRegs.pc); \ + if (p != NULL) recFunc = (void (**)()) (u32)p; \ + else { recError(); return; } \ + \ + if (*recFunc == 0) { \ + recRecompile(); \ + } \ + (*recFunc)(); \ +} + +static void DumpRegs() { + int i, j; + + printf("%lx %lx\n", psxRegs.pc, psxRegs.cycle); + for (i=0; i<4; i++) { + for (j=0; j<8; j++) + printf("%lx ", psxRegs.GPR.r[j*i]); + printf("\n"); + } +} + +static void recExecuteBios() { + while (psxRegs.pc != 0x80030000) { + execute(); + } +} + +static void recExecute() { + for (;;) execute(); +} + +static void recExecuteBlock() { + execute(); +} + +static void recClear(u32 Addr, u32 Size) { + memset((void*)PC_REC(Addr), 0, Size * 4); +} + +static void recNULL() { +// SysMessage("recUNK: %8.8x\n", psxRegs.code); +} + +/********************************************************* +* goes to opcodes tables... * +* Format: table[something....] * +*********************************************************/ + +//REC_SYS(SPECIAL); +static void recSPECIAL() { + recSPC[_Funct_](); +} + +static void recREGIMM() { + recREG[_Rt_](); +} + +static void recCOP0() { + recCP0[_Rs_](); +} + +//REC_SYS(COP2); +static void recCOP2() { + recCP2[_Funct_](); +} + +static void recBASIC() { + recCP2BSC[_Rs_](); +} + +//end of Tables opcodes... + +/********************************************************* +* Arithmetic with immediate operand * +* Format: OP rt, rs, immediate * +*********************************************************/ +/* +REC_FUNC(ADDI); +REC_FUNC(ADDIU); +REC_FUNC(ANDI); +REC_FUNC(ORI); +REC_FUNC(XORI); +REC_FUNC(SLTI); +REC_FUNC(SLTIU); +#if 0*/ +static void recADDIU() { +// Rt = Rs + Im + if (!_Rt_) return; + + if (_Rs_) { + if (_Rs_ == _Rt_) { + ADD32ItoM((u32)&psxRegs.GPR.r[_Rt_], _Imm_); + } else { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + if (_Imm_) ADD32ItoR(EAX, _Imm_); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); + } + } else { + MOV32ItoM((u32)&psxRegs.GPR.r[_Rt_], _Imm_); + } +} + +static void recADDI() { +// Rt = Rs + Im + recADDIU(); +} + +static void recSLTI() { +// Rt = Rs < Im (signed) + if (!_Rt_) return; + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + CMP32ItoR(EAX, _Imm_); + SETL8R (EAX); + AND32ItoR(EAX, 0xff); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); +} + +static void recSLTIU() { +// Rt = Rs < Im (unsigned) + if (!_Rt_) return; + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + CMP32ItoR(EAX, _Imm_); + SETB8R (EAX); + AND32ItoR(EAX, 0xff); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); +} + +static void recANDI() { +// Rt = Rs And Im + if (!_Rt_) return; + + if (_Rs_ && _ImmU_) { + if (_Rs_ == _Rt_) { + AND32ItoM((u32)&psxRegs.GPR.r[_Rt_], _ImmU_); + } else { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + AND32ItoR(EAX, _ImmU_); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); + } + } else { + XOR32RtoR(EAX, EAX); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); + } +} + +static void recORI() { +// Rt = Rs Or Im + if (!_Rt_) return; + + if (_Rs_) { + if (_Rs_ == _Rt_) { + OR32ItoM((u32)&psxRegs.GPR.r[_Rt_], _ImmU_); + } else { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + if (_ImmU_) OR32ItoR (EAX, _ImmU_); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); + } + } else { + MOV32ItoM((u32)&psxRegs.GPR.r[_Rt_], _ImmU_); + } +} + +static void recXORI() { +// Rt = Rs Xor Im + if (!_Rt_) return; + + if (_Rs_) { + if (_Rs_ == _Rt_) { + XOR32ItoM((u32)&psxRegs.GPR.r[_Rt_], _ImmU_); + } else { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + XOR32ItoR(EAX, _ImmU_); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); + } + } else { + MOV32ItoR(EAX, _ImmU_ ^ 0); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); + } +} +//#endif +//end of * Arithmetic with immediate operand + +/********************************************************* +* Load higher 16 bits of the first word in GPR with imm * +* Format: OP rt, immediate * +*********************************************************/ +/*REC_FUNC(LUI); +#if 0*/ +static void recLUI() { +// Rt = Imm << 16 + if (!_Rt_) return; + + MOV32ItoM((u32)&psxRegs.GPR.r[_Rt_], psxRegs.code << 16); +} +//#endif +//End of Load Higher ..... + + +/********************************************************* +* Register arithmetic * +* Format: OP rd, rs, rt * +*********************************************************/ +/* +REC_FUNC(ADD); +REC_FUNC(ADDU); +REC_FUNC(SUB); +REC_FUNC(SUBU); +REC_FUNC(AND); +REC_FUNC(OR); +REC_FUNC(XOR); +REC_FUNC(NOR); +REC_FUNC(SLT); +REC_FUNC(SLTU); + +#if 0*/ +static void recADDU() { +// Rd = Rs + Rt + if (!_Rd_) return; + + if (_Rs_ && _Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + ADD32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + } else if (_Rs_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + } else if (_Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + } else { + XOR32RtoR(EAX, EAX); + } + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); +} + +static void recADD() { +// Rd = Rs + Rt + recADDU(); +} + +static void recSUBU() { +// Rd = Rs - Rt + if (!_Rd_) return; + + if (_Rs_ || _Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + SUB32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + } else { + XOR32RtoR(EAX, EAX); + } + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); +} + +static void recSUB() { +// Rd = Rs - Rt + recSUBU(); +} + +static void recAND() { +// Rd = Rs And Rt + if (!_Rd_) return; + + if (_Rs_ && _Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + AND32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + } else { + XOR32RtoR(EAX, EAX); + } + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); +} + +static void recOR() { +// Rd = Rs Or Rt + if (!_Rd_) return; + + if (_Rs_ && _Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + OR32MtoR (EAX, (u32)&psxRegs.GPR.r[_Rt_]); + } else if (_Rs_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + } else if (_Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + } else { + XOR32RtoR(EAX, EAX); + } + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); +} + +static void recXOR() { +// Rd = Rs Xor Rt + if (!_Rd_) return; + + if (_Rs_ && _Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + XOR32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + } else if (_Rs_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + XOR32ItoR(EAX, 0); + } else if (_Rt_) { + XOR32RtoR(EAX, EAX); + XOR32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + } else { + XOR32RtoR(EAX, EAX); + } + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); +} + +static void recNOR() { +// Rd = Rs Nor Rt + if (!_Rd_) return; + + if (_Rs_ && _Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + OR32MtoR (EAX, (u32)&psxRegs.GPR.r[_Rt_]); + NOT32R (EAX); + } else if (_Rs_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + NOT32R (EAX); + } else if (_Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + NOT32R (EAX); + } else { + MOV32ItoR(EAX, ~0); + } + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); +} + +static void recSLT() { +// Rd = Rs < Rt (signed) + if (!_Rd_) return; + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + CMP32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + SETL8R (EAX); + AND32ItoR(EAX, 0xff); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); +} + +static void recSLTU() { +// Rd = Rs < Rt (unsigned) + if (!_Rd_) return; + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + CMP32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + SBB32RtoR(EAX, EAX); + NEG32R (EAX); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); +} +//#endif +//End of * Register arithmetic + +/********************************************************* +* Register mult/div & Register trap logic * +* Format: OP rs, rt * +*********************************************************/ + +/*REC_FUNC(MULT); +REC_FUNC(MULTU); +REC_FUNC(DIV); +REC_FUNC(DIVU); +#if 0*/ +static void recMULT() { +// Lo/Hi = Rs * Rt (signed) + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + IMUL32M ((u32)&psxRegs.GPR.r[_Rt_]); + MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); + MOV32RtoM((u32)&psxRegs.GPR.n.hi, EDX); +} + +static void recMULTU() { +// Lo/Hi = Rs * Rt (unsigned) + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + MUL32M ((u32)&psxRegs.GPR.r[_Rt_]); + MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); + MOV32RtoM((u32)&psxRegs.GPR.n.hi, EDX); +} + +static void recDIV() { +// Lo/Hi = Rs / Rt (signed) + + MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rt_]); + CMP32ItoR(ECX, 0); + j8Ptr[0] = JE8(0); + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + CDQ(); + IDIV32R (ECX); + MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); + MOV32RtoM((u32)&psxRegs.GPR.n.hi, EDX); + x86SetJ8(j8Ptr[0]); +} + +static void recDIVU() { +// Lo/Hi = Rs / Rt (unsigned) + + MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rt_]); + CMP32ItoR(ECX, 0); + j8Ptr[0] = JE8(0); + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + XOR32RtoR(EDX, EDX); + DIV32R (ECX); + MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); + MOV32RtoM((u32)&psxRegs.GPR.n.hi, EDX); + x86SetJ8(j8Ptr[0]); +} +//#endif +//End of * Register mult/div & Register trap logic + +/*REC_FUNC(LB); +REC_FUNC(LBU); +REC_FUNC(LH); +REC_FUNC(LHU); +REC_FUNC(LW); + +REC_FUNC(SB); +REC_FUNC(SH); +REC_FUNC(SW);*/ + +REC_FUNC(LWL); +REC_FUNC(LWR); +REC_FUNC(SWL); +REC_FUNC(SWR); +//#if 0 +static void recLB() { +// Rt = mem[Rs + Im] (signed) + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + if (_Imm_) ADD32ItoR(EAX, _Imm_); + PUSH32R (EAX); + CALLFunc((u32)psxMemRead8); + if (_Rt_) { + MOVSX32R8toR(EAX, EAX); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); + } + ADD32ItoR(ESP, 4); +} + +static void recLBU() { +// Rt = mem[Rs + Im] (unsigned) + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + if (_Imm_) ADD32ItoR(EAX, _Imm_); + PUSH32R (EAX); + CALLFunc((u32)psxMemRead8); + if (_Rt_) { + MOVZX32R8toR(EAX, EAX); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); + } + ADD32ItoR(ESP, 4); +} + +static void recLH() { +// Rt = mem[Rs + Im] (signed) + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + if (_Imm_) ADD32ItoR(EAX, _Imm_); + PUSH32R (EAX); + CALLFunc((u32)psxMemRead16); + if (_Rt_) { + MOVSX32R16toR(EAX, EAX); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); + } + ADD32ItoR(ESP, 4); +} + +static void recLHU() { +// Rt = mem[Rs + Im] (unsigned) + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + if (_Imm_) ADD32ItoR(EAX, _Imm_); + PUSH32R (EAX); + CALLFunc((u32)psxMemRead16); + if (_Rt_) { + MOVZX32R16toR(EAX, EAX); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); + } + ADD32ItoR(ESP, 4); +} + +static void recLW() { +// Rt = mem[Rs + Im] (unsigned) + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + if (_Imm_) ADD32ItoR(EAX, _Imm_); + PUSH32R (EAX); + CALLFunc((u32)psxMemRead32); + if (_Rt_) { + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); + } + ADD32ItoR(ESP, 4); +} +/* +void recLWL() { +} + +void recLWR() { +} +*/ +static void recSB() { +// mem[Rs + Im] = Rt + + PUSH32M ((u32)&psxRegs.GPR.r[_Rt_]); + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + if (_Imm_) ADD32ItoR(EAX, _Imm_); + PUSH32R (EAX); + CALLFunc((u32)psxMemWrite8); + ADD32ItoR(ESP, 8); +} + +static void recSH() { +// mem[Rs + Im] = Rt + + PUSH32M ((u32)&psxRegs.GPR.r[_Rt_]); + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + if (_Imm_) ADD32ItoR(EAX, _Imm_); + PUSH32R (EAX); + CALLFunc((u32)psxMemWrite16); + ADD32ItoR(ESP, 8); +} + +static void recSW() { +// mem[Rs + Im] = Rt + + PUSH32M ((u32)&psxRegs.GPR.r[_Rt_]); + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + if (_Imm_) ADD32ItoR(EAX, _Imm_); + PUSH32R (EAX); + CALLFunc((u32)psxMemWrite32); + ADD32ItoR(ESP, 8); +} +//#endif +/* +void recSWL() { +} + +void recSWR() { +} +*/ +/*REC_FUNC(SLL); +REC_FUNC(SRL); +REC_FUNC(SRA); +#if 0*/ +static void recSLL() { +// Rd = Rt << Sa + if (!_Rd_) return; + + if (_Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + if (_Sa_) SHL32ItoR(EAX, _Sa_); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); + } else { + XOR32RtoR(EAX, EAX); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); + } +} + +static void recSRL() { +// Rd = Rt >> Sa + if (!_Rd_) return; + + if (_Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + if (_Sa_) SHR32ItoR(EAX, _Sa_); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); + } else { + XOR32RtoR(EAX, EAX); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); + } +} + +static void recSRA() { +// Rd = Rt >> Sa + if (!_Rd_) return; + + if (_Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + if (_Sa_) SAR32ItoR(EAX, _Sa_); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); + } else { + XOR32RtoR(EAX, EAX); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); + } +} +//#endif + +/*REC_FUNC(SLLV); +REC_FUNC(SRLV); +REC_FUNC(SRAV); +#if 0*/ +static void recSLLV() { +// Rd = Rt << Rs + if (!_Rd_) return; + + if (_Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + if (_Rs_) { + MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rs_]); + SHL32CLtoR(EAX); + } + } + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); +} + +static void recSRLV() { +// Rd = Rt >> Rs + if (!_Rd_) return; + + if (_Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + if (_Rs_) { + MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rs_]); + SHR32CLtoR(EAX); + } + } + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); +} + +static void recSRAV() { +// Rd = Rt >> Rs + if (!_Rd_) return; + + if (_Rt_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + if (_Rs_) { + MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rs_]); + SAR32CLtoR(EAX); + } + } + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); +} +//#endif + +/*REC_SYS(SYSCALL); +REC_SYS(BREAK); + +#if 0*/ +static void recSYSCALL() { + MOV32ItoR(EAX, pc - 4); + MOV32RtoM((u32)&psxRegs.pc, EAX); + PUSH32I (branch == 1 ? 1 : 0); + PUSH32I (0x20); + CALLFunc ((u32)psxException); + ADD32ItoR(ESP, 8); + + if (!branch) branch = 2; +} + +static void recBREAK() { +} +//#endif +/* +REC_FUNC(MFHI); +REC_FUNC(MTHI); +REC_FUNC(MFLO); +REC_FUNC(MTLO); +#if 0*/ +static void recMFHI() { +// Rd = Hi + if (!_Rd_) return; + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.n.hi); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); +} + +static void recMTHI() { +// Hi = Rs + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + MOV32RtoM((u32)&psxRegs.GPR.n.hi, EAX); +} + +static void recMFLO() { +// Rd = Lo + if (!_Rd_) return; + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.n.lo); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); +} + +static void recMTLO() { +// Lo = Rs + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); +} +//#endif + +/*REC_BRANCH(J); +REC_BRANCH(JR); +REC_BRANCH(JAL); +REC_BRANCH(JALR); +REC_BRANCH(BLTZ); +REC_BRANCH(BGTZ); +REC_BRANCH(BLTZAL); +REC_BRANCH(BGEZAL); +REC_BRANCH(BNE); +REC_BRANCH(BEQ); +REC_BRANCH(BLEZ); +REC_BRANCH(BGEZ); + +#if 0*/ +static void recBLTZ() { +// Branch if Rs < 0 + + CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0); + j8Ptr[0] = JL8(0); + + MOV32ItoM((u32)&target, pc+4); + j8Ptr[1] = JMP8(0); + + x86SetJ8(j8Ptr[0]); + + MOV32ItoM((u32)&target, _Imm_ * 4 + pc); + + x86SetJ8(j8Ptr[1]); + + SetBranch(); +} + +static void recBGEZ() { +// Branch if Rs >= 0 + + CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0); + j8Ptr[0] = JGE8(0); + + MOV32ItoM((u32)&target, pc+4); + j8Ptr[1] = JMP8(0); + + x86SetJ8(j8Ptr[0]); + + MOV32ItoM((u32)&target, _Imm_ * 4 + pc); + + x86SetJ8(j8Ptr[1]); + + SetBranch(); +} + +static void recBLTZAL() { +// Branch if Rs < 0 + + CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0); + j8Ptr[0] = JL8(0); + + MOV32ItoM((u32)&target, pc+4); + j8Ptr[1] = JMP8(0); + + x86SetJ8(j8Ptr[0]); + + MOV32ItoM((u32)&target, _Imm_ * 4 + pc); + MOV32ItoM((u32)&psxRegs.GPR.r[31], pc + 4); + + x86SetJ8(j8Ptr[1]); + + SetBranch(); +} + +static void recBGEZAL() { +// Branch if Rs >= 0 + + CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0); + j8Ptr[0] = JGE8(0); + + MOV32ItoM((u32)&target, pc+4); + j8Ptr[1] = JMP8(0); + + x86SetJ8(j8Ptr[0]); + + MOV32ItoM((u32)&target, _Imm_ * 4 + pc); + MOV32ItoM((u32)&psxRegs.GPR.r[31], pc + 4); + + x86SetJ8(j8Ptr[1]); + + SetBranch(); +} + +static void recJ() { +// j target + MOV32ItoM((u32)&target, _Target_ * 4 + (pc & 0xf0000000)); + + SetBranch(); +} + +static void recJAL() { +// jal target + + MOV32ItoM((u32)&target, _Target_ * 4 + (pc & 0xf0000000)); + MOV32ItoM((u32)&psxRegs.GPR.r[31], pc + 4); + + SetBranch(); +} + +static void recJR() { +// jr Rs + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + MOV32RtoM((u32)&target, EAX); + + SetBranch(); +} + +static void recJALR() { +// jalr Rs + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + MOV32RtoM((u32)&target, EAX); + + if (_Rd_) { + MOV32ItoM((u32)&psxRegs.GPR.r[_Rd_], pc + 4); + } + + SetBranch(); +} + +static void recBEQ() { +// Branch if Rs == Rt + + if (_Rs_ == _Rt_) { + MOV32ItoM((u32)&target, _Imm_ * 4 + pc); + } else { + if (_Rs_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + } else { + XOR32RtoR(EAX, EAX); + } + CMP32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + j8Ptr[0] = JE8(0); + + MOV32ItoM((u32)&target, pc+4); + j8Ptr[1] = JMP8(0); + + x86SetJ8(j8Ptr[0]); + + MOV32ItoM((u32)&target, _Imm_ * 4 + pc); + + x86SetJ8(j8Ptr[1]); + } + + SetBranch(); +} + +static void recBNE() { +// Branch if Rs != Rt + + if (_Rs_) { + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); + } else { + XOR32RtoR(EAX, EAX); + } + CMP32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + j8Ptr[0] = JNE8(0); + + MOV32ItoM((u32)&target, pc+4); + j8Ptr[1] = JMP8(0); + + x86SetJ8(j8Ptr[0]); + + MOV32ItoM((u32)&target, _Imm_ * 4 + pc); + + x86SetJ8(j8Ptr[1]); + + SetBranch(); +} + +static void recBLEZ() { +// Branch if Rs <= 0 + + CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0); + j8Ptr[0] = JLE8(0); + + MOV32ItoM((u32)&target, pc+4); + j8Ptr[1] = JMP8(0); + + x86SetJ8(j8Ptr[0]); + + MOV32ItoM((u32)&target, _Imm_ * 4 + pc); + + x86SetJ8(j8Ptr[1]); + + SetBranch(); +} + +static void recBGTZ() { +// Branch if Rs > 0 + + CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0); + j8Ptr[0] = JG8(0); + + MOV32ItoM((u32)&target, pc+4); + j8Ptr[1] = JMP8(0); + + x86SetJ8(j8Ptr[0]); + + MOV32ItoM((u32)&target, _Imm_ * 4 + pc); + + x86SetJ8(j8Ptr[1]); + + SetBranch(); +} +//#endif + +/*REC_FUNC(MFC0); +REC_FUNC(MTC0); +REC_FUNC(CFC0); +REC_FUNC(CTC0); +REC_FUNC(RFE); +#if 0*/ +static void recMFC0() { +// Rt = Cop0->Rd + if (!_Rt_) return; + + MOV32MtoR(EAX, (u32)&psxRegs.CP0.r[_Rd_]); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); +} + +static void recCFC0() { +// Rt = Cop0->Rd + if (!_Rt_) return; + + MOV32MtoR(EAX, (u32)&psxRegs.CP0.r[_Rd_]); + MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); +} + +static void recMTC0() { +// Cop0->Rd = Rt + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + MOV32RtoM((u32)&psxRegs.CP0.r[_Rd_], EAX); +} + +static void recCTC0() { +// Cop0->Rd = Rt + + MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); + MOV32RtoM((u32)&psxRegs.CP0.r[_Rd_], EAX); +} + +static void recRFE() { + MOV32MtoR(EAX, (u32)&psxRegs.CP0.n.Status); + MOV32RtoR(ECX, EAX); + AND32ItoR(EAX, 0xfffffff0); + AND32ItoR(ECX, 0x3c); + SHR32ItoR(ECX, 2); + OR32RtoR (EAX, ECX); + MOV32RtoM((u32)&psxRegs.CP0.n.Status, EAX); +} +//#endif + +#define CP2_FUNC(f) \ +void gte##f(); \ +static void rec##f() { \ + MOV32ItoM((u32)&psxRegs.code, (u32)psxRegs.code); \ + MOV32ItoM((u32)&psxRegs.pc, (u32)pc); \ + CALLFunc ((u32)gte##f); \ +/* branch = 2; */\ +} + +CP2_FUNC(MFC2); +CP2_FUNC(MTC2); +CP2_FUNC(CFC2); +CP2_FUNC(CTC2); +CP2_FUNC(LWC2); +CP2_FUNC(SWC2); + +CP2_FUNC(RTPS); +CP2_FUNC(OP); +CP2_FUNC(NCLIP); +CP2_FUNC(DPCS); +CP2_FUNC(INTPL); +CP2_FUNC(MVMVA); +CP2_FUNC(NCDS); +CP2_FUNC(NCDT); +CP2_FUNC(CDP); +CP2_FUNC(NCCS); +CP2_FUNC(CC); +CP2_FUNC(NCS); +CP2_FUNC(NCT); +CP2_FUNC(SQR); +CP2_FUNC(DCPL); +CP2_FUNC(DPCT); +CP2_FUNC(AVSZ3); +CP2_FUNC(AVSZ4); +CP2_FUNC(RTPT); +CP2_FUNC(GPF); +CP2_FUNC(GPL); +CP2_FUNC(NCCT); + +static void recHLE() { + MOV32ItoR(EAX, (u32)psxHLEt[psxRegs.code & 0xff]); + CALL32R(EAX); + branch = 2; +} + +// + +static void (*recBSC[64])() = { + recSPECIAL, recREGIMM, recJ , recJAL , recBEQ , recBNE , recBLEZ, recBGTZ, + recADDI , recADDIU , recSLTI, recSLTIU, recANDI, recORI , recXORI, recLUI , + recCOP0 , recNULL , recCOP2, recNULL , recNULL, recNULL, recNULL, recNULL, + recNULL , recNULL , recNULL, recNULL , recNULL, recNULL, recNULL, recNULL, + recLB , recLH , recLWL , recLW , recLBU , recLHU , recLWR , recNULL, + recSB , recSH , recSWL , recSW , recNULL, recNULL, recSWR , recNULL, + recNULL , recNULL , recLWC2, recNULL , recNULL, recNULL, recNULL, recNULL, + recNULL , recNULL , recSWC2, recHLE , recNULL, recNULL, recNULL, recNULL +}; + +static void (*recSPC[64])() = { + recSLL , recNULL, recSRL , recSRA , recSLLV , recNULL , recSRLV, recSRAV, + recJR , recJALR, recNULL, recNULL, recSYSCALL, recBREAK, recNULL, recNULL, + recMFHI, recMTHI, recMFLO, recMTLO, recNULL , recNULL , recNULL, recNULL, + recMULT, recMULTU, recDIV, recDIVU, recNULL , recNULL , recNULL, recNULL, + recADD , recADDU, recSUB , recSUBU, recAND , recOR , recXOR , recNOR , + recNULL, recNULL, recSLT , recSLTU, recNULL , recNULL , recNULL, recNULL, + recNULL, recNULL, recNULL, recNULL, recNULL , recNULL , recNULL, recNULL, + recNULL, recNULL, recNULL, recNULL, recNULL , recNULL , recNULL, recNULL +}; + +static void (*recREG[32])() = { + recBLTZ , recBGEZ , recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, + recNULL , recNULL , recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, + recBLTZAL, recBGEZAL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, + recNULL , recNULL , recNULL, recNULL, recNULL, recNULL, recNULL, recNULL +}; + +static void (*recCP0[32])() = { + recMFC0, recNULL, recCFC0, recNULL, recMTC0, recNULL, recCTC0, recNULL, + recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, + recRFE , recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, + recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL +}; + +static void (*recCP2[64])() = { + recBASIC, recRTPS , recNULL , recNULL, recNULL, recNULL , recNCLIP, recNULL, // 00 + recNULL , recNULL , recNULL , recNULL, recOP , recNULL , recNULL , recNULL, // 08 + recDPCS , recINTPL, recMVMVA, recNCDS, recCDP , recNULL , recNCDT , recNULL, // 10 + recNULL , recNULL , recNULL , recNCCS, recCC , recNULL , recNCS , recNULL, // 18 + recNCT , recNULL , recNULL , recNULL, recNULL, recNULL , recNULL , recNULL, // 20 + recSQR , recDCPL , recDPCT , recNULL, recNULL, recAVSZ3, recAVSZ4, recNULL, // 28 + recRTPT , recNULL , recNULL , recNULL, recNULL, recNULL , recNULL , recNULL, // 30 + recNULL , recNULL , recNULL , recNULL, recNULL, recGPF , recGPL , recNCCT // 38 +}; + +static void (*recCP2BSC[32])() = { + recMFC2, recNULL, recCFC2, recNULL, recMTC2, recNULL, recCTC2, recNULL, + recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, + recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, + recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL +}; + +static void recRecompile() { + /* if x86Ptr reached the mem limit reset whole mem */ + if (((u32)x86Ptr - (u32)recMem) >= (RECMEM_SIZE - 0x10000)) + recReset(); + + PC_REC32(psxRegs.pc) = (u32)x86Ptr; + pc = psxRegs.pc; + + for (count=0; count<500;) { + char *p; + + p = (char *)PSXM(pc); + if (p == NULL) recError(); + psxRegs.code = *(u32 *)p; + + pc+=4; count++; + recBSC[psxRegs.code>>26](); + + if (branch) { + break; + } + } + + if (!branch) { + MOV32ItoM((u32)&psxRegs.pc, pc); + } + + /* store cycle */ + ADD32ItoM((u32)&psxRegs.cycle, count); + + branch = 0; + + RET(); +} + + +R3000Acpu psxRec = { + recInit, + recReset, + recExecute, + recExecuteBlock, + recClear, + recShutdown +}; diff --git a/PcsxSrc/ix86/ix86.c b/PcsxSrc/ix86/ix86.c index d0775e4..20d071d 100644 --- a/PcsxSrc/ix86/ix86.c +++ b/PcsxSrc/ix86/ix86.c @@ -1,966 +1,966 @@ -/* - * ix86 core. - * Author: linuzappz - */ - -#include - -#include "ix86.h" - -void x86Init(char *ptr) { - x86Ptr = ptr; -} - -void x86Shutdown() { -} - -void x86SetJ8(u8 *j8) { - *j8 = ((u8*)x86Ptr - j8) - 1; -} - -void x86SetJ32(u32 *j32) { - *j32 = ((u32*)x86Ptr - j32) - 4; -} - -#define SIB 4 -#define DISP32 5 - -#define write8(val) *(unsigned char *)x86Ptr = val; x86Ptr++; -#define write16(val) *(unsigned short*)x86Ptr = val; x86Ptr+=2; -#define write32(val) *(u32 *)x86Ptr = val; x86Ptr+=4; - -/* macros helpers */ - -#define ModRM(mod, rm, reg) \ - write8((mod << 6) | (rm << 3) | (reg)); - -#define SibSB(ss, rm, index) \ - write8((ss << 6) | (rm << 3) | (index)); - -#define SET8R(cc, to) { \ - write8(0x0F); write8(cc); \ - write8((0xC0) | (to)); } - -#define J8Rel(cc, to) { \ - write8(cc); write8(to); return x86Ptr - 1; } - -#define CMOV32RtoR(cc, to, from) { \ - write8(0x0F); write8(cc); \ - ModRM(3, to, from); } - -#define CMOV32MtoR(cc, to, from) { \ - write8(0x0F); write8(cc); \ - ModRM(0, to, DISP32); \ - write32(from); } - -/********************/ -/* IX86 intructions */ -/********************/ - -// mov instructions - -/* mov r32 to r32 */ -void MOV32RtoR(int to, int from) { - write8(0x89); - ModRM(3, from, to); -} - -/* mov r32 to m32 */ -void MOV32RtoM(u32 to, int from) { - write8(0x89); - ModRM(0, from, DISP32); - write32(to); -} - -/* mov m32 to r32 */ -void MOV32MtoR(int to, u32 from) { - write8(0x8B); - ModRM(0, to, DISP32); - write32(from); -} - -/* mov [r32] to r32 */ -void MOV32RmtoR(int to, int from) { - write8(0x8B); - ModRM(0, to, from); -} - -/* mov [r32][r32*scale] to r32 */ -void MOV32RmStoR(int to, int from, int from2, int scale) { - write8(0x8B); - ModRM(0, to, 0x4); - SibSB(scale, from2, from); -} - -/* mov r32 to [r32] */ -void MOV32RtoRm(int to, int from) { - write8(0x89); - ModRM(0, from, to); -} - -/* mov imm32 to r32 */ -void MOV32ItoR(int to, u32 from) { - write8(0xB8 | to); - write32(from); -} - -/* mov imm32 to m32 */ -void MOV32ItoM(u32 to, u32 from) { - write8(0xC7); - ModRM(0, 0, DISP32); - write32(to); - write32(from); -} - -/* movsx r8 to r32 */ -void MOVSX32R8toR(int to, int from) { - write16(0xBE0F); - ModRM(3, to, from); -} - -/* movsx r16 to r32 */ -void MOVSX32R16toR(int to, int from) { - write16(0xBF0F); - ModRM(3, to, from); -} - -/* movzx r8 to r32 */ -void MOVZX32R8toR(int to, int from) { - write16(0xB60F); - ModRM(3, to, from); -} - -/* movzx r16 to r32 */ -void MOVZX32R16toR(int to, int from) { - write16(0xB70F); - ModRM(3, to, from); -} - -/* cmovne r32 to r32 */ -void CMOVNE32RtoR(int to, int from) { - CMOV32RtoR(0x45, to, from); -} - -/* cmovne m32 to r32*/ -void CMOVNE32MtoR(int to, u32 from) { - CMOV32MtoR(0x45, to, from); -} - -/* cmove r32 to r32*/ -void CMOVE32RtoR(int to, int from) { - CMOV32RtoR(0x44, to, from); -} - -/* cmove m32 to r32*/ -void CMOVE32MtoR(int to, u32 from) { - CMOV32MtoR(0x44, to, from); -} - -/* cmovg r32 to r32*/ -void CMOVG32RtoR(int to, int from) { - CMOV32RtoR(0x4F, to, from); -} - -/* cmovg m32 to r32*/ -void CMOVG32MtoR(int to, u32 from) { - CMOV32MtoR(0x4F, to, from); -} - -/* cmovge r32 to r32*/ -void CMOVGE32RtoR(int to, int from) { - CMOV32RtoR(0x4D, to, from); -} - -/* cmovge m32 to r32*/ -void CMOVGE32MtoR(int to, u32 from) { - CMOV32MtoR(0x4D, to, from); -} - -/* cmovl r32 to r32*/ -void CMOVL32RtoR(int to, int from) { - CMOV32RtoR(0x4C, to, from); -} - -/* cmovl m32 to r32*/ -void CMOVL32MtoR(int to, u32 from) { - CMOV32MtoR(0x4C, to, from); -} - -/* cmovle r32 to r32*/ -void CMOVLE32RtoR(int to, int from) { - CMOV32RtoR(0x4E, to, from); -} - -/* cmovle m32 to r32*/ -void CMOVLE32MtoR(int to, u32 from) { - CMOV32MtoR(0x4E, to, from); -} - -// arithmic instructions - -/* add imm32 to r32 */ -void ADD32ItoR(int to, u32 from) { - if (to == EAX) { - write8(0x05); - } else { - write8(0x81); - ModRM(3, 0, to); - } - write32(from); -} - -/* add imm32 to m32 */ -void ADD32ItoM(u32 to, u32 from) { - write8(0x81); - ModRM(0, 0, DISP32); - write32(to); - write32(from); -} - -/* add r32 to r32 */ -void ADD32RtoR(int to, int from) { - write8(0x01); - ModRM(3, from, to); -} - -/* add m32 to r32 */ -void ADD32MtoR(int to, u32 from) { - write8(0x03); - ModRM(0, to, DISP32); - write32(from); -} - -/* adc imm32 to r32 */ -void ADC32ItoR(int to, u32 from) { - if (to == EAX) { - write8(0x15); - } else { - write8(0x81); - ModRM(3, 2, to); - } - write32(from); -} - -/* adc r32 to r32 */ -void ADC32RtoR(int to, int from) { - write8(0x11); - ModRM(3, from, to); -} - -/* adc m32 to r32 */ -void ADC32MtoR(int to, u32 from) { - write8(0x13); - ModRM(0, to, DISP32); - write32(from); -} - -/* sub imm32 to r32 */ -void SUB32ItoR(int to, u32 from) { - if (to == EAX) { - write8(0x2D); - } else { - write8(0x81); - ModRM(3, 5, to); - } - write32(from); -} - -/* sub r32 to r32 */ -void SUB32RtoR(int to, int from) { - write8(0x29); - ModRM(3, from, to); -} - -/* sub m32 to r32 */ -void SUB32MtoR(int to, u32 from) { - write8(0x2B); - ModRM(0, to, DISP32); - write32(from); -} - -/* sbb imm32 to r32 */ -void SBB32ItoR(int to, u32 from) { - if (to == EAX) { - write8(0x1D); - } else { - write8(0x81); - ModRM(3, 3, to); - } - write32(from); -} - -/* sbb r32 to r32 */ -void SBB32RtoR(int to, int from) { - write8(0x19); - ModRM(3, from, to); -} - -/* sbb m32 to r32 */ -void SBB32MtoR(int to, u32 from) { - write8(0x1B); - ModRM(0, to, DISP32); - write32(from); -} - -/* mul eax by r32 to edx:eax */ -void MUL32R(int from) { - write8(0xF7); - ModRM(3, 4, from); -} - -/* imul eax by r32 to edx:eax */ -void IMUL32R(int from) { - write8(0xF7); - ModRM(3, 5, from); -} - -/* mul eax by m32 to edx:eax */ -void MUL32M(u32 from) { - write8(0xF7); - ModRM(0, 4, DISP32); - write32(from); -} - -/* imul eax by m32 to edx:eax */ -void IMUL32M(u32 from) { - write8(0xF7); - ModRM(0, 5, DISP32); - write32(from); -} - -/* div eax by r32 to edx:eax */ -void DIV32R(int from) { - write8(0xF7); - ModRM(3, 6, from); -} - -/* idiv eax by r32 to edx:eax */ -void IDIV32R(int from) { - write8(0xF7); - ModRM(3, 7, from); -} - -/* div eax by m32 to edx:eax */ -void DIV32M(u32 from) { - write8(0xF7); - ModRM(0, 6, DISP32); - write32(from); -} - -/* idiv eax by m32 to edx:eax */ -void IDIV32M(u32 from) { - write8(0xF7); - ModRM(0, 7, DISP32); - write32(from); -} - -// shifting instructions - -/* shl imm8 to r32 */ -void SHL32ItoR(int to, unsigned char from) { - write8(0xC1); - ModRM(3, 4, to); - write8(from); -} - -/* shl cl to r32 */ -void SHL32CLtoR(int to) { - write8(0xD3); - ModRM(3, 4, to); -} - -/* shr imm8 to r32 */ -void SHR32ItoR(int to, unsigned char from) { - write8(0xC1); - ModRM(3, 5, to); - write8(from); -} - -/* shr cl to r32 */ -void SHR32CLtoR(int to) { - write8(0xD3); - ModRM(3, 5, to); -} - -/* sar imm8 to r32 */ -void SAR32ItoR(int to, unsigned char from) { - write8(0xC1); - ModRM(3, 7, to); - write8(from); -} - -/* sar cl to r32 */ -void SAR32CLtoR(int to) { - write8(0xD3); - ModRM(3, 7, to); -} - - -// logical instructions - -/* or imm32 to r32 */ -void OR32ItoR(int to, u32 from) { - if (to == EAX) { - write8(0x0D); - } else { - write8(0x81); - ModRM(3, 1, to); - } - write32(from); -} - -/* or imm32 to m32 */ -void OR32ItoM(u32 to, u32 from) { - write8(0x81); - ModRM(0, 1, DISP32); - write32(to); - write32(from); -} - -/* or r32 to r32 */ -void OR32RtoR(int to, int from) { - write8(0x09); - ModRM(3, from, to); -} - -/* or m32 to r32 */ -void OR32MtoR(int to, u32 from) { - write8(0x0B); - ModRM(0, to, DISP32); - write32(from); -} - -/* xor imm32 to r32 */ -void XOR32ItoR(int to, u32 from) { - if (to == EAX) { - write8(0x35); - } else { - write8(0x81); - ModRM(3, 6, to); - } - write32(from); -} - -/* xor imm32 to m32 */ -void XOR32ItoM(u32 to, u32 from) { - write8(0x81); - ModRM(0, 6, DISP32); - write32(to); - write32(from); -} - -/* xor r32 to r32 */ -void XOR32RtoR(int to, int from) { - write8(0x31); - ModRM(3, from, to); -} - -/* xor m32 to r32 */ -void XOR32MtoR(int to, u32 from) { - write8(0x33); - ModRM(0, to, DISP32); - write32(from); -} - -/* and imm32 to r32 */ -void AND32ItoR(int to, u32 from) { - if (to == EAX) { - write8(0x25); - } else { - write8(0x81); - ModRM(3, 0x4, to); - } - write32(from); -} - -/* and imm32 to m32 */ -void AND32ItoM(u32 to, u32 from) { - write8(0x81); - ModRM(0, 0x4, DISP32); - write32(to); - write32(from); -} - -/* and r32 to r32 */ -void AND32RtoR(int to, int from) { - write8(0x21); - ModRM(3, from, to); -} - -/* and m32 to r32 */ -void AND32MtoR(int to, u32 from) { - write8(0x23); - ModRM(0, to, DISP32); - write32(from); -} - -/* not r32 */ -void NOT32R(int from) { - write8(0xF7); - ModRM(3, 2, from); -} - -/* neg r32 */ -void NEG32R(int from) { - write8(0xF7); - ModRM(3, 3, from); -} - -// jump instructions - -/* jmp rel8 */ -u8* JMP8(unsigned char to) { - write8(0xEB); - write8(to); - return x86Ptr - 1; -} - -/* jmp rel32 */ -u32* JMP32(u32 to) { - write8(0xE9); - write32(to); - return (u32*)(x86Ptr - 4); -} - -/* jmp r32 */ -void JMP32R(int to) { - write8(0xFF); - ModRM(3, 4, to); -} - -/* je rel8 */ -u8* JE8(unsigned char to) { - J8Rel(0x74, to); -} - -/* jz rel8 */ -u8* JZ8(unsigned char to) { - J8Rel(0x74, to); -} - -/* jg rel8 */ -u8* JG8(unsigned char to) { - J8Rel(0x7F, to); } - -/* jge rel8 */ -u8* JGE8(unsigned char to) { - J8Rel(0x7D, to); -} - -/* jl rel8 */ -u8* JL8(unsigned char to) { - J8Rel(0x7C, to); -} - -/* jle rel8 */ -u8* JLE8(unsigned char to) { - J8Rel(0x7E, to); -} - -/* jne rel8 */ -u8* JNE8(unsigned char to) { - J8Rel(0x75, to); -} - -/* jnz rel8 */ -u8* JNZ8(unsigned char to) { - J8Rel(0x75, to); -} - -/* jng rel8 */ -u8* JNG8(unsigned char to) { - J8Rel(0x7E, to); -} - -/* jnge rel8 */ -u8* JNGE8(unsigned char to) { - J8Rel(0x7C, to); -} - -/* jnl rel8 */ -u8* JNL8(unsigned char to) { - J8Rel(0x7D, to); -} - -/* jnle rel8 */ -u8* JNLE8(unsigned char to) { - J8Rel(0x7F, to); -} - -/* call func */ -void CALLFunc(u32 func) { - CALL32(func - ((u32)x86Ptr + 5)); -} - -/* call rel32 */ -void CALL32(u32 to) { - write8(0xE8); - write32(to); -} - -/* call r32 */ -void CALL32R(int to) { - write8(0xFF); - ModRM(3, 2, to); -} - -// misc instructions - -/* cmp imm32 to r32 */ -void CMP32ItoR(int to, u32 from) { - if (to == EAX) { - write8(0x3D); - } else { - write8(0x81); - ModRM(3, 7, to); - } - write32(from); -} - -/* cmp imm32 to m32 */ -void CMP32ItoM(u32 to, u32 from) { - write8(0x81); - ModRM(0, 7, DISP32); - write32(to); - write32(from); -} - -/* cmp r32 to r32 */ -void CMP32RtoR(int to, int from) { - write8(0x39); - ModRM(3, from, to); -} - -/* cmp m32 to r32 */ -void CMP32MtoR(int to, u32 from) { - write8(0x3B); - ModRM(0, to, DISP32); - write32(from); -} - -/* test imm32 to r32 */ -void TEST32ItoR(int to, u32 from) { - if (to == EAX) { - write8(0xA9); - } else { - write8(0xF7); - ModRM(3, 0, to); - } - write32(from); -} - -/* test r32 to r32 */ -void TEST32RtoR(int to, int from) { - write8(0x85); - ModRM(3, from, to); -} - -/* setl r8 */ -void SETL8R(int to) { - SET8R(0x9C, to); -} - -/* setb r8 */ -void SETB8R(int to) { - SET8R(0x92, to); -} - -/* cbw */ -void CBW() { - write16(0x9866); -} - -/* cwd */ -void CWD() { - write8(0x98); -} - -/* cdq */ -void CDQ() { - write8(0x99); -} - -/* push r32 */ -void PUSH32R(int from) { - write8(0x50 | from); -} - -/* push m32 */ -void PUSH32M(u32 from) { - write8(0xFF); - ModRM(0, 6, DISP32); - write32(from); -} - -/* push imm32 */ -void PUSH32I(u32 from) { - write8(0x68); write32(from); -} - -/* pop r32 */ -void POP32R(int from) { - write8(0x58 | from); -} - -/* pushad */ -void PUSHA32() { - write8(0x60); -} - -/* popad */ -void POPA32() { - write8(0x61); -} - -/* ret */ -void RET() { - write8(0xC3); -} - -/********************/ -/* FPU instructions */ -/********************/ - -/* fild m32 to fpu reg stack */ -void FILD32(u32 from) { - write8(0xDB); - ModRM(0, 0x0, DISP32); - write32(from); -} - -/* fistp m32 from fpu reg stack */ -void FISTP32(u32 from) { - write8(0xDB); - ModRM(0, 0x3, DISP32); - write32(from); -} - -/* fld m32 to fpu reg stack */ -void FLD32(u32 from) { - write8(0xD9); - ModRM(0, 0x0, DISP32); - write32(from); -} - -/* fstp m32 from fpu reg stack */ -void FSTP32(u32 to) { - write8(0xD9); - ModRM(0, 0x3, DISP32); - write32(to); -} - -// - -/* fldcw fpu control word from m16 */ -void FLDCW(u32 from) { - write8(0xD9); - ModRM(0, 0x5, DISP32); - write32(from); -} - -/* fnstcw fpu control word to m16 */ -void FNSTCW(u32 to) { - write8(0xD9); - ModRM(0, 0x7, DISP32); - write32(to); -} - -// - -/* fadd m32 to fpu reg stack */ -void FADD32(u32 from) { - write8(0xD8); - ModRM(0, 0x0, DISP32); - write32(from); -} - -/* fsub m32 to fpu reg stack */ -void FSUB32(u32 from) { - write8(0xD8); - ModRM(0, 0x4, DISP32); - write32(from); -} - -/* fmul m32 to fpu reg stack */ -void FMUL32(u32 from) { - write8(0xD8); - ModRM(0, 0x1, DISP32); - write32(from); -} - -/* fdiv m32 to fpu reg stack */ -void FDIV32(u32 from) { - write8(0xD8); - ModRM(0, 0x6, DISP32); - write32(from); -} - -/* fabs fpu reg stack */ -void FABS() { - write16(0xE1D9); -} - -/* fsqrt fpu reg stack */ -void FSQRT() { - write16(0xFAD9); -} - -/* fchs fpu reg stack */ -void FCHS() { - write16(0xE0D9); -} - -/********************/ -/* MMX instructions */ -/********************/ - -// r64 = mm - -/* movq m64 to r64 */ -void MOVQMtoR(int to, u32 from) { - write16(0x6F0F); - ModRM(0, to, DISP32); - write32(from); -} - -/* movq r64 to m64 */ -void MOVQRtoM(u32 to, int from) { - write16(0x7F0F); - ModRM(0, from, DISP32); - write32(to); -} - -/* pand r64 to r64 */ -void PANDRtoR(int to, int from) { - write16(0xDB0F); - ModRM(3, to, from); -} - -/* por r64 to r64 */ -void PORRtoR(int to, int from) { - write16(0xEB0F); - ModRM(3, to, from); -} - -/* por m64 to r64 */ -void PORMtoR(int to, u32 from) { - write16(0xEB0F); - ModRM(0, to, DISP32); - write32(from); -} - -/* pxor r64 to r64 */ -void PXORRtoR(int to, int from) { - write16(0xEF0F); - ModRM(3, to, from); -} - -/* psllq r64 to r64 */ -void PSLLQRtoR(int to, int from) { - write16(0xF30F); - ModRM(3, to, from); -} - -/* psllq m64 to r64 */ -void PSLLQMtoR(int to, u32 from) { - write16(0xF30F); - ModRM(0, to, DISP32); - write32(from); -} - -/* psllq imm8 to r64 */ -void PSLLQItoR(int to, unsigned char from) { - write16(0x730F); - ModRM(3, 6, to); - write8(from); -} - -/* psrlq r64 to r64 */ -void PSRLQRtoR(int to, int from) { - write16(0xD30F); - ModRM(3, to, from); -} - -/* psrlq m64 to r64 */ -void PSRLQMtoR(int to, u32 from) { - write16(0xD30F); - ModRM(0, to, DISP32); - write32(from); -} - -/* psrlq imm8 to r64 */ -void PSRLQItoR(int to, unsigned char from) { - write16(0x730F); - ModRM(3, 2, to); - write8(from); -} - -/* paddusb r64 to r64 */ -void PADDUSBRtoR(int to, int from) { - write16(0xDC0F); - ModRM(3, to, from); -} - -/* paddusb m64 to r64 */ -void PADDUSBMtoR(int to, u32 from) { - write16(0xDC0F); - ModRM(0, to, DISP32); - write32(from); -} - -/* paddusw r64 to r64 */ -void PADDUSWRtoR(int to, int from) { - write16(0xDD0F); - ModRM(3, to, from); -} - -/* paddusw m64 to r64 */ -void PADDUSWMtoR(int to, u32 from) { - write16(0xDD0F); - ModRM(0, to, DISP32); - write32(from); -} - -/* paddb r64 to r64 */ -void PADDBRtoR(int to, int from) { - write16(0xFC0F); - ModRM(3, to, from); -} - -/* paddb m64 to r64 */ -void PADDBMtoR(int to, u32 from) { - write16(0xFC0F); - ModRM(0, to, DISP32); - write32(from); -} - -/* paddw r64 to r64 */ -void PADDWRtoR(int to, int from) { - write16(0xFD0F); - ModRM(3, to, from); -} - -/* paddw m64 to r64 */ -void PADDWMtoR(int to, u32 from) { - write16(0xFD0F); - ModRM(0, to, DISP32); - write32(from); -} - -/* paddd r64 to r64 */ -void PADDDRtoR(int to, int from) { - write16(0xFE0F); - ModRM(3, to, from); -} - -/* paddd m64 to r64 */ -void PADDDMtoR(int to, u32 from) { - write16(0xFE0F); - ModRM(0, to, DISP32); - write32(from); -} - -/* emms */ -void EMMS() { - write16(0x770F); -} +/* + * ix86 core. + * Author: linuzappz + */ + +#include + +#include "ix86.h" + +void x86Init(char *ptr) { + x86Ptr = ptr; +} + +void x86Shutdown() { +} + +void x86SetJ8(u8 *j8) { + *j8 = ((u8*)x86Ptr - j8) - 1; +} + +void x86SetJ32(u32 *j32) { + *j32 = ((u32*)x86Ptr - j32) - 4; +} + +#define SIB 4 +#define DISP32 5 + +#define write8(val) *(unsigned char *)x86Ptr = val; x86Ptr++; +#define write16(val) *(unsigned short*)x86Ptr = val; x86Ptr+=2; +#define write32(val) *(u32 *)x86Ptr = val; x86Ptr+=4; + +/* macros helpers */ + +#define ModRM(mod, rm, reg) \ + write8((mod << 6) | (rm << 3) | (reg)); + +#define SibSB(ss, rm, index) \ + write8((ss << 6) | (rm << 3) | (index)); + +#define SET8R(cc, to) { \ + write8(0x0F); write8(cc); \ + write8((0xC0) | (to)); } + +#define J8Rel(cc, to) { \ + write8(cc); write8(to); return x86Ptr - 1; } + +#define CMOV32RtoR(cc, to, from) { \ + write8(0x0F); write8(cc); \ + ModRM(3, to, from); } + +#define CMOV32MtoR(cc, to, from) { \ + write8(0x0F); write8(cc); \ + ModRM(0, to, DISP32); \ + write32(from); } + +/********************/ +/* IX86 intructions */ +/********************/ + +// mov instructions + +/* mov r32 to r32 */ +void MOV32RtoR(int to, int from) { + write8(0x89); + ModRM(3, from, to); +} + +/* mov r32 to m32 */ +void MOV32RtoM(u32 to, int from) { + write8(0x89); + ModRM(0, from, DISP32); + write32(to); +} + +/* mov m32 to r32 */ +void MOV32MtoR(int to, u32 from) { + write8(0x8B); + ModRM(0, to, DISP32); + write32(from); +} + +/* mov [r32] to r32 */ +void MOV32RmtoR(int to, int from) { + write8(0x8B); + ModRM(0, to, from); +} + +/* mov [r32][r32*scale] to r32 */ +void MOV32RmStoR(int to, int from, int from2, int scale) { + write8(0x8B); + ModRM(0, to, 0x4); + SibSB(scale, from2, from); +} + +/* mov r32 to [r32] */ +void MOV32RtoRm(int to, int from) { + write8(0x89); + ModRM(0, from, to); +} + +/* mov imm32 to r32 */ +void MOV32ItoR(int to, u32 from) { + write8(0xB8 | to); + write32(from); +} + +/* mov imm32 to m32 */ +void MOV32ItoM(u32 to, u32 from) { + write8(0xC7); + ModRM(0, 0, DISP32); + write32(to); + write32(from); +} + +/* movsx r8 to r32 */ +void MOVSX32R8toR(int to, int from) { + write16(0xBE0F); + ModRM(3, to, from); +} + +/* movsx r16 to r32 */ +void MOVSX32R16toR(int to, int from) { + write16(0xBF0F); + ModRM(3, to, from); +} + +/* movzx r8 to r32 */ +void MOVZX32R8toR(int to, int from) { + write16(0xB60F); + ModRM(3, to, from); +} + +/* movzx r16 to r32 */ +void MOVZX32R16toR(int to, int from) { + write16(0xB70F); + ModRM(3, to, from); +} + +/* cmovne r32 to r32 */ +void CMOVNE32RtoR(int to, int from) { + CMOV32RtoR(0x45, to, from); +} + +/* cmovne m32 to r32*/ +void CMOVNE32MtoR(int to, u32 from) { + CMOV32MtoR(0x45, to, from); +} + +/* cmove r32 to r32*/ +void CMOVE32RtoR(int to, int from) { + CMOV32RtoR(0x44, to, from); +} + +/* cmove m32 to r32*/ +void CMOVE32MtoR(int to, u32 from) { + CMOV32MtoR(0x44, to, from); +} + +/* cmovg r32 to r32*/ +void CMOVG32RtoR(int to, int from) { + CMOV32RtoR(0x4F, to, from); +} + +/* cmovg m32 to r32*/ +void CMOVG32MtoR(int to, u32 from) { + CMOV32MtoR(0x4F, to, from); +} + +/* cmovge r32 to r32*/ +void CMOVGE32RtoR(int to, int from) { + CMOV32RtoR(0x4D, to, from); +} + +/* cmovge m32 to r32*/ +void CMOVGE32MtoR(int to, u32 from) { + CMOV32MtoR(0x4D, to, from); +} + +/* cmovl r32 to r32*/ +void CMOVL32RtoR(int to, int from) { + CMOV32RtoR(0x4C, to, from); +} + +/* cmovl m32 to r32*/ +void CMOVL32MtoR(int to, u32 from) { + CMOV32MtoR(0x4C, to, from); +} + +/* cmovle r32 to r32*/ +void CMOVLE32RtoR(int to, int from) { + CMOV32RtoR(0x4E, to, from); +} + +/* cmovle m32 to r32*/ +void CMOVLE32MtoR(int to, u32 from) { + CMOV32MtoR(0x4E, to, from); +} + +// arithmic instructions + +/* add imm32 to r32 */ +void ADD32ItoR(int to, u32 from) { + if (to == EAX) { + write8(0x05); + } else { + write8(0x81); + ModRM(3, 0, to); + } + write32(from); +} + +/* add imm32 to m32 */ +void ADD32ItoM(u32 to, u32 from) { + write8(0x81); + ModRM(0, 0, DISP32); + write32(to); + write32(from); +} + +/* add r32 to r32 */ +void ADD32RtoR(int to, int from) { + write8(0x01); + ModRM(3, from, to); +} + +/* add m32 to r32 */ +void ADD32MtoR(int to, u32 from) { + write8(0x03); + ModRM(0, to, DISP32); + write32(from); +} + +/* adc imm32 to r32 */ +void ADC32ItoR(int to, u32 from) { + if (to == EAX) { + write8(0x15); + } else { + write8(0x81); + ModRM(3, 2, to); + } + write32(from); +} + +/* adc r32 to r32 */ +void ADC32RtoR(int to, int from) { + write8(0x11); + ModRM(3, from, to); +} + +/* adc m32 to r32 */ +void ADC32MtoR(int to, u32 from) { + write8(0x13); + ModRM(0, to, DISP32); + write32(from); +} + +/* sub imm32 to r32 */ +void SUB32ItoR(int to, u32 from) { + if (to == EAX) { + write8(0x2D); + } else { + write8(0x81); + ModRM(3, 5, to); + } + write32(from); +} + +/* sub r32 to r32 */ +void SUB32RtoR(int to, int from) { + write8(0x29); + ModRM(3, from, to); +} + +/* sub m32 to r32 */ +void SUB32MtoR(int to, u32 from) { + write8(0x2B); + ModRM(0, to, DISP32); + write32(from); +} + +/* sbb imm32 to r32 */ +void SBB32ItoR(int to, u32 from) { + if (to == EAX) { + write8(0x1D); + } else { + write8(0x81); + ModRM(3, 3, to); + } + write32(from); +} + +/* sbb r32 to r32 */ +void SBB32RtoR(int to, int from) { + write8(0x19); + ModRM(3, from, to); +} + +/* sbb m32 to r32 */ +void SBB32MtoR(int to, u32 from) { + write8(0x1B); + ModRM(0, to, DISP32); + write32(from); +} + +/* mul eax by r32 to edx:eax */ +void MUL32R(int from) { + write8(0xF7); + ModRM(3, 4, from); +} + +/* imul eax by r32 to edx:eax */ +void IMUL32R(int from) { + write8(0xF7); + ModRM(3, 5, from); +} + +/* mul eax by m32 to edx:eax */ +void MUL32M(u32 from) { + write8(0xF7); + ModRM(0, 4, DISP32); + write32(from); +} + +/* imul eax by m32 to edx:eax */ +void IMUL32M(u32 from) { + write8(0xF7); + ModRM(0, 5, DISP32); + write32(from); +} + +/* div eax by r32 to edx:eax */ +void DIV32R(int from) { + write8(0xF7); + ModRM(3, 6, from); +} + +/* idiv eax by r32 to edx:eax */ +void IDIV32R(int from) { + write8(0xF7); + ModRM(3, 7, from); +} + +/* div eax by m32 to edx:eax */ +void DIV32M(u32 from) { + write8(0xF7); + ModRM(0, 6, DISP32); + write32(from); +} + +/* idiv eax by m32 to edx:eax */ +void IDIV32M(u32 from) { + write8(0xF7); + ModRM(0, 7, DISP32); + write32(from); +} + +// shifting instructions + +/* shl imm8 to r32 */ +void SHL32ItoR(int to, unsigned char from) { + write8(0xC1); + ModRM(3, 4, to); + write8(from); +} + +/* shl cl to r32 */ +void SHL32CLtoR(int to) { + write8(0xD3); + ModRM(3, 4, to); +} + +/* shr imm8 to r32 */ +void SHR32ItoR(int to, unsigned char from) { + write8(0xC1); + ModRM(3, 5, to); + write8(from); +} + +/* shr cl to r32 */ +void SHR32CLtoR(int to) { + write8(0xD3); + ModRM(3, 5, to); +} + +/* sar imm8 to r32 */ +void SAR32ItoR(int to, unsigned char from) { + write8(0xC1); + ModRM(3, 7, to); + write8(from); +} + +/* sar cl to r32 */ +void SAR32CLtoR(int to) { + write8(0xD3); + ModRM(3, 7, to); +} + + +// logical instructions + +/* or imm32 to r32 */ +void OR32ItoR(int to, u32 from) { + if (to == EAX) { + write8(0x0D); + } else { + write8(0x81); + ModRM(3, 1, to); + } + write32(from); +} + +/* or imm32 to m32 */ +void OR32ItoM(u32 to, u32 from) { + write8(0x81); + ModRM(0, 1, DISP32); + write32(to); + write32(from); +} + +/* or r32 to r32 */ +void OR32RtoR(int to, int from) { + write8(0x09); + ModRM(3, from, to); +} + +/* or m32 to r32 */ +void OR32MtoR(int to, u32 from) { + write8(0x0B); + ModRM(0, to, DISP32); + write32(from); +} + +/* xor imm32 to r32 */ +void XOR32ItoR(int to, u32 from) { + if (to == EAX) { + write8(0x35); + } else { + write8(0x81); + ModRM(3, 6, to); + } + write32(from); +} + +/* xor imm32 to m32 */ +void XOR32ItoM(u32 to, u32 from) { + write8(0x81); + ModRM(0, 6, DISP32); + write32(to); + write32(from); +} + +/* xor r32 to r32 */ +void XOR32RtoR(int to, int from) { + write8(0x31); + ModRM(3, from, to); +} + +/* xor m32 to r32 */ +void XOR32MtoR(int to, u32 from) { + write8(0x33); + ModRM(0, to, DISP32); + write32(from); +} + +/* and imm32 to r32 */ +void AND32ItoR(int to, u32 from) { + if (to == EAX) { + write8(0x25); + } else { + write8(0x81); + ModRM(3, 0x4, to); + } + write32(from); +} + +/* and imm32 to m32 */ +void AND32ItoM(u32 to, u32 from) { + write8(0x81); + ModRM(0, 0x4, DISP32); + write32(to); + write32(from); +} + +/* and r32 to r32 */ +void AND32RtoR(int to, int from) { + write8(0x21); + ModRM(3, from, to); +} + +/* and m32 to r32 */ +void AND32MtoR(int to, u32 from) { + write8(0x23); + ModRM(0, to, DISP32); + write32(from); +} + +/* not r32 */ +void NOT32R(int from) { + write8(0xF7); + ModRM(3, 2, from); +} + +/* neg r32 */ +void NEG32R(int from) { + write8(0xF7); + ModRM(3, 3, from); +} + +// jump instructions + +/* jmp rel8 */ +u8* JMP8(unsigned char to) { + write8(0xEB); + write8(to); + return x86Ptr - 1; +} + +/* jmp rel32 */ +u32* JMP32(u32 to) { + write8(0xE9); + write32(to); + return (u32*)(x86Ptr - 4); +} + +/* jmp r32 */ +void JMP32R(int to) { + write8(0xFF); + ModRM(3, 4, to); +} + +/* je rel8 */ +u8* JE8(unsigned char to) { + J8Rel(0x74, to); +} + +/* jz rel8 */ +u8* JZ8(unsigned char to) { + J8Rel(0x74, to); +} + +/* jg rel8 */ +u8* JG8(unsigned char to) { + J8Rel(0x7F, to); } + +/* jge rel8 */ +u8* JGE8(unsigned char to) { + J8Rel(0x7D, to); +} + +/* jl rel8 */ +u8* JL8(unsigned char to) { + J8Rel(0x7C, to); +} + +/* jle rel8 */ +u8* JLE8(unsigned char to) { + J8Rel(0x7E, to); +} + +/* jne rel8 */ +u8* JNE8(unsigned char to) { + J8Rel(0x75, to); +} + +/* jnz rel8 */ +u8* JNZ8(unsigned char to) { + J8Rel(0x75, to); +} + +/* jng rel8 */ +u8* JNG8(unsigned char to) { + J8Rel(0x7E, to); +} + +/* jnge rel8 */ +u8* JNGE8(unsigned char to) { + J8Rel(0x7C, to); +} + +/* jnl rel8 */ +u8* JNL8(unsigned char to) { + J8Rel(0x7D, to); +} + +/* jnle rel8 */ +u8* JNLE8(unsigned char to) { + J8Rel(0x7F, to); +} + +/* call func */ +void CALLFunc(u32 func) { + CALL32(func - ((u32)x86Ptr + 5)); +} + +/* call rel32 */ +void CALL32(u32 to) { + write8(0xE8); + write32(to); +} + +/* call r32 */ +void CALL32R(int to) { + write8(0xFF); + ModRM(3, 2, to); +} + +// misc instructions + +/* cmp imm32 to r32 */ +void CMP32ItoR(int to, u32 from) { + if (to == EAX) { + write8(0x3D); + } else { + write8(0x81); + ModRM(3, 7, to); + } + write32(from); +} + +/* cmp imm32 to m32 */ +void CMP32ItoM(u32 to, u32 from) { + write8(0x81); + ModRM(0, 7, DISP32); + write32(to); + write32(from); +} + +/* cmp r32 to r32 */ +void CMP32RtoR(int to, int from) { + write8(0x39); + ModRM(3, from, to); +} + +/* cmp m32 to r32 */ +void CMP32MtoR(int to, u32 from) { + write8(0x3B); + ModRM(0, to, DISP32); + write32(from); +} + +/* test imm32 to r32 */ +void TEST32ItoR(int to, u32 from) { + if (to == EAX) { + write8(0xA9); + } else { + write8(0xF7); + ModRM(3, 0, to); + } + write32(from); +} + +/* test r32 to r32 */ +void TEST32RtoR(int to, int from) { + write8(0x85); + ModRM(3, from, to); +} + +/* setl r8 */ +void SETL8R(int to) { + SET8R(0x9C, to); +} + +/* setb r8 */ +void SETB8R(int to) { + SET8R(0x92, to); +} + +/* cbw */ +void CBW() { + write16(0x9866); +} + +/* cwd */ +void CWD() { + write8(0x98); +} + +/* cdq */ +void CDQ() { + write8(0x99); +} + +/* push r32 */ +void PUSH32R(int from) { + write8(0x50 | from); +} + +/* push m32 */ +void PUSH32M(u32 from) { + write8(0xFF); + ModRM(0, 6, DISP32); + write32(from); +} + +/* push imm32 */ +void PUSH32I(u32 from) { + write8(0x68); write32(from); +} + +/* pop r32 */ +void POP32R(int from) { + write8(0x58 | from); +} + +/* pushad */ +void PUSHA32() { + write8(0x60); +} + +/* popad */ +void POPA32() { + write8(0x61); +} + +/* ret */ +void RET() { + write8(0xC3); +} + +/********************/ +/* FPU instructions */ +/********************/ + +/* fild m32 to fpu reg stack */ +void FILD32(u32 from) { + write8(0xDB); + ModRM(0, 0x0, DISP32); + write32(from); +} + +/* fistp m32 from fpu reg stack */ +void FISTP32(u32 from) { + write8(0xDB); + ModRM(0, 0x3, DISP32); + write32(from); +} + +/* fld m32 to fpu reg stack */ +void FLD32(u32 from) { + write8(0xD9); + ModRM(0, 0x0, DISP32); + write32(from); +} + +/* fstp m32 from fpu reg stack */ +void FSTP32(u32 to) { + write8(0xD9); + ModRM(0, 0x3, DISP32); + write32(to); +} + +// + +/* fldcw fpu control word from m16 */ +void FLDCW(u32 from) { + write8(0xD9); + ModRM(0, 0x5, DISP32); + write32(from); +} + +/* fnstcw fpu control word to m16 */ +void FNSTCW(u32 to) { + write8(0xD9); + ModRM(0, 0x7, DISP32); + write32(to); +} + +// + +/* fadd m32 to fpu reg stack */ +void FADD32(u32 from) { + write8(0xD8); + ModRM(0, 0x0, DISP32); + write32(from); +} + +/* fsub m32 to fpu reg stack */ +void FSUB32(u32 from) { + write8(0xD8); + ModRM(0, 0x4, DISP32); + write32(from); +} + +/* fmul m32 to fpu reg stack */ +void FMUL32(u32 from) { + write8(0xD8); + ModRM(0, 0x1, DISP32); + write32(from); +} + +/* fdiv m32 to fpu reg stack */ +void FDIV32(u32 from) { + write8(0xD8); + ModRM(0, 0x6, DISP32); + write32(from); +} + +/* fabs fpu reg stack */ +void FABS() { + write16(0xE1D9); +} + +/* fsqrt fpu reg stack */ +void FSQRT() { + write16(0xFAD9); +} + +/* fchs fpu reg stack */ +void FCHS() { + write16(0xE0D9); +} + +/********************/ +/* MMX instructions */ +/********************/ + +// r64 = mm + +/* movq m64 to r64 */ +void MOVQMtoR(int to, u32 from) { + write16(0x6F0F); + ModRM(0, to, DISP32); + write32(from); +} + +/* movq r64 to m64 */ +void MOVQRtoM(u32 to, int from) { + write16(0x7F0F); + ModRM(0, from, DISP32); + write32(to); +} + +/* pand r64 to r64 */ +void PANDRtoR(int to, int from) { + write16(0xDB0F); + ModRM(3, to, from); +} + +/* por r64 to r64 */ +void PORRtoR(int to, int from) { + write16(0xEB0F); + ModRM(3, to, from); +} + +/* por m64 to r64 */ +void PORMtoR(int to, u32 from) { + write16(0xEB0F); + ModRM(0, to, DISP32); + write32(from); +} + +/* pxor r64 to r64 */ +void PXORRtoR(int to, int from) { + write16(0xEF0F); + ModRM(3, to, from); +} + +/* psllq r64 to r64 */ +void PSLLQRtoR(int to, int from) { + write16(0xF30F); + ModRM(3, to, from); +} + +/* psllq m64 to r64 */ +void PSLLQMtoR(int to, u32 from) { + write16(0xF30F); + ModRM(0, to, DISP32); + write32(from); +} + +/* psllq imm8 to r64 */ +void PSLLQItoR(int to, unsigned char from) { + write16(0x730F); + ModRM(3, 6, to); + write8(from); +} + +/* psrlq r64 to r64 */ +void PSRLQRtoR(int to, int from) { + write16(0xD30F); + ModRM(3, to, from); +} + +/* psrlq m64 to r64 */ +void PSRLQMtoR(int to, u32 from) { + write16(0xD30F); + ModRM(0, to, DISP32); + write32(from); +} + +/* psrlq imm8 to r64 */ +void PSRLQItoR(int to, unsigned char from) { + write16(0x730F); + ModRM(3, 2, to); + write8(from); +} + +/* paddusb r64 to r64 */ +void PADDUSBRtoR(int to, int from) { + write16(0xDC0F); + ModRM(3, to, from); +} + +/* paddusb m64 to r64 */ +void PADDUSBMtoR(int to, u32 from) { + write16(0xDC0F); + ModRM(0, to, DISP32); + write32(from); +} + +/* paddusw r64 to r64 */ +void PADDUSWRtoR(int to, int from) { + write16(0xDD0F); + ModRM(3, to, from); +} + +/* paddusw m64 to r64 */ +void PADDUSWMtoR(int to, u32 from) { + write16(0xDD0F); + ModRM(0, to, DISP32); + write32(from); +} + +/* paddb r64 to r64 */ +void PADDBRtoR(int to, int from) { + write16(0xFC0F); + ModRM(3, to, from); +} + +/* paddb m64 to r64 */ +void PADDBMtoR(int to, u32 from) { + write16(0xFC0F); + ModRM(0, to, DISP32); + write32(from); +} + +/* paddw r64 to r64 */ +void PADDWRtoR(int to, int from) { + write16(0xFD0F); + ModRM(3, to, from); +} + +/* paddw m64 to r64 */ +void PADDWMtoR(int to, u32 from) { + write16(0xFD0F); + ModRM(0, to, DISP32); + write32(from); +} + +/* paddd r64 to r64 */ +void PADDDRtoR(int to, int from) { + write16(0xFE0F); + ModRM(3, to, from); +} + +/* paddd m64 to r64 */ +void PADDDMtoR(int to, u32 from) { + write16(0xFE0F); + ModRM(0, to, DISP32); + write32(from); +} + +/* emms */ +void EMMS() { + write16(0x770F); +} diff --git a/PcsxSrc/ix86/ix86.h b/PcsxSrc/ix86/ix86.h index 3f3d6cd..c611893 100644 --- a/PcsxSrc/ix86/ix86.h +++ b/PcsxSrc/ix86/ix86.h @@ -1,397 +1,397 @@ -/* - * ix86 definitions. - * Author: linuzappz - */ - -#ifndef __IX86_H__ -#define __IX86_H__ - -// include basic types -#include "PsxCommon.h" - -/* general defines */ - -#define EAX 0 -#define EBX 3 -#define ECX 1 -#define EDX 2 -#define ESI 6 -#define EDI 7 -#define EBP 5 -#define ESP 4 - -#define MM0 0 -#define MM1 1 -#define MM2 2 -#define MM3 3 -#define MM4 4 -#define MM5 5 -#define MM6 6 -#define MM7 7 - -s8 *x86Ptr; -u8 *j8Ptr[32]; -u32 *j32Ptr[32]; - -void x86Init(char *ptr); -void x86SetJ8(u8 *j8); -void x86SetJ32(u32 *j32); -void x86Shutdown(); - - -/********************/ -/* IX86 intructions */ -/********************/ - -/* - * scale values: - * 0 - *1 - * 1 - *2 - * 2 - *4 - * 3 - *8 - */ - -// mov instructions - -/* mov r32 to r32 */ -void MOV32RtoR(int to, int from); -/* mov r32 to m32 */ -void MOV32RtoM(u32 to, int from); -/* mov m32 to r32 */ -void MOV32MtoR(int to, u32 from); -/* mov [r32] to r32 */ -void MOV32RmtoR(int to, int from); -/* mov [r32][r32*scale] to r32 */ -void MOV32RmStoR(int to, int from, int from2, int scale); -/* mov r32 to [r32] */ -void MOV32RtoRm(int to, int from); -/* mov imm32 to r32 */ -void MOV32ItoR(int to, u32 from); -/* mov imm32 to m32 */ -void MOV32ItoM(u32 to, u32 from); - -/* movsx r8 to r32 */ -void MOVSX32R8toR(int to, int from); -/* movsx r16 to r32 */ -void MOVSX32R16toR(int to, int from); -/* movzx r8 to r32 */ -void MOVZX32R8toR(int to, int from); -/* movzx r16 to r32 */ -void MOVZX32R16toR(int to, int from); - -/* cmovne r32 to r32 */ -void CMOVNE32RtoR(int to, int from); -/* cmovne m32 to r32*/ -void CMOVNE32MtoR(int to, u32 from); -/* cmove r32 to r32*/ -void CMOVE32RtoR(int to, int from); -/* cmove m32 to r32*/ -void CMOVE32MtoR(int to, u32 from); -/* cmovg r32 to r32*/ -void CMOVG32RtoR(int to, int from); -/* cmovg m32 to r32*/ -void CMOVG32MtoR(int to, u32 from); -/* cmovge r32 to r32*/ -void CMOVGE32RtoR(int to, int from); -/* cmovge m32 to r32*/ -void CMOVGE32MtoR(int to, u32 from); -/* cmovl r32 to r32*/ -void CMOVL32RtoR(int to, int from); -/* cmovl m32 to r32*/ -void CMOVL32MtoR(int to, u32 from); -/* cmovle r32 to r32*/ -void CMOVLE32RtoR(int to, int from); -/* cmovle m32 to r32*/ -void CMOVLE32MtoR(int to, u32 from); - -// arithmic instructions - -/* add imm32 to r32 */ -void ADD32ItoR(int to, u32 from); -/* add imm32 to m32 */ -void ADD32ItoM(u32 to, u32 from); -/* add r32 to r32 */ -void ADD32RtoR(int to, int from); -/* add m32 to r32 */ -void ADD32MtoR(int to, u32 from); - -/* adc imm32 to r32 */ -void ADC32ItoR(int to, u32 from); -/* adc r32 to r32 */ -void ADC32RtoR(int to, int from); -/* adc m32 to r32 */ -void ADC32MtoR(int to, u32 from); - -/* sub imm32 to r32 */ -void SUB32ItoR(int to, u32 from); -/* sub r32 to r32 */ -void SUB32RtoR(int to, int from); -/* sub m32 to r32 */ -void SUB32MtoR(int to, u32 from); - -/* sbb imm32 to r32 */ -void SBB32ItoR(int to, u32 from); -/* sbb r32 to r32 */ -void SBB32RtoR(int to, int from); -/* sbb m32 to r32 */ -void SBB32MtoR(int to, u32 from); - -/* mul eax by r32 to edx:eax */ -void MUL32R(int from); -/* mul eax by m32 to edx:eax */ -void MUL32M(u32 from); - -/* imul eax by r32 to edx:eax */ -void IMUL32R(int from); -/* imul eax by m32 to edx:eax */ -void IMUL32M(u32 from); - -/* div eax by r32 to edx:eax */ -void DIV32R(int from); -/* div eax by m32 to edx:eax */ -void DIV32M(u32 from); - -/* idiv eax by r32 to edx:eax */ -void IDIV32R(int from); -/* idiv eax by m32 to edx:eax */ -void IDIV32M(u32 from); - -// shifting instructions - -/* shl imm8 to r32 */ -void SHL32ItoR(int to, unsigned char from); -/* shl cl to r32 */ -void SHL32CLtoR(int to); - -/* shr imm8 to r32 */ -void SHR32ItoR(int to, unsigned char from); -/* shr cl to r32 */ -void SHR32CLtoR(int to); - -/* sar imm8 to r32 */ -void SAR32ItoR(int to, unsigned char from); -/* sar cl to r32 */ -void SAR32CLtoR(int to); - -/* sal imm8 to r32 */ -#define SAL32ItoR SHL32ItoR -/* sal cl to r32 */ -#define SAL32CLtoR SHL32CLtoR - -// logical instructions - -/* or imm32 to r32 */ -void OR32ItoR(int to, u32 from); -/* or imm32 to m32 */ -void OR32ItoM(u32 to, u32 from); -/* or r32 to r32 */ -void OR32RtoR(int to, int from); -/* or m32 to r32 */ -void OR32MtoR(int to, u32 from); - -/* xor imm32 to r32 */ -void XOR32ItoR(int to, u32 from); -/* xor imm32 to m32 */ -void XOR32ItoM(u32 to, u32 from); -/* xor r32 to r32 */ -void XOR32RtoR(int to, int from); -/* xor m32 to r32 */ -void XOR32MtoR(int to, u32 from); - -/* and imm32 to r32 */ -void AND32ItoR(int to, u32 from); -/* and imm32 to m32 */ -void AND32ItoM(u32 to, u32 from); -/* and r32 to r32 */ -void AND32RtoR(int to, int from); -/* and m32 to r32 */ -void AND32MtoR(int to, u32 from); - -/* not r32 */ -void NOT32R(int from); -/* neg r32 */ -void NEG32R(int from); - -// jump instructions - -/* jmp rel8 */ -u8* JMP8(unsigned char to); -/* jmp rel32 */ -u32* JMP32(u32 to); -/* jmp r32 */ -void JMP32R(int to); - -/* je rel8 */ -u8* JE8(unsigned char to); -/* jz rel8 */ -u8* JZ8(unsigned char to); -/* jg rel8 */ -u8* JG8(unsigned char to); -/* jge rel8 */ -u8* JGE8(unsigned char to); -/* jl rel8 */ -u8* JL8(unsigned char to); -/* jle rel8 */ -u8* JLE8(unsigned char to); -/* jne rel8 */ -u8* JNE8(unsigned char to); -/* jnz rel8 */ -u8* JNZ8(unsigned char to); -/* jng rel8 */ -u8* JNG8(unsigned char to); -/* jnge rel8 */ -u8* JNGE8(unsigned char to); -/* jnl rel8 */ -u8* JNL8(unsigned char to); -/* jnle rel8 */ -u8* JNLE8(unsigned char to); - -/* call func */ -void CALLFunc(u32 func); // based on CALL32 -/* call rel32 */ -void CALL32(u32 to); -/* call r32 */ -void CALL32R(int to); - -// misc instructions - -/* cmp imm32 to r32 */ -void CMP32ItoR(int to, u32 from); -/* cmp imm32 to m32 */ -void CMP32ItoM(u32 to, u32 from); -/* cmp r32 to r32 */ -void CMP32RtoR(int to, int from); -/* cmp m32 to r32 */ -void CMP32MtoR(int to, u32 from); - -/* test imm32 to r32 */ -void TEST32ItoR(int to, u32 from); -/* test r32 to r32 */ -void TEST32RtoR(int to, int from); - -/* setl r8 */ -void SETL8R(int to); -/* setb r8 */ -void SETB8R(int to); - -/* cbw */ -void CBW(); -/* cwd */ -void CWD(); -/* cdq */ -void CDQ(); - -/* push r32 */ -void PUSH32R(int from); -/* push m32 */ -void PUSH32M(u32 from); -/* push imm32 */ -void PUSH32I(u32 from); - -/* pop r32 */ -void POP32R(int from); - -/* pushad */ -void PUSHA32(); -/* popad */ -void POPA32(); - -/* ret */ -void RET(); - -/********************/ -/* FPU instructions */ -/********************/ - -/* fild m32 to fpu reg stack */ -void FILD32(u32 from); -/* fistp m32 from fpu reg stack */ -void FISTP32(u32 from); -/* fld m32 to fpu reg stack */ -void FLD32(u32 from); -/* fstp m32 from fpu reg stack */ -void FSTP32(u32 to); - -/* fldcw fpu control word from m16 */ -void FLDCW(u32 from); -/* fstcw fpu control word to m16 */ -void FNSTCW(u32 to); - -/* fadd m32 to fpu reg stack */ -void FADD32(u32 from); -/* fsub m32 to fpu reg stack */ -void FSUB32(u32 from); -/* fmul m32 to fpu reg stack */ -void FMUL32(u32 from); -/* fdiv m32 to fpu reg stack */ -void FDIV32(u32 from); -/* fabs fpu reg stack */ -void FABS(); -/* fsqrt fpu reg stack */ -void FSQRT(); -/* fchs fpu reg stack */ -void FCHS(); - -/********************/ -/* MMX instructions */ -/********************/ - -// r64 = mm - -/* movq m64 to r64 */ -void MOVQMtoR(int to, u32 from); -/* movq r64 to m64 */ -void MOVQRtoM(u32 to, int from); - -/* pand r64 to r64 */ -void PANDRtoR(int to, int from); - -/* por r64 to r64 */ -void PORRtoR(int to, int from); -/* por m64 to r64 */ -void PORMtoR(int to, u32 from); - -/* pxor r64 to r64 */ -void PXORRtoR(int to, int from); - -/* psllq r64 to r64 */ -void PSLLQRtoR(int to, int from); -/* psllq m64 to r64 */ -void PSLLQMtoR(int to, u32 from); -/* psllq imm8 to r64 */ -void PSLLQItoR(int to, unsigned char from); - -/* psrlq r64 to r64 */ -void PSRLQRtoR(int to, int from); -/* psrlq m64 to r64 */ -void PSRLQMtoR(int to, u32 from); -/* psrlq imm8 to r64 */ -void PSRLQItoR(int to, unsigned char from); - -/* paddusb r64 to r64 */ -void PADDUSBRtoR(int to, int from); -/* paddusb m64 to r64 */ -void PADDUSBMtoR(int to, u32 from); -/* paddusw r64 to r64 */ -void PADDUSWRtoR(int to, int from); -/* paddusw m64 to r64 */ -void PADDUSWMtoR(int to, u32 from); - -/* paddb r64 to r64 */ -void PADDBRtoR(int to, int from); -/* paddb m64 to r64 */ -void PADDBMtoR(int to, u32 from); -/* paddw r64 to r64 */ -void PADDWRtoR(int to, int from); -/* paddw m64 to r64 */ -void PADDWMtoR(int to, u32 from); -/* paddd r64 to r64 */ -void PADDDRtoR(int to, int from); -/* paddd m64 to r64 */ -void PADDDMtoR(int to, u32 from); - -/* emms */ -void EMMS(); - - -#endif /* __IX86_H__ */ +/* + * ix86 definitions. + * Author: linuzappz + */ + +#ifndef __IX86_H__ +#define __IX86_H__ + +// include basic types +#include "PsxCommon.h" + +/* general defines */ + +#define EAX 0 +#define EBX 3 +#define ECX 1 +#define EDX 2 +#define ESI 6 +#define EDI 7 +#define EBP 5 +#define ESP 4 + +#define MM0 0 +#define MM1 1 +#define MM2 2 +#define MM3 3 +#define MM4 4 +#define MM5 5 +#define MM6 6 +#define MM7 7 + +s8 *x86Ptr; +u8 *j8Ptr[32]; +u32 *j32Ptr[32]; + +void x86Init(char *ptr); +void x86SetJ8(u8 *j8); +void x86SetJ32(u32 *j32); +void x86Shutdown(); + + +/********************/ +/* IX86 intructions */ +/********************/ + +/* + * scale values: + * 0 - *1 + * 1 - *2 + * 2 - *4 + * 3 - *8 + */ + +// mov instructions + +/* mov r32 to r32 */ +void MOV32RtoR(int to, int from); +/* mov r32 to m32 */ +void MOV32RtoM(u32 to, int from); +/* mov m32 to r32 */ +void MOV32MtoR(int to, u32 from); +/* mov [r32] to r32 */ +void MOV32RmtoR(int to, int from); +/* mov [r32][r32*scale] to r32 */ +void MOV32RmStoR(int to, int from, int from2, int scale); +/* mov r32 to [r32] */ +void MOV32RtoRm(int to, int from); +/* mov imm32 to r32 */ +void MOV32ItoR(int to, u32 from); +/* mov imm32 to m32 */ +void MOV32ItoM(u32 to, u32 from); + +/* movsx r8 to r32 */ +void MOVSX32R8toR(int to, int from); +/* movsx r16 to r32 */ +void MOVSX32R16toR(int to, int from); +/* movzx r8 to r32 */ +void MOVZX32R8toR(int to, int from); +/* movzx r16 to r32 */ +void MOVZX32R16toR(int to, int from); + +/* cmovne r32 to r32 */ +void CMOVNE32RtoR(int to, int from); +/* cmovne m32 to r32*/ +void CMOVNE32MtoR(int to, u32 from); +/* cmove r32 to r32*/ +void CMOVE32RtoR(int to, int from); +/* cmove m32 to r32*/ +void CMOVE32MtoR(int to, u32 from); +/* cmovg r32 to r32*/ +void CMOVG32RtoR(int to, int from); +/* cmovg m32 to r32*/ +void CMOVG32MtoR(int to, u32 from); +/* cmovge r32 to r32*/ +void CMOVGE32RtoR(int to, int from); +/* cmovge m32 to r32*/ +void CMOVGE32MtoR(int to, u32 from); +/* cmovl r32 to r32*/ +void CMOVL32RtoR(int to, int from); +/* cmovl m32 to r32*/ +void CMOVL32MtoR(int to, u32 from); +/* cmovle r32 to r32*/ +void CMOVLE32RtoR(int to, int from); +/* cmovle m32 to r32*/ +void CMOVLE32MtoR(int to, u32 from); + +// arithmic instructions + +/* add imm32 to r32 */ +void ADD32ItoR(int to, u32 from); +/* add imm32 to m32 */ +void ADD32ItoM(u32 to, u32 from); +/* add r32 to r32 */ +void ADD32RtoR(int to, int from); +/* add m32 to r32 */ +void ADD32MtoR(int to, u32 from); + +/* adc imm32 to r32 */ +void ADC32ItoR(int to, u32 from); +/* adc r32 to r32 */ +void ADC32RtoR(int to, int from); +/* adc m32 to r32 */ +void ADC32MtoR(int to, u32 from); + +/* sub imm32 to r32 */ +void SUB32ItoR(int to, u32 from); +/* sub r32 to r32 */ +void SUB32RtoR(int to, int from); +/* sub m32 to r32 */ +void SUB32MtoR(int to, u32 from); + +/* sbb imm32 to r32 */ +void SBB32ItoR(int to, u32 from); +/* sbb r32 to r32 */ +void SBB32RtoR(int to, int from); +/* sbb m32 to r32 */ +void SBB32MtoR(int to, u32 from); + +/* mul eax by r32 to edx:eax */ +void MUL32R(int from); +/* mul eax by m32 to edx:eax */ +void MUL32M(u32 from); + +/* imul eax by r32 to edx:eax */ +void IMUL32R(int from); +/* imul eax by m32 to edx:eax */ +void IMUL32M(u32 from); + +/* div eax by r32 to edx:eax */ +void DIV32R(int from); +/* div eax by m32 to edx:eax */ +void DIV32M(u32 from); + +/* idiv eax by r32 to edx:eax */ +void IDIV32R(int from); +/* idiv eax by m32 to edx:eax */ +void IDIV32M(u32 from); + +// shifting instructions + +/* shl imm8 to r32 */ +void SHL32ItoR(int to, unsigned char from); +/* shl cl to r32 */ +void SHL32CLtoR(int to); + +/* shr imm8 to r32 */ +void SHR32ItoR(int to, unsigned char from); +/* shr cl to r32 */ +void SHR32CLtoR(int to); + +/* sar imm8 to r32 */ +void SAR32ItoR(int to, unsigned char from); +/* sar cl to r32 */ +void SAR32CLtoR(int to); + +/* sal imm8 to r32 */ +#define SAL32ItoR SHL32ItoR +/* sal cl to r32 */ +#define SAL32CLtoR SHL32CLtoR + +// logical instructions + +/* or imm32 to r32 */ +void OR32ItoR(int to, u32 from); +/* or imm32 to m32 */ +void OR32ItoM(u32 to, u32 from); +/* or r32 to r32 */ +void OR32RtoR(int to, int from); +/* or m32 to r32 */ +void OR32MtoR(int to, u32 from); + +/* xor imm32 to r32 */ +void XOR32ItoR(int to, u32 from); +/* xor imm32 to m32 */ +void XOR32ItoM(u32 to, u32 from); +/* xor r32 to r32 */ +void XOR32RtoR(int to, int from); +/* xor m32 to r32 */ +void XOR32MtoR(int to, u32 from); + +/* and imm32 to r32 */ +void AND32ItoR(int to, u32 from); +/* and imm32 to m32 */ +void AND32ItoM(u32 to, u32 from); +/* and r32 to r32 */ +void AND32RtoR(int to, int from); +/* and m32 to r32 */ +void AND32MtoR(int to, u32 from); + +/* not r32 */ +void NOT32R(int from); +/* neg r32 */ +void NEG32R(int from); + +// jump instructions + +/* jmp rel8 */ +u8* JMP8(unsigned char to); +/* jmp rel32 */ +u32* JMP32(u32 to); +/* jmp r32 */ +void JMP32R(int to); + +/* je rel8 */ +u8* JE8(unsigned char to); +/* jz rel8 */ +u8* JZ8(unsigned char to); +/* jg rel8 */ +u8* JG8(unsigned char to); +/* jge rel8 */ +u8* JGE8(unsigned char to); +/* jl rel8 */ +u8* JL8(unsigned char to); +/* jle rel8 */ +u8* JLE8(unsigned char to); +/* jne rel8 */ +u8* JNE8(unsigned char to); +/* jnz rel8 */ +u8* JNZ8(unsigned char to); +/* jng rel8 */ +u8* JNG8(unsigned char to); +/* jnge rel8 */ +u8* JNGE8(unsigned char to); +/* jnl rel8 */ +u8* JNL8(unsigned char to); +/* jnle rel8 */ +u8* JNLE8(unsigned char to); + +/* call func */ +void CALLFunc(u32 func); // based on CALL32 +/* call rel32 */ +void CALL32(u32 to); +/* call r32 */ +void CALL32R(int to); + +// misc instructions + +/* cmp imm32 to r32 */ +void CMP32ItoR(int to, u32 from); +/* cmp imm32 to m32 */ +void CMP32ItoM(u32 to, u32 from); +/* cmp r32 to r32 */ +void CMP32RtoR(int to, int from); +/* cmp m32 to r32 */ +void CMP32MtoR(int to, u32 from); + +/* test imm32 to r32 */ +void TEST32ItoR(int to, u32 from); +/* test r32 to r32 */ +void TEST32RtoR(int to, int from); + +/* setl r8 */ +void SETL8R(int to); +/* setb r8 */ +void SETB8R(int to); + +/* cbw */ +void CBW(); +/* cwd */ +void CWD(); +/* cdq */ +void CDQ(); + +/* push r32 */ +void PUSH32R(int from); +/* push m32 */ +void PUSH32M(u32 from); +/* push imm32 */ +void PUSH32I(u32 from); + +/* pop r32 */ +void POP32R(int from); + +/* pushad */ +void PUSHA32(); +/* popad */ +void POPA32(); + +/* ret */ +void RET(); + +/********************/ +/* FPU instructions */ +/********************/ + +/* fild m32 to fpu reg stack */ +void FILD32(u32 from); +/* fistp m32 from fpu reg stack */ +void FISTP32(u32 from); +/* fld m32 to fpu reg stack */ +void FLD32(u32 from); +/* fstp m32 from fpu reg stack */ +void FSTP32(u32 to); + +/* fldcw fpu control word from m16 */ +void FLDCW(u32 from); +/* fstcw fpu control word to m16 */ +void FNSTCW(u32 to); + +/* fadd m32 to fpu reg stack */ +void FADD32(u32 from); +/* fsub m32 to fpu reg stack */ +void FSUB32(u32 from); +/* fmul m32 to fpu reg stack */ +void FMUL32(u32 from); +/* fdiv m32 to fpu reg stack */ +void FDIV32(u32 from); +/* fabs fpu reg stack */ +void FABS(); +/* fsqrt fpu reg stack */ +void FSQRT(); +/* fchs fpu reg stack */ +void FCHS(); + +/********************/ +/* MMX instructions */ +/********************/ + +// r64 = mm + +/* movq m64 to r64 */ +void MOVQMtoR(int to, u32 from); +/* movq r64 to m64 */ +void MOVQRtoM(u32 to, int from); + +/* pand r64 to r64 */ +void PANDRtoR(int to, int from); + +/* por r64 to r64 */ +void PORRtoR(int to, int from); +/* por m64 to r64 */ +void PORMtoR(int to, u32 from); + +/* pxor r64 to r64 */ +void PXORRtoR(int to, int from); + +/* psllq r64 to r64 */ +void PSLLQRtoR(int to, int from); +/* psllq m64 to r64 */ +void PSLLQMtoR(int to, u32 from); +/* psllq imm8 to r64 */ +void PSLLQItoR(int to, unsigned char from); + +/* psrlq r64 to r64 */ +void PSRLQRtoR(int to, int from); +/* psrlq m64 to r64 */ +void PSRLQMtoR(int to, u32 from); +/* psrlq imm8 to r64 */ +void PSRLQItoR(int to, unsigned char from); + +/* paddusb r64 to r64 */ +void PADDUSBRtoR(int to, int from); +/* paddusb m64 to r64 */ +void PADDUSBMtoR(int to, u32 from); +/* paddusw r64 to r64 */ +void PADDUSWRtoR(int to, int from); +/* paddusw m64 to r64 */ +void PADDUSWMtoR(int to, u32 from); + +/* paddb r64 to r64 */ +void PADDBRtoR(int to, int from); +/* paddb m64 to r64 */ +void PADDBMtoR(int to, u32 from); +/* paddw r64 to r64 */ +void PADDWRtoR(int to, int from); +/* paddw m64 to r64 */ +void PADDWMtoR(int to, u32 from); +/* paddd r64 to r64 */ +void PADDDRtoR(int to, int from); +/* paddd m64 to r64 */ +void PADDDMtoR(int to, u32 from); + +/* emms */ +void EMMS(); + + +#endif /* __IX86_H__ */ diff --git a/PcsxSrc/plugins.c b/PcsxSrc/plugins.c index 20b88c3..225216a 100644 --- a/PcsxSrc/plugins.c +++ b/PcsxSrc/plugins.c @@ -1,678 +1,678 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 -#include -#include - -#include "PsxCommon.h" - -#ifdef __WIN32__ -#pragma warning(disable:4244) -#endif - -#define CheckErr(func) \ - err = SysLibError(); \ - if (err != NULL) { SysMessage ("Error loading %s: %s\n",func,err); return -1; } - -#define LoadSym(dest, src, name, checkerr) \ - dest = (src) SysLoadSym(drv, name); if (checkerr == 1) CheckErr(name); \ - if (checkerr == 2) { err = SysLibError(); if (err != NULL) errval = 1; } - -static char *err; -static int errval; - -void *hGPUDriver; - -void ConfigurePlugins(); - -void CALLBACK GPU__readDataMem(unsigned long *pMem, int iSize) { - while (iSize > 0) { - *pMem = GPU_readData(); - iSize--; - pMem++; - } -} - -void CALLBACK GPU__writeDataMem(unsigned long *pMem, int iSize) { - while (iSize > 0) { - GPU_writeData(*pMem); - iSize--; - pMem++; - } -} - -void CALLBACK GPU__displayText(char *pText) { - SysPrintf("%s\n", pText); -} - -extern int StatesC; -long CALLBACK GPU__freeze(unsigned long ulGetFreezeData, GPUFreeze_t *pF) { - pF->ulFreezeVersion = 1; - if (ulGetFreezeData == 0) { - int val; - - val = GPU_readStatus(); - val = 0x04000000 | ((val >> 29) & 0x3); - GPU_writeStatus(0x04000003); - GPU_writeStatus(0x01000000); - GPU_writeData(0xa0000000); - GPU_writeData(0x00000000); - GPU_writeData(0x02000400); - GPU_writeDataMem((unsigned long*)pF->psxVRam, 0x100000/4); - GPU_writeStatus(val); - - val = pF->ulStatus; - GPU_writeStatus(0x00000000); - GPU_writeData(0x01000000); - GPU_writeStatus(0x01000000); - GPU_writeStatus(0x03000000 | ((val>>24)&0x1)); - GPU_writeStatus(0x04000000 | ((val>>29)&0x3)); - GPU_writeStatus(0x08000000 | ((val>>17)&0x3f) | ((val>>10)&0x40)); - GPU_writeData(0xe1000000 | (val&0x7ff)); - GPU_writeData(0xe6000000 | ((val>>11)&3)); - -/* GPU_writeData(0xe3000000 | pF->ulControl[0] & 0xffffff); - GPU_writeData(0xe4000000 | pF->ulControl[1] & 0xffffff); - GPU_writeData(0xe5000000 | pF->ulControl[2] & 0xffffff);*/ - return 1; - } - if (ulGetFreezeData == 1) { - int val; - - val = GPU_readStatus(); - val = 0x04000000 | ((val >> 29) & 0x3); - GPU_writeStatus(0x04000003); - GPU_writeStatus(0x01000000); - GPU_writeData(0xc0000000); - GPU_writeData(0x00000000); - GPU_writeData(0x02000400); - GPU_readDataMem((unsigned long*)pF->psxVRam, 0x100000/4); - GPU_writeStatus(val); - - pF->ulStatus = GPU_readStatus(); - -/* GPU_writeStatus(0x10000003); - pF->ulControl[0] = GPU_readData(); - GPU_writeStatus(0x10000004); - pF->ulControl[1] = GPU_readData(); - GPU_writeStatus(0x10000005); - pF->ulControl[2] = GPU_readData();*/ - return 1; - } - if(ulGetFreezeData==2) { - long lSlotNum=*((long *)pF); - char Text[32]; - - sprintf (Text, "*PCSX*: Selected State %ld", lSlotNum+1); - GPU_displayText(Text); - return 1; - } - return 0; -} - -long CALLBACK GPU__configure(void) { return 0; } -long CALLBACK GPU__test(void) { return 0; } -void CALLBACK GPU__about(void) {} -void CALLBACK GPU__makeSnapshot(void) {} -void CALLBACK GPU__keypressed(int key) {} -long CALLBACK GPU__getScreenPic(unsigned char *pMem) { return -1; } -long CALLBACK GPU__showScreenPic(unsigned char *pMem) { return -1; } - -#define LoadGpuSym1(dest, name) \ - LoadSym(GPU_##dest, GPU##dest, name, 1); - -#define LoadGpuSym0(dest, name) \ - LoadSym(GPU_##dest, GPU##dest, name, 0); \ - if (GPU_##dest == NULL) GPU_##dest = (GPU##dest) GPU__##dest; - -int LoadGPUplugin(char *GPUdll) { - void *drv; - - hGPUDriver = SysLoadLibrary(GPUdll); - if (hGPUDriver == NULL) { SysMessage ("Could Not Load GPU Plugin %s\n", GPUdll); return -1; } - drv = hGPUDriver; - LoadGpuSym1(init, "GPUinit"); - LoadGpuSym1(shutdown, "GPUshutdown"); - LoadGpuSym1(open, "GPUopen"); - LoadGpuSym1(close, "GPUclose"); - LoadGpuSym1(readData, "GPUreadData"); - LoadGpuSym0(readDataMem, "GPUreadDataMem"); - LoadGpuSym1(readStatus, "GPUreadStatus"); - LoadGpuSym1(writeData, "GPUwriteData"); - LoadGpuSym0(writeDataMem, "GPUwriteDataMem"); - LoadGpuSym1(writeStatus, "GPUwriteStatus"); - LoadGpuSym1(dmaChain, "GPUdmaChain"); - LoadGpuSym1(updateLace, "GPUupdateLace"); - LoadGpuSym0(keypressed, "GPUkeypressed"); - LoadGpuSym0(displayText, "GPUdisplayText"); - LoadGpuSym0(makeSnapshot, "GPUmakeSnapshot"); - LoadGpuSym0(freeze, "GPUfreeze"); - LoadGpuSym0(getScreenPic, "GPUgetScreenPic"); - LoadGpuSym0(showScreenPic, "GPUshowScreenPic"); - LoadGpuSym0(configure, "GPUconfigure"); - LoadGpuSym0(test, "GPUtest"); - LoadGpuSym0(about, "GPUabout"); - - return 0; -} - -void *hCDRDriver; - -long CALLBACK CDR__play(unsigned char *sector) { return 0; } -long CALLBACK CDR__stop(void) { return 0; } - -long CALLBACK CDR__getStatus(struct CdrStat *stat) { - if (cdOpenCase) stat->Status = 0x10; - else stat->Status = 0; - return 0; -} - -char* CALLBACK CDR__getDriveLetter(void) { return NULL; } -unsigned char* CALLBACK CDR__getBufferSub(void) { return NULL; } -long CALLBACK CDR__configure(void) { return 0; } -long CALLBACK CDR__test(void) { return 0; } -void CALLBACK CDR__about(void) {} - -#define LoadCdrSym1(dest, name) \ - LoadSym(CDR_##dest, CDR##dest, name, 1); - -#define LoadCdrSym0(dest, name) \ - LoadSym(CDR_##dest, CDR##dest, name, 0); \ - if (CDR_##dest == NULL) CDR_##dest = (CDR##dest) CDR__##dest; - -int LoadCDRplugin(char *CDRdll) { - void *drv; - - hCDRDriver = SysLoadLibrary(CDRdll); - if (hCDRDriver == NULL) { SysMessage ("Could Not load CDR plugin %s\n",CDRdll); return -1; } - drv = hCDRDriver; - LoadCdrSym1(init, "CDRinit"); - LoadCdrSym1(shutdown, "CDRshutdown"); - LoadCdrSym1(open, "CDRopen"); - LoadCdrSym1(close, "CDRclose"); - LoadCdrSym1(getTN, "CDRgetTN"); - LoadCdrSym1(getTD, "CDRgetTD"); - LoadCdrSym1(readTrack, "CDRreadTrack"); - LoadCdrSym1(getBuffer, "CDRgetBuffer"); - LoadCdrSym0(play, "CDRplay"); - LoadCdrSym0(stop, "CDRstop"); - LoadCdrSym0(getStatus, "CDRgetStatus"); - LoadCdrSym0(getDriveLetter, "CDRgetDriveLetter"); - LoadCdrSym0(getBufferSub, "CDRgetBufferSub"); - LoadCdrSym0(configure, "CDRconfigure"); - LoadCdrSym0(test, "CDRtest"); - LoadCdrSym0(about, "CDRabout"); - - return 0; -} - -void *hSPUDriver; - -long CALLBACK SPU__configure(void) { return 0; } -void CALLBACK SPU__about(void) {} -long CALLBACK SPU__test(void) { return 0; } - -unsigned short regArea[10000]; -unsigned short spuCtrl,spuStat,spuIrq; -unsigned long spuAddr; - -void CALLBACK SPU__writeRegister(unsigned long add,unsigned short value) { // Old Interface - unsigned long r=add&0xfff; - regArea[(r-0xc00)/2] = value; - - if(r>=0x0c00 && r<0x0d80) { - unsigned char ch=(r>>4)-0xc0; - switch(r&0x0f) {//switch voices - case 0: //left volume - SPU_setVolumeL(ch,value); - return; - case 2: //right volume - SPU_setVolumeR(ch,value); - return; - case 4: //frequency - SPU_setPitch(ch,value); - return; - case 6://start address - SPU_setAddr(ch,value); - return; - //------------------------------------------------// level -// case 8: -// s_chan[ch].ADSRX.AttackModeExp = (val&0x8000)?TRUE:FALSE; -// s_chan[ch].ADSRX.AttackRate = (float)((val>>8) & 0x007f)*1000.0f/240.0f; -// s_chan[ch].ADSRX.DecayRate = (float)((val>>4) & 0x000f)*1000.0f/240.0f; -// s_chan[ch].ADSRX.SustainLevel = (float)((val) & 0x000f); - -// return; -// case 10: -// s_chan[ch].ADSRX.SustainModeExp = (val&0x8000)?TRUE:FALSE; -// s_chan[ch].ADSRX.ReleaseModeExp = (val&0x0020)?TRUE:FALSE; -// s_chan[ch].ADSRX.SustainRate = ((float)((val>>6) & 0x007f))*R_SUSTAIN; -// s_chan[ch].ADSRX.ReleaseRate = ((float)((val) & 0x001f))*R_RELEASE; -// if(val & 0x4000) s_chan[ch].ADSRX.SustainModeDec=-1.0f; -// else s_chan[ch].ADSRX.SustainModeDec=1.0f; -// return; -// case 12: -// return; -// case 14: -// s_chan[ch].pRepeat=spuMemC+((unsigned long) val<<3); -// return; - } - return; - } - - switch(r) { - case H_SPUaddr://SPU-memory address - spuAddr = (unsigned long) value<<3; - // spuAddr=value * 8; - return; - case H_SPUdata://DATA to SPU -// spuMem[spuAddr/2] = value; -// spuAddr+=2; -// if(spuAddr>0x7ffff) spuAddr=0; - SPU_putOne(spuAddr,value); - spuAddr+=2; - return; - case H_SPUctrl://SPU control 1 - spuCtrl=value; - return; - case H_SPUstat://SPU status - spuStat=value & 0xf800; - return; - case H_SPUirqAddr://SPU irq - spuIrq = value; - return; - case H_SPUon1://start sound play channels 0-16 - SPU_startChannels1(value); - return; - case H_SPUon2://start sound play channels 16-24 - SPU_startChannels2(value); - return; - case H_SPUoff1://stop sound play channels 0-16 - SPU_stopChannels1(value); - return; - case H_SPUoff2://stop sound play channels 16-24 - SPU_stopChannels2(value); - return; - } -} - -unsigned short CALLBACK SPU__readRegister(unsigned long add) { - switch(add&0xfff) {// Old Interface - case H_SPUctrl://spu control - return spuCtrl; - case H_SPUstat://spu status - return spuStat; - case H_SPUaddr://SPU-memory address - return (unsigned short)(spuAddr>>3); - case H_SPUdata://DATA to SPU - spuAddr+=2; -// if(spuAddr>0x7ffff) spuAddr=0; -// return spuMem[spuAddr/2]; - return SPU_getOne(spuAddr); - case H_SPUirqAddr://spu irq - return spuIrq; - //case H_SPUIsOn1: - //return IsSoundOn(0,16); - //case H_SPUIsOn2: - //return IsSoundOn(16,24); - } - return regArea[((add&0xfff)-0xc00)/2]; -} - -void CALLBACK SPU__writeDMA(unsigned short val) { - SPU_putOne(spuAddr, val); - spuAddr += 2; - if (spuAddr > 0x7ffff) spuAddr = 0; -} - -unsigned short CALLBACK SPU__readDMA(void) { - unsigned short tmp = SPU_getOne(spuAddr); - spuAddr += 2; - if (spuAddr > 0x7ffff) spuAddr = 0; - return tmp; -} - -void CALLBACK SPU__writeDMAMem(unsigned short *pMem, int iSize) { - while (iSize > 0) { - SPU_writeDMA(*pMem); - iSize--; - pMem++; - } -} - -void CALLBACK SPU__readDMAMem(unsigned short *pMem, int iSize) { - while (iSize > 0) { - *pMem = SPU_readDMA(); - iSize--; - pMem++; - } -} - -void CALLBACK SPU__playADPCMchannel(xa_decode_t *xap) {} - -long CALLBACK SPU__freeze(unsigned long ulFreezeMode, SPUFreeze_t *pF) { - if (ulFreezeMode == 2) { - memset(pF, 0, 16); - strcpy((char *)pF->PluginName, "Pcsx"); - pF->PluginVersion = 1; - pF->Size = 0x200 + 0x80000 + 16 + sizeof(xa_decode_t); - - return 1; - } - if (ulFreezeMode == 1) { - unsigned long addr; - unsigned short val; - - val = SPU_readRegister(0x1f801da6); - SPU_writeRegister(0x1f801da6, 0); - SPU_readDMAMem((unsigned short *)pF->SPURam, 0x80000/2); - SPU_writeRegister(0x1f801da6, val); - - for (addr = 0x1f801c00; addr < 0x1f801e00; addr+=2) { - if (addr == 0x1f801da8) { pF->SPUPorts[addr - 0x1f801c00] = 0; continue; } - pF->SPUPorts[addr - 0x1f801c00] = SPU_readRegister(addr); - } - - return 1; - } - if (ulFreezeMode == 0) { - unsigned long addr; - unsigned short val; - unsigned short *regs = (unsigned short *)pF->SPUPorts; - - val = SPU_readRegister(0x1f801da6); - SPU_writeRegister(0x1f801da6, 0); - SPU_writeDMAMem((unsigned short *)pF->SPURam, 0x80000/2); - SPU_writeRegister(0x1f801da6, val); - - for (addr = 0x1f801c00; addr < 0x1f801e00; addr+=2) { - if (addr == 0x1f801da8) { regs++; continue; } - SPU_writeRegister(addr, *(regs++)); - } - - return 1; - } - - return 0; -} - -void CALLBACK SPU__registerCallback(void (CALLBACK *callback)(void)) {} - -#define LoadSpuSym1(dest, name) \ - LoadSym(SPU_##dest, SPU##dest, name, 1); - -#define LoadSpuSym2(dest, name) \ - LoadSym(SPU_##dest, SPU##dest, name, 2); - -#define LoadSpuSym0(dest, name) \ - LoadSym(SPU_##dest, SPU##dest, name, 0); \ - if (SPU_##dest == NULL) SPU_##dest = (SPU##dest) SPU__##dest; - -#define LoadSpuSymE(dest, name) \ - LoadSym(SPU_##dest, SPU##dest, name, errval); \ - if (SPU_##dest == NULL) SPU_##dest = (SPU##dest) SPU__##dest; - -#define LoadSpuSymN(dest, name) \ - LoadSym(SPU_##dest, SPU##dest, name, 0); \ - -int LoadSPUplugin(char *SPUdll) { - void *drv; - - hSPUDriver = SysLoadLibrary(SPUdll); - if (hSPUDriver == NULL) { SysMessage ("Could not open SPU plugin %s\n",SPUdll); return -1; } - drv = hSPUDriver; - LoadSpuSym1(init, "SPUinit"); - LoadSpuSym1(shutdown, "SPUshutdown"); - LoadSpuSym1(open, "SPUopen"); - LoadSpuSym1(close, "SPUclose"); - LoadSpuSym0(configure, "SPUconfigure"); - LoadSpuSym0(about, "SPUabout"); - LoadSpuSym0(test, "SPUtest"); - errval = 0; - LoadSpuSym2(startChannels1, "SPUstartChannels1"); - LoadSpuSym2(startChannels2, "SPUstartChannels2"); - LoadSpuSym2(stopChannels1, "SPUstopChannels1"); - LoadSpuSym2(stopChannels2, "SPUstopChannels2"); - LoadSpuSym2(putOne, "SPUputOne"); - LoadSpuSym2(getOne, "SPUgetOne"); - LoadSpuSym2(setAddr, "SPUsetAddr"); - LoadSpuSym2(setPitch, "SPUsetPitch"); - LoadSpuSym2(setVolumeL, "SPUsetVolumeL"); - LoadSpuSym2(setVolumeR, "SPUsetVolumeR"); - LoadSpuSymE(writeRegister, "SPUwriteRegister"); - LoadSpuSymE(readRegister, "SPUreadRegister"); - LoadSpuSymE(writeDMA, "SPUwriteDMA"); - LoadSpuSymE(readDMA, "SPUreadDMA"); - LoadSpuSym0(writeDMAMem, "SPUwriteDMAMem"); - LoadSpuSym0(readDMAMem, "SPUreadDMAMem"); - LoadSpuSym0(playADPCMchannel, "SPUplayADPCMchannel"); - LoadSpuSym0(freeze, "SPUfreeze"); - LoadSpuSym0(registerCallback, "SPUregisterCallback"); - LoadSpuSymN(update, "SPUupdate"); - LoadSpuSymN(async, "SPUasync"); - - return 0; -} - - -void *hPAD1Driver; -void *hPAD2Driver; - -static unsigned char buf[256]; -unsigned char stdpar[10] = { 0x00, 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; -unsigned char mousepar[8] = { 0x00, 0x12, 0x5a, 0xff, 0xff, 0xff, 0xff }; -unsigned char analogpar[6] = { 0x00, 0xff, 0x5a, 0xff, 0xff }; - -static int bufcount, bufc; - -unsigned char _PADstartPoll(PadDataS *pad) { - bufc = 0; - - switch (pad->controllerType) { - case PSE_PAD_TYPE_MOUSE: - mousepar[3] = pad->buttonStatus & 0xff; - mousepar[4] = pad->buttonStatus >> 8; - mousepar[5] = pad->moveX; - mousepar[6] = pad->moveY; - - memcpy(buf, mousepar, 7); - bufcount = 6; - break; - case PSE_PAD_TYPE_ANALOGPAD: // scph1150 - analogpar[1] = 0x73; - analogpar[3] = pad->buttonStatus & 0xff; - analogpar[4] = pad->buttonStatus >> 8; - analogpar[5] = pad->rightJoyX; - analogpar[6] = pad->rightJoyY; - analogpar[7] = pad->leftJoyX; - analogpar[8] = pad->leftJoyY; - - memcpy(buf, analogpar, 9); - bufcount = 8; - break; - case PSE_PAD_TYPE_ANALOGJOY: // scph1110 - analogpar[1] = 0x53; - analogpar[3] = pad->buttonStatus & 0xff; - analogpar[4] = pad->buttonStatus >> 8; - analogpar[5] = pad->rightJoyX; - analogpar[6] = pad->rightJoyY; - analogpar[7] = pad->leftJoyX; - analogpar[8] = pad->leftJoyY; - - memcpy(buf, analogpar, 9); - bufcount = 8; - break; - case PSE_PAD_TYPE_STANDARD: - default: - stdpar[3] = pad->buttonStatus & 0xff; - stdpar[4] = pad->buttonStatus >> 8; - - memcpy(buf, stdpar, 5); - bufcount = 4; - } - - return buf[bufc++]; -} - -unsigned char _PADpoll(unsigned char value) { - if (bufc > bufcount) return 0; - return buf[bufc++]; -} - -unsigned char CALLBACK PAD1__startPoll(int pad) { - PadDataS padd; - - PAD1_readPort1(&padd); - - return _PADstartPoll(&padd); -} - -unsigned char CALLBACK PAD1__poll(unsigned char value) { - return _PADpoll(value); -} - -long CALLBACK PAD1__configure(void) { return 0; } -void CALLBACK PAD1__about(void) {} -long CALLBACK PAD1__test(void) { return 0; } -long CALLBACK PAD1__query(void) { return 3; } -long CALLBACK PAD1__keypressed() { return 0; } - -#define LoadPad1Sym1(dest, name) \ - LoadSym(PAD1_##dest, PAD##dest, name, 1); - -#define LoadPad1Sym0(dest, name) \ - LoadSym(PAD1_##dest, PAD##dest, name, 0); \ - if (PAD1_##dest == NULL) PAD1_##dest = (PAD##dest) PAD1__##dest; - -int LoadPAD1plugin(char *PAD1dll) { - void *drv; - - hPAD1Driver = SysLoadLibrary(PAD1dll); - if (hPAD1Driver == NULL) { SysMessage ("Could Not load PAD1 plugin %s\n",PAD1dll); return -1; } - drv = hPAD1Driver; - LoadPad1Sym1(init, "PADinit"); - LoadPad1Sym1(shutdown, "PADshutdown"); - LoadPad1Sym1(open, "PADopen"); - LoadPad1Sym1(close, "PADclose"); - LoadPad1Sym0(query, "PADquery"); - LoadPad1Sym1(readPort1, "PADreadPort1"); - LoadPad1Sym0(configure, "PADconfigure"); - LoadPad1Sym0(test, "PADtest"); - LoadPad1Sym0(about, "PADabout"); - LoadPad1Sym0(keypressed, "PADkeypressed"); - LoadPad1Sym0(startPoll, "PADstartPoll"); - LoadPad1Sym0(poll, "PADpoll"); - - return 0; -} - -unsigned char CALLBACK PAD2__startPoll(int pad) { - PadDataS padd; - - PAD2_readPort2(&padd); - - return _PADstartPoll(&padd); -} - -unsigned char CALLBACK PAD2__poll(unsigned char value) { - return _PADpoll(value); -} - -long CALLBACK PAD2__configure(void) { return 0; } -void CALLBACK PAD2__about(void) {} -long CALLBACK PAD2__test(void) { return 0; } -long CALLBACK PAD2__query(void) { return 3; } -long CALLBACK PAD2__keypressed() { return 0; } - -#define LoadPad2Sym1(dest, name) \ - LoadSym(PAD2_##dest, PAD##dest, name, 1); - -#define LoadPad2Sym0(dest, name) \ - LoadSym(PAD2_##dest, PAD##dest, name, 0); \ - if (PAD2_##dest == NULL) PAD2_##dest = (PAD##dest) PAD2__##dest; - -int LoadPAD2plugin(char *PAD2dll) { - void *drv; - - hPAD2Driver = SysLoadLibrary(PAD2dll); - if (hPAD2Driver == NULL) { SysMessage ("Could Not load PAD plugin %s\n",PAD2dll); return -1; } - drv = hPAD2Driver; - LoadPad2Sym1(init, "PADinit"); - LoadPad2Sym1(shutdown, "PADshutdown"); - LoadPad2Sym1(open, "PADopen"); - LoadPad2Sym1(close, "PADclose"); - LoadPad2Sym0(query, "PADquery"); - LoadPad2Sym1(readPort2, "PADreadPort2"); - LoadPad2Sym0(configure, "PADconfigure"); - LoadPad2Sym0(test, "PADtest"); - LoadPad2Sym0(about, "PADabout"); - LoadPad2Sym0(keypressed, "PADkeypressed"); - LoadPad2Sym0(startPoll, "PADstartPoll"); - LoadPad2Sym0(poll, "PADpoll"); - - return 0; -} - - -/*long PAD2__readBuffer() { - return PAD2_readBuffer(); -}*/ - -int LoadPlugins() { - int ret; - char Plugin[256]; - - sprintf(Plugin, "%s%s", Config.PluginsDir, Config.Cdr); - if (LoadCDRplugin(Plugin) == -1) return -1; - sprintf(Plugin, "%s%s", Config.PluginsDir, Config.Gpu); - if (LoadGPUplugin(Plugin) == -1) return -1; - sprintf(Plugin, "%s%s", Config.PluginsDir, Config.Spu); - if (LoadSPUplugin(Plugin) == -1) return -1; - sprintf(Plugin, "%s%s", Config.PluginsDir, Config.Pad1); - if (LoadPAD1plugin(Plugin) == -1) return -1; - sprintf(Plugin, "%s%s", Config.PluginsDir, Config.Pad2); - if (LoadPAD2plugin(Plugin) == -1) return -1; - ret = CDR_init(); - if (ret != 0) { SysMessage ("CDRinit error : %d\n",ret); return -1; } - ret = GPU_init(); - if (ret != 0) { SysMessage ("GPUinit error : %d\n",ret); return -1; } - ret = SPU_init(); - if (ret != 0) { SysMessage ("SPUinit error : %d\n",ret); return -1; } - ret = PAD1_init(1); - if (ret != 0) { SysMessage ("PAD1init error : %d\n",ret); return -1; } - ret = PAD2_init(2); - if (ret != 0) { SysMessage ("PAD2init error : %d\n",ret); return -1; } - - return 0; -} - -void ReleasePlugins() { - if (hCDRDriver == NULL || hGPUDriver == NULL || hSPUDriver == NULL || - hPAD1Driver == NULL || hPAD2Driver == NULL) return; - CDR_shutdown(); - GPU_shutdown(); - SPU_shutdown(); - PAD1_shutdown(); - PAD2_shutdown(); - SysCloseLibrary(hCDRDriver); hCDRDriver = NULL; - SysCloseLibrary(hGPUDriver); hGPUDriver = NULL; - SysCloseLibrary(hSPUDriver); hSPUDriver = NULL; - SysCloseLibrary(hPAD1Driver); hPAD1Driver = NULL; - SysCloseLibrary(hPAD2Driver); hPAD2Driver = NULL; -} +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 +#include +#include + +#include "PsxCommon.h" + +#ifdef __WIN32__ +#pragma warning(disable:4244) +#endif + +#define CheckErr(func) \ + err = SysLibError(); \ + if (err != NULL) { SysMessage ("Error loading %s: %s\n",func,err); return -1; } + +#define LoadSym(dest, src, name, checkerr) \ + dest = (src) SysLoadSym(drv, name); if (checkerr == 1) CheckErr(name); \ + if (checkerr == 2) { err = SysLibError(); if (err != NULL) errval = 1; } + +static char *err; +static int errval; + +void *hGPUDriver; + +void ConfigurePlugins(); + +void CALLBACK GPU__readDataMem(unsigned long *pMem, int iSize) { + while (iSize > 0) { + *pMem = GPU_readData(); + iSize--; + pMem++; + } +} + +void CALLBACK GPU__writeDataMem(unsigned long *pMem, int iSize) { + while (iSize > 0) { + GPU_writeData(*pMem); + iSize--; + pMem++; + } +} + +void CALLBACK GPU__displayText(char *pText) { + SysPrintf("%s\n", pText); +} + +extern int StatesC; +long CALLBACK GPU__freeze(unsigned long ulGetFreezeData, GPUFreeze_t *pF) { + pF->ulFreezeVersion = 1; + if (ulGetFreezeData == 0) { + int val; + + val = GPU_readStatus(); + val = 0x04000000 | ((val >> 29) & 0x3); + GPU_writeStatus(0x04000003); + GPU_writeStatus(0x01000000); + GPU_writeData(0xa0000000); + GPU_writeData(0x00000000); + GPU_writeData(0x02000400); + GPU_writeDataMem((unsigned long*)pF->psxVRam, 0x100000/4); + GPU_writeStatus(val); + + val = pF->ulStatus; + GPU_writeStatus(0x00000000); + GPU_writeData(0x01000000); + GPU_writeStatus(0x01000000); + GPU_writeStatus(0x03000000 | ((val>>24)&0x1)); + GPU_writeStatus(0x04000000 | ((val>>29)&0x3)); + GPU_writeStatus(0x08000000 | ((val>>17)&0x3f) | ((val>>10)&0x40)); + GPU_writeData(0xe1000000 | (val&0x7ff)); + GPU_writeData(0xe6000000 | ((val>>11)&3)); + +/* GPU_writeData(0xe3000000 | pF->ulControl[0] & 0xffffff); + GPU_writeData(0xe4000000 | pF->ulControl[1] & 0xffffff); + GPU_writeData(0xe5000000 | pF->ulControl[2] & 0xffffff);*/ + return 1; + } + if (ulGetFreezeData == 1) { + int val; + + val = GPU_readStatus(); + val = 0x04000000 | ((val >> 29) & 0x3); + GPU_writeStatus(0x04000003); + GPU_writeStatus(0x01000000); + GPU_writeData(0xc0000000); + GPU_writeData(0x00000000); + GPU_writeData(0x02000400); + GPU_readDataMem((unsigned long*)pF->psxVRam, 0x100000/4); + GPU_writeStatus(val); + + pF->ulStatus = GPU_readStatus(); + +/* GPU_writeStatus(0x10000003); + pF->ulControl[0] = GPU_readData(); + GPU_writeStatus(0x10000004); + pF->ulControl[1] = GPU_readData(); + GPU_writeStatus(0x10000005); + pF->ulControl[2] = GPU_readData();*/ + return 1; + } + if(ulGetFreezeData==2) { + long lSlotNum=*((long *)pF); + char Text[32]; + + sprintf (Text, "*PCSX*: Selected State %ld", lSlotNum+1); + GPU_displayText(Text); + return 1; + } + return 0; +} + +long CALLBACK GPU__configure(void) { return 0; } +long CALLBACK GPU__test(void) { return 0; } +void CALLBACK GPU__about(void) {} +void CALLBACK GPU__makeSnapshot(void) {} +void CALLBACK GPU__keypressed(int key) {} +long CALLBACK GPU__getScreenPic(unsigned char *pMem) { return -1; } +long CALLBACK GPU__showScreenPic(unsigned char *pMem) { return -1; } + +#define LoadGpuSym1(dest, name) \ + LoadSym(GPU_##dest, GPU##dest, name, 1); + +#define LoadGpuSym0(dest, name) \ + LoadSym(GPU_##dest, GPU##dest, name, 0); \ + if (GPU_##dest == NULL) GPU_##dest = (GPU##dest) GPU__##dest; + +int LoadGPUplugin(char *GPUdll) { + void *drv; + + hGPUDriver = SysLoadLibrary(GPUdll); + if (hGPUDriver == NULL) { SysMessage ("Could Not Load GPU Plugin %s\n", GPUdll); return -1; } + drv = hGPUDriver; + LoadGpuSym1(init, "GPUinit"); + LoadGpuSym1(shutdown, "GPUshutdown"); + LoadGpuSym1(open, "GPUopen"); + LoadGpuSym1(close, "GPUclose"); + LoadGpuSym1(readData, "GPUreadData"); + LoadGpuSym0(readDataMem, "GPUreadDataMem"); + LoadGpuSym1(readStatus, "GPUreadStatus"); + LoadGpuSym1(writeData, "GPUwriteData"); + LoadGpuSym0(writeDataMem, "GPUwriteDataMem"); + LoadGpuSym1(writeStatus, "GPUwriteStatus"); + LoadGpuSym1(dmaChain, "GPUdmaChain"); + LoadGpuSym1(updateLace, "GPUupdateLace"); + LoadGpuSym0(keypressed, "GPUkeypressed"); + LoadGpuSym0(displayText, "GPUdisplayText"); + LoadGpuSym0(makeSnapshot, "GPUmakeSnapshot"); + LoadGpuSym0(freeze, "GPUfreeze"); + LoadGpuSym0(getScreenPic, "GPUgetScreenPic"); + LoadGpuSym0(showScreenPic, "GPUshowScreenPic"); + LoadGpuSym0(configure, "GPUconfigure"); + LoadGpuSym0(test, "GPUtest"); + LoadGpuSym0(about, "GPUabout"); + + return 0; +} + +void *hCDRDriver; + +long CALLBACK CDR__play(unsigned char *sector) { return 0; } +long CALLBACK CDR__stop(void) { return 0; } + +long CALLBACK CDR__getStatus(struct CdrStat *stat) { + if (cdOpenCase) stat->Status = 0x10; + else stat->Status = 0; + return 0; +} + +char* CALLBACK CDR__getDriveLetter(void) { return NULL; } +unsigned char* CALLBACK CDR__getBufferSub(void) { return NULL; } +long CALLBACK CDR__configure(void) { return 0; } +long CALLBACK CDR__test(void) { return 0; } +void CALLBACK CDR__about(void) {} + +#define LoadCdrSym1(dest, name) \ + LoadSym(CDR_##dest, CDR##dest, name, 1); + +#define LoadCdrSym0(dest, name) \ + LoadSym(CDR_##dest, CDR##dest, name, 0); \ + if (CDR_##dest == NULL) CDR_##dest = (CDR##dest) CDR__##dest; + +int LoadCDRplugin(char *CDRdll) { + void *drv; + + hCDRDriver = SysLoadLibrary(CDRdll); + if (hCDRDriver == NULL) { SysMessage ("Could Not load CDR plugin %s\n",CDRdll); return -1; } + drv = hCDRDriver; + LoadCdrSym1(init, "CDRinit"); + LoadCdrSym1(shutdown, "CDRshutdown"); + LoadCdrSym1(open, "CDRopen"); + LoadCdrSym1(close, "CDRclose"); + LoadCdrSym1(getTN, "CDRgetTN"); + LoadCdrSym1(getTD, "CDRgetTD"); + LoadCdrSym1(readTrack, "CDRreadTrack"); + LoadCdrSym1(getBuffer, "CDRgetBuffer"); + LoadCdrSym0(play, "CDRplay"); + LoadCdrSym0(stop, "CDRstop"); + LoadCdrSym0(getStatus, "CDRgetStatus"); + LoadCdrSym0(getDriveLetter, "CDRgetDriveLetter"); + LoadCdrSym0(getBufferSub, "CDRgetBufferSub"); + LoadCdrSym0(configure, "CDRconfigure"); + LoadCdrSym0(test, "CDRtest"); + LoadCdrSym0(about, "CDRabout"); + + return 0; +} + +void *hSPUDriver; + +long CALLBACK SPU__configure(void) { return 0; } +void CALLBACK SPU__about(void) {} +long CALLBACK SPU__test(void) { return 0; } + +unsigned short regArea[10000]; +unsigned short spuCtrl,spuStat,spuIrq; +unsigned long spuAddr; + +void CALLBACK SPU__writeRegister(unsigned long add,unsigned short value) { // Old Interface + unsigned long r=add&0xfff; + regArea[(r-0xc00)/2] = value; + + if(r>=0x0c00 && r<0x0d80) { + unsigned char ch=(r>>4)-0xc0; + switch(r&0x0f) {//switch voices + case 0: //left volume + SPU_setVolumeL(ch,value); + return; + case 2: //right volume + SPU_setVolumeR(ch,value); + return; + case 4: //frequency + SPU_setPitch(ch,value); + return; + case 6://start address + SPU_setAddr(ch,value); + return; + //------------------------------------------------// level +// case 8: +// s_chan[ch].ADSRX.AttackModeExp = (val&0x8000)?TRUE:FALSE; +// s_chan[ch].ADSRX.AttackRate = (float)((val>>8) & 0x007f)*1000.0f/240.0f; +// s_chan[ch].ADSRX.DecayRate = (float)((val>>4) & 0x000f)*1000.0f/240.0f; +// s_chan[ch].ADSRX.SustainLevel = (float)((val) & 0x000f); + +// return; +// case 10: +// s_chan[ch].ADSRX.SustainModeExp = (val&0x8000)?TRUE:FALSE; +// s_chan[ch].ADSRX.ReleaseModeExp = (val&0x0020)?TRUE:FALSE; +// s_chan[ch].ADSRX.SustainRate = ((float)((val>>6) & 0x007f))*R_SUSTAIN; +// s_chan[ch].ADSRX.ReleaseRate = ((float)((val) & 0x001f))*R_RELEASE; +// if(val & 0x4000) s_chan[ch].ADSRX.SustainModeDec=-1.0f; +// else s_chan[ch].ADSRX.SustainModeDec=1.0f; +// return; +// case 12: +// return; +// case 14: +// s_chan[ch].pRepeat=spuMemC+((unsigned long) val<<3); +// return; + } + return; + } + + switch(r) { + case H_SPUaddr://SPU-memory address + spuAddr = (unsigned long) value<<3; + // spuAddr=value * 8; + return; + case H_SPUdata://DATA to SPU +// spuMem[spuAddr/2] = value; +// spuAddr+=2; +// if(spuAddr>0x7ffff) spuAddr=0; + SPU_putOne(spuAddr,value); + spuAddr+=2; + return; + case H_SPUctrl://SPU control 1 + spuCtrl=value; + return; + case H_SPUstat://SPU status + spuStat=value & 0xf800; + return; + case H_SPUirqAddr://SPU irq + spuIrq = value; + return; + case H_SPUon1://start sound play channels 0-16 + SPU_startChannels1(value); + return; + case H_SPUon2://start sound play channels 16-24 + SPU_startChannels2(value); + return; + case H_SPUoff1://stop sound play channels 0-16 + SPU_stopChannels1(value); + return; + case H_SPUoff2://stop sound play channels 16-24 + SPU_stopChannels2(value); + return; + } +} + +unsigned short CALLBACK SPU__readRegister(unsigned long add) { + switch(add&0xfff) {// Old Interface + case H_SPUctrl://spu control + return spuCtrl; + case H_SPUstat://spu status + return spuStat; + case H_SPUaddr://SPU-memory address + return (unsigned short)(spuAddr>>3); + case H_SPUdata://DATA to SPU + spuAddr+=2; +// if(spuAddr>0x7ffff) spuAddr=0; +// return spuMem[spuAddr/2]; + return SPU_getOne(spuAddr); + case H_SPUirqAddr://spu irq + return spuIrq; + //case H_SPUIsOn1: + //return IsSoundOn(0,16); + //case H_SPUIsOn2: + //return IsSoundOn(16,24); + } + return regArea[((add&0xfff)-0xc00)/2]; +} + +void CALLBACK SPU__writeDMA(unsigned short val) { + SPU_putOne(spuAddr, val); + spuAddr += 2; + if (spuAddr > 0x7ffff) spuAddr = 0; +} + +unsigned short CALLBACK SPU__readDMA(void) { + unsigned short tmp = SPU_getOne(spuAddr); + spuAddr += 2; + if (spuAddr > 0x7ffff) spuAddr = 0; + return tmp; +} + +void CALLBACK SPU__writeDMAMem(unsigned short *pMem, int iSize) { + while (iSize > 0) { + SPU_writeDMA(*pMem); + iSize--; + pMem++; + } +} + +void CALLBACK SPU__readDMAMem(unsigned short *pMem, int iSize) { + while (iSize > 0) { + *pMem = SPU_readDMA(); + iSize--; + pMem++; + } +} + +void CALLBACK SPU__playADPCMchannel(xa_decode_t *xap) {} + +long CALLBACK SPU__freeze(unsigned long ulFreezeMode, SPUFreeze_t *pF) { + if (ulFreezeMode == 2) { + memset(pF, 0, 16); + strcpy((char *)pF->PluginName, "Pcsx"); + pF->PluginVersion = 1; + pF->Size = 0x200 + 0x80000 + 16 + sizeof(xa_decode_t); + + return 1; + } + if (ulFreezeMode == 1) { + unsigned long addr; + unsigned short val; + + val = SPU_readRegister(0x1f801da6); + SPU_writeRegister(0x1f801da6, 0); + SPU_readDMAMem((unsigned short *)pF->SPURam, 0x80000/2); + SPU_writeRegister(0x1f801da6, val); + + for (addr = 0x1f801c00; addr < 0x1f801e00; addr+=2) { + if (addr == 0x1f801da8) { pF->SPUPorts[addr - 0x1f801c00] = 0; continue; } + pF->SPUPorts[addr - 0x1f801c00] = SPU_readRegister(addr); + } + + return 1; + } + if (ulFreezeMode == 0) { + unsigned long addr; + unsigned short val; + unsigned short *regs = (unsigned short *)pF->SPUPorts; + + val = SPU_readRegister(0x1f801da6); + SPU_writeRegister(0x1f801da6, 0); + SPU_writeDMAMem((unsigned short *)pF->SPURam, 0x80000/2); + SPU_writeRegister(0x1f801da6, val); + + for (addr = 0x1f801c00; addr < 0x1f801e00; addr+=2) { + if (addr == 0x1f801da8) { regs++; continue; } + SPU_writeRegister(addr, *(regs++)); + } + + return 1; + } + + return 0; +} + +void CALLBACK SPU__registerCallback(void (CALLBACK *callback)(void)) {} + +#define LoadSpuSym1(dest, name) \ + LoadSym(SPU_##dest, SPU##dest, name, 1); + +#define LoadSpuSym2(dest, name) \ + LoadSym(SPU_##dest, SPU##dest, name, 2); + +#define LoadSpuSym0(dest, name) \ + LoadSym(SPU_##dest, SPU##dest, name, 0); \ + if (SPU_##dest == NULL) SPU_##dest = (SPU##dest) SPU__##dest; + +#define LoadSpuSymE(dest, name) \ + LoadSym(SPU_##dest, SPU##dest, name, errval); \ + if (SPU_##dest == NULL) SPU_##dest = (SPU##dest) SPU__##dest; + +#define LoadSpuSymN(dest, name) \ + LoadSym(SPU_##dest, SPU##dest, name, 0); \ + +int LoadSPUplugin(char *SPUdll) { + void *drv; + + hSPUDriver = SysLoadLibrary(SPUdll); + if (hSPUDriver == NULL) { SysMessage ("Could not open SPU plugin %s\n",SPUdll); return -1; } + drv = hSPUDriver; + LoadSpuSym1(init, "SPUinit"); + LoadSpuSym1(shutdown, "SPUshutdown"); + LoadSpuSym1(open, "SPUopen"); + LoadSpuSym1(close, "SPUclose"); + LoadSpuSym0(configure, "SPUconfigure"); + LoadSpuSym0(about, "SPUabout"); + LoadSpuSym0(test, "SPUtest"); + errval = 0; + LoadSpuSym2(startChannels1, "SPUstartChannels1"); + LoadSpuSym2(startChannels2, "SPUstartChannels2"); + LoadSpuSym2(stopChannels1, "SPUstopChannels1"); + LoadSpuSym2(stopChannels2, "SPUstopChannels2"); + LoadSpuSym2(putOne, "SPUputOne"); + LoadSpuSym2(getOne, "SPUgetOne"); + LoadSpuSym2(setAddr, "SPUsetAddr"); + LoadSpuSym2(setPitch, "SPUsetPitch"); + LoadSpuSym2(setVolumeL, "SPUsetVolumeL"); + LoadSpuSym2(setVolumeR, "SPUsetVolumeR"); + LoadSpuSymE(writeRegister, "SPUwriteRegister"); + LoadSpuSymE(readRegister, "SPUreadRegister"); + LoadSpuSymE(writeDMA, "SPUwriteDMA"); + LoadSpuSymE(readDMA, "SPUreadDMA"); + LoadSpuSym0(writeDMAMem, "SPUwriteDMAMem"); + LoadSpuSym0(readDMAMem, "SPUreadDMAMem"); + LoadSpuSym0(playADPCMchannel, "SPUplayADPCMchannel"); + LoadSpuSym0(freeze, "SPUfreeze"); + LoadSpuSym0(registerCallback, "SPUregisterCallback"); + LoadSpuSymN(update, "SPUupdate"); + LoadSpuSymN(async, "SPUasync"); + + return 0; +} + + +void *hPAD1Driver; +void *hPAD2Driver; + +static unsigned char buf[256]; +unsigned char stdpar[10] = { 0x00, 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; +unsigned char mousepar[8] = { 0x00, 0x12, 0x5a, 0xff, 0xff, 0xff, 0xff }; +unsigned char analogpar[6] = { 0x00, 0xff, 0x5a, 0xff, 0xff }; + +static int bufcount, bufc; + +unsigned char _PADstartPoll(PadDataS *pad) { + bufc = 0; + + switch (pad->controllerType) { + case PSE_PAD_TYPE_MOUSE: + mousepar[3] = pad->buttonStatus & 0xff; + mousepar[4] = pad->buttonStatus >> 8; + mousepar[5] = pad->moveX; + mousepar[6] = pad->moveY; + + memcpy(buf, mousepar, 7); + bufcount = 6; + break; + case PSE_PAD_TYPE_ANALOGPAD: // scph1150 + analogpar[1] = 0x73; + analogpar[3] = pad->buttonStatus & 0xff; + analogpar[4] = pad->buttonStatus >> 8; + analogpar[5] = pad->rightJoyX; + analogpar[6] = pad->rightJoyY; + analogpar[7] = pad->leftJoyX; + analogpar[8] = pad->leftJoyY; + + memcpy(buf, analogpar, 9); + bufcount = 8; + break; + case PSE_PAD_TYPE_ANALOGJOY: // scph1110 + analogpar[1] = 0x53; + analogpar[3] = pad->buttonStatus & 0xff; + analogpar[4] = pad->buttonStatus >> 8; + analogpar[5] = pad->rightJoyX; + analogpar[6] = pad->rightJoyY; + analogpar[7] = pad->leftJoyX; + analogpar[8] = pad->leftJoyY; + + memcpy(buf, analogpar, 9); + bufcount = 8; + break; + case PSE_PAD_TYPE_STANDARD: + default: + stdpar[3] = pad->buttonStatus & 0xff; + stdpar[4] = pad->buttonStatus >> 8; + + memcpy(buf, stdpar, 5); + bufcount = 4; + } + + return buf[bufc++]; +} + +unsigned char _PADpoll(unsigned char value) { + if (bufc > bufcount) return 0; + return buf[bufc++]; +} + +unsigned char CALLBACK PAD1__startPoll(int pad) { + PadDataS padd; + + PAD1_readPort1(&padd); + + return _PADstartPoll(&padd); +} + +unsigned char CALLBACK PAD1__poll(unsigned char value) { + return _PADpoll(value); +} + +long CALLBACK PAD1__configure(void) { return 0; } +void CALLBACK PAD1__about(void) {} +long CALLBACK PAD1__test(void) { return 0; } +long CALLBACK PAD1__query(void) { return 3; } +long CALLBACK PAD1__keypressed() { return 0; } + +#define LoadPad1Sym1(dest, name) \ + LoadSym(PAD1_##dest, PAD##dest, name, 1); + +#define LoadPad1Sym0(dest, name) \ + LoadSym(PAD1_##dest, PAD##dest, name, 0); \ + if (PAD1_##dest == NULL) PAD1_##dest = (PAD##dest) PAD1__##dest; + +int LoadPAD1plugin(char *PAD1dll) { + void *drv; + + hPAD1Driver = SysLoadLibrary(PAD1dll); + if (hPAD1Driver == NULL) { SysMessage ("Could Not load PAD1 plugin %s\n",PAD1dll); return -1; } + drv = hPAD1Driver; + LoadPad1Sym1(init, "PADinit"); + LoadPad1Sym1(shutdown, "PADshutdown"); + LoadPad1Sym1(open, "PADopen"); + LoadPad1Sym1(close, "PADclose"); + LoadPad1Sym0(query, "PADquery"); + LoadPad1Sym1(readPort1, "PADreadPort1"); + LoadPad1Sym0(configure, "PADconfigure"); + LoadPad1Sym0(test, "PADtest"); + LoadPad1Sym0(about, "PADabout"); + LoadPad1Sym0(keypressed, "PADkeypressed"); + LoadPad1Sym0(startPoll, "PADstartPoll"); + LoadPad1Sym0(poll, "PADpoll"); + + return 0; +} + +unsigned char CALLBACK PAD2__startPoll(int pad) { + PadDataS padd; + + PAD2_readPort2(&padd); + + return _PADstartPoll(&padd); +} + +unsigned char CALLBACK PAD2__poll(unsigned char value) { + return _PADpoll(value); +} + +long CALLBACK PAD2__configure(void) { return 0; } +void CALLBACK PAD2__about(void) {} +long CALLBACK PAD2__test(void) { return 0; } +long CALLBACK PAD2__query(void) { return 3; } +long CALLBACK PAD2__keypressed() { return 0; } + +#define LoadPad2Sym1(dest, name) \ + LoadSym(PAD2_##dest, PAD##dest, name, 1); + +#define LoadPad2Sym0(dest, name) \ + LoadSym(PAD2_##dest, PAD##dest, name, 0); \ + if (PAD2_##dest == NULL) PAD2_##dest = (PAD##dest) PAD2__##dest; + +int LoadPAD2plugin(char *PAD2dll) { + void *drv; + + hPAD2Driver = SysLoadLibrary(PAD2dll); + if (hPAD2Driver == NULL) { SysMessage ("Could Not load PAD plugin %s\n",PAD2dll); return -1; } + drv = hPAD2Driver; + LoadPad2Sym1(init, "PADinit"); + LoadPad2Sym1(shutdown, "PADshutdown"); + LoadPad2Sym1(open, "PADopen"); + LoadPad2Sym1(close, "PADclose"); + LoadPad2Sym0(query, "PADquery"); + LoadPad2Sym1(readPort2, "PADreadPort2"); + LoadPad2Sym0(configure, "PADconfigure"); + LoadPad2Sym0(test, "PADtest"); + LoadPad2Sym0(about, "PADabout"); + LoadPad2Sym0(keypressed, "PADkeypressed"); + LoadPad2Sym0(startPoll, "PADstartPoll"); + LoadPad2Sym0(poll, "PADpoll"); + + return 0; +} + + +/*long PAD2__readBuffer() { + return PAD2_readBuffer(); +}*/ + +int LoadPlugins() { + int ret; + char Plugin[256]; + + sprintf(Plugin, "%s%s", Config.PluginsDir, Config.Cdr); + if (LoadCDRplugin(Plugin) == -1) return -1; + sprintf(Plugin, "%s%s", Config.PluginsDir, Config.Gpu); + if (LoadGPUplugin(Plugin) == -1) return -1; + sprintf(Plugin, "%s%s", Config.PluginsDir, Config.Spu); + if (LoadSPUplugin(Plugin) == -1) return -1; + sprintf(Plugin, "%s%s", Config.PluginsDir, Config.Pad1); + if (LoadPAD1plugin(Plugin) == -1) return -1; + sprintf(Plugin, "%s%s", Config.PluginsDir, Config.Pad2); + if (LoadPAD2plugin(Plugin) == -1) return -1; + ret = CDR_init(); + if (ret != 0) { SysMessage ("CDRinit error : %d\n",ret); return -1; } + ret = GPU_init(); + if (ret != 0) { SysMessage ("GPUinit error : %d\n",ret); return -1; } + ret = SPU_init(); + if (ret != 0) { SysMessage ("SPUinit error : %d\n",ret); return -1; } + ret = PAD1_init(1); + if (ret != 0) { SysMessage ("PAD1init error : %d\n",ret); return -1; } + ret = PAD2_init(2); + if (ret != 0) { SysMessage ("PAD2init error : %d\n",ret); return -1; } + + return 0; +} + +void ReleasePlugins() { + if (hCDRDriver == NULL || hGPUDriver == NULL || hSPUDriver == NULL || + hPAD1Driver == NULL || hPAD2Driver == NULL) return; + CDR_shutdown(); + GPU_shutdown(); + SPU_shutdown(); + PAD1_shutdown(); + PAD2_shutdown(); + SysCloseLibrary(hCDRDriver); hCDRDriver = NULL; + SysCloseLibrary(hGPUDriver); hGPUDriver = NULL; + SysCloseLibrary(hSPUDriver); hSPUDriver = NULL; + SysCloseLibrary(hPAD1Driver); hPAD1Driver = NULL; + SysCloseLibrary(hPAD2Driver); hPAD2Driver = NULL; +} diff --git a/PcsxSrc/plugins.h b/PcsxSrc/plugins.h index 040df1c..ba537ce 100644 --- a/PcsxSrc/plugins.h +++ b/PcsxSrc/plugins.h @@ -1,269 +1,269 @@ -/* Pcsx - Pc Psx Emulator - * Copyright (C) 1999-2002 Pcsx Team - * - * 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 - */ - -#ifndef __PLUGINS_H__ -#define __PLUGINS_H__ - -#if defined (__WIN32__) -#include "Win32\plugin.h" -#elif defined(__LINUX__) -typedef void* HWND; -#include "Linux/Plugin.h" -#endif - -#include "PSEmu_Plugin_Defs.h" -#include "Decode_XA.h" - -int LoadPlugins(); -void ReleasePlugins(); -void OpenPlugins(); -void ClosePlugins(); -void ResetPlugins(); - -#ifdef __LINUX__ -#define CALLBACK -#endif - -typedef unsigned long (CALLBACK* PSEgetLibType)(void); -typedef unsigned long (CALLBACK* PSEgetLibVersion)(void); -typedef char *(CALLBACK* PSEgetLibName)(void); - -///GPU PLUGIN STUFF -typedef long (CALLBACK* GPUinit)(void); -typedef long (CALLBACK* GPUshutdown)(void); -typedef long (CALLBACK* GPUclose)(void); -typedef void (CALLBACK* GPUwriteStatus)(unsigned long); -typedef void (CALLBACK* GPUwriteData)(unsigned long); -typedef void (CALLBACK* GPUwriteDataMem)(unsigned long *, int); -typedef unsigned long (CALLBACK* GPUreadStatus)(void); -typedef unsigned long (CALLBACK* GPUreadData)(void); -typedef void (CALLBACK* GPUreadDataMem)(unsigned long *, int); -typedef long (CALLBACK* GPUdmaChain)(unsigned long *,unsigned long); -typedef void (CALLBACK* GPUupdateLace)(void); -typedef long (CALLBACK* GPUconfigure)(void); -typedef long (CALLBACK* GPUtest)(void); -typedef void (CALLBACK* GPUabout)(void); -typedef void (CALLBACK* GPUmakeSnapshot)(void); -typedef void (CALLBACK* GPUkeypressed)(int); -typedef void (CALLBACK* GPUdisplayText)(char *); -typedef struct { - unsigned long ulFreezeVersion; - unsigned long ulStatus; - unsigned long ulControl[256]; - unsigned char psxVRam[1024*512*2]; -} GPUFreeze_t; -typedef long (CALLBACK* GPUfreeze)(unsigned long, GPUFreeze_t *); -typedef long (CALLBACK* GPUgetScreenPic)(unsigned char *); -typedef long (CALLBACK* GPUshowScreenPic)(unsigned char *); - -//plugin stuff From Shadow -// *** walking in the valley of your darking soul i realize that i was alone -//Gpu function pointers -GPUupdateLace GPU_updateLace; -GPUinit GPU_init; -GPUshutdown GPU_shutdown; -GPUconfigure GPU_configure; -GPUtest GPU_test; -GPUabout GPU_about; -GPUopen GPU_open; -GPUclose GPU_close; -GPUreadStatus GPU_readStatus; -GPUreadData GPU_readData; -GPUreadDataMem GPU_readDataMem; -GPUwriteStatus GPU_writeStatus; -GPUwriteData GPU_writeData; -GPUwriteDataMem GPU_writeDataMem; -GPUdmaChain GPU_dmaChain; -GPUkeypressed GPU_keypressed; -GPUdisplayText GPU_displayText; -GPUmakeSnapshot GPU_makeSnapshot; -GPUfreeze GPU_freeze; -GPUgetScreenPic GPU_getScreenPic; -GPUshowScreenPic GPU_showScreenPic; - -//cd rom plugin ;) -typedef long (CALLBACK* CDRinit)(void); -typedef long (CALLBACK* CDRshutdown)(void); -typedef long (CALLBACK* CDRopen)(void); -typedef long (CALLBACK* CDRclose)(void); -typedef long (CALLBACK* CDRgetTN)(unsigned char *); -typedef long (CALLBACK* CDRgetTD)(unsigned char , unsigned char *); -typedef long (CALLBACK* CDRreadTrack)(unsigned char *); -typedef unsigned char * (CALLBACK* CDRgetBuffer)(void); -typedef long (CALLBACK* CDRconfigure)(void); -typedef long (CALLBACK* CDRtest)(void); -typedef void (CALLBACK* CDRabout)(void); -typedef long (CALLBACK* CDRplay)(unsigned char *); -typedef long (CALLBACK* CDRstop)(void); -struct CdrStat { - unsigned long Type; - unsigned long Status; - unsigned char Time[3]; -}; -typedef long (CALLBACK* CDRgetStatus)(struct CdrStat *); -typedef char* (CALLBACK* CDRgetDriveLetter)(void); -struct SubQ { - char res0[11]; - unsigned char ControlAndADR; - unsigned char TrackNumber; - unsigned char IndexNumber; - unsigned char TrackRelativeAddress[3]; - unsigned char Filler; - unsigned char AbsoluteAddress[3]; - char res1[72]; -}; -typedef unsigned char* (CALLBACK* CDRgetBufferSub)(void); - -//cd rom function pointers -CDRinit CDR_init; -CDRshutdown CDR_shutdown; -CDRopen CDR_open; -CDRclose CDR_close; -CDRtest CDR_test; -CDRgetTN CDR_getTN; -CDRgetTD CDR_getTD; -CDRreadTrack CDR_readTrack; -CDRgetBuffer CDR_getBuffer; -CDRplay CDR_play; -CDRstop CDR_stop; -CDRgetStatus CDR_getStatus; -CDRgetDriveLetter CDR_getDriveLetter; -CDRgetBufferSub CDR_getBufferSub; -CDRconfigure CDR_configure; -CDRabout CDR_about; - -// spu plugin -typedef long (CALLBACK* SPUinit)(void); -typedef long (CALLBACK* SPUshutdown)(void); -typedef long (CALLBACK* SPUclose)(void); -typedef void (CALLBACK* SPUplaySample)(unsigned char); -typedef void (CALLBACK* SPUstartChannels1)(unsigned short); -typedef void (CALLBACK* SPUstartChannels2)(unsigned short); -typedef void (CALLBACK* SPUstopChannels1)(unsigned short); -typedef void (CALLBACK* SPUstopChannels2)(unsigned short); -typedef void (CALLBACK* SPUputOne)(unsigned long,unsigned short); -typedef unsigned short (CALLBACK* SPUgetOne)(unsigned long); -typedef void (CALLBACK* SPUsetAddr)(unsigned char, unsigned short); -typedef void (CALLBACK* SPUsetPitch)(unsigned char, unsigned short); -typedef void (CALLBACK* SPUsetVolumeL)(unsigned char, short ); -typedef void (CALLBACK* SPUsetVolumeR)(unsigned char, short ); -//psemu pro 2 functions from now.. -typedef void (CALLBACK* SPUwriteRegister)(unsigned long, unsigned short); -typedef unsigned short (CALLBACK* SPUreadRegister)(unsigned long); -typedef void (CALLBACK* SPUwriteDMA)(unsigned short); -typedef unsigned short (CALLBACK* SPUreadDMA)(void); -typedef void (CALLBACK* SPUwriteDMAMem)(unsigned short *, int); -typedef void (CALLBACK* SPUreadDMAMem)(unsigned short *, int); -typedef void (CALLBACK* SPUplayADPCMchannel)(xa_decode_t *); -typedef void (CALLBACK* SPUregisterCallback)(void (CALLBACK *callback)(void)); -typedef long (CALLBACK* SPUconfigure)(void); -typedef long (CALLBACK* SPUtest)(void); -typedef void (CALLBACK* SPUabout)(void); -typedef struct { - unsigned char PluginName[8]; - unsigned long PluginVersion; - unsigned long Size; - unsigned char SPUPorts[0x200]; - unsigned char SPURam[0x80000]; - xa_decode_t xa; - unsigned char *SPUInfo; -} SPUFreeze_t; -typedef long (CALLBACK* SPUfreeze)(unsigned long, SPUFreeze_t *); -typedef void (CALLBACK* SPUupdate)(void); -typedef void (CALLBACK* SPUasync)(unsigned long); - -//SPU POINTERS -SPUconfigure SPU_configure; -SPUabout SPU_about; -SPUinit SPU_init; -SPUshutdown SPU_shutdown; -SPUtest SPU_test; -SPUopen SPU_open; -SPUclose SPU_close; -SPUplaySample SPU_playSample; -SPUstartChannels1 SPU_startChannels1; -SPUstartChannels2 SPU_startChannels2; -SPUstopChannels1 SPU_stopChannels1; -SPUstopChannels2 SPU_stopChannels2; -SPUputOne SPU_putOne; -SPUgetOne SPU_getOne; -SPUsetAddr SPU_setAddr; -SPUsetPitch SPU_setPitch; -SPUsetVolumeL SPU_setVolumeL; -SPUsetVolumeR SPU_setVolumeR; -SPUwriteRegister SPU_writeRegister; -SPUreadRegister SPU_readRegister; -SPUwriteDMA SPU_writeDMA; -SPUreadDMA SPU_readDMA; -SPUwriteDMAMem SPU_writeDMAMem; -SPUreadDMAMem SPU_readDMAMem; -SPUplayADPCMchannel SPU_playADPCMchannel; -SPUfreeze SPU_freeze; -SPUregisterCallback SPU_registerCallback; -SPUupdate SPU_update; -SPUasync SPU_async; - -// PAD Functions - -typedef long (CALLBACK* PADconfigure)(void); -typedef void (CALLBACK* PADabout)(void); -typedef long (CALLBACK* PADinit)(long); -typedef long (CALLBACK* PADshutdown)(void); -typedef long (CALLBACK* PADtest)(void); -typedef long (CALLBACK* PADclose)(void); -typedef long (CALLBACK* PADquery)(void); -typedef long (CALLBACK* PADreadPort1)(PadDataS*); -typedef long (CALLBACK* PADreadPort2)(PadDataS*); -typedef long (CALLBACK* PADkeypressed)(void); -typedef unsigned char (CALLBACK* PADstartPoll)(int); -typedef unsigned char (CALLBACK* PADpoll)(unsigned char); - -//PAD POINTERS -PADconfigure PAD1_configure; -PADabout PAD1_about; -PADinit PAD1_init; -PADshutdown PAD1_shutdown; -PADtest PAD1_test; -PADopen PAD1_open; -PADclose PAD1_close; -PADquery PAD1_query; -PADreadPort1 PAD1_readPort1; -PADkeypressed PAD1_keypressed; -PADstartPoll PAD1_startPoll; -PADpoll PAD1_poll; - -PADconfigure PAD2_configure; -PADabout PAD2_about; -PADinit PAD2_init; -PADshutdown PAD2_shutdown; -PADtest PAD2_test; -PADopen PAD2_open; -PADclose PAD2_close; -PADquery PAD2_query; -PADreadPort2 PAD2_readPort2; -PADkeypressed PAD2_keypressed; -PADstartPoll PAD2_startPoll; -PADpoll PAD2_poll; - -int LoadCDRplugin(char *CDRdll); -int LoadGPUplugin(char *GPUdll); -int LoadSPUplugin(char *SPUdll); -int LoadPAD1plugin(char *PAD1dll); -int LoadPAD2plugin(char *PAD2dll); - -#endif /* __PLUGINS_H__ */ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * 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 + */ + +#ifndef __PLUGINS_H__ +#define __PLUGINS_H__ + +#if defined (__WIN32__) +#include "Win32\plugin.h" +#elif defined(__LINUX__) +typedef void* HWND; +#include "Linux/Plugin.h" +#endif + +#include "PSEmu_Plugin_Defs.h" +#include "Decode_XA.h" + +int LoadPlugins(); +void ReleasePlugins(); +void OpenPlugins(); +void ClosePlugins(); +void ResetPlugins(); + +#ifdef __LINUX__ +#define CALLBACK +#endif + +typedef unsigned long (CALLBACK* PSEgetLibType)(void); +typedef unsigned long (CALLBACK* PSEgetLibVersion)(void); +typedef char *(CALLBACK* PSEgetLibName)(void); + +///GPU PLUGIN STUFF +typedef long (CALLBACK* GPUinit)(void); +typedef long (CALLBACK* GPUshutdown)(void); +typedef long (CALLBACK* GPUclose)(void); +typedef void (CALLBACK* GPUwriteStatus)(unsigned long); +typedef void (CALLBACK* GPUwriteData)(unsigned long); +typedef void (CALLBACK* GPUwriteDataMem)(unsigned long *, int); +typedef unsigned long (CALLBACK* GPUreadStatus)(void); +typedef unsigned long (CALLBACK* GPUreadData)(void); +typedef void (CALLBACK* GPUreadDataMem)(unsigned long *, int); +typedef long (CALLBACK* GPUdmaChain)(unsigned long *,unsigned long); +typedef void (CALLBACK* GPUupdateLace)(void); +typedef long (CALLBACK* GPUconfigure)(void); +typedef long (CALLBACK* GPUtest)(void); +typedef void (CALLBACK* GPUabout)(void); +typedef void (CALLBACK* GPUmakeSnapshot)(void); +typedef void (CALLBACK* GPUkeypressed)(int); +typedef void (CALLBACK* GPUdisplayText)(char *); +typedef struct { + unsigned long ulFreezeVersion; + unsigned long ulStatus; + unsigned long ulControl[256]; + unsigned char psxVRam[1024*512*2]; +} GPUFreeze_t; +typedef long (CALLBACK* GPUfreeze)(unsigned long, GPUFreeze_t *); +typedef long (CALLBACK* GPUgetScreenPic)(unsigned char *); +typedef long (CALLBACK* GPUshowScreenPic)(unsigned char *); + +//plugin stuff From Shadow +// *** walking in the valley of your darking soul i realize that i was alone +//Gpu function pointers +GPUupdateLace GPU_updateLace; +GPUinit GPU_init; +GPUshutdown GPU_shutdown; +GPUconfigure GPU_configure; +GPUtest GPU_test; +GPUabout GPU_about; +GPUopen GPU_open; +GPUclose GPU_close; +GPUreadStatus GPU_readStatus; +GPUreadData GPU_readData; +GPUreadDataMem GPU_readDataMem; +GPUwriteStatus GPU_writeStatus; +GPUwriteData GPU_writeData; +GPUwriteDataMem GPU_writeDataMem; +GPUdmaChain GPU_dmaChain; +GPUkeypressed GPU_keypressed; +GPUdisplayText GPU_displayText; +GPUmakeSnapshot GPU_makeSnapshot; +GPUfreeze GPU_freeze; +GPUgetScreenPic GPU_getScreenPic; +GPUshowScreenPic GPU_showScreenPic; + +//cd rom plugin ;) +typedef long (CALLBACK* CDRinit)(void); +typedef long (CALLBACK* CDRshutdown)(void); +typedef long (CALLBACK* CDRopen)(void); +typedef long (CALLBACK* CDRclose)(void); +typedef long (CALLBACK* CDRgetTN)(unsigned char *); +typedef long (CALLBACK* CDRgetTD)(unsigned char , unsigned char *); +typedef long (CALLBACK* CDRreadTrack)(unsigned char *); +typedef unsigned char * (CALLBACK* CDRgetBuffer)(void); +typedef long (CALLBACK* CDRconfigure)(void); +typedef long (CALLBACK* CDRtest)(void); +typedef void (CALLBACK* CDRabout)(void); +typedef long (CALLBACK* CDRplay)(unsigned char *); +typedef long (CALLBACK* CDRstop)(void); +struct CdrStat { + unsigned long Type; + unsigned long Status; + unsigned char Time[3]; +}; +typedef long (CALLBACK* CDRgetStatus)(struct CdrStat *); +typedef char* (CALLBACK* CDRgetDriveLetter)(void); +struct SubQ { + char res0[11]; + unsigned char ControlAndADR; + unsigned char TrackNumber; + unsigned char IndexNumber; + unsigned char TrackRelativeAddress[3]; + unsigned char Filler; + unsigned char AbsoluteAddress[3]; + char res1[72]; +}; +typedef unsigned char* (CALLBACK* CDRgetBufferSub)(void); + +//cd rom function pointers +CDRinit CDR_init; +CDRshutdown CDR_shutdown; +CDRopen CDR_open; +CDRclose CDR_close; +CDRtest CDR_test; +CDRgetTN CDR_getTN; +CDRgetTD CDR_getTD; +CDRreadTrack CDR_readTrack; +CDRgetBuffer CDR_getBuffer; +CDRplay CDR_play; +CDRstop CDR_stop; +CDRgetStatus CDR_getStatus; +CDRgetDriveLetter CDR_getDriveLetter; +CDRgetBufferSub CDR_getBufferSub; +CDRconfigure CDR_configure; +CDRabout CDR_about; + +// spu plugin +typedef long (CALLBACK* SPUinit)(void); +typedef long (CALLBACK* SPUshutdown)(void); +typedef long (CALLBACK* SPUclose)(void); +typedef void (CALLBACK* SPUplaySample)(unsigned char); +typedef void (CALLBACK* SPUstartChannels1)(unsigned short); +typedef void (CALLBACK* SPUstartChannels2)(unsigned short); +typedef void (CALLBACK* SPUstopChannels1)(unsigned short); +typedef void (CALLBACK* SPUstopChannels2)(unsigned short); +typedef void (CALLBACK* SPUputOne)(unsigned long,unsigned short); +typedef unsigned short (CALLBACK* SPUgetOne)(unsigned long); +typedef void (CALLBACK* SPUsetAddr)(unsigned char, unsigned short); +typedef void (CALLBACK* SPUsetPitch)(unsigned char, unsigned short); +typedef void (CALLBACK* SPUsetVolumeL)(unsigned char, short ); +typedef void (CALLBACK* SPUsetVolumeR)(unsigned char, short ); +//psemu pro 2 functions from now.. +typedef void (CALLBACK* SPUwriteRegister)(unsigned long, unsigned short); +typedef unsigned short (CALLBACK* SPUreadRegister)(unsigned long); +typedef void (CALLBACK* SPUwriteDMA)(unsigned short); +typedef unsigned short (CALLBACK* SPUreadDMA)(void); +typedef void (CALLBACK* SPUwriteDMAMem)(unsigned short *, int); +typedef void (CALLBACK* SPUreadDMAMem)(unsigned short *, int); +typedef void (CALLBACK* SPUplayADPCMchannel)(xa_decode_t *); +typedef void (CALLBACK* SPUregisterCallback)(void (CALLBACK *callback)(void)); +typedef long (CALLBACK* SPUconfigure)(void); +typedef long (CALLBACK* SPUtest)(void); +typedef void (CALLBACK* SPUabout)(void); +typedef struct { + unsigned char PluginName[8]; + unsigned long PluginVersion; + unsigned long Size; + unsigned char SPUPorts[0x200]; + unsigned char SPURam[0x80000]; + xa_decode_t xa; + unsigned char *SPUInfo; +} SPUFreeze_t; +typedef long (CALLBACK* SPUfreeze)(unsigned long, SPUFreeze_t *); +typedef void (CALLBACK* SPUupdate)(void); +typedef void (CALLBACK* SPUasync)(unsigned long); + +//SPU POINTERS +SPUconfigure SPU_configure; +SPUabout SPU_about; +SPUinit SPU_init; +SPUshutdown SPU_shutdown; +SPUtest SPU_test; +SPUopen SPU_open; +SPUclose SPU_close; +SPUplaySample SPU_playSample; +SPUstartChannels1 SPU_startChannels1; +SPUstartChannels2 SPU_startChannels2; +SPUstopChannels1 SPU_stopChannels1; +SPUstopChannels2 SPU_stopChannels2; +SPUputOne SPU_putOne; +SPUgetOne SPU_getOne; +SPUsetAddr SPU_setAddr; +SPUsetPitch SPU_setPitch; +SPUsetVolumeL SPU_setVolumeL; +SPUsetVolumeR SPU_setVolumeR; +SPUwriteRegister SPU_writeRegister; +SPUreadRegister SPU_readRegister; +SPUwriteDMA SPU_writeDMA; +SPUreadDMA SPU_readDMA; +SPUwriteDMAMem SPU_writeDMAMem; +SPUreadDMAMem SPU_readDMAMem; +SPUplayADPCMchannel SPU_playADPCMchannel; +SPUfreeze SPU_freeze; +SPUregisterCallback SPU_registerCallback; +SPUupdate SPU_update; +SPUasync SPU_async; + +// PAD Functions + +typedef long (CALLBACK* PADconfigure)(void); +typedef void (CALLBACK* PADabout)(void); +typedef long (CALLBACK* PADinit)(long); +typedef long (CALLBACK* PADshutdown)(void); +typedef long (CALLBACK* PADtest)(void); +typedef long (CALLBACK* PADclose)(void); +typedef long (CALLBACK* PADquery)(void); +typedef long (CALLBACK* PADreadPort1)(PadDataS*); +typedef long (CALLBACK* PADreadPort2)(PadDataS*); +typedef long (CALLBACK* PADkeypressed)(void); +typedef unsigned char (CALLBACK* PADstartPoll)(int); +typedef unsigned char (CALLBACK* PADpoll)(unsigned char); + +//PAD POINTERS +PADconfigure PAD1_configure; +PADabout PAD1_about; +PADinit PAD1_init; +PADshutdown PAD1_shutdown; +PADtest PAD1_test; +PADopen PAD1_open; +PADclose PAD1_close; +PADquery PAD1_query; +PADreadPort1 PAD1_readPort1; +PADkeypressed PAD1_keypressed; +PADstartPoll PAD1_startPoll; +PADpoll PAD1_poll; + +PADconfigure PAD2_configure; +PADabout PAD2_about; +PADinit PAD2_init; +PADshutdown PAD2_shutdown; +PADtest PAD2_test; +PADopen PAD2_open; +PADclose PAD2_close; +PADquery PAD2_query; +PADreadPort2 PAD2_readPort2; +PADkeypressed PAD2_keypressed; +PADstartPoll PAD2_startPoll; +PADpoll PAD2_poll; + +int LoadCDRplugin(char *CDRdll); +int LoadGPUplugin(char *GPUdll); +int LoadSPUplugin(char *SPUdll); +int LoadPAD1plugin(char *PAD1dll); +int LoadPAD2plugin(char *PAD2dll); + +#endif /* __PLUGINS_H__ */ diff --git a/ToD/ExtracteurIdiot.cpp b/ToD/ExtracteurIdiot.cpp index 8825d97..fde5134 100644 --- a/ToD/ExtracteurIdiot.cpp +++ b/ToD/ExtracteurIdiot.cpp @@ -1,96 +1,96 @@ -#include -#include -#include -#include - -using namespace std; - -int main(int, char **) -{ - int iPosPointeur, iPosTexte; - char szPath[2][256]; - vector 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 << "\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 << ""; - break; - case 0x02: - ofTexte << "<02>"; - break; - case 0x03: - ofTexte << "<03>"; - break; - case 0x04: - switch (vFichier[++j]) - { - case 0x02: - ofTexte << ""; - break; - case 0x04: - ofTexte << ""; - break; - case 0x05: - ofTexte << ""; - break; - case 0x06: - ofTexte << ""; - break; - case 0x0F: - ofText << ""; - break; - default: - ofTexte << setw(2) << << setfill('0') << hex << vFichier[j]; - } - break; - case 0x05: - ofTexte << "<05>"; - break; - case 0x06: - ofTexte << "<06>"; - break; - case 0x0c: - ofTexte << "\n"; - break; - case 0x0a: - ofTexte.put('\n'); - break; - default: - ofTexte.put(vFichier[j]); - } - - ofTexte << "\n\n"; - } - - return 0; +#include +#include +#include +#include + +using namespace std; + +int main(int, char **) +{ + int iPosPointeur, iPosTexte; + char szPath[2][256]; + vector 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 << "\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 << ""; + break; + case 0x02: + ofTexte << "<02>"; + break; + case 0x03: + ofTexte << "<03>"; + break; + case 0x04: + switch (vFichier[++j]) + { + case 0x02: + ofTexte << ""; + break; + case 0x04: + ofTexte << ""; + break; + case 0x05: + ofTexte << ""; + break; + case 0x06: + ofTexte << ""; + break; + case 0x0F: + ofText << ""; + break; + default: + ofTexte << setw(2) << << setfill('0') << hex << vFichier[j]; + } + break; + case 0x05: + ofTexte << "<05>"; + break; + case 0x06: + ofTexte << "<06>"; + break; + case 0x0c: + ofTexte << "\n"; + break; + case 0x0a: + ofTexte.put('\n'); + break; + default: + ofTexte.put(vFichier[j]); + } + + ofTexte << "\n\n"; + } + + return 0; } \ No newline at end of file diff --git a/ToD/c_dumper.cpp b/ToD/c_dumper.cpp index 669a564..edbd8df 100644 --- a/ToD/c_dumper.cpp +++ b/ToD/c_dumper.cpp @@ -1,140 +1,140 @@ -#include -#include -#include -#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 +#include +#include +#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 f8af1ea..8c7c5f1 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 -#include -#include -#include -#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 \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 +#include +#include +#include +#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 \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 a3ff9a1..076d3bd 100644 --- a/VP/decomp-slz.cpp +++ b/VP/decomp-slz.cpp @@ -1,63 +1,63 @@ -#include -#include - -#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 +#include + +#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 5add9b3..9fa4dfa 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 -#include -#include -#include -#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 \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 +#include +#include +#include +#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 \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 d68149f..ebbf214 100644 --- a/VP/search-script.cpp +++ b/VP/search-script.cpp @@ -1,73 +1,73 @@ -#include -#include -#include -#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 \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 +#include +#include +#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 \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 1584041..36a258a 100644 --- a/VP/unarc.cpp +++ b/VP/unarc.cpp @@ -1,79 +1,79 @@ -#include -#include -#include - -#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 \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 +#include +#include + +#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 \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 7cdb1aa..0683078 100644 --- a/Xenogears/Decrypt.cpp +++ b/Xenogears/Decrypt.cpp @@ -1,513 +1,513 @@ -#include -#include -#include -#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, "\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) // "" - { - break; - } else if (val == 0x01) // "\n" - { - fprintf(f_cible, "\n"); - } else if (val == 0x02) // "" - { - fprintf(f_cible, "\n"); - } else if (val == 0x03) // "" - { - fprintf(f_cible, ""); - } 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, "", temp2); - } else if (temp1 == 5) { - switch (temp2) { - case 0: - fprintf(f_cible, ""); - break; - case 1: - fprintf(f_cible, ""); - break; - case 2: - fprintf(f_cible, ""); - break; - case 3: - fprintf(f_cible, ""); - break; - case 4: - fprintf(f_cible, ""); - break; - case 5: - fprintf(f_cible, ""); - break; - case 6: - fprintf(f_cible, ""); - break; - case 7: - fprintf(f_cible, ""); - break; - case 8: - fprintf(f_cible, ""); - break; - case 9: - fprintf(f_cible, ""); - break; - case 10: - fprintf(f_cible, ""); - break; - case 11: - fprintf(f_cible, ""); - break; - case 12: - fprintf(f_cible, ""); - break; - case 13: - fprintf(f_cible, ""); - break; - case 14: - fprintf(f_cible, ""); - break; - case 15: - fprintf(f_cible, ""); - break; - case 16: - fprintf(f_cible, ""); - break; - case 17: - fprintf(f_cible, ""); - break; - case 18: - fprintf(f_cible, ""); - break; - case 19: - fprintf(f_cible, ""); - break; - case 20: - fprintf(f_cible, ""); - break; - case 21: - fprintf(f_cible, ""); - break; - case 22: - fprintf(f_cible, ""); - break; - case 23: - fprintf(f_cible, ""); - break; - case 24: - fprintf(f_cible, ""); - break; - case 25: - fprintf(f_cible, ""); - break; - case 26: - fprintf(f_cible, ""); - break; - case 27: - fprintf(f_cible, ""); - break; - case 28: - fprintf(f_cible, ""); - break; - case 128: - fprintf(f_cible, ""); - break; - case 129: - fprintf(f_cible, ""); - break; - case 130: - fprintf(f_cible, ""); - break; - default: - fprintf(f_cible, "", temp2); - } - } else { - fprintf(f_cible, "", 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) // "" - { - fprintf(f_cible, ""); - } else if (val == 0x6F) // "" - { - fprintf(f_cible, ""); - } else if (val == 0x70) // "" - { - fprintf(f_cible, ""); - } else if (val == 0x71) // "<*>" - { - fprintf(f_cible, "<*>"); - } else if (val == 0x72) // "" - { - fprintf(f_cible, ""); - } else if (val == 0x73) // "" - { - fprintf(f_cible, ""); - } else if (val == 0x74) // "" - { - fprintf(f_cible, ""); - } else if (val == 0x75) // "" - { - fprintf(f_cible, ""); - } 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) // "" - { - fprintf(f_cible, ""); - } 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) // " - { - fread((unsigned char *) &temp1, 1, 1, f_source); - fprintf(f_cible, "", temp1); - } else if (val == 0xFF) // " - { - fread((unsigned char *) &temp1, 1, 1, f_source); - fprintf(f_cible, "", temp1); - } else { - fprintf(f_cible, "", val); - } - - position = ftell(f_source); - } - fprintf(f_cible, "\n\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, "\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 +#include +#include +#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, "\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) // "" + { + break; + } else if (val == 0x01) // "\n" + { + fprintf(f_cible, "\n"); + } else if (val == 0x02) // "" + { + fprintf(f_cible, "\n"); + } else if (val == 0x03) // "" + { + fprintf(f_cible, ""); + } 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, "", temp2); + } else if (temp1 == 5) { + switch (temp2) { + case 0: + fprintf(f_cible, ""); + break; + case 1: + fprintf(f_cible, ""); + break; + case 2: + fprintf(f_cible, ""); + break; + case 3: + fprintf(f_cible, ""); + break; + case 4: + fprintf(f_cible, ""); + break; + case 5: + fprintf(f_cible, ""); + break; + case 6: + fprintf(f_cible, ""); + break; + case 7: + fprintf(f_cible, ""); + break; + case 8: + fprintf(f_cible, ""); + break; + case 9: + fprintf(f_cible, ""); + break; + case 10: + fprintf(f_cible, ""); + break; + case 11: + fprintf(f_cible, ""); + break; + case 12: + fprintf(f_cible, ""); + break; + case 13: + fprintf(f_cible, ""); + break; + case 14: + fprintf(f_cible, ""); + break; + case 15: + fprintf(f_cible, ""); + break; + case 16: + fprintf(f_cible, ""); + break; + case 17: + fprintf(f_cible, ""); + break; + case 18: + fprintf(f_cible, ""); + break; + case 19: + fprintf(f_cible, ""); + break; + case 20: + fprintf(f_cible, ""); + break; + case 21: + fprintf(f_cible, ""); + break; + case 22: + fprintf(f_cible, ""); + break; + case 23: + fprintf(f_cible, ""); + break; + case 24: + fprintf(f_cible, ""); + break; + case 25: + fprintf(f_cible, ""); + break; + case 26: + fprintf(f_cible, ""); + break; + case 27: + fprintf(f_cible, ""); + break; + case 28: + fprintf(f_cible, ""); + break; + case 128: + fprintf(f_cible, ""); + break; + case 129: + fprintf(f_cible, ""); + break; + case 130: + fprintf(f_cible, ""); + break; + default: + fprintf(f_cible, "", temp2); + } + } else { + fprintf(f_cible, "", 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) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x6F) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x70) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x71) // "<*>" + { + fprintf(f_cible, "<*>"); + } else if (val == 0x72) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x73) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x74) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x75) // "" + { + fprintf(f_cible, ""); + } 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) // "" + { + fprintf(f_cible, ""); + } 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) // " + { + fread((unsigned char *) &temp1, 1, 1, f_source); + fprintf(f_cible, "", temp1); + } else if (val == 0xFF) // " + { + fread((unsigned char *) &temp1, 1, 1, f_source); + fprintf(f_cible, "", temp1); + } else { + fprintf(f_cible, "", val); + } + + position = ftell(f_source); + } + fprintf(f_cible, "\n\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, "\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 1edef8b..3f85437 100644 --- a/Xenogears/Translate.cpp +++ b/Xenogears/Translate.cpp @@ -1,256 +1,256 @@ -#include -#include - -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) // "" - { -// break; - fprintf(f_cible, "\n"); - } else if (val == 0x01) // "\n" - { - fprintf(f_cible, "\n"); - } else if (val == 0x02) // "" - { - fprintf(f_cible, "\n"); - } else if (val == 0x03) // "" - { - fprintf(f_cible, ""); - } else if (val == 0x0F) // " - { - fread((unsigned char *) &temp1, 1, 1, f_source); - fread((unsigned char *) &temp2, 1, 1, f_source); - if (temp1 == 0) { - fprintf(f_cible, "", temp2); - } else if (temp1 == 5) { - fprintf(f_cible, "", temp2); - } else { - fprintf(f_cible, "", 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) // "" - { - fprintf(f_cible, ""); - } else if (val == 0x6F) // "" - { - fprintf(f_cible, ""); - } else if (val == 0x70) // "" - { - fprintf(f_cible, ""); - } else if (val == 0x71) // "<*>" - { - fprintf(f_cible, "<*>"); - } else if (val == 0x72) // "" - { - fprintf(f_cible, ""); - } else if (val == 0x73) // "" - { - fprintf(f_cible, ""); - } else if (val == 0x74) // "" - { - fprintf(f_cible, ""); - } else if (val == 0x75) // "" - { - fprintf(f_cible, ""); - } 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) // "" - { - fprintf(f_cible, ""); - } 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) // " - { - fread((unsigned char *) &temp1, 1, 1, f_source); - fprintf(f_cible, "", temp1); - } else if (val == 0xFF) // " - { - fread((unsigned char *) &temp1, 1, 1, f_source); - fprintf(f_cible, "", temp1); - } else { - fprintf(f_cible, "", val); - } - } -} - -int main(void) { - dump_text(stdin, stdout); -} +#include +#include + +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) // "" + { +// break; + fprintf(f_cible, "\n"); + } else if (val == 0x01) // "\n" + { + fprintf(f_cible, "\n"); + } else if (val == 0x02) // "" + { + fprintf(f_cible, "\n"); + } else if (val == 0x03) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x0F) // " + { + fread((unsigned char *) &temp1, 1, 1, f_source); + fread((unsigned char *) &temp2, 1, 1, f_source); + if (temp1 == 0) { + fprintf(f_cible, "", temp2); + } else if (temp1 == 5) { + fprintf(f_cible, "", temp2); + } else { + fprintf(f_cible, "", 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) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x6F) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x70) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x71) // "<*>" + { + fprintf(f_cible, "<*>"); + } else if (val == 0x72) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x73) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x74) // "" + { + fprintf(f_cible, ""); + } else if (val == 0x75) // "" + { + fprintf(f_cible, ""); + } 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) // "" + { + fprintf(f_cible, ""); + } 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) // " + { + fread((unsigned char *) &temp1, 1, 1, f_source); + fprintf(f_cible, "", temp1); + } else if (val == 0xFF) // " + { + fread((unsigned char *) &temp1, 1, 1, f_source); + fprintf(f_cible, "", temp1); + } else { + fprintf(f_cible, "", val); + } + } +} + +int main(void) { + dump_text(stdin, stdout); +} diff --git a/Xenogears/archive.cpp b/Xenogears/archive.cpp index 286fa43..6701c2c 100644 --- a/Xenogears/archive.cpp +++ b/Xenogears/archive.cpp @@ -1,37 +1,37 @@ -#include -#include -#include -#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 +#include +#include +#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 1b1be62..6ab7835 100644 --- a/Xenogears/build-sector-2.cpp +++ b/Xenogears/build-sector-2.cpp @@ -1,14 +1,14 @@ -#include -#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 +#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 744a087..3effc35 100644 --- a/Xenogears/build-sector.cpp +++ b/Xenogears/build-sector.cpp @@ -1,14 +1,14 @@ -#include -#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 +#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 e2f5058..1610ec1 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 -#include -#include -#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 \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 +#include +#include +#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 \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 fb7460e..bf60cb4 100644 --- a/Xenogears/reinsert.cpp +++ b/Xenogears/reinsert.cpp @@ -1,290 +1,290 @@ -#include -#include -#include -#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 [-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 +#include +#include +#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 [-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 01f6bdd..4e835a7 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); - - printm(M_BARE, " Processing script\n"); - - 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->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 +#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(); + + 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->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 diff --git a/Xenogears/script-dec.cpp b/Xenogears/script-dec.cpp index 0285013..55edb31 100644 --- a/Xenogears/script-dec.cpp +++ b/Xenogears/script-dec.cpp @@ -1,82 +1,82 @@ -#include -#include -#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 +#include +#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 4591b9d..ecd0f7e 100644 --- a/Xenogears/test-dlzss.cpp +++ b/Xenogears/test-dlzss.cpp @@ -1,7 +1,7 @@ -#include -#include "lzss.h" - -int main(void) { - lzss_decomp(0, 1); - return 0; -} +#include +#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 b92808c..0257e99 100644 --- a/Xenogears/test-lzss.cpp +++ b/Xenogears/test-lzss.cpp @@ -1,7 +1,7 @@ -#include -#include "lzss.h" - -int main(void) { - lzss_comp(0, 1); - return 0; -} +#include +#include "lzss.h" + +int main(void) { + lzss_comp(0, 1); + return 0; +} diff --git a/bgrep.cpp b/bgrep.cpp index 82c62f9..b3ff324 100644 --- a/bgrep.cpp +++ b/bgrep.cpp @@ -1,34 +1,34 @@ -#include -#include -#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 +#include +#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 diff --git a/bin2c.cpp b/bin2c.cpp index 61f9618..69561a1 100644 --- a/bin2c.cpp +++ b/bin2c.cpp @@ -1,40 +1,40 @@ -#include -#include -#include - -CODE_BEGINS -virtual int startup() throw (GeneralException) { - int i; - - if (argc != 4) { - printm(M_BARE, "Usage: %s \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 +#include +#include + +CODE_BEGINS +virtual int startup() throw (GeneralException) { + int i; + + if (argc != 4) { + printm(M_BARE, "Usage: %s \n", argv[0]); + exit(-1); + } + + printm(M_BARE, "Starting converting %s to %s:\n", argv[1], argv[2]); + + Input binfile(argv[1]); + Output cfile(argv[2]); + + unsigned char * map = (unsigned char *) binfile.mmap(); + + cfile << "int " << argv[3] << "_size = " << binfile.GetSize() << ";\n"; + cfile << "unsigned char " << argv[3] << "[] = {"; + + for (i = 0; i < binfile.GetSize(); i++) { + String s; + + s.set("0x%02x, ", map[i]); + if (!(i % 16)) { + cfile << "\n\t"; + printm(M_BARE, "%5.2f%%\r", i * 100.0 / binfile.GetSize()); + } + cfile << s; + } + + cfile << "\n};\n"; + printm(M_BARE, "Done! \n"); + + return 0; +} +CODE_ENDS diff --git a/cd-tool.cpp b/cd-tool.cpp index f29b535..6065ed0 100644 --- a/cd-tool.cpp +++ b/cd-tool.cpp @@ -1,685 +1,685 @@ -/* - * 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: cd-tool.cpp,v 1.33 2004-11-27 21:01:20 pixel Exp $ */ - -#define WIP - -#define VERSION "0.5" - -#include -#include "Input.h" -#include "Output.h" -#include "Buffer.h" -#include "BLua.h" -#include "cdreader.h" -#include "cdutils.h" -#include "generic.h" -#include "Main.h" -#include "cdabstract.h" -#include "isobuilder.h" -#include "luacd.h" -#include "luapsx.h" -#include -#include - -#include "cd-tool-hc.h" - -#ifdef _WIN32 - -#include - -#include -#include -#include - -#define EXT_PREFIX 0x1f8 - -#define KEV irec.Event.KeyEvent /* to make life easier */ -#define KST irec.Event.KeyEvent.dwControlKeyState - - -static int pending_key = 0; -static int pending_count = 0; -static int pending_prefix = 0; - -extern int _rl_last_c_pos; /* imported from display.c */ -extern int _rl_last_v_pos; -extern int rl_dispatching; /* imported from readline.c */ -extern int rl_point; -extern int rl_done; -extern int rl_visible_prompt_length; - -extern "C" { -extern int haveConsole; /* imported from rltty.c */ -extern HANDLE hStdout, hStdin; -} - -int my_getc (FILE * stream) -{ - int key; - - if ( pending_count ) - { - --pending_count; - if ( pending_prefix && (pending_count & 1) ) - return pending_prefix; - else - return pending_key; - } - - while ( 1 ) - { - DWORD dummy; - - if (WaitForSingleObject(hStdin, WAIT_FOR_INPUT) != WAIT_OBJECT_0) - { - if ( rl_done ) - return( 0 ); - else - continue; - } - if ( haveConsole & FOR_INPUT ) - { - INPUT_RECORD irec; - ReadConsoleInput(hStdin, &irec, 1, &dummy); - switch(irec.EventType) - { - case KEY_EVENT: - if ( KEV.bKeyDown - && ((KEV.wVirtualKeyCode < VK_SHIFT) || (KEV.wVirtualKeyCode > VK_MENU)) ) - { - int mask = 0; - - key = KEV.uChar.AsciiChar & 0xff; -// if ( KST & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED) ) -// mask=0x100; - if ( key ) - { - /* Ascii direct */ - pending_count = KEV.wRepeatCount - 1; - pending_key = key; - pending_prefix = 0; - if ( mask ) - key = tolower(key) | mask; - } - else - /* Others prefixed */ - { - key = EXT_PREFIX; - if ( mask ) - key |= 4; - if (KST & SHIFT_PRESSED) - key |= 1; - if (KST & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) - key |= 2; - mask |= EXT_PREFIX; - pending_count = (KEV.wRepeatCount << 1) - 1; - pending_key = KEV.wVirtualKeyCode; - pending_prefix = key; - } - return key; - } - break; - default: - break; - } - } - else - { - ReadFile(hStdin, &key, 1, &dummy, NULL); - return key; - } - } -} -#endif - -bool interactive = false; -cdutils * cdutil = 0; -isobuilder * build = 0; - -static int myprint(lua_State * _L) { - Lua * L = Lua::find(_L); - String t = "From LUA: " + L->tostring() + "\n"; - char * tc = t.strdup(); - - Base::printm(M_STATUS, "%s", tc); - - free(tc); - - return 0; -} - -class Luabasecdtool : public LuaObject { - public: - static void pushstatics(Lua *) throw (GeneralException); -}; - -typedef void basecdtool; - -enum basecdtool_t { - BASECDTOOL_LOAD = 0, -}; - -struct lua_functypes_t basecdtool_functions[] = { - { BASECDTOOL_LOAD, "load", 0, 1, { LUA_STRING | LUA_OBJECT } }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_basecdtool : public Base { - public: - DECLARE_FUNCTION(basecdtool, BASECDTOOL_LOAD); - private: - static int basecdtool_proceed_statics(Lua * L, int n, int caller); -}; - -void Luabasecdtool::pushstatics(Lua * L) throw (GeneralException ) { - CHECK_FUNCTIONS(basecdtool); - - PUSH_FUNCTION(basecdtool, BASECDTOOL_LOAD); -} - -int sLua_basecdtool::basecdtool_proceed_statics(Lua * L, int n, int caller) { - int r = 0; - - switch (caller) { - case BASECDTOOL_LOAD: - if (!n) { - L->load(&Input("cd-tool.lua")); - } else { - if (L->isstring(1)) { - L->load(&Input(L->tostring(1))); - } else { - Handle * t = (Handle *) LuaObject::getme(L, 1); - L->load(t); - } - } - } - - return r; -} - -class Luacdtool : public LuaObject { - public: - static void pushstatics(Lua *) throw (GeneralException); -}; - -typedef void cdtool; - -enum cdtool_functions_t { - CDTOOL_PRINT = 0, - CDTOOL_PRINTN, - CDTOOL_QUIT, - CDTOOL_EXIT, - CDTOOL_INFOS, - CDTOOL_PATH, - CDTOOL_PRINTDIR, -}; - -struct lua_functypes_t cdtool_functions[] = { - { CDTOOL_PRINT, "print", 0, 1, { LUA_ANY } }, - { CDTOOL_PRINTN, "printn", 1, 1, { LUA_ANY } }, - { CDTOOL_QUIT, "quit", 0, 0, 0 }, - { CDTOOL_EXIT, "exit", 0, 0, 0 }, - { CDTOOL_INFOS, "infos", 0, 1, { LUA_OBJECT } }, - { CDTOOL_PATH, "path", 0, 1, { LUA_OBJECT } }, - { CDTOOL_PRINTDIR, "printdir", 1, 2, { LUA_STRING, LUA_OBJECT } }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_cdtool : public Base { - public: - DECLARE_FUNCTION(cdtool, CDTOOL_PRINT); - DECLARE_FUNCTION(cdtool, CDTOOL_PRINTN); - DECLARE_FUNCTION(cdtool, CDTOOL_QUIT); - DECLARE_FUNCTION(cdtool, CDTOOL_EXIT); - DECLARE_FUNCTION(cdtool, CDTOOL_INFOS); - DECLARE_FUNCTION(cdtool, CDTOOL_PATH); - DECLARE_FUNCTION(cdtool, CDTOOL_PRINTDIR); - private: - static int cdtool_proceed_statics(Lua * L, int n, int caller); -}; - -void Luacdtool::pushstatics(Lua * L) throw (GeneralException ) { - CHECK_FUNCTIONS(cdtool); - - PUSH_FUNCTION(cdtool, CDTOOL_PRINT); - PUSH_FUNCTION(cdtool, CDTOOL_PRINTN); - PUSH_FUNCTION(cdtool, CDTOOL_QUIT); - PUSH_FUNCTION(cdtool, CDTOOL_EXIT); - PUSH_FUNCTION(cdtool, CDTOOL_INFOS); - PUSH_FUNCTION(cdtool, CDTOOL_PATH); - PUSH_FUNCTION(cdtool, CDTOOL_PRINTDIR); -} - -int sLua_cdtool::cdtool_proceed_statics(Lua * L, int n, int caller) { - int r = 0; - String p; - cdutils * cd = cdutil; - char * tc; - String eol = ""; - - switch (caller) { - case CDTOOL_PRINT: - eol = "\n"; - case CDTOOL_PRINTN: - if (n) - p = L->tostring(1) + eol; - else - p = eol; - tc = p.strdup(); - printm(M_BARE, "%s", tc); - free(tc); - break; - case CDTOOL_QUIT: - case CDTOOL_EXIT: - interactive = false; - break; - case CDTOOL_INFOS: - if (n) - cd = (cdutils *) LuaObject::getme(L, 1); - if (cd) - cd->show_iso_infos(); - else - L->error("Cdutils object void"); - break; - case CDTOOL_PATH: - if (n) - cd = (cdutils *) LuaObject::getme(L, 1); - if (cd) - cd->show_pt_infos(); - else - L->error("Cdutils object void"); - break; - case CDTOOL_PRINTDIR: - p = L->tostring(1); - if (n == 2) - cd = (cdutils *) LuaObject::getme(L, 2); - if (cd) { - char * f; - cdutils::DirEntry dir = cd->find_path(f = p.strdup()); - free(f); - if (!dir.R) - L->error("Path `" + p + "' not found"); - if (!(dir.Flags & 2)) - L->error("Path `" + p + "' points to a file"); - cd->show_head_entry(); - cd->show_dir(&dir); - } else - L->error("Cdutils object void"); - break; - } - - return r; -} - -int lga = 0; -struct option long_options[] = { - {"help", 0, NULL, 'h'}, - {"verbose", 0, NULL, 'v'}, - {"file", 1, NULL, 'f'}, - {"write", 0, NULL, 'w'}, - {"output", 1, NULL, 'o'}, - {"archive", 1, NULL, 'a'}, - {"compile", 1, NULL, 'c'}, - {"debug", 0, NULL, 'd'}, - {"interactive", 0, NULL, 'i'}, - {"line", 0, NULL, 'l'}, - {"exec", 1, NULL, 'e'}, - {"built-in", 0, NULL, 'b'}, - {"probe", 0, NULL, 'p'}, - {0, 0, NULL, 0 } -}; - -CODE_BEGINS - -/* That's the basic lua starter for non interactive mode */ -Lua * start_basic_lua(void) { - Lua * L = new Lua(); - - L->open_base(); - L->open_math(); - L->open_string(); - L->open_table(); - L->open_dir(); - - LuaInput::pushconstruct(L); - LuaOutput::pushconstruct(L); - LuaBuffer::pushconstruct(L); - - CD_PUSHSTATICS(L); - - Luapsx::pushstatics(L); - - L->push("print"); - L->push(myprint); - L->setvar(); - - Luabasecdtool::pushstatics(L); - - return L; -} - -/* That's the extended stuff for interactive mode */ -Lua * start_full_lua(void) { - Lua * L = start_basic_lua(); - - Luacdtool::pushstatics(L); - - return L; -} - -void showbanner() { - printm(M_BARE, -"CD-Tool version " VERSION " (c) 2003-2004 Nicolas \"Pixel\" Noble\n" -#ifdef WIP -"Special version Work In Progress, compiled the " __DATE__ " at " __TIME__ "\n" -#endif -"This is free software with ABSOLUTELY NO WARRANTY.\n" -"\n"); -} - -void showhelp(bool longhelp = false) { - printm(M_BARE, -"Usage:\n" -"%s [options] [lua-script1] [lua-script2] ...\n" -"\n" -"Options:\n" -" -v for verbose mode.\n" -" -f to load an initial iso file (object cdutil).\n" -" -w to open the previous iso file in write mode.\n" -" -o to start creating an output iso (object iso).\n" -" -a to load an additionnal archive file.\n" -" -c to dump the compiled byte code to file.\n" -" -d to enable debug mode (ie, do not strip)\n" -" -i to start interactive mode.\n" -" -l to turn off the exec on end line.\n" -" -e to execute this single command in LUA.\n" -" -b to force the use of the built-in cd-tool.lua\n" -" -p to run a CD device probe.\n" -" -h for a help page.\n" -, argv[0]); - - if (longhelp) - printm(M_BARE, -"\n" -"Verbose mode can be somewhat a floody thing.\n" -"Options -i/-e and -c are mutually exclusive.\n" -"Options -i and -e are NOT mutually exclusive. For example:\n" -"\n" -" $ %s -i -e \"main()\" somescript.lua\n" -"\n" -"This will first load the script 'somescript.lua', then execute main, and\n" -"afterward, start the interactive mode.\n" -"\n" -"If a script contains inlined code, it will be run right after loading.\n" -, argv[0]); -} - -void probe(void) { - std::vector p; - - if (!cdabstract::canprobe()) { - printm(M_ERROR, "Can't probe on this platform.\n"); - exit(-1); - } - - p = cdabstract::probe(); - - printm(M_BARE, "Alvaible devices:\n"); - for (std::vector::iterator i = p.begin(); i != p.end(); i++) { - printm(M_BARE, *i + "\n"); - } -} - -virtual int startup() throw (GeneralException) { - char c; - - bool auto_exec = true, strip = true, todo = false, runit, write = false, builtin = false; - char * file = 0, * output = 0, * compile = 0, * exec = 0, * line_read = 0; - char prompt[10]; - Lua * L = 0; - Handle * read_iso = 0; - Output * build_iso = 0, * write_iso = 0; - Buffer command; - String line, endline; - int pos; - - verbosity = M_WARNING; - - showbanner(); - - /* Let's start parsing options */ - - while ((c = getopt_long(argc, argv, "Hhvf:wo:a:c:dile:pb", long_options, NULL)) != EOF) { - switch (c) { - case 'h': - case 'H': - case '?': - showhelp(true); - throw Exit(0); - case 'v': - verbosity = M_INFO; - break; - case 'f': - file = strdup(optarg); - break; - case 'w': - write = true; - break; - case 'o': - output = strdup(optarg); - break; - case 'a': - new Archive(optarg); - break; - case 'c': - compile = strdup(optarg); - break; - case 'd': - strip = false; - break; - case 'i': - interactive = true; - todo = true; - break; - case 'l': - auto_exec = false; - break; - case 'e': - exec = strdup(optarg); - todo = true; - break; - case 'p': - probe(); - throw Exit(0); - case 'b': - builtin = true; - break; - default: - showhelp(); - throw Exit(-1); - } - } - - if (interactive) - L = start_full_lua(); - else - L = start_basic_lua(); - - /* Loading cd-tool.lua (only when not compiling) */ - if (!compile && !builtin) { - try { - L->load(&Input("cd-tool.lua")); - } - catch (GeneralException e) { - printm(M_WARNING, "There was an error loading cd-tool.lua, using built-in: %s\n", e.GetMsg()); - builtin = true; - } - } - - if (!compile && builtin) { - Buffer built; - int i; - - for (i = 0; i < cd_tool_lua_size; i++) { - built.writeU8(cd_tool_lua[i]); - } - try { - L->load(&built); - } - catch (GeneralException e) { - printm(M_WARNING, "There was an error loading built-in cd-tool.lua: %s\n", e.GetMsg()); - builtin = true; - } - } - - /* Loading all the scripts */ - while (optind < argc) { - todo = true; - L->load(&Input(argv[optind++]), !compile); - } - - /* Doh... */ - if (!todo) { - showhelp(); - throw Exit(0); - } - - /* Compilation process will exit from itself right after */ - if (compile) { - L->dump(&Output(compile), strip); - throw Exit(0); - } - - /* The basic input (and eventually output) iso file */ - if (file) { - /* The write mode can't apply on a CD of course... */ - if (write) { - read_iso = new Input(file); - write_iso = new Output(file, 0, 0); - } else { - read_iso = cdabstract::open_cd(file); - } - cdutil = new cdutils(read_iso, write_iso); - if (!cdutil->get_iso_infos()) - throw Exit(-1); - Luacdutils lcdutil(cdutil); - L->push("cdutil"); - lcdutil.push(L); - L->setvar(); - } - - /* The generated iso file */ - if (output) { - build_iso = new Output(output); - build = new isobuilder(build_iso); - Luaisobuilder lbuild(build); - L->push("iso"); - lbuild.push(L); - L->setvar(); - } - - /* One shot command */ - if (exec) { - command << exec; - L->load(&command); - } - - /* Interactive mode loop */ - strcpy(prompt, "> "); -#ifdef _WIN32 - rl_getc_function = my_getc; -#endif - rl_bind_key('\t', rl_insert); - while (interactive) { - /* Basic usage of readline */ - if (line_read) - free(line_read); - - line_read = readline(prompt); - - if (!line_read) { - printm(M_BARE, "\n"); - break; - } - - if (*line_read) - add_history(line_read); - - line = line_read; - line = line.trim(); - endline = ""; - - /* Splitting the line between ;; */ - while (line.strlen()) { - runit = false; - - if ((pos = line.strstr(";;")) >= 0) { - endline = line.extract(pos + 2); - line = line.extract(0, pos); - runit = true; - } else { - endline = ""; - } - - if (line[line.strlen() - 1] == '\\') { - line[line.strlen() - 1] = ' '; - } else if (auto_exec) { - runit = true; - } - - command << line; - - if (runit) { - try { - L->load(&command); - } - 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()); - } - strcpy(prompt, "> "); - } else { - strcpy(prompt, "- "); - } - line = endline.trim(); - }; - } - - /* Finishing off the work, cleaning out the dust */ - if (output) { - delete build; - delete build_iso; - } - - if (file) { - delete cdutil; - } - - return 0; -} -CODE_ENDS +/* + * 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: cd-tool.cpp,v 1.34 2004-11-27 21:47:22 pixel Exp $ */ + +#define WIP + +#define VERSION "0.5" + +#include +#include "Input.h" +#include "Output.h" +#include "Buffer.h" +#include "BLua.h" +#include "cdreader.h" +#include "cdutils.h" +#include "generic.h" +#include "Main.h" +#include "cdabstract.h" +#include "isobuilder.h" +#include "luacd.h" +#include "luapsx.h" +#include +#include + +#include "cd-tool-hc.h" + +#ifdef _WIN32 + +#include + +#include +#include +#include + +#define EXT_PREFIX 0x1f8 + +#define KEV irec.Event.KeyEvent /* to make life easier */ +#define KST irec.Event.KeyEvent.dwControlKeyState + + +static int pending_key = 0; +static int pending_count = 0; +static int pending_prefix = 0; + +extern int _rl_last_c_pos; /* imported from display.c */ +extern int _rl_last_v_pos; +extern int rl_dispatching; /* imported from readline.c */ +extern int rl_point; +extern int rl_done; +extern int rl_visible_prompt_length; + +extern "C" { +extern int haveConsole; /* imported from rltty.c */ +extern HANDLE hStdout, hStdin; +} + +int my_getc (FILE * stream) +{ + int key; + + if ( pending_count ) + { + --pending_count; + if ( pending_prefix && (pending_count & 1) ) + return pending_prefix; + else + return pending_key; + } + + while ( 1 ) + { + DWORD dummy; + + if (WaitForSingleObject(hStdin, WAIT_FOR_INPUT) != WAIT_OBJECT_0) + { + if ( rl_done ) + return( 0 ); + else + continue; + } + if ( haveConsole & FOR_INPUT ) + { + INPUT_RECORD irec; + ReadConsoleInput(hStdin, &irec, 1, &dummy); + switch(irec.EventType) + { + case KEY_EVENT: + if ( KEV.bKeyDown + && ((KEV.wVirtualKeyCode < VK_SHIFT) || (KEV.wVirtualKeyCode > VK_MENU)) ) + { + int mask = 0; + + key = KEV.uChar.AsciiChar & 0xff; +// if ( KST & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED) ) +// mask=0x100; + if ( key ) + { + /* Ascii direct */ + pending_count = KEV.wRepeatCount - 1; + pending_key = key; + pending_prefix = 0; + if ( mask ) + key = tolower(key) | mask; + } + else + /* Others prefixed */ + { + key = EXT_PREFIX; + if ( mask ) + key |= 4; + if (KST & SHIFT_PRESSED) + key |= 1; + if (KST & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) + key |= 2; + mask |= EXT_PREFIX; + pending_count = (KEV.wRepeatCount << 1) - 1; + pending_key = KEV.wVirtualKeyCode; + pending_prefix = key; + } + return key; + } + break; + default: + break; + } + } + else + { + ReadFile(hStdin, &key, 1, &dummy, NULL); + return key; + } + } +} +#endif + +bool interactive = false; +cdutils * cdutil = 0; +isobuilder * build = 0; + +static int myprint(lua_State * _L) { + Lua * L = Lua::find(_L); + String t = "From LUA: " + L->tostring() + "\n"; + char * tc = t.strdup(); + + Base::printm(M_STATUS, "%s", tc); + + free(tc); + + return 0; +} + +class Luabasecdtool : public LuaObject { + public: + static void pushstatics(Lua *) throw (GeneralException); +}; + +typedef void basecdtool; + +enum basecdtool_t { + BASECDTOOL_LOAD = 0, +}; + +struct lua_functypes_t basecdtool_functions[] = { + { BASECDTOOL_LOAD, "load", 0, 1, { LUA_STRING | LUA_OBJECT } }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_basecdtool : public Base { + public: + DECLARE_FUNCTION(basecdtool, BASECDTOOL_LOAD); + private: + static int basecdtool_proceed_statics(Lua * L, int n, int caller); +}; + +void Luabasecdtool::pushstatics(Lua * L) throw (GeneralException ) { + CHECK_FUNCTIONS(basecdtool); + + PUSH_FUNCTION(basecdtool, BASECDTOOL_LOAD); +} + +int sLua_basecdtool::basecdtool_proceed_statics(Lua * L, int n, int caller) { + int r = 0; + + switch (caller) { + case BASECDTOOL_LOAD: + if (!n) { + L->load(&Input("cd-tool.lua")); + } else { + if (L->isstring(1)) { + L->load(&Input(L->tostring(1))); + } else { + Handle * t = (Handle *) LuaObject::getme(L, 1); + L->load(t); + } + } + } + + return r; +} + +class Luacdtool : public LuaObject { + public: + static void pushstatics(Lua *) throw (GeneralException); +}; + +typedef void cdtool; + +enum cdtool_functions_t { + CDTOOL_PRINT = 0, + CDTOOL_PRINTN, + CDTOOL_QUIT, + CDTOOL_EXIT, + CDTOOL_INFOS, + CDTOOL_PATH, + CDTOOL_PRINTDIR, +}; + +struct lua_functypes_t cdtool_functions[] = { + { CDTOOL_PRINT, "print", 0, 1, { LUA_ANY } }, + { CDTOOL_PRINTN, "printn", 1, 1, { LUA_ANY } }, + { CDTOOL_QUIT, "quit", 0, 0, 0 }, + { CDTOOL_EXIT, "exit", 0, 0, 0 }, + { CDTOOL_INFOS, "infos", 0, 1, { LUA_OBJECT } }, + { CDTOOL_PATH, "path", 0, 1, { LUA_OBJECT } }, + { CDTOOL_PRINTDIR, "printdir", 1, 2, { LUA_STRING, LUA_OBJECT } }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_cdtool : public Base { + public: + DECLARE_FUNCTION(cdtool, CDTOOL_PRINT); + DECLARE_FUNCTION(cdtool, CDTOOL_PRINTN); + DECLARE_FUNCTION(cdtool, CDTOOL_QUIT); + DECLARE_FUNCTION(cdtool, CDTOOL_EXIT); + DECLARE_FUNCTION(cdtool, CDTOOL_INFOS); + DECLARE_FUNCTION(cdtool, CDTOOL_PATH); + DECLARE_FUNCTION(cdtool, CDTOOL_PRINTDIR); + private: + static int cdtool_proceed_statics(Lua * L, int n, int caller); +}; + +void Luacdtool::pushstatics(Lua * L) throw (GeneralException ) { + CHECK_FUNCTIONS(cdtool); + + PUSH_FUNCTION(cdtool, CDTOOL_PRINT); + PUSH_FUNCTION(cdtool, CDTOOL_PRINTN); + PUSH_FUNCTION(cdtool, CDTOOL_QUIT); + PUSH_FUNCTION(cdtool, CDTOOL_EXIT); + PUSH_FUNCTION(cdtool, CDTOOL_INFOS); + PUSH_FUNCTION(cdtool, CDTOOL_PATH); + PUSH_FUNCTION(cdtool, CDTOOL_PRINTDIR); +} + +int sLua_cdtool::cdtool_proceed_statics(Lua * L, int n, int caller) { + int r = 0; + String p; + cdutils * cd = cdutil; + char * tc; + String eol = ""; + + switch (caller) { + case CDTOOL_PRINT: + eol = "\n"; + case CDTOOL_PRINTN: + if (n) + p = L->tostring(1) + eol; + else + p = eol; + tc = p.strdup(); + printm(M_BARE, "%s", tc); + free(tc); + break; + case CDTOOL_QUIT: + case CDTOOL_EXIT: + interactive = false; + break; + case CDTOOL_INFOS: + if (n) + cd = (cdutils *) LuaObject::getme(L, 1); + if (cd) + cd->show_iso_infos(); + else + L->error("Cdutils object void"); + break; + case CDTOOL_PATH: + if (n) + cd = (cdutils *) LuaObject::getme(L, 1); + if (cd) + cd->show_pt_infos(); + else + L->error("Cdutils object void"); + break; + case CDTOOL_PRINTDIR: + p = L->tostring(1); + if (n == 2) + cd = (cdutils *) LuaObject::getme(L, 2); + if (cd) { + char * f; + cdutils::DirEntry dir = cd->find_path(f = p.strdup()); + free(f); + if (!dir.R) + L->error("Path `" + p + "' not found"); + if (!(dir.Flags & 2)) + L->error("Path `" + p + "' points to a file"); + cd->show_head_entry(); + cd->show_dir(&dir); + } else + L->error("Cdutils object void"); + break; + } + + return r; +} + +int lga = 0; +struct option long_options[] = { + {"help", 0, NULL, 'h'}, + {"verbose", 0, NULL, 'v'}, + {"file", 1, NULL, 'f'}, + {"write", 0, NULL, 'w'}, + {"output", 1, NULL, 'o'}, + {"archive", 1, NULL, 'a'}, + {"compile", 1, NULL, 'c'}, + {"debug", 0, NULL, 'd'}, + {"interactive", 0, NULL, 'i'}, + {"line", 0, NULL, 'l'}, + {"exec", 1, NULL, 'e'}, + {"built-in", 0, NULL, 'b'}, + {"probe", 0, NULL, 'p'}, + {0, 0, NULL, 0 } +}; + +CODE_BEGINS + +/* That's the basic lua starter for non interactive mode */ +Lua * start_basic_lua(void) { + Lua * L = new Lua(); + + L->open_base(); + L->open_math(); + L->open_string(); + L->open_table(); + L->open_dir(); + + LuaInput::pushconstruct(L); + LuaOutput::pushconstruct(L); + LuaBuffer::pushconstruct(L); + + CD_PUSHSTATICS(L); + + Luapsx::pushstatics(L); + + L->push("print"); + L->push(myprint); + L->setvar(); + + Luabasecdtool::pushstatics(L); + + return L; +} + +/* That's the extended stuff for interactive mode */ +Lua * start_full_lua(void) { + Lua * L = start_basic_lua(); + + Luacdtool::pushstatics(L); + + return L; +} + +void showbanner() { + printm(M_BARE, +"CD-Tool version " VERSION " (c) 2003-2004 Nicolas \"Pixel\" Noble\n" +#ifdef WIP +"Special version Work In Progress, compiled the " __DATE__ " at " __TIME__ "\n" +#endif +"This is free software with ABSOLUTELY NO WARRANTY.\n" +"\n"); +} + +void showhelp(bool longhelp = false) { + printm(M_BARE, +"Usage:\n" +"%s [options] [lua-script1] [lua-script2] ...\n" +"\n" +"Options:\n" +" -v for verbose mode.\n" +" -f to load an initial iso file (object cdutil).\n" +" -w to open the previous iso file in write mode.\n" +" -o to start creating an output iso (object iso).\n" +" -a to load an additionnal archive file.\n" +" -c to dump the compiled byte code to file.\n" +" -d to enable debug mode (ie, do not strip)\n" +" -i to start interactive mode.\n" +" -l to turn off the exec on end line.\n" +" -e to execute this single command in LUA.\n" +" -b to force the use of the built-in cd-tool.lua\n" +" -p to run a CD device probe.\n" +" -h for a help page.\n" +, argv[0]); + + if (longhelp) + printm(M_BARE, +"\n" +"Verbose mode can be somewhat a floody thing.\n" +"Options -i/-e and -c are mutually exclusive.\n" +"Options -i and -e are NOT mutually exclusive. For example:\n" +"\n" +" $ %s -i -e \"main()\" somescript.lua\n" +"\n" +"This will first load the script 'somescript.lua', then execute main, and\n" +"afterward, start the interactive mode.\n" +"\n" +"If a script contains inlined code, it will be run right after loading.\n" +, argv[0]); +} + +void probe(void) { + std::vector p; + + if (!cdabstract::canprobe()) { + printm(M_ERROR, "Can't probe on this platform.\n"); + exit(-1); + } + + p = cdabstract::probe(); + + printm(M_BARE, "Alvaible devices:\n"); + for (std::vector::iterator i = p.begin(); i != p.end(); i++) { + printm(M_BARE, *i + "\n"); + } +} + +virtual int startup() throw (GeneralException) { + char c; + + bool auto_exec = true, strip = true, todo = false, runit, write = false, builtin = false; + char * file = 0, * output = 0, * compile = 0, * exec = 0, * line_read = 0; + char prompt[10]; + Lua * L = 0; + Handle * read_iso = 0; + Output * build_iso = 0, * write_iso = 0; + Buffer command; + String line, endline; + int pos; + + verbosity = M_WARNING; + + showbanner(); + + /* Let's start parsing options */ + + while ((c = getopt_long(argc, argv, "Hhvf:wo:a:c:dile:pb", long_options, NULL)) != EOF) { + switch (c) { + case 'h': + case 'H': + case '?': + showhelp(true); + throw Exit(0); + case 'v': + verbosity = M_INFO; + break; + case 'f': + file = strdup(optarg); + break; + case 'w': + write = true; + break; + case 'o': + output = strdup(optarg); + break; + case 'a': + new Archive(optarg); + break; + case 'c': + compile = strdup(optarg); + break; + case 'd': + strip = false; + break; + case 'i': + interactive = true; + todo = true; + break; + case 'l': + auto_exec = false; + break; + case 'e': + exec = strdup(optarg); + todo = true; + break; + case 'p': + probe(); + throw Exit(0); + case 'b': + builtin = true; + break; + default: + showhelp(); + throw Exit(-1); + } + } + + if (interactive) + L = start_full_lua(); + else + L = start_basic_lua(); + + /* Loading cd-tool.lua (only when not compiling) */ + if (!compile && !builtin) { + try { + L->load(&Input("cd-tool.lua")); + } + catch (GeneralException e) { + printm(M_WARNING, "There was an error loading cd-tool.lua, using built-in: %s\n", e.GetMsg()); + builtin = true; + } + } + + if (!compile && builtin) { + Buffer built; + int i; + + for (i = 0; i < cd_tool_lua_size; i++) { + built.writeU8(cd_tool_lua[i]); + } + try { + L->load(&built); + } + catch (GeneralException e) { + printm(M_WARNING, "There was an error loading built-in cd-tool.lua: %s\n", e.GetMsg()); + builtin = true; + } + } + + /* Loading all the scripts */ + while (optind < argc) { + todo = true; + L->load(&Input(argv[optind++]), !compile); + } + + /* Doh... */ + if (!todo) { + showhelp(); + throw Exit(0); + } + + /* Compilation process will exit from itself right after */ + if (compile) { + L->dump(&Output(compile), strip); + throw Exit(0); + } + + /* The basic input (and eventually output) iso file */ + if (file) { + /* The write mode can't apply on a CD of course... */ + if (write) { + read_iso = new Input(file); + write_iso = new Output(file, 0, 0); + } else { + read_iso = cdabstract::open_cd(file); + } + cdutil = new cdutils(read_iso, write_iso); + if (!cdutil->get_iso_infos()) + throw Exit(-1); + Luacdutils lcdutil(cdutil); + L->push("cdutil"); + lcdutil.push(L); + L->setvar(); + } + + /* The generated iso file */ + if (output) { + build_iso = new Output(output); + build = new isobuilder(build_iso); + Luaisobuilder lbuild(build); + L->push("iso"); + lbuild.push(L); + L->setvar(); + } + + /* One shot command */ + if (exec) { + command << exec; + L->load(&command); + } + + /* Interactive mode loop */ + strcpy(prompt, "> "); +#ifdef _WIN32 + rl_getc_function = my_getc; +#endif + rl_bind_key('\t', rl_insert); + while (interactive) { + /* Basic usage of readline */ + if (line_read) + free(line_read); + + line_read = readline(prompt); + + if (!line_read) { + printm(M_BARE, "\n"); + break; + } + + if (*line_read) + add_history(line_read); + + line = line_read; + line = line.trim(); + endline = ""; + + /* Splitting the line between ;; */ + while (line.strlen()) { + runit = false; + + if ((pos = line.strstr(";;")) >= 0) { + endline = line.extract(pos + 2); + line = line.extract(0, pos); + runit = true; + } else { + endline = ""; + } + + if (line[line.strlen() - 1] == '\\') { + line[line.strlen() - 1] = ' '; + } else if (auto_exec) { + runit = true; + } + + command << line; + + if (runit) { + try { + L->load(&command); + } + 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()); + } + strcpy(prompt, "> "); + } else { + strcpy(prompt, "- "); + } + line = endline.trim(); + }; + } + + /* Finishing off the work, cleaning out the dust */ + if (output) { + delete build; + delete build_iso; + } + + if (file) { + delete cdutil; + } + + return 0; +} +CODE_ENDS diff --git a/compile/Makefile b/compile/Makefile index 0b4f2b3..5cb971e 100644 --- a/compile/Makefile +++ b/compile/Makefile @@ -8,3 +8,10 @@ clean: make -C linux clean rebuild: clean all + +release: + ssh sumarit rm /var/www/cd-tool/* + scp cd-tool*.zip sumarit:/var/www/cd-tool + scp ../FAQ-cd.txt sumarit:/var/www/cd-tool/README.txt + scp ../COPYING sumarit:/var/www/cd-tool + scp *.lua sumarit:/var/www/cd-tool diff --git a/compile/linux/Makefile b/compile/linux/Makefile index 018c4bf..2e54e76 100644 --- a/compile/linux/Makefile +++ b/compile/linux/Makefile @@ -10,7 +10,7 @@ INCLUDES = -I../../includes -I../../psxdev -I../../generic/include \ -I../.. \ `sdl-config --cflags` -CPPFLAGS = $(INCLUDES) -O4 -march=i686 -DSTDC_HEADERS -DREADLINE_STATIC -DHAVE_UNISTD_H +CPPFLAGS = $(INCLUDES) -O4 -march=i686 -DSTDC_HEADERS -DREADLINE_STATIC -DHAVE_UNISTD_H -fexceptions LDFLAGS = -march=i586 -O4 `sdl-config --libs` diff --git a/compile/win32/Makefile b/compile/win32/Makefile index 2938ad2..4359413 100644 --- a/compile/win32/Makefile +++ b/compile/win32/Makefile @@ -11,7 +11,7 @@ INCLUDES = -I../../includes -I../../psxdev -I../../generic/include \ -I/usr/local/cross-tools/i386-mingw32msvc/include/SDL \ -I../.. -CPPFLAGS = $(INCLUDES) -O4 -march=i686 -DSTDC_HEADERS -DREADLINE_STATIC +CPPFLAGS = $(INCLUDES) -O4 -march=i686 -DSTDC_HEADERS -DREADLINE_STATIC -fexceptions LDFLAGS = -march=i586 -O4 @@ -70,7 +70,7 @@ LUA_SOURCES = \ PSX_SOURCES = \ ../../lib/cdabstract.cpp ../../lib/luacd.cpp \ ../../lib/cdreader.cpp ../../lib/luapsx.cpp \ -../../lib/cdutils.cpp ../../lib/lzss.cpp \ +../../lib/cdutils.cpp \ ../../lib/yazedc.cpp ../../lib/isobuilder.cpp PSXDEV_SOURCES = \ @@ -91,11 +91,15 @@ WHOLE_SOURCES = $(SOURCES) $(COMMON_SOURCES) $(MOGLTK_SOURCES) ALL_OBJECTS = $(addsuffix .o, $(notdir $(basename $(WHOLE_SOURCES)))) +ALL_DEP = $(addsuffix .dep, $(notdir $(basename $(WHOLE_SOURCES)))) + DALOS_OBJECTS = $(addsuffix .o, $(notdir $(basename $(COMMON_SOURCES) $(MOGLTK_SOURCES)))) Dalos.o CD_TOOL_OBJECTS = $(addsuffix .o, $(notdir $(basename $(COMMON_SOURCES)))) cd-tool.o -all: cd-tool.exe Dalos.exe +CD_TOOL_DEP = $(addsuffix .dep, $(notdir $(basename $(COMMON_SOURCES)))) cd-tool.o + +all: dep cd-tool.exe Dalos.exe stats: @wc $(WHOLE_SOURCES) @@ -116,19 +120,37 @@ cd-tool.exe: $(CD_TOOL_OBJECTS) upx-nrv -9 cd-tool.exe clean: - rm -f *.exe *.o + rm -f *.exe *.o *.dep +dep: $(ALL_DEP) +source: dep $(COMMON_SOURCES) ../../cd-tool.cpp + for s in $(COMMON_SOURCES) ../../cd-tool.cpp ; do \ + depfile=$${s/*\//} ; \ + depfile=$${depfile/\.*/}.dep ; \ + for f in `cat $$depfile | sed 's/\\\\//g' | tr \\ '\\012' | grep -v ^$$ | grep -v :` $$s; do \ + install -D $$f tmp/`echo $$f | sed 's/\.\.\/\.\.\///'` ; \ + done ; \ + done + (cd tmp ; zip -r9 ../../cd-tool-`date +%Y%m%d`-win32-fullsrc.zip .) + rm -rf tmp +-include $(ALL_OBJECTS:.o=.dep) define OBJECT_C_template $(addsuffix .o, $(notdir $(basename $(1)))): $(src) $$(CC) $$(CPPFLAGS) $$(CFLAGS) -c $(src) + + $(addsuffix .dep, $(notdir $(basename $(1)))): $(src) + $$(CC) $$(CPPFLAGS) $$(CFLAGS) -MM $(src) -o $$@ endef define OBJECT_CXX_template $(addsuffix .o, $(notdir $(basename $(1)))): $(src) $$(CXX) $$(CPPFLAGS) $$(CXXFLAGS) -c $(src) + + $(addsuffix .dep, $(notdir $(basename $(1)))): $(src) + $$(CXX) $$(CPPFLAGS) $$(CXXFLAGS) -MM $(src) -o $$@ endef $(foreach src, $(WHOLE_SOURCES), $(if $(filter %.c, $(src)), $(eval $(call OBJECT_C_template, $(src))), $(eval $(call OBJECT_CXX_template, $(src))))) diff --git a/crypto-search.cpp b/crypto-search.cpp index c5cb785..164c001 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 -#include -#ifdef __linux__ -#include -#else -#define MAXINT INT_MAX -#define MININT INT_MIN -#endif -#include -#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 \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 +#include +#ifdef __linux__ +#include +#else +#define MAXINT INT_MAX +#define MININT INT_MIN +#endif +#include +#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 \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 a9047b0..ec60509 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 -#include -#include -#include -#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 +#include +#include +#include +#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); +} diff --git a/gltest.cpp b/gltest.cpp index 7e69c3a..7965fa7 100644 --- a/gltest.cpp +++ b/gltest.cpp @@ -1,81 +1,81 @@ -#include -#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 +#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 a5dcd0e..1a49c07 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.6 2004-11-27 21:44:46 pixel Exp $ */ - -#ifndef __CD_ABSTRACT_H__ -#define __CD_ABSTRACT_H__ - -#if defined (_MSC_VER) || defined (__MINGW32__) -#include - -#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 -#include -#include - -class cdabstract : public Base { - public: - static Handle * open_cd(const String &); - static bool canprobe(); - static std::vector 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.7 2004-11-27 21:47:53 pixel Exp $ */ + +#ifndef __CD_ABSTRACT_H__ +#define __CD_ABSTRACT_H__ + +#if defined (_MSC_VER) || defined (__MINGW32__) +#include + +#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 +#include +#include + +class cdabstract : public Base { + public: + static Handle * open_cd(const String &); + static bool canprobe(); + static std::vector 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 6b01efc..7d0d15e 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.11 2004-11-27 21:44:46 pixel Exp $ */ - -#ifndef __CDREADER_H__ -#define __CDREADER_H__ - -#include -#include -#include -#include -#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.12 2004-11-27 21:47:53 pixel Exp $ */ + +#ifndef __CDREADER_H__ +#define __CDREADER_H__ + +#include +#include +#include +#include +#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 2f59341..3e11ca2 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.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 +/* + * 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.18 2004-11-27 21:47:53 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 f464084..3be7f9c 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 36573bc..c37de7f 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 d693651..9ced22c 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.10 2004-11-27 21:44:46 pixel Exp $ */ - -#ifndef __ISOBUILDER_H__ -#define __ISOBUILDER_H__ - -#include -#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.11 2004-11-27 21:47:53 pixel Exp $ */ + +#ifndef __ISOBUILDER_H__ +#define __ISOBUILDER_H__ + +#include +#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 f2c7e4a..1f7768f 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.7 2004-11-27 21:44:46 pixel Exp $ */ - -#ifndef __LUACD_H__ -#define __LUACD_H__ - -#include -#include -#include -#include -#include - -#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.8 2004-11-27 21:47:53 pixel Exp $ */ + +#ifndef __LUACD_H__ +#define __LUACD_H__ + +#include +#include +#include +#include +#include + +#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 4b8e6e7..740977c 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.4 2004-11-27 21:44:46 pixel Exp $ */ - -#ifndef __LUAPSX_H__ -#define __LUAPSX_H__ - -#include -#include -#include - -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.5 2004-11-27 21:47:53 pixel Exp $ */ + +#ifndef __LUAPSX_H__ +#define __LUAPSX_H__ + +#include +#include +#include + +class Luapsx : public LuaObject { + public: + static void pushstatics(Lua *) throw (GeneralException); +}; + +#endif diff --git a/includes/lzss.h b/includes/lzss.h index d4da684..14aa345 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 -#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 +#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 f3fc911..8ace76f 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 e8644cc..5ce2506 100644 --- a/includes/mipsdis.h +++ b/includes/mipsdis.h @@ -1,54 +1,54 @@ -#ifndef __MIPSDIS_H__ -#define __MIPSDIS_H__ -#include -#include -#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, std::greater > bheap; - std::priority_queue, std::greater > jheap; - std::priority_queue, std::greater > 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 +#include +#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, std::greater > bheap; + std::priority_queue, std::greater > jheap; + std::priority_queue, std::greater > 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 ca2047a..a6c6288 100644 --- a/includes/mipsdump.h +++ b/includes/mipsdump.h @@ -1,73 +1,73 @@ -#ifndef __MIPSDUMP_H__ -#define __MIPSDUMP_H__ - -#include -#include - -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 -struct mypair { - T1 left; - T2 right; -}; - -typedef mypair 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 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 +#include + +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 +struct mypair { + T1 left; + T2 right; +}; + +typedef mypair 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 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 b083b0f..f763af8 100644 --- a/includes/mipsmem.h +++ b/includes/mipsmem.h @@ -1,114 +1,114 @@ -#ifndef __MIPSMEM_H__ -#define __MIPSMEM_H__ -#define PSXMEM 0x200000 - -#include -#include - -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 +#include + +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 8ed68d8..18ac504 100644 --- a/includes/mipsobj.h +++ b/includes/mipsobj.h @@ -1,74 +1,74 @@ -#ifndef __MIPSOBJ_H__ -#define __MIPSOBJ_H__ - -#include -#include -#include - -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 relocs; - private: - String name; - int type; - Uint8 * datas; - int length; -}; - -class mipsobj : public Base { - public: - mipsobj(); - virtual ~mipsobj(); - std::map sections; - std::map 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 +#include +#include + +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 relocs; + private: + String name; + int type; + Uint8 * datas; + int length; +}; + +class mipsobj : public Base { + public: + mipsobj(); + virtual ~mipsobj(); + std::map sections; + std::map 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 8227e87..8b8652b 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.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 +/* + * 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.6 2004-11-27 21:47:54 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 29d0bc8..2ac872f 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 -#include -#include -#include -#include -#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 +#include +#include +#include +#include +#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 ceb5f70..44663f6 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.8 2004-11-27 21:44:48 pixel Exp $ */ - -#include "cdabstract.h" -#include "Input.h" -#include "cdreader.h" - -#ifdef __linux__ -#include -#include -#include -#include -#endif - -#if defined (_MSC_VER) || defined (__MINGW32__) -#include -#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 cdabstract::probe() throw (GeneralException) { - int i; - std::vector 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.9 2004-11-27 21:47:56 pixel Exp $ */ + +#include "cdabstract.h" +#include "Input.h" +#include "cdreader.h" + +#ifdef __linux__ +#include +#include +#include +#include +#endif + +#if defined (_MSC_VER) || defined (__MINGW32__) +#include +#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 cdabstract::probe() throw (GeneralException) { + int i; + std::vector 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 7777c4d..af1b419 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.20 2004-11-27 21:44:48 pixel Exp $ */ - -#include -#include -#include -#include -#include -#include -#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 -#include -#include - -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.21 2004-11-27 21:47:56 pixel Exp $ */ + +#include +#include +#include +#include +#include +#include +#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 +#include +#include + +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/cdutils.cpp b/lib/cdutils.cpp index 953b76e..ea4ff4c 100644 --- a/lib/cdutils.cpp +++ b/lib/cdutils.cpp @@ -1,952 +1,952 @@ -/* - * 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.cpp,v 1.32 2004-10-20 07:15:43 pixel Exp $ */ - -#include -#include -#include -#include "generic.h" -#include "cdutils.h" -#include "Output.h" - -const long sec_sizes[7] = {0, 2048, 2336, 2048, 2324, 2352, 2352}; -const long sec_offsts[7] = {0, 16, 16, 24, 24, 0, 0}; -const String sec_modes[7] = {"MODE 0 (empty)", "MODE 1", "MODE 2", "MODE 2 FORM 1", "MODE 2 FORM 2", "Raw", "Autodetect"}; - -cdutils::cdutils(Handle * r, Handle * w) : rootDir(0), f_iso_r(r), f_iso_w(w), ppf_file(0), pt1(-1), pt2(-1), snum(0), ptl(0), root(0) {} - -cdutils::~cdutils() { - if (ppf_file) - delete ppf_file; - free(rootDir); -} - -unsigned char cdutils::from_BCD(unsigned char x) { - return ((x & 0xf) + ((x & 0xf0) >> 4) * 10); -} - -unsigned char cdutils::to_BCD(unsigned char x) { - return ((x / 10) << 4) | (x % 10); -} - -bool cdutils::is_valid_BCD(unsigned char x) { - return (((x & 15) < 10) && ((x >> 4) < 10)); -} - -unsigned long cdutils::from_MSF(unsigned char m, unsigned char s, unsigned char f, unsigned long start) { - return (from_BCD(m) * 60 + from_BCD(s)) * 75 + from_BCD(f) - start; -} - -unsigned long cdutils::from_MSF(unsigned long msf, unsigned long start) { - unsigned char - f = msf & 0xff, - s = (msf >> 8) & 0xff, - m = (msf >> 16) & 0xff; - - return from_MSF(m, s, f, start); -} - -void cdutils::to_MSF(int sect, unsigned char & m, unsigned char & s, unsigned char & f, unsigned long start) { - sect += start; - f = to_BCD(sect % 75); - sect /= 75; - s = to_BCD(sect % 60); - m = to_BCD(sect / 60); -} - -unsigned long cdutils::to_MSF(int sect, unsigned long start) { - unsigned char m, s, f; - to_MSF(sect, m, s, f, start); - return f | (s << 8) | (m << 16); -} - -Handle * cdutils::open_ppf(String ppf, String comment) throw (GeneralException) { - int i, l; - - if (ppf_file) - throw GeneralException("Tried to open_ppf() while already opened."); - ppf_file = new Output(ppf); - ppf_file->write("PPF20\001", 6); - - l = comment.strlen(); - if (l >= 50) { - ppf_file->write(comment.to_charp(), 50); - } else { - char * t = " "; - ppf_file->write(comment.to_charp(), l); - for (i = l; i < 50; i++) { - ppf_file->write(t, 1); - } - } - - l = f_iso_r->GetSize(); - ppf_file->write(&l, sizeof(l)); - - f_iso_r->seek(0x9320, SEEK_SET); -// copy(f_iso_r, ppf_file, 1024); - return ppf_file; -} - -void cdutils::write_ppf(Byte * old_sec, Byte * new_sec, int sec_num) { - int i, l = 0, o; - - for (i = 0; i < 2352; i++) { - if (old_sec[i] == new_sec[i]) { - if (l != 0) { - o = 2352 * sec_num + i; - ppf_file->write(&o, sizeof(o)); - ppf_file->write(&l, 1); - ppf_file->write(new_sec + i - l - 1, l); - l = 0; - } - } else { - l++; - if (l == 255) { - o = 2352 * sec_num + i; - ppf_file->write(&o, 4); - ppf_file->write(&l, 1); - ppf_file->write(new_sec + i - 255, 255); - l = 0; - } - } - } -} - -void cdutils::close_ppf() throw (GeneralException) { - if (ppf_file) { - delete ppf_file; - ppf_file = 0; - } else { - throw GeneralException("Tried to close_ppf() without previous opening"); - } -} - -void cdutils::set_iso_w(Handle * w) { - if (!f_iso_w) - f_iso_w = w; -} - -String cdutils::format_date(String input) { - String output; - - output = input.extract(6, 7) + '/'; - output += input.extract(4, 5) + '/'; - output += input.extract(0, 3) + ' '; - output += input.extract(8, 9) + ':'; - output += input.extract(10, 11) + ':'; - output += input.extract(12, 13) + '.'; - output += input.extract(14, 15); - output += String("").set("%+3.1f", ((float) (*((input.to_charp()) + 16))) / 4); - return output; -} - -Uint16 cdutils::swap_word(Uint16 i) { - return (i >> 8) | (i << 8); -} - -Uint32 cdutils::swap_dword(Uint32 i) { - return (i >> 24) | ((i >> 8) & 0x0000ff00) | ((i << 8) & 0x00ff0000) | (i << 24); -} - -int cdutils::guess_type(int number) { - Byte header[24]; - - if (number >= 0) { - sector_seek(number); - } - - f_iso_r->read(header, 24); - f_iso_r->seek(-24, SEEK_CUR); - if (header[15] == 1) { - return MODE_1; - } else if (header[15] == 2) { - if (*((unsigned long *) &(header[16])) == *((unsigned long *) &(header[20]))) { - if ((header[16] == 0) && (header[17] == 0) && (header[19] == 0)) { - if (header[18] & 0x20) { - return MODE_2_FORM_2; - } else { - return MODE_2_FORM_1; - } - } - } - return MODE_2; - } - - return MODE_0; -} - -void cdutils::sector_seek(long sector) { - f_iso_r->seek(2352 * sector); - if (f_iso_w) - f_iso_w->seek(2352 * sector); -} - -long cdutils::read_sector(Byte * buffer, int type, int number) { - try { - if (number >= 0) { - sector_seek(number); - } - - if (type == GUESS) { - type = guess_type(); - } - - f_iso_r->seek(sec_offsts[type], SEEK_CUR); - f_iso_r->read(buffer, sec_sizes[type]); - f_iso_r->seek(2352 - sec_offsts[type] - sec_sizes[type], SEEK_CUR); - } catch (GeneralException e) { - if (number >= 0) - printm(M_ERROR, "Trouble reading sector %i: %s\n", number, e.GetMsg()); - else - printm(M_ERROR, "Trouble reading sector: %s\n", e.GetMsg()); - - if (type != GUESS) - memset(buffer, 0, sec_sizes[type]); - return 0; - } - return sec_sizes[type]; -} - -void cdutils::read_datas(Byte * buffer, long size, int type, int number) { - Byte sector[2352]; - int i, n, reste; - - if (type == GUESS) { - type = guess_type(number); - } - - n = size / sec_sizes[type]; - reste = size - n * sec_sizes[type]; - - sector_seek(number); - for (i = 0; i < n; i++) { - read_sector(buffer + i * sec_sizes[type], type); - } - - if (reste) { - read_sector(sector, type); - bcopy((char *) sector, (char *) (buffer + n * sec_sizes[type]), reste); - } -} - -void cdutils::read_file(Handle * file, long size, int type, int number) { - Byte sector[2352]; - int i, n, reste; - - if (type == GUESS) { - type = guess_type(number); - } - - n = size / sec_sizes[type]; - reste = size - n * sec_sizes[type]; - - for (i = 0; i < n; i++) { - sector_seek(number + i); - try { - read_sector(sector, type); - } - catch(...) { - memset(sector, 0, 2352); - } - file->write(sector, sec_sizes[type]); - } - - sector_seek(number + n); - if (reste) { - try { - read_sector(sector, type); - } - catch(...) { - memset(sector, 0, 2352); - } - file->write(sector, reste); - } -} - -void cdutils::write_sector(Byte * buffer, int type, int number) throw (GeneralException) { - Byte old_sector[2352], new_sector[2352]; - - if (type == GUESS) { - type = guess_type(number); - } - - if (number >= 0) { - sector_seek(number); - } else { - number = f_iso_r->tell() / 2352; - } - - f_iso_r->read(old_sector, 2352); - - yazedc_o.minute = old_sector[12]; - yazedc_o.second = old_sector[13]; - yazedc_o.frame = old_sector[14]; - - bcopy((char *) old_sector, (char *) new_sector, 2532); - bcopy((char *) buffer, (char *) new_sector + sec_offsts[type], sec_sizes[type]); - - yazedc_o.do_encode_L2(new_sector, type, 0); - if (f_iso_w) { - f_iso_w->write(new_sector, 2352); - } else if (ppf_file) { - write_ppf(old_sector, new_sector, number); - } else { - throw GeneralException("No writing method for iso file"); - } -} - -void cdutils::write_datas(Byte * buffer, long size, int type, int number) { - long nbsectors, i; - unsigned char sector[2352]; - - if (type == GUESS) { - type = guess_type(number); - } - - if (number >= 0) { - sector_seek(number); - } - - nbsectors = size / sec_sizes[type]; - - for (i = 0; i < nbsectors; i++) { - write_sector(buffer + i * sec_sizes[type], type, number + i); - } - - if (size % sec_sizes[type]) { - memset(sector, 0, 2352); - bcopy((char *) (buffer + i * sec_sizes[type]), (char *) sector, size % sec_sizes[type]); - write_sector(sector, type, number + i); - } -} - -void cdutils::write_file(Handle * file, long size, int type, int number) { - long nbsectors, i; - unsigned char buffer[2352]; - - if (type == GUESS) { - type = guess_type(number); - } - - if (number >= 0) { - sector_seek(number); - } - - if (size < 0) - size = file->GetSize(); - nbsectors = size / sec_sizes[type]; - - if (size % sec_sizes[type]) { - nbsectors++; - } - - for (i = 0; i < nbsectors; i++) { - memset(buffer, 0, 2352); - size = file->read(buffer, sec_sizes[type]); - write_sector(buffer, type); - } -} - -void cdutils::create_sector(int type, int number, bool eof) throw (GeneralException) { - Byte sector[2352]; - if (!f_iso_w) - throw GeneralException("Can't create sector: ISO not in write mode"); - - to_MSF(number, yazedc_o.minute, yazedc_o.second, yazedc_o.frame); - memset(sector, 0, 2352); - if ((type == MODE2_FORM1) || (type == MODE2_FORM2)) { - sector[16] = sector[20] = 0; // File Number - sector[17] = sector[21] = 0; // Channel Number - sector[18] = sector[22] = 8 | (eof ? 129 : 0) | - (type == MODE2_FORM2 ? 32 : 0); - sector[19] = sector[23] = 0; // Coding Info - } - yazedc_o.do_encode_L2(sector, type, 0); - - f_iso_w->seek(2352 * number); - - f_iso_w->write(sector, 2352); - - sector_seek(number); -} - -void cdutils::show_head_entry(void) { - printm(M_BARE, "Sector Size Date Time Flags Name XA flags\n"); -} - -int cdutils::show_entry(struct DirEntry * dir) { - char pbuf[200], pad; - int s; - if ((!dir) || (!dir->R)) { - return 1; - } - - strncpy(pbuf, dir->id, dir->N); - pbuf[dir->N] = 0; - if ((dir->N == 1) && (pbuf[0] == 0)) { - strcpy(pbuf, "."); - } - if ((dir->N == 1) && (pbuf[0] == 1)) { - strcpy(pbuf, ".."); - } - - s = 33 + dir->N; - if (s & 1) { - s++; - pad = 1; - } else { - pad = 0; - } - if (s != dir->R) { - if ((s + 14) == dir->R) { - Byte * p; - p = (Byte *) dir->id + dir->N + pad; - if ((p[6] == 'X') && (p[7] == 'A')) { - sprintf(pbuf, "%-14s %c%c%c%c%c", pbuf, - p[4] & 0x80 ? 'd' : '-', - p[4] & 0x40 ? 'a' : '-', - p[4] & 0x20 ? 's' : '-', - p[4] & 0x10 ? 'x' : '-', - p[4] & 0x08 ? 'f' : '-'); - } - } - } - - if (dir->Year < 70) - dir->Year += 100; - - printm(M_BARE, "%6i %9i %2i/%02i/%04i %2i:%02i:%02i%+03.1f %c%c%c%c%c%c%c%c %s\n", - dir->Sector, dir->Size, dir->Day, dir->Month, dir->Year + 1900, dir->Hour, dir->Minute, dir->Second, ((float) dir->Offset) / 4, - dir->Flags & 1 ? 'H' : '-', dir->Flags & 2 ? 'D' : '-', dir->Flags & 4 ? 'A' : '-', dir->Flags & 8 ? 'R' : '-', - dir->Flags & 16 ? 'P' : '-', dir->Flags & 32 ? '1' : '-', dir->Flags & 64 ? '1' : '-', dir->Flags & 128 ? 'C' : '-', pbuf); - return dir->R; -} - -int cdutils::show_dir(struct DirEntry * dir) { - unsigned int ptr; - Byte * buffer; - - if (!(dir->Flags & 2)) { - return 0; - } - - buffer = (Byte *) malloc(dir->Size); - read_datas(buffer, dir->Size, GUESS, dir->Sector); - - ptr = 0; - while(ptr < dir->Size) { - ptr += show_entry((struct DirEntry *) &(buffer[ptr])); - } - - free(buffer); - return 1; -} - -struct cdutils::DirEntry cdutils::find_dir_entry(struct DirEntry * dir, String name) { - unsigned int ptr, size; - unsigned char * buffer; - struct DirEntry r = {0, 0, 0, 0, 0}; - - if (!(dir->Flags & 2)) { - return r; - } - - buffer = (unsigned char *) malloc(size = dir->Size); - read_datas(buffer, dir->Size, GUESS, dir->Sector); - - ptr = 0; - while(ptr < size) { - dir = (struct DirEntry *) &(buffer[ptr]); - if (!dir->R) { - ptr++; - } else { - if (!strncmp(name.to_charp(), (char *) &(dir->id), dir->N)) { - r = *dir; - } - ptr += dir->R; - } - } - - free(buffer); - return r; -} - -struct cdutils::DirEntry * cdutils::find_dir_entry(Byte ** bufout, struct cdutils::DirEntry * dir, String name) { - unsigned int ptr, size; - Byte * buffer; - struct DirEntry * rdir = 0; - *bufout = 0; - - if (!(dir->Flags & 2)) { - return 0; - } - - buffer = (Byte *) malloc(size = dir->Size); - read_datas(buffer, dir->Size, GUESS, dir->Sector); - - ptr = 0; - while(ptr < size) { - dir = (struct DirEntry *) &(buffer[ptr]); - if (!dir->R) { - ptr++; - } else { - if (!strncmp(name.to_charp(), (char *) &(dir->id), dir->N)) { - rdir = dir; - } - ptr += dir->R; - } - } - - if (rdir && rdir->R) { - free(*bufout); - *bufout = buffer; - } else { - free(buffer); - rdir = 0; - } - return rdir; -} - -int cdutils::show_iso_infos() { - char buffer[2048]; - char pbuff[130]; - short int s, nogood = 0; - - read_sector((Byte *) buffer, GUESS, 16); - - printm(M_BARE, "Sector guessed mode : " + sec_modes[guess_type(16)] + "\n"); - printm(M_BARE, "offset-size-info : contents\n"); - printm(M_BARE, " 0 - 1- 1 : %i\n", buffer[0]); - memcpy(pbuff, buffer + 1, 5); - pbuff[5] = 0; - printm(M_BARE, " 1 - 5-`CD001' : %s\n", pbuff); - printm(M_BARE, " 6 - 2- 1 : %i\n", s = *((short int *) &(buffer[6]))); - printm(M_BARE, "(*this was the signature*)\n"); - if (buffer[0] != 1) nogood = 1; - if (strcmp(pbuff, "CD001")) nogood = 1; - if (s != 1) nogood = 1; - - if (nogood) { - printm(M_BARE, "Not a valid iso9660 file.\n"); - return 0; - } - - memcpy(pbuff, buffer + 8, 32); - pbuff[32] = 0; - printm(M_BARE, " 8 - 32- SYSID : %s\n", pbuff); - memcpy(pbuff, buffer + 40, 32); - pbuff[32] = 0; - printm(M_BARE, " 40 - 32- VOLID : %s\n", pbuff); - printm(M_BARE, " 80 - 8- SNum : %li\n", *((long int *) &(buffer[80]))); - printm(M_BARE, " 120 - 4- VOLSiz : %i\n", *((short int *) &(buffer[120]))); - printm(M_BARE, " 124 - 4- VOLNum : %i\n", *((short int *) &(buffer[124]))); - printm(M_BARE, " 128 - 4- SSize : %i\n", *((short int *) &(buffer[128]))); - printm(M_BARE, " 132 - 8- PSize : %li\n", *((long int *) &(buffer[132]))); - printm(M_BARE, " 140 - 4- 1SLPath: %i\n", *((long int *) &(buffer[140]))); - printm(M_BARE, " 144 - 4- 2SLPath: %i\n", *((long int *) &(buffer[144]))); - printm(M_BARE, " 148 - 4- 1SBPath: %i\n", swap_word(*((long int *) &(buffer[150])))); - printm(M_BARE, " 152 - 4- 2SBPath: %i\n", swap_word(*((long int *) &(buffer[154])))); - memcpy(pbuff, buffer + 190, 128); - pbuff[128] = 0; - printm(M_BARE, " 190 - 128- VStId : %s\n", pbuff); - memcpy(pbuff, buffer + 318, 128); - pbuff[128] = 0; - printm(M_BARE, " 318 - 128- PubId : %s\n", pbuff); - memcpy(pbuff, buffer + 446, 128); - pbuff[128] = 0; - printm(M_BARE, " 446 - 128- DPrId : %s\n", pbuff); - memcpy(pbuff, buffer + 574, 128); - pbuff[128] = 0; - printm(M_BARE, " 574 - 128- AppId : %s\n", pbuff); - memcpy(pbuff, buffer + 702, 37); - pbuff[37] = 0; - printm(M_BARE, " 702 - 37- CpyFile: %s\n", pbuff); - memcpy(pbuff, buffer + 739, 37); - pbuff[37] = 0; - printm(M_BARE, " 739 - 37- AbsFile: %s\n", pbuff); - memcpy(pbuff, buffer + 776, 37); - pbuff[37] = 0; - printm(M_BARE, " 776 - 37- BibFile: %s\n", pbuff); - printm(M_BARE, " 813 - 17- DTCreat: " + format_date(&buffer[813]) + "\n"); - printm(M_BARE, " 830 - 17- DTModif: " + format_date(&buffer[830]) + "\n"); - printm(M_BARE, " 847 - 17- DTExpir: " + format_date(&buffer[847]) + "\n"); - printm(M_BARE, " 864 - 17- DTEffec: " + format_date(&buffer[864]) + "\n"); - - printm(M_BARE, "Root record:\n"); - show_head_entry(); - show_entry((DirEntry *) &(buffer[156])); - - return 1; -} - -int cdutils::get_iso_infos() { - Byte buffer[2048]; - char pbuff[130]; - short int s, nogood = 0; - int rootsec; - - read_sector(buffer, GUESS, 16); - - memcpy(pbuff, buffer + 1, 5); - pbuff[5] = 0; - - s = *((short int *) &(buffer[6])); - if (buffer[0] != 1) nogood = 1; - if (strcmp(pbuff, "CD001")) nogood = 1; - if (s != 1) nogood = 1; - - if (nogood) { - printm(M_ERROR, "Not a valid iso9660 file.\n"); - return 0; - } - - pt1 = *((short int *) &(buffer[140])); - pt2 = *((short int *) &(buffer[144])); - snum = *((int *) &(buffer[80])); - ptl = *((long int *) &(buffer[132])); - rootsec = ((struct DirEntry *) (&buffer[156]))->Sector; - read_sector(buffer, GUESS, rootsec); - rootDir = (struct DirEntry *) malloc(buffer[0]); - memcpy(rootDir, buffer, buffer[0]); - return 1; -} - -int cdutils::get_pt_infos() { - Byte * buffer; - - if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos()) - return 0; - - if ((!pt1) & (!pt2)) { - printm(M_ERROR, "No path table defined.\n"); - return 0; - } - - buffer = (Byte *) malloc(ptl); - read_datas(buffer, ptl, GUESS, !pt1 ? pt2 : pt1); - - if (buffer[0] == 1) - if (buffer[1] == 0) - if (buffer[6] == 1) - if (buffer[7] == 0) - if (buffer[8] == 0) - if (buffer[9] == 0) - root = *((unsigned long int *) &(buffer[2])); - - free(buffer); - return root ? 1 : 0; -} - -int cdutils::show_pt_infos() { - Byte * buffer; - char pbuf[100]; - int i, ptr; - - if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos()) - return 0; - - if ((!pt1) & (!pt2)) { - printm(M_ERROR, "No path table defined.\n"); - return 0; - } - - buffer = (Byte *) malloc(ptl + 2); - read_datas(buffer, ptl, GUESS, !pt1 ? pt2 : pt1); - - printm(M_BARE, "node^paren@sector : name\n"); - for (ptr = 0, i = 1; buffer[ptr]; ptr += ptr & 1, i++) { - strncpy(pbuf, (char *) &(buffer[8 + ptr]), buffer[ptr]); - pbuf[buffer[ptr]] = 0; - printm(M_BARE, "%3i ^ %3i @ %6i: %s\n", i, *((unsigned short *) &(buffer[6 + ptr])), *((unsigned long *) &(buffer[2 + ptr])), pbuf); - ptr += 8 + buffer[ptr]; - } - - free(buffer); - return 1; -} - -struct cdutils::DirEntry cdutils::find_path(String path) { - char * newpath = path.strdup(); - char ** pts = split(newpath, '/'); - struct DirEntry dir = {0, 0, 0, 0, 0}; - - if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos()) { - free(newpath); - return dir; - } - - if ((!pt1) & (!pt2)) { - printm(M_ERROR, "No path table defined.\n"); - free(newpath); - return dir; - } - - if (!**pts) - pts++; - - for (dir = *rootDir; *pts; pts++) { - if (!strlen(*pts)) - continue; - dir = find_dir_entry(&dir, *pts); - if (!dir.R) { - free(newpath); - return dir; - } - } - - free(newpath); - return dir; -} - -struct cdutils::DirEntry cdutils::find_parent(String path) { - char * newpath = path.strdup(); - char ** pts, * p; - struct DirEntry dir = {0, 0, 0, 0, 0}; - - if ((p = strchr(newpath, '/'))) { - *p = 0; - } - if (!*newpath) { - free(newpath); - return *rootDir; - } - pts = split(newpath, '/'); - - if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos()) { - free(newpath); - return dir; - } - - if ((!pt1) & (!pt2)) { - printm(M_ERROR, "No path table defined.\n"); - free(newpath); - return dir; - } - - if (!**pts) - pts++; - - for (dir = *rootDir; *pts; pts++) { - if (!strlen(*pts)) - continue; - dir = find_dir_entry(&dir, *pts); - if (!dir.R) { - free(newpath); - return dir; - } - } - - free(newpath); - return dir; -} - -struct cdutils::DirEntry * cdutils::find_path(Byte ** bufout, String path) { - char * newpath = path.strdup(); - char ** pts = split(newpath, '/'); - struct DirEntry * dir; - - *bufout = 0; - - if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos()) { - free(newpath); - return 0; - } - - if ((!pt1) & (!pt2)) { - printm(M_ERROR, "No path table defined.\n"); - free(newpath); - return 0; - } - - if (!**pts) - pts++; - - for (dir = rootDir; *pts; pts++) { - if (!strlen(*pts)) - continue; - dir = find_dir_entry(bufout, dir, *pts); - if (!dir) { - free(newpath); - free(*bufout); - return 0; - } - } - - if (!dir) { - free(*bufout); - } - - free(newpath); - return dir; -} - -struct cdutils::DirEntry * cdutils::find_parent(Byte ** bufout, String path) { - char * newpath = path.strdup(); - char ** pts, * p; - struct DirEntry * dir; - - *bufout = 0; - - if ((p = strchr(newpath, '/'))) { - *p = 0; - } - if (!*newpath) { - free(newpath); - return rootDir; - } - pts = split(newpath, '/'); - - if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos()) { - free(newpath); - return 0; - } - - if ((!pt1) & (!pt2)) { - printm(M_ERROR, "No path table defined.\n"); - free(newpath); - return 0; - } - - if (!**pts) - pts++; - - for (dir = rootDir; *pts; pts++) { - free(*bufout); - if (!strlen(*pts)) - continue; - dir = find_dir_entry(bufout, dir, *pts); - if (!dir) { - free(newpath); - return dir; - } - } - - if (!dir) { - free(*bufout); - } - - free(newpath); - return dir; -} - -cdfile::cdfile(cdutils * _cd, const cdutils::DirEntry * d, int _mode) : Handle(-1), cd(_cd), sector(d->Sector), mode(_mode), size(d->Size), name(d->id) { - if (mode == GUESS) { - mode = cd->guess_type(sector); - } - dir = (cdutils::DirEntry *) malloc(d->R); - memcpy(dir, d, d->R); - itell = 0; -} - -cdfile::cdfile(cdutils * _cd, int _sector, ssize_t _size, int _mode) : Handle(-1), cd(_cd), sector(_sector), mode(_mode), size(_size), name("raw reading") { - Byte datas[2352]; - bool eof; - - if (mode == GUESS) { - mode = cd->guess_type(sector); - } - if (_size == -1) { - size = 0; - if ((mode == MODE2_FORM1) || (mode == MODE2_FORM2)) { - do { - cd->read_sector(datas, MODE_RAW, sector + size++); - eof = datas[18] & 0x80; - } while (!eof); - size *= sec_sizes[mode]; - } - } - dir = 0; - itell = 0; -} - -cdfile::~cdfile() { - free(dir); -} - -ssize_t cdfile::read(void *buf, size_t count) throw (GeneralException) { - Byte buffer[2352]; - size_t startsec, startbyte, nstartbytes; - - count = MIN(count, (size_t) (size - itell)); - - if (!count) { - close(); - return 0; - } - - startsec = itell / sec_sizes[mode] + sector; - startbyte = itell % sec_sizes[mode]; - nstartbytes = sec_sizes[mode] - startbyte; - nstartbytes = MIN(nstartbytes, count); - count -= nstartbytes; - - cd->read_sector(buffer, mode, startsec); - memcpy(buf, buffer + startbyte, nstartbytes); - buf = (Byte *) buf + nstartbytes; - - if (count) { - cd->read_datas((Byte *) buf, count, mode, startsec + 1); - } - - itell += count + nstartbytes; - - return count + nstartbytes; -} - -bool cdfile::CanRead() const { - return true; -} - -String cdfile::GetName() const { - return String("cdfile: ") + name; -} - -bool cdfile::CanWatch() const { - return false; -} - -ssize_t cdfile::GetSize() const { - return size; -} - -bool cdfile::CanSeek() const { - return true; -} - -off_t cdfile::seek(off_t off, int wheel) throw (GeneralException) { - switch (wheel) { - case SEEK_SET: - itell = off; - break; - case SEEK_CUR: - itell += off; - break; - case SEEK_END: - itell = size + off; - break; - } - return itell; -} +/* + * 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.cpp,v 1.33 2004-11-27 21:47:56 pixel Exp $ */ + +#include +#include +#include +#include "generic.h" +#include "cdutils.h" +#include "Output.h" + +const long sec_sizes[7] = {0, 2048, 2336, 2048, 2324, 2352, 2352}; +const long sec_offsts[7] = {0, 16, 16, 24, 24, 0, 0}; +const String sec_modes[7] = {"MODE 0 (empty)", "MODE 1", "MODE 2", "MODE 2 FORM 1", "MODE 2 FORM 2", "Raw", "Autodetect"}; + +cdutils::cdutils(Handle * r, Handle * w) : rootDir(0), f_iso_r(r), f_iso_w(w), ppf_file(0), pt1(-1), pt2(-1), snum(0), ptl(0), root(0) {} + +cdutils::~cdutils() { + if (ppf_file) + delete ppf_file; + free(rootDir); +} + +unsigned char cdutils::from_BCD(unsigned char x) { + return ((x & 0xf) + ((x & 0xf0) >> 4) * 10); +} + +unsigned char cdutils::to_BCD(unsigned char x) { + return ((x / 10) << 4) | (x % 10); +} + +bool cdutils::is_valid_BCD(unsigned char x) { + return (((x & 15) < 10) && ((x >> 4) < 10)); +} + +unsigned long cdutils::from_MSF(unsigned char m, unsigned char s, unsigned char f, unsigned long start) { + return (from_BCD(m) * 60 + from_BCD(s)) * 75 + from_BCD(f) - start; +} + +unsigned long cdutils::from_MSF(unsigned long msf, unsigned long start) { + unsigned char + f = msf & 0xff, + s = (msf >> 8) & 0xff, + m = (msf >> 16) & 0xff; + + return from_MSF(m, s, f, start); +} + +void cdutils::to_MSF(int sect, unsigned char & m, unsigned char & s, unsigned char & f, unsigned long start) { + sect += start; + f = to_BCD(sect % 75); + sect /= 75; + s = to_BCD(sect % 60); + m = to_BCD(sect / 60); +} + +unsigned long cdutils::to_MSF(int sect, unsigned long start) { + unsigned char m, s, f; + to_MSF(sect, m, s, f, start); + return f | (s << 8) | (m << 16); +} + +Handle * cdutils::open_ppf(String ppf, String comment) throw (GeneralException) { + int i, l; + + if (ppf_file) + throw GeneralException("Tried to open_ppf() while already opened."); + ppf_file = new Output(ppf); + ppf_file->write("PPF20\001", 6); + + l = comment.strlen(); + if (l >= 50) { + ppf_file->write(comment.to_charp(), 50); + } else { + char * t = " "; + ppf_file->write(comment.to_charp(), l); + for (i = l; i < 50; i++) { + ppf_file->write(t, 1); + } + } + + l = f_iso_r->GetSize(); + ppf_file->write(&l, sizeof(l)); + + f_iso_r->seek(0x9320, SEEK_SET); +// copy(f_iso_r, ppf_file, 1024); + return ppf_file; +} + +void cdutils::write_ppf(Byte * old_sec, Byte * new_sec, int sec_num) { + int i, l = 0, o; + + for (i = 0; i < 2352; i++) { + if (old_sec[i] == new_sec[i]) { + if (l != 0) { + o = 2352 * sec_num + i; + ppf_file->write(&o, sizeof(o)); + ppf_file->write(&l, 1); + ppf_file->write(new_sec + i - l - 1, l); + l = 0; + } + } else { + l++; + if (l == 255) { + o = 2352 * sec_num + i; + ppf_file->write(&o, 4); + ppf_file->write(&l, 1); + ppf_file->write(new_sec + i - 255, 255); + l = 0; + } + } + } +} + +void cdutils::close_ppf() throw (GeneralException) { + if (ppf_file) { + delete ppf_file; + ppf_file = 0; + } else { + throw GeneralException("Tried to close_ppf() without previous opening"); + } +} + +void cdutils::set_iso_w(Handle * w) { + if (!f_iso_w) + f_iso_w = w; +} + +String cdutils::format_date(String input) { + String output; + + output = input.extract(6, 7) + '/'; + output += input.extract(4, 5) + '/'; + output += input.extract(0, 3) + ' '; + output += input.extract(8, 9) + ':'; + output += input.extract(10, 11) + ':'; + output += input.extract(12, 13) + '.'; + output += input.extract(14, 15); + output += String("").set("%+3.1f", ((float) (*((input.to_charp()) + 16))) / 4); + return output; +} + +Uint16 cdutils::swap_word(Uint16 i) { + return (i >> 8) | (i << 8); +} + +Uint32 cdutils::swap_dword(Uint32 i) { + return (i >> 24) | ((i >> 8) & 0x0000ff00) | ((i << 8) & 0x00ff0000) | (i << 24); +} + +int cdutils::guess_type(int number) { + Byte header[24]; + + if (number >= 0) { + sector_seek(number); + } + + f_iso_r->read(header, 24); + f_iso_r->seek(-24, SEEK_CUR); + if (header[15] == 1) { + return MODE_1; + } else if (header[15] == 2) { + if (*((unsigned long *) &(header[16])) == *((unsigned long *) &(header[20]))) { + if ((header[16] == 0) && (header[17] == 0) && (header[19] == 0)) { + if (header[18] & 0x20) { + return MODE_2_FORM_2; + } else { + return MODE_2_FORM_1; + } + } + } + return MODE_2; + } + + return MODE_0; +} + +void cdutils::sector_seek(long sector) { + f_iso_r->seek(2352 * sector); + if (f_iso_w) + f_iso_w->seek(2352 * sector); +} + +long cdutils::read_sector(Byte * buffer, int type, int number) { + try { + if (number >= 0) { + sector_seek(number); + } + + if (type == GUESS) { + type = guess_type(); + } + + f_iso_r->seek(sec_offsts[type], SEEK_CUR); + f_iso_r->read(buffer, sec_sizes[type]); + f_iso_r->seek(2352 - sec_offsts[type] - sec_sizes[type], SEEK_CUR); + } catch (GeneralException e) { + if (number >= 0) + printm(M_ERROR, "Trouble reading sector %i: %s\n", number, e.GetMsg()); + else + printm(M_ERROR, "Trouble reading sector: %s\n", e.GetMsg()); + + if (type != GUESS) + memset(buffer, 0, sec_sizes[type]); + return 0; + } + return sec_sizes[type]; +} + +void cdutils::read_datas(Byte * buffer, long size, int type, int number) { + Byte sector[2352]; + int i, n, reste; + + if (type == GUESS) { + type = guess_type(number); + } + + n = size / sec_sizes[type]; + reste = size - n * sec_sizes[type]; + + sector_seek(number); + for (i = 0; i < n; i++) { + read_sector(buffer + i * sec_sizes[type], type); + } + + if (reste) { + read_sector(sector, type); + bcopy((char *) sector, (char *) (buffer + n * sec_sizes[type]), reste); + } +} + +void cdutils::read_file(Handle * file, long size, int type, int number) { + Byte sector[2352]; + int i, n, reste; + + if (type == GUESS) { + type = guess_type(number); + } + + n = size / sec_sizes[type]; + reste = size - n * sec_sizes[type]; + + for (i = 0; i < n; i++) { + sector_seek(number + i); + try { + read_sector(sector, type); + } + catch(...) { + memset(sector, 0, 2352); + } + file->write(sector, sec_sizes[type]); + } + + sector_seek(number + n); + if (reste) { + try { + read_sector(sector, type); + } + catch(...) { + memset(sector, 0, 2352); + } + file->write(sector, reste); + } +} + +void cdutils::write_sector(Byte * buffer, int type, int number) throw (GeneralException) { + Byte old_sector[2352], new_sector[2352]; + + if (type == GUESS) { + type = guess_type(number); + } + + if (number >= 0) { + sector_seek(number); + } else { + number = f_iso_r->tell() / 2352; + } + + f_iso_r->read(old_sector, 2352); + + yazedc_o.minute = old_sector[12]; + yazedc_o.second = old_sector[13]; + yazedc_o.frame = old_sector[14]; + + bcopy((char *) old_sector, (char *) new_sector, 2532); + bcopy((char *) buffer, (char *) new_sector + sec_offsts[type], sec_sizes[type]); + + yazedc_o.do_encode_L2(new_sector, type, 0); + if (f_iso_w) { + f_iso_w->write(new_sector, 2352); + } else if (ppf_file) { + write_ppf(old_sector, new_sector, number); + } else { + throw GeneralException("No writing method for iso file"); + } +} + +void cdutils::write_datas(Byte * buffer, long size, int type, int number) { + long nbsectors, i; + unsigned char sector[2352]; + + if (type == GUESS) { + type = guess_type(number); + } + + if (number >= 0) { + sector_seek(number); + } + + nbsectors = size / sec_sizes[type]; + + for (i = 0; i < nbsectors; i++) { + write_sector(buffer + i * sec_sizes[type], type, number + i); + } + + if (size % sec_sizes[type]) { + memset(sector, 0, 2352); + bcopy((char *) (buffer + i * sec_sizes[type]), (char *) sector, size % sec_sizes[type]); + write_sector(sector, type, number + i); + } +} + +void cdutils::write_file(Handle * file, long size, int type, int number) { + long nbsectors, i; + unsigned char buffer[2352]; + + if (type == GUESS) { + type = guess_type(number); + } + + if (number >= 0) { + sector_seek(number); + } + + if (size < 0) + size = file->GetSize(); + nbsectors = size / sec_sizes[type]; + + if (size % sec_sizes[type]) { + nbsectors++; + } + + for (i = 0; i < nbsectors; i++) { + memset(buffer, 0, 2352); + size = file->read(buffer, sec_sizes[type]); + write_sector(buffer, type); + } +} + +void cdutils::create_sector(int type, int number, bool eof) throw (GeneralException) { + Byte sector[2352]; + if (!f_iso_w) + throw GeneralException("Can't create sector: ISO not in write mode"); + + to_MSF(number, yazedc_o.minute, yazedc_o.second, yazedc_o.frame); + memset(sector, 0, 2352); + if ((type == MODE2_FORM1) || (type == MODE2_FORM2)) { + sector[16] = sector[20] = 0; // File Number + sector[17] = sector[21] = 0; // Channel Number + sector[18] = sector[22] = 8 | (eof ? 129 : 0) | + (type == MODE2_FORM2 ? 32 : 0); + sector[19] = sector[23] = 0; // Coding Info + } + yazedc_o.do_encode_L2(sector, type, 0); + + f_iso_w->seek(2352 * number); + + f_iso_w->write(sector, 2352); + + sector_seek(number); +} + +void cdutils::show_head_entry(void) { + printm(M_BARE, "Sector Size Date Time Flags Name XA flags\n"); +} + +int cdutils::show_entry(struct DirEntry * dir) { + char pbuf[200], pad; + int s; + if ((!dir) || (!dir->R)) { + return 1; + } + + strncpy(pbuf, dir->id, dir->N); + pbuf[dir->N] = 0; + if ((dir->N == 1) && (pbuf[0] == 0)) { + strcpy(pbuf, "."); + } + if ((dir->N == 1) && (pbuf[0] == 1)) { + strcpy(pbuf, ".."); + } + + s = 33 + dir->N; + if (s & 1) { + s++; + pad = 1; + } else { + pad = 0; + } + if (s != dir->R) { + if ((s + 14) == dir->R) { + Byte * p; + p = (Byte *) dir->id + dir->N + pad; + if ((p[6] == 'X') && (p[7] == 'A')) { + sprintf(pbuf, "%-14s %c%c%c%c%c", pbuf, + p[4] & 0x80 ? 'd' : '-', + p[4] & 0x40 ? 'a' : '-', + p[4] & 0x20 ? 's' : '-', + p[4] & 0x10 ? 'x' : '-', + p[4] & 0x08 ? 'f' : '-'); + } + } + } + + if (dir->Year < 70) + dir->Year += 100; + + printm(M_BARE, "%6i %9i %2i/%02i/%04i %2i:%02i:%02i%+03.1f %c%c%c%c%c%c%c%c %s\n", + dir->Sector, dir->Size, dir->Day, dir->Month, dir->Year + 1900, dir->Hour, dir->Minute, dir->Second, ((float) dir->Offset) / 4, + dir->Flags & 1 ? 'H' : '-', dir->Flags & 2 ? 'D' : '-', dir->Flags & 4 ? 'A' : '-', dir->Flags & 8 ? 'R' : '-', + dir->Flags & 16 ? 'P' : '-', dir->Flags & 32 ? '1' : '-', dir->Flags & 64 ? '1' : '-', dir->Flags & 128 ? 'C' : '-', pbuf); + return dir->R; +} + +int cdutils::show_dir(struct DirEntry * dir) { + unsigned int ptr; + Byte * buffer; + + if (!(dir->Flags & 2)) { + return 0; + } + + buffer = (Byte *) malloc(dir->Size); + read_datas(buffer, dir->Size, GUESS, dir->Sector); + + ptr = 0; + while(ptr < dir->Size) { + ptr += show_entry((struct DirEntry *) &(buffer[ptr])); + } + + free(buffer); + return 1; +} + +struct cdutils::DirEntry cdutils::find_dir_entry(struct DirEntry * dir, String name) { + unsigned int ptr, size; + unsigned char * buffer; + struct DirEntry r = {0, 0, 0, 0, 0}; + + if (!(dir->Flags & 2)) { + return r; + } + + buffer = (unsigned char *) malloc(size = dir->Size); + read_datas(buffer, dir->Size, GUESS, dir->Sector); + + ptr = 0; + while(ptr < size) { + dir = (struct DirEntry *) &(buffer[ptr]); + if (!dir->R) { + ptr++; + } else { + if (!strncmp(name.to_charp(), (char *) &(dir->id), dir->N)) { + r = *dir; + } + ptr += dir->R; + } + } + + free(buffer); + return r; +} + +struct cdutils::DirEntry * cdutils::find_dir_entry(Byte ** bufout, struct cdutils::DirEntry * dir, String name) { + unsigned int ptr, size; + Byte * buffer; + struct DirEntry * rdir = 0; + *bufout = 0; + + if (!(dir->Flags & 2)) { + return 0; + } + + buffer = (Byte *) malloc(size = dir->Size); + read_datas(buffer, dir->Size, GUESS, dir->Sector); + + ptr = 0; + while(ptr < size) { + dir = (struct DirEntry *) &(buffer[ptr]); + if (!dir->R) { + ptr++; + } else { + if (!strncmp(name.to_charp(), (char *) &(dir->id), dir->N)) { + rdir = dir; + } + ptr += dir->R; + } + } + + if (rdir && rdir->R) { + free(*bufout); + *bufout = buffer; + } else { + free(buffer); + rdir = 0; + } + return rdir; +} + +int cdutils::show_iso_infos() { + char buffer[2048]; + char pbuff[130]; + short int s, nogood = 0; + + read_sector((Byte *) buffer, GUESS, 16); + + printm(M_BARE, "Sector guessed mode : " + sec_modes[guess_type(16)] + "\n"); + printm(M_BARE, "offset-size-info : contents\n"); + printm(M_BARE, " 0 - 1- 1 : %i\n", buffer[0]); + memcpy(pbuff, buffer + 1, 5); + pbuff[5] = 0; + printm(M_BARE, " 1 - 5-`CD001' : %s\n", pbuff); + printm(M_BARE, " 6 - 2- 1 : %i\n", s = *((short int *) &(buffer[6]))); + printm(M_BARE, "(*this was the signature*)\n"); + if (buffer[0] != 1) nogood = 1; + if (strcmp(pbuff, "CD001")) nogood = 1; + if (s != 1) nogood = 1; + + if (nogood) { + printm(M_BARE, "Not a valid iso9660 file.\n"); + return 0; + } + + memcpy(pbuff, buffer + 8, 32); + pbuff[32] = 0; + printm(M_BARE, " 8 - 32- SYSID : %s\n", pbuff); + memcpy(pbuff, buffer + 40, 32); + pbuff[32] = 0; + printm(M_BARE, " 40 - 32- VOLID : %s\n", pbuff); + printm(M_BARE, " 80 - 8- SNum : %li\n", *((long int *) &(buffer[80]))); + printm(M_BARE, " 120 - 4- VOLSiz : %i\n", *((short int *) &(buffer[120]))); + printm(M_BARE, " 124 - 4- VOLNum : %i\n", *((short int *) &(buffer[124]))); + printm(M_BARE, " 128 - 4- SSize : %i\n", *((short int *) &(buffer[128]))); + printm(M_BARE, " 132 - 8- PSize : %li\n", *((long int *) &(buffer[132]))); + printm(M_BARE, " 140 - 4- 1SLPath: %i\n", *((long int *) &(buffer[140]))); + printm(M_BARE, " 144 - 4- 2SLPath: %i\n", *((long int *) &(buffer[144]))); + printm(M_BARE, " 148 - 4- 1SBPath: %i\n", swap_word(*((long int *) &(buffer[150])))); + printm(M_BARE, " 152 - 4- 2SBPath: %i\n", swap_word(*((long int *) &(buffer[154])))); + memcpy(pbuff, buffer + 190, 128); + pbuff[128] = 0; + printm(M_BARE, " 190 - 128- VStId : %s\n", pbuff); + memcpy(pbuff, buffer + 318, 128); + pbuff[128] = 0; + printm(M_BARE, " 318 - 128- PubId : %s\n", pbuff); + memcpy(pbuff, buffer + 446, 128); + pbuff[128] = 0; + printm(M_BARE, " 446 - 128- DPrId : %s\n", pbuff); + memcpy(pbuff, buffer + 574, 128); + pbuff[128] = 0; + printm(M_BARE, " 574 - 128- AppId : %s\n", pbuff); + memcpy(pbuff, buffer + 702, 37); + pbuff[37] = 0; + printm(M_BARE, " 702 - 37- CpyFile: %s\n", pbuff); + memcpy(pbuff, buffer + 739, 37); + pbuff[37] = 0; + printm(M_BARE, " 739 - 37- AbsFile: %s\n", pbuff); + memcpy(pbuff, buffer + 776, 37); + pbuff[37] = 0; + printm(M_BARE, " 776 - 37- BibFile: %s\n", pbuff); + printm(M_BARE, " 813 - 17- DTCreat: " + format_date(&buffer[813]) + "\n"); + printm(M_BARE, " 830 - 17- DTModif: " + format_date(&buffer[830]) + "\n"); + printm(M_BARE, " 847 - 17- DTExpir: " + format_date(&buffer[847]) + "\n"); + printm(M_BARE, " 864 - 17- DTEffec: " + format_date(&buffer[864]) + "\n"); + + printm(M_BARE, "Root record:\n"); + show_head_entry(); + show_entry((DirEntry *) &(buffer[156])); + + return 1; +} + +int cdutils::get_iso_infos() { + Byte buffer[2048]; + char pbuff[130]; + short int s, nogood = 0; + int rootsec; + + read_sector(buffer, GUESS, 16); + + memcpy(pbuff, buffer + 1, 5); + pbuff[5] = 0; + + s = *((short int *) &(buffer[6])); + if (buffer[0] != 1) nogood = 1; + if (strcmp(pbuff, "CD001")) nogood = 1; + if (s != 1) nogood = 1; + + if (nogood) { + printm(M_ERROR, "Not a valid iso9660 file.\n"); + return 0; + } + + pt1 = *((short int *) &(buffer[140])); + pt2 = *((short int *) &(buffer[144])); + snum = *((int *) &(buffer[80])); + ptl = *((long int *) &(buffer[132])); + rootsec = ((struct DirEntry *) (&buffer[156]))->Sector; + read_sector(buffer, GUESS, rootsec); + rootDir = (struct DirEntry *) malloc(buffer[0]); + memcpy(rootDir, buffer, buffer[0]); + return 1; +} + +int cdutils::get_pt_infos() { + Byte * buffer; + + if ((pt1 <= 0) && (pt2 <= 0)) + if (!get_iso_infos()) + return 0; + + if ((!pt1) & (!pt2)) { + printm(M_ERROR, "No path table defined.\n"); + return 0; + } + + buffer = (Byte *) malloc(ptl); + read_datas(buffer, ptl, GUESS, !pt1 ? pt2 : pt1); + + if (buffer[0] == 1) + if (buffer[1] == 0) + if (buffer[6] == 1) + if (buffer[7] == 0) + if (buffer[8] == 0) + if (buffer[9] == 0) + root = *((unsigned long int *) &(buffer[2])); + + free(buffer); + return root ? 1 : 0; +} + +int cdutils::show_pt_infos() { + Byte * buffer; + char pbuf[100]; + int i, ptr; + + if ((pt1 <= 0) && (pt2 <= 0)) + if (!get_iso_infos()) + return 0; + + if ((!pt1) & (!pt2)) { + printm(M_ERROR, "No path table defined.\n"); + return 0; + } + + buffer = (Byte *) malloc(ptl + 2); + read_datas(buffer, ptl, GUESS, !pt1 ? pt2 : pt1); + + printm(M_BARE, "node^paren@sector : name\n"); + for (ptr = 0, i = 1; buffer[ptr]; ptr += ptr & 1, i++) { + strncpy(pbuf, (char *) &(buffer[8 + ptr]), buffer[ptr]); + pbuf[buffer[ptr]] = 0; + printm(M_BARE, "%3i ^ %3i @ %6i: %s\n", i, *((unsigned short *) &(buffer[6 + ptr])), *((unsigned long *) &(buffer[2 + ptr])), pbuf); + ptr += 8 + buffer[ptr]; + } + + free(buffer); + return 1; +} + +struct cdutils::DirEntry cdutils::find_path(String path) { + char * newpath = path.strdup(); + char ** pts = split(newpath, '/'); + struct DirEntry dir = {0, 0, 0, 0, 0}; + + if ((pt1 <= 0) && (pt2 <= 0)) + if (!get_iso_infos()) { + free(newpath); + return dir; + } + + if ((!pt1) & (!pt2)) { + printm(M_ERROR, "No path table defined.\n"); + free(newpath); + return dir; + } + + if (!**pts) + pts++; + + for (dir = *rootDir; *pts; pts++) { + if (!strlen(*pts)) + continue; + dir = find_dir_entry(&dir, *pts); + if (!dir.R) { + free(newpath); + return dir; + } + } + + free(newpath); + return dir; +} + +struct cdutils::DirEntry cdutils::find_parent(String path) { + char * newpath = path.strdup(); + char ** pts, * p; + struct DirEntry dir = {0, 0, 0, 0, 0}; + + if ((p = strchr(newpath, '/'))) { + *p = 0; + } + if (!*newpath) { + free(newpath); + return *rootDir; + } + pts = split(newpath, '/'); + + if ((pt1 <= 0) && (pt2 <= 0)) + if (!get_iso_infos()) { + free(newpath); + return dir; + } + + if ((!pt1) & (!pt2)) { + printm(M_ERROR, "No path table defined.\n"); + free(newpath); + return dir; + } + + if (!**pts) + pts++; + + for (dir = *rootDir; *pts; pts++) { + if (!strlen(*pts)) + continue; + dir = find_dir_entry(&dir, *pts); + if (!dir.R) { + free(newpath); + return dir; + } + } + + free(newpath); + return dir; +} + +struct cdutils::DirEntry * cdutils::find_path(Byte ** bufout, String path) { + char * newpath = path.strdup(); + char ** pts = split(newpath, '/'); + struct DirEntry * dir; + + *bufout = 0; + + if ((pt1 <= 0) && (pt2 <= 0)) + if (!get_iso_infos()) { + free(newpath); + return 0; + } + + if ((!pt1) & (!pt2)) { + printm(M_ERROR, "No path table defined.\n"); + free(newpath); + return 0; + } + + if (!**pts) + pts++; + + for (dir = rootDir; *pts; pts++) { + if (!strlen(*pts)) + continue; + dir = find_dir_entry(bufout, dir, *pts); + if (!dir) { + free(newpath); + free(*bufout); + return 0; + } + } + + if (!dir) { + free(*bufout); + } + + free(newpath); + return dir; +} + +struct cdutils::DirEntry * cdutils::find_parent(Byte ** bufout, String path) { + char * newpath = path.strdup(); + char ** pts, * p; + struct DirEntry * dir; + + *bufout = 0; + + if ((p = strchr(newpath, '/'))) { + *p = 0; + } + if (!*newpath) { + free(newpath); + return rootDir; + } + pts = split(newpath, '/'); + + if ((pt1 <= 0) && (pt2 <= 0)) + if (!get_iso_infos()) { + free(newpath); + return 0; + } + + if ((!pt1) & (!pt2)) { + printm(M_ERROR, "No path table defined.\n"); + free(newpath); + return 0; + } + + if (!**pts) + pts++; + + for (dir = rootDir; *pts; pts++) { + free(*bufout); + if (!strlen(*pts)) + continue; + dir = find_dir_entry(bufout, dir, *pts); + if (!dir) { + free(newpath); + return dir; + } + } + + if (!dir) { + free(*bufout); + } + + free(newpath); + return dir; +} + +cdfile::cdfile(cdutils * _cd, const cdutils::DirEntry * d, int _mode) : Handle(-1), cd(_cd), sector(d->Sector), mode(_mode), size(d->Size), name(d->id) { + if (mode == GUESS) { + mode = cd->guess_type(sector); + } + dir = (cdutils::DirEntry *) malloc(d->R); + memcpy(dir, d, d->R); + itell = 0; +} + +cdfile::cdfile(cdutils * _cd, int _sector, ssize_t _size, int _mode) : Handle(-1), cd(_cd), sector(_sector), mode(_mode), size(_size), name("raw reading") { + Byte datas[2352]; + bool eof; + + if (mode == GUESS) { + mode = cd->guess_type(sector); + } + if (_size == -1) { + size = 0; + if ((mode == MODE2_FORM1) || (mode == MODE2_FORM2)) { + do { + cd->read_sector(datas, MODE_RAW, sector + size++); + eof = datas[18] & 0x80; + } while (!eof); + size *= sec_sizes[mode]; + } + } + dir = 0; + itell = 0; +} + +cdfile::~cdfile() { + free(dir); +} + +ssize_t cdfile::read(void *buf, size_t count) throw (GeneralException) { + Byte buffer[2352]; + size_t startsec, startbyte, nstartbytes; + + count = MIN(count, (size_t) (size - itell)); + + if (!count) { + close(); + return 0; + } + + startsec = itell / sec_sizes[mode] + sector; + startbyte = itell % sec_sizes[mode]; + nstartbytes = sec_sizes[mode] - startbyte; + nstartbytes = MIN(nstartbytes, count); + count -= nstartbytes; + + cd->read_sector(buffer, mode, startsec); + memcpy(buf, buffer + startbyte, nstartbytes); + buf = (Byte *) buf + nstartbytes; + + if (count) { + cd->read_datas((Byte *) buf, count, mode, startsec + 1); + } + + itell += count + nstartbytes; + + return count + nstartbytes; +} + +bool cdfile::CanRead() const { + return true; +} + +String cdfile::GetName() const { + return String("cdfile: ") + name; +} + +bool cdfile::CanWatch() const { + return false; +} + +ssize_t cdfile::GetSize() const { + return size; +} + +bool cdfile::CanSeek() const { + return true; +} + +off_t cdfile::seek(off_t off, int wheel) throw (GeneralException) { + switch (wheel) { + case SEEK_SET: + itell = off; + break; + case SEEK_CUR: + itell += off; + break; + case SEEK_END: + itell = size + off; + break; + } + return itell; +} diff --git a/lib/dteutils.cpp b/lib/dteutils.cpp index 42f36bf..85a7df2 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 -#include -#include -#include -#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 +#include +#include +#include +#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/isobuilder.cpp b/lib/isobuilder.cpp index 2b60131..6ed8abd 100644 --- a/lib/isobuilder.cpp +++ b/lib/isobuilder.cpp @@ -1,876 +1,876 @@ -/* - * 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.cpp,v 1.14 2004-10-19 15:58:41 pixel Exp $ */ - -#include "isobuilder.h" - -void isobuilder::Date::dump(Byte * datas) { - char pbuf[256]; - - sprintf(pbuf, "%04i", year); - memcpy(datas + 0, pbuf, 4); - sprintf(pbuf, "%02i", month); - memcpy(datas + 4, pbuf, 2); - sprintf(pbuf, "%02i", day); - memcpy(datas + 6, pbuf, 2); - sprintf(pbuf, "%02i", hour); - memcpy(datas + 8, pbuf, 2); - sprintf(pbuf, "%02i", minute); - memcpy(datas + 10, pbuf, 2); - sprintf(pbuf, "%02i", second); - memcpy(datas + 12, pbuf, 2); - sprintf(pbuf, "%02i", hundredths); - memcpy(datas + 14, pbuf, 2); - - *((char *) (datas + 16)) = offset; -} - -isobuilder::Date::Date(int) { - year = month = day = hour = minute = second = hundredths = offset = 0; -} - -isobuilder::Date::Date(Byte * datas) { - char pbuf[256]; - char * cdatas = (char *) datas; - - memcpy(pbuf, cdatas + 0, 4); - pbuf[4] = 0; - sscanf(pbuf, "%d", &year); - - memcpy(pbuf, cdatas + 4, 2); - pbuf[2] = 0; - sscanf(pbuf, "%d", &month); - - memcpy(pbuf, cdatas + 6, 2); - pbuf[2] = 0; - sscanf(pbuf, "%d", &day); - - memcpy(pbuf, cdatas + 8, 2); - pbuf[2] = 0; - sscanf(pbuf, "%d", &hour); - - memcpy(pbuf, cdatas + 10, 2); - pbuf[2] = 0; - sscanf(pbuf, "%d", &minute); - - memcpy(pbuf, cdatas + 12, 2); - pbuf[2] = 0; - sscanf(pbuf, "%d", &second); - - memcpy(pbuf, cdatas + 14, 2); - pbuf[2] = 0; - sscanf(pbuf, "%d", &hundredths); - - offset = *(cdatas + 16); -} - -isobuilder::DirTree::DirTree(isobuilder::DirTree * _father, bool _dir) : mode(-1), father(_father), dir(_dir) { - DirTree * p; - - child = brother = 0; - - if (!father) - return; - - creation = father->creation; - - if (father->child) { - for (p = father->child; p->brother; p = p->brother); - p->brother = this; - } else { - father->child = this; - } -} - -isobuilder::DirTree::~DirTree() { - while (child) { - delete child; - } - - if (!father) - return; - - if (father->child == this) { - father->child = brother; - } else { - // Dirty, should not happen. - DirTree * p; - for (p = father->child; p->brother != this; p = p->brother); - p->brother = brother; - } -} - -void isobuilder::DirTree::dumpdirs(isobuilder * builder) throw (GeneralException) { - Byte * dir, * odir; - int cursiz, cursectsize, R; - String oldname; - DirTree * p; - - odir = dir = (Byte *) malloc(cursiz = size); - cursectsize = 2048; - - oldname = name; - name = "."; - R = buildentry(dir, cursectsize); - name = oldname; - cursectsize -= R; - dir += R; - - if (father) { - oldname = father->name; - father->name = ".."; - R = father->buildentry(dir, cursectsize); - father->name = oldname; - } else { - name = ".."; - R = buildentry(dir, cursectsize); - name = "."; - } - - cursectsize -= R; - dir += R; - - for (p = child; p; p = p->brother) { - if (p->dir) { - p->dumpdirs(builder); - } - if (p->hardhide) - continue; - while (!(R = p->buildentry(dir, cursectsize))) { - cursiz -= 2048; - dir += cursectsize; - cursectsize = 2048; - if (!cursiz) - throw GeneralException("Directory is too small! Entries don't fit."); - } - cursectsize -= R; - dir += R; - } - - builder->putdatas(odir, size, mode, sector); - - free(odir); -} - -int isobuilder::DirTree::buildpath(Byte * datas, int size, bool bigendian) throw (GeneralException) { - int N, r, tr; - Uint16 pn; - char pbuf[256], pad; - - if (!dir) { - if (brother) { - return brother->buildpath(datas, size, bigendian); - } else { - return 0; - } - } - - if (!father) { - numerate(1); - N = 1; - pbuf[0] = 0; - pn = 1; - } else { - N = name.strlen(); - strcpy(pbuf, name.to_charp()); - pn = father->node; - } - - pad = N & 1; - size -= (r = N + pad + 8); - - if (size < 0) - throw GeneralException("Path table too small."); - - datas[0] = N; - datas[1] = 0; - *((Uint32 *) (datas + 2)) = bigendian ? cdutils::swap_dword(sector) : sector; - *((Uint16 *) (datas + 6)) = bigendian ? cdutils::swap_word(pn) : pn; - memcpy(datas + 8, pbuf, N); - if (pad) - datas[8 + N] = 0; - - datas += r; - - if (brother) { - tr = brother->buildpath(datas, size, bigendian); - r += tr; - size -= tr; - datas += tr; - } - - if (child) { - tr = child->buildpath(datas, size, bigendian); - r += tr; - size -= tr; - datas += tr; - } - - return r; -} - -int isobuilder::DirTree::buildentry(Byte * buffer, int spaceleft, bool put_xa) { - int N, R; - char pbuf[256], pad; - Byte * p; - cdutils::DirEntry * d = (cdutils::DirEntry *) buffer; - - put_xa = put_xa && have_xa; - - memset(pbuf, 0, 256); - - if (name == ".") { - N = 1; - pbuf[0] = 0; - } else if (name == "..") { - N = 1; - pbuf[0] = 1; - } else { - strcpy(pbuf, name.to_charp()); - N = name.strlen(); - if (!dir) { - N += 2; - strcat(pbuf, ";1"); - } - } - - R = N + 33; - - if (R & 1) { - R++; - pad = 1; - } else { - pad = 0; - } - - if (put_xa) { - R += 14; - p = (Byte *) pbuf + N + pad; - p[4] = 0x05; - p[5] = 0x55; - p[6] = 'X'; - p[7] = 'A'; - - p[4] |= xa_dir ? 0x80 : 0; - p[4] |= xa_audio ? 0x40 : 0; - p[4] |= xa_str ? 0x20 : 0; - p[4] |= xa_xa ? 0x10 : 0; - p[4] |= xa_form1 ? 0x08 : 0; - } - - if (R > spaceleft) { - return 0; - } - - memset(d, 0, R); - - d->R = R; - d->N = N; - memcpy(d->id, pbuf, N + pad + (put_xa ? 14 : 0)); - - d->Sector = sector; - d->BESector = cdutils::swap_dword(sector); - d->Size = size; - d->BESize = cdutils::swap_dword(size); - if (creation.year >= 1000) { - d->Year = creation.year - 1900; - } else { - d->Year = creation.year; - } - d->Month = creation.month; - d->Day = creation.day; - d->Hour = creation.hour; - d->Minute = creation.minute; - d->Second = creation.second; - d->Offset = creation.offset; - d->Flags |= hidden ? 1 : 0; - d->Flags |= dir ? 2 : 0; - - return R; -} - -void isobuilder::DirTree::fromdir(cdutils::DirEntry * d) { - Date t; - char pbuf[200], pad; - int s; - if ((!d) || (!d->R)) { - return; - } - - if ((d->N == 1) && (d->id[0] == 0)) { - name = "."; - } else if ((d->N == 1) && (d->id[0] == 1)) { - name = ".."; - } else { - memcpy(pbuf, d->id, s = (d->N - ((d->Flags & 2) ? 0 : 2))); - pbuf[s] = 0; - name = pbuf; - } - hidden = d->Flags & 1; - if (d->Year < 70) - d->Year += 100; - t.year = d->Year; - t.month = d->Month; - t.day = d->Day; - t.hour = d->Hour; - t.second = d->Second; - t.hundredths = 0; - t.offset = d->Offset; - creation = t; - - s = 33 + d->N; - if (s & 1) { - s++; - pad = 1; - } else { - pad = 0; - } - if (s != d->R) { - if ((s + 14) == d->R) { - Byte * p; - p = (Byte *) d->id + d->N + pad; - if ((p[6] == 'X') && (p[7] == 'A')) { - have_xa = true; - xa_dir = p[4] & 0x80; - xa_audio = p[4] & 0x40; - xa_str = p[4] & 0x20; - xa_xa = p[4] & 0x10; - xa_form1 = p[4] & 0x08; - } - } - } -} - -bool isobuilder::DirTree::isdir() { - return dir; -} - -void isobuilder::DirTree::setbasicsxa() { - have_xa = true; - if (dir) - xa_dir = true; - xa_form1 = true; -} - -int isobuilder::DirTree::numerate(int n) { - if (!dir) { - if (brother) { - return brother->numerate(n); - } else { - return n; - } - } - - node = n++; - - if (brother) - n = brother->numerate(n); - - if (child) - n = child->numerate(n); - - return n; -} - -isobuilder::DirTree * isobuilder::DirTree::Father() { - return father; -} - -isobuilder::DirTree * isobuilder::DirTree::Brother() { - return brother; -} - -isobuilder::DirTree * isobuilder::DirTree::Child() { - return child; -} - -isobuilder::DirTree * isobuilder::DirTree::Find(const String & _name) { - DirTree * p = 0; - - if (name == _name) - return this; - - if (brother) - p = brother->Find(_name); - - if (!p && child) - return child->Find(_name); - - return p; -} - -isobuilder::isobuilder(Handle * _w, int _mode) : w(_w), sector(0), nsectors(0), basics(false), dmode(_mode) { - Byte sect[2352]; - memset(sect, 0, 2352); - - for (int i = 0; i < 16; i++) { - createsector(sect, MODE2, i); - } -} - -isobuilder::~isobuilder() { - if (!closed) - close(); - if (root) - delete root; -} - -void isobuilder::foreword(cdutils * cd) { - Byte sect[2352]; - for (int i = 0; i < 16; i++) { - cd->read_sector(sect, MODE_RAW, i); - createsector(sect, MODE_RAW, i); - } -} - -void isobuilder::foreword(Handle * forewords, int mode) { - Byte sect[2352]; - for (int i = 0; i < 16; i++) { - forewords->read(sect, sec_sizes[mode]); - createsector(sect, mode, i); - } -} - -void isobuilder::foreword(Byte * forewords, int mode) { - for (int i = 0; i < 16; i++) { - createsector(forewords + i * sec_sizes[mode], mode, i); - } -} - -int isobuilder::getdispsect() { - return lastdispsect; -} - -int isobuilder::putfile(Handle * file, int mode, int n) { - Byte datas[2352]; - ssize_t filesize; - int fsect; - - if (mode < 0) - mode = dmode; - - if (n >= 0) { - sector = n; - } else { - sector = lastdispsect; - } - - fsect = sector; - - filesize = file->GetSize(); - - while (filesize > 0) { - memset(datas, 0, 2352); - filesize -= file->read(datas, sec_sizes[mode]); - if ((mode == MODE2_FORM1) || (mode == MODE2_FORM2)) { - if (filesize) { - clearEOF(); - } else { - setEOF(); - } - } - createsector(datas, mode); - } - - return fsect; -} - -int isobuilder::putdatas(Byte * _datas, size_t size, int smode, int n) { - Byte datas[2352]; - size_t eating; - int dsect; - if (n >= 0) { - sector = n; - } else { - sector = lastdispsect; - } - - dsect = sector; - - if (smode < 0) - smode = dmode; - - while (size > 0) { - memset(datas, 0, 2352); - eating = MIN(size, (size_t) sec_sizes[smode]); - memcpy(datas, _datas, eating); - size -= eating; - _datas += eating; - if ((smode == MODE2_FORM1) || (smode == MODE2_FORM2)) { - if (size) { - clearEOF(); - } else { - setEOF(); - } - } - createsector(datas, smode); - } - - return dsect; -} - -int isobuilder::createsector(Byte * datas, int smode, int n) { - Byte dsector[2352]; - int rsector; - if (n >= 0) - sector = n; - - if (smode < 0) - smode = dmode; - - rsector = sector; - - w->seek(2352 * sector, SEEK_SET); - - memcpy(dsector + sec_offsts[smode], datas, sec_sizes[smode]); - - if ((smode == MODE2_FORM1) || (smode == MODE2_FORM2)) { - // Mode 2 Form 2 would be odd, but well.... - dsector[16] = dsector[20] = 0; // File Number - dsector[17] = dsector[21] = 0; // Channel Number - dsector[18] = dsector[22] = sub_EOR | sub_EOF | 8 | - (smode == MODE2_FORM2 ? 32 : 0); - dsector[19] = dsector[23] = 0; // Coding Info - } - - if (smode != MODE_RAW) { - sector += 150; - yazedc_o.minute = cdutils::to_BCD(sector / 60 / 75); - yazedc_o.second = cdutils::to_BCD((sector / 75) % 60); - yazedc_o.frame = cdutils::to_BCD(sector % 75); - sector -= 150; - yazedc_o.do_encode_L2(dsector, smode, 0); - } - - w->write(dsector, 2352); - - sector++; - - nsectors = MAX(nsectors, sector); - lastdispsect = MAX(lastdispsect, sector); - - return rsector; -} - -void isobuilder::setEOF() { - sub_EOF = 128; - sub_EOR = 1; -} - -void isobuilder::clearEOF() { - sub_EOF = sub_EOR = 0; -} - -isobuilder::DirTree * isobuilder::setbasics(PVD _pvd, int _rootsize, int _ptsize, int _nvd, int _rootsect) throw (GeneralException) { - if (basics) { - throw GeneralException("Basic ISO structures already set"); - } - basics = true; - - pvd = _pvd; - rootsize = _rootsize; - ptsize = _ptsize; - nvd = _nvd; - - ptsect = 17 + nvd; - rootsect = ptsect + ptsize * 4; - if (_rootsect >= 0) - rootsect = _rootsect; - lastdispsect = rootsect + rootsize; - - root = new DirTree(0); - root->name = "."; - root->creation = pvd.volcreat; - root->sector = rootsect; - root->size = rootsize * 2048; - return root; -} - -isobuilder::DirTree * isobuilder::createdir(DirTree * p, const String & _name, int size, cdutils::DirEntry * d, int mode) throw (GeneralException) { - DirTree * r; - - if (!p) - throw GeneralException("Empty father"); - - if (closed) - throw GeneralException("ISO is closed"); - - if (!basics) - throw GeneralException("ISO basis not created (no root!)"); - - r = new DirTree(p); - - r->creation = p->creation; - if (d) - r->fromdir(d); - if (_name != "") - r->name = _name; - r->size = size * 2048; - if (!r->size) - r->size = d->Size; - r->sector = lastdispsect; - if (mode >= 0) - r->mode = mode; - else - r->mode = dmode; - - lastdispsect += size; - - return r; -} - -isobuilder::DirTree * isobuilder::createfile(DirTree * p, Handle * file, const String & _name, cdutils::DirEntry * d, int mode) throw (GeneralException) { - DirTree * r; - - if (!p) - throw GeneralException("Empty father"); - - if (closed) - throw GeneralException("ISO is closed"); - - if (!basics) - throw GeneralException("ISO basis not created (no root!)"); - - r = new DirTree(p, false); - - r->name = _name; - r->creation = p->creation; - r->fromdir(d); - if (_name != "") - r->name = _name; - r->size = file->GetSize(); - r->sector = putfile(file, mode); - if (mode >= 0) - r->mode = mode; - else - r->mode = dmode; - - return r; -} - -void isobuilder::copydir(isobuilder::DirTree * r, cdutils * cd, cdutils::DirEntry * d, int mode) { - Byte datas[2048]; - cdutils::DirEntry * p; - int nsectors = d->Size / 2048, ssize, c = 0; - int fsize, osize; - - if (mode < 0) - mode = dmode; - - while (nsectors) { - cd->read_sector(datas, mode, d->Sector + c++); - nsectors--; - p = (cdutils::DirEntry *) datas; - ssize = 2048; - while ((ssize) && (p->R)) { - ssize -= p->R; - char pbuf[256]; - memcpy(pbuf, p->id, p->N); - pbuf[p->N] = 0; - if (p->Flags & 2) { - if (!((p->N == 1) && ((p->id[0] == 0) || (p->id[0] == 1)))) - copydir(createdir(r, "", p->Size / 2048, p, mode), cd, p, mode); - } else { - printm(M_INFO, "Dupping %s\n", pbuf); - int fmode; - osize = fsize = p->Size; - if (mode == MODE1) { - fmode = mode; - } else { - fmode = MODE2_FORM1; - int s, pad; - s = 33 + p->N; - if (s & 1) { - s++; - pad = 1; - } else { - pad = 0; - } - if ((s != p->R) && ((s + 14) == p->R)) { - if (!(p->id[p->N + pad + 4] & 8)) { - fmode = MODE2; - fsize = (p->Size / 2048) * 2336; - } - } - } - p->Size = fsize; - cdfile * tmp = new cdfile(cd, p, fmode); - createfile(r, tmp, "", p, fmode)->size = osize; - delete tmp; - p->Size = osize; - } - p = (cdutils::DirEntry *) (((Byte *) p) + p->R); - } - } -} - -isobuilder::PVD isobuilder::createpvd(Handle * f) { - Byte datas[2048]; - f->read(datas, 2048); - return createpvd(datas); -} - -isobuilder::PVD isobuilder::createpvd(cdutils * cd) { - Byte datas[2048]; - cd->read_sector(datas, GUESS, 16); - return createpvd(datas); -} - -isobuilder::PVD isobuilder::createpvd(Byte * buffer) { - PVD r; - char pbuff[256]; - - memcpy(pbuff, buffer + 8, 32); - pbuff[32] = 0; - r.sysid = pbuff; - r.sysid.rtrim(); - memcpy(pbuff, buffer + 40, 32); - pbuff[32] = 0; - r.volid = pbuff; - r.volid.rtrim(); - memcpy(pbuff, buffer + 190, 128); - pbuff[128] = 0; - r.volsetid = pbuff; - r.volsetid.rtrim(); - memcpy(pbuff, buffer + 318, 128); - pbuff[128] = 0; - r.pubid = pbuff; - r.pubid.rtrim(); - memcpy(pbuff, buffer + 446, 128); - pbuff[128] = 0; - r.prepid = pbuff; - r.prepid.rtrim(); - memcpy(pbuff, buffer + 574, 128); - pbuff[128] = 0; - r.appid = pbuff; - r.appid.rtrim(); - memcpy(pbuff, buffer + 702, 37); - pbuff[37] = 0; - r.copyright = pbuff; - r.copyright.rtrim(); - memcpy(pbuff, buffer + 739, 37); - pbuff[37] = 0; - r.abstract = pbuff; - r.abstract.rtrim(); - memcpy(pbuff, buffer + 776, 37); - pbuff[37] = 0; - r.biblio = pbuff; - r.biblio.rtrim(); - - r.volcreat = Date(buffer + 813); - r.modif = Date(buffer + 830); - r.volexp = Date(buffer + 847); - r.voleff = Date(buffer + 864); - - memcpy(r.appdata, buffer + 883, 512); - - return r; -} - -void isobuilder::close(Handle * cue, int mode, int nsects) throw (GeneralException) { - Byte datas[2048]; - Byte * pdatas; - char * cdatas = (char *) datas; - int psize; - - if (nsects < 0) - nsects = nsectors; - - memset(datas, 0, 2048); - - pdatas = (Byte *) malloc(ptsize * 2048); - psize = root->buildpath(pdatas, ptsize * 2048); - putdatas(pdatas, ptsize * 2048, mode, ptsect); - putdatas(pdatas, ptsize * 2048, mode, ptsect + ptsize); - root->buildpath(pdatas, ptsize * 2048, true); - putdatas(pdatas, ptsize * 2048, mode, ptsect + ptsize * 2); - putdatas(pdatas, ptsize * 2048, mode, ptsect + ptsize * 3); - free(pdatas); - - datas[0] = 1; - datas[1] = 67; - datas[2] = 68; - datas[3] = 48; - datas[4] = 48; - datas[5] = 49; - datas[6] = 1; - datas[7] = 0; - - sprintf(cdatas + 8, "%-32s", pvd.sysid.to_charp()); - sprintf(cdatas + 40, "%-32s", pvd.volid.to_charp()); - *((Uint32 *) (datas + 80)) = nsects; - *((Uint32 *) (datas + 84)) = cdutils::swap_dword(nsects); - - datas[120] = 1; - datas[121] = 0; - datas[122] = 0; - datas[123] = 1; - datas[124] = 1; - datas[125] = 0; - datas[126] = 0; - datas[127] = 1; - datas[128] = 0; - datas[129] = 8; - datas[130] = 8; - datas[131] = 0; - *((Uint32 *) (datas + 132)) = psize; - *((Uint32 *) (datas + 136)) = cdutils::swap_dword(psize); - *((Uint32 *) (datas + 140)) = ptsect; - *((Uint32 *) (datas + 144)) = ptsect + ptsize; - *((Uint32 *) (datas + 148)) = cdutils::swap_dword(ptsect + ptsize * 2); - *((Uint32 *) (datas + 152)) = cdutils::swap_dword(ptsect + ptsize * 3); - - root->buildentry(datas + 156, 34, false); - - sprintf(cdatas + 190, "%-128s", pvd.volsetid.to_charp()); - sprintf(cdatas + 318, "%-128s", pvd.pubid.to_charp()); - sprintf(cdatas + 446, "%-128s", pvd.prepid.to_charp()); - sprintf(cdatas + 574, "%-128s", pvd.appid.to_charp()); - sprintf(cdatas + 702, "%-37s", pvd.copyright.to_charp()); - sprintf(cdatas + 739, "%-37s", pvd.abstract.to_charp()); - sprintf(cdatas + 776, "%-37s", pvd.biblio.to_charp()); - - pvd.volcreat.dump(datas + 813); - pvd.modif.dump(datas + 830); - pvd.volexp.dump(datas + 847); - pvd.voleff.dump(datas + 864); - - memcpy(datas + 883, pvd.appdata, 512); - - clearEOF(); - sub_EOR = 1; - createsector(datas, mode, 16); - - memset(datas, 0, 2048); - datas[0] =255; - datas[1] = 67; - datas[2] = 68; - datas[3] = 48; - datas[4] = 48; - datas[5] = 49; - datas[6] = 1; - - setEOF(); - createsector(datas, mode); - - root->dumpdirs(this); - - closed = true; -} +/* + * 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.cpp,v 1.15 2004-11-27 21:47:56 pixel Exp $ */ + +#include "isobuilder.h" + +void isobuilder::Date::dump(Byte * datas) { + char pbuf[256]; + + sprintf(pbuf, "%04i", year); + memcpy(datas + 0, pbuf, 4); + sprintf(pbuf, "%02i", month); + memcpy(datas + 4, pbuf, 2); + sprintf(pbuf, "%02i", day); + memcpy(datas + 6, pbuf, 2); + sprintf(pbuf, "%02i", hour); + memcpy(datas + 8, pbuf, 2); + sprintf(pbuf, "%02i", minute); + memcpy(datas + 10, pbuf, 2); + sprintf(pbuf, "%02i", second); + memcpy(datas + 12, pbuf, 2); + sprintf(pbuf, "%02i", hundredths); + memcpy(datas + 14, pbuf, 2); + + *((char *) (datas + 16)) = offset; +} + +isobuilder::Date::Date(int) { + year = month = day = hour = minute = second = hundredths = offset = 0; +} + +isobuilder::Date::Date(Byte * datas) { + char pbuf[256]; + char * cdatas = (char *) datas; + + memcpy(pbuf, cdatas + 0, 4); + pbuf[4] = 0; + sscanf(pbuf, "%d", &year); + + memcpy(pbuf, cdatas + 4, 2); + pbuf[2] = 0; + sscanf(pbuf, "%d", &month); + + memcpy(pbuf, cdatas + 6, 2); + pbuf[2] = 0; + sscanf(pbuf, "%d", &day); + + memcpy(pbuf, cdatas + 8, 2); + pbuf[2] = 0; + sscanf(pbuf, "%d", &hour); + + memcpy(pbuf, cdatas + 10, 2); + pbuf[2] = 0; + sscanf(pbuf, "%d", &minute); + + memcpy(pbuf, cdatas + 12, 2); + pbuf[2] = 0; + sscanf(pbuf, "%d", &second); + + memcpy(pbuf, cdatas + 14, 2); + pbuf[2] = 0; + sscanf(pbuf, "%d", &hundredths); + + offset = *(cdatas + 16); +} + +isobuilder::DirTree::DirTree(isobuilder::DirTree * _father, bool _dir) : mode(-1), father(_father), dir(_dir) { + DirTree * p; + + child = brother = 0; + + if (!father) + return; + + creation = father->creation; + + if (father->child) { + for (p = father->child; p->brother; p = p->brother); + p->brother = this; + } else { + father->child = this; + } +} + +isobuilder::DirTree::~DirTree() { + while (child) { + delete child; + } + + if (!father) + return; + + if (father->child == this) { + father->child = brother; + } else { + // Dirty, should not happen. + DirTree * p; + for (p = father->child; p->brother != this; p = p->brother); + p->brother = brother; + } +} + +void isobuilder::DirTree::dumpdirs(isobuilder * builder) throw (GeneralException) { + Byte * dir, * odir; + int cursiz, cursectsize, R; + String oldname; + DirTree * p; + + odir = dir = (Byte *) malloc(cursiz = size); + cursectsize = 2048; + + oldname = name; + name = "."; + R = buildentry(dir, cursectsize); + name = oldname; + cursectsize -= R; + dir += R; + + if (father) { + oldname = father->name; + father->name = ".."; + R = father->buildentry(dir, cursectsize); + father->name = oldname; + } else { + name = ".."; + R = buildentry(dir, cursectsize); + name = "."; + } + + cursectsize -= R; + dir += R; + + for (p = child; p; p = p->brother) { + if (p->dir) { + p->dumpdirs(builder); + } + if (p->hardhide) + continue; + while (!(R = p->buildentry(dir, cursectsize))) { + cursiz -= 2048; + dir += cursectsize; + cursectsize = 2048; + if (!cursiz) + throw GeneralException("Directory is too small! Entries don't fit."); + } + cursectsize -= R; + dir += R; + } + + builder->putdatas(odir, size, mode, sector); + + free(odir); +} + +int isobuilder::DirTree::buildpath(Byte * datas, int size, bool bigendian) throw (GeneralException) { + int N, r, tr; + Uint16 pn; + char pbuf[256], pad; + + if (!dir) { + if (brother) { + return brother->buildpath(datas, size, bigendian); + } else { + return 0; + } + } + + if (!father) { + numerate(1); + N = 1; + pbuf[0] = 0; + pn = 1; + } else { + N = name.strlen(); + strcpy(pbuf, name.to_charp()); + pn = father->node; + } + + pad = N & 1; + size -= (r = N + pad + 8); + + if (size < 0) + throw GeneralException("Path table too small."); + + datas[0] = N; + datas[1] = 0; + *((Uint32 *) (datas + 2)) = bigendian ? cdutils::swap_dword(sector) : sector; + *((Uint16 *) (datas + 6)) = bigendian ? cdutils::swap_word(pn) : pn; + memcpy(datas + 8, pbuf, N); + if (pad) + datas[8 + N] = 0; + + datas += r; + + if (brother) { + tr = brother->buildpath(datas, size, bigendian); + r += tr; + size -= tr; + datas += tr; + } + + if (child) { + tr = child->buildpath(datas, size, bigendian); + r += tr; + size -= tr; + datas += tr; + } + + return r; +} + +int isobuilder::DirTree::buildentry(Byte * buffer, int spaceleft, bool put_xa) { + int N, R; + char pbuf[256], pad; + Byte * p; + cdutils::DirEntry * d = (cdutils::DirEntry *) buffer; + + put_xa = put_xa && have_xa; + + memset(pbuf, 0, 256); + + if (name == ".") { + N = 1; + pbuf[0] = 0; + } else if (name == "..") { + N = 1; + pbuf[0] = 1; + } else { + strcpy(pbuf, name.to_charp()); + N = name.strlen(); + if (!dir) { + N += 2; + strcat(pbuf, ";1"); + } + } + + R = N + 33; + + if (R & 1) { + R++; + pad = 1; + } else { + pad = 0; + } + + if (put_xa) { + R += 14; + p = (Byte *) pbuf + N + pad; + p[4] = 0x05; + p[5] = 0x55; + p[6] = 'X'; + p[7] = 'A'; + + p[4] |= xa_dir ? 0x80 : 0; + p[4] |= xa_audio ? 0x40 : 0; + p[4] |= xa_str ? 0x20 : 0; + p[4] |= xa_xa ? 0x10 : 0; + p[4] |= xa_form1 ? 0x08 : 0; + } + + if (R > spaceleft) { + return 0; + } + + memset(d, 0, R); + + d->R = R; + d->N = N; + memcpy(d->id, pbuf, N + pad + (put_xa ? 14 : 0)); + + d->Sector = sector; + d->BESector = cdutils::swap_dword(sector); + d->Size = size; + d->BESize = cdutils::swap_dword(size); + if (creation.year >= 1000) { + d->Year = creation.year - 1900; + } else { + d->Year = creation.year; + } + d->Month = creation.month; + d->Day = creation.day; + d->Hour = creation.hour; + d->Minute = creation.minute; + d->Second = creation.second; + d->Offset = creation.offset; + d->Flags |= hidden ? 1 : 0; + d->Flags |= dir ? 2 : 0; + + return R; +} + +void isobuilder::DirTree::fromdir(cdutils::DirEntry * d) { + Date t; + char pbuf[200], pad; + int s; + if ((!d) || (!d->R)) { + return; + } + + if ((d->N == 1) && (d->id[0] == 0)) { + name = "."; + } else if ((d->N == 1) && (d->id[0] == 1)) { + name = ".."; + } else { + memcpy(pbuf, d->id, s = (d->N - ((d->Flags & 2) ? 0 : 2))); + pbuf[s] = 0; + name = pbuf; + } + hidden = d->Flags & 1; + if (d->Year < 70) + d->Year += 100; + t.year = d->Year; + t.month = d->Month; + t.day = d->Day; + t.hour = d->Hour; + t.second = d->Second; + t.hundredths = 0; + t.offset = d->Offset; + creation = t; + + s = 33 + d->N; + if (s & 1) { + s++; + pad = 1; + } else { + pad = 0; + } + if (s != d->R) { + if ((s + 14) == d->R) { + Byte * p; + p = (Byte *) d->id + d->N + pad; + if ((p[6] == 'X') && (p[7] == 'A')) { + have_xa = true; + xa_dir = p[4] & 0x80; + xa_audio = p[4] & 0x40; + xa_str = p[4] & 0x20; + xa_xa = p[4] & 0x10; + xa_form1 = p[4] & 0x08; + } + } + } +} + +bool isobuilder::DirTree::isdir() { + return dir; +} + +void isobuilder::DirTree::setbasicsxa() { + have_xa = true; + if (dir) + xa_dir = true; + xa_form1 = true; +} + +int isobuilder::DirTree::numerate(int n) { + if (!dir) { + if (brother) { + return brother->numerate(n); + } else { + return n; + } + } + + node = n++; + + if (brother) + n = brother->numerate(n); + + if (child) + n = child->numerate(n); + + return n; +} + +isobuilder::DirTree * isobuilder::DirTree::Father() { + return father; +} + +isobuilder::DirTree * isobuilder::DirTree::Brother() { + return brother; +} + +isobuilder::DirTree * isobuilder::DirTree::Child() { + return child; +} + +isobuilder::DirTree * isobuilder::DirTree::Find(const String & _name) { + DirTree * p = 0; + + if (name == _name) + return this; + + if (brother) + p = brother->Find(_name); + + if (!p && child) + return child->Find(_name); + + return p; +} + +isobuilder::isobuilder(Handle * _w, int _mode) : w(_w), sector(0), nsectors(0), basics(false), dmode(_mode) { + Byte sect[2352]; + memset(sect, 0, 2352); + + for (int i = 0; i < 16; i++) { + createsector(sect, MODE2, i); + } +} + +isobuilder::~isobuilder() { + if (!closed) + close(); + if (root) + delete root; +} + +void isobuilder::foreword(cdutils * cd) { + Byte sect[2352]; + for (int i = 0; i < 16; i++) { + cd->read_sector(sect, MODE_RAW, i); + createsector(sect, MODE_RAW, i); + } +} + +void isobuilder::foreword(Handle * forewords, int mode) { + Byte sect[2352]; + for (int i = 0; i < 16; i++) { + forewords->read(sect, sec_sizes[mode]); + createsector(sect, mode, i); + } +} + +void isobuilder::foreword(Byte * forewords, int mode) { + for (int i = 0; i < 16; i++) { + createsector(forewords + i * sec_sizes[mode], mode, i); + } +} + +int isobuilder::getdispsect() { + return lastdispsect; +} + +int isobuilder::putfile(Handle * file, int mode, int n) { + Byte datas[2352]; + ssize_t filesize; + int fsect; + + if (mode < 0) + mode = dmode; + + if (n >= 0) { + sector = n; + } else { + sector = lastdispsect; + } + + fsect = sector; + + filesize = file->GetSize(); + + while (filesize > 0) { + memset(datas, 0, 2352); + filesize -= file->read(datas, sec_sizes[mode]); + if ((mode == MODE2_FORM1) || (mode == MODE2_FORM2)) { + if (filesize) { + clearEOF(); + } else { + setEOF(); + } + } + createsector(datas, mode); + } + + return fsect; +} + +int isobuilder::putdatas(Byte * _datas, size_t size, int smode, int n) { + Byte datas[2352]; + size_t eating; + int dsect; + if (n >= 0) { + sector = n; + } else { + sector = lastdispsect; + } + + dsect = sector; + + if (smode < 0) + smode = dmode; + + while (size > 0) { + memset(datas, 0, 2352); + eating = MIN(size, (size_t) sec_sizes[smode]); + memcpy(datas, _datas, eating); + size -= eating; + _datas += eating; + if ((smode == MODE2_FORM1) || (smode == MODE2_FORM2)) { + if (size) { + clearEOF(); + } else { + setEOF(); + } + } + createsector(datas, smode); + } + + return dsect; +} + +int isobuilder::createsector(Byte * datas, int smode, int n) { + Byte dsector[2352]; + int rsector; + if (n >= 0) + sector = n; + + if (smode < 0) + smode = dmode; + + rsector = sector; + + w->seek(2352 * sector, SEEK_SET); + + memcpy(dsector + sec_offsts[smode], datas, sec_sizes[smode]); + + if ((smode == MODE2_FORM1) || (smode == MODE2_FORM2)) { + // Mode 2 Form 2 would be odd, but well.... + dsector[16] = dsector[20] = 0; // File Number + dsector[17] = dsector[21] = 0; // Channel Number + dsector[18] = dsector[22] = sub_EOR | sub_EOF | 8 | + (smode == MODE2_FORM2 ? 32 : 0); + dsector[19] = dsector[23] = 0; // Coding Info + } + + if (smode != MODE_RAW) { + sector += 150; + yazedc_o.minute = cdutils::to_BCD(sector / 60 / 75); + yazedc_o.second = cdutils::to_BCD((sector / 75) % 60); + yazedc_o.frame = cdutils::to_BCD(sector % 75); + sector -= 150; + yazedc_o.do_encode_L2(dsector, smode, 0); + } + + w->write(dsector, 2352); + + sector++; + + nsectors = MAX(nsectors, sector); + lastdispsect = MAX(lastdispsect, sector); + + return rsector; +} + +void isobuilder::setEOF() { + sub_EOF = 128; + sub_EOR = 1; +} + +void isobuilder::clearEOF() { + sub_EOF = sub_EOR = 0; +} + +isobuilder::DirTree * isobuilder::setbasics(PVD _pvd, int _rootsize, int _ptsize, int _nvd, int _rootsect) throw (GeneralException) { + if (basics) { + throw GeneralException("Basic ISO structures already set"); + } + basics = true; + + pvd = _pvd; + rootsize = _rootsize; + ptsize = _ptsize; + nvd = _nvd; + + ptsect = 17 + nvd; + rootsect = ptsect + ptsize * 4; + if (_rootsect >= 0) + rootsect = _rootsect; + lastdispsect = rootsect + rootsize; + + root = new DirTree(0); + root->name = "."; + root->creation = pvd.volcreat; + root->sector = rootsect; + root->size = rootsize * 2048; + return root; +} + +isobuilder::DirTree * isobuilder::createdir(DirTree * p, const String & _name, int size, cdutils::DirEntry * d, int mode) throw (GeneralException) { + DirTree * r; + + if (!p) + throw GeneralException("Empty father"); + + if (closed) + throw GeneralException("ISO is closed"); + + if (!basics) + throw GeneralException("ISO basis not created (no root!)"); + + r = new DirTree(p); + + r->creation = p->creation; + if (d) + r->fromdir(d); + if (_name != "") + r->name = _name; + r->size = size * 2048; + if (!r->size) + r->size = d->Size; + r->sector = lastdispsect; + if (mode >= 0) + r->mode = mode; + else + r->mode = dmode; + + lastdispsect += size; + + return r; +} + +isobuilder::DirTree * isobuilder::createfile(DirTree * p, Handle * file, const String & _name, cdutils::DirEntry * d, int mode) throw (GeneralException) { + DirTree * r; + + if (!p) + throw GeneralException("Empty father"); + + if (closed) + throw GeneralException("ISO is closed"); + + if (!basics) + throw GeneralException("ISO basis not created (no root!)"); + + r = new DirTree(p, false); + + r->name = _name; + r->creation = p->creation; + r->fromdir(d); + if (_name != "") + r->name = _name; + r->size = file->GetSize(); + r->sector = putfile(file, mode); + if (mode >= 0) + r->mode = mode; + else + r->mode = dmode; + + return r; +} + +void isobuilder::copydir(isobuilder::DirTree * r, cdutils * cd, cdutils::DirEntry * d, int mode) { + Byte datas[2048]; + cdutils::DirEntry * p; + int nsectors = d->Size / 2048, ssize, c = 0; + int fsize, osize; + + if (mode < 0) + mode = dmode; + + while (nsectors) { + cd->read_sector(datas, mode, d->Sector + c++); + nsectors--; + p = (cdutils::DirEntry *) datas; + ssize = 2048; + while ((ssize) && (p->R)) { + ssize -= p->R; + char pbuf[256]; + memcpy(pbuf, p->id, p->N); + pbuf[p->N] = 0; + if (p->Flags & 2) { + if (!((p->N == 1) && ((p->id[0] == 0) || (p->id[0] == 1)))) + copydir(createdir(r, "", p->Size / 2048, p, mode), cd, p, mode); + } else { + printm(M_INFO, "Dupping %s\n", pbuf); + int fmode; + osize = fsize = p->Size; + if (mode == MODE1) { + fmode = mode; + } else { + fmode = MODE2_FORM1; + int s, pad; + s = 33 + p->N; + if (s & 1) { + s++; + pad = 1; + } else { + pad = 0; + } + if ((s != p->R) && ((s + 14) == p->R)) { + if (!(p->id[p->N + pad + 4] & 8)) { + fmode = MODE2; + fsize = (p->Size / 2048) * 2336; + } + } + } + p->Size = fsize; + cdfile * tmp = new cdfile(cd, p, fmode); + createfile(r, tmp, "", p, fmode)->size = osize; + delete tmp; + p->Size = osize; + } + p = (cdutils::DirEntry *) (((Byte *) p) + p->R); + } + } +} + +isobuilder::PVD isobuilder::createpvd(Handle * f) { + Byte datas[2048]; + f->read(datas, 2048); + return createpvd(datas); +} + +isobuilder::PVD isobuilder::createpvd(cdutils * cd) { + Byte datas[2048]; + cd->read_sector(datas, GUESS, 16); + return createpvd(datas); +} + +isobuilder::PVD isobuilder::createpvd(Byte * buffer) { + PVD r; + char pbuff[256]; + + memcpy(pbuff, buffer + 8, 32); + pbuff[32] = 0; + r.sysid = pbuff; + r.sysid.rtrim(); + memcpy(pbuff, buffer + 40, 32); + pbuff[32] = 0; + r.volid = pbuff; + r.volid.rtrim(); + memcpy(pbuff, buffer + 190, 128); + pbuff[128] = 0; + r.volsetid = pbuff; + r.volsetid.rtrim(); + memcpy(pbuff, buffer + 318, 128); + pbuff[128] = 0; + r.pubid = pbuff; + r.pubid.rtrim(); + memcpy(pbuff, buffer + 446, 128); + pbuff[128] = 0; + r.prepid = pbuff; + r.prepid.rtrim(); + memcpy(pbuff, buffer + 574, 128); + pbuff[128] = 0; + r.appid = pbuff; + r.appid.rtrim(); + memcpy(pbuff, buffer + 702, 37); + pbuff[37] = 0; + r.copyright = pbuff; + r.copyright.rtrim(); + memcpy(pbuff, buffer + 739, 37); + pbuff[37] = 0; + r.abstract = pbuff; + r.abstract.rtrim(); + memcpy(pbuff, buffer + 776, 37); + pbuff[37] = 0; + r.biblio = pbuff; + r.biblio.rtrim(); + + r.volcreat = Date(buffer + 813); + r.modif = Date(buffer + 830); + r.volexp = Date(buffer + 847); + r.voleff = Date(buffer + 864); + + memcpy(r.appdata, buffer + 883, 512); + + return r; +} + +void isobuilder::close(Handle * cue, int mode, int nsects) throw (GeneralException) { + Byte datas[2048]; + Byte * pdatas; + char * cdatas = (char *) datas; + int psize; + + if (nsects < 0) + nsects = nsectors; + + memset(datas, 0, 2048); + + pdatas = (Byte *) malloc(ptsize * 2048); + psize = root->buildpath(pdatas, ptsize * 2048); + putdatas(pdatas, ptsize * 2048, mode, ptsect); + putdatas(pdatas, ptsize * 2048, mode, ptsect + ptsize); + root->buildpath(pdatas, ptsize * 2048, true); + putdatas(pdatas, ptsize * 2048, mode, ptsect + ptsize * 2); + putdatas(pdatas, ptsize * 2048, mode, ptsect + ptsize * 3); + free(pdatas); + + datas[0] = 1; + datas[1] = 67; + datas[2] = 68; + datas[3] = 48; + datas[4] = 48; + datas[5] = 49; + datas[6] = 1; + datas[7] = 0; + + sprintf(cdatas + 8, "%-32s", pvd.sysid.to_charp()); + sprintf(cdatas + 40, "%-32s", pvd.volid.to_charp()); + *((Uint32 *) (datas + 80)) = nsects; + *((Uint32 *) (datas + 84)) = cdutils::swap_dword(nsects); + + datas[120] = 1; + datas[121] = 0; + datas[122] = 0; + datas[123] = 1; + datas[124] = 1; + datas[125] = 0; + datas[126] = 0; + datas[127] = 1; + datas[128] = 0; + datas[129] = 8; + datas[130] = 8; + datas[131] = 0; + *((Uint32 *) (datas + 132)) = psize; + *((Uint32 *) (datas + 136)) = cdutils::swap_dword(psize); + *((Uint32 *) (datas + 140)) = ptsect; + *((Uint32 *) (datas + 144)) = ptsect + ptsize; + *((Uint32 *) (datas + 148)) = cdutils::swap_dword(ptsect + ptsize * 2); + *((Uint32 *) (datas + 152)) = cdutils::swap_dword(ptsect + ptsize * 3); + + root->buildentry(datas + 156, 34, false); + + sprintf(cdatas + 190, "%-128s", pvd.volsetid.to_charp()); + sprintf(cdatas + 318, "%-128s", pvd.pubid.to_charp()); + sprintf(cdatas + 446, "%-128s", pvd.prepid.to_charp()); + sprintf(cdatas + 574, "%-128s", pvd.appid.to_charp()); + sprintf(cdatas + 702, "%-37s", pvd.copyright.to_charp()); + sprintf(cdatas + 739, "%-37s", pvd.abstract.to_charp()); + sprintf(cdatas + 776, "%-37s", pvd.biblio.to_charp()); + + pvd.volcreat.dump(datas + 813); + pvd.modif.dump(datas + 830); + pvd.volexp.dump(datas + 847); + pvd.voleff.dump(datas + 864); + + memcpy(datas + 883, pvd.appdata, 512); + + clearEOF(); + sub_EOR = 1; + createsector(datas, mode, 16); + + memset(datas, 0, 2048); + datas[0] =255; + datas[1] = 67; + datas[2] = 68; + datas[3] = 48; + datas[4] = 48; + datas[5] = 49; + datas[6] = 1; + + setEOF(); + createsector(datas, mode); + + root->dumpdirs(this); + + closed = true; +} diff --git a/lib/luacd.cpp b/lib/luacd.cpp index e4e2b23..c330921 100644 --- a/lib/luacd.cpp +++ b/lib/luacd.cpp @@ -1,1661 +1,1661 @@ -/* - * 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.cpp,v 1.14 2004-10-19 15:58:42 pixel Exp $ */ - -#include "luacd.h" - - - /**************************\ -|** class cdutils exports **| - \**************************/ - -Luacdutils::Luacdutils(cdutils * _cd) : cd(_cd) { } -class Luacdfile : public LuaHandle { - public: - Luacdfile(cdfile * h) : LuaHandle(h) {} -}; - -enum cdutils_methods_t { - CDUTILS_SETISOW = 0, - CDUTILS_GUESSTYPE, - CDUTILS_SECTORSEEK, - CDUTILS_READSECTOR, - CDUTILS_READDATAS, - CDUTILS_READFILE, - CDUTILS_WRITESECTOR, - CDUTILS_WRITEDATAS, - CDUTILS_WRITEFILE, - CDUTILS_GETISOINFOS, - CDUTILS_GETPTINFOS, - CDUTILS_FINDPATH, - CDUTILS_FINDPARENT, - CDUTILS_FINDDIRENTRY, - CDUTILS_NEWCDFILE, - CDUTILS_UPDATESIZE, - CDUTILS_UPDATESECTOR, - CDUTILS_CREATESECTOR, -}; - -enum cdutils_functions_t { - CDUTILS_NEWCDUTILS = 0, - CDUTILS_SWAPWORD, - CDUTILS_SWAPDWORD, - CDUTILS_FROM_BCD, - CDUTILS_TO_BCD, - CDUTILS_IS_VALID_BCD, - CDUTILS_FROM_MSF, - CDUTILS_TO_MSF, -}; - -struct lua_functypes_t cdutils_methods[] = { - { CDUTILS_SETISOW, "set_iso_w", 1, 1, {LUA_OBJECT} }, - { CDUTILS_GUESSTYPE, "guessmode", 0, 1, {LUA_NUMBER} }, - { CDUTILS_SECTORSEEK, "sectorseek", 1, 1, {LUA_NUMBER} }, - { CDUTILS_READSECTOR, "readsector", 0, 2, {LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_READDATAS, "readdatas", 1, 3, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_READFILE, "readfile", 2, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_WRITESECTOR, "writesector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_WRITEDATAS, "writedatas", 2, 4, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_WRITEFILE, "writefile", 1, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_GETISOINFOS, "getisoinfos", 0, 0, 0 }, - { CDUTILS_GETPTINFOS, "getptinfos", 0, 0, 0 }, - { CDUTILS_FINDPATH, "findpath", 1, 1, {LUA_STRING} }, - { CDUTILS_FINDPARENT, "findparent", 1, 1, {LUA_STRING} }, - { CDUTILS_FINDDIRENTRY, "finddirentry", 2, 2, {LUA_OBJECT, LUA_STRING} }, - { CDUTILS_NEWCDFILE, "cdfile", 1, 3, {LUA_ANY, LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_UPDATESIZE, "updatesize", 2, 2, {LUA_STRING, LUA_NUMBER} }, - { CDUTILS_UPDATESECTOR, "updatesector", 2, 2, {LUA_STRING, LUA_NUMBER} }, - { CDUTILS_CREATESECTOR, "createsector", 2, 3, {LUA_NUMBER, LUA_NUMBER, LUA_BOOLEAN} }, - { -1, 0, 0, 0, 0 } -}; - -struct lua_functypes_t cdutils_functions[] = { - { CDUTILS_NEWCDUTILS, "cdutils" , 1, 2, {LUA_OBJECT, LUA_OBJECT} }, - { CDUTILS_SWAPWORD, "swapword", 1, 1, {LUA_NUMBER} }, - { CDUTILS_SWAPDWORD, "swapdword", 1, 1, {LUA_NUMBER} }, - { CDUTILS_FROM_BCD, "from_BCD", 1, 1, {LUA_NUMBER} }, - { CDUTILS_TO_BCD, "to_BCD", 1, 1, {LUA_NUMBER} }, - { CDUTILS_IS_VALID_BCD, "is_valid_BCD", 1, 1, {LUA_NUMBER} }, - { CDUTILS_FROM_MSF, "from_MSF", 1, 4, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_TO_MSF, "to_MSF", 1, 2, {LUA_NUMBER, LUA_NUMBER} }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_cdutils : public Base { - public: - DECLARE_METHOD(cdutils, CDUTILS_SETISOW); - DECLARE_METHOD(cdutils, CDUTILS_GUESSTYPE); - DECLARE_METHOD(cdutils, CDUTILS_SECTORSEEK); - DECLARE_METHOD(cdutils, CDUTILS_READSECTOR); - DECLARE_METHOD(cdutils, CDUTILS_READDATAS); - DECLARE_METHOD(cdutils, CDUTILS_READFILE); - DECLARE_METHOD(cdutils, CDUTILS_WRITESECTOR); - DECLARE_METHOD(cdutils, CDUTILS_WRITEDATAS); - DECLARE_METHOD(cdutils, CDUTILS_WRITEFILE); - DECLARE_METHOD(cdutils, CDUTILS_GETISOINFOS); - DECLARE_METHOD(cdutils, CDUTILS_GETPTINFOS); - DECLARE_METHOD(cdutils, CDUTILS_FINDPATH); - DECLARE_METHOD(cdutils, CDUTILS_FINDPARENT); - DECLARE_METHOD(cdutils, CDUTILS_FINDDIRENTRY); - DECLARE_METHOD(cdutils, CDUTILS_NEWCDFILE); - DECLARE_METHOD(cdutils, CDUTILS_UPDATESIZE); - DECLARE_METHOD(cdutils, CDUTILS_UPDATESECTOR); - DECLARE_METHOD(cdutils, CDUTILS_CREATESECTOR); - - DECLARE_FUNCTION(cdutils, CDUTILS_NEWCDUTILS); - DECLARE_FUNCTION(cdutils, CDUTILS_SWAPWORD); - DECLARE_FUNCTION(cdutils, CDUTILS_SWAPDWORD); - DECLARE_FUNCTION(cdutils, CDUTILS_FROM_BCD); - DECLARE_FUNCTION(cdutils, CDUTILS_TO_BCD); - DECLARE_FUNCTION(cdutils, CDUTILS_IS_VALID_BCD); - DECLARE_FUNCTION(cdutils, CDUTILS_FROM_MSF); - DECLARE_FUNCTION(cdutils, CDUTILS_TO_MSF); - - private: - static int cdutils_proceed(Lua * L, int n, cdutils * obj, int caller); - static int cdutils_proceed_statics(Lua * L, int n, int caller); -}; - -void Luacdutils::pushmembers(Lua * L) { - pushme(L, cd); - - PUSH_METHOD(cdutils, CDUTILS_SETISOW); - PUSH_METHOD(cdutils, CDUTILS_GUESSTYPE); - PUSH_METHOD(cdutils, CDUTILS_SECTORSEEK); - PUSH_METHOD(cdutils, CDUTILS_READSECTOR); - PUSH_METHOD(cdutils, CDUTILS_READDATAS); - PUSH_METHOD(cdutils, CDUTILS_READFILE); - PUSH_METHOD(cdutils, CDUTILS_WRITESECTOR); - PUSH_METHOD(cdutils, CDUTILS_WRITEDATAS); - PUSH_METHOD(cdutils, CDUTILS_WRITEFILE); - PUSH_METHOD(cdutils, CDUTILS_GETISOINFOS); - PUSH_METHOD(cdutils, CDUTILS_GETPTINFOS); - PUSH_METHOD(cdutils, CDUTILS_FINDPATH); - PUSH_METHOD(cdutils, CDUTILS_FINDPARENT); - PUSH_METHOD(cdutils, CDUTILS_FINDDIRENTRY); - PUSH_METHOD(cdutils, CDUTILS_NEWCDFILE); - PUSH_METHOD(cdutils, CDUTILS_UPDATESIZE); - PUSH_METHOD(cdutils, CDUTILS_UPDATESECTOR); - PUSH_METHOD(cdutils, CDUTILS_CREATESECTOR); -} - -void Luacdutils::pushstatics(Lua * L) throw (GeneralException) { - CHECK_METHODS(cdutils); - CHECK_FUNCTIONS(cdutils); - - PUSH_FUNCTION(cdutils, CDUTILS_NEWCDUTILS); - PUSH_FUNCTION(cdutils, CDUTILS_SWAPWORD); - PUSH_FUNCTION(cdutils, CDUTILS_SWAPDWORD); - PUSH_FUNCTION(cdutils, CDUTILS_FROM_BCD); - PUSH_FUNCTION(cdutils, CDUTILS_TO_BCD); - PUSH_FUNCTION(cdutils, CDUTILS_IS_VALID_BCD); - PUSH_FUNCTION(cdutils, CDUTILS_FROM_MSF); - PUSH_FUNCTION(cdutils, CDUTILS_TO_MSF); - - L->push("MODE0"); - L->push((lua_Number) MODE0); - L->setvar(); - - L->push("MODE1"); - L->push((lua_Number) MODE1); - L->setvar(); - - L->push("MODE2"); - L->push((lua_Number) MODE2); - L->setvar(); - - L->push("MODE2_FORM1"); - L->push((lua_Number) MODE2_FORM1); - L->setvar(); - - L->push("MODE2_FORM2"); - L->push((lua_Number) MODE2_FORM2); - L->setvar(); - - L->push("MORE_RAW"); - L->push((lua_Number) MODE_RAW); - L->setvar(); - - L->push("GUESS"); - L->push((lua_Number) GUESS); - L->setvar(); - - int i; - - L->push("sec_sizes"); - L->newtable(); - for (i = 0; i <= GUESS; i++) { - L->push((lua_Number) i); - L->push((lua_Number) sec_sizes[i]); - L->settable(); - } - L->setvar(); - - L->push("sec_offsts"); - L->newtable(); - for (i = 0; i <= GUESS; i++) { - L->push((lua_Number) i); - L->push((lua_Number) sec_offsts[i]); - L->settable(); - } - L->setvar(); - - L->push("sec_modes"); - L->newtable(); - for (i = 0; i <= GUESS; i++) { - L->push((lua_Number) i); - L->push(sec_modes[i]); - L->settable(); - } - L->setvar(); -} - -int sLua_cdutils::cdutils_proceed(Lua * L, int n, cdutils * cd, int caller) { - int r = 0, sect = -1, mode = GUESS, size = -1, i; - Handle * h; - Byte sdatas[2352], * datas; - String path; - cdutils::DirEntry * dir, * bdir, * adir, pdir; - bool invalid = false, eof = false; - int sector; - cdfile * cdf; - - switch(caller) { - case CDUTILS_SETISOW: - h = (Handle *) LuaObject::getme(L, 2); - cd->set_iso_w(h); - break; - case CDUTILS_GUESSTYPE: - if (n == 1) { - sect = L->tonumber(2); - } - L->push((lua_Number) cd->guess_type(sect)); - r = 1; - break; - case CDUTILS_SECTORSEEK: - sect = L->tonumber(2); - cd->sector_seek(sect); - break; - case CDUTILS_READSECTOR: - if (n >= 1) - sect = L->tonumber(2); - if (n == 2) - mode = L->tonumber(3); - size = cd->read_sector(sdatas, mode, sect); - L->newtable(); - for (i = 0; i < size; i++) { - L->push((lua_Number) i); - L->push((lua_Number) sdatas[i]); - L->settable(); - } - r = 1; - break; - case CDUTILS_READDATAS: - size = L->tonumber(2); - if (n >= 2) - sect = L->tonumber(3); - if (n == 3) - mode = L->tonumber(3); - datas = (Byte *) malloc(size); - cd->read_datas(datas, size, mode, sect); - L->newtable(); - for (i = 0; i < size; i++) { - L->push((lua_Number) i); - L->push((lua_Number) datas[i]); - L->settable(); - } - r = 1; - free(datas); - break; - case CDUTILS_READFILE: - h = (Handle *) LuaObject::getme(L, 2); - size = L->tonumber(5); - if (n >= 3) - sect = L->tonumber(4); - if (n == 4) - mode = L->tonumber(5); - cd->read_file(h, size, mode, sect); - break; - case CDUTILS_WRITESECTOR: - if (n >= 2) - sect = L->tonumber(3); - if (n == 3) - mode = L->tonumber(4); - for (i = 0; i < 2352; i++) { - L->push((lua_Number) i); - L->gettable(2); - sdatas[i] = L->tonumber(); - L->pop(); - } - cd->write_sector(datas, mode, sect); - break; - case CDUTILS_WRITEDATAS: - size = L->tonumber(3); - if (n >= 3) - sect = L->tonumber(4); - if (n == 4) - mode = L->tonumber(5); - datas = (Byte *) malloc(size); - - for (i = 0; i < size; i++) { - L->push((lua_Number) i); - L->gettable(2); - sdatas[i] = L->tonumber(); - L->pop(); - } - cd->write_datas(datas, size, mode, sect); - free(datas); - break; - case CDUTILS_WRITEFILE: - h = (Handle *) LuaObject::getme(L, 2); - if (n >= 2) - size = L->tonumber(3); - if (n >= 3) - sect = L->tonumber(4); - if (n == 4) - mode = L->tonumber(5); - cd->write_file(h, size, mode, sect); - break; - case CDUTILS_GETISOINFOS: - L->push((lua_Number) cd->get_iso_infos()); - r = 1; - break; - case CDUTILS_GETPTINFOS: - L->push((lua_Number) cd->get_pt_infos()); - r = 1; - break; - case CDUTILS_FINDPATH: - path = L->tostring(2); - bdir = cd->find_path(&datas, path); - if ((bdir) && bdir->R) { - dir = (cdutils::DirEntry *) malloc(bdir->R); - memcpy(dir, bdir, bdir->R); - } else { - dir = 0; - } - if (dir) { - Luadirentry ldir(dir); - ldir.pushdestruct(L); - } else { - L->push(); - } - r = 1; - free(datas); - break; - case CDUTILS_FINDPARENT: - path = L->tostring(2); - bdir = cd->find_parent(&datas, path); - if ((bdir) && bdir->R) { - dir = (cdutils::DirEntry *) malloc(bdir->R); - memcpy(dir, bdir, bdir->R); - } else { - dir = 0; - } - if (dir) { - Luadirentry ldir(dir); - ldir.pushdestruct(L); - } else { - L->push(); - } - r = 1; - free(datas); - break; - case CDUTILS_FINDDIRENTRY: - adir = (cdutils::DirEntry *) LuaObject::getme(L, 2); - path = L->tostring(3); - bdir = cd->find_dir_entry(&datas, adir, path); - if ((bdir) && bdir->R) { - dir = (cdutils::DirEntry *) malloc(bdir->R); - memcpy(dir, bdir, bdir->R); - } else { - dir = 0; - } - if (dir) { - Luadirentry ldir(dir); - ldir.pushdestruct(L); - } else { - L->push(); - } - r = 1; - free(datas); - break; - case CDUTILS_NEWCDFILE: - if (L->istable(2)) { - if (n <= 2) { - dir = (cdutils::DirEntry *) LuaObject::getme(L, 2); - if (n == 2) - mode = L->tonumber(3); - cdf = new cdfile(cd, dir, mode); - } else { - invalid = true; - } - } else if (L->isnumber(2)) { - if (n >= 1) { - sector = L->tonumber(2); - if (n >= 2) - size = L->tonumber(3); - if (n == 3) - mode = L->tonumber(4); - cdf = new cdfile(cd, sector, size, mode); - } else { - invalid = true; - } - } else { - invalid = true; - } - if (invalid) { - L->error("Invalid arguments to constructor of cdfile"); - } else { - Luacdfile luacdf(cdf); - luacdf.pushdestruct(L); - r = 1; - } - break; - case CDUTILS_UPDATESIZE: - case CDUTILS_UPDATESECTOR: - path = L->tostring(2); - pdir = cd->find_parent(path); - dir = cd->find_path(&datas, path); - switch (caller) { - case CDUTILS_UPDATESIZE: - dir->Size = tolittle((Uint32) L->tonumber(3)); - dir->BESize = tobig((Uint32) L->tonumber(3)); - break; - case CDUTILS_UPDATESECTOR: - dir->Sector = tolittle((Uint32) L->tonumber(3)); - dir->BESector = tobig((Uint32) L->tonumber(3)); - break; - } - cd->write_datas(datas, pdir.Size, GUESS, pdir.Sector); - free(datas); - break; - case CDUTILS_CREATESECTOR: - mode = L->tonumber(2); - sect = L->tonumber(3); - if (n == 3) - eof = L->toboolean(4); - cd->create_sector(mode, sect, eof); - break; - } - - - return r; -} - -int sLua_cdutils::cdutils_proceed_statics(Lua * L, int n, int caller) { - int r = 0; - Uint32 x; - Handle * isor = 0, * isow = 0; - Uint32 sector, msf, start = 150; - Byte m, s, f; - - switch(caller) { - case CDUTILS_NEWCDUTILS: - isor = (Handle *) LuaObject::getme(L, 1); - if (n == 2) - isow = (Handle *) LuaObject::getme(L, 2); - { - Luacdutils cd(new cdutils(isor, isow)); - cd.pushdestruct(L); - } - break; - case CDUTILS_SWAPWORD: - x = L->tonumber(); - L->push((lua_Number) cdutils::swap_word(x)); - r = 1; - break; - case CDUTILS_SWAPDWORD: - x = L->tonumber(); - L->push((lua_Number) cdutils::swap_dword(x)); - r = 1; - break; - case CDUTILS_FROM_BCD: - x = L->tonumber(); - L->push((lua_Number) cdutils::from_BCD(x)); - r = 1; - break; - case CDUTILS_TO_BCD: - x = L->tonumber(); - L->push((lua_Number) cdutils::to_BCD(x)); - r = 1; - break; - case CDUTILS_IS_VALID_BCD: - x = L->tonumber(); - L->push(cdutils::is_valid_BCD(x)); - r = 1; - break; - case CDUTILS_FROM_MSF: - if (n <= 2) { - msf = L->tonumber(1); - if (n == 2) - start = L->tonumber(2); - L->push((lua_Number) cdutils::from_MSF(msf, start)); - } else { - m = L->tonumber(1); - s = L->tonumber(2); - f = L->tonumber(3); - if (n == 4) - start = L->tonumber(4); - L->push((lua_Number) cdutils::from_MSF(m, s, f, start)); - } - r = 1; - break; - case CDUTILS_TO_MSF: - sector = L->tonumber(1); - if (n == 2) - start = L->tonumber(2); - cdutils::to_MSF(sector, m, s, f, start); - msf = cdutils::to_MSF(sector, start); - L->push((lua_Number) msf); - L->push((lua_Number) m); - L->push((lua_Number) s); - L->push((lua_Number) f); - r = 4; - break; - } - - return r; -} - - - /***************************\ -|** class direntry exports **| - \***************************/ - -typedef cdutils::DirEntry direntry; - -Luadirentry::Luadirentry(cdutils::DirEntry * _dir) : dir(_dir) { } - -enum direntry_methods_t { - DIRENTRY_INDEX = 0, - DIRENTRY_ISHIDDEN, - DIRENTRY_ISDIR, - DIRENTRY_HASXA, - DIRENTRY_ISXADIR, - DIRENTRY_ISXAAUDIO, - DIRENTRY_ISXASTR, - DIRENTRY_ISXAXA, - DIRENTRY_ISXAFORM1, -}; - -struct lua_functypes_t direntry_methods[] = { - { DIRENTRY_INDEX, "index", 1, 1, {LUA_STRING} }, - { DIRENTRY_ISHIDDEN, "ishidden", 0, 0, 0 }, - { DIRENTRY_ISDIR, "isdir", 0, 0, 0 }, - { DIRENTRY_HASXA, "hasxa", 0, 0, 0 }, - { DIRENTRY_ISXADIR, "isxadir", 0, 0, 0 }, - { DIRENTRY_ISXAAUDIO, "isxaaudio", 0, 0, 0 }, - { DIRENTRY_ISXASTR, "isxastr", 0, 0, 0 }, - { DIRENTRY_ISXAXA, "isxaxa", 0, 0, 0 }, - { DIRENTRY_ISXAFORM1, "isxaform1", 0, 0, 0 }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_direntry : public Base { - public: - DECLARE_METHOD(direntry, DIRENTRY_INDEX); - DECLARE_METHOD(direntry, DIRENTRY_ISHIDDEN); - DECLARE_METHOD(direntry, DIRENTRY_ISDIR); - DECLARE_METHOD(direntry, DIRENTRY_HASXA); - DECLARE_METHOD(direntry, DIRENTRY_ISXADIR); - DECLARE_METHOD(direntry, DIRENTRY_ISXAAUDIO); - DECLARE_METHOD(direntry, DIRENTRY_ISXASTR); - DECLARE_METHOD(direntry, DIRENTRY_ISXAXA); - DECLARE_METHOD(direntry, DIRENTRY_ISXAFORM1); - private: - static int direntry_proceed(Lua * L, int n, direntry * obj, int caller); -}; - -void Luadirentry::pushmembers(Lua * L) { - pushme(L, dir, false); - - PUSH_METAMETHOD(direntry, DIRENTRY_INDEX); - PUSH_METHOD(direntry, DIRENTRY_ISHIDDEN); - PUSH_METHOD(direntry, DIRENTRY_ISDIR); - PUSH_METHOD(direntry, DIRENTRY_HASXA); - PUSH_METHOD(direntry, DIRENTRY_ISXADIR); - PUSH_METHOD(direntry, DIRENTRY_ISXAAUDIO); - PUSH_METHOD(direntry, DIRENTRY_ISXASTR); - PUSH_METHOD(direntry, DIRENTRY_ISXAXA); - PUSH_METHOD(direntry, DIRENTRY_ISXAFORM1); -} - -int sLua_direntry::direntry_proceed(Lua * L, int n, direntry * dir, int caller) { - int r = 0, s, pad; - String index; - bool has_xa = false; - Byte * p; - - s = 33 + dir->N; - if (s & 1) { - s++; - pad = 1; - } else { - pad = 0; - } - if (s != dir->R) { - if ((s + 14) == dir->R) { - p = (Byte *) dir->id + dir->N + pad; - if ((p[6] == 'X') && (p[7] == 'A')) { - has_xa = true; - } - } - } - - switch (caller) { - case DIRENTRY_HASXA: - L->push(has_xa); - r = 1; - break; - case DIRENTRY_ISHIDDEN: - L->push(dir->Flags & 1 ? true : false); - r = 1; - break; - case DIRENTRY_ISDIR: - L->push(dir->Flags & 2 ? true : false); - r = 1; - break; - case DIRENTRY_ISXADIR: - L->push(p[4] & 0x80 ? true : false); - r = 1; - break; - case DIRENTRY_ISXAAUDIO: - L->push(p[4] & 0x40 ? true : false); - r = 1; - break; - case DIRENTRY_ISXASTR: - L->push(p[4] & 0x20 ? true : false); - r = 1; - break; - case DIRENTRY_ISXAXA: - L->push(p[4] & 0x10 ? true : false); - r = 1; - break; - case DIRENTRY_ISXAFORM1: - L->push(p[4] & 0x08 ? true : false); - r = 1; - break; - case DIRENTRY_INDEX: - index = L->tostring(); - r = 1; - if (index == "R") { - L->push((lua_Number) dir->R); - } else if (index == "NExt") { - L->push((lua_Number) dir->NExt); - } else if (index == "Sector") { - L->push((lua_Number) dir->Sector); - } else if (index == "Size") { - L->push((lua_Number) dir->Size); - } else if (index == "Year") { - L->push((lua_Number) dir->Year); - } else if (index == "Month") { - L->push((lua_Number) dir->Month); - } else if (index == "Day") { - L->push((lua_Number) dir->Day); - } else if (index == "Hour") { - L->push((lua_Number) dir->Hour); - } else if (index == "Minute") { - L->push((lua_Number) dir->Minute); - } else if (index == "Second") { - L->push((lua_Number) dir->Second); - } else if (index == "Offset") { - L->push((lua_Number) dir->Offset); - } else if (index == "Flags") { - L->push((lua_Number) dir->Flags); - } else if (index == "HandleUnit") { - L->push((lua_Number) dir->HandleUnit); - } else if (index == "HandleGap") { - L->push((lua_Number) dir->HandleGap); - } else if (index == "VolSeq") { - L->push((lua_Number) dir->VolSeq); - } else if (index == "N") { - L->push((lua_Number) dir->N); - } else if (index == "id") { - char pbuf[256]; - memcpy(pbuf, dir->id, dir->N); - pbuf[dir->N] = 0; - L->push(pbuf, dir->N); - } else { - L->push(); - } - } - - return r; -} - - - /***************************\ -|** class direntry exports **| - \***************************/ - -typedef isobuilder::Date cddate; - -Luacddate::Luacddate(isobuilder::Date * _date) : date(_date) { } - -enum cddate_methods_t { - CDDATE_INDEX = 0, - CDDATE_NEWINDEX, -}; - -enum cddate_functions_t { - CDDATE_NEWCDDATE = 0, -}; - -struct lua_functypes_t cddate_methods[] = { - { CDDATE_INDEX, "index", 1, 1, {LUA_STRING} }, - { CDDATE_NEWINDEX, "newindex", 2, 2, {LUA_STRING, LUA_NUMBER} }, - { -1, 0, 0, 0, 0 } -}; - -struct lua_functypes_t cddate_functions[] = { - { CDDATE_NEWCDDATE, "cddate", 0, 0, 0 }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_cddate : public Base { - public: - DECLARE_METHOD(cddate, CDDATE_INDEX); - DECLARE_METHOD(cddate, CDDATE_NEWINDEX); - DECLARE_FUNCTION(cddate, CDDATE_NEWCDDATE); - private: - static int cddate_proceed(Lua * L, int n, cddate * obj, int caller); - static int cddate_proceed_statics(Lua * L, int n, int caller); -}; - -void Luacddate::pushmembers(Lua * L) { - pushme(L, date, false); - - PUSH_METAMETHOD(cddate, CDDATE_INDEX); - PUSH_METAMETHOD(cddate, CDDATE_NEWINDEX); -} - -void Luacddate::pushstatics(Lua * L) throw (GeneralException) { - CHECK_METHODS(cddate); - CHECK_FUNCTIONS(cddate); - - PUSH_FUNCTION(cddate, CDDATE_NEWCDDATE); -} - -int sLua_cddate::cddate_proceed(Lua * L, int n, cddate * date, int caller) { - int r, value; - String key; - - switch (caller) { - case CDDATE_INDEX: - key = L->tostring(2); - r = 1; - if (key == "year") { - L->push((lua_Number) date->year); - } else if (key == "month") { - L->push((lua_Number) date->month); - } else if (key == "day") { - L->push((lua_Number) date->day); - } else if (key == "hour") { - L->push((lua_Number) date->hour); - } else if (key == "minute") { - L->push((lua_Number) date->minute); - } else if (key == "second") { - L->push((lua_Number) date->second); - } else if (key == "hundredths") { - L->push((lua_Number) date->hundredths); - } else if (key == "offset") { - L->push((lua_Number) date->offset); - } else { - L->error("Key " + key + " not in class Date"); - } - break; - case CDDATE_NEWINDEX: - r = 0; - key = L->tostring(2); - value = L->tonumber(3); - if (key == "year") { - date->year = value; - } else if (key == "month") { - date->month = value; - } else if (key == "day") { - date->day = value; - } else if (key == "hour") { - date->hour = value; - } else if (key == "minute") { - date->minute = value; - } else if (key == "second") { - date->second = value; - } else if (key == "hundredths") { - date->hundredths = value; - } else if (key == "offset") { - date->offset = value; - } else { - L->error("Key " + key + " not in class Date"); - } - break; - } - - return r; -} - -int sLua_cddate::cddate_proceed_statics(Lua * L, int n, int caller) { - int r = 0; - - switch (caller) { - case CDDATE_NEWCDDATE: - { - Luacddate t(new isobuilder::Date()); - t.pushdestruct(L); - } - } - - return r; -} - - /**********************\ -|** class PVD exports **| - \**********************/ - -typedef isobuilder::PVD PVD; - -LuaPVD::LuaPVD(struct isobuilder::PVD * _pvd) : pvd(_pvd) { } - -enum PVD_methods_t { - PVD_INDEX = 0, - PVD_NEWINDEX, -}; - -enum PVD_functions_t { - PVD_NEWPVD = 0, -}; - -struct lua_functypes_t PVD_methods[] = { - { PVD_INDEX, "index", 1, 1, {LUA_ANY} }, - { PVD_NEWINDEX, "newindex", 2, 2, {LUA_ANY, LUA_ANY} }, - { -1, 0, 0, 0, 0 } -}; - -struct lua_functypes_t PVD_functions[] = { - { PVD_NEWPVD, "PVD", 0, 0, 0 }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_PVD : public Base { - public: - DECLARE_METHOD(PVD, PVD_INDEX); - DECLARE_METHOD(PVD, PVD_NEWINDEX); - - DECLARE_FUNCTION(PVD, PVD_NEWPVD); - - private: - static int PVD_proceed(Lua * L, int n, PVD * obj, int caller); - static int PVD_proceed_statics(Lua * L, int n, int caller); -}; - -void LuaPVD::pushmembers(Lua * L) { - pushme(L, pvd, false); - - PUSH_METAMETHOD(PVD, PVD_INDEX); - PUSH_METAMETHOD(PVD, PVD_NEWINDEX); -} - -void LuaPVD::pushstatics(Lua * L) throw (GeneralException) { - CHECK_METHODS(PVD); - CHECK_FUNCTIONS(PVD); - - PUSH_FUNCTION(PVD, PVD_NEWPVD); -} - -int sLua_PVD::PVD_proceed(Lua * L, int n, PVD * pvd, int caller) { - int r = 0, key_i = 0, value_i; - String key_s, value_s; - cddate * value_date; - bool invalid = false, keyisstring; - - if (L->isnumber(2)) { - keyisstring = false; - key_i = L->tonumber(2); - } else { - keyisstring = true; - key_s = L->tostring(2); - } - - switch (caller) { - case PVD_INDEX: - r = 1; - if (keyisstring && (key_s == "sysid")) { - L->push(pvd->sysid); - } else if (keyisstring && (key_s == "volid")) { - L->push(pvd->volid); - } else if (keyisstring && (key_s == "volsetid")) { - L->push(pvd->volsetid); - } else if (keyisstring && (key_s == "pubid")) { - L->push(pvd->pubid); - } else if (keyisstring && (key_s == "prepid")) { - L->push(pvd->prepid); - } else if (keyisstring && (key_s == "appid")) { - L->push(pvd->appid); - } else if (keyisstring && (key_s == "copyright")) { - L->push(pvd->copyright); - } else if (keyisstring && (key_s == "abstract")) { - L->push(pvd->abstract); - } else if (keyisstring && (key_s == "biblio")) { - L->push(pvd->biblio); - } else if (keyisstring && (key_s == "volcreat")) { - { - Luacddate date(&pvd->volcreat); - date.push(L); - } - } else if (keyisstring && (key_s == "modif")) { - { - Luacddate date(&pvd->modif); - date.push(L); - } - } else if (keyisstring && (key_s == "volexp")) { - { - Luacddate date(&pvd->volexp); - date.push(L); - } - } else if (keyisstring && (key_s == "voleff")) { - { - Luacddate date(&pvd->voleff); - date.push(L); - } - } else if (!keyisstring && (key_i >= 0) && (key_i < 512)) { - L->push((lua_Number) pvd->appdata[key_i]); - } else { - invalid = true; - } - break; - case PVD_NEWINDEX: - if (keyisstring && (key_s == "sysid")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->sysid = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "volid")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->volid = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "volsetid")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->volsetid = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "pubid")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->pubid = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "prepid")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->prepid = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "appid")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->appid = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "copyright")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->copyright = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "abstract")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->abstract = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "biblio")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->biblio = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "volcreat")) { - if (L->islightuserdata(3)) { - value_date = (cddate *) LuaObject::getme(L, 3); - pvd->volcreat = *value_date; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "modif")) { - if (L->islightuserdata(3)) { - value_date = (cddate *) LuaObject::getme(L, 3); - pvd->modif = *value_date; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "volexp")) { - if (L->islightuserdata(3)) { - value_date = (cddate *) LuaObject::getme(L, 3); - pvd->volexp = *value_date; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "voleff")) { - if (L->islightuserdata(3)) { - value_date = (cddate *) LuaObject::getme(L, 3); - pvd->voleff = *value_date; - } else { - invalid = true; - } - } else if (!keyisstring && (key_i >= 0) && (key_i < 512)) { - if (L->isnumber(3)) { - pvd->appdata[key_i] = L->tonumber(3); - } else { - invalid = true; - } - } else { - invalid = true; - } - break; - } - - if (invalid) { - L->error("Invalid usage of structure PVD"); - } - - return r; -} - -int sLua_PVD::PVD_proceed_statics(Lua * L, int n, int caller) { - int r = 0; - - switch (caller) { - case PVD_NEWPVD: - r = 1; - { - LuaPVD pvd((PVD *) malloc(sizeof(PVD))); - pvd.pushdestruct(L); - } - break; - } - - return r; -} - - - /**************************\ -|** class DirTree exports **| - \**************************/ - -typedef isobuilder::DirTree DirTree; - -LuaDirTree::LuaDirTree(isobuilder::DirTree * _dir) : dir(_dir) { } - -enum DirTree_methods_t { - DIRTREE_INDEX = 0, - DIRTREE_NEWINDEX, - DIRTREE_FROMDIR, - DIRTREE_SETBASICSXA, - DIRTREE_FIND, -}; - -enum DirTree_functions_t { - DIRTREE_NEWDIRTREE = 0, -}; - -struct lua_functypes_t DirTree_methods[] = { - { DIRTREE_INDEX, "index", 1, 1, {LUA_STRING} }, - { DIRTREE_NEWINDEX, "newindex", 2, 2, {LUA_STRING, LUA_ANY} }, - { DIRTREE_FROMDIR, "fromdir", 1, 1, {LUA_OBJECT} }, - { DIRTREE_SETBASICSXA, "setbasicsxa", 0, 0, 0 }, - { DIRTREE_FIND, "find", 1, 1, {LUA_STRING} }, - { -1, 0, 0, 0, 0 } -}; - -struct lua_functypes_t DirTree_functions[] = { - { DIRTREE_NEWDIRTREE, "DirTree", 1, 2, {LUA_OBJECT, LUA_BOOLEAN} }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_DirTree : public Base { - public: - DECLARE_METHOD(DirTree, DIRTREE_INDEX); - DECLARE_METHOD(DirTree, DIRTREE_NEWINDEX); - DECLARE_METHOD(DirTree, DIRTREE_FROMDIR); - DECLARE_METHOD(DirTree, DIRTREE_SETBASICSXA); - DECLARE_METHOD(DirTree, DIRTREE_FIND); - - DECLARE_FUNCTION(DirTree, DIRTREE_NEWDIRTREE); - private: - static int DirTree_proceed(Lua * L, int n, DirTree * obj, int caller); - static int DirTree_proceed_statics(Lua * L, int n, int caller); -}; - -void LuaDirTree::pushmembers(Lua * L) { - pushme(L, dir); - - PUSH_METAMETHOD(DirTree, DIRTREE_INDEX); - PUSH_METAMETHOD(DirTree, DIRTREE_NEWINDEX); - - PUSH_METHOD(DirTree, DIRTREE_FROMDIR); - PUSH_METHOD(DirTree, DIRTREE_SETBASICSXA); - PUSH_METHOD(DirTree, DIRTREE_FIND); -} - -void LuaDirTree::pushstatics(Lua * L) throw (GeneralException) { - CHECK_METHODS(DirTree); - CHECK_FUNCTIONS(DirTree); - - PUSH_FUNCTION(DirTree, DIRTREE_NEWDIRTREE); -} - -int sLua_DirTree::DirTree_proceed(Lua * L, int n, DirTree * dir, int caller) { - int r = 0, value_i; - direntry * dirent; - DirTree * rdir; - String f, key, value_s; - bool invalid = false, value_b; - cddate * value_date; - - switch (caller) { - case DIRTREE_FROMDIR: - dirent = (direntry *) LuaObject::getme(L, 2); - dir->fromdir(dirent); - break; - case DIRTREE_SETBASICSXA: - dir->setbasicsxa(); - break; - case DIRTREE_FIND: - f = L->tostring(2); - rdir = dir->Find(f); - if (rdir) { - LuaDirTree dirt(rdir); - dirt.push(L); - } else { - L->push(); - } - break; - case DIRTREE_INDEX: - key = L->tostring(2); - r = 1; - if (key == "sector") { - L->push((lua_Number) dir->sector); - } else if (key == "size") { - L->push((lua_Number) dir->size); - } else if (key == "hidden") { - L->push(dir->hidden); - } else if (key == "hardhide") { - L->push(dir->hardhide); - } else if (key == "name") { - L->push(dir->name); - } else if (key == "creation") { - Luacddate date(&dir->creation); - date.push(L); - } else if (key == "have_xa") { - L->push(dir->have_xa); - } else if (key == "xa_dir") { - L->push(dir->xa_dir); - } else if (key == "xa_audio") { - L->push(dir->xa_audio); - } else if (key == "xa_str") { - L->push(dir->xa_str); - } else if (key == "xa_xa") { - L->push(dir->xa_xa); - } else if (key == "xa_form1") { - L->push(dir->xa_form1); - } else if (key == "mode") { - L->push((lua_Number) dir->mode); - } else if (key == "father") { - LuaDirTree tdir(dir->Father()); - tdir.push(L); - } else if (key == "child") { - LuaDirTree tdir(dir->Child()); - tdir.push(L); - } else if (key == "brother") { - LuaDirTree tdir(dir->Brother()); - tdir.push(L); - } else if (key == "isdir") { - L->push(dir->isdir()); - } else { - invalid = true; - } - break; - case DIRTREE_NEWINDEX: - key = L->tostring(2); - if (key == "sector") { - if (L->isnumber(3)) { - value_i = L->tonumber(3); - dir->sector = value_i; - } else { - invalid = true; - } - } else if (key == "size") { - if (L->isnumber(3)) { - value_i = L->tonumber(3); - dir->size = value_i; - } else { - invalid = true; - } - } else if (key == "hidden") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->hidden = value_b; - } else { - invalid = true; - } - } else if (key == "hardhide") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->hardhide = value_b; - } else { - invalid = true; - } - } else if (key == "name") { - if (L->isstring(3)) { - value_s = L->tostring(3); - dir->name = value_s; - } else { - invalid = true; - } - } else if (key == "creation") { - if (L->islightuserdata(3)) { - value_date = (cddate *) LuaObject::getme(L, 3); - dir->creation = *value_date; - } else { - invalid = true; - } - } else if (key == "have_xa") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->have_xa = value_b; - } else { - invalid = true; - } - } else if (key == "xa_dir") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->xa_dir = value_b; - } else { - invalid = true; - } - } else if (key == "xa_audio") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->xa_audio = value_b; - } else { - invalid = true; - } - } else if (key == "xa_str") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->xa_str = value_b; - } else { - invalid = true; - } - } else if (key == "xa_xa") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->xa_xa = value_b; - } else { - invalid = true; - } - } else if (key == "xa_form1") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->xa_form1 = value_b; - } else { - invalid = true; - } - } else if (key == "mode") { - if (L->isnumber(3)) { - value_i = L->tonumber(3); - dir->mode = value_i; - } else { - invalid = true; - } - } else { - invalid = true; - } - break; - } - - if (invalid) { - L->error("Invalid usage of structure DirTree"); - } - - return r; -} - -int sLua_DirTree::DirTree_proceed_statics(Lua * L, int n, int caller) { - int r; - DirTree * father; - bool dir = true; - - switch (caller) { - case DIRTREE_NEWDIRTREE: - father = (DirTree *) LuaObject::getme(L, 1); - if (n == 2) - dir = L->toboolean(2); - { - LuaDirTree dirt(new DirTree(father, dir)); - dirt.pushdestruct(L); - } - break; - } - - return r; -} - - - /*****************************\ -|** class isobuilder exports **| - \*****************************/ - -Luaisobuilder::Luaisobuilder(isobuilder * _iso) : iso(_iso) { } - -enum isobuilder_methods_t { - ISOBUILDER_FOREWORD = 0, - ISOBUILDER_FOREWORD_HANDLE, - ISOBUILDER_FOREWORD_ARRAY, - ISOBUILDER_GETDISPSECT, - ISOBUILDER_PUTFILE, - ISOBUILDER_PUTDATAS, - ISOBUILDER_CREATESECTOR, - ISOBUILDER_SETEOF, - ISOBUILDER_CLEAREOF, - ISOBUILDER_SETBASICS, - ISOBUILDER_CREATEDIR, - ISOBUILDER_CREATEFILE, - ISOBUILDER_COPYDIR, - ISOBUILDER_CLOSE, -}; - -enum isobuilder_functions_t { - ISOBUILDER_NEWISOBUILDER = 0, - ISOBUILDER_CREATEPVD_HANDLE, - ISOBUILDER_CREATEPVD, - ISOBUILDER_CREATEPVD_ARRAY, -}; - -struct lua_functypes_t isobuilder_methods[] = { - { ISOBUILDER_FOREWORD, "foreword", 1, 1, {LUA_OBJECT} }, - { ISOBUILDER_FOREWORD_HANDLE, "foreword_handle", 1, 2, {LUA_OBJECT, LUA_NUMBER} }, - { ISOBUILDER_FOREWORD_ARRAY, "foreword_array", 1, 2, {LUA_TABLE, LUA_NUMBER} }, - { ISOBUILDER_GETDISPSECT, "getdispsect", 0, 0, 0}, - { ISOBUILDER_PUTFILE, "putfile", 1, 3, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER} }, - { ISOBUILDER_PUTDATAS, "putdatas", 2, 4, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, - { ISOBUILDER_CREATESECTOR, "createsector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} }, - { ISOBUILDER_SETEOF, "setEOF", 0, 0, 0 }, - { ISOBUILDER_CLEAREOF, "clearEOF", 0, 0, 0 }, - { ISOBUILDER_SETBASICS, "setbasics", 1, 5, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, - { ISOBUILDER_CREATEDIR, "createdir", 2, 5, {LUA_OBJECT, LUA_STRING, LUA_NUMBER, LUA_OBJECT, LUA_NUMBER} }, - { ISOBUILDER_CREATEFILE, "createfile", 3, 5, {LUA_OBJECT, LUA_STRING, LUA_OBJECT, LUA_OBJECT, LUA_NUMBER} }, - { ISOBUILDER_COPYDIR, "copydir", 3, 4, {LUA_OBJECT, LUA_OBJECT, LUA_OBJECT, LUA_NUMBER} }, - { ISOBUILDER_CLOSE, "close", 0, 3, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER} }, - { -1, 0, 0, 0, 0 } -}; - -struct lua_functypes_t isobuilder_functions[] = { - { ISOBUILDER_NEWISOBUILDER, "isobuilder", 1, 2, {LUA_OBJECT, LUA_NUMBER} }, - { ISOBUILDER_CREATEPVD_HANDLE, "createpvd_handle", 1, 1, {LUA_OBJECT} }, - { ISOBUILDER_CREATEPVD, "createpvd", 1, 1, {LUA_OBJECT} }, - { ISOBUILDER_CREATEPVD_ARRAY, "createpvd_array", 1, 1, {LUA_TABLE} }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_isobuilder : public Base { +/* + * 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.cpp,v 1.15 2004-11-27 21:47:56 pixel Exp $ */ + +#include "luacd.h" + + + /**************************\ +|** class cdutils exports **| + \**************************/ + +Luacdutils::Luacdutils(cdutils * _cd) : cd(_cd) { } +class Luacdfile : public LuaHandle { public: - DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD); - DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD_HANDLE); - DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD_ARRAY); - DECLARE_METHOD(isobuilder, ISOBUILDER_GETDISPSECT); - DECLARE_METHOD(isobuilder, ISOBUILDER_PUTFILE); - DECLARE_METHOD(isobuilder, ISOBUILDER_PUTDATAS); - DECLARE_METHOD(isobuilder, ISOBUILDER_CREATESECTOR); - DECLARE_METHOD(isobuilder, ISOBUILDER_SETEOF); - DECLARE_METHOD(isobuilder, ISOBUILDER_CLEAREOF); - DECLARE_METHOD(isobuilder, ISOBUILDER_SETBASICS); - DECLARE_METHOD(isobuilder, ISOBUILDER_CREATEDIR); - DECLARE_METHOD(isobuilder, ISOBUILDER_CREATEFILE); - DECLARE_METHOD(isobuilder, ISOBUILDER_COPYDIR); - DECLARE_METHOD(isobuilder, ISOBUILDER_CLOSE); - - DECLARE_FUNCTION(isobuilder, ISOBUILDER_NEWISOBUILDER); - DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_HANDLE); - DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD); - DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_ARRAY); - - private: - static int isobuilder_proceed(Lua * L, int n, isobuilder * obj, int caller); - static int isobuilder_proceed_statics(Lua * L, int n, int caller); + Luacdfile(cdfile * h) : LuaHandle(h) {} }; - -void Luaisobuilder::pushmembers(Lua * L) { - pushme(L, iso); - - PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD); - PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD_HANDLE); - PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD_ARRAY); - PUSH_METHOD(isobuilder, ISOBUILDER_GETDISPSECT); - PUSH_METHOD(isobuilder, ISOBUILDER_PUTFILE); - PUSH_METHOD(isobuilder, ISOBUILDER_PUTDATAS); - PUSH_METHOD(isobuilder, ISOBUILDER_CREATESECTOR); - PUSH_METHOD(isobuilder, ISOBUILDER_SETEOF); - PUSH_METHOD(isobuilder, ISOBUILDER_CLEAREOF); - PUSH_METHOD(isobuilder, ISOBUILDER_SETBASICS); - PUSH_METHOD(isobuilder, ISOBUILDER_CREATEDIR); - PUSH_METHOD(isobuilder, ISOBUILDER_CREATEFILE); - PUSH_METHOD(isobuilder, ISOBUILDER_COPYDIR); - PUSH_METHOD(isobuilder, ISOBUILDER_CLOSE); -} - -void Luaisobuilder::pushstatics(Lua * L) throw (GeneralException) { - CHECK_METHODS(isobuilder); - CHECK_FUNCTIONS(isobuilder); - - PUSH_FUNCTION(isobuilder, ISOBUILDER_NEWISOBUILDER); - PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_HANDLE); - PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD); - PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_ARRAY); -} - -int sLua_isobuilder::isobuilder_proceed(Lua * L, int n, isobuilder * iso, int caller) { - int r = 0, i; - Handle * h = 0; - int mode = -1, sector = -1, rootsize = 1, ptsize = 1, nvd = 1, rootsect = -1, nsects = -1; - size_t size; - Byte datas[2352 * 16], * p; - PVD * pvd; - DirTree * dirt, * rdir; - direntry * dire = 0; - String name; - cdutils * cd; - - switch (caller) { - case ISOBUILDER_FOREWORD: - cd = (cdutils *) LuaObject::getme(L, 2); - iso->foreword(cd); - break; - case ISOBUILDER_FOREWORD_HANDLE: - mode = MODE_RAW; - h = (Handle *) LuaObject::getme(L, 2); - if (n == 2) - mode = L->tonumber(3); - iso->foreword(h, mode); - break; - case ISOBUILDER_FOREWORD_ARRAY: - mode = MODE_RAW; - if (n == 2) - mode = L->tonumber(3); - for (i = 0; i < 16 * 2352; i++) { - L->push((lua_Number) i); - L->gettable(2); - datas[i] = L->tonumber(); - L->pop(); - } - iso->foreword(datas, mode); - break; - case ISOBUILDER_GETDISPSECT: - L->push((lua_Number) iso->getdispsect()); - r = 1; - break; - case ISOBUILDER_PUTFILE: - h = (Handle *) LuaObject::getme(L, 2); - if (n >= 2) - mode = L->tonumber(3); - if (n >= 3) - sector = L->tonumber(4); - L->push((lua_Number) iso->putfile(h, mode, sector)); - r = 1; - break; - case ISOBUILDER_PUTDATAS: - size = L->tonumber(3); - if (n >= 3) - mode = L->tonumber(4); - if (n >= 4) - sector = L->tonumber(5); - p = (Byte *) malloc(size); - for (i = 0; i < size; i++) { - L->push((lua_Number) i); - L->gettable(2); - p[i] = L->tonumber(); - L->pop(); - } - L->push((lua_Number) iso->putdatas(p, size, mode, sector)); - r = 1; - free(p); - break; - case ISOBUILDER_CREATESECTOR: - if (n >= 2) - mode = L->tonumber(3); - if (n >= 3) - sector = L->tonumber(4); - for (i = 0; i < 2352; i++) { - L->push((lua_Number) i); - L->gettable(2); - datas[i] = L->tonumber(); - L->pop(); - } - L->push((lua_Number) iso->createsector(datas, mode, sector)); - r = 1; - break; - case ISOBUILDER_SETEOF: - iso->setEOF(); - break; - case ISOBUILDER_CLEAREOF: - iso->clearEOF(); - break; - case ISOBUILDER_SETBASICS: - pvd = (PVD *) LuaObject::getme(L, 2); - if (n >= 2) - rootsize = L->tonumber(3); - if (n >= 3) - ptsize = L->tonumber(4); - if (n >= 4) - nvd = L->tonumber(5); - if (n >= 5) - rootsect = L->tonumber(6); - rdir = iso->setbasics(*pvd, rootsize, ptsize, nvd, rootsect); - { - LuaDirTree t(rdir); - t.push(L); - } - r = 1; - break; - case ISOBUILDER_CREATEDIR: - size = 1; - dirt = 0; - dirt = (DirTree *) LuaObject::getme(L, 2); - name = L->tostring(3); - if (n >= 3) - size = L->tonumber(4); - if (n >= 4) - dire = (direntry *) LuaObject::getme(L, 5); - if (n >= 5) - mode = L->tonumber(6); - rdir = iso->createdir(dirt, name, size, dire, mode); - { - LuaDirTree t(rdir); - t.push(L); - } - r = 1; - break; - case ISOBUILDER_CREATEFILE: - dirt = (DirTree *) LuaObject::getme(L, 2); - name = L->tostring(3); - h = (Handle *) LuaObject::getme(L, 4); - if (n >= 4) - dire = (direntry *) LuaObject::getme(L, 5); - if (n >= 5) - mode = L->tonumber(6); - rdir = iso->createfile(dirt, h, name, dire, mode); - { - LuaDirTree t(rdir); - t.push(L); - } - r = 1; - break; - case ISOBUILDER_COPYDIR: - dirt = (DirTree *) LuaObject::getme(L, 2); - cd = (cdutils *) LuaObject::getme(L, 3); - dire = (direntry *) LuaObject::getme(L, 4); - if (n >= 4) - mode = L->tonumber(5); - iso->copydir(dirt, cd, dire, mode); - break; - case ISOBUILDER_CLOSE: - if (n >= 1) - h = (Handle *) LuaObject::getme(L, 2); - if (n >= 2) - mode = L->tonumber(3); - if (n >= 3) - nsects = L->tonumber(4); - iso->close(h, mode, nsects); - break; - } - - return r; -} - -int sLua_isobuilder::isobuilder_proceed_statics(Lua * L, int n, int caller) { - int r = 0, i; - Handle * h; - int mode = MODE2_FORM1; - cdutils * cd; - Byte datas[2048]; - PVD * pvd; - - switch (caller) { - case ISOBUILDER_NEWISOBUILDER: - h = (Handle *) LuaObject::getme(L, 1); - if (n >= 2) - mode = L->tonumber(); - { - Luaisobuilder t(new isobuilder(h, mode)); - t.pushdestruct(L); - } - r = 1; - break; - case ISOBUILDER_CREATEPVD_HANDLE: - h = (Handle *) LuaObject::getme(L, 1); - pvd = (PVD *) malloc(sizeof(PVD)); - *pvd = isobuilder::createpvd(h); - { - LuaPVD t(pvd); - t.pushdestruct(L); - } - r = 1; - break; - case ISOBUILDER_CREATEPVD: - cd = (cdutils *) LuaObject::getme(L, 1); - pvd = (PVD *) malloc(sizeof(PVD)); - *pvd = isobuilder::createpvd(cd); - { - LuaPVD t(pvd); - t.pushdestruct(L); - } - r = 1; - break; - case ISOBUILDER_CREATEPVD_ARRAY: - for (i = 0; i < 2048; i++) { - L->push((lua_Number) i); - L->gettable(1); - datas[i] = L->tonumber(); - L->pop(); - } - pvd = (PVD *) malloc(sizeof(PVD)); - *pvd = isobuilder::createpvd(datas); - { - LuaPVD t(pvd); - t.pushdestruct(L); - } - r = 1; - break; - } - - return r; -} + +enum cdutils_methods_t { + CDUTILS_SETISOW = 0, + CDUTILS_GUESSTYPE, + CDUTILS_SECTORSEEK, + CDUTILS_READSECTOR, + CDUTILS_READDATAS, + CDUTILS_READFILE, + CDUTILS_WRITESECTOR, + CDUTILS_WRITEDATAS, + CDUTILS_WRITEFILE, + CDUTILS_GETISOINFOS, + CDUTILS_GETPTINFOS, + CDUTILS_FINDPATH, + CDUTILS_FINDPARENT, + CDUTILS_FINDDIRENTRY, + CDUTILS_NEWCDFILE, + CDUTILS_UPDATESIZE, + CDUTILS_UPDATESECTOR, + CDUTILS_CREATESECTOR, +}; + +enum cdutils_functions_t { + CDUTILS_NEWCDUTILS = 0, + CDUTILS_SWAPWORD, + CDUTILS_SWAPDWORD, + CDUTILS_FROM_BCD, + CDUTILS_TO_BCD, + CDUTILS_IS_VALID_BCD, + CDUTILS_FROM_MSF, + CDUTILS_TO_MSF, +}; + +struct lua_functypes_t cdutils_methods[] = { + { CDUTILS_SETISOW, "set_iso_w", 1, 1, {LUA_OBJECT} }, + { CDUTILS_GUESSTYPE, "guessmode", 0, 1, {LUA_NUMBER} }, + { CDUTILS_SECTORSEEK, "sectorseek", 1, 1, {LUA_NUMBER} }, + { CDUTILS_READSECTOR, "readsector", 0, 2, {LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_READDATAS, "readdatas", 1, 3, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_READFILE, "readfile", 2, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_WRITESECTOR, "writesector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_WRITEDATAS, "writedatas", 2, 4, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_WRITEFILE, "writefile", 1, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_GETISOINFOS, "getisoinfos", 0, 0, 0 }, + { CDUTILS_GETPTINFOS, "getptinfos", 0, 0, 0 }, + { CDUTILS_FINDPATH, "findpath", 1, 1, {LUA_STRING} }, + { CDUTILS_FINDPARENT, "findparent", 1, 1, {LUA_STRING} }, + { CDUTILS_FINDDIRENTRY, "finddirentry", 2, 2, {LUA_OBJECT, LUA_STRING} }, + { CDUTILS_NEWCDFILE, "cdfile", 1, 3, {LUA_ANY, LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_UPDATESIZE, "updatesize", 2, 2, {LUA_STRING, LUA_NUMBER} }, + { CDUTILS_UPDATESECTOR, "updatesector", 2, 2, {LUA_STRING, LUA_NUMBER} }, + { CDUTILS_CREATESECTOR, "createsector", 2, 3, {LUA_NUMBER, LUA_NUMBER, LUA_BOOLEAN} }, + { -1, 0, 0, 0, 0 } +}; + +struct lua_functypes_t cdutils_functions[] = { + { CDUTILS_NEWCDUTILS, "cdutils" , 1, 2, {LUA_OBJECT, LUA_OBJECT} }, + { CDUTILS_SWAPWORD, "swapword", 1, 1, {LUA_NUMBER} }, + { CDUTILS_SWAPDWORD, "swapdword", 1, 1, {LUA_NUMBER} }, + { CDUTILS_FROM_BCD, "from_BCD", 1, 1, {LUA_NUMBER} }, + { CDUTILS_TO_BCD, "to_BCD", 1, 1, {LUA_NUMBER} }, + { CDUTILS_IS_VALID_BCD, "is_valid_BCD", 1, 1, {LUA_NUMBER} }, + { CDUTILS_FROM_MSF, "from_MSF", 1, 4, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { CDUTILS_TO_MSF, "to_MSF", 1, 2, {LUA_NUMBER, LUA_NUMBER} }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_cdutils : public Base { + public: + DECLARE_METHOD(cdutils, CDUTILS_SETISOW); + DECLARE_METHOD(cdutils, CDUTILS_GUESSTYPE); + DECLARE_METHOD(cdutils, CDUTILS_SECTORSEEK); + DECLARE_METHOD(cdutils, CDUTILS_READSECTOR); + DECLARE_METHOD(cdutils, CDUTILS_READDATAS); + DECLARE_METHOD(cdutils, CDUTILS_READFILE); + DECLARE_METHOD(cdutils, CDUTILS_WRITESECTOR); + DECLARE_METHOD(cdutils, CDUTILS_WRITEDATAS); + DECLARE_METHOD(cdutils, CDUTILS_WRITEFILE); + DECLARE_METHOD(cdutils, CDUTILS_GETISOINFOS); + DECLARE_METHOD(cdutils, CDUTILS_GETPTINFOS); + DECLARE_METHOD(cdutils, CDUTILS_FINDPATH); + DECLARE_METHOD(cdutils, CDUTILS_FINDPARENT); + DECLARE_METHOD(cdutils, CDUTILS_FINDDIRENTRY); + DECLARE_METHOD(cdutils, CDUTILS_NEWCDFILE); + DECLARE_METHOD(cdutils, CDUTILS_UPDATESIZE); + DECLARE_METHOD(cdutils, CDUTILS_UPDATESECTOR); + DECLARE_METHOD(cdutils, CDUTILS_CREATESECTOR); + + DECLARE_FUNCTION(cdutils, CDUTILS_NEWCDUTILS); + DECLARE_FUNCTION(cdutils, CDUTILS_SWAPWORD); + DECLARE_FUNCTION(cdutils, CDUTILS_SWAPDWORD); + DECLARE_FUNCTION(cdutils, CDUTILS_FROM_BCD); + DECLARE_FUNCTION(cdutils, CDUTILS_TO_BCD); + DECLARE_FUNCTION(cdutils, CDUTILS_IS_VALID_BCD); + DECLARE_FUNCTION(cdutils, CDUTILS_FROM_MSF); + DECLARE_FUNCTION(cdutils, CDUTILS_TO_MSF); + + private: + static int cdutils_proceed(Lua * L, int n, cdutils * obj, int caller); + static int cdutils_proceed_statics(Lua * L, int n, int caller); +}; + +void Luacdutils::pushmembers(Lua * L) { + pushme(L, cd); + + PUSH_METHOD(cdutils, CDUTILS_SETISOW); + PUSH_METHOD(cdutils, CDUTILS_GUESSTYPE); + PUSH_METHOD(cdutils, CDUTILS_SECTORSEEK); + PUSH_METHOD(cdutils, CDUTILS_READSECTOR); + PUSH_METHOD(cdutils, CDUTILS_READDATAS); + PUSH_METHOD(cdutils, CDUTILS_READFILE); + PUSH_METHOD(cdutils, CDUTILS_WRITESECTOR); + PUSH_METHOD(cdutils, CDUTILS_WRITEDATAS); + PUSH_METHOD(cdutils, CDUTILS_WRITEFILE); + PUSH_METHOD(cdutils, CDUTILS_GETISOINFOS); + PUSH_METHOD(cdutils, CDUTILS_GETPTINFOS); + PUSH_METHOD(cdutils, CDUTILS_FINDPATH); + PUSH_METHOD(cdutils, CDUTILS_FINDPARENT); + PUSH_METHOD(cdutils, CDUTILS_FINDDIRENTRY); + PUSH_METHOD(cdutils, CDUTILS_NEWCDFILE); + PUSH_METHOD(cdutils, CDUTILS_UPDATESIZE); + PUSH_METHOD(cdutils, CDUTILS_UPDATESECTOR); + PUSH_METHOD(cdutils, CDUTILS_CREATESECTOR); +} + +void Luacdutils::pushstatics(Lua * L) throw (GeneralException) { + CHECK_METHODS(cdutils); + CHECK_FUNCTIONS(cdutils); + + PUSH_FUNCTION(cdutils, CDUTILS_NEWCDUTILS); + PUSH_FUNCTION(cdutils, CDUTILS_SWAPWORD); + PUSH_FUNCTION(cdutils, CDUTILS_SWAPDWORD); + PUSH_FUNCTION(cdutils, CDUTILS_FROM_BCD); + PUSH_FUNCTION(cdutils, CDUTILS_TO_BCD); + PUSH_FUNCTION(cdutils, CDUTILS_IS_VALID_BCD); + PUSH_FUNCTION(cdutils, CDUTILS_FROM_MSF); + PUSH_FUNCTION(cdutils, CDUTILS_TO_MSF); + + L->push("MODE0"); + L->push((lua_Number) MODE0); + L->setvar(); + + L->push("MODE1"); + L->push((lua_Number) MODE1); + L->setvar(); + + L->push("MODE2"); + L->push((lua_Number) MODE2); + L->setvar(); + + L->push("MODE2_FORM1"); + L->push((lua_Number) MODE2_FORM1); + L->setvar(); + + L->push("MODE2_FORM2"); + L->push((lua_Number) MODE2_FORM2); + L->setvar(); + + L->push("MORE_RAW"); + L->push((lua_Number) MODE_RAW); + L->setvar(); + + L->push("GUESS"); + L->push((lua_Number) GUESS); + L->setvar(); + + int i; + + L->push("sec_sizes"); + L->newtable(); + for (i = 0; i <= GUESS; i++) { + L->push((lua_Number) i); + L->push((lua_Number) sec_sizes[i]); + L->settable(); + } + L->setvar(); + + L->push("sec_offsts"); + L->newtable(); + for (i = 0; i <= GUESS; i++) { + L->push((lua_Number) i); + L->push((lua_Number) sec_offsts[i]); + L->settable(); + } + L->setvar(); + + L->push("sec_modes"); + L->newtable(); + for (i = 0; i <= GUESS; i++) { + L->push((lua_Number) i); + L->push(sec_modes[i]); + L->settable(); + } + L->setvar(); +} + +int sLua_cdutils::cdutils_proceed(Lua * L, int n, cdutils * cd, int caller) { + int r = 0, sect = -1, mode = GUESS, size = -1, i; + Handle * h; + Byte sdatas[2352], * datas; + String path; + cdutils::DirEntry * dir, * bdir, * adir, pdir; + bool invalid = false, eof = false; + int sector; + cdfile * cdf; + + switch(caller) { + case CDUTILS_SETISOW: + h = (Handle *) LuaObject::getme(L, 2); + cd->set_iso_w(h); + break; + case CDUTILS_GUESSTYPE: + if (n == 1) { + sect = L->tonumber(2); + } + L->push((lua_Number) cd->guess_type(sect)); + r = 1; + break; + case CDUTILS_SECTORSEEK: + sect = L->tonumber(2); + cd->sector_seek(sect); + break; + case CDUTILS_READSECTOR: + if (n >= 1) + sect = L->tonumber(2); + if (n == 2) + mode = L->tonumber(3); + size = cd->read_sector(sdatas, mode, sect); + L->newtable(); + for (i = 0; i < size; i++) { + L->push((lua_Number) i); + L->push((lua_Number) sdatas[i]); + L->settable(); + } + r = 1; + break; + case CDUTILS_READDATAS: + size = L->tonumber(2); + if (n >= 2) + sect = L->tonumber(3); + if (n == 3) + mode = L->tonumber(3); + datas = (Byte *) malloc(size); + cd->read_datas(datas, size, mode, sect); + L->newtable(); + for (i = 0; i < size; i++) { + L->push((lua_Number) i); + L->push((lua_Number) datas[i]); + L->settable(); + } + r = 1; + free(datas); + break; + case CDUTILS_READFILE: + h = (Handle *) LuaObject::getme(L, 2); + size = L->tonumber(5); + if (n >= 3) + sect = L->tonumber(4); + if (n == 4) + mode = L->tonumber(5); + cd->read_file(h, size, mode, sect); + break; + case CDUTILS_WRITESECTOR: + if (n >= 2) + sect = L->tonumber(3); + if (n == 3) + mode = L->tonumber(4); + for (i = 0; i < 2352; i++) { + L->push((lua_Number) i); + L->gettable(2); + sdatas[i] = L->tonumber(); + L->pop(); + } + cd->write_sector(datas, mode, sect); + break; + case CDUTILS_WRITEDATAS: + size = L->tonumber(3); + if (n >= 3) + sect = L->tonumber(4); + if (n == 4) + mode = L->tonumber(5); + datas = (Byte *) malloc(size); + + for (i = 0; i < size; i++) { + L->push((lua_Number) i); + L->gettable(2); + sdatas[i] = L->tonumber(); + L->pop(); + } + cd->write_datas(datas, size, mode, sect); + free(datas); + break; + case CDUTILS_WRITEFILE: + h = (Handle *) LuaObject::getme(L, 2); + if (n >= 2) + size = L->tonumber(3); + if (n >= 3) + sect = L->tonumber(4); + if (n == 4) + mode = L->tonumber(5); + cd->write_file(h, size, mode, sect); + break; + case CDUTILS_GETISOINFOS: + L->push((lua_Number) cd->get_iso_infos()); + r = 1; + break; + case CDUTILS_GETPTINFOS: + L->push((lua_Number) cd->get_pt_infos()); + r = 1; + break; + case CDUTILS_FINDPATH: + path = L->tostring(2); + bdir = cd->find_path(&datas, path); + if ((bdir) && bdir->R) { + dir = (cdutils::DirEntry *) malloc(bdir->R); + memcpy(dir, bdir, bdir->R); + } else { + dir = 0; + } + if (dir) { + Luadirentry ldir(dir); + ldir.pushdestruct(L); + } else { + L->push(); + } + r = 1; + free(datas); + break; + case CDUTILS_FINDPARENT: + path = L->tostring(2); + bdir = cd->find_parent(&datas, path); + if ((bdir) && bdir->R) { + dir = (cdutils::DirEntry *) malloc(bdir->R); + memcpy(dir, bdir, bdir->R); + } else { + dir = 0; + } + if (dir) { + Luadirentry ldir(dir); + ldir.pushdestruct(L); + } else { + L->push(); + } + r = 1; + free(datas); + break; + case CDUTILS_FINDDIRENTRY: + adir = (cdutils::DirEntry *) LuaObject::getme(L, 2); + path = L->tostring(3); + bdir = cd->find_dir_entry(&datas, adir, path); + if ((bdir) && bdir->R) { + dir = (cdutils::DirEntry *) malloc(bdir->R); + memcpy(dir, bdir, bdir->R); + } else { + dir = 0; + } + if (dir) { + Luadirentry ldir(dir); + ldir.pushdestruct(L); + } else { + L->push(); + } + r = 1; + free(datas); + break; + case CDUTILS_NEWCDFILE: + if (L->istable(2)) { + if (n <= 2) { + dir = (cdutils::DirEntry *) LuaObject::getme(L, 2); + if (n == 2) + mode = L->tonumber(3); + cdf = new cdfile(cd, dir, mode); + } else { + invalid = true; + } + } else if (L->isnumber(2)) { + if (n >= 1) { + sector = L->tonumber(2); + if (n >= 2) + size = L->tonumber(3); + if (n == 3) + mode = L->tonumber(4); + cdf = new cdfile(cd, sector, size, mode); + } else { + invalid = true; + } + } else { + invalid = true; + } + if (invalid) { + L->error("Invalid arguments to constructor of cdfile"); + } else { + Luacdfile luacdf(cdf); + luacdf.pushdestruct(L); + r = 1; + } + break; + case CDUTILS_UPDATESIZE: + case CDUTILS_UPDATESECTOR: + path = L->tostring(2); + pdir = cd->find_parent(path); + dir = cd->find_path(&datas, path); + switch (caller) { + case CDUTILS_UPDATESIZE: + dir->Size = tolittle((Uint32) L->tonumber(3)); + dir->BESize = tobig((Uint32) L->tonumber(3)); + break; + case CDUTILS_UPDATESECTOR: + dir->Sector = tolittle((Uint32) L->tonumber(3)); + dir->BESector = tobig((Uint32) L->tonumber(3)); + break; + } + cd->write_datas(datas, pdir.Size, GUESS, pdir.Sector); + free(datas); + break; + case CDUTILS_CREATESECTOR: + mode = L->tonumber(2); + sect = L->tonumber(3); + if (n == 3) + eof = L->toboolean(4); + cd->create_sector(mode, sect, eof); + break; + } + + + return r; +} + +int sLua_cdutils::cdutils_proceed_statics(Lua * L, int n, int caller) { + int r = 0; + Uint32 x; + Handle * isor = 0, * isow = 0; + Uint32 sector, msf, start = 150; + Byte m, s, f; + + switch(caller) { + case CDUTILS_NEWCDUTILS: + isor = (Handle *) LuaObject::getme(L, 1); + if (n == 2) + isow = (Handle *) LuaObject::getme(L, 2); + { + Luacdutils cd(new cdutils(isor, isow)); + cd.pushdestruct(L); + } + break; + case CDUTILS_SWAPWORD: + x = L->tonumber(); + L->push((lua_Number) cdutils::swap_word(x)); + r = 1; + break; + case CDUTILS_SWAPDWORD: + x = L->tonumber(); + L->push((lua_Number) cdutils::swap_dword(x)); + r = 1; + break; + case CDUTILS_FROM_BCD: + x = L->tonumber(); + L->push((lua_Number) cdutils::from_BCD(x)); + r = 1; + break; + case CDUTILS_TO_BCD: + x = L->tonumber(); + L->push((lua_Number) cdutils::to_BCD(x)); + r = 1; + break; + case CDUTILS_IS_VALID_BCD: + x = L->tonumber(); + L->push(cdutils::is_valid_BCD(x)); + r = 1; + break; + case CDUTILS_FROM_MSF: + if (n <= 2) { + msf = L->tonumber(1); + if (n == 2) + start = L->tonumber(2); + L->push((lua_Number) cdutils::from_MSF(msf, start)); + } else { + m = L->tonumber(1); + s = L->tonumber(2); + f = L->tonumber(3); + if (n == 4) + start = L->tonumber(4); + L->push((lua_Number) cdutils::from_MSF(m, s, f, start)); + } + r = 1; + break; + case CDUTILS_TO_MSF: + sector = L->tonumber(1); + if (n == 2) + start = L->tonumber(2); + cdutils::to_MSF(sector, m, s, f, start); + msf = cdutils::to_MSF(sector, start); + L->push((lua_Number) msf); + L->push((lua_Number) m); + L->push((lua_Number) s); + L->push((lua_Number) f); + r = 4; + break; + } + + return r; +} + + + /***************************\ +|** class direntry exports **| + \***************************/ + +typedef cdutils::DirEntry direntry; + +Luadirentry::Luadirentry(cdutils::DirEntry * _dir) : dir(_dir) { } + +enum direntry_methods_t { + DIRENTRY_INDEX = 0, + DIRENTRY_ISHIDDEN, + DIRENTRY_ISDIR, + DIRENTRY_HASXA, + DIRENTRY_ISXADIR, + DIRENTRY_ISXAAUDIO, + DIRENTRY_ISXASTR, + DIRENTRY_ISXAXA, + DIRENTRY_ISXAFORM1, +}; + +struct lua_functypes_t direntry_methods[] = { + { DIRENTRY_INDEX, "index", 1, 1, {LUA_STRING} }, + { DIRENTRY_ISHIDDEN, "ishidden", 0, 0, 0 }, + { DIRENTRY_ISDIR, "isdir", 0, 0, 0 }, + { DIRENTRY_HASXA, "hasxa", 0, 0, 0 }, + { DIRENTRY_ISXADIR, "isxadir", 0, 0, 0 }, + { DIRENTRY_ISXAAUDIO, "isxaaudio", 0, 0, 0 }, + { DIRENTRY_ISXASTR, "isxastr", 0, 0, 0 }, + { DIRENTRY_ISXAXA, "isxaxa", 0, 0, 0 }, + { DIRENTRY_ISXAFORM1, "isxaform1", 0, 0, 0 }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_direntry : public Base { + public: + DECLARE_METHOD(direntry, DIRENTRY_INDEX); + DECLARE_METHOD(direntry, DIRENTRY_ISHIDDEN); + DECLARE_METHOD(direntry, DIRENTRY_ISDIR); + DECLARE_METHOD(direntry, DIRENTRY_HASXA); + DECLARE_METHOD(direntry, DIRENTRY_ISXADIR); + DECLARE_METHOD(direntry, DIRENTRY_ISXAAUDIO); + DECLARE_METHOD(direntry, DIRENTRY_ISXASTR); + DECLARE_METHOD(direntry, DIRENTRY_ISXAXA); + DECLARE_METHOD(direntry, DIRENTRY_ISXAFORM1); + private: + static int direntry_proceed(Lua * L, int n, direntry * obj, int caller); +}; + +void Luadirentry::pushmembers(Lua * L) { + pushme(L, dir, false); + + PUSH_METAMETHOD(direntry, DIRENTRY_INDEX); + PUSH_METHOD(direntry, DIRENTRY_ISHIDDEN); + PUSH_METHOD(direntry, DIRENTRY_ISDIR); + PUSH_METHOD(direntry, DIRENTRY_HASXA); + PUSH_METHOD(direntry, DIRENTRY_ISXADIR); + PUSH_METHOD(direntry, DIRENTRY_ISXAAUDIO); + PUSH_METHOD(direntry, DIRENTRY_ISXASTR); + PUSH_METHOD(direntry, DIRENTRY_ISXAXA); + PUSH_METHOD(direntry, DIRENTRY_ISXAFORM1); +} + +int sLua_direntry::direntry_proceed(Lua * L, int n, direntry * dir, int caller) { + int r = 0, s, pad; + String index; + bool has_xa = false; + Byte * p; + + s = 33 + dir->N; + if (s & 1) { + s++; + pad = 1; + } else { + pad = 0; + } + if (s != dir->R) { + if ((s + 14) == dir->R) { + p = (Byte *) dir->id + dir->N + pad; + if ((p[6] == 'X') && (p[7] == 'A')) { + has_xa = true; + } + } + } + + switch (caller) { + case DIRENTRY_HASXA: + L->push(has_xa); + r = 1; + break; + case DIRENTRY_ISHIDDEN: + L->push(dir->Flags & 1 ? true : false); + r = 1; + break; + case DIRENTRY_ISDIR: + L->push(dir->Flags & 2 ? true : false); + r = 1; + break; + case DIRENTRY_ISXADIR: + L->push(p[4] & 0x80 ? true : false); + r = 1; + break; + case DIRENTRY_ISXAAUDIO: + L->push(p[4] & 0x40 ? true : false); + r = 1; + break; + case DIRENTRY_ISXASTR: + L->push(p[4] & 0x20 ? true : false); + r = 1; + break; + case DIRENTRY_ISXAXA: + L->push(p[4] & 0x10 ? true : false); + r = 1; + break; + case DIRENTRY_ISXAFORM1: + L->push(p[4] & 0x08 ? true : false); + r = 1; + break; + case DIRENTRY_INDEX: + index = L->tostring(); + r = 1; + if (index == "R") { + L->push((lua_Number) dir->R); + } else if (index == "NExt") { + L->push((lua_Number) dir->NExt); + } else if (index == "Sector") { + L->push((lua_Number) dir->Sector); + } else if (index == "Size") { + L->push((lua_Number) dir->Size); + } else if (index == "Year") { + L->push((lua_Number) dir->Year); + } else if (index == "Month") { + L->push((lua_Number) dir->Month); + } else if (index == "Day") { + L->push((lua_Number) dir->Day); + } else if (index == "Hour") { + L->push((lua_Number) dir->Hour); + } else if (index == "Minute") { + L->push((lua_Number) dir->Minute); + } else if (index == "Second") { + L->push((lua_Number) dir->Second); + } else if (index == "Offset") { + L->push((lua_Number) dir->Offset); + } else if (index == "Flags") { + L->push((lua_Number) dir->Flags); + } else if (index == "HandleUnit") { + L->push((lua_Number) dir->HandleUnit); + } else if (index == "HandleGap") { + L->push((lua_Number) dir->HandleGap); + } else if (index == "VolSeq") { + L->push((lua_Number) dir->VolSeq); + } else if (index == "N") { + L->push((lua_Number) dir->N); + } else if (index == "id") { + char pbuf[256]; + memcpy(pbuf, dir->id, dir->N); + pbuf[dir->N] = 0; + L->push(pbuf, dir->N); + } else { + L->push(); + } + } + + return r; +} + + + /***************************\ +|** class direntry exports **| + \***************************/ + +typedef isobuilder::Date cddate; + +Luacddate::Luacddate(isobuilder::Date * _date) : date(_date) { } + +enum cddate_methods_t { + CDDATE_INDEX = 0, + CDDATE_NEWINDEX, +}; + +enum cddate_functions_t { + CDDATE_NEWCDDATE = 0, +}; + +struct lua_functypes_t cddate_methods[] = { + { CDDATE_INDEX, "index", 1, 1, {LUA_STRING} }, + { CDDATE_NEWINDEX, "newindex", 2, 2, {LUA_STRING, LUA_NUMBER} }, + { -1, 0, 0, 0, 0 } +}; + +struct lua_functypes_t cddate_functions[] = { + { CDDATE_NEWCDDATE, "cddate", 0, 0, 0 }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_cddate : public Base { + public: + DECLARE_METHOD(cddate, CDDATE_INDEX); + DECLARE_METHOD(cddate, CDDATE_NEWINDEX); + DECLARE_FUNCTION(cddate, CDDATE_NEWCDDATE); + private: + static int cddate_proceed(Lua * L, int n, cddate * obj, int caller); + static int cddate_proceed_statics(Lua * L, int n, int caller); +}; + +void Luacddate::pushmembers(Lua * L) { + pushme(L, date, false); + + PUSH_METAMETHOD(cddate, CDDATE_INDEX); + PUSH_METAMETHOD(cddate, CDDATE_NEWINDEX); +} + +void Luacddate::pushstatics(Lua * L) throw (GeneralException) { + CHECK_METHODS(cddate); + CHECK_FUNCTIONS(cddate); + + PUSH_FUNCTION(cddate, CDDATE_NEWCDDATE); +} + +int sLua_cddate::cddate_proceed(Lua * L, int n, cddate * date, int caller) { + int r, value; + String key; + + switch (caller) { + case CDDATE_INDEX: + key = L->tostring(2); + r = 1; + if (key == "year") { + L->push((lua_Number) date->year); + } else if (key == "month") { + L->push((lua_Number) date->month); + } else if (key == "day") { + L->push((lua_Number) date->day); + } else if (key == "hour") { + L->push((lua_Number) date->hour); + } else if (key == "minute") { + L->push((lua_Number) date->minute); + } else if (key == "second") { + L->push((lua_Number) date->second); + } else if (key == "hundredths") { + L->push((lua_Number) date->hundredths); + } else if (key == "offset") { + L->push((lua_Number) date->offset); + } else { + L->error("Key " + key + " not in class Date"); + } + break; + case CDDATE_NEWINDEX: + r = 0; + key = L->tostring(2); + value = L->tonumber(3); + if (key == "year") { + date->year = value; + } else if (key == "month") { + date->month = value; + } else if (key == "day") { + date->day = value; + } else if (key == "hour") { + date->hour = value; + } else if (key == "minute") { + date->minute = value; + } else if (key == "second") { + date->second = value; + } else if (key == "hundredths") { + date->hundredths = value; + } else if (key == "offset") { + date->offset = value; + } else { + L->error("Key " + key + " not in class Date"); + } + break; + } + + return r; +} + +int sLua_cddate::cddate_proceed_statics(Lua * L, int n, int caller) { + int r = 0; + + switch (caller) { + case CDDATE_NEWCDDATE: + { + Luacddate t(new isobuilder::Date()); + t.pushdestruct(L); + } + } + + return r; +} + + /**********************\ +|** class PVD exports **| + \**********************/ + +typedef isobuilder::PVD PVD; + +LuaPVD::LuaPVD(struct isobuilder::PVD * _pvd) : pvd(_pvd) { } + +enum PVD_methods_t { + PVD_INDEX = 0, + PVD_NEWINDEX, +}; + +enum PVD_functions_t { + PVD_NEWPVD = 0, +}; + +struct lua_functypes_t PVD_methods[] = { + { PVD_INDEX, "index", 1, 1, {LUA_ANY} }, + { PVD_NEWINDEX, "newindex", 2, 2, {LUA_ANY, LUA_ANY} }, + { -1, 0, 0, 0, 0 } +}; + +struct lua_functypes_t PVD_functions[] = { + { PVD_NEWPVD, "PVD", 0, 0, 0 }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_PVD : public Base { + public: + DECLARE_METHOD(PVD, PVD_INDEX); + DECLARE_METHOD(PVD, PVD_NEWINDEX); + + DECLARE_FUNCTION(PVD, PVD_NEWPVD); + + private: + static int PVD_proceed(Lua * L, int n, PVD * obj, int caller); + static int PVD_proceed_statics(Lua * L, int n, int caller); +}; + +void LuaPVD::pushmembers(Lua * L) { + pushme(L, pvd, false); + + PUSH_METAMETHOD(PVD, PVD_INDEX); + PUSH_METAMETHOD(PVD, PVD_NEWINDEX); +} + +void LuaPVD::pushstatics(Lua * L) throw (GeneralException) { + CHECK_METHODS(PVD); + CHECK_FUNCTIONS(PVD); + + PUSH_FUNCTION(PVD, PVD_NEWPVD); +} + +int sLua_PVD::PVD_proceed(Lua * L, int n, PVD * pvd, int caller) { + int r = 0, key_i = 0, value_i; + String key_s, value_s; + cddate * value_date; + bool invalid = false, keyisstring; + + if (L->isnumber(2)) { + keyisstring = false; + key_i = L->tonumber(2); + } else { + keyisstring = true; + key_s = L->tostring(2); + } + + switch (caller) { + case PVD_INDEX: + r = 1; + if (keyisstring && (key_s == "sysid")) { + L->push(pvd->sysid); + } else if (keyisstring && (key_s == "volid")) { + L->push(pvd->volid); + } else if (keyisstring && (key_s == "volsetid")) { + L->push(pvd->volsetid); + } else if (keyisstring && (key_s == "pubid")) { + L->push(pvd->pubid); + } else if (keyisstring && (key_s == "prepid")) { + L->push(pvd->prepid); + } else if (keyisstring && (key_s == "appid")) { + L->push(pvd->appid); + } else if (keyisstring && (key_s == "copyright")) { + L->push(pvd->copyright); + } else if (keyisstring && (key_s == "abstract")) { + L->push(pvd->abstract); + } else if (keyisstring && (key_s == "biblio")) { + L->push(pvd->biblio); + } else if (keyisstring && (key_s == "volcreat")) { + { + Luacddate date(&pvd->volcreat); + date.push(L); + } + } else if (keyisstring && (key_s == "modif")) { + { + Luacddate date(&pvd->modif); + date.push(L); + } + } else if (keyisstring && (key_s == "volexp")) { + { + Luacddate date(&pvd->volexp); + date.push(L); + } + } else if (keyisstring && (key_s == "voleff")) { + { + Luacddate date(&pvd->voleff); + date.push(L); + } + } else if (!keyisstring && (key_i >= 0) && (key_i < 512)) { + L->push((lua_Number) pvd->appdata[key_i]); + } else { + invalid = true; + } + break; + case PVD_NEWINDEX: + if (keyisstring && (key_s == "sysid")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->sysid = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "volid")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->volid = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "volsetid")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->volsetid = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "pubid")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->pubid = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "prepid")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->prepid = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "appid")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->appid = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "copyright")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->copyright = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "abstract")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->abstract = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "biblio")) { + if (L->isstring(3)) { + value_s = L->tostring(3); + pvd->biblio = value_s; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "volcreat")) { + if (L->islightuserdata(3)) { + value_date = (cddate *) LuaObject::getme(L, 3); + pvd->volcreat = *value_date; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "modif")) { + if (L->islightuserdata(3)) { + value_date = (cddate *) LuaObject::getme(L, 3); + pvd->modif = *value_date; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "volexp")) { + if (L->islightuserdata(3)) { + value_date = (cddate *) LuaObject::getme(L, 3); + pvd->volexp = *value_date; + } else { + invalid = true; + } + } else if (keyisstring && (key_s == "voleff")) { + if (L->islightuserdata(3)) { + value_date = (cddate *) LuaObject::getme(L, 3); + pvd->voleff = *value_date; + } else { + invalid = true; + } + } else if (!keyisstring && (key_i >= 0) && (key_i < 512)) { + if (L->isnumber(3)) { + pvd->appdata[key_i] = L->tonumber(3); + } else { + invalid = true; + } + } else { + invalid = true; + } + break; + } + + if (invalid) { + L->error("Invalid usage of structure PVD"); + } + + return r; +} + +int sLua_PVD::PVD_proceed_statics(Lua * L, int n, int caller) { + int r = 0; + + switch (caller) { + case PVD_NEWPVD: + r = 1; + { + LuaPVD pvd((PVD *) malloc(sizeof(PVD))); + pvd.pushdestruct(L); + } + break; + } + + return r; +} + + + /**************************\ +|** class DirTree exports **| + \**************************/ + +typedef isobuilder::DirTree DirTree; + +LuaDirTree::LuaDirTree(isobuilder::DirTree * _dir) : dir(_dir) { } + +enum DirTree_methods_t { + DIRTREE_INDEX = 0, + DIRTREE_NEWINDEX, + DIRTREE_FROMDIR, + DIRTREE_SETBASICSXA, + DIRTREE_FIND, +}; + +enum DirTree_functions_t { + DIRTREE_NEWDIRTREE = 0, +}; + +struct lua_functypes_t DirTree_methods[] = { + { DIRTREE_INDEX, "index", 1, 1, {LUA_STRING} }, + { DIRTREE_NEWINDEX, "newindex", 2, 2, {LUA_STRING, LUA_ANY} }, + { DIRTREE_FROMDIR, "fromdir", 1, 1, {LUA_OBJECT} }, + { DIRTREE_SETBASICSXA, "setbasicsxa", 0, 0, 0 }, + { DIRTREE_FIND, "find", 1, 1, {LUA_STRING} }, + { -1, 0, 0, 0, 0 } +}; + +struct lua_functypes_t DirTree_functions[] = { + { DIRTREE_NEWDIRTREE, "DirTree", 1, 2, {LUA_OBJECT, LUA_BOOLEAN} }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_DirTree : public Base { + public: + DECLARE_METHOD(DirTree, DIRTREE_INDEX); + DECLARE_METHOD(DirTree, DIRTREE_NEWINDEX); + DECLARE_METHOD(DirTree, DIRTREE_FROMDIR); + DECLARE_METHOD(DirTree, DIRTREE_SETBASICSXA); + DECLARE_METHOD(DirTree, DIRTREE_FIND); + + DECLARE_FUNCTION(DirTree, DIRTREE_NEWDIRTREE); + private: + static int DirTree_proceed(Lua * L, int n, DirTree * obj, int caller); + static int DirTree_proceed_statics(Lua * L, int n, int caller); +}; + +void LuaDirTree::pushmembers(Lua * L) { + pushme(L, dir); + + PUSH_METAMETHOD(DirTree, DIRTREE_INDEX); + PUSH_METAMETHOD(DirTree, DIRTREE_NEWINDEX); + + PUSH_METHOD(DirTree, DIRTREE_FROMDIR); + PUSH_METHOD(DirTree, DIRTREE_SETBASICSXA); + PUSH_METHOD(DirTree, DIRTREE_FIND); +} + +void LuaDirTree::pushstatics(Lua * L) throw (GeneralException) { + CHECK_METHODS(DirTree); + CHECK_FUNCTIONS(DirTree); + + PUSH_FUNCTION(DirTree, DIRTREE_NEWDIRTREE); +} + +int sLua_DirTree::DirTree_proceed(Lua * L, int n, DirTree * dir, int caller) { + int r = 0, value_i; + direntry * dirent; + DirTree * rdir; + String f, key, value_s; + bool invalid = false, value_b; + cddate * value_date; + + switch (caller) { + case DIRTREE_FROMDIR: + dirent = (direntry *) LuaObject::getme(L, 2); + dir->fromdir(dirent); + break; + case DIRTREE_SETBASICSXA: + dir->setbasicsxa(); + break; + case DIRTREE_FIND: + f = L->tostring(2); + rdir = dir->Find(f); + if (rdir) { + LuaDirTree dirt(rdir); + dirt.push(L); + } else { + L->push(); + } + break; + case DIRTREE_INDEX: + key = L->tostring(2); + r = 1; + if (key == "sector") { + L->push((lua_Number) dir->sector); + } else if (key == "size") { + L->push((lua_Number) dir->size); + } else if (key == "hidden") { + L->push(dir->hidden); + } else if (key == "hardhide") { + L->push(dir->hardhide); + } else if (key == "name") { + L->push(dir->name); + } else if (key == "creation") { + Luacddate date(&dir->creation); + date.push(L); + } else if (key == "have_xa") { + L->push(dir->have_xa); + } else if (key == "xa_dir") { + L->push(dir->xa_dir); + } else if (key == "xa_audio") { + L->push(dir->xa_audio); + } else if (key == "xa_str") { + L->push(dir->xa_str); + } else if (key == "xa_xa") { + L->push(dir->xa_xa); + } else if (key == "xa_form1") { + L->push(dir->xa_form1); + } else if (key == "mode") { + L->push((lua_Number) dir->mode); + } else if (key == "father") { + LuaDirTree tdir(dir->Father()); + tdir.push(L); + } else if (key == "child") { + LuaDirTree tdir(dir->Child()); + tdir.push(L); + } else if (key == "brother") { + LuaDirTree tdir(dir->Brother()); + tdir.push(L); + } else if (key == "isdir") { + L->push(dir->isdir()); + } else { + invalid = true; + } + break; + case DIRTREE_NEWINDEX: + key = L->tostring(2); + if (key == "sector") { + if (L->isnumber(3)) { + value_i = L->tonumber(3); + dir->sector = value_i; + } else { + invalid = true; + } + } else if (key == "size") { + if (L->isnumber(3)) { + value_i = L->tonumber(3); + dir->size = value_i; + } else { + invalid = true; + } + } else if (key == "hidden") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->hidden = value_b; + } else { + invalid = true; + } + } else if (key == "hardhide") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->hardhide = value_b; + } else { + invalid = true; + } + } else if (key == "name") { + if (L->isstring(3)) { + value_s = L->tostring(3); + dir->name = value_s; + } else { + invalid = true; + } + } else if (key == "creation") { + if (L->islightuserdata(3)) { + value_date = (cddate *) LuaObject::getme(L, 3); + dir->creation = *value_date; + } else { + invalid = true; + } + } else if (key == "have_xa") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->have_xa = value_b; + } else { + invalid = true; + } + } else if (key == "xa_dir") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->xa_dir = value_b; + } else { + invalid = true; + } + } else if (key == "xa_audio") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->xa_audio = value_b; + } else { + invalid = true; + } + } else if (key == "xa_str") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->xa_str = value_b; + } else { + invalid = true; + } + } else if (key == "xa_xa") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->xa_xa = value_b; + } else { + invalid = true; + } + } else if (key == "xa_form1") { + if (L->isboolean(3)) { + value_b = L->toboolean(3); + dir->xa_form1 = value_b; + } else { + invalid = true; + } + } else if (key == "mode") { + if (L->isnumber(3)) { + value_i = L->tonumber(3); + dir->mode = value_i; + } else { + invalid = true; + } + } else { + invalid = true; + } + break; + } + + if (invalid) { + L->error("Invalid usage of structure DirTree"); + } + + return r; +} + +int sLua_DirTree::DirTree_proceed_statics(Lua * L, int n, int caller) { + int r; + DirTree * father; + bool dir = true; + + switch (caller) { + case DIRTREE_NEWDIRTREE: + father = (DirTree *) LuaObject::getme(L, 1); + if (n == 2) + dir = L->toboolean(2); + { + LuaDirTree dirt(new DirTree(father, dir)); + dirt.pushdestruct(L); + } + break; + } + + return r; +} + + + /*****************************\ +|** class isobuilder exports **| + \*****************************/ + +Luaisobuilder::Luaisobuilder(isobuilder * _iso) : iso(_iso) { } + +enum isobuilder_methods_t { + ISOBUILDER_FOREWORD = 0, + ISOBUILDER_FOREWORD_HANDLE, + ISOBUILDER_FOREWORD_ARRAY, + ISOBUILDER_GETDISPSECT, + ISOBUILDER_PUTFILE, + ISOBUILDER_PUTDATAS, + ISOBUILDER_CREATESECTOR, + ISOBUILDER_SETEOF, + ISOBUILDER_CLEAREOF, + ISOBUILDER_SETBASICS, + ISOBUILDER_CREATEDIR, + ISOBUILDER_CREATEFILE, + ISOBUILDER_COPYDIR, + ISOBUILDER_CLOSE, +}; + +enum isobuilder_functions_t { + ISOBUILDER_NEWISOBUILDER = 0, + ISOBUILDER_CREATEPVD_HANDLE, + ISOBUILDER_CREATEPVD, + ISOBUILDER_CREATEPVD_ARRAY, +}; + +struct lua_functypes_t isobuilder_methods[] = { + { ISOBUILDER_FOREWORD, "foreword", 1, 1, {LUA_OBJECT} }, + { ISOBUILDER_FOREWORD_HANDLE, "foreword_handle", 1, 2, {LUA_OBJECT, LUA_NUMBER} }, + { ISOBUILDER_FOREWORD_ARRAY, "foreword_array", 1, 2, {LUA_TABLE, LUA_NUMBER} }, + { ISOBUILDER_GETDISPSECT, "getdispsect", 0, 0, 0}, + { ISOBUILDER_PUTFILE, "putfile", 1, 3, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER} }, + { ISOBUILDER_PUTDATAS, "putdatas", 2, 4, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { ISOBUILDER_CREATESECTOR, "createsector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} }, + { ISOBUILDER_SETEOF, "setEOF", 0, 0, 0 }, + { ISOBUILDER_CLEAREOF, "clearEOF", 0, 0, 0 }, + { ISOBUILDER_SETBASICS, "setbasics", 1, 5, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, + { ISOBUILDER_CREATEDIR, "createdir", 2, 5, {LUA_OBJECT, LUA_STRING, LUA_NUMBER, LUA_OBJECT, LUA_NUMBER} }, + { ISOBUILDER_CREATEFILE, "createfile", 3, 5, {LUA_OBJECT, LUA_STRING, LUA_OBJECT, LUA_OBJECT, LUA_NUMBER} }, + { ISOBUILDER_COPYDIR, "copydir", 3, 4, {LUA_OBJECT, LUA_OBJECT, LUA_OBJECT, LUA_NUMBER} }, + { ISOBUILDER_CLOSE, "close", 0, 3, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER} }, + { -1, 0, 0, 0, 0 } +}; + +struct lua_functypes_t isobuilder_functions[] = { + { ISOBUILDER_NEWISOBUILDER, "isobuilder", 1, 2, {LUA_OBJECT, LUA_NUMBER} }, + { ISOBUILDER_CREATEPVD_HANDLE, "createpvd_handle", 1, 1, {LUA_OBJECT} }, + { ISOBUILDER_CREATEPVD, "createpvd", 1, 1, {LUA_OBJECT} }, + { ISOBUILDER_CREATEPVD_ARRAY, "createpvd_array", 1, 1, {LUA_TABLE} }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_isobuilder : public Base { + public: + DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD); + DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD_HANDLE); + DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD_ARRAY); + DECLARE_METHOD(isobuilder, ISOBUILDER_GETDISPSECT); + DECLARE_METHOD(isobuilder, ISOBUILDER_PUTFILE); + DECLARE_METHOD(isobuilder, ISOBUILDER_PUTDATAS); + DECLARE_METHOD(isobuilder, ISOBUILDER_CREATESECTOR); + DECLARE_METHOD(isobuilder, ISOBUILDER_SETEOF); + DECLARE_METHOD(isobuilder, ISOBUILDER_CLEAREOF); + DECLARE_METHOD(isobuilder, ISOBUILDER_SETBASICS); + DECLARE_METHOD(isobuilder, ISOBUILDER_CREATEDIR); + DECLARE_METHOD(isobuilder, ISOBUILDER_CREATEFILE); + DECLARE_METHOD(isobuilder, ISOBUILDER_COPYDIR); + DECLARE_METHOD(isobuilder, ISOBUILDER_CLOSE); + + DECLARE_FUNCTION(isobuilder, ISOBUILDER_NEWISOBUILDER); + DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_HANDLE); + DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD); + DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_ARRAY); + + private: + static int isobuilder_proceed(Lua * L, int n, isobuilder * obj, int caller); + static int isobuilder_proceed_statics(Lua * L, int n, int caller); +}; + +void Luaisobuilder::pushmembers(Lua * L) { + pushme(L, iso); + + PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD); + PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD_HANDLE); + PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD_ARRAY); + PUSH_METHOD(isobuilder, ISOBUILDER_GETDISPSECT); + PUSH_METHOD(isobuilder, ISOBUILDER_PUTFILE); + PUSH_METHOD(isobuilder, ISOBUILDER_PUTDATAS); + PUSH_METHOD(isobuilder, ISOBUILDER_CREATESECTOR); + PUSH_METHOD(isobuilder, ISOBUILDER_SETEOF); + PUSH_METHOD(isobuilder, ISOBUILDER_CLEAREOF); + PUSH_METHOD(isobuilder, ISOBUILDER_SETBASICS); + PUSH_METHOD(isobuilder, ISOBUILDER_CREATEDIR); + PUSH_METHOD(isobuilder, ISOBUILDER_CREATEFILE); + PUSH_METHOD(isobuilder, ISOBUILDER_COPYDIR); + PUSH_METHOD(isobuilder, ISOBUILDER_CLOSE); +} + +void Luaisobuilder::pushstatics(Lua * L) throw (GeneralException) { + CHECK_METHODS(isobuilder); + CHECK_FUNCTIONS(isobuilder); + + PUSH_FUNCTION(isobuilder, ISOBUILDER_NEWISOBUILDER); + PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_HANDLE); + PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD); + PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_ARRAY); +} + +int sLua_isobuilder::isobuilder_proceed(Lua * L, int n, isobuilder * iso, int caller) { + int r = 0, i; + Handle * h = 0; + int mode = -1, sector = -1, rootsize = 1, ptsize = 1, nvd = 1, rootsect = -1, nsects = -1; + size_t size; + Byte datas[2352 * 16], * p; + PVD * pvd; + DirTree * dirt, * rdir; + direntry * dire = 0; + String name; + cdutils * cd; + + switch (caller) { + case ISOBUILDER_FOREWORD: + cd = (cdutils *) LuaObject::getme(L, 2); + iso->foreword(cd); + break; + case ISOBUILDER_FOREWORD_HANDLE: + mode = MODE_RAW; + h = (Handle *) LuaObject::getme(L, 2); + if (n == 2) + mode = L->tonumber(3); + iso->foreword(h, mode); + break; + case ISOBUILDER_FOREWORD_ARRAY: + mode = MODE_RAW; + if (n == 2) + mode = L->tonumber(3); + for (i = 0; i < 16 * 2352; i++) { + L->push((lua_Number) i); + L->gettable(2); + datas[i] = L->tonumber(); + L->pop(); + } + iso->foreword(datas, mode); + break; + case ISOBUILDER_GETDISPSECT: + L->push((lua_Number) iso->getdispsect()); + r = 1; + break; + case ISOBUILDER_PUTFILE: + h = (Handle *) LuaObject::getme(L, 2); + if (n >= 2) + mode = L->tonumber(3); + if (n >= 3) + sector = L->tonumber(4); + L->push((lua_Number) iso->putfile(h, mode, sector)); + r = 1; + break; + case ISOBUILDER_PUTDATAS: + size = L->tonumber(3); + if (n >= 3) + mode = L->tonumber(4); + if (n >= 4) + sector = L->tonumber(5); + p = (Byte *) malloc(size); + for (i = 0; i < size; i++) { + L->push((lua_Number) i); + L->gettable(2); + p[i] = L->tonumber(); + L->pop(); + } + L->push((lua_Number) iso->putdatas(p, size, mode, sector)); + r = 1; + free(p); + break; + case ISOBUILDER_CREATESECTOR: + if (n >= 2) + mode = L->tonumber(3); + if (n >= 3) + sector = L->tonumber(4); + for (i = 0; i < 2352; i++) { + L->push((lua_Number) i); + L->gettable(2); + datas[i] = L->tonumber(); + L->pop(); + } + L->push((lua_Number) iso->createsector(datas, mode, sector)); + r = 1; + break; + case ISOBUILDER_SETEOF: + iso->setEOF(); + break; + case ISOBUILDER_CLEAREOF: + iso->clearEOF(); + break; + case ISOBUILDER_SETBASICS: + pvd = (PVD *) LuaObject::getme(L, 2); + if (n >= 2) + rootsize = L->tonumber(3); + if (n >= 3) + ptsize = L->tonumber(4); + if (n >= 4) + nvd = L->tonumber(5); + if (n >= 5) + rootsect = L->tonumber(6); + rdir = iso->setbasics(*pvd, rootsize, ptsize, nvd, rootsect); + { + LuaDirTree t(rdir); + t.push(L); + } + r = 1; + break; + case ISOBUILDER_CREATEDIR: + size = 1; + dirt = 0; + dirt = (DirTree *) LuaObject::getme(L, 2); + name = L->tostring(3); + if (n >= 3) + size = L->tonumber(4); + if (n >= 4) + dire = (direntry *) LuaObject::getme(L, 5); + if (n >= 5) + mode = L->tonumber(6); + rdir = iso->createdir(dirt, name, size, dire, mode); + { + LuaDirTree t(rdir); + t.push(L); + } + r = 1; + break; + case ISOBUILDER_CREATEFILE: + dirt = (DirTree *) LuaObject::getme(L, 2); + name = L->tostring(3); + h = (Handle *) LuaObject::getme(L, 4); + if (n >= 4) + dire = (direntry *) LuaObject::getme(L, 5); + if (n >= 5) + mode = L->tonumber(6); + rdir = iso->createfile(dirt, h, name, dire, mode); + { + LuaDirTree t(rdir); + t.push(L); + } + r = 1; + break; + case ISOBUILDER_COPYDIR: + dirt = (DirTree *) LuaObject::getme(L, 2); + cd = (cdutils *) LuaObject::getme(L, 3); + dire = (direntry *) LuaObject::getme(L, 4); + if (n >= 4) + mode = L->tonumber(5); + iso->copydir(dirt, cd, dire, mode); + break; + case ISOBUILDER_CLOSE: + if (n >= 1) + h = (Handle *) LuaObject::getme(L, 2); + if (n >= 2) + mode = L->tonumber(3); + if (n >= 3) + nsects = L->tonumber(4); + iso->close(h, mode, nsects); + break; + } + + return r; +} + +int sLua_isobuilder::isobuilder_proceed_statics(Lua * L, int n, int caller) { + int r = 0, i; + Handle * h; + int mode = MODE2_FORM1; + cdutils * cd; + Byte datas[2048]; + PVD * pvd; + + switch (caller) { + case ISOBUILDER_NEWISOBUILDER: + h = (Handle *) LuaObject::getme(L, 1); + if (n >= 2) + mode = L->tonumber(); + { + Luaisobuilder t(new isobuilder(h, mode)); + t.pushdestruct(L); + } + r = 1; + break; + case ISOBUILDER_CREATEPVD_HANDLE: + h = (Handle *) LuaObject::getme(L, 1); + pvd = (PVD *) malloc(sizeof(PVD)); + *pvd = isobuilder::createpvd(h); + { + LuaPVD t(pvd); + t.pushdestruct(L); + } + r = 1; + break; + case ISOBUILDER_CREATEPVD: + cd = (cdutils *) LuaObject::getme(L, 1); + pvd = (PVD *) malloc(sizeof(PVD)); + *pvd = isobuilder::createpvd(cd); + { + LuaPVD t(pvd); + t.pushdestruct(L); + } + r = 1; + break; + case ISOBUILDER_CREATEPVD_ARRAY: + for (i = 0; i < 2048; i++) { + L->push((lua_Number) i); + L->gettable(1); + datas[i] = L->tonumber(); + L->pop(); + } + pvd = (PVD *) malloc(sizeof(PVD)); + *pvd = isobuilder::createpvd(datas); + { + LuaPVD t(pvd); + t.pushdestruct(L); + } + r = 1; + break; + } + + return r; +} diff --git a/lib/luapsx.cpp b/lib/luapsx.cpp index eb1473b..da66ac6 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.6 2004-11-27 21:44:48 pixel Exp $ */ - -#include -#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.7 2004-11-27 21:47:56 pixel Exp $ */ + +#include +#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 7b134aa..1d7ecfb 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 -#include -#include -#include -#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 +#include +#include +#include +#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 05a1201..3a9a8f9 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.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); -} +/* + * 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.5 2004-11-27 21:47:56 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 bb6364c..ce63623 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.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 -} +/* + * 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.4 2004-11-27 21:47:56 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 1eb59f7..1e427e1 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.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::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.3 2004-11-27 21:47:56 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::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 660c3fc..3f5bd71 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.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); - } -} +/* + * 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.3 2004-11-27 21:47:56 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 233c5c5..97663e6 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 secnames; - std::map 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 secnames; + std::map 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 100cd38..c9ee1b2 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.4 2004-11-27 21:44:48 pixel Exp $ */ - -#include -#include -#include -#include -#include -#include -#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.5 2004-11-27 21:47:56 pixel Exp $ */ + +#include +#include +#include +#include +#include +#include +#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-res.h b/luapatch-res.h index 2abf630..2d6d917 100644 --- a/luapatch-res.h +++ b/luapatch-res.h @@ -1,34 +1,34 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by luapatch.rc -// -#define IDD_FILESELECT 101 -#define IDD_ABOUT 102 -#define ID_FILE_QUIT 104 -#define IDI_ICON 105 -#define IDC_ABOUTTEXT 1001 -#define IDC_ABOUT 1003 -#define IDC_ST_SOURCETYPE 1004 -#define IDC_SOURCETYPE 1007 -#define IDC_ST_SOURCE 1008 -#define IDC_DRIVE 1009 -#define IDC_DEST 1010 -#define IDC_DEST_SELECT 1011 -#define IDC_ST_DEST 1012 -#define IDC_PATCH 1013 -#define IDC_ST_PATCH 1014 -#define IDC_PATCH_SELECT 1015 -#define IDC_SOURCE 1016 -#define IDC_SOURCEFILE_SELECT 1017 -#define IDC_SOURCE_SELECT 1017 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 107 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1015 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by luapatch.rc +// +#define IDD_FILESELECT 101 +#define IDD_ABOUT 102 +#define ID_FILE_QUIT 104 +#define IDI_ICON 105 +#define IDC_ABOUTTEXT 1001 +#define IDC_ABOUT 1003 +#define IDC_ST_SOURCETYPE 1004 +#define IDC_SOURCETYPE 1007 +#define IDC_ST_SOURCE 1008 +#define IDC_DRIVE 1009 +#define IDC_DEST 1010 +#define IDC_DEST_SELECT 1011 +#define IDC_ST_DEST 1012 +#define IDC_PATCH 1013 +#define IDC_ST_PATCH 1014 +#define IDC_PATCH_SELECT 1015 +#define IDC_SOURCE 1016 +#define IDC_SOURCEFILE_SELECT 1017 +#define IDC_SOURCE_SELECT 1017 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 107 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1015 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/luapatch.cpp b/luapatch.cpp index 8e5c8ee..7665b9e 100644 --- a/luapatch.cpp +++ b/luapatch.cpp @@ -1,599 +1,599 @@ -#include - -#include -#include -#include -#include -#include - -#include "cdabstract.h" -#include "cdutils.h" -#include "isobuilder.h" -#include "luacd.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; -} - -bool Verify(HWND); - -enum strings_e { - ISOFILE, - CDDRIVE, - ISOSOURCE, - ISODEST, - PATCH, - NO_DESTINATION, - NO_SOURCE, - NO_PATCH, - MSGERROR, -}; - -bool quit = false; -bool canprobe; -bool fromdrive = false; - -String source, dest, patch; - -struct texts_t { - int id; - int owner; - char * str; -}; - -struct texts_t t_english[] = { - {ISOFILE, 0, "Iso file"}, - {CDDRIVE, 0, "CD drive"}, - {ISODEST, 0, "2352-raw image (*.bin)\0*.BIN\0\0\0"}, - {ISOSOURCE, 0, "2352-raw image (*.bin, *.iso, *.img)\0*.BIN;*.ISO;*.IMG\0\0\0"}, - {PATCH, 0, "PAQ Archive (*.paq)\0*.PAQ\0\0\0"}, - {MSGERROR, 0, "Error"}, - {NO_DESTINATION, 0, "No destination file."}, - {NO_SOURCE, 0, "No source file."}, - {NO_PATCH, 0, "No patch file."}, - {-1, 0} -}; - -struct texts_t t_french[] = { - {IDC_ABOUTTEXT, IDD_ABOUT, -"LuaPatch version 0.3.0\n" -"Version artisanale spéciale MFC \"Eve\"\n\n" -"Un système de patch de CD\n\n" -"Copyrignt © 2003-2004 Nicolas \"Pixel\" Noble / NOBIS\n\n" -"http://www.nobis-crew.org/luapatch/\n" -"http://www.nobis-crew.org/"}, - {IDCANCEL, IDD_FILESELECT, "Quitter"}, - {IDC_ABOUT, IDD_FILESELECT, "A propos"}, - {IDC_ST_SOURCETYPE, IDD_FILESELECT, "Type de source:"}, - {IDC_ST_DEST, IDD_FILESELECT, "Fichier de destination:"}, - {IDC_ST_PATCH, IDD_FILESELECT, "Fichier de patch:"}, - {ISOFILE, 0, "Fichier ISO"}, - {CDDRIVE, 0, "Lecteur CD"}, - {ISODEST, 0, "Image ISO 2352-raw (*.bin)\0*.BIN\0\0\0"}, - {ISOSOURCE, 0, "Image ISO 2352-raw (*.bin, *.iso, *.img)\0*.BIN;*.ISO;*.IMG\0\0\0"}, - {PATCH, 0, "Archive PAQ (*.paq)\0*.PAQ\0\0\0"}, - {MSGERROR, 0, "Erreur"}, - {NO_DESTINATION, 0, "Pas de fichier de destination."}, - {NO_SOURCE, 0, "Pas de fichier source."}, - {NO_PATCH, 0, "Pas de fichier patch."}, - {-1, 0} -}; - -struct texts_t t_german[] = { - {IDC_ABOUTTEXT, IDD_ABOUT, -"LuaPatch version 0.3.0\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" -"http://www.nobis-crew.org/"}, - {IDCANCEL, IDD_FILESELECT, "Beenden"}, - {IDC_ABOUT, IDD_FILESELECT, "Info"}, - {IDC_ST_SOURCETYPE, IDD_FILESELECT, "Quelletyp:"}, - {IDC_ST_SOURCE, IDD_FILESELECT, "Quelle:"}, - {IDC_ST_DEST, IDD_FILESELECT, "Ziel Datei:"}, - {IDC_ST_PATCH, IDD_FILESELECT, "Patch Datei:"}, - {ISOFILE, 0, "Iso Image"}, - {CDDRIVE, 0, "CD Laufwerk"}, - {ISODEST, 0, "ISO Image 2352-raw (*.bin)\0*.BIN\0\0\0"}, - {ISOSOURCE, 0, "ISO Image 2352-raw (*.bin, *.iso, *.img)\0*.BIN;*.ISO;*.IMG\0\0\0"}, - {PATCH, 0, "Archiv PAQ (*.paq)\0*.PAQ\0\0\0"}, - {MSGERROR, 0, "Fehler"}, - {NO_DESTINATION, 0, "Keine Zeildatei."}, - {NO_SOURCE, 0, "Keine Quelldatei."}, - {NO_PATCH, 0, "Keine Patchdatei."}, - {-1, 0} -}; - -struct trad_t { - int langid; - struct texts_t * trad; -}; - -struct trad_t trads[] = { - {LANG_NEUTRAL, t_english}, - {LANG_FRENCH, t_french}, - {LANG_GERMAN, t_german}, - {-1, 0} -}; - -int langid; - -enum { - DEST_SELECT, - SOURCE_SELECT, - PATCH_SELECT, -}; - -void translate(int ownerid, HWND hW) { - struct trad_t * t; - struct texts_t * txt; - - for (t = trads; t->trad && t->langid != langid; t++); - - if (!t->trad) - return; - - for (txt = t->trad; txt->str; txt++) { - if (txt->owner == ownerid) - SetDlgItemText(hW, txt->id, txt->str); - } -} - -const char * GetString(int id) { - struct trad_t * t; - struct texts_t * txt; - int oldlangid = langid; - const char * r; - - for (t = trads; t->trad && t->langid != langid; t++); - - if (!t->trad) { - oldlangid = langid; - langid = LANG_NEUTRAL; - r = GetString(id); - langid = oldlangid; - return r; - } - - for (txt = t->trad; txt->str; txt++) { - if ((txt->owner == 0) && (txt->id == id)) - return txt->str; - } - - if (langid == LANG_NEUTRAL) - return NULL; - - oldlangid = langid; - langid = LANG_NEUTRAL; - r = GetString(id); - langid = oldlangid; - return r; -} - -void ChooseFile(HWND hW, int iFType) { - OPENFILENAME ofn; - char szB[260]; - BOOL b; - - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = hW; - ofn.hInstance = NULL; - - switch (iFType) { - case DEST_SELECT: - ofn.lpstrFilter = GetString(ISODEST); - GetDlgItemText(hW, IDC_DEST, szB, 259); - break; - case SOURCE_SELECT: - ofn.lpstrFilter = GetString(ISOSOURCE); - GetDlgItemText(hW, IDC_SOURCE, szB, 259); - break; - case PATCH_SELECT: - ofn.lpstrFilter = GetString(PATCH); - GetDlgItemText(hW, IDC_PATCH, szB, 259); - break; - } - - ofn.lpstrCustomFilter=NULL; - ofn.nMaxCustFilter=0; - ofn.nFilterIndex=0; - - ofn.lpstrFile = szB; - ofn.nMaxFile = 259; - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = NULL; - ofn.lpstrTitle = NULL; - - ofn.nFileOffset=0; - ofn.nFileExtension=0; - ofn.lpstrDefExt=0; - ofn.lCustData=0; - ofn.lpfnHook=NULL; - ofn.lpTemplateName=NULL; - - if (iFType == DEST_SELECT) { - ofn.Flags = OFN_CREATEPROMPT | - OFN_NOCHANGEDIR | - OFN_HIDEREADONLY | - OFN_OVERWRITEPROMPT; - b = GetSaveFileName(&ofn); - } else { - ofn.Flags = OFN_FILEMUSTEXIST | - OFN_NOCHANGEDIR | - OFN_HIDEREADONLY; - b = GetOpenFileName(&ofn); - } - - if (b) { - switch (iFType) { - case DEST_SELECT: - SetDlgItemText(hW, IDC_DEST, szB); - break; - case SOURCE_SELECT: - SetDlgItemText(hW, IDC_SOURCE, szB); - break; - case PATCH_SELECT: - SetDlgItemText(hW, IDC_PATCH, szB); - break; - } - } -} - -BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { - RECT r; - POINT p; - int bwidth, bheight, wsize; - HWND button; - - switch (uMsg) { - case WM_INITDIALOG: - translate(IDD_ABOUT, hW); - - button = GetDlgItem(hW, IDOK); - GetWindowRect(button, &r); - p.x = r.left; - p.y = r.top; - ScreenToClient(hW, &p); - bwidth = r.right - r.left; - bheight = r.bottom - r.top; - GetWindowRect(hW, &r); - wsize = r.right - r.left; - MoveWindow(button, wsize / 2 - bwidth / 2, p.y, bwidth, bheight, TRUE); - break; - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDOK: EndDialog(hW, 0); return TRUE; - } - break; - } - return FALSE; -} - -BOOL CALLBACK FileSelectDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { - RECT r; - POINT p; - int bwidth, bheight, wsize; - HWND button, control; - - switch (uMsg) { - case WM_INITDIALOG: - translate(IDD_FILESELECT, hW); - - control = GetDlgItem(hW, IDC_SOURCETYPE); - ComboBox_ResetContent(control); - - ComboBox_AddString(control, GetString(ISOFILE)); - ComboBox_SetCurSel(control, 0); - if (canprobe) { - ComboBox_AddString(control, GetString(CDDRIVE)); - ComboBox_SetCurSel(control, 1); - - control = GetDlgItem(hW, IDC_DRIVE); - - std::vector p; - p = cdabstract::probe(); - - for (std::vector::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); - ShowWindow(GetDlgItem(hW, IDC_SOURCE_SELECT), SW_HIDE); - } else { - EnableWindow(control, false); - } - - button = GetDlgItem(hW, IDOK); - GetWindowRect(button, &r); - p.x = r.left; - p.y = r.top; - ScreenToClient(hW, &p); - bwidth = r.right - r.left; - bheight = r.bottom - r.top; - GetWindowRect(hW, &r); - wsize = r.right - r.left; - MoveWindow(button, wsize / 2 - bwidth / 2, p.y, bwidth, bheight, TRUE); - break; - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDOK: - if (Verify(hW)) - EndDialog(hW, 0); - return TRUE; - case IDCANCEL: - EndDialog(hW, 0); - quit = true; - return TRUE; - case IDC_ABOUT: - DialogBox(0, MAKEINTRESOURCE(IDD_ABOUT), - GetActiveWindow(), AboutDlgProc); - return TRUE; - case IDC_SOURCETYPE: - if (HIWORD(wParam) != CBN_SELCHANGE) - return FALSE; - if (ComboBox_GetCurSel(GetDlgItem(hW, IDC_SOURCETYPE))) { - fromdrive = true; - ShowWindow(GetDlgItem(hW, IDC_DRIVE), SW_SHOW); - ShowWindow(GetDlgItem(hW, IDC_SOURCE), SW_HIDE); - ShowWindow(GetDlgItem(hW, IDC_SOURCE_SELECT), SW_HIDE); - } else { - fromdrive = false; - ShowWindow(GetDlgItem(hW, IDC_DRIVE), SW_HIDE); - ShowWindow(GetDlgItem(hW, IDC_SOURCE), SW_SHOW); - ShowWindow(GetDlgItem(hW, IDC_SOURCE_SELECT), SW_SHOW); - } - break; - case IDC_SOURCE_SELECT: - ChooseFile(hW, SOURCE_SELECT); - break; - case IDC_PATCH_SELECT: - ChooseFile(hW, PATCH_SELECT); - break; - case IDC_DEST_SELECT: - ChooseFile(hW, DEST_SELECT); - break; - } - break; - } - return FALSE; -} - -bool Verify(HWND hW) { - char szB[260]; - - GetDlgItemText(hW, IDC_DEST, szB, 259); - if (!szB[0]) { - MessageBox(hW, GetString(NO_DESTINATION), GetString(MSGERROR), MB_OK | MB_ICONERROR); - return false; - } - dest = szB; - - GetDlgItemText(hW, IDC_PATCH, szB, 259); - if (!szB[0]) { - MessageBox(hW, GetString(NO_PATCH), GetString(MSGERROR), MB_OK | MB_ICONERROR); - return false; - } - patch = szB; - - GetDlgItemText(hW, IDC_SOURCE, szB, 259); - if (!szB[0] && !fromdrive) { - MessageBox(hW, GetString(NO_SOURCE), GetString(MSGERROR), MB_OK | MB_ICONERROR); - return false; - } - if (fromdrive) { - GetDlgItemText(hW, IDC_DRIVE, szB, 259); - source = String("cd:") + szB; - } else { - source = szB; - } - - return true; -} - -CODE_BEGINS -virtual int startup(void) throw (GeneralException) { - verbosity = M_INFO; - printm(M_BARE, "LuaPatch (C) 2004 Nicolas \"Pixel\" Noble - front-end starting.\n"); - - int lang; - lang = GetUserDefaultLangID(); - langid = PRIMARYLANGID(lang); - - canprobe = cdabstract::canprobe(); - - DialogBox(0, MAKEINTRESOURCE(IDD_FILESELECT), - GetActiveWindow(), FileSelectDlgProc); - - if (quit) - exit(0); - - 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)); - 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; - - return 0; -} -CODE_ENDS - -#if 0 - String message; - char bleh[256]; - switch (uMsg) { -case 0x0000: message="WM_NULL"; break; -case 0x0001: message="WM_CREATE"; break; -case 0x0002: message="WM_DESTROY"; break; -case 0x0003: message="WM_MOVE"; break; -case 0x0005: message="WM_SIZE"; break; -case 0x0006: message="WM_ACTIVATE"; break; -case 0x0007: message="WM_SETFOCUS"; break; -case 0x0008: message="WM_KILLFOCUS"; break; -case 0x000A: message="WM_ENABLE"; break; -case 0x000B: message="WM_SETREDRAW"; break; -case 0x000C: message="WM_SETTEXT"; break; -case 0x000D: message="WM_GETTEXT"; break; -case 0x000E: message="WM_GETTEXTLENGTH"; break; -case 0x000F: message="WM_PAINT"; break; -case 0x0010: message="WM_CLOSE"; break; -case 0x0011: message="WM_QUERYENDSESSION"; break; -case 0x0013: message="WM_QUERYOPEN"; break; -case 0x0016: message="WM_ENDSESSION"; break; -case 0x0012: message="WM_QUIT"; break; -case 0x0014: message="WM_ERASEBKGND"; break; -case 0x0015: message="WM_SYSCOLORCHANGE"; break; -case 0x0018: message="WM_SHOWWINDOW"; break; -case 0x001A: message="WM_WININICHANGE"; break; -case 0x001B: message="WM_DEVMODECHANGE"; break; -case 0x001C: message="WM_ACTIVATEAPP"; break; -case 0x001D: message="WM_FONTCHANGE"; break; -case 0x001E: message="WM_TIMECHANGE"; break; -case 0x001F: message="WM_CANCELMODE"; break; -case 0x0020: message="WM_SETCURSOR"; break; -case 0x0021: message="WM_MOUSEACTIVATE"; break; -case 0x0022: message="WM_CHILDACTIVATE"; break; -case 0x0023: message="WM_QUEUESYNC"; break; -case 0x0024: message="WM_GETMINMAXINFO"; break; -case 0x0026: message="WM_PAINTICON"; break; -case 0x0027: message="WM_ICONERASEBKGND"; break; -case 0x0028: message="WM_NEXTDLGCTL"; break; -case 0x002A: message="WM_SPOOLERSTATUS"; break; -case 0x002B: message="WM_DRAWITEM"; break; -case 0x002C: message="WM_MEASUREITEM"; break; -case 0x002D: message="WM_DELETEITEM"; break; -case 0x002E: message="WM_VKEYTOITEM"; break; -case 0x002F: message="WM_CHARTOITEM"; break; -case 0x0030: message="WM_SETFONT"; break; -case 0x0031: message="WM_GETFONT"; break; -case 0x0032: message="WM_SETHOTKEY"; break; -case 0x0033: message="WM_GETHOTKEY"; break; -case 0x0037: message="WM_QUERYDRAGICON"; break; -case 0x0039: message="WM_COMPAREITEM"; break; -case 0x003D: message="WM_GETOBJECT"; break; -case 0x0041: message="WM_COMPACTING"; break; -case 0x0044: message="WM_COMMNOTIFY"; break; -case 0x0046: message="WM_WINDOWPOSCHANGING"; break; -case 0x0047: message="WM_WINDOWPOSCHANGED"; break; -case 0x0048: message="WM_POWER"; break; -case 0x004A: message="WM_COPYDATA"; break; -case 0x004B: message="WM_CANCELJOURNAL"; break; -case 0x004E: message="WM_NOTIFY"; break; -case 0x0050: message="WM_INPUTLANGCHANGEREQUEST"; break; -case 0x0051: message="WM_INPUTLANGCHANGE"; break; -case 0x0052: message="WM_TCARD"; break; -case 0x0053: message="WM_HELP"; break; -case 0x0054: message="WM_USERCHANGED"; break; -case 0x0055: message="WM_NOTIFYFORMAT"; break; -case 0x007B: message="WM_CONTEXTMENU"; break; -case 0x007C: message="WM_STYLECHANGING"; break; -case 0x007D: message="WM_STYLECHANGED"; break; -case 0x007E: message="WM_DISPLAYCHANGE"; break; -case 0x007F: message="WM_GETICON"; break; -case 0x0080: message="WM_SETICON"; break; -case 0x0081: message="WM_NCCREATE"; break; -case 0x0082: message="WM_NCDESTROY"; break; -case 0x0083: message="WM_NCCALCSIZE"; break; -case 0x0084: message="WM_NCHITTEST"; break; -case 0x0085: message="WM_NCPAINT"; break; -case 0x0086: message="WM_NCACTIVATE"; break; -case 0x0087: message="WM_GETDLGCODE"; break; -case 0x0088: message="WM_SYNCPAINT"; break; -case 0x00A0: message="WM_NCMOUSEMOVE"; break; -case 0x00A1: message="WM_NCLBUTTONDOWN"; break; -case 0x00A2: message="WM_NCLBUTTONUP"; break; -case 0x00A3: message="WM_NCLBUTTONDBLCLK"; break; -case 0x00A4: message="WM_NCRBUTTONDOWN"; break; -case 0x00A5: message="WM_NCRBUTTONUP"; break; -case 0x00A6: message="WM_NCRBUTTONDBLCLK"; break; -case 0x00A7: message="WM_NCMBUTTONDOWN"; break; -case 0x00A8: message="WM_NCMBUTTONUP"; break; -case 0x00A9: message="WM_NCMBUTTONDBLCLK"; break; -case 0x00AB: message="WM_NCXBUTTONDOWN"; break; -case 0x00AC: message="WM_NCXBUTTONUP"; break; -case 0x00AD: message="WM_NCXBUTTONDBLCLK"; break; -case 0x00FF: message="WM_INPUT"; break; -case 0x0100: message="WM_KEYFIRST"; break; -case 0x0101: message="WM_KEYUP"; break; -case 0x0102: message="WM_CHAR"; break; -case 0x0103: message="WM_DEADCHAR"; break; -case 0x0104: message="WM_SYSKEYDOWN"; break; -case 0x0105: message="WM_SYSKEYUP"; break; -case 0x0106: message="WM_SYSCHAR"; break; -case 0x0107: message="WM_SYSDEADCHAR"; break; -case 0x0109: message="WM_UNICHAR"; break; -case 0x0108: message="WM_KEYLAST"; break; -case 0x010D: message="WM_IME_STARTCOMPOSITION"; break; -case 0x010E: message="WM_IME_ENDCOMPOSITION"; break; -case 0x010F: message="WM_IME_COMPOSITION"; break; -case 0x0110: message="WM_INITDIALOG"; break; -case 0x0111: message="WM_COMMAND"; break; -case 0x0112: message="WM_SYSCOMMAND"; break; -case 0x0113: message="WM_TIMER"; break; -case 0x0114: message="WM_HSCROLL"; break; -case 0x0115: message="WM_VSCROLL"; break; -case 0x0116: message="WM_INITMENU"; break; -case 0x0117: message="WM_INITMENUPOPUP"; break; -case 0x011F: message="WM_MENUSELECT"; break; -case 0x0120: message="WM_MENUCHAR"; break; -case 0x0121: message="WM_ENTERIDLE"; break; -case 0x0122: message="WM_MENURBUTTONUP"; break; -case 0x0123: message="WM_MENUDRAG"; break; -case 0x0124: message="WM_MENUGETOBJECT"; break; -case 0x0125: message="WM_UNINITMENUPOPUP"; break; -case 0x0126: message="WM_MENUCOMMAND"; break; -case 0x0127: message="WM_CHANGEUISTATE"; break; -case 0x0128: message="WM_UPDATEUISTATE"; break; -case 0x0129: message="WM_QUERYUISTATE"; break; -default: message="Unknown"; break; - } - sprintf(bleh, " (0x%04x)\n", uMsg); - message = "AboutDlgProc: uMsg = " + message + bleh; - Base::printm(M_STATUS, message); -#endif +#include + +#include +#include +#include +#include +#include + +#include "cdabstract.h" +#include "cdutils.h" +#include "isobuilder.h" +#include "luacd.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; +} + +bool Verify(HWND); + +enum strings_e { + ISOFILE, + CDDRIVE, + ISOSOURCE, + ISODEST, + PATCH, + NO_DESTINATION, + NO_SOURCE, + NO_PATCH, + MSGERROR, +}; + +bool quit = false; +bool canprobe; +bool fromdrive = false; + +String source, dest, patch; + +struct texts_t { + int id; + int owner; + char * str; +}; + +struct texts_t t_english[] = { + {ISOFILE, 0, "Iso file"}, + {CDDRIVE, 0, "CD drive"}, + {ISODEST, 0, "2352-raw image (*.bin)\0*.BIN\0\0\0"}, + {ISOSOURCE, 0, "2352-raw image (*.bin, *.iso, *.img)\0*.BIN;*.ISO;*.IMG\0\0\0"}, + {PATCH, 0, "PAQ Archive (*.paq)\0*.PAQ\0\0\0"}, + {MSGERROR, 0, "Error"}, + {NO_DESTINATION, 0, "No destination file."}, + {NO_SOURCE, 0, "No source file."}, + {NO_PATCH, 0, "No patch file."}, + {-1, 0} +}; + +struct texts_t t_french[] = { + {IDC_ABOUTTEXT, IDD_ABOUT, +"LuaPatch version 0.3.0\n" +"Version artisanale spéciale MFC \"Eve\"\n\n" +"Un système de patch de CD\n\n" +"Copyrignt © 2003-2004 Nicolas \"Pixel\" Noble / NOBIS\n\n" +"http://www.nobis-crew.org/luapatch/\n" +"http://www.nobis-crew.org/"}, + {IDCANCEL, IDD_FILESELECT, "Quitter"}, + {IDC_ABOUT, IDD_FILESELECT, "A propos"}, + {IDC_ST_SOURCETYPE, IDD_FILESELECT, "Type de source:"}, + {IDC_ST_DEST, IDD_FILESELECT, "Fichier de destination:"}, + {IDC_ST_PATCH, IDD_FILESELECT, "Fichier de patch:"}, + {ISOFILE, 0, "Fichier ISO"}, + {CDDRIVE, 0, "Lecteur CD"}, + {ISODEST, 0, "Image ISO 2352-raw (*.bin)\0*.BIN\0\0\0"}, + {ISOSOURCE, 0, "Image ISO 2352-raw (*.bin, *.iso, *.img)\0*.BIN;*.ISO;*.IMG\0\0\0"}, + {PATCH, 0, "Archive PAQ (*.paq)\0*.PAQ\0\0\0"}, + {MSGERROR, 0, "Erreur"}, + {NO_DESTINATION, 0, "Pas de fichier de destination."}, + {NO_SOURCE, 0, "Pas de fichier source."}, + {NO_PATCH, 0, "Pas de fichier patch."}, + {-1, 0} +}; + +struct texts_t t_german[] = { + {IDC_ABOUTTEXT, IDD_ABOUT, +"LuaPatch version 0.3.0\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" +"http://www.nobis-crew.org/"}, + {IDCANCEL, IDD_FILESELECT, "Beenden"}, + {IDC_ABOUT, IDD_FILESELECT, "Info"}, + {IDC_ST_SOURCETYPE, IDD_FILESELECT, "Quelletyp:"}, + {IDC_ST_SOURCE, IDD_FILESELECT, "Quelle:"}, + {IDC_ST_DEST, IDD_FILESELECT, "Ziel Datei:"}, + {IDC_ST_PATCH, IDD_FILESELECT, "Patch Datei:"}, + {ISOFILE, 0, "Iso Image"}, + {CDDRIVE, 0, "CD Laufwerk"}, + {ISODEST, 0, "ISO Image 2352-raw (*.bin)\0*.BIN\0\0\0"}, + {ISOSOURCE, 0, "ISO Image 2352-raw (*.bin, *.iso, *.img)\0*.BIN;*.ISO;*.IMG\0\0\0"}, + {PATCH, 0, "Archiv PAQ (*.paq)\0*.PAQ\0\0\0"}, + {MSGERROR, 0, "Fehler"}, + {NO_DESTINATION, 0, "Keine Zeildatei."}, + {NO_SOURCE, 0, "Keine Quelldatei."}, + {NO_PATCH, 0, "Keine Patchdatei."}, + {-1, 0} +}; + +struct trad_t { + int langid; + struct texts_t * trad; +}; + +struct trad_t trads[] = { + {LANG_NEUTRAL, t_english}, + {LANG_FRENCH, t_french}, + {LANG_GERMAN, t_german}, + {-1, 0} +}; + +int langid; + +enum { + DEST_SELECT, + SOURCE_SELECT, + PATCH_SELECT, +}; + +void translate(int ownerid, HWND hW) { + struct trad_t * t; + struct texts_t * txt; + + for (t = trads; t->trad && t->langid != langid; t++); + + if (!t->trad) + return; + + for (txt = t->trad; txt->str; txt++) { + if (txt->owner == ownerid) + SetDlgItemText(hW, txt->id, txt->str); + } +} + +const char * GetString(int id) { + struct trad_t * t; + struct texts_t * txt; + int oldlangid = langid; + const char * r; + + for (t = trads; t->trad && t->langid != langid; t++); + + if (!t->trad) { + oldlangid = langid; + langid = LANG_NEUTRAL; + r = GetString(id); + langid = oldlangid; + return r; + } + + for (txt = t->trad; txt->str; txt++) { + if ((txt->owner == 0) && (txt->id == id)) + return txt->str; + } + + if (langid == LANG_NEUTRAL) + return NULL; + + oldlangid = langid; + langid = LANG_NEUTRAL; + r = GetString(id); + langid = oldlangid; + return r; +} + +void ChooseFile(HWND hW, int iFType) { + OPENFILENAME ofn; + char szB[260]; + BOOL b; + + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = hW; + ofn.hInstance = NULL; + + switch (iFType) { + case DEST_SELECT: + ofn.lpstrFilter = GetString(ISODEST); + GetDlgItemText(hW, IDC_DEST, szB, 259); + break; + case SOURCE_SELECT: + ofn.lpstrFilter = GetString(ISOSOURCE); + GetDlgItemText(hW, IDC_SOURCE, szB, 259); + break; + case PATCH_SELECT: + ofn.lpstrFilter = GetString(PATCH); + GetDlgItemText(hW, IDC_PATCH, szB, 259); + break; + } + + ofn.lpstrCustomFilter=NULL; + ofn.nMaxCustFilter=0; + ofn.nFilterIndex=0; + + ofn.lpstrFile = szB; + ofn.nMaxFile = 259; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.lpstrTitle = NULL; + + ofn.nFileOffset=0; + ofn.nFileExtension=0; + ofn.lpstrDefExt=0; + ofn.lCustData=0; + ofn.lpfnHook=NULL; + ofn.lpTemplateName=NULL; + + if (iFType == DEST_SELECT) { + ofn.Flags = OFN_CREATEPROMPT | + OFN_NOCHANGEDIR | + OFN_HIDEREADONLY | + OFN_OVERWRITEPROMPT; + b = GetSaveFileName(&ofn); + } else { + ofn.Flags = OFN_FILEMUSTEXIST | + OFN_NOCHANGEDIR | + OFN_HIDEREADONLY; + b = GetOpenFileName(&ofn); + } + + if (b) { + switch (iFType) { + case DEST_SELECT: + SetDlgItemText(hW, IDC_DEST, szB); + break; + case SOURCE_SELECT: + SetDlgItemText(hW, IDC_SOURCE, szB); + break; + case PATCH_SELECT: + SetDlgItemText(hW, IDC_PATCH, szB); + break; + } + } +} + +BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { + RECT r; + POINT p; + int bwidth, bheight, wsize; + HWND button; + + switch (uMsg) { + case WM_INITDIALOG: + translate(IDD_ABOUT, hW); + + button = GetDlgItem(hW, IDOK); + GetWindowRect(button, &r); + p.x = r.left; + p.y = r.top; + ScreenToClient(hW, &p); + bwidth = r.right - r.left; + bheight = r.bottom - r.top; + GetWindowRect(hW, &r); + wsize = r.right - r.left; + MoveWindow(button, wsize / 2 - bwidth / 2, p.y, bwidth, bheight, TRUE); + break; + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: EndDialog(hW, 0); return TRUE; + } + break; + } + return FALSE; +} + +BOOL CALLBACK FileSelectDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { + RECT r; + POINT p; + int bwidth, bheight, wsize; + HWND button, control; + + switch (uMsg) { + case WM_INITDIALOG: + translate(IDD_FILESELECT, hW); + + control = GetDlgItem(hW, IDC_SOURCETYPE); + ComboBox_ResetContent(control); + + ComboBox_AddString(control, GetString(ISOFILE)); + ComboBox_SetCurSel(control, 0); + if (canprobe) { + ComboBox_AddString(control, GetString(CDDRIVE)); + ComboBox_SetCurSel(control, 1); + + control = GetDlgItem(hW, IDC_DRIVE); + + std::vector p; + p = cdabstract::probe(); + + for (std::vector::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); + ShowWindow(GetDlgItem(hW, IDC_SOURCE_SELECT), SW_HIDE); + } else { + EnableWindow(control, false); + } + + button = GetDlgItem(hW, IDOK); + GetWindowRect(button, &r); + p.x = r.left; + p.y = r.top; + ScreenToClient(hW, &p); + bwidth = r.right - r.left; + bheight = r.bottom - r.top; + GetWindowRect(hW, &r); + wsize = r.right - r.left; + MoveWindow(button, wsize / 2 - bwidth / 2, p.y, bwidth, bheight, TRUE); + break; + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: + if (Verify(hW)) + EndDialog(hW, 0); + return TRUE; + case IDCANCEL: + EndDialog(hW, 0); + quit = true; + return TRUE; + case IDC_ABOUT: + DialogBox(0, MAKEINTRESOURCE(IDD_ABOUT), + GetActiveWindow(), AboutDlgProc); + return TRUE; + case IDC_SOURCETYPE: + if (HIWORD(wParam) != CBN_SELCHANGE) + return FALSE; + if (ComboBox_GetCurSel(GetDlgItem(hW, IDC_SOURCETYPE))) { + fromdrive = true; + ShowWindow(GetDlgItem(hW, IDC_DRIVE), SW_SHOW); + ShowWindow(GetDlgItem(hW, IDC_SOURCE), SW_HIDE); + ShowWindow(GetDlgItem(hW, IDC_SOURCE_SELECT), SW_HIDE); + } else { + fromdrive = false; + ShowWindow(GetDlgItem(hW, IDC_DRIVE), SW_HIDE); + ShowWindow(GetDlgItem(hW, IDC_SOURCE), SW_SHOW); + ShowWindow(GetDlgItem(hW, IDC_SOURCE_SELECT), SW_SHOW); + } + break; + case IDC_SOURCE_SELECT: + ChooseFile(hW, SOURCE_SELECT); + break; + case IDC_PATCH_SELECT: + ChooseFile(hW, PATCH_SELECT); + break; + case IDC_DEST_SELECT: + ChooseFile(hW, DEST_SELECT); + break; + } + break; + } + return FALSE; +} + +bool Verify(HWND hW) { + char szB[260]; + + GetDlgItemText(hW, IDC_DEST, szB, 259); + if (!szB[0]) { + MessageBox(hW, GetString(NO_DESTINATION), GetString(MSGERROR), MB_OK | MB_ICONERROR); + return false; + } + dest = szB; + + GetDlgItemText(hW, IDC_PATCH, szB, 259); + if (!szB[0]) { + MessageBox(hW, GetString(NO_PATCH), GetString(MSGERROR), MB_OK | MB_ICONERROR); + return false; + } + patch = szB; + + GetDlgItemText(hW, IDC_SOURCE, szB, 259); + if (!szB[0] && !fromdrive) { + MessageBox(hW, GetString(NO_SOURCE), GetString(MSGERROR), MB_OK | MB_ICONERROR); + return false; + } + if (fromdrive) { + GetDlgItemText(hW, IDC_DRIVE, szB, 259); + source = String("cd:") + szB; + } else { + source = szB; + } + + return true; +} + +CODE_BEGINS +virtual int startup(void) throw (GeneralException) { + verbosity = M_INFO; + printm(M_BARE, "LuaPatch (C) 2004 Nicolas \"Pixel\" Noble - front-end starting.\n"); + + int lang; + lang = GetUserDefaultLangID(); + langid = PRIMARYLANGID(lang); + + canprobe = cdabstract::canprobe(); + + DialogBox(0, MAKEINTRESOURCE(IDD_FILESELECT), + GetActiveWindow(), FileSelectDlgProc); + + if (quit) + exit(0); + + 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)); + 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; + + return 0; +} +CODE_ENDS + +#if 0 + String message; + char bleh[256]; + switch (uMsg) { +case 0x0000: message="WM_NULL"; break; +case 0x0001: message="WM_CREATE"; break; +case 0x0002: message="WM_DESTROY"; break; +case 0x0003: message="WM_MOVE"; break; +case 0x0005: message="WM_SIZE"; break; +case 0x0006: message="WM_ACTIVATE"; break; +case 0x0007: message="WM_SETFOCUS"; break; +case 0x0008: message="WM_KILLFOCUS"; break; +case 0x000A: message="WM_ENABLE"; break; +case 0x000B: message="WM_SETREDRAW"; break; +case 0x000C: message="WM_SETTEXT"; break; +case 0x000D: message="WM_GETTEXT"; break; +case 0x000E: message="WM_GETTEXTLENGTH"; break; +case 0x000F: message="WM_PAINT"; break; +case 0x0010: message="WM_CLOSE"; break; +case 0x0011: message="WM_QUERYENDSESSION"; break; +case 0x0013: message="WM_QUERYOPEN"; break; +case 0x0016: message="WM_ENDSESSION"; break; +case 0x0012: message="WM_QUIT"; break; +case 0x0014: message="WM_ERASEBKGND"; break; +case 0x0015: message="WM_SYSCOLORCHANGE"; break; +case 0x0018: message="WM_SHOWWINDOW"; break; +case 0x001A: message="WM_WININICHANGE"; break; +case 0x001B: message="WM_DEVMODECHANGE"; break; +case 0x001C: message="WM_ACTIVATEAPP"; break; +case 0x001D: message="WM_FONTCHANGE"; break; +case 0x001E: message="WM_TIMECHANGE"; break; +case 0x001F: message="WM_CANCELMODE"; break; +case 0x0020: message="WM_SETCURSOR"; break; +case 0x0021: message="WM_MOUSEACTIVATE"; break; +case 0x0022: message="WM_CHILDACTIVATE"; break; +case 0x0023: message="WM_QUEUESYNC"; break; +case 0x0024: message="WM_GETMINMAXINFO"; break; +case 0x0026: message="WM_PAINTICON"; break; +case 0x0027: message="WM_ICONERASEBKGND"; break; +case 0x0028: message="WM_NEXTDLGCTL"; break; +case 0x002A: message="WM_SPOOLERSTATUS"; break; +case 0x002B: message="WM_DRAWITEM"; break; +case 0x002C: message="WM_MEASUREITEM"; break; +case 0x002D: message="WM_DELETEITEM"; break; +case 0x002E: message="WM_VKEYTOITEM"; break; +case 0x002F: message="WM_CHARTOITEM"; break; +case 0x0030: message="WM_SETFONT"; break; +case 0x0031: message="WM_GETFONT"; break; +case 0x0032: message="WM_SETHOTKEY"; break; +case 0x0033: message="WM_GETHOTKEY"; break; +case 0x0037: message="WM_QUERYDRAGICON"; break; +case 0x0039: message="WM_COMPAREITEM"; break; +case 0x003D: message="WM_GETOBJECT"; break; +case 0x0041: message="WM_COMPACTING"; break; +case 0x0044: message="WM_COMMNOTIFY"; break; +case 0x0046: message="WM_WINDOWPOSCHANGING"; break; +case 0x0047: message="WM_WINDOWPOSCHANGED"; break; +case 0x0048: message="WM_POWER"; break; +case 0x004A: message="WM_COPYDATA"; break; +case 0x004B: message="WM_CANCELJOURNAL"; break; +case 0x004E: message="WM_NOTIFY"; break; +case 0x0050: message="WM_INPUTLANGCHANGEREQUEST"; break; +case 0x0051: message="WM_INPUTLANGCHANGE"; break; +case 0x0052: message="WM_TCARD"; break; +case 0x0053: message="WM_HELP"; break; +case 0x0054: message="WM_USERCHANGED"; break; +case 0x0055: message="WM_NOTIFYFORMAT"; break; +case 0x007B: message="WM_CONTEXTMENU"; break; +case 0x007C: message="WM_STYLECHANGING"; break; +case 0x007D: message="WM_STYLECHANGED"; break; +case 0x007E: message="WM_DISPLAYCHANGE"; break; +case 0x007F: message="WM_GETICON"; break; +case 0x0080: message="WM_SETICON"; break; +case 0x0081: message="WM_NCCREATE"; break; +case 0x0082: message="WM_NCDESTROY"; break; +case 0x0083: message="WM_NCCALCSIZE"; break; +case 0x0084: message="WM_NCHITTEST"; break; +case 0x0085: message="WM_NCPAINT"; break; +case 0x0086: message="WM_NCACTIVATE"; break; +case 0x0087: message="WM_GETDLGCODE"; break; +case 0x0088: message="WM_SYNCPAINT"; break; +case 0x00A0: message="WM_NCMOUSEMOVE"; break; +case 0x00A1: message="WM_NCLBUTTONDOWN"; break; +case 0x00A2: message="WM_NCLBUTTONUP"; break; +case 0x00A3: message="WM_NCLBUTTONDBLCLK"; break; +case 0x00A4: message="WM_NCRBUTTONDOWN"; break; +case 0x00A5: message="WM_NCRBUTTONUP"; break; +case 0x00A6: message="WM_NCRBUTTONDBLCLK"; break; +case 0x00A7: message="WM_NCMBUTTONDOWN"; break; +case 0x00A8: message="WM_NCMBUTTONUP"; break; +case 0x00A9: message="WM_NCMBUTTONDBLCLK"; break; +case 0x00AB: message="WM_NCXBUTTONDOWN"; break; +case 0x00AC: message="WM_NCXBUTTONUP"; break; +case 0x00AD: message="WM_NCXBUTTONDBLCLK"; break; +case 0x00FF: message="WM_INPUT"; break; +case 0x0100: message="WM_KEYFIRST"; break; +case 0x0101: message="WM_KEYUP"; break; +case 0x0102: message="WM_CHAR"; break; +case 0x0103: message="WM_DEADCHAR"; break; +case 0x0104: message="WM_SYSKEYDOWN"; break; +case 0x0105: message="WM_SYSKEYUP"; break; +case 0x0106: message="WM_SYSCHAR"; break; +case 0x0107: message="WM_SYSDEADCHAR"; break; +case 0x0109: message="WM_UNICHAR"; break; +case 0x0108: message="WM_KEYLAST"; break; +case 0x010D: message="WM_IME_STARTCOMPOSITION"; break; +case 0x010E: message="WM_IME_ENDCOMPOSITION"; break; +case 0x010F: message="WM_IME_COMPOSITION"; break; +case 0x0110: message="WM_INITDIALOG"; break; +case 0x0111: message="WM_COMMAND"; break; +case 0x0112: message="WM_SYSCOMMAND"; break; +case 0x0113: message="WM_TIMER"; break; +case 0x0114: message="WM_HSCROLL"; break; +case 0x0115: message="WM_VSCROLL"; break; +case 0x0116: message="WM_INITMENU"; break; +case 0x0117: message="WM_INITMENUPOPUP"; break; +case 0x011F: message="WM_MENUSELECT"; break; +case 0x0120: message="WM_MENUCHAR"; break; +case 0x0121: message="WM_ENTERIDLE"; break; +case 0x0122: message="WM_MENURBUTTONUP"; break; +case 0x0123: message="WM_MENUDRAG"; break; +case 0x0124: message="WM_MENUGETOBJECT"; break; +case 0x0125: message="WM_UNINITMENUPOPUP"; break; +case 0x0126: message="WM_MENUCOMMAND"; break; +case 0x0127: message="WM_CHANGEUISTATE"; break; +case 0x0128: message="WM_UPDATEUISTATE"; break; +case 0x0129: message="WM_QUERYUISTATE"; break; +default: message="Unknown"; break; + } + sprintf(bleh, " (0x%04x)\n", uMsg); + message = "AboutDlgProc: uMsg = " + message + bleh; + Base::printm(M_STATUS, message); +#endif diff --git a/lzss-main.cpp b/lzss-main.cpp index b5587a2..ec17495 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 -#include -#include -#include -#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 ] [-l ] [-S] [-v] \n" -"\n" -"-c --compress Compress to \n" -"-d --decompress Decompress to \n" -"-s --scheme= Loads the built-in scheme number \n" -"-l --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 +#include +#include +#include +#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 ] [-l ] [-S] [-v] \n" +"\n" +"-c --compress Compress to \n" +"-d --decompress Decompress to \n" +"-s --scheme= Loads the built-in scheme number \n" +"-l --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 ef956fd..e4551fb 100644 --- a/mipspoke.cpp +++ b/mipspoke.cpp @@ -1,30 +1,30 @@ -#include -#include - -#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 +#include + +#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 e7c3526..a79a877 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 -#include "bs.h" -#include "common.h" - -/* static const char *copyright = N_("Copyright (C) 2000 by Daniel Balster "); */ - -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 (nbitcount) { - ctxt->bitcount-=n; - ctxt->bitbuf |= x << ctxt->bitcount; - } else { - n-=ctxt->bitcount; - WriteWord(ctxt->bitbuf | (x>>n) ); - if (nbitcount = 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<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>=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;xwidth;x+=16) { - xw = img->width-x; if (xw>16) xw = 16; - for(y=0;yheight;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;inextline; - switch(img->bit) { - case 16: - for(j=0;j>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;jbs_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 +#include "bs.h" +#include "common.h" + +/* static const char *copyright = N_("Copyright (C) 2000 by Daniel Balster "); */ + +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 (nbitcount) { + ctxt->bitcount-=n; + ctxt->bitbuf |= x << ctxt->bitcount; + } else { + n-=ctxt->bitcount; + WriteWord(ctxt->bitbuf | (x>>n) ); + if (nbitcount = 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<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>=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;xwidth;x+=16) { + xw = img->width-x; if (xw>16) xw = 16; + for(y=0;yheight;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;inextline; + switch(img->bit) { + case 16: + for(j=0;j>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;jbs_size * 2); + free (ctxt); + + return rl; +} diff --git a/psxdev/bs.h b/psxdev/bs.h index ac6f22c..ddbe316 100644 --- a/psxdev/bs.h +++ b/psxdev/bs.h @@ -1,94 +1,94 @@ -/* $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 - - 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 -#include -#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.5 2004-11-27 21:48:07 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 + + 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 +#include +#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 be53bc9..6df00e2 100644 --- a/psxdev/common.h +++ b/psxdev/common.h @@ -1,49 +1,49 @@ -/* $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 - - 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 - -#if ENABLE_NLS -#if HAVE_LOCALE_H -#include -#endif -#if HAVE_LIBINTL_H -#include -#endif -#define _(string) gettext(string) -#define N_(string) (string) -#else -#define _(string) (string) -#define N_(string) (string) -#endif - -#endif +/* $Id: common.h,v 1.4 2004-11-27 21:48:07 pixel Exp $ */ + +/* + common stuff + + Copyright (C) 1997, 1998, 1999, 2000 by these people, who contributed to this project + + Daniel Balster + + 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 + +#if ENABLE_NLS +#if HAVE_LOCALE_H +#include +#endif +#if HAVE_LIBINTL_H +#include +#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 5b857e9..345cdb1 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;i16 + * 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>(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 3e50b18..0b50ad3 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 c313cdc..4ff3d06 100644 --- a/psxdev/vlc.c +++ b/psxdev/vlc.c @@ -1,606 +1,606 @@ -#include -#include -#include -#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()<=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<=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_rliqtab[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 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=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=0;y--) - { - memcpy(dst,src,w*2); - src+=w; - dst-=width; - } - } - - free (image); - free (rl); -} +#include +#include +#include +#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()<=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<=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_rliqtab[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 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=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=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 39523aa..10da6c9 100644 --- a/psxdev/xadecode.c +++ b/psxdev/xadecode.c @@ -1,302 +1,302 @@ -/* - author: unknown, probably bitmaster? - slightly modified by dbalster -*/ - -#include -#include -#include -#include -#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 +#include +#include +#include +#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 4714667..b886285 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) (ab?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) (ab?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 de62e50..99ddd15 100644 --- a/str-player.cpp +++ b/str-player.cpp @@ -1,262 +1,262 @@ -#include -#include -#include -#include -#include -#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 +#include +#include +#include +#include +#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 914f2a9..223270c 100644 --- a/str-util.cpp +++ b/str-util.cpp @@ -1,215 +1,215 @@ -#include -#include -#include -#include -#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 +#include +#include +#include +#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 c88df53..eb9dd71 100644 --- a/tile-convert.cpp +++ b/tile-convert.cpp @@ -1,238 +1,238 @@ -#include -#include -#include -#include -#include -#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 +#include +#include +#include +#include +#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 0c5a836..533567c 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 -#include -#include -#include -#include -#include - -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 +#include +#include +#include +#include +#include + +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; +} -- cgit v1.2.3