Browse Source

implement msgversion

tags/v10
parent
commit
dee812399d
Signed by: govanify <gauvain@govanify.com> GPG Key ID: DE62E1E2A6145556
6 changed files with 73 additions and 3 deletions
  1. +2
    -0
      bindings/c/c_ffi.cpp
  2. +5
    -0
      bindings/c/c_ffi.h
  3. +1
    -0
      src/client.cpp
  4. +48
    -1
      src/pcsx2_ipc.h
  5. +15
    -0
      src/tests.cpp
  6. +2
    -2
      utils/default.nix

+ 2
- 0
bindings/c/c_ffi.cpp View File

@@ -121,6 +121,8 @@ void pcsx2ipc_write(PCSX2Ipc *v, uint32_t address, uint8_t val,
}
}

char *pcsx2ipc_version(PCSX2Ipc *v, bool batch) { return v->Version(); }

PCSX2Ipc::IPCStatus pcsx2ipc_get_error(PCSX2Ipc *v) { return v->GetError(); }

void pcsx2ipc_free_batch_command(int cmd) {


+ 5
- 0
bindings/c/c_ffi.h View File

@@ -59,6 +59,11 @@ void pcsx2ipc_send_command(PCSX2Ipc *v, int cmd);
uint64_t pcsx2ipc_read(PCSX2Ipc *v, uint32_t address, PCSX2Ipc::IPCCommand msg,
bool batch);

/**
* @see PCSX2Ipc::Version
*/
char *pcsx2ipc_version(PCSX2Ipc *v, bool batch);

/**
* @see PCSX2Ipc::Write
*/


+ 1
- 0
src/client.cpp View File

@@ -61,6 +61,7 @@ auto main(int argc, char *argv[]) -> int {
// in this case we wait 5 seconds before writing to our address
msleep(5000);
try {
printf("%s\n", ipc->Version());
// a normal write can be done this way
ipc->Write<u8>(0x00347D34, 0x5);



+ 48
- 1
src/pcsx2_ipc.h View File

@@ -228,6 +228,7 @@ class PCSX2Ipc {
MsgWrite16 = 5, /**< Write 16 bit value to memory. */
MsgWrite32 = 6, /**< Write 32 bit value to memory. */
MsgWrite64 = 7, /**< Write 64 bit value to memory. */
MsgVersion = 8, /**< Returns PCSX2 version. */
MsgUnimplemented = 0xFF /**< Unimplemented IPC message. */
};

@@ -371,7 +372,13 @@ class PCSX2Ipc {
return FromArray<uint32_t>(buf, loc);
else if constexpr (T == MsgRead64)
return FromArray<uint64_t>(buf, loc);
else {
else if constexpr (T == MsgVersion) {
// TODO: very small memleak here since we don't ask the user to
// delete, how to fix?
char *version = new char[256];
memcpy(version, &buf[loc], 256);
return version;
} else {
SetError(Unimplemented);
return;
}
@@ -676,6 +683,46 @@ class PCSX2Ipc {
}
}

/**
* Retrieves PCSX2 version. @n
* On error throws an IPCStatus. @n
* Format: XX @n
* Legend: XX = IPC Tag. @n
* Return: ZZ * 256 @n
* Legend: ZZ = version string.
* @see IPCCommand
* @see IPCStatus
* @param T Flag to enable batch processing or not.
* @return If in batch mode the IPC message otherwise the version string.
*/
template <bool T = false>
auto Version() {
constexpr IPCCommand tag = MsgVersion;

// batch mode
if constexpr (T) {
if (BatchSafetyChecks(1)) {
SetError(OutOfMemory);
return (char *)0;
}
char *cmd = &ipc_buffer[batch_len];
cmd[0] = tag;
batch_len += 1;
batch_arg_place[arg_cnt] = reply_len;
reply_len += 256;
arg_cnt += 1;
return cmd;
} else {
// we are already locked in batch mode
std::lock_guard<std::mutex> lock(ipc_blocking);
ToArray(ipc_buffer, 4 + 1, 0);
ipc_buffer[4] = tag;
SendCommand(IPCBuffer{ 4 + 1, ipc_buffer },
IPCBuffer{ 256 + 4 + 1, ret_buffer });
return GetReply<tag>(ret_buffer, 5);
}
}

/**
* PCSX2Ipc Initializer.
*/


+ 15
- 0
src/tests.cpp View File

@@ -137,6 +137,19 @@ SCENARIO("PCSX2 can be interacted with remotely through IPC", "[pcsx2_ipc]") {
}
}

WHEN("We want to know PCSX2 Version") {
THEN("It returns a correct one") {

// we do a bunch of writes, read back, ensure the result is
// correct and ensure we didn't threw an error.
REQUIRE_NOTHROW([&]() {
PCSX2Ipc *ipc = new PCSX2Ipc();
char* version = ipc->Version();
REQUIRE(strncmp(version, "PCSX2", 5) == 0);
}());
}
}

WHEN("We want to execute multiple operations in a row") {
THEN("The operations get executed successfully and consistently") {

@@ -160,9 +173,11 @@ SCENARIO("PCSX2 can be interacted with remotely through IPC", "[pcsx2_ipc]") {
ipc->Read<u32, true>(0x00347E44);
ipc->Read<u16, true>(0x00347E54);
ipc->Read<u8, true>(0x00347E64);
ipc->Version<true>();
auto resr = ipc->FinalizeBatch();
ipc->SendCommand(resr);

REQUIRE(strncmp(ipc->GetReply<PCSX2Ipc::MsgVersion>(resr, 4), "PCSX2", 5) == 0);
REQUIRE(ipc->GetReply<PCSX2Ipc::MsgRead8>(resr, 3) == 8);
REQUIRE(ipc->GetReply<PCSX2Ipc::MsgRead16>(resr, 2) == 7);
REQUIRE(ipc->GetReply<PCSX2Ipc::MsgRead32>(resr, 1) == 6);


+ 2
- 2
utils/default.nix View File

@@ -5,8 +5,8 @@ let
src = pkgs.fetchFromGitHub {
owner = "GovanifY";
repo = "pcsx2";
rev = "7da0617909867365f7253c53bfabf3994481b9ef";
sha256 = "17s8l55sp881q6nriknh9srl9l9ilfiy0l335vaxazg32qq5wq6b";
rev = "b1d50465d5f8125c946bb387634a7e67eb097e6a";
sha256 = "0nn2586dqlkh2l6iwpsscgvwkvq8cag33pflb0c6xxhsj2kqlv4g";
};
cmakeFlags = oldAttrs.cmakeFlags ++ ["-DEXTRA_PLUGINS=TRUE"];
});


Loading…
Cancel
Save