Previous 15994 Revisions Next

r7351 Sunday 14th February, 2010 at 12:46:03 UTC by Miodrag Milanović
Cleaned natural keyboard implementation
[src/emu]inptport.c inptport.h ui.c uimenu.c

src/emu/uimenu.c
r7350r7351
15361536#endif /* MESS */
15371537
15381538     /* 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);
1539     if (input_machine_has_keyboard(machine) && inputx_can_post(machine))
1540      ui_menu_item_append(menu, "Keyboard Mode", NULL, 0, (void *)ui_menu_keyboard_mode);
15411541
15421542   /* add sliders menu */
15431543   ui_menu_item_append(menu, "Slider Controls", NULL, 0, (void *)menu_sliders);
src/emu/inptport.c
r7350r7351
269269   UINT32                  playback_accumulated_frames;/* accumulated frames during playback */
270270};
271271
272typedef const input_port_config *input_port_config_c;
273typedef const input_field_config *input_field_config_c;
274272
275
276273typedef struct _inputx_code inputx_code;
277274struct _inputx_code
278275{
279276   unicode_char ch;
280   input_field_config_c field[NUM_SIMUL_KEYS];
277   const input_field_config * field[NUM_SIMUL_KEYS];
281278};
282279
283280typedef struct _key_buffer key_buffer;
r7350r7351
19131910   return ch;
19141911}
19151912
1913/***************************************************************************
1914    MISCELLANEOUS
1915***************************************************************************/
1916
19161917/*-------------------------------------------------
1918    find_charinfo - looks up information about a
1919    particular character
1920-------------------------------------------------*/
1921
1922static const char_info *find_charinfo(unicode_char target_char)
1923{
1924   int low = 0;
1925   int high = ARRAY_LENGTH(charinfo);
1926   int i;
1927   unicode_char ch;
1928
1929   /* perform a simple binary search to find the proper alternate */
1930   while(high > low)
1931   {
1932      i = (high + low) / 2;
1933      ch = charinfo[i].ch;
1934      if (ch < target_char)
1935         low = i + 1;
1936      else if (ch > target_char)
1937         high = i;
1938      else
1939         return &charinfo[i];
1940   }
1941   return NULL;
1942}
1943
1944/*-------------------------------------------------
1945    inputx_key_name - returns the name of a
1946    specific key
1947-------------------------------------------------*/
1948
1949static const char *inputx_key_name(unicode_char ch)
1950{
1951   static char buf[UTF8_CHAR_MAX + 1];
1952   const char_info *ci;
1953   const char *result;
1954   int pos;
1955
1956   ci = find_charinfo(ch);
1957   result = ci ? ci->name : NULL;
1958
1959   if (ci && ci->name)
1960   {
1961      result = ci->name;
1962   }
1963   else
1964   {
1965      if ((ch > 0x7F) || isprint(ch))
1966      {
1967         pos = utf8_from_uchar(buf, ARRAY_LENGTH(buf), ch);
1968         buf[pos] = '\0';
1969         result = buf;
1970      }
1971      else
1972         result = "???";
1973   }
1974   return result;
1975}
1976
1977/*-------------------------------------------------
19171978    get_keyboard_key_name - builds the name of
19181979    a key based on natural keyboard characters
19191980-------------------------------------------------*/
r7350r7351
46414702   }
46424703}
46434704
4644int input_machine_have_keyboard(running_machine *machine)
4705int input_machine_has_keyboard(running_machine *machine)
46454706{
46464707   const input_field_config *field;
46474708   const input_port_config *port;
r7350r7351
46594720}
46604721
46614722/***************************************************************************
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/***************************************************************************
46954723    CODE ASSEMBLING
46964724***************************************************************************/
46974725
r7350r7351
47474775    sets up natural keyboard input mapping
47484776-------------------------------------------------*/
47494777
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)
4778static int scan_keys(running_machine *machine, const input_port_config *portconfig, inputx_code *codes, const input_port_config * *ports, const input_field_config * *shift_ports, int keys, int shift)
47514779{
47524780   int code_count = 0;
47534781   const input_port_config *port;
r7350r7351
49114939   }
49124940
49134941   /* posting keys directly only makes sense for a computer */
4914   if (input_machine_have_keyboard(machine))
4942   if (input_machine_has_keyboard(machine))
49154943   {
49164944      codes = build_codes(machine, machine->portlist.first());
49174945      setup_keybuffer(machine);
r7350r7351
49805008   return 1;
49815009}
49825010
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
49925011static attotime choose_delay(unicode_char ch)
49935012{
49945013   attoseconds_t delay = 0;
r7350r7351
50465065
50475066
50485067
5049void inputx_postn_rate(running_machine *machine, const unicode_char *text, size_t text_len, attotime rate)
5068static void inputx_postn_rate(running_machine *machine, const unicode_char *text, size_t text_len, attotime rate)
50505069{
50515070   int last_cr = 0;
50525071   unicode_char ch;
r7350r7351
51475166   }
51485167}
51495168
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
51875169int inputx_is_posting(running_machine *machine)
51885170{
51895171   const key_buffer *keybuf;
r7350r7351
51915173   return (keybuf->begin_pos != keybuf->end_pos) || (charqueue_empty && !charqueue_empty());
51925174}
51935175
5194
5195
51965176/***************************************************************************
51975177
51985178    Coded input
51995179
52005180***************************************************************************/
5181static void inputx_postc_rate(running_machine *machine, unicode_char ch, attotime rate);
52015182
5202void inputx_postn_coded_rate(running_machine *machine, const char *text, size_t text_len, attotime rate)
5183static void inputx_postn_coded_rate(running_machine *machine, const char *text, size_t text_len, attotime rate)
52035184{
52045185   size_t i, j, key_len, increment;
52055186   unicode_char ch;
r7350r7351
52765257
52775258***************************************************************************/
52785259
5279void inputx_postn(running_machine *machine, const unicode_char *text, size_t text_len)
5260static void inputx_postc_rate(running_machine *machine, unicode_char ch, attotime rate)
52805261{
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{
53055262   inputx_postn_rate(machine, &ch, 1, rate);
53065263}
53075264
5308
5309
53105265void inputx_postc(running_machine *machine, unicode_char ch)
53115266{
53125267   inputx_postc_rate(machine, ch, attotime_make(0, 0));
53135268}
53145269
5315
5316
5317void inputx_postn_utf16_rate(running_machine *machine, const utf16_char *text, size_t text_len, attotime rate)
5270static void inputx_postn_utf8_rate(running_machine *machine, const char *text, size_t text_len, attotime rate)
53185271{
53195272   size_t len = 0;
5320   unicode_char c;
5321   utf16_char w1, w2;
53225273   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];
54005274   unicode_char c;
54015275   int rc;
54025276
r7350r7351
54045278   {
54055279      if (len == ARRAY_LENGTH(buf))
54065280      {
5407         inputx_postn(machine, buf, len);
5281         inputx_postn_rate(machine, buf, len, attotime_make(0, 0));
54085282         len = 0;
54095283      }
54105284
r7350r7351
54215295   inputx_postn_rate(machine, buf, len, rate);
54225296}
54235297
5424
5425
5426void inputx_postn_utf8(running_machine *machine, const char *text, size_t text_len)
5298void inputx_post_utf8(running_machine *machine, const char *text)
54275299{
5428   inputx_postn_utf8_rate(machine, text, text_len, attotime_make(0, 0));
5300   inputx_postn_utf8_rate(machine, text, strlen(text), attotime_make(0, 0));
54295301}
54305302
5431
5432
54335303void inputx_post_utf8_rate(running_machine *machine, const char *text, attotime rate)
54345304{
54355305   inputx_postn_utf8_rate(machine, text, strlen(text), rate);
5436}
5306} 
54375307
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
54685308/***************************************************************************
54695309
54705310    Other stuff
r7350r7351
56535493
56545494static void execute_input(running_machine *machine, int ref, int params, const char *param[])
56555495{
5656   inputx_post_coded(machine, param[0]);
5496   inputx_postn_coded_rate(machine, param[0], strlen(param[0]), attotime_make(0, 0));
56575497}
56585498
56595499
src/emu/inptport.h
r7350r7351
11561156const char *input_port_string_from_token(const input_port_token token);
11571157
11581158/* return TRUE if machine use full keyboard emulation */
1159int input_machine_have_keyboard(running_machine *machine);
1159int input_machine_has_keyboard(running_machine *machine);
11601160
11611161/* these are called by the core; they should not be called from FEs */
11621162void inputx_init(running_machine *machine);
r7350r7351
11721172
11731173/* these can be called from FEs */
11741174int 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);
11781175
11791176/* 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);
11821177void 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);
11901178void inputx_post_utf8(running_machine *machine, const char *text);
11911179void 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);
1180int inputx_is_posting(running_machine *machine);
11981181
11991182/* miscellaneous functions */
12001183int input_classify_port(const input_field_config *field);
src/emu/ui.c
r7350r7351
931931      string.cat("There are known problems with this " GAMENOUN "\n\n");
932932
933933      /* add one line per warning flag */
934      if (input_machine_have_keyboard(machine))
934      if (input_machine_has_keyboard(machine))
935935         string.cat("The keyboard emulation may not be 100% accurate.\n");
936936      if (machine->gamedrv->flags & GAME_IMPERFECT_COLORS)
937937         string.cat("The colors aren't 100% accurate.\n");
r7350r7351
13001300   }
13011301
13021302   /* 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);
1303   int ui_disabled = ui_use_new_ui() || (input_machine_has_keyboard(machine) && !ui_active);
13041304
13051305   /* is ScrLk UI toggling applicable here? */
1306   if (!ui_use_new_ui() && input_machine_have_keyboard(machine))
1306   if (!ui_use_new_ui() && input_machine_has_keyboard(machine))
13071307   {
13081308      /* are we toggling the UI with ScrLk? */
13091309      if (ui_input_pressed(machine, IPT_UI_TOGGLE_UI))

Previous 15994 Revisions Next


© 1998-2018 The MESS Team