foxygit / fake-08-xbox360 Log in
commit 774f69db76ed29ccaba6bf0110412002a1a370cf
Merge: 30ec1cc 130814e
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Tue Dec 23 17:16:03 2025 -0700
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Tue Dec 23 17:16:03 2025 -0700

    Merge branch 'master' into game-loop-refactor

 .github/workflows/build.yml                    |   2 +-
 platform/libretro/libretro.cpp                 | 172 +++++++++++--
 platform/libretro/libretro_core_options.h      | 321 +++++++++++++++++++++++++
 platform/libretro/libretro_core_options_intl.h |  90 +++++++
 platform/libretro/retro_inline.h               |  45 ++++
 source/Audio.cpp                               |  22 +-
 source/Audio.h                                 |   2 +-
 source/graphics.cpp                            | 180 +++++++++++++-
 source/graphics.h                              |   6 +
 source/p8GlobalLuaFunctions.h                  |  17 +-
 source/picoluaapi.cpp                          |  53 +++-
 source/picoluaapi.h                            |   2 +
 source/printHelper.cpp                         |  59 ++++-
 test/audiotests.cpp                            |  22 +-
 test/endtoendtests.cpp                         |   3 +-
 test/graphicstests.cpp                         | 251 +++++++++++++++++++
 test/picoluaapitests.cpp                       |  68 +++---
 test/printHelperTests.cpp                      |  32 +++
 test/stubhost.cpp                              |  14 +-
 test/vmtests.cpp                               | 108 ++++++++-
 20 files changed, 1376 insertions(+), 93 deletions(-)

