Previous 15994 Revisions Next

r2484 Saturday 26th April, 2008 at 17:23:05 UTC by Nathan Woods
Created a 'dumpkbd' debugger command to dump all natural keyboard info.
[docs]messnew.txt
[src/mess]inputx.c

src/mess/inputx.c
r2483r2484
2525
2626#define NUM_SIMUL_KEYS   (UCHAR_SHIFT_END - UCHAR_SHIFT_BEGIN + 1)
2727#define LOG_INPUTX      0
28#define DUMP_CODES      0
2928#define SPACE_COUNT      3
3029
3130
r2483r2484
381380
382381***************************************************************************/
383382
384static const char *charstr(unicode_char ch)
383/*-------------------------------------------------
384    code_point_string - obtain a string representation of a
385   given code; used for logging and debugging
386-------------------------------------------------*/
387
388static const char *code_point_string(unicode_char ch)
385389{
386390   static char buf[16];
387391   const char *result = buf;
388392
389393   switch(ch)
390394   {
395      /* check some magic values */
391396      case '\0':   strcpy(buf, "\\0");      break;
392397      case '\r':   strcpy(buf, "\\r");      break;
393398      case '\n':   strcpy(buf, "\\n");      break;
394399      case '\t':   strcpy(buf, "\\t");      break;
395400
396401      default:
397         if (ch < 128)
402         if ((ch >= 32) && (ch < 128))
398403         {
404            /* seven bit ASCII is easy */
399405            buf[0] = (char) ch;
400406            buf[1] = '\0';
401407         }
402         else if ((ch >= UCHAR_MAMEKEY_BEGIN) && (ch < UCHAR_MAMEKEY_BEGIN + 1024))
408         else if (ch >= UCHAR_MAMEKEY_BEGIN)
403409         {
410            /* try to obtain a codename with input_code_name(); this can result in an empty string */
404411            astring *astr = astring_alloc();
405412            input_code_name(astr, (input_code) ch - UCHAR_MAMEKEY_BEGIN);
406413            snprintf(buf, ARRAY_LENGTH(buf), "%s", astring_c(astr));
r2483r2484
408415         }
409416         else
410417         {
418            /* empty string; resolve later */
419            buf[0] = '\0';
420         }
421
422         /* did we fail to resolve? if so, we have a last resort */
423         if (buf[0] == '\0')
411424            snprintf(buf, ARRAY_LENGTH(buf), "U+%04X", (unsigned) ch);
412         }
413425         break;
414426   }
415427   return result;
r2483r2484
467479                  code_count++;
468480
469481                  if (LOG_INPUTX)
470                     logerror("inputx: code=%i (%s) port=%i ipt->name='%s'\n", (int) code, charstr(code), port, ipt->name);
482                     logerror("inputx: code=%i (%s) port=%i ipt->name='%s'\n", (int) code, code_point_string(code), port, ipt->name);
471483               }
472484            }
473485            break;
r2483r2484
595607
596608
597609/***************************************************************************
598
599   Core
600
610    CORE IMPLEMENTATION
601611***************************************************************************/
602612
603613static mess_input_code *codes;
r2483r2484
613623
614624
615625#ifdef ENABLE_DEBUGGER
616static void execute_input(int ref, int params, const char *param[])
617{
618   inputx_post_coded(param[0]);
619}
626static void execute_input(int ref, int params, const char *param[]);
627static void execute_dumpkbd(int ref, int params, const char *param[]);
620628#endif /* ENABLE_DEBUGGER */
621629
622630
r2483r2484
640648
641649
642650
643/*-------------------------------------------------
644    dump_codes - output all natural keyboard data
645   to a text file
646-------------------------------------------------*/
647
648static void dump_codes(void)
649{
650   FILE *f;
651   int i;
652
653   f = fopen("codes.txt", "w");
654   if (!f)
655      return;
656
657   if (codes)
658   {
659      for (i = 0; codes[i].ch; i++)
660      {
661         fprintf(f, "%-10d (%s)\n", codes[i].ch, charstr(codes[i].ch));
662      }
663   }
664   fclose(f);
665}
666
667
668
669651void inputx_init(running_machine *machine)
670652{
671653   codes = NULL;
r2483r2484
677659
678660#ifdef ENABLE_DEBUGGER
679661   if (machine->debug_mode)
662   {
680663      debug_console_register_command("input", CMDFLAG_NONE, 0, 1, 1, execute_input);
664      debug_console_register_command("dumpkbd", CMDFLAG_NONE, 0, 0, 1, execute_dumpkbd);
665   }
681666#endif /* ENABLE_DEBUGGER */
682667
683668   /* posting keys directly only makes sense for a computer */
684669   if (machine->gamedrv->flags & GAME_COMPUTER)
685670   {
686671      codes = build_codes(machine->input_ports);
687      if (DUMP_CODES)
688         dump_codes();
689672      setup_keybuffer(machine);
690673   }
691674}
r2483r2484
868851            if (LOG_INPUTX)
869852            {
870853               code = find_code(ch);
871               logerror("inputx_postn(): code=%i (%s) port=%i ipt->name='%s'\n", (int) ch, charstr(ch), code ? code->port[0] : -1, (code && code->ipt[0]) ? code->ipt[0]->name : "<null>");
854               logerror("inputx_postn(): code=%i (%s) port=%i ipt->name='%s'\n", (int) ch, code_point_string(ch), code ? code->port[0] : -1, (code && code->ipt[0]) ? code->ipt[0]->name : "<null>");
872855            }
873856
874857            if (can_post_key_directly(ch))
r2483r2484
14751458   }
14761459   return FALSE;
14771460}
1461
1462
1463
1464/***************************************************************************
1465    DEBUGGER SUPPORT
1466***************************************************************************/
1467
1468/*-------------------------------------------------
1469    execute_input - debugger command to enter
1470   natural keyboard input
1471-------------------------------------------------*/
1472
1473#ifdef ENABLE_DEBUGGER
1474static void execute_input(int ref, int params, const char *param[])
1475{
1476   inputx_post_coded(param[0]);
1477}
1478#endif /* ENABLE_DEBUGGER */
1479
1480
1481
1482/*-------------------------------------------------
1483    execute_dumpkbd - debugger command to natural
1484   keyboard codes
1485-------------------------------------------------*/
1486
1487#ifdef ENABLE_DEBUGGER
1488static void execute_dumpkbd(int ref, int params, const char *param[])
1489{
1490   const char *filename;
1491   FILE *file = NULL;
1492   const mess_input_code *code;
1493   char buffer[512];
1494   size_t pos;
1495   int i, j;
1496   size_t left_column_width = 24;
1497
1498   /* was there a file specified? */
1499   filename = (params > 0) ? param[0] : NULL;
1500   if (filename != NULL)
1501   {
1502      /* if so, open it */
1503      file = fopen(filename, "w");
1504      if (file == NULL)
1505      {
1506         debug_console_printf("Cannot open \"%s\"\n", filename);
1507         return;
1508      }
1509   }
1510
1511   if ((codes != NULL) && (codes[0].ch != 0))
1512   {
1513      /* loop through all codes */
1514      for (i = 0; codes[i].ch; i++)
1515      {
1516         code = &codes[i];
1517         pos = 0;
1518
1519         /* describe the character code */
1520         pos += snprintf(&buffer[pos], ARRAY_LENGTH(buffer) - pos, "%08X (%s) ",
1521            code->ch,
1522            code_point_string(code->ch));
1523
1524         /* pad with spaces */
1525         while(pos < left_column_width)
1526            buffer[pos++] = ' ';
1527         buffer[pos] = '\0';
1528
1529         /* identify the keys used */
1530         for (j = 0; j < ARRAY_LENGTH(code->ipt) && (code->ipt[j] != NULL); j++)
1531         {
1532            pos += snprintf(&buffer[pos], ARRAY_LENGTH(buffer) - pos, "%s'%s'",
1533               (j > 0) ? ", " : "",
1534               code->ipt[j]->name);
1535         }
1536
1537         /* and output it as appropriate */
1538         if (file != NULL)
1539            fprintf(file, "%s\n", buffer);
1540         else
1541            debug_console_printf("%s\n", buffer);
1542      }
1543   }
1544   else
1545   {
1546      debug_console_printf("No natural keyboard support\n");
1547   }
1548
1549   /* cleanup */
1550   if (file != NULL)
1551      fclose(file);
1552
1553}
1554#endif /* ENABLE_DEBUGGER */
docs/messnew.txt
r2483r2484
104104- Clarified error message when MESS fails to load because of a device that is
105105  expected to be present.  (bug #1493)  [Nate Woods]
106106
107- Created a 'dumpkbd' debugger command to dump all natural keyboard info.
108  [Nate Woods]
107109
108110
111
1091120.124a
110113
111114New System Drivers Supported (in no particular order):

Previous 15994 Revisions Next


© 1998-2018 The MESS Team