osdinput.c文件里面,主要是这样子设置的:
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);
这里注册设备,然后对应的名字,以及这个对应的从哪个数组里面拿数值。
static INT32 my_get_state(void *device_internal, void *item_internal)
{
UINT8 *keystate = (UINT8 *)item_internal;
return *keystate;
}
这个方法,是模拟器内部调用,我们只需要改动前面的值就可以了。、
我们使用的地方:
droid_ios_poll_input
这里面,是上层的按钮按下,弹起,会将这里面的一些数组改,主要是按下:0x80,弹起0x0
通过这两个值,模拟器会得到一次按下,然后驱动模拟器内部运行。
void droid_ios_poll_input(running_machine *machine)
{
my_poll_ports(machine);
long _pad_status = joystick_read(0);
netplay_t *handle = netplay_get_handle();
int netplay = handle->has_connection && handle->has_begun_game;
if(mystate == STATE_NORMAL)
{
keyboard_state[KEY_1] = 0;
keyboard_state[KEY_2] = 0;
if(myosd_exitGame || handle->state.ext & NP_EXIT || handle->peer_state.ext & NP_EXIT)
{
if(netplay)
{
if(myosd_in_menu)
{
if(handle->state.ext & NP_EXIT || handle->peer_state.ext & NP_EXIT)
{
keyboard_state[KEY_ESCAPE] = 0x80;
myosd_ext_status &= ~ NP_EXIT;
}
else
{
myosd_ext_status |= NP_EXIT;
}
}
else
{
handle->has_connection = 0;
handle->has_begun_game = 0;
keyboard_state[KEY_ESCAPE] = 0x80;
}
}
else
{
handle->has_begun_game = 0;//ensure for auto disconnect
keyboard_state[KEY_ESCAPE] = 0x80;
}
myosd_exitGame = 0;
handle->state.ext &= ~ NP_EXIT;
handle->peer_state.ext &= ~ NP_EXIT;
}
else
{
keyboard_state[KEY_ESCAPE] = 0;
if(myosd_reset_filter==1){
myosd_exitGame= 1;
}
}
if(myosd_service && !myosd_in_menu && !netplay)
{
keyboard_state[KEY_SERVICE] = 0x80;
myosd_service = 0;
}
else
{
keyboard_state[KEY_SERVICE] = 0;
}
keyboard_state[KEY_LOAD] = 0;
keyboard_state[KEY_SAVE] = 0;
if(myosd_savestate || handle->state.ext & NP_SAVE || handle->peer_state.ext & NP_SAVE)
{
if(netplay)
{
if(handle->state.ext & NP_SAVE || handle->peer_state.ext & NP_SAVE)
{
keyboard_state[KEY_SAVE] = 0x80;
mystate = STATE_LOADSAVE;
myosd_ext_status &= ~ NP_SAVE;
}
else
{
myosd_ext_status |= NP_SAVE;
}
}
else
{
keyboard_state[KEY_SAVE] = 0x80;
mystate = STATE_LOADSAVE;
}
handle->state.ext &= ~ NP_SAVE;
handle->peer_state.ext &= ~ NP_SAVE;
myosd_savestate = 0;
myosd_fs_counter = 60 * 5;
return;
}
if(myosd_loadstate || handle->state.ext & NP_LOAD || handle->peer_state.ext & NP_LOAD)
{
if(netplay)
{
if(handle->state.ext & NP_LOAD || handle->peer_state.ext & NP_LOAD)
{
keyboard_state[KEY_LOAD] = 0x80;
mystate = STATE_LOADSAVE;
myosd_ext_status &= ~ NP_LOAD;
}
else
{
myosd_ext_status |= NP_LOAD;
}
}
else
{
keyboard_state[KEY_LOAD] = 0x80;
mystate = STATE_LOADSAVE;
}
handle->state.ext &= ~ NP_LOAD;
handle->peer_state.ext &= ~ NP_LOAD;
myosd_loadstate = 0;
myosd_fs_counter = 60 * 5;
return;
}
for(int i=0; i<4; i++)
{
if(i!=0 && myosd_in_menu==1 && myosd_num_of_joys <=1)//to avoid mapping issues when pxasp1 is active
break;
_pad_status = joystick_read(i);
if(i==0)
{
if(!myosd_inGame && !myosd_in_menu)
{
keyboard_state[KEY_PGUP] = ((_pad_status & MYOSD_LEFT) != 0) ? 0x80 : 0;
keyboard_state[KEY_PGDN] = ((_pad_status & MYOSD_RIGHT) != 0) ? 0x80 : 0;
}
else
{
keyboard_state[KEY_PGUP] = 0;
keyboard_state[KEY_PGDN] = 0;
}
if((_pad_status & MYOSD_START /*& MYOSD_SELECT*/) && (_pad_status /*& MYOSD_A*/ & MYOSD_L1) && myosd_saveload_combo)
{
myosd_savestate = 1;
break;
}
if((_pad_status /*& MYOSD_SELECT*/ & MYOSD_START) && (_pad_status /*& MYOSD_A*/ & MYOSD_R1) && myosd_saveload_combo)
{
myosd_loadstate = 1;
break;
}
}
// lo cambio de 0 a i...
if(joystick_read_analog(i, 'x') == 0 && joystick_read_analog(i, 'y')==0)
{
joy_hats[i][0] = ((_pad_status & MYOSD_UP) != 0) ? 0x80 : 0;
joy_hats[i][1] = ((_pad_status & MYOSD_DOWN) != 0) ? 0x80 : 0;
joy_hats[i][2] = ((_pad_status & MYOSD_LEFT) != 0) ? 0x80 : 0;
joy_hats[i][3] = ((_pad_status & MYOSD_RIGHT) != 0) ? 0x80 : 0;
joy_axis[i][0] = 0;
joy_axis[i][1] = 0;
lightgun_axis[i][0] = (int)(lightgun_x[myosd_pxasp1 ? 0 : i] * 32767 * 2 );
lightgun_axis[i][1] = (int)(lightgun_y[myosd_pxasp1 ? 0 : i] * 32767 * -2 );
}
else
{
joy_axis[i][0] = (int)(joystick_read_analog(i, 'x') * 32767 * 2 );
joy_axis[i][1] = (int)(joystick_read_analog(i, 'y') * 32767 * -2 );
joy_hats[i][0] = 0;
joy_hats[i][1] = 0;
joy_hats[i][2] = 0;
joy_hats[i][3] = 0;
lightgun_x[i] = 0;
lightgun_y[i] = 0;
lightgun_axis[i][0] = 0;
lightgun_axis[i][1] = 0;
}
if(myosd_inGame && !myosd_in_menu && myosd_autofire && !netplay)
{
old_B_pressed[i] = B_pressed[i];
B_pressed[i] = _pad_status & MYOSD_B;
if(!old_B_pressed[i] && B_pressed[i])
{
enabled_autofire[i] = !enabled_autofire[i];
}
}
else
enabled_autofire[i] = false;
if(enabled_autofire[i])//AUTOFIRE
{
int value = 0;
switch (myosd_autofire) {
case 1: value = 1;break;
case 2: value = 2;break;
case 3: value = 4; break;
case 4: value = 6; break;
case 5: value = 8; break;
case 6: value = 10; break;
case 7: value = 13; break;
case 8: value = 16; break;
case 9: value = 20; break;
default:
value = 6; break;
break;
}
joy_buttons[i][0] = fire[i]++ >=value ? 0x80 : 0;
if(fire[ i] >= value*2)
fire[ i] = 0;
}
else
joy_buttons[i][0] = ((_pad_status & MYOSD_B) != 0) ? 0x80 : 0;
joy_buttons[i][1] = ((_pad_status & MYOSD_X) != 0) ? 0x80 : 0;
joy_buttons[i][2] = ((_pad_status & MYOSD_A) != 0) ? 0x80 : 0;
joy_buttons[i][3] = ((_pad_status & MYOSD_Y) != 0) ? 0x80 : 0;
joy_buttons[i][4] = ((_pad_status & MYOSD_L1) != 0) ? 0x80 : 0;
joy_buttons[i][5] = ((_pad_status & MYOSD_R1) != 0) ? 0x80 : 0;
if(i!=0 && (myosd_num_of_joys==1 || myosd_num_of_joys==0) && !netplay)
continue;
joy_buttons[i][6] = ((_pad_status & MYOSD_SELECT ) != 0) ? 0x80 : 0;
joy_buttons[i][7] = ((_pad_status & MYOSD_START ) != 0) ? 0x80 : 0;
}
}
else if(mystate == STATE_LOADSAVE)
{
keyboard_state[KEY_ESCAPE] = 0;
keyboard_state[KEY_1] = 0;
keyboard_state[KEY_2] = 0;
if(myosd_exitGame || handle->state.ext & NP_EXIT || handle->peer_state.ext & NP_EXIT)
{
if(netplay)
{
if(handle->state.ext & NP_EXIT || handle->peer_state.ext & NP_EXIT)
{
keyboard_state[KEY_ESCAPE] = 0x80;
mystate = STATE_NORMAL;
myosd_ext_status &= ~ NP_EXIT;
}
else
{
myosd_ext_status |= NP_EXIT;
}
}
else
{
keyboard_state[KEY_ESCAPE] = 0x80;
mystate = STATE_NORMAL;
}
myosd_exitGame = 0;
handle->state.ext &= ~ NP_EXIT;
handle->peer_state.ext &= ~ NP_EXIT;
}
if ((_pad_status & MYOSD_B) != 0)
{
keyboard_state[KEY_1] = 0x80;
mystate = STATE_NORMAL;
do{}while(myosd_joystick_read(0) & MYOSD_B);
}
if ((_pad_status & MYOSD_X) != 0)
{
keyboard_state[KEY_2] = 0x80;
mystate = STATE_NORMAL;
do{}while(myosd_joystick_read(0) & MYOSD_X);
}
}
else {/*???*/}
}
我们改动主要是这里,配合着上层java,完成对打。同时这块还可以设置热键,组合键。