Joystick: per-core button map. Core can provide buttons names.
This commit is contained in:
27
ini_parser.c
27
ini_parser.c
@@ -117,29 +117,6 @@ int ini_putline(char* line)
|
||||
return ini_pt;
|
||||
}
|
||||
|
||||
char *get_core_name()
|
||||
{
|
||||
switch (user_io_core_type())
|
||||
{
|
||||
case CORE_TYPE_MINIMIG2:
|
||||
return "MINIMIG";
|
||||
|
||||
case CORE_TYPE_PACE:
|
||||
return "PACE";
|
||||
|
||||
case CORE_TYPE_MIST:
|
||||
return "ST";
|
||||
|
||||
case CORE_TYPE_ARCHIE:
|
||||
return "ARCHIE";
|
||||
|
||||
case CORE_TYPE_8BIT:
|
||||
return user_io_get_core_name();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
//// ini_get_section() ////
|
||||
int ini_get_section(const ini_cfg_t* cfg, char* buf)
|
||||
{
|
||||
@@ -177,7 +154,7 @@ int ini_get_section(const ini_cfg_t* cfg, char* buf)
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcasecmp(buf, get_core_name())) return cfg->sections[0].id;
|
||||
if (!strcasecmp(buf, user_io_get_core_name_ex())) return cfg->sections[0].id;
|
||||
|
||||
return INI_SECTION_INVALID_ID;
|
||||
}
|
||||
@@ -271,7 +248,7 @@ void ini_parse(const ini_cfg_t* cfg)
|
||||
int section = INI_SECTION_INVALID_ID;
|
||||
int line_status;
|
||||
|
||||
ini_parser_debugf("Start INI parser for core \"%s\".", get_core_name());
|
||||
ini_parser_debugf("Start INI parser for core \"%s\".", user_io_get_core_name_ex());
|
||||
|
||||
memset(&ini_file, 0, sizeof(ini_file));
|
||||
if (!FileOpen(&ini_file, cfg->filename))
|
||||
|
||||
47
input.c
47
input.c
@@ -438,15 +438,17 @@ int toggle_kbdled(int mask)
|
||||
return state;
|
||||
}
|
||||
|
||||
int mapping = 0;
|
||||
int mapping_button;
|
||||
int mapping_dev;
|
||||
static int mapping = 0;
|
||||
static int mapping_button;
|
||||
static int mapping_dev;
|
||||
static int mapping_count;
|
||||
|
||||
void start_map_setting()
|
||||
void start_map_setting(int cnt)
|
||||
{
|
||||
mapping_button = 0;
|
||||
mapping = 1;
|
||||
mapping_dev = -1;
|
||||
mapping_count = cnt;
|
||||
}
|
||||
|
||||
int get_map_button()
|
||||
@@ -454,14 +456,18 @@ int get_map_button()
|
||||
return mapping_button;
|
||||
}
|
||||
|
||||
static char *get_map_name(int dev)
|
||||
{
|
||||
static char name[128];
|
||||
sprintf(name, "%s_input_%04x_%04x.map", user_io_get_core_name_ex(), input[dev].vid, input[dev].pid);
|
||||
return name;
|
||||
}
|
||||
|
||||
void finish_map_setting()
|
||||
{
|
||||
mapping = 0;
|
||||
if (mapping_dev<0) return;
|
||||
|
||||
char name[32];
|
||||
sprintf(name, "input_%04x_%04x.map", input[mapping_dev].vid, input[mapping_dev].pid);
|
||||
FileSaveConfig(name, &input[mapping_dev].map, sizeof(input[mapping_dev].map));
|
||||
FileSaveConfig(get_map_name(mapping_dev), &input[mapping_dev].map, sizeof(input[mapping_dev].map));
|
||||
}
|
||||
|
||||
uint16_t get_map_vid()
|
||||
@@ -479,14 +485,14 @@ uint16_t get_map_pid()
|
||||
#define KEY_EMU_UP (KEY_MAX+3)
|
||||
#define KEY_EMU_DOWN (KEY_MAX+4)
|
||||
|
||||
static char joy[2] = { 0 };
|
||||
static uint16_t joy[2] = { 0 };
|
||||
static void input_cb(struct input_event *ev, int dev);
|
||||
|
||||
static void joy_digital(int num, uint16_t mask, char press)
|
||||
static void joy_digital(int num, uint16_t mask, char press, int bnum)
|
||||
{
|
||||
if (num < 2)
|
||||
{
|
||||
if (user_io_osd_is_visible() || (mask == JOY_OSD))
|
||||
if (user_io_osd_is_visible() || (bnum == 16))
|
||||
{
|
||||
memset(joy, 0, sizeof(joy));
|
||||
struct input_event ev;
|
||||
@@ -522,11 +528,8 @@ static void joy_digital(int num, uint16_t mask, char press)
|
||||
ev.code = KEY_BACKSPACE;
|
||||
break;
|
||||
|
||||
case JOY_OSD:
|
||||
ev.code = KEY_F12;
|
||||
break;
|
||||
default:
|
||||
ev.code = 0;
|
||||
ev.code = (bnum == 16) ? KEY_F12 : 0;
|
||||
}
|
||||
|
||||
input_cb(&ev, 0);
|
||||
@@ -638,9 +641,7 @@ static void input_cb(struct input_event *ev, int dev)
|
||||
|
||||
if (!input[dev].has_map)
|
||||
{
|
||||
char name[32];
|
||||
sprintf(name, "input_%04x_%04x.map", input[dev].vid, input[dev].pid);
|
||||
if (!FileLoadConfig(name, &input[dev].map, sizeof(input[dev].map)))
|
||||
if (!FileLoadConfig(get_map_name(dev), &input[dev].map, sizeof(input[dev].map)))
|
||||
{
|
||||
memset(&input[dev].map, 0, sizeof(input[dev].map));
|
||||
}
|
||||
@@ -653,7 +654,7 @@ static void input_cb(struct input_event *ev, int dev)
|
||||
if (ev->type == EV_KEY && ev->value <= 1 && ev->code >= BTN_JOYSTICK)
|
||||
{
|
||||
if (mapping_dev < 0) mapping_dev = dev;
|
||||
if (mapping_dev == dev && mapping_button < 9)
|
||||
if (mapping_dev == dev && mapping_button < mapping_count)
|
||||
{
|
||||
if (ev->value)
|
||||
{
|
||||
@@ -664,7 +665,7 @@ static void input_cb(struct input_event *ev, int dev)
|
||||
|
||||
if (!found)
|
||||
{
|
||||
input[dev].map[mapping_button] = ev->code;
|
||||
input[dev].map[(mapping_button == (mapping_count-1)) ? 16 : mapping_button] = ev->code;
|
||||
key_mapped = 1;
|
||||
}
|
||||
}
|
||||
@@ -687,11 +688,11 @@ static void input_cb(struct input_event *ev, int dev)
|
||||
{
|
||||
if (first_joystick < 0) first_joystick = dev;
|
||||
|
||||
for (int i = 0; i < 9; i++)
|
||||
for (int i = 0; i <= 16; i++)
|
||||
{
|
||||
if (ev->code == input[dev].map[i])
|
||||
{
|
||||
joy_digital((first_joystick == dev) ? 0 : 1, 1<<i, ev->value);
|
||||
joy_digital((first_joystick == dev) ? 0 : 1, 1<<i, ev->value, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -704,7 +705,7 @@ static void input_cb(struct input_event *ev, int dev)
|
||||
if (first_joystick < 0) break;
|
||||
|
||||
// TODO:
|
||||
// 1) add analog axis mapping (input[dev].map[16], input[dev].map[17])
|
||||
// 1) add analog axis mapping
|
||||
// 2) enable invertion
|
||||
|
||||
if (ev->code == 0) // x
|
||||
|
||||
2
input.h
2
input.h
@@ -14,7 +14,7 @@ int toggle_kbdled(int mask);
|
||||
int input_poll(int getchar);
|
||||
|
||||
|
||||
void start_map_setting();
|
||||
void start_map_setting(int cnt);
|
||||
int get_map_button();
|
||||
void finish_map_setting();
|
||||
uint16_t get_map_vid();
|
||||
|
||||
98
menu.c
98
menu.c
@@ -157,6 +157,9 @@ char *config_button_turbo_msg[] = { "OFF", "FAST", "MEDIUM", "SLOW" };
|
||||
char *config_button_turbo_choice_msg[] = { "A only", "B only", "A & B" };
|
||||
char *joy_button_map[] = { "RIGHT", "LEFT", "DOWN", "UP", "BUTTON 1", "BUTTON 2", "BUTTON 3", "BUTTON 4", "BUTTON OSD" };
|
||||
|
||||
char joy_bnames[12][32];
|
||||
int joy_bcount = 0;
|
||||
|
||||
|
||||
enum HelpText_Message { HELPTEXT_NONE, HELPTEXT_MAIN, HELPTEXT_HARDFILE, HELPTEXT_CHIPSET, HELPTEXT_MEMORY, HELPTEXT_VIDEO };
|
||||
const char *helptexts[] = {
|
||||
@@ -817,6 +820,7 @@ void HandleUI(void)
|
||||
int old_osd_size = OsdGetSize();
|
||||
while (1)
|
||||
{
|
||||
joy_bcount = 0;
|
||||
selentry = 0;
|
||||
entry = 0;
|
||||
menumask = 0;
|
||||
@@ -845,7 +849,7 @@ void HandleUI(void)
|
||||
unsigned long status = user_io_8bit_set_status(0, 0); // 0,0 gets status
|
||||
|
||||
p = user_io_8bit_get_string(i);
|
||||
// iprintf("Option %d: %s\n", i-1, p);
|
||||
printf("Option %d: %s\n", i-1, p);
|
||||
|
||||
// check for 'F'ile or 'S'D image strings
|
||||
if (p && ((p[0] == 'F') || (p[0] == 'S'))) {
|
||||
@@ -928,17 +932,29 @@ void HandleUI(void)
|
||||
}
|
||||
|
||||
// check for 'V'ersion strings
|
||||
if (p && (p[0] == 'V')) {
|
||||
|
||||
// p[1] is not used but kept for future use
|
||||
char x = p[1];
|
||||
|
||||
if (p && (p[0] == 'V'))
|
||||
{
|
||||
// get version string
|
||||
strcpy(s, OsdCoreName());
|
||||
strcat(s, " ");
|
||||
substrcpy(s + strlen(s), p, 1);
|
||||
OsdCoreNameSet(s);
|
||||
}
|
||||
|
||||
if (p && (p[0] == 'J'))
|
||||
{
|
||||
// joystick button names.
|
||||
for (int n = 0; n < 12; n++)
|
||||
{
|
||||
substrcpy(joy_bnames[n], p, n+1);
|
||||
printf("joy_bname = %s\n", joy_bnames[n]);
|
||||
if(!joy_bnames[n][0]) break;
|
||||
joy_bcount++;
|
||||
}
|
||||
|
||||
printf("joy_bcount = %d\n", joy_bcount);
|
||||
}
|
||||
|
||||
i++;
|
||||
} while (p);
|
||||
|
||||
@@ -1096,7 +1112,7 @@ void HandleUI(void)
|
||||
menusub = 0;
|
||||
break;
|
||||
case 1:
|
||||
start_map_setting();
|
||||
start_map_setting(joy_bcount ? joy_bcount+5 : 9);
|
||||
menustate = MENU_JOYDIGMAP;
|
||||
menusub = 0;
|
||||
break;
|
||||
@@ -1180,7 +1196,21 @@ void HandleUI(void)
|
||||
break;
|
||||
|
||||
case MENU_JOYDIGMAP1:
|
||||
if(get_map_button()<9) sprintf(s, " Press: %s", joy_button_map[get_map_button()]);
|
||||
p = 0;
|
||||
if (get_map_button() < 4)
|
||||
{
|
||||
p = joy_button_map[get_map_button()];
|
||||
}
|
||||
else if(joy_bcount)
|
||||
{
|
||||
p = (get_map_button() < joy_bcount + 4) ? joy_bnames[get_map_button() - 4] : joy_button_map[8];
|
||||
}
|
||||
else
|
||||
{
|
||||
p = (get_map_button() < 9) ? joy_button_map[get_map_button()] : "";
|
||||
}
|
||||
|
||||
sprintf(s, " Press: %s", p);
|
||||
OsdWrite(3, s, 0, 0);
|
||||
if (get_map_button())
|
||||
{
|
||||
@@ -1188,10 +1218,10 @@ void HandleUI(void)
|
||||
if (get_map_button()<9) sprintf(s, " Joystick ID: %04x:%04x", get_map_vid(), get_map_pid());
|
||||
OsdWrite(5, s, 0, 0);
|
||||
}
|
||||
if (select || menu || get_map_button()>=9)
|
||||
if (select || menu || get_map_button() >= (joy_bcount ? joy_bcount + 5 : 9))
|
||||
{
|
||||
finish_map_setting();
|
||||
menustate = MENU_8BIT_SYSTEM1;
|
||||
menustate = is_menu_core() ? MENU_FIRMWARE1 : MENU_8BIT_SYSTEM1;
|
||||
menusub = 1;
|
||||
}
|
||||
break;
|
||||
@@ -3159,8 +3189,6 @@ void HandleUI(void)
|
||||
helptext = helptexts[HELPTEXT_NONE];
|
||||
parentstate = menustate;
|
||||
|
||||
menumask = 3;
|
||||
|
||||
OsdSetTitle("FW & Core", 0);
|
||||
//OsdWrite(0, "", 0, 0);
|
||||
siprintf(s, " ARM s/w ver. %s", version + 5);
|
||||
@@ -3169,39 +3197,42 @@ void HandleUI(void)
|
||||
|
||||
if (is_menu_core())
|
||||
{
|
||||
menumask = 3;
|
||||
OsdWrite(2, "", 0, 0);
|
||||
if (getStorage(0))
|
||||
{
|
||||
OsdWrite(3, " Using USB storage", 0, 0);
|
||||
OsdWrite(5, " Switch to SD card", menusub == 0, 0);
|
||||
OsdWrite(4, " Switch to SD card", menusub == 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getStorage(1))
|
||||
{
|
||||
OsdWrite(3, " No USB found, using SD card", 0, 0);
|
||||
OsdWrite(5, " Switch to SD card", menusub == 0, 0);
|
||||
OsdWrite(4, " Switch to SD card", menusub == 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
OsdWrite(3, " Using SD card", 0, 0);
|
||||
OsdWrite(5, " Switch to USB storage", menusub == 0, !isUSBMounted());
|
||||
OsdWrite(4, " Switch to USB storage", menusub == 0, !isUSBMounted());
|
||||
}
|
||||
}
|
||||
OsdWrite(4, "", 0, 0);
|
||||
OsdWrite(6, "", 0, 0);
|
||||
OsdWrite(7, " NOTE:", 0, 0);
|
||||
OsdWrite(8, " USB storage takes longer", 0, 0);
|
||||
OsdWrite(9, " time to initialize", 0, 0);
|
||||
OsdWrite(10, " upon cold boot.", 0, 0);
|
||||
OsdWrite(11, " Use OSD or USER button to", 0, 0);
|
||||
OsdWrite(12, " cancel USB waiting", 0, 0);
|
||||
OsdWrite(13, " and use SD instead.", 0, 0);
|
||||
OsdWrite(14, "", 0, 0);
|
||||
OsdWrite(5, "", 0, 0);
|
||||
OsdWrite(6, " NOTE:", 0, 0);
|
||||
OsdWrite(7, " USB storage takes longer", 0, 0);
|
||||
OsdWrite(8, " time to initialize", 0, 0);
|
||||
OsdWrite(9, " upon cold boot.", 0, 0);
|
||||
OsdWrite(10, " Use OSD or USER button to", 0, 0);
|
||||
OsdWrite(11, " cancel USB waiting", 0, 0);
|
||||
OsdWrite(12, " and use SD instead.", 0, 0);
|
||||
OsdWrite(13, "", 0, 0);
|
||||
OsdWrite(14, " Define joystick buttons", menusub == 1, 0);
|
||||
OsdWrite(15, "", 0, 0);
|
||||
menustate = MENU_STORAGE;
|
||||
}
|
||||
else
|
||||
{
|
||||
menumask = 3;
|
||||
OsdWrite(2, "", 0, 0);
|
||||
OsdWrite(3, "", 0, 0);
|
||||
int len = strlen(OsdCoreName());
|
||||
@@ -3217,13 +3248,13 @@ void HandleUI(void)
|
||||
OsdWrite(5, "", 0, 0);
|
||||
OsdWrite(6, " Change FPGA core", menusub == 0, 0);
|
||||
for (int i = 7; i < OsdGetSize() - 1; i++) OsdWrite(i, "", 0, 0);
|
||||
OsdWrite(OsdGetSize() - 1, STD_EXIT, menusub == 1, 0);
|
||||
menustate = MENU_FIRMWARE2;
|
||||
}
|
||||
OsdWrite(OsdGetSize() - 1, STD_EXIT, menusub == 1, 0);
|
||||
break;
|
||||
|
||||
case MENU_STORAGE:
|
||||
if (menu || ((menusub == 1) && select))
|
||||
if (menu)
|
||||
{
|
||||
switch (user_io_core_type()) {
|
||||
case CORE_TYPE_MIST:
|
||||
@@ -3242,12 +3273,21 @@ void HandleUI(void)
|
||||
}
|
||||
else if (select)
|
||||
{
|
||||
if (menusub == 0)
|
||||
switch (menusub)
|
||||
{
|
||||
if(getStorage(1) || isUSBMounted())
|
||||
case 0:
|
||||
if (getStorage(1) || isUSBMounted())
|
||||
{
|
||||
setStorage(!getStorage(1));
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
joy_bcount = 1;
|
||||
strcpy(joy_bnames[0], "Select");
|
||||
start_map_setting(6);
|
||||
menustate = MENU_JOYDIGMAP;
|
||||
menusub = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
7
spi.c
7
spi.c
@@ -227,6 +227,13 @@ void spi_uio_cmd8(uint8_t cmd, uint8_t parm)
|
||||
DisableIO();
|
||||
}
|
||||
|
||||
void spi_uio_cmd16(uint8_t cmd, uint16_t parm)
|
||||
{
|
||||
spi_uio_cmd_cont(cmd);
|
||||
spi_w(parm);
|
||||
DisableIO();
|
||||
}
|
||||
|
||||
void spi_uio_cmd32(uint8_t cmd, uint32_t parm, int wide)
|
||||
{
|
||||
EnableIO();
|
||||
|
||||
1
spi.h
1
spi.h
@@ -54,6 +54,7 @@ void spi_uio_cmd_cont(uint8_t cmd);
|
||||
void spi_uio_cmd(uint8_t cmd);
|
||||
void spi_uio_cmd8(uint8_t cmd, uint8_t parm);
|
||||
void spi_uio_cmd8_cont(uint8_t cmd, uint8_t parm);
|
||||
void spi_uio_cmd16(uint8_t cmd, uint16_t parm);
|
||||
void spi_uio_cmd32(uint8_t cmd, uint32_t parm, int wide);
|
||||
|
||||
#endif // SPI_H
|
||||
|
||||
31
user_io.c
31
user_io.c
@@ -119,6 +119,29 @@ char *user_io_get_core_name()
|
||||
return core_name;
|
||||
}
|
||||
|
||||
char *user_io_get_core_name_ex()
|
||||
{
|
||||
switch (user_io_core_type())
|
||||
{
|
||||
case CORE_TYPE_MINIMIG2:
|
||||
return "MINIMIG";
|
||||
|
||||
case CORE_TYPE_PACE:
|
||||
return "PACE";
|
||||
|
||||
case CORE_TYPE_MIST:
|
||||
return "ST";
|
||||
|
||||
case CORE_TYPE_ARCHIE:
|
||||
return "ARCHIE";
|
||||
|
||||
case CORE_TYPE_8BIT:
|
||||
return core_name;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
char is_menu_core()
|
||||
{
|
||||
return !strcasecmp(core_name, "MENU");
|
||||
@@ -278,7 +301,7 @@ void user_io_analog_joystick(unsigned char joystick, char valueX, char valueY)
|
||||
}
|
||||
}
|
||||
|
||||
void user_io_digital_joystick(unsigned char joystick, unsigned char map)
|
||||
void user_io_digital_joystick(unsigned char joystick, uint16_t map)
|
||||
{
|
||||
uint8_t state = map;
|
||||
// "only" 6 joysticks are supported
|
||||
@@ -325,13 +348,13 @@ void user_io_digital_joystick(unsigned char joystick, unsigned char map)
|
||||
// but only for joystick 1 and 2
|
||||
if ((core_type == CORE_TYPE_MIST) && (joystick < 2))
|
||||
{
|
||||
ikbd_joystick(joystick, map);
|
||||
ikbd_joystick(joystick, (uint8_t)map);
|
||||
return;
|
||||
}
|
||||
|
||||
// every other core else uses this
|
||||
// (even MIST, joystick 3 and 4 were introduced later)
|
||||
spi_uio_cmd8((joystick < 2) ? (UIO_JOYSTICK0 + joystick) : ((UIO_JOYSTICK2 + joystick - 2)), map);
|
||||
spi_uio_cmd16((joystick < 2) ? (UIO_JOYSTICK0 + joystick) : ((UIO_JOYSTICK2 + joystick - 2)), map);
|
||||
}
|
||||
|
||||
static char dig2ana(char min, char max)
|
||||
@@ -341,7 +364,7 @@ static char dig2ana(char min, char max)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void user_io_joystick(unsigned char joystick, unsigned char map)
|
||||
void user_io_joystick(unsigned char joystick, uint16_t map)
|
||||
{
|
||||
// digital joysticks also send analog signals
|
||||
user_io_digital_joystick(joystick, map);
|
||||
|
||||
@@ -72,7 +72,6 @@
|
||||
#define JOY_BTN2 0x20
|
||||
#define JOY_BTN3 0x40
|
||||
#define JOY_BTN4 0x80
|
||||
#define JOY_OSD 0x100
|
||||
#define JOY_MOVE (JOY_RIGHT|JOY_LEFT|JOY_UP|JOY_DOWN)
|
||||
|
||||
#define BUTTON1 0x01
|
||||
@@ -164,6 +163,7 @@ char user_io_dip_switch1(void);
|
||||
char user_io_serial_status(serial_status_t *, uint8_t);
|
||||
int user_io_file_mount(char *name);
|
||||
char *user_io_get_core_name();
|
||||
char *user_io_get_core_name_ex();
|
||||
char is_menu_core();
|
||||
|
||||
// io controllers interface for FPGA ethernet emulation using usb ethernet
|
||||
@@ -177,11 +177,11 @@ void user_io_eth_receive_tx_frame(uint8_t *, uint16_t);
|
||||
void user_io_mouse(unsigned char b, int16_t x, int16_t y);
|
||||
void user_io_kbd(unsigned char m, unsigned char *k, unsigned short vid, unsigned short pid);
|
||||
char* user_io_create_config_name();
|
||||
void user_io_digital_joystick(unsigned char, unsigned char);
|
||||
void user_io_digital_joystick(unsigned char, uint16_t);
|
||||
void user_io_analog_joystick(unsigned char, char, char);
|
||||
char user_io_osd_is_visible();
|
||||
void user_io_send_buttons(char);
|
||||
void user_io_joystick(unsigned char joystick, unsigned char map);
|
||||
void user_io_joystick(unsigned char joystick, uint16_t map);
|
||||
|
||||
void user_io_key_remap(char *);
|
||||
void add_modifiers(uint8_t mod, uint16_t* keys_ps2);
|
||||
|
||||
Reference in New Issue
Block a user