Previous 15994 Revisions Next

r11869 Wednesday 8th June, 2011 at 13:00:06 UTC by Miodrag Milanović
Image related menu added to debugger (windows only for now) (no whatsnew)
[src/osd/windows]debugwin.c windows.mak

src/osd/windows/windows.mak
r11868r11869
258258CCOMFLAGS += -DDIRECTINPUT_VERSION=0x0700
259259endif
260260
261LIBS += -lcomdlg32
261262
262
263263#-------------------------------------------------
264264# OSD core library
265265#-------------------------------------------------
src/osd/windows/debugwin.c
r11868r11869
4444#include <windows.h>
4545#include <windowsx.h>
4646#include <tchar.h>
47#include <commdlg.h>
4748#ifdef _MSC_VER
4849#include <zmouse.h>
4950#endif
r11868r11869
5152// MAME headers
5253#include "emu.h"
5354#include "uiinput.h"
55#include "imagedev/cassette.h"
5456#include "debugger.h"
5557#include "debug/debugvw.h"
5658#include "debug/dvdisasm.h"
r11868r11869
138140   ID_SHOW_ENCRYPTED,
139141   ID_SHOW_COMMENTS,
140142   ID_RUN_TO_CURSOR,
141   ID_TOGGLE_BREAKPOINT
143   ID_TOGGLE_BREAKPOINT,
144   
145   ID_DEVICE_OPTIONS  // keep this always at the end
142146};
143147
144148
r11868r11869
266270static void smart_show_window(HWND wnd, BOOL show);
267271static void smart_show_all(BOOL show);
268272
273static void image_update_menu(debugwin_info *info);
269274
270
271275//============================================================
272276//  wait_for_debugger
273277//============================================================
r11868r11869
23762380}
23772381
23782382
2383enum
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};
23792395
23802396//============================================================
2397//  memory_update_menu
2398//============================================================
2399
2400static 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//============================================================
23812458//  console_create_window
23822459//============================================================
23832460
r11868r11869
23882465   RECT bounds, work_bounds;
23892466   HMENU optionsmenu;
23902467   UINT32 conchars;
2468   device_image_interface *img = NULL;
23912469
23922470   // create the window
23932471   info = debugwin_window_create(machine, "Debug", NULL);
r11868r11869
24132491   AppendMenu(optionsmenu, MF_ENABLED, ID_SHOW_COMMENTS, TEXT("Comments\tCtrl+N"));
24142492   AppendMenu(GetMenu(info->wnd), MF_ENABLED | MF_POPUP, (UINT_PTR)optionsmenu, TEXT("Options"));
24152493
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   
24162500   // set the handlers
24172501   info->handle_command = disasm_handle_command;
24182502   info->handle_key = disasm_handle_key;
r11868r11869
26472731   return menubar;
26482732}
26492733
2734//============================================================
2735//  copy_extension_list
2736//============================================================
26502737
2738static int copy_extension_list(char *dest, size_t dest_len, const char *extensions)
2739{
2740   const char *s;
2741   int pos = 0;
26512742
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
26522769//============================================================
2770//  add_filter_entry
2771//============================================================
2772
2773static 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
2798static 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//============================================================
26532824//  global_handle_command
26542825//============================================================
26552826
r11868r11869
27152886            info->machine().schedule_exit();
27162887            return 1;
27172888      }
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);
27182912
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      }
27192972   return 0;
27202973}
27212974

Previous 15994 Revisions Next


© 1998-2018 The MESS Team