- FIFO changes - minor cleanup, code organization based on Nolan's changes
- Minor code cleanup
- CommandProcessor changes - Allow BP IRQ clearing for either raising or falling edges.
- Revived old SetFifoIdle code

Gets Pokemon XD to run, but will crash to any CPU-GPU desync. Other games like Metroid Prime, look happy with the new FIFO changes.

Please report any problems.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3984 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
omegadox 2009-08-15 07:33:35 +00:00
parent 7e43c60314
commit b71b0e3da2
5 changed files with 53 additions and 51 deletions

View File

@ -339,6 +339,7 @@ THREAD_RETURN EmuThread(void *pArg)
VideoInitialize.pUpdateInterrupts = &(CommandProcessor::UpdateInterruptsFromVideoPlugin); VideoInitialize.pUpdateInterrupts = &(CommandProcessor::UpdateInterruptsFromVideoPlugin);
VideoInitialize.pMemoryBase = Memory::base; VideoInitialize.pMemoryBase = Memory::base;
VideoInitialize.pKeyPress = Callback_KeyPress; VideoInitialize.pKeyPress = Callback_KeyPress;
VideoInitialize.pSetFifoIdle = &(CommandProcessor::SetFifoIdleFromVideoPlugin);
VideoInitialize.bWii = _CoreParameter.bWii; VideoInitialize.bWii = _CoreParameter.bWii;
VideoInitialize.bUseDualCore = _CoreParameter.bUseDualCore; VideoInitialize.bUseDualCore = _CoreParameter.bUseDualCore;
VideoInitialize.pBBox = &PixelEngine::bbox[0]; VideoInitialize.pBBox = &PixelEngine::bbox[0];

View File

@ -152,6 +152,7 @@ u16 m_tokenReg;
SCPFifoStruct fifo; //This one is shared between gfx thread and emulator thread SCPFifoStruct fifo; //This one is shared between gfx thread and emulator thread
static u32 fake_GPWatchdogLastToken = 0; static u32 fake_GPWatchdogLastToken = 0;
static Common::Event s_fifoIdleEvent;
void DoState(PointerWrap &p) void DoState(PointerWrap &p)
{ {
@ -191,7 +192,8 @@ void IncrementGPWDToken()
void WaitForFrameFinish() void WaitForFrameFinish()
{ {
while ((fake_GPWatchdogLastToken == fifo.Fake_GPWDToken) && fifo.bFF_GPReadEnable && (fifo.CPReadWriteDistance > 0) && !(fifo.bFF_BPEnable && fifo.bFF_Breakpoint)) while ((fake_GPWatchdogLastToken == fifo.Fake_GPWDToken) && fifo.bFF_GPReadEnable && (fifo.CPReadWriteDistance > 0) && !(fifo.bFF_BPEnable && fifo.bFF_Breakpoint))
Common::YieldCPU(); s_fifoIdleEvent.MsgWait();
fake_GPWatchdogLastToken = fifo.Fake_GPWDToken; fake_GPWatchdogLastToken = fifo.Fake_GPWDToken;
} }
@ -222,11 +224,14 @@ void Init()
fifo.CPCmdIdle = 1 ; fifo.CPCmdIdle = 1 ;
fifo.CPReadIdle = 1; fifo.CPReadIdle = 1;
s_fifoIdleEvent.Init();
et_UpdateInterrupts = CoreTiming::RegisterEvent("UpdateInterrupts", UpdateInterrupts_Wrapper); et_UpdateInterrupts = CoreTiming::RegisterEvent("UpdateInterrupts", UpdateInterrupts_Wrapper);
} }
void Shutdown() void Shutdown()
{ {
s_fifoIdleEvent.Shutdown();
} }
void Read16(u16& _rReturnValue, const u32 _Address) void Read16(u16& _rReturnValue, const u32 _Address)
@ -377,7 +382,7 @@ void Write16(const u16 _Value, const u32 _Address)
// (mb2) We don't sleep here since it could be a perf issue for super monkey ball (yup only this game IIRC) // (mb2) We don't sleep here since it could be a perf issue for super monkey ball (yup only this game IIRC)
// Touching that game is a no-go so I don't want to take the risk :p // Touching that game is a no-go so I don't want to take the risk :p
while (fifo.bFF_GPReadEnable && fifo.CPReadWriteDistance > 0 && !(fifo.bFF_BPEnable && fifo.bFF_Breakpoint) ) while (fifo.bFF_GPReadEnable && fifo.CPReadWriteDistance > 0 && !(fifo.bFF_BPEnable && fifo.bFF_Breakpoint) )
Common::YieldCPU(); s_fifoIdleEvent.MsgWait();
} }
} }
@ -428,9 +433,9 @@ void Write16(const u16 _Value, const u32 _Address)
// BP interrupt is cleared here // BP interrupt is cleared here
//if (tmpCtrl.CPIntEnable)
if (!m_CPCtrlReg.CPIntEnable && tmpCtrl.CPIntEnable) // raising edge
//if (m_CPCtrlReg.CPIntEnable && !tmpCtrl.Hex) // falling edge //if (m_CPCtrlReg.CPIntEnable && !tmpCtrl.Hex) // falling edge
// raising edge or falling egde
if ((!m_CPCtrlReg.CPIntEnable && tmpCtrl.CPIntEnable) || (m_CPCtrlReg.CPIntEnable && !tmpCtrl.Hex))
{ {
m_CPStatusReg.Breakpoint = 0; m_CPStatusReg.Breakpoint = 0;
Common::AtomicStore(fifo.bFF_Breakpoint, 0); Common::AtomicStore(fifo.bFF_Breakpoint, 0);
@ -608,7 +613,7 @@ void STACKALIGN GatherPipeBursted()
INFO_LOG(COMMANDPROCESSOR, "(GatherPipeBursted): CPHiWatermark reached"); INFO_LOG(COMMANDPROCESSOR, "(GatherPipeBursted): CPHiWatermark reached");
// Wait for GPU to catch up // Wait for GPU to catch up
while (!(fifo.bFF_BPEnable && fifo.bFF_Breakpoint) && fifo.CPReadWriteDistance > fifo.CPLoWatermark) while (!(fifo.bFF_BPEnable && fifo.bFF_Breakpoint) && fifo.CPReadWriteDistance > fifo.CPLoWatermark)
Common::YieldCPU(); s_fifoIdleEvent.MsgWait();
} }
// check if we are in sync // check if we are in sync
_assert_msg_(COMMANDPROCESSOR, fifo.CPWritePointer == CPeripheralInterface::Fifo_CPUWritePointer, "FIFOs linked but out of sync"); _assert_msg_(COMMANDPROCESSOR, fifo.CPWritePointer == CPeripheralInterface::Fifo_CPUWritePointer, "FIFOs linked but out of sync");
@ -677,7 +682,6 @@ void CatchUpGPU()
// adjust, take care // adjust, take care
ptr = Memory::GetPointer(fifo.CPReadPointer); ptr = Memory::GetPointer(fifo.CPReadPointer);
INFO_LOG(COMMANDPROCESSOR, "BUFFER LOOP"); INFO_LOG(COMMANDPROCESSOR, "BUFFER LOOP");
// PanicAlert("loop now");
} }
} }
} }
@ -734,4 +738,9 @@ void UpdateInterruptsFromVideoPlugin()
CoreTiming::ScheduleEvent_Threadsafe(0, et_UpdateInterrupts); CoreTiming::ScheduleEvent_Threadsafe(0, et_UpdateInterrupts);
} }
void SetFifoIdleFromVideoPlugin()
{
s_fifoIdleEvent.Set();
}
} // end of namespace CommandProcessor } // end of namespace CommandProcessor

