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
|
/* pokefinder.c: Win32 interface to the poke finder
Copyright (c) 2004 Marek Januszwski
$Id: pokefinder.c 3987 2009-03-06 18:45:00Z specu $
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 <tchar.h>
#include <windows.h>
#include "debugger/debugger.h"
#include "pokefinder.h"
#include "pokefinder/pokefinder.h"
#include "ui/ui.h"
#include "win32internals.h"
static void win32ui_pokefinder_incremented();
static void win32ui_pokefinder_decremented();
static void win32ui_pokefinder_search();
static void win32ui_pokefinder_reset();
static void win32ui_pokefinder_close();
static void update_pokefinder( void );
static void possible_click( LPNMITEMACTIVATE lpnmitem );
#define MAX_POSSIBLE 20
int possible_page[ MAX_POSSIBLE ];
libspectrum_word possible_offset[ MAX_POSSIBLE ];
static INT_PTR CALLBACK
win32ui_pokefinder_proc( HWND hWnd, UINT msg,
WPARAM wParam, LPARAM lParam )
{
switch( msg ) {
case WM_COMMAND:
switch( LOWORD( wParam ) ) {
case IDCLOSE:
win32ui_pokefinder_close();
return 0;
case IDC_PF_INC:
win32ui_pokefinder_incremented();
return 0;
case IDC_PF_DEC:
win32ui_pokefinder_decremented();
return 0;
case IDC_PF_SEARCH:
win32ui_pokefinder_search();
return 0;
case IDC_PF_RESET:
win32ui_pokefinder_reset();
return 0;
}
break;
case WM_CLOSE:
win32ui_pokefinder_close();
return 0;
case WM_NOTIFY:
switch ( ( ( LPNMHDR ) lParam )->code ) {
case NM_DBLCLK:
possible_click( ( LPNMITEMACTIVATE ) lParam );
return 0; /* "The return value for this notification is not used." */
}
break;
}
return FALSE;
}
static void
update_pokefinder( void )
{
size_t page, offset;
TCHAR buffer[256], *possible_text[2] = { &buffer[0], &buffer[128] };
/* clear the listview */
SendDlgItemMessage( fuse_hPFWnd, IDC_PF_LIST, LVM_DELETEALLITEMS, 0, 0 );
/* display suspected locations if < 20 */
int i = 0;
LV_ITEM lvi;
lvi.mask = LVIF_TEXT;
if( pokefinder_count && pokefinder_count <= MAX_POSSIBLE ) {
size_t which = 0;
for( page = 0; page < 2 * SPECTRUM_RAM_PAGES; page++ )
for( offset = 0; offset < 0x2000; offset++ )
if( ! (pokefinder_impossible[page][offset/8] & 1 << (offset & 7)) ) {
possible_page[ which ] = page / 2;
possible_offset[ which ] = offset + 8192 * (page & 1);
which++;
_sntprintf( possible_text[0], 128, "%d", (unsigned)page );
_sntprintf( possible_text[1], 128, "0x%04X", (unsigned)offset );
/* set new count of items */
SendDlgItemMessage( fuse_hPFWnd, IDC_PF_LIST, LVM_SETITEMCOUNT,
i, 0 );
/* add the item */
lvi.iItem = i;
lvi.iSubItem = 0;
lvi.pszText = possible_text[0];
SendDlgItemMessage( fuse_hPFWnd, IDC_PF_LIST, LVM_INSERTITEM, 0,
( LPARAM ) &lvi );
lvi.iSubItem = 1;
lvi.pszText = possible_text[1];
SendDlgItemMessage( fuse_hPFWnd, IDC_PF_LIST, LVM_SETITEM, 0,
( LPARAM ) &lvi );
i++;
}
/* show the listview */
ShowWindow( GetDlgItem( fuse_hPFWnd, IDC_PF_LIST ), SW_SHOW );
} else {
/* hide the listview */
ShowWindow( GetDlgItem( fuse_hPFWnd, IDC_PF_LIST ), SW_HIDE );
}
/* print possible locations */
_sntprintf( buffer, 256, "Possible locations: %d\n", pokefinder_count );
SendDlgItemMessage( fuse_hPFWnd, IDC_PF_LOCATIONS, WM_SETTEXT, 0, (LPARAM) buffer );
}
void
menu_machine_pokefinder( int action )
{
if (fuse_hPFWnd == NULL) {
/* FIXME: Implement accelerators for this dialog */
fuse_hPFWnd = CreateDialog( fuse_hInstance,
MAKEINTRESOURCE( IDD_POKEFINDER ),
fuse_hWnd,
( DLGPROC ) win32ui_pokefinder_proc );
if ( fuse_hPFWnd == NULL ) {
win32_verror( 1 ); /* FIXME: improve this function */
return;
}
/* set extended listview style to select full row, when an item is selected */
DWORD lv_ext_style;
lv_ext_style = SendDlgItemMessage( fuse_hPFWnd, IDC_PF_LIST,
LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0 );
lv_ext_style |= LVS_EX_FULLROWSELECT;
SendDlgItemMessage( fuse_hPFWnd, IDC_PF_LIST,
LVM_SETEXTENDEDLISTVIEWSTYLE, 0, lv_ext_style );
/* create columns */
LVCOLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT ;
lvc.fmt = LVCFMT_LEFT;
lvc.cx = 114;
lvc.pszText = TEXT( "Page" );
SendDlgItemMessage( fuse_hPFWnd, IDC_PF_LIST, LVM_INSERTCOLUMN, 0,
( LPARAM ) &lvc );
lvc.mask |= LVCF_SUBITEM;
lvc.cx = 114;
lvc.pszText = TEXT( "Offset" );
SendDlgItemMessage( fuse_hPFWnd, IDC_PF_LIST, LVM_INSERTCOLUMN, 1,
( LPARAM ) &lvc );
} else {
SetActiveWindow( fuse_hPFWnd );
}
update_pokefinder();
}
static void
win32ui_pokefinder_incremented()
{
pokefinder_incremented();
update_pokefinder();
}
static void
win32ui_pokefinder_decremented()
{
pokefinder_decremented();
update_pokefinder();
}
static void
win32ui_pokefinder_search()
{
long value;
TCHAR *buffer;
int buffer_size;
/* poll the size of the value in Search box first */
buffer_size = SendDlgItemMessage( fuse_hPFWnd, IDC_PF_EDIT, WM_GETTEXTLENGTH,
(WPARAM) 0, (LPARAM) 0 );
buffer = malloc( ( buffer_size + 1 ) * sizeof( TCHAR ) );
if( buffer == NULL ) {
ui_error( UI_ERROR_ERROR, "Out of memory in %s.", __func__ );
return;
}
/* get the value in Search box first */
if( SendDlgItemMessage( fuse_hPFWnd, IDC_PF_EDIT, WM_GETTEXT,
(WPARAM) ( buffer_size + 1 ),
(LPARAM) buffer ) != buffer_size ) {
ui_error( UI_ERROR_ERROR, "Couldn't get the content of the Search text box" );
return;
}
value = _ttol( buffer );
free( buffer );
if( 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
win32ui_pokefinder_reset()
{
pokefinder_clear();
update_pokefinder();
}
static void
win32ui_pokefinder_close()
{
DestroyWindow( fuse_hPFWnd );
fuse_hPFWnd = NULL;
}
static void
possible_click( LPNMITEMACTIVATE lpnmitem )
{
/* FIXME: implement equivalent of GTK's select-via-keyboard to enter here */
int error;
libspectrum_word row;
if( lpnmitem->iItem < 0 ) return;
row = lpnmitem->iItem;
error = debugger_breakpoint_add_address(
DEBUGGER_BREAKPOINT_TYPE_WRITE, possible_page[ row ] + 1,
possible_offset[ row ], 0, DEBUGGER_BREAKPOINT_LIFE_PERMANENT, NULL
);
if( error ) return;
ui_debugger_update();
}
void
win32ui_pokefinder_clear( void )
{
pokefinder_clear();
if( fuse_hPFWnd != NULL ) update_pokefinder();
}
|