Try to match especially the size of ge contexts.

But also some of the actual data, most of it matches like this.
This commit is contained in:
Unknown W. Brackets 2013-09-20 00:33:32 -07:00
parent 3604c2285a
commit 7906de26f7
3 changed files with 109 additions and 4 deletions

View File

@ -476,7 +476,7 @@ u32 sceGeSaveContext(u32 ctxAddr)
// Let's just dump gstate.
if (Memory::IsValidAddress(ctxAddr))
{
Memory::WriteStruct(ctxAddr, &gstate);
gstate.Save((u32_le *)Memory::GetPointer(ctxAddr));
}
// This action should probably be pushed to the end of the queue of the display thread -
@ -497,7 +497,7 @@ u32 sceGeRestoreContext(u32 ctxAddr)
if (Memory::IsValidAddress(ctxAddr))
{
Memory::ReadStruct(ctxAddr, &gstate);
gstate.Restore((u32_le *)Memory::GetPointer(ctxAddr));
}
ReapplyGfxState();

View File

@ -103,9 +103,110 @@ void ShutdownGfxState()
// When you have changed state outside the psp gfx core,
// or saved the context and has reloaded it, call this function.
void ReapplyGfxState()
{
void ReapplyGfxState() {
if (!gpu)
return;
gpu->ReapplyGfxState();
}
struct CmdRange {
u8 start;
u8 end;
};
static const CmdRange contextCmdRanges[] = {
{0x00, 0x02},
// Skip: {0x03, 0x0F},
{0x10, 0x10},
// Skip: {0x11, 0x11},
{0x12, 0x28},
// Skip: {0x29, 0x2B},
{0x2c, 0x33},
// Skip: {0x34, 0x35},
{0x36, 0x38},
// Skip: {0x39, 0x41},
{0x42, 0x4D},
// Skip: {0x4E, 0x4F},
{0x50, 0x51},
// Skip: {0x52, 0x52},
{0x53, 0x58},
// Skip: {0x59, 0x5A},
{0x5B, 0xB5},
// Skip: {0xB6, 0xB7},
{0xB8, 0xC3},
// Skip: {0xC4, 0xC4},
{0xC5, 0xD0},
// Skip: {0xD1, 0xD1}
{0xD2, 0xE9},
// Skip: {0xEA, 0xEA},
{0xEB, 0xEC},
// Skip: {0xED, 0xED},
{0xEE, 0xEE},
// Skip: {0xEF, 0xEF},
{0xF0, 0xF6},
// Skip: {0xF7, 0xF7},
{0xF8, 0xF9},
// Skip: {0xFA, 0xFF},
};
void GPUgstate::Save(u32_le *ptr) {
// Not sure what the first 10 values are, exactly, but these seem right.
ptr[5] = gstate_c.vertexAddr;
ptr[6] = gstate_c.indexAddr;
ptr[7] = gstate_c.offsetAddr;
// Command values start 17 bytes in.
u32_le *cmds = ptr + 17;
for (size_t i = 0; i < ARRAY_SIZE(contextCmdRanges); ++i) {
for (int n = contextCmdRanges[i].start; n <= contextCmdRanges[i].end; ++n) {
*cmds++ = cmdmem[n];
}
}
if (Memory::IsValidAddress(getClutAddress()))
*cmds++ = loadclut;
// Seems like it actually writes commands to load the matrices and then reset the counts.
*cmds++ = boneMatrixNumber;
*cmds++ = worldmtxnum;
*cmds++ = viewmtxnum;
*cmds++ = projmtxnum;
*cmds++ = texmtxnum;
u8 *matrices = (u8 *)cmds;
memcpy(matrices, boneMatrix, sizeof(boneMatrix)); matrices += sizeof(boneMatrix);
memcpy(matrices, worldMatrix, sizeof(worldMatrix)); matrices += sizeof(worldMatrix);
memcpy(matrices, viewMatrix, sizeof(viewMatrix)); matrices += sizeof(viewMatrix);
memcpy(matrices, projMatrix, sizeof(projMatrix)); matrices += sizeof(projMatrix);
memcpy(matrices, tgenMatrix, sizeof(tgenMatrix)); matrices += sizeof(tgenMatrix);
}
void GPUgstate::Restore(u32_le *ptr) {
// Not sure what the first 10 values are, exactly, but these seem right.
gstate_c.vertexAddr = ptr[5];
gstate_c.indexAddr = ptr[6];
gstate_c.offsetAddr = ptr[7];
// Command values start 17 bytes in.
u32_le *cmds = ptr + 17;
for (size_t i = 0; i < ARRAY_SIZE(contextCmdRanges); ++i) {
for (int n = contextCmdRanges[i].start; n <= contextCmdRanges[i].end; ++n) {
cmdmem[n] = *cmds++;
}
}
if (Memory::IsValidAddress(getClutAddress()))
loadclut = *cmds++;
boneMatrixNumber = *cmds++;
worldmtxnum = *cmds++;
viewmtxnum = *cmds++;
projmtxnum = *cmds++;
texmtxnum = *cmds++;
u8 *matrices = (u8 *)cmds;
memcpy(boneMatrix, matrices, sizeof(boneMatrix)); matrices += sizeof(boneMatrix);
memcpy(worldMatrix, matrices, sizeof(worldMatrix)); matrices += sizeof(worldMatrix);
memcpy(viewMatrix, matrices, sizeof(viewMatrix)); matrices += sizeof(viewMatrix);
memcpy(projMatrix, matrices, sizeof(projMatrix)); matrices += sizeof(projMatrix);
memcpy(tgenMatrix, matrices, sizeof(tgenMatrix)); matrices += sizeof(tgenMatrix);
}

View File

@ -20,6 +20,7 @@
#include <cmath>
#include "../Globals.h"
#include "ge_constants.h"
#include "Common/Swap.h"
// PSP uses a curious 24-bit float - it's basically the top 24 bits of a regular IEEE754 32-bit float.
// This is used for light positions, transform matrices, you name it.
@ -389,6 +390,9 @@ struct GPUgstate
int getTransferBpp() const { return (transferstart & 1) ? 4 : 2; }
// Real data in the context ends here
void Save(u32_le *ptr);
void Restore(u32_le *ptr);
};
enum SkipDrawReasonFlags {