diff --git a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs index c1420387b2..0c033643be 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs @@ -347,11 +347,11 @@ namespace BizHawk.Emulation.Cores.Sony.PSX } - [FeatureNotImplemented] public void ResetCounters() { - // FIXME when all this stuff is implemented Frame = 0; + LagCount = 0; + IsLagFrame = false; } void SetInput() @@ -513,6 +513,15 @@ namespace BizHawk.Emulation.Cores.Sony.PSX OctoshockDll.shock_Step(psx, OctoshockDll.eShockStep.Frame); //------------------------ + //lag maintenance: + int pad1 = OctoshockDll.shock_Peripheral_PollActive(psx, 0x01, true); + int pad2 = OctoshockDll.shock_Peripheral_PollActive(psx, 0x02, true); + IsLagFrame = true; + if (pad1 == OctoshockDll.SHOCK_TRUE) IsLagFrame = false; + if (pad2 == OctoshockDll.SHOCK_TRUE) IsLagFrame = false; + if (IsLagFrame) + LagCount++; + //what happens to sound in this case? if (render == false) return; diff --git a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/OctoshockDll.cs b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/OctoshockDll.cs index 2db3755599..d438629d5d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/OctoshockDll.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/OctoshockDll.cs @@ -193,6 +193,9 @@ namespace BizHawk.Emulation.Cores.Sony.PSX [DllImport(dd, CallingConvention = cc)] public static extern int shock_Peripheral_MemcardTransact(IntPtr psx, int address, ref ShockMemcardTransaction transaction); + [DllImport(dd, CallingConvention = cc)] + public static extern int shock_Peripheral_PollActive(IntPtr psx, int address, bool clear); + [DllImport(dd, CallingConvention = cc)] public static extern int shock_MountEXE(IntPtr psx, void* exebuf, int size); diff --git a/output/dll/octoshock.dll b/output/dll/octoshock.dll index 172ef0f5dd..6b99c891ed 100644 Binary files a/output/dll/octoshock.dll and b/output/dll/octoshock.dll differ diff --git a/psx/octoshock/bizhawk/octoshock.vcxproj b/psx/octoshock/bizhawk/octoshock.vcxproj index 17d4399f4d..34e123e3ad 100644 --- a/psx/octoshock/bizhawk/octoshock.vcxproj +++ b/psx/octoshock/bizhawk/octoshock.vcxproj @@ -39,7 +39,9 @@ - + + false + @@ -54,6 +56,8 @@ + + diff --git a/psx/octoshock/bizhawk/octoshock.vcxproj.filters b/psx/octoshock/bizhawk/octoshock.vcxproj.filters index 72d05a57b3..060c5e61e5 100644 --- a/psx/octoshock/bizhawk/octoshock.vcxproj.filters +++ b/psx/octoshock/bizhawk/octoshock.vcxproj.filters @@ -215,6 +215,12 @@ cdrom + + emuware + + + emuware + diff --git a/psx/octoshock/emuware/PACKED.h b/psx/octoshock/emuware/PACKED.h deleted file mode 100644 index eaef0c7a40..0000000000 --- a/psx/octoshock/emuware/PACKED.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __GNUC__ -#pragma pack(push, 1) -#pragma warning(disable : 4103) -#endif - -#ifndef __PACKED - #ifdef __GNUC__ - #define __PACKED __attribute__((__packed__)) - #else - #define __PACKED - #endif -#endif diff --git a/psx/octoshock/emuware/PACKED_END.h b/psx/octoshock/emuware/PACKED_END.h deleted file mode 100644 index 6eb7bd7c15..0000000000 --- a/psx/octoshock/emuware/PACKED_END.h +++ /dev/null @@ -1,3 +0,0 @@ -#ifndef __GNUC__ -#pragma pack(pop) -#endif diff --git a/psx/octoshock/emuware/emuware.h b/psx/octoshock/emuware/emuware.h index 99b9d5a21b..b4e6b828a0 100644 --- a/psx/octoshock/emuware/emuware.h +++ b/psx/octoshock/emuware/emuware.h @@ -150,3 +150,10 @@ char (*BLAHBLAHBLAH( UNALIGNED T (&)[N] ))[N]; #else #define EW_EXPORT extern "C" __declspec(dllimport) #endif + +//http://stackoverflow.com/questions/1537964/visual-c-equivalent-of-gccs-attribute-packed +#ifdef _MSC_VER +#define EW_PACKED( ... ) __pragma( pack(push, 1) ) __VA_ARGS__ __pragma( pack(pop) ) +#else +#define EW_PACKED( ... ) __Declaration__ __VA_ARGS__ ((__packed__)) +#endif diff --git a/psx/octoshock/psx/cdc.cpp b/psx/octoshock/psx/cdc.cpp index 87b003b3f6..76457c077e 100644 --- a/psx/octoshock/psx/cdc.cpp +++ b/psx/octoshock/psx/cdc.cpp @@ -537,7 +537,7 @@ void PS_CDC::GetCDAudio(int32 samples[2]) ApplyVolume(samples); } -#include "emuware/PACKED.h" +EW_PACKED( struct XA_Subheader { uint8 file; @@ -549,16 +549,14 @@ struct XA_Subheader uint8 channel_dup; uint8 submode_dup; uint8 coding_dup; -}; -#include "emuware/PACKED_END.h" +}); -#include "emuware/PACKED.h" +EW_PACKED( struct XA_SoundGroup { uint8 params[16]; uint8 samples[112]; -}; -#include "emuware/PACKED_END.h" +}); #define XA_SUBMODE_EOF 0x80 #define XA_SUBMODE_REALTIME 0x40 diff --git a/psx/octoshock/psx/frontio.cpp b/psx/octoshock/psx/frontio.cpp index 474f63e294..ef47b12407 100644 --- a/psx/octoshock/psx/frontio.cpp +++ b/psx/octoshock/psx/frontio.cpp @@ -35,7 +35,7 @@ namespace MDFN_IEN_PSX { -InputDevice::InputDevice() : chair_r(0), chair_g(0), chair_b(0), draw_chair(0), chair_x(-1000), chair_y(-1000) +InputDevice::InputDevice() : chair_r(0), chair_g(0), chair_b(0), chair_x(-1000), chair_y(-1000) { } diff --git a/psx/octoshock/psx/frontio.h b/psx/octoshock/psx/frontio.h index 4d08377d3e..900997eb98 100644 --- a/psx/octoshock/psx/frontio.h +++ b/psx/octoshock/psx/frontio.h @@ -51,7 +51,6 @@ class InputDevice private: unsigned chair_r, chair_g, chair_b; - bool draw_chair; protected: int32 chair_x, chair_y; }; diff --git a/psx/octoshock/psx/gte.cpp b/psx/octoshock/psx/gte.cpp index 4cf80afb20..9463b0bc6c 100644 --- a/psx/octoshock/psx/gte.cpp +++ b/psx/octoshock/psx/gte.cpp @@ -46,13 +46,12 @@ namespace MDFN_IEN_PSX { #endif -#include "emuware/PACKED.h" +EW_PACKED( struct gtematrix { int16 MX[3][3]; int16 dummy; -}; -#include "emuware/PACKED_END.h" +}); typedef struct { diff --git a/psx/octoshock/psx/input/dualshock.cpp b/psx/octoshock/psx/input/dualshock.cpp index 5d28867896..f11ae65c40 100644 --- a/psx/octoshock/psx/input/dualshock.cpp +++ b/psx/octoshock/psx/input/dualshock.cpp @@ -77,6 +77,9 @@ class InputDevice_DualShock : public InputDevice void CheckManualAnaModeChange(void); + //non-serialized state + IO_Dualshock* io; + // // bool cur_ana_button_state; @@ -261,6 +264,7 @@ void InputDevice_DualShock::Power(void) void InputDevice_DualShock::UpdateInput(const void *data) { + io = (IO_Dualshock*)data; uint8 *d8 = (uint8 *)data; uint8* const rumb_dp = &d8[3 + 16]; @@ -438,13 +442,15 @@ bool InputDevice_DualShock::Clock(bool TxD, int32 &dsr_pulse_delay) transmit_buffer[4] = axes[0][1]; transmit_buffer[5] = axes[1][0]; transmit_buffer[6] = axes[1][1]; - transmit_count = 7; + transmit_count = 7; + io->active = 1; } else { transmit_buffer[1] = 0xFF ^ buttons[0]; transmit_buffer[2] = 0xFF ^ buttons[1]; transmit_count = 3; + io->active = 1; } } else @@ -452,8 +458,8 @@ bool InputDevice_DualShock::Clock(bool TxD, int32 &dsr_pulse_delay) command_phase = -1; transmit_buffer[1] = 0; transmit_buffer[2] = 0; - transmit_pos = 0; - transmit_count = 0; + transmit_pos = 0; + transmit_count = 0; } break; @@ -557,12 +563,14 @@ bool InputDevice_DualShock::Clock(bool TxD, int32 &dsr_pulse_delay) transmit_buffer[4] = axes[1][0]; transmit_buffer[5] = axes[1][1]; transmit_count = 6; + io->active = 1; } else { transmit_buffer[0] = 0xFF ^ buttons[0]; transmit_buffer[1] = 0xFF ^ buttons[1]; transmit_count = 2; + io->active = 1; if(!(rumble_magic[2] & 0xFE)) { diff --git a/psx/octoshock/psx/input/dualshock.h b/psx/octoshock/psx/input/dualshock.h index 36e7f3d796..08d3ea6a5b 100644 --- a/psx/octoshock/psx/input/dualshock.h +++ b/psx/octoshock/psx/input/dualshock.h @@ -1,10 +1,25 @@ #ifndef __MDFN_PSX_INPUT_DUALSHOCK_H #define __MDFN_PSX_INPUT_DUALSHOCK_H -#include +#include "octoshock.h" namespace MDFN_IEN_PSX { -InputDevice *Device_DualShock_Create(); + InputDevice *Device_DualShock_Create(); + + EW_PACKED( + struct IO_Dualshock + { + u8 buttons[3]; + u8 right_x, right_y; + u8 left_x, left_y; + u8 active; + u8 pad[8]; + u8 pad2[3]; + u16 rumble; + u8 pad3[11]; + }); } + + #endif diff --git a/psx/octoshock/psx/psx.cpp b/psx/octoshock/psx/psx.cpp index 0018535642..47d7aaa7ad 100644 --- a/psx/octoshock/psx/psx.cpp +++ b/psx/octoshock/psx/psx.cpp @@ -28,6 +28,8 @@ #include "endian.h" #include "emuware/EW_state.h" +#include "input/dualshock.h" + //#include #include @@ -1097,6 +1099,36 @@ struct { return SHOCK_OK; } + s32 PollActive(s32 address, bool clear) + { + //check the port address + int portnum = address&0x0F; + if(portnum != 1 && portnum != 2) + return SHOCK_INVALID_ADDRESS; + portnum--; + + s32 ret = SHOCK_FALSE; + + u8* buf = ports[portnum].buffer; + switch(ports[portnum].type) + { + case ePeripheralType_DualShock: + { + IO_Dualshock* io_dualshock = (IO_Dualshock*)buf; + if(io_dualshock->active) ret = SHOCK_TRUE; + if(clear) io_dualshock->active = 0; + return ret; + break; + } + + case ePeripheralType_None: + return SHOCK_NOCANDO; + + default: + return SHOCK_ERROR; + } + } + s32 SetPadInput(s32 address, u32 buttons, u8 left_x, u8 left_y, u8 right_x, u8 right_y) { //check the port address @@ -1109,14 +1141,17 @@ struct { switch(ports[portnum].type) { case ePeripheralType_DualShock: - buf[0] = (buttons>>0)&0xFF; - buf[1] = (buttons>>8)&0xFF; - buf[2] = (buttons>>16)&0xFF; //this is only the analog mode button - buf[3] = right_x; - buf[4] = right_y; - buf[5] = left_x; - buf[6] = left_y; - return SHOCK_OK; + { + IO_Dualshock* io_dualshock = (IO_Dualshock*)buf; + io_dualshock->buttons[0] = (buttons>>0)&0xFF; + io_dualshock->buttons[1] = (buttons>>8)&0xFF; + io_dualshock->buttons[2] = (buttons>>16)&0xFF; //this is only the analog mode button + io_dualshock->right_x = right_x; + io_dualshock->right_y = right_y; + io_dualshock->left_x = left_x; + io_dualshock->left_y = left_y; + return SHOCK_OK; + } default: return SHOCK_ERROR; @@ -1164,7 +1199,7 @@ struct { EW_EXPORT s32 shock_Peripheral_Connect(void* psx, s32 address, s32 type) { - return s_ShockPeripheralState.Connect(address,type); + return s_ShockPeripheralState.Connect(address, type); } EW_EXPORT s32 shock_Peripheral_SetPadInput(void* psx, s32 address, u32 buttons, u8 left_x, u8 left_y, u8 right_x, u8 right_y) @@ -1172,6 +1207,11 @@ EW_EXPORT s32 shock_Peripheral_SetPadInput(void* psx, s32 address, u32 buttons, return s_ShockPeripheralState.SetPadInput(address, buttons, left_x, left_y, right_x, right_y); } +EW_EXPORT s32 shock_Peripheral_PollActive(void* psx, s32 address, s32 clear) +{ + return s_ShockPeripheralState.PollActive(address, clear!=SHOCK_FALSE); +} + EW_EXPORT s32 shock_Peripheral_MemcardTransact(void* psx, s32 address, ShockMemcardTransaction* transaction) { return s_ShockPeripheralState.MemcardTransact(address, transaction); @@ -1731,7 +1771,7 @@ static void LoadEXE(const uint8 *data, const uint32 size, bool ignore_pcsp = fal po += 4; } -EW_EXPORT s32 shock_MountEXE(void* psx, void* exebuf, int size) +EW_EXPORT s32 shock_MountEXE(void* psx, void* exebuf, s32 size) { LoadEXE((uint8*)exebuf, (uint32)size); return SHOCK_OK; diff --git a/psx/octoshock/psx/psx.h b/psx/octoshock/psx/psx.h index 022d582a9c..90ef718f5a 100644 --- a/psx/octoshock/psx/psx.h +++ b/psx/octoshock/psx/psx.h @@ -319,8 +319,17 @@ EW_EXPORT s32 shock_Peripheral_SetPadInput(void* psx, s32 address, u32 buttons, //Performs one of several transactions on an attached memory card. EW_EXPORT s32 shock_Peripheral_MemcardTransact(void* psx, s32 address, ShockMemcardTransaction* transaction); +//Polls the given peripheral address for it's active flag status (inverse of lag flag) +//If you want, the lag flag can be cleared +//Returns SHOCK_TRUE if the input has been read this frame +//Returns SHOCK_FALSE if the input hasnt been read this frame (is lagging) +//Returns SHOCK_NOCANDO if there is no peripheral there +//Returns SHOCK_INVALID_ADDRESS if address is invalid +//Returns SHOCK_ERROR for other errors. +EW_EXPORT s32 shock_Peripheral_PollActive(void* psx, s32 address, s32 clear); + //Mounts a PS-EXE executable -EW_EXPORT s32 shock_MountEXE(void* psx, void* exebuf, int size); +EW_EXPORT s32 shock_MountEXE(void* psx, void* exebuf, s32 size); //Sets the power to ON. Returns SHOCK_NOCANDO if already on. EW_EXPORT s32 shock_PowerOn(void* psx);