View File

@ -81,6 +81,7 @@ void CatchUpGPU();
void GatherPipeBursted(); void GatherPipeBursted();
void UpdateInterrupts(); void UpdateInterrupts();
void UpdateInterruptsFromVideoPlugin(); void UpdateInterruptsFromVideoPlugin();
void SetFifoIdleFromVideoPlugin();
bool AllowIdleSkipping(); bool AllowIdleSkipping();
@ -88,8 +89,8 @@ bool AllowIdleSkipping();
void IncrementGPWDToken(); void IncrementGPWDToken();
void WaitForFrameFinish(); void WaitForFrameFinish();
} // end of namespace CommandProcessor } // namespace CommandProcessor
#endif #endif // _COMMANDPROCESSOR_H

View File

@ -25,20 +25,17 @@
#include "Fifo.h" #include "Fifo.h"
volatile bool g_bSkipCurrentFrame = false; volatile bool g_bSkipCurrentFrame = false;
volatile bool g_EFBAccessRequested = false;
extern u8* g_pVideoData; extern u8* g_pVideoData;
volatile bool g_EFBAccessRequested = false; namespace
{
namespace {
static volatile bool fifoStateRun = false; static volatile bool fifoStateRun = false;
static u8 *videoBuffer; static u8 *videoBuffer;
static Common::Event fifo_exit_event; static Common::Event fifo_exit_event;
static Common::CriticalSection s_criticalFifo; static Common::CriticalSection s_criticalFifo;
// STATE_TO_SAVE // STATE_TO_SAVE
static int size = 0; static int size = 0;
} // namespace } // namespace
void Fifo_DoState(PointerWrap &p) void Fifo_DoState(PointerWrap &p)
@ -78,8 +75,9 @@ u8* FAKE_GetFifoEndPtr()
return &videoBuffer[size]; return &videoBuffer[size];
} }
void Fifo_SetRendering(bool bEnabled) { void Fifo_SetRendering(bool enabled)
g_bSkipCurrentFrame = !bEnabled; {
g_bSkipCurrentFrame = !enabled;
} }
// Executed from another thread, no the graphics thread! // Executed from another thread, no the graphics thread!
@ -133,9 +131,7 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize)
while (fifoStateRun) while (fifoStateRun)
{ {
video_initialize.pPeekMessages(); video_initialize.pPeekMessages();
VideoFifo_CheckEFBAccess(); VideoFifo_CheckEFBAccess();
VideoFifo_CheckSwapRequest(); VideoFifo_CheckSwapRequest();
s_criticalFifo.Enter(); s_criticalFifo.Enter();
@ -145,58 +141,52 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize)
{ {
Common::AtomicStore(_fifo.CPReadIdle, 0); Common::AtomicStore(_fifo.CPReadIdle, 0);
while (_fifo.bFF_GPReadEnable && _fifo.CPReadWriteDistance) do
{ {
if (!fifoStateRun) if (!fifoStateRun)
break; break;
// Get the Read Pointer
// Create pointer to video data and send it to the VideoPlugin // Create pointer to video data and send it to the VideoPlugin
u32 readPtr = _fifo.CPReadPointer; u32 readPtr = _fifo.CPReadPointer;
u8 *uData = video_initialize.pGetMemoryPointer(readPtr);
// Set distance
// if we are on BP mode we must send 32B chunks to Video plugin for BP checking // if we are on BP mode we must send 32B chunks to Video plugin for BP checking
// TODO (mb2): test & check if MP1/MP2 realy need this now. distToSend = _fifo.bFF_BPEnable ? 32 : _fifo.CPReadWriteDistance;
if (_fifo.bFF_BPEnable) // send 1024B chunk max length to have better control over PeekMessages' period
{ //distToSend = distToSend > 1024 ? 1024 : distToSend;
if (readPtr == _fifo.CPBreakpoint)
{ // Get Data based on pointer
Common::AtomicStore(_fifo.bFF_Breakpoint, 1); u8 *uData = video_initialize.pGetMemoryPointer(readPtr);
video_initialize.pUpdateInterrupts();
break; // Check Pointer and move pointer
} if ((distToSend + readPtr) >= _fifo.CPEnd)
distToSend = 32;
readPtr += 32;
if ( readPtr >= _fifo.CPEnd)
readPtr = _fifo.CPBase;
}
else
{ {
distToSend = _fifo.CPReadWriteDistance; distToSend =_fifo.CPEnd - readPtr;
// send 1024B chunk max length to have better control over PeekMessages' period readPtr = _fifo.CPBase;
distToSend = distToSend > 1024 ? 1024 : distToSend;
if ((distToSend + readPtr) >= _fifo.CPEnd) // TODO: better?
{
distToSend =_fifo.CPEnd - readPtr;
readPtr = _fifo.CPBase;
}
else
readPtr += distToSend;
} }
else
readPtr += distToSend;
// Execute new instructions found in uData // Execute new instructions found in uData
Fifo_SendFifoData(uData, distToSend); Fifo_SendFifoData(uData, distToSend);
//Check BP Mode - Pokemon XD wants this to be called after the pointer move
if (_fifo.bFF_BPEnable && (readPtr == _fifo.CPBreakpoint))
{
Common::AtomicStore(_fifo.bFF_Breakpoint, 1);
video_initialize.pUpdateInterrupts();
}
// Update CPReadPointer and RWDistance
Common::AtomicStore(_fifo.CPReadPointer, readPtr); Common::AtomicStore(_fifo.CPReadPointer, readPtr);
Common::AtomicAdd(_fifo.CPReadWriteDistance, -distToSend); Common::AtomicAdd(_fifo.CPReadWriteDistance, -distToSend);
video_initialize.pPeekMessages();
VideoFifo_CheckEFBAccess(); } while (_fifo.bFF_GPReadEnable && _fifo.CPReadWriteDistance && !(_fifo.bFF_BPEnable && _fifo.bFF_Breakpoint));
VideoFifo_CheckSwapRequest();
}
Common::AtomicStore(_fifo.CPReadIdle, 1); Common::AtomicStore(_fifo.CPReadIdle, 1);
video_initialize.pSetFifoIdle();
} }
else else
{ {

View File

@ -21,6 +21,7 @@ typedef unsigned int (*TPeekMessages)(void);
typedef void (*TUpdateInterrupts)(void); typedef void (*TUpdateInterrupts)(void);
typedef void (*TUpdateFPSDisplay)(const char* text); // sets the window title typedef void (*TUpdateFPSDisplay)(const char* text); // sets the window title
typedef void (*TKeyPressed)(int keycode, bool shift, bool control); // sets the window title typedef void (*TKeyPressed)(int keycode, bool shift, bool control); // sets the window title
typedef void (*TSetFifoIdle)();
enum FieldType enum FieldType
{ {
@ -81,7 +82,7 @@ typedef struct
TUpdateInterrupts pUpdateInterrupts; TUpdateInterrupts pUpdateInterrupts;
TUpdateFPSDisplay pUpdateFPSDisplay; TUpdateFPSDisplay pUpdateFPSDisplay;
TKeyPressed pKeyPress; TKeyPressed pKeyPress;
TSetFifoIdle pSetFifoIdle;
SCPFifoStruct *pCPFifo; SCPFifoStruct *pCPFifo;
void *pMemoryBase; void *pMemoryBase;
bool bWii; bool bWii;