mGBA Forums

Full Version: Trying to integrate Wanderbar with mGBA, but need some advice
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello! I've been working on integrating my Wanderbar sidebar thingy into Windows mGBA 0.6.1, but I know almost nothing about Qt and threads, plus the mGBA source code is light-years more advanced and cleaner than anything I could ever produce.

Still, I've been poking at the code and learning how things work. I've mostly got my Wanderbar working with mGBA now, but the biggest (and probably final) snag is that I need to call my Wanderbar's "doLogic" function before each GB/GBC/GBA CPU instruction.

Currently, I do that call in thread.c, around this part. (This actually works fine until my Wanderbar needs to update the browser, after which it crashes & I can't debug the cause, but it appears to be thread-related)

[Image: thread.c.jpg]

The issue is that I need to move this call out of thread.c and make it so that GameController.cpp (or maybe Window.cpp) calls my Wanderbar logic function instead. So basically I can't find a clear way to make it so that GameController.cpp knows when a core CPU instruction is about to be executed.

I figure that's probably not even how something like this should be handled, but again, I'm out of my league here with threads and Qt and such. Is there any way to make this work somehow? Currently my best guess is to try to create something like the debugger that's in the "if" statement in the code above, but that's also all written in C and part of the core, so I don't think that'll work either Sad
So, that class is actually gone in mGBA 0.7.0 and replaced with CoreController. You might want to take a look at the mDebugger interface and notably how the debug console bridges things across threads. I think there's a generic enough base in there for you to get started, otherwise I can toss you some helpers.
Cool, thanks! I'll take a look and try incorporating it with the latest version rather than 0.6.1. I feel like I'm in over my head, but yeah, last night I considered just modifying the debugger itself to do what I want, and now hearing there's a CoreController sounds very promising  Big Grin
Thanks to your suggestion, I've got 0.7.0 compiled and running now. I'm way out of my league with this level of abstraction/threading/callbacks though, so I've spent the last week trying to solve the puzzle.

Basically, each time a CPU instruction is run, I specifically need for GBAApp to be notified. I've gotten it so CoreController is notified each time an instruction is executed, but I don't know how to pass it upward to GBAApp. For reference, here's basically where I am now - this is the callback I added to CoreController.cpp, and it gets called as intended:

Code:
// WANDERBAR ADDITION
m_threadContext.instructionCallback = [](mCoreThread* context) {
    CoreController* controller = static_cast<CoreController*>(context->userData);

    // obviously this doesn't work but I basically just want to pass word on up to GBAApp that an instruction has just been executed
    bool t = QMetaObject::invokeMethod(GBAApp, "instructionHasRunSoSendMessagePlease");
};

My hunch is that what I'm asking is crazy and/or not possible, but I hope I'm wrong. Do you have any suggestions/advice? I'm so way in over my head here  Tongue
Meant to reply to this yesterday--unfortunately interrupting the thread every instruction will be prohibitively slow. What you want to do is either batch updates or do as much from the CPU thread as possible and only interrupt the thread when needed. Is there somewhere more direct I can talk to you about this, like Discord, so I can get a better impression of what you're actually doing behind the scenes, and maybe help implementing it?
Well, it's hard to explain and I unfortunately can't debug the problem, but basically, my Wanderbar uses something called Awesomium ( https://web.archive.org/web/201703241753...omium.com/ ) for all the browser stuff and LuaBridge for the Lua scripting. I've got it loading properly with mGBA now, and it works/runs fine... when there isn't a game core loaded. Here's a pic from last week showing the Wanderbar loaded alongside a game:

[Image: GBATEST.jpg]

The pic above shows that the browser with its startup page loaded, but once a core IS loaded, the instant I ask the browser to update or ask my Lua stuff to run, I get the follow sort of error:

[Image: Capture.jpg]

If I ask the browser or Lua engine to execute *outside* of the game core, it seems to work just fine, however, which is why I was trying to get it to happen in GBAApp... but I'm basically praying that that would even solve the problem.

My best guess is that the threaded nature of mGBA's cores conflicts with these things somehow, but I don't know enough to figure it out.

I've never done Discord stuff before, but if you think it'd help here, I can try to figure it out.
Hmm, that looks like a null pointer dereference. Without a backtrace I can't even begin to guess why though.

Discord is likely easiest for me but I can also do IRC, Slack, or Skype I guess.
Thanks! It'll take a bit of work for me to get things organized enough to share, so it'll be a little while until I have it ready. I should note that the web core's values and functions all work properly regardless of where I ask for them, it's just the web core's Update function that causes the problem. It's a separate process of its own I think, so I guess it has something to do with that.


Code:
using namespace Awesomium;

WebConfig config;
WebCore* core = WebCore::Initialize(config);

WebView* view = core->CreateWebView(512, 512);
view->LoadURL(WSLit("http://www.google.com"));

// finish loading the page
while (view->IsLoading())
  core->Update();
Anyway, I'll prep stuff and then jump onto Discord in a few days.