Skip to content

Commit

Permalink
LibUV glue.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasnoble committed Jan 18, 2020
1 parent 720de96 commit 98c872b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ftdi/abstract-ftd2xx-win32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ static HANDLE s_kickEvent = nullptr;
static std::shared_mutex s_listLock;
static unsigned s_numOpened = 0;

static PCSX::GUI* s_gui = nullptr;

PCSX::FTDI::Device::~Device() {
assert(m_private->m_state == Private::DeviceData::STATE_CLOSED);
assert(!m_private->m_event);
Expand Down Expand Up @@ -189,4 +191,6 @@ void PCSX::FTDI::Devices::stopThread() {

bool PCSX::FTDI::Devices::isThreadRunning() { return s_threadRunning; }

void PCSX::FTDI::Devices::setGUI(GUI* gui) { s_gui = gui; }

#endif
26 changes: 26 additions & 0 deletions src/ftdi/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@

#include <stdint.h>

#include <atomic>
#include <functional>
#include <string>
#include <vector>

#include "gui/gui.h"
#include "support/slice.h"

namespace PCSX {

namespace FTDI {
Expand Down Expand Up @@ -60,6 +64,27 @@ class Device {

Private::DeviceData* m_private;

static const unsigned SLICES_COUNT = 256;
Slice m_slices[SLICES_COUNT];
std::atomic_uint16_t m_slicesIndexes = 0;

unsigned usedSlices() {
uint16_t indexes = m_slicesIndexes.load();
unsigned first = indexes & 0xff;
unsigned last = (indexes >> 8) & 0xff;
if (last < first) last += 256;
return last - first;
}

unsigned availableSlices() { return 256 - usedSlices(); }

Slice& allocateSlice() {
while (availableSlices() == 0)
;
uint16_t indexes = m_slicesIndexes.fetch_add(0x100);
return m_slices[(indexes >> 8) & 0xff];
}

friend class Devices;
};

Expand All @@ -70,6 +95,7 @@ class Devices {
static bool isThreadRunning();
static void startThread();
static void stopThread();
static void setGUI(GUI*);

// technically private, but difficult to enforce properly
static void threadProc();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class GUI final {
}
}

uv_loop_t &loop();

private:
GLFWwindow *m_window = nullptr;
int &m_glfwPosX = settings.get<WindowPosX>().value;
Expand Down
2 changes: 2 additions & 0 deletions src/main/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "core/r3000a.h"
#include "core/sstate.h"
#include "flags.h"
#include "ftdi/abstract.h"
#include "gui/gui.h"
#include "spu/interface.h"
#include "support/slice.h"
Expand Down Expand Up @@ -197,6 +198,7 @@ int main(int argc, char **argv) {
LoadPlugins();
PCSX::g_emulator.m_gpu->open(s_gui);
PCSX::g_emulator.m_spu->open();
PCSX::FTDI::setGUI(s_gui);

PCSX::g_emulator.EmuInit();
PCSX::g_emulator.EmuReset();
Expand Down

0 comments on commit 98c872b

Please sign in to comment.