Added the ability to remap scan codes in the configuration file.
This commit is contained in:
43
src/config.c
43
src/config.c
@@ -154,6 +154,25 @@ load_global(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Load scan code mappings. */
|
||||||
|
static void
|
||||||
|
load_scan_code_mappings(void)
|
||||||
|
{
|
||||||
|
ini_section_t cat = ini_find_section(config, "Scan code mappings");
|
||||||
|
char temp[512];
|
||||||
|
|
||||||
|
for (int c = 0; c < 768; c++) {
|
||||||
|
sprintf(temp, "scan_code_mapping_%03X", c);
|
||||||
|
|
||||||
|
int mapping = ini_section_get_hex12(cat, temp, c);
|
||||||
|
|
||||||
|
if (mapping == c)
|
||||||
|
ini_section_delete_var(cat, temp);
|
||||||
|
else
|
||||||
|
scancode_config_map[c] = mapping;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Load "General" section. */
|
/* Load "General" section. */
|
||||||
static void
|
static void
|
||||||
load_general(void)
|
load_general(void)
|
||||||
@@ -2091,6 +2110,9 @@ config_load(void)
|
|||||||
#endif
|
#endif
|
||||||
memset(rdisk_drives, 0, sizeof(rdisk_drive_t));
|
memset(rdisk_drives, 0, sizeof(rdisk_drive_t));
|
||||||
|
|
||||||
|
for (int i = 0; i < 768; i++)
|
||||||
|
scancode_config_map[i] = i;
|
||||||
|
|
||||||
config = ini_read(cfg_path);
|
config = ini_read(cfg_path);
|
||||||
|
|
||||||
if (config == NULL) {
|
if (config == NULL) {
|
||||||
@@ -2167,6 +2189,7 @@ config_load(void)
|
|||||||
load_general(); /* General */
|
load_general(); /* General */
|
||||||
for (i = 0; i < MONITORS_NUM; i++)
|
for (i = 0; i < MONITORS_NUM; i++)
|
||||||
load_monitor(i); /* Monitors */
|
load_monitor(i); /* Monitors */
|
||||||
|
load_scan_code_mappings(); /* Scan code mappings */
|
||||||
load_machine(); /* Machine */
|
load_machine(); /* Machine */
|
||||||
load_video(); /* Video */
|
load_video(); /* Video */
|
||||||
load_input_devices(); /* Input devices */
|
load_input_devices(); /* Input devices */
|
||||||
@@ -2275,6 +2298,25 @@ save_global(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Save scan code mappings. */
|
||||||
|
static void
|
||||||
|
save_scan_code_mappings(void)
|
||||||
|
{
|
||||||
|
ini_section_t cat = ini_find_section(config, "Scan code mappings");
|
||||||
|
char temp[512];
|
||||||
|
|
||||||
|
for (int c = 0; c < 768; c++) {
|
||||||
|
sprintf(temp, "scan_code_mapping_%03X", c);
|
||||||
|
|
||||||
|
if (scancode_config_map[c] == c)
|
||||||
|
ini_section_delete_var(cat, temp);
|
||||||
|
else
|
||||||
|
ini_section_set_hex12(cat, temp, scancode_config_map[c]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ini_delete_section_if_empty(config, cat);
|
||||||
|
}
|
||||||
|
|
||||||
/* Save "General" section. */
|
/* Save "General" section. */
|
||||||
static void
|
static void
|
||||||
save_general(void)
|
save_general(void)
|
||||||
@@ -3571,6 +3613,7 @@ config_save(void)
|
|||||||
save_general(); /* General */
|
save_general(); /* General */
|
||||||
for (uint8_t i = 0; i < MONITORS_NUM; i++)
|
for (uint8_t i = 0; i < MONITORS_NUM; i++)
|
||||||
save_monitor(i); /* Monitors */
|
save_monitor(i); /* Monitors */
|
||||||
|
save_scan_code_mappings(); /* Scan code mappings */
|
||||||
save_machine(); /* Machine */
|
save_machine(); /* Machine */
|
||||||
save_video(); /* Video */
|
save_video(); /* Video */
|
||||||
save_input_devices(); /* Input devices */
|
save_input_devices(); /* Input devices */
|
||||||
|
|||||||
@@ -33,7 +33,8 @@
|
|||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
|
|
||||||
uint16_t scancode_map[768] = { 0 };
|
uint16_t scancode_map[768] = { 0 };
|
||||||
|
uint16_t scancode_config_map[768] = { 0 };
|
||||||
|
|
||||||
int keyboard_scan;
|
int keyboard_scan;
|
||||||
|
|
||||||
@@ -89,11 +90,11 @@ kbc_at_log(const char* fmt, ...)
|
|||||||
|
|
||||||
void (*keyboard_send)(uint16_t val);
|
void (*keyboard_send)(uint16_t val);
|
||||||
|
|
||||||
static int recv_key[512] = { 0 }; /* keyboard input buffer */
|
static int recv_key[768] = { 0 }; /* keyboard input buffer */
|
||||||
static int recv_key_ui[512] = { 0 }; /* keyboard input buffer */
|
static int recv_key_ui[768] = { 0 }; /* keyboard input buffer */
|
||||||
static int oldkey[512];
|
static int oldkey[768];
|
||||||
#if 0
|
#if 0
|
||||||
static int keydelay[512];
|
static int keydelay[768];
|
||||||
#endif
|
#endif
|
||||||
static scancode *scan_table; /* scancode table for keyboard */
|
static scancode *scan_table; /* scancode table for keyboard */
|
||||||
|
|
||||||
@@ -202,6 +203,8 @@ key_process(uint16_t scan, int down)
|
|||||||
if (!keyboard_scan || (keyboard_send == NULL))
|
if (!keyboard_scan || (keyboard_send == NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
scan = scancode_config_map[scan];
|
||||||
|
|
||||||
oldkey[scan] = down;
|
oldkey[scan] = down;
|
||||||
|
|
||||||
kbc_at_log("Key %04X,%d in process\n", scan, down);
|
kbc_at_log("Key %04X,%d in process\n", scan, down);
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ extern uint32_t ini_section_get_uint(ini_section_t section, const char *name, ui
|
|||||||
extern float ini_section_get_float(ini_section_t section, const char *name, float def);
|
extern float ini_section_get_float(ini_section_t section, const char *name, float def);
|
||||||
#endif
|
#endif
|
||||||
extern double ini_section_get_double(ini_section_t section, const char *name, double def);
|
extern double ini_section_get_double(ini_section_t section, const char *name, double def);
|
||||||
|
extern int ini_section_get_hex12(ini_section_t section, const char *name, int def);
|
||||||
extern int ini_section_get_hex16(ini_section_t section, const char *name, int def);
|
extern int ini_section_get_hex16(ini_section_t section, const char *name, int def);
|
||||||
extern int ini_section_get_hex20(ini_section_t section, const char *name, int def);
|
extern int ini_section_get_hex20(ini_section_t section, const char *name, int def);
|
||||||
extern int ini_section_get_mac(ini_section_t section, const char *name, int def);
|
extern int ini_section_get_mac(ini_section_t section, const char *name, int def);
|
||||||
@@ -54,6 +55,7 @@ extern void ini_section_set_uint(ini_section_t section, const char *name, ui
|
|||||||
extern void ini_section_set_float(ini_section_t section, const char *name, float val);
|
extern void ini_section_set_float(ini_section_t section, const char *name, float val);
|
||||||
#endif
|
#endif
|
||||||
extern void ini_section_set_double(ini_section_t section, const char *name, double val);
|
extern void ini_section_set_double(ini_section_t section, const char *name, double val);
|
||||||
|
extern void ini_section_set_hex12(ini_section_t section, const char *name, int val);
|
||||||
extern void ini_section_set_hex16(ini_section_t section, const char *name, int val);
|
extern void ini_section_set_hex16(ini_section_t section, const char *name, int val);
|
||||||
extern void ini_section_set_hex20(ini_section_t section, const char *name, int val);
|
extern void ini_section_set_hex20(ini_section_t section, const char *name, int val);
|
||||||
extern void ini_section_set_mac(ini_section_t section, const char *name, int val);
|
extern void ini_section_set_mac(ini_section_t section, const char *name, int val);
|
||||||
@@ -69,6 +71,7 @@ extern int ini_has_entry(ini_section_t self, const char *name);
|
|||||||
#define ini_get_float(ini, head, name, def) ini_section_get_float(ini_find_section(ini, head), name, def)
|
#define ini_get_float(ini, head, name, def) ini_section_get_float(ini_find_section(ini, head), name, def)
|
||||||
#endif
|
#endif
|
||||||
#define ini_get_double(ini, head, name, def) ini_section_get_double(ini_find_section(ini, head), name, def)
|
#define ini_get_double(ini, head, name, def) ini_section_get_double(ini_find_section(ini, head), name, def)
|
||||||
|
#define ini_get_hex12(ini, head, name, def) ini_section_get_hex12(ini_find_section(ini, head), name, def)
|
||||||
#define ini_get_hex16(ini, head, name, def) ini_section_get_hex16(ini_find_section(ini, head), name, def)
|
#define ini_get_hex16(ini, head, name, def) ini_section_get_hex16(ini_find_section(ini, head), name, def)
|
||||||
#define ini_get_hex20(ini, head, name, def) ini_section_get_hex20(ini_find_section(ini, head), name, def)
|
#define ini_get_hex20(ini, head, name, def) ini_section_get_hex20(ini_find_section(ini, head), name, def)
|
||||||
#define ini_get_mac(ini, head, name, def) ini_section_get_mac(ini_find_section(ini, head), name, def)
|
#define ini_get_mac(ini, head, name, def) ini_section_get_mac(ini_find_section(ini, head), name, def)
|
||||||
@@ -81,6 +84,7 @@ extern int ini_has_entry(ini_section_t self, const char *name);
|
|||||||
#define ini_set_float(ini, head, name, val) ini_section_set_float(ini_find_or_create_section(ini, head), name, val)
|
#define ini_set_float(ini, head, name, val) ini_section_set_float(ini_find_or_create_section(ini, head), name, val)
|
||||||
#endif
|
#endif
|
||||||
#define ini_set_double(ini, head, name, val) ini_section_set_double(ini_find_or_create_section(ini, head), name, val)
|
#define ini_set_double(ini, head, name, val) ini_section_set_double(ini_find_or_create_section(ini, head), name, val)
|
||||||
|
#define ini_set_hex12(ini, head, name, val) ini_section_set_hex12(ini_find_or_create_section(ini, head), name, val)
|
||||||
#define ini_set_hex16(ini, head, name, val) ini_section_set_hex16(ini_find_or_create_section(ini, head), name, val)
|
#define ini_set_hex16(ini, head, name, val) ini_section_set_hex16(ini_find_or_create_section(ini, head), name, val)
|
||||||
#define ini_set_hex20(ini, head, name, val) ini_section_set_hex20(ini_find_or_create_section(ini, head), name, val)
|
#define ini_set_hex20(ini, head, name, val) ini_section_set_hex20(ini_find_or_create_section(ini, head), name, val)
|
||||||
#define ini_set_mac(ini, head, name, val) ini_section_set_mac(ini_find_or_create_section(ini, head), name, val)
|
#define ini_set_mac(ini, head, name, val) ini_section_set_mac(ini_find_or_create_section(ini, head), name, val)
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ extern uint8_t keyboard_mode;
|
|||||||
extern int keyboard_scan;
|
extern int keyboard_scan;
|
||||||
|
|
||||||
extern uint16_t scancode_map[768];
|
extern uint16_t scancode_map[768];
|
||||||
|
extern uint16_t scancode_config_map[768];
|
||||||
|
|
||||||
extern void (*keyboard_send)(uint16_t val);
|
extern void (*keyboard_send)(uint16_t val);
|
||||||
extern void kbd_adddata_process(uint16_t val, void (*adddata)(uint16_t val));
|
extern void kbd_adddata_process(uint16_t val, void (*adddata)(uint16_t val));
|
||||||
|
|||||||
@@ -782,6 +782,25 @@ ini_section_get_double(ini_section_t self, const char *name, double def)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ini_section_get_hex12(ini_section_t self, const char *name, int def)
|
||||||
|
{
|
||||||
|
section_t *section = (section_t *) self;
|
||||||
|
const entry_t *entry;
|
||||||
|
unsigned int value = 0;
|
||||||
|
|
||||||
|
if (section == NULL)
|
||||||
|
return def;
|
||||||
|
|
||||||
|
entry = find_entry(section, name);
|
||||||
|
if (entry == NULL)
|
||||||
|
return def;
|
||||||
|
|
||||||
|
sscanf(entry->data, "%03X", &value);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ini_section_get_hex16(ini_section_t self, const char *name, int def)
|
ini_section_get_hex16(ini_section_t self, const char *name, int def)
|
||||||
{
|
{
|
||||||
@@ -943,6 +962,23 @@ ini_section_set_double(ini_section_t self, const char *name, double val)
|
|||||||
mbstowcs(ent->wdata, ent->data, 512);
|
mbstowcs(ent->wdata, ent->data, 512);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ini_section_set_hex12(ini_section_t self, const char *name, int val)
|
||||||
|
{
|
||||||
|
section_t *section = (section_t *) self;
|
||||||
|
entry_t *ent;
|
||||||
|
|
||||||
|
if (section == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ent = find_entry(section, name);
|
||||||
|
if (ent == NULL)
|
||||||
|
ent = create_entry(section, name);
|
||||||
|
|
||||||
|
sprintf(ent->data, "%03X", val);
|
||||||
|
mbstowcs(ent->wdata, ent->data, sizeof_w(ent->wdata));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ini_section_set_hex16(ini_section_t self, const char *name, int val)
|
ini_section_set_hex16(ini_section_t self, const char *name, int val)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user