grumpycoders / pcsx-redux

The PCSX-Redux project is a collection of tools, research, hardware design, and libraries aiming at development and reverse engineering on the PlayStation 1. The core product itself, PCSX-Redux, is yet another fork of the Playstation emulator, PCSX.
https://pcsx-redux.consoledev.net
GNU General Public License v2.0
664 stars 108 forks source link

[psyqo] basic "hello" sample doesn't work on Mednafen #1769

Open eliasdaler opened 1 month ago

eliasdaler commented 1 month ago

The psyqo applications (even basic ones) don't seem to work on Mednafen - here's a "hello" sample - it hangs somewhere after the first frame (but seems to boot and do a clear):

image

~/work/ps1dev$ mednafen --version
Starting Mednafen 1.32.1
 Build information:
   Compiled with gcc 13.2.0
   Compiled against zlib 1.3, running with zlib 1.3.1(flags=0x000000a9)
   Compiled against SDL 2.30.1(SDL-release-2.30.1-0-g5adbf3765 (Debian 2.30.1+dfsg-4)), running with SDL 2.30.7(SDL-release-2.30.7-0-g9519b9916 (Debian 2.30.7+dfsg-1))
   Running with libFLAC 1.4.3
 Base directory: /home/eliasdaler/.mednafen
 Emulation modules: apple2 nes snes gb gba pce lynx md pcfx ngp psx ss ssfplay vb wswan sms gg sasplay snes_faust pce_fast demo cdplay

Here's a .cue/.iso of the demo I built:

game.zip

And here's the output of "warnings" psx.dbg_mask of Mednafen - not sure if it's relevant, because most of the warnings happen during boot logo: dbg_out.txt

nicolasnoble commented 1 month ago

I mean, supporting all emulators out there is going to be difficult. The main loop is definitely different from the typical one from psyq, and there's absolutely a few tricks used here and there that are unusual, even though I tried to avoid really nasty stuff which I know would've been hell to work out on emulators.

My point being, this feels more like this belongs to the mednafen repository than anything else. I'm more than happy to help locate what the emulator is doing that's not proper, but it's also likely documented in the psx-spx, so emulators following it would have no issues.

My hunch is how psyqo is handling DMA transfers, which uses documented behavior of the DMA hardware registers but which is rarely used by games. Note that I said "rarely" , not "never".

This code, basically: https://github.com/grumpycoders/pcsx-redux/blob/300e80b3070e83d5bd2061175daa11d26d3de4ac/src/mips/psyqo/src/gpu.cpp#L137-L186

I know I surprised @stenzek with it, who had to tweak some details of his own implementation in Duckstation.

Note this works fine in older but proper emulators like Xebra.

eliasdaler commented 1 month ago

My point being, this feels more like this belongs to the mednafen repository than anything else. I'm more than happy to help locate what the emulator is doing that's not proper, but it's also likely documented in the psx-spx, so emulators following it would have no issues.

Yes, I understand that it might be mednafen doing wrong things, so it would be good if you could take a look so that I don't come to them with the code and it turns out that it's the psyqo issue. If it's mednafen doing things wrong, I'll report it to them. :)

It would be great to support mednafen as well as it's yet another data point for some bugs which show up on HW, but don't show up in Redux/Duckstation.

nicolasnoble commented 1 month ago

Right, we can try and narrow it down a bit, but FYI, there's also emulators like older PCSX, ePSXe, or even no$psx, which also struggle with this code, afaik. Basically, they don't properly update the DMA hardware registers upon completion, and psyqo heavily relies on that to avoid a way more costly back-and-forth to the main loop.