src/osd/windows/debugwin.c
| r11868 | r11869 | |
| 44 | 44 | #include <windows.h> |
| 45 | 45 | #include <windowsx.h> |
| 46 | 46 | #include <tchar.h> |
| 47 | #include <commdlg.h> |
| 47 | 48 | #ifdef _MSC_VER |
| 48 | 49 | #include <zmouse.h> |
| 49 | 50 | #endif |
| r11868 | r11869 | |
| 51 | 52 | // MAME headers |
| 52 | 53 | #include "emu.h" |
| 53 | 54 | #include "uiinput.h" |
| 55 | #include "imagedev/cassette.h" |
| 54 | 56 | #include "debugger.h" |
| 55 | 57 | #include "debug/debugvw.h" |
| 56 | 58 | #include "debug/dvdisasm.h" |
| r11868 | r11869 | |
| 138 | 140 | ID_SHOW_ENCRYPTED, |
| 139 | 141 | ID_SHOW_COMMENTS, |
| 140 | 142 | ID_RUN_TO_CURSOR, |
| 141 | | ID_TOGGLE_BREAKPOINT |
| 143 | ID_TOGGLE_BREAKPOINT, |
| 144 | |
| 145 | ID_DEVICE_OPTIONS // keep this always at the end |
| 142 | 146 | }; |
| 143 | 147 | |
| 144 | 148 | |
| r11868 | r11869 | |
| 266 | 270 | static void smart_show_window(HWND wnd, BOOL show); |
| 267 | 271 | static void smart_show_all(BOOL show); |
| 268 | 272 | |
| 273 | static void image_update_menu(debugwin_info *info); |
| 269 | 274 | |
| 270 | | |
| 271 | 275 | //============================================================ |
| 272 | 276 | // wait_for_debugger |
| 273 | 277 | //============================================================ |
| r11868 | r11869 | |
| 2376 | 2380 | } |
| 2377 | 2381 | |
| 2378 | 2382 | |
| 2383 | enum |
| 2384 | { |
| 2385 | DEVOPTION_OPEN, |
| 2386 | DEVOPTION_CREATE, |
| 2387 | DEVOPTION_CLOSE, |
| 2388 | DEVOPTION_CASSETTE_STOPPAUSE, |
| 2389 | DEVOPTION_CASSETTE_PLAY, |
| 2390 | DEVOPTION_CASSETTE_RECORD, |
| 2391 | DEVOPTION_CASSETTE_REWIND, |
| 2392 | DEVOPTION_CASSETTE_FASTFORWARD, |
| 2393 | DEVOPTION_MAX |
| 2394 | }; |
| 2379 | 2395 | |
| 2380 | 2396 | //============================================================ |
| 2397 | // memory_update_menu |
| 2398 | //============================================================ |
| 2399 | |
| 2400 | static void image_update_menu(debugwin_info *info) |
| 2401 | { |
| 2402 | device_image_interface *img = NULL; |
| 2403 | UINT32 cnt = 0; |
| 2404 | HMENU devicesmenu; |
| 2405 | |
| 2406 | DeleteMenu(GetMenu(info->wnd), 2, MF_BYPOSITION); |
| 2407 | |
| 2408 | // create the image menu |
| 2409 | devicesmenu = CreatePopupMenu(); |
| 2410 | for (bool gotone = info->machine().devicelist().first(img); gotone; gotone = img->next(img)) |
| 2411 | { |
| 2412 | astring temp; |
| 2413 | UINT flags_for_exists; |
| 2414 | UINT flags_for_writing; |
| 2415 | HMENU devicesubmenu = CreatePopupMenu(); |
| 2416 | |
| 2417 | UINT_PTR new_item = ID_DEVICE_OPTIONS + (cnt * DEVOPTION_MAX); |
| 2418 | |
| 2419 | flags_for_exists = MF_ENABLED | MF_STRING; |
| 2420 | |
| 2421 | if (!img->exists()) |
| 2422 | flags_for_exists |= MF_GRAYED; |
| 2423 | |
| 2424 | flags_for_writing = flags_for_exists; |
| 2425 | if (img->is_readonly()) |
| 2426 | flags_for_writing |= MF_GRAYED; |
| 2427 | |
| 2428 | AppendMenu(devicesubmenu, MF_STRING, new_item + DEVOPTION_OPEN, TEXT("Mount...")); |
| 2429 | |
| 2430 | /*if (img->is_creatable()) |
| 2431 | AppendMenu(devicesubmenu, MF_STRING, new_item + DEVOPTION_CREATE, TEXT("Create...")); |
| 2432 | */ |
| 2433 | AppendMenu(devicesubmenu, flags_for_exists, new_item + DEVOPTION_CLOSE, TEXT("Unmount")); |
| 2434 | |
| 2435 | if (img->device().type() == CASSETTE) |
| 2436 | { |
| 2437 | cassette_state state; |
| 2438 | state = (cassette_state)(img->exists() ? (cassette_get_state(&img->device()) & CASSETTE_MASK_UISTATE) : CASSETTE_STOPPED); |
| 2439 | AppendMenu(devicesubmenu, MF_SEPARATOR, 0, NULL); |
| 2440 | AppendMenu(devicesubmenu, flags_for_exists | ((state == CASSETTE_STOPPED) ? MF_CHECKED : 0), new_item + DEVOPTION_CASSETTE_STOPPAUSE, TEXT("Pause/Stop")); |
| 2441 | AppendMenu(devicesubmenu, flags_for_exists | ((state == CASSETTE_PLAY) ? MF_CHECKED : 0), new_item + DEVOPTION_CASSETTE_PLAY, TEXT("Play")); |
| 2442 | AppendMenu(devicesubmenu, flags_for_writing | ((state == CASSETTE_RECORD) ? MF_CHECKED : 0), new_item + DEVOPTION_CASSETTE_RECORD, TEXT("Record")); |
| 2443 | AppendMenu(devicesubmenu, flags_for_exists, new_item + DEVOPTION_CASSETTE_REWIND, TEXT("Rewind")); |
| 2444 | AppendMenu(devicesubmenu, flags_for_exists, new_item + DEVOPTION_CASSETTE_FASTFORWARD, TEXT("Fast Forward")); |
| 2445 | } |
| 2446 | |
| 2447 | temp.format("%s :%s", img->device().name(), img->exists() ? img->filename() : "[empty slot]"); |
| 2448 | |
| 2449 | AppendMenu(devicesmenu, MF_ENABLED | MF_POPUP, (UINT_PTR)devicesubmenu, tstring_from_utf8(temp.cstr())); |
| 2450 | |
| 2451 | cnt++; |
| 2452 | } |
| 2453 | AppendMenu(GetMenu(info->wnd), MF_ENABLED | MF_POPUP, (UINT_PTR)devicesmenu, TEXT("Images")); |
| 2454 | |
| 2455 | } |
| 2456 | |
| 2457 | //============================================================ |
| 2381 | 2458 | // console_create_window |
| 2382 | 2459 | //============================================================ |
| 2383 | 2460 | |
| r11868 | r11869 | |
| 2388 | 2465 | RECT bounds, work_bounds; |
| 2389 | 2466 | HMENU optionsmenu; |
| 2390 | 2467 | UINT32 conchars; |
| 2468 | device_image_interface *img = NULL; |
| 2391 | 2469 | |
| 2392 | 2470 | // create the window |
| 2393 | 2471 | info = debugwin_window_create(machine, "Debug", NULL); |
| r11868 | r11869 | |
| 2413 | 2491 | AppendMenu(optionsmenu, MF_ENABLED, ID_SHOW_COMMENTS, TEXT("Comments\tCtrl+N")); |
| 2414 | 2492 | AppendMenu(GetMenu(info->wnd), MF_ENABLED | MF_POPUP, (UINT_PTR)optionsmenu, TEXT("Options")); |
| 2415 | 2493 | |
| 2494 | // Add image menu only if image devices exist |
| 2495 | if (info->machine().devicelist().first(img)) { |
| 2496 | info->update_menu = image_update_menu; |
| 2497 | image_update_menu(info); |
| 2498 | } |
| 2499 | |
| 2416 | 2500 | // set the handlers |
| 2417 | 2501 | info->handle_command = disasm_handle_command; |
| 2418 | 2502 | info->handle_key = disasm_handle_key; |
| r11868 | r11869 | |
| 2647 | 2731 | return menubar; |
| 2648 | 2732 | } |
| 2649 | 2733 | |
| 2734 | //============================================================ |
| 2735 | // copy_extension_list |
| 2736 | //============================================================ |
| 2650 | 2737 | |
| 2738 | static int copy_extension_list(char *dest, size_t dest_len, const char *extensions) |
| 2739 | { |
| 2740 | const char *s; |
| 2741 | int pos = 0; |
| 2651 | 2742 | |
| 2743 | // our extension lists are comma delimited; Win32 expects to see lists |
| 2744 | // delimited by semicolons |
| 2745 | s = extensions; |
| 2746 | while(*s) |
| 2747 | { |
| 2748 | // append a semicolon if not at the beginning |
| 2749 | if (s != extensions) |
| 2750 | pos += snprintf(&dest[pos], dest_len - pos, ";"); |
| 2751 | |
| 2752 | // append ".*" |
| 2753 | pos += snprintf(&dest[pos], dest_len - pos, "*."); |
| 2754 | |
| 2755 | // append the file extension |
| 2756 | while(*s && (*s != ',')) |
| 2757 | { |
| 2758 | pos += snprintf(&dest[pos], dest_len - pos, "%c", *s); |
| 2759 | s++; |
| 2760 | } |
| 2761 | |
| 2762 | // if we found a comma, advance |
| 2763 | while(*s == ',') |
| 2764 | s++; |
| 2765 | } |
| 2766 | return pos; |
| 2767 | } |
| 2768 | |
| 2652 | 2769 | //============================================================ |
| 2770 | // add_filter_entry |
| 2771 | //============================================================ |
| 2772 | |
| 2773 | static int add_filter_entry(char *dest, size_t dest_len, const char *description, const char *extensions) |
| 2774 | { |
| 2775 | int pos = 0; |
| 2776 | |
| 2777 | // add the description |
| 2778 | pos += snprintf(&dest[pos], dest_len - pos, "%s (", description); |
| 2779 | |
| 2780 | // add the extensions to the description |
| 2781 | pos += copy_extension_list(&dest[pos], dest_len - pos, extensions); |
| 2782 | |
| 2783 | // add the trailing rparen and '|' character |
| 2784 | pos += snprintf(&dest[pos], dest_len - pos, ")|"); |
| 2785 | |
| 2786 | // now add the extension list itself |
| 2787 | pos += copy_extension_list(&dest[pos], dest_len - pos, extensions); |
| 2788 | |
| 2789 | // append a '|' |
| 2790 | pos += snprintf(&dest[pos], dest_len - pos, "|"); |
| 2791 | |
| 2792 | return pos; |
| 2793 | } |
| 2794 | //============================================================ |
| 2795 | // build_generic_filter |
| 2796 | //============================================================ |
| 2797 | |
| 2798 | static void build_generic_filter(device_image_interface *img, int is_save, char *filter, size_t filter_len) |
| 2799 | { |
| 2800 | char *s; |
| 2801 | |
| 2802 | const char *file_extension; |
| 2803 | |
| 2804 | /* copy the string */ |
| 2805 | file_extension = img->file_extensions(); |
| 2806 | |
| 2807 | // start writing the filter |
| 2808 | s = filter; |
| 2809 | |
| 2810 | // common image types |
| 2811 | s += add_filter_entry(filter, filter_len, "Common image types", file_extension); |
| 2812 | |
| 2813 | // all files |
| 2814 | s += sprintf(s, "All files (*.*)|*.*|"); |
| 2815 | |
| 2816 | // compressed |
| 2817 | if (!is_save) |
| 2818 | s += sprintf(s, "Compressed Images (*.zip)|*.zip|"); |
| 2819 | |
| 2820 | *(s++) = '\0'; |
| 2821 | } |
| 2822 | |
| 2823 | //============================================================ |
| 2653 | 2824 | // global_handle_command |
| 2654 | 2825 | //============================================================ |
| 2655 | 2826 | |
| r11868 | r11869 | |
| 2715 | 2886 | info->machine().schedule_exit(); |
| 2716 | 2887 | return 1; |
| 2717 | 2888 | } |
| 2889 | if (LOWORD(wparam) >= ID_DEVICE_OPTIONS) { |
| 2890 | UINT32 devid = (LOWORD(wparam) - ID_DEVICE_OPTIONS) / DEVOPTION_MAX; |
| 2891 | device_image_interface *img = NULL; |
| 2892 | UINT32 cnt = 0; |
| 2893 | for (bool gotone = info->machine().devicelist().first(img); gotone; gotone = img->next(img)) |
| 2894 | { |
| 2895 | if (cnt==devid) break; |
| 2896 | cnt++; |
| 2897 | } |
| 2898 | if (img!=NULL) { |
| 2899 | switch ((LOWORD(wparam) - ID_DEVICE_OPTIONS) % DEVOPTION_MAX) |
| 2900 | { |
| 2901 | case DEVOPTION_OPEN : |
| 2902 | { |
| 2903 | char filter[2048]; |
| 2904 | build_generic_filter(img, FALSE, filter, ARRAY_LENGTH(filter)); |
| 2905 | |
| 2906 | TCHAR selectedFilename[MAX_PATH]; |
| 2907 | selectedFilename[0] = '\0'; |
| 2908 | LPTSTR buffer; |
| 2909 | LPTSTR t_filter = NULL; |
| 2910 | |
| 2911 | buffer = tstring_from_utf8(filter); |
| 2718 | 2912 | |
| 2913 | // convert a pipe-char delimited string into a NUL delimited string |
| 2914 | t_filter = (LPTSTR) alloca((_tcslen(buffer) + 2) * sizeof(*t_filter)); |
| 2915 | int i = 0; |
| 2916 | for (i = 0; buffer[i] != '\0'; i++) |
| 2917 | t_filter[i] = (buffer[i] != '|') ? buffer[i] : '\0'; |
| 2918 | t_filter[i++] = '\0'; |
| 2919 | t_filter[i++] = '\0'; |
| 2920 | osd_free(buffer); |
| 2921 | |
| 2922 | |
| 2923 | OPENFILENAME ofn; |
| 2924 | memset(&ofn,0,sizeof(ofn)); |
| 2925 | ofn.lStructSize = sizeof(ofn); |
| 2926 | ofn.hwndOwner = NULL; |
| 2927 | ofn.lpstrFile = selectedFilename; |
| 2928 | ofn.lpstrFile[0] = '\0'; |
| 2929 | ofn.nMaxFile = MAX_PATH; |
| 2930 | ofn.lpstrFilter = t_filter; |
| 2931 | ofn.nFilterIndex = 1; |
| 2932 | ofn.lpstrFileTitle = NULL; |
| 2933 | ofn.nMaxFileTitle = 0; |
| 2934 | ofn.lpstrInitialDir = NULL; |
| 2935 | ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; |
| 2936 | |
| 2937 | if (GetOpenFileName(&ofn)) { |
| 2938 | img->load(utf8_from_tstring(selectedFilename)); |
| 2939 | } |
| 2940 | } |
| 2941 | return 1; |
| 2942 | /* case DEVOPTION_CREATE: |
| 2943 | return 1;*/ |
| 2944 | case DEVOPTION_CLOSE: |
| 2945 | img->unload(); |
| 2946 | return 1; |
| 2947 | default: |
| 2948 | if (img->device().type() == CASSETTE) { |
| 2949 | switch ((LOWORD(wparam) - ID_DEVICE_OPTIONS) % DEVOPTION_MAX) |
| 2950 | { |
| 2951 | |
| 2952 | case DEVOPTION_CASSETTE_STOPPAUSE: |
| 2953 | cassette_change_state(&img->device(), CASSETTE_STOPPED, CASSETTE_MASK_UISTATE); |
| 2954 | return 1; |
| 2955 | case DEVOPTION_CASSETTE_PLAY: |
| 2956 | cassette_change_state(&img->device(), CASSETTE_PLAY, CASSETTE_MASK_UISTATE); |
| 2957 | return 1; |
| 2958 | case DEVOPTION_CASSETTE_RECORD: |
| 2959 | cassette_change_state(&img->device(), CASSETTE_RECORD, CASSETTE_MASK_UISTATE); |
| 2960 | return 1; |
| 2961 | case DEVOPTION_CASSETTE_REWIND: |
| 2962 | cassette_seek(&img->device(), -60.0, SEEK_CUR); |
| 2963 | return 1; |
| 2964 | case DEVOPTION_CASSETTE_FASTFORWARD: |
| 2965 | cassette_seek(&img->device(), +60.0, SEEK_CUR); |
| 2966 | return 1; |
| 2967 | } |
| 2968 | } |
| 2969 | } |
| 2970 | } |
| 2971 | } |
| 2719 | 2972 | return 0; |
| 2720 | 2973 | } |
| 2721 | 2974 | |