From 032f74dd1a205a3e2d032e0d0deb60eac8b42de4 Mon Sep 17 00:00:00 2001 From: "SND\\weimingzhi_cp" Date: Mon, 29 Jun 2009 12:48:12 +0000 Subject: implemented cheat search git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@23829 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- ChangeLog | 13 + data/pcsx.glade2 | 632 ++++++++++++++++++++++++++----------------- gui/Cheat.c | 706 ++++++++++++++++++++++++++++++++++++++++++++++++- gui/Gtk2Gui.c | 2 + libpcsxcore/cdriso.c | 8 +- libpcsxcore/cheat.c | 602 +++++++++++++++++++++++++++++++++++++++-- libpcsxcore/cheat.h | 62 ++++- libpcsxcore/psxhw.c | 8 +- libpcsxcore/psxmem.h | 5 +- libpcsxcore/r3000a.c | 5 + plugins/dfsound/alsa.c | 4 +- plugins/dfsound/spu.c | 34 ++- win32/gui/WndMain.c | 16 +- 13 files changed, 1792 insertions(+), 305 deletions(-) diff --git a/ChangeLog b/ChangeLog index 25f66ca0..2d219424 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +June 29, 2009 Wei Mingzhi + + * libpcsxcore/cheat.c: Implemented Cheat Search. + * libpcsxcore/cheat.h: Likewise. + * gui/Cheat.c: Likewise. + * gui/Gtk2Gui.c: Backup the memory for cheat search when continuing emulation. + * data/pcsx.glade2: Tweaked the cheat search dialog for implemention. Fixed + the main menu under newer version of Glade. + * libpcsxcore/r3000a.c: Free cheat search results on exit. + * libpcsxcore/psxmem.h: Fixed a typo in psxMu8(). Removed check for __sh__ + macro. + * win32/gui/WndMain.c: Restarting is no longer needed at first run. + June 20, 2009 Wei Mingzhi * libpcsxcore/misc.c: Fixed a bug which prevented files in a subdirectory diff --git a/data/pcsx.glade2 b/data/pcsx.glade2 index f37cad67..0e3d698c 100644 --- a/data/pcsx.glade2 +++ b/data/pcsx.glade2 @@ -1,14 +1,14 @@ - - - + + + 350 195 True PCSX False - GTK_WIN_POS_CENTER + center pcsx-icon.png @@ -26,64 +26,69 @@ - True Run _CD + True True + False - + - + True + 0.49000000953674316 gtk-cdrom - 1 + 1 - True Run _ISO + True True + False - + - + True gtk-open - 1 + 1 - True Run _BIOS + True True + False - + - + True gtk-convert - 1 + 1 - True Run _EXE + True True + False - + - + True gtk-execute - 1 + 1 @@ -95,16 +100,17 @@ - True E_xit + True True + False - + - + True gtk-quit - 1 + 1 @@ -122,30 +128,32 @@ - True _Continue + True True + False - + True gtk-go-forward - 1 + 1 - True _Reset + True True + False - + True gtk-refresh - 1 + 1 @@ -157,16 +165,17 @@ - True _Switch ISO + True True + False - + - + True gtk-open - 1 + 1 @@ -178,9 +187,10 @@ - True _Save State + True True + False @@ -189,7 +199,7 @@ Slot _1 True - + @@ -198,7 +208,7 @@ Slot _2 True - + @@ -207,7 +217,7 @@ Slot _3 True - + @@ -216,7 +226,7 @@ Slot _4 True - + @@ -225,21 +235,22 @@ Slot _5 True - + - True _Other... + True True + False - + - + True - gtk-open - 1 + gtk-save-as + 1 @@ -247,19 +258,20 @@ - + True gtk-save-as - 1 + 1 - True _Load State + True True + False @@ -268,7 +280,7 @@ Slot _1 True - + @@ -277,7 +289,7 @@ Slot _2 True - + @@ -286,7 +298,7 @@ Slot _3 True - + @@ -295,7 +307,7 @@ Slot _4 True - + @@ -304,21 +316,22 @@ Slot _5 True - + - True _Other... + True True + False - + - + True gtk-open - 1 + 1 @@ -326,10 +339,10 @@ - + True gtk-revert-to-saved - 1 + 1 @@ -347,16 +360,17 @@ - True _Plugins & BIOS + True True + False - + - + True gtk-preferences - 1 + 1 @@ -368,46 +382,49 @@ - True _CPU + True True + False - + True gtk-properties - 1 + 1 - True _Memory Cards + True True + False - + - + True gtk-floppy - 1 + 1 - True _Netplay + True True + False - + True gtk-properties - 1 + 1 @@ -419,36 +436,39 @@ - True Chea_t + True True + False True - True _Browse + True True + False - + True gtk-index - 1 + 1 - True _Search + True True + False - + True gtk-find - 1 + 1 @@ -456,10 +476,10 @@ - + True gtk-indent - 1 + 1 @@ -477,15 +497,16 @@ - True _About PCSX + True True + False - + True - gtk-dialog-question - 1 + gtk-about + 1 @@ -498,6 +519,7 @@ False False + 0 @@ -516,7 +538,7 @@ True Configure PCSX True - GDK_WINDOW_TYPE_HINT_DIALOG + dialog True @@ -613,7 +635,7 @@ True - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER + select-folder Select Folder to Search @@ -645,7 +667,7 @@ True True - 0 + False @@ -689,8 +711,8 @@ True - - + + @@ -727,7 +749,7 @@ True True - 0 + False @@ -749,7 +771,7 @@ True True - 0 + False @@ -771,7 +793,7 @@ True True - 0 + False @@ -793,7 +815,7 @@ True True - 0 + False @@ -815,7 +837,7 @@ True True - 0 + False @@ -837,7 +859,7 @@ True True - 0 + False @@ -859,7 +881,7 @@ True True - 0 + False @@ -881,7 +903,7 @@ True True - 0 + False @@ -976,7 +998,7 @@ True True - 0 + False @@ -1010,6 +1032,7 @@ False False + 0 @@ -1031,6 +1054,7 @@ False + 0 @@ -1044,7 +1068,7 @@ True - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER + select-folder False @@ -1080,22 +1104,29 @@ True - GTK_BUTTONBOX_END + end + gtk-close + -5 True True True - gtk-close + False True - -5 + + False + False + 0 + False - GTK_PACK_END + end + 0 @@ -1105,7 +1136,7 @@ True Configure CPU True - GDK_WINDOW_TYPE_HINT_DIALOG + dialog True @@ -1128,11 +1159,11 @@ 2 + Enable Debugger True True - Enable Debugger + False True - 0 True @@ -1146,11 +1177,11 @@ + SPU IRQ Always Enabled True True - SPU IRQ Always Enabled + False True - 0 True @@ -1162,11 +1193,11 @@ + Black & White Movies True True - Black & White Movies + False True - 0 True @@ -1178,11 +1209,11 @@ + Enable Console Output True True - Enable Console Output + False True - 0 True @@ -1196,11 +1227,11 @@ + Enable Interpreter CPU True True - Enable Interpreter CPU + False True - 0 True @@ -1214,11 +1245,11 @@ + SIO IRQ Always Enabled True True - SIO IRQ Always Enabled + False True - 0 True @@ -1230,11 +1261,11 @@ + Disable CD Audio True True - Disable CD Audio + False True - 0 True @@ -1246,11 +1277,11 @@ + Disable XA Decoding True True - Disable XA Decoding + False True - 0 True @@ -1259,14 +1290,17 @@ + + 0 + + Parasite Eve 2, Vandal Hearts 1/2 Fix True True - Parasite Eve 2, Vandal Hearts 1/2 Fix + False True - 0 True @@ -1277,11 +1311,11 @@ + InuYasha Sengoku Battle Fix True True - InuYasha Sengoku Battle Fix + False True - 0 True @@ -1303,6 +1337,9 @@ + + 0 + @@ -1316,17 +1353,18 @@ 83 + Autodetect True True - Autodetect + False True - 0 True False False + 0 @@ -1366,21 +1404,28 @@ PAL True - GTK_BUTTONBOX_END + end + gtk-close + -7 True True True - gtk-close + False True - -7 + + False + False + 0 + False - GTK_PACK_END + end + 0 @@ -1390,7 +1435,7 @@ PAL True Configure NetPlay True - GDK_WINDOW_TYPE_HINT_DIALOG + dialog @@ -1416,6 +1461,9 @@ PAL True gtk-network + + 0 + @@ -1429,7 +1477,7 @@ PAL True True - 0 + False @@ -1448,7 +1496,7 @@ PAL True True - 0 + False @@ -1481,6 +1529,7 @@ PAL False False + 0 @@ -1491,22 +1540,29 @@ PAL True - GTK_BUTTONBOX_END + end + gtk-close + -7 True True True - gtk-close + False True - -7 + + False + False + 0 + False - GTK_PACK_END + end + 0 @@ -1518,7 +1574,7 @@ PAL True 688 400 - GDK_WINDOW_TYPE_HINT_DIALOG + dialog True @@ -1539,9 +1595,9 @@ PAL True False - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_IN + automatic + automatic + in True @@ -1549,6 +1605,9 @@ PAL + + 0 + @@ -1560,7 +1619,7 @@ PAL True True True - 0 + False @@ -1579,6 +1638,7 @@ PAL False False + 0 @@ -1598,13 +1658,18 @@ PAL + + False + False + 0 + True True True - 0 + False @@ -1623,6 +1688,7 @@ PAL False False + 0 @@ -1643,6 +1709,8 @@ PAL + False + False 1 @@ -1677,6 +1745,7 @@ PAL False False 4 + 0 @@ -1685,6 +1754,9 @@ PAL + + 0 + @@ -1695,13 +1767,13 @@ PAL True 6 - GTK_BUTTONBOX_SPREAD + spread True True True - 0 + False @@ -1720,6 +1792,7 @@ PAL False False + 0 @@ -1739,13 +1812,18 @@ PAL + + False + False + 0 + True True True - 0 + False @@ -1764,6 +1842,7 @@ PAL False False + 0 @@ -1784,6 +1863,8 @@ PAL + False + False 1 @@ -1792,7 +1873,7 @@ PAL True True True - 0 + False @@ -1811,6 +1892,7 @@ PAL False False + 0 @@ -1831,6 +1913,8 @@ PAL + False + False 2 @@ -1839,7 +1923,7 @@ PAL True True True - 0 + False @@ -1858,6 +1942,7 @@ PAL False False + 0 @@ -1878,6 +1963,8 @@ PAL + False + False 3 @@ -1903,9 +1990,9 @@ PAL True False - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_IN + automatic + automatic + in True @@ -1913,6 +2000,9 @@ PAL + + 0 + @@ -1924,7 +2014,7 @@ PAL True True True - 0 + False @@ -1943,6 +2033,7 @@ PAL False False + 0 @@ -1962,13 +2053,18 @@ PAL + + False + False + 0 + True True True - 0 + False @@ -1987,6 +2083,7 @@ PAL False False + 0 @@ -2007,6 +2104,8 @@ PAL + False + False 1 @@ -2041,6 +2140,7 @@ PAL False False 4 + 0 @@ -2061,21 +2161,28 @@ PAL True - GTK_BUTTONBOX_END + end + gtk-close + -7 True True True - gtk-close + False True - -7 + + False + False + 0 + False - GTK_PACK_END + end + 0 @@ -2084,9 +2191,9 @@ PAL True True - GTK_WIN_POS_CENTER + center True - GDK_WINDOW_TYPE_HINT_NORMAL + normal PCSX-Reloaded (C) 1999-2003 PCSX Team (C) 2005-2006 Ryan Schultz @@ -2132,11 +2239,11 @@ Romain Lafourcade - - + False - GTK_PACK_END + end + 0 @@ -2147,8 +2254,8 @@ Romain Lafourcade 5 Edit Cheat Codes True - GTK_WIN_POS_CENTER - GDK_WINDOW_TYPE_HINT_DIALOG + center + dialog True @@ -2165,10 +2272,10 @@ Romain Lafourcade True True 5 - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC + automatic + automatic True - GTK_SHADOW_ETCHED_IN + etched-in 300 @@ -2190,6 +2297,9 @@ Romain Lafourcade + + 0 + @@ -2197,22 +2307,23 @@ Romain Lafourcade 10 + gtk-add True True True - gtk-add True - 0 + + 0 + + gtk-edit True True True - gtk-edit True - 0 1 @@ -2220,12 +2331,11 @@ Romain Lafourcade + gtk-delete True True True - gtk-delete True - 0 2 @@ -2236,7 +2346,6 @@ Romain Lafourcade True True True - 0 True @@ -2244,8 +2353,11 @@ Romain Lafourcade True gtk-apply - 1 + 1 + + 0 + @@ -2268,7 +2380,6 @@ Romain Lafourcade True True True - 0 True @@ -2276,8 +2387,11 @@ Romain Lafourcade True gtk-cancel - 1 + 1 + + 0 + @@ -2297,12 +2411,11 @@ Romain Lafourcade + gtk-open True True True - gtk-open True - 0 5 @@ -2310,12 +2423,11 @@ Romain Lafourcade + gtk-save-as True True True - gtk-save-as True - 0 6 @@ -2336,21 +2448,26 @@ Romain Lafourcade True - GTK_BUTTONBOX_END + end + gtk-close True True True - gtk-close True - 0 + + False + False + 0 + False - GTK_PACK_END + end + 0 @@ -2361,8 +2478,8 @@ Romain Lafourcade 5 Cheat Search True - GTK_WIN_POS_CENTER - GDK_WINDOW_TYPE_HINT_DIALOG + center + dialog True @@ -2388,18 +2505,12 @@ Romain Lafourcade 4 10 10 - - - True - Unsigned 8-bit -Unsigned 16-bit -Unsigned 32-bit -Signed 8-bit -Signed 16-bit -Signed 32-bit + 8-bit +16-bit +32-bit 1 @@ -2462,7 +2573,13 @@ Signed 32-bit True Equal Value Not Equal Value -Range +Range +Increased By +Decreased By +Increased +Decreased +Different +No Change 1 @@ -2498,21 +2615,7 @@ Hexadecimal - - True - True - Big-Endian - 0 - True - - - 3 - 4 - - - - - + True To: @@ -2535,10 +2638,17 @@ Hexadecimal 3 + + + + + + False False + 0 @@ -2548,45 +2658,50 @@ Hexadecimal True True - GTK_POLICY_NEVER - GTK_SHADOW_ETCHED_IN + never + etched-in - + 450 250 True True False - GTK_TREE_VIEW_GRID_LINES_VERTICAL + vertical + + 0 + True 20 - GTK_BUTTONBOX_START + start - + True True True - 0 True True - gtk-missing-image - 1 + gtk-ok + 1 + + 0 + True - label + Freeze 1 @@ -2595,27 +2710,34 @@ Hexadecimal + + False + False + 0 + - + True True True - 0 True True - gtk-missing-image - 1 + gtk-edit + 1 + + 0 + True - label + Modify 1 @@ -2625,29 +2747,33 @@ Hexadecimal + False + False 1 - + True True True - 0 True True - gtk-missing-image - 1 + gtk-paste + 1 + + 0 + True - label + Copy 1 @@ -2657,11 +2783,15 @@ Hexadecimal + False + False 2 + False + False 10 1 @@ -2689,13 +2819,12 @@ Hexadecimal True 20 - GTK_BUTTONBOX_CENTER + center True True True - 0 True @@ -2703,8 +2832,11 @@ Hexadecimal True gtk-ok - 1 + 1 + + 0 + @@ -2718,13 +2850,17 @@ Hexadecimal + + False + False + 0 + True True True - 0 True @@ -2732,8 +2868,11 @@ Hexadecimal True gtk-undo - 1 + 1 + + 0 + @@ -2748,6 +2887,8 @@ Hexadecimal + False + False 1 @@ -2780,21 +2921,26 @@ Hexadecimal True - GTK_BUTTONBOX_END + end + gtk-close True True True - gtk-close True - 0 + + False + False + 0 + False - GTK_PACK_END + end + 0 diff --git a/gui/Cheat.c b/gui/Cheat.c index db3d4a26..f324ee7d 100644 --- a/gui/Cheat.c +++ b/gui/Cheat.c @@ -1,6 +1,6 @@ /* Cheat Support for PCSX-Reloaded * - * Copyright (C) 2009, Wei Mingzhi . + * Copyright (C) 2009, Wei Mingzhi . * * 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 @@ -29,6 +29,7 @@ #include "Linux.h" #include "../libpcsxcore/cheat.h" +#include "../libpcsxcore/psxmem.h" GtkWidget *CheatListDlg = NULL; GtkWidget *CheatSearchDlg = NULL; @@ -427,7 +428,7 @@ static void OnCheatListDlg_SaveClicked(GtkWidget *widget, gpointer user_data) { g_free(filename); } -static void OnCheatListDlg_Clicked() { +static void OnCheatListDlg_CloseClicked() { gtk_widget_destroy(CheatListDlg); CheatListDlg = NULL; } @@ -501,7 +502,7 @@ void RunCheatListDialog() { // Setup a handler for when Close or Cancel is clicked g_signal_connect_data(GTK_OBJECT(CheatListDlg), "response", - GTK_SIGNAL_FUNC(OnCheatListDlg_Clicked), xml, (GClosureNotify)g_object_unref, G_CONNECT_AFTER); + GTK_SIGNAL_FUNC(OnCheatListDlg_CloseClicked), xml, (GClosureNotify)g_object_unref, G_CONNECT_AFTER); gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "savebutton1")), NumCheats); gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "editbutton1")), FALSE); @@ -513,18 +514,663 @@ void RunCheatListDialog() { /////////////////////////////////////////////////////////////////////////////// -struct cheatSearchResult { +#define SEARCH_EQUALVAL 0 +#define SEARCH_NOTEQUALVAL 1 +#define SEARCH_RANGE 2 +#define SEARCH_INCBY 3 +#define SEARCH_DECBY 4 +#define SEARCH_INC 5 +#define SEARCH_DEC 6 +#define SEARCH_DIFFERENT 7 +#define SEARCH_NOCHANGE 8 + +#define SEARCHTYPE_8BIT 0 +#define SEARCHTYPE_16BIT 1 +#define SEARCHTYPE_32BIT 2 + +#define SEARCHBASE_DEC 0 +#define SEARCHBASE_HEX 1 + +static char current_search = SEARCH_EQUALVAL; +static char current_searchtype = SEARCHTYPE_8BIT; +static char current_searchbase = SEARCHBASE_DEC; +static uint32_t current_valuefrom = 0; +static uint32_t current_valueto = 0; + +// update the cheat search dialog +static void UpdateCheatSearchDialog() { + GladeXML *xml; + char buf[256]; + int i; u32 addr; + GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING); + GtkTreeIter iter; + GtkWidget *widget; + + xml = glade_get_widget_tree(CheatSearchDlg); + widget = glade_xml_get_widget(xml, "GtkCList_Result"); + + gtk_combo_box_set_active(GTK_COMBO_BOX(glade_xml_get_widget(xml, "combo_searchfor")), current_search); + gtk_combo_box_set_active(GTK_COMBO_BOX(glade_xml_get_widget(xml, "combo_datatype")), current_searchtype); + gtk_combo_box_set_active(GTK_COMBO_BOX(glade_xml_get_widget(xml, "combo_database")), current_searchbase); + + if (current_searchbase == SEARCHBASE_DEC) { + sprintf(buf, "%u", current_valuefrom); + gtk_entry_set_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_value")), buf); + sprintf(buf, "%u", current_valueto); + gtk_entry_set_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_valueto")), buf); + } + else { + sprintf(buf, "%X", current_valuefrom); + gtk_entry_set_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_value")), buf); + sprintf(buf, "%X", current_valueto); + gtk_entry_set_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_valueto")), buf); + } + + if (current_search == SEARCH_RANGE) { + gtk_widget_show(GTK_WIDGET(glade_xml_get_widget(xml, "label_valueto"))); + gtk_widget_show(GTK_WIDGET(glade_xml_get_widget(xml, "entry_valueto"))); + } + else { + gtk_widget_hide(GTK_WIDGET(glade_xml_get_widget(xml, "label_valueto"))); + gtk_widget_hide(GTK_WIDGET(glade_xml_get_widget(xml, "entry_valueto"))); + } + + if (current_search >= SEARCH_INC) { + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "entry_value")), FALSE); + } + else { + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "entry_value")), TRUE); + } + + if (current_search >= SEARCH_INCBY && prevM == NULL) { + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "btn_start")), FALSE); + } + else { + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "btn_start")), TRUE); + } + + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "btn_freeze")), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "btn_modify")), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "btn_copy")), FALSE); + + if (prevM != NULL) { + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "combo_datatype")), FALSE); + + if (NumSearchResults > 100) { + // too many results to be shown + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, 0, _("Too many addresses found."), -1); + gtk_widget_set_sensitive(widget, FALSE); + } + else { + for (i = 0; i < NumSearchResults; i++) { + addr = SearchResults[i]; + + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + sprintf(buf, _("%.8X Current: %u (%.2X), Previous: %u (%.2X)"), + addr, PSXMu8(addr), PSXMu8(addr), PrevMu8(addr), PrevMu8(addr)); + break; + + case SEARCHTYPE_16BIT: + sprintf(buf, _("%.8X Current: %u (%.4X), Previous: %u (%.4X)"), + addr, PSXMu16(addr), PSXMu16(addr), PrevMu16(addr), PrevMu16(addr)); + break; + + case SEARCHTYPE_32BIT: + sprintf(buf, _("%.8X Current: %u (%.8X), Previous: %u (%.8X)"), + addr, PSXMu32(addr), PSXMu32(addr), PrevMu32(addr), PrevMu32(addr)); + break; + + default: + assert(FALSE); // impossible + break; + } + + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, 0, buf, -1); + } + gtk_widget_set_sensitive(widget, TRUE); + } + + sprintf(buf, _("Founded Addresses: %d"), NumSearchResults); + gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(xml, "label_resultsfound")), buf); + } + else { + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "combo_datatype")), TRUE); + gtk_widget_set_sensitive(widget, FALSE); + + gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(xml, "label_resultsfound")), + _("Enter the values and start your search.")); + } + + gtk_tree_view_set_model(GTK_TREE_VIEW(widget), GTK_TREE_MODEL(store)); + g_object_unref(G_OBJECT(store)); + gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(widget), TRUE); + gtk_widget_show(widget); +} + +// get the current selected result index in the list +static int GetSelectedResultIndex() { + GladeXML *xml; + GtkTreeSelection *selection; + GtkTreeIter iter; + GtkTreeModel *model; + GtkTreePath *path; + gboolean selected; + int i; + + xml = glade_get_widget_tree(CheatSearchDlg); + + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(xml, "GtkCList_Result"))); + selected = gtk_tree_selection_get_selected(selection, &model, &iter); + + if (!selected) { + return -1; + } + + path = gtk_tree_model_get_path(model, &iter); + i = *gtk_tree_path_get_indices(path); + + assert(i < NumSearchResults); + return i; +} + +// add cheat code to freeze the value +static void OnCheatSearchDlg_FreezeClicked(GtkWidget *widget, gpointer user_data) { + GtkWidget *dlg; + GtkWidget *box, *hbox, *label, *descr_edit, *value_edit; + char buf[256]; + u32 addr, val = 0; + + addr = SearchResults[GetSelectedResultIndex()]; + + dlg = gtk_dialog_new_with_buttons(_("Freeze value"), GTK_WINDOW(CheatListDlg), + GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); + + box = GTK_WIDGET(GTK_DIALOG(dlg)->vbox); + + label = gtk_label_new(_("Description:")); + gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 5); + gtk_widget_show(label); + + descr_edit = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(box), descr_edit, FALSE, FALSE, 10); + gtk_widget_show(descr_edit); + + hbox = gtk_hbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 15); + + label = gtk_label_new(_("Value:")); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); + gtk_widget_show(label); + + value_edit = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(hbox), value_edit, FALSE, FALSE, 10); + gtk_widget_show(value_edit); + + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + val = PSXMu8(addr); + break; + + case SEARCHTYPE_16BIT: + val = PSXMu16(addr); + break; + + case SEARCHTYPE_32BIT: + val = PSXMu32(addr); + break; + + default: + assert(FALSE); // should not reach here + break; + } + + sprintf(buf, "%u", val); + gtk_entry_set_text(GTK_ENTRY(value_edit), buf); + + sprintf(buf, "%.8X", addr); + gtk_entry_set_text(GTK_ENTRY(descr_edit), buf); + + gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER); + gtk_widget_show_all(dlg); + + if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_ACCEPT) { + val = 0; + sscanf(gtk_entry_get_text(GTK_ENTRY(value_edit)), "%u", &val); + + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + if (val > (u32)0xFF) { + val = 0xFF; + } + sprintf(buf, "%.8X %.4X", (addr & 0x1FFFFF) | (CHEAT_CONST8 << 24), val); + break; + + case SEARCHTYPE_16BIT: + if (val > (u32)0xFFFF) { + val = 0xFFFF; + } + sprintf(buf, "%.8X %.4X", (addr & 0x1FFFFF) | (CHEAT_CONST16 << 24), val); + break; + + case SEARCHTYPE_32BIT: + sprintf(buf, "%.8X %.4X\n%.8X %.4X", + (addr & 0x1FFFFF) | (CHEAT_CONST16 << 24), val & 0xFFFF, + ((addr + 2) & 0x1FFFFF) | (CHEAT_CONST16 << 24), ((val & 0xFFFF0000) >> 16) & 0xFFFF); + break; + + default: + assert(FALSE); // should not reach here + break; + } + + if (AddCheat(gtk_entry_get_text(GTK_ENTRY(descr_edit)), buf) == 0) { + Cheats[NumCheats - 1].Enabled = 1; + } + } + + gtk_widget_destroy(dlg); +} + +// modify the value on the fly +static void OnCheatSearchDlg_ModifyClicked(GtkWidget *widget, gpointer user_data) { + GtkWidget *dlg; + GtkWidget *box, *hbox, *label, *value_edit; + char buf[256]; + u32 addr, val = 0; + + addr = SearchResults[GetSelectedResultIndex()]; + + dlg = gtk_dialog_new_with_buttons(_("Modify value"), GTK_WINDOW(CheatListDlg), + GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); + + box = GTK_WIDGET(GTK_DIALOG(dlg)->vbox); + hbox = gtk_hbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); + + label = gtk_label_new(_("New value:")); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); + gtk_widget_show(label); + + value_edit = gtk_entry_new(); + gtk_box_pack_start(GTK_BOX(hbox), value_edit, FALSE, FALSE, 10); + gtk_widget_show(value_edit); + + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + val = PSXMu8(addr); + break; + + case SEARCHTYPE_16BIT: + val = PSXMu16(addr); + break; + + case SEARCHTYPE_32BIT: + val = PSXMu32(addr); + break; + + default: + assert(FALSE); // should not reach here + break; + } + + sprintf(buf, "%u", val); + gtk_entry_set_text(GTK_ENTRY(value_edit), buf); + + gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER); + gtk_widget_show_all(dlg); + + if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_ACCEPT) { + val = 0; + sscanf(gtk_entry_get_text(GTK_ENTRY(value_edit)), "%u", &val); + + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + psxMemWrite8(addr, (u8)val); + break; + + case SEARCHTYPE_16BIT: + psxMemWrite16(addr, (u16)val); + break; + + case SEARCHTYPE_32BIT: + psxMemWrite32(addr, (u32)val); + break; + + default: + assert(FALSE); // should not reach here + break; + } + + UpdateCheatSearchDialog(); + } + + gtk_widget_destroy(dlg); +} + +// copy the selected address to clipboard +static void OnCheatSearchDlg_CopyClicked(GtkWidget *widget, gpointer user_data) { + int i; + char buf[9]; + + i = GetSelectedResultIndex(); + assert(i != -1); + + sprintf(buf, "%8X", SearchResults[i]); + buf[8] = '\0'; + + gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), buf, 8); +} + +// preform the search +static void OnCheatSearchDlg_SearchClicked(GtkWidget *widget, gpointer user_data) { + GladeXML *xml; + + xml = glade_get_widget_tree(CheatSearchDlg); + + current_search = gtk_combo_box_get_active(GTK_COMBO_BOX(glade_xml_get_widget(xml, "combo_searchfor"))); + current_searchtype = gtk_combo_box_get_active(GTK_COMBO_BOX(glade_xml_get_widget(xml, "combo_datatype"))); + current_searchbase = gtk_combo_box_get_active(GTK_COMBO_BOX(glade_xml_get_widget(xml, "combo_database"))); + current_valuefrom = 0; + current_valueto = 0; + + if (current_searchbase == SEARCHBASE_DEC) { + sscanf(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_value"))), "%u", ¤t_valuefrom); + sscanf(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_valueto"))), "%u", ¤t_valueto); + } + else { + sscanf(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_value"))), "%x", ¤t_valuefrom); + sscanf(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_valueto"))), "%x", ¤t_valueto); + } + + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + if (current_valuefrom > (u32)0xFF) { + current_valuefrom = 0xFF; + } + if (current_valueto > (u32)0xFF) { + current_valueto = 0xFF; + } + break; + + case SEARCHTYPE_16BIT: + if (current_valuefrom > (u32)0xFFFF) { + current_valuefrom = 0xFFFF; + } + if (current_valueto > (u32)0xFFFF) { + current_valueto = 0xFFFF; + } + break; + } + + if (current_search == SEARCH_RANGE && current_valuefrom > current_valueto) { + u32 t = current_valuefrom; + current_valuefrom = current_valueto; + current_valueto = t; + } + + switch (current_search) { + case SEARCH_EQUALVAL: + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + CheatSearchEqual8((u8)current_valuefrom); + break; + + case SEARCHTYPE_16BIT: + CheatSearchEqual16((u16)current_valuefrom); + break; + + case SEARCHTYPE_32BIT: + CheatSearchEqual32((u32)current_valuefrom); + break; + } + break; + + case SEARCH_NOTEQUALVAL: + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + CheatSearchNotEqual8((u8)current_valuefrom); + break; + + case SEARCHTYPE_16BIT: + CheatSearchNotEqual16((u16)current_valuefrom); + break; + + case SEARCHTYPE_32BIT: + CheatSearchNotEqual32((u32)current_valuefrom); + break; + } + break; + + case SEARCH_RANGE: + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + CheatSearchRange8((u8)current_valuefrom, (u8)current_valueto); + break; + + case SEARCHTYPE_16BIT: + CheatSearchRange16((u16)current_valuefrom, (u16)current_valueto); + break; + + case SEARCHTYPE_32BIT: + CheatSearchRange32((u32)current_valuefrom, (u32)current_valueto); + break; + } + break; + + case SEARCH_INCBY: + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + CheatSearchIncreasedBy8((u8)current_valuefrom); + break; + + case SEARCHTYPE_16BIT: + CheatSearchIncreasedBy16((u16)current_valuefrom); + break; + + case SEARCHTYPE_32BIT: + CheatSearchIncreasedBy32((u32)current_valuefrom); + break; + } + break; + + case SEARCH_DECBY: + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + CheatSearchDecreasedBy8((u8)current_valuefrom); + break; + + case SEARCHTYPE_16BIT: + CheatSearchDecreasedBy16((u16)current_valuefrom); + break; + + case SEARCHTYPE_32BIT: + CheatSearchDecreasedBy32((u32)current_valuefrom); + break; + } + break; + + case SEARCH_INC: + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + CheatSearchIncreased8(); + break; + + case SEARCHTYPE_16BIT: + CheatSearchIncreased16(); + break; + + case SEARCHTYPE_32BIT: + CheatSearchIncreased32(); + break; + } + break; + + case SEARCH_DEC: + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + CheatSearchDecreased8(); + break; + + case SEARCHTYPE_16BIT: + CheatSearchDecreased16(); + break; + + case SEARCHTYPE_32BIT: + CheatSearchDecreased32(); + break; + } + break; + + case SEARCH_DIFFERENT: + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + CheatSearchDifferent8(); + break; + + case SEARCHTYPE_16BIT: + CheatSearchDifferent16(); + break; + + case SEARCHTYPE_32BIT: + CheatSearchDifferent32(); + break; + } + break; + + case SEARCH_NOCHANGE: + switch (current_searchtype) { + case SEARCHTYPE_8BIT: + CheatSearchNoChange8(); + break; + + case SEARCHTYPE_16BIT: + CheatSearchNoChange16(); + break; + + case SEARCHTYPE_32BIT: + CheatSearchNoChange32(); + break; + } + break; + + default: + assert(FALSE); // not possible + break; + } + + UpdateCheatSearchDialog(); +} + +// restart the search +static void OnCheatSearchDlg_RestartClicked(GtkWidget *widget, gpointer user_data) { + FreeCheatSearchResults(); + FreeCheatSearchMem(); + + current_search = SEARCH_EQUALVAL; + current_searchtype = SEARCHTYPE_8BIT; + current_searchbase = SEARCHBASE_DEC; + current_valuefrom = 0; + current_valueto = 0; + + UpdateCheatSearchDialog(); +} + +// close the cheat search window +static void OnCheatSearchDlg_CloseClicked(GtkWidget *widget, gpointer user_data) { + gtk_widget_destroy(CheatSearchDlg); + CheatSearchDlg = NULL; +} + +static void OnCheatSearchDlg_SearchForChanged(GtkWidget *widget, gpointer user_data) { + GladeXML *xml; + + xml = glade_get_widget_tree(CheatSearchDlg); + + if (gtk_combo_box_get_active(GTK_COMBO_BOX(widget)) == SEARCH_RANGE) { + gtk_widget_show(GTK_WIDGET(glade_xml_get_widget(xml, "label_valueto"))); + gtk_widget_show(GTK_WIDGET(glade_xml_get_widget(xml, "entry_valueto"))); + } + else { + gtk_widget_hide(GTK_WIDGET(glade_xml_get_widget(xml, "label_valueto"))); + gtk_widget_hide(GTK_WIDGET(glade_xml_get_widget(xml, "entry_valueto"))); + } + + if (gtk_combo_box_get_active(GTK_COMBO_BOX(widget)) >= SEARCH_INC) { + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "entry_value")), FALSE); + } + else { + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "entry_value")), TRUE); + } + + if (gtk_combo_box_get_active(GTK_COMBO_BOX(widget)) >= SEARCH_INCBY && prevM == NULL) { + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "btn_start")), FALSE); + } + else { + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "btn_start")), TRUE); + } +} + +static void OnCheatSearchDlg_DataBaseChanged(GtkWidget *widget, gpointer user_data) { u32 val; -}; + char buf[256]; + GladeXML *xml; -struct cheatSearchResult *SearchResult = NULL; -int NumSearchResult = 0; + xml = glade_get_widget_tree(CheatSearchDlg); + + if (gtk_combo_box_get_active(GTK_COMBO_BOX(widget)) == SEARCHBASE_DEC) { + val = 0; + sscanf(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_value"))), "%x", &val); + sprintf(buf, "%u", val); + gtk_entry_set_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_value")), buf); + + val = 0; + sscanf(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_valueto"))), "%x", &val); + sprintf(buf, "%u", val); + gtk_entry_set_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_valueto")), buf); + } + else { + val = 0; + sscanf(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_value"))), "%u", &val); + sprintf(buf, "%X", val); + gtk_entry_set_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_value")), buf); + + val = 0; + sscanf(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_valueto"))), "%u", &val); + sprintf(buf, "%X", val); + gtk_entry_set_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry_valueto")), buf); + } +} + +static void CheatSearch_TreeSelectionChanged(GtkTreeSelection *selection, gpointer user_data) { + GladeXML *xml; + + xml = glade_get_widget_tree(CheatSearchDlg); + + if (GetSelectedResultIndex() != -1) { + // If a row was selected, we can now enable some of the disabled widgets + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "btn_freeze")), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "btn_modify")), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "btn_copy")), TRUE); + } else { + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "btn_freeze")), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "btn_modify")), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(glade_xml_get_widget(xml, "btn_copy")), FALSE); + } +} // run the cheat search dialog void RunCheatSearchDialog() { GladeXML *xml; GtkWidget *widget; + GtkCellRenderer *renderer; + GtkTreeSelection *treesel; + GtkTreeViewColumn *column; xml = glade_xml_new(PACKAGE_DATA_DIR "pcsx.glade2", "CheatSearchDlg", NULL); if (!xml) { @@ -534,4 +1180,50 @@ void RunCheatSearchDialog() { CheatSearchDlg = glade_xml_get_widget(xml, "CheatSearchDlg"); gtk_window_set_title(GTK_WINDOW(CheatSearchDlg), _("Cheat Search")); + + widget = glade_xml_get_widget(xml, "GtkCList_Result"); + + renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes(_("Search Results"), + renderer, "text", 0, NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW(widget), column); + + treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); + gtk_tree_selection_set_mode (treesel, GTK_SELECTION_SINGLE); + g_signal_connect_data(G_OBJECT(treesel), "changed", + G_CALLBACK(CheatSearch_TreeSelectionChanged), + NULL, NULL, G_CONNECT_AFTER); + + UpdateCheatSearchDialog(); + + widget = glade_xml_get_widget(xml, "btn_freeze"); + g_signal_connect_data(GTK_OBJECT(widget), "clicked", + GTK_SIGNAL_FUNC(OnCheatSearchDlg_FreezeClicked), xml, NULL, G_CONNECT_AFTER); + + widget = glade_xml_get_widget(xml, "btn_modify"); + g_signal_connect_data(GTK_OBJECT(widget), "clicked", + GTK_SIGNAL_FUNC(OnCheatSearchDlg_ModifyClicked), xml, NULL, G_CONNECT_AFTER); + + widget = glade_xml_get_widget(xml, "btn_copy"); + g_signal_connect_data(GTK_OBJECT(widget), "clicked", + GTK_SIGNAL_FUNC(OnCheatSearchDlg_CopyClicked), xml, NULL, G_CONNECT_AFTER); + + widget = glade_xml_get_widget(xml, "btn_start"); + g_signal_connect_data(GTK_OBJECT(widget), "clicked", + GTK_SIGNAL_FUNC(OnCheatSearchDlg_SearchClicked), xml, NULL, G_CONNECT_AFTER); + + widget = glade_xml_get_widget(xml, "btn_restart"); + g_signal_connect_data(GTK_OBJECT(widget), "clicked", + GTK_SIGNAL_FUNC(OnCheatSearchDlg_RestartClicked), xml, NULL, G_CONNECT_AFTER); + + widget = glade_xml_get_widget(xml, "combo_searchfor"); + g_signal_connect_data(GTK_OBJECT(widget), "changed", + GTK_SIGNAL_FUNC(OnCheatSearchDlg_SearchForChanged), xml, NULL, G_CONNECT_AFTER); + + widget = glade_xml_get_widget(xml, "combo_database"); + g_signal_connect_data(GTK_OBJECT(widget), "changed", + GTK_SIGNAL_FUNC(OnCheatSearchDlg_DataBaseChanged), xml, NULL, G_CONNECT_AFTER); + + g_signal_connect_data(GTK_OBJECT(CheatSearchDlg), "response", + GTK_SIGNAL_FUNC(OnCheatSearchDlg_CloseClicked), xml, (GClosureNotify)g_object_unref, G_CONNECT_AFTER); } diff --git a/gui/Gtk2Gui.c b/gui/Gtk2Gui.c index f39c49c1..08336e37 100644 --- a/gui/Gtk2Gui.c +++ b/gui/Gtk2Gui.c @@ -706,6 +706,7 @@ void OnEmu_Run() { } if (Config.Dbg) hdb_start(); + CheatSearchBackupMemory(); psxCpu->Execute(); } @@ -758,6 +759,7 @@ void OnEmu_SwitchImage() { cdOpenCase = time(NULL) + 2; if (Config.Dbg) hdb_start(); + CheatSearchBackupMemory(); psxCpu->Execute(); } diff --git a/libpcsxcore/cdriso.c b/libpcsxcore/cdriso.c index 8de93763..07751ce5 100644 --- a/libpcsxcore/cdriso.c +++ b/libpcsxcore/cdriso.c @@ -33,7 +33,6 @@ FILE *cdHandle = NULL; static unsigned char cdbuffer[CD_FRAMESIZE_RAW * 10]; char* CALLBACK CDR__getDriveLetter(void); -unsigned char* CALLBACK CDR__getBufferSub(void); long CALLBACK CDR__configure(void); long CALLBACK CDR__test(void); void CALLBACK CDR__about(void); @@ -279,6 +278,11 @@ static long CALLBACK ISOstop(void) { return 0; // TODO } +// gets subchannel data +unsigned char* CALLBACK ISOgetBufferSub(void) { + return NULL; // TODO +} + void imageReaderInit(void) { assert(hCDRDriver == NULL); @@ -292,10 +296,10 @@ void imageReaderInit(void) { CDR_getBuffer = ISOgetBuffer; CDR_play = ISOplay; CDR_stop = ISOstop; + CDR_getBufferSub = ISOgetBufferSub; CDR_getStatus = CDR__getStatus; CDR_getDriveLetter = CDR__getDriveLetter; - CDR_getBufferSub = CDR__getBufferSub; CDR_configure = CDR__configure; CDR_test = CDR__test; CDR_about = CDR__about; diff --git a/libpcsxcore/cheat.c b/libpcsxcore/cheat.c index 284d833b..763c8d01 100644 --- a/libpcsxcore/cheat.c +++ b/libpcsxcore/cheat.c @@ -1,6 +1,6 @@ /* Cheat Support for PCSX-Reloaded * - * Copyright (c) 2009, Wei Mingzhi . + * Copyright (c) 2009, Wei Mingzhi . * * 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 @@ -31,26 +31,12 @@ CheatCode *CheatCodes = NULL; int NumCodes = 0; static int NumCodesAllocated = 0; -#define ALLOC_INCREMENT 100 +s8 *prevM = NULL; +u32 *SearchResults = NULL; +int NumSearchResults = 0; +static int NumSearchResultsAllocated = 0; -// cheat types -#define CHEAT_CONST8 0x30 /* 8-bit Constant Write */ -#define CHEAT_CONST16 0x80 /* 16-bit Constant Write */ -#define CHEAT_INC16 0x10 /* 16-bit Increment */ -#define CHEAT_DEC16 0x11 /* 16-bit Decrement */ -#define CHEAT_INC8 0x20 /* 8-bit Increment */ -#define CHEAT_DEC8 0x21 /* 8-bit Decrement */ -#define CHEAT_SLIDE 0x50 /* Slide Codes */ -#define CHEAT_MEMCPY 0xC2 /* Memory Copy */ - -#define CHEAT_EQU8 0xE0 /* 8-bit Equal To */ -#define CHEAT_NOTEQU8 0xE1 /* 8-bit Not Equal To */ -#define CHEAT_LESSTHAN8 0xE2 /* 8-bit Less Than */ -#define CHEAT_GREATERTHAN8 0xE3 /* 8-bit Greater Than */ -#define CHEAT_EQU16 0xD0 /* 16-bit Equal To */ -#define CHEAT_NOTEQU16 0xD1 /* 16-bit Not Equal To */ -#define CHEAT_LESSTHAN16 0xD2 /* 16-bit Less Than */ -#define CHEAT_GREATERTHAN16 0xD3 /* 16-bit Greater Than */ +#define ALLOC_INCREMENT 100 void ClearAllCheats() { int i; @@ -457,3 +443,579 @@ int EditCheat(int index, const char *descr, char *code) { return 0; } + +void FreeCheatSearchResults() { + if (SearchResults != NULL) { + free(SearchResults); + } + SearchResults = NULL; + + NumSearchResults = 0; + NumSearchResultsAllocated = 0; +} + +void FreeCheatSearchMem() { + if (prevM != NULL) { + free(prevM); + } + prevM = NULL; +} + +void CheatSearchBackupMemory() { + if (prevM != NULL) { + memcpy(prevM, psxM, 0x200000); + } +} + +static void CheatSearchInitBackupMemory() { + if (prevM == NULL) { + prevM = (s8 *)malloc(0x200000); + CheatSearchBackupMemory(); + } +} + +static void CheatSearchAddResult(u32 addr) { + if (NumSearchResults >= NumSearchResultsAllocated) { + NumSearchResultsAllocated += ALLOC_INCREMENT; + + if (SearchResults == NULL) { + SearchResults = (u32 *)malloc(sizeof(u32) * NumSearchResultsAllocated); + } + else { + SearchResults = (u32 *)realloc(SearchResults, sizeof(u32) * NumSearchResultsAllocated); + } + } + + SearchResults[NumSearchResults++] = addr; +} + +void CheatSearchEqual8(u8 val) { + u32 i, j; + + CheatSearchInitBackupMemory(); + + if (SearchResults == NULL) { + // search the whole memory + for (i = 0; i < 0x200000; i++) { + if (PSXMu8(i) == val) { + CheatSearchAddResult(i); + } + } + } + else { + // only search within the previous results + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PSXMu8(SearchResults[i]) == val) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; + } +} + +void CheatSearchEqual16(u16 val) { + u32 i, j; + + CheatSearchInitBackupMemory(); + + if (SearchResults == NULL) { + // search the whole memory + for (i = 0; i < 0x200000; i += 2) { + if (PSXMu16(i) == val) { + CheatSearchAddResult(i); + } + } + } + else { + // only search within the previous results + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PSXMu16(SearchResults[i]) == val) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; + } +} + +void CheatSearchEqual32(u32 val) { + u32 i, j; + + CheatSearchInitBackupMemory(); + + if (SearchResults == NULL) { + // search the whole memory + for (i = 0; i < 0x200000; i += 4) { + if (PSXMu32(i) == val) { + CheatSearchAddResult(i); + } + } + } + else { + // only search within the previous results + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PSXMu32(SearchResults[i]) == val) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; + } +} + +void CheatSearchNotEqual8(u8 val) { + u32 i, j; + + CheatSearchInitBackupMemory(); + + if (SearchResults == NULL) { + // search the whole memory + for (i = 0; i < 0x200000; i++) { + if (PSXMu8(i) != val) { + CheatSearchAddResult(i); + } + } + } + else { + // only search within the previous results + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PSXMu8(SearchResults[i]) != val) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; + } +} + +void CheatSearchNotEqual16(u16 val) { + u32 i, j; + + CheatSearchInitBackupMemory(); + + if (SearchResults == NULL) { + // search the whole memory + for (i = 0; i < 0x200000; i += 2) { + if (PSXMu16(i) != val) { + CheatSearchAddResult(i); + } + } + } + else { + // only search within the previous results + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PSXMu16(SearchResults[i]) != val) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; + } +} + +void CheatSearchNotEqual32(u32 val) { + u32 i, j; + + CheatSearchInitBackupMemory(); + + if (SearchResults == NULL) { + // search the whole memory + for (i = 0; i < 0x200000; i += 4) { + if (PSXMu32(i) != val) { + CheatSearchAddResult(i); + } + } + } + else { + // only search within the previous results + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PSXMu32(SearchResults[i]) != val) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; + } +} + +void CheatSearchRange8(u8 min, u8 max) { + u32 i, j; + + CheatSearchInitBackupMemory(); + + if (SearchResults == NULL) { + // search the whole memory + for (i = 0; i < 0x200000; i++) { + if (PSXMu8(i) >= min && PSXMu8(i) <= max) { + CheatSearchAddResult(i); + } + } + } + else { + // only search within the previous results + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PSXMu8(SearchResults[i]) >= min && PSXMu8(SearchResults[i]) <= max) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; + } +} + +void CheatSearchRange16(u16 min, u16 max) { + u32 i, j; + + CheatSearchInitBackupMemory(); + + if (SearchResults == NULL) { + // search the whole memory + for (i = 0; i < 0x200000; i += 2) { + if (PSXMu16(i) >= min && PSXMu16(i) <= max) { + CheatSearchAddResult(i); + } + } + } + else { + // only search within the previous results + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PSXMu16(SearchResults[i]) >= min && PSXMu16(SearchResults[i]) <= max) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; + } +} + +void CheatSearchRange32(u32 min, u32 max) { + u32 i, j; + + CheatSearchInitBackupMemory(); + + if (SearchResults == NULL) { + // search the whole memory + for (i = 0; i < 0x200000; i += 4) { + if (PSXMu32(i) >= min && PSXMu32(i) <= max) { + CheatSearchAddResult(i); + } + } + } + else { + // only search within the previous results + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PSXMu32(SearchResults[i]) >= min && PSXMu32(SearchResults[i]) <= max) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; + } +} + +void CheatSearchIncreasedBy8(u8 val) { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PSXMu8(SearchResults[i]) - PrevMu8(SearchResults[i]) == val) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchIncreasedBy16(u16 val) { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PSXMu16(SearchResults[i]) - PrevMu16(SearchResults[i]) == val) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchIncreasedBy32(u32 val) { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PSXMu32(SearchResults[i]) - PrevMu32(SearchResults[i]) == val) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchDecreasedBy8(u8 val) { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu8(SearchResults[i]) - PSXMu8(SearchResults[i]) == val) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchDecreasedBy16(u16 val) { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu16(SearchResults[i]) - PSXMu16(SearchResults[i]) == val) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchDecreasedBy32(u32 val) { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu32(SearchResults[i]) - PSXMu32(SearchResults[i]) == val) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchIncreased8() { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu8(SearchResults[i]) < PSXMu8(SearchResults[i])) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchIncreased16() { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu16(SearchResults[i]) < PSXMu16(SearchResults[i])) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchIncreased32() { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu32(SearchResults[i]) < PSXMu32(SearchResults[i])) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchDecreased8() { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu8(SearchResults[i]) > PSXMu8(SearchResults[i])) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchDecreased16() { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu16(SearchResults[i]) > PSXMu16(SearchResults[i])) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchDecreased32() { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu32(SearchResults[i]) > PSXMu32(SearchResults[i])) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchDifferent8() { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu8(SearchResults[i]) != PSXMu8(SearchResults[i])) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchDifferent16() { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu16(SearchResults[i]) != PSXMu16(SearchResults[i])) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchDifferent32() { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu32(SearchResults[i]) != PSXMu32(SearchResults[i])) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchNoChange8() { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu8(SearchResults[i]) == PSXMu8(SearchResults[i])) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchNoChange16() { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu16(SearchResults[i]) == PSXMu16(SearchResults[i])) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} + +void CheatSearchNoChange32() { + u32 i, j; + + assert(prevM != NULL); // not possible for the first search + + j = 0; + + for (i = 0; i < NumSearchResults; i++) { + if (PrevMu32(SearchResults[i]) == PSXMu32(SearchResults[i])) { + SearchResults[j++] = SearchResults[i]; + } + } + + NumSearchResults = j; +} diff --git a/libpcsxcore/cheat.h b/libpcsxcore/cheat.h index 3e32c753..c5c74cd7 100644 --- a/libpcsxcore/cheat.h +++ b/libpcsxcore/cheat.h @@ -1,6 +1,6 @@ /* Cheat Support for PCSX-Reloaded * - * Copyright (C) 2009, Wei Mingzhi . + * Copyright (C) 2009, Wei Mingzhi . * * 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 @@ -43,9 +43,69 @@ int AddCheat(const char *descr, char *code); void RemoveCheat(int index); int EditCheat(int index, const char *descr, char *code); +void FreeCheatSearchResults(); +void FreeCheatSearchMem(); +void CheatSearchBackupMemory(); + +void CheatSearchEqual8(u8 val); +void CheatSearchEqual16(u16 val); +void CheatSearchEqual32(u32 val); +void CheatSearchNotEqual8(u8 val); +void CheatSearchNotEqual16(u16 val); +void CheatSearchNotEqual32(u32 val); +void CheatSearchRange8(u8 min, u8 max); +void CheatSearchRange16(u16 min, u16 max); +void CheatSearchRange32(u32 min, u32 max); +void CheatSearchIncreasedBy8(u8 val); +void CheatSearchIncreasedBy16(u16 val); +void CheatSearchIncreasedBy32(u32 val); +void CheatSearchDecreasedBy8(u8 val); +void CheatSearchDecreasedBy16(u16 val); +void CheatSearchDecreasedBy32(u32 val); +void CheatSearchIncreased8(); +void CheatSearchIncreased16(); +void CheatSearchIncreased32(); +void CheatSearchDecreased8(); +void CheatSearchDecreased16(); +void CheatSearchDecreased32(); +void CheatSearchDifferent8(); +void CheatSearchDifferent16(); +void CheatSearchDifferent32(); +void CheatSearchNoChange8(); +void CheatSearchNoChange16(); +void CheatSearchNoChange32(); + extern Cheat *Cheats; extern CheatCode *CheatCodes; extern int NumCheats; extern int NumCodes; +extern s8 *prevM; +extern u32 *SearchResults; +extern int NumSearchResults; + +#define PREVM(mem) (&prevM[mem]) +#define PrevMu8(mem) (*(u8 *)PREVM(mem)) +#define PrevMu16(mem) (SWAP16(*(u16 *)PREVM(mem))) +#define PrevMu32(mem) (SWAP32(*(u32 *)PREVM(mem))) + +// cheat types +#define CHEAT_CONST8 0x30 /* 8-bit Constant Write */ +#define CHEAT_CONST16 0x80 /* 16-bit Constant Write */ +#define CHEAT_INC16 0x10 /* 16-bit Increment */ +#define CHEAT_DEC16 0x11 /* 16-bit Decrement */ +#define CHEAT_INC8 0x20 /* 8-bit Increment */ +#define CHEAT_DEC8 0x21 /* 8-bit Decrement */ +#define CHEAT_SLIDE 0x50 /* Slide Codes */ +#define CHEAT_MEMCPY 0xC2 /* Memory Copy */ + +#define CHEAT_EQU8 0xE0 /* 8-bit Equal To */ +#define CHEAT_NOTEQU8 0xE1 /* 8-bit Not Equal To */ +#define CHEAT_LESSTHAN8 0xE2 /* 8-bit Less Than */ +#define CHEAT_GREATERTHAN8 0xE3 /* 8-bit Greater Than */ +#define CHEAT_EQU16 0xD0 /* 16-bit Equal To */ +#define CHEAT_NOTEQU16 0xD1 /* 16-bit Not Equal To */ +#define CHEAT_LESSTHAN16 0xD2 /* 16-bit Less Than */ +#define CHEAT_GREATERTHAN16 0xD3 /* 16-bit Greater Than */ + #endif diff --git a/libpcsxcore/psxhw.c b/libpcsxcore/psxhw.c index 27e69ec8..2e48469c 100644 --- a/libpcsxcore/psxhw.c +++ b/libpcsxcore/psxhw.c @@ -54,7 +54,7 @@ u8 psxHwRead8(u32 add) { #endif return hard; } - + #ifdef PSXHW_LOG PSXHW_LOG("*Known 8bit read at address %lx value %x\n", add, hard); #endif @@ -111,7 +111,7 @@ u16 psxHwRead16(u32 add) { // 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 @@ -166,12 +166,12 @@ u16 psxHwRead16(u32 add) { 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) { + if (add >= 0x1f801c00 && add < 0x1f801e00) { hard = SPU_readRegister(add); } else { hard = psxHu16(add); diff --git a/libpcsxcore/psxmem.h b/libpcsxcore/psxmem.h index cc4616c6..ba880ed5 100644 --- a/libpcsxcore/psxmem.h +++ b/libpcsxcore/psxmem.h @@ -50,7 +50,7 @@ s8 *psxM; #define psxMs8(mem) psxM[(mem) & 0x1fffff] #define psxMs16(mem) (SWAP16(*(s16*)&psxM[(mem) & 0x1fffff])) #define psxMs32(mem) (SWAP32(*(s32*)&psxM[(mem) & 0x1fffff])) -#define psxMu8(mem) (*(u8*)&psxM[(mem) & 0x1fffff])) +#define psxMu8(mem) (*(u8*)&psxM[(mem) & 0x1fffff]) #define psxMu16(mem) (SWAP16(*(u16*)&psxM[(mem) & 0x1fffff])) #define psxMu32(mem) (SWAP32(*(u32*)&psxM[(mem) & 0x1fffff])) @@ -119,8 +119,7 @@ u8** psxMemRLUT; #define PSXMu32ref(mem) (*(u32*)PSXM(mem)) - -#if !defined(PSXREC) && (defined(__x86_64__) || defined(__i386__) || defined(__sh__) || defined(__ppc__)) && !defined(NOPSXREC) +#if !defined(PSXREC) && (defined(__x86_64__) || defined(__i386__) || defined(__ppc__)) && !defined(NOPSXREC) #define PSXREC #endif diff --git a/libpcsxcore/r3000a.c b/libpcsxcore/r3000a.c index b46ec124..6f45a1bb 100644 --- a/libpcsxcore/r3000a.c +++ b/libpcsxcore/r3000a.c @@ -51,6 +51,9 @@ int psxInit() { } void psxReset() { + FreeCheatSearchResults(); + FreeCheatSearchMem(); + psxCpu->Reset(); psxMemReset(); @@ -81,6 +84,8 @@ void psxShutdown() { psxCpu->Shutdown(); ClearAllCheats(); + FreeCheatSearchResults(); + FreeCheatSearchMem(); } void psxException(u32 code, u32 bd) { diff --git a/plugins/dfsound/alsa.c b/plugins/dfsound/alsa.c index 5daa2857..e9ea0a3b 100644 --- a/plugins/dfsound/alsa.c +++ b/plugins/dfsound/alsa.c @@ -145,8 +145,8 @@ unsigned long SoundGetBytesBuffered(void) if (handle == NULL) // failed to open? return SOUNDSIZE; l = snd_pcm_avail_update(handle); - if(l < 0) return 0; - if(l < buffer_size / 2) // can we write in at least the half of fragments? + if (l < 0) return 0; + if (l < buffer_size / 2) // can we write in at least the half of fragments? l = SOUNDSIZE; // -> no? wait else l = 0; // -> else go on diff --git a/plugins/dfsound/spu.c b/plugins/dfsound/spu.c index ce697382..e1b0e099 100644 --- a/plugins/dfsound/spu.c +++ b/plugins/dfsound/spu.c @@ -23,7 +23,7 @@ #include "cfg.h" #include "dsoundoss.h" #include "regs.h" - + #if defined(USEALSA) static char * libraryName = "ALSA Sound"; #elif defined (USEOSS) @@ -629,39 +629,37 @@ ENDX: ; } } else // stereo: - for(ns=0;ns32767) d=32767; - *pS++=d; + d = SSumL[ns] / voldiv; SSumL[ns] = 0; + if (d < -32767) d = -32767; if (d > 32767) d = 32767; + *pS++ = d; - SSumR[ns]+=MixREVERBRight(); + SSumR[ns] += MixREVERBRight(); - d=SSumR[ns]/voldiv;SSumR[ns]=0; - if(d<-32767) d=-32767;if(d>32767) d=32767; - *pS++=d; + d = SSumR[ns] / voldiv; SSumR[ns] = 0; + if(d < -32767) d = -32767; if(d > 32767) d = 32767; + *pS++ = d; } InitREVERB(); // feed the sound // wanna have around 1/60 sec (16.666 ms) updates - - if(iCycle++>8) //temp fix: lowered for low latency alsa configs + if (iCycle++ > 16) { - SoundFeedStreamData((unsigned char*)pSpuBuffer, - ((unsigned char *)pS)- - ((unsigned char *)pSpuBuffer)); - pS=(short *)pSpuBuffer; - iCycle=0; + SoundFeedStreamData((unsigned char *)pSpuBuffer, + ((unsigned char *)pS) - ((unsigned char *)pSpuBuffer)); + pS = (short *)pSpuBuffer; + iCycle = 0; } } // end of big main loop... - bThreadEnded=1; + bThreadEnded = 1; return 0; } diff --git a/win32/gui/WndMain.c b/win32/gui/WndMain.c index e5654a3b..1ba3e8ce 100644 --- a/win32/gui/WndMain.c +++ b/win32/gui/WndMain.c @@ -126,13 +126,19 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine Config.PsxAuto = 1; strcpy(Config.PluginsDir, "Plugins\\"); strcpy(Config.BiosDir, "Bios\\"); - SysMessage(_("Pcsx needs to be configured")); - ConfPlug=1; + + strcpy(Config.Mcd1, "memcards\\Mcd001.mcr"); + strcpy(Config.Mcd2, "memcards\\Mcd002.mcr"); + + 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 (LoadConfig() == -1) { + return 0; + } } + if (Config.Lang[0] == 0) { strcpy(Config.Lang, "English"); } -- cgit v1.2.3