08-30-2017, 06:39 AM
(08-30-2017, 04:37 AM)kenshen Wrote: [ -> ]with that define option, why don't you make a separate class with the specific define and any other unique psx code then wrap that into the if statement? in the meantime I have several games in my psx library namely most of the spyro games and medieval and metal gear solid that not only boot but are perfectly playable in pcsx2 as it is right now so I'll test your build.
Even though the PS2 specific and PSX specific functions are independent from each other, they are still called out of the same places. The only reason the emulator is capable of knowing which to run is because they are in the same place and a quick check on the card's isPSX() flag allows the siomode to change to match. Separate the two and I personally think it would be messy. Definitely an option worth exploring, but on the surface it seems like a steep slope.
What I had in mind...
The define is only referenced in two places. In Sio.cpp, it affects SIO Interrupts as we see here:
Code:
#ifdef SIO_INLINE_IRQS
#define SIO_INT() sioInterrupt()
#define SIO_FORCEINLINE __fi
#else
__fi void SIO_INT()
{
if( !(psxRegs.interrupt & (1<<IopEvt_SIO)) )
PSX_INT(IopEvt_SIO, 64 ); // PSXCLK/250000);
}
#define SIO_FORCEINLINE __fi
#endif
And in R3000A.cpp we see another instance:
Code:
#ifndef SIO_INLINE_IRQS
IopTestEvent(IopEvt_SIO, sioInterrupt);
#endif
The latter case is nested in a function called _psxTestInterrupts(). If this function lives up to its name, it shouldn't be a factor in PS2 mode. It's an ifndef, if not defined. So if removing the define is a condition for PSX games being save capable... on paper, that makes the entire ifndef arbitrary, as it would be satisfied every time. In short, cut out the ifndef and just call the function in sequence with the other calls in there.
The former is a little more involved but from what I can tell it centers around this SIO_INT() function. If the define is there, macro it such that SIO_INT() is now sioInterrupt(). If not, create definition for function SIO_INT(). In both cases, macro SIO_FORCEINLINE so that it is now __fi. I have no idea what __fi is, I will have to look into that. But that is beside the point. My thought here is, if we are crudely adhering to "the define is a must for PS2 but a problem for PSX", why not just find all the places SIO_INT() shows up, and replace those with sioInterrupt() when we know it is a PS2 game (the PS2 specific SIO functions), and make SIO_INT() a plain old function declaration without any fancy preprocessor constraints when we know it is a PSX game (the PSX specific SIO functions)? Throw in the #define SIO_FORCEINLINE __fi at the top of the file, and call it done?
That's the concept I have floating in my mind. No idea if I can implement this yet. I am treading into unfamiliar C++ territory here so if I just said anything completely off the wall, feel free to reality check me.