void droid_ios_init_input(running_machine *machine) { memset(keyboard_state,0,sizeof(keyboard_state)); memset(joy_buttons,0,sizeof(joy_buttons)); memset(joy_axis,0,sizeof(joy_axis)); memset(joy_hats,0,sizeof(joy_hats)); //input_device_class_enable(machine, DEVICE_CLASS_LIGHTGUN, TRUE); input_device_class_enable(machine, DEVICE_CLASS_JOYSTICK, TRUE); for (int i = 0; i < 4; i++) { char name[10]; input_device *devinfo; snprintf(name, 10, "Joy %d", i + 1); devinfo = input_device_add(machine, DEVICE_CLASS_JOYSTICK, name, NULL); input_device_item_add(devinfo, "Bt_B", &joy_buttons[i][0], ITEM_ID_BUTTON1, my_get_state); input_device_item_add(devinfo, "Bt_X", &joy_buttons[i][1], ITEM_ID_BUTTON2, my_get_state); input_device_item_add(devinfo, "Bt_A", &joy_buttons[i][2], ITEM_ID_BUTTON3, my_get_state); input_device_item_add(devinfo, "Bt_Y", &joy_buttons[i][3], ITEM_ID_BUTTON4, my_get_state); input_device_item_add(devinfo, "Bt_L", &joy_buttons[i][4], ITEM_ID_BUTTON5, my_get_state); input_device_item_add(devinfo, "Bt_R", &joy_buttons[i][5], ITEM_ID_BUTTON6, my_get_state); input_device_item_add(devinfo, "Coin", &joy_buttons[i][6], ITEM_ID_BUTTON7, my_get_state); input_device_item_add(devinfo, "Start", &joy_buttons[i][7], ITEM_ID_BUTTON8, my_get_state); input_device_item_add(devinfo, "X Axis", &joy_axis[i][0], ITEM_ID_XAXIS, my_axis_get_state); input_device_item_add(devinfo, "Y Axis", &joy_axis[i][1], ITEM_ID_YAXIS, my_axis_get_state); input_device_item_add(devinfo, "D-Pad Up", &joy_hats[i][0],(input_item_id)( ITEM_ID_HAT1UP+i*4), my_get_state); input_device_item_add(devinfo, "D-Pad Down", &joy_hats[i][1],(input_item_id)( ITEM_ID_HAT1DOWN+i*4), my_get_state); input_device_item_add(devinfo, "D-Pad Left", &joy_hats[i][2], (input_item_id)(ITEM_ID_HAT1LEFT+i*4), my_get_state); input_device_item_add(devinfo, "D-Pad Right", &joy_hats[i][3], (input_item_id)(ITEM_ID_HAT1RIGHT+i*4), my_get_state); } keyboard_device = input_device_add(machine, DEVICE_CLASS_KEYBOARD, "Keyboard", NULL); if (keyboard_device == NULL) fatalerror("Error creating keyboard device"); input_device_item_add(keyboard_device, "Exit", &keyboard_state[KEY_ESCAPE], ITEM_ID_ESC, my_get_state); input_device_item_add(keyboard_device, "1", &keyboard_state[KEY_1], ITEM_ID_1, my_get_state); input_device_item_add(keyboard_device, "2", &keyboard_state[KEY_2], ITEM_ID_2, my_get_state); input_device_item_add(keyboard_device, "Load", &keyboard_state[KEY_LOAD], ITEM_ID_F7, my_get_state); input_device_item_add(keyboard_device, "Save", &keyboard_state[KEY_SAVE], ITEM_ID_F8, my_get_state); input_device_item_add(keyboard_device, "PGUP", &keyboard_state[KEY_PGUP], ITEM_ID_PGUP, my_get_state); input_device_item_add(keyboard_device, "PGDN", &keyboard_state[KEY_PGDN], ITEM_ID_PGDN, my_get_state); input_device_item_add(keyboard_device, "Service", &keyboard_state[KEY_SERVICE], ITEM_ID_F2, my_get_state); poll_ports = 1; }
void mini_osd_interface::init(running_machine &machine) { // call our parent osd_interface::init(machine); // initialize the video system by allocating a rendering target our_target = machine.render().target_alloc(); // nothing yet to do to initialize sound, since we don't have any // sound updates are handled by update_audio_stream() below // initialize the input system by adding devices // let's pretend like we have a keyboard device keyboard_device = input_device_add(&machine, DEVICE_CLASS_KEYBOARD, "Keyboard", NULL); if (keyboard_device == NULL) fatalerror("Error creating keyboard device"); // our faux keyboard only has a couple of keys (corresponding to the // common defaults) input_device_item_add(keyboard_device, "Esc", &keyboard_state[KEY_ESCAPE], ITEM_ID_ESC, keyboard_get_state); input_device_item_add(keyboard_device, "P1", &keyboard_state[KEY_P1_START], ITEM_ID_1, keyboard_get_state); input_device_item_add(keyboard_device, "B1", &keyboard_state[KEY_BUTTON_1], ITEM_ID_LCONTROL, keyboard_get_state); input_device_item_add(keyboard_device, "B2", &keyboard_state[KEY_BUTTON_2], ITEM_ID_LALT, keyboard_get_state); input_device_item_add(keyboard_device, "B3", &keyboard_state[KEY_BUTTON_3], ITEM_ID_SPACE, keyboard_get_state); input_device_item_add(keyboard_device, "JoyU", &keyboard_state[KEY_JOYSTICK_U], ITEM_ID_UP, keyboard_get_state); input_device_item_add(keyboard_device, "JoyD", &keyboard_state[KEY_JOYSTICK_D], ITEM_ID_DOWN, keyboard_get_state); input_device_item_add(keyboard_device, "JoyL", &keyboard_state[KEY_JOYSTICK_L], ITEM_ID_LEFT, keyboard_get_state); input_device_item_add(keyboard_device, "JoyR", &keyboard_state[KEY_JOYSTICK_R], ITEM_ID_RIGHT, keyboard_get_state); // hook up the debugger log // add_logerror_callback(machine, output_oslog); }
//we have no seat filters, we account all input devices and all dce6 display //devices void lwl_udev_input_cold_plug(void) { struct udev_enumerate *e; e=udev_enumerate_new(lwl_udev); if(!e){ PERRC("fatal:cold plug:unable to create enumeration\n"); exit(LWL_ERR); } int r=udev_enumerate_add_match_subsystem(e,"input"); if(r){ PERRC("fatal:cold plug:unable to select input subsystem for enumeration\n"); exit(LWL_ERR); } r=udev_enumerate_add_match_subsystem(e,"dce6_display"); if(r){ PERRC("fatal:cold plug:unable to select dce6_display subsystem for" " enumeration\n"); exit(LWL_ERR); } r=udev_enumerate_scan_devices(e); if(r){ PERRC("fatal:cold plug:error while enumerating input devices\n"); exit(LWL_ERR); } struct udev_list_entry *first=udev_enumerate_get_list_entry(e); struct udev_list_entry *item=0; LOG_UDEV("cold plug:starting input devices enumeration...\n"); udev_list_entry_foreach(item,first){ struct udev_device *d=udev_device_new_from_syspath(lwl_udev, udev_list_entry_get_name(item)); if(!d) continue; void *subsys=(void*)udev_device_get_subsystem(d); if(!strncmp(INPUT_STR,subsys,cs_n(INPUT_STR))) input_device_add(d); else if(!strncmp(DCE6_DISPLAY_STR,subsys,cs_n(DCE6_DISPLAY_STR))){ struct gbl *o=output_plugged(d); if(o) registry_gbl_ref(o); } udev_device_unref(d); } LOG_UDEV("cold plug:end of input devices enumeration\n"); udev_enumerate_unref(e); }
void lwl_udev_monitor_rd(void) { struct udev_device *d; LOG_UDEV("monitor:starting processing of udev input event\n"); d=udev_monitor_receive_device(monitor); if(!d){ PERRC("fatal:udev:monitor:unable to get device\n"); exit(LWL_ERR); } void *action=(void*)udev_device_get_action(d); if(!action) goto unref_device; void *sysname=(void*)udev_device_get_sysname(d); void *subsys=(void*)udev_device_get_subsystem(d); LOG_UDEV("monitor:action=%s seq=%lld subsystem=%s sysname=%s\n",action, udev_device_get_seqnum(d),subsys,sysname); if(!strncmp(action,"add",cs_n("add"))){ if(!strncmp(INPUT_STR,subsys,cs_n(INPUT_STR))) input_device_add(d); else if(!strncmp(DCE6_DISPLAY_STR,subsys,cs_n(DCE6_DISPLAY_STR))){ struct gbl *o=output_plugged(d); if(o) registry_gbl_ref(o); } }else if (!strncmp(action,"remove",cs_n("remove"))){ if(!strncmp(INPUT_STR,subsys,cs_n(INPUT_STR))) //XXX:The evdev device may be already gone with a fd error which would //have killed the device. This is for udev based removal of a device. lwl_evdev_remove((void*)udev_device_get_devnode(d)); else if(!strncmp(DCE6_DISPLAY_STR,subsys,cs_n(DCE6_DISPLAY_STR))){ struct gbl *o=output_gone(d); if(o) registry_gbl_unref(o); } } unref_device: udev_device_unref(d); LOG_UDEV("monitor:end of udev input event processing\n"); }
void droid_init_input(running_machine *machine) { keyboard_device = input_device_add(machine, DEVICE_CLASS_KEYBOARD, "Keyboard", NULL); if (keyboard_device == NULL) fatalerror("Error creating keyboard device"); input_device_item_add(keyboard_device, "Esc", &keyboard_state[KEY_ESCAPE], ITEM_ID_ESC, keyboard_get_state); input_device_item_add(keyboard_device, "P1", &keyboard_state[KEY_P1_START], ITEM_ID_1, keyboard_get_state); input_device_item_add(keyboard_device, "P2", &keyboard_state[KEY_P2_START], ITEM_ID_2, keyboard_get_state); input_device_item_add(keyboard_device, "P3", &keyboard_state[KEY_P3_START], ITEM_ID_3, keyboard_get_state); input_device_item_add(keyboard_device, "P4", &keyboard_state[KEY_P4_START], ITEM_ID_4, keyboard_get_state); input_device_item_add(keyboard_device, "B1", &keyboard_state[KEY_BUTTON_1], ITEM_ID_LCONTROL, keyboard_get_state); input_device_item_add(keyboard_device, "B2", &keyboard_state[KEY_BUTTON_2], ITEM_ID_LALT, keyboard_get_state); input_device_item_add(keyboard_device, "B3", &keyboard_state[KEY_BUTTON_3], ITEM_ID_SPACE, keyboard_get_state); input_device_item_add(keyboard_device, "B4", &keyboard_state[KEY_BUTTON_4], ITEM_ID_LSHIFT, keyboard_get_state); input_device_item_add(keyboard_device, "B5", &keyboard_state[KEY_BUTTON_5], ITEM_ID_Z, keyboard_get_state); input_device_item_add(keyboard_device, "B6", &keyboard_state[KEY_BUTTON_6], ITEM_ID_X, keyboard_get_state); input_device_item_add(keyboard_device, "JoyU", &keyboard_state[KEY_JOYSTICK_U], ITEM_ID_UP, keyboard_get_state); input_device_item_add(keyboard_device, "JoyD", &keyboard_state[KEY_JOYSTICK_D], ITEM_ID_DOWN, keyboard_get_state); input_device_item_add(keyboard_device, "JoyL", &keyboard_state[KEY_JOYSTICK_L], ITEM_ID_LEFT, keyboard_get_state); input_device_item_add(keyboard_device, "JoyR", &keyboard_state[KEY_JOYSTICK_R], ITEM_ID_RIGHT, keyboard_get_state); input_device_item_add(keyboard_device, "C1", &keyboard_state[KEY_P1_COIN], ITEM_ID_5, keyboard_get_state); input_device_item_add(keyboard_device, "C2", &keyboard_state[KEY_P2_COIN], ITEM_ID_6, keyboard_get_state); input_device_item_add(keyboard_device, "C3", &keyboard_state[KEY_P3_COIN], ITEM_ID_7, keyboard_get_state); input_device_item_add(keyboard_device, "C4", &keyboard_state[KEY_P4_COIN], ITEM_ID_8, keyboard_get_state); input_device_item_add(keyboard_device, "Menu", &keyboard_state[KEY_MENU], ITEM_ID_TAB, keyboard_get_state); input_device_item_add(keyboard_device, "Select", &keyboard_state[KEY_SELECT], ITEM_ID_ENTER, keyboard_get_state); input_device_item_add(keyboard_device, "LOADSAVE", &keyboard_state[KEY_LOADSAVE], ITEM_ID_F7, keyboard_get_state); input_device_item_add(keyboard_device, "PGUP", &keyboard_state[KEY_PGUP], ITEM_ID_PGUP, keyboard_get_state); input_device_item_add(keyboard_device, "PGDN", &keyboard_state[KEY_PGDN], ITEM_ID_PGDN, keyboard_get_state); }
/** * This function is called back by MAME when it is starting up. It passes the * descriptor that it uses internally for every possible input port, and gives * us the opportunity to define what callback we will provide for fetching the * state of that input port. We ignore those input ports that are not used in * the current game, and for the others, make our own custom controllers as * neceessary to provide the inputs, and hook the input callbacks up to fetch * the input state from the one single LibMame_AllControlsState structure * that we store in the g_state object. In this way, we completely hardwire * the way that MAME handles input so that the users of libmame can do * whatever they want to satisfy getting inputs for the various controllers * types. **/ static void osd_customize_input_type_list(input_type_desc *typelist) { /** * For each input descriptor, create a keyboard key, or mouse axis, or * lightgun control, or joystick axis for it, and change its input * sequence to match the new item. Also, set up the polling callback for * it to have the data it needs to get the right controller state. **/ input_type_desc *typedesc; input_device *item_device; input_item_id item_id = ITEM_ID_INVALID; int input_code = 0; /** * New keyboards are created as we run out of keys; the only keys we * use are between ITEM_ID_A and ITEM_ID_Z (inclusive). It is * important that ITEM_IDs that identify keys from a keyboard are used as * MAME internally detects the ITEM_ID type and treats it specially in * different circumstances, and so the ITEM_ID must "match" the * input_device type that it is attached to. For example, if we used * something outside of the key range for a keyboard * (e.g. ITEM_ID_RELATIVE1), then MAME would interpret the INT32 that it * gets when it calls back to get the state of the input incorrectly (it * would interpret it as some kind of delta value, not as a "pressed or * not pressed" boolean). The same concept holds true for joysticks, * mice, etc, so those only use ITEM_ID values that make sense for their * types. And why only use keyboard keys up to Z and not the others? * Well, apparently MAME also does something very weird and interprets * devices which have been mapped to key '0' (and probably other MAME * default UI keys) as having input that triggers that UI event. **/ input_device *keyboard = 0; input_item_id keyboard_item = ITEM_ID_A; int keyboard_count = 0; /* As to all of the rest, they are created as needed, one for each player */ input_device *analog_joystick[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; input_device *spinner[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; input_device *paddle[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; input_device *trackball[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; input_device *lightgun[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; input_device *pedal[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; char namebuf[256]; #define GET_ITEM_DEVICE_AND_ID(device_type, device_class, item_class) \ do { \ if (device_type [typedesc->player] == 0) { \ snprintf(namebuf, sizeof(namebuf), \ "libmame_virtual_" #device_type "_%d", \ typedesc->player); \ device_type [typedesc->player] = input_device_add \ (g_state.machine, device_class, namebuf, NULL); \ } \ item_device = device_type [typedesc->player]; \ item_id = g_input_descriptors[typedesc->type].item_id; \ input_code = INPUT_CODE(device_class, \ input_device_get_index \ (g_state.machine, \ device_type [typedesc->player]), \ item_class, ITEM_MODIFIER_NONE, \ item_id); \ } while (0); for (typedesc = typelist; typedesc; typedesc = typedesc->next) { item_device = NULL; if (controllers_have_input(g_state.maximum_player_count, &(g_state.controllers), typedesc->player, typedesc->type)) { switch (g_input_descriptors[typedesc->type].type) { case libmame_input_type_invalid: break; case libmame_input_type_Normal_button: case libmame_input_type_Mahjong_button: case libmame_input_type_Hanafuda_button: case libmame_input_type_Gambling_button: case libmame_input_type_Shared_button: case libmame_input_type_left_joystick: case libmame_input_type_right_joystick: case libmame_input_type_Ui_button: if (!keyboard || (keyboard_item > ITEM_ID_Z)) { snprintf(namebuf, sizeof(namebuf), "libmame_virtual_keyboard_%d", keyboard_count++); keyboard = input_device_add (g_state.machine, DEVICE_CLASS_KEYBOARD, namebuf, NULL); keyboard_item = ITEM_ID_A; } item_device = keyboard; item_id = keyboard_item; keyboard_item++; input_code = INPUT_CODE(DEVICE_CLASS_KEYBOARD, input_device_get_index(g_state.machine, keyboard), ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, item_id); break; /* * For all of the following, we use DEVICE_CLASS_LIGHTGUN, * ITEM_CLASS_ABSOLUTE for any device for which we provide * absolute values, and DEVICE_CLASS_MOUSE, * ITEM_CLASS_RELATIVE for any device for which we provide * relative values. The { MOUSE, RELATIVE } choice makes * sense, but the { LIGHTGUN, ABSOLUTE } seems weird for * things like analog joysticks and paddles. However, * LIGHTGUN is the device class that MAME does the least * amount of internal fiddling with when interpreting input * values, and that's what we want. If we choose * DEVICE_CLASS_JOYSTICK then it will do deadzone stuff, and * if we choose DEVICE_CLASS_MOUSE, it will force the input to * be relative which will cause input handling to always use * 0. It's weird, but DEVICE_CLASS_LIGHTGUN is the best * choice for any absolute control type. */ case libmame_input_type_analog_joystick_horizontal: case libmame_input_type_analog_joystick_vertical: /* Yes, it's weird that LIGHTGUN is used here - see above comment */ GET_ITEM_DEVICE_AND_ID(analog_joystick, DEVICE_CLASS_LIGHTGUN, ITEM_CLASS_ABSOLUTE); break; case libmame_input_type_spinner: case libmame_input_type_vertical_spinner: GET_ITEM_DEVICE_AND_ID(spinner, DEVICE_CLASS_MOUSE, ITEM_CLASS_RELATIVE); break; case libmame_input_type_paddle: case libmame_input_type_vertical_paddle: /* Yes, it's weird that LIGHTGUN is used here - see above comment */ GET_ITEM_DEVICE_AND_ID(paddle, DEVICE_CLASS_LIGHTGUN, ITEM_CLASS_ABSOLUTE); break; case libmame_input_type_trackball_horizontal: case libmame_input_type_trackball_vertical: GET_ITEM_DEVICE_AND_ID(trackball, DEVICE_CLASS_MOUSE, ITEM_CLASS_RELATIVE); break; case libmame_input_type_lightgun_horizontal: case libmame_input_type_lightgun_vertical: /* Hey, LIGHTGUN actually makes sense here! */ GET_ITEM_DEVICE_AND_ID(lightgun, DEVICE_CLASS_LIGHTGUN, ITEM_CLASS_ABSOLUTE); break; case libmame_input_type_pedal: case libmame_input_type_pedal2: case libmame_input_type_pedal3: /* Yes, it's weird that LIGHTGUN is used here - see above comment */ GET_ITEM_DEVICE_AND_ID(pedal, DEVICE_CLASS_LIGHTGUN, ITEM_CLASS_ABSOLUTE); break; } } if (item_device) { input_device_item_add (item_device, "", (void *) CBDATA_MAKE(typedesc->player, typedesc->type), item_id, &get_controller_state); } else { /* For some reason or another, we can't handle this input, so turn it off by setting it to an item_id that we never use */ item_id = ITEM_ID_MAXIMUM; } input_seq_set_1(&(typedesc->seq[SEQ_TYPE_STANDARD]), input_code); } }
static void startup_callback(running_machine &machine) { /** * If the special input ports have not been configured yet, do so now. * This is the earliest opportunity we have to do this, which must be done * after osd_customize_input_type_list. **/ if (!g_state.special_inputs_configured) { g_state.special_inputs_configured = true; input_device *keyboard = 0; input_item_id keyboard_item = ITEM_ID_A; int keyboard_count = 0; int special_button_index = 0; ioport_list &ioportlist = g_state.machine->m_portlist; const input_port_config *port; const input_field_config *field; for (port = ioportlist.first(); port; port = port->next()) { for (field = port->fieldlist; field; field = field->next) { if ((field->type != IPT_OTHER) || !field->name) { continue; } if (!keyboard || (keyboard_item > ITEM_ID_Z)) { char namebuf[256]; snprintf(namebuf, sizeof(namebuf), "libmame_virtual_special_keyboard_%d", keyboard_count++); keyboard = input_device_add (g_state.machine, DEVICE_CLASS_KEYBOARD, namebuf, NULL); keyboard_item = ITEM_ID_A; } keyboard_item++; int input_code = INPUT_CODE(DEVICE_CLASS_KEYBOARD, input_device_get_index(g_state.machine, keyboard), ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, keyboard_item); input_device_item_add(keyboard, "", (void *) special_button_index++, keyboard_item, &get_special_state); input_field_user_settings settings; input_seq_set_1(&(settings.seq[SEQ_TYPE_STANDARD]), input_code); input_field_set_user_settings(field, &settings); } } } LibMame_StartupPhase phase; switch (machine.init_phase()) { case STARTUP_PHASE_PREPARING: phase = LibMame_StartupPhase_Preparing; break; case STARTUP_PHASE_LOADING_ROMS: phase = LibMame_StartupPhase_LoadingRoms; break; case STARTUP_PHASE_INITIALIZING_STATE: phase = LibMame_StartupPhase_InitializingMachine; break; default: /* Else ignore, unknown phase? */ return; } /* Currently, only one running game at a time is supported, so just pass in a bogus value */ (*(g_state.callbacks->StartingUp)) (phase, machine.init_phase_percent_complete(), (LibMame_RunningGame *) 0x1, g_state.callback_data); }