diff --cc platform/libretro/libretro.cpp
index 9001f50,47fa867..6c30a3c
--- a/platform/libretro/libretro.cpp
+++ b/platform/libretro/libretro.cpp
@@@ -223,91 -317,99 +317,100 @@@ int flip = 0

  EXPORT void retro_run()
  {
-     input_poll_cb();
+  bool updated  = false;
+
+    if (enviro_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
+       check_variables(false);
+
+     //TODO: improve this so slower hardware can play 30fps games at full speed
+     if (_vm->getTargetFps() == 60 || frame % 2 == 0)
+     {
+         input_poll_cb();
++    }

 -        uint8_t currKDown = 0;
 -        uint8_t currKHeld = 0;
 -        for (int i = 0; i < 7; i++) {
 -            bool down = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, buttons[i]);
 -            if (down) {
 -                currKHeld |= BITMASK(i);
 -                //if the key is a new push this frame, mark it as down as well
 -                if (!(kHeld & BITMASK(i))) {
 -                    currKDown |= BITMASK(i);
 -                }
 +    uint8_t currKDown = 0;
 +    uint8_t currKHeld = 0;
 +    for (int i = 0; i < 7; i++) {
 +        bool down = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, buttons[i]);
 +        if (down) {
 +            currKHeld |= BITMASK(i);
 +            //if the key is a new push this frame, mark it as down as well
 +            if (!(kHeld & BITMASK(i))) {
 +                currKDown |= BITMASK(i);
              }
          }
 +    }

 -        mouseBtnState = 0;
 +    mouseBtnState = 0;

 -        if (_memory->drawState.devkitMode) {
 -            bool havePointer = false;
 -            bool haveAnalog = false;
 -            bool haveMouse = false;
 -            bool gotTouch = false;
 -
 -            uint64_t flags = 0;
 -            enviro_cb(RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES, &flags);
 +    if (_memory->drawState.devkitMode) {
 +        bool havePointer = false;
 +        bool haveAnalog = false;
 +        bool haveMouse = false;
 +        bool gotTouch = false;
 +
 +        uint64_t flags = 0;
 +        enviro_cb(RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES, &flags);


 -            haveMouse = flags & (1 << RETRO_DEVICE_MOUSE);
 -            havePointer = flags & (1 << RETRO_DEVICE_POINTER);
 -            haveAnalog = flags & (1 << RETRO_DEVICE_ANALOG);
 +        haveMouse = flags & (1 << RETRO_DEVICE_MOUSE);
 +        havePointer = flags & (1 << RETRO_DEVICE_POINTER);
 +        haveAnalog = flags & (1 << RETRO_DEVICE_ANALOG);

 -            if (haveMouse) {
 -                int16_t pointX = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X);
 -                int16_t pointY = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y);
 -                mouseBtnState = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_PRESSED);
 +        if (haveMouse) {
 +            int16_t pointX = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X);
 +            int16_t pointY = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y);
 +            mouseBtnState = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_PRESSED);

 -                //this needs to be adjusted to screen scale I think?
 -                picoMouseX += pointX;
 -                picoMouseY += pointY;
 -            }
 -            else if (havePointer) {
 -                int16_t pointX = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X);
 -                int16_t pointY = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y);
 -                int16_t pressed = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_PRESSED);
 -
 -                if (pressed) {
 -                    picoMouseX = pointX * 64 / 32768 + 64;
 -                    picoMouseY = pointY * 64 / 32768 + 64;
 -                    mouseBtnState = 1;
 -                    gotTouch = true;
 -                }
 +            //this needs to be adjusted to screen scale I think?
 +            picoMouseX += pointX;
 +            picoMouseY += pointY;
 +        }
 +        else if (havePointer) {
 +            int16_t pointX = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X);
 +            int16_t pointY = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y);
 +            int16_t pressed = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_PRESSED);
 +
 +            if (pressed) {
 +                picoMouseX = pointX * 64 / 32768 + 64;
 +                picoMouseY = pointY * 64 / 32768 + 64;
 +                mouseBtnState = 1;
 +                gotTouch = true;
              }
 +        }

 -            if (haveAnalog && !gotTouch) {
 -                // Read the analog X/Y
 -                int16_t analogX = input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X);
 -                int16_t analogY = input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y);
 -                // Pre-calculate where the cursor will be
 -                int16_t tempX = picoMouseX + (((PicoScreenWidth / 32767.0f ) * analogX)/32);
 -                int16_t tempY = picoMouseY + (((PicoScreenHeight / 32767.0f ) * analogY)/32);
 -                // Make sure the cursor stays within the screen
 -                if ( ((tempX - 0) | (PicoScreenWidth - tempX)) >= 0) {
 -                    picoMouseX = tempX;
 -                }
 -                if ( ((tempY - 0) | (PicoScreenHeight - tempY)) >= 0) {
 -                    picoMouseY = tempY;
 -                }
 -                // Grab the state of the X button
 -                mouseBtnState = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X);
 +        if (haveAnalog && !gotTouch) {
 +            // Read the analog X/Y
 +            int16_t analogX = input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X);
 +            int16_t analogY = input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y);
 +            // Pre-calculate where the cursor will be
 +            int16_t tempX = picoMouseX + (((PicoScreenWidth / 32767.0f ) * analogX)/32);
 +            int16_t tempY = picoMouseY + (((PicoScreenHeight / 32767.0f ) * analogY)/32);
 +            // Make sure the cursor stays within the screen
 +            if ( ((tempX - 0) | (PicoScreenWidth - tempX)) >= 0) {
 +                picoMouseX = tempX;
 +            }
 +            if ( ((tempY - 0) | (PicoScreenHeight - tempY)) >= 0) {
 +                picoMouseY = tempY;
              }
 +            // Grab the state of the X button
 +            mouseBtnState = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X);
          }
 -
 -        setInputState(currKDown, currKHeld, picoMouseX, picoMouseY, mouseBtnState);
 -
 -        _vm->UpdateAndDraw();
 -        kHeld = currKHeld;
 -        kDown = currKDown;
 +    }
 +
 +    setInputState(currKDown, currKHeld, picoMouseX, picoMouseY, mouseBtnState);

 -        if (frame % 2 == 0) {
 -            _audio->FillAudioBuffer(&audioBuffer, 0, SAMPLESPERFRAME);
 -            audio_batch_cb(audioBuffer, SAMPLESPERFRAME);
 -        }
 +    _vm->Step();
 +    //_vm->UpdateAndDraw();
 +    kHeld = currKHeld;
 +    kDown = currKDown;

 +    if (frame % 2 == 0) {
 +        _audio->FillAudioBuffer(&audioBuffer, 0, SAMPLESPERFRAME);
 +        audio_batch_cb(audioBuffer, SAMPLESPERFRAME);
      }

 +
      uint8_t* picoFb = _vm->GetPicoInteralFb();
      uint8_t* screenPaletteMap = _vm->GetScreenPaletteMap();

diff --cc test/stubhost.cpp
index 024a3ee,5bbefd3..11c260f
--- a/test/stubhost.cpp
+++ b/test/stubhost.cpp
@@@ -18,11 -19,13 +19,13 @@@ static uint8_t stubCurrKDown
  static uint8_t stubCurrKHeld;
  static bool stubCurrKBdown = false;
  static std::string stubCurrKBkey = "";
+ static std::map<std::string, std::string> stubCartDataStorage;


-
- Host::Host(int windowWidth, int windowHeight)  { }
- StubHost::StubHost() { }
 -Host::Host() { }
++Host::Host(int windowWidth, int windowHeight)
+ StubHost::StubHost() {
+     stubCartDataStorage.clear();
+ }


  void Host::oneTimeSetup(Audio* audio){