Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ps2xRuntime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ FetchContent_MakeAvailable(raylib)

add_library(ps2_runtime STATIC
src/lib/game_overrides.cpp
src/lib/ps2_gif_arbiter.cpp
src/lib/ps2_audio.cpp
src/lib/ps2_audio_vag.cpp
src/lib/ps2_gs_gpu.cpp
Expand All @@ -32,6 +33,7 @@ add_library(ps2_runtime STATIC
src/lib/ps2_stubs.cpp
src/lib/ps2_syscalls.cpp
src/lib/ps2_vif1_interpreter.cpp
src/lib/ps2_vu1.cpp
)

file(GLOB RUNNER_SRC_FILES CONFIGURE_DEPENDS
Expand Down
10 changes: 10 additions & 0 deletions ps2xRuntime/include/ps2_call_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@
X(sceGsSyncV) \
X(sceGsSyncVCallback) \
X(sceGszbufaddr) \
X(sceeFontInit) \
X(sceeFontLoadFont) \
X(sceeFontPrintfAt) \
X(sceeFontPrintfAt2) \
X(sceeFontGenerateString) \
X(sceeFontClose) \
X(sceeFontSetColour) \
X(sceeFontSetMode) \
X(sceeFontSetFont) \
X(sceeFontSetScale) \
X(sceIoctl) \
X(sceIpuInit) \
X(sceIpuRestartDMA) \
Expand Down
42 changes: 42 additions & 0 deletions ps2xRuntime/include/ps2_gif_arbiter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef PS2_GIF_ARBITER_H
#define PS2_GIF_ARBITER_H

#include <cstdint>
#include <functional>
#include <vector>

enum class GifPathId : uint8_t
{
Path1 = 1,
Path2 = 2,
Path3 = 3,
};

struct GifArbiterPacket
{
GifPathId pathId;
std::vector<uint8_t> data;
};

class GifArbiter
{
public:
using ProcessPacketFn = std::function<void(const uint8_t *, uint32_t)>;

GifArbiter() = default;
explicit GifArbiter(ProcessPacketFn processFn);

void setProcessPacketFn(ProcessPacketFn fn) { m_processFn = std::move(fn); }

void submit(GifPathId pathId, const uint8_t *data, uint32_t sizeBytes);

void drain();

private:
ProcessPacketFn m_processFn;
std::vector<GifArbiterPacket> m_queue;

static uint8_t pathPriority(GifPathId id);
};

#endif
57 changes: 57 additions & 0 deletions ps2xRuntime/include/ps2_gs_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef PS2_GS_COMMON_H
#define PS2_GS_COMMON_H

#include "ps2_gs_gpu.h"
#include <cstdint>

namespace GSInternal
{
static inline uint32_t bitsPerPixel(uint8_t psm)
{
switch (psm)
{
case GS_PSM_CT32:
case GS_PSM_Z32:
return 32;
case GS_PSM_CT24:
case GS_PSM_Z24:
return 32;
case GS_PSM_CT16:
case GS_PSM_CT16S:
case GS_PSM_Z16:
case GS_PSM_Z16S:
return 16;
case GS_PSM_T8:
case GS_PSM_T8H:
return 8;
case GS_PSM_T4:
case GS_PSM_T4HL:
case GS_PSM_T4HH:
return 4;
default:
return 32;
}
}

static inline uint32_t fbStride(uint32_t fbw, uint8_t psm)
{
uint32_t pixelsPerRow = fbw * 64u;
return pixelsPerRow * (bitsPerPixel(psm) / 8u);
}

static inline int clampInt(int v, int lo, int hi)
{
if (v < lo) return lo;
if (v > hi) return hi;
return v;
}

static inline uint8_t clampU8(int v)
{
if (v < 0) return 0;
if (v > 255) return 255;
return static_cast<uint8_t>(v);
}
}

#endif
Loading