Commit Graph

61 Commits

Author SHA1 Message Date
Ranieri cf4a90c4ab feat: default capture history gs to false (#167)
fix: remove wrong logic on frameupload
fix: fix option to enable and disable logs
2026-07-08 22:09:23 -03:00
Ranieri ecc86f4b5d Feature vu1 cache (#158)
* feat: explode vu1 in files
feat: added way  more tests for vu1

* feat: added VU1 cache
2026-07-07 21:48:26 -03:00
Ranieri 52edf07657 Feature/agressive recompiler (#146)
* feat: added guestBranchKind enum to categorize branch types
feat: added missingFunctionPolicy enum to define behaviors for missing function scenarios
refactor: added handle guest branches and report missing functions
feat lookupFunction to utilize new dispatch logic and improve error handling for unregistered functions

* fix: fix test conflict

* feat: added debug sound driver logs

* feat: emmiter for return

* feat: added recompiler reporter
feat: added strict diagnostics flag for heavy debug calls

* feat: staticc table insted of hashmap for runtime

* feat: back file to ignore

* feat: explode code across helpers and classes

* feat: update codegen test
feat: better guest nop check

* feat: fix link problem on linux

* feat: fix Segmentation fault

* feat: added recompile replace for DMA and MMIO
feat: added a clean memory helpers
feat: use memory helpers across the project
feat: fix ucrt on msvc

* feat: undo messup merge
2026-07-07 10:14:25 -03:00
Shane Michael Mathews (Personal Account) 61621b8313 fix(runtime): make GS CSR atomic to fix vsync-worker/guest data race (#145)
updateGsCsrFieldForVSync runs on the detached vsync worker and updated the
FIELD bit with a non-atomic read-modify-write of GSRegisters::csr while
guest threads concurrently read/write the same word (MMIO read32/read64 and
the W1C handling in write32/write64) and the GIF path sets SIGNAL/FINISH.
Even though the writers touch disjoint bits, a whole-word RMW loses the
other side's update: a clobbered SIGNAL/FINISH set hangs a game
synchronizing on GS completion, a clobbered W1C clear re-asserts a handled
interrupt, and a clobbered FIELD toggle stalls interlace field polling.
ThreadSanitizer flags the race on main (updateGsCsrFieldForVSync vs
PS2Memory::write64 and GS::writeRegister).

Make the field std::atomic<uint64_t> and perform every update as a single
atomic RMW:

- vsync FIELD toggle -> fetch_or / fetch_and
- MMIO W1C writes -> compare_exchange loop in shared helpers (a
  load-then-store pair would still race); a 32-bit store to the CSR's upper
  dword previously bypassed the W1C special case entirely and went through
  the plain merge branch - both halves now share the same atomic helper
  with unchanged guest-visible semantics
- GIF SIGNAL/FINISH -> fetch_or
- reads -> load()

std::atomic<uint64_t> is lock-free on all supported targets (static_assert
added), the struct's size/alignment asserts are unchanged, GSRegisters is
never copied by value, and default (seq_cst) ordering is used throughout -
these operations are rare (vblank ticks, GIF signals, CSR MMIO), so
reviewability wins over micro-optimization.

New regression test: two racer threads each own one status bit (SIGNAL /
FINISH) and loop 80k GIF-set + W1C-clear cycles verifying their own bit
after each half-op while the vsync worker toggles FIELD. Fails 20/20 runs
against the previous code, passes 50/50 with the fix, ~350ms runtime, no
sanitizer needed.
2026-07-06 12:35:44 -03:00
Ranieri 5196a6672a Refactor runtime for move speed and better code style (#140)
* feat: added guestBranchKind enum to categorize branch types
feat: added missingFunctionPolicy enum to define behaviors for missing function scenarios
refactor: added handle guest branches and report missing functions
feat lookupFunction to utilize new dispatch logic and improve error handling for unregistered functions

* fix: fix test conflict

* feat: added debug sound driver logs

* feat: emmiter for return

* feat: added recompiler reporter
feat: added strict diagnostics flag for heavy debug calls

* feat: staticc table insted of hashmap for runtime

* feat: back file to ignore

* feat: explode code across helpers and classes

* feat: update codegen test
feat: better guest nop check

* feat: fix link problem on linux

* feat: fix Segmentation fault
2026-07-04 00:43:22 -03:00
Jeffrey Shulkin 3a2e0d69fd feat: add SSE2 support and fix SSE4.1 paths for PADDSW and PSUBSW instructions (#141)
* feat: add sses2 support for PADDSW and PSUBSW instructions

* Fixed SSE4.1 PADDSW/PSUBSW implementations
2026-07-04 00:02:00 -03:00
Jeffrey Shulkin db3d44fbde Added explicit FPU ACC register (#143) 2026-07-03 10:03:59 -03:00
Ranieri 8c8a97af65 Feature/mpeg decoder (#120)
* feat: added ffmepg as dependency

* feat: wip decoder video

* feat: some perf and cleanup

* feat:  added generic MPEG stream notification

* feat: CMakeLists.txt in ps2xStudio to configure SDL2 build options for static linking.
fix: fix ffmpeg setup for linux
fix: now MPEG decoder now identify that movie has ended and can play again anytime
feat: better audio stub to not block games

* feat: fix expansion test

* feat: foo

* a

* feat: finally added a helper to to prevent thread starvation

* feat: added basic  vu0 code execution

* feat: added yield Guest Execution After Wake to prevent deadlock

* feat: added  options  on  cmake for logs
feat: better input for keyboard pad

* feat: small corrections like top and itop vu branches etc

* feat: changes

* feat: working feature

* feat: fatal frame iop

* feat: test fix
feat: z buffer fix

* fix: gix GsPutIMR IMR

* feat: added rl imgui

* feat: added helper to get snapshot

* feat: added debug panel consuming snapshots

* feat: added pad snapshot
feat: added RCP debug events

* feat: final cleanup from old code

* feat: added EE timer counter
feat: applyed sound driver for Lotr
feat: better check for sound driver compat layout
feat: enquee and cosumed DMa cause
feat: added Pad execCMd
feat: update GS vsync signal flag
feat: custom IOPs for LotR

* feat: small cleanups

* fix: fix wrong import
2026-06-26 21:04:39 -03:00
tealalchemist 91592e3faa GS rasterizer rework (#132)
* [runtime] Memory swizzling rework

Reimplementation of memory swizzling supporting all valid GS texture
storage types.

An additional optimization was done to improve the speed of lookups.
Since page access is linear, we can precompute the non-linear bit
(blocks and columns) for an entire page for each format. This reduces
the runtime calculation to just calculating the correct page in 2d
memory space and then performing a lookup in the table to get the
location in memory inside a page. Since all page accesses are the same,
this works across all pages. Speed improvements should be compounded by
the number of accesses but there might be some reductions as a result of
actually implementing formats that were not implemented before.

I took care to do this with simple math. GS swizzling is complicated and
optimizing it for debug builds is outside the scope of my current work.

This is just the standalone code. It will be worked into the current
rasterizer in a follow up commit.

* [runtime] Reimplement GS host -> local transfers

Reimplement the host -> local transfers using new swizzling code

* [runtime] Reimplement sampling with new swizzling

Reimplements the rasterizer sampling code to use the new swizzling code

* [runtime] Replace fb writes with new swizzling

Replace the framebuffer write code with the new swizzling code

* [runtime] Reduce vram read/write to func lookup

Reduces the vram read write switches to a function lookup

* [tests] fix GS tests not handling depth test

* [runtime] z interpolation and write support

Add support for interpolating z from primitives and writing to the z
buffer after z testing and masking

* [runtime] local to local transfer rework

* [runtime] host readout uses new sizzling code

plus cleanup some dead code

* [runtime] rework local->host transfer

update to the new swizzling code

* [runtime] update clear function with new swizzling
2026-06-21 00:07:26 -03:00
Ranieri 790aaf4cda feat: invert codegen hight to low convertion (#131)
* feat: invert codegen hight to low convertion
feat: added copy and GetEntryAddress
feat: handle truncated DMAC

* feat: always use address on analyzer now

* feat: correct pick syscalls ID

* feat: added deci2Call

* feat: added wip dbcmain IOP

* feat: added InitTLB
feat: added err logs on thread for debug sus crash

* fix: fix SetupHeap for strange cases

* feat: fix incorrect SetupHeap test(it use a wrong idea on how heap allocate memory)

* feat: added memalign and memalign_r
feat: added GetOsdConfigParam2 and  SetOsdConfigParam2 but idk if was a good idea

* feat: added more memory stuff

* feat: back to library functions
2026-06-13 16:39:39 -03:00
Ranieri 93e221feaa Feature/runtime ecosystem refactor (#107)
* feat: remove memory and pad from stub section

* feat: add support for resume entry targets in CodeGenerator (this allow jumps in address outside function)
feat: refactor entry point discovery one more try to reduce big generated file

* feat: optmizations for release build

* feat: remove unused  file

* feat: added some test cases for code gen

* feat: added log macro and remove win specific code

* feat: refactor runtime folder structure
feat: added reset sound driver RPC state and compatibility layout
feat: rename and added new test
feat: update RPC calls to use defined constants
feat: added more PSMC(16, 32)
feat: change cd read to try find the asset ignoring case sensitive
fix: fix some render problems
feat: add logs on pad
feat: added more RPC handles

* feat: added game override for code veronica

* feat: apply vita patch

* feat: flags to disable build

* feat: fix merges
feat: break a lot of tests

* feat: better throw error on empty cd path
feat: remove recompiler unusde function
feat: apply missing patch

* feat: gamedp is now part of lib
feat: missing file

* feat: small cleanup

* feat: missing vita changes

* feat: fix more merge

* feat: fix tests

* feat: last missing feature

* feat: added missing import

* feat: rename test local functions

* feat: init syscall on ps2 list

* feat: added DMA helpers

* feat: faster builds
feat: more implement for darkcloud

* feat: back missing file

* feat: added missing includes

* feat: remove test

* feat: missing include

* feat: read register funtion

* feat: build  fix

* feat: force  exit on detach thread
2026-04-04 23:09:56 -03:00
roby65 553a9027d8 sceGsSetDefDBuff and sceGsSwapDBuff implementation based on the DC version (#106) 2026-03-24 21:34:17 -03:00
Ranieri cad1ca0bb5 Feature/added execution guess gs psmt (#104)
* fix: CRITICAL fix on code gen on generating BEQ translation, I added a small yeld because goto could spin forever and monopolize guest execution

* feat: add scratchpad alias base and improve scratchpad address handling

* feat: added debug logging on GifArbiter for submit and drain operations

* feat: add interrupt and thread management syscall implementations
fix: change some IDs calls to match ps2sdk

* feat: added vif1 logs

* feat: added logs on gs gpu
feat: added performLocalToLocalTransfer to GS emulation path for TRXDIR = 2. (emulates the PS2 GS “copy this rectangle from one place in VRAM to another”)

* feat: added PSMT8 and refactor PSMT4

* feat: some identation on vu1
feat: added some logs on vu1

* feat: added GuestExecutionScope to temporarily stop owning guest execution, then restore it exactly as it was.
feat: added vsync wizardry
feat: added some regression test

* fix: fix gs logger

* feat: remove extra logs I think they will help no one
feat: move join all threads to prevent the app to get stuck on close, but now it random crash on closing
feat: one more small test on psmt4 to try fix ghosting on re code veronica

* feat: added a small case for exporter from ghidra for metal slug 3

* feat: added ugly code to pass on test
2026-03-18 19:14:40 -03:00
Ranieri 7ca6a866c9 Feature/ghidra export and syscall fixes (#100)
* docs: deprecate the local analyzer workflow in favor of Ghidra
feat: improve the Ghidra exporter for stripped games and internal entry points
fix: correct FindAddress behavior in the runtime
fix: emit missing delay-slot code in recompiler  edge cases
feat: add SetSyscall support from @Whoneon
feat: add dispatchSyscallOverride support from @Whoneon
fix: fix  Unmatched '{' due to missing newlines from issue #96
feat: delete python ghidra script I never updated it anyway
feat: added a lot more of regression test
feat: added a lot of logs to help debug on runtime
fix: fix wrong syscall ID on runtime
2026-03-09 00:41:51 -03:00
Antonio Guastella ccd17e5244 Issue 13: Minimal libpad (SIO2/PAD) stubs, input mapping and tests (#69)
* pad: implement basic input mapping and stubs

Add a minimal libpad implementation backed by raylib input
Provide override hooks for deterministic tests
Add pad input tests and link runtime into test target

* FIX: moved pad override test hooks to ps2_call_list.h

* pad: move test hooks to X macro list + removing __cplusplus ifdef

* removed one last ifdef remaining

* refresh PR merge status

---------

Co-authored-by: Ranieri <ran-junior@hotmail.com>
2026-03-03 16:02:04 -03:00
Ranieri 669114f3f6 Feature/runtime review codegen fixes (#87)
* feat: small fixes on code gen

* feat: added code gen test

* feat: rename IOP

* fix: fix special case on JR
feat: added code generator test

* feat: ps2 logs now need special macros

* feat: a lot of regressions test
feat: use test to fix bugs on runtime
fix: fix incorrect instructions on code generator
feat: added missing decode on r5900 decoder
feat: added scissor on rasterizer

* feat: better ghidra plugin analyzer
fix: fix real bug on function finding on elf analyzer

* feat: some logs on GS
feat: added more syscalls stubs
feat: added more ps2 stubs

* feat: added missing stub
2026-02-27 03:44:59 -03:00
DanielSvoboda 8d1f1c5672 Fix 'max' (#81) 2026-02-24 19:05:25 -03:00
Aslan Hud 1551d59fbc Feat: GS, VIF1, VU1 pathways + font rendering stubs + mpeg stubs (#80)
* GS stubs (ps2_stubs_gs.inl):
- Replace direct VRAM writes with GIF packet path
- sceGsExecLoadImage: build GIF packet, set MADR/QWC/CHCR
- sceGsExecStoreImage: GIF packet, processPendingTransfers, consumeLocalToHostBytes
- sceGsPutDispEnv/sceGsPutDrawEnv: program GIF DMA Path3 (5/9 QWs)
- sceGsResetGraph: GIF packet + writeIORegister for pmode/smode2/dispfb/display/bgcolor
- sceGsSetDefDrawEnv: GIF packet layout, sceGszbufaddr for zbuf
- sceGsSyncPath: processPendingTransfers, poll DMA channels
- sceGsSyncV/sceGsSyncVCallback: return 0
- sceGszbufaddr: zbuf calculation (width/height blocks, gparam)

Helpers (ps2_stubs_helpers.inl):
- GsDispEnvMem: 5 fields (pmode, smode2, dispfb, display, bgcolor) for GIF layout
- writeGsDispEnv: read-modify-write pattern
- toDmaPhys: SPR (scratchpad) handling for DMA MADR bit 31
- submitDmaSend: chain mode (chcr=0x185) for sceDmaSend/sceDmaSendI/sceDmaSendM

Misc stubs (ps2_stubs_misc.inl):
- Add sceeFontInit, sceeFontLoadFont, sceeFontPrintfAt, sceeFontPrintfAt2
- Add sceeFontClose, sceeFontSetColour, sceeFontSetMode, sceeFontSetFont, sceeFontSetScale
- Font stubs use GIF packets for CLUT and texture upload

Call list (ps2_call_list.h):
- Add sceeFont* entries between sceGszbufaddr and sceIoctl

* added: added more scee font stubs in stubs misc
fix: fixed flickering error when rendering in memory.cpp

* fix: fixed linux build error
2026-02-24 19:04:52 -03:00
Aslan Hud c1e98c9398 Add IOP, audio, pad, fio changes, VAG handling, and call-stack logger (#76)
- Add IOP with RPC handling (handleRPC, LibSd SID) and init/reset using RDRAM
- Add IOP audio layer for LibSd RPC (handleLibSdRpc)
- Add PS2AudioBackend with VAG decode, onVagTransfer/onSoundCommand, raylib playback
- Add PSPadBackend with readState and raylib input
- Add IOP RAM mapping in Memory (getIOPRAM) for EE↔IOP access
- Add fio syscalls: fioOpen, fioRead, fioWrite, fioClose, fioLseek, fioMkdir
- Add VAG accumulation for fio reads (multi-chunk VagAccumEntry)
- Add ps2_log.h call-stack logger (tab-indented, Debug only, ps2_log.txt next to exe)
- Code generator: emit ps2_log include and PS_LOG_ENTRY for full functions
- Recompiler: emit ps2_log include and PS_LOG_ENTRY for stubs
- Runtime: print "[PS2 LOG] Logs saved at <path>" on exit (Debug only)
2026-02-24 11:45:52 -03:00
DanielSvoboda bac1fc9ef8 Add game name to window title (#74)
* Add game title resolution from internal database

* +

* -
2026-02-22 22:30:27 -03:00
Ranieri 8584c0613a Feature/runtime gs recompiler instructions (#73)
* feat: basic gs
feat: basic rasterizer
fix: a lot of fixes to runtime stubs
feat: basic vif intercepter
feat: return "ok" for some stubs
feat: disassembly code as comment
fix: fix code gen instructions set
fix: again jump
feat: remove unused macro
fix: fix some problematic macros
feat: track delayslots on runtime
and many more

* feat: added missing files

* fix: fix instruction test
2026-02-22 02:20:42 -03:00
Ranieri 934672ac9a Feature/code gen entry (#62)
* feat: multipass discover additional entrypoints

* feat: added helpers for returning
feat: added game overrides

* added missing PS2_SHUFFLE_EPI8 macro after report from @playmer
2026-02-18 15:10:49 -03:00
Ranieri 4a538d3589 Feature/resident evil code veronica patch 1 (#60)
* feat: split runtime code in small files to be easy to develop

* feat: split stubs in inl files

* feat: function auto link function treat functions with underscore as same as without underscore

* feat: remove underscore prefix from stubs

* feat: thread and flags refactor

* feat: propagate request stop
feat: some elf validation on runtime

* feat: remove Z7 compiler options
feat: added a literal float case error on vu

* fix: fix critical recompiler error on marking pc calls

* feat: better system interrupt
refactor: small refactor on thread system

* feat: stubs implements for resident evil code veronica

* feat: merge fileio
2026-02-17 23:33:44 -03:00
Antonio Guastella cf5f57180f Feature/mc0 IO + Win IO fixes (#57)
* mc0: map memory card paths to mcRoot and related io tests

* Fix mc0 test setup to initialize temp paths

* fix: implementing WIN32 I/O support in syscalls

* fix: avoid fioWrite deadlock

Do not lock the fd map while calling getHostFile; use the syscall file mutex around fwrite instead
2026-02-17 12:40:57 -03:00
Ranieri c4555f6723 feat: split runtime code in small files to be easy to develop (#56)
* feat: split runtime code in small files to be easy to develop

* feat: split stubs in inl files

* feat: function auto link function treat functions with underscore as same as without underscore

* feat: remove underscore prefix from stubs
2026-02-17 03:00:59 -03:00
Ranieri b7973593ee fix: added missing header include for gcc (#54) 2026-02-14 13:00:36 -03:00
Ranieri 8f747334d6 feat: refactor analyzer to not realy only on debug symbols (#53)
fix: patching NOP things that code gen already know how to handle
feat: added a bug on JAL/J/JAR code gen
feat: enhanced tom file
fix: fix memory layout for ps2 macros
feat: added a lot of not working garbabe to runtime (fix later)
feat: some code organization
feat: added new tests
feat: update readme
2026-02-13 15:02:34 -03:00
Enrique Martinez 1d1b79d5f0 Added ARM64 (Apple Silicon) support using sse2neon (#50)
* feat: implemented arm64 support for builds

* feat: explicitly add compiler flags when needed
2026-02-06 20:12:36 -03:00
Enrique Martinez c0447ce3c1 fix: trailing backslash in PS2_STUB_LIST macro (#49)
Remove trailing backslash without continuation that was causing
preprocessor errors during array initialization in ps2_runtime_calls.h.
2026-02-06 13:04:02 -03:00
Ranieri 5e4361a1c6 feat: added new empty stubs (#47) 2026-02-06 01:39:52 -03:00
Ranieri e567c4cf60 feat: added thread naming functionality (#44)
feat: improve function name sanitization
2026-02-05 02:07:49 -03:00
M. Sami Gürpınar 5d3be0e2e7 fix portability issue (#41)
* refactor: update function name checks to use contains method

* refactor: update code generation to use static_cast

* refactor: made member methods const

* refactor: made range-based loop

* refactor: make one variable constructor explicit

* refactor: remove redundant else

* refactor: turn includes to forward declarations

* refactor: brace placements turned into allman style

* refactor: structed binding for readability and clarity, used emplace_back to prevent extra-copied object

* fix: add dwarf_private.h include

* fix: update GPR_U32 and GPR_S32 macros to use _mm_extract_epi32 for SSE/AVX intrinsics
2026-02-03 10:25:22 -03:00
Joshua T. Fisher e770572116 ps2_recomp lib and runner separation, fix runtime default build (#36)
* Separate the exe and lib of ps2_recomp.

* Move macro header to runtime, don't generate it, apply generated diff.
2026-01-31 19:29:18 -03:00
Ran-j af53b08543 feat: added more empty stubs
feat: added TODO_NAMED to help debug
fix: disable for now audio thread
2026-01-28 16:37:18 -03:00
Ran-j b8c1d7eaee feat: add runtime stubs for missing IOP calls
fix: fix small function on recompiler
2026-01-28 03:11:45 -03:00
Ran-j b1f86a7597 feat: auto set runtime internal stubs and syscalls on recompiled code 2026-01-27 17:12:35 -03:00
Ran-j 2e08d5e87b refactor: refactor runtime and recompile for better workflow and correct generating code and analyze output 2026-01-04 22:21:50 -03:00
Ran-j 2d1f7ec07f feat: added missing v0 instructions
feat: added threads inplementation on ps2 syscalls
feat: patch entrypoint on recompiler
feat: ps2 macros now is part of the runtime
feat: use thread to hold game loop
feat: sanitize functions like point out by chrisking1981
fix: fix old instructions cast
fix: fix missing patch for opcode j
2025-12-27 11:33:24 -03:00
Ran-j c05d8f1809 feat: misc fixes 2025-11-29 18:19:36 -03:00
Ran-j 9f05b32713 feat: update ps2 stubs API 2025-11-29 02:30:18 -03:00
Ran-j fae9a7ad71 feat: update ps2 CPU context 2025-11-29 02:28:05 -03:00
Ran-j b56dd174e9 feat: update ps2 syscalls api to match register 2025-11-29 01:40:06 -03:00
Ran-j c423e2f1ae feat: misc runtime changes 2025-11-29 00:18:25 -03:00
Ran-j 7f17931249 feat: remove unused function from rumtime ps2 syscall 2025-06-24 09:30:42 -03:00
Ran-j 0df7594bbb feat: added runtime frame decoder and entrypoint 2025-06-24 00:28:01 -03:00
Ran-j 5fde9612a9 feat: runtime fixes and finish implementations 2025-05-29 18:11:53 -03:00
Ran-j a0314c9847 feat: placeholder for exec VU0Microprogram 2025-05-29 16:21:00 -03:00
Ran-j 342bb19607 feat: added more instructions with revision 2025-05-29 16:20:08 -03:00
Ran-j 70f672cfd8 feat: better decode and code gen (remove some old instruction) 2025-04-24 12:04:56 -03:00
Ran-j e09f797202 feat: added new register for runtime 2025-04-24 02:32:40 -03:00