Previous 15994 Revisions Next

r7336 Friday 12th February, 2010 at 15:44:13 UTC by Miodrag Milanović
- Moved natural keyboard support from MESS to MAME
- Moved OSD file functions and clipboard access functions into OSD core
[src/emu]emu.h emu.mak emuopts.c emuopts.h inptport.c inptport.h inpttype.h mame.c mame.h ui.c ui.h uimenu.c validity.c
[src/mame/machine]pckeybrd.c
[src/mess]device.c device.h image.h inputx.c inputx.h mess.h messcore.mak messdrv.h messopts.c messopts.h mesvalid.c mslegacy.c mslegacy.h tapectrl.c uimess.c uimess.h
[src/mess/drivers]apexc.c
[src/mess/osd]osdmess.h
[src/mess/osd/sdl]configms.c configms.h glob.c glob.h menu.h osdutils.h sdl.mak sdlmess.c sdlutil.c winutils.c winutils.h
[src/mess/osd/windows]configms.c configms.h dialog.c glob.c glob.h menu.c windows.mak winmess.c winutils.c winutils.h
[src/mess/tools/castool]main.c
[src/mess/tools/imgtool]main.c
[src/mess/tools/messtest]core.c main.c testmess.c
[src/osd]osdcore.h
[src/osd/sdl]input.c sdl.mak sdlclip.c* sdlfile.c sdlmain.c video.c window.c
[src/osd/windows]input.c winclip.c* windows.mak winfile.c

src/mame/machine/pckeybrd.c
r7335r7336
1919#include "emu.h"
2020#include "machine/pckeybrd.h"
2121
22#ifdef MESS
23#include "inputx.h"
24#endif /* MESS */
25
2622/* AT keyboard documentation comes from www.beyondlogic.org and HelpPC documentation */
2723
2824/* to enable logging of keyboard read/writes */
src/osd/sdl/sdl.mak
r7335r7336
257257   $(SDLOBJ)/strconv.o   \
258258   $(SDLOBJ)/sdldir.o   \
259259   $(SDLOBJ)/sdlfile.o    \
260   $(SDLOBJ)/sdlclip.o    \
260261   $(SDLOBJ)/sdlmisc_$(BASE_TARGETOS).o   \
261262   $(SDLOBJ)/sdlos_$(BASE_TARGETOS).o   \
262263   $(SDLOBJ)/sdlsync_$(SYNC_IMPLEMENTATION).o     \
src/osd/sdl/video.c
r7335r7336
5858#include "osdsdl.h"
5959#include "sdlos.h"
6060
61#ifdef MESS
62#include "menu.h"
63#endif
64
6561//============================================================
6662//  CONSTANTS
6763//============================================================
src/osd/sdl/sdlfile.c
r7335r7336
379379/*      osd_is_path_separator */
380380/*============================================================ */
381381
382static int osd_is_path_separator(char c)
382int osd_is_path_separator(char c)
383383{
384384        return (c == '/') || (c == '\\');
385385}
r7335r7336
495495}
496496#endif
497497#endif
498
499//============================================================
500//   osd_getcurdir
501//============================================================
502
503file_error osd_getcurdir(char *buffer, size_t buffer_len)
504{
505   file_error filerr = FILERR_NONE;
506
507   if (getcwd(buffer, buffer_len) == NULL)
508   {
509      filerr = FILERR_FAILURE;
510   }
511
512   if( filerr != FILERR_FAILURE )
513   {
514      if( strcmp( &buffer[strlen(buffer)-1], PATH_SEPARATOR ) != 0 )
515      {
516              strncat( buffer, PATH_SEPARATOR, buffer_len );
517      }
518   }
519
520   return filerr;
521}
522
523//============================================================
524//  osd_get_full_path
525//============================================================
526
527file_error osd_get_full_path(char **dst, const char *path)
528{
529   file_error err;
530   char path_buffer[512];
531
532   err = FILERR_NONE;
533
534   if (getcwd(path_buffer, 511) == NULL)
535   {
536      printf("osd_get_full_path: failed!\n");
537      err = FILERR_FAILURE;
538   }
539   else
540   {
541      *dst = (char *)malloc(strlen(path_buffer)+strlen(path)+3);
542
543      // if it's already a full path, just pass it through
544      if (path[0] == '/')
545      {
546         strcpy(*dst, path);
547      }
548      else
549      {
550         sprintf(*dst, "%s%s%s", path_buffer, PATH_SEPARATOR, path);
551      }
552   }
553
554   return err;
555}
556
557//============================================================
558//  osd_setcurdir
559//============================================================
560
561file_error osd_setcurdir(const char *dir)
562{
563   file_error filerr = FILERR_NONE;
564
565   if (chdir(dir) != 0)
566   {
567      filerr = FILERR_FAILURE;
568   }
569
570   return filerr;
571}
572
573//============================================================
574//  osd_basename
575//============================================================
576
577char *osd_basename(char *filename)
578{
579   char *c;
580
581   // NULL begets NULL
582   if (!filename)
583      return NULL;
584
585   // start at the end and return when we hit a slash or colon
586   for (c = filename + strlen(filename) - 1; c >= filename; c--)
587      if (*c == '\\' || *c == '/' || *c == ':')
588         return c + 1;
589
590   // otherwise, return the whole thing
591   return filename;
592}
593
594//============================================================
595//  osd_dirname
596//============================================================
597
598char *osd_dirname(const char *filename)
599{
600   char *dirname;
601   char *c;
602
603   // NULL begets NULL
604   if (!filename)
605      return NULL;
606
607   // allocate space for it
608   dirname = (char*)malloc(strlen(filename) + 1);
609   if (!dirname)
610      return NULL;
611
612   // copy in the name
613   strcpy(dirname, filename);
614
615   // search backward for a slash or a colon
616   for (c = dirname + strlen(dirname) - 1; c >= dirname; c--)
617      if (*c == '\\' || *c == '/' || *c == ':')
618      {
619         // found it: NULL terminate and return
620         *(c + 1) = 0;
621         return dirname;
622      }
623
624   // otherwise, return an empty string
625   dirname[0] = 0;
626   return dirname;
627}
628
629// no idea what these are for, just cheese them
630int osd_num_devices(void)
631{
632   return 1;
633}
634
635const char *osd_get_device_name(int idx)
636{
637   return "/";
638}
639
640//============================================================
641//  osd_get_temp_filename
642//============================================================
643
644file_error osd_get_temp_filename(char *buffer, size_t buffer_len, const char *basename)
645{
646   char tempbuf[512];
647
648   if (!basename)
649      basename = "tempfile";
650
651   sprintf(tempbuf, "/tmp/%s", basename);
652   unlink(tempbuf);
653
654   strncpy(buffer, tempbuf, buffer_len);
655
656   return FILERR_NONE;
657}
658
659//============================================================
660//  osd_mkdir
661//============================================================
662
663file_error osd_mkdir(const char *dir)
664{
665   file_error filerr = FILERR_NONE;
666
667   #ifdef SDLMAME_WIN32
668   if (mkdir(dir) != 0)
669   #else
670   if (mkdir(dir, 0700) != 0)
671   #endif
672   {
673      filerr = FILERR_FAILURE;
674   }
675
676   return filerr;
677}
678
679//============================================================
680//  osd_rmdir
681//============================================================
682
683file_error osd_rmdir(const char *dir)
684{
685   file_error filerr = FILERR_NONE;
686
687   if (rmdir(dir) != 0)
688   {
689      filerr = FILERR_FAILURE;
690   }
691
692   return filerr;
693}
694char sdl_cwd[512];
695void osd_get_emulator_directory(char *dir, size_t dir_size)
696{
697   strncpy(dir, sdl_cwd, dir_size);
698}
src/osd/sdl/sdlmain.c
r7335r7336
5656//  LOCAL VARIABLES
5757//============================================================
5858
59#ifdef MESS
6059#include <unistd.h>
61static char cwd[512];
62#endif
60extern char sdl_cwd[512];
6361
6462//============================================================
6563//  OPTIONS
r7335r7336
186184   { NULL,                                 NULL,  OPTION_HEADER,     "SDL KEYBOARD MAPPING" },
187185   { SDLOPTION_KEYMAP,                      "0",    OPTION_BOOLEAN,    "enable keymap" },
188186   { SDLOPTION_KEYMAP_FILE,                 "keymap.dat", 0,           "keymap filename" },
189#ifdef MESS
190#ifdef SDLMAME_MACOSX   // work around for SDL 1.2.11 on Mac - 1.2.12 should not require this
191   { SDLOPTION_UIMODEKEY,         "DELETE", 0,                  "Key to toggle MESS keyboard mode" },
192#else
193   { SDLOPTION_UIMODEKEY,         "SCROLLOCK", 0,                  "Key to toggle MESS keyboard mode" },
194#endif   // SDLMAME_MACOSX
195#endif   // MESS
196187
197188   // joystick mapping
198189   { NULL,                                NULL,   OPTION_HEADER,     "SDL JOYSTICK MAPPING" },
r7335r7336
280271   MorphToPM();
281272   #endif
282273
283   #ifdef MESS
284   getcwd(cwd, 511);
285   #endif
274   getcwd(sdl_cwd, 511);
286275
287276#if defined(SDLMAME_X11) && (SDL_MAJOR_VERSION == 1) && (SDL_MINOR_VERSION == 2)
288277   if (SDL_Linked_Version()->patch < 10)
r7335r7336
572561   SDL_EnableUNICODE(SDL_TRUE);
573562#endif
574563}
575
576#ifdef MESS
577char *osd_get_startup_cwd(void)
578{
579   return cwd;
580}
581#endif
src/osd/sdl/input.c
r7335r7336
914914   return index;
915915}
916916
917#ifdef MESS
918917static int lookup_mame_code(const char *scode)
919918{
920919   int index;
r7335r7336
924923   else
925924      return -1;
926925}
927#endif
928926
929927
930928//============================================================
r7335r7336
15841582
15851583void osd_customize_input_type_list(input_type_desc *typelist)
15861584{
1587   #ifdef MESS
15881585   int mameid_code ,ui_code;
1589   #endif
15901586   input_type_desc *typedesc;
15911587
15921588   // loop over the defaults
r7335r7336
15941590   {
15951591      switch (typedesc->type)
15961592      {
1597         #ifdef MESS
15981593         // configurable UI mode switch
15991594         case IPT_UI_TOGGLE_UI:
16001595            mameid_code = lookup_mame_code((const char *)options_get_string(mame_options(), SDLOPTION_UIMODEKEY));
16011596            ui_code = INPUT_CODE(DEVICE_CLASS_KEYBOARD, 0, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, mameid_code);
16021597            input_seq_set_1(&typedesc->seq[SEQ_TYPE_STANDARD], ui_code);
16031598            break;
1604         #endif
16051599         // alt-enter for fullscreen
16061600         case IPT_OSD_1:
16071601            typedesc->token = "TOGGLE_FULLSCREEN";
src/osd/sdl/window.c
r7335r7336
3131#include "input.h"
3232#include "osdsdl.h"
3333
34#ifdef MESS
35#include "menu.h"
36#endif /* MESS */
37
3834//============================================================
3935//  PARAMETERS
4036//============================================================
src/osd/sdl/sdlclip.c
r0r7336
1#include <stdlib.h>
2#include <fcntl.h>
3#include <unistd.h>
4#include <ctype.h>
5#include <sys/stat.h>
6#include <sys/types.h>
7#include <ctype.h>
8#include <errno.h>
9
10#ifdef SDLMAME_WIN32
11#define WIN32_LEAN_AND_MEAN
12#include <windows.h>
13#include <tchar.h>
14#include "strconv.h"
15#endif
16
17#ifdef SDLMAME_MACOSX
18#include <Carbon/Carbon.h>
19#endif
20
21
22#ifdef SDLMAME_MACOSX
23//============================================================
24//  osd_get_clipboard_text
25//============================================================
26
27char *osd_get_clipboard_text(void)
28{
29   char *result = NULL; /* core expects a malloced C string of uft8 data */
30
31   PasteboardRef pasteboard_ref;
32   OSStatus err;
33   PasteboardSyncFlags sync_flags;
34   PasteboardItemID item_id;
35   CFIndex flavor_count;
36   CFArrayRef flavor_type_array;
37   CFIndex flavor_index;
38   ItemCount item_count;
39   UInt32 item_index;
40   Boolean   success = false;
41
42   err = PasteboardCreate(kPasteboardClipboard, &pasteboard_ref);
43
44   if (!err)
45   {
46      sync_flags = PasteboardSynchronize( pasteboard_ref );
47
48      err = PasteboardGetItemCount(pasteboard_ref, &item_count );
49
50      for (item_index=1; item_index<=item_count; item_index++)
51      {
52         err = PasteboardGetItemIdentifier(pasteboard_ref, item_index, &item_id);
53
54         if (!err)
55         {
56            err = PasteboardCopyItemFlavors(pasteboard_ref, item_id, &flavor_type_array);
57
58            if (!err)
59            {
60               flavor_count = CFArrayGetCount(flavor_type_array);
61
62               for (flavor_index = 0; flavor_index < flavor_count; flavor_index++)
63               {
64                  CFStringRef flavor_type;
65                  CFDataRef flavor_data;
66                  CFStringEncoding encoding;
67                  CFStringRef string_ref;
68                  CFDataRef data_ref;
69                  CFIndex length;
70                  CFRange range;
71
72                  flavor_type = (CFStringRef)CFArrayGetValueAtIndex(flavor_type_array, flavor_index);
73
74                  if (UTTypeConformsTo (flavor_type, kUTTypeUTF16PlainText))
75                     encoding = kCFStringEncodingUTF16;
76                  else if (UTTypeConformsTo (flavor_type, kUTTypeUTF8PlainText))
77                     encoding = kCFStringEncodingUTF8;
78                  else if (UTTypeConformsTo (flavor_type, kUTTypePlainText))
79                     encoding = kCFStringEncodingMacRoman;
80                  else
81                     continue;
82
83                  err = PasteboardCopyItemFlavorData(pasteboard_ref, item_id, flavor_type, &flavor_data);
84
85                  if( !err )
86                  {
87                     string_ref = CFStringCreateFromExternalRepresentation (kCFAllocatorDefault, flavor_data, encoding);
88                     data_ref = CFStringCreateExternalRepresentation (kCFAllocatorDefault, string_ref, kCFStringEncodingUTF8, '?');
89
90                     length = CFDataGetLength (data_ref);
91                     range = CFRangeMake (0,length);
92
93                     result = (char *)malloc (length+1);
94                     if (result != NULL)
95                     {
96                        CFDataGetBytes (data_ref, range, (unsigned char *)result);
97                        result[length] = 0;
98                        success = true;
99                        break;
100                     }
101
102                     CFRelease(data_ref);
103                     CFRelease(string_ref);
104                     CFRelease(flavor_data);
105                  }
106               }
107
108               CFRelease(flavor_type_array);
109            }
110         }
111
112         if (success)
113            break;
114      }
115
116      CFRelease(pasteboard_ref);
117   }
118
119   return result;
120}
121#endif
122
123#ifdef SDLMAME_WIN32
124//============================================================
125//  get_clipboard_text_by_format
126//============================================================
127
128static char *get_clipboard_text_by_format(UINT format, char *(*convert)(LPCVOID data))
129{
130   char *result = NULL;
131   HANDLE data_handle;
132   LPVOID data;
133
134   // check to see if this format is available
135   if (IsClipboardFormatAvailable(format))
136   {
137      // open the clipboard
138      if (OpenClipboard(NULL))
139      {
140         // try to access clipboard data
141         data_handle = GetClipboardData(format);
142         if (data_handle != NULL)
143         {
144            // lock the data
145            data = GlobalLock(data_handle);
146            if (data != NULL)
147            {
148               // invoke the convert
149               result = (*convert)(data);
150
151               // unlock the data
152               GlobalUnlock(data_handle);
153            }
154         }
155
156         // close out the clipboard
157         CloseClipboard();
158      }
159   }
160   return result;
161}
162
163
164
165//============================================================
166//  convert_wide
167//============================================================
168
169static char *convert_wide(LPCVOID data)
170{
171   return utf8_from_wstring((LPCWSTR) data);
172}
173
174
175
176//============================================================
177//  convert_ansi
178//============================================================
179
180static char *convert_ansi(LPCVOID data)
181{
182   return utf8_from_astring((LPCSTR) data);
183}
184
185
186
187//============================================================
188//  osd_get_clipboard_text
189//============================================================
190
191char *osd_get_clipboard_text(void)
192{
193   char *result = NULL;
194
195   // try to access unicode text
196   if (result == NULL)
197      result = get_clipboard_text_by_format(CF_UNICODETEXT, convert_wide);
198
199   // try to access ANSI text
200   if (result == NULL)
201      result = get_clipboard_text_by_format(CF_TEXT, convert_ansi);
202
203   return result;
204}
205#endif
206
207#if defined(SDL_VIDEO_DRIVER_X11)
208//============================================================
209//  osd_get_clipboard_text
210//============================================================
211
212char *osd_get_clipboard_text(void)
213{
214   SDL_SysWMinfo info;
215   Display* display;
216   Window our_win;
217   Window selection_win;
218   Atom data_type;
219   int data_format;
220   unsigned long nitems;
221   unsigned long bytes_remaining;
222   unsigned char* prop;
223   char* result;
224   XEvent event;
225   Uint32 t0, t1;
226   Atom types[2];
227   int i;
228
229   /* get & validate SDL sys-wm info */
230   SDL_VERSION(&info.version);
231   if ( ! SDL_GetWMInfo( &info ) )
232      return NULL;
233   if ( info.subsystem != SDL_SYSWM_X11 )
234      return NULL;
235   if ( (display = info.info.x11.display) == NULL )
236      return NULL;
237   if ( (our_win = info.info.x11.window) == None )
238      return NULL;
239
240   /* request data to owner */
241   selection_win = XGetSelectionOwner( display, XA_PRIMARY );
242   if ( selection_win == None )
243      return NULL;
244
245   /* first, try UTF-8, then latin-1 */
246   types[0] = XInternAtom( display, "UTF8_STRING", False );
247   types[1] = XA_STRING; /* latin-1 */
248
249   for ( i = 0; i < ARRAY_LENGTH(types); i++ )
250   {
251
252      XConvertSelection( display, XA_PRIMARY, types[i], types[i], our_win, CurrentTime );
253
254      /* wait for SelectionNotify, but no more than 100 ms */
255      t0 = t1 = SDL_GetTicks();
256      while ( 1 )
257      {
258         if (  XCheckTypedWindowEvent( display, our_win,  SelectionNotify, &event ) ) break;
259         SDL_Delay( 1 );
260         t1 = SDL_GetTicks();
261         if ( t1 - t0 > 100 )
262            return NULL;
263      }
264      if ( event.xselection.property == None )
265         continue;
266
267      /* get property & check its type */
268      if ( XGetWindowProperty( display, our_win, types[i], 0, 65536, False, types[i],
269                &data_type, &data_format, &nitems, &bytes_remaining, &prop )
270           != Success )
271         continue;
272      if ( ! prop )
273         continue;
274      if ( (data_format != 8) || (data_type != types[i]) )
275      {
276         XFree( prop );
277         continue;
278      }
279
280      /* return a copy & free original */
281      result = core_strdup( (char*) prop );
282      XFree( prop );
283      return result;
284   }
285
286   return NULL;
287}
288
289#endif
290
291#if defined(SDLMAME_UNIX) && !defined(SDLMAME_MACOSX) && !defined(SDL_VIDEO_DRIVER_X11)
292//============================================================
293//  osd_get_clipboard_text
294//============================================================
295
296char *osd_get_clipboard_text(void)
297{
298   char *result = NULL;
299
300   return result;
301}
302#endif
src/osd/osdcore.h
r7335r7336
5050
5151#include "osdcomm.h"
5252
53
54
5553/***************************************************************************
5654    FILE I/O INTERFACES
5755***************************************************************************/
r7335r7336
8684/* osd_file is an opaque type which represents an open file */
8785typedef struct _osd_file osd_file;
8886
87enum
88{
89   OSD_FOPEN_READ,
90   OSD_FOPEN_WRITE,
91   OSD_FOPEN_RW,
92   OSD_FOPEN_RW_CREATE
93};
8994
95
96struct _mame_file;
97
98
9099/*-----------------------------------------------------------------------------
91100    osd_open: open a new file.
92101
r7335r7336
810819-----------------------------------------------------------------------------*/
811820void osd_break_into_debugger(const char *message);
812821
822/***************************************************************************
823    FILE I/O INTERFACES
824***************************************************************************/
813825
826/*-----------------------------------------------------------------------------
827    osd_copyfile: copies a file
828
829    Parameters:
830
831        destfile - path to destination
832
833        srcfile - path to source file
834
835    Return value:
836
837        a file_error describing any error that occurred while copying
838        the file, or FILERR_NONE if no error occurred
839-----------------------------------------------------------------------------*/
840file_error osd_copyfile(const char *destfile, const char *srcfile);
841
842
843/*-----------------------------------------------------------------------------
844    osd_get_temp_filename: given a filename, return a full path with that
845    filename but in a temporary directory
846
847    Parameters:
848
849        buffer - pointer to buffer
850
851        buffer_len - length of buffer
852
853        basename - basename of file to create
854
855    Return value:
856
857        a file_error describing any error that occurred while copying
858        the file, or FILERR_NONE if no error occurred
859-----------------------------------------------------------------------------*/
860file_error osd_get_temp_filename(char *buffer, size_t buffer_len, const char *basename);
861
862
863/***************************************************************************
864    DIRECTORY INTERFACES
865***************************************************************************/
866
867/*-----------------------------------------------------------------------------
868    osd_stat: return a directory entry for a path
869
870    Parameters:
871
872        path - path in question
873
874    Return value:
875
876        an allocated pointer to an osd_directory_entry representing
877        info on the path; even if the file does not exist
878
879-----------------------------------------------------------------------------*/
880osd_directory_entry *osd_stat(const char *path);
881
882
883/*-----------------------------------------------------------------------------
884    osd_mkdir: creates a directory
885
886    Parameters:
887
888        dir - path to directory to create
889
890    Return value:
891
892        a file_error describing any error that occurred while creating
893        the directory, or FILERR_NONE if no error occurred
894-----------------------------------------------------------------------------*/
895file_error osd_mkdir(const char *dir);
896
897
898/*-----------------------------------------------------------------------------
899    osd_rmdir: removes a directory
900
901    Parameters:
902
903        dir - path to directory to removes
904
905    Return value:
906
907        a file_error describing any error that occurred while deleting
908        the directory, or FILERR_NONE if no error occurred
909-----------------------------------------------------------------------------*/
910file_error osd_rmdir(const char *dir);
911
912
913/*-----------------------------------------------------------------------------
914    osd_getcurdir: retrieves the current working directory
915
916    Parameters:
917
918        buffer - place to store current working directory
919
920        buffer_len - length of buffer
921
922    Return value:
923
924        a file_error describing any error that occurred while deleting
925        the directory, or FILERR_NONE if no error occurred
926-----------------------------------------------------------------------------*/
927file_error osd_getcurdir(char *buffer, size_t buffer_len);
928
929
930/*-----------------------------------------------------------------------------
931    osd_setcurdir: sets the current working directory
932
933    Parameters:
934
935        dir - path to directory to which to change
936
937    Return value:
938
939        a file_error describing any error that occurred while deleting
940        the directory, or FILERR_NONE if no error occurred
941-----------------------------------------------------------------------------*/
942file_error osd_setcurdir(const char *dir);
943
944
945/***************************************************************************
946    PATH INTERFACES
947***************************************************************************/
948
949/*-----------------------------------------------------------------------------
950    osd_get_emulator_directory: returns the path containing the emulator
951
952    Parameters:
953
954        dir - space to output directory
955        dir_size - size of path
956
957-----------------------------------------------------------------------------*/
958
959void osd_get_emulator_directory(char *dir, size_t dir_size);
960
961/*-----------------------------------------------------------------------------
962    osd_is_path_separator: returns whether a character is a path separator
963
964    Parameters:
965
966        c - the character in question
967
968    Return value:
969
970        non-zero if the character is a path separator, zero otherwise
971
972-----------------------------------------------------------------------------*/
973int osd_is_path_separator(char c);
974
975
976/*-----------------------------------------------------------------------------
977    osd_dirname: returns the base directory of a file path
978
979    Parameters:
980
981        filename - the path in question
982
983    Return value:
984
985        an allocated path to the directory containing this file
986
987-----------------------------------------------------------------------------*/
988char *osd_dirname(const char *filename);
989
990
991/*-----------------------------------------------------------------------------
992    osd_basename: returns the file or directory name from a full path
993
994    Parameters:
995
996        filename - the path in question
997
998    Return value:
999
1000        a pointer to the base name of the file
1001
1002-----------------------------------------------------------------------------*/
1003char *osd_basename(char *filename);
1004
1005
1006/*-----------------------------------------------------------------------------
1007    osd_get_full_path: retrieves the full path
1008
1009    Parameters:
1010
1011        path - the path in question
1012        dst - pointer to receive new path; the returned string needs to be free()-ed!
1013
1014    Return value:
1015
1016        file error
1017
1018-----------------------------------------------------------------------------*/
1019file_error osd_get_full_path(char **dst, const char *path);
1020
1021
1022
1023/***************************************************************************
1024    UNCATEGORIZED INTERFACES
1025***************************************************************************/
1026
1027
1028/* reads text from the clipboard - the returned string needs to be free()-ed! */
1029char *osd_get_clipboard_text(void);
1030
1031
1032
1033/******************************************************************************
1034
1035  Device and file browsing
1036
1037******************************************************************************/
1038
1039int osd_num_devices(void);
1040const char *osd_get_device_name(int idx);
1041
1042
8141043#endif   /* __OSDEPEND_H__ */
src/osd/windows/windows.mak
r7335r7336
255255   $(WINOBJ)/wintime.o \
256256   $(WINOBJ)/winutf8.o \
257257   $(WINOBJ)/winutil.o \
258   $(WINOBJ)/winclip.o \
258259   $(WINOBJ)/winwork.o
259260
260261
src/osd/windows/winfile.c
r7335r7336
5252// MAMEOS headers
5353#include "strconv.h"
5454#include "winutil.h"
55#include "winutf8.h"
5556
56
5757//============================================================
5858//  TYPE DEFINITIONS
5959//============================================================
r7335r7336
373373      return GetLastError();
374374   return NO_ERROR;
375375}
376
377//============================================================
378//  win_error_to_mame_file_error
379//============================================================
380
381static file_error win_error_to_mame_file_error(DWORD error)
382{
383   file_error filerr;
384
385   // convert a Windows error to a file_error
386   switch (error)
387   {
388      case ERROR_SUCCESS:
389         filerr = FILERR_NONE;
390         break;
391
392      case ERROR_OUTOFMEMORY:
393         filerr = FILERR_OUT_OF_MEMORY;
394         break;
395
396      case ERROR_FILE_NOT_FOUND:
397      case ERROR_PATH_NOT_FOUND:
398         filerr = FILERR_NOT_FOUND;
399         break;
400
401      case ERROR_ACCESS_DENIED:
402         filerr = FILERR_ACCESS_DENIED;
403         break;
404
405      case ERROR_SHARING_VIOLATION:
406         filerr = FILERR_ALREADY_OPEN;
407         break;
408
409      default:
410         filerr = FILERR_FAILURE;
411         break;
412   }
413   return filerr;
414}
415
416
417//============================================================
418//  osd_get_temp_filename
419//============================================================
420
421file_error osd_get_temp_filename(char *buffer, size_t buffer_len, const char *basename)
422{
423   TCHAR tempbuf[MAX_PATH];
424   TCHAR *t_filename;
425   char *u_tempbuf;
426
427   if (!basename)
428      basename = "tempfile.tmp";
429
430   GetTempPath(ARRAY_LENGTH(tempbuf), tempbuf);
431   t_filename = tstring_from_utf8(basename);
432   _tcscat(tempbuf, t_filename);
433   free(t_filename);
434   DeleteFile(tempbuf);
435
436   u_tempbuf = utf8_from_tstring(tempbuf);
437   snprintf(buffer, buffer_len, "%s", u_tempbuf);
438   free(u_tempbuf);
439
440   return FILERR_NONE;
441}
442
443
444//============================================================
445//  osd_copyfile
446//============================================================
447
448file_error osd_copyfile(const char *destfile, const char *srcfile)
449{
450   // wrapper for win_copy_file_utf8()
451   if (!win_copy_file_utf8(srcfile, destfile, TRUE))
452      return win_error_to_mame_file_error(GetLastError());
453
454   return FILERR_NONE;
455}
456
457
458//============================================================
459//  osd_stat
460//============================================================
461
462osd_directory_entry *osd_stat(const char *path)
463{
464   osd_directory_entry *result = NULL;
465   TCHAR *t_path;
466   HANDLE find = INVALID_HANDLE_VALUE;
467   WIN32_FIND_DATA find_data;
468
469   // convert the path to TCHARs
470   t_path = tstring_from_utf8(path);
471   if (t_path == NULL)
472      goto done;
473
474   // is this path a root directory (e.g. - C:)?
475   if (isalpha(path[0]) && (path[1] == ':') && (path[2] == '\0'))
476   {
477      // need to do special logic for root directories
478      memset(&find_data, 0, sizeof(find_data));
479      find_data.dwFileAttributes = GetFileAttributes(t_path);
480   }
481   else
482   {
483      // attempt to find the first file
484      find = FindFirstFile(t_path, &find_data);
485      if (find == INVALID_HANDLE_VALUE)
486         goto done;
487   }
488
489   // create an osd_directory_entry; be sure to make sure that the caller can
490   // free all resources by just freeing the resulting osd_directory_entry
491   result = (osd_directory_entry *)malloc(sizeof(*result) + strlen(path) + 1);
492   if (!result)
493      goto done;
494   strcpy(((char *) result) + sizeof(*result), path);
495   result->name = ((char *) result) + sizeof(*result);
496   result->type = win_attributes_to_entry_type(find_data.dwFileAttributes);
497   result->size = find_data.nFileSizeLow | ((UINT64) find_data.nFileSizeHigh << 32);
498
499done:
500   if (t_path != NULL)
501      free(t_path);
502   return result;
503}
504
505
506
507//============================================================
508//  osd_is_path_separator
509//============================================================
510
511int osd_is_path_separator(char c)
512{
513   return (c == '/') || (c == '\\');
514}
515
516
517
518//============================================================
519//  osd_dirname
520//============================================================
521
522char *osd_dirname(const char *filename)
523{
524   char *dirname;
525   char *c;
526
527   // NULL begets NULL
528   if (!filename)
529      return NULL;
530
531   // allocate space for it
532   dirname = (char*)malloc(strlen(filename) + 1);
533   if (!dirname)
534      return NULL;
535
536   // copy in the name
537   strcpy(dirname, filename);
538
539   // search backward for a slash or a colon
540   for (c = dirname + strlen(dirname) - 1; c >= dirname; c--)
541      if (*c == '\\' || *c == '/' || *c == ':')
542      {
543         // found it: NULL terminate and return
544         *(c + 1) = 0;
545         return dirname;
546      }
547
548   // otherwise, return an empty string
549   dirname[0] = 0;
550   return dirname;
551}
552
553
554//============================================================
555//  osd_basename
556//============================================================
557
558char *osd_basename(char *filename)
559{
560   char *c;
561
562   // NULL begets NULL
563   if (!filename)
564      return NULL;
565
566   // start at the end and return when we hit a slash or colon
567   for (c = filename + strlen(filename) - 1; c >= filename; c--)
568      if (*c == '\\' || *c == '/' || *c == ':')
569         return c + 1;
570
571   // otherwise, return the whole thing
572   return filename;
573}
574
575
576//============================================================
577//  osd_get_full_path
578//============================================================
579
580file_error osd_get_full_path(char **dst, const char *path)
581{
582   file_error err;
583   TCHAR *t_path;
584   TCHAR buffer[MAX_PATH];
585
586   // convert the path to TCHARs
587   t_path = tstring_from_utf8(path);
588   if (t_path == NULL)
589   {
590      err = FILERR_OUT_OF_MEMORY;
591      goto done;
592   }
593
594   // cannonicalize the path
595   if (!GetFullPathName(t_path, ARRAY_LENGTH(buffer), buffer, NULL))
596   {
597      err = win_error_to_mame_file_error(GetLastError());
598      goto done;
599   }
600
601   // convert the result back to UTF-8
602   *dst = utf8_from_tstring(buffer);
603   if (!*dst)
604   {
605      err = FILERR_OUT_OF_MEMORY;
606      goto done;
607   }
608
609   err = FILERR_NONE;
610
611done:
612   if (t_path != NULL)
613      free(t_path);
614   return err;
615}
616
617
618//============================================================
619//  osd_mkdir
620//============================================================
621
622file_error osd_mkdir(const char *dir)
623{
624   file_error filerr = FILERR_NONE;
625
626   TCHAR *tempstr = tstring_from_utf8(dir);
627   if (!tempstr)
628   {
629      filerr = FILERR_OUT_OF_MEMORY;
630      goto done;
631   }
632
633   if (!CreateDirectory(tempstr, NULL))
634   {
635      filerr = win_error_to_mame_file_error(GetLastError());
636      goto done;
637   }
638
639done:
640   if (tempstr)
641      free(tempstr);
642   return filerr;
643}
644
645
646//============================================================
647//  osd_rmdir
648//============================================================
649
650file_error osd_rmdir(const char *dir)
651{
652   file_error filerr = FILERR_NONE;
653
654   TCHAR *tempstr = tstring_from_utf8(dir);
655   if (!tempstr)
656   {
657      filerr = FILERR_OUT_OF_MEMORY;
658      goto done;
659   }
660
661   if (!RemoveDirectory(tempstr))
662   {
663      filerr = win_error_to_mame_file_error(GetLastError());
664      goto done;
665   }
666
667done:
668   if (tempstr)
669      free(tempstr);
670   return filerr;
671}
672
673
674//============================================================
675//  osd_getcurdir
676//============================================================
677
678file_error osd_getcurdir(char *buffer, size_t buffer_len)
679{
680   file_error filerr = FILERR_NONE;
681   char *tempstr = NULL;
682   TCHAR path[_MAX_PATH];
683
684   if (!GetCurrentDirectory(ARRAY_LENGTH(path), path))
685   {
686      filerr = win_error_to_mame_file_error(GetLastError());
687      goto done;
688   }
689
690   tempstr = utf8_from_tstring(path);
691   if (!tempstr)
692   {
693      filerr = FILERR_OUT_OF_MEMORY;
694      goto done;
695   }
696   snprintf(buffer, buffer_len, "%s", tempstr);
697
698done:
699   if (tempstr)
700      free(tempstr);
701   return filerr;
702}
703
704
705//============================================================
706//  osd_setcurdir
707//============================================================
708
709file_error osd_setcurdir(const char *dir)
710{
711   file_error filerr = FILERR_NONE;
712
713   TCHAR *tempstr = tstring_from_utf8(dir);
714   if (!tempstr)
715   {
716      filerr = FILERR_OUT_OF_MEMORY;
717      goto done;
718   }
719
720   if (!SetCurrentDirectory(tempstr))
721   {
722      filerr = win_error_to_mame_file_error(GetLastError());
723      goto done;
724   }
725
726done:
727   if (tempstr)
728      free(tempstr);
729   return filerr;
730}
731
732
733//============================================================
734//  DIRECTORIES
735//============================================================
736
737int osd_num_devices(void)
738{
739   char szBuffer[128];
740   char *p;
741   int i;
742
743   GetLogicalDriveStringsA(ARRAY_LENGTH(szBuffer), szBuffer);
744
745   i = 0;
746   for (p = szBuffer; *p; p += (strlen(p) + 1))
747      i++;
748   return i;
749}
750
751const char *osd_get_device_name(int idx)
752{
753   static char szBuffer[128];
754   const char *p;
755
756   GetLogicalDriveStringsA(ARRAY_LENGTH(szBuffer), szBuffer);
757
758   p = szBuffer;
759   while(idx--)
760      p += strlen(p) + 1;
761
762   return p;
763}
764
765void osd_get_emulator_directory(char *dir, size_t dir_size)
766{
767   char *s;
768   win_get_module_file_name_utf8(NULL, dir, dir_size);
769   s = strrchr(dir, '\\');
770   if (s)
771      s[1] = '\0';
772}
src/osd/windows/input.c
r7335r7336
771771            input_seq_set_2(&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_LALT, KEYCODE_ENTER);
772772            break;
773773
774#ifdef MESS
775774         case IPT_OSD_2:
776            if (ui_mess_use_new_ui())
775            if (ui_use_new_ui())
777776            {
778777               typedesc->token = "TOGGLE_MENUBAR";
779778               typedesc->name = "Toggle Menubar";
r7335r7336
784783         case IPT_UI_THROTTLE:
785784            input_seq_set_0(&typedesc->seq[SEQ_TYPE_STANDARD]);
786785            break;
787#endif /* MESS */
788786      }
789787}
790788
src/osd/windows/winclip.c
r0r7336
1//============================================================
2//
3//  winclip.c - Win32 OSD core clipboard access functions
4//
5//============================================================
6//
7//  Copyright Aaron Giles
8//  All rights reserved.
9//
10//  Redistribution and use in source and binary forms, with or
11//  without modification, are permitted provided that the
12//  following conditions are met:
13//
14//    * Redistributions of source code must retain the above
15//      copyright notice, this list of conditions and the
16//      following disclaimer.
17//    * Redistributions in binary form must reproduce the
18//      above copyright notice, this list of conditions and
19//      the following disclaimer in the documentation and/or
20//      other materials provided with the distribution.
21//    * Neither the name 'MAME' nor the names of its
22//      contributors may be used to endorse or promote
23//      products derived from this software without specific
24//      prior written permission.
25//
26//  THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND
27//  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
29//  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
30//  EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
31//  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32//  DAMAGE (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33//  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
35//  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36//  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37//  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
38//  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39//
40//============================================================
41
42#define WIN32_LEAN_AND_MEAN
43#include <windows.h>
44
45#include "strconv.h"
46
47//============================================================
48//  get_clipboard_text_by_format
49//============================================================
50
51static char *get_clipboard_text_by_format(UINT format, char *(*convert)(LPCVOID data))
52{
53   char *result = NULL;
54   HANDLE data_handle;
55   LPVOID data;
56
57   // check to see if this format is available
58   if (IsClipboardFormatAvailable(format))
59   {
60      // open the clipboard
61      if (OpenClipboard(NULL))
62      {
63         // try to access clipboard data
64         data_handle = GetClipboardData(format);
65         if (data_handle != NULL)
66         {
67            // lock the data
68            data = GlobalLock(data_handle);
69            if (data != NULL)
70            {
71               // invoke the convert
72               result = (*convert)(data);
73
74               // unlock the data
75               GlobalUnlock(data_handle);
76            }
77         }
78
79         // close out the clipboard
80         CloseClipboard();
81      }
82   }
83   return result;
84}
85
86//============================================================
87//  convert_wide
88//============================================================
89
90static char *convert_wide(LPCVOID data)
91{
92   return utf8_from_wstring((LPCWSTR) data);
93}
94
95//============================================================
96//  convert_ansi
97//============================================================
98
99static char *convert_ansi(LPCVOID data)
100{
101   return utf8_from_astring((LPCSTR) data);
102}
103
104
105
106//============================================================
107//  osd_get_clipboard_text
108//============================================================
109
110char *osd_get_clipboard_text(void)
111{
112   char *result = NULL;
113
114   // try to access unicode text
115   if (result == NULL)
116      result = get_clipboard_text_by_format(CF_UNICODETEXT, convert_wide);
117
118   // try to access ANSI text
119   if (result == NULL)
120      result = get_clipboard_text_by_format(CF_TEXT, convert_ansi);
121
122   return result;
123}
src/emu/emuopts.c
r7335r7336
129129   { "joystick_map;joymap",         "auto",      0,                 "explicit joystick map, or auto to auto-select" },
130130   { "joystick_deadzone;joy_deadzone;jdz",      "0.3",  0,          "center deadzone range for joystick where change is ignored (0.0 center, 1.0 end)" },
131131   { "joystick_saturation;joy_saturation;jsat", "0.85", 0,          "end of axis saturation range for joystick where change is ignored (0.0 center, 1.0 end)" },
132   { "natural;nat",             "0",        OPTION_BOOLEAN,    "specifies whether to use a natural keyboard or not" },
133   #if defined(__APPLE__) && defined(__MACH__)
134   { "uimodekey;umk",              "ITEM_ID_INSERT",  0,           "specifies the key used to toggle between full and partial UI mode" },
135   #else
136   { "uimodekey;umk",              "ITEM_ID_SCRLOCK", 0,           "specifies the key used to toggle between full and partial UI mode" },
137   #endif
138   
132139
133140   /* input autoenable options */
134141   { NULL,                          NULL,        OPTION_HEADER,     "CORE INPUT AUTOMATIC ENABLE OPTIONS" },
src/emu/emuopts.h
r7335r7336
138138#define OPTION_JOYSTICK_SATURATION   "joystick_saturation"
139139#define OPTION_STEADYKEY         "steadykey"
140140#define OPTION_OFFSCREEN_RELOAD      "offscreen_reload"
141#define OPTION_NATURAL_KEYBOARD      "natural"
141142
142143/* core debugging options */
143144#define OPTION_VERBOSE            "verbose"
src/emu/uimenu.c
r7335r7336
2121
2222#ifdef MESS
2323#include "uimess.h"
24#include "inputx.h"
2524#endif /* MESS */
2625
2726#include <ctype.h>
r7335r7336
276275static void menu_settings_populate(running_machine *machine, ui_menu *menu, settings_menu_state *menustate, UINT32 type);
277276static void menu_analog(running_machine *machine, ui_menu *menu, void *parameter, void *state);
278277static void menu_analog_populate(running_machine *machine, ui_menu *menu);
279#ifndef MESS
280278static void menu_bookkeeping(running_machine *machine, ui_menu *menu, void *parameter, void *state);
281279static void menu_bookkeeping_populate(running_machine *machine, ui_menu *menu, attotime *curtime);
282#endif
283280static void menu_game_info(running_machine *machine, ui_menu *menu, void *parameter, void *state);
284281static void menu_cheat(running_machine *machine, ui_menu *menu, void *parameter, void *state);
285282static void menu_cheat_populate(running_machine *machine, ui_menu *menu);
r7335r7336
14601457
14611458
14621459/*-------------------------------------------------
1460    ui_menu_keyboard_mode - menu that
1461-------------------------------------------------*/
1462
1463static void ui_menu_keyboard_mode(running_machine *machine, ui_menu *menu, void *parameter, void *state)
1464{
1465   const ui_menu_event *event;
1466   int natural = ui_get_use_natural_keyboard(machine);
1467
1468   /* if the menu isn't built, populate now */
1469   if (!ui_menu_populated(menu))
1470   {
1471      ui_menu_item_append(menu, "Keyboard Mode:", natural ? "Natural" : "Emulated", natural ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, NULL);
1472   }
1473
1474   /* process the menu */
1475   event = ui_menu_process(machine, menu, 0);
1476
1477   if (event != NULL)
1478   {
1479      if (event->iptkey == IPT_UI_LEFT || event->iptkey == IPT_UI_RIGHT) {
1480         ui_set_use_natural_keyboard(machine, natural ^ TRUE);
1481         ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF);
1482      }
1483   }
1484}
1485
1486/*-------------------------------------------------
14631487    menu_main_populate - populate the main menu
14641488-------------------------------------------------*/
14651489
r7335r7336
15001524   if (has_analog)
15011525      ui_menu_item_append(menu, "Analog Controls", NULL, 0, (void *)menu_analog);
15021526
1503#ifndef MESS
15041527   /* add bookkeeping menu */
15051528   ui_menu_item_append(menu, "Bookkeeping Info", NULL, 0, (void *)menu_bookkeeping);
1506#endif
15071529
15081530   /* add game info menu */
15091531   ui_menu_item_append(menu, CAPSTARTGAMENOUN " Information", NULL, 0, (void *)menu_game_info);
r7335r7336
15131535   ui_mess_main_menu_populate(machine, menu);
15141536#endif /* MESS */
15151537
1538     /* add keyboard mode menu */
1539     if (input_machine_have_keyboard(machine) && inputx_can_post(machine))
1540      ui_menu_item_append(menu, "Keyboard Mode", NULL, 0, (void*)ui_menu_keyboard_mode);
1541
15161542   /* add sliders menu */
15171543   ui_menu_item_append(menu, "Slider Controls", NULL, 0, (void *)menu_sliders);
15181544
r7335r7336
23832409    information menu
23842410-------------------------------------------------*/
23852411
2386#ifndef MESS
23872412static void menu_bookkeeping(running_machine *machine, ui_menu *menu, void *parameter, void *state)
23882413{
23892414   attotime *prevtime;
r7335r7336
24062431   /* process the menu */
24072432   ui_menu_process(machine, menu, 0);
24082433}
2409#endif
24102434
24112435
24122436/*-------------------------------------------------
r7335r7336
24142438    information menu
24152439-------------------------------------------------*/
24162440
2417#ifndef MESS
24182441static void menu_bookkeeping_populate(running_machine *machine, ui_menu *menu, attotime *curtime)
24192442{
24202443   int tickets = get_dispensed_tickets(machine);
r7335r7336
24542477   /* append the single item */
24552478   ui_menu_item_append(menu, tempstring, NULL, MENU_FLAG_MULTILINE, NULL);
24562479}
2457#endif
24582480
24592481
24602482/*-------------------------------------------------
src/emu/emu.mak
r7335r7336
182182
183183EMUVIDEOOBJS = \
184184   $(EMUVIDEO)/generic.o \
185   $(EMUVIDEO)/hd63484.o \
186185   $(EMUVIDEO)/mc6845.o \
187186   $(EMUVIDEO)/poly.o \
188187   $(EMUVIDEO)/resnet.o \
src/emu/inptport.c
r7335r7336
9898#include "profiler.h"
9999#include "ui.h"
100100#include "uiinput.h"
101#include "debug/debugcon.h"
101102
102103#include <ctype.h>
103104#include <time.h>
104105
105#ifdef MESS
106#include "uimess.h"
107#endif /* MESS */
108
109
110106/* temporary: set this to 1 to enable the originally defined behavior that
111107   a field specified via PORT_MODIFY which intersects a previously-defined
112108   field completely wipes out the previous definition */
r7335r7336
130126#define JOYDIR_LEFT_BIT      (1 << JOYDIR_LEFT)
131127#define JOYDIR_RIGHT_BIT   (1 << JOYDIR_RIGHT)
132128
129#define NUM_SIMUL_KEYS   (UCHAR_SHIFT_END - UCHAR_SHIFT_BEGIN + 1)
130#define LOG_INPUTX      0
131#define SPACE_COUNT      3
132#define INVALID_CHAR   '?'
133#define IP_NAME_DEFAULT   NULL
133134
134135
135136/***************************************************************************
r7335r7336
268269   UINT32                  playback_accumulated_frames;/* accumulated frames during playback */
269270};
270271
272typedef const input_port_config *input_port_config_c;
273typedef const input_field_config *input_field_config_c;
271274
272275
276typedef struct _inputx_code inputx_code;
277struct _inputx_code
278{
279   unicode_char ch;
280   input_field_config_c field[NUM_SIMUL_KEYS];
281};
282
283typedef struct _key_buffer key_buffer;
284struct _key_buffer
285{
286   int begin_pos;
287   int end_pos;
288   unsigned int status_keydown : 1;
289   unicode_char buffer[4096];
290};
291
292typedef struct _char_info char_info;
293struct _char_info
294{
295   unicode_char ch;
296   const char *name;
297   const char *alternate;   /* alternative string, in UTF-8 */
298};
299
273300/***************************************************************************
274301    MACROS
275302***************************************************************************/
r7335r7336
291318static const char *const seqtypestrings[] = { "standard", "decrement", "increment" };
292319
293320
321static const char_info charinfo[] =
322{
323   { 0x0008,               "Backspace",   NULL },      /* Backspace */
324   { 0x0009,               "Tab",         "    " },   /* Tab */
325   { 0x000c,               "Clear",      NULL },      /* Clear */
326   { 0x000d,               "Enter",      NULL },      /* Enter */
327   { 0x001a,               "Esc",         NULL },      /* Esc */
328   { 0x0020,               "Space",      " " },      /* Space */
329   { 0x0061,               NULL,         "A" },      /* a */
330   { 0x0062,               NULL,         "B" },      /* b */
331   { 0x0063,               NULL,         "C" },      /* c */
332   { 0x0064,               NULL,         "D" },      /* d */
333   { 0x0065,               NULL,         "E" },      /* e */
334   { 0x0066,               NULL,         "F" },      /* f */
335   { 0x0067,               NULL,         "G" },      /* g */
336   { 0x0068,               NULL,         "H" },      /* h */
337   { 0x0069,               NULL,         "I" },      /* i */
338   { 0x006a,               NULL,         "J" },      /* j */
339   { 0x006b,               NULL,         "K" },      /* k */
340   { 0x006c,               NULL,         "L" },      /* l */
341   { 0x006d,               NULL,         "M" },      /* m */
342   { 0x006e,               NULL,         "N" },      /* n */
343   { 0x006f,               NULL,         "O" },      /* o */
344   { 0x0070,               NULL,         "P" },      /* p */
345   { 0x0071,               NULL,         "Q" },      /* q */
346   { 0x0072,               NULL,         "R" },      /* r */
347   { 0x0073,               NULL,         "S" },      /* s */
348   { 0x0074,               NULL,         "T" },      /* t */
349   { 0x0075,               NULL,         "U" },      /* u */
350   { 0x0076,               NULL,         "V" },      /* v */
351   { 0x0077,               NULL,         "W" },      /* w */
352   { 0x0078,               NULL,         "X" },      /* x */
353   { 0x0079,               NULL,         "Y" },      /* y */
354   { 0x007a,               NULL,         "Z" },      /* z */
355   { 0x00a0,               NULL,         " " },      /* non breaking space */
356   { 0x00a1,               NULL,         "!" },      /* inverted exclaimation mark */
357   { 0x00a6,               NULL,         "|" },      /* broken bar */
358   { 0x00a9,               NULL,         "(c)" },   /* copyright sign */
359   { 0x00ab,               NULL,         "<<" },      /* left pointing double angle */
360   { 0x00ae,               NULL,         "(r)" },   /* registered sign */
361   { 0x00bb,               NULL,         ">>" },      /* right pointing double angle */
362   { 0x00bc,               NULL,         "1/4" },   /* vulgar fraction one quarter */
363   { 0x00bd,               NULL,         "1/2" },   /* vulgar fraction one half */
364   { 0x00be,               NULL,         "3/4" },   /* vulgar fraction three quarters */
365   { 0x00bf,               NULL,         "?" },      /* inverted question mark */
366   { 0x00c0,               NULL,         "A" },      /* 'A' grave */
367   { 0x00c1,               NULL,         "A" },      /* 'A' acute */
368   { 0x00c2,               NULL,         "A" },      /* 'A' circumflex */
369   { 0x00c3,               NULL,         "A" },      /* 'A' tilde */
370   { 0x00c4,               NULL,         "A" },      /* 'A' diaeresis */
371   { 0x00c5,               NULL,         "A" },      /* 'A' ring above */
372   { 0x00c6,               NULL,         "AE" },      /* 'AE' ligature */
373   { 0x00c7,               NULL,         "C" },      /* 'C' cedilla */
374   { 0x00c8,               NULL,         "E" },      /* 'E' grave */
375   { 0x00c9,               NULL,         "E" },      /* 'E' acute */
376   { 0x00ca,               NULL,         "E" },      /* 'E' circumflex */
377   { 0x00cb,               NULL,         "E" },      /* 'E' diaeresis */
378   { 0x00cc,               NULL,         "I" },      /* 'I' grave */
379   { 0x00cd,               NULL,         "I" },      /* 'I' acute */
380   { 0x00ce,               NULL,         "I" },      /* 'I' circumflex */
381   { 0x00cf,               NULL,         "I" },      /* 'I' diaeresis */
382   { 0x00d0,               NULL,         "D" },      /* 'ETH' */
383   { 0x00d1,               NULL,         "N" },      /* 'N' tilde */
384   { 0x00d2,               NULL,         "O" },      /* 'O' grave */
385   { 0x00d3,               NULL,         "O" },      /* 'O' acute */
386   { 0x00d4,               NULL,         "O" },      /* 'O' circumflex */
387   { 0x00d5,               NULL,         "O" },      /* 'O' tilde */
388   { 0x00d6,               NULL,         "O" },      /* 'O' diaeresis */
389   { 0x00d7,               NULL,         "X" },      /* multiplication sign */
390   { 0x00d8,               NULL,         "O" },      /* 'O' stroke */
391   { 0x00d9,               NULL,         "U" },      /* 'U' grave */
392   { 0x00da,               NULL,         "U" },      /* 'U' acute */
393   { 0x00db,               NULL,         "U" },      /* 'U' circumflex */
394   { 0x00dc,               NULL,         "U" },      /* 'U' diaeresis */
395   { 0x00dd,               NULL,         "Y" },      /* 'Y' acute */
396   { 0x00df,               NULL,         "SS" },      /* sharp S */
397   { 0x00e0,               NULL,         "a" },      /* 'a' grave */
398   { 0x00e1,               NULL,         "a" },      /* 'a' acute */
399   { 0x00e2,               NULL,         "a" },      /* 'a' circumflex */
400   { 0x00e3,               NULL,         "a" },      /* 'a' tilde */
401   { 0x00e4,               NULL,         "a" },      /* 'a' diaeresis */
402   { 0x00e5,               NULL,         "a" },      /* 'a' ring above */
403   { 0x00e6,               NULL,         "ae" },      /* 'ae' ligature */
404   { 0x00e7,               NULL,         "c" },      /* 'c' cedilla */
405   { 0x00e8,               NULL,         "e" },      /* 'e' grave */
406   { 0x00e9,               NULL,         "e" },      /* 'e' acute */
407   { 0x00ea,               NULL,         "e" },      /* 'e' circumflex */
408   { 0x00eb,               NULL,         "e" },      /* 'e' diaeresis */
409   { 0x00ec,               NULL,         "i" },      /* 'i' grave */
410   { 0x00ed,               NULL,         "i" },      /* 'i' acute */
411   { 0x00ee,               NULL,         "i" },      /* 'i' circumflex */
412   { 0x00ef,               NULL,         "i" },      /* 'i' diaeresis */
413   { 0x00f0,               NULL,         "d" },      /* 'eth' */
414   { 0x00f1,               NULL,         "n" },      /* 'n' tilde */
415   { 0x00f2,               NULL,         "o" },      /* 'o' grave */
416   { 0x00f3,               NULL,         "o" },      /* 'o' acute */
417   { 0x00f4,               NULL,         "o" },      /* 'o' circumflex */
418   { 0x00f5,               NULL,         "o" },      /* 'o' tilde */
419   { 0x00f6,               NULL,         "o" },      /* 'o' diaeresis */
420   { 0x00f8,               NULL,         "o" },      /* 'o' stroke */
421   { 0x00f9,               NULL,         "u" },      /* 'u' grave */
422   { 0x00fa,               NULL,         "u" },      /* 'u' acute */
423   { 0x00fb,               NULL,         "u" },      /* 'u' circumflex */
424   { 0x00fc,               NULL,         "u" },      /* 'u' diaeresis */
425   { 0x00fd,               NULL,         "y" },      /* 'y' acute */
426   { 0x00ff,               NULL,         "y" },      /* 'y' diaeresis */
427   { 0x2010,               NULL,         "-" },      /* hyphen */
428   { 0x2011,               NULL,         "-" },      /* non-breaking hyphen */
429   { 0x2012,               NULL,         "-" },      /* figure dash */
430   { 0x2013,               NULL,         "-" },      /* en dash */
431   { 0x2014,               NULL,         "-" },      /* em dash */
432   { 0x2015,               NULL,         "-" },      /* horizontal dash */
433   { 0x2018,               NULL,         "\'" },      /* left single quotation mark */
434   { 0x2019,               NULL,         "\'" },      /* right single quotation mark */
435   { 0x201a,               NULL,         "\'" },      /* single low quotation mark */
436   { 0x201b,               NULL,         "\'" },      /* single high reversed quotation mark */
437   { 0x201c,               NULL,         "\"" },      /* left double quotation mark */
438   { 0x201d,               NULL,         "\"" },      /* right double quotation mark */
439   { 0x201e,               NULL,         "\"" },      /* double low quotation mark */
440   { 0x201f,               NULL,         "\"" },      /* double high reversed quotation mark */
441   { 0x2024,               NULL,         "." },      /* one dot leader */
442   { 0x2025,               NULL,         ".." },      /* two dot leader */
443   { 0x2026,               NULL,         "..." },   /* horizontal ellipsis */
444   { 0x2047,               NULL,         "??" },      /* double question mark */
445   { 0x2048,               NULL,         "?!" },      /* question exclamation mark */
446   { 0x2049,               NULL,         "!?" },      /* exclamation question mark */
447   { 0xff01,               NULL,         "!" },      /* fullwidth exclamation point */
448   { 0xff02,               NULL,         "\"" },      /* fullwidth quotation mark */
449   { 0xff03,               NULL,         "#" },      /* fullwidth number sign */
450   { 0xff04,               NULL,         "$" },      /* fullwidth dollar sign */
451   { 0xff05,               NULL,         "%" },      /* fullwidth percent sign */
452   { 0xff06,               NULL,         "&" },      /* fullwidth ampersand */
453   { 0xff07,               NULL,         "\'" },      /* fullwidth apostrophe */
454   { 0xff08,               NULL,         "(" },      /* fullwidth left parenthesis */
455   { 0xff09,               NULL,         ")" },      /* fullwidth right parenthesis */
456   { 0xff0a,               NULL,         "*" },      /* fullwidth asterisk */
457   { 0xff0b,               NULL,         "+" },      /* fullwidth plus */
458   { 0xff0c,               NULL,         "," },      /* fullwidth comma */
459   { 0xff0d,               NULL,         "-" },      /* fullwidth minus */
460   { 0xff0e,               NULL,         "." },      /* fullwidth period */
461   { 0xff0f,               NULL,         "/" },      /* fullwidth slash */
462   { 0xff10,               NULL,         "0" },      /* fullwidth zero */
463   { 0xff11,               NULL,         "1" },      /* fullwidth one */
464   { 0xff12,               NULL,         "2" },      /* fullwidth two */
465   { 0xff13,               NULL,         "3" },      /* fullwidth three */
466   { 0xff14,               NULL,         "4" },      /* fullwidth four */
467   { 0xff15,               NULL,         "5" },      /* fullwidth five */
468   { 0xff16,               NULL,         "6" },      /* fullwidth six */
469   { 0xff17,               NULL,         "7" },      /* fullwidth seven */
470   { 0xff18,               NULL,         "8" },      /* fullwidth eight */
471   { 0xff19,               NULL,         "9" },      /* fullwidth nine */
472   { 0xff1a,               NULL,         ":" },      /* fullwidth colon */
473   { 0xff1b,               NULL,         ";" },      /* fullwidth semicolon */
474   { 0xff1c,               NULL,         "<" },      /* fullwidth less than sign */
475   { 0xff1d,               NULL,         "=" },      /* fullwidth equals sign */
476   { 0xff1e,               NULL,         ">" },      /* fullwidth greater than sign */
477   { 0xff1f,               NULL,         "?" },      /* fullwidth question mark */
478   { 0xff20,               NULL,         "@" },      /* fullwidth at sign */
479   { 0xff21,               NULL,         "A" },      /* fullwidth 'A' */
480   { 0xff22,               NULL,         "B" },      /* fullwidth 'B' */
481   { 0xff23,               NULL,         "C" },      /* fullwidth 'C' */
482   { 0xff24,               NULL,         "D" },      /* fullwidth 'D' */
483   { 0xff25,               NULL,         "E" },      /* fullwidth 'E' */
484   { 0xff26,               NULL,         "F" },      /* fullwidth 'F' */
485   { 0xff27,               NULL,         "G" },      /* fullwidth 'G' */
486   { 0xff28,               NULL,         "H" },      /* fullwidth 'H' */
487   { 0xff29,               NULL,         "I" },      /* fullwidth 'I' */
488   { 0xff2a,               NULL,         "J" },      /* fullwidth 'J' */
489   { 0xff2b,               NULL,         "K" },      /* fullwidth 'K' */
490   { 0xff2c,               NULL,         "L" },      /* fullwidth 'L' */
491   { 0xff2d,               NULL,         "M" },      /* fullwidth 'M' */
492   { 0xff2e,               NULL,         "N" },      /* fullwidth 'N' */
493   { 0xff2f,               NULL,         "O" },      /* fullwidth 'O' */
494   { 0xff30,               NULL,         "P" },      /* fullwidth 'P' */
495   { 0xff31,               NULL,         "Q" },      /* fullwidth 'Q' */
496   { 0xff32,               NULL,         "R" },      /* fullwidth 'R' */
497   { 0xff33,               NULL,         "S" },      /* fullwidth 'S' */
498   { 0xff34,               NULL,         "T" },      /* fullwidth 'T' */
499   { 0xff35,               NULL,         "U" },      /* fullwidth 'U' */
500   { 0xff36,               NULL,         "V" },      /* fullwidth 'V' */
501   { 0xff37,               NULL,         "W" },      /* fullwidth 'W' */
502   { 0xff38,               NULL,         "X" },      /* fullwidth 'X' */
503   { 0xff39,               NULL,         "Y" },      /* fullwidth 'Y' */
504   { 0xff3a,               NULL,         "Z" },      /* fullwidth 'Z' */
505   { 0xff3b,               NULL,         "[" },      /* fullwidth left bracket */
506   { 0xff3c,               NULL,         "\\" },      /* fullwidth backslash */
507   { 0xff3d,               NULL,         "]"   },      /* fullwidth right bracket */
508   { 0xff3e,               NULL,         "^" },      /* fullwidth caret */
509   { 0xff3f,               NULL,         "_" },      /* fullwidth underscore */
510   { 0xff40,               NULL,         "`" },      /* fullwidth backquote */
511   { 0xff41,               NULL,         "a" },      /* fullwidth 'a' */
512   { 0xff42,               NULL,         "b" },      /* fullwidth 'b' */
513   { 0xff43,               NULL,         "c" },      /* fullwidth 'c' */
514   { 0xff44,               NULL,         "d" },      /* fullwidth 'd' */
515   { 0xff45,               NULL,         "e" },      /* fullwidth 'e' */
516   { 0xff46,               NULL,         "f" },      /* fullwidth 'f' */
517   { 0xff47,               NULL,         "g" },      /* fullwidth 'g' */
518   { 0xff48,               NULL,         "h" },      /* fullwidth 'h' */
519   { 0xff49,               NULL,         "i" },      /* fullwidth 'i' */
520   { 0xff4a,               NULL,         "j" },      /* fullwidth 'j' */
521   { 0xff4b,               NULL,         "k" },      /* fullwidth 'k' */
522   { 0xff4c,               NULL,         "l" },      /* fullwidth 'l' */
523   { 0xff4d,               NULL,         "m" },      /* fullwidth 'm' */
524   { 0xff4e,               NULL,         "n" },      /* fullwidth 'n' */
525   { 0xff4f,               NULL,         "o" },      /* fullwidth 'o' */
526   { 0xff50,               NULL,         "p" },      /* fullwidth 'p' */
527   { 0xff51,               NULL,         "q" },      /* fullwidth 'q' */
528   { 0xff52,               NULL,         "r" },      /* fullwidth 'r' */
529   { 0xff53,               NULL,         "s" },      /* fullwidth 's' */
530   { 0xff54,               NULL,         "t" },      /* fullwidth 't' */
531   { 0xff55,               NULL,         "u" },      /* fullwidth 'u' */
532   { 0xff56,               NULL,         "v" },      /* fullwidth 'v' */
533   { 0xff57,               NULL,         "w" },      /* fullwidth 'w' */
534   { 0xff58,               NULL,         "x" },      /* fullwidth 'x' */
535   { 0xff59,               NULL,         "y" },      /* fullwidth 'y' */
536   { 0xff5a,               NULL,         "z" },      /* fullwidth 'z' */
537   { 0xff5b,               NULL,         "{" },      /* fullwidth left brace */
538   { 0xff5c,               NULL,         "|" },      /* fullwidth vertical bar */
539   { 0xff5d,               NULL,         "}" },      /* fullwidth right brace */
540   { 0xff5e,               NULL,         "~" },      /* fullwidth tilde */
541   { 0xff5f,               NULL,         "((" },      /* fullwidth double left parenthesis */
542   { 0xff60,               NULL,         "))" },      /* fullwidth double right parenthesis */
543   { 0xffe0,               NULL,         "\xC2\xA2" },      /* fullwidth cent sign */
544   { 0xffe1,               NULL,         "\xC2\xA3" },      /* fullwidth pound sign */
545   { 0xffe4,               NULL,         "\xC2\xA4" },      /* fullwidth broken bar */
546   { 0xffe5,               NULL,         "\xC2\xA5" },      /* fullwidth yen sign */
547   { 0xffe6,               NULL,         "\xE2\x82\xA9" },   /* fullwidth won sign */
548   { 0xffe9,               NULL,         "\xE2\x86\x90" },   /* fullwidth left arrow */
549   { 0xffea,               NULL,         "\xE2\x86\x91" },   /* fullwidth up arrow */
550   { 0xffeb,               NULL,         "\xE2\x86\x92" },   /* fullwidth right arrow */
551   { 0xffec,               NULL,         "\xE2\x86\x93" },   /* fullwidth down arrow */
552   { 0xffed,               NULL,         "\xE2\x96\xAA" },   /* fullwidth solid box */
553   { 0xffee,               NULL,         "\xE2\x97\xA6" },   /* fullwidth open circle */
554   { UCHAR_SHIFT_1,         "Shift",      NULL },      /* Shift key */
555   { UCHAR_SHIFT_2,         "Ctrl",         NULL },      /* Ctrl key */
556   { UCHAR_MAMEKEY(F1),      "F1",         NULL },      /* F1 function key */
557   { UCHAR_MAMEKEY(F2),      "F2",         NULL },      /* F2 function key */
558   { UCHAR_MAMEKEY(F3),      "F3",         NULL },      /* F3 function key */
559   { UCHAR_MAMEKEY(F4),      "F4",         NULL },      /* F4 function key */
560   { UCHAR_MAMEKEY(F5),      "F5",         NULL },      /* F5 function key */
561   { UCHAR_MAMEKEY(F6),      "F6",         NULL },      /* F6 function key */
562   { UCHAR_MAMEKEY(F7),      "F7",         NULL },      /* F7 function key */
563   { UCHAR_MAMEKEY(F8),      "F8",         NULL },      /* F8 function key */
564   { UCHAR_MAMEKEY(F9),      "F9",         NULL },      /* F9 function key */
565   { UCHAR_MAMEKEY(F10),      "F10",         NULL },      /* F10 function key */
566   { UCHAR_MAMEKEY(F11),      "F11",         NULL },      /* F11 function key */
567   { UCHAR_MAMEKEY(F12),      "F12",         NULL },      /* F12 function key */
568   { UCHAR_MAMEKEY(F13),      "F13",         NULL },      /* F13 function key */
569   { UCHAR_MAMEKEY(F14),      "F14",         NULL },      /* F14 function key */
570   { UCHAR_MAMEKEY(F15),      "F15",         NULL },      /* F15 function key */
571   { UCHAR_MAMEKEY(ESC),      "Esc",         "\033" },   /* Esc key */
572   { UCHAR_MAMEKEY(INSERT),   "Insert",      NULL },      /* Insert key */
573   { UCHAR_MAMEKEY(DEL),      "Delete",      "\010" },   /* Delete key */
574   { UCHAR_MAMEKEY(HOME),      "Home",         "\014" },   /* Home key */
575   { UCHAR_MAMEKEY(END),      "End",         NULL },      /* End key */
576   { UCHAR_MAMEKEY(PGUP),      "Page Up",      NULL },      /* Page Up key */
577   { UCHAR_MAMEKEY(PGDN),      "Page Down",   NULL },      /* Page Down key */
578   { UCHAR_MAMEKEY(LEFT),      "Cursor Left",   NULL },      /* Cursor Left */
579   { UCHAR_MAMEKEY(RIGHT),      "Cursor Right",   NULL },      /* Cursor Right */
580   { UCHAR_MAMEKEY(UP),      "Cursor Up",   NULL },      /* Cursor Up */
581   { UCHAR_MAMEKEY(DOWN),      "Cursor Down",   NULL },      /* Cursor Down */
582   { UCHAR_MAMEKEY(0_PAD),      "Keypad 0",      NULL },      /* 0 on the numeric keypad */
583   { UCHAR_MAMEKEY(1_PAD),      "Keypad 1",      NULL },      /* 1 on the numeric keypad */
584   { UCHAR_MAMEKEY(2_PAD),      "Keypad 2",      NULL },      /* 2 on the numeric keypad */
585   { UCHAR_MAMEKEY(3_PAD),      "Keypad 3",      NULL },      /* 3 on the numeric keypad */
586   { UCHAR_MAMEKEY(4_PAD),      "Keypad 4",      NULL },      /* 4 on the numeric keypad */
587   { UCHAR_MAMEKEY(5_PAD),      "Keypad 5",      NULL },      /* 5 on the numeric keypad */
588   { UCHAR_MAMEKEY(6_PAD),      "Keypad 6",      NULL },      /* 6 on the numeric keypad */
589   { UCHAR_MAMEKEY(7_PAD),      "Keypad 7",      NULL },      /* 7 on the numeric keypad */
590   { UCHAR_MAMEKEY(8_PAD),      "Keypad 8",      NULL },      /* 8 on the numeric keypad */
591   { UCHAR_MAMEKEY(9_PAD),      "Keypad 9",      NULL },      /* 9 on the numeric keypad */
592   { UCHAR_MAMEKEY(SLASH_PAD),   "Keypad /",      NULL },      /* / on the numeric keypad */
593   { UCHAR_MAMEKEY(ASTERISK),   "Keypad *",      NULL },      /* * on the numeric keypad */
594   { UCHAR_MAMEKEY(MINUS_PAD),   "Keypad -",      NULL },      /* - on the numeric Keypad */
595   { UCHAR_MAMEKEY(PLUS_PAD),   "Keypad +",      NULL },      /* + on the numeric Keypad */
596   { UCHAR_MAMEKEY(DEL_PAD),   "Keypad .",      NULL },      /* . on the numeric keypad */
597   { UCHAR_MAMEKEY(ENTER_PAD),   "Keypad Enter",   NULL },      /* Enter on the numeric keypad */
598   { UCHAR_MAMEKEY(PRTSCR),   "Print Screen",   NULL },      /* Print Screen key */
599   { UCHAR_MAMEKEY(PAUSE),      "Pause",      NULL },      /* Pause key */
600   { UCHAR_MAMEKEY(LSHIFT),   "Left Shift",   NULL },      /* Left Shift key */
601   { UCHAR_MAMEKEY(RSHIFT),   "Right Shift",   NULL },      /* Right Shift key */
602   { UCHAR_MAMEKEY(LCONTROL),   "Left Ctrl",   NULL },      /* Left Control key */
603   { UCHAR_MAMEKEY(RCONTROL),   "Right Ctrl",   NULL },      /* Right Control key */
604   { UCHAR_MAMEKEY(LALT),      "Left Alt",      NULL },      /* Left Alt key */
605   { UCHAR_MAMEKEY(RALT),      "Right Alt",   NULL },      /* Right Alt key */
606   { UCHAR_MAMEKEY(SCRLOCK),   "Scroll Lock",   NULL },      /* Scroll Lock key */
607   { UCHAR_MAMEKEY(NUMLOCK),   "Num Lock",      NULL },      /* Num Lock key */
608   { UCHAR_MAMEKEY(CAPSLOCK),   "Caps Lock",   NULL },      /* Caps Lock key */
609   { UCHAR_MAMEKEY(LWIN),      "Left Win",      NULL },      /* Left Win key */
610   { UCHAR_MAMEKEY(RWIN),      "Right Win",   NULL },      /* Right Win key */
611   { UCHAR_MAMEKEY(MENU),      "Menu",         NULL },      /* Menu key */
612   { UCHAR_MAMEKEY(CANCEL),   "Break",      NULL }      /* Break/Pause key */
613};
294614
615static inputx_code *codes;
616static key_buffer *keybuffer;
617static emu_timer *inputx_timer;
618static int (*queue_chars)(const unicode_char *text, size_t text_len);
619static int (*accept_char)(unicode_char ch);
620static int (*charqueue_empty)(void);
621static attotime current_rate;
622
623static TIMER_CALLBACK(inputx_timerproc);
624
625
626/*  Debugging commands and handlers. */
627static void execute_input(running_machine *machine, int ref, int params, const char *param[]);
628static void execute_dumpkbd(running_machine *machine, int ref, int params, const char *param[]);
629
295630/***************************************************************************
296631    COMMON SHARED STRINGS
297632***************************************************************************/
r7335r7336
15631898   }
15641899}
15651900
1901/*-------------------------------------------------
1902    get_keyboard_code - accesses a particular
1903    keyboard code
1904-------------------------------------------------*/
15661905
1906static unicode_char get_keyboard_code(const input_field_config *field, int i)
1907{
1908   unicode_char ch = field->chars[i];
1909
1910   /* special hack to allow for PORT_CODE('\xA3') */
1911   if ((ch >= 0xFFFFFF80) && (ch <= 0xFFFFFFFF))
1912      ch &= 0xFF;
1913   return ch;
1914}
1915
15671916/*-------------------------------------------------
1917    get_keyboard_key_name - builds the name of
1918    a key based on natural keyboard characters
1919-------------------------------------------------*/
1920
1921static astring *get_keyboard_key_name(const input_field_config *field)
1922{
1923   astring *result = astring_alloc();
1924   int i;
1925   unicode_char ch;
1926
1927
1928   /* loop through each character on the field*/
1929   for (i = 0; i < ARRAY_LENGTH(field->chars) && (field->chars[i] != '\0'); i++)
1930   {
1931      ch = get_keyboard_code(field, i);
1932      astring_printf(result, "%s%-*s ", astring_c(result), MAX(SPACE_COUNT - 1, 0), inputx_key_name(ch));
1933   }
1934
1935   /* trim extra spaces */
1936   astring_trimspace(result);
1937
1938   /* special case */
1939   if (astring_len(result) == 0)
1940      astring_cpyc(result, "Unnamed Key");
1941
1942   return result;
1943}
1944
1945/*-------------------------------------------------
15681946    init_port_state - initialize the live port
15691947    states based on the tokens
15701948-------------------------------------------------*/
r7335r7336
16392017            writedevicetail = &(*writedevicetail)->next;
16402018         }
16412019
1642#ifdef MESS
1643         /* MESS-specific code to name keyboard key names */
2020         /* Name keyboard key names */
16442021         if ((field->type == IPT_KEYBOARD) && (field->name == NULL))
16452022         {
1646            astring *name = mess_get_keyboard_key_name(field);
2023            astring *name = get_keyboard_key_name(field);
16472024            if (name != NULL)
16482025            {
16492026               field->state->name = auto_strdup(machine, astring_c(name));
16502027               astring_free(name);
16512028            }
16522029         }
1653#endif /* MESS */
16542030      }
16552031   }
16562032
r7335r7336
19522328   frame_update(machine);
19532329}
19542330
2331static key_buffer *get_buffer(running_machine *machine)
2332{
2333   assert(inputx_can_post(machine));
2334   return (key_buffer *) keybuffer;
2335}
19552336
2337
2338
2339static const inputx_code *find_code(unicode_char ch)
2340{
2341   int i;
2342
2343   assert(codes);
2344   for (i = 0; codes[i].ch; i++)
2345   {
2346      if (codes[i].ch == ch)
2347         return &codes[i];
2348   }
2349   return NULL;
2350}
2351
19562352/*-------------------------------------------------
2353    input_port_update_hook - hook function
2354    called from core to allow for natural keyboard
2355-------------------------------------------------*/
2356
2357static void input_port_update_hook(running_machine *machine, const input_port_config *port, input_port_value *digital)
2358{
2359   const key_buffer *keybuf;
2360   const inputx_code *code;
2361   unicode_char ch;
2362   int i;
2363   UINT32 value;
2364
2365   if (inputx_can_post(machine))
2366   {
2367      keybuf = get_buffer(machine);
2368
2369      /* is the key down right now? */
2370      if (keybuf->status_keydown && (keybuf->begin_pos != keybuf->end_pos))
2371      {
2372         /* identify the character that is down right now, and its component codes */
2373         ch = keybuf->buffer[keybuf->begin_pos];
2374         code = find_code(ch);
2375
2376         /* loop through this character's component codes */
2377         if (code != NULL)
2378         {
2379            for (i = 0; i < ARRAY_LENGTH(code->field) && (code->field[i] != NULL); i++)
2380            {
2381               if (code->field[i]->port == port)
2382               {
2383                  value = code->field[i]->mask;
2384                  *digital |= value;
2385               }
2386            }
2387         }
2388      }
2389   }
2390}
2391
2392
2393/*-------------------------------------------------
19572394    frame_update - core logic for per-frame input
19582395    port updating
19592396-------------------------------------------------*/
r7335r7336
20242461               port->state->digital |= field->mask;
20252462         }
20262463
2027#ifdef MESS
20282464      /* hook for MESS's natural keyboard support */
2029      mess_input_port_update_hook(machine, port, &port->state->digital);
2030#endif /* MESS */
2031
2465      input_port_update_hook(machine, port, &port->state->digital);
2466     
20322467      /* handle playback/record */
20332468      playback_port(port);
20342469      record_port(port);
r7335r7336
22992734      changed = TRUE;
23002735   }
23012736
2302#ifdef MESS
2303   /* (MESS-specific) check for disabled keyboard */
2304   if (field->type == IPT_KEYBOARD && ui_mess_keyboard_disabled(field->port->machine))
2737   if (field->type == IPT_KEYBOARD && ui_get_use_natural_keyboard(field->port->machine))
23052738      return FALSE;
2306#endif /* MESS */
23072739
23082740   /* if this is a switch-down event, handle impulse and toggle */
23092741   if (changed && curstate)
r7335r7336
42254657   }
42264658   return have_keyboard;
42274659}
4660
4661/***************************************************************************
4662    MISCELLANEOUS
4663***************************************************************************/
4664
4665/*-------------------------------------------------
4666    find_charinfo - looks up information about a
4667    particular character
4668-------------------------------------------------*/
4669
4670static const char_info *find_charinfo(unicode_char target_char)
4671{
4672   int low = 0;
4673   int high = ARRAY_LENGTH(charinfo);
4674   int i;
4675   unicode_char ch;
4676
4677   /* perform a simple binary search to find the proper alternate */
4678   while(high > low)
4679   {
4680      i = (high + low) / 2;
4681      ch = charinfo[i].ch;
4682      if (ch < target_char)
4683         low = i + 1;
4684      else if (ch > target_char)
4685         high = i;
4686      else
4687         return &charinfo[i];
4688   }
4689   return NULL;
4690}
4691
4692
4693
4694/***************************************************************************
4695    CODE ASSEMBLING
4696***************************************************************************/
4697
4698/*-------------------------------------------------
4699    code_point_string - obtain a string representation of a
4700    given code; used for logging and debugging
4701-------------------------------------------------*/
4702
4703static const char *code_point_string(running_machine *machine, unicode_char ch)
4704{
4705   static char buf[16];
4706   const char *result = buf;
4707
4708   switch(ch)
4709   {
4710      /* check some magic values */
4711      case '\0':   strcpy(buf, "\\0");      break;
4712      case '\r':   strcpy(buf, "\\r");      break;
4713      case '\n':   strcpy(buf, "\\n");      break;
4714      case '\t':   strcpy(buf, "\\t");      break;
4715
4716      default:
4717         if ((ch >= 32) && (ch < 128))
4718         {
4719            /* seven bit ASCII is easy */
4720            buf[0] = (char) ch;
4721            buf[1] = '\0';
4722         }
4723         else if (ch >= UCHAR_MAMEKEY_BEGIN)
4724         {
4725            /* try to obtain a codename with input_code_name(); this can result in an empty string */
4726            astring astr;
4727            input_code_name(machine, astr, (input_code) ch - UCHAR_MAMEKEY_BEGIN);
4728            snprintf(buf, ARRAY_LENGTH(buf), "%s", astr.cstr());
4729         }
4730         else
4731         {
4732            /* empty string; resolve later */
4733            buf[0] = '\0';
4734         }
4735
4736         /* did we fail to resolve? if so, we have a last resort */
4737         if (buf[0] == '\0')
4738            snprintf(buf, ARRAY_LENGTH(buf), "U+%04X", (unsigned) ch);
4739         break;
4740   }
4741   return result;
4742}
4743
4744
4745/*-------------------------------------------------
4746    scan_keys - scans through input ports and
4747    sets up natural keyboard input mapping
4748-------------------------------------------------*/
4749
4750static int scan_keys(running_machine *machine, const input_port_config *portconfig, inputx_code *codes, input_port_config_c *ports, input_field_config_c *shift_ports, int keys, int shift)
4751{
4752   int code_count = 0;
4753   const input_port_config *port;
4754   const input_field_config *field;
4755   unicode_char code;
4756
4757   assert(keys < NUM_SIMUL_KEYS);
4758
4759   for (port = portconfig; port != NULL; port = port->next)
4760   {
4761      for (field = port->fieldlist; field != NULL; field = field->next)
4762      {
4763         if (field->type == IPT_KEYBOARD)
4764         {
4765            code = get_keyboard_code(field, shift);
4766            if (code != 0)
4767            {
4768               /* is this a shifter key? */
4769               if ((code >= UCHAR_SHIFT_BEGIN) && (code <= UCHAR_SHIFT_END))
4770               {
4771                  shift_ports[keys] = field;
4772                  code_count += scan_keys(machine,
4773                     portconfig,
4774                     codes ? &codes[code_count] : NULL,
4775                     ports,
4776                     shift_ports,
4777                     keys+1,
4778                     code - UCHAR_SHIFT_1 + 1);
4779               }
4780               else
4781               {
4782                  /* not a shifter key; record normally */
4783                  if (codes)
4784                  {
4785                     /* if we have a destination, record the codes used here */
4786                     memcpy((void *) codes[code_count].field, shift_ports, sizeof(shift_ports[0]) * keys);
4787                     codes[code_count].ch = code;
4788                     codes[code_count].field[keys] = field;
4789                  }
4790
4791                  /* increment the count */
4792                  code_count++;
4793
4794                  if (LOG_INPUTX)
4795                     logerror("inputx: code=%i (%s) port=%p field->name='%s'\n", (int) code, code_point_string(machine, code), port, field->name);
4796               }
4797            }
4798         }
4799      }
4800   }
4801   return code_count;
4802}
4803
4804
4805
4806/*-------------------------------------------------
4807    build_codes - given an input port table, create
4808    a input code table useful for mapping unicode
4809    chars
4810-------------------------------------------------*/
4811
4812static inputx_code *build_codes(running_machine *machine, const input_port_config *portconfig)
4813{
4814   inputx_code *codes = NULL;
4815   const input_port_config *ports[NUM_SIMUL_KEYS];
4816   const input_field_config *fields[NUM_SIMUL_KEYS];
4817   int code_count;
4818
4819   /* first count the number of codes */
4820   code_count = scan_keys(machine, portconfig, NULL, ports, fields, 0, 0);
4821   if (code_count > 0)
4822   {
4823      /* allocate the codes */
4824      codes = auto_alloc_array_clear(machine, inputx_code, code_count + 1);
4825
4826      /* and populate them */
4827      scan_keys(machine, portconfig, codes, ports, fields, 0, 0);
4828   }
4829   return codes;
4830}
4831
4832
4833
4834/***************************************************************************
4835    VALIDITY CHECKS
4836***************************************************************************/
4837
4838/*-------------------------------------------------
4839    validate_natural_keyboard_statics -
4840    validates natural keyboard static data
4841-------------------------------------------------*/
4842
4843int validate_natural_keyboard_statics(void)
4844{
4845   int i;
4846   int error = FALSE;
4847   unicode_char last_char = 0;
4848   const char_info *ci;
4849
4850   /* check to make sure that charinfo is in order */
4851   for (i = 0; i < ARRAY_LENGTH(charinfo); i++)
4852   {
4853      if (last_char >= charinfo[i].ch)
4854      {
4855         mame_printf_error("inputx: charinfo is out of order; 0x%08x should be higher than 0x%08x\n", charinfo[i].ch, last_char);
4856         error = TRUE;
4857      }
4858      last_char = charinfo[i].ch;
4859   }
4860
4861   /* check to make sure that I can look up everything on alternate_charmap */
4862   for (i = 0; i < ARRAY_LENGTH(charinfo); i++)
4863   {
4864      ci = find_charinfo(charinfo[i].ch);
4865      if (ci != &charinfo[i])
4866      {
4867         mame_printf_error("inputx: expected find_charinfo(0x%08x) to work properly\n", charinfo[i].ch);
4868         error = TRUE;
4869      }
4870   }
4871   return error;
4872}
4873
4874
4875
4876/***************************************************************************
4877    CORE IMPLEMENTATION
4878***************************************************************************/
4879
4880static void clear_keybuffer(running_machine *machine)
4881{
4882   keybuffer = NULL;
4883   queue_chars = NULL;
4884   codes = NULL;
4885}
4886
4887
4888
4889static void setup_keybuffer(running_machine *machine)
4890{
4891   inputx_timer = timer_alloc(machine, inputx_timerproc, NULL);
4892   keybuffer = auto_alloc_clear(machine, key_buffer);
4893   add_exit_callback(machine, clear_keybuffer);
4894}
4895
4896
4897
4898void inputx_init(running_machine *machine)
4899{
4900   codes = NULL;
4901   inputx_timer = NULL;
4902   queue_chars = NULL;
4903   accept_char = NULL;
4904   charqueue_empty = NULL;
4905   keybuffer = NULL;
4906
4907   if (machine->debug_flags & DEBUG_FLAG_ENABLED)
4908   {
4909      debug_console_register_command(machine, "input", CMDFLAG_NONE, 0, 1, 1, execute_input);
4910      debug_console_register_command(machine, "dumpkbd", CMDFLAG_NONE, 0, 0, 1, execute_dumpkbd);
4911   }
4912
4913   /* posting keys directly only makes sense for a computer */
4914   if (input_machine_have_keyboard(machine))
4915   {
4916      codes = build_codes(machine, machine->portlist.first());
4917      setup_keybuffer(machine);
4918   }
4919}
4920
4921
4922
4923void inputx_setup_natural_keyboard(
4924   int (*queue_chars_)(const unicode_char *text, size_t text_len),
4925   int (*accept_char_)(unicode_char ch),
4926   int (*charqueue_empty_)(void))
4927{
4928   queue_chars = queue_chars_;
4929   accept_char = accept_char_;
4930   charqueue_empty = charqueue_empty_;
4931}
4932
4933int inputx_can_post(running_machine *machine)
4934{
4935   return queue_chars || codes;
4936}
4937
4938
4939static int can_post_key_directly(unicode_char ch)
4940{
4941   int rc = FALSE;
4942   const inputx_code *code;
4943
4944   if (queue_chars)
4945   {
4946      rc = accept_char ? accept_char(ch) : TRUE;
4947   }
4948   else
4949   {
4950      code = find_code(ch);
4951      if (code)
4952         rc = code->field[0] != NULL;
4953   }
4954   return rc;
4955}
4956
4957
4958
4959static int can_post_key_alternate(unicode_char ch)
4960{
4961   const char *s;
4962   const char_info *ci;
4963   unicode_char uchar;
4964   int rc;
4965
4966   ci = find_charinfo(ch);
4967   s = ci ? ci->alternate : NULL;
4968   if (!s)
4969      return 0;
4970
4971   while(*s)
4972   {
4973      rc = uchar_from_utf8(&uchar, s, strlen(s));
4974      if (rc <= 0)
4975         return 0;
4976      if (!can_post_key_directly(uchar))
4977         return 0;
4978      s += rc;
4979   }
4980   return 1;
4981}
4982
4983
4984
4985int inputx_can_post_key(running_machine *machine, unicode_char ch)
4986{
4987   return inputx_can_post(machine) && (can_post_key_directly(ch) || can_post_key_alternate(ch));
4988}
4989
4990
4991
4992static attotime choose_delay(unicode_char ch)
4993{
4994   attoseconds_t delay = 0;
4995
4996   if (attotime_compare(current_rate, attotime_zero) != 0)
4997      return current_rate;
4998
4999   if (queue_chars)
5000   {
5001      /* systems with queue_chars can afford a much smaller delay */
5002      delay = DOUBLE_TO_ATTOSECONDS(0.01);
5003   }
5004   else
5005   {
5006      switch(ch) {
5007      case '\r':
5008         delay = DOUBLE_TO_ATTOSECONDS(0.2);
5009         break;
5010
5011      default:
5012         delay = DOUBLE_TO_ATTOSECONDS(0.05);
5013         break;
5014      }
5015   }
5016   return attotime_make(0, delay);
5017}
5018
5019
5020
5021static void internal_post_key(running_machine *machine, unicode_char ch)
5022{
5023   key_buffer *keybuf;
5024
5025   keybuf = get_buffer(machine);
5026
5027   /* need to start up the timer? */
5028   if (keybuf->begin_pos == keybuf->end_pos)
5029   {
5030      timer_adjust_oneshot(inputx_timer, choose_delay(ch), 0);
5031      keybuf->status_keydown = 0;
5032   }
5033
5034   keybuf->buffer[keybuf->end_pos++] = ch;
5035   keybuf->end_pos %= ARRAY_LENGTH(keybuf->buffer);
5036}
5037
5038
5039
5040static int buffer_full(running_machine *machine)
5041{
5042   key_buffer *keybuf;
5043   keybuf = get_buffer(machine);
5044   return ((keybuf->end_pos + 1) % ARRAY_LENGTH(keybuf->buffer)) == keybuf->begin_pos;
5045}
5046
5047
5048
5049void inputx_postn_rate(running_machine *machine, const unicode_char *text, size_t text_len, attotime rate)
5050{
5051   int last_cr = 0;
5052   unicode_char ch;
5053   const char *s;
5054   const char_info *ci;
5055   const inputx_code *code;
5056
5057   current_rate = rate;
5058
5059   if (inputx_can_post(machine))
5060   {
5061      while((text_len > 0) && !buffer_full(machine))
5062      {
5063         ch = *(text++);
5064         text_len--;
5065
5066         /* change all eolns to '\r' */
5067         if ((ch != '\n') || !last_cr)
5068         {
5069            if (ch == '\n')
5070               ch = '\r';
5071            else
5072               last_cr = (ch == '\r');
5073
5074            if (LOG_INPUTX)
5075            {
5076               code = find_code(ch);
5077               logerror("inputx_postn(): code=%i (%s) field->name='%s'\n", (int) ch, code_point_string(machine, ch), (code && code->field[0]) ? code->field[0]->name : "<null>");
5078            }
5079
5080            if (can_post_key_directly(ch))
5081            {
5082               /* we can post this key in the queue directly */
5083               internal_post_key(machine, ch);
5084            }
5085            else if (can_post_key_alternate(ch))
5086            {
5087               /* we can post this key with an alternate representation */
5088               ci = find_charinfo(ch);
5089               assert(ci && ci->alternate);
5090               s = ci->alternate;
5091               while(*s)
5092               {
5093                  s += uchar_from_utf8(&ch, s, strlen(s));
5094                  internal_post_key(machine, ch);
5095               }
5096            }
5097         }
5098         else
5099         {
5100            last_cr = 0;
5101         }
5102      }
5103   }
5104}
5105
5106
5107
5108static TIMER_CALLBACK(inputx_timerproc)
5109{
5110   key_buffer *keybuf;
5111   attotime delay;
5112
5113   keybuf = get_buffer(machine);
5114
5115   if (queue_chars)
5116   {
5117      /* the driver has a queue_chars handler */
5118      while((keybuf->begin_pos != keybuf->end_pos) && queue_chars(&keybuf->buffer[keybuf->begin_pos], 1))
5119      {
5120         keybuf->begin_pos++;
5121         keybuf->begin_pos %= ARRAY_LENGTH(keybuf->buffer);
5122
5123         if (attotime_compare(current_rate, attotime_zero) != 0)
5124            break;
5125      }
5126   }
5127   else
5128   {
5129      /* the driver does not have a queue_chars handler */
5130      if (keybuf->status_keydown)
5131      {
5132         keybuf->status_keydown = FALSE;
5133         keybuf->begin_pos++;
5134         keybuf->begin_pos %= ARRAY_LENGTH(keybuf->buffer);
5135      }
5136      else
5137      {
5138         keybuf->status_keydown = TRUE;
5139      }
5140   }
5141
5142   /* need to make sure timerproc is called again if buffer not empty */
5143   if (keybuf->begin_pos != keybuf->end_pos)
5144   {
5145      delay = choose_delay(keybuf->buffer[keybuf->begin_pos]);
5146      timer_adjust_oneshot(inputx_timer, delay, 0);
5147   }
5148}
5149
5150/*-------------------------------------------------
5151    inputx_key_name - returns the name of a
5152    specific key
5153-------------------------------------------------*/
5154
5155const char *inputx_key_name(unicode_char ch)
5156{
5157   static char buf[UTF8_CHAR_MAX + 1];
5158   const char_info *ci;
5159   const char *result;
5160   int pos;
5161
5162   ci = find_charinfo(ch);
5163   result = ci ? ci->name : NULL;
5164
5165   if (ci && ci->name)
5166   {
5167      result = ci->name;
5168   }
5169   else
5170   {
5171      if ((ch > 0x7F) || isprint(ch))
5172      {
5173         pos = utf8_from_uchar(buf, ARRAY_LENGTH(buf), ch);
5174         buf[pos] = '\0';
5175         result = buf;
5176      }
5177      else
5178         result = "???";
5179   }
5180   return result;
5181}
5182
5183
5184
5185/* --------------------------------------------------------------------- */
5186
5187int inputx_is_posting(running_machine *machine)
5188{
5189   const key_buffer *keybuf;
5190   keybuf = get_buffer(machine);
5191   return (keybuf->begin_pos != keybuf->end_pos) || (charqueue_empty && !charqueue_empty());
5192}
5193
5194
5195
5196/***************************************************************************
5197
5198    Coded input
5199
5200***************************************************************************/
5201
5202void inputx_postn_coded_rate(running_machine *machine, const char *text, size_t text_len, attotime rate)
5203{
5204   size_t i, j, key_len, increment;
5205   unicode_char ch;
5206
5207   static const struct
5208   {
5209      const char *key;
5210      unicode_char code;
5211   } codes[] =
5212   {
5213      { "BACKSPACE",   8 },
5214      { "BS",         8 },
5215      { "BKSP",      8 },
5216      { "DEL",      UCHAR_MAMEKEY(DEL) },
5217      { "DELETE",      UCHAR_MAMEKEY(DEL) },
5218      { "END",      UCHAR_MAMEKEY(END) },
5219      { "ENTER",      13 },
5220      { "ESC",      '\033' },
5221      { "HOME",      UCHAR_MAMEKEY(HOME) },
5222      { "INS",      UCHAR_MAMEKEY(INSERT) },
5223      { "INSERT",      UCHAR_MAMEKEY(INSERT) },
5224      { "PGDN",      UCHAR_MAMEKEY(PGDN) },
5225      { "PGUP",      UCHAR_MAMEKEY(PGUP) },
5226      { "SPACE",      32 },
5227      { "TAB",      9 },
5228      { "F1",         UCHAR_MAMEKEY(F1) },
5229      { "F2",         UCHAR_MAMEKEY(F2) },
5230      { "F3",         UCHAR_MAMEKEY(F3) },
5231      { "F4",         UCHAR_MAMEKEY(F4) },
5232      { "F5",         UCHAR_MAMEKEY(F5) },
5233      { "F6",         UCHAR_MAMEKEY(F6) },
5234      { "F7",         UCHAR_MAMEKEY(F7) },
5235      { "F8",         UCHAR_MAMEKEY(F8) },
5236      { "F9",         UCHAR_MAMEKEY(F9) },
5237      { "F10",      UCHAR_MAMEKEY(F10) },
5238      { "F11",      UCHAR_MAMEKEY(F11) },
5239      { "F12",      UCHAR_MAMEKEY(F12) },
5240      { "QUOTE",      '\"' }
5241   };
5242
5243   i = 0;
5244   while(i < text_len)
5245   {
5246      ch = text[i];
5247      increment = 1;
5248
5249      if (ch == '{')
5250      {
5251         for (j = 0; j < ARRAY_LENGTH(codes); j++)
5252         {
5253            key_len = strlen(codes[j].key);
5254            if (i + key_len + 2 <= text_len)
5255            {
5256               if (!memcmp(codes[j].key, &text[i + 1], key_len) && (text[i + key_len + 1] == '}'))
5257               {
5258                  ch = codes[j].code;
5259                  increment = key_len + 2;
5260               }
5261            }
5262         }
5263      }
5264
5265      if (ch)
5266         inputx_postc_rate(machine, ch, rate);
5267      i += increment;
5268   }
5269}
5270
5271
5272
5273/***************************************************************************
5274
5275    Alternative calls
5276
5277***************************************************************************/
5278
5279void inputx_postn(running_machine *machine, const unicode_char *text, size_t text_len)
5280{
5281   inputx_postn_rate(machine, text, text_len, attotime_make(0, 0));
5282}
5283
5284
5285
5286void inputx_post_rate(running_machine *machine, const unicode_char *text, attotime rate)
5287{
5288   size_t len = 0;
5289   while(text[len])
5290      len++;
5291   inputx_postn_rate(machine, text, len, rate);
5292}
5293
5294
5295
5296void inputx_post(running_machine *machine, const unicode_char *text)
5297{
5298   inputx_post_rate(machine, text, attotime_make(0, 0));
5299}
5300
5301
5302
5303void inputx_postc_rate(running_machine *machine, unicode_char ch, attotime rate)
5304{
5305   inputx_postn_rate(machine, &ch, 1, rate);
5306}
5307
5308
5309
5310void inputx_postc(running_machine *machine, unicode_char ch)
5311{
5312   inputx_postc_rate(machine, ch, attotime_make(0, 0));
5313}
5314
5315
5316
5317void inputx_postn_utf16_rate(running_machine *machine, const utf16_char *text, size_t text_len, attotime rate)
5318{
5319   size_t len = 0;
5320   unicode_char c;
5321   utf16_char w1, w2;
5322   unicode_char buf[256];
5323
5324   while(text_len > 0)
5325   {
5326      if (len == ARRAY_LENGTH(buf))
5327      {
5328         inputx_postn(machine, buf, len);
5329         len = 0;
5330      }
5331
5332      w1 = *(text++);
5333      text_len--;
5334
5335      if ((w1 >= 0xd800) && (w1 <= 0xdfff))
5336      {
5337         if (w1 <= 0xDBFF)
5338         {
5339            w2 = 0;
5340            if (text_len > 0)
5341            {
5342               w2 = *(text++);
5343               text_len--;
5344            }
5345            if ((w2 >= 0xdc00) && (w2 <= 0xdfff))
5346            {
5347               c = w1 & 0x03ff;
5348               c <<= 10;
5349               c |= w2 & 0x03ff;
5350            }
5351            else
5352            {
5353               c = INVALID_CHAR;
5354            }
5355         }
5356         else
5357         {
5358            c = INVALID_CHAR;
5359         }
5360      }
5361      else
5362      {
5363         c = w1;
5364      }
5365      buf[len++] = c;
5366   }
5367   inputx_postn_rate(machine, buf, len, rate);
5368}
5369
5370
5371
5372void inputx_postn_utf16(running_machine *machine, const utf16_char *text, size_t text_len)
5373{
5374   inputx_postn_utf16_rate(machine, text, text_len, attotime_make(0, 0));
5375}
5376
5377
5378
5379void inputx_post_utf16_rate(running_machine *machine, const utf16_char *text, attotime rate)
5380{
5381   size_t len = 0;
5382   while(text[len])
5383      len++;
5384   inputx_postn_utf16_rate(machine, text, len, rate);
5385}
5386
5387
5388
5389void inputx_post_utf16(running_machine *machine, const utf16_char *text)
5390{
5391   inputx_post_utf16_rate(machine, text, attotime_make(0, 0));
5392}
5393
5394
5395
5396void inputx_postn_utf8_rate(running_machine *machine, const char *text, size_t text_len, attotime rate)
5397{
5398   size_t len = 0;
5399   unicode_char buf[256];
5400   unicode_char c;
5401   int rc;
5402
5403   while(text_len > 0)
5404   {
5405      if (len == ARRAY_LENGTH(buf))
5406      {
5407         inputx_postn(machine, buf, len);
5408         len = 0;
5409      }
5410
5411      rc = uchar_from_utf8(&c, text, text_len);
5412      if (rc < 0)
5413      {
5414         rc = 1;
5415         c = INVALID_CHAR;
5416      }
5417      text += rc;
5418      text_len -= rc;
5419      buf[len++] = c;
5420   }
5421   inputx_postn_rate(machine, buf, len, rate);
5422}
5423
5424
5425
5426void inputx_postn_utf8(running_machine *machine, const char *text, size_t text_len)
5427{
5428   inputx_postn_utf8_rate(machine, text, text_len, attotime_make(0, 0));
5429}
5430
5431
5432
5433void inputx_post_utf8_rate(running_machine *machine, const char *text, attotime rate)
5434{
5435   inputx_postn_utf8_rate(machine, text, strlen(text), rate);
5436}
5437
5438
5439
5440void inputx_post_utf8(running_machine *machine, const char *text)
5441{
5442   inputx_post_utf8_rate(machine, text, attotime_make(0, 0));
5443}
5444
5445
5446
5447void inputx_post_coded(running_machine *machine, const char *text)
5448{
5449   inputx_postn_coded(machine, text, strlen(text));
5450}
5451
5452
5453
5454void inputx_post_coded_rate(running_machine *machine, const char *text, attotime rate)
5455{
5456   inputx_postn_coded_rate(machine, text, strlen(text), rate);
5457}
5458
5459
5460
5461void inputx_postn_coded(running_machine *machine, const char *text, size_t text_len)
5462{
5463   inputx_postn_coded_rate(machine, text, text_len, attotime_make(0, 0));
5464}
5465
5466
5467
5468/***************************************************************************
5469
5470    Other stuff
5471
5472    This stuff is here more out of convienience than anything else
5473***************************************************************************/
5474
5475int input_classify_port(const input_field_config *field)
5476{
5477   int result;
5478
5479   if (field->category && (field->type != IPT_CATEGORY))
5480      return INPUT_CLASS_CATEGORIZED;
5481
5482   switch(field->type)
5483   {
5484      case IPT_JOYSTICK_UP:
5485      case IPT_JOYSTICK_DOWN:
5486      case IPT_JOYSTICK_LEFT:
5487      case IPT_JOYSTICK_RIGHT:
5488      case IPT_JOYSTICKLEFT_UP:
5489      case IPT_JOYSTICKLEFT_DOWN:
5490      case IPT_JOYSTICKLEFT_LEFT:
5491      case IPT_JOYSTICKLEFT_RIGHT:
5492      case IPT_JOYSTICKRIGHT_UP:
5493      case IPT_JOYSTICKRIGHT_DOWN:
5494      case IPT_JOYSTICKRIGHT_LEFT:
5495      case IPT_JOYSTICKRIGHT_RIGHT:
5496      case IPT_BUTTON1:
5497      case IPT_BUTTON2:
5498      case IPT_BUTTON3:
5499      case IPT_BUTTON4:
5500      case IPT_BUTTON5:
5501      case IPT_BUTTON6:
5502      case IPT_BUTTON7:
5503      case IPT_BUTTON8:
5504      case IPT_BUTTON9:
5505      case IPT_BUTTON10:
5506      case IPT_AD_STICK_X:
5507      case IPT_AD_STICK_Y:
5508      case IPT_AD_STICK_Z:
5509      case IPT_TRACKBALL_X:
5510      case IPT_TRACKBALL_Y:
5511      case IPT_LIGHTGUN_X:
5512      case IPT_LIGHTGUN_Y:
5513      case IPT_MOUSE_X:
5514      case IPT_MOUSE_Y:
5515      case IPT_START:
5516      case IPT_SELECT:
5517         result = INPUT_CLASS_CONTROLLER;
5518         break;
5519
5520      case IPT_KEYBOARD:
5521         result = INPUT_CLASS_KEYBOARD;
5522         break;
5523
5524      case IPT_CONFIG:
5525         result = INPUT_CLASS_CONFIG;
5526         break;
5527
5528      case IPT_DIPSWITCH:
5529         result = INPUT_CLASS_DIPSWITCH;
5530         break;
5531
5532      case 0:
5533         if (field->name && (field->name != (const char *) -1))
5534            result = INPUT_CLASS_MISC;
5535         else
5536            result = INPUT_CLASS_INTERNAL;
5537         break;
5538
5539      default:
5540         result = INPUT_CLASS_INTERNAL;
5541         break;
5542   }
5543   return result;
5544}
5545
5546
5547
5548int input_player_number(const input_field_config *port)
5549{
5550   return port->player;
5551}
5552
5553
5554
5555/*-------------------------------------------------
5556    input_has_input_class - checks to see if a
5557    particular input class is present
5558-------------------------------------------------*/
5559
5560int input_has_input_class(running_machine *machine, int inputclass)
5561{
5562   const input_port_config *port;
5563   const input_field_config *field;
5564
5565   for (port = machine->portlist.first(); port != NULL; port = port->next)
5566   {
5567      for (field = port->fieldlist; field != NULL; field = field->next)
5568      {
5569         if (input_classify_port(field) == inputclass)
5570            return TRUE;
5571      }
5572   }
5573   return FALSE;
5574}
5575
5576
5577
5578/*-------------------------------------------------
5579    input_count_players - counts the number of
5580    active players
5581-------------------------------------------------*/
5582
5583int input_count_players(running_machine *machine)
5584{
5585   const input_port_config *port;
5586   const input_field_config *field;
5587   int joystick_count;
5588
5589   joystick_count = 0;
5590   for (port = machine->portlist.first(); port != NULL; port = port->next)
5591   {
5592      for (field = port->fieldlist;  field != NULL; field = field->next)
5593      {
5594         if (input_classify_port(field) == INPUT_CLASS_CONTROLLER)
5595         {
5596            if (joystick_count <= field->player + 1)
5597               joystick_count = field->player + 1;
5598         }
5599      }
5600   }
5601   return joystick_count;
5602}
5603
5604
5605
5606/*-------------------------------------------------
5607    input_category_active - checks to see if a
5608    specific category is active
5609-------------------------------------------------*/
5610
5611int input_category_active(running_machine *machine, int category)
5612{
5613   const input_port_config *port;
5614   const input_field_config *field = NULL;
5615   const input_setting_config *setting;
5616   input_field_user_settings settings;
5617
5618   assert(category >= 1);
5619
5620   /* loop through the input ports */
5621   for (port = machine->portlist.first(); port != NULL; port = port->next)
5622   {
5623      for (field = port->fieldlist; field != NULL; field = field->next)
5624      {
5625         /* is this field a category? */
5626         if (field->type == IPT_CATEGORY)
5627         {
5628            /* get the settings value */
5629            input_field_get_user_settings(field, &settings);
5630
5631            for (setting = field->settinglist; setting != NULL; setting = setting->next)
5632            {
5633               /* is this the category we want?  if so, is this settings value correct? */
5634               if ((setting->category == category) && (settings.value == setting->value))
5635                  return TRUE;
5636            }
5637         }
5638      }
5639   }
5640   return FALSE;
5641}
5642
5643
5644
5645/***************************************************************************
5646    DEBUGGER SUPPORT
5647***************************************************************************/
5648
5649/*-------------------------------------------------
5650    execute_input - debugger command to enter
5651    natural keyboard input
5652-------------------------------------------------*/
5653
5654static void execute_input(running_machine *machine, int ref, int params, const char *param[])
5655{
5656   inputx_post_coded(machine, param[0]);
5657}
5658
5659
5660
5661/*-------------------------------------------------
5662    execute_dumpkbd - debugger command to natural
5663    keyboard codes
5664-------------------------------------------------*/
5665
5666static void execute_dumpkbd(running_machine *machine, int ref, int params, const char *param[])
5667{
5668   const char *filename;
5669   FILE *file = NULL;
5670   const inputx_code *code;
5671   char buffer[512];
5672   size_t pos;
5673   int i, j;
5674   size_t left_column_width = 24;
5675
5676   /* was there a file specified? */
5677   filename = (params > 0) ? param[0] : NULL;
5678   if (filename != NULL)
5679   {
5680      /* if so, open it */
5681      file = fopen(filename, "w");
5682      if (file == NULL)
5683      {
5684         debug_console_printf(machine, "Cannot open \"%s\"\n", filename);
5685         return;
5686      }
5687   }
5688
5689   if ((codes != NULL) && (codes[0].ch != 0))
5690   {
5691      /* loop through all codes */
5692      for (i = 0; codes[i].ch; i++)
5693      {
5694         code = &codes[i];
5695         pos = 0;
5696
5697         /* describe the character code */
5698         pos += snprintf(&buffer[pos], ARRAY_LENGTH(buffer) - pos, "%08X (%s) ",
5699            code->ch,
5700            code_point_string(machine, code->ch));
5701
5702         /* pad with spaces */
5703         while(pos < left_column_width)
5704            buffer[pos++] = ' ';
5705         buffer[pos] = '\0';
5706
5707         /* identify the keys used */
5708         for (j = 0; j < ARRAY_LENGTH(code->field) && (code->field[j] != NULL); j++)
5709         {
5710            pos += snprintf(&buffer[pos], ARRAY_LENGTH(buffer) - pos, "%s'%s'",
5711               (j > 0) ? ", " : "",
5712               code->field[j]->name);
5713         }
5714
5715         /* and output it as appropriate */
5716         if (file != NULL)
5717            fprintf(file, "%s\n", buffer);
5718         else
5719            debug_console_printf(machine, "%s\n", buffer);
5720      }
5721   }
5722   else
5723   {
5724      debug_console_printf(machine, "No natural keyboard support\n");
5725   }
5726
5727   /* cleanup */
5728   if (file != NULL)
5729      fclose(file);
5730
5731}
src/emu/mame.c
r7335r7336
12881288     generic_audio_data(NULL),
12891289#ifdef MESS
12901290     images_data(NULL),
1291     ui_mess_data(NULL),
12921291#endif /* MESS */
12931292     driver_data(NULL)
12941293{
r7335r7336
13651364   palette_init(machine);
13661365   render_init(machine);
13671366   ui_init(machine);
1368#ifdef MESS
1369   ui_mess_init(machine);
1370#endif /* MESS */
13711367   generic_machine_init(machine);
13721368   generic_video_init(machine);
13731369   generic_sound_init(machine);
src/emu/inpttype.h
r7335r7336
603603   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_NEXT_GROUP,       "UI Next Group",          SEQ_DEF_1(KEYCODE_CLOSEBRACE) )
604604   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_ROTATE,           "UI Rotate",              SEQ_DEF_1(KEYCODE_R) )
605605   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_SHOW_PROFILER,    "Show Profiler",          SEQ_DEF_2(KEYCODE_F11, KEYCODE_LSHIFT) )
606#ifdef MESS
607606   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_TOGGLE_UI,        "UI Toggle",              SEQ_DEF_3(KEYCODE_SCRLOCK, SEQCODE_NOT, KEYCODE_LSHIFT) )
608607   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_PASTE,            "UI Paste Text",          SEQ_DEF_2(KEYCODE_SCRLOCK, KEYCODE_LSHIFT) )
609#endif /* MESS */
610608   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_TOGGLE_DEBUG,     "Toggle Debugger",        SEQ_DEF_1(KEYCODE_F5) )
611609   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_SAVE_STATE,       "Save State",             SEQ_DEF_2(KEYCODE_F7, KEYCODE_LSHIFT) )
612610   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_LOAD_STATE,       "Load State",             SEQ_DEF_3(KEYCODE_F7, SEQCODE_NOT, KEYCODE_LSHIFT) )
src/emu/inptport.h
r7335r7336
547547};
548548
549549
550/* input classes */
551enum
552{
553   INPUT_CLASS_INTERNAL,
554   INPUT_CLASS_KEYBOARD,
555   INPUT_CLASS_CONTROLLER,
556   INPUT_CLASS_CONFIG,
557   INPUT_CLASS_DIPSWITCH,
558   INPUT_CLASS_CATEGORIZED,
559   INPUT_CLASS_MISC
560};
550561
562#define UCHAR_PRIVATE      (0x100000)
563#define UCHAR_SHIFT_1      (UCHAR_PRIVATE + 0)
564#define UCHAR_SHIFT_2      (UCHAR_PRIVATE + 1)
565#define UCHAR_MAMEKEY_BEGIN   (UCHAR_PRIVATE + 2)
566#define UCHAR_MAMEKEY_END   (UCHAR_MAMEKEY_BEGIN + __code_key_last)
567#define UCHAR_MAMEKEY(code)   (UCHAR_MAMEKEY_BEGIN + KEYCODE_##code)
568
569#define UCHAR_SHIFT_BEGIN   (UCHAR_SHIFT_1)
570#define UCHAR_SHIFT_END      (UCHAR_SHIFT_2)
571
551572/***************************************************************************
552573    TYPE DEFINITIONS
553574***************************************************************************/
r7335r7336
11371158/* return TRUE if machine use full keyboard emulation */
11381159int input_machine_have_keyboard(running_machine *machine);
11391160
1161/* these are called by the core; they should not be called from FEs */
1162void inputx_init(running_machine *machine);
1163
1164/* called by drivers to setup natural keyboard support */
1165void inputx_setup_natural_keyboard(
1166   int (*queue_chars)(const unicode_char *text, size_t text_len),
1167   int (*accept_char)(unicode_char ch),
1168   int (*charqueue_empty)(void));
1169
1170/* validity checks */
1171int validate_natural_keyboard_statics(void);
1172
1173/* these can be called from FEs */
1174int inputx_can_post(running_machine *machine);
1175int inputx_can_post_key(running_machine *machine, unicode_char ch);
1176int inputx_is_posting(running_machine *machine);
1177const char *inputx_key_name(unicode_char ch);
1178
1179/* various posting functions; can be called from FEs */
1180void inputx_post(running_machine *machine, const unicode_char *text);
1181void inputx_post_rate(running_machine *machine, const unicode_char *text, attotime rate);
1182void inputx_postc(running_machine *machine, unicode_char ch);
1183void inputx_postc_rate(running_machine *machine, unicode_char ch, attotime rate);
1184void inputx_postn(running_machine *machine, const unicode_char *text, size_t text_len);
1185void inputx_postn_rate(running_machine *machine, const unicode_char *text, size_t text_len, attotime rate);
1186void inputx_post_utf16(running_machine *machine, const utf16_char *text);
1187void inputx_post_utf16_rate(running_machine *machine, const utf16_char *text, attotime rate);
1188void inputx_postn_utf16(running_machine *machine, const utf16_char *text, size_t text_len);
1189void inputx_postn_utf16_rate(running_machine *machine, const utf16_char *text, size_t text_len, attotime rate);
1190void inputx_post_utf8(running_machine *machine, const char *text);
1191void inputx_post_utf8_rate(running_machine *machine, const char *text, attotime rate);
1192void inputx_postn_utf8(running_machine *machine, const char *text, size_t text_len);
1193void inputx_postn_utf8_rate(running_machine *machine, const char *text, size_t text_len, attotime rate);
1194void inputx_post_coded(running_machine *machine, const char *text);
1195void inputx_post_coded_rate(running_machine *machine, const char *text, attotime rate);
1196void inputx_postn_coded(running_machine *machine, const char *text, size_t text_len);
1197void inputx_postn_coded_rate(running_machine *machine, const char *text, size_t text_len, attotime rate);
1198
1199/* miscellaneous functions */
1200int input_classify_port(const input_field_config *field);
1201int input_has_input_class(running_machine *machine, int inputclass);
1202int input_player_number(const input_field_config *field);
1203int input_count_players(running_machine *machine);
1204int input_category_active(running_machine *machine, int category);
1205
11401206#endif   /* __INPTPORT_H__ */
src/emu/mame.h
r7335r7336
284284   generic_audio_private *   generic_audio_data;   /* internal data from audio/generic.c */
285285#ifdef MESS
286286   images_private *      images_data;      /* internal data from image.c */
287   ui_mess_private *      ui_mess_data;      /* internal data from uimess.c */
288287#endif /* MESS */
289288
290289   /* driver-specific information */
r7335r7336
466465/* retrieve the current system time */
467466void mame_get_current_datetime(running_machine *machine, mame_system_time *systime);
468467
469
470
471#ifdef MESS
472#include "mess.h"
473#endif /* MESS */
474
475
476
477468/***************************************************************************
478469    INLINE FUNCTIONS
479470***************************************************************************/
src/emu/emu.h
r7335r7336
9393// the running machine
9494#ifdef MESS
9595#include "mess.h"
96#include "uimess.h"
9796#include "image.h"
9897#include "messdrv.h"
9998#endif /* MESS */
src/emu/ui.c
r7335r7336
2323#include "uigfx.h"
2424
2525#ifdef MESS
26#include "mess.h"
2726#include "uimess.h"
28#include "inputx.h"
29#include "messopts.h"
3027#endif /* MESS */
3128
3229#include <ctype.h>
r7335r7336
4542};
4643
4744
45/***************************************************************************
46    LOCAL VARIABLES
47***************************************************************************/
4848
49/* list of natural keyboard keys that are not associated with UI_EVENT_CHARs */
50static const input_item_id non_char_keys[] =
51{
52   ITEM_ID_ESC,
53   ITEM_ID_F1,
54   ITEM_ID_F2,
55   ITEM_ID_F3,
56   ITEM_ID_F4,
57   ITEM_ID_F5,
58   ITEM_ID_F6,
59   ITEM_ID_F7,
60   ITEM_ID_F8,
61   ITEM_ID_F9,
62   ITEM_ID_F10,
63   ITEM_ID_F11,
64   ITEM_ID_F12,
65   ITEM_ID_NUMLOCK,
66   ITEM_ID_0_PAD,
67   ITEM_ID_1_PAD,
68   ITEM_ID_2_PAD,
69   ITEM_ID_3_PAD,
70   ITEM_ID_4_PAD,
71   ITEM_ID_5_PAD,
72   ITEM_ID_6_PAD,
73   ITEM_ID_7_PAD,
74   ITEM_ID_8_PAD,
75   ITEM_ID_9_PAD,
76   ITEM_ID_DEL_PAD,
77   ITEM_ID_PLUS_PAD,
78   ITEM_ID_MINUS_PAD,
79   ITEM_ID_INSERT,
80   ITEM_ID_DEL,
81   ITEM_ID_HOME,
82   ITEM_ID_END,
83   ITEM_ID_PGUP,
84   ITEM_ID_PGDN,
85   ITEM_ID_UP,
86   ITEM_ID_DOWN,
87   ITEM_ID_LEFT,
88   ITEM_ID_RIGHT,
89   ITEM_ID_PAUSE,
90   ITEM_ID_CANCEL
91};
92
4993/***************************************************************************
5094    GLOBAL VARIABLES
5195***************************************************************************/
r7335r7336
78122static slider_state *slider_list;
79123static slider_state *slider_current;
80124
125static int ui_active;
126/* natural keyboard info */
127static int ui_use_natural_keyboard;
128static UINT8 non_char_keys_down[(ARRAY_LENGTH(non_char_keys) + 7) / 8];   
81129
82130
83131/***************************************************************************
r7335r7336
206254
207255   /* reset globals */
208256   single_step = FALSE;
209   ui_set_handler(handler_messagebox, 0);
257   ui_set_handler(handler_messagebox, 0);   
258   ui_active = 0;
259   /* retrieve options */
260   ui_use_natural_keyboard = options_get_bool(mame_options(), OPTION_NATURAL_KEYBOARD);
261   
210262   return 0;
211263}
212264
r7335r7336
11271179
11281180
11291181/*-------------------------------------------------
1182    ui_use_new_ui - determines if the "new ui"
1183    is in use
1184-------------------------------------------------*/
1185
1186int ui_use_new_ui(void)
1187{
1188#ifdef MESS
1189#if (defined(WIN32) || defined(_MSC_VER)) && !defined(SDLMAME_WIN32)
1190   if (options_get_bool(mame_options(), "newui"))
1191      return TRUE;
1192#endif
1193#endif
1194   return FALSE;
1195}
1196
1197/*-------------------------------------------------
1198    process_natural_keyboard - processes any
1199    natural keyboard input
1200-------------------------------------------------*/
1201
1202static void process_natural_keyboard(running_machine *machine)
1203{
1204   ui_event event;
1205   int i, pressed;
1206   input_item_id itemid;
1207   input_code code;
1208   UINT8 *key_down_ptr;
1209   UINT8 key_down_mask;
1210
1211   /* loop while we have interesting events */
1212   while (ui_input_pop_event(machine, &event))
1213   {
1214      /* if this was a UI_EVENT_CHAR event, post it */
1215      if (event.event_type == UI_EVENT_CHAR)
1216         inputx_postc(machine, event.ch);
1217   }
1218
1219   /* process natural keyboard keys that don't get UI_EVENT_CHARs */
1220   for (i = 0; i < ARRAY_LENGTH(non_char_keys); i++)
1221   {
1222      /* identify this keycode */
1223      itemid = non_char_keys[i];
1224      code = input_code_from_input_item_id(machine, itemid);
1225
1226      /* ...and determine if it is pressed */
1227      pressed = input_code_pressed(machine, code);
1228
1229      /* figure out whey we are in the key_down map */
1230      key_down_ptr = &non_char_keys_down[i / 8];
1231      key_down_mask = 1 << (i % 8);
1232
1233      if (pressed && !(*key_down_ptr & key_down_mask))
1234      {
1235         /* this key is now down */
1236         *key_down_ptr |= key_down_mask;
1237
1238         /* post the key */
1239         inputx_postc(machine, UCHAR_MAMEKEY_BEGIN + code);
1240      }
1241      else if (!pressed && (*key_down_ptr & key_down_mask))
1242      {
1243         /* this key is now up */
1244         *key_down_ptr &= ~key_down_mask;
1245      }
1246   }
1247}
1248
1249/*-------------------------------------------------
1250    ui_paste - does a paste from the keyboard
1251-------------------------------------------------*/
1252
1253void ui_paste(running_machine *machine)
1254{
1255   /* retrieve the clipboard text */
1256   char *text = osd_get_clipboard_text();
1257
1258   /* was a result returned? */
1259   if (text != NULL)
1260   {
1261      /* post the text */
1262      inputx_post_utf8(machine, text);
1263
1264      /* free the string */
1265      free(text);
1266   }
1267}
1268
1269/*-------------------------------------------------
11301270    handler_ingame - in-game handler takes care
11311271    of the standard keypresses
11321272-------------------------------------------------*/
r7335r7336
11591299      single_step = FALSE;
11601300   }
11611301
1302   /* determine if we should disable the rest of the UI */
1303   int ui_disabled = ui_use_new_ui() || (input_machine_have_keyboard(machine) && !ui_active);
1304
1305   /* is ScrLk UI toggling applicable here? */
1306   if (!ui_use_new_ui() && input_machine_have_keyboard(machine))
1307   {
1308      /* are we toggling the UI with ScrLk? */
1309      if (ui_input_pressed(machine, IPT_UI_TOGGLE_UI))
1310      {
1311         /* toggle the UI */
1312         ui_active = !ui_active;
1313
1314         /* display a popup indicating the new status */
1315         if (ui_active)
1316         {
1317            ui_popup_time(2, "%s\n%s\n%s\n%s\n%s\n%s\n",
1318               "Keyboard Emulation Status",
1319               "-------------------------",
1320               "Mode: PARTIAL Emulation",
1321               "UI:   Enabled",
1322               "-------------------------",
1323               "**Use ScrLock to toggle**");
1324         }
1325         else
1326         {
1327            ui_popup_time(2, "%s\n%s\n%s\n%s\n%s\n%s\n",
1328               "Keyboard Emulation Status",
1329               "-------------------------",
1330               "Mode: FULL Emulation",
1331               "UI:   Disabled",
1332               "-------------------------",
1333               "**Use ScrLock to toggle**");
1334         }
1335      }
1336   }
1337
1338   /* is the natural keyboard enabled? */
1339   if (ui_get_use_natural_keyboard(machine) && (mame_get_phase(machine) == MAME_PHASE_RUNNING))
1340      process_natural_keyboard(machine);
1341
1342   /* MESS-specific UI; provided that the UI is not disabled */
1343   if (!ui_disabled)
1344   {
1345      /* paste command */
1346      if (ui_input_pressed(machine, IPT_UI_PASTE))
1347         ui_paste(machine);
1348   }
1349
1350   if (ui_disabled) return ui_disabled;
1351
11621352#ifdef MESS
1163   if (ui_mess_handler_ingame(machine))
1164      return 0;
1353   ui_mess_handler_ingame(machine);
11651354#endif /* MESS */
11661355
11671356   /* if the user pressed ESC, stop the emulation */
r7335r7336
20032192   return field->crossoffset;
20042193}
20052194#endif
2195
2196
2197/*-------------------------------------------------
2198    ui_get_use_natural_keyboard - returns
2199    whether the natural keyboard is active
2200-------------------------------------------------*/
2201
2202int ui_get_use_natural_keyboard(running_machine *machine)
2203{
2204   return ui_use_natural_keyboard;
2205}
2206
2207
2208
2209/*-------------------------------------------------
2210    ui_set_use_natural_keyboard - specifies
2211    whether the natural keyboard is active
2212-------------------------------------------------*/
2213
2214void ui_set_use_natural_keyboard(running_machine *machine, int use_natural_keyboard)
2215{
2216   ui_use_natural_keyboard = use_natural_keyboard;
2217}
2218
src/emu/ui.h
r7335r7336
178178/* get the list of sliders */
179179const slider_state *ui_get_slider_list(void);
180180
181/* paste */
182void ui_paste(running_machine *machine);
183
184int ui_use_new_ui(void);
185
186/* returns whether the natural keyboard is active */
187int ui_get_use_natural_keyboard(running_machine *machine);
188
189/* specifies whether the natural keyboard is active */
190void ui_set_use_natural_keyboard(running_machine *machine, int use_natural_keyboard);
191
181192#endif   /* __USRINTRF_H__ */
src/emu/validity.c
r7335r7336
11921192               }
11931193            }
11941194      }
1195   /* free the config */
1195     
1196   error = error || validate_natural_keyboard_statics();
1197   
1198   /* free the config */   
11961199   return error;
11971200}
11981201
r7335r7336
14611464   osd_ticks_t input_checks = 0;
14621465   osd_ticks_t sound_checks = 0;
14631466   osd_ticks_t device_checks = 0;
1464#ifdef MESS
1465   osd_ticks_t mess_checks = 0;
1466#endif
14671467
14681468   int drivnum, strnum;
14691469   int error = FALSE;
r7335r7336
15751575
15761576      machine_config_free(config);
15771577   }
1578
1579#ifdef MESS
1580   mess_checks -= get_profile_ticks();
1581   if (mess_validitychecks())
1582      error = TRUE;
1583   mess_checks += get_profile_ticks();
1584#endif /* MESS */
1585
1578   
15861579#if (REPORT_TIMES)
15871580   mame_printf_info("Prep:      %8dm\n", (int)(prep / 1000000));
15881581   mame_printf_info("Expansion: %8dm\n", (int)(expansion / 1000000));
r7335r7336
15931586   mame_printf_info("Graphics:  %8dm\n", (int)(gfx_checks / 1000000));
15941587   mame_printf_info("Input:     %8dm\n", (int)(input_checks / 1000000));
15951588   mame_printf_info("Sound:     %8dm\n", (int)(sound_checks / 1000000));
1596#ifdef MESS
1597   mame_printf_info("MESS:      %8dm\n", (int)(mess_checks / 1000000));
15981589#endif
1599#endif
16001590
16011591   return error;
16021592}
src/mess/mslegacy.c
r7335r7336
1/*********************************************************************
2
3    mslegacy.c
4
5    Defines since removed from MAME, but kept in MESS for legacy
6    reasons
7
8*********************************************************************/
9
10#include "emu.h"
11#include "mslegacy.h"
12
13
14static const char *const mess_default_text[] =
15{
16   "OK",
17   "Off",
18   "On",
19   "Dip Switches",
20   "Driver Configuration",
21   "Analog Controls",
22   "Digital Speed",
23   "Autocenter Speed",
24   "Reverse",
25   "Sensitivity",
26
27   "Keyboard Emulation Status",
28   "-------------------------",
29   "Mode: PARTIAL Emulation",
30   "Mode: FULL Emulation",
31   "UI:   Enabled",
32   "UI:   Disabled",
33   "**Use ScrLock to toggle**",
34
35   "No Tape Image loaded",
36   "recording",
37   "playing",
38   "(recording)",
39   "(playing)",
40   "stopped",
41   "Pause/Stop",
42   "Record",
43   "Play",
44   "Rewind",
45   "Fast Forward",
46   "Mount...",
47   "Create...",
48   "Unmount",
49   "[empty slot]",
50   "Input Devices",
51   "Quit Fileselector",
52   "File Specification"
53};
54
55
56
57/***************************************************************************
58    UI TEXT
59***************************************************************************/
60
61const char * ui_getstring (int string_num)
62{
63   return mess_default_text[string_num];
64}
src/mess/mslegacy.h
r7335r7336
1/*********************************************************************
2
3    mslegacy.h
4
5    Defines since removed from MAME, but kept in MESS for legacy
6    reasons
7
8*********************************************************************/
9
10#ifndef MSLEGACY_H
11#define MSLEGACY_H
12
13#include "emu.h"
14
15enum
16{
17   UI_OK,
18   UI_off,
19   UI_on,
20   UI_dipswitches,
21   UI_configuration,
22   UI_analogcontrols,
23   UI_keyjoyspeed,
24   UI_centerspeed,
25   UI_reverse,
26   UI_sensitivity,
27
28   UI_last_mame_entry,
29   UI_keyb1 = UI_last_mame_entry,
30   UI_keyb2,
31   UI_keyb3,
32   UI_keyb4,
33   UI_keyb5,
34   UI_keyb6,
35   UI_keyb7,
36
37   UI_notapeimageloaded,
38   UI_recording,
39   UI_playing,
40   UI_recording_inhibited,
41   UI_playing_inhibited,
42   UI_stopped,
43   UI_pauseorstop,
44   UI_record,
45   UI_play,
46   UI_rewind,
47   UI_fastforward,
48   UI_mount,
49   UI_create,
50   UI_unmount,
51   UI_emptyslot,
52   UI_categories,
53   UI_quitfileselector,
54   UI_filespecification,   /* IMPORTANT: be careful to ensure that the following */
55   UI_cartridge,         /* device list matches the order found in device.h    */
56   UI_floppydisk,         /* and is ALWAYS placed after UI_filespecification    */
57   UI_harddisk,
58   UI_cylinder,
59   UI_cassette,
60   UI_punchcard,
61   UI_punchtape,
62   UI_printer,
63   UI_serial,
64   UI_parallel,
65   UI_snapshot,
66   UI_quickload,
67   UI_memcard,
68   UI_cdrom,
69   UI_magtape
70};
71
72
73
74/* uitext */
75const char * ui_getstring (int string_num);
76
77#endif /* MSLEGACY_H */
src/mess/inputx.c
r7335r7336
1/*********************************************************************
2
3    inputx.c
4
5    Secondary input related functions for MESS specific functionality
6
7*********************************************************************/
8
9#include <ctype.h>
10#include <assert.h>
11#include <wctype.h>
12#include "emu.h"
13#include "inputx.h"
14
15#include "debug/debugcon.h"
16
17
18
19/***************************************************************************
20    CONSTANTS
21***************************************************************************/
22
23#define NUM_SIMUL_KEYS   (UCHAR_SHIFT_END - UCHAR_SHIFT_BEGIN + 1)
24#define LOG_INPUTX      0
25#define SPACE_COUNT      3
26#define INVALID_CHAR   '?'
27#define IP_NAME_DEFAULT   NULL
28
29
30
31/***************************************************************************
32    TYPE DEFINITIONS
33***************************************************************************/
34
35typedef const input_port_config *input_port_config_c;
36typedef const input_field_config *input_field_config_c;
37
38
39typedef struct _mess_input_code mess_input_code;
40struct _mess_input_code
41{
42   unicode_char ch;
43   input_field_config_c field[NUM_SIMUL_KEYS];
44};
45
46typedef struct _key_buffer key_buffer;
47struct _key_buffer
48{
49   int begin_pos;
50   int end_pos;
51   unsigned int status_keydown : 1;
52   unicode_char buffer[4096];
53};
54
55typedef struct _char_info char_info;
56struct _char_info
57{
58   unicode_char ch;
59   const char *name;
60   const char *alternate;   /* alternative string, in UTF-8 */
61};
62
63
64
65/***************************************************************************
66    GLOBAL VARIABLES
67***************************************************************************/
68
69static const char_info charinfo[] =
70{
71   { 0x0008,               "Backspace",   NULL },      /* Backspace */
72   { 0x0009,               "Tab",         "    " },   /* Tab */
73   { 0x000c,               "Clear",      NULL },      /* Clear */
74   { 0x000d,               "Enter",      NULL },      /* Enter */
75   { 0x001a,               "Esc",         NULL },      /* Esc */
76   { 0x0020,               "Space",      " " },      /* Space */
77   { 0x0061,               NULL,         "A" },      /* a */
78   { 0x0062,               NULL,         "B" },      /* b */
79   { 0x0063,               NULL,         "C" },      /* c */
80   { 0x0064,               NULL,         "D" },      /* d */
81   { 0x0065,               NULL,         "E" },      /* e */
82   { 0x0066,               NULL,         "F" },      /* f */
83   { 0x0067,               NULL,         "G" },      /* g */
84   { 0x0068,               NULL,         "H" },      /* h */
85   { 0x0069,               NULL,         "I" },      /* i */
86   { 0x006a,               NULL,         "J" },      /* j */
87   { 0x006b,               NULL,         "K" },      /* k */
88   { 0x006c,               NULL,         "L" },      /* l */
89   { 0x006d,               NULL,         "M" },      /* m */
90   { 0x006e,               NULL,         "N" },      /* n */
91   { 0x006f,               NULL,         "O" },      /* o */
92   { 0x0070,               NULL,         "P" },      /* p */
93   { 0x0071,               NULL,         "Q" },      /* q */
94   { 0x0072,               NULL,         "R" },      /* r */
95   { 0x0073,               NULL,         "S" },      /* s */
96   { 0x0074,               NULL,         "T" },      /* t */
97   { 0x0075,               NULL,         "U" },      /* u */
98   { 0x0076,               NULL,         "V" },      /* v */
99   { 0x0077,               NULL,         "W" },      /* w */
100   { 0x0078,               NULL,         "X" },      /* x */
101   { 0x0079,               NULL,         "Y" },      /* y */
102   { 0x007a,               NULL,         "Z" },      /* z */
103   { 0x00a0,               NULL,         " " },      /* non breaking space */
104   { 0x00a1,               NULL,         "!" },      /* inverted exclaimation mark */
105   { 0x00a6,               NULL,         "|" },      /* broken bar */
106   { 0x00a9,               NULL,         "(c)" },   /* copyright sign */
107   { 0x00ab,               NULL,         "<<" },      /* left pointing double angle */
108   { 0x00ae,               NULL,         "(r)" },   /* registered sign */
109   { 0x00bb,               NULL,         ">>" },      /* right pointing double angle */
110   { 0x00bc,               NULL,         "1/4" },   /* vulgar fraction one quarter */
111   { 0x00bd,               NULL,         "1/2" },   /* vulgar fraction one half */
112   { 0x00be,               NULL,         "3/4" },   /* vulgar fraction three quarters */
113   { 0x00bf,               NULL,         "?" },      /* inverted question mark */
114   { 0x00c0,               NULL,         "A" },      /* 'A' grave */
115   { 0x00c1,               NULL,         "A" },      /* 'A' acute */
116   { 0x00c2,               NULL,         "A" },      /* 'A' circumflex */
117   { 0x00c3,               NULL,         "A" },      /* 'A' tilde */
118   { 0x00c4,               NULL,         "A" },      /* 'A' diaeresis */
119   { 0x00c5,               NULL,         "A" },      /* 'A' ring above */
120   { 0x00c6,               NULL,         "AE" },      /* 'AE' ligature */
121   { 0x00c7,               NULL,         "C" },      /* 'C' cedilla */
122   { 0x00c8,               NULL,         "E" },      /* 'E' grave */
123   { 0x00c9,               NULL,         "E" },      /* 'E' acute */
124   { 0x00ca,               NULL,         "E" },      /* 'E' circumflex */
125   { 0x00cb,               NULL,         "E" },      /* 'E' diaeresis */
126   { 0x00cc,               NULL,         "I" },      /* 'I' grave */
127   { 0x00cd,               NULL,         "I" },      /* 'I' acute */
128   { 0x00ce,               NULL,         "I" },      /* 'I' circumflex */
129   { 0x00cf,               NULL,         "I" },      /* 'I' diaeresis */
130   { 0x00d0,               NULL,         "D" },      /* 'ETH' */
131   { 0x00d1,               NULL,         "N" },      /* 'N' tilde */
132   { 0x00d2,               NULL,         "O" },      /* 'O' grave */
133   { 0x00d3,               NULL,         "O" },      /* 'O' acute */
134   { 0x00d4,               NULL,         "O" },      /* 'O' circumflex */
135   { 0x00d5,               NULL,         "O" },      /* 'O' tilde */
136   { 0x00d6,               NULL,         "O" },      /* 'O' diaeresis */
137   { 0x00d7,               NULL,         "X" },      /* multiplication sign */
138   { 0x00d8,               NULL,         "O" },      /* 'O' stroke */
139   { 0x00d9,               NULL,         "U" },      /* 'U' grave */
140   { 0x00da,               NULL,         "U" },      /* 'U' acute */
141   { 0x00db,               NULL,         "U" },      /* 'U' circumflex */
142   { 0x00dc,               NULL,         "U" },      /* 'U' diaeresis */
143   { 0x00dd,               NULL,         "Y" },      /* 'Y' acute */
144   { 0x00df,               NULL,         "SS" },      /* sharp S */
145   { 0x00e0,               NULL,         "a" },      /* 'a' grave */
146   { 0x00e1,               NULL,         "a" },      /* 'a' acute */
147   { 0x00e2,               NULL,         "a" },      /* 'a' circumflex */
148   { 0x00e3,               NULL,         "a" },      /* 'a' tilde */
149   { 0x00e4,               NULL,         "a" },      /* 'a' diaeresis */
150   { 0x00e5,               NULL,         "a" },      /* 'a' ring above */
151   { 0x00e6,               NULL,         "ae" },      /* 'ae' ligature */
152   { 0x00e7,               NULL,         "c" },      /* 'c' cedilla */
153   { 0x00e8,               NULL,         "e" },      /* 'e' grave */
154   { 0x00e9,               NULL,         "e" },      /* 'e' acute */
155   { 0x00ea,               NULL,         "e" },      /* 'e' circumflex */
156   { 0x00eb,               NULL,         "e" },      /* 'e' diaeresis */
157   { 0x00ec,               NULL,         "i" },      /* 'i' grave */
158   { 0x00ed,               NULL,         "i" },      /* 'i' acute */
159   { 0x00ee,               NULL,         "i" },      /* 'i' circumflex */
160   { 0x00ef,               NULL,         "i" },      /* 'i' diaeresis */
161   { 0x00f0,               NULL,         "d" },      /* 'eth' */
162   { 0x00f1,               NULL,         "n" },      /* 'n' tilde */
163   { 0x00f2,               NULL,         "o" },      /* 'o' grave */
164   { 0x00f3,               NULL,         "o" },      /* 'o' acute */
165   { 0x00f4,               NULL,         "o" },      /* 'o' circumflex */
166   { 0x00f5,               NULL,         "o" },      /* 'o' tilde */
167   { 0x00f6,               NULL,         "o" },      /* 'o' diaeresis */
168   { 0x00f8,               NULL,         "o" },      /* 'o' stroke */
169   { 0x00f9,               NULL,         "u" },      /* 'u' grave */
170   { 0x00fa,               NULL,         "u" },      /* 'u' acute */
171   { 0x00fb,               NULL,         "u" },      /* 'u' circumflex */
172   { 0x00fc,               NULL,         "u" },      /* 'u' diaeresis */
173   { 0x00fd,               NULL,         "y" },      /* 'y' acute */
174   { 0x00ff,               NULL,         "y" },      /* 'y' diaeresis */
175   { 0x2010,               NULL,         "-" },      /* hyphen */
176   { 0x2011,               NULL,         "-" },      /* non-breaking hyphen */
177   { 0x2012,               NULL,         "-" },      /* figure dash */
178   { 0x2013,               NULL,         "-" },      /* en dash */
179   { 0x2014,               NULL,         "-" },      /* em dash */
180   { 0x2015,               NULL,         "-" },      /* horizontal dash */
181   { 0x2018,               NULL,         "\'" },      /* left single quotation mark */
182   { 0x2019,               NULL,         "\'" },      /* right single quotation mark */
183   { 0x201a,               NULL,         "\'" },      /* single low quotation mark */
184   { 0x201b,               NULL,         "\'" },      /* single high reversed quotation mark */
185   { 0x201c,               NULL,         "\"" },      /* left double quotation mark */
186   { 0x201d,               NULL,         "\"" },      /* right double quotation mark */
187   { 0x201e,               NULL,         "\"" },      /* double low quotation mark */
188   { 0x201f,               NULL,         "\"" },      /* double high reversed quotation mark */
189   { 0x2024,               NULL,         "." },      /* one dot leader */
190   { 0x2025,               NULL,         ".." },      /* two dot leader */
191   { 0x2026,               NULL,         "..." },   /* horizontal ellipsis */
192   { 0x2047,               NULL,         "??" },      /* double question mark */
193   { 0x2048,               NULL,         "?!" },      /* question exclamation mark */
194   { 0x2049,               NULL,         "!?" },      /* exclamation question mark */
195   { 0xff01,               NULL,         "!" },      /* fullwidth exclamation point */
196   { 0xff02,               NULL,         "\"" },      /* fullwidth quotation mark */
197   { 0xff03,               NULL,         "#" },      /* fullwidth number sign */
198   { 0xff04,               NULL,         "$" },      /* fullwidth dollar sign */
199   { 0xff05,               NULL,         "%" },      /* fullwidth percent sign */
200   { 0xff06,               NULL,         "&" },      /* fullwidth ampersand */
201   { 0xff07,               NULL,         "\'" },      /* fullwidth apostrophe */
202   { 0xff08,               NULL,         "(" },      /* fullwidth left parenthesis */
203   { 0xff09,               NULL,         ")" },      /* fullwidth right parenthesis */
204   { 0xff0a,               NULL,         "*" },      /* fullwidth asterisk */
205   { 0xff0b,               NULL,         "+" },      /* fullwidth plus */
206   { 0xff0c,               NULL,         "," },      /* fullwidth comma */
207   { 0xff0d,               NULL,         "-" },      /* fullwidth minus */
208   { 0xff0e,               NULL,         "." },      /* fullwidth period */
209   { 0xff0f,               NULL,         "/" },      /* fullwidth slash */
210   { 0xff10,               NULL,         "0" },      /* fullwidth zero */
211   { 0xff11,               NULL,         "1" },      /* fullwidth one */
212   { 0xff12,               NULL,         "2" },      /* fullwidth two */
213   { 0xff13,               NULL,         "3" },      /* fullwidth three */
214   { 0xff14,               NULL,         "4" },      /* fullwidth four */
215   { 0xff15,               NULL,         "5" },      /* fullwidth five */
216   { 0xff16,               NULL,         "6" },      /* fullwidth six */
217   { 0xff17,               NULL,         "7" },      /* fullwidth seven */
218   { 0xff18,               NULL,         "8" },      /* fullwidth eight */
219   { 0xff19,               NULL,         "9" },      /* fullwidth nine */
220   { 0xff1a,               NULL,         ":" },      /* fullwidth colon */
221   { 0xff1b,               NULL,         ";" },      /* fullwidth semicolon */
222   { 0xff1c,               NULL,         "<" },      /* fullwidth less than sign */
223   { 0xff1d,               NULL,         "=" },      /* fullwidth equals sign */
224   { 0xff1e,               NULL,         ">" },      /* fullwidth greater than sign */
225   { 0xff1f,               NULL,         "?" },      /* fullwidth question mark */
226   { 0xff20,               NULL,         "@" },      /* fullwidth at sign */
227   { 0xff21,               NULL,         "A" },      /* fullwidth 'A' */
228   { 0xff22,               NULL,         "B" },      /* fullwidth 'B' */
229   { 0xff23,               NULL,         "C" },      /* fullwidth 'C' */
230   { 0xff24,               NULL,         "D" },      /* fullwidth 'D' */
231   { 0xff25,               NULL,         "E" },      /* fullwidth 'E' */
232   { 0xff26,               NULL,         "F" },      /* fullwidth 'F' */
233   { 0xff27,               NULL,         "G" },      /* fullwidth 'G' */
234   { 0xff28,               NULL,         "H" },      /* fullwidth 'H' */
235   { 0xff29,               NULL,         "I" },      /* fullwidth 'I' */
236   { 0xff2a,               NULL,         "J" },      /* fullwidth 'J' */
237   { 0xff2b,               NULL,         "K" },      /* fullwidth 'K' */
238   { 0xff2c,               NULL,         "L" },      /* fullwidth 'L' */
239   { 0xff2d,               NULL,         "M" },      /* fullwidth 'M' */
240   { 0xff2e,               NULL,         "N" },      /* fullwidth 'N' */
241   { 0xff2f,               NULL,         "O" },      /* fullwidth 'O' */
242   { 0xff30,               NULL,         "P" },      /* fullwidth 'P' */
243   { 0xff31,               NULL,         "Q" },      /* fullwidth 'Q' */
244   { 0xff32,               NULL,         "R" },      /* fullwidth 'R' */
245   { 0xff33,               NULL,         "S" },      /* fullwidth 'S' */
246   { 0xff34,               NULL,         "T" },      /* fullwidth 'T' */
247   { 0xff35,               NULL,         "U" },      /* fullwidth 'U' */
248   { 0xff36,               NULL,         "V" },      /* fullwidth 'V' */
249   { 0xff37,               NULL,         "W" },      /* fullwidth 'W' */
250   { 0xff38,               NULL,         "X" },      /* fullwidth 'X' */
251   { 0xff39,               NULL,         "Y" },      /* fullwidth 'Y' */
252   { 0xff3a,               NULL,         "Z" },      /* fullwidth 'Z' */
253   { 0xff3b,               NULL,         "[" },      /* fullwidth left bracket */
254   { 0xff3c,               NULL,         "\\" },      /* fullwidth backslash */
255   { 0xff3d,               NULL,         "]"   },      /* fullwidth right bracket */
256   { 0xff3e,               NULL,         "^" },      /* fullwidth caret */
257   { 0xff3f,               NULL,         "_" },      /* fullwidth underscore */
258   { 0xff40,               NULL,         "`" },      /* fullwidth backquote */
259   { 0xff41,               NULL,         "a" },      /* fullwidth 'a' */
260   { 0xff42,               NULL,         "b" },      /* fullwidth 'b' */
261   { 0xff43,               NULL,         "c" },      /* fullwidth 'c' */
262   { 0xff44,               NULL,         "d" },      /* fullwidth 'd' */
263   { 0xff45,               NULL,         "e" },      /* fullwidth 'e' */
264   { 0xff46,               NULL,         "f" },      /* fullwidth 'f' */
265   { 0xff47,               NULL,         "g" },      /* fullwidth 'g' */
266   { 0xff48,               NULL,         "h" },      /* fullwidth 'h' */
267   { 0xff49,               NULL,         "i" },      /* fullwidth 'i' */
268   { 0xff4a,               NULL,         "j" },      /* fullwidth 'j' */
269   { 0xff4b,               NULL,         "k" },      /* fullwidth 'k' */
270   { 0xff4c,               NULL,         "l" },      /* fullwidth 'l' */
271   { 0xff4d,               NULL,         "m" },      /* fullwidth 'm' */
272   { 0xff4e,               NULL,         "n" },      /* fullwidth 'n' */
273   { 0xff4f,               NULL,         "o" },      /* fullwidth 'o' */
274   { 0xff50,               NULL,         "p" },      /* fullwidth 'p' */
275   { 0xff51,               NULL,         "q" },      /* fullwidth 'q' */
276   { 0xff52,               NULL,         "r" },      /* fullwidth 'r' */
277   { 0xff53,               NULL,         "s" },      /* fullwidth 's' */
278   { 0xff54,               NULL,         "t" },      /* fullwidth 't' */
279   { 0xff55,               NULL,         "u" },      /* fullwidth 'u' */
280   { 0xff56,               NULL,         "v" },      /* fullwidth 'v' */
281   { 0xff57,               NULL,         "w" },      /* fullwidth 'w' */
282   { 0xff58,               NULL,         "x" },      /* fullwidth 'x' */
283   { 0xff59,               NULL,         "y" },      /* fullwidth 'y' */
284   { 0xff5a,               NULL,         "z" },      /* fullwidth 'z' */
285   { 0xff5b,               NULL,         "{" },      /* fullwidth left brace */
286   { 0xff5c,               NULL,         "|" },      /* fullwidth vertical bar */
287   { 0xff5d,               NULL,         "}" },      /* fullwidth right brace */
288   { 0xff5e,               NULL,         "~" },      /* fullwidth tilde */
289   { 0xff5f,               NULL,         "((" },      /* fullwidth double left parenthesis */
290   { 0xff60,               NULL,         "))" },      /* fullwidth double right parenthesis */
291   { 0xffe0,               NULL,         "\xC2\xA2" },      /* fullwidth cent sign */
292   { 0xffe1,               NULL,         "\xC2\xA3" },      /* fullwidth pound sign */
293   { 0xffe4,               NULL,         "\xC2\xA4" },      /* fullwidth broken bar */
294   { 0xffe5,               NULL,         "\xC2\xA5" },      /* fullwidth yen sign */
295   { 0xffe6,               NULL,         "\xE2\x82\xA9" },   /* fullwidth won sign */
296   { 0xffe9,               NULL,         "\xE2\x86\x90" },   /* fullwidth left arrow */
297   { 0xffea,               NULL,         "\xE2\x86\x91" },   /* fullwidth up arrow */
298   { 0xffeb,               NULL,         "\xE2\x86\x92" },   /* fullwidth right arrow */
299   { 0xffec,               NULL,         "\xE2\x86\x93" },   /* fullwidth down arrow */
300   { 0xffed,               NULL,         "\xE2\x96\xAA" },   /* fullwidth solid box */
301   { 0xffee,               NULL,         "\xE2\x97\xA6" },   /* fullwidth open circle */
302   { UCHAR_SHIFT_1,         "Shift",      NULL },      /* Shift key */
303   { UCHAR_SHIFT_2,         "Ctrl",         NULL },      /* Ctrl key */
304   { UCHAR_MAMEKEY(F1),      "F1",         NULL },      /* F1 function key */
305   { UCHAR_MAMEKEY(F2),      "F2",         NULL },      /* F2 function key */
306   { UCHAR_MAMEKEY(F3),      "F3",         NULL },      /* F3 function key */
307   { UCHAR_MAMEKEY(F4),      "F4",         NULL },      /* F4 function key */
308   { UCHAR_MAMEKEY(F5),      "F5",         NULL },      /* F5 function key */
309   { UCHAR_MAMEKEY(F6),      "F6",         NULL },      /* F6 function key */
310   { UCHAR_MAMEKEY(F7),      "F7",         NULL },      /* F7 function key */
311   { UCHAR_MAMEKEY(F8),      "F8",         NULL },      /* F8 function key */
312   { UCHAR_MAMEKEY(F9),      "F9",         NULL },      /* F9 function key */
313   { UCHAR_MAMEKEY(F10),      "F10",         NULL },      /* F10 function key */
314   { UCHAR_MAMEKEY(F11),      "F11",         NULL },      /* F11 function key */
315   { UCHAR_MAMEKEY(F12),      "F12",         NULL },      /* F12 function key */
316   { UCHAR_MAMEKEY(F13),      "F13",         NULL },      /* F13 function key */
317   { UCHAR_MAMEKEY(F14),      "F14",         NULL },      /* F14 function key */
318   { UCHAR_MAMEKEY(F15),      "F15",         NULL },      /* F15 function key */
319   { UCHAR_MAMEKEY(ESC),      "Esc",         "\033" },   /* Esc key */
320   { UCHAR_MAMEKEY(INSERT),   "Insert",      NULL },      /* Insert key */
321   { UCHAR_MAMEKEY(DEL),      "Delete",      "\010" },   /* Delete key */
322   { UCHAR_MAMEKEY(HOME),      "Home",         "\014" },   /* Home key */
323   { UCHAR_MAMEKEY(END),      "End",         NULL },      /* End key */
324   { UCHAR_MAMEKEY(PGUP),      "Page Up",      NULL },      /* Page Up key */
325   { UCHAR_MAMEKEY(PGDN),      "Page Down",   NULL },      /* Page Down key */
326   { UCHAR_MAMEKEY(LEFT),      "Cursor Left",   NULL },      /* Cursor Left */
327   { UCHAR_MAMEKEY(RIGHT),      "Cursor Right",   NULL },      /* Cursor Right */
328   { UCHAR_MAMEKEY(UP),      "Cursor Up",   NULL },      /* Cursor Up */
329   { UCHAR_MAMEKEY(DOWN),      "Cursor Down",   NULL },      /* Cursor Down */
330   { UCHAR_MAMEKEY(0_PAD),      "Keypad 0",      NULL },      /* 0 on the numeric keypad */
331   { UCHAR_MAMEKEY(1_PAD),      "Keypad 1",      NULL },      /* 1 on the numeric keypad */
332   { UCHAR_MAMEKEY(2_PAD),      "Keypad 2",      NULL },      /* 2 on the numeric keypad */
333   { UCHAR_MAMEKEY(3_PAD),      "Keypad 3",      NULL },      /* 3 on the numeric keypad */
334   { UCHAR_MAMEKEY(4_PAD),      "Keypad 4",      NULL },      /* 4 on the numeric keypad */
335   { UCHAR_MAMEKEY(5_PAD),      "Keypad 5",      NULL },      /* 5 on the numeric keypad */
336   { UCHAR_MAMEKEY(6_PAD),      "Keypad 6",      NULL },      /* 6 on the numeric keypad */
337   { UCHAR_MAMEKEY(7_PAD),      "Keypad 7",      NULL },      /* 7 on the numeric keypad */
338   { UCHAR_MAMEKEY(8_PAD),      "Keypad 8",      NULL },      /* 8 on the numeric keypad */
339   { UCHAR_MAMEKEY(9_PAD),      "Keypad 9",      NULL },      /* 9 on the numeric keypad */
340   { UCHAR_MAMEKEY(SLASH_PAD),   "Keypad /",      NULL },      /* / on the numeric keypad */
341   { UCHAR_MAMEKEY(ASTERISK),   "Keypad *",      NULL },      /* * on the numeric keypad */
342   { UCHAR_MAMEKEY(MINUS_PAD),   "Keypad -",      NULL },      /* - on the numeric Keypad */
343   { UCHAR_MAMEKEY(PLUS_PAD),   "Keypad +",      NULL },      /* + on the numeric Keypad */
344   { UCHAR_MAMEKEY(DEL_PAD),   "Keypad .",      NULL },      /* . on the numeric keypad */
345   { UCHAR_MAMEKEY(ENTER_PAD),   "Keypad Enter",   NULL },      /* Enter on the numeric keypad */
346   { UCHAR_MAMEKEY(PRTSCR),   "Print Screen",   NULL },      /* Print Screen key */
347   { UCHAR_MAMEKEY(PAUSE),      "Pause",      NULL },      /* Pause key */
348   { UCHAR_MAMEKEY(LSHIFT),   "Left Shift",   NULL },      /* Left Shift key */
349   { UCHAR_MAMEKEY(RSHIFT),   "Right Shift",   NULL },      /* Right Shift key */
350   { UCHAR_MAMEKEY(LCONTROL),   "Left Ctrl",   NULL },      /* Left Control key */
351   { UCHAR_MAMEKEY(RCONTROL),   "Right Ctrl",   NULL },      /* Right Control key */
352   { UCHAR_MAMEKEY(LALT),      "Left Alt",      NULL },      /* Left Alt key */
353   { UCHAR_MAMEKEY(RALT),      "Right Alt",   NULL },      /* Right Alt key */
354   { UCHAR_MAMEKEY(SCRLOCK),   "Scroll Lock",   NULL },      /* Scroll Lock key */
355   { UCHAR_MAMEKEY(NUMLOCK),   "Num Lock",      NULL },      /* Num Lock key */
356   { UCHAR_MAMEKEY(CAPSLOCK),   "Caps Lock",   NULL },      /* Caps Lock key */
357   { UCHAR_MAMEKEY(LWIN),      "Left Win",      NULL },      /* Left Win key */
358   { UCHAR_MAMEKEY(RWIN),      "Right Win",   NULL },      /* Right Win key */
359   { UCHAR_MAMEKEY(MENU),      "Menu",         NULL },      /* Menu key */
360   { UCHAR_MAMEKEY(CANCEL),   "Break",      NULL }      /* Break/Pause key */
361};
362
363
364
365
366/***************************************************************************
367    MISCELLANEOUS
368***************************************************************************/
369
370/*-------------------------------------------------
371    find_charinfo - looks up information about a
372    particular character
373-------------------------------------------------*/
374
375static const char_info *find_charinfo(unicode_char target_char)
376{
377   int low = 0;
378   int high = ARRAY_LENGTH(charinfo);
379   int i;
380   unicode_char ch;
381
382   /* perform a simple binary search to find the proper alternate */
383   while(high > low)
384   {
385      i = (high + low) / 2;
386      ch = charinfo[i].ch;
387      if (ch < target_char)
388         low = i + 1;
389      else if (ch > target_char)
390         high = i;
391      else
392         return &charinfo[i];
393   }
394   return NULL;
395}
396
397
398
399/***************************************************************************
400    CODE ASSEMBLING
401***************************************************************************/
402
403/*-------------------------------------------------
404    code_point_string - obtain a string representation of a
405    given code; used for logging and debugging
406-------------------------------------------------*/
407
408static const char *code_point_string(running_machine *machine, unicode_char ch)
409{
410   static char buf[16];
411   const char *result = buf;
412
413   switch(ch)
414   {
415      /* check some magic values */
416      case '\0':   strcpy(buf, "\\0");      break;
417      case '\r':   strcpy(buf, "\\r");      break;
418      case '\n':   strcpy(buf, "\\n");      break;
419      case '\t':   strcpy(buf, "\\t");      break;
420
421      default:
422         if ((ch >= 32) && (ch < 128))
423         {
424            /* seven bit ASCII is easy */
425            buf[0] = (char) ch;
426            buf[1] = '\0';
427         }
428         else if (ch >= UCHAR_MAMEKEY_BEGIN)
429         {
430            /* try to obtain a codename with input_code_name(); this can result in an empty string */
431            astring astr;
432            input_code_name(machine, astr, (input_code) ch - UCHAR_MAMEKEY_BEGIN);
433            snprintf(buf, ARRAY_LENGTH(buf), "%s", astr.cstr());
434         }
435         else
436         {
437            /* empty string; resolve later */
438            buf[0] = '\0';
439         }
440
441         /* did we fail to resolve? if so, we have a last resort */
442         if (buf[0] == '\0')
443            snprintf(buf, ARRAY_LENGTH(buf), "U+%04X", (unsigned) ch);
444         break;
445   }
446   return result;
447}
448
449
450
451/*-------------------------------------------------
452    get_keyboard_code - accesses a particular
453    keyboard code
454-------------------------------------------------*/
455
456static unicode_char get_keyboard_code(const input_field_config *field, int i)
457{
458   unicode_char ch = field->chars[i];
459
460   /* special hack to allow for PORT_CODE('\xA3') */
461   if ((ch >= 0xFFFFFF80) && (ch <= 0xFFFFFFFF))
462      ch &= 0xFF;
463   return ch;
464}
465
466
467
468/*-------------------------------------------------
469    scan_keys - scans through input ports and
470    sets up natural keyboard input mapping
471-------------------------------------------------*/
472
473static int scan_keys(running_machine *machine, const input_port_config *portconfig, mess_input_code *codes, input_port_config_c *ports, input_field_config_c *shift_ports, int keys, int shift)
474{
475   int code_count = 0;
476   const input_port_config *port;
477   const input_field_config *field;
478   unicode_char code;
479
480   assert(keys < NUM_SIMUL_KEYS);
481
482   for (port = portconfig; port != NULL; port = port->next)
483   {
484      for (field = port->fieldlist; field != NULL; field = field->next)
485      {
486         if (field->type == IPT_KEYBOARD)
487         {
488            code = get_keyboard_code(field, shift);
489            if (code != 0)
490            {
491               /* is this a shifter key? */
492               if ((code >= UCHAR_SHIFT_BEGIN) && (code <= UCHAR_SHIFT_END))
493               {
494                  shift_ports[keys] = field;
495                  code_count += scan_keys(machine,
496                     portconfig,
497                     codes ? &codes[code_count] : NULL,
498                     ports,
499                     shift_ports,
500                     keys+1,
501                     code - UCHAR_SHIFT_1 + 1);
502               }
503               else
504               {
505                  /* not a shifter key; record normally */
506                  if (codes)
507                  {
508                     /* if we have a destination, record the codes used here */
509                     memcpy((void *) codes[code_count].field, shift_ports, sizeof(shift_ports[0]) * keys);
510                     codes[code_count].ch = code;
511                     codes[code_count].field[keys] = field;
512                  }
513
514                  /* increment the count */
515                  code_count++;
516
517                  if (LOG_INPUTX)
518                     logerror("inputx: code=%i (%s) port=%p field->name='%s'\n", (int) code, code_point_string(machine, code), port, field->name);
519               }
520            }
521         }
522      }
523   }
524   return code_count;
525}
526
527
528
529/*-------------------------------------------------
530    build_codes - given an input port table, create
531    a input code table useful for mapping unicode
532    chars
533-------------------------------------------------*/
534
535static mess_input_code *build_codes(running_machine *machine, const input_port_config *portconfig)
536{
537   mess_input_code *codes = NULL;
538   const input_port_config *ports[NUM_SIMUL_KEYS];
539   const input_field_config *fields[NUM_SIMUL_KEYS];
540   int code_count;
541
542   /* first count the number of codes */
543   code_count = scan_keys(machine, portconfig, NULL, ports, fields, 0, 0);
544   if (code_count > 0)
545   {
546      /* allocate the codes */
547      codes = auto_alloc_array_clear(machine, mess_input_code, code_count + 1);
548
549      /* and populate them */
550      scan_keys(machine, portconfig, codes, ports, fields, 0, 0);
551   }
552   return codes;
553}
554
555
556
557/***************************************************************************
558    VALIDITY CHECKS
559***************************************************************************/
560
561/*-------------------------------------------------
562    mess_validate_natural_keyboard_statics -
563    validates natural keyboard static data
564-------------------------------------------------*/
565
566int mess_validate_natural_keyboard_statics(void)
567{
568   int i;
569   int error = FALSE;
570   unicode_char last_char = 0;
571   const char_info *ci;
572
573   /* check to make sure that charinfo is in order */
574   for (i = 0; i < ARRAY_LENGTH(charinfo); i++)
575   {
576      if (last_char >= charinfo[i].ch)
577      {
578         mame_printf_error("inputx: charinfo is out of order; 0x%08x should be higher than 0x%08x\n", charinfo[i].ch, last_char);
579         error = TRUE;
580      }
581      last_char = charinfo[i].ch;
582   }
583
584   /* check to make sure that I can look up everything on alternate_charmap */
585   for (i = 0; i < ARRAY_LENGTH(charinfo); i++)
586   {
587      ci = find_charinfo(charinfo[i].ch);
588      if (ci != &charinfo[i])
589      {
590         mame_printf_error("inputx: expected find_charinfo(0x%08x) to work properly\n", charinfo[i].ch);
591         error = TRUE;
592      }
593   }
594   return error;
595}
596
597
598
599/***************************************************************************
600    CORE IMPLEMENTATION
601***************************************************************************/
602
603static mess_input_code *codes;
604static key_buffer *keybuffer;
605static emu_timer *inputx_timer;
606static int (*queue_chars)(const unicode_char *text, size_t text_len);
607static int (*accept_char)(unicode_char ch);
608static int (*charqueue_empty)(void);
609static attotime current_rate;
610
611static TIMER_CALLBACK(inputx_timerproc);
612
613
614/*  Debugging commands and handlers. */
615static void execute_input(running_machine *machine, int ref, int params, const char *param[]);
616static void execute_dumpkbd(running_machine *machine, int ref, int params, const char *param[]);
617
618
619
620static void clear_keybuffer(running_machine *machine)
621{
622   keybuffer = NULL;
623   queue_chars = NULL;
624   codes = NULL;
625}
626
627
628
629static void setup_keybuffer(running_machine *machine)
630{
631   inputx_timer = timer_alloc(machine, inputx_timerproc, NULL);
632   keybuffer = auto_alloc_clear(machine, key_buffer);
633   add_exit_callback(machine, clear_keybuffer);
634}
635
636
637
638void inputx_init(running_machine *machine)
639{
640   codes = NULL;
641   inputx_timer = NULL;
642   queue_chars = NULL;
643   accept_char = NULL;
644   charqueue_empty = NULL;
645   keybuffer = NULL;
646
647   if (machine->debug_flags & DEBUG_FLAG_ENABLED)
648   {
649      debug_console_register_command(machine, "input", CMDFLAG_NONE, 0, 1, 1, execute_input);
650      debug_console_register_command(machine, "dumpkbd", CMDFLAG_NONE, 0, 0, 1, execute_dumpkbd);
651   }
652
653   /* posting keys directly only makes sense for a computer */
654   if (input_machine_have_keyboard(machine))
655   {
656      codes = build_codes(machine, machine->portlist.first());
657      setup_keybuffer(machine);
658   }
659}
660
661
662
663void inputx_setup_natural_keyboard(
664   int (*queue_chars_)(const unicode_char *text, size_t text_len),
665   int (*accept_char_)(unicode_char ch),
666   int (*charqueue_empty_)(void))
667{
668   queue_chars = queue_chars_;
669   accept_char = accept_char_;
670   charqueue_empty = charqueue_empty_;
671}
672
673int inputx_can_post(running_machine *machine)
674{
675   return queue_chars || codes;
676}
677
678static key_buffer *get_buffer(running_machine *machine)
679{
680   assert(inputx_can_post(machine));
681   return (key_buffer *) keybuffer;
682}
683
684
685
686static const mess_input_code *find_code(unicode_char ch)
687{
688   int i;
689
690   assert(codes);
691   for (i = 0; codes[i].ch; i++)
692   {
693      if (codes[i].ch == ch)
694         return &codes[i];
695   }
696   return NULL;
697}
698
699
700
701static int can_post_key_directly(unicode_char ch)
702{
703   int rc = FALSE;
704   const mess_input_code *code;
705
706   if (queue_chars)
707   {
708      rc = accept_char ? accept_char(ch) : TRUE;
709   }
710   else
711   {
712      code = find_code(ch);
713      if (code)
714         rc = code->field[0] != NULL;
715   }
716   return rc;
717}
718
719
720
721static int can_post_key_alternate(unicode_char ch)
722{
723   const char *s;
724   const char_info *ci;
725   unicode_char uchar;
726   int rc;
727
728   ci = find_charinfo(ch);
729   s = ci ? ci->alternate : NULL;
730   if (!s)
731      return 0;
732
733   while(*s)
734   {
735      rc = uchar_from_utf8(&uchar, s, strlen(s));
736      if (rc <= 0)
737         return 0;
738      if (!can_post_key_directly(uchar))
739         return 0;
740      s += rc;
741   }
742   return 1;
743}
744
745
746
747int inputx_can_post_key(running_machine *machine, unicode_char ch)
748{
749   return inputx_can_post(machine) && (can_post_key_directly(ch) || can_post_key_alternate(ch));
750}
751
752
753
754static attotime choose_delay(unicode_char ch)
755{
756   attoseconds_t delay = 0;
757
758   if (attotime_compare(current_rate, attotime_zero) != 0)
759      return current_rate;
760
761   if (queue_chars)
762   {
763      /* systems with queue_chars can afford a much smaller delay */
764      delay = DOUBLE_TO_ATTOSECONDS(0.01);
765   }
766   else
767   {
768      switch(ch) {
769      case '\r':
770         delay = DOUBLE_TO_ATTOSECONDS(0.2);
771         break;
772
773      default:
774         delay = DOUBLE_TO_ATTOSECONDS(0.05);
775         break;
776      }
777   }
778   return attotime_make(0, delay);
779}
780
781
782
783static void internal_post_key(running_machine *machine, unicode_char ch)
784{
785   key_buffer *keybuf;
786
787   keybuf = get_buffer(machine);
788
789   /* need to start up the timer? */
790   if (keybuf->begin_pos == keybuf->end_pos)
791   {
792      timer_adjust_oneshot(inputx_timer, choose_delay(ch), 0);
793      keybuf->status_keydown = 0;
794   }
795
796   keybuf->buffer[keybuf->end_pos++] = ch;
797   keybuf->end_pos %= ARRAY_LENGTH(keybuf->buffer);
798}
799
800
801
802static int buffer_full(running_machine *machine)
803{
804   key_buffer *keybuf;
805   keybuf = get_buffer(machine);
806   return ((keybuf->end_pos + 1) % ARRAY_LENGTH(keybuf->buffer)) == keybuf->begin_pos;
807}
808
809
810
811void inputx_postn_rate(running_machine *machine, const unicode_char *text, size_t text_len, attotime rate)
812{
813   int last_cr = 0;
814   unicode_char ch;
815   const char *s;
816   const char_info *ci;
817   const mess_input_code *code;
818
819   current_rate = rate;
820
821   if (inputx_can_post(machine))
822   {
823      while((text_len > 0) && !buffer_full(machine))
824      {
825         ch = *(text++);
826         text_len--;
827
828         /* change all eolns to '\r' */
829         if ((ch != '\n') || !last_cr)
830         {
831            if (ch == '\n')
832               ch = '\r';
833            else
834               last_cr = (ch == '\r');
835
836            if (LOG_INPUTX)
837            {
838               code = find_code(ch);
839               logerror("inputx_postn(): code=%i (%s) field->name='%s'\n", (int) ch, code_point_string(machine, ch), (code && code->field[0]) ? code->field[0]->name : "<null>");
840            }
841
842            if (can_post_key_directly(ch))
843            {
844               /* we can post this key in the queue directly */
845               internal_post_key(machine, ch);
846            }
847            else if (can_post_key_alternate(ch))
848            {
849               /* we can post this key with an alternate representation */
850               ci = find_charinfo(ch);
851               assert(ci && ci->alternate);
852               s = ci->alternate;
853               while(*s)
854               {
855                  s += uchar_from_utf8(&ch, s, strlen(s));
856                  internal_post_key(machine, ch);
857               }
858            }
859         }
860         else
861         {
862            last_cr = 0;
863         }
864      }
865   }
866}
867
868
869
870static TIMER_CALLBACK(inputx_timerproc)
871{
872   key_buffer *keybuf;
873   attotime delay;
874
875   keybuf = get_buffer(machine);
876
877   if (queue_chars)
878   {
879      /* the driver has a queue_chars handler */
880      while((keybuf->begin_pos != keybuf->end_pos) && queue_chars(&keybuf->buffer[keybuf->begin_pos], 1))
881      {
882         keybuf->begin_pos++;
883         keybuf->begin_pos %= ARRAY_LENGTH(keybuf->buffer);
884
885         if (attotime_compare(current_rate, attotime_zero) != 0)
886            break;
887      }
888   }
889   else
890   {
891      /* the driver does not have a queue_chars handler */
892      if (keybuf->status_keydown)
893      {
894         keybuf->status_keydown = FALSE;
895         keybuf->begin_pos++;
896         keybuf->begin_pos %= ARRAY_LENGTH(keybuf->buffer);
897      }
898      else
899      {
900         keybuf->status_keydown = TRUE;
901      }
902   }
903
904   /* need to make sure timerproc is called again if buffer not empty */
905   if (keybuf->begin_pos != keybuf->end_pos)
906   {
907      delay = choose_delay(keybuf->buffer[keybuf->begin_pos]);
908      timer_adjust_oneshot(inputx_timer, delay, 0);
909   }
910}
911
912
913
914/*-------------------------------------------------
915    mess_input_port_update_hook - hook function
916    called from core to allow for natural keyboard
917-------------------------------------------------*/
918
919void mess_input_port_update_hook(running_machine *machine, const input_port_config *port, input_port_value *digital)
920{
921   const key_buffer *keybuf;
922   const mess_input_code *code;
923   unicode_char ch;
924   int i;
925   UINT32 value;
926
927   if (inputx_can_post(machine))
928   {
929      keybuf = get_buffer(machine);
930
931      /* is the key down right now? */
932      if (keybuf->status_keydown && (keybuf->begin_pos != keybuf->end_pos))
933      {
934         /* identify the character that is down right now, and its component codes */
935         ch = keybuf->buffer[keybuf->begin_pos];
936         code = find_code(ch);
937
938         /* loop through this character's component codes */
939         if (code != NULL)
940         {
941            for (i = 0; i < ARRAY_LENGTH(code->field) && (code->field[i] != NULL); i++)
942            {
943               if (code->field[i]->port == port)
944               {
945                  value = code->field[i]->mask;
946                  *digital |= value;
947               }
948            }
949         }
950      }
951   }
952}
953
954
955
956/*-------------------------------------------------
957    mess_get_keyboard_key_name - builds the name of
958    a key based on natural keyboard characters
959-------------------------------------------------*/
960
961astring *mess_get_keyboard_key_name(const input_field_config *field)
962{
963   astring *result = astring_alloc();
964   int i;
965   unicode_char ch;
966
967
968   /* loop through each character on the field*/
969   for (i = 0; i < ARRAY_LENGTH(field->chars) && (field->chars[i] != '\0'); i++)
970   {
971      ch = get_keyboard_code(field, i);
972      astring_printf(result, "%s%-*s ", astring_c(result), MAX(SPACE_COUNT - 1, 0), inputx_key_name(ch));
973   }
974
975   /* trim extra spaces */
976   astring_trimspace(result);
977
978   /* special case */
979   if (astring_len(result) == 0)
980      astring_cpyc(result, "Unnamed Key");
981
982   return result;
983}
984
985
986
987/*-------------------------------------------------
988    inputx_key_name - returns the name of a
989    specific key
990-------------------------------------------------*/
991
992const char *inputx_key_name(unicode_char ch)
993{
994   static char buf[UTF8_CHAR_MAX + 1];
995   const char_info *ci;
996   const char *result;
997   int pos;
998
999   ci = find_charinfo(ch);
1000   result = ci ? ci->name : NULL;
1001
1002   if (ci && ci->name)
1003   {
1004      result = ci->name;
1005   }
1006   else
1007   {
1008      if ((ch > 0x7F) || isprint(ch))
1009      {
1010         pos = utf8_from_uchar(buf, ARRAY_LENGTH(buf), ch);
1011         buf[pos] = '\0';
1012         result = buf;
1013      }
1014      else
1015         result = "???";
1016   }
1017   return result;
1018}
1019
1020
1021
1022/* --------------------------------------------------------------------- */
1023
1024int inputx_is_posting(running_machine *machine)
1025{
1026   const key_buffer *keybuf;
1027   keybuf = get_buffer(machine);
1028   return (keybuf->begin_pos != keybuf->end_pos) || (charqueue_empty && !charqueue_empty());
1029}
1030
1031
1032
1033/***************************************************************************
1034
1035    Coded input
1036
1037***************************************************************************/
1038
1039void inputx_postn_coded_rate(running_machine *machine, const char *text, size_t text_len, attotime rate)
1040{
1041   size_t i, j, key_len, increment;
1042   unicode_char ch;
1043
1044   static const struct
1045   {
1046      const char *key;
1047      unicode_char code;
1048   } codes[] =
1049   {
1050      { "BACKSPACE",   8 },
1051      { "BS",         8 },
1052      { "BKSP",      8 },
1053      { "DEL",      UCHAR_MAMEKEY(DEL) },
1054      { "DELETE",      UCHAR_MAMEKEY(DEL) },
1055      { "END",      UCHAR_MAMEKEY(END) },
1056      { "ENTER",      13 },
1057      { "ESC",      '\033' },
1058      { "HOME",      UCHAR_MAMEKEY(HOME) },
1059      { "INS",      UCHAR_MAMEKEY(INSERT) },
1060      { "INSERT",      UCHAR_MAMEKEY(INSERT) },
1061      { "PGDN",      UCHAR_MAMEKEY(PGDN) },
1062      { "PGUP",      UCHAR_MAMEKEY(PGUP) },
1063      { "SPACE",      32 },
1064      { "TAB",      9 },
1065      { "F1",         UCHAR_MAMEKEY(F1) },
1066      { "F2",         UCHAR_MAMEKEY(F2) },
1067      { "F3",         UCHAR_MAMEKEY(F3) },
1068      { "F4",         UCHAR_MAMEKEY(F4) },
1069      { "F5",         UCHAR_MAMEKEY(F5) },
1070      { "F6",         UCHAR_MAMEKEY(F6) },
1071      { "F7",         UCHAR_MAMEKEY(F7) },
1072      { "F8",         UCHAR_MAMEKEY(F8) },
1073      { "F9",         UCHAR_MAMEKEY(F9) },
1074      { "F10",      UCHAR_MAMEKEY(F10) },
1075      { "F11",      UCHAR_MAMEKEY(F11) },
1076      { "F12",      UCHAR_MAMEKEY(F12) },
1077      { "QUOTE",      '\"' }
1078   };
1079
1080   i = 0;
1081   while(i < text_len)
1082   {
1083      ch = text[i];
1084      increment = 1;
1085
1086      if (ch == '{')
1087      {
1088         for (j = 0; j < ARRAY_LENGTH(codes); j++)
1089         {
1090            key_len = strlen(codes[j].key);
1091            if (i + key_len + 2 <= text_len)
1092            {
1093               if (!memcmp(codes[j].key, &text[i + 1], key_len) && (text[i + key_len + 1] == '}'))
1094               {
1095                  ch = codes[j].code;
1096                  increment = key_len + 2;
1097               }
1098            }
1099         }
1100      }
1101
1102      if (ch)
1103         inputx_postc_rate(machine, ch, rate);
1104      i += increment;
1105   }
1106}
1107
1108
1109
1110/***************************************************************************
1111
1112    Alternative calls
1113
1114***************************************************************************/
1115
1116void inputx_postn(running_machine *machine, const unicode_char *text, size_t text_len)
1117{
1118   inputx_postn_rate(machine, text, text_len, attotime_make(0, 0));
1119}
1120
1121
1122
1123void inputx_post_rate(running_machine *machine, const unicode_char *text, attotime rate)
1124{
1125   size_t len = 0;
1126   while(text[len])
1127      len++;
1128   inputx_postn_rate(machine, text, len, rate);
1129}
1130
1131
1132
1133void inputx_post(running_machine *machine, const unicode_char *text)
1134{
1135   inputx_post_rate(machine, text, attotime_make(0, 0));
1136}
1137
1138
1139
1140void inputx_postc_rate(running_machine *machine, unicode_char ch, attotime rate)
1141{
1142   inputx_postn_rate(machine, &ch, 1, rate);
1143}
1144
1145
1146
1147void inputx_postc(running_machine *machine, unicode_char ch)
1148{
1149   inputx_postc_rate(machine, ch, attotime_make(0, 0));
1150}
1151
1152
1153
1154void inputx_postn_utf16_rate(running_machine *machine, const utf16_char *text, size_t text_len, attotime rate)
1155{
1156   size_t len = 0;
1157   unicode_char c;
1158   utf16_char w1, w2;
1159   unicode_char buf[256];
1160
1161   while(text_len > 0)
1162   {
1163      if (len == ARRAY_LENGTH(buf))
1164      {
1165         inputx_postn(machine, buf, len);
1166         len = 0;
1167      }
1168
1169      w1 = *(text++);
1170      text_len--;
1171
1172      if ((w1 >= 0xd800) && (w1 <= 0xdfff))
1173      {
1174         if (w1 <= 0xDBFF)
1175         {
1176            w2 = 0;
1177            if (text_len > 0)
1178            {
1179               w2 = *(text++);
1180               text_len--;
1181            }
1182            if ((w2 >= 0xdc00) && (w2 <= 0xdfff))
1183            {
1184               c = w1 & 0x03ff;
1185               c <<= 10;
1186               c |= w2 & 0x03ff;
1187            }
1188            else
1189            {
1190               c = INVALID_CHAR;
1191            }
1192         }
1193         else
1194         {
1195            c = INVALID_CHAR;
1196         }
1197      }
1198      else
1199      {
1200         c = w1;
1201      }
1202      buf[len++] = c;
1203   }
1204   inputx_postn_rate(machine, buf, len, rate);
1205}
1206
1207
1208
1209void inputx_postn_utf16(running_machine *machine, const utf16_char *text, size_t text_len)
1210{
1211   inputx_postn_utf16_rate(machine, text, text_len, attotime_make(0, 0));
1212}
1213
1214
1215
1216void inputx_post_utf16_rate(running_machine *machine, const utf16_char *text, attotime rate)
1217{
1218   size_t len = 0;
1219   while(text[len])
1220      len++;
1221   inputx_postn_utf16_rate(machine, text, len, rate);
1222}
1223
1224
1225
1226void inputx_post_utf16(running_machine *machine, const utf16_char *text)
1227{
1228   inputx_post_utf16_rate(machine, text, attotime_make(0, 0));
1229}
1230
1231
1232
1233void inputx_postn_utf8_rate(running_machine *machine, const char *text, size_t text_len, attotime rate)
1234{
1235   size_t len = 0;
1236   unicode_char buf[256];
1237   unicode_char c;
1238   int rc;
1239
1240   while(text_len > 0)
1241   {
1242      if (len == ARRAY_LENGTH(buf))
1243      {
1244         inputx_postn(machine, buf, len);
1245         len = 0;
1246      }
1247
1248      rc = uchar_from_utf8(&c, text, text_len);
1249      if (rc < 0)
1250      {
1251         rc = 1;
1252         c = INVALID_CHAR;
1253      }
1254      text += rc;
1255      text_len -= rc;
1256      buf[len++] = c;
1257   }
1258   inputx_postn_rate(machine, buf, len, rate);
1259}
1260
1261
1262
1263void inputx_postn_utf8(running_machine *machine, const char *text, size_t text_len)
1264{
1265   inputx_postn_utf8_rate(machine, text, text_len, attotime_make(0, 0));
1266}
1267
1268
1269
1270void inputx_post_utf8_rate(running_machine *machine, const char *text, attotime rate)
1271{
1272   inputx_postn_utf8_rate(machine, text, strlen(text), rate);
1273}
1274
1275
1276
1277void inputx_post_utf8(running_machine *machine, const char *text)
1278{
1279   inputx_post_utf8_rate(machine, text, attotime_make(0, 0));
1280}
1281
1282
1283
1284void inputx_post_coded(running_machine *machine, const char *text)
1285{
1286   inputx_postn_coded(machine, text, strlen(text));
1287}
1288
1289
1290
1291void inputx_post_coded_rate(running_machine *machine, const char *text, attotime rate)
1292{
1293   inputx_postn_coded_rate(machine, text, strlen(text), rate);
1294}
1295
1296
1297
1298void inputx_postn_coded(running_machine *machine, const char *text, size_t text_len)
1299{
1300   inputx_postn_coded_rate(machine, text, text_len, attotime_make(0, 0));
1301}
1302
1303
1304
1305/***************************************************************************
1306
1307    Other stuff
1308
1309    This stuff is here more out of convienience than anything else
1310***************************************************************************/
1311
1312int input_classify_port(const input_field_config *field)
1313{
1314   int result;
1315
1316   if (field->category && (field->type != IPT_CATEGORY))
1317      return INPUT_CLASS_CATEGORIZED;
1318
1319   switch(field->type)
1320   {
1321      case IPT_JOYSTICK_UP:
1322      case IPT_JOYSTICK_DOWN:
1323      case IPT_JOYSTICK_LEFT:
1324      case IPT_JOYSTICK_RIGHT:
1325      case IPT_JOYSTICKLEFT_UP:
1326      case IPT_JOYSTICKLEFT_DOWN:
1327      case IPT_JOYSTICKLEFT_LEFT:
1328      case IPT_JOYSTICKLEFT_RIGHT:
1329      case IPT_JOYSTICKRIGHT_UP:
1330      case IPT_JOYSTICKRIGHT_DOWN:
1331      case IPT_JOYSTICKRIGHT_LEFT:
1332      case IPT_JOYSTICKRIGHT_RIGHT:
1333      case IPT_BUTTON1:
1334      case IPT_BUTTON2:
1335      case IPT_BUTTON3:
1336      case IPT_BUTTON4:
1337      case IPT_BUTTON5:
1338      case IPT_BUTTON6:
1339      case IPT_BUTTON7:
1340      case IPT_BUTTON8:
1341      case IPT_BUTTON9:
1342      case IPT_BUTTON10:
1343      case IPT_AD_STICK_X:
1344      case IPT_AD_STICK_Y:
1345      case IPT_AD_STICK_Z:
1346      case IPT_TRACKBALL_X:
1347      case IPT_TRACKBALL_Y:
1348      case IPT_LIGHTGUN_X:
1349      case IPT_LIGHTGUN_Y:
1350      case IPT_MOUSE_X:
1351      case IPT_MOUSE_Y:
1352      case IPT_START:
1353      case IPT_SELECT:
1354         result = INPUT_CLASS_CONTROLLER;
1355         break;
1356
1357      case IPT_KEYBOARD:
1358         result = INPUT_CLASS_KEYBOARD;
1359         break;
1360
1361      case IPT_CONFIG:
1362         result = INPUT_CLASS_CONFIG;
1363         break;
1364
1365      case IPT_DIPSWITCH:
1366         result = INPUT_CLASS_DIPSWITCH;
1367         break;
1368
1369      case 0:
1370         if (field->name && (field->name != (const char *) -1))
1371            result = INPUT_CLASS_MISC;
1372         else
1373            result = INPUT_CLASS_INTERNAL;
1374         break;
1375
1376      default:
1377         result = INPUT_CLASS_INTERNAL;
1378         break;
1379   }
1380   return result;
1381}
1382
1383
1384
1385int input_player_number(const input_field_config *port)
1386{
1387   return port->player;
1388}
1389
1390
1391
1392/*-------------------------------------------------
1393    input_has_input_class - checks to see if a
1394    particular input class is present
1395-------------------------------------------------*/
1396
1397int input_has_input_class(running_machine *machine, int inputclass)
1398{
1399   const input_port_config *port;
1400   const input_field_config *field;
1401
1402   for (port = machine->portlist.first(); port != NULL; port = port->next)
1403   {
1404      for (field = port->fieldlist; field != NULL; field = field->next)
1405      {
1406         if (input_classify_port(field) == inputclass)
1407            return TRUE;
1408      }
1409   }
1410   return FALSE;
1411}
1412
1413
1414
1415/*-------------------------------------------------
1416    input_count_players - counts the number of
1417    active players
1418-------------------------------------------------*/
1419
1420int input_count_players(running_machine *machine)
1421{
1422   const input_port_config *port;
1423   const input_field_config *field;
1424   int joystick_count;
1425
1426   joystick_count = 0;
1427   for (port = machine->portlist.first(); port != NULL; port = port->next)
1428   {
1429      for (field = port->fieldlist;  field != NULL; field = field->next)
1430      {
1431         if (input_classify_port(field) == INPUT_CLASS_CONTROLLER)
1432         {
1433            if (joystick_count <= field->player + 1)
1434               joystick_count = field->player + 1;
1435         }
1436      }
1437   }
1438   return joystick_count;
1439}
1440
1441
1442
1443/*-------------------------------------------------
1444    input_category_active - checks to see if a
1445    specific category is active
1446-------------------------------------------------*/
1447
1448int input_category_active(running_machine *machine, int category)
1449{
1450   const input_port_config *port;
1451   const input_field_config *field = NULL;
1452   const input_setting_config *setting;
1453   input_field_user_settings settings;
1454
1455   assert(category >= 1);
1456
1457   /* loop through the input ports */
1458   for (port = machine->portlist.first(); port != NULL; port = port->next)
1459   {
1460      for (field = port->fieldlist; field != NULL; field = field->next)
1461      {
1462         /* is this field a category? */
1463         if (field->type == IPT_CATEGORY)
1464         {
1465            /* get the settings value */
1466            input_field_get_user_settings(field, &settings);
1467
1468            for (setting = field->settinglist; setting != NULL; setting = setting->next)
1469            {
1470               /* is this the category we want?  if so, is this settings value correct? */
1471               if ((setting->category == category) && (settings.value == setting->value))
1472                  return TRUE;
1473            }
1474         }
1475      }
1476   }
1477   return FALSE;
1478}
1479
1480
1481
1482/***************************************************************************
1483    DEBUGGER SUPPORT
1484***************************************************************************/
1485
1486/*-------------------------------------------------
1487    execute_input - debugger command to enter
1488    natural keyboard input
1489-------------------------------------------------*/
1490
1491static void execute_input(running_machine *machine, int ref, int params, const char *param[])
1492{
1493   inputx_post_coded(machine, param[0]);
1494}
1495
1496
1497
1498/*-------------------------------------------------
1499    execute_dumpkbd - debugger command to natural
1500    keyboard codes
1501-------------------------------------------------*/
1502
1503static void execute_dumpkbd(running_machine *machine, int ref, int params, const char *param[])
1504{
1505   const char *filename;
1506   FILE *file = NULL;
1507   const mess_input_code *code;
1508   char buffer[512];
1509   size_t pos;
1510   int i, j;
1511   size_t left_column_width = 24;
1512
1513   /* was there a file specified? */
1514   filename = (params > 0) ? param[0] : NULL;
1515   if (filename != NULL)
1516   {
1517      /* if so, open it */
1518      file = fopen(filename, "w");
1519      if (file == NULL)
1520      {
1521         debug_console_printf(machine, "Cannot open \"%s\"\n", filename);
1522         return;
1523      }
1524   }
1525
1526   if ((codes != NULL) && (codes[0].ch != 0))
1527   {
1528      /* loop through all codes */
1529      for (i = 0; codes[i].ch; i++)
1530      {
1531         code = &codes[i];
1532         pos = 0;
1533
1534         /* describe the character code */
1535         pos += snprintf(&buffer[pos], ARRAY_LENGTH(buffer) - pos, "%08X (%s) ",
1536            code->ch,
1537            code_point_string(machine, code->ch));
1538
1539         /* pad with spaces */
1540         while(pos < left_column_width)
1541            buffer[pos++] = ' ';
1542         buffer[pos] = '\0';
1543
1544         /* identify the keys used */
1545         for (j = 0; j < ARRAY_LENGTH(code->field) && (code->field[j] != NULL); j++)
1546         {
1547            pos += snprintf(&buffer[pos], ARRAY_LENGTH(buffer) - pos, "%s'%s'",
1548               (j > 0) ? ", " : "",
1549               code->field[j]->name);
1550         }
1551
1552         /* and output it as appropriate */
1553         if (file != NULL)
1554            fprintf(file, "%s\n", buffer);
1555         else
1556            debug_console_printf(machine, "%s\n", buffer);
1557      }
1558   }
1559   else
1560   {
1561      debug_console_printf(machine, "No natural keyboard support\n");
1562   }
1563
1564   /* cleanup */
1565   if (file != NULL)
1566      fclose(file);
1567
1568}
src/mess/inputx.h
r7335r7336
1/*********************************************************************
2
3    inputx.h
4
5    Secondary input related functions for MESS specific functionality
6
7*********************************************************************/
8
9#ifndef __INPUTX_H__
10#define __INPUTX_H__
11
12/***************************************************************************
13    CONSTANTS
14***************************************************************************/
15
16/* input classes */
17enum
18{
19   INPUT_CLASS_INTERNAL,
20   INPUT_CLASS_KEYBOARD,
21   INPUT_CLASS_CONTROLLER,
22   INPUT_CLASS_CONFIG,
23   INPUT_CLASS_DIPSWITCH,
24   INPUT_CLASS_CATEGORIZED,
25   INPUT_CLASS_MISC
26};
27
28/* MESS uses Supplementary private use B to represent code points
29 * corresponding to MAME keycodes and shift keys.  The nice thing about
30 * supplemental private use B is that it is higher than any possible code
31 * points */
32#define UCHAR_PRIVATE      (0x100000)
33#define UCHAR_SHIFT_1      (UCHAR_PRIVATE + 0)
34#define UCHAR_SHIFT_2      (UCHAR_PRIVATE + 1)
35#define UCHAR_MAMEKEY_BEGIN   (UCHAR_PRIVATE + 2)
36#define UCHAR_MAMEKEY_END   (UCHAR_MAMEKEY_BEGIN + __code_key_last)
37#define UCHAR_MAMEKEY(code)   (UCHAR_MAMEKEY_BEGIN + KEYCODE_##code)
38
39#define UCHAR_SHIFT_BEGIN   (UCHAR_SHIFT_1)
40#define UCHAR_SHIFT_END      (UCHAR_SHIFT_2)
41
42
43
44/***************************************************************************
45    FUNCTION PROTOTYPES
46***************************************************************************/
47
48/* these are called by the core; they should not be called from FEs */
49void inputx_init(running_machine *machine);
50void mess_input_port_update_hook(running_machine *machine, const input_port_config *port, input_port_value *digital);
51astring *mess_get_keyboard_key_name(const input_field_config *field);
52
53/* called by drivers to setup natural keyboard support */
54void inputx_setup_natural_keyboard(
55   int (*queue_chars)(const unicode_char *text, size_t text_len),
56   int (*accept_char)(unicode_char ch),
57   int (*charqueue_empty)(void));
58
59/* validity checks */
60int mess_validate_natural_keyboard_statics(void);
61
62/* these can be called from FEs */
63int inputx_can_post(running_machine *machine);
64int inputx_can_post_key(running_machine *machine, unicode_char ch);
65int inputx_is_posting(running_machine *machine);
66const char *inputx_key_name(unicode_char ch);
67
68/* various posting functions; can be called from FEs */
69void inputx_post(running_machine *machine, const unicode_char *text);
70void inputx_post_rate(running_machine *machine, const unicode_char *text, attotime rate);
71void inputx_postc(running_machine *machine, unicode_char ch);
72void inputx_postc_rate(running_machine *machine, unicode_char ch, attotime rate);
73void inputx_postn(running_machine *machine, const unicode_char *text, size_t text_len);
74void inputx_postn_rate(running_machine *machine, const unicode_char *text, size_t text_len, attotime rate);
75void inputx_post_utf16(running_machine *machine, const utf16_char *text);
76void inputx_post_utf16_rate(running_machine *machine, const utf16_char *text, attotime rate);
77void inputx_postn_utf16(running_machine *machine, const utf16_char *text, size_t text_len);
78void inputx_postn_utf16_rate(running_machine *machine, const utf16_char *text, size_t text_len, attotime rate);
79void inputx_post_utf8(running_machine *machine, const char *text);
80void inputx_post_utf8_rate(running_machine *machine, const char *text, attotime rate);
81void inputx_postn_utf8(running_machine *machine, const char *text, size_t text_len);
82void inputx_postn_utf8_rate(running_machine *machine, const char *text, size_t text_len, attotime rate);
83void inputx_post_coded(running_machine *machine, const char *text);
84void inputx_post_coded_rate(running_machine *machine, const char *text, attotime rate);
85void inputx_postn_coded(running_machine *machine, const char *text, size_t text_len);
86void inputx_postn_coded_rate(running_machine *machine, const char *text, size_t text_len, attotime rate);
87
88/* miscellaneous functions */
89int input_classify_port(const input_field_config *field);
90int input_has_input_class(running_machine *machine, int inputclass);
91int input_player_number(const input_field_config *field);
92int input_count_players(running_machine *machine);
93int input_category_active(running_machine *machine, int category);
94
95#endif /* INPUTX_H */
src/mess/mesvalid.c
r7335r7336
1/***************************************************************************
2
3    mesvalid.c
4
5    Validity checks on internal MESS data structures.
6
7***************************************************************************/
8
9#include <ctype.h>
10
11#include "emu.h"
12#include "mess.h"
13#include "device.h"
14#include "inputx.h"
15
16/*************************************
17 *
18 *  MESS validity checks
19 *
20 *************************************/
21
22int mess_validitychecks(void)
23{
24   return mess_validate_natural_keyboard_statics();
25}
src/mess/uimess.c
r7335r7336
77*********************************************************************/
88
99#include "emu.h"
10#include "mslegacy.h"
1110#include "uimenu.h"
1211#include "uimess.h"
1312#include "uiinput.h"
r7335r7336
1615
1716
1817/***************************************************************************
19    LOCAL VARIABLES
20***************************************************************************/
21
22/* list of natural keyboard keys that are not associated with UI_EVENT_CHARs */
23static const input_item_id non_char_keys[] =
24{
25   ITEM_ID_ESC,
26   ITEM_ID_F1,
27   ITEM_ID_F2,
28   ITEM_ID_F3,
29   ITEM_ID_F4,
30   ITEM_ID_F5,
31   ITEM_ID_F6,
32   ITEM_ID_F7,
33   ITEM_ID_F8,
34   ITEM_ID_F9,
35   ITEM_ID_F10,
36   ITEM_ID_F11,
37   ITEM_ID_F12,
38   ITEM_ID_NUMLOCK,
39   ITEM_ID_0_PAD,
40   ITEM_ID_1_PAD,
41   ITEM_ID_2_PAD,
42   ITEM_ID_3_PAD,
43   ITEM_ID_4_PAD,
44   ITEM_ID_5_PAD,
45   ITEM_ID_6_PAD,
46   ITEM_ID_7_PAD,
47   ITEM_ID_8_PAD,
48   ITEM_ID_9_PAD,
49   ITEM_ID_DEL_PAD,
50   ITEM_ID_PLUS_PAD,
51   ITEM_ID_MINUS_PAD,
52   ITEM_ID_INSERT,
53   ITEM_ID_DEL,
54   ITEM_ID_HOME,
55   ITEM_ID_END,
56   ITEM_ID_PGUP,
57   ITEM_ID_PGDN,
58   ITEM_ID_UP,
59   ITEM_ID_DOWN,
60   ITEM_ID_LEFT,
61   ITEM_ID_RIGHT,
62   ITEM_ID_PAUSE,
63   ITEM_ID_CANCEL
64};
65
66
67
68/***************************************************************************
69    TYPE DEFINITIONS
70***************************************************************************/
71
72struct _ui_mess_private
73{
74   int active;
75   int use_natural_keyboard;
76   UINT8 non_char_keys_down[(ARRAY_LENGTH(non_char_keys) + 7) / 8];
77};
78
79
80
81/***************************************************************************
8218    IMPLEMENTATION
8319***************************************************************************/
8420
85/*-------------------------------------------------
86    ui_mess_init - initialize the MESS-specific
87    UI
88-------------------------------------------------*/
8921
90void ui_mess_init(running_machine *machine)
91{
92   /* allocate memory for our data structure */
93   machine->ui_mess_data = auto_alloc_clear(machine, ui_mess_private);
94
95   /* retrieve options */
96   machine->ui_mess_data->use_natural_keyboard = options_get_bool(mame_options(), OPTION_NATURAL_KEYBOARD);
97}
98
99
100
10122/*-------------------------------------------------
102    process_natural_keyboard - processes any
103    natural keyboard input
104-------------------------------------------------*/
105
106static void process_natural_keyboard(running_machine *machine)
107{
108   ui_event event;
109   int i, pressed;
110   input_item_id itemid;
111   input_code code;
112   UINT8 *key_down_ptr;
113   UINT8 key_down_mask;
114
115   /* loop while we have interesting events */
116   while (ui_input_pop_event(machine, &event))
117   {
118      /* if this was a UI_EVENT_CHAR event, post it */
119      if (event.event_type == UI_EVENT_CHAR)
120         inputx_postc(machine, event.ch);
121   }
122
123   /* process natural keyboard keys that don't get UI_EVENT_CHARs */
124   for (i = 0; i < ARRAY_LENGTH(non_char_keys); i++)
125   {
126      /* identify this keycode */
127      itemid = non_char_keys[i];
128      code = input_code_from_input_item_id(machine, itemid);
129
130      /* ...and determine if it is pressed */
131      pressed = input_code_pressed(machine, code);
132
133      /* figure out whey we are in the key_down map */
134      key_down_ptr = &machine->ui_mess_data->non_char_keys_down[i / 8];
135      key_down_mask = 1 << (i % 8);
136
137      if (pressed && !(*key_down_ptr & key_down_mask))
138      {
139         /* this key is now down */
140         *key_down_ptr |= key_down_mask;
141
142         /* post the key */
143         inputx_postc(machine, UCHAR_MAMEKEY_BEGIN + code);
144      }
145      else if (!pressed && (*key_down_ptr & key_down_mask))
146      {
147         /* this key is now up */
148         *key_down_ptr &= ~key_down_mask;
149      }
150   }
151}
152
153
154
155/*-------------------------------------------------
15623    ui_mess_handler_ingame - function to determine
15724    if the builtin UI should be disabled
15825-------------------------------------------------*/
15926
160int ui_mess_handler_ingame(running_machine *machine)
27void ui_mess_handler_ingame(running_machine *machine)
16128{
162   int ui_disabled;
16329   running_device *dev;
16430
16531   /* run display routine for devices */
r7335r7336
17945      }
18046   }
18147
182   /* determine if we should disable the rest of the UI */
183   ui_disabled = ui_mess_use_new_ui()
184      || (input_machine_have_keyboard(machine) && !machine->ui_mess_data->active);
185
186
187   /* is ScrLk UI toggling applicable here? */
188   if (!ui_mess_use_new_ui() && input_machine_have_keyboard(machine))
189   {
190      /* are we toggling the UI with ScrLk? */
191      if (ui_input_pressed(machine, IPT_UI_TOGGLE_UI))
192      {
193         /* toggle the UI */
194         machine->ui_mess_data->active = !machine->ui_mess_data->active;
195
196         /* display a popup indicating the new status */
197         if (machine->ui_mess_data->active)
198         {
199            ui_popup_time(2, "%s\n%s\n%s\n%s\n%s\n%s\n",
200               ui_getstring(UI_keyb1),
201               ui_getstring(UI_keyb2),
202               ui_getstring(UI_keyb3),
203               ui_getstring(UI_keyb5),
204               ui_getstring(UI_keyb2),
205               ui_getstring(UI_keyb7));
206         }
207         else
208         {
209            ui_popup_time(2, "%s\n%s\n%s\n%s\n%s\n%s\n",
210               ui_getstring(UI_keyb1),
211               ui_getstring(UI_keyb2),
212               ui_getstring(UI_keyb4),
213               ui_getstring(UI_keyb6),
214               ui_getstring(UI_keyb2),
215               ui_getstring(UI_keyb7));
216         }
217      }
218   }
219
220   /* is the natural keyboard enabled? */
221   if (ui_mess_get_use_natural_keyboard(machine) && (mame_get_phase(machine) == MAME_PHASE_RUNNING))
222      process_natural_keyboard(machine);
223
224   /* MESS-specific UI; provided that the UI is not disabled */
225   if (!ui_disabled)
226   {
227      /* paste command */
228      if (ui_input_pressed(machine, IPT_UI_PASTE))
229         ui_mess_paste(machine);
230   }
231
232   return ui_disabled;
23348}
23449
23550
r7335r7336
325140}
326141
327142
328
329143/*-------------------------------------------------
330    ui_mess_use_new_ui - determines if the "new ui"
331    is in use
144    ui_mess_main_menu_populate - populate MESS-specific menus
332145-------------------------------------------------*/
333146
334int ui_mess_use_new_ui(void)
335{
336#if (defined(WIN32) || defined(_MSC_VER)) && !defined(SDLMAME_WIN32)
337   if (options_get_bool(mame_options(), "newui"))
338      return TRUE;
339#endif
340   return FALSE;
341}
342
343
344
345/*-------------------------------------------------
346    ui_mess_paste - does a paste from the keyboard
347-------------------------------------------------*/
348
349void ui_mess_paste(running_machine *machine)
350{
351   /* retrieve the clipboard text */
352   char *text = osd_get_clipboard_text();
353
354   /* was a result returned? */
355   if (text != NULL)
356   {
357      /* post the text */
358      inputx_post_utf8(machine, text);
359
360      /* free the string */
361      free(text);
362   }
363}
364
365
366
367/*-------------------------------------------------
368    ui_mess_keyboard_disabled - returns whether
369    IPT_KEYBOARD input should be disabled
370-------------------------------------------------*/
371
372int ui_mess_keyboard_disabled(running_machine *machine)
373{
374   return ui_mess_get_use_natural_keyboard(machine);
375}
376
377
378
379/*-------------------------------------------------
380    ui_mess_get_use_natural_keyboard - returns
381    whether the natural keyboard is active
382-------------------------------------------------*/
383
384int ui_mess_get_use_natural_keyboard(running_machine *machine)
385{
386   return machine->ui_mess_data->use_natural_keyboard;
387}
388
389
390
391/*-------------------------------------------------
392    ui_mess_set_use_natural_keyboard - specifies
393    whether the natural keyboard is active
394-------------------------------------------------*/
395
396void ui_mess_set_use_natural_keyboard(running_machine *machine, int use_natural_keyboard)
397{
398   machine->ui_mess_data->use_natural_keyboard = use_natural_keyboard;
399}
400
401
402
403/*-------------------------------------------------
404    ui_mess_menu_keyboard_mode - menu that
405-------------------------------------------------*/
406
407void ui_mess_menu_keyboard_mode(running_machine *machine, ui_menu *menu, void *parameter, void *state)
408{
409   const ui_menu_event *event;
410   int natural = ui_mess_get_use_natural_keyboard(machine);
411
412   /* if the menu isn't built, populate now */
413   if (!ui_menu_populated(menu))
414   {
415      ui_menu_item_append(menu, "Keyboard Mode:", natural ? "Natural" : "Emulated", natural ? MENU_FLAG_LEFT_ARROW : MENU_FLAG_RIGHT_ARROW, NULL);
416   }
417
418   /* process the menu */
419   event = ui_menu_process(machine, menu, 0);
420
421   if (event != NULL)
422   {
423      if (event->iptkey == IPT_UI_LEFT || event->iptkey == IPT_UI_RIGHT) {
424         ui_mess_set_use_natural_keyboard(machine, natural ^ TRUE);
425         ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_REF);
426      }
427   }
428}
429
430
431
432/*-------------------------------------------------
433    ui_mess_menu_keyboard_mode - populate MESS-specific menus
434-------------------------------------------------*/
435
436147void ui_mess_main_menu_populate(running_machine *machine, ui_menu *menu)
437148{   
438   int has_keyboard = input_machine_have_keyboard(machine);
439
440149     /* add image info menu */
441150   ui_menu_item_append(menu, "Image Information", NULL, 0, (void*)ui_mess_menu_image_info);
442151
r7335r7336
446155     /* add tape control menu */
447156   if (machine->devicelist.first(CASSETTE))
448157      ui_menu_item_append(menu, "Tape Control", NULL, 0, (void*)ui_mess_menu_tape_control);
449
450     /* add keyboard mode menu */
451     if (has_keyboard && inputx_can_post(machine))
452      ui_menu_item_append(menu, "Keyboard Mode", NULL, 0, (void*)ui_mess_menu_keyboard_mode);
453158}
src/mess/messcore.mak
r7335r7336
7777   $(MESSOBJ)/mess.o      \
7878   $(MESSOBJ)/messopts.o   \
7979   $(MESSOBJ)/configms.o   \
80   $(MESSOBJ)/mesvalid.o   \
8180   $(MESSOBJ)/image.o      \
8281   $(MESSOBJ)/device.o      \
8382   $(MESSOBJ)/hashfile.o   \
84   $(MESSOBJ)/inputx.o      \
8583   $(MESSOBJ)/uimess.o      \
8684   $(MESSOBJ)/filemngr.o   \
8785   $(MESSOBJ)/tapectrl.o   \
8886   $(MESSOBJ)/utils.o      \
8987   $(MESSOBJ)/eventlst.o   \
90   $(MESSOBJ)/mslegacy.o   \
9188   $(MESSOBJ)/cheatms.o   \
9289   $(MESSOBJ)/opresolv.o   \
9390   $(MESSOBJ)/infomess.o   \
src/mess/uimess.h
r7335r7336
1212#include "ui.h"
1313#include "uimenu.h"
1414
15
1615/***************************************************************************
17    TYPE DEFINITIONS
18***************************************************************************/
19
20struct _ui_mess_private;
21typedef struct _ui_mess_private ui_mess_private;
22
23
24
25/***************************************************************************
2616    PROTOTYPES
2717***************************************************************************/
28
29/* initialize the MESS-specific UI */
30void ui_mess_init(running_machine *machine);
31
3218/* MESS-specific in-"game" UI */
33int ui_mess_handler_ingame(running_machine *machine);
19void ui_mess_handler_ingame(running_machine *machine);
3420
35/* returns whether the "new UI" is active or not */
36int ui_mess_use_new_ui(void);
37
3821/* image info screen */
3922void ui_mess_menu_image_info(running_machine *machine, ui_menu *menu, void *parameter, void *state);
4023
r7335r7336
4528void ui_mess_menu_tape_control(running_machine *machine, ui_menu *menu, void *parameter, void *state);
4629astring *tapecontrol_gettime(astring *dest, running_device *device, int *curpos, int *endpos);
4730
48/* paste */
49void ui_mess_paste(running_machine *machine);
50
51/* returns whether IPT_KEYBOARD input should be disabled */
52int ui_mess_keyboard_disabled(running_machine *machine);
53
54/* returns whether the natural keyboard is active */
55int ui_mess_get_use_natural_keyboard(running_machine *machine);
56
57/* specifies whether the natural keyboard is active */
58void ui_mess_set_use_natural_keyboard(running_machine *machine, int use_natural_keyboard);
59
60/* keyboard mode menu */
61void ui_mess_menu_keyboard_mode(running_machine *machine, ui_menu *menu, void *parameter, void *state);
62
6331/* populate MESS-specific menus */
6432void ui_mess_main_menu_populate(running_machine *machine, ui_menu *menu);
6533
src/mess/mess.h
r7335r7336
99#ifndef __MESS_H__
1010#define __MESS_H__
1111
12#include <stdarg.h>
13
14//#include "image.h"
15//#include "memory.h"
1612#include "configms.h"
1713#include "messopts.h"
1814
r7335r7336
2622
2723#define LCD_FRAMES_PER_SECOND   30
2824
29
3025/**************************************************************************/
3126
32/* Win32 defines this for vararg functions */
33#ifndef DECL_SPEC
34#define DECL_SPEC
35#endif
36
37
38/**************************************************************************/
39
4027/* mess specific layout files */
4128extern const char layout_lcd[];   /* generic 1:1 lcd screen layout */
4229extern const char layout_lcd_rot[];   /* same, for use with ROT90 or ROT270 */
r7335r7336
4633
4734extern const char mess_disclaimer[];
4835
49
50
5136/***************************************************************************/
5237
5338/* IODevice Initialisation return values.  Use these to determine if */
r7335r7336
5742#define IMAGE_VERIFY_PASS 0
5843#define IMAGE_VERIFY_FAIL 1
5944
60/* runs checks to see if device code is proper */
61int mess_validitychecks(void);
62
6345/* these are called from mame.c */
6446void mess_predevice_init(running_machine *machine);
6547void mess_postdevice_init(running_machine *machine);
src/mess/tapectrl.c
r7335r7336
1010#include "image.h"
1111#include "ui.h"
1212#include "uimenu.h"
13#include "mslegacy.h"
1413#include "devices/cassette.h"
1514
1615
r7335r7336
115114      state = cassette_get_state(menustate->device);
116115      ui_menu_item_append(
117116         menu,
118         ui_getstring((state & CASSETTE_MASK_UISTATE) == CASSETTE_STOPPED
119            ?   UI_stopped
117         (state & CASSETTE_MASK_UISTATE) == CASSETTE_STOPPED
118            ?   "stopped"
120119            :   ((state & CASSETTE_MASK_UISTATE) == CASSETTE_PLAY
121               ? ((state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_ENABLED ? UI_playing : UI_playing_inhibited)
122               : ((state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_ENABLED ? UI_recording : UI_recording_inhibited)
123               )),
120               ? ((state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_ENABLED ? "playing" : "(playing)")
121               : ((state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_ENABLED ? "recording" : "(recording)")
122               ),
124123         astring_c(&timepos),
125124         0,
126125         NULL);
127126
128127      /* pause or stop */
129      ui_menu_item_append(menu, ui_getstring(UI_pauseorstop), NULL, 0, TAPECMD_STOP);
128      ui_menu_item_append(menu, "Pause/Stop", NULL, 0, TAPECMD_STOP);
130129
131130      /* play */
132      ui_menu_item_append(menu, ui_getstring(UI_play), NULL, 0, TAPECMD_PLAY);
131      ui_menu_item_append(menu, "Play", NULL, 0, TAPECMD_PLAY);
133132
134133      /* record */
135      ui_menu_item_append(menu, ui_getstring(UI_record), NULL, 0, TAPECMD_RECORD);
134      ui_menu_item_append(menu, "Record", NULL, 0, TAPECMD_RECORD);
136135
137136      /* rewind */
138      ui_menu_item_append(menu, ui_getstring(UI_rewind), NULL, 0, TAPECMD_REWIND);
137      ui_menu_item_append(menu, "Rewind", NULL, 0, TAPECMD_REWIND);
139138
140139      /* fast forward */
141      ui_menu_item_append(menu, ui_getstring(UI_fastforward), NULL, 0, TAPECMD_FAST_FORWARD);
140      ui_menu_item_append(menu, "Fast Forward", NULL, 0, TAPECMD_FAST_FORWARD);
142141   }
143142   else
144143   {
145144      /* no tape loaded */
146      ui_menu_item_append(menu, ui_getstring(UI_notapeimageloaded), NULL, flags, NULL);
145      ui_menu_item_append(menu, "No Tape Image loaded", NULL, flags, NULL);
147146   }
148147}
149148
src/mess/tools/castool/main.c
r7335r7336
132132   const struct CassetteFormat * const *selected_formats = NULL;
133133   cassette_image *cassette;
134134   FILE *f;
135#ifdef WIN32
136   //win_expand_wildcards(&argc, &argv);
137#endif /* WIN32 */
138135
139136   if (argc > 1)
140137   {
src/mess/tools/messtest/main.c
r7335r7336
7979   clock_t begin_time;
8080   double elapsed_time;
8181   core_options *messtest_options = NULL;
82
83   /* test case for memory allocation system */
84#ifdef _WIN32
85   /* expand wildcards so '*' can be used */
86   win_expand_wildcards(&argc, &argv);
87#endif
88
82   
8983   test_count = 0;
9084   failure_count = 0;
9185   messtest_options = NULL;
src/mess/tools/messtest/testmess.c
r7335r7336
1313#include "emu.h"
1414#include "emuopts.h"
1515#include "testmess.h"
16#include "inputx.h"
1716#include "pile.h"
1817#include "pool.h"
1918#include "sound/wavwrite.h"
src/mess/tools/messtest/core.c
r7335r7336
2222#include "osdepend.h"
2323#include "pool.h"
2424#include "pile.h"
25#include "inputx.h"
2625#include "unzip.h"
2726
2827#define EOLN (CRLF == 1 ? "\r" : (CRLF == 2 ? "\n" : (CRLF == 3 ? "\r\n" : NULL)))
src/mess/tools/imgtool/main.c
r7335r7336
929929      return -1;
930930#endif /* MAME_DEBUG */
931931
932#ifdef WIN32
933   win_expand_wildcards(&argc, &argv);
934#endif /* WIN32 */
935
936932   putchar('\n');
937933
938934   if (argc > 1)
src/mess/image.h
r7335r7336
1414#include "fileio.h"
1515#include "utils.h"
1616#include "opresolv.h"
17#include "osd/osdmess.h"
1817#include "softlist.h"
1918
2019
src/mess/messdrv.h
r7335r7336
99#ifndef __MESSDRV_H__
1010#define __MESSDRV_H__
1111
12#include <assert.h>
13#include "inputx.h"
14
1512/******************************************************************************
1613 * MESS' version of the GAME() macros of MAME
1714 * CONS is for consoles
src/mess/device.c
r7335r7336
1010
1111#include "emu.h"
1212#include "device.h"
13#include "mslegacy.h"
1413
1514typedef struct _mess_device_type_info mess_device_type_info;
1615struct _mess_device_type_info
src/mess/device.h
r7335r7336
99#ifndef DEVICE_H
1010#define DEVICE_H
1111
12// MAME headers
13#include "devintrf.h"
14
15// MESS headers
16#include "osdmess.h"
17#include "opresolv.h"
18#include "image.h"
19
20
2112/*************************************
2213 *
2314 *  Other
src/mess/osd/osdmess.h
r7335r7336
1/*********************************************************************
2
3    osdmess.h
4
5    OS dependent calls for MESS
6
7*********************************************************************/
8
9#ifndef __OSDMESS_H__
10#define __OSDMESS_H__
11
12#include "osdcore.h"
13#include "options.h"
14enum
15{
16   OSD_FOPEN_READ,
17   OSD_FOPEN_WRITE,
18   OSD_FOPEN_RW,
19   OSD_FOPEN_RW_CREATE
20};
21
22
23struct _mame_file;
24
25
26
27/***************************************************************************
28    FILE I/O INTERFACES
29***************************************************************************/
30
31/*-----------------------------------------------------------------------------
32    osd_copyfile: copies a file
33
34    Parameters:
35
36        destfile - path to destination
37
38        srcfile - path to source file
39
40    Return value:
41
42        a file_error describing any error that occurred while copying
43        the file, or FILERR_NONE if no error occurred
44-----------------------------------------------------------------------------*/
45file_error osd_copyfile(const char *destfile, const char *srcfile);
46
47
48/*-----------------------------------------------------------------------------
49    osd_get_temp_filename: given a filename, return a full path with that
50    filename but in a temporary directory
51
52    Parameters:
53
54        buffer - pointer to buffer
55
56        buffer_len - length of buffer
57
58        basename - basename of file to create
59
60    Return value:
61
62        a file_error describing any error that occurred while copying
63        the file, or FILERR_NONE if no error occurred
64-----------------------------------------------------------------------------*/
65file_error osd_get_temp_filename(char *buffer, size_t buffer_len, const char *basename);
66
67
68/***************************************************************************
69    DIRECTORY INTERFACES
70***************************************************************************/
71
72/*-----------------------------------------------------------------------------
73    osd_stat: return a directory entry for a path
74
75    Parameters:
76
77        path - path in question
78
79    Return value:
80
81        an allocated pointer to an osd_directory_entry representing
82        info on the path; even if the file does not exist
83
84-----------------------------------------------------------------------------*/
85osd_directory_entry *osd_stat(const char *path);
86
87
88/*-----------------------------------------------------------------------------
89    osd_mkdir: creates a directory
90
91    Parameters:
92
93        dir - path to directory to create
94
95    Return value:
96
97        a file_error describing any error that occurred while creating
98        the directory, or FILERR_NONE if no error occurred
99-----------------------------------------------------------------------------*/
100file_error osd_mkdir(const char *dir);
101
102
103/*-----------------------------------------------------------------------------
104    osd_rmdir: removes a directory
105
106    Parameters:
107
108        dir - path to directory to removes
109
110    Return value:
111
112        a file_error describing any error that occurred while deleting
113        the directory, or FILERR_NONE if no error occurred
114-----------------------------------------------------------------------------*/
115file_error osd_rmdir(const char *dir);
116
117
118/*-----------------------------------------------------------------------------
119    osd_getcurdir: retrieves the current working directory
120
121    Parameters:
122
123        buffer - place to store current working directory
124
125        buffer_len - length of buffer
126
127    Return value:
128
129        a file_error describing any error that occurred while deleting
130        the directory, or FILERR_NONE if no error occurred
131-----------------------------------------------------------------------------*/
132file_error osd_getcurdir(char *buffer, size_t buffer_len);
133
134
135/*-----------------------------------------------------------------------------
136    osd_setcurdir: sets the current working directory
137
138    Parameters:
139
140        dir - path to directory to which to change
141
142    Return value:
143
144        a file_error describing any error that occurred while deleting
145        the directory, or FILERR_NONE if no error occurred
146-----------------------------------------------------------------------------*/
147file_error osd_setcurdir(const char *dir);
148
149
150/***************************************************************************
151    PATH INTERFACES
152***************************************************************************/
153
154/*-----------------------------------------------------------------------------
155    osd_get_emulator_directory: returns the path containing the emulator
156
157    Parameters:
158
159        dir - space to output directory
160        dir_size - size of path
161
162-----------------------------------------------------------------------------*/
163
164void osd_get_emulator_directory(char *dir, size_t dir_size);
165
166/*-----------------------------------------------------------------------------
167    osd_is_path_separator: returns whether a character is a path separator
168
169    Parameters:
170
171        c - the character in question
172
173    Return value:
174
175        non-zero if the character is a path separator, zero otherwise
176
177-----------------------------------------------------------------------------*/
178int osd_is_path_separator(char c);
179
180
181/*-----------------------------------------------------------------------------
182    osd_dirname: returns the base directory of a file path
183
184    Parameters:
185
186        filename - the path in question
187
188    Return value:
189
190        an allocated path to the directory containing this file
191
192-----------------------------------------------------------------------------*/
193char *osd_dirname(const char *filename);
194
195
196/*-----------------------------------------------------------------------------
197    osd_basename: returns the file or directory name from a full path
198
199    Parameters:
200
201        filename - the path in question
202
203    Return value:
204
205        a pointer to the base name of the file
206
207-----------------------------------------------------------------------------*/
208char *osd_basename(char *filename);
209
210
211/*-----------------------------------------------------------------------------
212    osd_get_full_path: retrieves the full path
213
214    Parameters:
215
216        path - the path in question
217        dst - pointer to receive new path; the returned string needs to be free()-ed!
218
219    Return value:
220
221        file error
222
223-----------------------------------------------------------------------------*/
224file_error osd_get_full_path(char **dst, const char *path);
225
226
227
228/***************************************************************************
229    UNCATEGORIZED INTERFACES
230***************************************************************************/
231
232
233/* reads text from the clipboard - the returned string needs to be free()-ed! */
234char *osd_get_clipboard_text(void);
235
236
237
238/******************************************************************************
239
240  Device and file browsing
241
242******************************************************************************/
243
244int osd_num_devices(void);
245const char *osd_get_device_name(int idx);
246
247void osd_mess_options_init(core_options *opts);
248
249#endif /* __OSDMESS_H__ */
src/mess/osd/sdl/sdlutil.c
r7335r7336
1//============================================================
2//
3//  sdlutil.c - SDLMESS utilities that can't be in COREOBJS
4//
5//============================================================
6
7// MESS headers
8#include "emu.h"
9//#include "windows/config.h"
10#include "menu.h"
11#include "configms.h"
12#include "pool.h"
13#include "config.h"
14
15//============================================================
16//  GLOBAL VARIABLES
17//============================================================
18
19//============================================================
20//  LOCAL VARIABLES
21//============================================================
22
23//============================================================
24//  osd_keyboard_disabled
25//============================================================
26
27int osd_keyboard_disabled(void)
28{
29   return 0;
30}
31
32
src/mess/osd/sdl/glob.c
r7335r7336
1/*
2 * Copyright (c) 1989, 1993
3 *  The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Guido van Rossum.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *  This product includes software developed by the University of
19 *  California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 *    may be used to endorse or promote products derived from this software
22 *    without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char sccsid[] = "@(#)glob.c   8.3 (Berkeley) 10/13/93";
39#endif /* LIBC_SCCS and not lint */
40
41/*
42 * glob(3) -- a superset of the one defined in POSIX 1003.2.
43 *
44 * The [!...] convention to negate a range is supported (SysV, Posix, ksh).
45 *
46 * Optional extra services, controlled by flags not defined by POSIX:
47 *
48 * GLOB_QUOTE:
49 *  Escaping convention: \ inhibits any special meaning the following
50 *  character might have (except \ at end of string is retained).
51 * GLOB_MAGCHAR:
52 *  Set in gl_flags if pattern contained a globbing character.
53 * GLOB_NOMAGIC:
54 *  Same as GLOB_NOCHECK, but it will only append pattern if it did
55 *  not contain any magic characters.  [Used in csh style globbing]
56 * GLOB_ALTDIRFUNC:
57 *  Use alternately specified directory access functions.
58 * GLOB_TILDE:
59 *  expand ~user/foo to the /home/dir/of/user/foo
60 * GLOB_BRACE:
61 *  expand {1,2}{a,b} to 1a 1b 2a 2b
62 * gl_matchc:
63 *  Number of matches in the current invocation of glob.
64 */
65
66#ifdef WIN32
67#ifdef _MSC_VER
68#define __STDC__   0
69#endif
70#else
71#include <sys/param.h>
72#endif
73#include <sys/stat.h>
74
75#include <ctype.h>
76
77#include "osdcore.h"
78#include "osdmess.h"
79
80#include <errno.h>
81#include "glob.h"
82#include <stdio.h>
83#include <stdlib.h>
84#include <string.h>
85
86#define   DOLLAR      '$'
87#define   DOT      '.'
88#define   EOS      '\0'
89#define   LBRACKET   '['
90#define   NOT      '!'
91#define   QUESTION   '?'
92#define   QUOTE      '\\'
93#define   RANGE      '-'
94#define   RBRACKET   ']'
95#define   SEP      '/'
96#define   STAR      '*'
97#define   TILDE      '~'
98#define   UNDERSCORE   '_'
99#define   LBRACE      '{'
100#define   RBRACE      '}'
101#define   SLASH      '/'
102#define   COMMA      ','
103
104#ifdef WIN32
105#define S_ISLNK(s)   (0)
106#undef SEP
107#define SEP '\\'
108struct passwd
109{
110   char *pw_dir;
111};
112#define getlogin()   (NULL)
113#define getpwnam(h)   (NULL)
114#define getpwuid(h)   (NULL)
115#define getuid()   (0)
116#define lstat      stat
117typedef unsigned int u_int;
118typedef unsigned short u_short;
119typedef unsigned char u_char;
120#else
121#include <unistd.h>
122#include <pwd.h>
123#endif
124
125#ifndef DEBUG
126
127#define   M_QUOTE      0x8000
128#define   M_PROTECT   0x4000
129#define   M_MASK      0xffff
130#define   M_ASCII      0x00ff
131
132typedef u_short Char;
133
134#else
135
136#define   M_QUOTE      0x80
137#define   M_PROTECT   0x40
138#define   M_MASK      0xff
139#define   M_ASCII      0x7f
140
141typedef char Char;
142
143#endif
144
145
146#define   CHAR(c)      ((Char)((c)&M_ASCII))
147#define   META(c)      ((Char)((c)|M_QUOTE))
148#define   M_ALL      META('*')
149#define   M_END      META(']')
150#define   M_NOT      META('!')
151#define   M_ONE      META('?')
152#define   M_RNG      META('-')
153#define   M_SET      META('[')
154#define   ismeta(c)   (((c)&M_QUOTE) != 0)
155
156
157static int    compare __P((const void *, const void *));
158static void    g_Ctoc __P((const Char *, char *));
159//static int     g_lstat __P((Char *, struct stat *, glob_t *));
160static osd_directory   *g_opendir __P((Char *, glob_t *));
161static Char   *g_strchr __P((Char *, int));
162#ifdef notdef
163static Char   *g_strcat __P((Char *, const Char *));
164#endif
165//static int     g_stat __P((Char *, struct stat *, glob_t *));
166static int    glob0 __P((const Char *, glob_t *));
167static int    glob1 __P((Char *, glob_t *));
168static int    glob2 __P((Char *, Char *, Char *, glob_t *));
169static int    glob3 __P((Char *, Char *, Char *, Char *, glob_t *));
170static int    globextend __P((const Char *, glob_t *));
171static const Char *    globtilde __P((const Char *, Char *, size_t, glob_t *));
172static int    globexp1 __P((const Char *, glob_t *));
173static int    globexp2 __P((const Char *, const Char *, glob_t *, int *));
174static int    match __P((Char *, Char *, Char *));
175#ifdef DEBUG
176static void    qprintf __P((const char *, Char *));
177#endif
178
179int   glob (const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob)
180{
181   const u_char *patnext;
182   int c;
183   Char *bufnext, *bufend, patbuf[_MAX_PATH+1];
184
185   patnext = (u_char *) pattern;
186   if (!(flags & GLOB_APPEND)) {
187      pglob->gl_pathc = 0;
188      pglob->gl_pathv = NULL;
189      if (!(flags & GLOB_DOOFFS))
190         pglob->gl_offs = 0;
191   }
192   pglob->gl_flags = flags & ~GLOB_MAGCHAR;
193   pglob->gl_errfunc = errfunc;
194   pglob->gl_matchc = 0;
195
196   bufnext = patbuf;
197   bufend = bufnext + _MAX_PATH;
198   if (flags & GLOB_QUOTE) {
199      /* Protect the quoted characters. */
200      while (bufnext < bufend && (c = *patnext++) != EOS)
201         if (c == QUOTE) {
202            if ((c = *patnext++) == EOS) {
203               c = QUOTE;
204               --patnext;
205            }
206            *bufnext++ = c | M_PROTECT;
207         }
208         else
209            *bufnext++ = c;
210   }
211   else
212       while (bufnext < bufend && (c = *patnext++) != EOS)
213          *bufnext++ = c;
214   *bufnext = EOS;
215
216   if (flags & GLOB_BRACE)
217       return globexp1(patbuf, pglob);
218   else
219       return glob0(patbuf, pglob);
220}
221
222/*
223 * Expand recursively a glob {} pattern. When there is no more expansion
224 * invoke the standard globbing routine to glob the rest of the magic
225 * characters
226 */
227static int globexp1(const Char *pattern, glob_t *pglob)
228{
229   const Char* ptr = (const Char *) pattern;
230   int rv;
231
232   /* Protect a single {}, for find(1), like csh */
233   if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
234      return glob0(pattern, pglob);
235
236   while ((ptr = (Char *) g_strchr((Char *) ptr, LBRACE)) != NULL)
237      if (!globexp2(ptr, pattern, pglob, &rv))
238         return rv;
239
240   return glob0(pattern, pglob);
241}
242
243
244/*
245 * Recursive brace globbing helper. Tries to expand a single brace.
246 * If it succeeds then it invokes globexp1 with the new pattern.
247 * If it fails then it tries to glob the rest of the pattern and returns.
248 */
249static int globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv)
250{
251   int     i;
252   Char   *lm, *ls;
253   const Char *pe, *pm, *pl;
254   Char    patbuf[_MAX_PATH + 1];
255
256   /* copy part up to the brace */
257   for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
258      continue;
259   ls = lm;
260
261   /* Find the balanced brace */
262   for (i = 0, pe = ++ptr; *pe; pe++)
263      if (*pe == LBRACKET) {
264         /* Ignore everything between [] */
265         for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++)
266            continue;
267         if (*pe == EOS) {
268            /*
269                 * We could not find a matching RBRACKET.
270                 * Ignore and just look for RBRACE
271                 */
272            pe = pm;
273         }
274      }
275      else if (*pe == LBRACE)
276         i++;
277      else if (*pe == RBRACE) {
278         if (i == 0)
279            break;
280         i--;
281      }
282
283   /* Non matching braces; just glob the pattern */
284   if (i != 0 || *pe == EOS) {
285      *rv = glob0(patbuf, pglob);
286      return 0;
287   }
288
289   for (i = 0, pl = pm = ptr; pm <= pe; pm++)
290      switch (*pm) {
291      case LBRACKET:
292         /* Ignore everything between [] */
293         for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++)
294            continue;
295         if (*pm == EOS) {
296            /*
297                 * We could not find a matching RBRACKET.
298                 * Ignore and just look for RBRACE
299                 */
300            pm = pl;
301         }
302         break;
303
304      case LBRACE:
305         i++;
306         break;
307
308      case RBRACE:
309         if (i) {
310             i--;
311             break;
312         }
313         /* FALLTHROUGH */
314      case COMMA:
315         if (i && *pm == COMMA)
316            break;
317         else {
318            /* Append the current string */
319            for (lm = ls; (pl < pm); *lm++ = *pl++)
320               continue;
321            /*
322                 * Append the rest of the pattern after the
323                 * closing brace
324                 */
325            for (pl = pe + 1; (*lm++ = *pl++) != EOS;)
326               continue;
327
328            /* Expand the current pattern */
329#ifdef DEBUG
330            qprintf("globexp2:", patbuf);
331#endif
332            *rv = globexp1(patbuf, pglob);
333
334            /* move after the comma, to the next string */
335            pl = pm + 1;
336         }
337         break;
338
339      default:
340         break;
341      }
342   *rv = 0;
343   return 0;
344}
345
346
347
348/*
349 * expand tilde from the passwd file.
350 */
351static const Char *globtilde(const Char *pattern,Char *patbuf, size_t patbuf_len, glob_t *pglob)
352{
353   struct passwd *pwd;
354   char *h;
355   const Char *p;
356   Char *b, *eb;
357
358   if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
359      return pattern;
360
361   /*
362     * Copy up to the end of the string or /
363     */
364   eb = &patbuf[patbuf_len - 1];
365   for (p = pattern + 1, h = (char *) patbuf;
366       h < (char *)eb && *p && *p != SLASH; *h++ = *p++)
367      continue;
368
369   *h = EOS;
370
371   if (((char *) patbuf)[0] == EOS) {
372      /*
373         * handle a plain ~ or ~/ by expanding $HOME first (iff
374         * we're not running setuid or setgid) and then trying
375         * the password file
376         */
377      if (
378          (h = getenv("HOME")) == NULL) {
379         if (((h = getlogin()) != NULL &&
380              (pwd = getpwnam(h)) != NULL) ||
381             (pwd = getpwuid(getuid())) != NULL)
382            h = pwd->pw_dir;
383         else
384            return pattern;
385      }
386   }
387   else {
388      /*
389         * Expand a ~user
390         */
391      if ((pwd = getpwnam((char*) patbuf)) == NULL)
392         return pattern;
393      else
394         h = pwd->pw_dir;
395   }
396
397   /* Copy the home directory */
398   for (b = patbuf; b < eb && *h; *b++ = *h++)
399      continue;
400
401   /* Append the rest of the pattern */
402   while (b < eb && (*b++ = *p++) != EOS)
403      continue;
404   *b = EOS;
405
406   return patbuf;
407}
408
409
410/*
411 * The main glob() routine: compiles the pattern (optionally processing
412 * quotes), calls glob1() to do the real pattern matching, and finally
413 * sorts the list (unless unsorted operation is requested).  Returns 0
414 * if things went well, nonzero if errors occurred.  It is not an error
415 * to find no matches.
416 */
417static int glob0(const Char *pattern,glob_t *pglob)
418{
419   const Char *qpatnext;
420   int c, err, oldpathc;
421   Char *bufnext, patbuf[_MAX_PATH+1];
422
423   qpatnext = globtilde(pattern, patbuf, ARRAY_LENGTH(patbuf), pglob);
424   oldpathc = pglob->gl_pathc;
425   bufnext = patbuf;
426
427   /* We don't need to check for buffer overflow any more. */
428   while ((c = *qpatnext++) != EOS) {
429      switch (c) {
430      case LBRACKET:
431         c = *qpatnext;
432         if (c == NOT)
433            ++qpatnext;
434         if (*qpatnext == EOS ||
435             g_strchr((Char *) qpatnext+1, RBRACKET) == NULL) {
436            *bufnext++ = LBRACKET;
437            if (c == NOT)
438               --qpatnext;
439            break;
440         }
441         *bufnext++ = M_SET;
442         if (c == NOT)
443            *bufnext++ = M_NOT;
444         c = *qpatnext++;
445         do {
446            *bufnext++ = CHAR(c);
447            if (*qpatnext == RANGE &&
448                (c = qpatnext[1]) != RBRACKET) {
449               *bufnext++ = M_RNG;
450               *bufnext++ = CHAR(c);
451               qpatnext += 2;
452            }
453         } while ((c = *qpatnext++) != RBRACKET);
454         pglob->gl_flags |= GLOB_MAGCHAR;
455         *bufnext++ = M_END;
456         break;
457      case QUESTION:
458         pglob->gl_flags |= GLOB_MAGCHAR;
459         *bufnext++ = M_ONE;
460         break;
461      case STAR:
462         pglob->gl_flags |= GLOB_MAGCHAR;
463         /* collapse adjacent stars to one,
464             * to avoid exponential behavior
465             */
466         if (bufnext == patbuf || bufnext[-1] != M_ALL)
467             *bufnext++ = M_ALL;
468         break;
469      default:
470         *bufnext++ = CHAR(c);
471         break;
472      }
473   }
474   *bufnext = EOS;
475#ifdef DEBUG
476   qprintf("glob0:", patbuf);
477#endif
478
479   if ((err = glob1(patbuf, pglob)) != 0)
480      return(err);
481
482   /*
483     * If there was no match we are going to append the pattern
484     * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
485     * and the pattern did not contain any magic characters
486     * GLOB_NOMAGIC is there just for compatibility with csh.
487     */
488   if (pglob->gl_pathc == oldpathc &&
489       ((pglob->gl_flags & GLOB_NOCHECK) ||
490         ((pglob->gl_flags & GLOB_NOMAGIC) &&
491          !(pglob->gl_flags & GLOB_MAGCHAR))))
492      return(globextend(pattern, pglob));
493   else if (!(pglob->gl_flags & GLOB_NOSORT))
494      qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
495          pglob->gl_pathc - oldpathc, sizeof(char *), compare);
496   return(0);
497}
498
499static int compare(const void *p, const void *q)
500{
501   return(strcmp(*(char **)p, *(char **)q));
502}
503
504static int glob1(Char *pattern,glob_t *pglob)
505{
506   Char pathbuf[_MAX_PATH+1];
507
508   /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
509   if (*pattern == EOS)
510      return(0);
511   return(glob2(pathbuf, pathbuf, pattern, pglob));
512}
513
514/*
515 * The functions glob2 and glob3 are mutually recursive; there is one level
516 * of recursion for each segment in the pattern that contains one or more
517 * meta characters.
518 */
519static int glob2(Char *pathbuf, Char *pathend, Char *pattern,glob_t *pglob)
520{
521   Char *p, *q;
522   int anymeta;
523   osd_directory_entry *entry = NULL;
524   osd_directory_entry *entry2 = NULL;
525   char buf[_MAX_PATH];
526
527   /*
528     * Loop over pattern segments until end of pattern or until
529     * segment with meta character found.
530     */
531   for (anymeta = 0;;) {
532      if (*pattern == EOS) {      /* End of pattern? */
533         *pathend = EOS;
534         g_Ctoc(pathbuf, buf);
535         entry = osd_stat(buf);
536         if (!entry)
537            return(0);
538
539         if ((((pglob->gl_flags & GLOB_MARK) &&
540             pathend[-1] != SEP) && (entry->type == ENTTYPE_DIR))
541             || ((S_ISLNK(sb.st_mode) &&
542             ((entry2 = osd_stat(buf)) != NULL) &&
543             (entry2->type == ENTTYPE_DIR)))) {
544            *pathend++ = SEP;
545            *pathend = EOS;
546         }
547         free(entry);
548         if (entry2)
549            free(entry2);
550         ++pglob->gl_matchc;
551         return(globextend(pathbuf, pglob));
552      }
553
554      /* Find end of next segment, copy tentatively to pathend. */
555      q = pathend;
556      p = pattern;
557      while (*p != EOS && *p != SEP) {
558         if (ismeta(*p))
559            anymeta = 1;
560         *q++ = *p++;
561      }
562
563      if (!anymeta) {      /* No expansion, do next segment. */
564         pathend = q;
565         pattern = p;
566         while (*pattern == SEP)
567            *pathend++ = *pattern++;
568      } else         /* Need expansion, recurse. */
569         return(glob3(pathbuf, pathend, pattern, p, pglob));
570   }
571   /* NOTREACHED */
572}
573
574static int glob3(Char *pathbuf,Char *pathend,Char *pattern,Char *restpattern,glob_t *pglob)   
575{
576   register const osd_directory_entry *dp;
577   osd_directory *dirp;
578   int err;
579   char buf[_MAX_PATH];
580
581   /*
582     * The readdirfunc declaration can't be prototyped, because it is
583     * assigned, below, to two functions which are prototyped in glob.h
584     * and dirent.h as taking pointers to differently typed opaque
585     * structures.
586     */
587   typedef const osd_directory_entry *(*readdirfunc_t)(osd_directory *);
588   readdirfunc_t readdirfunc;
589
590   *pathend = EOS;
591   errno = 0;
592
593   if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
594      /* TODO: don't call for ENOENT or ENOTDIR? */
595      if (pglob->gl_errfunc) {
596         g_Ctoc(pathbuf, buf);
597         if (pglob->gl_errfunc(buf, errno) ||
598             pglob->gl_flags & GLOB_ERR)
599            return (GLOB_ABEND);
600      }
601      return(0);
602   }
603
604   err = 0;
605
606   /* Search directory for matching names. */
607   if (pglob->gl_flags & GLOB_ALTDIRFUNC)
608      readdirfunc = (readdirfunc_t) pglob->gl_readdir;
609   else
610      readdirfunc = osd_readdir;
611   while ((dp = (*readdirfunc)(dirp))) {
612      register u_char *sc;
613      register Char *dc;
614
615      /* Initial DOT must be matched literally. */
616      if (dp->name[0] == DOT && *pattern != DOT)
617         continue;
618      for (sc = (u_char *) dp->name, dc = pathend;
619           (*dc++ = *sc++) != EOS;)
620         continue;
621      if (!match(pathend, pattern, restpattern)) {
622         *pathend = EOS;
623         continue;
624      }
625      err = glob2(pathbuf, --dc, restpattern, pglob);
626      if (err)
627         break;
628   }
629
630   if (pglob->gl_flags & GLOB_ALTDIRFUNC)
631      (*pglob->gl_closedir)(dirp);
632   else
633      osd_closedir(dirp);
634   return(err);
635}
636
637
638/*
639 * Extend the gl_pathv member of a glob_t structure to accomodate a new item,
640 * add the new item, and update gl_pathc.
641 *
642 * This assumes the BSD realloc, which only copies the block when its size
643 * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
644 * behavior.
645 *
646 * Return 0 if new item added, error code if memory couldn't be allocated.
647 *
648 * Invariant of the glob_t structure:
649 *  Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
650 *  gl_pathv points to (gl_offs + gl_pathc + 1) items.
651 */
652static int globextend(const Char *path, glob_t *pglob)
653{
654   register char **pathv;
655   register int i;
656   u_int newsize;
657   char *copy;
658   const Char *p;
659
660   newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
661   pathv = pglob->gl_pathv ?
662          (char **)realloc(pglob->gl_pathv, newsize) :
663          (char **)malloc(newsize);
664   if (pathv == NULL)
665      return(GLOB_NOSPACE);
666
667   if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
668      /* first time around -- clear initial gl_offs items */
669      pathv += pglob->gl_offs;
670      for (i = pglob->gl_offs; --i >= 0; )
671         *--pathv = NULL;
672   }
673   pglob->gl_pathv = pathv;
674
675   for (p = path; *p++;)
676      continue;
677   if ((copy = (char *)malloc(p - path)) != NULL) {
678      g_Ctoc(path, copy);
679      pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
680   }
681   pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
682   return(copy == NULL ? GLOB_NOSPACE : 0);
683}
684
685/*
686 * pattern matching function for filenames.  Each occurrence of the *
687 * pattern causes a recursion level.
688 */
689static int match(register Char *name, register Char *pat, register Char *patend)
690{
691   int ok, negate_range;
692   Char c, k;
693
694   while (pat < patend) {
695      c = *pat++;
696      switch (c & M_MASK) {
697      case M_ALL:
698         if (pat == patend)
699            return(1);
700         do
701             if (match(name, pat, patend))
702                return(1);
703         while (*name++ != EOS);
704         return(0);
705      case M_ONE:
706         if (*name++ == EOS)
707            return(0);
708         break;
709      case M_SET:
710         ok = 0;
711         if ((k = *name++) == EOS)
712            return(0);
713         if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
714            ++pat;
715         while (((c = *pat++) & M_MASK) != M_END)
716            if ((*pat & M_MASK) == M_RNG) {
717               if (CHAR(c) <= CHAR(k) && CHAR(k) <= CHAR(pat[1]))
718                  ok = 1;
719               pat += 2;
720            } else if (c == k)
721               ok = 1;
722         if (ok == negate_range)
723            return(0);
724         break;
725      default:
726         if (*name++ != c)
727            return(0);
728         break;
729      }
730   }
731   return(*name == EOS);
732}
733
734/* Free allocated data belonging to a glob_t structure. */
735void globfree(glob_t *pglob)
736{
737   register int i;
738   register char **pp;
739
740   if (pglob->gl_pathv != NULL) {
741      pp = pglob->gl_pathv + pglob->gl_offs;
742      for (i = pglob->gl_pathc; i--; ++pp)
743         if (*pp)
744            free(*pp);
745      free(pglob->gl_pathv);
746   }
747}
748
749static osd_directory *g_opendir(register Char *str,glob_t *pglob)   
750{
751   char buf[_MAX_PATH];
752
753   if (!*str)
754      strcpy(buf, ".");
755   else
756      g_Ctoc(str, buf);
757
758   if (pglob->gl_flags & GLOB_ALTDIRFUNC)
759      return((osd_directory *)(*pglob->gl_opendir)(buf));
760
761   return osd_opendir(buf);
762}
763
764static Char *g_strchr(Char *str,int ch)   
765{
766   do {
767      if (*str == ch)
768         return (str);
769   } while (*str++);
770   return (NULL);
771}
772
773#ifdef notdef
774static Char *
775g_strcat(dst, src)
776   Char *dst;
777   const Char* src;
778{
779   Char *sdst = dst;
780
781   while (*dst++)
782      continue;
783   --dst;
784   while((*dst++ = *src++) != EOS)
785       continue;
786
787   return (sdst);
788}
789#endif
790
791static void g_Ctoc(register const Char *str, char *buf)
792{
793   register char *dc;
794
795   for (dc = buf; (*dc++ = *str++) != EOS;)
796      continue;
797}
798
799#ifdef DEBUG
800static void
801qprintf(str, s)
802   const char *str;
803   register Char *s;
804{
805   register Char *p;
806
807   (void)printf("%s:\n", str);
808   for (p = s; *p; p++)
809      (void)printf("%c", CHAR(*p));
810   (void)printf("\n");
811   for (p = s; *p; p++)
812      (void)printf("%c", *p & M_PROTECT ? '"' : ' ');
813   (void)printf("\n");
814   for (p = s; *p; p++)
815      (void)printf("%c", ismeta(*p) ? '_' : ' ');
816   (void)printf("\n");
817}
818#endif
src/mess/osd/sdl/configms.c
r7335r7336
1//============================================================
2//
3//  configms.c - SDL MESS specific options
4//
5//============================================================
6
7// MESS headers
8#include "emu.h"
9//#include "windows/config.h"
10#include "menu.h"
11#include "configms.h"
12#include "pool.h"
13#include "config.h"
14
15//============================================================
16//  LOCAL VARIABLES
17//============================================================
18
19static const options_entry win_mess_opts[] =
20{
21   { NULL,                     NULL,   OPTION_HEADER,      "SDL MESS SPECIFIC OPTIONS" },
22   #if defined(__APPLE__) && defined(__MACH__)
23   { "uimodekey;umk",        "ITEM_ID_INSERT", 0,    "specifies the key used to toggle between full and partial UI mode" },
24   #else
25   { "uimodekey;umk",        "ITEM_ID_SCRLOCK", 0,    "specifies the key used to toggle between full and partial UI mode" },
26   #endif
27   { NULL }
28};
29
30extern char *osd_get_startup_cwd(void);
31
32//============================================================
33
34void osd_mess_options_init(core_options *opts)
35{
36   options_add_entries(opts, win_mess_opts);
37}
38
39void osd_get_emulator_directory(char *dir, size_t dir_size)
40{
41   strncpy(dir, osd_get_startup_cwd(), dir_size);
42}
43
src/mess/osd/sdl/glob.h
r7335r7336
1/*
2 * Copyright (c) 1991, 1993
3 *  The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Berkeley Software Design, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *  This product includes software developed by the University of
19 *  California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 *    may be used to endorse or promote products derived from this software
22 *    without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 *  @(#)cdefs.h 8.8 (Berkeley) 1/9/95
37 * $FreeBSD: src/sys/sys/cdefs.h,v 1.28.2.1 2000/03/18 23:30:03 jasone Exp $
38 */
39
40#ifndef _SYS_CDEFS_H   /* guard against newer GLIBC too */
41#define _SYS_CDEFS_H
42
43#ifndef   _SYS_CDEFS_H_
44#define   _SYS_CDEFS_H_
45
46#if defined(__cplusplus)
47#define   __BEGIN_DECLS   extern "C" {
48#define   __END_DECLS   }
49#else
50#define   __BEGIN_DECLS
51#define   __END_DECLS
52#endif
53
54/*
55 * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
56 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
57 * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
58 * mode -- there must be no spaces between its arguments, and for nested
59 * __CONCAT's, all the __CONCAT's must be at the left.  __CONCAT can also
60 * concatenate double-quoted strings produced by the __STRING macro, but
61 * this only works with ANSI C.
62 *
63 * __XSTRING is like __STRING, but it expands any macros in its argument
64 * first.  It is only available with ANSI C.
65 */
66#if defined(__STDC__) || defined(__cplusplus)
67#define   __P(protos)   protos      /* full-blown ANSI C */
68#define   __STRING(x)   #x      /* stringify without expanding x */
69#define   __XSTRING(x)   __STRING(x)   /* expand x, then stringify */
70
71#define   __const      const      /* define reserved names to standard */
72#define   __signed   signed
73#define   __volatile   volatile
74#if defined(__cplusplus)
75#define   __inline   inline      /* convert to C++ keyword */
76#else
77#ifndef __GNUC__
78#define   __inline         /* delete GCC keyword */
79#endif /* !__GNUC__ */
80#endif /* !__cplusplus */
81
82#else   /* !(__STDC__ || __cplusplus) */
83#define   __P(protos)   ()      /* traditional C preprocessor */
84#define   __STRING(x)   "x"
85
86#ifndef __GNUC__
87#define   __const            /* delete pseudo-ANSI C keywords */
88#define   __inline
89#define   __signed
90#define   __volatile
91/*
92 * In non-ANSI C environments, new programs will want ANSI-only C keywords
93 * deleted from the program and old programs will want them left alone.
94 * When using a compiler other than gcc, programs using the ANSI C keywords
95 * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
96 * When using "gcc -traditional", we assume that this is the intent; if
97 * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
98 */
99#ifndef   NO_ANSI_KEYWORDS
100#define   const            /* delete ANSI C keywords */
101#ifndef inline
102#define   inline
103#endif
104#define   signed
105#define   volatile
106#endif   /* !NO_ANSI_KEYWORDS */
107#endif   /* !__GNUC__ */
108#endif   /* !(__STDC__ || __cplusplus) */
109
110/*
111 * Compiler-dependent macros to help declare dead (non-returning) and
112 * pure (no side effects) functions, and unused variables.  They are
113 * null except for versions of gcc that are known to support the features
114 * properly (old versions of gcc-2 supported the dead and pure features
115 * in a different (wrong) way).
116 */
117#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 5
118#define __dead2
119#define __pure2
120#define __unused
121#endif
122#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7
123#define __dead2      __attribute__((__noreturn__))
124#define __pure2      __attribute__((__const__))
125#define __unused
126#endif
127#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7
128#define __dead2      __attribute__((__noreturn__))
129#define __pure2      __attribute__((__const__))
130#define __unused   __attribute__((__unused__))
131#endif
132
133/*
134 * Compiler-dependent macros to declare that functions take printf-like
135 * or scanf-like arguments.  They are null except for versions of gcc
136 * that are known to support the features properly (old versions of gcc-2
137 * didn't permit keeping the keywords out of the application namespace).
138 */
139#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 7
140#define   __printflike(fmtarg, firstvararg)
141#define   __scanflike(fmtarg, firstvararg)
142#else
143#define   __printflike(fmtarg, firstvararg) \
144       __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
145#define   __scanflike(fmtarg, firstvararg) \
146       __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
147#endif
148
149/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
150#define __FreeBSD_cc_version 0
151#if __FreeBSD_cc_version >= 300001
152#define   __printf0like(fmtarg, firstvararg) \
153       __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
154#else
155#define   __printf0like(fmtarg, firstvararg)
156#endif
157
158#ifdef __GNUC__
159#define __strong_reference(sym,aliassym)   \
160   extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)));
161#ifdef __ELF__
162#ifdef __STDC__
163#define   __weak_reference(sym,alias)   \
164   __asm__(".weak " #alias);   \
165   __asm__(".equ "  #alias ", " #sym)
166#define   __warn_references(sym,msg)   \
167   __asm__(".section .gnu.warning." #sym);   \
168   __asm__(".asciz \"" msg "\"");   \
169   __asm__(".previous")
170#else
171#define   __weak_reference(sym,alias)   \
172   __asm__(".weak alias");      \
173   __asm__(".equ alias, sym")
174#define   __warn_references(sym,msg)   \
175   __asm__(".section .gnu.warning.sym"); \
176   __asm__(".asciz \"msg\"");   \
177   __asm__(".previous")
178#endif   /* __STDC__ */
179#else   /* !__ELF__ */
180#ifdef __STDC__
181#define __weak_reference(sym,alias)   \
182   __asm__(".stabs \"_" #alias "\",11,0,0,0");   \
183   __asm__(".stabs \"_" #sym "\",1,0,0,0")
184#define __warn_references(sym,msg)   \
185   __asm__(".stabs \"" msg "\",30,0,0,0");      \
186   __asm__(".stabs \"_" #sym "\",1,0,0,0")
187#else
188#define __weak_reference(sym,alias)   \
189   __asm__(".stabs \"_/**/alias\",11,0,0,0");   \
190   __asm__(".stabs \"_/**/sym\",1,0,0,0")
191#define __warn_references(sym,msg)   \
192   __asm__(".stabs msg,30,0,0,0");         \
193   __asm__(".stabs \"_/**/sym\",1,0,0,0")
194#endif   /* __STDC__ */
195#endif   /* __ELF__ */
196#endif   /* __GNUC__ */
197
198#if defined(__GNUC__) && defined(__ELF__)
199#define   __IDSTRING(name,string)   __asm__(".ident\t\"" string "\"")
200#else
201#define   __IDSTRING(name,string)   static const char name[] __unused = string
202#endif
203
204#ifndef   __RCSID
205#define   __RCSID(s)   __IDSTRING(rcsid,s)
206#endif
207
208#ifndef   __RCSID_SOURCE
209#define   __RCSID_SOURCE(s) __IDSTRING(rcsid_source,s)
210#endif
211
212#ifndef   __COPYRIGHT
213#define   __COPYRIGHT(s)   __IDSTRING(copyright,s)
214#endif
215
216#endif /* !_SYS_CDEFS_H_ */
217#endif /* ~_SYS_CDEFS_H */
218
219/*
220 * Copyright (c) 1989, 1993
221 *  The Regents of the University of California.  All rights reserved.
222 *
223 * This code is derived from software contributed to Berkeley by
224 * Guido van Rossum.
225 *
226 * Redistribution and use in source and binary forms, with or without
227 * modification, are permitted provided that the following conditions
228 * are met:
229 * 1. Redistributions of source code must retain the above copyright
230 *    notice, this list of conditions and the following disclaimer.
231 * 2. Redistributions in binary form must reproduce the above copyright
232 *    notice, this list of conditions and the following disclaimer in the
233 *    documentation and/or other materials provided with the distribution.
234 * 3. All advertising materials mentioning features or use of this software
235 *    must display the following acknowledgement:
236 *  This product includes software developed by the University of
237 *  California, Berkeley and its contributors.
238 * 4. Neither the name of the University nor the names of its contributors
239 *    may be used to endorse or promote products derived from this software
240 *    without specific prior written permission.
241 *
242 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
243 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
244 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
245 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
246 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
247 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
248 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
249 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
250 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
251 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
252 * SUCH DAMAGE.
253 *
254 *  @(#)glob.h  8.1 (Berkeley) 6/2/93
255 */
256
257#ifndef _GLOB_H_
258#define   _GLOB_H_
259
260//BEOS: sys/cdefs.h included above
261
262struct stat;
263typedef struct {
264   int gl_pathc;      /* Count of total paths so far. */
265   int gl_matchc;      /* Count of paths matching pattern. */
266   int gl_offs;      /* Reserved at beginning of gl_pathv. */
267   int gl_flags;      /* Copy of flags parameter to glob. */
268   char **gl_pathv;   /* List of paths matching pattern. */
269            /* Copy of errfunc parameter to glob. */
270   int (*gl_errfunc) __P((const char *, int));
271
272   /*
273     * Alternate filesystem access methods for glob; replacement
274     * versions of closedir(3), readdir(3), opendir(3), stat(2)
275     * and lstat(2).
276     */
277   void (*gl_closedir) __P((void *));
278   struct dirent *(*gl_readdir) __P((void *));
279   void *(*gl_opendir) __P((const char *));
280   int (*gl_lstat) __P((const char *, struct stat *));
281   int (*gl_stat) __P((const char *, struct stat *));
282} glob_t;
283
284#define   GLOB_APPEND   0x0001   /* Append to output from previous call. */
285#define   GLOB_DOOFFS   0x0002   /* Use gl_offs. */
286#define   GLOB_ERR   0x0004   /* Return on error. */
287#define   GLOB_MARK   0x0008   /* Append / to matching directories. */
288#define   GLOB_NOCHECK   0x0010   /* Return pattern itself if nothing matches. */
289#define   GLOB_NOSORT   0x0020   /* Don't sort. */
290
291#define   GLOB_ALTDIRFUNC   0x0040   /* Use alternately specified directory funcs. */
292#define   GLOB_BRACE   0x0080   /* Expand braces ala csh. */
293#define   GLOB_MAGCHAR   0x0100   /* Pattern had globbing characters. */
294#define   GLOB_NOMAGIC   0x0200   /* GLOB_NOCHECK without magic chars (csh). */
295#define   GLOB_QUOTE   0x0400   /* Quote special chars with \. */
296#define   GLOB_TILDE   0x0800   /* Expand tilde names from the passwd file. */
297
298#define   GLOB_NOSPACE   (-1)   /* Malloc call failed. */
299#define   GLOB_ABEND   (-2)   /* Unignored error. */
300
301__BEGIN_DECLS
302int   glob __P((const char *, int, int (*)(const char *, int), glob_t *));
303void   globfree __P((glob_t *));
304__END_DECLS
305
306#endif /* !_GLOB_H_ */
307
src/mess/osd/sdl/menu.h
r7335r7336
1//============================================================
2//
3//  menu.h - SDLMESS menu handling
4//
5//============================================================
6
7#ifndef MENU_H
8#define MENU_H
9
10
11//============================================================
12//  GLOBAL VARIABLES
13//============================================================
14
15extern int win_use_natural_keyboard;
16
17
18
19//============================================================
20//  PROTOTYPES
21//============================================================
22
23
24
25#endif /* MENU_H */
26
src/mess/osd/sdl/configms.h
r7335r7336
1//============================================================
2//
3//  configms.h - Win32 MESS specific options
4//
5//============================================================
6
7#ifndef CONFIGMS_H
8#define CONFIGMS_H
9
10#include "options.h"
11
12extern int win_write_config;
13
14void osd_mess_config_init(running_machine *machine);
15void osd_mess_options_init(core_options *opts);
16
17// ugh hack
18const char *get_devicedirectory(int dev);
19void set_devicedirectory(int dev, const char *dir);
20
21#endif /* CONFIGMS_H */
22
src/mess/osd/sdl/sdlmess.c
r7335r7336
1#include <stdlib.h>
2#include <fcntl.h>
3#include <unistd.h>
4#include <ctype.h>
5#include <sys/stat.h>
6#include <sys/types.h>
7#include <ctype.h>
8#include <errno.h>
9
10#include "osdmess.h"
11#include "utils.h"
12
13#ifdef SDLMAME_WIN32
14#define WIN32_LEAN_AND_MEAN
15#include <windows.h>
16#include <tchar.h>
17#include "strconv.h"
18#endif
19
20#ifdef SDLMAME_MACOSX
21#include <Carbon/Carbon.h>
22#endif
23
24//============================================================
25//   osd_getcurdir
26//============================================================
27
28file_error osd_getcurdir(char *buffer, size_t buffer_len)
29{
30   file_error filerr = FILERR_NONE;
31
32   if (getcwd(buffer, buffer_len) == NULL)
33   {
34      filerr = FILERR_FAILURE;
35   }
36
37   if( filerr != FILERR_FAILURE )
38   {
39      if( strcmp( &buffer[strlen(buffer)-1], PATH_SEPARATOR ) != 0 )
40      {
41              strncat( buffer, PATH_SEPARATOR, buffer_len );
42      }
43   }
44
45   return filerr;
46}
47
48//============================================================
49//  osd_get_full_path
50//============================================================
51
52file_error osd_get_full_path(char **dst, const char *path)
53{
54   file_error err;
55   char path_buffer[512];
56
57   err = FILERR_NONE;
58
59   if (getcwd(path_buffer, 511) == NULL)
60   {
61      printf("osd_get_full_path: failed!\n");
62      err = FILERR_FAILURE;
63   }
64   else
65   {
66      *dst = (char *)malloc(strlen(path_buffer)+strlen(path)+3);
67
68      // if it's already a full path, just pass it through
69      if (path[0] == '/')
70      {
71         strcpy(*dst, path);
72      }
73      else
74      {
75         sprintf(*dst, "%s%s%s", path_buffer, PATH_SEPARATOR, path);
76      }
77   }
78
79   return err;
80}
81
82//============================================================
83//  osd_setcurdir
84//============================================================
85
86file_error osd_setcurdir(const char *dir)
87{
88   file_error filerr = FILERR_NONE;
89
90   if (chdir(dir) != 0)
91   {
92      filerr = FILERR_FAILURE;
93   }
94
95   return filerr;
96}
97
98//============================================================
99//  osd_basename
100//============================================================
101
102char *osd_basename(char *filename)
103{
104   char *c;
105
106   // NULL begets NULL
107   if (!filename)
108      return NULL;
109
110   // start at the end and return when we hit a slash or colon
111   for (c = filename + strlen(filename) - 1; c >= filename; c--)
112      if (*c == '\\' || *c == '/' || *c == ':')
113         return c + 1;
114
115   // otherwise, return the whole thing
116   return filename;
117}
118
119//============================================================
120//  osd_dirname
121//============================================================
122
123char *osd_dirname(const char *filename)
124{
125   char *dirname;
126   char *c;
127
128   // NULL begets NULL
129   if (!filename)
130      return NULL;
131
132   // allocate space for it
133   dirname = (char*)malloc(strlen(filename) + 1);
134   if (!dirname)
135      return NULL;
136
137   // copy in the name
138   strcpy(dirname, filename);
139
140   // search backward for a slash or a colon
141   for (c = dirname + strlen(dirname) - 1; c >= dirname; c--)
142      if (*c == '\\' || *c == '/' || *c == ':')
143      {
144         // found it: NULL terminate and return
145         *(c + 1) = 0;
146         return dirname;
147      }
148
149   // otherwise, return an empty string
150   dirname[0] = 0;
151   return dirname;
152}
153
154// no idea what these are for, just cheese them
155int osd_num_devices(void)
156{
157   return 1;
158}
159
160const char *osd_get_device_name(int idx)
161{
162   return "/";
163}
164
165//============================================================
166//  osd_get_temp_filename
167//============================================================
168
169file_error osd_get_temp_filename(char *buffer, size_t buffer_len, const char *basename)
170{
171   char tempbuf[512];
172
173   if (!basename)
174      basename = "tempfile";
175
176   sprintf(tempbuf, "/tmp/%s", basename);
177   unlink(tempbuf);
178
179   strncpy(buffer, tempbuf, buffer_len);
180
181   return FILERR_NONE;
182}
183
184//============================================================
185//  osd_mkdir
186//============================================================
187
188file_error osd_mkdir(const char *dir)
189{
190   file_error filerr = FILERR_NONE;
191
192   #ifdef SDLMAME_WIN32
193   if (mkdir(dir) != 0)
194   #else
195   if (mkdir(dir, 0700) != 0)
196   #endif
197   {
198      filerr = FILERR_FAILURE;
199   }
200
201   return filerr;
202}
203
204//============================================================
205//  osd_is_path_separator
206//============================================================
207
208int osd_is_path_separator(char c)
209{
210   return (c == '/') || (c == '\\');
211}
212
213
214//============================================================
215//  osd_rmdir
216//============================================================
217
218file_error osd_rmdir(const char *dir)
219{
220   file_error filerr = FILERR_NONE;
221
222   if (rmdir(dir) != 0)
223   {
224      filerr = FILERR_FAILURE;
225   }
226
227   return filerr;
228}
229
230#ifdef SDLMAME_MACOSX
231//============================================================
232//  osd_get_clipboard_text
233//============================================================
234
235char *osd_get_clipboard_text(void)
236{
237   char *result = NULL; /* core expects a malloced C string of uft8 data */
238
239   PasteboardRef pasteboard_ref;
240   OSStatus err;
241   PasteboardSyncFlags sync_flags;
242   PasteboardItemID item_id;
243   CFIndex flavor_count;
244   CFArrayRef flavor_type_array;
245   CFIndex flavor_index;
246   ItemCount item_count;
247   UInt32 item_index;
248   Boolean   success = false;
249
250   err = PasteboardCreate(kPasteboardClipboard, &pasteboard_ref);
251
252   if (!err)
253   {
254      sync_flags = PasteboardSynchronize( pasteboard_ref );
255
256      err = PasteboardGetItemCount(pasteboard_ref, &item_count );
257
258      for (item_index=1; item_index<=item_count; item_index++)
259      {
260         err = PasteboardGetItemIdentifier(pasteboard_ref, item_index, &item_id);
261
262         if (!err)
263         {
264            err = PasteboardCopyItemFlavors(pasteboard_ref, item_id, &flavor_type_array);
265
266            if (!err)
267            {
268               flavor_count = CFArrayGetCount(flavor_type_array);
269
270               for (flavor_index = 0; flavor_index < flavor_count; flavor_index++)
271               {
272                  CFStringRef flavor_type;
273                  CFDataRef flavor_data;
274                  CFStringEncoding encoding;
275                  CFStringRef string_ref;
276                  CFDataRef data_ref;
277                  CFIndex length;
278                  CFRange range;
279
280                  flavor_type = (CFStringRef)CFArrayGetValueAtIndex(flavor_type_array, flavor_index);
281
282                  if (UTTypeConformsTo (flavor_type, kUTTypeUTF16PlainText))
283                     encoding = kCFStringEncodingUTF16;
284                  else if (UTTypeConformsTo (flavor_type, kUTTypeUTF8PlainText))
285                     encoding = kCFStringEncodingUTF8;
286                  else if (UTTypeConformsTo (flavor_type, kUTTypePlainText))
287                     encoding = kCFStringEncodingMacRoman;
288                  else
289                     continue;
290
291                  err = PasteboardCopyItemFlavorData(pasteboard_ref, item_id, flavor_type, &flavor_data);
292
293                  if( !err )
294                  {
295                     string_ref = CFStringCreateFromExternalRepresentation (kCFAllocatorDefault, flavor_data, encoding);
296                     data_ref = CFStringCreateExternalRepresentation (kCFAllocatorDefault, string_ref, kCFStringEncodingUTF8, '?');
297
298                     length = CFDataGetLength (data_ref);
299                     range = CFRangeMake (0,length);
300
301                     result = (char *)malloc (length+1);
302                     if (result != NULL)
303                     {
304                        CFDataGetBytes (data_ref, range, (unsigned char *)result);
305                        result[length] = 0;
306                        success = true;
307                        break;
308                     }
309
310                     CFRelease(data_ref);
311                     CFRelease(string_ref);
312                     CFRelease(flavor_data);
313                  }
314               }
315
316               CFRelease(flavor_type_array);
317            }
318         }
319
320         if (success)
321            break;
322      }
323
324      CFRelease(pasteboard_ref);
325   }
326
327   return result;
328}
329#endif
330
331#ifdef SDLMAME_WIN32
332//============================================================
333//  get_clipboard_text_by_format
334//============================================================
335
336static char *get_clipboard_text_by_format(UINT format, char *(*convert)(LPCVOID data))
337{
338   char *result = NULL;
339   HANDLE data_handle;
340   LPVOID data;
341
342   // check to see if this format is available
343   if (IsClipboardFormatAvailable(format))
344   {
345      // open the clipboard
346      if (OpenClipboard(NULL))
347      {
348         // try to access clipboard data
349         data_handle = GetClipboardData(format);
350         if (data_handle != NULL)
351         {
352            // lock the data
353            data = GlobalLock(data_handle);
354            if (data != NULL)
355            {
356               // invoke the convert
357               result = (*convert)(data);
358
359               // unlock the data
360               GlobalUnlock(data_handle);
361            }
362         }
363
364         // close out the clipboard
365         CloseClipboard();
366      }
367   }
368   return result;
369}
370
371
372
373//============================================================
374//  convert_wide
375//============================================================
376
377static char *convert_wide(LPCVOID data)
378{
379   return utf8_from_wstring((LPCWSTR) data);
380}
381
382
383
384//============================================================
385//  convert_ansi
386//============================================================
387
388static char *convert_ansi(LPCVOID data)
389{
390   return utf8_from_astring((LPCSTR) data);
391}
392
393
394
395//============================================================
396//  osd_get_clipboard_text
397//============================================================
398
399char *osd_get_clipboard_text(void)
400{
401   char *result = NULL;
402
403   // try to access unicode text
404   if (result == NULL)
405      result = get_clipboard_text_by_format(CF_UNICODETEXT, convert_wide);
406
407   // try to access ANSI text
408   if (result == NULL)
409      result = get_clipboard_text_by_format(CF_TEXT, convert_ansi);
410
411   return result;
412}
413#endif
414
415#if defined(SDL_VIDEO_DRIVER_X11)
416//============================================================
417//  osd_get_clipboard_text
418//============================================================
419
420char *osd_get_clipboard_text(void)
421{
422   SDL_SysWMinfo info;
423   Display* display;
424   Window our_win;
425   Window selection_win;
426   Atom data_type;
427   int data_format;
428   unsigned long nitems;
429   unsigned long bytes_remaining;
430   unsigned char* prop;
431   char* result;
432   XEvent event;
433   Uint32 t0, t1;
434   Atom types[2];
435   int i;
436
437   /* get & validate SDL sys-wm info */
438   SDL_VERSION(&info.version);
439   if ( ! SDL_GetWMInfo( &info ) )
440      return NULL;
441   if ( info.subsystem != SDL_SYSWM_X11 )
442      return NULL;
443   if ( (display = info.info.x11.display) == NULL )
444      return NULL;
445   if ( (our_win = info.info.x11.window) == None )
446      return NULL;
447
448   /* request data to owner */
449   selection_win = XGetSelectionOwner( display, XA_PRIMARY );
450   if ( selection_win == None )
451      return NULL;
452
453   /* first, try UTF-8, then latin-1 */
454   types[0] = XInternAtom( display, "UTF8_STRING", False );
455   types[1] = XA_STRING; /* latin-1 */
456
457   for ( i = 0; i < ARRAY_LENGTH(types); i++ )
458   {
459
460      XConvertSelection( display, XA_PRIMARY, types[i], types[i], our_win, CurrentTime );
461
462      /* wait for SelectionNotify, but no more than 100 ms */
463      t0 = t1 = SDL_GetTicks();
464      while ( 1 )
465      {
466         if (  XCheckTypedWindowEvent( display, our_win,  SelectionNotify, &event ) ) break;
467         SDL_Delay( 1 );
468         t1 = SDL_GetTicks();
469         if ( t1 - t0 > 100 )
470            return NULL;
471      }
472      if ( event.xselection.property == None )
473         continue;
474
475      /* get property & check its type */
476      if ( XGetWindowProperty( display, our_win, types[i], 0, 65536, False, types[i],
477                &data_type, &data_format, &nitems, &bytes_remaining, &prop )
478           != Success )
479         continue;
480      if ( ! prop )
481         continue;
482      if ( (data_format != 8) || (data_type != types[i]) )
483      {
484         XFree( prop );
485         continue;
486      }
487
488      /* return a copy & free original */
489      result = core_strdup( (char*) prop );
490      XFree( prop );
491      return result;
492   }
493
494   return NULL;
495}
496
497#endif
498
499#if defined(SDLMAME_UNIX) && !defined(SDLMAME_MACOSX) && !defined(SDL_VIDEO_DRIVER_X11)
500//============================================================
501//  osd_get_clipboard_text
502//============================================================
503
504char *osd_get_clipboard_text(void)
505{
506   char *result = NULL;
507
508   return result;
509}
510#endif
src/mess/osd/sdl/osdutils.h
r7335r7336
1#ifndef PATH_SEPARATOR
2#define PATH_SEPARATOR   '/'
3#endif
4
5#define EOLN "\n"
src/mess/osd/sdl/winutils.c
r7335r7336
1818// MESS headers
1919#include "winutils.h"
2020#include "strconv.h"
21#include "glob.h"
2221
2322//============================================================
2423//  win_get_file_attributes_utf8
r7335r7336
3736   }
3837   return result;
3938}
40
41void win_expand_wildcards(int *argc, char **argv[])
42{
43   int i;
44   glob_t g;
45
46   memset(&g, 0, sizeof(g));
47
48   for (i = 0; i < *argc; i++)
49      glob((*argv)[i], (g.gl_pathc > 0) ? GLOB_APPEND|GLOB_NOCHECK : GLOB_NOCHECK, NULL, &g);
50
51   *argc = g.gl_pathc;
52   *argv = g.gl_pathv;
53}
src/mess/osd/sdl/winutils.h
r7335r7336
1616
1717DWORD win_get_file_attributes_utf8(const char *filename);
1818
19/* expand wildcards so '*' can be used */
20void win_expand_wildcards(int *argc, char **argv[]);
21
2219#endif // WINUTILS_H
src/mess/osd/sdl/sdl.mak
r7335r7336
1313
1414#OSDOBJS += \
1515
16OSDCOREOBJS += \
17   $(MESS_SDLOBJ)/sdlutil.o   \
18   $(MESS_SDLOBJ)/configms.o   \
19   $(MESS_SDLOBJ)/sdlmess.o   
20
2116$(LIBOSD): $(OSDOBJS)
2217
2318ifeq ($(TARGETOS),win32)
2419OSDCOREOBJS += \
25   $(MESS_SDLOBJ)/glob.o   \
2620   $(MESS_SDLOBJ)/winutils.o \
2721   $(MESS_SDLOBJ)/w32util.o
2822endif
src/mess/osd/windows/configms.c
r7335r7336
1//============================================================
2//
3//  configms.c - Win32 MESS specific options
4//
5//============================================================
6
7// standard windows headers
8#define WIN32_LEAN_AND_MEAN
9#include <windows.h>
10#include <ctype.h>
11
12// MESS headers
13#include "emu.h"
14#include "winmain.h"
15#include "menu.h"
16#include "configms.h"
17#include "pool.h"
18#include "config.h"
19#include "winutf8.h"
20
21
22//============================================================
23//  GLOBAL VARIABLES
24//============================================================
25
26const options_entry mess_win_options[] =
27{
28   { NULL,                     NULL,   OPTION_HEADER,      "WINDOWS MESS SPECIFIC OPTIONS" },
29   { "newui;nu",                   "0",    OPTION_BOOLEAN,      "use the new MESS UI" },
30   { NULL }
31};
32
33//============================================================
34
35void osd_mess_options_init(core_options *opts)
36{
37   options_add_entries(opts, mess_win_options);
38}
39
40
41
42void osd_get_emulator_directory(char *dir, size_t dir_size)
43{
44   char *s;
45   win_get_module_file_name_utf8(NULL, dir, dir_size);
46   s = strrchr(dir, '\\');
47   if (s)
48      s[1] = '\0';
49}
src/mess/osd/windows/configms.h
r7335r7336
1//============================================================
2//
3//  configms.h - Win32 MESS specific options
4//
5//============================================================
6
7#ifndef CONFIGMS_H
8#define CONFIGMS_H
9
10#include "options.h"
11
12
13//============================================================
14//  GLOBAL VARIABLES
15//============================================================
16
17extern const options_entry mess_win_options[];
18
19#endif /* CONFIGMS_H */
20
src/mess/osd/windows/glob.c
r7335r7336
1/*
2 * Copyright (c) 1989, 1993
3 *  The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Guido van Rossum.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *  This product includes software developed by the University of
19 *  California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 *    may be used to endorse or promote products derived from this software
22 *    without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char sccsid[] = "@(#)glob.c   8.3 (Berkeley) 10/13/93";
39#endif /* LIBC_SCCS and not lint */
40
41/*
42 * glob(3) -- a superset of the one defined in POSIX 1003.2.
43 *
44 * The [!...] convention to negate a range is supported (SysV, Posix, ksh).
45 *
46 * Optional extra services, controlled by flags not defined by POSIX:
47 *
48 * GLOB_QUOTE:
49 *  Escaping convention: \ inhibits any special meaning the following
50 *  character might have (except \ at end of string is retained).
51 * GLOB_MAGCHAR:
52 *  Set in gl_flags if pattern contained a globbing character.
53 * GLOB_NOMAGIC:
54 *  Same as GLOB_NOCHECK, but it will only append pattern if it did
55 *  not contain any magic characters.  [Used in csh style globbing]
56 * GLOB_ALTDIRFUNC:
57 *  Use alternately specified directory access functions.
58 * GLOB_TILDE:
59 *  expand ~user/foo to the /home/dir/of/user/foo
60 * GLOB_BRACE:
61 *  expand {1,2}{a,b} to 1a 1b 2a 2b
62 * gl_matchc:
63 *  Number of matches in the current invocation of glob.
64 */
65
66#ifndef WIN32
67#define WIN32
68#endif
69
70#ifdef WIN32
71#ifdef _MSC_VER
72#define __STDC__   0
73#endif
74#else
75#include <sys/param.h>
76#endif
77#include <sys/stat.h>
78
79#include <ctype.h>
80
81#include "osdcore.h"
82#include "osdmess.h"
83
84#include <errno.h>
85#include "glob.h"
86#include <stdio.h>
87#include <stdlib.h>
88#include <string.h>
89
90#define   DOLLAR      '$'
91#define   DOT      '.'
92#define   EOS      '\0'
93#define   LBRACKET   '['
94#define   NOT      '!'
95#define   QUESTION   '?'
96#define   QUOTE      '\\'
97#define   RANGE      '-'
98#define   RBRACKET   ']'
99#define   SEP      '/'
100#define   STAR      '*'
101#define   TILDE      '~'
102#define   UNDERSCORE   '_'
103#define   LBRACE      '{'
104#define   RBRACE      '}'
105#define   SLASH      '/'
106#define   COMMA      ','
107
108#ifdef WIN32
109#define S_ISLNK(s)   (0)
110#undef SEP
111#define SEP '\\'
112struct passwd
113{
114   char *pw_dir;
115};
116#define getlogin()   (NULL)
117#define getpwnam(h)   (NULL)
118#define getpwuid(h)   (NULL)
119#define getuid()   (0)
120#define lstat      stat
121typedef unsigned int u_int;
122typedef unsigned short u_short;
123typedef unsigned char u_char;
124#else
125#include <unistd.h>
126#include <pwd.h>
127#endif
128
129#ifndef DEBUG
130
131#define   M_QUOTE      0x8000
132#define   M_PROTECT   0x4000
133#define   M_MASK      0xffff
134#define   M_ASCII      0x00ff
135
136typedef u_short Char;
137
138#else
139
140#define   M_QUOTE      0x80
141#define   M_PROTECT   0x40
142#define   M_MASK      0xff
143#define   M_ASCII      0x7f
144
145typedef char Char;
146
147#endif
148
149
150#define   CHAR(c)      ((Char)((c)&M_ASCII))
151#define   META(c)      ((Char)((c)|M_QUOTE))
152#define   M_ALL      META('*')
153#define   M_END      META(']')
154#define   M_NOT      META('!')
155#define   M_ONE      META('?')
156#define   M_RNG      META('-')
157#define   M_SET      META('[')
158#define   ismeta(c)   (((c)&M_QUOTE) != 0)
159
160#ifndef DECL_SPEC
161#define DECL_SPEC
162#endif
163
164
165static int    DECL_SPEC compare __P((const void *, const void *));
166static void    g_Ctoc __P((const Char *, char *));
167static osd_directory   *g_opendir __P((Char *, glob_t *));
168static Char   *g_strchr __P((Char *, int));
169#ifdef notdef
170static Char   *g_strcat __P((Char *, const Char *));
171#endif
172static int    glob0 __P((const Char *, glob_t *));
173static int    glob1 __P((Char *, glob_t *));
174static int    glob2 __P((Char *, Char *, Char *, glob_t *));
175static int    glob3 __P((Char *, Char *, Char *, Char *, glob_t *));
176static int    globextend __P((const Char *, glob_t *));
177static const Char *    globtilde __P((const Char *, Char *, size_t, glob_t *));
178static int    globexp1 __P((const Char *, glob_t *));
179static int    globexp2 __P((const Char *, const Char *, glob_t *, int *));
180static int    match __P((Char *, Char *, Char *));
181#ifdef DEBUG
182static void    qprintf __P((const char *, Char *));
183#endif
184
185int   glob (const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob)
186{
187   const u_char *patnext;
188   int c;
189   Char *bufnext, *bufend, patbuf[_MAX_PATH+1];
190
191   patnext = (u_char *) pattern;
192   if (!(flags & GLOB_APPEND)) {
193      pglob->gl_pathc = 0;
194      pglob->gl_pathv = NULL;
195      if (!(flags & GLOB_DOOFFS))
196         pglob->gl_offs = 0;
197   }
198   pglob->gl_flags = flags & ~GLOB_MAGCHAR;
199   pglob->gl_errfunc = errfunc;
200   pglob->gl_matchc = 0;
201
202   bufnext = patbuf;
203   bufend = bufnext + _MAX_PATH;
204   if (flags & GLOB_QUOTE) {
205      /* Protect the quoted characters. */
206      while (bufnext < bufend && (c = *patnext++) != EOS)
207         if (c == QUOTE) {
208            if ((c = *patnext++) == EOS) {
209               c = QUOTE;
210               --patnext;
211            }
212            *bufnext++ = c | M_PROTECT;
213         }
214         else
215            *bufnext++ = c;
216   }
217   else
218       while (bufnext < bufend && (c = *patnext++) != EOS)
219          *bufnext++ = c;
220   *bufnext = EOS;
221
222   if (flags & GLOB_BRACE)
223       return globexp1(patbuf, pglob);
224   else
225       return glob0(patbuf, pglob);
226}
227
228/*
229 * Expand recursively a glob {} pattern. When there is no more expansion
230 * invoke the standard globbing routine to glob the rest of the magic
231 * characters
232 */
233static int globexp1(const Char *pattern, glob_t *pglob)
234{
235   Char* ptr = (Char *) pattern;
236   int rv;
237
238   /* Protect a single {}, for find(1), like csh */
239   if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
240      return glob0(pattern, pglob);
241
242   while ((ptr = (Char *) g_strchr((Char *) ptr, LBRACE)) != NULL)
243      if (!globexp2(ptr, pattern, pglob, &rv))
244         return rv;
245
246   return glob0(pattern, pglob);
247}
248
249
250/*
251 * Recursive brace globbing helper. Tries to expand a single brace.
252 * If it succeeds then it invokes globexp1 with the new pattern.
253 * If it fails then it tries to glob the rest of the pattern and returns.
254 */
255static int globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv)
256{
257   int     i;
258   Char   *lm, *ls;
259   const Char *pe, *pm, *pl;
260   Char    patbuf[_MAX_PATH + 1];
261
262   /* copy part up to the brace */
263   for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
264      continue;
265   ls = lm;
266
267   /* Find the balanced brace */
268   for (i = 0, pe = ++ptr; *pe; pe++)
269      if (*pe == LBRACKET) {
270         /* Ignore everything between [] */
271         for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++)
272            continue;
273         if (*pe == EOS) {
274            /*
275                 * We could not find a matching RBRACKET.
276                 * Ignore and just look for RBRACE
277                 */
278            pe = pm;
279         }
280      }
281      else if (*pe == LBRACE)
282         i++;
283      else if (*pe == RBRACE) {
284         if (i == 0)
285            break;
286         i--;
287      }
288
289   /* Non matching braces; just glob the pattern */
290   if (i != 0 || *pe == EOS) {
291      *rv = glob0(patbuf, pglob);
292      return 0;
293   }
294
295   for (i = 0, pl = pm = ptr; pm <= pe; pm++)
296      switch (*pm) {
297      case LBRACKET:
298         /* Ignore everything between [] */
299         for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++)
300            continue;
301         if (*pm == EOS) {
302            /*
303                 * We could not find a matching RBRACKET.
304                 * Ignore and just look for RBRACE
305                 */
306            pm = pl;
307         }
308         break;
309
310      case LBRACE:
311         i++;
312         break;
313
314      case RBRACE:
315         if (i) {
316             i--;
317             break;
318         }
319         /* FALLTHROUGH */
320      case COMMA:
321         if (i && *pm == COMMA)
322            break;
323         else {
324            /* Append the current string */
325            for (lm = ls; (pl < pm); *lm++ = *pl++)
326               continue;
327            /*
328                 * Append the rest of the pattern after the
329                 * closing brace
330                 */
331            for (pl = pe + 1; (*lm++ = *pl++) != EOS;)
332               continue;
333
334            /* Expand the current pattern */
335#ifdef DEBUG
336            qprintf("globexp2:", patbuf);
337#endif
338            *rv = globexp1(patbuf, pglob);
339
340            /* move after the comma, to the next string */
341            pl = pm + 1;
342         }
343         break;
344
345      default:
346         break;
347      }
348   *rv = 0;
349   return 0;
350}
351
352
353
354/*
355 * expand tilde from the passwd file.
356 */
357static const Char *globtilde(const Char *pattern,Char *patbuf, size_t patbuf_len, glob_t *pglob)
358{
359   struct passwd *pwd;
360   char *h;
361   const Char *p;
362   Char *b, *eb;
363
364   if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
365      return pattern;
366
367   /*
368     * Copy up to the end of the string or /
369     */
370   eb = &patbuf[patbuf_len - 1];
371   for (p = pattern + 1, h = (char *) patbuf;
372       h < (char *)eb && *p && *p != SLASH; *h++ = *p++)
373      continue;
374
375   *h = EOS;
376
377   if (((char *) patbuf)[0] == EOS) {
378      /*
379         * handle a plain ~ or ~/ by expanding $HOME first (iff
380         * we're not running setuid or setgid) and then trying
381         * the password file
382         */
383      if (
384          (h = getenv("HOME")) == NULL) {
385         if (((h = getlogin()) != NULL &&
386              (pwd = getpwnam(h)) != NULL) ||
387             (pwd = getpwuid(getuid())) != NULL)
388            h = pwd->pw_dir;
389         else
390            return pattern;
391      }
392   }
393   else {
394      /*
395         * Expand a ~user
396         */
397      if ((pwd = getpwnam((char*) patbuf)) == NULL)
398         return pattern;
399      else
400         h = pwd->pw_dir;
401   }
402
403   /* Copy the home directory */
404   for (b = patbuf; b < eb && *h; *b++ = *h++)
405      continue;
406
407   /* Append the rest of the pattern */
408   while (b < eb && (*b++ = *p++) != EOS)
409      continue;
410   *b = EOS;
411
412   return patbuf;
413}
414
415
416/*
417 * The main glob() routine: compiles the pattern (optionally processing
418 * quotes), calls glob1() to do the real pattern matching, and finally
419 * sorts the list (unless unsorted operation is requested).  Returns 0
420 * if things went well, nonzero if errors occurred.  It is not an error
421 * to find no matches.
422 */
423static int glob0(const Char *pattern,glob_t *pglob)
424{
425   const Char *qpatnext;
426   int c, err, oldpathc;
427   Char *bufnext, patbuf[_MAX_PATH+1];
428
429   qpatnext = globtilde(pattern, patbuf, ARRAY_LENGTH(patbuf), pglob);
430   oldpathc = pglob->gl_pathc;
431   bufnext = patbuf;
432
433   /* We don't need to check for buffer overflow any more. */
434   while ((c = *qpatnext++) != EOS) {
435      switch (c) {
436      case LBRACKET:
437         c = *qpatnext;
438         if (c == NOT)
439            ++qpatnext;
440         if (*qpatnext == EOS ||
441             g_strchr((Char *) qpatnext+1, RBRACKET) == NULL) {
442            *bufnext++ = LBRACKET;
443            if (c == NOT)
444               --qpatnext;
445            break;
446         }
447         *bufnext++ = M_SET;
448         if (c == NOT)
449            *bufnext++ = M_NOT;
450         c = *qpatnext++;
451         do {
452            *bufnext++ = CHAR(c);
453            if (*qpatnext == RANGE &&
454                (c = qpatnext[1]) != RBRACKET) {
455               *bufnext++ = M_RNG;
456               *bufnext++ = CHAR(c);
457               qpatnext += 2;
458            }
459         } while ((c = *qpatnext++) != RBRACKET);
460         pglob->gl_flags |= GLOB_MAGCHAR;
461         *bufnext++ = M_END;
462         break;
463      case QUESTION:
464         pglob->gl_flags |= GLOB_MAGCHAR;
465         *bufnext++ = M_ONE;
466         break;
467      case STAR:
468         pglob->gl_flags |= GLOB_MAGCHAR;
469         /* collapse adjacent stars to one,
470             * to avoid exponential behavior
471             */
472         if (bufnext == patbuf || bufnext[-1] != M_ALL)
473             *bufnext++ = M_ALL;
474         break;
475      default:
476         *bufnext++ = CHAR(c);
477         break;
478      }
479   }
480   *bufnext = EOS;
481#ifdef DEBUG
482   qprintf("glob0:", patbuf);
483#endif
484
485   if ((err = glob1(patbuf, pglob)) != 0)
486      return(err);
487
488   /*
489     * If there was no match we are going to append the pattern
490     * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
491     * and the pattern did not contain any magic characters
492     * GLOB_NOMAGIC is there just for compatibility with csh.
493     */
494   if (pglob->gl_pathc == oldpathc &&
495       ((pglob->gl_flags & GLOB_NOCHECK) ||
496         ((pglob->gl_flags & GLOB_NOMAGIC) &&
497          !(pglob->gl_flags & GLOB_MAGCHAR))))
498      return(globextend(pattern, pglob));
499   else if (!(pglob->gl_flags & GLOB_NOSORT))
500      qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
501          pglob->gl_pathc - oldpathc, sizeof(char *), compare);
502   return(0);
503}
504
505static int compare(const void *p, const void *q)
506{
507   return(strcmp(*(char **)p, *(char **)q));
508}
509
510static int glob1(Char *pattern,glob_t *pglob)
511{
512   Char pathbuf[_MAX_PATH+1];
513
514   /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
515   if (*pattern == EOS)
516      return(0);
517   return(glob2(pathbuf, pathbuf, pattern, pglob));
518}
519
520/*
521 * The functions glob2 and glob3 are mutually recursive; there is one level
522 * of recursion for each segment in the pattern that contains one or more
523 * meta characters.
524 */
525static int glob2(Char *pathbuf, Char *pathend, Char *pattern,glob_t *pglob)
526{
527   Char *p, *q;
528   int anymeta;
529   osd_directory_entry *entry = NULL;
530   osd_directory_entry *entry2 = NULL;
531   char buf[_MAX_PATH];
532
533   /*
534     * Loop over pattern segments until end of pattern or until
535     * segment with meta character found.
536     */
537   for (anymeta = 0;;) {
538      if (*pattern == EOS) {      /* End of pattern? */
539         *pathend = EOS;
540         g_Ctoc(pathbuf, buf);
541         entry = osd_stat(buf);
542         if (!entry)
543            return(0);
544
545         if ((((pglob->gl_flags & GLOB_MARK) &&
546             pathend[-1] != SEP) && (entry->type == ENTTYPE_DIR))
547             || ((S_ISLNK(sb.st_mode) &&
548             ((entry2 = osd_stat(buf)) != NULL) &&
549             (entry2->type == ENTTYPE_DIR)))) {
550            *pathend++ = SEP;
551            *pathend = EOS;
552         }
553         free(entry);
554         if (entry2)
555            free(entry2);
556         ++pglob->gl_matchc;
557         return(globextend(pathbuf, pglob));
558      }
559
560      /* Find end of next segment, copy tentatively to pathend. */
561      q = pathend;
562      p = pattern;
563      while (*p != EOS && *p != SEP) {
564         if (ismeta(*p))
565            anymeta = 1;
566         *q++ = *p++;
567      }
568
569      if (!anymeta) {      /* No expansion, do next segment. */
570         pathend = q;
571         pattern = p;
572         while (*pattern == SEP)
573            *pathend++ = *pattern++;
574      } else         /* Need expansion, recurse. */
575         return(glob3(pathbuf, pathend, pattern, p, pglob));
576   }
577   /* NOTREACHED */
578}
579
580static int glob3(Char *pathbuf,Char *pathend,Char *pattern,Char *restpattern,glob_t *pglob)   
581{
582   register const osd_directory_entry *dp;
583   osd_directory *dirp;
584   int err;
585   char buf[_MAX_PATH];
586
587   /*
588     * The readdirfunc declaration can't be prototyped, because it is
589     * assigned, below, to two functions which are prototyped in glob.h
590     * and dirent.h as taking pointers to differently typed opaque
591     * structures.
592     */
593   typedef const osd_directory_entry *(*readdirfunc_t)(osd_directory *);
594   readdirfunc_t readdirfunc;
595
596   *pathend = EOS;
597   errno = 0;
598
599   if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
600      /* TODO: don't call for ENOENT or ENOTDIR? */
601      if (pglob->gl_errfunc) {
602         g_Ctoc(pathbuf, buf);
603         if (pglob->gl_errfunc(buf, errno) ||
604             pglob->gl_flags & GLOB_ERR)
605            return (GLOB_ABEND);
606      }
607      return(0);
608   }
609
610   err = 0;
611
612   /* Search directory for matching names. */
613   if (pglob->gl_flags & GLOB_ALTDIRFUNC)
614      readdirfunc = (readdirfunc_t) pglob->gl_readdir;
615   else
616      readdirfunc = osd_readdir;
617   while ((dp = (*readdirfunc)(dirp))) {
618      register u_char *sc;
619      register Char *dc;
620
621      /* Initial DOT must be matched literally. */
622      if (dp->name[0] == DOT && *pattern != DOT)
623         continue;
624      for (sc = (u_char *) dp->name, dc = pathend;
625           (*dc++ = *sc++) != EOS;)
626         continue;
627      if (!match(pathend, pattern, restpattern)) {
628         *pathend = EOS;
629         continue;
630      }
631      err = glob2(pathbuf, --dc, restpattern, pglob);
632      if (err)
633         break;
634   }
635
636   if (pglob->gl_flags & GLOB_ALTDIRFUNC)
637      (*pglob->gl_closedir)(dirp);
638   else
639      osd_closedir(dirp);
640   return(err);
641}
642
643
644/*
645 * Extend the gl_pathv member of a glob_t structure to accomodate a new item,
646 * add the new item, and update gl_pathc.
647 *
648 * This assumes the BSD realloc, which only copies the block when its size
649 * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
650 * behavior.
651 *
652 * Return 0 if new item added, error code if memory couldn't be allocated.
653 *
654 * Invariant of the glob_t structure:
655 *  Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
656 *  gl_pathv points to (gl_offs + gl_pathc + 1) items.
657 */
658static int globextend(const Char *path, glob_t *pglob)
659{
660   register char **pathv;
661   register int i;
662   u_int newsize;
663   char *copy;
664   const Char *p;
665
666   newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
667   pathv = pglob->gl_pathv ?
668          (char **)realloc(pglob->gl_pathv, newsize) :
669          (char **)malloc(newsize);
670   if (pathv == NULL)
671      return(GLOB_NOSPACE);
672
673   if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
674      /* first time around -- clear initial gl_offs items */
675      pathv += pglob->gl_offs;
676      for (i = pglob->gl_offs; --i >= 0; )
677         *--pathv = NULL;
678   }
679   pglob->gl_pathv = pathv;
680
681   for (p = path; *p++;)
682      continue;
683   if ((copy = (char *)malloc(p - path)) != NULL) {
684      g_Ctoc(path, copy);
685      pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
686   }
687   pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
688   return(copy == NULL ? GLOB_NOSPACE : 0);
689}
690
691/*
692 * pattern matching function for filenames.  Each occurrence of the *
693 * pattern causes a recursion level.
694 */
695static int match(register Char *name, register Char *pat, register Char *patend)
696{
697   int ok, negate_range;
698   Char c, k;
699
700   while (pat < patend) {
701      c = *pat++;
702      switch (c & M_MASK) {
703      case M_ALL:
704         if (pat == patend)
705            return(1);
706         do
707             if (match(name, pat, patend))
708                return(1);
709         while (*name++ != EOS);
710         return(0);
711      case M_ONE:
712         if (*name++ == EOS)
713            return(0);
714         break;
715      case M_SET:
716         ok = 0;
717         if ((k = *name++) == EOS)
718            return(0);
719         if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
720            ++pat;
721         while (((c = *pat++) & M_MASK) != M_END)
722            if ((*pat & M_MASK) == M_RNG) {
723               if (CHAR(c) <= CHAR(k) && CHAR(k) <= CHAR(pat[1]))
724                  ok = 1;
725               pat += 2;
726            } else if (c == k)
727               ok = 1;
728         if (ok == negate_range)
729            return(0);
730         break;
731      default:
732         if (*name++ != c)
733            return(0);
734         break;
735      }
736   }
737   return(*name == EOS);
738}
739
740/* Free allocated data belonging to a glob_t structure. */
741void globfree(glob_t *pglob)
742{
743   register int i;
744   register char **pp;
745
746   if (pglob->gl_pathv != NULL) {
747      pp = pglob->gl_pathv + pglob->gl_offs;
748      for (i = pglob->gl_pathc; i--; ++pp)
749         if (*pp)
750            free(*pp);
751      free(pglob->gl_pathv);
752   }
753}
754
755static osd_directory *g_opendir(register Char *str,glob_t *pglob)   
756{
757   char buf[_MAX_PATH];
758
759   if (!*str)
760      strcpy(buf, ".");
761   else
762      g_Ctoc(str, buf);
763
764   if (pglob->gl_flags & GLOB_ALTDIRFUNC)
765      return((osd_directory *)(*pglob->gl_opendir)(buf));
766
767   return osd_opendir(buf);
768}
769
770static Char *g_strchr(Char *str,int ch)   
771{
772   do {
773      if (*str == ch)
774         return (str);
775   } while (*str++);
776   return (NULL);
777}
778
779#ifdef notdef
780static Char *
781g_strcat(dst, src)
782   Char *dst;
783   const Char* src;
784{
785   Char *sdst = dst;
786
787   while (*dst++)
788      continue;
789   --dst;
790   while((*dst++ = *src++) != EOS)
791       continue;
792
793   return (sdst);
794}
795#endif
796
797static void g_Ctoc(register const Char *str, char *buf)
798{
799   register char *dc;
800
801   for (dc = buf; (*dc++ = *str++) != EOS;)
802      continue;
803}
804
805#ifdef DEBUG
806static void
807qprintf(str, s)
808   const char *str;
809   register Char *s;
810{
811   register Char *p;
812
813   (void)printf("%s:\n", str);
814   for (p = s; *p; p++)
815      (void)printf("%c", CHAR(*p));
816   (void)printf("\n");
817   for (p = s; *p; p++)
818      (void)printf("%c", *p & M_PROTECT ? '"' : ' ');
819   (void)printf("\n");
820   for (p = s; *p; p++)
821      (void)printf("%c", ismeta(*p) ? '_' : ' ');
822   (void)printf("\n");
823}
824#endif
src/mess/osd/windows/winmess.c
r7335r7336
1#define WIN32_LEAN_AND_MEAN
2#include <windows.h>
3#include <ctype.h>
4#include <tchar.h>
5#include <shlwapi.h>
6
7#include "emuopts.h"
8#include "emu.h"
9#include "osdmess.h"
10#include "utils.h"
11#include "winutil.h"
12#include "strconv.h"
13#include "winutf8.h"
14#include "inputx.h"
15
16//============================================================
17//  win_error_to_mame_file_error
18//============================================================
19
20static file_error win_error_to_mame_file_error(DWORD error)
21{
22   file_error filerr;
23
24   // convert a Windows error to a file_error
25   switch (error)
26   {
27      case ERROR_SUCCESS:
28         filerr = FILERR_NONE;
29         break;
30
31      case ERROR_OUTOFMEMORY:
32         filerr = FILERR_OUT_OF_MEMORY;
33         break;
34
35      case ERROR_FILE_NOT_FOUND:
36      case ERROR_PATH_NOT_FOUND:
37         filerr = FILERR_NOT_FOUND;
38         break;
39
40      case ERROR_ACCESS_DENIED:
41         filerr = FILERR_ACCESS_DENIED;
42         break;
43
44      case ERROR_SHARING_VIOLATION:
45         filerr = FILERR_ALREADY_OPEN;
46         break;
47
48      default:
49         filerr = FILERR_FAILURE;
50         break;
51   }
52   return filerr;
53}
54
55
56//============================================================
57//  osd_get_temp_filename
58//============================================================
59
60file_error osd_get_temp_filename(char *buffer, size_t buffer_len, const char *basename)
61{
62   TCHAR tempbuf[MAX_PATH];
63   TCHAR *t_filename;
64   char *u_tempbuf;
65
66   if (!basename)
67      basename = "tempfile.tmp";
68
69   GetTempPath(ARRAY_LENGTH(tempbuf), tempbuf);
70   t_filename = tstring_from_utf8(basename);
71   _tcscat(tempbuf, t_filename);
72   global_free(t_filename);
73   DeleteFile(tempbuf);
74
75   u_tempbuf = utf8_from_tstring(tempbuf);
76   snprintf(buffer, buffer_len, "%s", u_tempbuf);
77   global_free(u_tempbuf);
78
79   return FILERR_NONE;
80}
81
82
83//============================================================
84//  osd_copyfile
85//============================================================
86
87file_error osd_copyfile(const char *destfile, const char *srcfile)
88{
89   // wrapper for win_copy_file_utf8()
90   if (!win_copy_file_utf8(srcfile, destfile, TRUE))
91      return win_error_to_mame_file_error(GetLastError());
92
93   return FILERR_NONE;
94}
95
96
97//============================================================
98//  osd_stat
99//============================================================
100
101osd_directory_entry *osd_stat(const char *path)
102{
103   osd_directory_entry *result = NULL;
104   TCHAR *t_path;
105   HANDLE find = INVALID_HANDLE_VALUE;
106   WIN32_FIND_DATA find_data;
107
108   // convert the path to TCHARs
109   t_path = tstring_from_utf8(path);
110   if (t_path == NULL)
111      goto done;
112
113   // is this path a root directory (e.g. - C:)?
114   if (isalpha(path[0]) && (path[1] == ':') && (path[2] == '\0'))
115   {
116      // need to do special logic for root directories
117      memset(&find_data, 0, sizeof(find_data));
118      find_data.dwFileAttributes = GetFileAttributes(t_path);
119   }
120   else
121   {
122      // attempt to find the first file
123      find = FindFirstFile(t_path, &find_data);
124      if (find == INVALID_HANDLE_VALUE)
125         goto done;
126   }
127
128   // create an osd_directory_entry; be sure to make sure that the caller can
129   // free all resources by just freeing the resulting osd_directory_entry
130   result = (osd_directory_entry *)global_alloc_array_clear(UINT8,sizeof(*result) + strlen(path) + 1);
131   if (!result)
132      goto done;
133   strcpy(((char *) result) + sizeof(*result), path);
134   result->name = ((char *) result) + sizeof(*result);
135   result->type = win_attributes_to_entry_type(find_data.dwFileAttributes);
136   result->size = find_data.nFileSizeLow | ((UINT64) find_data.nFileSizeHigh << 32);
137
138done:
139   if (t_path != NULL)
140      global_free(t_path);
141   return result;
142}
143
144
145
146//============================================================
147//  osd_is_path_separator
148//============================================================
149
150int osd_is_path_separator(char c)
151{
152   return (c == '/') || (c == '\\');
153}
154
155
156
157//============================================================
158//  osd_dirname
159//============================================================
160
161char *osd_dirname(const char *filename)
162{
163   char *dirname;
164   char *c;
165
166   // NULL begets NULL
167   if (!filename)
168      return NULL;
169
170   // allocate space for it
171   dirname = (char*)global_alloc_array_clear(char,strlen(filename) + 1);
172   if (!dirname)
173      return NULL;
174
175   // copy in the name
176   strcpy(dirname, filename);
177
178   // search backward for a slash or a colon
179   for (c = dirname + strlen(dirname) - 1; c >= dirname; c--)
180      if (*c == '\\' || *c == '/' || *c == ':')
181      {
182         // found it: NULL terminate and return
183         *(c + 1) = 0;
184         return dirname;
185      }
186
187   // otherwise, return an empty string
188   dirname[0] = 0;
189   return dirname;
190}
191
192
193//============================================================
194//  osd_basename
195//============================================================
196
197char *osd_basename(char *filename)
198{
199   char *c;
200
201   // NULL begets NULL
202   if (!filename)
203      return NULL;
204
205   // start at the end and return when we hit a slash or colon
206   for (c = filename + strlen(filename) - 1; c >= filename; c--)
207      if (*c == '\\' || *c == '/' || *c == ':')
208         return c + 1;
209
210   // otherwise, return the whole thing
211   return filename;
212}
213
214
215//============================================================
216//  osd_get_full_path
217//============================================================
218
219file_error osd_get_full_path(char **dst, const char *path)
220{
221   file_error err;
222   TCHAR *t_path;
223   TCHAR buffer[MAX_PATH];
224
225   // convert the path to TCHARs
226   t_path = tstring_from_utf8(path);
227   if (t_path == NULL)
228   {
229      err = FILERR_OUT_OF_MEMORY;
230      goto done;
231   }
232
233   // cannonicalize the path
234   if (!GetFullPathName(t_path, ARRAY_LENGTH(buffer), buffer, NULL))
235   {
236      err = win_error_to_mame_file_error(GetLastError());
237      goto done;
238   }
239
240   // convert the result back to UTF-8
241   *dst = utf8_from_tstring(buffer);
242   if (!*dst)
243   {
244      err = FILERR_OUT_OF_MEMORY;
245      goto done;
246   }
247
248   err = FILERR_NONE;
249
250done:
251   if (t_path != NULL)
252      global_free(t_path);
253   return err;
254}
255
256
257//============================================================
258//  osd_mkdir
259//============================================================
260
261file_error osd_mkdir(const char *dir)
262{
263   file_error filerr = FILERR_NONE;
264
265   TCHAR *tempstr = tstring_from_utf8(dir);
266   if (!tempstr)
267   {
268      filerr = FILERR_OUT_OF_MEMORY;
269      goto done;
270   }
271
272   if (!CreateDirectory(tempstr, NULL))
273   {
274      filerr = win_error_to_mame_file_error(GetLastError());
275      goto done;
276   }
277
278done:
279   if (tempstr)
280      global_free(tempstr);
281   return filerr;
282}
283
284
285//============================================================
286//  osd_rmdir
287//============================================================
288
289file_error osd_rmdir(const char *dir)
290{
291   file_error filerr = FILERR_NONE;
292
293   TCHAR *tempstr = tstring_from_utf8(dir);
294   if (!tempstr)
295   {
296      filerr = FILERR_OUT_OF_MEMORY;
297      goto done;
298   }
299
300   if (!RemoveDirectory(tempstr))
301   {
302      filerr = win_error_to_mame_file_error(GetLastError());
303      goto done;
304   }
305
306done:
307   if (tempstr)
308      global_free(tempstr);
309   return filerr;
310}
311
312
313//============================================================
314//  osd_getcurdir
315//============================================================
316
317file_error osd_getcurdir(char *buffer, size_t buffer_len)
318{
319   file_error filerr = FILERR_NONE;
320   char *tempstr = NULL;
321   TCHAR path[_MAX_PATH];
322
323   if (!GetCurrentDirectory(ARRAY_LENGTH(path), path))
324   {
325      filerr = win_error_to_mame_file_error(GetLastError());
326      goto done;
327   }
328
329   tempstr = utf8_from_tstring(path);
330   if (!tempstr)
331   {
332      filerr = FILERR_OUT_OF_MEMORY;
333      goto done;
334   }
335   snprintf(buffer, buffer_len, "%s", tempstr);
336
337done:
338   if (tempstr)
339      global_free(tempstr);
340   return filerr;
341}
342
343
344//============================================================
345//  osd_setcurdir
346//============================================================
347
348file_error osd_setcurdir(const char *dir)
349{
350   file_error filerr = FILERR_NONE;
351
352   TCHAR *tempstr = tstring_from_utf8(dir);
353   if (!tempstr)
354   {
355      filerr = FILERR_OUT_OF_MEMORY;
356      goto done;
357   }
358
359   if (!SetCurrentDirectory(tempstr))
360   {
361      filerr = win_error_to_mame_file_error(GetLastError());
362      goto done;
363   }
364
365done:
366   if (tempstr)
367      global_free(tempstr);
368   return filerr;
369}
370
371
372
373//============================================================
374//  CLIPBOARD
375//============================================================
376
377//============================================================
378//  get_clipboard_text_by_format
379//============================================================
380
381static char *get_clipboard_text_by_format(UINT format, char *(*convert)(LPCVOID data))
382{
383   char *result = NULL;
384   HANDLE data_handle;
385   LPVOID data;
386
387   // check to see if this format is available
388   if (IsClipboardFormatAvailable(format))
389   {
390      // open the clipboard
391      if (OpenClipboard(NULL))
392      {
393         // try to access clipboard data
394         data_handle = GetClipboardData(format);
395         if (data_handle != NULL)
396         {
397            // lock the data
398            data = GlobalLock(data_handle);
399            if (data != NULL)
400            {
401               // invoke the convert
402               result = (*convert)(data);
403
404               // unlock the data
405               GlobalUnlock(data_handle);
406            }
407         }
408
409         // close out the clipboard
410         CloseClipboard();
411      }
412   }
413   return result;
414}
415
416
417
418//============================================================
419//  convert_wide
420//============================================================
421
422static char *convert_wide(LPCVOID data)
423{
424   return utf8_from_wstring((LPCWSTR) data);
425}
426
427
428
429//============================================================
430//  convert_ansi
431//============================================================
432
433static char *convert_ansi(LPCVOID data)
434{
435   return utf8_from_astring((LPCSTR) data);
436}
437
438
439
440//============================================================
441//  osd_get_clipboard_text
442//============================================================
443
444char *osd_get_clipboard_text(void)
445{
446   char *result = NULL;
447
448   // try to access unicode text
449   if (result == NULL)
450      result = get_clipboard_text_by_format(CF_UNICODETEXT, convert_wide);
451
452   // try to access ANSI text
453   if (result == NULL)
454      result = get_clipboard_text_by_format(CF_TEXT, convert_ansi);
455
456   return result;
457}
458
459
460
461//============================================================
462//  DIRECTORIES
463//============================================================
464
465#ifdef UNDER_CE
466int osd_num_devices(void)
467{
468   return 1;
469}
470
471const char *osd_get_device_name(int idx)
472{
473   return "\\";
474}
475#else
476int osd_num_devices(void)
477{
478   char szBuffer[128];
479   char *p;
480   int i;
481
482   GetLogicalDriveStringsA(ARRAY_LENGTH(szBuffer), szBuffer);
483
484   i = 0;
485   for (p = szBuffer; *p; p += (strlen(p) + 1))
486      i++;
487   return i;
488}
489
490const char *osd_get_device_name(int idx)
491{
492   static char szBuffer[128];
493   const char *p;
494
495   GetLogicalDriveStringsA(ARRAY_LENGTH(szBuffer), szBuffer);
496
497   p = szBuffer;
498   while(idx--)
499      p += strlen(p) + 1;
500
501   return p;
502}
503#endif
src/mess/osd/windows/glob.h
r7335r7336
1/*
2 * Copyright (c) 1991, 1993
3 *  The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Berkeley Software Design, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *  This product includes software developed by the University of
19 *  California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 *    may be used to endorse or promote products derived from this software
22 *    without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 *  @(#)cdefs.h 8.8 (Berkeley) 1/9/95
37 * $FreeBSD: src/sys/sys/cdefs.h,v 1.28.2.1 2000/03/18 23:30:03 jasone Exp $
38 */
39
40#ifndef   _SYS_CDEFS_H_
41#define   _SYS_CDEFS_H_
42
43#if defined(__cplusplus)
44#define   __BEGIN_DECLS   extern "C" {
45#define   __END_DECLS   }
46#else
47#define   __BEGIN_DECLS
48#define   __END_DECLS
49#endif
50
51/*
52 * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
53 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
54 * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
55 * mode -- there must be no spaces between its arguments, and for nested
56 * __CONCAT's, all the __CONCAT's must be at the left.  __CONCAT can also
57 * concatenate double-quoted strings produced by the __STRING macro, but
58 * this only works with ANSI C.
59 *
60 * __XSTRING is like __STRING, but it expands any macros in its argument
61 * first.  It is only available with ANSI C.
62 */
63#if defined(__STDC__) || defined(__cplusplus)
64#define   __P(protos)   protos      /* full-blown ANSI C */
65#define   __STRING(x)   #x      /* stringify without expanding x */
66#define   __XSTRING(x)   __STRING(x)   /* expand x, then stringify */
67
68#define   __const      const      /* define reserved names to standard */
69#define   __signed   signed
70#define   __volatile   volatile
71#if defined(__cplusplus)
72#define   __inline   inline      /* convert to C++ keyword */
73#else
74#ifndef __GNUC__
75#define   __inline         /* delete GCC keyword */
76#endif /* !__GNUC__ */
77#endif /* !__cplusplus */
78
79#else   /* !(__STDC__ || __cplusplus) */
80#define   __P(protos)   ()      /* traditional C preprocessor */
81#define   __STRING(x)   "x"
82
83#ifndef __GNUC__
84#define   __const            /* delete pseudo-ANSI C keywords */
85#define   __inline
86#define   __signed
87#undef __volatile
88#define   __volatile
89/*
90 * In non-ANSI C environments, new programs will want ANSI-only C keywords
91 * deleted from the program and old programs will want them left alone.
92 * When using a compiler other than gcc, programs using the ANSI C keywords
93 * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
94 * When using "gcc -traditional", we assume that this is the intent; if
95 * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
96 */
97#ifndef   NO_ANSI_KEYWORDS
98#define   const            /* delete ANSI C keywords */
99#ifndef inline
100#define   inline
101#endif
102#define   signed
103#define   volatile
104#endif   /* !NO_ANSI_KEYWORDS */
105#endif   /* !__GNUC__ */
106#endif   /* !(__STDC__ || __cplusplus) */
107
108/*
109 * Compiler-dependent macros to help declare dead (non-returning) and
110 * pure (no side effects) functions, and unused variables.  They are
111 * null except for versions of gcc that are known to support the features
112 * properly (old versions of gcc-2 supported the dead and pure features
113 * in a different (wrong) way).
114 */
115#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 5
116#define __dead2
117#define __pure2
118#define __unused
119#endif
120#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7
121#define __dead2      __attribute__((__noreturn__))
122#define __pure2      __attribute__((__const__))
123#define __unused
124#endif
125#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7
126#define __dead2      __attribute__((__noreturn__))
127#define __pure2      __attribute__((__const__))
128#define __unused   __attribute__((__unused__))
129#endif
130
131/*
132 * Compiler-dependent macros to declare that functions take printf-like
133 * or scanf-like arguments.  They are null except for versions of gcc
134 * that are known to support the features properly (old versions of gcc-2
135 * didn't permit keeping the keywords out of the application namespace).
136 */
137#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 7
138#define   __printflike(fmtarg, firstvararg)
139#define   __scanflike(fmtarg, firstvararg)
140#else
141#define   __printflike(fmtarg, firstvararg) \
142       __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
143#define   __scanflike(fmtarg, firstvararg) \
144       __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
145#endif
146
147/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
148#define __FreeBSD_cc_version 0
149#if __FreeBSD_cc_version >= 300001
150#define   __printf0like(fmtarg, firstvararg) \
151       __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
152#else
153#define   __printf0like(fmtarg, firstvararg)
154#endif
155
156#ifdef __GNUC__
157#define __strong_reference(sym,aliassym)   \
158   extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)));
159#ifdef __ELF__
160#ifdef __STDC__
161#define   __weak_reference(sym,alias)   \
162   __asm__(".weak " #alias);   \
163   __asm__(".equ "  #alias ", " #sym)
164#define   __warn_references(sym,msg)   \
165   __asm__(".section .gnu.warning." #sym);   \
166   __asm__(".asciz \"" msg "\"");   \
167   __asm__(".previous")
168#else
169#define   __weak_reference(sym,alias)   \
170   __asm__(".weak alias");      \
171   __asm__(".equ alias, sym")
172#define   __warn_references(sym,msg)   \
173   __asm__(".section .gnu.warning.sym"); \
174   __asm__(".asciz \"msg\"");   \
175   __asm__(".previous")
176#endif   /* __STDC__ */
177#else   /* !__ELF__ */
178#ifdef __STDC__
179#define __weak_reference(sym,alias)   \
180   __asm__(".stabs \"_" #alias "\",11,0,0,0");   \
181   __asm__(".stabs \"_" #sym "\",1,0,0,0")
182#define __warn_references(sym,msg)   \
183   __asm__(".stabs \"" msg "\",30,0,0,0");      \
184   __asm__(".stabs \"_" #sym "\",1,0,0,0")
185#else
186#define __weak_reference(sym,alias)   \
187   __asm__(".stabs \"_/**/alias\",11,0,0,0");   \
188   __asm__(".stabs \"_/**/sym\",1,0,0,0")
189#define __warn_references(sym,msg)   \
190   __asm__(".stabs msg,30,0,0,0");         \
191   __asm__(".stabs \"_/**/sym\",1,0,0,0")
192#endif   /* __STDC__ */
193#endif   /* __ELF__ */
194#endif   /* __GNUC__ */
195
196#if defined(__GNUC__) && defined(__ELF__)
197#define   __IDSTRING(name,string)   __asm__(".ident\t\"" string "\"")
198#else
199#define   __IDSTRING(name,string)   static const char name[] __unused = string
200#endif
201
202#ifndef   __RCSID
203#define   __RCSID(s)   __IDSTRING(rcsid,s)
204#endif
205
206#ifndef   __RCSID_SOURCE
207#define   __RCSID_SOURCE(s) __IDSTRING(rcsid_source,s)
208#endif
209
210#ifndef   __COPYRIGHT
211#define   __COPYRIGHT(s)   __IDSTRING(copyright,s)
212#endif
213
214#endif /* !_SYS_CDEFS_H_ */
215
216/*
217 * Copyright (c) 1989, 1993
218 *  The Regents of the University of California.  All rights reserved.
219 *
220 * This code is derived from software contributed to Berkeley by
221 * Guido van Rossum.
222 *
223 * Redistribution and use in source and binary forms, with or without
224 * modification, are permitted provided that the following conditions
225 * are met:
226 * 1. Redistributions of source code must retain the above copyright
227 *    notice, this list of conditions and the following disclaimer.
228 * 2. Redistributions in binary form must reproduce the above copyright
229 *    notice, this list of conditions and the following disclaimer in the
230 *    documentation and/or other materials provided with the distribution.
231 * 3. All advertising materials mentioning features or use of this software
232 *    must display the following acknowledgement:
233 *  This product includes software developed by the University of
234 *  California, Berkeley and its contributors.
235 * 4. Neither the name of the University nor the names of its contributors
236 *    may be used to endorse or promote products derived from this software
237 *    without specific prior written permission.
238 *
239 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
240 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
242 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
243 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
244 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
245 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
246 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
247 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
248 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
249 * SUCH DAMAGE.
250 *
251 *  @(#)glob.h  8.1 (Berkeley) 6/2/93
252 */
253
254#ifndef _GLOB_H_
255#define   _GLOB_H_
256
257//BEOS: sys/cdefs.h included above
258
259struct stat;
260typedef struct {
261   int gl_pathc;      /* Count of total paths so far. */
262   int gl_matchc;      /* Count of paths matching pattern. */
263   int gl_offs;      /* Reserved at beginning of gl_pathv. */
264   int gl_flags;      /* Copy of flags parameter to glob. */
265   char **gl_pathv;   /* List of paths matching pattern. */
266            /* Copy of errfunc parameter to glob. */
267   int (*gl_errfunc) __P((const char *, int));
268
269   /*
270     * Alternate filesystem access methods for glob; replacement
271     * versions of closedir(3), readdir(3), opendir(3), stat(2)
272     * and lstat(2).
273     */
274   void (*gl_closedir) __P((void *));
275   struct dirent *(*gl_readdir) __P((void *));
276   void *(*gl_opendir) __P((const char *));
277   int (*gl_lstat) __P((const char *, struct stat *));
278   int (*gl_stat) __P((const char *, struct stat *));
279} glob_t;
280
281#define   GLOB_APPEND   0x0001   /* Append to output from previous call. */
282#define   GLOB_DOOFFS   0x0002   /* Use gl_offs. */
283#define   GLOB_ERR   0x0004   /* Return on error. */
284#define   GLOB_MARK   0x0008   /* Append / to matching directories. */
285#define   GLOB_NOCHECK   0x0010   /* Return pattern itself if nothing matches. */
286#define   GLOB_NOSORT   0x0020   /* Don't sort. */
287
288#define   GLOB_ALTDIRFUNC   0x0040   /* Use alternately specified directory funcs. */
289#define   GLOB_BRACE   0x0080   /* Expand braces ala csh. */
290#define   GLOB_MAGCHAR   0x0100   /* Pattern had globbing characters. */
291#define   GLOB_NOMAGIC   0x0200   /* GLOB_NOCHECK without magic chars (csh). */
292#define   GLOB_QUOTE   0x0400   /* Quote special chars with \. */
293#define   GLOB_TILDE   0x0800   /* Expand tilde names from the passwd file. */
294
295#define   GLOB_NOSPACE   (-1)   /* Malloc call failed. */
296#define   GLOB_ABEND   (-2)   /* Unignored error. */
297
298int   glob (const char *, int, int (*)(const char *, int), glob_t *);
299void   globfree(glob_t *);
300
301#endif /* !_GLOB_H_ */
src/mess/osd/windows/winutils.c
r7335r7336
2020// MESS headers
2121#include "winutils.h"
2222#include "strconv.h"
23#include "glob.h"
2423
2524// stupid hack; not sure why this is needed
2625#ifdef const
r7335r7336
241240   return result;
242241}
243242
244void win_expand_wildcards(int *argc, char **argv[])
245{
246   int i;
247   glob_t g;
248
249   memset(&g, 0, sizeof(g));
250
251   for (i = 0; i < *argc; i++)
252      glob((*argv)[i], (g.gl_pathc > 0) ? GLOB_APPEND|GLOB_NOCHECK : GLOB_NOCHECK, NULL, &g);
253
254   *argc = g.gl_pathc;
255   *argv = g.gl_pathv;
256}
src/mess/osd/windows/dialog.c
r7335r7336
1111
1212#include "dialog.h"
1313#include "emu.h"
14#include "mslegacy.h"
15#include "inputx.h"
1614#include "utils.h"
1715#include "strconv.h"
1816#include "pool.h"
r7335r7336
129127#define DLGITEM_SCROLLBAR      ((const WCHAR *) dlgitem_scrollbar)
130128#define DLGITEM_COMBOBOX      ((const WCHAR *) dlgitem_combobox)
131129
132#define DLGTEXT_OK            ui_getstring(UI_OK)
130#define DLGTEXT_OK            "OK"
133131#define DLGTEXT_APPLY         "Apply"
134132#define DLGTEXT_CANCEL         "Cancel"
135133
src/mess/osd/windows/windows.mak
r7335r7336
2525RESFILE = $(MESS_WINOBJ)/mess.res
2626
2727OSDOBJS += \
28   $(MESS_WINOBJ)/configms.o   \
2928   $(MESS_WINOBJ)/dialog.o   \
3029   $(MESS_WINOBJ)/menu.o      \
3130   $(MESS_WINOBJ)/mess.res   \
r7335r7336
3433$(LIBOSD): $(OSDOBJS)
3534
3635OSDCOREOBJS += \
37   $(OBJ)/mess/osd/windows/winmess.o   \
38   $(OBJ)/mess/osd/windows/winutils.o   \
39   $(OBJ)/mess/osd/windows/glob.o
36   $(OBJ)/mess/osd/windows/winutils.o
4037
4138$(LIBOCORE): $(OSDCOREOBJS)
4239
src/mess/osd/windows/winutils.h
r7335r7336
4949void win_scroll_window(HWND window, WPARAM wparam, int scroll_bar, int scroll_delta_line);
5050DWORD win_get_file_attributes_utf8(const char *filename);
5151
52/* expand wildcards so '*' can be used */
53void win_expand_wildcards(int *argc, char **argv[]);
54
5552#endif // WINUTILS_H
src/mess/osd/windows/menu.c
r7335r7336
1717#include "menu.h"
1818#include "ui.h"
1919#include "messres.h"
20#include "inputx.h"
2120#include "windows/video.h"
2221#include "windows/input.h"
2322#include "dialog.h"
2423#include "opcntrl.h"
25#include "mslegacy.h"
2624#include "strconv.h"
2725#include "utils.h"
2826#include "png.h"
r7335r7336
3129#include "devices/cassette.h"
3230#include "windows/window.h"
3331#include "uimess.h"
34#include "mslegacy.h"
3532#include "winutf8.h"
3633
3734#ifdef UNDER_CE
r7335r7336
519516//  customize_switches
520517//============================================================
521518
522static void customize_switches(running_machine *machine, HWND wnd, int title_string_num, UINT32 ipt_name)
519static void customize_switches(running_machine *machine, HWND wnd, const char* title_string, UINT32 ipt_name)
523520{
524521   dialog_box *dlg;
525522   const input_port_config *port;
r7335r7336
530527
531528   UINT32 type;
532529
533   dlg = win_dialog_init(ui_getstring(title_string_num), NULL);
530   dlg = win_dialog_init(title_string, NULL);
534531   if (!dlg)
535532      goto done;
536533
r7335r7336
576573
577574static void customize_dipswitches(running_machine *machine, HWND wnd)
578575{
579   customize_switches(machine, wnd, UI_dipswitches, IPT_DIPSWITCH);
576   customize_switches(machine, wnd, "Dip Switches", IPT_DIPSWITCH);
580577}
581578
582579
r7335r7336
587584
588585static void customize_configuration(running_machine *machine, HWND wnd)
589586{
590   customize_switches(machine, wnd, UI_configuration, IPT_CONFIG);
587   customize_switches(machine, wnd, "Driver Configuration", IPT_CONFIG);
591588}
592589
593590
r7335r7336
670667   char buf[255];
671668   static const struct dialog_layout layout = { 120, 52 };
672669
673   dlg = win_dialog_init(ui_getstring(UI_analogcontrols), &layout);
670   dlg = win_dialog_init("Analog Controls", &layout);
674671   if (!dlg)
675672      goto done;
676673
r7335r7336
684681            name = input_field_name(field);
685682
686683            _snprintf(buf, ARRAY_LENGTH(buf),
687               "%s %s", name, ui_getstring(UI_keyjoyspeed));
684               "%s %s", name, "Digital Speed");
688685            if (win_dialog_add_adjuster(dlg, buf, settings.delta, 1, 255, FALSE, store_delta, (void *) field))
689686               goto done;
690687
691688            _snprintf(buf, ARRAY_LENGTH(buf),
692               "%s %s", name, ui_getstring(UI_centerspeed));
689               "%s %s", name, "Autocenter Speed");
693690            if (win_dialog_add_adjuster(dlg, buf, settings.centerdelta, 1, 255, FALSE, store_centerdelta, (void *) field))
694691               goto done;
695692
696693            _snprintf(buf, ARRAY_LENGTH(buf),
697               "%s %s", name, ui_getstring(UI_reverse));
694               "%s %s", name, "Reverse");
698695            if (win_dialog_add_combobox(dlg, buf, settings.reverse ? 1 : 0, store_reverse, (void *) field))
699696               goto done;
700            if (win_dialog_add_combobox_item(dlg, ui_getstring(UI_off), 0))
697            if (win_dialog_add_combobox_item(dlg, "Off", 0))
701698               goto done;
702            if (win_dialog_add_combobox_item(dlg, ui_getstring(UI_on), 1))
699            if (win_dialog_add_combobox_item(dlg, "On", 1))
703700               goto done;
704701
705702            _snprintf(buf, ARRAY_LENGTH(buf),
706               "%s %s", name, ui_getstring(UI_sensitivity));
703               "%s %s", name, "Sensitivity");
707704            if (win_dialog_add_adjuster(dlg, buf, settings.sensitivity, 1, 255, TRUE, store_sensitivity, (void *) field))
708705               goto done;
709706         }
r7335r7336
13131310//  append_menu_uistring
13141311//============================================================
13151312
1316static void append_menu_uistring(HMENU menu, UINT flags, UINT_PTR id, int uistring)
1313static void append_menu_uistring(HMENU menu, UINT flags, UINT_PTR id, const char *uistring)
13171314{
1318   append_menu_utf8(menu, flags, id, (uistring >= 0) ? ui_getstring(uistring) : NULL);
1315   append_menu_utf8(menu, flags, id, uistring);
13191316}
13201317
13211318
r7335r7336
15351532#endif
15361533
15371534   set_command_state(menu_bar, ID_KEYBOARD_EMULATED,      (has_keyboard) ?
1538                                                (!ui_mess_get_use_natural_keyboard(window->machine)               ? MFS_CHECKED : MFS_ENABLED)
1535                                                (!ui_get_use_natural_keyboard(window->machine)               ? MFS_CHECKED : MFS_ENABLED)
15391536                                                                                    : MFS_GRAYED);
1540   set_command_state(menu_bar, ID_KEYBOARD_NATURAL,      (has_keyboard && inputx_can_post(window->machine)) ?                                                (ui_mess_get_use_natural_keyboard(window->machine)               ? MFS_CHECKED : MFS_ENABLED)
1537   set_command_state(menu_bar, ID_KEYBOARD_NATURAL,      (has_keyboard && inputx_can_post(window->machine)) ?                                                (ui_get_use_natural_keyboard(window->machine)               ? MFS_CHECKED : MFS_ENABLED)
15411538                                                                                    : MFS_GRAYED);
15421539   set_command_state(menu_bar, ID_KEYBOARD_CUSTOMIZE,      has_keyboard                        ? MFS_ENABLED : MFS_GRAYED);
15431540
r7335r7336
16191616            flags_for_writing |= MF_GRAYED;
16201617
16211618         sub_menu = CreateMenu();
1622         append_menu_uistring(sub_menu, MF_STRING,      new_item + DEVOPTION_OPEN,      UI_mount);
1619         append_menu_uistring(sub_menu, MF_STRING,      new_item + DEVOPTION_OPEN,      "Mount...");
16231620
16241621         if (info.creatable)
1625            append_menu_uistring(sub_menu, MF_STRING,   new_item + DEVOPTION_CREATE,   UI_create);
1622            append_menu_uistring(sub_menu, MF_STRING,   new_item + DEVOPTION_CREATE,   "Create...");
16261623
1627         append_menu_uistring(sub_menu, flags_for_exists,   new_item + DEVOPTION_CLOSE,   UI_unmount);
1624         append_menu_uistring(sub_menu, flags_for_exists,   new_item + DEVOPTION_CLOSE,   "Unmount");
16281625
16291626         if ((img->type == CASSETTE) && !strcmp(info.file_extensions, "wav"))
16301627         {
16311628            cassette_state state;
16321629            state = (cassette_state)(image_exists(img) ? (cassette_get_state(img) & CASSETTE_MASK_UISTATE) : CASSETTE_STOPPED);
1633            append_menu_uistring(sub_menu, MF_SEPARATOR, 0, -1);
1634            append_menu_uistring(sub_menu, flags_for_exists   | ((state == CASSETTE_STOPPED)   ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_STOPPAUSE,   UI_pauseorstop);
1635            append_menu_uistring(sub_menu, flags_for_exists   | ((state == CASSETTE_PLAY)      ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_PLAY,         UI_play);
1636            append_menu_uistring(sub_menu, flags_for_writing   | ((state == CASSETTE_RECORD)   ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_RECORD,      UI_record);
1637            append_menu_uistring(sub_menu, flags_for_exists,                                          new_item + DEVOPTION_CASSETTE_REWIND,      UI_rewind);
1638            append_menu_uistring(sub_menu, flags_for_exists,                                          new_item + DEVOPTION_CASSETTE_FASTFORWARD,   UI_fastforward);
1630            append_menu_uistring(sub_menu, MF_SEPARATOR, 0, NULL);
1631            append_menu_uistring(sub_menu, flags_for_exists   | ((state == CASSETTE_STOPPED)   ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_STOPPAUSE,   "Pause/Stop");
1632            append_menu_uistring(sub_menu, flags_for_exists   | ((state == CASSETTE_PLAY)      ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_PLAY,         "Play");
1633            append_menu_uistring(sub_menu, flags_for_writing   | ((state == CASSETTE_RECORD)   ? MF_CHECKED : 0),   new_item + DEVOPTION_CASSETTE_RECORD,      "Record");
1634            append_menu_uistring(sub_menu, flags_for_exists,                                          new_item + DEVOPTION_CASSETTE_REWIND,      "Rewind");
1635            append_menu_uistring(sub_menu, flags_for_exists,                                          new_item + DEVOPTION_CASSETTE_FASTFORWARD,   "Fast Forward");
16391636         }
1640         s = image_exists(img) ? image_filename(img) : ui_getstring(UI_emptyslot);
1637         s = image_exists(img) ? image_filename(img) : "[empty slot]";
16411638         flags = MF_POPUP;
16421639
16431640         snprintf(buf, ARRAY_LENGTH(buf), "%s: %s", image_typename_id(img), s);
r7335r7336
19341931         break;
19351932
19361933      case ID_KEYBOARD_NATURAL:
1937         ui_mess_set_use_natural_keyboard(window->machine, TRUE);
1934         ui_set_use_natural_keyboard(window->machine, TRUE);
19381935         break;
19391936
19401937      case ID_KEYBOARD_EMULATED:
1941         ui_mess_set_use_natural_keyboard(window->machine, FALSE);
1938         ui_set_use_natural_keyboard(window->machine, FALSE);
19421939         break;
19431940
19441941      case ID_KEYBOARD_CUSTOMIZE:
r7335r7336
22522249   HMENU menu_bar = NULL;
22532250   HMODULE module;
22542251
2255   if (ui_mess_use_new_ui())
2252   if (ui_use_new_ui())
22562253   {
22572254      module = win_resource_module();
22582255      menu_bar = LoadMenu(module, MAKEINTRESOURCE(IDR_RUNTIME_MENU));
r7335r7336
22912288         {
22922289            LONG_PTR ptr = GetWindowLongPtr(wnd, GWLP_USERDATA);
22932290            win_window_info *window = (win_window_info *)ptr;
2294            ui_mess_paste(window->machine);
2291            ui_paste(window->machine);
22952292         }
22962293         break;
22972294
src/mess/messopts.c
r7335r7336
77#include "emu.h"
88#include "emuopts.h"
99#include "options.h"
10#include "emu.h"
1110#include "pool.h"
1211#include "config.h"
1312#include "xmlfile.h"
1413#include "messopts.h"
15#include "osdmess.h"
1614
1715#define OPTION_ADDED_DEVICE_OPTIONS   "added_device_options"
1816
r7335r7336
3533   { NULL,                     NULL,   OPTION_HEADER,                  "MESS SPECIFIC OPTIONS" },
3634   { "ramsize;ram",            NULL,   0,                           "size of RAM (if supported by driver)" },
3735   { "writeconfig;wc",            "0",   OPTION_BOOLEAN,                  "writes configuration to (driver).ini on exit" },
36   { "newui;nu",                   "0",    OPTION_BOOLEAN,                  "use the new MESS UI" },   
3837   { OPTION_ADDED_DEVICE_OPTIONS,   "0",   OPTION_BOOLEAN | OPTION_INTERNAL,   "device-specific options have been added" },
39   { "natural;nat",            "0",   OPTION_BOOLEAN,                  "specifies whether to use a natural keyboard or not" },
4038   { NULL }
4139};
4240
r7335r7336
190188   /* add MESS-specific options */
191189   options_add_entries(opts, mess_core_options);
192190
193   /* add OSD-MESS specific options (hack!) */
194   osd_mess_options_init(opts);
195
196191   /* we need to dynamically add options when the device name is parsed */
197192   options_set_option_callback(opts, OPTION_GAMENAME, mess_driver_name_callback);
198193}
src/mess/messopts.h
r7335r7336
88#define __MESSOPTS_H__
99
1010#include "image.h"
11#include "options.h"
1112
1213/***************************************************************************
1314    CONSTANTS
r7335r7336
1516
1617#define OPTION_RAMSIZE         "ramsize"
1718#define OPTION_WRITECONFIG      "writeconfig"
18#define OPTION_NATURAL_KEYBOARD   "natural"
1919
2020
2121
src/mess/drivers/apexc.c
r7335r7336
77*/
88
99#include "emu.h"
10#include "mslegacy.h"
1110#include "cpu/apexc/apexc.h"
1211
1312

Previous 15994 Revisions Next


© 1998-2018 The MESS Team