1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
|
/* pokefinder.c: GTK+ interface to the poke finder
Copyright (c) 2003-2011 Philip Kendall
$Id: pokefinder.c 4723 2012-07-08 13:26:15Z fredm $
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.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Author contact information:
E-mail: philip-fuse@shadowmagic.org.uk
*/
#include <config.h>
#include <errno.h>
#include <stdio.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include "compat.h"
#include "debugger/debugger.h"
#include "gtkcompat.h"
#include "gtkinternals.h"
#include "menu.h"
#include "pokefinder/pokefinder.h"
#include "ui/ui.h"
static int create_dialog( void );
static void gtkui_pokefinder_incremented( GtkWidget *widget,
gpointer user_data GCC_UNUSED );
static void gtkui_pokefinder_decremented( GtkWidget *widget,
gpointer user_data GCC_UNUSED );
static void gtkui_pokefinder_search( GtkWidget *widget, gpointer user_data );
static void gtkui_pokefinder_reset( GtkWidget *widget, gpointer user_data );
static void gtkui_pokefinder_close( GtkWidget *widget, gpointer user_data );
static gboolean delete_dialog( GtkWidget *widget, GdkEvent *event,
gpointer user_data );
static void update_pokefinder( void );
static void possible_click( GtkTreeView *treeview, GtkTreePath *path,
GtkTreeViewColumn *col, gpointer user_data );
static int dialog_created = 0;
static GtkWidget
*dialog, /* The dialog box itself */
*count_label, /* The number of possible locations */
*location_list; /* The list view of possible locations */
static GtkTreeModel *location_model; /* The data of possible locations */
/* The possible locations */
#define MAX_POSSIBLE 20
int possible_page[ MAX_POSSIBLE ];
libspectrum_word possible_offset[ MAX_POSSIBLE ];
/* List columns */
enum
{
COL_PAGE = 0,
COL_OFFSET,
NUM_COLS
};
void
menu_machine_pokefinder( GtkAction *gtk_action GCC_UNUSED,
gpointer data GCC_UNUSED )
{
int error;
if( !dialog_created ) {
error = create_dialog(); if( error ) return;
}
gtk_widget_show_all( dialog );
update_pokefinder();
}
GtkWidget *
create_location_list( void )
{
GtkWidget *view;
GtkCellRenderer *renderer;
GtkListStore *store;
view = gtk_tree_view_new();
/* Add columns */
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW( view ),
-1,
"Page",
renderer,
"text", COL_PAGE,
NULL );
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW( view ),
-1,
"Offset",
renderer,
"text", COL_OFFSET,
NULL );
/* Create data model */
store = gtk_list_store_new( NUM_COLS, G_TYPE_STRING, G_TYPE_STRING );
location_model = GTK_TREE_MODEL( store );
gtk_tree_view_set_model( GTK_TREE_VIEW( view ), location_model );
g_object_unref( location_model );
/* Activate breakpoints */
g_signal_connect( G_OBJECT( view ), "row-activated",
G_CALLBACK( possible_click ), NULL );
return view;
}
static int
create_dialog( void )
{
GtkWidget *hbox, *vbox, *label, *entry, *content_area;
GtkAccelGroup *accel_group;
dialog = gtkstock_dialog_new( "Fuse - Poke Finder",
G_CALLBACK( delete_dialog ) );
hbox = gtk_box_new( GTK_ORIENTATION_HORIZONTAL, 0 );
content_area = gtk_dialog_get_content_area( GTK_DIALOG( dialog ) );
gtk_box_pack_start( GTK_BOX( content_area ), hbox, TRUE, TRUE, 0 );
label = gtk_label_new( "Search for:" );
gtk_box_pack_start( GTK_BOX( hbox ), label, TRUE, TRUE, 5 );
entry = gtk_entry_new();
g_signal_connect( G_OBJECT( entry ), "activate",
G_CALLBACK( gtkui_pokefinder_search ), NULL );
gtk_box_pack_start( GTK_BOX( hbox ), entry, TRUE, TRUE, 5 );
vbox = gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 );
gtk_box_pack_start( GTK_BOX( hbox ), vbox, TRUE, TRUE, 5 );
count_label = gtk_label_new( "" );
gtk_box_pack_start( GTK_BOX( vbox ), count_label, TRUE, TRUE, 5 );
location_list = create_location_list();
gtk_box_pack_start( GTK_BOX( vbox ), location_list, TRUE, TRUE, 5 );
{
static gtkstock_button btn[] = {
{ "Incremented", G_CALLBACK( gtkui_pokefinder_incremented ), NULL, NULL, 0, 0, 0, 0 },
{ "Decremented", G_CALLBACK( gtkui_pokefinder_decremented ), NULL, NULL, 0, 0, 0, 0 },
{ "!Search", G_CALLBACK( gtkui_pokefinder_search ), NULL, NULL, GDK_KEY_Return, 0, 0, 0 },
{ "Reset", G_CALLBACK( gtkui_pokefinder_reset ), NULL, NULL, 0, 0, 0, 0 }
};
btn[2].actiondata = G_OBJECT( entry );
accel_group = gtkstock_create_buttons( dialog, NULL, btn,
sizeof( btn ) / sizeof( btn[0] ) );
gtkstock_create_close( dialog, accel_group,
G_CALLBACK( gtkui_pokefinder_close ), TRUE );
}
/* Users shouldn't be able to resize this window */
gtk_window_set_resizable( GTK_WINDOW( dialog ), FALSE );
dialog_created = 1;
return 0;
}
static void
gtkui_pokefinder_incremented( GtkWidget *widget GCC_UNUSED,
gpointer user_data GCC_UNUSED )
{
pokefinder_incremented();
update_pokefinder();
}
static void
gtkui_pokefinder_decremented( GtkWidget *widget GCC_UNUSED,
gpointer user_data GCC_UNUSED )
{
pokefinder_decremented();
update_pokefinder();
}
static void
gtkui_pokefinder_search( GtkWidget *widget, gpointer user_data GCC_UNUSED )
{
long value;
errno = 0;
value = strtol( gtk_entry_get_text( GTK_ENTRY( widget ) ), NULL, 10 );
if( errno != 0 || value < 0 || value > 255 ) {
ui_error( UI_ERROR_ERROR, "Invalid value: use an integer from 0 to 255" );
return;
}
pokefinder_search( value );
update_pokefinder();
}
static void
gtkui_pokefinder_reset( GtkWidget *widget GCC_UNUSED,
gpointer user_data GCC_UNUSED)
{
pokefinder_clear();
update_pokefinder();
}
static gboolean
delete_dialog( GtkWidget *widget, GdkEvent *event GCC_UNUSED,
gpointer user_data )
{
gtkui_pokefinder_close( widget, user_data );
return TRUE;
}
static void
gtkui_pokefinder_close( GtkWidget *widget, gpointer user_data GCC_UNUSED )
{
gtk_widget_hide( widget );
}
static void
update_pokefinder( void )
{
size_t page, offset, bank, bank_offset;
gchar buffer[256], *possible_text[2] = { &buffer[0], &buffer[128] };
GtkTreeIter iter;
gtk_list_store_clear( GTK_LIST_STORE( location_model ) );
if( pokefinder_count && pokefinder_count <= MAX_POSSIBLE ) {
size_t which;
which = 0;
for( page = 0; page < MEMORY_PAGES_IN_16K * SPECTRUM_RAM_PAGES; page++ ) {
memory_page *mapping = &memory_map_ram[page];
bank = mapping->page_num;
for( offset = 0; offset < MEMORY_PAGE_SIZE; offset++ )
if( ! (pokefinder_impossible[page][offset/8] & 1 << (offset & 7)) ) {
bank_offset = mapping->offset + offset;
possible_page[ which ] = bank;
possible_offset[ which ] = bank_offset;
which++;
snprintf( possible_text[0], 128, "%lu", (unsigned long)bank );
snprintf( possible_text[1], 128, "0x%04X", (unsigned)bank_offset );
/* Append a new row and fill data */
gtk_list_store_append( GTK_LIST_STORE( location_model ), &iter );
gtk_list_store_set( GTK_LIST_STORE( location_model ), &iter,
COL_PAGE, possible_text[0],
COL_OFFSET, possible_text[1],
-1 );
}
}
gtk_widget_show( location_list );
} else {
gtk_widget_hide( location_list );
}
snprintf( buffer, 256, "Possible locations: %lu",
(unsigned long)pokefinder_count );
gtk_label_set_text( GTK_LABEL( count_label ), buffer );
}
static void
possible_click( GtkTreeView *treeview GCC_UNUSED, GtkTreePath *path,
GtkTreeViewColumn *col GCC_UNUSED,
gpointer user_data GCC_UNUSED )
{
int error, *indices, row;
/* Get selected row via double-clicks or keyboard */
indices = gtk_tree_path_get_indices( path );
if( !indices ) return;
row = indices[0];
error = debugger_breakpoint_add_address(
DEBUGGER_BREAKPOINT_TYPE_WRITE, memory_source_ram, possible_page[ row ],
possible_offset[ row ], 0, DEBUGGER_BREAKPOINT_LIFE_PERMANENT, NULL
);
if( error ) return;
ui_debugger_update();
}
void
gtkui_pokefinder_clear( void )
{
pokefinder_clear();
if( dialog_created ) update_pokefinder();
}
|