diff --git a/src/libretro/StellaLIBRETRO.hxx b/src/libretro/StellaLIBRETRO.hxx index 135a5413b..f54eac326 100644 --- a/src/libretro/StellaLIBRETRO.hxx +++ b/src/libretro/StellaLIBRETRO.hxx @@ -60,7 +60,7 @@ class StellaLIBRETRO void* getROM() const { return rom_image.get(); } uInt32 getROMSize() const { return rom_size; } - constexpr uInt32 getROMMax() const { return Cartridge::maxSize(); } + constexpr uInt32 getROMMax() const { return uInt32(Cartridge::maxSize()); } uInt8* getRAM() { return system_ram; } constexpr uInt32 getRAMSize() const { return 128; } @@ -100,6 +100,10 @@ class StellaLIBRETRO return myOSystem->console().tia().height() * getVideoZoom(); } + const Common::Rect& getImageRect() const { + return myOSystem->frameBuffer().imageRect(); + } + float getAudioRate() const { return getConsoleNTSC() ? (262 * 76 * 60) / 38.0 : (312 * 76 * 50) / 38.0; } diff --git a/src/libretro/libretro.cxx b/src/libretro/libretro.cxx index e9fe39de5..d18d3b400 100644 --- a/src/libretro/libretro.cxx +++ b/src/libretro/libretro.cxx @@ -129,11 +129,18 @@ static void update_input() break; case Controller::Type::Lightgun: - EVENT(Event::MouseAxisXValue, input_state_cb(pad, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X)); - EVENT(Event::MouseAxisYValue, input_state_cb(pad, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y)); + { + // scale from -0x8000..0x7fff to image rect + const Common::Rect& rect = stella.getImageRect(); + const Int32 x = (input_state_cb(pad, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X) + 0x8000) * rect.w() / 0xffff; + const Int32 y = (input_state_cb(pad, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y) + 0x8000) * rect.h() / 0xffff; + + EVENT(Event::MouseAxisXValue, x); + EVENT(Event::MouseAxisYValue, y); EVENT(Event::MouseButtonLeftValue, input_state_cb(pad, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TRIGGER)); EVENT(Event::MouseButtonRightValue, input_state_cb(pad, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_TRIGGER)); break; + } default: break;