2012-12-29 01:10:29 +00:00
|
|
|
#include "../Core/MemMap.h"
|
|
|
|
#include "GeDisasm.h"
|
2012-12-28 20:58:00 +00:00
|
|
|
#include "GPUCommon.h"
|
2012-12-29 01:10:29 +00:00
|
|
|
#include "GPUState.h"
|
|
|
|
|
|
|
|
|
2012-12-28 20:58:00 +00:00
|
|
|
|
|
|
|
static int dlIdGenerator = 1;
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
dlIdGenerator = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPUCommon::listStatus(int listid)
|
|
|
|
{
|
2013-01-10 08:02:55 +00:00
|
|
|
for(DisplayListQueue::iterator it(dlQueue.begin()); it != dlQueue.end(); ++it)
|
2012-12-28 20:58:00 +00:00
|
|
|
{
|
|
|
|
if(it->id == listid)
|
|
|
|
{
|
|
|
|
return it->status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0x80000100; // INVALID_ID
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:50:35 +00:00
|
|
|
u32 GPUCommon::EnqueueList(u32 listpc, u32 stall, int subIntrBase, bool head)
|
2012-12-28 20:58:00 +00:00
|
|
|
{
|
|
|
|
DisplayList dl;
|
|
|
|
dl.id = dlIdGenerator++;
|
|
|
|
dl.pc = listpc & 0xFFFFFFF;
|
|
|
|
dl.stall = stall & 0xFFFFFFF;
|
|
|
|
dl.status = PSP_GE_LIST_QUEUED;
|
2012-12-22 06:50:35 +00:00
|
|
|
dl.subIntrBase = subIntrBase;
|
2012-12-28 20:58:00 +00:00
|
|
|
if(head)
|
|
|
|
dlQueue.push_front(dl);
|
|
|
|
else
|
|
|
|
dlQueue.push_back(dl);
|
|
|
|
ProcessDLQueue();
|
|
|
|
return dl.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::UpdateStall(int listid, u32 newstall)
|
|
|
|
{
|
2013-01-09 21:13:09 +00:00
|
|
|
|
|
|
|
for (auto iter = dlQueue.begin(); iter != dlQueue.end(); ++iter)
|
2012-12-28 20:58:00 +00:00
|
|
|
{
|
2013-01-09 21:13:09 +00:00
|
|
|
DisplayList &cur = *iter;
|
|
|
|
if (cur.id == listid)
|
2012-12-28 20:58:00 +00:00
|
|
|
{
|
2013-01-09 21:13:09 +00:00
|
|
|
cur.stall = newstall & 0xFFFFFFF;
|
2012-12-28 20:58:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessDLQueue();
|
2012-12-29 01:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GPUCommon::InterpretList(DisplayList &list)
|
|
|
|
{
|
|
|
|
currentList = &list;
|
|
|
|
// Reset stackptr for safety
|
|
|
|
stackptr = 0;
|
|
|
|
u32 op = 0;
|
|
|
|
prev = 0;
|
|
|
|
finished = false;
|
|
|
|
while (!finished)
|
|
|
|
{
|
|
|
|
list.status = PSP_GE_LIST_DRAWING;
|
|
|
|
if (!Memory::IsValidAddress(list.pc)) {
|
|
|
|
ERROR_LOG(G3D, "DL PC = %08x WTF!!!!", list.pc);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (list.pc == list.stall)
|
|
|
|
{
|
|
|
|
list.status = PSP_GE_LIST_STALL_REACHED;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
op = Memory::ReadUnchecked_U32(list.pc); //read from memory
|
|
|
|
u32 cmd = op >> 24;
|
|
|
|
u32 diff = op ^ gstate.cmdmem[cmd];
|
|
|
|
PreExecuteOp(op, diff);
|
|
|
|
// TODO: Add a compiler flag to remove stuff like this at very-final build time.
|
|
|
|
if (dumpThisFrame_) {
|
|
|
|
char temp[256];
|
|
|
|
GeDisassembleOp(list.pc, op, prev, temp);
|
|
|
|
NOTICE_LOG(G3D, "%s", temp);
|
|
|
|
}
|
|
|
|
gstate.cmdmem[cmd] = op; // crashes if I try to put the whole op there??
|
|
|
|
|
|
|
|
ExecuteOp(op, diff);
|
|
|
|
|
|
|
|
list.pc += 4;
|
|
|
|
prev = op;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GPUCommon::ProcessDLQueue()
|
|
|
|
{
|
|
|
|
DisplayListQueue::iterator iter = dlQueue.begin();
|
|
|
|
while (!(iter == dlQueue.end()))
|
|
|
|
{
|
|
|
|
DisplayList &l = *iter;
|
|
|
|
DEBUG_LOG(G3D,"Okay, starting DL execution at %08x - stall = %08x", l.pc, l.stall);
|
|
|
|
if (!InterpretList(l))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//At the end, we can remove it from the queue and continue
|
|
|
|
dlQueue.erase(iter);
|
|
|
|
//this invalidated the iterator, let's fix it
|
|
|
|
iter = dlQueue.begin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true; //no more lists!
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::PreExecuteOp(u32 op, u32 diff) {
|
|
|
|
// Nothing to do
|
2012-12-29 19:41:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::DoState(PointerWrap &p) {
|
|
|
|
p.Do(dlIdGenerator);
|
|
|
|
p.Do<DisplayList>(dlQueue);
|
|
|
|
p.DoMarker("GPUCommon");
|
|
|
|
}
|