diff --git a/input.cpp b/input.cpp index 523dc60..cb7ea77 100644 --- a/input.cpp +++ b/input.cpp @@ -22,6 +22,9 @@ static int astick_deadzone = 0; static int trigger_deadzone = 0; static float mouse_sensitivity = 1.0f; +static unsigned geometry_width = 0; +static unsigned geometry_height = 0; + typedef union { uint8_t u8[ 32 ]; @@ -440,6 +443,14 @@ void input_init() } } +void input_set_geometry( unsigned width, unsigned height ) +{ + log_cb( RETRO_LOG_INFO, "input_set_geometry: %dx%d\n", width, height ); + + geometry_width = width; + geometry_height = height; +} + void input_set_deadzone_stick( int percent ) { if ( percent >= 0 && percent <= 100 ) @@ -881,7 +892,9 @@ void input_update( retro_input_state_t input_state_cb ) forced_reload = input_state_cb( iplayer, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_RELOAD ); // off-screen? - if ( input_state_cb( iplayer, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN ) || forced_reload ) + if ( input_state_cb( iplayer, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN ) || + forced_reload || + geometry_height == 0 ) { shot_type = 0x4; // off-screen shot @@ -897,15 +910,15 @@ void input_update( retro_input_state_t input_state_cb ) gun_y_raw = input_state_cb( iplayer, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y ); // .. scale into screen space: - // NOTE: the scaling here is semi-guesswork, need to re-write. - // TODO: Test with PAL games. + // NOTE: the scaling here is empirical-guesswork. + // Tested at 352x240 (ntsc) and 352x256 (pal) const int scale_x = 21472; - const int offset_x = 60; - const int scale_y = 240; + const int scale_y = geometry_height; + const int offset_y = geometry_height - 240; - gun_x = ( ( gun_x_raw + offset_x + 0x7fff ) * scale_x ) / (0x7fff << 1); - gun_y = ( ( gun_y_raw + 0x7fff ) * scale_y ) / (0x7fff << 1); + gun_x = ( ( gun_x_raw + 0x7fff ) * scale_x ) / (0x7fff << 1); + gun_y = ( ( gun_y_raw + 0x7fff ) * scale_y ) / (0x7fff << 1) + offset_y; } // position diff --git a/input.h b/input.h index aeec617..54e7826 100644 --- a/input.h +++ b/input.h @@ -11,6 +11,8 @@ extern void input_init_env( retro_environment_t environ_cb ); extern void input_init(); +extern void input_set_geometry( unsigned width, unsigned height ); + extern void input_set_env( retro_environment_t environ_cb ); extern void input_set_deadzone_stick( int percent ); diff --git a/libretro.cpp b/libretro.cpp index 9e3338d..645ce6c 100644 --- a/libretro.cpp +++ b/libretro.cpp @@ -2257,6 +2257,8 @@ void retro_run(void) game_width = width; game_height = height; + + input_set_geometry( width, height ); } pix += surf->pitchinpix * (linevisfirst << PrevInterlaced) + overscan_mask;