src/osd/sdl/debugosx.c
| r6032 | r6033 | |
| 1 | | //============================================================ |
| 2 | | // |
| 3 | | // debugosx.c - MacOS X debug window handling |
| 4 | | // |
| 5 | | // Copyright (c) 1996-2008, Nicola Salmoria and the MAME Team. |
| 6 | | // Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | // |
| 8 | | //============================================================ |
| 9 | | |
| 10 | | // NOTES: |
| 11 | | // |
| 12 | | // debug_window_proc is called for events on the debugger windows: Must install carbon handler on it |
| 13 | | // debugwin_view_proc is called for events on the debugger controls: Must install carbon handler on it |
| 14 | | // |
| 15 | | |
| 16 | | |
| 17 | | #define OSX_DEBUGGER_FONT_NAME "Monaco" |
| 18 | | #define OSX_DEBUGGER_FONT_SIZE 10 |
| 19 | | |
| 20 | | #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 |
| 21 | | #define OSX_LEOPARD 1 |
| 22 | | #else |
| 23 | | #define OSX_LEOPARD 0 |
| 24 | | #endif |
| 25 | | |
| 26 | | // standard windows headers |
| 27 | | #include <Carbon/Carbon.h> |
| 28 | | |
| 29 | | // MAME headers |
| 30 | | #include <SDL/SDL.h> |
| 31 | | #include "driver.h" |
| 32 | | #include "debug/debugvw.h" |
| 33 | | #include "debug/debugcon.h" |
| 34 | | #include "debug/debugcpu.h" |
| 35 | | #include "debugger.h" |
| 36 | | #include "uiinput.h" |
| 37 | | |
| 38 | | // MAMEOS headers |
| 39 | | #include "debugwin.h" |
| 40 | | #include "window.h" |
| 41 | | #include "video.h" |
| 42 | | #include "config.h" |
| 43 | | |
| 44 | | #define OSX_POPUP_COMMAND 'popu' |
| 45 | | #define OSX_BASE_ID 'cmd0' |
| 46 | | |
| 47 | | enum |
| 48 | | { |
| 49 | | KEY_F1 = 0x7A, |
| 50 | | KEY_F2 = 0x78, |
| 51 | | KEY_F3 = 0x63, |
| 52 | | KEY_F4 = 0x76, |
| 53 | | KEY_F5 = 0x60, |
| 54 | | KEY_F6 = 0x61, |
| 55 | | KEY_F7 = 0x62, |
| 56 | | KEY_F8 = 0x64, |
| 57 | | KEY_F9 = 0x65, |
| 58 | | KEY_F10 = 0x6D, |
| 59 | | KEY_F11 = 0x67, |
| 60 | | KEY_F12 = 0x6F, |
| 61 | | KEY_F13 = 0x69, |
| 62 | | KEY_F14 = 0x6B, |
| 63 | | KEY_F15 = 0x71 |
| 64 | | }; |
| 65 | | |
| 66 | | |
| 67 | | //============================================================ |
| 68 | | // PARAMETERS |
| 69 | | //============================================================ |
| 70 | | |
| 71 | | #define MAX_VIEWS 4 |
| 72 | | #define EDGE_WIDTH 3 |
| 73 | | #define MAX_EDIT_STRING 256 |
| 74 | | #define HISTORY_LENGTH 20 |
| 75 | | #define MAX_OTHER_WND 4 |
| 76 | | |
| 77 | | // debugger window styles |
| 78 | | #define DEBUG_WINDOW_STYLE ( kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowStandardHandlerAttribute | kWindowCompositingAttribute | kWindowResizableAttribute | kWindowLiveResizeAttribute ) |
| 79 | | |
| 80 | | // debugger window events |
| 81 | | static EventTypeSpec debug_window_events[] = |
| 82 | | { |
| 83 | | { kEventClassWindow, kEventWindowActivated }, |
| 84 | | { kEventClassWindow, kEventWindowGetMinimumSize }, |
| 85 | | { kEventClassWindow, kEventWindowGetMaximumSize }, |
| 86 | | { kEventClassWindow, kEventWindowBoundsChanging }, |
| 87 | | { kEventClassWindow, kEventWindowClose }, |
| 88 | | { kEventClassWindow, kEventWindowDispose }, |
| 89 | | { kEventClassCommand, kEventCommandProcess } |
| 90 | | }; |
| 91 | | |
| 92 | | // debugger view events |
| 93 | | static EventTypeSpec debug_view_events[] = |
| 94 | | { |
| 95 | | { kEventClassControl, kEventControlDraw }, |
| 96 | | { kEventClassControl, kEventControlClick }, |
| 97 | | { kEventClassControl, kEventControlContextualMenuClick }, |
| 98 | | { kEventClassControl, kEventControlSetFocusPart }, |
| 99 | | { kEventClassKeyboard, kEventRawKeyDown }, |
| 100 | | { kEventClassKeyboard, kEventRawKeyRepeat }, |
| 101 | | { kEventClassMouse, kEventMouseWheelMoved } |
| 102 | | }; |
| 103 | | |
| 104 | | // debugger keyboard events |
| 105 | | static EventTypeSpec debug_keyboard_events[] = |
| 106 | | { |
| 107 | | { kEventClassKeyboard, kEventRawKeyDown }, |
| 108 | | { kEventClassKeyboard, kEventRawKeyRepeat } |
| 109 | | }; |
| 110 | | |
| 111 | | enum |
| 112 | | { |
| 113 | | ID_NEW_MEMORY_WND = OSX_BASE_ID, |
| 114 | | ID_NEW_DISASM_WND, |
| 115 | | ID_NEW_LOG_WND, |
| 116 | | ID_RUN, |
| 117 | | ID_RUN_AND_HIDE, |
| 118 | | ID_RUN_VBLANK, |
| 119 | | ID_RUN_IRQ, |
| 120 | | ID_NEXT_CPU, |
| 121 | | ID_STEP, |
| 122 | | ID_STEP_OVER, |
| 123 | | ID_STEP_OUT, |
| 124 | | ID_HARD_RESET, |
| 125 | | ID_SOFT_RESET, |
| 126 | | ID_EXIT, |
| 127 | | |
| 128 | | ID_1_BYTE_CHUNKS, |
| 129 | | ID_2_BYTE_CHUNKS, |
| 130 | | ID_4_BYTE_CHUNKS, |
| 131 | | ID_8_BYTE_CHUNKS, |
| 132 | | ID_LOGICAL_ADDRESSES, |
| 133 | | ID_PHYSICAL_ADDRESSES, |
| 134 | | ID_REVERSE_VIEW, |
| 135 | | ID_INCREASE_MEM_WIDTH, |
| 136 | | ID_DECREASE_MEM_WIDTH, |
| 137 | | |
| 138 | | ID_SHOW_RAW, |
| 139 | | ID_SHOW_ENCRYPTED, |
| 140 | | ID_SHOW_COMMENTS, |
| 141 | | ID_RUN_TO_CURSOR, |
| 142 | | ID_TOGGLE_BREAKPOINT |
| 143 | | }; |
| 144 | | |
| 145 | | |
| 146 | | |
| 147 | | //============================================================ |
| 148 | | // TYPES |
| 149 | | //============================================================ |
| 150 | | |
| 151 | | typedef struct _debugview_info debugview_info; |
| 152 | | typedef struct _debugwin_info debugwin_info; |
| 153 | | |
| 154 | | |
| 155 | | struct _debugview_info |
| 156 | | { |
| 157 | | debugwin_info * owner; |
| 158 | | debug_view * view; |
| 159 | | HIViewRef wnd; |
| 160 | | HIViewRef hscroll; |
| 161 | | HIViewRef vscroll; |
| 162 | | UINT8 is_textbuf; |
| 163 | | }; |
| 164 | | |
| 165 | | |
| 166 | | struct _debugwin_info |
| 167 | | { |
| 168 | | debugwin_info * next; |
| 169 | | WindowRef wnd; |
| 170 | | HIViewRef focuswnd; |
| 171 | | // WNDPROC handler; |
| 172 | | |
| 173 | | UINT32 minwidth, maxwidth; |
| 174 | | UINT32 minheight, maxheight; |
| 175 | | void (*recompute_children)(debugwin_info *); |
| 176 | | |
| 177 | | int (*handle_command)(debugwin_info *, EventRef); |
| 178 | | int (*handle_key)(debugwin_info *, EventRef); |
| 179 | | UINT16 ignore_char_lparam; |
| 180 | | |
| 181 | | debugview_info view[MAX_VIEWS]; |
| 182 | | |
| 183 | | HIViewRef editwnd; |
| 184 | | HIViewRef menuwnd; |
| 185 | | char edit_defstr[256]; |
| 186 | | void (*process_string)(debugwin_info *, const char *); |
| 187 | | // WNDPROC original_editproc; |
| 188 | | char history[HISTORY_LENGTH][MAX_EDIT_STRING]; |
| 189 | | int history_count; |
| 190 | | int last_history; |
| 191 | | |
| 192 | | HIViewRef otherwnd[MAX_OTHER_WND]; |
| 193 | | |
| 194 | | MenuRef contextualMenu; |
| 195 | | HIViewRef contentView; |
| 196 | | |
| 197 | | running_machine *machine; |
| 198 | | }; |
| 199 | | |
| 200 | | |
| 201 | | //============================================================ |
| 202 | | // GLOBAL VARIABLES |
| 203 | | //============================================================ |
| 204 | | |
| 205 | | |
| 206 | | |
| 207 | | //============================================================ |
| 208 | | // LOCAL VARIABLES |
| 209 | | //============================================================ |
| 210 | | |
| 211 | | static debugwin_info *window_list; |
| 212 | | static debugwin_info *main_console = NULL; |
| 213 | | |
| 214 | | static UINT8 debugger_active_countdown; |
| 215 | | static UINT8 waiting_for_debugger; |
| 216 | | |
| 217 | | static UINT32 debug_font_height; |
| 218 | | static UINT32 debug_font_width; |
| 219 | | static UINT32 debug_font_ascent; |
| 220 | | |
| 221 | | static UINT32 hscroll_height; |
| 222 | | static UINT32 vscroll_width; |
| 223 | | |
| 224 | | static int temporarily_fake_that_we_are_not_visible; |
| 225 | | |
| 226 | | static EventHandlerRef keyEventHandler = NULL; |
| 227 | | |
| 228 | | static int osx_inited_debugger = 0; |
| 229 | | |
| 230 | | //============================================================ |
| 231 | | // PROTOTYPES |
| 232 | | //============================================================ |
| 233 | | |
| 234 | | static int debugwin_init_windows(running_machine *machine); |
| 235 | | static debugwin_info *debug_window_create(running_machine *machine, const char * title, void *unused); |
| 236 | | static void debug_window_free(debugwin_info *info); |
| 237 | | static OSStatus debug_window_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData); |
| 238 | | |
| 239 | | static void debugwin_view_draw_contents(debugview_info *view, CGContextRef dc); |
| 240 | | static debugview_info *debug_view_find(debug_view *view); |
| 241 | | static OSStatus debugwin_view_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData); |
| 242 | | static void debugwin_view_update(debug_view *view, void *osdprivate); |
| 243 | | static int debugwin_view_create(debugwin_info *info, int which, int type); |
| 244 | | static void debugwin_view_process_scroll(HIViewRef inView, ControlPartCode partCode); |
| 245 | | |
| 246 | | static OSStatus debugwin_edit_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData); |
| 247 | | |
| 248 | | #if 0 |
| 249 | | static void generic_create_window(int type); |
| 250 | | #endif |
| 251 | | static void generic_recompute_children(debugwin_info *info); |
| 252 | | |
| 253 | | static void memory_create_window(running_machine *machine); |
| 254 | | static void memory_recompute_children(debugwin_info *info); |
| 255 | | static void memory_process_string(debugwin_info *info, const char *string); |
| 256 | | static void memory_update_checkmarks(debugwin_info *info); |
| 257 | | static int memory_handle_command(debugwin_info *info, EventRef inEvent); |
| 258 | | static int memory_handle_key(debugwin_info *info, EventRef inEvent); |
| 259 | | static void memory_update_caption(debugwin_info *info); |
| 260 | | |
| 261 | | static void disasm_create_window(running_machine *machine); |
| 262 | | static void disasm_recompute_children(debugwin_info *info); |
| 263 | | static void disasm_process_string(debugwin_info *info, const char *string); |
| 264 | | static void disasm_update_checkmarks(debugwin_info *info); |
| 265 | | static int disasm_handle_command(debugwin_info *info, EventRef inEvent); |
| 266 | | static int disasm_handle_key(debugwin_info *info, EventRef inEvent); |
| 267 | | static void disasm_update_caption(debugwin_info *info); |
| 268 | | |
| 269 | | static void console_create_window(running_machine *machine); |
| 270 | | static void console_recompute_children(debugwin_info *info); |
| 271 | | static void console_process_string(debugwin_info *info, const char *string); |
| 272 | | static void console_set_cpu(const device_config *device); |
| 273 | | |
| 274 | | static MenuRef create_standard_menubar(void); |
| 275 | | static int global_handle_command(debugwin_info *info, EventRef inEvent); |
| 276 | | static int global_handle_key(debugwin_info *info, EventRef inEvent); |
| 277 | | static void smart_set_view_bounds(HIViewRef wnd, HIRect *bounds); |
| 278 | | static void smart_show_window(WindowRef wnd, int show); |
| 279 | | static void smart_show_view(HIViewRef wnd, int show); |
| 280 | | static void smart_show_all(int show); |
| 281 | | |
| 282 | | //============================================================ |
| 283 | | // OSX stubs |
| 284 | | //============================================================ |
| 285 | | |
| 286 | | INLINE void osx_init_debugger(running_machine *machine) |
| 287 | | { |
| 288 | | if ( osx_inited_debugger == 0 ) |
| 289 | | { |
| 290 | | if ( debugwin_init_windows(machine) != 0 ) |
| 291 | | { |
| 292 | | mame_printf_error( "Could not init debugger\n" ); |
| 293 | | exit( -1 ); |
| 294 | | } |
| 295 | | osx_inited_debugger = 1; |
| 296 | | } |
| 297 | | } |
| 298 | | |
| 299 | | |
| 300 | | static void osx_SetFocus( HIViewRef inView ) |
| 301 | | { |
| 302 | | HIViewRef focus; |
| 303 | | WindowRef parent = HIViewGetWindow( inView ); |
| 304 | | |
| 305 | | if ( GetKeyboardFocus(parent, &focus) == noErr ) |
| 306 | | { |
| 307 | | if ( focus == inView ) |
| 308 | | return; |
| 309 | | } |
| 310 | | |
| 311 | | SetKeyboardFocus(parent, inView, kControlFocusNextPart); |
| 312 | | } |
| 313 | | |
| 314 | | static void osx_GlobalToViewPoint( HIViewRef inView, const HIPoint * inGlobalPoint, HIPoint * outViewPoint ) |
| 315 | | { |
| 316 | | Rect windBounds; |
| 317 | | |
| 318 | | GetWindowBounds( GetControlOwner( inView ), kWindowStructureRgn, &windBounds ); |
| 319 | | |
| 320 | | *outViewPoint = *inGlobalPoint; |
| 321 | | |
| 322 | | outViewPoint->x -= windBounds.left; |
| 323 | | outViewPoint->y -= windBounds.top; |
| 324 | | |
| 325 | | HIViewConvertPoint( outViewPoint, NULL, inView ); |
| 326 | | } |
| 327 | | |
| 328 | | static void osx_ViewToGlobalPoint( HIViewRef inView, const HIPoint * inViewPoint, HIPoint * outGlobalPoint ) |
| 329 | | { |
| 330 | | Rect windBounds; |
| 331 | | |
| 332 | | GetWindowBounds( GetControlOwner( inView ), kWindowStructureRgn, &windBounds ); |
| 333 | | |
| 334 | | *outGlobalPoint = *inViewPoint; |
| 335 | | |
| 336 | | HIViewConvertPoint( outGlobalPoint, inView, NULL ); |
| 337 | | |
| 338 | | outGlobalPoint->x += windBounds.left; |
| 339 | | outGlobalPoint->y += windBounds.top; |
| 340 | | } |
| 341 | | |
| 342 | | INLINE void osx_RectToHIRect( const Rect *inRect, HIRect *outRect ) |
| 343 | | { |
| 344 | | outRect->origin.x = inRect->left; |
| 345 | | outRect->origin.y = inRect->top; |
| 346 | | outRect->size.width = inRect->right - inRect->left; |
| 347 | | outRect->size.height = inRect->bottom - inRect->top; |
| 348 | | } |
| 349 | | |
| 350 | | //============================================================ |
| 351 | | // osd_wait_for_debugger |
| 352 | | //============================================================ |
| 353 | | |
| 354 | | void osd_wait_for_debugger(const device_config *device, int firststop) |
| 355 | | { |
| 356 | | EventRef message; |
| 357 | | EventTargetRef target = GetEventDispatcherTarget(); |
| 358 | | |
| 359 | | osx_init_debugger(device->machine); |
| 360 | | |
| 361 | | // create a console window |
| 362 | | if (!main_console) |
| 363 | | console_create_window(device->machine); |
| 364 | | |
| 365 | | // update the views in the console to reflect the current CPU |
| 366 | | if (main_console) |
| 367 | | console_set_cpu(device); |
| 368 | | |
| 369 | | // make sure the debug windows are visible |
| 370 | | waiting_for_debugger = TRUE; |
| 371 | | smart_show_all(TRUE); |
| 372 | | |
| 373 | | // get and process messages |
| 374 | | if (ReceiveNextEvent(0, NULL, kEventDurationForever, TRUE, &message) == noErr) |
| 375 | | { |
| 376 | | SendEventToEventTarget(message, target); |
| 377 | | ReleaseEvent(message); |
| 378 | | } |
| 379 | | |
| 380 | | // mark the debugger as active |
| 381 | | debugger_active_countdown = 2; |
| 382 | | waiting_for_debugger = FALSE; |
| 383 | | } |
| 384 | | |
| 385 | | |
| 386 | | |
| 387 | | //============================================================ |
| 388 | | // debugwin_init_windows |
| 389 | | //============================================================ |
| 390 | | |
| 391 | | static int debugwin_init_windows(running_machine *machine) |
| 392 | | { |
| 393 | | SInt32 val; |
| 394 | | |
| 395 | | // get the font metrics |
| 396 | | { |
| 397 | | ATSFontMetrics metrics; |
| 398 | | ATSFontRef fontid = ATSFontFindFromName( CFSTR(OSX_DEBUGGER_FONT_NAME), kATSOptionFlagsDefault ); |
| 399 | | |
| 400 | | if (!fontid) |
| 401 | | return 1; |
| 402 | | |
| 403 | | if ( ATSFontGetHorizontalMetrics( fontid, kATSOptionFlagsDefault, &metrics ) != noErr ) |
| 404 | | return 1; |
| 405 | | |
| 406 | | debug_font_width = metrics.maxAdvanceWidth * (float)OSX_DEBUGGER_FONT_SIZE; |
| 407 | | debug_font_height = ( metrics.ascent + -metrics.descent ) * (float)OSX_DEBUGGER_FONT_SIZE; |
| 408 | | debug_font_ascent = metrics.ascent * (float)OSX_DEBUGGER_FONT_SIZE; |
| 409 | | } |
| 410 | | |
| 411 | | // get other metrics |
| 412 | | hscroll_height = 15; |
| 413 | | vscroll_width = 15; |
| 414 | | |
| 415 | | if ( GetThemeMetric( kThemeMetricScrollBarWidth, &val ) == noErr ) |
| 416 | | { |
| 417 | | hscroll_height = val; |
| 418 | | vscroll_width = val; |
| 419 | | } |
| 420 | | |
| 421 | | return 0; |
| 422 | | } |
| 423 | | |
| 424 | | |
| 425 | | |
| 426 | | #if 0 |
| 427 | | //============================================================ |
| 428 | | // debugwin_destroy_windows |
| 429 | | //============================================================ |
| 430 | | |
| 431 | | void debugwin_destroy_windows(void) |
| 432 | | { |
| 433 | | // loop over windows and free them |
| 434 | | while (window_list) |
| 435 | | DisposeWindow(window_list->wnd); |
| 436 | | |
| 437 | | // free the combobox info |
| 438 | | while (memorycombo) |
| 439 | | { |
| 440 | | void *temp = memorycombo; |
| 441 | | memorycombo = memorycombo->next; |
| 442 | | free(temp); |
| 443 | | } |
| 444 | | |
| 445 | | main_console = NULL; |
| 446 | | } |
| 447 | | |
| 448 | | |
| 449 | | |
| 450 | | //============================================================ |
| 451 | | // debugwin_show |
| 452 | | //============================================================ |
| 453 | | |
| 454 | | void debugwin_show(int type) |
| 455 | | { |
| 456 | | debugwin_info *info; |
| 457 | | |
| 458 | | // loop over windows and show/hide them |
| 459 | | for (info = window_list; info; info = info->next) |
| 460 | | ShowWindow(info->wnd, type); |
| 461 | | } |
| 462 | | |
| 463 | | #endif |
| 464 | | |
| 465 | | //============================================================ |
| 466 | | // debugwin_update_during_game |
| 467 | | //============================================================ |
| 468 | | |
| 469 | | void debugwin_update_during_game(running_machine *machine) |
| 470 | | { |
| 471 | | osx_init_debugger(machine); |
| 472 | | |
| 473 | | if (!machine->debugcpu_data) return; |
| 474 | | |
| 475 | | // if we're running live, do some checks |
| 476 | | if ( ! debug_cpu_is_stopped(machine) ) |
| 477 | | { |
| 478 | | // see if the interrupt key is pressed and break if it is |
| 479 | | temporarily_fake_that_we_are_not_visible = TRUE; |
| 480 | | if (ui_input_pressed(machine, IPT_UI_DEBUG_BREAK)) |
| 481 | | { |
| 482 | | debugwin_info *info; |
| 483 | | HIViewRef focuswnd; |
| 484 | | |
| 485 | | if ( GetKeyboardFocus( GetFrontWindowOfClass( kDocumentWindowClass, TRUE ), &focuswnd ) != noErr ) |
| 486 | | { |
| 487 | | focuswnd = NULL; |
| 488 | | } |
| 489 | | |
| 490 | | debug_cpu_halt_on_next_instruction(debug_cpu_get_visible_cpu(machine), "User-initiated break\n"); |
| 491 | | |
| 492 | | // if we were focused on some window's edit box, reset it to default |
| 493 | | for (info = window_list; info; info = info->next) |
| 494 | | if (focuswnd == info->editwnd) |
| 495 | | { |
| 496 | | ControlEditTextSelectionRec sel; |
| 497 | | |
| 498 | | sel.selStart = 0; |
| 499 | | sel.selEnd = strlen(info->edit_defstr); |
| 500 | | |
| 501 | | SetControlData(focuswnd, kControlEntireControl, kControlEditTextTextTag, strlen(info->edit_defstr), info->edit_defstr); |
| 502 | | SetControlData(focuswnd, kControlEntireControl, kControlEditTextSelectionTag, sizeof( sel ), &sel ); |
| 503 | | } |
| 504 | | } |
| 505 | | temporarily_fake_that_we_are_not_visible = FALSE; |
| 506 | | } |
| 507 | | } |
| 508 | | |
| 509 | | |
| 510 | | //============================================================ |
| 511 | | // debug_window_create |
| 512 | | //============================================================ |
| 513 | | |
| 514 | | static debugwin_info *debug_window_create(running_machine *machine, const char *title, void *unused) |
| 515 | | { |
| 516 | | CGDirectDisplayID mainID = CGMainDisplayID(); |
| 517 | | |
| 518 | | debugwin_info *info = NULL; |
| 519 | | Rect work_bounds; |
| 520 | | |
| 521 | | (void)unused; |
| 522 | | |
| 523 | | // allocate memory |
| 524 | | info = malloc(sizeof(*info)); |
| 525 | | if (!info) |
| 526 | | return NULL; |
| 527 | | memset(info, 0, sizeof(*info)); |
| 528 | | |
| 529 | | info->wnd = NULL; |
| 530 | | info->machine = machine; |
| 531 | | |
| 532 | | // create the window |
| 533 | | work_bounds.top = work_bounds.left = 0; |
| 534 | | work_bounds.bottom = work_bounds.right = 100; |
| 535 | | |
| 536 | | if ( CreateNewWindow(kDocumentWindowClass, DEBUG_WINDOW_STYLE, &work_bounds, &info->wnd) != noErr ) |
| 537 | | goto cleanup; |
| 538 | | |
| 539 | | // install keyboard handler |
| 540 | | if ( keyEventHandler == NULL ) |
| 541 | | { |
| 542 | | if ( InstallEventHandler( GetApplicationEventTarget(), NewEventHandlerUPP(debug_window_proc), sizeof( debug_keyboard_events ) / sizeof( EventTypeSpec ), debug_keyboard_events, info, &keyEventHandler ) != noErr ) |
| 543 | | goto cleanup; |
| 544 | | } |
| 545 | | |
| 546 | | // setup event handler |
| 547 | | if ( InstallEventHandler( GetWindowEventTarget( info->wnd ), NewEventHandlerUPP(debug_window_proc), sizeof( debug_window_events ) / sizeof( EventTypeSpec ), debug_window_events, info, NULL ) != noErr ) |
| 548 | | goto cleanup; |
| 549 | | |
| 550 | | // find the content view, and install draw handler |
| 551 | | { |
| 552 | | EventTypeSpec spec = { kEventClassControl, kEventControlDraw }; |
| 553 | | |
| 554 | | if ( HIViewFindByID( HIViewGetRoot( info->wnd ), kHIViewWindowContentID, &info->contentView ) != noErr ) |
| 555 | | goto cleanup; |
| 556 | | |
| 557 | | if ( InstallEventHandler( GetControlEventTarget( info->contentView ), NewEventHandlerUPP(debug_window_proc), 1, &spec, info, NULL ) != noErr ) |
| 558 | | goto cleanup; |
| 559 | | } |
| 560 | | |
| 561 | | // fill in some defaults |
| 562 | | { |
| 563 | | #if OSX_LEOPARD |
| 564 | | HIRect mainBounds; |
| 565 | | HIWindowGetAvailablePositioningBounds( mainID, kHICoordSpaceScreenPixel, &mainBounds ); |
| 566 | | work_bounds.left = mainBounds.origin.x; |
| 567 | | work_bounds.top = mainBounds.origin.y; |
| 568 | | work_bounds.right = mainBounds.origin.x + mainBounds.size.width; |
| 569 | | work_bounds.bottom = mainBounds.origin.y + mainBounds.size.height; |
| 570 | | #else |
| 571 | | GDHandle mainDevice; |
| 572 | | DMGetGDeviceByDisplayID((DisplayIDType)mainID, &mainDevice, TRUE); |
| 573 | | GetAvailableWindowPositioningBounds(mainDevice, &work_bounds); |
| 574 | | #endif |
| 575 | | } |
| 576 | | info->minwidth = 200; |
| 577 | | info->minheight = 200; |
| 578 | | info->maxwidth = work_bounds.right - work_bounds.left; |
| 579 | | info->maxheight = work_bounds.bottom - work_bounds.top; |
| 580 | | |
| 581 | | // set the default handlers |
| 582 | | info->handle_command = global_handle_command; |
| 583 | | info->handle_key = global_handle_key; |
| 584 | | strcpy(info->edit_defstr, ""); |
| 585 | | |
| 586 | | // hook us in |
| 587 | | info->next = window_list; |
| 588 | | window_list = info; |
| 589 | | return info; |
| 590 | | |
| 591 | | cleanup: |
| 592 | | if (info->wnd) |
| 593 | | DisposeWindow(info->wnd); |
| 594 | | free(info); |
| 595 | | return NULL; |
| 596 | | } |
| 597 | | |
| 598 | | |
| 599 | | |
| 600 | | //============================================================ |
| 601 | | // debug_window_free |
| 602 | | //============================================================ |
| 603 | | |
| 604 | | static void debug_window_free(debugwin_info *info) |
| 605 | | { |
| 606 | | debugwin_info *prev, *curr; |
| 607 | | |
| 608 | | // first unlink us from the list |
| 609 | | for (curr = window_list, prev = NULL; curr; prev = curr, curr = curr->next) |
| 610 | | if (curr == info) |
| 611 | | { |
| 612 | | if (prev) |
| 613 | | prev->next = curr->next; |
| 614 | | else |
| 615 | | window_list = curr->next; |
| 616 | | break; |
| 617 | | } |
| 618 | | |
| 619 | | #if 0 |
| 620 | | { |
| 621 | | int viewnum; |
| 622 | | |
| 623 | | // free any views |
| 624 | | for (viewnum = 0; viewnum < MAX_VIEWS; viewnum++) |
| 625 | | if (info->view[viewnum].view) |
| 626 | | { |
| 627 | | debug_view_free(info->view[viewnum].view); |
| 628 | | info->view[viewnum].view = NULL; |
| 629 | | } |
| 630 | | } |
| 631 | | #endif |
| 632 | | |
| 633 | | // free our memory |
| 634 | | free(info); |
| 635 | | } |
| 636 | | |
| 637 | | |
| 638 | | |
| 639 | | //============================================================ |
| 640 | | // debug_window_draw_contents |
| 641 | | //============================================================ |
| 642 | | |
| 643 | | static void debug_window_draw_contents(debugwin_info *info, CGContextRef dc) |
| 644 | | { |
| 645 | | HIRect bounds; |
| 646 | | // int curview, curwnd; |
| 647 | | |
| 648 | | // find the content view |
| 649 | | HIViewRef content = info->contentView; |
| 650 | | |
| 651 | | CGContextSaveGState(dc); |
| 652 | | |
| 653 | | // fill the background with light gray |
| 654 | | HIViewGetBounds(content, &bounds); |
| 655 | | CGContextSetRGBFillColor(dc, 0.75, 0.75, 0.75, 1.0); |
| 656 | | CGContextFillRect(dc,bounds); |
| 657 | | |
| 658 | | #if 0 |
| 659 | | // draw edges around all views |
| 660 | | for (curview = 0; curview < MAX_VIEWS; curview++) |
| 661 | | if (info->view[curview].wnd) |
| 662 | | { |
| 663 | | HIViewGetFrame(info->view[curview].wnd, &bounds); |
| 664 | | bounds = CGRectInset(bounds, -EDGE_WIDTH, -EDGE_WIDTH); |
| 665 | | CGContextSetRGBStrokeColor(dc, 0.0, 0.0, 0.0, 1.0); |
| 666 | | CGContextStrokeRect(dc,bounds); |
| 667 | | } |
| 668 | | |
| 669 | | // draw edges around all children |
| 670 | | if (info->editwnd) |
| 671 | | { |
| 672 | | HIViewGetFrame(info->editwnd, &bounds); |
| 673 | | bounds = CGRectInset(bounds, -EDGE_WIDTH, -EDGE_WIDTH); |
| 674 | | CGContextSetRGBStrokeColor(dc, 0.0, 0.0, 0.0, 1.0); |
| 675 | | CGContextStrokeRect(dc,bounds); |
| 676 | | } |
| 677 | | |
| 678 | | for (curwnd = 0; curwnd < MAX_OTHER_WND; curwnd++) |
| 679 | | if (info->otherwnd[curwnd]) |
| 680 | | { |
| 681 | | HIViewGetFrame(info->otherwnd[curwnd], &bounds); |
| 682 | | bounds = CGRectInset(bounds, -EDGE_WIDTH, -EDGE_WIDTH); |
| 683 | | CGContextSetRGBStrokeColor(dc, 0.0, 0.0, 0.0, 1.0); |
| 684 | | CGContextStrokeRect(dc,bounds); |
| 685 | | } |
| 686 | | #endif |
| 687 | | CGContextRestoreGState(dc); |
| 688 | | } |
| 689 | | |
| 690 | | |
| 691 | | |
| 692 | | //============================================================ |
| 693 | | // debug_window_proc |
| 694 | | //============================================================ |
| 695 | | |
| 696 | | static OSStatus debug_window_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData) |
| 697 | | { |
| 698 | | debugwin_info *info = (debugwin_info *)inUserData; |
| 699 | | UInt32 eventClass = GetEventClass( inEvent ); |
| 700 | | UInt32 eventKind = GetEventKind( inEvent ); |
| 701 | | |
| 702 | | // handle a few messages |
| 703 | | if ( eventClass == kEventClassControl && eventKind == kEventControlDraw ) |
| 704 | | { |
| 705 | | CGContextRef dc; |
| 706 | | |
| 707 | | if ( GetEventParameter( inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(dc), NULL, &dc ) != noErr ) |
| 708 | | { |
| 709 | | mame_printf_error( "Compositing attribute not set!\n" ); |
| 710 | | exit( -1 ); |
| 711 | | } |
| 712 | | |
| 713 | | debug_window_draw_contents(info, dc); |
| 714 | | return noErr; |
| 715 | | // don't return noErr, so the rest of the views can be updated |
| 716 | | } |
| 717 | | else if ( eventClass == kEventClassWindow ) |
| 718 | | { |
| 719 | | switch( eventKind ) |
| 720 | | { |
| 721 | | case kEventWindowActivated: |
| 722 | | { |
| 723 | | if ( info->focuswnd != NULL ) |
| 724 | | { |
| 725 | | osx_SetFocus( info->focuswnd ); |
| 726 | | } |
| 727 | | return noErr; |
| 728 | | } |
| 729 | | break; |
| 730 | | |
| 731 | | case kEventWindowGetMinimumSize: |
| 732 | | case kEventWindowGetMaximumSize: |
| 733 | | { |
| 734 | | Point pt; |
| 735 | | |
| 736 | | if ( eventKind == kEventWindowGetMinimumSize ) |
| 737 | | { |
| 738 | | pt.h = info->minwidth; |
| 739 | | pt.v = info->minheight; |
| 740 | | } |
| 741 | | else |
| 742 | | { |
| 743 | | pt.h = info->maxwidth; |
| 744 | | pt.v = info->maxheight; |
| 745 | | } |
| 746 | | |
| 747 | | SetEventParameter( inEvent, kEventParamDimensions, typeQDPoint, sizeof( pt ), &pt ); |
| 748 | | return noErr; |
| 749 | | } |
| 750 | | break; |
| 751 | | |
| 752 | | case kEventWindowBoundsChanging: |
| 753 | | { |
| 754 | | Rect prev, cur; |
| 755 | | |
| 756 | | if ( GetEventParameter( inEvent, kEventParamPreviousBounds, typeQDRectangle, NULL, sizeof(prev), NULL, &prev ) == noErr ) |
| 757 | | { |
| 758 | | if ( GetEventParameter( inEvent, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof(cur), NULL, &cur ) == noErr ) |
| 759 | | { |
| 760 | | Point old, new; |
| 761 | | |
| 762 | | old.h = prev.right - prev.left; old.v = prev.bottom - prev.top; |
| 763 | | new.h = cur.right - cur.left; new.v = cur.bottom - cur.top; |
| 764 | | |
| 765 | | if ( old.h != new.h || old.v != new.v ) |
| 766 | | { |
| 767 | | if (info->recompute_children) |
| 768 | | { |
| 769 | | (*info->recompute_children)(info); |
| 770 | | } |
| 771 | | } |
| 772 | | } |
| 773 | | } |
| 774 | | |
| 775 | | return noErr; |
| 776 | | } |
| 777 | | break; |
| 778 | | |
| 779 | | // TODO: mousewheel support |
| 780 | | |
| 781 | | case kEventWindowClose: |
| 782 | | { |
| 783 | | if (main_console && main_console->wnd == info->wnd) |
| 784 | | { |
| 785 | | smart_show_all(FALSE); |
| 786 | | debug_cpu_go(info->machine, ~0); |
| 787 | | return noErr; |
| 788 | | } |
| 789 | | |
| 790 | | // return not handled, so the system calls DisposeWindow() on it's own |
| 791 | | return eventNotHandledErr; |
| 792 | | } |
| 793 | | break; |
| 794 | | |
| 795 | | case kEventWindowDispose: |
| 796 | | { |
| 797 | | debug_window_free(info); |
| 798 | | return noErr; |
| 799 | | } |
| 800 | | break; |
| 801 | | } |
| 802 | | } |
| 803 | | else if ( eventClass == kEventClassCommand && eventKind == kEventCommandProcess ) |
| 804 | | { |
| 805 | | if ( (*info->handle_command)(info, inEvent) ) |
| 806 | | return noErr; |
| 807 | | } |
| 808 | | else if ( eventClass == kEventClassKeyboard && ( eventKind == kEventRawKeyDown || eventKind == kEventRawKeyRepeat ) ) |
| 809 | | { |
| 810 | | WindowRef win = GetFrontWindowOfClass( kDocumentWindowClass, TRUE ); |
| 811 | | |
| 812 | | for (info = window_list; info; info = info->next) |
| 813 | | { |
| 814 | | if ( info->wnd == win ) |
| 815 | | { |
| 816 | | if ( IsWindowActive( win ) ) |
| 817 | | { |
| 818 | | HIViewRef focusChild; |
| 819 | | |
| 820 | | // Get the current control focus |
| 821 | | if ( GetKeyboardFocus( win, &focusChild ) != noErr ) |
| 822 | | { |
| 823 | | focusChild = NULL; |
| 824 | | } |
| 825 | | |
| 826 | | // window gets first dibs to the event |
| 827 | | if ( (*info->handle_key)(info, inEvent) ) |
| 828 | | return noErr; |
| 829 | | |
| 830 | | // then any of the childs |
| 831 | | if ( focusChild != NULL ) |
| 832 | | { |
| 833 | | int curview; |
| 834 | | |
| 835 | | for (curview = 0; curview < MAX_VIEWS; curview++) |
| 836 | | { |
| 837 | | if (info->view[curview].wnd == focusChild ) |
| 838 | | { |
| 839 | | return debugwin_view_proc( inHandler, inEvent, &info->view[curview] ); |
| 840 | | } |
| 841 | | } |
| 842 | | } |
| 843 | | } |
| 844 | | } |
| 845 | | } |
| 846 | | } |
| 847 | | |
| 848 | | return eventNotHandledErr; |
| 849 | | } |
| 850 | | |
| 851 | | |
| 852 | | |
| 853 | | //============================================================ |
| 854 | | // debugwin_view_create |
| 855 | | //============================================================ |
| 856 | | |
| 857 | | static int debugwin_view_create(debugwin_info *info, int which, int type) |
| 858 | | { |
| 859 | | Rect bounds; |
| 860 | | debugview_info *view = &info->view[which]; |
| 861 | | |
| 862 | | // set the owner |
| 863 | | view->owner = info; |
| 864 | | |
| 865 | | bounds.top = bounds.left = 0; |
| 866 | | bounds.right = bounds.bottom = 100; |
| 867 | | |
| 868 | | // create the child view |
| 869 | | if ( CreateUserPaneControl(info->wnd, &bounds, 0, &view->wnd) != noErr ) |
| 870 | | goto cleanup; |
| 871 | | |
| 872 | | if ( InstallEventHandler( GetControlEventTarget( view->wnd ), NewEventHandlerUPP(debugwin_view_proc), sizeof( debug_view_events ) / sizeof( EventTypeSpec ), debug_view_events, view, NULL ) != noErr ) |
| 873 | | goto cleanup; |
| 874 | | |
| 875 | | // create the scroll bars |
| 876 | | bounds.top = bounds.bottom - hscroll_height; |
| 877 | | |
| 878 | | if ( CreateScrollBarControl(info->wnd, &bounds, 0, 0, 0, 0, TRUE, NewControlActionUPP(debugwin_view_process_scroll), &view->hscroll ) != noErr ) |
| 879 | | goto cleanup; |
| 880 | | |
| 881 | | SetControlProperty(view->hscroll, 'MAME', 'info', sizeof( view ), &view ); |
| 882 | | |
| 883 | | bounds.top = 0; |
| 884 | | bounds.left = bounds.right - vscroll_width; |
| 885 | | |
| 886 | | if ( CreateScrollBarControl(info->wnd, &bounds, 0, 0, 0, 0, TRUE, NewControlActionUPP(debugwin_view_process_scroll), &view->vscroll ) != noErr ) |
| 887 | | goto cleanup; |
| 888 | | |
| 889 | | SetControlProperty(view->vscroll, 'MAME', 'info', sizeof( view ), &view ); |
| 890 | | |
| 891 | | // create the debug view |
| 892 | | view->view = debug_view_alloc(info->machine, type, debugwin_view_update, view); |
| 893 | | if (!view->view) |
| 894 | | goto cleanup; |
| 895 | | |
| 896 | | return 1; |
| 897 | | |
| 898 | | cleanup: |
| 899 | | if (view->view) |
| 900 | | debug_view_free(view->view); |
| 901 | | if (view->hscroll) |
| 902 | | DisposeControl(view->hscroll); |
| 903 | | if (view->vscroll) |
| 904 | | DisposeControl(view->vscroll); |
| 905 | | if (view->wnd) |
| 906 | | DisposeControl(view->wnd); |
| 907 | | return 0; |
| 908 | | } |
| 909 | | |
| 910 | | |
| 911 | | |
| 912 | | //============================================================ |
| 913 | | // debugwin_view_set_bounds |
| 914 | | //============================================================ |
| 915 | | |
| 916 | | static void debugwin_view_set_bounds(debugview_info *info, const Rect *newbounds) |
| 917 | | { |
| 918 | | // account for the edges and set the bounds |
| 919 | | if (info->wnd) |
| 920 | | { |
| 921 | | HIRect bounds; |
| 922 | | |
| 923 | | bounds.origin.x = newbounds->left; |
| 924 | | bounds.origin.y = newbounds->top; |
| 925 | | bounds.size.width = newbounds->right - newbounds->left; |
| 926 | | bounds.size.height = newbounds->bottom - newbounds->top; |
| 927 | | |
| 928 | | smart_set_view_bounds(info->wnd, &bounds); |
| 929 | | } |
| 930 | | |
| 931 | | // update |
| 932 | | debugwin_view_update(info->view, info); |
| 933 | | } |
| 934 | | |
| 935 | | |
| 936 | | |
| 937 | | //============================================================ |
| 938 | | // debugwin_view_draw_contents |
| 939 | | //============================================================ |
| 940 | | |
| 941 | | static void debugwin_view_draw_contents(debugview_info *view, CGContextRef dc) |
| 942 | | { |
| 943 | | const debug_view_char *viewdata = debug_view_get_chars(view->view); |
| 944 | | debug_view_xy visarea = debug_view_get_visible_size(view->view); |
| 945 | | UINT32 col, row; |
| 946 | | HIRect client; |
| 947 | | |
| 948 | | CGContextSaveGState(dc); |
| 949 | | |
| 950 | | // get the client rect |
| 951 | | HIViewGetBounds(view->wnd,&client); |
| 952 | | |
| 953 | | if (!viewdata) return; |
| 954 | | |
| 955 | | // set the font |
| 956 | | CGContextSelectFont(dc, OSX_DEBUGGER_FONT_NAME, OSX_DEBUGGER_FONT_SIZE, kCGEncodingMacRoman); |
| 957 | | CGContextSetTextDrawingMode(dc,kCGTextFill); |
| 958 | | |
| 959 | | // Set the text transform |
| 960 | | { |
| 961 | | CGAffineTransform mtx = CGAffineTransformIdentity; |
| 962 | | |
| 963 | | mtx.d = -mtx.d; |
| 964 | | |
| 965 | | CGContextSetTextMatrix(dc, mtx); |
| 966 | | } |
| 967 | | |
| 968 | | // iterate over rows and columns |
| 969 | | for (row = 0; row < visarea.y; row++) |
| 970 | | { |
| 971 | | int iter; |
| 972 | | |
| 973 | | // loop twice; once to fill the background and once to draw the text |
| 974 | | for (iter = 0; iter < 2; iter++) |
| 975 | | { |
| 976 | | float fgcolor[4] = { 0, 0, 0, 1.0 }; |
| 977 | | float bgcolor[4] = { 1.0, 1.0, 1.0, 1.0 }; |
| 978 | | int last_attrib = -1; |
| 979 | | char buffer[256]; |
| 980 | | int count = 0; |
| 981 | | Rect bounds; |
| 982 | | |
| 983 | | // initialize the text bounds |
| 984 | | bounds.left = bounds.right = 0; |
| 985 | | bounds.top = row * debug_font_height; |
| 986 | | bounds.bottom = bounds.top + debug_font_height; |
| 987 | | |
| 988 | | // iterate over columns |
| 989 | | for (col = 0; col < visarea.x; col++) |
| 990 | | { |
| 991 | | // if the attribute changed, adjust the colors |
| 992 | | if (viewdata[col].attrib != last_attrib) |
| 993 | | { |
| 994 | | float oldbg[4]; |
| 995 | | |
| 996 | | memcpy( oldbg, bgcolor, sizeof( oldbg ) ); |
| 997 | | |
| 998 | | // reset to standard colors |
| 999 | | fgcolor[0] = fgcolor[1] = fgcolor[2] = 0; |
| 1000 | | bgcolor[0] = bgcolor[1] = bgcolor[2] = 1.0; |
| 1001 | | |
| 1002 | | // pick new fg/bg colors |
| 1003 | | if (viewdata[col].attrib & DCA_ANCILLARY) { bgcolor[0] = bgcolor[1] = bgcolor[2] = 0.875; } |
| 1004 | | if (viewdata[col].attrib & DCA_SELECTED) { bgcolor[0] = 1.0; bgcolor[1] = bgcolor[2] = 0.5; } |
| 1005 | | if (viewdata[col].attrib & DCA_CURRENT) { bgcolor[0] = bgcolor[1] = 1.0; bgcolor[2] = 0; } |
| 1006 | | if ((viewdata[col].attrib & DCA_SELECTED) && (viewdata[col].attrib & DCA_CURRENT)) { bgcolor[0] = 1.0; bgcolor[1] = 0.75; bgcolor[2] = 0.5; } |
| 1007 | | if (viewdata[col].attrib & DCA_CHANGED) { fgcolor[0] = 1.0; fgcolor[1] = fgcolor[2] = 0; } |
| 1008 | | if (viewdata[col].attrib & DCA_INVALID) { fgcolor[0] = fgcolor[1] = 0; fgcolor[2] = 1.0; } |
| 1009 | | if (viewdata[col].attrib & DCA_DISABLED) { fgcolor[0] = ( fgcolor[0] + bgcolor[0]) / 2; fgcolor[1] = ( fgcolor[1] + bgcolor[1]) / 2; fgcolor[2] = ( fgcolor[2] + bgcolor[2]) / 2; } |
| 1010 | | if (viewdata[col].attrib & DCA_COMMENT) { fgcolor[0] = fgcolor[2] = 0; fgcolor[1] = 0.5; } |
| 1011 | | |
| 1012 | | // flush any pending drawing |
| 1013 | | if (count > 0) |
| 1014 | | { |
| 1015 | | bounds.right = bounds.left + count * debug_font_width; |
| 1016 | | if (iter == 0) |
| 1017 | | { |
| 1018 | | HIRect frame; |
| 1019 | | |
| 1020 | | frame.origin.x = bounds.left; frame.origin.y = bounds.top; |
| 1021 | | frame.size.width = bounds.right - bounds.left; |
| 1022 | | frame.size.height = bounds.bottom - bounds.top; |
| 1023 | | |
| 1024 | | CGContextSetRGBFillColor(dc, bgcolor[0], bgcolor[1], bgcolor[2], bgcolor[3]); |
| 1025 | | CGContextFillRect(dc, frame); |
| 1026 | | } |
| 1027 | | else |
| 1028 | | { |
| 1029 | | CGContextSetRGBFillColor(dc, fgcolor[0], fgcolor[1], fgcolor[2], fgcolor[3]); |
| 1030 | | CGContextShowTextAtPoint(dc, bounds.left, bounds.top + debug_font_ascent, buffer, count); |
| 1031 | | } |
| 1032 | | bounds.left = bounds.right; |
| 1033 | | count = 0; |
| 1034 | | } |
| 1035 | | |
| 1036 | | last_attrib = viewdata[col].attrib; |
| 1037 | | } |
| 1038 | | |
| 1039 | | // add this character to the buffer |
| 1040 | | buffer[count++] = viewdata[col].byte; |
| 1041 | | } |
| 1042 | | |
| 1043 | | // flush any remaining stuff |
| 1044 | | if (count > 0) |
| 1045 | | { |
| 1046 | | bounds.right = bounds.left + count * debug_font_width; |
| 1047 | | if (iter == 0) |
| 1048 | | { |
| 1049 | | HIRect frame; |
| 1050 | | |
| 1051 | | frame.origin.x = bounds.left; frame.origin.y = bounds.top; |
| 1052 | | frame.size.width = bounds.right - bounds.left; |
| 1053 | | frame.size.height = bounds.bottom - bounds.top; |
| 1054 | | |
| 1055 | | CGContextSetRGBFillColor(dc, bgcolor[0], bgcolor[1], bgcolor[2], bgcolor[3]); |
| 1056 | | CGContextFillRect(dc, frame); |
| 1057 | | } |
| 1058 | | else |
| 1059 | | { |
| 1060 | | CGContextSetRGBFillColor(dc, fgcolor[0], fgcolor[1], fgcolor[2], fgcolor[3]); |
| 1061 | | CGContextShowTextAtPoint(dc, bounds.left, bounds.top + debug_font_ascent, buffer, count); |
| 1062 | | } |
| 1063 | | } |
| 1064 | | |
| 1065 | | // erase to the end of the line |
| 1066 | | if (iter == 0) |
| 1067 | | { |
| 1068 | | HIRect frame; |
| 1069 | | |
| 1070 | | bounds.left = bounds.right; |
| 1071 | | bounds.right = client.origin.x + client.size.width; |
| 1072 | | |
| 1073 | | frame.origin.x = bounds.left; frame.origin.y = bounds.top; |
| 1074 | | frame.size.width = bounds.right - bounds.left; |
| 1075 | | frame.size.height = bounds.bottom - bounds.top; |
| 1076 | | |
| 1077 | | CGContextSetRGBFillColor(dc, bgcolor[0], bgcolor[1], bgcolor[2], bgcolor[3]); |
| 1078 | | CGContextFillRect(dc, frame); |
| 1079 | | } |
| 1080 | | } |
| 1081 | | |
| 1082 | | // advance viewdata |
| 1083 | | viewdata += visarea.x; |
| 1084 | | } |
| 1085 | | |
| 1086 | | // erase anything beyond the bottom with white |
| 1087 | | HIViewGetBounds(view->wnd,&client); |
| 1088 | | client.origin.y = visarea.y * debug_font_height; |
| 1089 | | |
| 1090 | | CGContextSetRGBFillColor(dc, 1.0, 1.0, 1.0, 1.0); |
| 1091 | | CGContextFillRect(dc, client); |
| 1092 | | CGContextRestoreGState(dc); |
| 1093 | | } |
| 1094 | | |
| 1095 | | |
| 1096 | | |
| 1097 | | //============================================================ |
| 1098 | | // debugwin_view_update |
| 1099 | | //============================================================ |
| 1100 | | |
| 1101 | | static void debugwin_view_update(debug_view *view, void *osdprivate) |
| 1102 | | { |
| 1103 | | debugview_info *info = debug_view_find(view); |
| 1104 | | |
| 1105 | | // if we have a view window, process it |
| 1106 | | if (info && info->view) |
| 1107 | | { |
| 1108 | | HIRect bounds, vscroll_bounds, hscroll_bounds; |
| 1109 | | debug_view_xy totalsize, visiblesize, topleft; |
| 1110 | | int show_vscroll, show_hscroll; |
| 1111 | | |
| 1112 | | // get the view window bounds |
| 1113 | | HIViewGetFrame(info->wnd,&bounds); |
| 1114 | | visiblesize.x = bounds.size.width / debug_font_width; |
| 1115 | | visiblesize.y = bounds.size.height / debug_font_height; |
| 1116 | | |
| 1117 | | // get the updated total rows/cols and left row/col |
| 1118 | | totalsize = debug_view_get_total_size(view); |
| 1119 | | topleft = debug_view_get_visible_position(view); |
| 1120 | | |
| 1121 | | // determine if we need to show the scrollbars |
| 1122 | | show_vscroll = show_hscroll = 0; |
| 1123 | | if (totalsize.x > visiblesize.x) |
| 1124 | | { |
| 1125 | | bounds.size.height -= hscroll_height; |
| 1126 | | visiblesize.y = bounds.size.height / debug_font_height; |
| 1127 | | show_hscroll = TRUE; |
| 1128 | | } |
| 1129 | | if (totalsize.y > visiblesize.y) |
| 1130 | | { |
| 1131 | | bounds.size.width -= vscroll_width; |
| 1132 | | visiblesize.x = bounds.size.width / debug_font_width; |
| 1133 | | show_vscroll = TRUE; |
| 1134 | | } |
| 1135 | | if (!show_vscroll && totalsize.y > visiblesize.y) |
| 1136 | | { |
| 1137 | | bounds.size.width -= vscroll_width; |
| 1138 | | visiblesize.x = bounds.size.width / debug_font_width; |
| 1139 | | show_vscroll = TRUE; |
| 1140 | | } |
| 1141 | | |
| 1142 | | // compute the bounds of the scrollbars |
| 1143 | | vscroll_bounds = bounds; |
| 1144 | | vscroll_bounds.origin.x = bounds.origin.x + bounds.size.width; |
| 1145 | | vscroll_bounds.size.width = vscroll_width; |
| 1146 | | |
| 1147 | | hscroll_bounds = bounds; |
| 1148 | | hscroll_bounds.origin.y = bounds.origin.y + bounds.size.height; |
| 1149 | | hscroll_bounds.size.height = hscroll_height; |
| 1150 | | |
| 1151 | | // if we hid the scrollbars, make sure we reset the top/left corners |
| 1152 | | if (topleft.y + visiblesize.y > totalsize.y) |
| 1153 | | topleft.y = MAX(totalsize.y - visiblesize.y, 0); |
| 1154 | | if (topleft.x + visiblesize.x > totalsize.x) |
| 1155 | | topleft.x = MAX(totalsize.x - visiblesize.x, 0); |
| 1156 | | |
| 1157 | | // fill out the scroll info struct for the vertical scrollbar |
| 1158 | | if ( show_vscroll ) |
| 1159 | | { |
| 1160 | | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1161 | | HIViewSetMinimum(info->vscroll,0); |
| 1162 | | HIViewSetMaximum(info->vscroll,totalsize.y-visiblesize.y); |
| 1163 | | HIViewSetValue(info->vscroll,topleft.y); |
| 1164 | | HIViewSetViewSize(info->vscroll,visiblesize.y); |
| 1165 | | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1166 | | SetControl32BitMinimum(info->vscroll,0); |
| 1167 | | SetControl32BitMaximum(info->vscroll,totalsize.y-visiblesize.y); |
| 1168 | | SetControl32BitValue(info->vscroll,topleft.y); |
| 1169 | | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1170 | | } |
| 1171 | | |
| 1172 | | // fill out the scroll info struct for the horizontal scrollbar |
| 1173 | | if ( show_hscroll ) |
| 1174 | | { |
| 1175 | | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1176 | | HIViewSetMinimum(info->hscroll,0); |
| 1177 | | HIViewSetMaximum(info->hscroll,totalsize.x-visiblesize.x); |
| 1178 | | HIViewSetValue(info->hscroll,topleft.x); |
| 1179 | | HIViewSetViewSize(info->hscroll,visiblesize.x); |
| 1180 | | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1181 | | SetControl32BitMinimum(info->hscroll,0); |
| 1182 | | SetControl32BitMaximum(info->hscroll,totalsize.x-visiblesize.x); |
| 1183 | | SetControl32BitValue(info->hscroll,topleft.x); |
| 1184 | | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1185 | | } |
| 1186 | | |
| 1187 | | // update window info |
| 1188 | | visiblesize.y++; |
| 1189 | | visiblesize.x++; |
| 1190 | | debug_view_set_visible_size(view, visiblesize); |
| 1191 | | debug_view_set_visible_position(view, topleft); |
| 1192 | | |
| 1193 | | // invalidate the bounds |
| 1194 | | HIViewSetNeedsDisplay(info->wnd, TRUE); |
| 1195 | | HIViewSetNeedsDisplay(info->hscroll, TRUE); |
| 1196 | | HIViewSetNeedsDisplay(info->vscroll, TRUE); |
| 1197 | | |
| 1198 | | // adjust the bounds of the scrollbars and show/hide them |
| 1199 | | if (info->vscroll) |
| 1200 | | { |
| 1201 | | if (show_vscroll) |
| 1202 | | { |
| 1203 | | // Shorten scroll bar if it intersects with grow box |
| 1204 | | HIPoint scrollBottom, growTop; |
| 1205 | | Rect growRect; |
| 1206 | | |
| 1207 | | GetWindowBounds( HIViewGetWindow( info->wnd ), kWindowGrowRgn, &growRect ); |
| 1208 | | |
| 1209 | | growTop.x = growRect.left; |
| 1210 | | growTop.y = growRect.top; |
| 1211 | | |
| 1212 | | scrollBottom.x = vscroll_bounds.origin.x+vscroll_bounds.size.width; |
| 1213 | | scrollBottom.y = vscroll_bounds.origin.y+vscroll_bounds.size.height; |
| 1214 | | |
| 1215 | | osx_GlobalToViewPoint( HIViewGetSuperview(info->wnd), &growTop, &growTop ); |
| 1216 | | |
| 1217 | | if( scrollBottom.y > growTop.y ) |
| 1218 | | vscroll_bounds.size.height -= hscroll_height; |
| 1219 | | |
| 1220 | | smart_set_view_bounds(info->vscroll, &vscroll_bounds); |
| 1221 | | } |
| 1222 | | |
| 1223 | | smart_show_view(info->vscroll, show_vscroll); |
| 1224 | | } |
| 1225 | | if (info->hscroll) |
| 1226 | | { |
| 1227 | | if (show_hscroll) |
| 1228 | | smart_set_view_bounds(info->hscroll, &hscroll_bounds); |
| 1229 | | smart_show_view(info->hscroll, show_hscroll); |
| 1230 | | } |
| 1231 | | } |
| 1232 | | } |
| 1233 | | |
| 1234 | | |
| 1235 | | |
| 1236 | | //============================================================ |
| 1237 | | // debug_view_find |
| 1238 | | //============================================================ |
| 1239 | | |
| 1240 | | static debugview_info *debug_view_find(debug_view *view) |
| 1241 | | { |
| 1242 | | debugwin_info *info; |
| 1243 | | int curview; |
| 1244 | | |
| 1245 | | // loop over windows and find the view |
| 1246 | | for (info = window_list; info; info = info->next) |
| 1247 | | for (curview = 0; curview < MAX_VIEWS; curview++) |
| 1248 | | if (info->view[curview].view == view) |
| 1249 | | return &info->view[curview]; |
| 1250 | | return NULL; |
| 1251 | | } |
| 1252 | | |
| 1253 | | //============================================================ |
| 1254 | | // debugwin_view_process_scroll |
| 1255 | | //============================================================ |
| 1256 | | |
| 1257 | | static void debugwin_view_process_scroll(HIViewRef inView, ControlPartCode partCode) |
| 1258 | | { |
| 1259 | | debugview_info *info; |
| 1260 | | INT32 result; |
| 1261 | | INT32 maxval; |
| 1262 | | int isHorz; |
| 1263 | | |
| 1264 | | if ( GetControlProperty(inView, 'MAME', 'info', sizeof( info ), NULL, &info ) != noErr) |
| 1265 | | return; |
| 1266 | | |
| 1267 | | isHorz = (inView == info->hscroll) ? 1 : 0; |
| 1268 | | |
| 1269 | | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1270 | | maxval = HIViewGetMaximum(inView); |
| 1271 | | result = HIViewGetValue(inView); |
| 1272 | | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1273 | | maxval = GetControl32BitMaximum(inView); |
| 1274 | | result = GetControl32BitValue(inView); |
| 1275 | | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1276 | | |
| 1277 | | switch( partCode ) |
| 1278 | | { |
| 1279 | | case kAppearancePartUpButton: |
| 1280 | | result--; |
| 1281 | | break; |
| 1282 | | |
| 1283 | | case kAppearancePartDownButton: |
| 1284 | | result++; |
| 1285 | | break; |
| 1286 | | |
| 1287 | | case kAppearancePartIndicator: |
| 1288 | | // nothing if on the thumb |
| 1289 | | break; |
| 1290 | | |
| 1291 | | case kAppearancePartPageUpArea: |
| 1292 | | if ( isHorz ) |
| 1293 | | result -= debug_view_get_visible_size(info->view).x; |
| 1294 | | else |
| 1295 | | result -= debug_view_get_visible_size(info->view).y; |
| 1296 | | break; |
| 1297 | | |
| 1298 | | case kAppearancePartPageDownArea: |
| 1299 | | if ( isHorz ) |
| 1300 | | result += debug_view_get_visible_size(info->view).x; |
| 1301 | | else |
| 1302 | | result += debug_view_get_visible_size(info->view).y; |
| 1303 | | break; |
| 1304 | | } |
| 1305 | | |
| 1306 | | if ( result < 0 ) |
| 1307 | | result = 0; |
| 1308 | | if ( result >= maxval ) |
| 1309 | | result = maxval; |
| 1310 | | |
| 1311 | | if ( isHorz ) |
| 1312 | | { |
| 1313 | | debug_view_xy topleft = debug_view_get_visible_position(info->view); |
| 1314 | | topleft.x = result; |
| 1315 | | debug_view_set_visible_position(info->view, topleft); |
| 1316 | | } |
| 1317 | | else |
| 1318 | | { |
| 1319 | | // if (info->is_textbuf) |
| 1320 | | // { |
| 1321 | | // if( result == maxval ) |
| 1322 | | // result = -1; |
| 1323 | | // debug_view_set_property_UINT32(info->view, DVP_TEXTBUF_LINE_LOCK, result); |
| 1324 | | // } |
| 1325 | | // else |
| 1326 | | { |
| 1327 | | debug_view_xy topleft = debug_view_get_visible_position(info->view); |
| 1328 | | topleft.y = result; |
| 1329 | | debug_view_set_visible_position(info->view, topleft); |
| 1330 | | } |
| 1331 | | } |
| 1332 | | } |
| 1333 | | |
| 1334 | | |
| 1335 | | //============================================================ |
| 1336 | | // debugwin_view_prev_view |
| 1337 | | //============================================================ |
| 1338 | | |
| 1339 | | static void debugwin_view_prev_view(debugwin_info *info, debugview_info *curview) |
| 1340 | | { |
| 1341 | | int curindex = 1; |
| 1342 | | int numviews; |
| 1343 | | |
| 1344 | | // count the number of views |
| 1345 | | for (numviews = 0; numviews < MAX_VIEWS; numviews++) |
| 1346 | | if (info->view[numviews].wnd == NULL) |
| 1347 | | break; |
| 1348 | | |
| 1349 | | // if we have a curview, find out its index |
| 1350 | | if (curview) |
| 1351 | | curindex = curview - &info->view[0]; |
| 1352 | | |
| 1353 | | // loop until we find someone to take focus |
| 1354 | | while (1) |
| 1355 | | { |
| 1356 | | // advance to the previous index |
| 1357 | | curindex--; |
| 1358 | | if (curindex < -1) |
| 1359 | | curindex = numviews - 1; |
| 1360 | | |
| 1361 | | // negative numbers mean the focuswnd |
| 1362 | | if (curindex < 0 && info->focuswnd != NULL) |
| 1363 | | { |
| 1364 | | osx_SetFocus(info->focuswnd); |
| 1365 | | break; |
| 1366 | | } |
| 1367 | | |
| 1368 | | // positive numbers mean a view |
| 1369 | | else if (curindex >= 0 && info->view[curindex].wnd != NULL && debug_view_get_cursor_supported(info->view[curindex].view)) |
| 1370 | | { |
| 1371 | | osx_SetFocus(info->view[curindex].wnd); |
| 1372 | | break; |
| 1373 | | } |
| 1374 | | } |
| 1375 | | } |
| 1376 | | |
| 1377 | | |
| 1378 | | |
| 1379 | | //============================================================ |
| 1380 | | // debugwin_view_next_view |
| 1381 | | //============================================================ |
| 1382 | | |
| 1383 | | static void debugwin_view_next_view(debugwin_info *info, debugview_info *curview) |
| 1384 | | { |
| 1385 | | int curindex = -1; |
| 1386 | | int numviews; |
| 1387 | | |
| 1388 | | // count the number of views |
| 1389 | | for (numviews = 0; numviews < MAX_VIEWS; numviews++) |
| 1390 | | if (info->view[numviews].wnd == NULL) |
| 1391 | | break; |
| 1392 | | |
| 1393 | | // if we have a curview, find out its index |
| 1394 | | if (curview) |
| 1395 | | curindex = curview - &info->view[0]; |
| 1396 | | |
| 1397 | | // loop until we find someone to take focus |
| 1398 | | while (1) |
| 1399 | | { |
| 1400 | | // advance to the previous index |
| 1401 | | curindex++; |
| 1402 | | if (curindex >= numviews) |
| 1403 | | curindex = -1; |
| 1404 | | |
| 1405 | | // negative numbers mean the focuswnd |
| 1406 | | if (curindex < 0 && info->focuswnd != NULL) |
| 1407 | | { |
| 1408 | | osx_SetFocus(info->focuswnd); |
| 1409 | | break; |
| 1410 | | } |
| 1411 | | |
| 1412 | | // positive numbers mean a view |
| 1413 | | else if (curindex >= 0 && info->view[curindex].wnd != NULL && debug_view_get_cursor_supported(info->view[curindex].view)) |
| 1414 | | { |
| 1415 | | osx_SetFocus(info->view[curindex].wnd); |
| 1416 | | HIViewSetNeedsDisplay(info->view[curindex].wnd, TRUE); |
| 1417 | | break; |
| 1418 | | } |
| 1419 | | } |
| 1420 | | } |
| 1421 | | |
| 1422 | | |
| 1423 | | |
| 1424 | | //============================================================ |
| 1425 | | // debugwin_view_proc |
| 1426 | | //============================================================ |
| 1427 | | |
| 1428 | | static OSStatus debugwin_view_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData) |
| 1429 | | { |
| 1430 | | debugview_info *info = (debugview_info *)inUserData; |
| 1431 | | UInt32 eventClass = GetEventClass( inEvent ); |
| 1432 | | UInt32 eventKind = GetEventKind( inEvent ); |
| 1433 | | |
| 1434 | | if ( eventClass == kEventClassControl ) |
| 1435 | | { |
| 1436 | | switch( eventKind ) |
| 1437 | | { |
| 1438 | | // draw |
| 1439 | | case kEventControlDraw: |
| 1440 | | { |
| 1441 | | CGContextRef dc; |
| 1442 | | |
| 1443 | | if ( GetEventParameter( inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(dc), NULL, &dc ) != noErr ) |
| 1444 | | { |
| 1445 | | mame_printf_error( "Compositing attribute not set!\n" ); |
| 1446 | | exit( -1 ); |
| 1447 | | } |
| 1448 | | |
| 1449 | | debugwin_view_draw_contents(info, dc); |
| 1450 | | return noErr; |
| 1451 | | } |
| 1452 | | break; |
| 1453 | | |
| 1454 | | // focus |
| 1455 | | case kEventControlSetFocusPart: |
| 1456 | | { |
| 1457 | | ControlPartCode part; |
| 1458 | | |
| 1459 | | if ( GetEventParameter( inEvent, kEventParamControlPart, typeControlPartCode, NULL, sizeof(part), NULL, &part ) == noErr ) |
| 1460 | | { |
| 1461 | | if ( part == kControlFocusNoPart ) // losing focus |
| 1462 | | { |
| 1463 | | if (debug_view_get_cursor_supported(info->view)) |
| 1464 | | debug_view_set_cursor_visible(info->view, FALSE); |
| 1465 | | } |
| 1466 | | else // gaining focus |
| 1467 | | { |
| 1468 | | if (debug_view_get_cursor_supported(info->view)) |
| 1469 | | debug_view_set_cursor_visible(info->view, TRUE); |
| 1470 | | |
| 1471 | | part = kControlLabelPart; |
| 1472 | | SetEventParameter( inEvent, kEventParamControlPart, typeControlPartCode, sizeof(part), &part ); |
| 1473 | | } |
| 1474 | | |
| 1475 | | return noErr; |
| 1476 | | } |
| 1477 | | } |
| 1478 | | break; |
| 1479 | | |
| 1480 | | // mouse click |
| 1481 | | case kEventControlClick: |
| 1482 | | { |
| 1483 | | HIPoint mousePos; |
| 1484 | | HIPoint viewPos; |
| 1485 | | |
| 1486 | | if ( GetEventParameter( inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(mousePos), NULL, &mousePos ) == noErr ) |
| 1487 | | { |
| 1488 | | EventMouseButton button; |
| 1489 | | |
| 1490 | | osx_GlobalToViewPoint( info->wnd, &mousePos, &viewPos ); |
| 1491 | | |
| 1492 | | if ( GetEventParameter( inEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button ) == noErr ) |
| 1493 | | { |
| 1494 | | if ( button == kEventMouseButtonPrimary ) |
| 1495 | | { |
| 1496 | | if (debug_view_get_cursor_supported(info->view)) |
| 1497 | | { |
| 1498 | | // debug_view_xy topleft = debug_view_get_visible_position(info->view); |
| 1499 | | debug_view_xy newpos; |
| 1500 | | newpos.x = viewPos.x / debug_font_width; |
| 1501 | | newpos.y = viewPos.y / debug_font_height; |
| 1502 | | debug_view_set_cursor_position(info->view, newpos); |
| 1503 | | osx_SetFocus(info->wnd); |
| 1504 | | } |
| 1505 | | return noErr; |
| 1506 | | } |
| 1507 | | } |
| 1508 | | } |
| 1509 | | } |
| 1510 | | break; |
| 1511 | | |
| 1512 | | // contextual menu click |
| 1513 | | case kEventControlContextualMenuClick: |
| 1514 | | { |
| 1515 | | HIPoint viewPos; |
| 1516 | | HIPoint mousePos; |
| 1517 | | |
| 1518 | | if ( GetEventParameter( inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(viewPos), NULL, &viewPos ) == noErr ) |
| 1519 | | { |
| 1520 | | if ( info->owner->contextualMenu ) |
| 1521 | | { |
| 1522 | | osx_ViewToGlobalPoint( info->wnd, &viewPos, &mousePos ); |
| 1523 | | |
| 1524 | | PopUpMenuSelect( info->owner->contextualMenu, mousePos.y, mousePos.x, 0 ); |
| 1525 | | return noErr; |
| 1526 | | } |
| 1527 | | } |
| 1528 | | } |
| 1529 | | break; |
| 1530 | | } |
| 1531 | | } |
| 1532 | | else if ( eventClass == kEventClassMouse && eventKind == kEventMouseWheelMoved ) |
| 1533 | | { |
| 1534 | | EventMouseWheelAxis axis; |
| 1535 | | SInt32 delta; |
| 1536 | | |
| 1537 | | if ( GetEventParameter( inEvent, kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL, sizeof(axis), NULL, &axis ) == noErr ) |
| 1538 | | { |
| 1539 | | if ( GetEventParameter( inEvent, kEventParamMouseWheelDelta, typeLongInteger, NULL, sizeof(delta), NULL, &delta ) == noErr ) |
| 1540 | | { |
| 1541 | | INT32 maxval = 0, result = 0; |
| 1542 | | |
| 1543 | | if ( axis == kEventMouseWheelAxisX && info->hscroll != NULL ) |
| 1544 | | { |
| 1545 | | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1546 | | maxval = HIViewGetMaximum(info->hscroll); |
| 1547 | | result = HIViewGetValue(info->hscroll); |
| 1548 | | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1549 | | maxval = GetControl32BitMaximum(info->hscroll); |
| 1550 | | result = GetControl32BitValue(info->hscroll); |
| 1551 | | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1552 | | } |
| 1553 | | else if ( axis == kEventMouseWheelAxisY && info->vscroll != NULL ) |
| 1554 | | { |
| 1555 | | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1556 | | maxval = HIViewGetMaximum(info->vscroll); |
| 1557 | | result = HIViewGetValue(info->vscroll); |
| 1558 | | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1559 | | maxval = GetControl32BitMaximum(info->vscroll); |
| 1560 | | result = GetControl32BitValue(info->vscroll); |
| 1561 | | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 1562 | | } |
| 1563 | | |
| 1564 | | result -= delta; |
| 1565 | | |
| 1566 | | if ( result < 0 ) |
| 1567 | | result = 0; |
| 1568 | | if ( result >= maxval ) |
| 1569 | | result = maxval; |
| 1570 | | |
| 1571 | | if ( axis == kEventMouseWheelAxisX && info->hscroll ) |
| 1572 | | { |
| 1573 | | debug_view_xy topleft = debug_view_get_visible_position(info->view); |
| 1574 | | topleft.x = result; |
| 1575 | | debug_view_set_visible_position(info->view, topleft); |
| 1576 | | } |
| 1577 | | else if ( axis == kEventMouseWheelAxisY && info->vscroll != NULL ) |
| 1578 | | { |
| 1579 | | // if (info->is_textbuf) |
| 1580 | | // debug_view_set_property_UINT32(info->view, DVP_TEXTBUF_LINE_LOCK, result); |
| 1581 | | // else |
| 1582 | | { |
| 1583 | | debug_view_xy topleft = debug_view_get_visible_position(info->view); |
| 1584 | | topleft.y = result; |
| 1585 | | debug_view_set_visible_position(info->view, topleft); |
| 1586 | | } |
| 1587 | | } |
| 1588 | | } |
| 1589 | | } |
| 1590 | | } |
| 1591 | | else if ( eventClass == kEventClassKeyboard && ( eventKind == kEventRawKeyDown || eventKind == kEventRawKeyRepeat ) ) |
| 1592 | | { |
| 1593 | | EventRecord event; |
| 1594 | | |
| 1595 | | if ( ConvertEventRefToEventRecord( inEvent, &event ) ) |
| 1596 | | { |
| 1597 | | switch( event.message & charCodeMask ) |
| 1598 | | { |
| 1599 | | case kUpArrowCharCode: |
| 1600 | | { |
| 1601 | | debug_view_type_character(info->view, DCH_UP); |
| 1602 | | return noErr; |
| 1603 | | } |
| 1604 | | break; |
| 1605 | | |
| 1606 | | case kDownArrowCharCode: |
| 1607 | | { |
| 1608 | | debug_view_type_character(info->view, DCH_DOWN); |
| 1609 | | return noErr; |
| 1610 | | } |
| 1611 | | break; |
| 1612 | | |
| 1613 | | case kLeftArrowCharCode: |
| 1614 | | { |
| 1615 | | if ( event.modifiers & cmdKey ) |
| 1616 | | debug_view_type_character(info->view, DCH_CTRLLEFT); |
| 1617 | | else |
| 1618 | | debug_view_type_character(info->view, DCH_LEFT); |
| 1619 | | |
| 1620 | | return noErr; |
| 1621 | | } |
| 1622 | | break; |
| 1623 | | |
| 1624 | | case kRightArrowCharCode: |
| 1625 | | { |
| 1626 | | if ( event.modifiers & cmdKey ) |
| 1627 | | debug_view_type_character(info->view, DCH_CTRLRIGHT); |
| 1628 | | else |
| 1629 | | debug_view_type_character(info->view, DCH_RIGHT); |
| 1630 | | |
| 1631 | | return noErr; |
| 1632 | | } |
| 1633 | | break; |
| 1634 | | |
| 1635 | | case kPageUpCharCode: |
| 1636 | | { |
| 1637 | | debug_view_type_character(info->view, DCH_PUP); |
| 1638 | | return noErr; |
| 1639 | | } |
| 1640 | | break; |
| 1641 | | |
| 1642 | | case kPageDownCharCode: |
| 1643 | | { |
| 1644 | | debug_view_type_character(info->view, DCH_PDOWN); |
| 1645 | | return noErr; |
| 1646 | | } |
| 1647 | | break; |
| 1648 | | |
| 1649 | | case kHomeCharCode: |
| 1650 | | { |
| 1651 | | if ( event.modifiers & cmdKey ) |
| 1652 | | debug_view_type_character(info->view, DCH_CTRLHOME); |
| 1653 | | else |
| 1654 | | debug_view_type_character(info->view, DCH_HOME); |
| 1655 | | |
| 1656 | | return noErr; |
| 1657 | | } |
| 1658 | | break; |
| 1659 | | |
| 1660 | | case kEndCharCode: |
| 1661 | | { |
| 1662 | | if ( event.modifiers & cmdKey ) |
| 1663 | | debug_view_type_character(info->view, DCH_CTRLEND); |
| 1664 | | else |
| 1665 | | debug_view_type_character(info->view, DCH_END); |
| 1666 | | |
| 1667 | | return noErr; |
| 1668 | | } |
| 1669 | | break; |
| 1670 | | |
| 1671 | | case kEscapeCharCode: |
| 1672 | | { |
| 1673 | | if (info->owner->focuswnd != NULL) |
| 1674 | | osx_SetFocus(info->owner->focuswnd); |
| 1675 | | return noErr; |
| 1676 | | } |
| 1677 | | break; |
| 1678 | | |
| 1679 | | case kTabCharCode: |
| 1680 | | { |
| 1681 | | if ( event.modifiers & shiftKey ) |
| 1682 | | debugwin_view_prev_view(info->owner, info); |
| 1683 | | else |
| 1684 | | debugwin_view_next_view(info->owner, info); |
| 1685 | | return noErr; |
| 1686 | | } |
| 1687 | | break; |
| 1688 | | |
| 1689 | | default: |
| 1690 | | { |
| 1691 | | char code = event.message & charCodeMask; |
| 1692 | | |
| 1693 | | if (code >= 32 && code < 127 && debug_view_get_cursor_supported(info->view)) |
| 1694 | | { |
| 1695 | | debug_view_type_character(info->view, code); |
| 1696 | | return noErr; |
| 1697 | | } |
| 1698 | | } |
| 1699 | | break; |
| 1700 | | } |
| 1701 | | } |
| 1702 | | } |
| 1703 | | |
| 1704 | | return eventNotHandledErr; |
| 1705 | | } |
| 1706 | | |
| 1707 | | |
| 1708 | | |
| 1709 | | //============================================================ |
| 1710 | | // debugwin_edit_proc |
| 1711 | | //============================================================ |
| 1712 | | |
| 1713 | | static OSStatus debugwin_edit_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData) |
| 1714 | | { |
| 1715 | | debugwin_info *info = (debugwin_info *)inUserData; |
| 1716 | | char buffer[MAX_EDIT_STRING]; |
| 1717 | | |
| 1718 | | UInt32 eventClass = GetEventClass( inEvent ); |
| 1719 | | UInt32 eventKind = GetEventKind( inEvent ); |
| 1720 | | |
| 1721 | | if ( eventClass == kEventClassKeyboard && ( eventKind == kEventRawKeyDown || eventKind == kEventRawKeyRepeat ) ) |
| 1722 | | { |
| 1723 | | EventRecord event; |
| 1724 | | |
| 1725 | | if ( ConvertEventRefToEventRecord( inEvent, &event ) ) |
| 1726 | | { |
| 1727 | | switch( event.message & charCodeMask ) |
| 1728 | | { |
| 1729 | | case kUpArrowCharCode: |
| 1730 | | { |
| 1731 | | ControlEditTextSelectionRec sel; |
| 1732 | | |
| 1733 | | if (info->last_history < info->history_count - 1) |
| 1734 | | info->last_history++; |
| 1735 | | else |
| 1736 | | info->last_history = 0; |
| 1737 | | |
| 1738 | | sel.selStart = strlen(&info->history[info->last_history][0]); |
| 1739 | | sel.selEnd = sel.selStart; |
| 1740 | | |
| 1741 | | SetControlData(info->editwnd, kControlEntireControl, kControlEditTextTextTag, strlen(&info->history[info->last_history][0]), &info->history[info->last_history][0]); |
| 1742 | | SetControlData(info->editwnd, kControlEntireControl, kControlEditTextSelectionTag, sizeof( sel ), &sel ); |
| 1743 | | return noErr; |
| 1744 | | } |
| 1745 | | break; |
| 1746 | | |
| 1747 | | case kDownArrowCharCode: |
| 1748 | | { |
| 1749 | | ControlEditTextSelectionRec sel; |
| 1750 | | |
| 1751 | | if (info->last_history > 0) |
| 1752 | | info->last_history--; |
| 1753 | | else if (info->history_count > 0) |
| 1754 | | info->last_history = info->history_count - 1; |
| 1755 | | else |
| 1756 | | info->last_history = 0; |
| 1757 | | |
| 1758 | | sel.selStart = strlen(&info->history[info->last_history][0]); |
| 1759 | | sel.selEnd = sel.selStart; |
| 1760 | | |
| 1761 | | SetControlData(info->editwnd, kControlEntireControl, kControlEditTextTextTag, strlen(&info->history[info->last_history][0]), &info->history[info->last_history][0]); |
| 1762 | | SetControlData(info->editwnd, kControlEntireControl, kControlEditTextSelectionTag, sizeof( sel ), &sel ); |
| 1763 | | return noErr; |
| 1764 | | } |
| 1765 | | break; |
| 1766 | | |
| 1767 | | case kTabCharCode: |
| 1768 | | { |
| 1769 | | if (event.modifiers & shiftKey) |
| 1770 | | debugwin_view_prev_view(info, NULL); |
| 1771 | | else |
| 1772 | | debugwin_view_next_view(info, NULL); |
| 1773 | | |
| 1774 | | return noErr; |
| 1775 | | } |
| 1776 | | break; |
| 1777 | | |
| 1778 | | case kReturnCharCode: |
| 1779 | | { |
| 1780 | | // fetch the text |
| 1781 | | Size actualSize; |
| 1782 | | GetControlData(info->editwnd, kControlEntireControl, kControlEditTextTextTag, sizeof(buffer), buffer, &actualSize); |
| 1783 | | |
| 1784 | | buffer[actualSize] = 0; |
| 1785 | | |
| 1786 | | // add to the history if it's not a repeat of the last one |
| 1787 | | if (buffer[0] != 0 && strcmp(buffer, &info->history[0][0])) |
| 1788 | | { |
| 1789 | | memmove(&info->history[1][0], &info->history[0][0], (HISTORY_LENGTH - 1) * MAX_EDIT_STRING); |
| 1790 | | strcpy(&info->history[0][0], buffer); |
| 1791 | | if (info->history_count < HISTORY_LENGTH) |
| 1792 | | info->history_count++; |
| 1793 | | } |
| 1794 | | info->last_history = info->history_count - 1; |
| 1795 | | |
| 1796 | | // process |
| 1797 | | if (info->process_string) |
| 1798 | | (*info->process_string)(info, buffer); |
| 1799 | | return noErr; |
| 1800 | | } |
| 1801 | | break; |
| 1802 | | |
| 1803 | | case kEscapeCharCode: |
| 1804 | | { |
| 1805 | | // fetch the text |
| 1806 | | Size actualSize; |
| 1807 | | GetControlData(info->editwnd, kControlEntireControl, kControlEditTextTextTag, sizeof(buffer), buffer, &actualSize); |
| 1808 | | |
| 1809 | | buffer[actualSize] = 0; |
| 1810 | | |
| 1811 | | if (strlen(buffer) > 0) |
| 1812 | | { |
| 1813 | | SetControlData(info->editwnd, kControlEntireControl, kControlEditTextTextTag, 0, buffer); |
| 1814 | | } |
| 1815 | | return noErr; |
| 1816 | | } |
| 1817 | | break; |
| 1818 | | } |
| 1819 | | } |
| 1820 | | } |
| 1821 | | |
| 1822 | | return eventNotHandledErr; |
| 1823 | | } |
| 1824 | | |
| 1825 | | |
| 1826 | | //============================================================ |
| 1827 | | // generic_recompute_children |
| 1828 | | //============================================================ |
| 1829 | | |
| 1830 | | static void generic_recompute_children(debugwin_info *info) |
| 1831 | | { |
| 1832 | | debug_view_xy totalsize = debug_view_get_total_size(info->view[0].view); |
| 1833 | | Rect parent; |
| 1834 | | Rect bounds; |
| 1835 | | HIRect hibounds; |
| 1836 | | |
| 1837 | | // compute a client rect |
| 1838 | | bounds.top = bounds.left = 0; |
| 1839 | | bounds.right = totalsize.x * debug_font_width + vscroll_width + 2 * EDGE_WIDTH; |
| 1840 | | bounds.bottom = 200; |
| 1841 | | // AdjustWindowRectEx(&bounds, DEBUG_WINDOW_STYLE, FALSE, DEBUG_WINDOW_STYLE_EX); |
| 1842 | | |
| 1843 | | // clamp the min/max size |
| 1844 | | info->maxwidth = bounds.right - bounds.left; |
| 1845 | | |
| 1846 | | // get the parent's dimensions |
| 1847 | | HIViewGetBounds(info->contentView,&hibounds); |
| 1848 | | parent.top = hibounds.origin.y; |
| 1849 | | parent.bottom = hibounds.origin.y + hibounds.size.height; |
| 1850 | | parent.left = hibounds.origin.x; |
| 1851 | | parent.right = hibounds.origin.x + hibounds.size.width; |
| 1852 | | |
| 1853 | | // view gets the remaining space |
| 1854 | | parent.top += EDGE_WIDTH; parent.left += EDGE_WIDTH; |
| 1855 | | parent.bottom -= EDGE_WIDTH; parent.right -= EDGE_WIDTH; |
| 1856 | | |
| 1857 | | debugwin_view_set_bounds(&info->view[0], &parent); |
| 1858 | | } |
| 1859 | | |
| 1860 | | |
| 1861 | | |
| 1862 | | //============================================================ |
| 1863 | | // log_create_window |
| 1864 | | //============================================================ |
| 1865 | | |
| 1866 | | static void log_create_window(running_machine *machine) |
| 1867 | | { |
| 1868 | | debug_view_xy totalsize; |
| 1869 | | debugwin_info *info; |
| 1870 | | char title[256]; |
| 1871 | | UINT32 width, height; |
| 1872 | | Rect bounds; |
| 1873 | | |
| 1874 | | // create the window |
| 1875 | | snprintf(title, ARRAY_LENGTH(title), "Errorlog: %s [%s]", machine->gamedrv->description, machine->gamedrv->name); |
| 1876 | | info = debug_window_create(machine, title, NULL); |
| 1877 | | if (info == NULL || !debugwin_view_create(info, 0, DVT_LOG)) |
| 1878 | | return; |
| 1879 | | |
| 1880 | | // set the child function |
| 1881 | | info->recompute_children = generic_recompute_children; |
| 1882 | | |
| 1883 | | // get the view width |
| 1884 | | totalsize = debug_view_get_total_size(info->view[0].view); |
| 1885 | | |
| 1886 | | // compute a client rect |
| 1887 | | bounds.top = bounds.left = 0; |
| 1888 | | bounds.right = totalsize.x * debug_font_width + vscroll_width + 2 * EDGE_WIDTH; |
| 1889 | | bounds.bottom = 200; |
| 1890 | | // AdjustWindowRectEx(&bounds, DEBUG_WINDOW_STYLE, FALSE, DEBUG_WINDOW_STYLE_EX); |
| 1891 | | |
| 1892 | | // clamp the min/max size |
| 1893 | | info->maxwidth = bounds.right - bounds.left; |
| 1894 | | |
| 1895 | | // position the window at the bottom-right |
| 1896 | | width = bounds.right - bounds.left; |
| 1897 | | height = bounds.bottom - bounds.top; |
| 1898 | | |
| 1899 | | bounds.top = bounds.left = 100; |
| 1900 | | bounds.right = bounds.left + width; |
| 1901 | | bounds.bottom = bounds.top + height; |
| 1902 | | |
| 1903 | | SetWindowBounds(info->wnd, kWindowStructureRgn, &bounds ); |
| 1904 | | ShowWindow(info->wnd); |
| 1905 | | SelectWindow(info->wnd); |
| 1906 | | |
| 1907 | | // recompute the children and set focus on the edit box |
| 1908 | | generic_recompute_children(info); |
| 1909 | | } |
| 1910 | | |
| 1911 | | |
| 1912 | | |
| 1913 | | //============================================================ |
| 1914 | | // memory_create_window |
| 1915 | | //============================================================ |
| 1916 | | |
| 1917 | | static void memory_create_window(running_machine *machine) |
| 1918 | | { |
| 1919 | | const device_config *curcpu = debug_cpu_get_visible_cpu(machine); |
| 1920 | | const memory_subview_item *subview; |
| 1921 | | int cursel = -1; |
| 1922 | | debugwin_info *info; |
| 1923 | | MenuRef optionsmenu,popupmenu; |
| 1924 | | Rect bounds; |
| 1925 | | ControlFontStyleRec style; |
| 1926 | | Str255 fontName; |
| 1927 | | MenuItemIndex menuIndex; |
| 1928 | | ControlButtonContentInfo content; |
| 1929 | | |
| 1930 | | // create the window |
| 1931 | | info = debug_window_create(machine, "Memory", NULL); |
| 1932 | | if (!info || !debugwin_view_create(info, 0, DVT_MEMORY)) |
| 1933 | | return; |
| 1934 | | |
| 1935 | | // set the handlers |
| 1936 | | info->handle_command = memory_handle_command; |
| 1937 | | info->handle_key = memory_handle_key; |
| 1938 | | |
| 1939 | | // create the options menu |
| 1940 | | if ( CreateNewMenu( 0, 0, &optionsmenu ) != noErr ) |
| 1941 | | { |
| 1942 | | mame_printf_error( "Could not create menu\n" ); |
| 1943 | | exit( -1 ); |
| 1944 | | } |
| 1945 | | |
| 1946 | | { |
| 1947 | | EventTypeSpec spec = { kEventClassCommand, kEventCommandProcess }; |
| 1948 | | |
| 1949 | | InstallEventHandler( GetMenuEventTarget( optionsmenu ), NewEventHandlerUPP(debug_window_proc), 1, &spec, info, NULL ); |
| 1950 | | } |
| 1951 | | |
| 1952 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("1-byte chunks"), 0, ID_1_BYTE_CHUNKS, &menuIndex ); |
| 1953 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, '1'); |
| 1954 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("2-byte chunks"), 0, ID_2_BYTE_CHUNKS, &menuIndex ); |
| 1955 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, '2'); |
| 1956 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("4-byte chunks"), 0, ID_4_BYTE_CHUNKS, &menuIndex ); |
| 1957 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, '4'); |
| 1958 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("8-byte chunks"), 0, ID_8_BYTE_CHUNKS, &menuIndex ); |
| 1959 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, '8'); |
| 1960 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("-"), kMenuItemAttrSeparator, 0, NULL ); |
| 1961 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Logical Addresses"), 0, ID_LOGICAL_ADDRESSES, &menuIndex ); |
| 1962 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, 'L'); |
| 1963 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Physical Addresses"), 0, ID_PHYSICAL_ADDRESSES, &menuIndex ); |
| 1964 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, 'Y'); |
| 1965 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("-"), kMenuItemAttrSeparator, 0, NULL ); |
| 1966 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Reverse View"), 0, ID_REVERSE_VIEW, &menuIndex ); |
| 1967 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, 'R'); |
| 1968 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("-"), kMenuItemAttrSeparator, 0, NULL ); |
| 1969 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Increase bytes per line"), 0, ID_INCREASE_MEM_WIDTH, &menuIndex ); |
| 1970 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, 'P'); |
| 1971 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Decrease bytes per line"), 0, ID_DECREASE_MEM_WIDTH, &menuIndex ); |
| 1972 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, 'O'); |
| 1973 | | info->contextualMenu = optionsmenu; |
| 1974 | | memory_update_checkmarks(info); |
| 1975 | | |
| 1976 | | // set up the view to track the initial expression |
| 1977 | | memory_view_set_expression(info->view[0].view, "0"); |
| 1978 | | strcpy(info->edit_defstr, "0"); |
| 1979 | | |
| 1980 | | fontName[0] = strlen( OSX_DEBUGGER_FONT_NAME ); |
| 1981 | | strcpy( (char*)&fontName[1], OSX_DEBUGGER_FONT_NAME ); |
| 1982 | | |
| 1983 | | style.flags = kControlUseFontMask | kControlUseSizeMask; |
| 1984 | | style.font = ATSFontFamilyFindFromQuickDrawName(fontName); |
| 1985 | | style.size = OSX_DEBUGGER_FONT_SIZE; |
| 1986 | | |
| 1987 | | // create an edit box and override its key handling |
| 1988 | | bounds.top = bounds.left = 0; |
| 1989 | | bounds.bottom = bounds.right = 100; |
| 1990 | | CreateEditUnicodeTextControl(info->wnd, &bounds, CFSTR("0"), false, NULL, &info->editwnd); |
| 1991 | | SetControlFontStyle(info->editwnd,&style); |
| 1992 | | InstallEventHandler( GetControlEventTarget(info->editwnd), NewEventHandlerUPP(debugwin_edit_proc), sizeof( debug_keyboard_events ) / sizeof( EventTypeSpec ), debug_keyboard_events, info, NULL ); |
| 1993 | | |
| 1994 | | // create action menu and attach the contextual menu |
| 1995 | | content.contentType = kControlContentTextOnly; |
| 1996 | | bounds.top = bounds.left = 0; |
| 1997 | | bounds.bottom = bounds.right = 100; |
| 1998 | | CreateBevelButtonControl(info->wnd, &bounds, CFSTR(""), kControlBevelButtonSmallBevel, kControlBehaviorPushbutton, &content, 1, kControlBehaviorMultiValueMenu, kControlBevelButtonMenuOnBottom, &info->menuwnd ); |
| 1999 | | SetControlData(info->menuwnd, kControlEntireControl, kControlBevelButtonMenuHandleTag, sizeof(optionsmenu), &optionsmenu); |
| 2000 | | |
| 2001 | | // create a popup control |
| 2002 | | CreatePopupButtonControl(info->wnd, &bounds, CFSTR(""), -12345, FALSE, 0, teFlushRight, normal, &info->otherwnd[0]); |
| 2003 | | SetControlFontStyle(info->otherwnd[0],&style); |
| 2004 | | SetControlCommandID(info->otherwnd[0], OSX_POPUP_COMMAND); |
| 2005 | | |
| 2006 | | if ( CreateNewMenu( 0, 0, &popupmenu ) != noErr ) |
| 2007 | | { |
| 2008 | | mame_printf_error( "Could not create menu\n" ); |
| 2009 | | exit( -1 ); |
| 2010 | | } |
| 2011 | | |
| 2012 | | { |
| 2013 | | EventTypeSpec spec = { kEventClassCommand, kEventCommandProcess }; |
| 2014 | | |
| 2015 | | InstallEventHandler( GetMenuEventTarget( popupmenu ), NewEventHandlerUPP(debug_window_proc), 1, &spec, info, NULL ); |
| 2016 | | } |
| 2017 | | |
| 2018 | | // populate the combobox |
| 2019 | | for (subview = memory_view_get_subview_list(info->view[0].view); subview != NULL; subview = subview->next) |
| 2020 | | { |
| 2021 | | CFStringRef cfName = CFStringCreateWithCString( NULL, subview->name, CFStringGetSystemEncoding() ); |
| 2022 | | UInt16 item; |
| 2023 | | |
| 2024 | | AppendMenuItemTextWithCFString( popupmenu, cfName, 0, 0, &item ); |
| 2025 | | |
| 2026 | | CFRelease( cfName ); |
| 2027 | | |
| 2028 | | if (cursel == -1 && subview->space != NULL && subview->space->cpu == curcpu) |
| 2029 | | { |
| 2030 | | cursel = item; |
| 2031 | | } |
| 2032 | | } |
| 2033 | | if (cursel == -1) cursel = 0; |
| 2034 | | |
| 2035 | | SetControlData(info->otherwnd[0], kControlEntireControl, kControlPopupButtonOwnedMenuRefTag, sizeof(popupmenu),&popupmenu); |
| 2036 | | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2037 | | HIViewSetMinimum(info->otherwnd[0], 1); |
| 2038 | | HIViewSetMaximum(info->otherwnd[0], CountMenuItems(popupmenu)); |
| 2039 | | HIViewSetValue(info->otherwnd[0],cursel); |
| 2040 | | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2041 | | SetControl32BitMinimum(info->otherwnd[0], 1); |
| 2042 | | SetControl32BitMaximum(info->otherwnd[0], CountMenuItems(popupmenu)); |
| 2043 | | SetControl32BitValue(info->otherwnd[0],cursel); |
| 2044 | | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2045 | | |
| 2046 | | // set the child functions |
| 2047 | | info->recompute_children = memory_recompute_children; |
| 2048 | | info->process_string = memory_process_string; |
| 2049 | | |
| 2050 | | // set the caption |
| 2051 | | memory_update_caption(info); |
| 2052 | | |
| 2053 | | // recompute the children once to get the maxwidth |
| 2054 | | memory_recompute_children(info); |
| 2055 | | |
| 2056 | | // position the window and recompute children again |
| 2057 | | bounds.top = bounds.left = 100; |
| 2058 | | bounds.right = bounds.left + info->maxwidth; |
| 2059 | | bounds.bottom = bounds.top + 200; |
| 2060 | | |
| 2061 | | SetWindowBounds(info->wnd, kWindowStructureRgn, &bounds ); |
| 2062 | | ShowWindow(info->wnd); |
| 2063 | | SelectWindow(info->wnd); |
| 2064 | | |
| 2065 | | memory_recompute_children(info); |
| 2066 | | |
| 2067 | | // mark the edit box as the default focus and set it |
| 2068 | | info->focuswnd = info->editwnd; |
| 2069 | | osx_SetFocus(info->editwnd); |
| 2070 | | } |
| 2071 | | |
| 2072 | | |
| 2073 | | |
| 2074 | | //============================================================ |
| 2075 | | // memory_recompute_children |
| 2076 | | //============================================================ |
| 2077 | | |
| 2078 | | static void memory_recompute_children(debugwin_info *info) |
| 2079 | | { |
| 2080 | | debug_view_xy totalsize = debug_view_get_total_size(info->view[0].view); |
| 2081 | | Rect parent, memrect, editrect, comborect, actionrect; |
| 2082 | | Rect bounds; |
| 2083 | | HIRect hibounds; |
| 2084 | | |
| 2085 | | // compute a client rect |
| 2086 | | bounds.top = bounds.left = 0; |
| 2087 | | bounds.right = totalsize.x * debug_font_width + vscroll_width + 2 * EDGE_WIDTH; |
| 2088 | | bounds.bottom = 200; |
| 2089 | | // AdjustWindowRectEx(&bounds, DEBUG_WINDOW_STYLE, FALSE, DEBUG_WINDOW_STYLE_EX); |
| 2090 | | |
| 2091 | | // clamp the min/max size |
| 2092 | | info->maxwidth = bounds.right - bounds.left; |
| 2093 | | |
| 2094 | | // get the parent's dimensions |
| 2095 | | HIViewGetBounds(info->contentView,&hibounds); |
| 2096 | | parent.top = hibounds.origin.y; |
| 2097 | | parent.bottom = hibounds.origin.y + hibounds.size.height; |
| 2098 | | parent.left = hibounds.origin.x; |
| 2099 | | parent.right = hibounds.origin.x + hibounds.size.width; |
| 2100 | | |
| 2101 | | // edit box gets half of the width (minus a little for the action button) |
| 2102 | | editrect.top = parent.top + EDGE_WIDTH; |
| 2103 | | editrect.bottom = editrect.top + debug_font_height + 4; |
| 2104 | | editrect.left = parent.left + EDGE_WIDTH; |
| 2105 | | editrect.right = parent.left + (parent.right - parent.left) / 2 - EDGE_WIDTH - 20 - EDGE_WIDTH; |
| 2106 | | |
| 2107 | | // action button goes right next to the edit box |
| 2108 | | |
| 2109 | | actionrect.top = editrect.top - 1; |
| 2110 | | actionrect.bottom = editrect.bottom + 1; |
| 2111 | | actionrect.left = editrect.right + EDGE_WIDTH + 2; |
| 2112 | | actionrect.right = actionrect.left + 20; |
| 2113 | | |
| 2114 | | // combo box gets the other half of the width |
| 2115 | | comborect.top = editrect.top; |
| 2116 | | comborect.bottom = editrect.bottom; |
| 2117 | | comborect.left = actionrect.right + EDGE_WIDTH; |
| 2118 | | comborect.right = parent.right - EDGE_WIDTH; |
| 2119 | | |
| 2120 | | // memory view gets the rest |
| 2121 | | memrect.top = editrect.bottom + 2 * EDGE_WIDTH; |
| 2122 | | memrect.bottom = parent.bottom - EDGE_WIDTH; |
| 2123 | | memrect.left = parent.left + EDGE_WIDTH; |
| 2124 | | memrect.right = parent.right - EDGE_WIDTH; |
| 2125 | | |
| 2126 | | // set the bounds of things |
| 2127 | | debugwin_view_set_bounds(&info->view[0], &memrect); |
| 2128 | | |
| 2129 | | osx_RectToHIRect( &editrect, &hibounds ); |
| 2130 | | smart_set_view_bounds(info->editwnd, &hibounds); |
| 2131 | | |
| 2132 | | osx_RectToHIRect( &comborect, &hibounds ); |
| 2133 | | smart_set_view_bounds(info->otherwnd[0], &hibounds); |
| 2134 | | |
| 2135 | | osx_RectToHIRect( &actionrect, &hibounds ); |
| 2136 | | smart_set_view_bounds(info->menuwnd, &hibounds); |
| 2137 | | } |
| 2138 | | |
| 2139 | | //============================================================ |
| 2140 | | // memory_process_string |
| 2141 | | //============================================================ |
| 2142 | | |
| 2143 | | static void memory_process_string(debugwin_info *info, const char *string) |
| 2144 | | { |
| 2145 | | // set the string to the memory view |
| 2146 | | memory_view_set_expression(info->view[0].view, string); |
| 2147 | | |
| 2148 | | // select everything in the edit text box |
| 2149 | | { |
| 2150 | | ControlEditTextSelectionRec sel; |
| 2151 | | |
| 2152 | | sel.selStart = 0; |
| 2153 | | sel.selEnd = strlen(string); |
| 2154 | | |
| 2155 | | SetControlData(info->editwnd, kControlEntireControl, kControlEditTextSelectionTag, sizeof( sel ), &sel ); |
| 2156 | | } |
| 2157 | | |
| 2158 | | // update the default string to match |
| 2159 | | strncpy(info->edit_defstr, string, sizeof(info->edit_defstr) - 1); |
| 2160 | | } |
| 2161 | | |
| 2162 | | |
| 2163 | | |
| 2164 | | //============================================================ |
| 2165 | | // memory_update_checkmarks |
| 2166 | | //============================================================ |
| 2167 | | |
| 2168 | | static void memory_update_checkmarks(debugwin_info *info) |
| 2169 | | { |
| 2170 | | if ( info->contextualMenu != NULL ) |
| 2171 | | { |
| 2172 | | MenuItemIndex menuindex; |
| 2173 | | |
| 2174 | | GetIndMenuItemWithCommandID( info->contextualMenu, ID_1_BYTE_CHUNKS, 1, NULL, &menuindex ); |
| 2175 | | CheckMenuItem(info->contextualMenu, menuindex, (memory_view_get_bytes_per_chunk(info->view[0].view) == 1)); |
| 2176 | | GetIndMenuItemWithCommandID( info->contextualMenu, ID_2_BYTE_CHUNKS, 1, NULL, &menuindex); |
| 2177 | | CheckMenuItem(info->contextualMenu, menuindex, (memory_view_get_bytes_per_chunk(info->view[0].view) == 2)); |
| 2178 | | GetIndMenuItemWithCommandID( info->contextualMenu, ID_4_BYTE_CHUNKS, 1, NULL, &menuindex); |
| 2179 | | CheckMenuItem(info->contextualMenu, menuindex, (memory_view_get_bytes_per_chunk(info->view[0].view) == 4)); |
| 2180 | | GetIndMenuItemWithCommandID( info->contextualMenu, ID_8_BYTE_CHUNKS, 1, NULL, &menuindex); |
| 2181 | | CheckMenuItem(info->contextualMenu, menuindex, (memory_view_get_bytes_per_chunk(info->view[0].view) == 8)); |
| 2182 | | GetIndMenuItemWithCommandID( info->contextualMenu, ID_LOGICAL_ADDRESSES, 1, NULL, &menuindex); |
| 2183 | | CheckMenuItem(info->contextualMenu, menuindex, (memory_view_get_physical(info->view[0].view) == 0)); |
| 2184 | | GetIndMenuItemWithCommandID( info->contextualMenu, ID_PHYSICAL_ADDRESSES, 1, NULL, &menuindex); |
| 2185 | | CheckMenuItem(info->contextualMenu, menuindex, (memory_view_get_physical(info->view[0].view) != 0)); |
| 2186 | | GetIndMenuItemWithCommandID( info->contextualMenu, ID_REVERSE_VIEW, 1, NULL, &menuindex); |
| 2187 | | CheckMenuItem(info->contextualMenu, menuindex, memory_view_get_reverse(info->view[0].view)); |
| 2188 | | } |
| 2189 | | } |
| 2190 | | |
| 2191 | | |
| 2192 | | |
| 2193 | | //============================================================ |
| 2194 | | // memory_handle_command |
| 2195 | | //============================================================ |
| 2196 | | |
| 2197 | | static int memory_handle_command(debugwin_info *info, EventRef inEvent) |
| 2198 | | { |
| 2199 | | HICommand cmd; |
| 2200 | | |
| 2201 | | if ( GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof( cmd ), NULL, &cmd ) != noErr ) |
| 2202 | | return global_handle_command(info, inEvent); |
| 2203 | | |
| 2204 | | switch( cmd.commandID ) |
| 2205 | | { |
| 2206 | | case OSX_POPUP_COMMAND: |
| 2207 | | { |
| 2208 | | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2209 | | int sel = HIViewGetValue(info->otherwnd[0]); |
| 2210 | | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2211 | | int sel = GetControl32BitValue(info->otherwnd[0]); |
| 2212 | | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2213 | | |
| 2214 | | if ( sel > 0 ) |
| 2215 | | { |
| 2216 | | memory_view_set_subview(info->view[0].view, sel-1); |
| 2217 | | memory_update_caption(info); |
| 2218 | | |
| 2219 | | // reset the focus |
| 2220 | | osx_SetFocus(info->focuswnd); |
| 2221 | | return 1; |
| 2222 | | } |
| 2223 | | } |
| 2224 | | break; |
| 2225 | | |
| 2226 | | |
| 2227 | | case ID_1_BYTE_CHUNKS: |
| 2228 | | memory_view_set_bytes_per_chunk(info->view[0].view, 1); |
| 2229 | | return 1; |
| 2230 | | |
| 2231 | | case ID_2_BYTE_CHUNKS: |
| 2232 | | memory_view_set_bytes_per_chunk(info->view[0].view, 2); |
| 2233 | | return 1; |
| 2234 | | |
| 2235 | | case ID_4_BYTE_CHUNKS: |
| 2236 | | memory_view_set_bytes_per_chunk(info->view[0].view, 4); |
| 2237 | | return 1; |
| 2238 | | |
| 2239 | | case ID_8_BYTE_CHUNKS: |
| 2240 | | memory_view_set_bytes_per_chunk(info->view[0].view, 8); |
| 2241 | | return 1; |
| 2242 | | |
| 2243 | | case ID_LOGICAL_ADDRESSES: |
| 2244 | | memory_view_set_physical(info->view[0].view, FALSE); |
| 2245 | | return 1; |
| 2246 | | |
| 2247 | | case ID_PHYSICAL_ADDRESSES: |
| 2248 | | memory_view_set_physical(info->view[0].view, TRUE); |
| 2249 | | return 1; |
| 2250 | | |
| 2251 | | case ID_REVERSE_VIEW: |
| 2252 | | memory_view_set_reverse(info->view[0].view, !memory_view_get_reverse(info->view[0].view)); |
| 2253 | | return 1; |
| 2254 | | |
| 2255 | | case ID_INCREASE_MEM_WIDTH: |
| 2256 | | memory_view_set_chunks_per_row(info->view[0].view, memory_view_get_chunks_per_row(info->view[0].view) + 1); |
| 2257 | | return 1; |
| 2258 | | |
| 2259 | | case ID_DECREASE_MEM_WIDTH: |
| 2260 | | memory_view_set_chunks_per_row(info->view[0].view, memory_view_get_chunks_per_row(info->view[0].view) - 1); |
| 2261 | | return 1; |
| 2262 | | } |
| 2263 | | |
| 2264 | | return global_handle_command(info, inEvent); |
| 2265 | | } |
| 2266 | | |
| 2267 | | |
| 2268 | | |
| 2269 | | //============================================================ |
| 2270 | | // memory_handle_key |
| 2271 | | //============================================================ |
| 2272 | | |
| 2273 | | static int memory_handle_key(debugwin_info *info, EventRef inEvent) |
| 2274 | | { |
| 2275 | | EventRecord event; |
| 2276 | | |
| 2277 | | if ( ConvertEventRefToEventRecord( inEvent, &event ) ) |
| 2278 | | { |
| 2279 | | if ( event.modifiers & cmdKey ) |
| 2280 | | { |
| 2281 | | switch( event.message & charCodeMask ) |
| 2282 | | { |
| 2283 | | case '1': |
| 2284 | | memory_view_set_bytes_per_chunk(info->view[0].view, 1); |
| 2285 | | return 1; |
| 2286 | | |
| 2287 | | case '2': |
| 2288 | | memory_view_set_bytes_per_chunk(info->view[0].view, 2); |
| 2289 | | return 1; |
| 2290 | | |
| 2291 | | case '4': |
| 2292 | | memory_view_set_bytes_per_chunk(info->view[0].view, 4); |
| 2293 | | return 1; |
| 2294 | | |
| 2295 | | case '8': |
| 2296 | | memory_view_set_bytes_per_chunk(info->view[0].view, 8); |
| 2297 | | return 1; |
| 2298 | | |
| 2299 | | case 'l': |
| 2300 | | case 'L': |
| 2301 | | memory_view_set_physical(info->view[0].view, FALSE); |
| 2302 | | return 1; |
| 2303 | | |
| 2304 | | case 'y': |
| 2305 | | case 'Y': |
| 2306 | | memory_view_set_physical(info->view[0].view, TRUE); |
| 2307 | | return 1; |
| 2308 | | |
| 2309 | | case 'r': |
| 2310 | | case 'R': |
| 2311 | | memory_view_set_reverse(info->view[0].view, !memory_view_get_reverse(info->view[0].view)); |
| 2312 | | return 1; |
| 2313 | | |
| 2314 | | case 'p': |
| 2315 | | case 'P': |
| 2316 | | memory_view_set_chunks_per_row(info->view[0].view, memory_view_get_chunks_per_row(info->view[0].view) + 1); |
| 2317 | | return 1; |
| 2318 | | |
| 2319 | | case 'o': |
| 2320 | | case 'O': |
| 2321 | | memory_view_set_chunks_per_row(info->view[0].view, memory_view_get_chunks_per_row(info->view[0].view) - 1); |
| 2322 | | return 1; |
| 2323 | | } |
| 2324 | | } |
| 2325 | | } |
| 2326 | | |
| 2327 | | return global_handle_key(info, inEvent); |
| 2328 | | } |
| 2329 | | |
| 2330 | | |
| 2331 | | |
| 2332 | | //============================================================ |
| 2333 | | // memory_update_caption |
| 2334 | | //============================================================ |
| 2335 | | |
| 2336 | | static void memory_update_caption(debugwin_info *info) |
| 2337 | | { |
| 2338 | | const memory_subview_item *subview = memory_view_get_current_subview(info->view[0].view); |
| 2339 | | CFStringRef cftitle; |
| 2340 | | char title[256]; |
| 2341 | | |
| 2342 | | // update the caption |
| 2343 | | snprintf(title, ARRAY_LENGTH(title), "Memory: %s", subview->name); |
| 2344 | | |
| 2345 | | cftitle = CFStringCreateWithCString( NULL, title, CFStringGetSystemEncoding() ); |
| 2346 | | |
| 2347 | | if ( cftitle ) |
| 2348 | | { |
| 2349 | | SetWindowTitleWithCFString( info->wnd, cftitle); |
| 2350 | | CFRelease( cftitle ); |
| 2351 | | } |
| 2352 | | } |
| 2353 | | |
| 2354 | | |
| 2355 | | |
| 2356 | | //============================================================ |
| 2357 | | // disasm_create_window |
| 2358 | | //============================================================ |
| 2359 | | |
| 2360 | | static void disasm_create_window(running_machine *machine) |
| 2361 | | { |
| 2362 | | const device_config *curcpu = debug_cpu_get_visible_cpu(machine); |
| 2363 | | const disasm_subview_item *subview; |
| 2364 | | int cursel = 0; |
| 2365 | | debugwin_info *info; |
| 2366 | | MenuRef optionsmenu, popupmenu; |
| 2367 | | Rect bounds; |
| 2368 | | ControlFontStyleRec style; |
| 2369 | | Str255 fontName; |
| 2370 | | MenuItemIndex menuIndex; |
| 2371 | | ControlButtonContentInfo content; |
| 2372 | | |
| 2373 | | // create the window |
| 2374 | | info = debug_window_create(machine, "Disassembly", NULL); |
| 2375 | | if (!info || !debugwin_view_create(info, 0, DVT_DISASSEMBLY)) |
| 2376 | | return; |
| 2377 | | |
| 2378 | | // create the options menu |
| 2379 | | if ( CreateNewMenu( 0, 0, &optionsmenu ) != noErr ) |
| 2380 | | { |
| 2381 | | mame_printf_error( "Could not create menu\n" ); |
| 2382 | | exit( -1 ); |
| 2383 | | } |
| 2384 | | |
| 2385 | | { |
| 2386 | | EventTypeSpec spec = { kEventClassCommand, kEventCommandProcess }; |
| 2387 | | |
| 2388 | | InstallEventHandler( GetMenuEventTarget( optionsmenu ), NewEventHandlerUPP(debug_window_proc), 1, &spec, info, NULL ); |
| 2389 | | } |
| 2390 | | |
| 2391 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Set breakpoint at cursor"), 0, ID_TOGGLE_BREAKPOINT, &menuIndex ); |
| 2392 | | SetMenuItemKeyGlyph(optionsmenu, menuIndex, kMenuF9Glyph); SetMenuItemModifiers(optionsmenu, menuIndex, kMenuNoCommandModifier); |
| 2393 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Run to cursor"), 0, ID_RUN_TO_CURSOR, &menuIndex ); |
| 2394 | | SetMenuItemKeyGlyph(optionsmenu, menuIndex, kMenuF4Glyph); SetMenuItemModifiers(optionsmenu, menuIndex, kMenuNoCommandModifier); |
| 2395 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("-"), kMenuItemAttrSeparator, 0, NULL ); |
| 2396 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Raw opcodes"), 0, ID_SHOW_RAW, &menuIndex ); |
| 2397 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, 'R'); |
| 2398 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Encrypted opcodes"), 0, ID_SHOW_ENCRYPTED, &menuIndex ); |
| 2399 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, 'E'); |
| 2400 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Comments"), 0, ID_SHOW_COMMENTS, &menuIndex ); |
| 2401 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, 'N'); |
| 2402 | | info->contextualMenu = optionsmenu; |
| 2403 | | disasm_update_checkmarks(info); |
| 2404 | | |
| 2405 | | // set the handlers |
| 2406 | | info->handle_command = disasm_handle_command; |
| 2407 | | info->handle_key = disasm_handle_key; |
| 2408 | | |
| 2409 | | // set up the view to track the initial expression |
| 2410 | | disasm_view_set_expression(info->view[0].view, "curpc"); |
| 2411 | | strcpy(info->edit_defstr, "curpc"); |
| 2412 | | |
| 2413 | | fontName[0] = strlen( OSX_DEBUGGER_FONT_NAME ); |
| 2414 | | strcpy( (char*)&fontName[1], OSX_DEBUGGER_FONT_NAME ); |
| 2415 | | |
| 2416 | | style.flags = kControlUseFontMask | kControlUseSizeMask; |
| 2417 | | style.font = ATSFontFamilyFindFromQuickDrawName(fontName); |
| 2418 | | style.size = OSX_DEBUGGER_FONT_SIZE; |
| 2419 | | |
| 2420 | | // create an edit box and override its key handling |
| 2421 | | bounds.top = bounds.left = 0; |
| 2422 | | bounds.bottom = bounds.right = 100; |
| 2423 | | CreateEditUnicodeTextControl(info->wnd, &bounds, CFSTR("0"), false, NULL, &info->editwnd); |
| 2424 | | SetControlFontStyle(info->editwnd,&style); |
| 2425 | | InstallEventHandler( GetControlEventTarget(info->editwnd), NewEventHandlerUPP(debugwin_edit_proc), sizeof( debug_keyboard_events ) / sizeof( EventTypeSpec ), debug_keyboard_events, info, NULL ); |
| 2426 | | |
| 2427 | | // create action menu and attach the contextual menu |
| 2428 | | content.contentType = kControlContentTextOnly; |
| 2429 | | bounds.top = bounds.left = 0; |
| 2430 | | bounds.bottom = bounds.right = 100; |
| 2431 | | CreateBevelButtonControl(info->wnd, &bounds, CFSTR(""), kControlBevelButtonSmallBevel, kControlBehaviorPushbutton, &content, 1, kControlBehaviorMultiValueMenu, kControlBevelButtonMenuOnBottom, &info->menuwnd ); |
| 2432 | | SetControlData(info->menuwnd, kControlEntireControl, kControlBevelButtonMenuHandleTag, sizeof(optionsmenu), &optionsmenu); |
| 2433 | | |
| 2434 | | // create a popup control |
| 2435 | | CreatePopupButtonControl(info->wnd, &bounds, CFSTR(""), -12345, FALSE, 0, teFlushRight, normal, &info->otherwnd[0]); |
| 2436 | | SetControlFontStyle(info->otherwnd[0],&style); |
| 2437 | | SetControlCommandID(info->otherwnd[0], OSX_POPUP_COMMAND); |
| 2438 | | |
| 2439 | | if ( CreateNewMenu( 0, 0, &popupmenu ) != noErr ) |
| 2440 | | { |
| 2441 | | mame_printf_error( "Could not create menu\n" ); |
| 2442 | | exit( -1 ); |
| 2443 | | } |
| 2444 | | |
| 2445 | | { |
| 2446 | | EventTypeSpec spec = { kEventClassCommand, kEventCommandProcess }; |
| 2447 | | |
| 2448 | | InstallEventHandler( GetMenuEventTarget( popupmenu ), NewEventHandlerUPP(debug_window_proc), 1, &spec, info, NULL ); |
| 2449 | | } |
| 2450 | | |
| 2451 | | // populate the combobox |
| 2452 | | for (subview = disasm_view_get_subview_list(info->view[0].view); subview != NULL; subview = subview->next) |
| 2453 | | { |
| 2454 | | CFStringRef cfName; |
| 2455 | | char name[100]; |
| 2456 | | UInt16 item; |
| 2457 | | |
| 2458 | | snprintf(name, ARRAY_LENGTH(name), "%s", subview->name); |
| 2459 | | |
| 2460 | | cfName = CFStringCreateWithCString( NULL, name, CFStringGetSystemEncoding() ); |
| 2461 | | AppendMenuItemTextWithCFString( popupmenu, cfName, 0, 0, &item ); |
| 2462 | | CFRelease( cfName ); |
| 2463 | | |
| 2464 | | if (cursel == 0 && subview->space->cpu == curcpu) |
| 2465 | | cursel = item; |
| 2466 | | } |
| 2467 | | disasm_view_set_subview(info->view[0].view, cursel-1); |
| 2468 | | |
| 2469 | | SetControlData(info->otherwnd[0], kControlEntireControl, kControlPopupButtonOwnedMenuRefTag, sizeof(popupmenu),&popupmenu); |
| 2470 | | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2471 | | HIViewSetMinimum(info->otherwnd[0], 1); |
| 2472 | | HIViewSetMaximum(info->otherwnd[0], CountMenuItems(popupmenu)); |
| 2473 | | HIViewSetValue(info->otherwnd[0],cursel); |
| 2474 | | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2475 | | SetControl32BitMinimum(info->otherwnd[0], 1); |
| 2476 | | SetControl32BitMaximum(info->otherwnd[0], CountMenuItems(popupmenu)); |
| 2477 | | SetControl32BitValue(info->otherwnd[0],cursel); |
| 2478 | | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2479 | | |
| 2480 | | // set the child functions |
| 2481 | | info->recompute_children = disasm_recompute_children; |
| 2482 | | info->process_string = disasm_process_string; |
| 2483 | | |
| 2484 | | // set the caption |
| 2485 | | disasm_update_caption(info); |
| 2486 | | |
| 2487 | | // recompute the children once to get the maxwidth |
| 2488 | | disasm_recompute_children(info); |
| 2489 | | |
| 2490 | | // position the window and recompute children again |
| 2491 | | bounds.top = bounds.left = 100; |
| 2492 | | bounds.right = bounds.left + info->maxwidth; |
| 2493 | | bounds.bottom = bounds.top + 200; |
| 2494 | | |
| 2495 | | SetWindowBounds(info->wnd, kWindowStructureRgn, &bounds ); |
| 2496 | | ShowWindow(info->wnd); |
| 2497 | | SelectWindow(info->wnd); |
| 2498 | | |
| 2499 | | disasm_recompute_children(info); |
| 2500 | | |
| 2501 | | // mark the edit box as the default focus and set it |
| 2502 | | info->focuswnd = info->editwnd; |
| 2503 | | osx_SetFocus(info->editwnd); |
| 2504 | | } |
| 2505 | | |
| 2506 | | |
| 2507 | | |
| 2508 | | //============================================================ |
| 2509 | | // disasm_recompute_children |
| 2510 | | //============================================================ |
| 2511 | | |
| 2512 | | static void disasm_recompute_children(debugwin_info *info) |
| 2513 | | { |
| 2514 | | debug_view_xy totalsize = debug_view_get_total_size(info->view[0].view); |
| 2515 | | Rect parent, dasmrect, editrect, comborect, actionrect; |
| 2516 | | Rect bounds; |
| 2517 | | HIRect hibounds; |
| 2518 | | |
| 2519 | | // compute a client rect |
| 2520 | | bounds.top = bounds.left = 0; |
| 2521 | | bounds.right = totalsize.x * debug_font_width + vscroll_width + 2 * EDGE_WIDTH; |
| 2522 | | bounds.bottom = 200; |
| 2523 | | // AdjustWindowRectEx(&bounds, DEBUG_WINDOW_STYLE, FALSE, DEBUG_WINDOW_STYLE_EX); |
| 2524 | | |
| 2525 | | // clamp the min/max size |
| 2526 | | info->maxwidth = bounds.right - bounds.left; |
| 2527 | | |
| 2528 | | // get the parent's dimensions |
| 2529 | | HIViewGetBounds(info->contentView,&hibounds); |
| 2530 | | parent.top = hibounds.origin.y; |
| 2531 | | parent.bottom = hibounds.origin.y + hibounds.size.height; |
| 2532 | | parent.left = hibounds.origin.x; |
| 2533 | | parent.right = hibounds.origin.x + hibounds.size.width; |
| 2534 | | |
| 2535 | | // edit box gets half of the width |
| 2536 | | editrect.top = parent.top + EDGE_WIDTH; |
| 2537 | | editrect.bottom = editrect.top + debug_font_height + 4; |
| 2538 | | editrect.left = parent.left + EDGE_WIDTH; |
| 2539 | | editrect.right = parent.left + (parent.right - parent.left) / 2 - EDGE_WIDTH - 20 - EDGE_WIDTH; |
| 2540 | | |
| 2541 | | // action button goes right next to the edit box |
| 2542 | | actionrect.top = editrect.top - 1; |
| 2543 | | actionrect.bottom = editrect.bottom + 1; |
| 2544 | | actionrect.left = editrect.right + EDGE_WIDTH + 2; |
| 2545 | | actionrect.right = actionrect.left + 20; |
| 2546 | | |
| 2547 | | // combo box gets the other half of the width |
| 2548 | | comborect.top = editrect.top; |
| 2549 | | comborect.bottom = editrect.bottom; |
| 2550 | | comborect.left = actionrect.right + EDGE_WIDTH; |
| 2551 | | comborect.right = parent.right - EDGE_WIDTH; |
| 2552 | | |
| 2553 | | // disasm view gets the rest |
| 2554 | | dasmrect.top = editrect.bottom + 2 * EDGE_WIDTH; |
| 2555 | | dasmrect.bottom = parent.bottom - EDGE_WIDTH; |
| 2556 | | dasmrect.left = parent.left + EDGE_WIDTH; |
| 2557 | | dasmrect.right = parent.right - EDGE_WIDTH; |
| 2558 | | |
| 2559 | | // set the bounds of things |
| 2560 | | debugwin_view_set_bounds(&info->view[0], &dasmrect); |
| 2561 | | |
| 2562 | | osx_RectToHIRect( &editrect, &hibounds ); |
| 2563 | | smart_set_view_bounds(info->editwnd, &hibounds); |
| 2564 | | |
| 2565 | | osx_RectToHIRect( &comborect, &hibounds ); |
| 2566 | | smart_set_view_bounds(info->otherwnd[0], &hibounds); |
| 2567 | | |
| 2568 | | osx_RectToHIRect( &actionrect, &hibounds ); |
| 2569 | | smart_set_view_bounds(info->menuwnd, &hibounds); |
| 2570 | | } |
| 2571 | | |
| 2572 | | |
| 2573 | | |
| 2574 | | //============================================================ |
| 2575 | | // disasm_process_string |
| 2576 | | //============================================================ |
| 2577 | | |
| 2578 | | static void disasm_process_string(debugwin_info *info, const char *string) |
| 2579 | | { |
| 2580 | | // set the string to the disasm view |
| 2581 | | disasm_view_set_expression(info->view[0].view, string); |
| 2582 | | |
| 2583 | | // select everything in the edit text box |
| 2584 | | { |
| 2585 | | ControlEditTextSelectionRec sel; |
| 2586 | | |
| 2587 | | sel.selStart = 0; |
| 2588 | | sel.selEnd = strlen(string); |
| 2589 | | |
| 2590 | | SetControlData(info->editwnd, kControlEntireControl, kControlEditTextSelectionTag, sizeof( sel ), &sel ); |
| 2591 | | } |
| 2592 | | |
| 2593 | | // update the default string to match |
| 2594 | | strncpy(info->edit_defstr, string, sizeof(info->edit_defstr) - 1); |
| 2595 | | } |
| 2596 | | |
| 2597 | | |
| 2598 | | |
| 2599 | | //============================================================ |
| 2600 | | // disasm_update_checkmarks |
| 2601 | | //============================================================ |
| 2602 | | |
| 2603 | | static void disasm_update_checkmarks(debugwin_info *info) |
| 2604 | | { |
| 2605 | | if ( info->contextualMenu != NULL ) |
| 2606 | | { |
| 2607 | | MenuItemIndex menuindex; |
| 2608 | | |
| 2609 | | disasm_right_column rightcol = disasm_view_get_right_column(info->view[0].view); |
| 2610 | | |
| 2611 | | GetIndMenuItemWithCommandID( info->contextualMenu, ID_SHOW_RAW, 1, NULL, &menuindex ); |
| 2612 | | CheckMenuItem(info->contextualMenu, menuindex, (rightcol == DASM_RIGHTCOL_RAW)); |
| 2613 | | GetIndMenuItemWithCommandID( info->contextualMenu, ID_SHOW_ENCRYPTED, 1, NULL, &menuindex ); |
| 2614 | | CheckMenuItem(info->contextualMenu, menuindex, (rightcol == DASM_RIGHTCOL_ENCRYPTED)); |
| 2615 | | GetIndMenuItemWithCommandID( info->contextualMenu, ID_SHOW_COMMENTS, 1, NULL, &menuindex ); |
| 2616 | | CheckMenuItem(info->contextualMenu, menuindex, (rightcol == DASM_RIGHTCOL_COMMENTS)); |
| 2617 | | } |
| 2618 | | } |
| 2619 | | |
| 2620 | | |
| 2621 | | |
| 2622 | | //============================================================ |
| 2623 | | // disasm_handle_command |
| 2624 | | //============================================================ |
| 2625 | | |
| 2626 | | static int disasm_handle_command(debugwin_info *info, EventRef inEvent) |
| 2627 | | { |
| 2628 | | HICommand cmd; |
| 2629 | | char command[64]; |
| 2630 | | |
| 2631 | | if ( GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof( cmd ), NULL, &cmd ) != noErr ) |
| 2632 | | return global_handle_command(info, inEvent); |
| 2633 | | |
| 2634 | | switch( cmd.commandID ) |
| 2635 | | { |
| 2636 | | case OSX_POPUP_COMMAND: |
| 2637 | | { |
| 2638 | | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2639 | | int sel = HIViewGetValue(info->otherwnd[0]); |
| 2640 | | #else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2641 | | int sel = GetControl32BitValue(info->otherwnd[0]); |
| 2642 | | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
| 2643 | | |
| 2644 | | if ( sel > 0 ) |
| 2645 | | { |
| 2646 | | disasm_view_set_subview(info->view[0].view, sel-1); |
| 2647 | | disasm_update_caption(info); |
| 2648 | | |
| 2649 | | // reset the focus |
| 2650 | | osx_SetFocus(info->focuswnd); |
| 2651 | | return 1; |
| 2652 | | } |
| 2653 | | } |
| 2654 | | break; |
| 2655 | | |
| 2656 | | case ID_SHOW_RAW: |
| 2657 | | disasm_view_set_right_column(info->view[0].view, DASM_RIGHTCOL_RAW); |
| 2658 | | (*info->recompute_children)(info); |
| 2659 | | return 1; |
| 2660 | | |
| 2661 | | case ID_SHOW_ENCRYPTED: |
| 2662 | | disasm_view_set_right_column(info->view[0].view, DASM_RIGHTCOL_ENCRYPTED); |
| 2663 | | (*info->recompute_children)(info); |
| 2664 | | return 1; |
| 2665 | | |
| 2666 | | case ID_SHOW_COMMENTS: |
| 2667 | | disasm_view_set_right_column(info->view[0].view, DASM_RIGHTCOL_COMMENTS); |
| 2668 | | (*info->recompute_children)(info); |
| 2669 | | return 1; |
| 2670 | | |
| 2671 | | case ID_RUN_TO_CURSOR: |
| 2672 | | if (debug_view_get_cursor_visible(info->view[0].view)) |
| 2673 | | { |
| 2674 | | const address_space *space = disasm_view_get_current_subview(info->view[0].view)->space; |
| 2675 | | if (debug_cpu_get_visible_cpu(info->machine) == space->cpu) |
| 2676 | | { |
| 2677 | | offs_t address = memory_byte_to_address(space, disasm_view_get_selected_address(info->view[0].view)); |
| 2678 | | sprintf(command, "go %X", address); |
| 2679 | | debug_console_execute_command(info->machine, command, 1); |
| 2680 | | } |
| 2681 | | } |
| 2682 | | return 1; |
| 2683 | | |
| 2684 | | case ID_TOGGLE_BREAKPOINT: |
| 2685 | | if (debug_view_get_cursor_visible(info->view[0].view)) |
| 2686 | | { |
| 2687 | | const address_space *space = disasm_view_get_current_subview(info->view[0].view)->space; |
| 2688 | | if (debug_cpu_get_visible_cpu(info->machine) == space->cpu) |
| 2689 | | { |
| 2690 | | offs_t address = memory_byte_to_address(space, disasm_view_get_selected_address(info->view[0].view)); |
| 2691 | | cpu_debug_data *cpuinfo = cpu_get_debug_data(space->cpu); |
| 2692 | | debug_cpu_breakpoint *bp; |
| 2693 | | INT32 bpindex = -1; |
| 2694 | | |
| 2695 | | /* first find an existing breakpoint at this address */ |
| 2696 | | for (bp = cpuinfo->bplist; bp != NULL; bp = bp->next) |
| 2697 | | if (address == bp->address) |
| 2698 | | { |
| 2699 | | bpindex = bp->index; |
| 2700 | | break; |
| 2701 | | } |
| 2702 | | |
| 2703 | | /* if it doesn't exist, add a new one */ |
| 2704 | | if (bpindex == -1) |
| 2705 | | sprintf(command, "bpset %X", address); |
| 2706 | | else |
| 2707 | | sprintf(command, "bpclear %X", bpindex); |
| 2708 | | debug_console_execute_command(info->machine, command, 1); |
| 2709 | | } |
| 2710 | | } |
| 2711 | | return 1; |
| 2712 | | } |
| 2713 | | |
| 2714 | | return global_handle_command(info, inEvent); |
| 2715 | | } |
| 2716 | | |
| 2717 | | //============================================================ |
| 2718 | | // disasm_handle_key |
| 2719 | | //============================================================ |
| 2720 | | |
| 2721 | | static int disasm_handle_key(debugwin_info *info, EventRef inEvent) |
| 2722 | | { |
| 2723 | | EventRecord event; |
| 2724 | | char command[64]; |
| 2725 | | |
| 2726 | | if ( ConvertEventRefToEventRecord( inEvent, &event ) ) |
| 2727 | | { |
| 2728 | | if ( event.modifiers & cmdKey ) |
| 2729 | | { |
| 2730 | | switch( event.message & charCodeMask ) |
| 2731 | | { |
| 2732 | | case 'r': |
| 2733 | | case 'R': |
| 2734 | | disasm_view_set_right_column(info->view[0].view, DASM_RIGHTCOL_RAW); |
| 2735 | | (*info->recompute_children)(info); |
| 2736 | | return 1; |
| 2737 | | |
| 2738 | | case 'e': |
| 2739 | | case 'E': |
| 2740 | | disasm_view_set_right_column(info->view[0].view, DASM_RIGHTCOL_ENCRYPTED); |
| 2741 | | (*info->recompute_children)(info); |
| 2742 | | return 1; |
| 2743 | | |
| 2744 | | case 'n': |
| 2745 | | case 'N': |
| 2746 | | disasm_view_set_right_column(info->view[0].view, DASM_RIGHTCOL_COMMENTS); |
| 2747 | | (*info->recompute_children)(info); |
| 2748 | | return 1; |
| 2749 | | } |
| 2750 | | } |
| 2751 | | |
| 2752 | | switch( ( ( event.message & keyCodeMask ) >> 8 ) & 0xFF ) |
| 2753 | | { |
| 2754 | | case KEY_F4: |
| 2755 | | if (debug_view_get_cursor_visible(info->view[0].view)) |
| 2756 | | { |
| 2757 | | const address_space *space = disasm_view_get_current_subview(info->view[0].view)->space; |
| 2758 | | if (debug_cpu_get_visible_cpu(info->machine) == space->cpu) |
| 2759 | | { |
| 2760 | | offs_t address = memory_byte_to_address(space, disasm_view_get_selected_address(info->view[0].view)); |
| 2761 | | sprintf(command, "go %X", address); |
| 2762 | | debug_console_execute_command(info->machine, command, 1); |
| 2763 | | } |
| 2764 | | } |
| 2765 | | return 1; |
| 2766 | | |
| 2767 | | case KEY_F9: |
| 2768 | | if (debug_view_get_cursor_visible(info->view[0].view)) |
| 2769 | | { |
| 2770 | | const address_space *space = disasm_view_get_current_subview(info->view[0].view)->space; |
| 2771 | | if (debug_cpu_get_visible_cpu(info->machine) == space->cpu) |
| 2772 | | { |
| 2773 | | offs_t address = memory_byte_to_address(space, disasm_view_get_selected_address(info->view[0].view)); |
| 2774 | | cpu_debug_data *cpuinfo = cpu_get_debug_data(space->cpu); |
| 2775 | | debug_cpu_breakpoint *bp; |
| 2776 | | INT32 bpindex = -1; |
| 2777 | | |
| 2778 | | /* first find an existing breakpoint at this address */ |
| 2779 | | for (bp = cpuinfo->bplist; bp != NULL; bp = bp->next) |
| 2780 | | if (address == bp->address) |
| 2781 | | { |
| 2782 | | bpindex = bp->index; |
| 2783 | | break; |
| 2784 | | } |
| 2785 | | |
| 2786 | | /* if it doesn't exist, add a new one */ |
| 2787 | | if (bpindex == -1) |
| 2788 | | sprintf(command, "bpset %X", address); |
| 2789 | | else |
| 2790 | | sprintf(command, "bpclear %X", bpindex); |
| 2791 | | debug_console_execute_command(info->machine, command, 1); |
| 2792 | | } |
| 2793 | | } |
| 2794 | | return 1; |
| 2795 | | } |
| 2796 | | |
| 2797 | | if ( ( event.message & charCodeMask ) == kReturnCharCode ) |
| 2798 | | { |
| 2799 | | if (debug_view_get_cursor_visible(info->view[0].view)) |
| 2800 | | { |
| 2801 | | debug_cpu_single_step(info->machine, 1); |
| 2802 | | return 1; |
| 2803 | | } |
| 2804 | | } |
| 2805 | | } |
| 2806 | | |
| 2807 | | return global_handle_key(info, inEvent); |
| 2808 | | } |
| 2809 | | |
| 2810 | | |
| 2811 | | |
| 2812 | | //============================================================ |
| 2813 | | // disasm_update_caption |
| 2814 | | //============================================================ |
| 2815 | | |
| 2816 | | static void disasm_update_caption(debugwin_info *info) |
| 2817 | | { |
| 2818 | | const disasm_subview_item *subview = disasm_view_get_current_subview(info->view[0].view); |
| 2819 | | CFStringRef cftitle; |
| 2820 | | char title[100]; |
| 2821 | | |
| 2822 | | // update the caption |
| 2823 | | snprintf(title, ARRAY_LENGTH(title), "Disassembly: %s", subview->name); |
| 2824 | | |
| 2825 | | cftitle = CFStringCreateWithCString( NULL, title, CFStringGetSystemEncoding() ); |
| 2826 | | |
| 2827 | | if ( cftitle ) |
| 2828 | | { |
| 2829 | | SetWindowTitleWithCFString( info->wnd, cftitle); |
| 2830 | | CFRelease( cftitle ); |
| 2831 | | } |
| 2832 | | } |
| 2833 | | |
| 2834 | | |
| 2835 | | |
| 2836 | | //============================================================ |
| 2837 | | // console_create_window |
| 2838 | | //============================================================ |
| 2839 | | |
| 2840 | | void console_create_window(running_machine *machine) |
| 2841 | | { |
| 2842 | | const registers_subview_item *regsubview; |
| 2843 | | const disasm_subview_item *dasmsubview; |
| 2844 | | debugwin_info *info; |
| 2845 | | int bestwidth, bestheight; |
| 2846 | | Rect bounds, work_bounds; |
| 2847 | | MenuRef optionsmenu, popupmenu; |
| 2848 | | ControlFontStyleRec style; |
| 2849 | | Str255 fontName; |
| 2850 | | CGDirectDisplayID mainID = CGMainDisplayID(); |
| 2851 | | MenuItemIndex menuIndex; |
| 2852 | | ControlButtonContentInfo content; |
| 2853 | | |
| 2854 | | // create the window |
| 2855 | | info = debug_window_create(machine, "Debug", NULL); |
| 2856 | | if (info == NULL) |
| 2857 | | return; |
| 2858 | | main_console = info; |
| 2859 | | console_set_cpu(machine->firstcpu); |
| 2860 | | |
| 2861 | | // create the views |
| 2862 | | if (!debugwin_view_create(info, 0, DVT_DISASSEMBLY)) |
| 2863 | | goto cleanup; |
| 2864 | | if (!debugwin_view_create(info, 1, DVT_REGISTERS)) |
| 2865 | | goto cleanup; |
| 2866 | | if (!debugwin_view_create(info, 2, DVT_CONSOLE)) |
| 2867 | | goto cleanup; |
| 2868 | | |
| 2869 | | // create the options menu |
| 2870 | | if ( CreateNewMenu( 0, 0, &optionsmenu ) != noErr ) |
| 2871 | | { |
| 2872 | | mame_printf_error( "Could not create menu\n" ); |
| 2873 | | exit( -1 ); |
| 2874 | | } |
| 2875 | | |
| 2876 | | popupmenu = create_standard_menubar(); |
| 2877 | | |
| 2878 | | if ( popupmenu ) |
| 2879 | | { |
| 2880 | | MenuItemIndex menuindex; |
| 2881 | | AppendMenuItemTextWithCFString(optionsmenu, CFSTR("Main Options"), 0, 0, &menuindex); |
| 2882 | | SetMenuItemHierarchicalMenu(optionsmenu, menuindex, popupmenu); |
| 2883 | | } |
| 2884 | | |
| 2885 | | { |
| 2886 | | EventTypeSpec spec = { kEventClassCommand, kEventCommandProcess }; |
| 2887 | | |
| 2888 | | InstallEventHandler( GetMenuEventTarget( popupmenu ), NewEventHandlerUPP(debug_window_proc), 1, &spec, info, NULL ); |
| 2889 | | } |
| 2890 | | |
| 2891 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Set breakpoint at cursor"), 0, ID_TOGGLE_BREAKPOINT, &menuIndex ); |
| 2892 | | SetMenuItemKeyGlyph(optionsmenu, menuIndex, kMenuF9Glyph); SetMenuItemModifiers(optionsmenu, menuIndex, kMenuNoCommandModifier); |
| 2893 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Run to cursor"), 0, ID_RUN_TO_CURSOR, &menuIndex ); |
| 2894 | | SetMenuItemKeyGlyph(optionsmenu, menuIndex, kMenuF4Glyph); SetMenuItemModifiers(optionsmenu, menuIndex, kMenuNoCommandModifier); |
| 2895 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("-"), kMenuItemAttrSeparator, 0, NULL ); |
| 2896 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Raw opcodes"), 0, ID_SHOW_RAW, &menuIndex ); |
| 2897 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, 'R'); |
| 2898 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Encrypted opcodes"), 0, ID_SHOW_ENCRYPTED, &menuIndex ); |
| 2899 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, 'E'); |
| 2900 | | AppendMenuItemTextWithCFString( optionsmenu, CFSTR("Comments"), 0, ID_SHOW_COMMENTS, &menuIndex ); |
| 2901 | | SetMenuItemCommandKey(optionsmenu, menuIndex, FALSE, 'C'); |
| 2902 | | info->contextualMenu = optionsmenu; |
| 2903 | | disasm_update_checkmarks(info); |
| 2904 | | |
| 2905 | | // set the handlers |
| 2906 | | info->handle_command = disasm_handle_command; |
| 2907 | | info->handle_key = disasm_handle_key; |
| 2908 | | |
| 2909 | | // lock us to the bottom of the console by default |
| 2910 | | info->view[2].is_textbuf = TRUE; |
| 2911 | | |
| 2912 | | // set up the disassembly view to track the current pc |
| 2913 | | disasm_view_set_expression(info->view[0].view, "curpc"); |
| 2914 | | |
| 2915 | | fontName[0] = strlen( OSX_DEBUGGER_FONT_NAME ); |
| 2916 | | strcpy( (char*)&fontName[1], OSX_DEBUGGER_FONT_NAME ); |
| 2917 | | |
| 2918 | | style.flags = kControlUseFontMask | kControlUseSizeMask; |
| 2919 | | style.font = ATSFontFamilyFindFromQuickDrawName(fontName); |
| 2920 | | style.size = OSX_DEBUGGER_FONT_SIZE; |
| 2921 | | |
| 2922 | | // create an edit box and override its key handling |
| 2923 | | bounds.top = bounds.left = 0; |
| 2924 | | bounds.bottom = bounds.right = 100; |
| 2925 | | CreateEditUnicodeTextControl(info->wnd, &bounds, CFSTR("0"), false, NULL, &info->editwnd); |
| 2926 | | SetControlFontStyle(info->editwnd,&style); |
| 2927 | | InstallEventHandler( GetControlEventTarget(info->editwnd), NewEventHandlerUPP(debugwin_edit_proc), sizeof( debug_keyboard_events ) / sizeof( EventTypeSpec ), debug_keyboard_events, info, NULL ); |
| 2928 | | |
| 2929 | | // create popup menu and attach the contextual menu |
| 2930 | | content.contentType = kControlContentTextOnly; |
| 2931 | | bounds.top = bounds.left = 0; |
| 2932 | | bounds.bottom = bounds.right = 100; |
| 2933 | | CreateBevelButtonControl(info->wnd, &bounds, CFSTR(""), kControlBevelButtonSmallBevel, kControlBehaviorPushbutton, &content, 1, kControlBehaviorMultiValueMenu, kControlBevelButtonMenuOnBottom, &info->menuwnd ); |
| 2934 | | SetControlData(info->menuwnd, kControlEntireControl, kControlBevelButtonMenuHandleTag, sizeof(optionsmenu), &optionsmenu); |
| 2935 | | |
| 2936 | | // set the child functions |
| 2937 | | info->recompute_children = console_recompute_children; |
| 2938 | | info->process_string = console_process_string; |
| 2939 | | |
| 2940 | | // loop over all CPUs and compute the sizes |
| 2941 | | info->minwidth = 0; |
| 2942 | | info->maxwidth = 0; |
| 2943 | | for (dasmsubview = disasm_view_get_subview_list(info->view[0].view); dasmsubview != NULL; dasmsubview = dasmsubview->next) |
| 2944 | | for (regsubview = registers_view_get_subview_list(info->view[1].view); regsubview != NULL; regsubview = regsubview->next) |
| 2945 | | if (dasmsubview->space->cpu == regsubview->device) |
| 2946 | | { |
| 2947 | | UINT32 regchars, dischars, conchars; |
| 2948 | | UINT32 minwidth, maxwidth; |
| 2949 | | |
| 2950 | | // point all views to the new CPU number |
| 2951 | | disasm_view_set_subview(info->view[0].view, dasmsubview->index); |
| 2952 | | registers_view_set_subview(info->view[1].view, regsubview->index); |
| 2953 | | |
| 2954 | | // get the total width of all three children |
| 2955 | | dischars = debug_view_get_total_size(info->view[0].view).x; |
| 2956 | | regchars = debug_view_get_total_size(info->view[1].view).x; |
| 2957 | | conchars = debug_view_get_total_size(info->view[2].view).x; |
| 2958 | | |
| 2959 | | // compute the preferred width |
| 2960 | | minwidth = EDGE_WIDTH + regchars * debug_font_width + vscroll_width + 2 * EDGE_WIDTH + 100 + EDGE_WIDTH; |
| 2961 | | maxwidth = EDGE_WIDTH + regchars * debug_font_width + vscroll_width + 2 * EDGE_WIDTH + ((dischars > conchars) ? dischars : conchars) * debug_font_width + vscroll_width + EDGE_WIDTH; |
| 2962 | | if (minwidth > info->minwidth) |
| 2963 | | info->minwidth = minwidth; |
| 2964 | | if (maxwidth > info->maxwidth) |
| 2965 | | info->maxwidth = maxwidth; |
| 2966 | | } |
| 2967 | | |
| 2968 | | // get the work bounds |
| 2969 | | { |
| 2970 | | #if OSX_LEOPARD |
| 2971 | | HIRect mainBounds; |
| 2972 | | HIWindowGetAvailablePositioningBounds( mainID, kHICoordSpaceScreenPixel, &mainBounds ); |
| 2973 | | work_bounds.left = mainBounds.origin.x; |
| 2974 | | work_bounds.top = mainBounds.origin.y; |
| 2975 | | work_bounds.right = mainBounds.origin.x + mainBounds.size.width; |
| 2976 | | work_bounds.bottom = mainBounds.origin.y + mainBounds.size.height; |
| 2977 | | #else |
| 2978 | | GDHandle mainDevice; |
| 2979 | | DMGetGDeviceByDisplayID((DisplayIDType)mainID, &mainDevice, TRUE); |
| 2980 | | GetAvailableWindowPositioningBounds(mainDevice, &work_bounds); |
| 2981 | | #endif |
| 2982 | | } |
| 2983 | | |
| 2984 | | // adjust the min/max sizes for the window style |
| 2985 | | bounds.top = bounds.left = 0; |
| 2986 | | bounds.right = bounds.bottom = info->minwidth; |
| 2987 | | // AdjustWindowRectEx(&bounds, DEBUG_WINDOW_STYLE, FALSE, DEBUG_WINDOW_STYLE_EX); |
| 2988 | | info->minwidth = bounds.right - bounds.left; |
| 2989 | | |
| 2990 | | bounds.top = bounds.left = 0; |
| 2991 | | bounds.right = bounds.bottom = info->maxwidth; |
| 2992 | | // AdjustWindowRectEx(&bounds, DEBUG_WINDOW_STYLE, FALSE, DEBUG_WINDOW_STYLE_EX); |
| 2993 | | info->maxwidth = bounds.right - bounds.left; |
| 2994 | | |
| 2995 | | // position the window at the bottom-right |
| 2996 | | bestwidth = (info->maxwidth < (work_bounds.right - work_bounds.left)) ? info->maxwidth : (work_bounds.right - work_bounds.left); |
| 2997 | | bestheight = (500 < (work_bounds.bottom - work_bounds.top)) ? 500 : (work_bounds.bottom - work_bounds.top); |
| 2998 | | |
| 2999 | | bounds.left = work_bounds.right - bestwidth; |
| 3000 | | bounds.top = work_bounds.bottom - bestheight; |
| 3001 | | bounds.right = bounds.left + bestwidth; |
| 3002 | | bounds.bottom = bounds.top + bestheight; |
| 3003 | | |
| 3004 | | SetWindowBounds(info->wnd, kWindowStructureRgn, &bounds ); |
| 3005 | | |
| 3006 | | // recompute the children |
| 3007 | | console_recompute_children(info); |
| 3008 | | |
| 3009 | | // mark the edit box as the default focus and set it |
| 3010 | | info->focuswnd = info->editwnd; |
| 3011 | | osx_SetFocus(info->editwnd); |
| 3012 | | return; |
| 3013 | | |
| 3014 | | cleanup: |
| 3015 | | if (info->view[2].view) |
| 3016 | | debug_view_free(info->view[2].view); |
| 3017 | | if (info->view[1].view) |
| 3018 | | debug_view_free(info->view[1].view); |
| 3019 | | if (info->view[0].view) |
| 3020 | | debug_view_free(info->view[0].view); |
| 3021 | | } |
| 3022 | | |
| 3023 | | |
| 3024 | | |
| 3025 | | //============================================================ |
| 3026 | | // console_recompute_children |
| 3027 | | //============================================================ |
| 3028 | | |
| 3029 | | static void console_recompute_children(debugwin_info *info) |
| 3030 | | { |
| 3031 | | Rect parent, regrect, disrect, conrect, editrect, actionrect; |
| 3032 | | UINT32 regchars, dischars, conchars; |
| 3033 | | HIRect hibounds; |
| 3034 | | |
| 3035 | | // get the parent's dimensions |
| 3036 | | HIViewGetBounds(info->contentView,&hibounds); |
| 3037 | | parent.top = hibounds.origin.y; |
| 3038 | | parent.bottom = hibounds.origin.y + hibounds.size.height; |
| 3039 | | parent.left = hibounds.origin.x; |
| 3040 | | parent.right = hibounds.origin.x + hibounds.size.width; |
| 3041 | | |
| 3042 | | // get the total width of all three children |
| 3043 | | dischars = debug_view_get_total_size(info->view[0].view).x; |
| 3044 | | regchars = debug_view_get_total_size(info->view[1].view).x; |
| 3045 | | conchars = debug_view_get_total_size(info->view[2].view).x; |
| 3046 | | |
| 3047 | | // registers always get their desired width, and span the entire height |
| 3048 | | regrect.top = parent.top + EDGE_WIDTH; |
| 3049 | | regrect.bottom = parent.bottom - EDGE_WIDTH; |
| 3050 | | regrect.left = parent.left + EDGE_WIDTH; |
| 3051 | | regrect.right = regrect.left + debug_font_width * regchars + vscroll_width; |
| 3052 | | |
| 3053 | | // If there is no room for the full register width, force them to half the window |
| 3054 | | if( regrect.right > parent.right ) |
| 3055 | | regrect.right = parent.right / 2; |
| 3056 | | |
| 3057 | | // edit box goes at the bottom of the remaining area (minus a little for a popup menu) |
| 3058 | | editrect.bottom = parent.bottom - EDGE_WIDTH; |
| 3059 | | editrect.top = editrect.bottom - debug_font_height - 4; |
| 3060 | | editrect.left = regrect.right + EDGE_WIDTH * 2; |
| 3061 | | editrect.right = parent.right - EDGE_WIDTH - 35; |
| 3062 | | |
| 3063 | | // Popup button goes to the right of the edit box |
| 3064 | | actionrect.top = editrect.top-1; |
| 3065 | | actionrect.bottom = editrect.bottom+1; |
| 3066 | | actionrect.left = editrect.right + EDGE_WIDTH; |
| 3067 | | actionrect.right = parent.right - 16; |
| 3068 | | |
| 3069 | | // console and disassembly split the difference |
| 3070 | | disrect.top = parent.top + EDGE_WIDTH; |
| 3071 | | disrect.bottom = (editrect.top - parent.top) / 2 - EDGE_WIDTH; |
| 3072 | | disrect.left = regrect.right + EDGE_WIDTH * 2; |
| 3073 | | disrect.right = parent.right - EDGE_WIDTH; |
| 3074 | | |
| 3075 | | conrect.top = disrect.bottom + EDGE_WIDTH * 2; |
| 3076 | | conrect.bottom = editrect.top - EDGE_WIDTH; |
| 3077 | | conrect.left = regrect.right + EDGE_WIDTH * 2; |
| 3078 | | conrect.right = parent.right - EDGE_WIDTH; |
| 3079 | | |
| 3080 | | // set the bounds of things |
| 3081 | | debugwin_view_set_bounds(&info->view[0], &disrect); |
| 3082 | | debugwin_view_set_bounds(&info->view[1], ®rect); |
| 3083 | | debugwin_view_set_bounds(&info->view[2], &conrect); |
| 3084 | | |
| 3085 | | osx_RectToHIRect( &editrect, &hibounds ); |
| 3086 | | smart_set_view_bounds(info->editwnd, &hibounds); |
| 3087 | | |
| 3088 | | osx_RectToHIRect( &actionrect, &hibounds ); |
| 3089 | | smart_set_view_bounds(info->menuwnd, &hibounds); |
| 3090 | | } |
| 3091 | | |
| 3092 | | |
| 3093 | | |
| 3094 | | //============================================================ |
| 3095 | | // console_process_string |
| 3096 | | //============================================================ |
| 3097 | | |
| 3098 | | static void console_process_string(debugwin_info *info, const char *string) |
| 3099 | | { |
| 3100 | | char buffer = 0; |
| 3101 | | |
| 3102 | | // an empty string is a single step |
| 3103 | | if (string[0] == 0) |
| 3104 | | debug_cpu_single_step(info->machine, 1); |
| 3105 | | |
| 3106 | | // otherwise, just process the command |
| 3107 | | else |
| 3108 | | debug_console_execute_command(info->machine, string, 1); |
| 3109 | | |
| 3110 | | // clear the edit text box |
| 3111 | | SetControlData(info->editwnd, kControlEntireControl, kControlEditTextTextTag, 0, &buffer); |
| 3112 | | } |
| 3113 | | |
| 3114 | | |
| 3115 | | |
| 3116 | | //============================================================ |
| 3117 | | // console_set_cpu |
| 3118 | | //============================================================ |
| 3119 | | |
| 3120 | | static void console_set_cpu(const device_config *device) |
| 3121 | | { |
| 3122 | | const registers_subview_item *regsubitem = NULL; |
| 3123 | | const disasm_subview_item *dasmsubitem; |
| 3124 | | char title[256]; |
| 3125 | | CFStringRef cftitle; |
| 3126 | | |
| 3127 | | // first set all the views to the new cpu number |
| 3128 | | if (main_console->view[0].view != NULL) |
| 3129 | | for (dasmsubitem = disasm_view_get_subview_list(main_console->view[0].view); dasmsubitem != NULL; dasmsubitem = dasmsubitem->next) |
| 3130 | | if (dasmsubitem->space->cpu == device) |
| 3131 | | { |
| 3132 | | disasm_view_set_subview(main_console->view[0].view, dasmsubitem->index); |
| 3133 | | break; |
| 3134 | | } |
| 3135 | | if (main_console->view[1].view != NULL) |
| 3136 | | for (regsubitem = registers_view_get_subview_list(main_console->view[1].view); regsubitem != NULL; regsubitem = regsubitem->next) |
| 3137 | | if (regsubitem->device == device) |
| 3138 | | { |
| 3139 | | registers_view_set_subview(main_console->view[1].view, regsubitem->index); |
| 3140 | | break; |
| 3141 | | } |
| 3142 | | |
| 3143 | | // then update the caption |
| 3144 | | if (regsubitem != NULL) |
| 3145 | | { |
| 3146 | | snprintf(title, ARRAY_LENGTH(title), "Debug: %s - %s", device->machine->gamedrv->name, regsubitem->name); |
| 3147 | | |
| 3148 | | cftitle = CFStringCreateWithCString( NULL, title, CFStringGetSystemEncoding() ); |
| 3149 | | |
| 3150 | | if ( cftitle ) |
| 3151 | | { |
| 3152 | | SetWindowTitleWithCFString( main_console->wnd, cftitle); |
| 3153 | | CFRelease( cftitle ); |
| 3154 | | } |
| 3155 | | } |
| 3156 | | } |
| 3157 | | |
| 3158 | | |
| 3159 | | |
| 3160 | | //============================================================ |
| 3161 | | // create_standard_menubar |
| 3162 | | //============================================================ |
| 3163 | | |
| 3164 | | static MenuRef create_standard_menubar(void) |
| 3165 | | { |
| 3166 | | MenuRef debugmenu; |
| 3167 | | MenuItemIndex menuIndex; |
| 3168 | | |
| 3169 | | // create the debug menu |
| 3170 | | if ( CreateNewMenu( 0, 0, &debugmenu ) != noErr ) |
| 3171 | | { |
| 3172 | | return NULL; |
| 3173 | | } |
| 3174 | | |
| 3175 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("New Memory Window"), 0, ID_NEW_MEMORY_WND, &menuIndex ); |
| 3176 | | SetMenuItemCommandKey(debugmenu, menuIndex, FALSE, 'M'); |
| 3177 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("New Disassembly Window"), 0, ID_NEW_DISASM_WND, &menuIndex ); |
| 3178 | | SetMenuItemCommandKey(debugmenu, menuIndex, FALSE, 'D'); |
| 3179 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("New Error Log Window"), 0, ID_NEW_LOG_WND, &menuIndex ); |
| 3180 | | SetMenuItemCommandKey(debugmenu, menuIndex, FALSE, 'L'); |
| 3181 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("-"), kMenuItemAttrSeparator, 0, NULL ); |
| 3182 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("Run"), 0, ID_RUN, &menuIndex ); |
| 3183 | | SetMenuItemKeyGlyph(debugmenu, menuIndex, kMenuF5Glyph); SetMenuItemModifiers(debugmenu, menuIndex, kMenuNoCommandModifier); |
| 3184 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("Run and Hide Debugger"), 0, ID_RUN_AND_HIDE, &menuIndex ); |
| 3185 | | SetMenuItemKeyGlyph(debugmenu, menuIndex, kMenuF12Glyph); SetMenuItemModifiers(debugmenu, menuIndex, kMenuNoCommandModifier); |
| 3186 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("Run to Next CPU"), 0, ID_NEXT_CPU, &menuIndex ); |
| 3187 | | SetMenuItemKeyGlyph(debugmenu, menuIndex, kMenuF6Glyph); SetMenuItemModifiers(debugmenu, menuIndex, kMenuNoCommandModifier); |
| 3188 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("Run until Next Interrupt on This CPU"), 0, ID_RUN_IRQ, &menuIndex ); |
| 3189 | | SetMenuItemKeyGlyph(debugmenu, menuIndex, kMenuF7Glyph); SetMenuItemModifiers(debugmenu, menuIndex, kMenuNoCommandModifier); |
| 3190 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("Run until Next VBLANK"), 0, ID_RUN_VBLANK, &menuIndex ); |
| 3191 | | SetMenuItemKeyGlyph(debugmenu, menuIndex, kMenuF8Glyph); SetMenuItemModifiers(debugmenu, menuIndex, kMenuNoCommandModifier); |
| 3192 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("-"), kMenuItemAttrSeparator, 0, NULL ); |
| 3193 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("Step Into"), 0, ID_STEP, &menuIndex ); |
| 3194 | | SetMenuItemKeyGlyph(debugmenu, menuIndex, kMenuF11Glyph); SetMenuItemModifiers(debugmenu, menuIndex, kMenuNoCommandModifier); |
| 3195 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("Step Over"), 0, ID_STEP_OVER, &menuIndex ); |
| 3196 | | SetMenuItemKeyGlyph(debugmenu, menuIndex, kMenuF10Glyph); SetMenuItemModifiers(debugmenu, menuIndex, kMenuNoCommandModifier); |
| 3197 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("Step Out"), 0, ID_STEP_OUT, &menuIndex ); |
| 3198 | | SetMenuItemKeyGlyph(debugmenu, menuIndex, kMenuF10Glyph); SetMenuItemModifiers(debugmenu, menuIndex, kMenuShiftModifier | kMenuNoCommandModifier); |
| 3199 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("-"), kMenuItemAttrSeparator, 0, NULL ); |
| 3200 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("Soft Reset"), 0, ID_SOFT_RESET, &menuIndex ); |
| 3201 | | SetMenuItemKeyGlyph(debugmenu, menuIndex, kMenuF3Glyph); SetMenuItemModifiers(debugmenu, menuIndex, kMenuNoCommandModifier); |
| 3202 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("Hard Reset"), 0, ID_HARD_RESET, &menuIndex ); |
| 3203 | | SetMenuItemKeyGlyph(debugmenu, menuIndex, kMenuF3Glyph); SetMenuItemModifiers(debugmenu, menuIndex, kMenuShiftModifier | kMenuNoCommandModifier); |
| 3204 | | AppendMenuItemTextWithCFString( debugmenu, CFSTR("Exit"), 0, ID_EXIT, &menuIndex ); |
| 3205 | | |
| 3206 | | return debugmenu; |
| 3207 | | } |
| 3208 | | |
| 3209 | | |
| 3210 | | |
| 3211 | | //============================================================ |
| 3212 | | // global_handle_command |
| 3213 | | //============================================================ |
| 3214 | | |
| 3215 | | static int global_handle_command(debugwin_info *info, EventRef inEvent) |
| 3216 | | { |
| 3217 | | HICommand cmd; |
| 3218 | | |
| 3219 | | if ( GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof( cmd ), NULL, &cmd ) != noErr ) |
| 3220 | | return 0; |
| 3221 | | |
| 3222 | | switch( cmd.commandID ) |
| 3223 | | { |
| 3224 | | case ID_NEW_MEMORY_WND: |
| 3225 | | memory_create_window(info->machine); |
| 3226 | | return 1; |
| 3227 | | |
| 3228 | | case ID_NEW_DISASM_WND: |
| 3229 | | disasm_create_window(info->machine); |
| 3230 | | return 1; |
| 3231 | | |
| 3232 | | case ID_NEW_LOG_WND: |
| 3233 | | log_create_window(info->machine); |
| 3234 | | return 1; |
| 3235 | | |
| 3236 | | case ID_RUN_AND_HIDE: |
| 3237 | | smart_show_all(FALSE); |
| 3238 | | case ID_RUN: |
| 3239 | | debug_cpu_go(info->machine, ~0); |
| 3240 | | return 1; |
| 3241 | | |
| 3242 | | case ID_NEXT_CPU: |
| 3243 | | debug_cpu_next_cpu(info->machine); |
| 3244 | | return 1; |
| 3245 | | |
| 3246 | | case ID_RUN_VBLANK: |
| 3247 | | debug_cpu_go_vblank(info->machine); |
| 3248 | | return 1; |
| 3249 | | |
| 3250 | | case ID_RUN_IRQ: |
| 3251 | | debug_cpu_go_interrupt(info->machine, -1); |
| 3252 | | return 1; |
| 3253 | | |
| 3254 | | case ID_STEP: |
| 3255 | | debug_cpu_single_step(info->machine, 1); |
| 3256 | | return 1; |
| 3257 | | |
| 3258 | | case ID_STEP_OVER: |
| 3259 | | debug_cpu_single_step_over(info->machine, 1); |
| 3260 | | return 1; |
| 3261 | | |
| 3262 | | case ID_STEP_OUT: |
| 3263 | | debug_cpu_single_step_out(info->machine); |
| 3264 | | return 1; |
| 3265 | | |
| 3266 | | case ID_HARD_RESET: |
| 3267 | | mame_schedule_hard_reset(info->machine); |
| 3268 | | return 1; |
| 3269 | | |
| 3270 | | case ID_SOFT_RESET: |
| 3271 | | mame_schedule_soft_reset(info->machine); |
| 3272 | | debug_cpu_go(info->machine, ~0); |
| 3273 | | return 1; |
| 3274 | | |
| 3275 | | case ID_EXIT: |
| 3276 | | mame_schedule_exit(info->machine); |
| 3277 | | return 1; |
| 3278 | | } |
| 3279 | | |
| 3280 | | return 0; |
| 3281 | | } |
| 3282 | | |
| 3283 | | |
| 3284 | | |
| 3285 | | //============================================================ |
| 3286 | | // global_handle_key |
| 3287 | | //============================================================ |
| 3288 | | |
| 3289 | | static int global_handle_key(debugwin_info *info, EventRef inEvent) |
| 3290 | | { |
| 3291 | | EventRecord event; |
| 3292 | | int ignoreme; |
| 3293 | | |
| 3294 | | /* ignore any keys that are received while the debug key is down */ |
| 3295 | | ignoreme = ui_input_pressed(info->machine, IPT_UI_DEBUG_BREAK); |
| 3296 | | if (ignoreme) |
| 3297 | | return 1; |
| 3298 | | |
| 3299 | | if ( ConvertEventRefToEventRecord( inEvent, &event ) ) |
| 3300 | | { |
| 3301 | | switch( ( ( event.message & keyCodeMask ) >> 8 ) & 0xFF ) |
| 3302 | | { |
| 3303 | | case KEY_F3: |
| 3304 | | if ( event.modifiers & shiftKey ) |
| 3305 | | mame_schedule_hard_reset(info->machine); |
| 3306 | | else |
| 3307 | | { |
| 3308 | | mame_schedule_soft_reset(info->machine); |
| 3309 | | debug_cpu_go(info->machine,~0); |
| 3310 | | } |
| 3311 | | return 1; |
| 3312 | | |
| 3313 | | case KEY_F4: |
| 3314 | | if ( event.modifiers & optionKey ) |
| 3315 | | mame_schedule_exit(info->machine); |
| 3316 | | return 1; |
| 3317 | | |
| 3318 | | case KEY_F5: |
| 3319 | | debug_cpu_go(info->machine, ~0); |
| 3320 | | return 1; |
| 3321 | | |
| 3322 | | case KEY_F6: |
| 3323 | | debug_cpu_next_cpu(info->machine); |
| 3324 | | return 1; |
| 3325 | | |
| 3326 | | case KEY_F7: |
| 3327 | | debug_cpu_go_interrupt(info->machine, -1); |
| 3328 | | return 1; |
| 3329 | | |
| 3330 | | case KEY_F8: |
| 3331 | | debug_cpu_go_vblank(info->machine); |
| 3332 | | return 1; |
| 3333 | | |
| 3334 | | case KEY_F10: |
| 3335 | | debug_cpu_single_step_over(info->machine, 1); |
| 3336 | | return 1; |
| 3337 | | |
| 3338 | | case KEY_F11: |
| 3339 | | if ( event.modifiers & shiftKey ) |
| 3340 | | debug_cpu_single_step_out(info->machine); |
| 3341 | | else |
| 3342 | | debug_cpu_single_step(info->machine, 1); |
| 3343 | | return 1; |
| 3344 | | |
| 3345 | | case KEY_F12: |
| 3346 | | smart_show_all(FALSE); |
| 3347 | | debug_cpu_go(info->machine, ~0); |
| 3348 | | return 1; |
| 3349 | | } |
| 3350 | | |
| 3351 | | if ( event.modifiers & cmdKey ) |
| 3352 | | { |
| 3353 | | switch( event.message & charCodeMask ) |
| 3354 | | { |
| 3355 | | case 'm': |
| 3356 | | case 'M': |
| 3357 | | memory_create_window(info->machine); |
| 3358 | | return 1; |
| 3359 | | |
| 3360 | | case 'd': |
| 3361 | | case 'D': |
| 3362 | | disasm_create_window(info->machine); |
| 3363 | | return 1; |
| 3364 | | |
| 3365 | | case 'l': |
| 3366 | | case 'L': |
| 3367 | | log_create_window(info->machine); |
| 3368 | | return 1; |
| 3369 | | } |
| 3370 | | } |
| 3371 | | } |
| 3372 | | |
| 3373 | | return 0; |
| 3374 | | } |
| 3375 | | |
| 3376 | | |
| 3377 | | //============================================================ |
| 3378 | | // smart_set_window_bounds |
| 3379 | | //============================================================ |
| 3380 | | |
| 3381 | | static void smart_set_view_bounds(HIViewRef wnd, HIRect *bounds) |
| 3382 | | { |
| 3383 | | HIRect finalRect; |
| 3384 | | |
| 3385 | | memcpy( &finalRect, bounds, sizeof( HIRect ) ); |
| 3386 | | |
| 3387 | | if ( finalRect.size.width < 0 ) |
| 3388 | | finalRect.size.width = 0; |
| 3389 | | |
| 3390 | | if ( finalRect.size.height < 0 ) |
| 3391 | | finalRect.size.height = 0; |
| 3392 | | |
| 3393 | | HIViewSetFrame( wnd, &finalRect ); |
| 3394 | | } |
| 3395 | | |
| 3396 | | |
| 3397 | | //============================================================ |
| 3398 | | // smart_show_window |
| 3399 | | //============================================================ |
| 3400 | | |
| 3401 | | static void smart_show_window(WindowRef wnd, int show) |
| 3402 | | { |
| 3403 | | int select = 0; |
| 3404 | | |
| 3405 | | if ( show && main_console && main_console->wnd && main_console->wnd == wnd && IsWindowVisible( wnd ) == false ) |
| 3406 | | { |
| 3407 | | select = 1; |
| 3408 | | } |
| 3409 | | |
| 3410 | | ShowHide(wnd, show ? TRUE : FALSE); |
| 3411 | | |
| 3412 | | if ( select ) |
| 3413 | | { |
| 3414 | | SelectWindow( wnd ); |
| 3415 | | } |
| 3416 | | } |
| 3417 | | |
| 3418 | | //============================================================ |
| 3419 | | // smart_show_view |
| 3420 | | //============================================================ |
| 3421 | | |
| 3422 | | static void smart_show_view(HIViewRef wnd, int show) |
| 3423 | | { |
| 3424 | | HIViewSetVisible(wnd, show); |
| 3425 | | } |
| 3426 | | |
| 3427 | | |
| 3428 | | //============================================================ |
| 3429 | | // smart_show_all |
| 3430 | | //============================================================ |
| 3431 | | |
| 3432 | | static void smart_show_all(int show) |
| 3433 | | { |
| 3434 | | debugwin_info *info; |
| 3435 | | for (info = window_list; info; info = info->next) |
| 3436 | | smart_show_window(info->wnd, show); |
| 3437 | | } |
src/osd/sdl/debugosx.m
| r0 | r6033 | |
| 1 | //============================================================ |
| 2 | // |
| 3 | // debugosx.m - MacOS X Cocoa debug window handling |
| 4 | // |
| 5 | // Copyright (c) 1996-2008, Nicola Salmoria and the MAME Team. |
| 6 | // Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | // |
| 8 | //============================================================ |
| 9 | |
| 10 | |
| 11 | // TODO: |
| 12 | // * Automatic scrolling for console and log views |
| 13 | // * Using alpha for disabled foreground colours doesn't really work |
| 14 | // * New windows created from auxiliary windows should inherit focus rather than pointing at current CPU |
| 15 | // * Should have map of machine to console for multiple machine support rather than a single console |
| 16 | // * Improve behaviour of expression history in memory and disassembly windows - the double tap is annoying |
| 17 | // * Keyboard shortcuts in error log windows |
| 18 | // * Don't accept keyboard input while the game is running |
| 19 | // * Interior focus rings - standard/exterior focus rings look really ugly here |
| 20 | // * Scroll views with content narrower than clipping area are flaky under Tiger - nothing I can do about this |
| 21 | |
| 22 | |
| 23 | // standard Cocoa headers |
| 24 | #include <AvailabilityMacros.h> |
| 25 | #import <Cocoa/Cocoa.h> |
| 26 | |
| 27 | // MAME headers |
| 28 | #include "driver.h" |
| 29 | #include "debug/debugvw.h" |
| 30 | #include "debug/debugcon.h" |
| 31 | #include "debug/debugcpu.h" |
| 32 | #include "debugger.h" |
| 33 | |
| 34 | // MAMEOS headers |
| 35 | #include "debugosx.h" |
| 36 | |
| 37 | |
| 38 | |
| 39 | //============================================================ |
| 40 | // LOCAL VARIABLES |
| 41 | //============================================================ |
| 42 | |
| 43 | static MAMEDebugConsole *main_console = nil; |
| 44 | |
| 45 | static BOOL waiting_for_debugger = NO; |
| 46 | |
| 47 | static NSString *const MAMEHideDebuggerNotification = @"MAMEHideDebuggerNotification"; |
| 48 | static NSString *const MAMEShowDebuggerNotification = @"MAMEShowDebuggerNotification"; |
| 49 | static NSString *const MAMEAuxiliaryDebugWindowWillCloseNotification |
| 50 | = @"MAMEAuxiliaryDebugWindowWillCloseNotification"; |
| 51 | |
| 52 | |
| 53 | //============================================================ |
| 54 | // PROTOTYPES |
| 55 | //============================================================ |
| 56 | |
| 57 | static void debugwin_view_update(debug_view *view, void *osdprivate); |
| 58 | |
| 59 | static void console_create_window(running_machine *machine); |
| 60 | |
| 61 | |
| 62 | //============================================================ |
| 63 | // osd_wait_for_debugger |
| 64 | //============================================================ |
| 65 | |
| 66 | void osd_wait_for_debugger(const device_config *device, int firststop) |
| 67 | { |
| 68 | // create a console window |
| 69 | if (main_console == nil) |
| 70 | console_create_window(device->machine); |
| 71 | |
| 72 | // make sure the debug windows are visible |
| 73 | waiting_for_debugger = YES; |
| 74 | if (firststop) { |
| 75 | NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:[NSValue valueWithPointer:device], |
| 76 | @"MAMEDebugDevice", |
| 77 | nil]; |
| 78 | [[NSNotificationCenter defaultCenter] postNotificationName:MAMEShowDebuggerNotification |
| 79 | object:main_console |
| 80 | userInfo:info]; |
| 81 | } |
| 82 | |
| 83 | // get and process messages |
| 84 | { |
| 85 | NSEvent *ev = [NSApp nextEventMatchingMask:NSAnyEventMask |
| 86 | untilDate:[NSDate distantFuture] |
| 87 | inMode:NSDefaultRunLoopMode |
| 88 | dequeue:YES]; |
| 89 | if (ev != nil) |
| 90 | [NSApp sendEvent:ev]; |
| 91 | } |
| 92 | |
| 93 | // mark the debugger as active |
| 94 | waiting_for_debugger = NO; |
| 95 | } |
| 96 | |
| 97 | |
| 98 | //============================================================ |
| 99 | // debugwin_update_during_game |
| 100 | //============================================================ |
| 101 | |
| 102 | void debugwin_update_during_game(running_machine *machine) |
| 103 | { |
| 104 | } |
| 105 | |
| 106 | |
| 107 | //============================================================ |
| 108 | // debugwin_view_update |
| 109 | //============================================================ |
| 110 | |
| 111 | static void debugwin_view_update(debug_view *view, void *osdprivate) |
| 112 | { |
| 113 | [(MAMEDebugView *)osdprivate update]; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | //============================================================ |
| 118 | // console_create_window |
| 119 | //============================================================ |
| 120 | |
| 121 | void console_create_window(running_machine *machine) |
| 122 | { |
| 123 | main_console = [[MAMEDebugConsole alloc] initWithMachine:machine]; |
| 124 | } |
| 125 | |
| 126 | |
| 127 | //============================================================ |
| 128 | // MAMEDebugView class |
| 129 | //============================================================ |
| 130 | |
| 131 | @implementation MAMEDebugCommandHistory |
| 132 | |
| 133 | + (NSInteger)defaultLength { |
| 134 | return 100; |
| 135 | } |
| 136 | |
| 137 | |
| 138 | - (id)init { |
| 139 | if (!(self = [super init])) |
| 140 | return nil; |
| 141 | length = [[self class] defaultLength]; |
| 142 | position = -1; |
| 143 | current = nil; |
| 144 | history = [[NSMutableArray alloc] initWithCapacity:length]; |
| 145 | return self; |
| 146 | } |
| 147 | |
| 148 | |
| 149 | - (void)dealloc { |
| 150 | if (current != nil) |
| 151 | [current release]; |
| 152 | if (history != nil) |
| 153 | [history release]; |
| 154 | [super dealloc]; |
| 155 | } |
| 156 | |
| 157 | |
| 158 | - (NSInteger)length { |
| 159 | return length; |
| 160 | } |
| 161 | |
| 162 | |
| 163 | - (void)setLength:(NSInteger)l { |
| 164 | length = l; |
| 165 | while ([history count] > length) |
| 166 | [history removeLastObject]; |
| 167 | } |
| 168 | |
| 169 | |
| 170 | - (void)add:(NSString *)entry { |
| 171 | if (([history count] == 0) || ![[history objectAtIndex:0] isEqualToString:entry]) { |
| 172 | [history insertObject:entry atIndex:0]; |
| 173 | while ([history count] > length) |
| 174 | [history removeLastObject]; |
| 175 | } |
| 176 | position = -1; |
| 177 | } |
| 178 | |
| 179 | |
| 180 | - (NSString *)previous:(NSString *)cur { |
| 181 | if ((position + 1) < [history count]) { |
| 182 | if (position < 0) { |
| 183 | [current autorelease]; |
| 184 | current = [cur copy]; |
| 185 | } |
| 186 | return [history objectAtIndex:++position]; |
| 187 | } else { |
| 188 | return nil; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | |
| 193 | - (NSString *)next:(NSString *)cur { |
| 194 | if (position > 0) { |
| 195 | return [history objectAtIndex:--position]; |
| 196 | } else if (position == 0) { |
| 197 | position--; |
| 198 | return [[current retain] autorelease]; |
| 199 | } else { |
| 200 | return nil; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | |
| 205 | - (void)reset { |
| 206 | position = -1; |
| 207 | if (current != nil) { |
| 208 | [current release]; |
| 209 | current = nil; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | |
| 214 | - (void)clear { |
| 215 | position = -1; |
| 216 | if (current != nil) { |
| 217 | [current release]; |
| 218 | current = nil; |
| 219 | } |
| 220 | [history removeAllObjects]; |
| 221 | } |
| 222 | |
| 223 | @end |
| 224 | |
| 225 | |
| 226 | //============================================================ |
| 227 | // MAMEDebugView class |
| 228 | //============================================================ |
| 229 | |
| 230 | @implementation MAMEDebugView |
| 231 | |
| 232 | - (NSColor *)foregroundForAttribute:(UINT8)attrib { |
| 233 | const CGFloat alpha = (attrib & DCA_DISABLED) ? 0.5 : 1.0; |
| 234 | if (attrib & DCA_COMMENT) |
| 235 | return [NSColor colorWithCalibratedRed:0.0 green:0.375 blue:0.0 alpha:1.0]; |
| 236 | else if (attrib & DCA_INVALID) |
| 237 | return [NSColor colorWithCalibratedRed:0.0 green:0.0 blue:1.0 alpha:alpha]; |
| 238 | else if (attrib & DCA_CHANGED) |
| 239 | return [NSColor colorWithCalibratedRed:0.875 green:0.0 blue:0.0 alpha:alpha]; |
| 240 | else |
| 241 | return [NSColor colorWithCalibratedWhite:0.0 alpha:alpha]; |
| 242 | } |
| 243 | |
| 244 | |
| 245 | - (NSColor *)backgroundForAttribute:(UINT8)attrib { |
| 246 | if ((attrib & DCA_SELECTED) && (attrib & DCA_CURRENT)) { |
| 247 | if ([[self window] isKeyWindow] && ([[self window] firstResponder] == self)) |
| 248 | return [NSColor colorWithCalibratedRed:0.875 green:0.625 blue:0.875 alpha:1.0]; |
| 249 | else |
| 250 | return [NSColor colorWithCalibratedRed:0.875 green:0.5 blue:0.625 alpha:1.0]; |
| 251 | } else if (attrib & DCA_CURRENT) { |
| 252 | return [NSColor colorWithCalibratedRed:1.0 green:0.625 blue:0.625 alpha:1.0]; |
| 253 | } else if (attrib & DCA_SELECTED) { |
| 254 | if ([[self window] isKeyWindow] && ([[self window] firstResponder] == self)) |
| 255 | return [NSColor colorWithCalibratedRed:0.75 green:0.875 blue:1.0 alpha:1.0]; |
| 256 | else |
| 257 | return [NSColor colorWithCalibratedWhite:0.875 alpha:1.0]; |
| 258 | } else if (attrib & DCA_ANCILLARY) { |
| 259 | return [NSColor colorWithCalibratedWhite:0.75 alpha:1.0]; |
| 260 | } else { |
| 261 | return [NSColor colorWithCalibratedWhite:1.0 alpha:1.0]; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | |
| 266 | - (debug_view_xy)convertLocation:(NSPoint)location { |
| 267 | debug_view_xy position; |
| 268 | position.x = lround(floor(location.x / fontWidth)); |
| 269 | position.y = lround(floor(location.y / fontHeight)); |
| 270 | if (position.x < 0) |
| 271 | position.x = 0; |
| 272 | else if (position.x >= totalSize.x) |
| 273 | position.x = totalSize.x - 1; |
| 274 | if (position.y < 0) |
| 275 | position.y = 0; |
| 276 | else if (position.y >= totalSize.y) |
| 277 | position.y = totalSize.y - 1; |
| 278 | return position; |
| 279 | } |
| 280 | |
| 281 | |
| 282 | - (void)convertBounds:(NSRect)b toPosition:(debug_view_xy *)origin size:(debug_view_xy *)size { |
| 283 | origin->x = lround(floor(b.origin.x / fontWidth)); |
| 284 | origin->y = lround(floor(b.origin.y / fontHeight)); |
| 285 | size->x = lround(ceil((b.origin.x + b.size.width) / fontWidth)) - origin->x; |
| 286 | size->y = lround(ceil((b.origin.y + b.size.height) / fontHeight)) - origin->y; |
| 287 | } |
| 288 | |
| 289 | |
| 290 | - (void)recomputeVisible { |
| 291 | if ([self window] != nil) { |
| 292 | debug_view_xy origin, size; |
| 293 | |
| 294 | // this gets all the characters that are at least paritally visible |
| 295 | [self convertBounds:[self visibleRect] toPosition:&origin size:&size]; |
| 296 | |
| 297 | // need to render entire lines or we get screwed up characters when widening views |
| 298 | origin.x = 0; |
| 299 | size.x = totalSize.x; |
| 300 | |
| 301 | // tell them what we think |
| 302 | debug_view_set_visible_size(view, size); |
| 303 | debug_view_set_visible_position(view, origin); |
| 304 | topLeft = origin; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | |
| 309 | - (void)typeCharacterAndScrollToCursor:(char)ch { |
| 310 | if (debug_view_get_cursor_supported(view)) { |
| 311 | debug_view_xy oldPos = debug_view_get_cursor_position(view); |
| 312 | debug_view_type_character(view, ch); |
| 313 | { |
| 314 | debug_view_xy newPos = debug_view_get_cursor_position(view); |
| 315 | if ((newPos.x != oldPos.x) || (newPos.y != oldPos.y)) { |
| 316 | [self scrollRectToVisible:NSMakeRect(newPos.x * fontWidth, |
| 317 | newPos.y * fontHeight, |
| 318 | fontWidth, |
| 319 | fontHeight)]; |
| 320 | } |
| 321 | } |
| 322 | } else { |
| 323 | debug_view_type_character(view, ch); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | |
| 328 | + (NSFont *)defaultFont { |
| 329 | // maybe we should get the configured system fixed-width font... |
| 330 | return [NSFont fontWithName:@"Monaco" size:10]; |
| 331 | } |
| 332 | |
| 333 | |
| 334 | - (id)initWithFrame:(NSRect)f type:(int)t machine:(running_machine *)m { |
| 335 | if (!(self = [super initWithFrame:f])) |
| 336 | return nil; |
| 337 | type = t; |
| 338 | machine = m; |
| 339 | view = debug_view_alloc(machine, type, debugwin_view_update, self); |
| 340 | if (view == nil) { |
| 341 | [self release]; |
| 342 | return nil; |
| 343 | } |
| 344 | totalSize.x = totalSize.y = 0; |
| 345 | topLeft.x = topLeft.y = 0; |
| 346 | [self setFont:[[self class] defaultFont]]; |
| 347 | return self; |
| 348 | } |
| 349 | |
| 350 | |
| 351 | - (void)dealloc { |
| 352 | [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 353 | if (view != NULL) |
| 354 | debug_view_free(view); |
| 355 | if (font != nil) |
| 356 | [font release]; |
| 357 | [super dealloc]; |
| 358 | } |
| 359 | |
| 360 | |
| 361 | - (void)update { |
| 362 | debug_view_xy newSize, newOrigin; |
| 363 | |
| 364 | // resize our frame if the total size has changed |
| 365 | newSize = debug_view_get_total_size(view); |
| 366 | if ((newSize.x != totalSize.x) || (newSize.y != totalSize.y)) { |
| 367 | [self setFrameSize:NSMakeSize(fontWidth * newSize.x, fontHeight * newSize.y)]; |
| 368 | totalSize = newSize; |
| 369 | } |
| 370 | |
| 371 | // scroll the view if we're being told to |
| 372 | newOrigin = debug_view_get_visible_position(view); |
| 373 | if (newOrigin.y != topLeft.y) { |
| 374 | [self scrollPoint:NSMakePoint([self visibleRect].origin.x, newOrigin.y * fontHeight)]; |
| 375 | topLeft.y = newOrigin.y; |
| 376 | } |
| 377 | |
| 378 | // recompute the visible area and mark as dirty |
| 379 | [self recomputeVisible]; |
| 380 | [self setNeedsDisplay:YES]; |
| 381 | } |
| 382 | |
| 383 | |
| 384 | - (NSSize)maximumFrameSize { |
| 385 | debug_view_xy max = debug_view_get_total_size(view); |
| 386 | return NSMakeSize(max.x * fontWidth, max.y * fontHeight); |
| 387 | } |
| 388 | |
| 389 | |
| 390 | - (NSFont *)font { |
| 391 | return [[font retain] autorelease]; |
| 392 | } |
| 393 | |
| 394 | |
| 395 | - (void)setFont:(NSFont *)f { |
| 396 | [font autorelease]; |
| 397 | font = [f retain]; |
| 398 | fontWidth = [font maximumAdvancement].width; |
| 399 | fontHeight = ceil([font ascender] - [font descender]); |
| 400 | fontAscent = [font ascender]; |
| 401 | [[self enclosingScrollView] setLineScroll:fontHeight]; |
| 402 | totalSize.x = totalSize.y = 0; |
| 403 | [self update]; |
| 404 | } |
| 405 | |
| 406 | |
| 407 | - (void)windowDidBecomeKey:(NSNotification *)notification { |
| 408 | NSWindow *win = [notification object]; |
| 409 | if ((win == [self window]) && ([win firstResponder] == self) && debug_view_get_cursor_supported(view)) |
| 410 | [self setNeedsDisplay:YES]; |
| 411 | } |
| 412 | |
| 413 | |
| 414 | - (void)windowDidResignKey:(NSNotification *)notification { |
| 415 | NSWindow *win = [notification object]; |
| 416 | if ((win == [self window]) && ([win firstResponder] == self) && debug_view_get_cursor_supported(view)) |
| 417 | [self setNeedsDisplay:YES]; |
| 418 | } |
| 419 | |
| 420 | |
| 421 | - (BOOL)acceptsFirstResponder { |
| 422 | return debug_view_get_cursor_supported(view); |
| 423 | } |
| 424 | |
| 425 | |
| 426 | - (BOOL)becomeFirstResponder { |
| 427 | if (debug_view_get_cursor_supported(view)) { |
| 428 | debug_view_xy pos; |
| 429 | debug_view_set_cursor_visible(view, TRUE); |
| 430 | pos = debug_view_get_cursor_position(view); |
| 431 | [self scrollRectToVisible:NSMakeRect(pos.x * fontWidth, pos.y * fontHeight, fontWidth, fontHeight)]; |
| 432 | [self setNeedsDisplay:YES]; |
| 433 | return [super becomeFirstResponder]; |
| 434 | } else { |
| 435 | return NO; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | |
| 440 | - (BOOL)resignFirstResponder { |
| 441 | if (debug_view_get_cursor_supported(view)) |
| 442 | [self setNeedsDisplay:YES]; |
| 443 | return [super resignFirstResponder]; |
| 444 | } |
| 445 | |
| 446 | |
| 447 | - (void)viewDidMoveToSuperview { |
| 448 | [[self enclosingScrollView] setLineScroll:fontHeight]; |
| 449 | [super viewDidMoveToSuperview]; |
| 450 | } |
| 451 | |
| 452 | |
| 453 | - (void)viewDidMoveToWindow { |
| 454 | [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidBecomeKeyNotification object:nil]; |
| 455 | [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidResignKeyNotification object:nil]; |
| 456 | if ([self window] != nil) { |
| 457 | [[NSNotificationCenter defaultCenter] addObserver:self |
| 458 | selector:@selector(windowDidBecomeKey:) |
| 459 | name:NSWindowDidBecomeKeyNotification |
| 460 | object:[self window]]; |
| 461 | [[NSNotificationCenter defaultCenter] addObserver:self |
| 462 | selector:@selector(windowDidResignKey:) |
| 463 | name:NSWindowDidResignKeyNotification |
| 464 | object:[self window]]; |
| 465 | [self recomputeVisible]; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | |
| 470 | - (BOOL)isFlipped { |
| 471 | return YES; |
| 472 | } |
| 473 | |
| 474 | |
| 475 | - (void)drawRect:(NSRect)dirtyRect { |
| 476 | const debug_view_char *base; |
| 477 | debug_view_xy origin, size; |
| 478 | debug_view_xy position, clip; |
| 479 | NSMutableString *text; |
| 480 | NSMutableDictionary *attributes; |
| 481 | UINT32 pass, row, col; |
| 482 | |
| 483 | // work out how much we need to draw |
| 484 | [self recomputeVisible]; |
| 485 | origin = debug_view_get_visible_position(view); |
| 486 | size = debug_view_get_visible_size(view); |
| 487 | [self convertBounds:dirtyRect toPosition:&position size:&clip]; |
| 488 | |
| 489 | // this gets the text for the whole visible area |
| 490 | base = debug_view_get_chars(view); |
| 491 | if (!base) |
| 492 | return; |
| 493 | |
| 494 | text = [[NSMutableString alloc] initWithCapacity:clip.x]; |
| 495 | attributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:font, NSFontAttributeName, nil]; |
| 496 | for (pass = 0; pass < 2; pass++) { |
| 497 | const debug_view_char *data = base + ((position.y - origin.y) * size.x); |
| 498 | for (row = position.y; row < position.y + clip.y; row++, data += size.x) { |
| 499 | int attr = -1; |
| 500 | |
| 501 | if ((row < origin.y) || (row >= origin.y + size.y)) |
| 502 | continue; |
| 503 | |
| 504 | // render entire lines to get character alignment right |
| 505 | for (col = origin.x; col < origin.x + size.x; col++) { |
| 506 | if ((attr != data[col - origin.x].attrib) && ([text length] > 0)) { |
| 507 | if (pass == 0) { |
| 508 | [[self backgroundForAttribute:attr] set]; |
| 509 | [NSBezierPath fillRect:NSMakeRect((col - [text length]) * fontWidth, |
| 510 | row * fontHeight, |
| 511 | [text length] * fontWidth, |
| 512 | fontHeight)]; |
| 513 | } else { |
| 514 | [attributes setObject:[self foregroundForAttribute:attr] |
| 515 | forKey:NSForegroundColorAttributeName]; |
| 516 | [text drawAtPoint:NSMakePoint((col - [text length]) * fontWidth, row * fontHeight) |
| 517 | withAttributes:attributes]; |
| 518 | } |
| 519 | [text setString:@""]; |
| 520 | } |
| 521 | attr = data[col - origin.x].attrib; |
| 522 | [text appendFormat:@"%c", data[col - origin.x].byte]; |
| 523 | } |
| 524 | if ([text length] > 0) { |
| 525 | if (pass == 0) { |
| 526 | [[self backgroundForAttribute:attr] set]; |
| 527 | [NSBezierPath fillRect:NSMakeRect((col - [text length]) * fontWidth, |
| 528 | row * fontHeight, |
| 529 | [text length] * fontWidth, |
| 530 | fontHeight)]; |
| 531 | } else { |
| 532 | [attributes setObject:[self foregroundForAttribute:attr] |
| 533 | forKey:NSForegroundColorAttributeName]; |
| 534 | [text drawAtPoint:NSMakePoint((col - [text length]) * fontWidth, row * fontHeight) |
| 535 | withAttributes:attributes]; |
| 536 | } |
| 537 | [text setString:@""]; |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | [attributes release]; |
| 542 | [text release]; |
| 543 | } |
| 544 | |
| 545 | |
| 546 | - (void)mouseDown:(NSEvent *)event { |
| 547 | NSPoint location = [self convertPoint:[event locationInWindow] fromView:nil]; |
| 548 | if (debug_view_get_cursor_supported(view)) { |
| 549 | debug_view_set_cursor_position(view, [self convertLocation:location]); |
| 550 | debug_view_set_cursor_visible(view, TRUE); |
| 551 | [self setNeedsDisplay:YES]; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | |
| 556 | - (void)mouseDragged:(NSEvent *)event { |
| 557 | NSPoint location = [self convertPoint:[event locationInWindow] fromView:nil]; |
| 558 | if (debug_view_get_cursor_supported(view)) { |
| 559 | [self autoscroll:event]; |
| 560 | debug_view_set_cursor_position(view, [self convertLocation:location]); |
| 561 | [self setNeedsDisplay:YES]; |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | |
| 566 | - (void)rightMouseDown:(NSEvent *)event { |
| 567 | NSPoint location = [self convertPoint:[event locationInWindow] fromView:nil]; |
| 568 | if (debug_view_get_cursor_supported(view)) { |
| 569 | debug_view_set_cursor_position(view, [self convertLocation:location]); |
| 570 | debug_view_set_cursor_visible(view, TRUE); |
| 571 | [self setNeedsDisplay:YES]; |
| 572 | } |
| 573 | [super rightMouseDown:event]; |
| 574 | } |
| 575 | |
| 576 | |
| 577 | - (void)keyDown:(NSEvent *)event { |
| 578 | NSUInteger modifiers = [event modifierFlags]; |
| 579 | NSString *str = [event charactersIgnoringModifiers]; |
| 580 | |
| 581 | if ([str length] == 1) { |
| 582 | if (modifiers & NSNumericPadKeyMask) { |
| 583 | switch ([str characterAtIndex:0]) { |
| 584 | case NSUpArrowFunctionKey: |
| 585 | if (modifiers & NSCommandKeyMask) |
| 586 | debug_view_type_character(view, DCH_CTRLHOME); |
| 587 | else |
| 588 | debug_view_type_character(view, DCH_UP); |
| 589 | return; |
| 590 | case NSDownArrowFunctionKey: |
| 591 | if (modifiers & NSCommandKeyMask) |
| 592 | debug_view_type_character(view, DCH_CTRLEND); |
| 593 | else |
| 594 | debug_view_type_character(view, DCH_DOWN); |
| 595 | return; |
| 596 | case NSLeftArrowFunctionKey: |
| 597 | if (modifiers & NSCommandKeyMask) |
| 598 | [self typeCharacterAndScrollToCursor:DCH_HOME]; |
| 599 | else if (modifiers & NSAlternateKeyMask) |
| 600 | [self typeCharacterAndScrollToCursor:DCH_CTRLLEFT]; |
| 601 | else |
| 602 | [self typeCharacterAndScrollToCursor:DCH_LEFT]; |
| 603 | return; |
| 604 | case NSRightArrowFunctionKey: |
| 605 | if (modifiers & NSCommandKeyMask) |
| 606 | [self typeCharacterAndScrollToCursor:DCH_END]; |
| 607 | else if (modifiers & NSAlternateKeyMask) |
| 608 | [self typeCharacterAndScrollToCursor:DCH_CTRLRIGHT]; |
| 609 | else |
| 610 | [self typeCharacterAndScrollToCursor:DCH_RIGHT]; |
| 611 | return; |
| 612 | default: |
| 613 | [self interpretKeyEvents:[NSArray arrayWithObject:event]]; |
| 614 | return; |
| 615 | } |
| 616 | } else if (modifiers & NSFunctionKeyMask) { |
| 617 | switch ([str characterAtIndex:0]) { |
| 618 | case NSPageUpFunctionKey: |
| 619 | if (modifiers & NSAlternateKeyMask) { |
| 620 | debug_view_type_character(view, DCH_PUP); |
| 621 | return; |
| 622 | } |
| 623 | case NSPageDownFunctionKey: |
| 624 | if (modifiers & NSAlternateKeyMask) { |
| 625 | debug_view_type_character(view, DCH_PDOWN); |
| 626 | return; |
| 627 | } |
| 628 | default: |
| 629 | ; |
| 630 | } |
| 631 | [super keyDown:event]; |
| 632 | return; |
| 633 | } |
| 634 | } |
| 635 | [self interpretKeyEvents:[NSArray arrayWithObject:event]]; |
| 636 | } |
| 637 | |
| 638 | |
| 639 | - (void)insertTab:(id)sender { |
| 640 | if ([[self window] firstResponder] == self) |
| 641 | [[self window] selectNextKeyView:self]; |
| 642 | } |
| 643 | |
| 644 | |
| 645 | - (void)insertBacktab:(id)sender { |
| 646 | if ([[self window] firstResponder] == self) |
| 647 | [[self window] selectPreviousKeyView:self]; |
| 648 | } |
| 649 | |
| 650 | |
| 651 | - (void)insertNewline:(id)sender { |
| 652 | debug_cpu_single_step(machine, 1); |
| 653 | } |
| 654 | |
| 655 | |
| 656 | - (void)insertText:(id)string { |
| 657 | NSUInteger len; |
| 658 | NSRange found; |
| 659 | if ([string isKindOfClass:[NSAttributedString class]]) |
| 660 | string = [string string]; |
| 661 | for (len = [string length], found = NSMakeRange(0, 0); |
| 662 | found.location < len; |
| 663 | found.location += found.length) { |
| 664 | found = [string rangeOfComposedCharacterSequenceAtIndex:found.location]; |
| 665 | if (found.length == 1) { |
| 666 | unichar ch = [string characterAtIndex:found.location]; |
| 667 | if ((ch >= 32) && (ch < 127)) |
| 668 | [self typeCharacterAndScrollToCursor:ch]; |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | @end |
| 674 | |
| 675 | |
| 676 | //============================================================ |
| 677 | // MAMEMemoryView class |
| 678 | //============================================================ |
| 679 | |
| 680 | @implementation MAMEMemoryView |
| 681 | |
| 682 | - (id)initWithFrame:(NSRect)f machine:(running_machine *)m { |
| 683 | NSMenu *contextMenu; |
| 684 | |
| 685 | if (!(self = [super initWithFrame:f type:DVT_MEMORY machine:m])) |
| 686 | return nil; |
| 687 | |
| 688 | contextMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Memory"]; |
| 689 | [self insertActionItemsInMenu:contextMenu atIndex:0]; |
| 690 | [self setMenu:contextMenu]; |
| 691 | [contextMenu release]; |
| 692 | |
| 693 | return self; |
| 694 | } |
| 695 | |
| 696 | |
| 697 | - (void)dealloc { |
| 698 | [super dealloc]; |
| 699 | } |
| 700 | |
| 701 | |
| 702 | - (BOOL)validateMenuItem:(NSMenuItem *)item { |
| 703 | SEL action = [item action]; |
| 704 | NSInteger tag = [item tag]; |
| 705 | |
| 706 | if (action == @selector(showChunkSize:)) { |
| 707 | [item setState:((tag == memory_view_get_bytes_per_chunk(view)) ? NSOnState : NSOffState)]; |
| 708 | } else if (action == @selector(showPhysicalAddresses:)) { |
| 709 | [item setState:((tag == memory_view_get_physical(view)) ? NSOnState : NSOffState)]; |
| 710 | } else if (action == @selector(showReverseView:)) { |
| 711 | [item setState:((tag == memory_view_get_reverse(view)) ? NSOnState : NSOffState)]; |
| 712 | } else if (action == @selector(showReverseViewToggle:)) { |
| 713 | [item setState:(memory_view_get_reverse(view) ? NSOnState : NSOffState)]; |
| 714 | } |
| 715 | return YES; |
| 716 | } |
| 717 | |
| 718 | |
| 719 | - (NSSize)maximumFrameSize { |
| 720 | const int selected = memory_view_get_subview(view); |
| 721 | const memory_subview_item *subitem; |
| 722 | debug_view_xy max; |
| 723 | |
| 724 | max.x = max.y = 0; |
| 725 | for (subitem = memory_view_get_subview_list(view); subitem != NULL; subitem = subitem->next) { |
| 726 | debug_view_xy current; |
| 727 | memory_view_set_subview(view, subitem->index); |
| 728 | current = debug_view_get_total_size(view); |
| 729 | if (current.x > max.x) |
| 730 | max.x = current.x; |
| 731 | if (current.y > max.y) |
| 732 | max.y = current.y; |
| 733 | } |
| 734 | memory_view_set_subview(view, selected); |
| 735 | return NSMakeSize(max.x * fontWidth, max.y * fontHeight); |
| 736 | } |
| 737 | |
| 738 | |
| 739 | - (NSString *)selectedSubviewName { |
| 740 | const memory_subview_item *subitem = memory_view_get_current_subview(view); |
| 741 | if (subitem != NULL) |
| 742 | return [NSString stringWithUTF8String:subitem->name]; |
| 743 | else |
| 744 | return @""; |
| 745 | } |
| 746 | |
| 747 | |
| 748 | - (int)selectedSubviewIndex { |
| 749 | const memory_subview_item *subitem = memory_view_get_current_subview(view); |
| 750 | if (subitem != NULL) |
| 751 | return subitem->index; |
| 752 | else |
| 753 | return -1; |
| 754 | } |
| 755 | |
| 756 | |
| 757 | - (void)selectSubviewAtIndex:(int)index { |
| 758 | const int selected = memory_view_get_subview(view); |
| 759 | if (selected != index) { |
| 760 | memory_view_set_subview(view, index); |
| 761 | if ([[self window] firstResponder] != self) |
| 762 | debug_view_set_cursor_visible(view, FALSE); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | |
| 767 | - (void)selectSubviewForCPU:(const device_config *)device { |
| 768 | const int selected = memory_view_get_subview(view); |
| 769 | const memory_subview_item *subitem; |
| 770 | for (subitem = memory_view_get_subview_list(view); subitem != NULL; subitem = subitem->next) { |
| 771 | if (subitem->space->cpu == device) { |
| 772 | if (selected != subitem->index) { |
| 773 | memory_view_set_subview(view, subitem->index); |
| 774 | if ([[self window] firstResponder] != self) |
| 775 | debug_view_set_cursor_visible(view, FALSE); |
| 776 | } |
| 777 | break; |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | |
| 783 | - (NSString *)expression { |
| 784 | return [NSString stringWithUTF8String:memory_view_get_expression(view)]; |
| 785 | } |
| 786 | |
| 787 | |
| 788 | - (void)setExpression:(NSString *)exp { |
| 789 | memory_view_set_expression(view, [exp UTF8String]); |
| 790 | } |
| 791 | |
| 792 | |
| 793 | - (IBAction)showChunkSize:(id)sender { |
| 794 | memory_view_set_bytes_per_chunk(view, [sender tag]); |
| 795 | } |
| 796 | |
| 797 | |
| 798 | - (IBAction)showPhysicalAddresses:(id)sender { |
| 799 | memory_view_set_physical(view, [sender tag]); |
| 800 | } |
| 801 | |
| 802 | |
| 803 | - (IBAction)showReverseView:(id)sender { |
| 804 | memory_view_set_reverse(view, [sender tag]); |
| 805 | } |
| 806 | |
| 807 | |
| 808 | - (IBAction)showReverseViewToggle:(id)sender { |
| 809 | memory_view_set_reverse(view, !memory_view_get_reverse(view)); |
| 810 | } |
| 811 | |
| 812 | |
| 813 | - (void)insertActionItemsInMenu:(NSMenu *)menu atIndex:(NSInteger)index { |
| 814 | { |
| 815 | NSInteger tag; |
| 816 | for (tag = 1; tag <= 8; tag <<= 1) { |
| 817 | NSString *title = [NSString stringWithFormat:@"%d-byte Chunks", tag]; |
| 818 | NSMenuItem *chunkItem = [menu insertItemWithTitle:title |
| 819 | action:@selector(showChunkSize:) |
| 820 | keyEquivalent:[NSString stringWithFormat:@"%d", tag] |
| 821 | atIndex:index++]; |
| 822 | [chunkItem setTarget:self]; |
| 823 | [chunkItem setTag:tag]; |
| 824 | } |
| 825 | } |
| 826 | [menu insertItem:[NSMenuItem separatorItem] atIndex:index++]; |
| 827 | { |
| 828 | NSMenuItem *logicalItem = [menu insertItemWithTitle:@"Logical Addresses" |
| 829 | action:@selector(showPhysicalAddresses:) |
| 830 | keyEquivalent:@"v" |
| 831 | atIndex:index++]; |
| 832 | [logicalItem setTarget:self]; |
| 833 | [logicalItem setTag:FALSE]; |
| 834 | } |
| 835 | { |
| 836 | NSMenuItem *physicalItem = [menu insertItemWithTitle:@"Physical Addresses" |
| 837 | action:@selector(showPhysicalAddresses:) |
| 838 | keyEquivalent:@"y" |
| 839 | atIndex:index++]; |
| 840 | [physicalItem setTarget:self]; |
| 841 | [physicalItem setTag:TRUE]; |
| 842 | } |
| 843 | [menu insertItem:[NSMenuItem separatorItem] atIndex:index++]; |
| 844 | { |
| 845 | NSMenuItem *reverseItem = [menu insertItemWithTitle:@"Reverse View" |
| 846 | action:@selector(showReverseViewToggle:) |
| 847 | keyEquivalent:@"r" |
| 848 | atIndex:index++]; |
| 849 | [reverseItem setTarget:self]; |
| 850 | } |
| 851 | if (index < [menu numberOfItems]) |
| 852 | [menu insertItem:[NSMenuItem separatorItem] atIndex:index++]; |
| 853 | } |
| 854 | |
| 855 | |
| 856 | - (void)insertSubviewItemsInMenu:(NSMenu *)menu atIndex:(NSInteger)index { |
| 857 | const memory_subview_item *subitem; |
| 858 | for (subitem = memory_view_get_subview_list(view); subitem != NULL; subitem = subitem->next) { |
| 859 | [[menu insertItemWithTitle:[NSString stringWithUTF8String:subitem->name] |
| 860 | action:NULL |
| 861 | keyEquivalent:@"" |
| 862 | atIndex:index++] setTag:subitem->index]; |
| 863 | } |
| 864 | if (index < [menu numberOfItems]) |
| 865 | [menu insertItem:[NSMenuItem separatorItem] atIndex:index++]; |
| 866 | } |
| 867 | |
| 868 | @end |
| 869 | |
| 870 | |
| 871 | //============================================================ |
| 872 | // MAMEDisassemblyView class |
| 873 | //============================================================ |
| 874 | |
| 875 | @implementation MAMEDisassemblyView |
| 876 | |
| 877 | - (debug_cpu_breakpoint *)findBreakpointAtAddress:(offs_t)address inAddressSpace:(const address_space *)space { |
| 878 | cpu_debug_data *cpuinfo = cpu_get_debug_data(space->cpu); |
| 879 | debug_cpu_breakpoint *bp; |
| 880 | for (bp = cpuinfo->bplist; (bp != NULL) && (address != bp->address); bp = bp->next) {} |
| 881 | return bp; |
| 882 | } |
| 883 | |
| 884 | - (void)createContextMenu { |
| 885 | NSMenu *contextMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Disassembly"]; |
| 886 | NSMenuItem *item; |
| 887 | |
| 888 | item = [contextMenu addItemWithTitle:@"Toggle Breakpoint" |
| 889 | action:@selector(debugToggleBreakpoint:) |
| 890 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF9FunctionKey]]; |
| 891 | [item setKeyEquivalentModifierMask:0]; |
| 892 | [item setTarget:self]; |
| 893 | |
| 894 | item = [contextMenu addItemWithTitle:@"Disable Breakpoint" |
| 895 | action:@selector(debugToggleBreakpointEnable:) |
| 896 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF9FunctionKey]]; |
| 897 | [item setKeyEquivalentModifierMask:NSShiftKeyMask]; |
| 898 | [item setTarget:self]; |
| 899 | |
| 900 | [contextMenu addItem:[NSMenuItem separatorItem]]; |
| 901 | |
| 902 | item = [contextMenu addItemWithTitle:@"Run to Cursor" |
| 903 | action:@selector(debugRunToCursor:) |
| 904 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF4FunctionKey]]; |
| 905 | [item setKeyEquivalentModifierMask:0]; |
| 906 | [item setTarget:self]; |
| 907 | |
| 908 | [contextMenu addItem:[NSMenuItem separatorItem]]; |
| 909 | |
| 910 | item = [contextMenu addItemWithTitle:@"Raw Opcodes" |
| 911 | action:@selector(showRightColumn:) |
| 912 | keyEquivalent:@"r"]; |
| 913 | [item setTarget:self]; |
| 914 | [item setTag:DASM_RIGHTCOL_RAW]; |
| 915 | |
| 916 | item = [contextMenu addItemWithTitle:@"Encrypted Opcodes" |
| 917 | action:@selector(showRightColumn:) |
| 918 | keyEquivalent:@"e"]; |
| 919 | [item setTarget:self]; |
| 920 | [item setTag:DASM_RIGHTCOL_ENCRYPTED]; |
| 921 | |
| 922 | item = [contextMenu addItemWithTitle:@"Comments" |
| 923 | action:@selector(showRightColumn:) |
| 924 | keyEquivalent:@"n"]; |
| 925 | [item setTarget:self]; |
| 926 | [item setTag:DASM_RIGHTCOL_COMMENTS]; |
| 927 | |
| 928 | [self setMenu:contextMenu]; |
| 929 | [contextMenu release]; |
| 930 | } |
| 931 | |
| 932 | |
| 933 | - (id)initWithFrame:(NSRect)f machine:(running_machine *)m useConsole:(BOOL)uc { |
| 934 | if (!(self = [super initWithFrame:f type:DVT_DISASSEMBLY machine:m])) |
| 935 | return nil; |
| 936 | useConsole = uc; |
| 937 | [self createContextMenu]; |
| 938 | return self; |
| 939 | } |
| 940 | |
| 941 | |
| 942 | - (void)dealloc { |
| 943 | [super dealloc]; |
| 944 | } |
| 945 | |
| 946 | |
| 947 | - (BOOL)validateMenuItem:(NSMenuItem *)item { |
| 948 | SEL action = [item action]; |
| 949 | BOOL inContextMenu = ([item menu] == [self menu]); |
| 950 | BOOL haveCursor = NO, isCurrent = NO; |
| 951 | debug_cpu_breakpoint *breakpoint = NULL; |
| 952 | |
| 953 | if (debug_view_get_cursor_visible(view)) { |
| 954 | const address_space *space = disasm_view_get_current_subview(view)->space; |
| 955 | isCurrent = (debug_cpu_get_visible_cpu(machine) == space->cpu); |
| 956 | if (!useConsole || isCurrent) { |
| 957 | offs_t address = memory_byte_to_address(space, disasm_view_get_selected_address(view)); |
| 958 | haveCursor = YES; |
| 959 | breakpoint = [self findBreakpointAtAddress:address inAddressSpace:space]; |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | if (action == @selector(debugToggleBreakpoint:)) { |
| 964 | if (haveCursor) { |
| 965 | if (breakpoint != NULL) { |
| 966 | if (inContextMenu) |
| 967 | [item setTitle:@"Clear Breakpoint"]; |
| 968 | else |
| 969 | [item setTitle:@"Clear Breakpoint at Cursor"]; |
| 970 | } else { |
| 971 | if (inContextMenu) |
| 972 | [item setTitle:@"Set Breakpoint"]; |
| 973 | else |
| 974 | [item setTitle:@"Set Breakpoint at Cursor"]; |
| 975 | } |
| 976 | } else { |
| 977 | if (inContextMenu) |
| 978 | [item setTitle:@"Toggle Breakpoint"]; |
| 979 | else |
| 980 | [item setTitle:@"Toggle Breakpoint at Cursor"]; |
| 981 | } |
| 982 | return haveCursor; |
| 983 | } else if (action == @selector(debugToggleBreakpointEnable:)) { |
| 984 | if ((breakpoint != NULL) && !breakpoint->enabled) { |
| 985 | if (inContextMenu) |
| 986 | [item setTitle:@"Enable Breakpoint"]; |
| 987 | else |
| 988 | [item setTitle:@"Enable Breakpoint at Cursor"]; |
| 989 | } else { |
| 990 | if (inContextMenu) |
| 991 | [item setTitle:@"Disable Breakpoint"]; |
| 992 | else |
| 993 | [item setTitle:@"Disable Breakpoint at Cursor"]; |
| 994 | } |
| 995 | return (breakpoint != NULL); |
| 996 | } else if (action == @selector(debugRunToCursor:)) { |
| 997 | return isCurrent; |
| 998 | } else if (action == @selector(showRightColumn:)) { |
| 999 | [item setState:((disasm_view_get_right_column(view) == [item tag]) ? NSOnState : NSOffState)]; |
| 1000 | return YES; |
| 1001 | } else { |
| 1002 | return YES; |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | |
| 1007 | - (NSSize)maximumFrameSize { |
| 1008 | const int selected = disasm_view_get_subview(view); |
| 1009 | const disasm_subview_item *subitem; |
| 1010 | debug_view_xy max; |
| 1011 | |
| 1012 | max.x = max.y = 0; |
| 1013 | for (subitem = disasm_view_get_subview_list(view); subitem != NULL; subitem = subitem->next) { |
| 1014 | debug_view_xy current; |
| 1015 | disasm_view_set_subview(view, subitem->index); |
| 1016 | current = debug_view_get_total_size(view); |
| 1017 | if (current.x > max.x) |
| 1018 | max.x = current.x; |
| 1019 | if (current.y > max.y) |
| 1020 | max.y = current.y; |
| 1021 | } |
| 1022 | disasm_view_set_subview(view, selected); |
| 1023 | return NSMakeSize(max.x * fontWidth, max.y * fontHeight); |
| 1024 | } |
| 1025 | |
| 1026 | |
| 1027 | - (NSString *)selectedSubviewName { |
| 1028 | const disasm_subview_item *subitem = disasm_view_get_current_subview(view); |
| 1029 | if (subitem != NULL) |
| 1030 | return [NSString stringWithUTF8String:subitem->name]; |
| 1031 | else |
| 1032 | return @""; |
| 1033 | } |
| 1034 | |
| 1035 | |
| 1036 | - (int)selectedSubviewIndex { |
| 1037 | const disasm_subview_item *subitem = disasm_view_get_current_subview(view); |
| 1038 | if (subitem != NULL) |
| 1039 | return subitem->index; |
| 1040 | else |
| 1041 | return -1; |
| 1042 | } |
| 1043 | |
| 1044 | |
| 1045 | - (void)selectSubviewAtIndex:(int)index { |
| 1046 | const int selected = disasm_view_get_subview(view); |
| 1047 | if (selected != index) { |
| 1048 | disasm_view_set_subview(view, index); |
| 1049 | if ([[self window] firstResponder] != self) |
| 1050 | debug_view_set_cursor_visible(view, FALSE); |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | |
| 1055 | - (void)selectSubviewForCPU:(const device_config *)device { |
| 1056 | const int selected = disasm_view_get_subview(view); |
| 1057 | const disasm_subview_item *subitem; |
| 1058 | for (subitem = disasm_view_get_subview_list(view); subitem != NULL; subitem = subitem->next) { |
| 1059 | if (subitem->space->cpu == device) { |
| 1060 | if (selected != subitem->index) { |
| 1061 | disasm_view_set_subview(view, subitem->index); |
| 1062 | if ([[self window] firstResponder] != self) |
| 1063 | debug_view_set_cursor_visible(view, FALSE); |
| 1064 | } |
| 1065 | break; |
| 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | |
| 1071 | - (NSString *)expression { |
| 1072 | return [NSString stringWithUTF8String:disasm_view_get_expression(view)]; |
| 1073 | } |
| 1074 | |
| 1075 | |
| 1076 | - (void)setExpression:(NSString *)exp { |
| 1077 | disasm_view_set_expression(view, [exp UTF8String]); |
| 1078 | } |
| 1079 | |
| 1080 | |
| 1081 | - (IBAction)debugToggleBreakpoint:(id)sender { |
| 1082 | if (debug_view_get_cursor_visible(view)) { |
| 1083 | const address_space *space = disasm_view_get_current_subview(view)->space; |
| 1084 | if (!useConsole || (debug_cpu_get_visible_cpu(machine) == space->cpu)) { |
| 1085 | offs_t address = memory_byte_to_address(space, disasm_view_get_selected_address(view)); |
| 1086 | debug_cpu_breakpoint *bp = [self findBreakpointAtAddress:address inAddressSpace:space]; |
| 1087 | |
| 1088 | // if it doesn't exist, add a new one |
| 1089 | if (useConsole) { |
| 1090 | NSString *command; |
| 1091 | if (bp == NULL) |
| 1092 | command = [NSString stringWithFormat:@"bpset %lX", (unsigned long)address]; |
| 1093 | else |
| 1094 | command = [NSString stringWithFormat:@"bpclear %X", (unsigned)bp->index]; |
| 1095 | debug_console_execute_command(machine, [command UTF8String], 1); |
| 1096 | } else { |
| 1097 | if (bp == NULL) |
| 1098 | debug_cpu_breakpoint_set(space->cpu, address, NULL, NULL); |
| 1099 | else |
| 1100 | debug_cpu_breakpoint_clear(machine, bp->index); |
| 1101 | debug_view_update_type(machine, DVT_DISASSEMBLY); |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | |
| 1108 | - (IBAction)debugToggleBreakpointEnable:(id)sender { |
| 1109 | if (debug_view_get_cursor_visible(view)) { |
| 1110 | const address_space *space = disasm_view_get_current_subview(view)->space; |
| 1111 | if (!useConsole || (debug_cpu_get_visible_cpu(machine) == space->cpu)) { |
| 1112 | offs_t address = memory_byte_to_address(space, disasm_view_get_selected_address(view)); |
| 1113 | debug_cpu_breakpoint *bp = [self findBreakpointAtAddress:address inAddressSpace:space]; |
| 1114 | |
| 1115 | if (bp != NULL) { |
| 1116 | NSString *command; |
| 1117 | if (useConsole) { |
| 1118 | if (bp->enabled) |
| 1119 | command = [NSString stringWithFormat:@"bpdisable %X", (unsigned)bp->index]; |
| 1120 | else |
| 1121 | command = [NSString stringWithFormat:@"bpenable %X", (unsigned)bp->index]; |
| 1122 | debug_console_execute_command(machine, [command UTF8String], 1); |
| 1123 | } else { |
| 1124 | debug_cpu_breakpoint_enable(machine, bp->index, !bp->enabled); |
| 1125 | debug_view_update_type(machine, DVT_DISASSEMBLY); |
| 1126 | } |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | |
| 1133 | - (IBAction)debugRunToCursor:(id)sender { |
| 1134 | if (debug_view_get_cursor_visible(view)) { |
| 1135 | const address_space *space = disasm_view_get_current_subview(view)->space; |
| 1136 | if (debug_cpu_get_visible_cpu(machine) == space->cpu) { |
| 1137 | offs_t address = memory_byte_to_address(space, disasm_view_get_selected_address(view)); |
| 1138 | if (useConsole) { |
| 1139 | NSString *command = [NSString stringWithFormat:@"go %lX", (unsigned long)address]; |
| 1140 | debug_console_execute_command(machine, [command UTF8String], 1); |
| 1141 | } else { |
| 1142 | debug_cpu_go(machine, address); |
| 1143 | } |
| 1144 | } |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | |
| 1149 | - (IBAction)showRightColumn:(id)sender { |
| 1150 | disasm_view_set_right_column(view, [sender tag]); |
| 1151 | } |
| 1152 | |
| 1153 | |
| 1154 | - (void)insertActionItemsInMenu:(NSMenu *)menu atIndex:(NSInteger)index { |
| 1155 | { |
| 1156 | NSMenuItem *breakItem = [menu insertItemWithTitle:@"Toggle Breakpoint at Cursor" |
| 1157 | action:@selector(debugToggleBreakpoint:) |
| 1158 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF9FunctionKey] |
| 1159 | atIndex:index++]; |
| 1160 | [breakItem setKeyEquivalentModifierMask:0]; |
| 1161 | [breakItem setTarget:self]; |
| 1162 | } |
| 1163 | { |
| 1164 | NSMenuItem *disableItem = [menu insertItemWithTitle:@"Disable Breakpoint at Cursor" |
| 1165 | action:@selector(debugToggleBreakpointEnable:) |
| 1166 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF9FunctionKey] |
| 1167 | atIndex:index++]; |
| 1168 | [disableItem setKeyEquivalentModifierMask:NSShiftKeyMask]; |
| 1169 | [disableItem setAlternate:YES]; |
| 1170 | [disableItem setTarget:self]; |
| 1171 | } |
| 1172 | { |
| 1173 | NSMenu *runMenu = [[menu itemWithTitle:@"Run"] submenu]; |
| 1174 | NSMenuItem *runItem; |
| 1175 | if (runMenu != nil) { |
| 1176 | runItem = [runMenu addItemWithTitle:@"to Cursor" |
| 1177 | action:@selector(debugRunToCursor:) |
| 1178 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF4FunctionKey]]; |
| 1179 | } else { |
| 1180 | runItem = [menu insertItemWithTitle:@"Run to Cursor" |
| 1181 | action:@selector(debugRunToCursor:) |
| 1182 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF4FunctionKey] |
| 1183 | atIndex:index++]; |
| 1184 | } |
| 1185 | [runItem setKeyEquivalentModifierMask:0]; |
| 1186 | [runItem setTarget:self]; |
| 1187 | } |
| 1188 | [menu insertItem:[NSMenuItem separatorItem] atIndex:index++]; |
| 1189 | { |
| 1190 | NSMenuItem *rawItem = [menu insertItemWithTitle:@"Show Raw Opcodes" |
| 1191 | action:@selector(showRightColumn:) |
| 1192 | keyEquivalent:@"r" |
| 1193 | atIndex:index++]; |
| 1194 | [rawItem setTarget:self]; |
| 1195 | [rawItem setTag:DASM_RIGHTCOL_RAW]; |
| 1196 | } |
| 1197 | { |
| 1198 | NSMenuItem *encItem = [menu insertItemWithTitle:@"Show Encrypted Opcodes" |
| 1199 | action:@selector(showRightColumn:) |
| 1200 | keyEquivalent:@"e" |
| 1201 | atIndex:index++]; |
| 1202 | [encItem setTarget:self]; |
| 1203 | [encItem setTag:DASM_RIGHTCOL_ENCRYPTED]; |
| 1204 | } |
| 1205 | { |
| 1206 | NSMenuItem *commentsItem = [menu insertItemWithTitle:@"Show Comments" |
| 1207 | action:@selector(showRightColumn:) |
| 1208 | keyEquivalent:@"n" |
| 1209 | atIndex:index++]; |
| 1210 | [commentsItem setTarget:self]; |
| 1211 | [commentsItem setTag:DASM_RIGHTCOL_COMMENTS]; |
| 1212 | } |
| 1213 | if (index < [menu numberOfItems]) |
| 1214 | [menu insertItem:[NSMenuItem separatorItem] atIndex:index++]; |
| 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | - (void)insertSubviewItemsInMenu:(NSMenu *)menu atIndex:(NSInteger)index { |
| 1219 | const disasm_subview_item *subitem; |
| 1220 | for (subitem = disasm_view_get_subview_list(view); subitem != NULL; subitem = subitem->next) { |
| 1221 | [[menu insertItemWithTitle:[NSString stringWithUTF8String:subitem->name] |
| 1222 | action:NULL |
| 1223 | keyEquivalent:@"" |
| 1224 | atIndex:index++] setTag:subitem->index]; |
| 1225 | } |
| 1226 | if (index < [menu numberOfItems]) |
| 1227 | [menu insertItem:[NSMenuItem separatorItem] atIndex:index++]; |
| 1228 | } |
| 1229 | |
| 1230 | @end |
| 1231 | |
| 1232 | |
| 1233 | //============================================================ |
| 1234 | // MAMERegistersView class |
| 1235 | //============================================================ |
| 1236 | |
| 1237 | @implementation MAMERegistersView |
| 1238 | |
| 1239 | - (id)initWithFrame:(NSRect)f machine:(running_machine *)m { |
| 1240 | if (!(self = [super initWithFrame:f type:DVT_REGISTERS machine:m])) |
| 1241 | return nil; |
| 1242 | return self; |
| 1243 | } |
| 1244 | |
| 1245 | |
| 1246 | - (void)dealloc { |
| 1247 | [super dealloc]; |
| 1248 | } |
| 1249 | |
| 1250 | |
| 1251 | - (NSSize)maximumFrameSize { |
| 1252 | const int selected = registers_view_get_subview(view); |
| 1253 | const registers_subview_item *subitem; |
| 1254 | debug_view_xy max; |
| 1255 | |
| 1256 | max.x = max.y = 0; |
| 1257 | for (subitem = registers_view_get_subview_list(view); subitem != NULL; subitem = subitem->next) { |
| 1258 | debug_view_xy current; |
| 1259 | registers_view_set_subview(view, subitem->index); |
| 1260 | current = debug_view_get_total_size(view); |
| 1261 | if (current.x > max.x) |
| 1262 | max.x = current.x; |
| 1263 | if (current.y > max.y) |
| 1264 | max.y = current.y; |
| 1265 | } |
| 1266 | registers_view_set_subview(view, selected); |
| 1267 | return NSMakeSize(max.x * fontWidth, max.y * fontHeight); |
| 1268 | } |
| 1269 | |
| 1270 | |
| 1271 | - (NSString *)selectedSubviewName { |
| 1272 | const registers_subview_item *subitem = registers_view_get_current_subview(view); |
| 1273 | if (subitem != NULL) |
| 1274 | return [NSString stringWithUTF8String:subitem->name]; |
| 1275 | else |
| 1276 | return @""; |
| 1277 | } |
| 1278 | |
| 1279 | |
| 1280 | - (int)selectedSubviewIndex { |
| 1281 | const registers_subview_item *subitem = registers_view_get_current_subview(view); |
| 1282 | if (subitem != NULL) |
| 1283 | return subitem->index; |
| 1284 | else |
| 1285 | return -1; |
| 1286 | } |
| 1287 | |
| 1288 | |
| 1289 | - (void)selectSubviewAtIndex:(int)index { |
| 1290 | const int selected = registers_view_get_subview(view); |
| 1291 | if (selected != index) { |
| 1292 | registers_view_set_subview(view, index); |
| 1293 | if ([[self window] firstResponder] != self) |
| 1294 | debug_view_set_cursor_visible(view, FALSE); |
| 1295 | } |
| 1296 | } |
| 1297 | |
| 1298 | |
| 1299 | - (void)selectSubviewForCPU:(const device_config *)device { |
| 1300 | const int selected = registers_view_get_subview(view); |
| 1301 | const registers_subview_item *subitem; |
| 1302 | for (subitem = registers_view_get_subview_list(view); subitem != NULL; subitem = subitem->next) { |
| 1303 | if (subitem->device == device) { |
| 1304 | if (selected != subitem->index) { |
| 1305 | registers_view_set_subview(view, subitem->index); |
| 1306 | if ([[self window] firstResponder] != self) |
| 1307 | debug_view_set_cursor_visible(view, FALSE); |
| 1308 | } |
| 1309 | break; |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | @end |
| 1315 | |
| 1316 | |
| 1317 | //============================================================ |
| 1318 | // MAMEConsoleView class |
| 1319 | //============================================================ |
| 1320 | |
| 1321 | @implementation MAMEConsoleView |
| 1322 | |
| 1323 | - (id)initWithFrame:(NSRect)f machine:(running_machine *)m { |
| 1324 | if (!(self = [super initWithFrame:f type:DVT_CONSOLE machine:m])) |
| 1325 | return nil; |
| 1326 | return self; |
| 1327 | } |
| 1328 | |
| 1329 | |
| 1330 | - (void)dealloc { |
| 1331 | [super dealloc]; |
| 1332 | } |
| 1333 | |
| 1334 | @end |
| 1335 | |
| 1336 | |
| 1337 | //============================================================ |
| 1338 | // MAMEErrorLogView class |
| 1339 | //============================================================ |
| 1340 | |
| 1341 | @implementation MAMEErrorLogView |
| 1342 | |
| 1343 | - (id)initWithFrame:(NSRect)f machine:(running_machine *)m { |
| 1344 | if (!(self = [super initWithFrame:f type:DVT_LOG machine:m])) |
| 1345 | return nil; |
| 1346 | return self; |
| 1347 | } |
| 1348 | |
| 1349 | |
| 1350 | - (void)dealloc { |
| 1351 | [super dealloc]; |
| 1352 | } |
| 1353 | |
| 1354 | @end |
| 1355 | |
| 1356 | |
| 1357 | //============================================================ |
| 1358 | // MAMEDebugWindowHandler class |
| 1359 | //============================================================ |
| 1360 | |
| 1361 | @implementation MAMEDebugWindowHandler |
| 1362 | |
| 1363 | + (void)addCommonActionItems:(NSMenu *)menu { |
| 1364 | { |
| 1365 | NSMenuItem *runParentItem = [menu addItemWithTitle:@"Run" |
| 1366 | action:@selector(debugRun:) |
| 1367 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF5FunctionKey]]; |
| 1368 | NSMenu *runMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Run"]; |
| 1369 | [runParentItem setSubmenu:runMenu]; |
| 1370 | [runMenu release]; |
| 1371 | [runParentItem setKeyEquivalentModifierMask:0]; |
| 1372 | [[runMenu addItemWithTitle:@"and Hide Debugger" |
| 1373 | action:@selector(debugRunAndHide:) |
| 1374 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF12FunctionKey]] |
| 1375 | setKeyEquivalentModifierMask:0]; |
| 1376 | [[runMenu addItemWithTitle:@"to Next CPU" |
| 1377 | action:@selector(debugRunToNextCPU:) |
| 1378 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF6FunctionKey]] |
| 1379 | setKeyEquivalentModifierMask:0]; |
| 1380 | [[runMenu addItemWithTitle:@"until Next Interrupt on Current CPU" |
| 1381 | action:@selector(debugRunToNextInterrupt:) |
| 1382 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF7FunctionKey]] |
| 1383 | setKeyEquivalentModifierMask:0]; |
| 1384 | [[runMenu addItemWithTitle:@"until Next VBLANK" |
| 1385 | action:@selector(debugRunToNextVBLANK:) |
| 1386 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF8FunctionKey]] |
| 1387 | setKeyEquivalentModifierMask:0]; |
| 1388 | } |
| 1389 | { |
| 1390 | NSMenuItem *stepParentItem = [menu addItemWithTitle:@"Step" action:NULL keyEquivalent:@""]; |
| 1391 | NSMenu *stepMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Step"]; |
| 1392 | [stepParentItem setSubmenu:stepMenu]; |
| 1393 | [stepMenu release]; |
| 1394 | [[stepMenu addItemWithTitle:@"Into" |
| 1395 | action:@selector(debugStepInto:) |
| 1396 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF11FunctionKey]] |
| 1397 | setKeyEquivalentModifierMask:0]; |
| 1398 | [[stepMenu addItemWithTitle:@"Over" |
| 1399 | action:@selector(debugStepOver:) |
| 1400 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF10FunctionKey]] |
| 1401 | setKeyEquivalentModifierMask:0]; |
| 1402 | [[stepMenu addItemWithTitle:@"Out" |
| 1403 | action:@selector(debugStepOut:) |
| 1404 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF10FunctionKey]] |
| 1405 | setKeyEquivalentModifierMask:NSShiftKeyMask]; |
| 1406 | } |
| 1407 | { |
| 1408 | NSMenuItem *resetParentItem = [menu addItemWithTitle:@"Reset" action:NULL keyEquivalent:@""]; |
| 1409 | NSMenu *resetMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Reset"]; |
| 1410 | [resetParentItem setSubmenu:resetMenu]; |
| 1411 | [resetMenu release]; |
| 1412 | [[resetMenu addItemWithTitle:@"Soft" |
| 1413 | action:@selector(debugSoftReset:) |
| 1414 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF3FunctionKey]] |
| 1415 | setKeyEquivalentModifierMask:0]; |
| 1416 | [[resetMenu addItemWithTitle:@"Hard" |
| 1417 | action:@selector(debugHardReset:) |
| 1418 | keyEquivalent:[NSString stringWithFormat:@"%C", NSF3FunctionKey]] |
| 1419 | setKeyEquivalentModifierMask:NSShiftKeyMask]; |
| 1420 | } |
| 1421 | [menu addItem:[NSMenuItem separatorItem]]; |
| 1422 | { |
| 1423 | NSMenuItem *newParentItem = [menu addItemWithTitle:@"New" action:NULL keyEquivalent:@""]; |
| 1424 | NSMenu *newMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"New"]; |
| 1425 | [newParentItem setSubmenu:newMenu]; |
| 1426 | [newMenu release]; |
| 1427 | [newMenu addItemWithTitle:@"Memory Window" |
| 1428 | action:@selector(debugNewMemoryWindow:) |
| 1429 | keyEquivalent:@"d"]; |
| 1430 | [newMenu addItemWithTitle:@"Disassembly Window" |
| 1431 | action:@selector(debugNewDisassemblyWindow:) |
| 1432 | keyEquivalent:@"a"]; |
| 1433 | [newMenu addItemWithTitle:@"Error Log Window" |
| 1434 | action:@selector(debugNewErrorLogWindow:) |
| 1435 | keyEquivalent:@"l"]; |
| 1436 | } |
| 1437 | [menu addItem:[NSMenuItem separatorItem]]; |
| 1438 | [menu addItemWithTitle:@"Close Window" action:@selector(performClose:) keyEquivalent:@"w"]; |
| 1439 | [menu addItemWithTitle:@"Exit" action:@selector(debugExit:) keyEquivalent:@""]; |
| 1440 | } |
| 1441 | |
| 1442 | |
| 1443 | + (NSPopUpButton *)newActionButtonWithFrame:(NSRect)frame { |
| 1444 | NSPopUpButton *actionButton = [[NSPopUpButton alloc] initWithFrame:frame pullsDown:YES]; |
| 1445 | [actionButton setTitle:@""]; |
| 1446 | [actionButton addItemWithTitle:@""]; |
| 1447 | [actionButton setBezelStyle:NSShadowlessSquareBezelStyle]; |
| 1448 | [actionButton setFocusRingType:NSFocusRingTypeNone]; |
| 1449 | [[actionButton cell] setArrowPosition:NSPopUpArrowAtCenter]; |
| 1450 | [[self class] addCommonActionItems:[actionButton menu]]; |
| 1451 | return actionButton; |
| 1452 | } |
| 1453 | |
| 1454 | |
| 1455 | - (id)initWithMachine:(running_machine *)m title:(NSString *)t { |
| 1456 | if (!(self = [super init])) |
| 1457 | return nil; |
| 1458 | |
| 1459 | window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 320, 240) |
| 1460 | styleMask:(NSTitledWindowMask | |
| 1461 | NSClosableWindowMask | |
| 1462 | NSMiniaturizableWindowMask | |
| 1463 | NSResizableWindowMask) |
| 1464 | backing:NSBackingStoreBuffered |
| 1465 | defer:YES]; |
| 1466 | [window setReleasedWhenClosed:NO]; |
| 1467 | [window setDelegate:self]; |
| 1468 | [window setTitle:t]; |
| 1469 | [window setContentMinSize:NSMakeSize(320, 240)]; |
| 1470 | |
| 1471 | [[NSNotificationCenter defaultCenter] addObserver:self |
| 1472 | selector:@selector(showDebugger:) |
| 1473 | name:MAMEShowDebuggerNotification |
| 1474 | object:nil]; |
| 1475 | [[NSNotificationCenter defaultCenter] addObserver:self |
| 1476 | selector:@selector(hideDebugger:) |
| 1477 | name:MAMEHideDebuggerNotification |
| 1478 | object:nil]; |
| 1479 | |
| 1480 | machine = m; |
| 1481 | |
| 1482 | return self; |
| 1483 | } |
| 1484 | |
| 1485 | |
| 1486 | - (void)dealloc { |
| 1487 | [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 1488 | |
| 1489 | if (window != nil) |
| 1490 | [window release]; |
| 1491 | |
| 1492 | [super dealloc]; |
| 1493 | } |
| 1494 | |
| 1495 | |
| 1496 | - (void)activate { |
| 1497 | [window makeKeyAndOrderFront:self]; |
| 1498 | } |
| 1499 | |
| 1500 | |
| 1501 | - (IBAction)debugRun:(id)sender { |
| 1502 | debug_cpu_go(machine, ~0); |
| 1503 | } |
| 1504 | |
| 1505 | |
| 1506 | - (IBAction)debugRunAndHide:(id)sender { |
| 1507 | [[NSNotificationCenter defaultCenter] postNotificationName:MAMEHideDebuggerNotification object:self]; |
| 1508 | debug_cpu_go(machine, ~0); |
| 1509 | } |
| 1510 | |
| 1511 | |
| 1512 | - (IBAction)debugRunToNextCPU:(id)sender { |
| 1513 | debug_cpu_next_cpu(machine); |
| 1514 | } |
| 1515 | |
| 1516 | |
| 1517 | - (IBAction)debugRunToNextInterrupt:(id)sender { |
| 1518 | debug_cpu_go_interrupt(machine, -1); |
| 1519 | } |
| 1520 | |
| 1521 | |
| 1522 | - (IBAction)debugRunToNextVBLANK:(id)sender { |
| 1523 | debug_cpu_go_vblank(machine); |
| 1524 | } |
| 1525 | |
| 1526 | |
| 1527 | - (IBAction)debugStepInto:(id)sender { |
| 1528 | debug_cpu_single_step(machine, 1); |
| 1529 | } |
| 1530 | |
| 1531 | |
| 1532 | - (IBAction)debugStepOver:(id)sender { |
| 1533 | debug_cpu_single_step_over(machine, 1); |
| 1534 | } |
| 1535 | |
| 1536 | |
| 1537 | - (IBAction)debugStepOut:(id)sender { |
| 1538 | debug_cpu_single_step_out(machine); |
| 1539 | } |
| 1540 | |
| 1541 | |
| 1542 | - (IBAction)debugSoftReset:(id)sender { |
| 1543 | mame_schedule_soft_reset(machine); |
| 1544 | } |
| 1545 | |
| 1546 | |
| 1547 | - (IBAction)debugHardReset:(id)sender { |
| 1548 | mame_schedule_hard_reset(machine); |
| 1549 | } |
| 1550 | |
| 1551 | |
| 1552 | - (IBAction)debugExit:(id)sender { |
| 1553 | mame_schedule_exit(machine); |
| 1554 | } |
| 1555 | |
| 1556 | |
| 1557 | - (void)showDebugger:(NSNotification *)notification { |
| 1558 | const device_config *device = [[[notification userInfo] objectForKey:@"MAMEDebugDevice"] pointerValue]; |
| 1559 | if (device->machine == machine) { |
| 1560 | if (![window isVisible] && ![window isMiniaturized]) |
| 1561 | [window orderFront:self]; |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | |
| 1566 | - (void)hideDebugger:(NSNotification *)notification { |
| 1567 | [window orderOut:self]; |
| 1568 | } |
| 1569 | |
| 1570 | @end |
| 1571 | |
| 1572 | |
| 1573 | |
| 1574 | //============================================================ |
| 1575 | // MAMEDebugConsole class |
| 1576 | //============================================================ |
| 1577 | |
| 1578 | @implementation MAMEDebugConsole |
| 1579 | |
| 1580 | - (id)initWithMachine:(running_machine *)m { |
| 1581 | NSSplitView *regSplit, *dasmSplit; |
| 1582 | NSScrollView *regScroll, *dasmScroll, *consoleScroll; |
| 1583 | NSView *consoleContainer; |
| 1584 | NSPopUpButton *actionButton; |
| 1585 | NSRect rct; |
| 1586 | |
| 1587 | // initialise superclass |
| 1588 | if (!(self = [super initWithMachine:m title:@"Debug"])) |
| 1589 | return nil; |
| 1590 | history = [[MAMEDebugCommandHistory alloc] init]; |
| 1591 | auxiliaryWindows = [[NSMutableArray alloc] init]; |
| 1592 | |
| 1593 | // create the register view |
| 1594 | regView = [[MAMERegistersView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) machine:machine]; |
| 1595 | regScroll = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; |
| 1596 | [regScroll setDrawsBackground:YES]; |
| 1597 | [regScroll setHasHorizontalScroller:YES]; |
| 1598 | [regScroll setHasVerticalScroller:YES]; |
| 1599 | [regScroll setAutohidesScrollers:YES]; |
| 1600 | [regScroll setBorderType:NSBezelBorder]; |
| 1601 | [regScroll setDocumentView:regView]; |
| 1602 | [regView release]; |
| 1603 | |
| 1604 | // create the disassembly view |
| 1605 | dasmView = [[MAMEDisassemblyView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) |
| 1606 | machine:machine |
| 1607 | useConsole:YES]; |
| 1608 | [dasmView setExpression:@"curpc"]; |
| 1609 | dasmScroll = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; |
| 1610 | [dasmScroll setDrawsBackground:YES]; |
| 1611 | [dasmScroll setHasHorizontalScroller:YES]; |
| 1612 | [dasmScroll setHasVerticalScroller:YES]; |
| 1613 | [dasmScroll setAutohidesScrollers:YES]; |
| 1614 | [dasmScroll setBorderType:NSBezelBorder]; |
| 1615 | [dasmScroll setDocumentView:dasmView]; |
| 1616 | [dasmView release]; |
| 1617 | |
| 1618 | // create the console view |
| 1619 | consoleView = [[MAMEConsoleView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) machine:machine]; |
| 1620 | consoleScroll = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; |
| 1621 | [consoleScroll setDrawsBackground:YES]; |
| 1622 | [consoleScroll setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; |
| 1623 | [consoleScroll setHasHorizontalScroller:YES]; |
| 1624 | [consoleScroll setHasVerticalScroller:YES]; |
| 1625 | [consoleScroll setAutohidesScrollers:YES]; |
| 1626 | [consoleScroll setBorderType:NSBezelBorder]; |
| 1627 | [consoleScroll setDocumentView:consoleView]; |
| 1628 | [consoleView release]; |
| 1629 | |
| 1630 | // create the command field |
| 1631 | commandField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 19)]; |
| 1632 | [commandField setAutoresizingMask:(NSViewWidthSizable | NSViewMaxYMargin)]; |
| 1633 | [commandField setFont:[[MAMEDebugView class] defaultFont]]; |
| 1634 | [commandField setFocusRingType:NSFocusRingTypeNone]; |
| 1635 | [commandField setTarget:self]; |
| 1636 | [commandField setAction:@selector(doCommand:)]; |
| 1637 | [commandField setDelegate:self]; |
| 1638 | rct = [commandField frame]; |
| 1639 | [commandField setFrame:NSMakeRect(rct.size.height, 0, rct.size.width - rct.size.height, rct.size.height)]; |
| 1640 | |
| 1641 | // create the action pull-down button |
| 1642 | actionButton = [[self class] newActionButtonWithFrame:NSMakeRect(0, 0, rct.size.height, rct.size.height)]; |
| 1643 | [actionButton setAutoresizingMask:(NSViewMaxXMargin | NSViewMaxYMargin)]; |
| 1644 | [dasmView insertActionItemsInMenu:[actionButton menu] atIndex:1]; |
| 1645 | |
| 1646 | // create the container for the console and command input field |
| 1647 | consoleContainer = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; |
| 1648 | [consoleScroll setFrame:NSMakeRect(0, |
| 1649 | rct.size.height, |
| 1650 | 100, |
| 1651 | [consoleContainer bounds].size.height - rct.size.height)]; |
| 1652 | [consoleContainer addSubview:consoleScroll]; |
| 1653 | [consoleContainer addSubview:commandField]; |
| 1654 | [consoleContainer addSubview:actionButton]; |
| 1655 | [consoleScroll release]; |
| 1656 | [commandField release]; |
| 1657 | [actionButton release]; |
| 1658 | |
| 1659 | // create the split between the disassembly and the console |
| 1660 | dasmSplit = [[NSSplitView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; |
| 1661 | [dasmSplit setDelegate:self]; |
| 1662 | [dasmSplit setVertical:NO]; |
| 1663 | [dasmSplit addSubview:dasmScroll]; |
| 1664 | [dasmSplit addSubview:consoleContainer]; |
| 1665 | [dasmScroll release]; |
| 1666 | [consoleContainer release]; |
| 1667 | |
| 1668 | // create the split between the registers and the console |
| 1669 | regSplit = [[NSSplitView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; |
| 1670 | [regSplit setDelegate:self]; |
| 1671 | [regSplit setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; |
| 1672 | [regSplit setVertical:YES]; |
| 1673 | [regSplit addSubview:regScroll]; |
| 1674 | [regSplit addSubview:dasmSplit]; |
| 1675 | [regScroll release]; |
| 1676 | [dasmSplit release]; |
| 1677 | |
| 1678 | // put the split views in the window and get them into a half-reasonable state |
| 1679 | [window setContentView:regSplit]; |
| 1680 | [regSplit release]; |
| 1681 | [regSplit adjustSubviews]; |
| 1682 | [dasmSplit adjustSubviews]; |
| 1683 | |
| 1684 | // keyboard focus should start on the command field |
| 1685 | [window makeFirstResponder:commandField]; |
| 1686 | |
| 1687 | // calculate the optimal size for everything |
| 1688 | { |
| 1689 | NSRect available = [[NSScreen mainScreen] visibleFrame]; |
| 1690 | NSRect windowFrame = [window frame]; |
| 1691 | NSSize regCurrent = [regScroll frame].size; |
| 1692 | NSSize regSize = [NSScrollView frameSizeForContentSize:[regView maximumFrameSize] |
| 1693 | hasHorizontalScroller:YES |
| 1694 | hasVerticalScroller:YES |
| 1695 | borderType:[regScroll borderType]]; |
| 1696 | NSSize dasmCurrent = [dasmScroll frame].size; |
| 1697 | NSSize dasmSize = [NSScrollView frameSizeForContentSize:[dasmView maximumFrameSize] |
| 1698 | hasHorizontalScroller:YES |
| 1699 | hasVerticalScroller:YES |
| 1700 | borderType:[dasmScroll borderType]]; |
| 1701 | NSSize consoleCurrent = [consoleContainer frame].size; |
| 1702 | NSSize consoleSize = [NSScrollView frameSizeForContentSize:[consoleView maximumFrameSize] |
| 1703 | hasHorizontalScroller:YES |
| 1704 | hasVerticalScroller:YES |
| 1705 | borderType:[consoleScroll borderType]]; |
| 1706 | NSSize adjustment; |
| 1707 | NSRect lhsFrame, rhsFrame; |
| 1708 | |
| 1709 | consoleSize.width += consoleCurrent.width - [consoleScroll frame].size.width; |
| 1710 | consoleSize.height += consoleCurrent.height - [consoleScroll frame].size.height; |
| 1711 | adjustment.width = regSize.width - regCurrent.width; |
| 1712 | adjustment.height = regSize.height - regCurrent.height; |
| 1713 | adjustment.width += MAX(dasmSize.width - dasmCurrent.width, consoleSize.width - consoleCurrent.width); |
| 1714 | |
| 1715 | windowFrame.size.width += adjustment.width; |
| 1716 | windowFrame.size.height += adjustment.height; // not used - better to go for fixed height |
| 1717 | windowFrame.size.height = MIN(512.0, available.size.height); |
| 1718 | windowFrame.size.width = MIN(windowFrame.size.width, available.size.width); |
| 1719 | windowFrame.origin.x = available.origin.x + available.size.width - windowFrame.size.width; |
| 1720 | windowFrame.origin.y = available.origin.y; |
| 1721 | [window setFrame:windowFrame display:YES]; |
| 1722 | |
| 1723 | lhsFrame = [regScroll frame]; |
| 1724 | rhsFrame = [dasmSplit frame]; |
| 1725 | adjustment.width = MIN(regSize.width, ([regSplit frame].size.width - [regSplit dividerThickness]) / 2); |
| 1726 | rhsFrame.origin.x -= lhsFrame.size.width - adjustment.width; |
| 1727 | rhsFrame.size.width += lhsFrame.size.width - adjustment.width; |
| 1728 | lhsFrame.size.width = adjustment.width; |
| 1729 | [regScroll setFrame:lhsFrame]; |
| 1730 | [dasmSplit setFrame:rhsFrame]; |
| 1731 | } |
| 1732 | |
| 1733 | // select the current processor |
| 1734 | [self setCPU:machine->firstcpu]; |
| 1735 | |
| 1736 | [[NSNotificationCenter defaultCenter] addObserver:self |
| 1737 | selector:@selector(auxiliaryWindowWillClose:) |
| 1738 | name:MAMEAuxiliaryDebugWindowWillCloseNotification |
| 1739 | object:nil]; |
| 1740 | |
| 1741 | // don't forget the return value |
| 1742 | return self; |
| 1743 | } |
| 1744 | |
| 1745 | |
| 1746 | - (void)dealloc { |
| 1747 | [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 1748 | |
| 1749 | if (history != nil) |
| 1750 | [history release]; |
| 1751 | if (auxiliaryWindows != nil) |
| 1752 | [auxiliaryWindows release]; |
| 1753 | |
| 1754 | [super dealloc]; |
| 1755 | } |
| 1756 | |
| 1757 | |
| 1758 | - (void)setCPU:(const device_config *)device { |
| 1759 | [regView selectSubviewForCPU:device]; |
| 1760 | [dasmView selectSubviewForCPU:device]; |
| 1761 | [window setTitle:[NSString stringWithFormat:@"Debug: %s - %@", |
| 1762 | device->machine->gamedrv->name, |
| 1763 | [regView selectedSubviewName]]]; |
| 1764 | } |
| 1765 | |
| 1766 | |
| 1767 | - (IBAction)doCommand:(id)sender { |
| 1768 | NSString *command = [sender stringValue]; |
| 1769 | if ([command length] == 0) { |
| 1770 | debug_cpu_single_step(machine, 1); |
| 1771 | } else { |
| 1772 | debug_console_execute_command(machine, [command UTF8String], 1); |
| 1773 | [history add:command]; |
| 1774 | } |
| 1775 | [sender setStringValue:@""]; |
| 1776 | } |
| 1777 | |
| 1778 | |
| 1779 | - (IBAction)debugNewMemoryWindow:(id)sender { |
| 1780 | MAMEMemoryViewer *win = [[MAMEMemoryViewer alloc] initWithMachine:machine console:self]; |
| 1781 | [auxiliaryWindows addObject:win]; |
| 1782 | [win release]; |
| 1783 | [win activate]; |
| 1784 | } |
| 1785 | |
| 1786 | |
| 1787 | - (IBAction)debugNewDisassemblyWindow:(id)sender { |
| 1788 | MAMEDisassemblyViewer *win = [[MAMEDisassemblyViewer alloc] initWithMachine:machine console:self]; |
| 1789 | [auxiliaryWindows addObject:win]; |
| 1790 | [win release]; |
| 1791 | [win activate]; |
| 1792 | } |
| 1793 | |
| 1794 | |
| 1795 | - (IBAction)debugNewErrorLogWindow:(id)sender { |
| 1796 | MAMEDisassemblyViewer *win = [[MAMEErrorLogViewer alloc] initWithMachine:machine console:self]; |
| 1797 | [auxiliaryWindows addObject:win]; |
| 1798 | [win release]; |
| 1799 | [win activate]; |
| 1800 | } |
| 1801 | |
| 1802 | |
| 1803 | - (void)showDebugger:(NSNotification *)notification { |
| 1804 | const device_config *device = [[[notification userInfo] objectForKey:@"MAMEDebugDevice"] pointerValue]; |
| 1805 | if (device->machine == machine) { |
| 1806 | [self setCPU:device]; |
| 1807 | [window makeKeyAndOrderFront:self]; |
| 1808 | } |
| 1809 | } |
| 1810 | |
| 1811 | |
| 1812 | - (void)auxiliaryWindowWillClose:(NSNotification *)notification { |
| 1813 | [auxiliaryWindows removeObjectIdenticalTo:[notification object]]; |
| 1814 | } |
| 1815 | |
| 1816 | |
| 1817 | - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command { |
| 1818 | if (control == commandField) { |
| 1819 | if (command == @selector(cancelOperation:)) { |
| 1820 | [commandField setStringValue:@""]; |
| 1821 | [history reset]; |
| 1822 | return YES; |
| 1823 | } else if (command == @selector(moveUp:)) { |
| 1824 | NSString *hist = [history previous:[commandField stringValue]]; |
| 1825 | if (hist != nil) { |
| 1826 | [commandField setStringValue:hist]; |
| 1827 | [commandField selectText:self]; |
| 1828 | [(NSText *)[window firstResponder] setSelectedRange:NSMakeRange([hist length], 0)]; |
| 1829 | } |
| 1830 | return YES; |
| 1831 | } else if (command == @selector(moveDown:)) { |
| 1832 | NSString *hist = [history next:[commandField stringValue]]; |
| 1833 | if (hist != nil) { |
| 1834 | [commandField setStringValue:hist]; |
| 1835 | [commandField selectText:self]; |
| 1836 | [(NSText *)[window firstResponder] setSelectedRange:NSMakeRange([hist length], 0)]; |
| 1837 | } |
| 1838 | return YES; |
| 1839 | } |
| 1840 | } |
| 1841 | return NO; |
| 1842 | } |
| 1843 | |
| 1844 | |
| 1845 | - (void)windowWillClose:(NSNotification *)notification { |
| 1846 | if ([notification object] != window) |
| 1847 | return; |
| 1848 | [[NSNotificationCenter defaultCenter] postNotificationName:MAMEHideDebuggerNotification object:self]; |
| 1849 | debug_cpu_go(machine, ~0); |
| 1850 | } |
| 1851 | |
| 1852 | |
| 1853 | - (CGFloat)splitView:(NSSplitView *)sender constrainMinCoordinate:(CGFloat)min ofSubviewAt:(NSInteger)offs { |
| 1854 | return (min < 100) ? 100 : min; |
| 1855 | } |
| 1856 | |
| 1857 | |
| 1858 | - (CGFloat)splitView:(NSSplitView *)sender constrainMaxCoordinate:(CGFloat)max ofSubviewAt:(NSInteger)offs { |
| 1859 | NSSize sz = [sender bounds].size; |
| 1860 | CGFloat allowed = ([sender isVertical] ? sz.width : sz.height) - 100 - [sender dividerThickness]; |
| 1861 | return (max > allowed) ? allowed : max; |
| 1862 | } |
| 1863 | |
| 1864 | |
| 1865 | - (BOOL)splitView:(NSSplitView *)sender canCollapseSubview:(NSView *)subview { |
| 1866 | // allow registers or disassembly to be collapsed, but not console |
| 1867 | return [[sender subviews] indexOfObjectIdenticalTo:subview] == 0; |
| 1868 | } |
| 1869 | |
| 1870 | |
| 1871 | - (void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:(NSSize)oldSize { |
| 1872 | // This can only deal with a single split, but that's all we use, anyway |
| 1873 | NSRect first, second; |
| 1874 | [sender adjustSubviews]; |
| 1875 | first = [[[sender subviews] objectAtIndex:0] frame]; |
| 1876 | second = [[[sender subviews] objectAtIndex:1] frame]; |
| 1877 | if ([sender isVertical]) { |
| 1878 | if (first.size.width < 100) { |
| 1879 | CGFloat diff = 100 - first.size.width; |
| 1880 | first.size.width = 100; |
| 1881 | second.origin.x += diff; |
| 1882 | second.size.width -= diff; |
| 1883 | } else if (second.size.width < 100) { |
| 1884 | CGFloat diff = 100 - second.size.width; |
| 1885 | second.size.width = 100; |
| 1886 | second.origin.x -= diff; |
| 1887 | first.size.width -= diff; |
| 1888 | } |
| 1889 | } else { |
| 1890 | if (first.size.height < 100) { |
| 1891 | CGFloat diff = 100 - first.size.height; |
| 1892 | first.size.height = 100; |
| 1893 | second.origin.y += diff; |
| 1894 | second.size.height -= diff; |
| 1895 | } else if (second.size.height < 100) { |
| 1896 | CGFloat diff = 100 - second.size.height; |
| 1897 | second.size.height = 100; |
| 1898 | second.origin.y -= diff; |
| 1899 | first.size.height -= diff; |
| 1900 | } |
| 1901 | } |
| 1902 | [[[sender subviews] objectAtIndex:0] setFrame:first]; |
| 1903 | [[[sender subviews] objectAtIndex:1] setFrame:second]; |
| 1904 | } |
| 1905 | |
| 1906 | @end |
| 1907 | |
| 1908 | |
| 1909 | //============================================================ |
| 1910 | // MAMEAuxiliaryDebugWindowHandler class |
| 1911 | //============================================================ |
| 1912 | |
| 1913 | @implementation MAMEAuxiliaryDebugWindowHandler |
| 1914 | |
| 1915 | + (void)cascadeWindow:(NSWindow *)window { |
| 1916 | static NSPoint lastPosition = { 0, 0 }; |
| 1917 | if (NSEqualPoints(lastPosition, NSZeroPoint)) { |
| 1918 | NSRect available = [[NSScreen mainScreen] visibleFrame]; |
| 1919 | lastPosition = NSMakePoint(available.origin.x + 12, available.origin.y + available.size.height - 8); |
| 1920 | } |
| 1921 | lastPosition = [window cascadeTopLeftFromPoint:lastPosition]; |
| 1922 | } |
| 1923 | |
| 1924 | |
| 1925 | - (id)initWithMachine:(running_machine *)m title:(NSString *)t console:(MAMEDebugConsole *)c { |
| 1926 | if (!(self = [super initWithMachine:m title:t])) |
| 1927 | return nil; |
| 1928 | console = c; |
| 1929 | return self; |
| 1930 | } |
| 1931 | |
| 1932 | |
| 1933 | - (void)dealloc { |
| 1934 | [super dealloc]; |
| 1935 | } |
| 1936 | |
| 1937 | |
| 1938 | - (IBAction)debugNewMemoryWindow:(id)sender { |
| 1939 | [console debugNewMemoryWindow:sender]; |
| 1940 | } |
| 1941 | |
| 1942 | |
| 1943 | - (IBAction)debugNewDisassemblyWindow:(id)sender { |
| 1944 | [console debugNewDisassemblyWindow:sender]; |
| 1945 | } |
| 1946 | |
| 1947 | |
| 1948 | - (IBAction)debugNewErrorLogWindow:(id)sender { |
| 1949 | [console debugNewErrorLogWindow:sender]; |
| 1950 | } |
| 1951 | |
| 1952 | |
| 1953 | - (void)windowWillClose:(NSNotification *)notification { |
| 1954 | [[NSNotificationCenter defaultCenter] postNotificationName:MAMEAuxiliaryDebugWindowWillCloseNotification |
| 1955 | object:self]; |
| 1956 | } |
| 1957 | |
| 1958 | - (void)cascadeWindowWithDesiredSize:(NSSize)desired forView:(NSView *)view { |
| 1959 | NSRect available = [[NSScreen mainScreen] visibleFrame]; |
| 1960 | NSRect windowFrame = [window frame]; |
| 1961 | NSSize current = [view frame].size; |
| 1962 | |
| 1963 | desired.width -= current.width; |
| 1964 | desired.height -= current.height; |
| 1965 | |
| 1966 | windowFrame.size.width += desired.width; |
| 1967 | windowFrame.size.height += desired.height; |
| 1968 | windowFrame.size.height = MIN(MIN(windowFrame.size.height, 240), available.size.height); |
| 1969 | windowFrame.size.width = MIN(windowFrame.size.width, available.size.width); |
| 1970 | windowFrame.origin.x = available.origin.x + available.size.width - windowFrame.size.width; |
| 1971 | windowFrame.origin.y = available.origin.y; |
| 1972 | [window setFrame:windowFrame display:YES]; |
| 1973 | [[self class] cascadeWindow:window]; |
| 1974 | |
| 1975 | windowFrame = [[window contentView] frame]; |
| 1976 | desired = [window contentMinSize]; |
| 1977 | [window setContentMinSize:NSMakeSize(MIN(windowFrame.size.width, desired.width), |
| 1978 | MIN(windowFrame.size.height, desired.height))]; |
| 1979 | } |
| 1980 | |
| 1981 | @end |
| 1982 | |
| 1983 | |
| 1984 | //============================================================ |
| 1985 | // MAMEExpreesionAuxiliaryDebugWindowHandler class |
| 1986 | //============================================================ |
| 1987 | |
| 1988 | @implementation MAMEExpressionAuxiliaryDebugWindowHandler |
| 1989 | |
| 1990 | - (id)initWithMachine:(running_machine *)m title:(NSString *)t console:(MAMEDebugConsole *)c { |
| 1991 | if (!(self = [super initWithMachine:m title:t console:c])) |
| 1992 | return nil; |
| 1993 | history = [[MAMEDebugCommandHistory alloc] init]; |
| 1994 | return self; |
| 1995 | } |
| 1996 | |
| 1997 | |
| 1998 | - (void)dealloc { |
| 1999 | if (history != nil) |
| 2000 | [history release]; |
| 2001 | [super dealloc]; |
| 2002 | } |
| 2003 | |
| 2004 | |
| 2005 | - (id <MAMEDebugViewExpressionSupport>)documentView { |
| 2006 | return nil; |
| 2007 | } |
| 2008 | |
| 2009 | |
| 2010 | - (IBAction)doExpression:(id)sender { |
| 2011 | NSString *expr = [sender stringValue]; |
| 2012 | if ([expr length] > 0) { |
| 2013 | [history add:expr]; |
| 2014 | [[self documentView] setExpression:expr]; |
| 2015 | } else { |
| 2016 | [sender setStringValue:[[self documentView] expression]]; |
| 2017 | [history reset]; |
| 2018 | } |
| 2019 | [sender selectText:self]; |
| 2020 | } |
| 2021 | |
| 2022 | |
| 2023 | - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command { |
| 2024 | if (control == expressionField) { |
| 2025 | if (command == @selector(cancelOperation:)) { |
| 2026 | [history reset]; |
| 2027 | [expressionField setStringValue:[[self documentView] expression]]; |
| 2028 | [expressionField selectText:self]; |
| 2029 | return YES; |
| 2030 | } else if (command == @selector(moveUp:)) { |
| 2031 | NSString *hist = [history previous:[expressionField stringValue]]; |
| 2032 | if (hist != nil) { |
| 2033 | [expressionField setStringValue:hist]; |
| 2034 | [expressionField selectText:self]; |
| 2035 | } |
| 2036 | return YES; |
| 2037 | } else if (command == @selector(moveDown:)) { |
| 2038 | NSString *hist = [history next:[expressionField stringValue]]; |
| 2039 | if (hist != nil) { |
| 2040 | [expressionField setStringValue:hist]; |
| 2041 | [expressionField selectText:self]; |
| 2042 | } |
| 2043 | return YES; |
| 2044 | } |
| 2045 | } |
| 2046 | return NO; |
| 2047 | } |
| 2048 | |
| 2049 | @end |
| 2050 | |
| 2051 | |
| 2052 | //============================================================ |
| 2053 | // MAMEMemoryViewer class |
| 2054 | //============================================================ |
| 2055 | |
| 2056 | @implementation MAMEMemoryViewer |
| 2057 | |
| 2058 | - (id)initWithMachine:(running_machine *)m console:(MAMEDebugConsole *)c { |
| 2059 | NSScrollView *memoryScroll; |
| 2060 | NSView *expressionContainer; |
| 2061 | NSPopUpButton *actionButton, *subviewButton; |
| 2062 | NSRect contentBounds, expressionFrame; |
| 2063 | |
| 2064 | if (!(self = [super initWithMachine:m title:@"Memory" console:c])) |
| 2065 | return nil; |
| 2066 | contentBounds = [[window contentView] bounds]; |
| 2067 | |
| 2068 | // create the expression field |
| 2069 | expressionField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 19)]; |
| 2070 | [expressionField setAutoresizingMask:(NSViewWidthSizable | NSViewMaxXMargin | NSViewMinYMargin)]; |
| 2071 | [expressionField setFont:[[MAMEDebugView class] defaultFont]]; |
| 2072 | [expressionField setFocusRingType:NSFocusRingTypeNone]; |
| 2073 | [expressionField setTarget:self]; |
| 2074 | [expressionField setAction:@selector(doExpression:)]; |
| 2075 | [expressionField setDelegate:self]; |
| 2076 | expressionFrame = [expressionField frame]; |
| 2077 | expressionFrame.size.width = (contentBounds.size.width - expressionFrame.size.height) / 2; |
| 2078 | [expressionField setFrameSize:expressionFrame.size]; |
| 2079 | |
| 2080 | // create the subview popup |
| 2081 | subviewButton = [[NSPopUpButton alloc] initWithFrame:NSOffsetRect(expressionFrame, |
| 2082 | expressionFrame.size.width, |
| 2083 | 0)]; |
| 2084 | [subviewButton setAutoresizingMask:(NSViewWidthSizable | NSViewMinXMargin | NSViewMinYMargin)]; |
| 2085 | [subviewButton setBezelStyle:NSShadowlessSquareBezelStyle]; |
| 2086 | [subviewButton setFocusRingType:NSFocusRingTypeNone]; |
| 2087 | [subviewButton setFont:[[MAMEDebugView class] defaultFont]]; |
| 2088 | [subviewButton setTarget:self]; |
| 2089 | [subviewButton setAction:@selector(changeSubview:)]; |
| 2090 | [[subviewButton cell] setArrowPosition:NSPopUpArrowAtBottom]; |
| 2091 | |
| 2092 | // create a container for the expression field and subview popup |
| 2093 | expressionFrame = NSMakeRect(expressionFrame.size.height, |
| 2094 | contentBounds.size.height - expressionFrame.size.height, |
| 2095 | contentBounds.size.width - expressionFrame.size.height, |
| 2096 | expressionFrame.size.height); |
| 2097 | expressionContainer = [[NSView alloc] initWithFrame:expressionFrame]; |
| 2098 | [expressionContainer setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)]; |
| 2099 | [expressionContainer addSubview:expressionField]; |
| 2100 | [expressionField release]; |
| 2101 | [expressionContainer addSubview:subviewButton]; |
| 2102 | [subviewButton release]; |
| 2103 | [[window contentView] addSubview:expressionContainer]; |
| 2104 | [expressionContainer release]; |
| 2105 | |
| 2106 | // create the memory view |
| 2107 | memoryView = [[MAMEMemoryView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) |
| 2108 | machine:machine]; |
| 2109 | [memoryView insertSubviewItemsInMenu:[subviewButton menu] atIndex:0]; |
| 2110 | memoryScroll = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, |
| 2111 | 0, |
| 2112 | contentBounds.size.width, |
| 2113 | expressionFrame.origin.y)]; |
| 2114 | [memoryScroll setDrawsBackground:YES]; |
| 2115 | [memoryScroll setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; |
| 2116 | [memoryScroll setHasHorizontalScroller:YES]; |
| 2117 | [memoryScroll setHasVerticalScroller:YES]; |
| 2118 | [memoryScroll setAutohidesScrollers:YES]; |
| 2119 | [memoryScroll setBorderType:NSNoBorder]; |
| 2120 | [memoryScroll setDocumentView:memoryView]; |
| 2121 | [memoryView release]; |
| 2122 | [[window contentView] addSubview:memoryScroll]; |
| 2123 | [memoryScroll release]; |
| 2124 | |
| 2125 | // create the action popup |
| 2126 | actionButton = [[self class] newActionButtonWithFrame:NSMakeRect(0, |
| 2127 | expressionFrame.origin.y, |
| 2128 | expressionFrame.size.height, |
| 2129 | expressionFrame.size.height)]; |
| 2130 | [actionButton setAutoresizingMask:(NSViewMaxXMargin | NSViewMinYMargin)]; |
| 2131 | [memoryView insertActionItemsInMenu:[actionButton menu] atIndex:1]; |
| 2132 | [[window contentView] addSubview:actionButton]; |
| 2133 | [actionButton release]; |
| 2134 | |
| 2135 | // set default state |
| 2136 | [memoryView selectSubviewForCPU:debug_cpu_get_visible_cpu(machine)]; |
| 2137 | [memoryView setExpression:@"0"]; |
| 2138 | [expressionField setStringValue:@"0"]; |
| 2139 | [expressionField selectText:self]; |
| 2140 | [subviewButton selectItemAtIndex:[subviewButton indexOfItemWithTag:[memoryView selectedSubviewIndex]]]; |
| 2141 | [window makeFirstResponder:expressionField]; |
| 2142 | [window setTitle:[NSString stringWithFormat:@"Memory: %@", [memoryView selectedSubviewName]]]; |
| 2143 | |
| 2144 | // calculate the optimal size for everything |
| 2145 | { |
| 2146 | NSSize desired = [NSScrollView frameSizeForContentSize:[memoryView maximumFrameSize] |
| 2147 | hasHorizontalScroller:YES |
| 2148 | hasVerticalScroller:YES |
| 2149 | borderType:[memoryScroll borderType]]; |
| 2150 | [self cascadeWindowWithDesiredSize:desired forView:memoryScroll]; |
| 2151 | } |
| 2152 | |
| 2153 | // don't forget the result |
| 2154 | return self; |
| 2155 | } |
| 2156 | |
| 2157 | |
| 2158 | - (void)dealloc { |
| 2159 | [super dealloc]; |
| 2160 | } |
| 2161 | |
| 2162 | |
| 2163 | - (id <MAMEDebugViewExpressionSupport>)documentView { |
| 2164 | return memoryView; |
| 2165 | } |
| 2166 | |
| 2167 | |
| 2168 | - (IBAction)changeSubview:(id)sender { |
| 2169 | [memoryView selectSubviewAtIndex:[[sender selectedItem] tag]]; |
| 2170 | [window setTitle:[NSString stringWithFormat:@"Memory: %@", [memoryView selectedSubviewName]]]; |
| 2171 | } |
| 2172 | |
| 2173 | @end |
| 2174 | |
| 2175 | |
| 2176 | //============================================================ |
| 2177 | // MAMEDisassemblyViewer class |
| 2178 | //============================================================ |
| 2179 | |
| 2180 | @implementation MAMEDisassemblyViewer |
| 2181 | |
| 2182 | - (id)initWithMachine:(running_machine *)m console:(MAMEDebugConsole *)c { |
| 2183 | NSScrollView *dasmScroll; |
| 2184 | NSView *expressionContainer; |
| 2185 | NSPopUpButton *actionButton, *subviewButton; |
| 2186 | NSRect contentBounds, expressionFrame; |
| 2187 | |
| 2188 | if (!(self = [super initWithMachine:m title:@"Disassembly" console:c])) |
| 2189 | return nil; |
| 2190 | contentBounds = [[window contentView] bounds]; |
| 2191 | |
| 2192 | // create the expression field |
| 2193 | expressionField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 19)]; |
| 2194 | [expressionField setAutoresizingMask:(NSViewWidthSizable | NSViewMaxXMargin | NSViewMinYMargin)]; |
| 2195 | [expressionField setFont:[[MAMEDebugView class] defaultFont]]; |
| 2196 | [expressionField setFocusRingType:NSFocusRingTypeNone]; |
| 2197 | [expressionField setTarget:self]; |
| 2198 | [expressionField setAction:@selector(doExpression:)]; |
| 2199 | [expressionField setDelegate:self]; |
| 2200 | expressionFrame = [expressionField frame]; |
| 2201 | expressionFrame.size.width = (contentBounds.size.width - expressionFrame.size.height) / 2; |
| 2202 | [expressionField setFrameSize:expressionFrame.size]; |
| 2203 | |
| 2204 | // create the subview popup |
| 2205 | subviewButton = [[NSPopUpButton alloc] initWithFrame:NSOffsetRect(expressionFrame, |
| 2206 | expressionFrame.size.width, |
| 2207 | 0)]; |
| 2208 | [subviewButton setAutoresizingMask:(NSViewWidthSizable | NSViewMinXMargin | NSViewMinYMargin)]; |
| 2209 | [subviewButton setBezelStyle:NSShadowlessSquareBezelStyle]; |
| 2210 | [subviewButton setFocusRingType:NSFocusRingTypeNone]; |
| 2211 | [subviewButton setFont:[[MAMEDebugView class] defaultFont]]; |
| 2212 | [subviewButton setTarget:self]; |
| 2213 | [subviewButton setAction:@selector(changeSubview:)]; |
| 2214 | [[subviewButton cell] setArrowPosition:NSPopUpArrowAtBottom]; |
| 2215 | |
| 2216 | // create a container for the expression field and subview popup |
| 2217 | expressionFrame = NSMakeRect(expressionFrame.size.height, |
| 2218 | contentBounds.size.height - expressionFrame.size.height, |
| 2219 | contentBounds.size.width - expressionFrame.size.height, |
| 2220 | expressionFrame.size.height); |
| 2221 | expressionContainer = [[NSView alloc] initWithFrame:expressionFrame]; |
| 2222 | [expressionContainer setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)]; |
| 2223 | [expressionContainer addSubview:expressionField]; |
| 2224 | [expressionField release]; |
| 2225 | [expressionContainer addSubview:subviewButton]; |
| 2226 | [subviewButton release]; |
| 2227 | [[window contentView] addSubview:expressionContainer]; |
| 2228 | [expressionContainer release]; |
| 2229 | |
| 2230 | // create the disassembly view |
| 2231 | dasmView = [[MAMEDisassemblyView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) |
| 2232 | machine:machine |
| 2233 | useConsole:NO]; |
| 2234 | [dasmView insertSubviewItemsInMenu:[subviewButton menu] atIndex:0]; |
| 2235 | dasmScroll = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, |
| 2236 | 0, |
| 2237 | contentBounds.size.width, |
| 2238 | expressionFrame.origin.y)]; |
| 2239 | [dasmScroll setDrawsBackground:YES]; |
| 2240 | [dasmScroll setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; |
| 2241 | [dasmScroll setHasHorizontalScroller:YES]; |
| 2242 | [dasmScroll setHasVerticalScroller:YES]; |
| 2243 | [dasmScroll setAutohidesScrollers:YES]; |
| 2244 | [dasmScroll setBorderType:NSNoBorder]; |
| 2245 | [dasmScroll setDocumentView:dasmView]; |
| 2246 | [dasmView release]; |
| 2247 | [[window contentView] addSubview:dasmScroll]; |
| 2248 | [dasmScroll release]; |
| 2249 | |
| 2250 | // create the action popup |
| 2251 | actionButton = [[self class] newActionButtonWithFrame:NSMakeRect(0, |
| 2252 | expressionFrame.origin.y, |
| 2253 | expressionFrame.size.height, |
| 2254 | expressionFrame.size.height)]; |
| 2255 | [actionButton setAutoresizingMask:(NSViewMaxXMargin | NSViewMinYMargin)]; |
| 2256 | [dasmView insertActionItemsInMenu:[actionButton menu] atIndex:1]; |
| 2257 | [[window contentView] addSubview:actionButton]; |
| 2258 | [actionButton release]; |
| 2259 | |
| 2260 | // set default state |
| 2261 | [dasmView selectSubviewForCPU:debug_cpu_get_visible_cpu(machine)]; |
| 2262 | [dasmView setExpression:@"curpc"]; |
| 2263 | [expressionField setStringValue:@"curpc"]; |
| 2264 | [expressionField selectText:self]; |
| 2265 | [subviewButton selectItemAtIndex:[subviewButton indexOfItemWithTag:[dasmView selectedSubviewIndex]]]; |
| 2266 | [window makeFirstResponder:expressionField]; |
| 2267 | [window setTitle:[NSString stringWithFormat:@"Disassembly: %@", [dasmView selectedSubviewName]]]; |
| 2268 | |
| 2269 | // calculate the optimal size for everything |
| 2270 | { |
| 2271 | NSSize desired = [NSScrollView frameSizeForContentSize:[dasmView maximumFrameSize] |
| 2272 | hasHorizontalScroller:YES |
| 2273 | hasVerticalScroller:YES |
| 2274 | borderType:[dasmScroll borderType]]; |
| 2275 | [self cascadeWindowWithDesiredSize:desired forView:dasmScroll]; |
| 2276 | } |
| 2277 | |
| 2278 | // don't forget the result |
| 2279 | return self; |
| 2280 | } |
| 2281 | |
| 2282 | |
| 2283 | - (void)dealloc { |
| 2284 | [super dealloc]; |
| 2285 | } |
| 2286 | |
| 2287 | |
| 2288 | - (id <MAMEDebugViewExpressionSupport>)documentView { |
| 2289 | return dasmView; |
| 2290 | } |
| 2291 | |
| 2292 | |
| 2293 | - (IBAction)changeSubview:(id)sender { |
| 2294 | [dasmView selectSubviewAtIndex:[[sender selectedItem] tag]]; |
| 2295 | [window setTitle:[NSString stringWithFormat:@"Disassembly: %@", [dasmView selectedSubviewName]]]; |
| 2296 | } |
| 2297 | |
| 2298 | @end |
| 2299 | |
| 2300 | |
| 2301 | //============================================================ |
| 2302 | // MAMEErrorLogViewer class |
| 2303 | //============================================================ |
| 2304 | |
| 2305 | @implementation MAMEErrorLogViewer |
| 2306 | |
| 2307 | - (id)initWithMachine:(running_machine *)m console:(MAMEDebugConsole *)c { |
| 2308 | NSScrollView *logScroll; |
| 2309 | NSString *title; |
| 2310 | |
| 2311 | title = [NSString stringWithFormat:@"Error Log: %@ [%@]", |
| 2312 | [NSString stringWithUTF8String:m->gamedrv->description], |
| 2313 | [NSString stringWithUTF8String:m->gamedrv->name]]; |
| 2314 | if (!(self = [super initWithMachine:m title:title console:c])) |
| 2315 | return nil; |
| 2316 | |
| 2317 | // create the error log view |
| 2318 | logView = [[MAMEErrorLogView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) machine:machine]; |
| 2319 | logScroll = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; |
| 2320 | [logScroll setDrawsBackground:YES]; |
| 2321 | [logScroll setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; |
| 2322 | [logScroll setHasHorizontalScroller:YES]; |
| 2323 | [logScroll setHasVerticalScroller:YES]; |
| 2324 | [logScroll setAutohidesScrollers:YES]; |
| 2325 | [logScroll setBorderType:NSNoBorder]; |
| 2326 | [logScroll setDocumentView:logView]; |
| 2327 | [logView release]; |
| 2328 | [window setContentView:logScroll]; |
| 2329 | [logScroll release]; |
| 2330 | |
| 2331 | // calculate the optimal size for everything |
| 2332 | { |
| 2333 | NSSize desired = [NSScrollView frameSizeForContentSize:[logView maximumFrameSize] |
| 2334 | hasHorizontalScroller:YES |
| 2335 | hasVerticalScroller:YES |
| 2336 | borderType:[logScroll borderType]]; |
| 2337 | |
| 2338 | // this thing starts with no content, so its prefered height may be very small |
| 2339 | desired.height = MAX(desired.height, 240); |
| 2340 | [self cascadeWindowWithDesiredSize:desired forView:logScroll]; |
| 2341 | } |
| 2342 | |
| 2343 | // don't forget the result |
| 2344 | return self; |
| 2345 | } |
| 2346 | |
| 2347 | |
| 2348 | - (void)dealloc { |
| 2349 | [super dealloc]; |
| 2350 | } |
| 2351 | |
| 2352 | @end |