Create constants for CP registers and masks
This commit is contained in:
parent
d702f3b4ad
commit
c27efb3f1f
|
@ -467,22 +467,22 @@ void FifoPlayer::LoadRegisters()
|
|||
}
|
||||
|
||||
regs = m_File->GetCPMem();
|
||||
LoadCPReg(0x30, regs[0x30]);
|
||||
LoadCPReg(0x40, regs[0x40]);
|
||||
LoadCPReg(0x50, regs[0x50]);
|
||||
LoadCPReg(0x60, regs[0x60]);
|
||||
LoadCPReg(MATINDEX_A, regs[MATINDEX_A]);
|
||||
LoadCPReg(MATINDEX_B, regs[MATINDEX_B]);
|
||||
LoadCPReg(VCD_LO, regs[VCD_LO]);
|
||||
LoadCPReg(VCD_HI, regs[VCD_HI]);
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
for (int i = 0; i < CP_NUM_VAT_REG; ++i)
|
||||
{
|
||||
LoadCPReg(0x70 + i, regs[0x70 + i]);
|
||||
LoadCPReg(0x80 + i, regs[0x80 + i]);
|
||||
LoadCPReg(0x90 + i, regs[0x90 + i]);
|
||||
LoadCPReg(CP_VAT_REG_A + i, regs[CP_VAT_REG_A + i]);
|
||||
LoadCPReg(CP_VAT_REG_B + i, regs[CP_VAT_REG_B + i]);
|
||||
LoadCPReg(CP_VAT_REG_C + i, regs[CP_VAT_REG_C + i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
for (int i = 0; i < CP_NUM_ARRAYS; ++i)
|
||||
{
|
||||
LoadCPReg(0xa0 + i, regs[0xa0 + i]);
|
||||
LoadCPReg(0xb0 + i, regs[0xb0 + i]);
|
||||
LoadCPReg(ARRAY_BASE + i, regs[ARRAY_BASE + i]);
|
||||
LoadCPReg(ARRAY_STRIDE + i, regs[ARRAY_STRIDE + i]);
|
||||
}
|
||||
|
||||
regs = m_File->GetXFMem();
|
||||
|
|
|
@ -7,6 +7,38 @@
|
|||
#include "Common/BitSet.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
enum
|
||||
{
|
||||
// These commands use the high nybble for the command itself, and the lower nybble is an argument.
|
||||
// TODO: However, Dolphin's implementation (in LoadCPReg) and YAGCD disagree about what values are
|
||||
// valid for the lower nybble.
|
||||
|
||||
// YAGCD says 0x30 only; LoadCPReg allows any
|
||||
MATINDEX_A = 0x30,
|
||||
// YAGCD says 0x40 only; LoadCPReg allows any
|
||||
MATINDEX_B = 0x40,
|
||||
// YAGCD says 0x50-0x57 for distinct VCDs; LoadCPReg allows any for a single VCD
|
||||
VCD_LO = 0x50,
|
||||
// YAGCD says 0x60-0x67 for distinct VCDs; LoadCPReg allows any for a single VCD
|
||||
VCD_HI = 0x60,
|
||||
// YAGCD and LoadCPReg both agree that only 0x70-0x77 are valid
|
||||
CP_VAT_REG_A = 0x70,
|
||||
// YAGCD and LoadCPReg both agree that only 0x80-0x87 are valid
|
||||
CP_VAT_REG_B = 0x80,
|
||||
// YAGCD and LoadCPReg both agree that only 0x90-0x97 are valid
|
||||
CP_VAT_REG_C = 0x90,
|
||||
// YAGCD and LoadCPReg agree that 0xa0-0xaf are valid
|
||||
ARRAY_BASE = 0xa0,
|
||||
// YAGCD and LoadCPReg agree that 0xb0-0xbf are valid
|
||||
ARRAY_STRIDE = 0xb0,
|
||||
|
||||
CP_COMMAND_MASK = 0xf0,
|
||||
CP_NUM_VAT_REG = 0x08,
|
||||
CP_VAT_MASK = 0x07,
|
||||
CP_NUM_ARRAYS = 0x10,
|
||||
CP_ARRAY_MASK = 0x0f,
|
||||
};
|
||||
|
||||
// Vertex array numbers
|
||||
enum
|
||||
{
|
||||
|
@ -242,18 +274,18 @@ class VertexLoaderBase;
|
|||
// STATE_TO_SAVE
|
||||
struct CPState final
|
||||
{
|
||||
u32 array_bases[16];
|
||||
u32 array_strides[16];
|
||||
u32 array_bases[CP_NUM_ARRAYS];
|
||||
u32 array_strides[CP_NUM_ARRAYS];
|
||||
TMatrixIndexA matrix_index_a;
|
||||
TMatrixIndexB matrix_index_b;
|
||||
TVtxDesc vtx_desc;
|
||||
// Most games only use the first VtxAttr and simply reconfigure it all the time as needed.
|
||||
VAT vtx_attr[8];
|
||||
VAT vtx_attr[CP_NUM_VAT_REG];
|
||||
|
||||
// Attributes that actually belong to VertexLoaderManager:
|
||||
BitSet32 attr_dirty;
|
||||
bool bases_dirty;
|
||||
VertexLoaderBase* vertex_loaders[8];
|
||||
VertexLoaderBase* vertex_loaders[CP_NUM_VAT_REG];
|
||||
int last_id;
|
||||
};
|
||||
|
||||
|
|
|
@ -15,9 +15,11 @@
|
|||
|
||||
#include "Common/Assert.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Core/HW/Memmap.h"
|
||||
|
||||
#include "VideoCommon/BPMemory.h"
|
||||
#include "VideoCommon/CPMemory.h"
|
||||
#include "VideoCommon/CommandProcessor.h"
|
||||
#include "VideoCommon/DataReader.h"
|
||||
#include "VideoCommon/IndexGenerator.h"
|
||||
|
@ -302,79 +304,86 @@ void LoadCPReg(u32 sub_cmd, u32 value, bool is_preprocess)
|
|||
{
|
||||
bool update_global_state = !is_preprocess;
|
||||
CPState* state = is_preprocess ? &g_preprocess_cp_state : &g_main_cp_state;
|
||||
switch (sub_cmd & 0xF0)
|
||||
switch (sub_cmd & CP_COMMAND_MASK)
|
||||
{
|
||||
case 0x30:
|
||||
case MATINDEX_A:
|
||||
if (update_global_state)
|
||||
VertexShaderManager::SetTexMatrixChangedA(value);
|
||||
break;
|
||||
|
||||
case 0x40:
|
||||
case MATINDEX_B:
|
||||
if (update_global_state)
|
||||
VertexShaderManager::SetTexMatrixChangedB(value);
|
||||
break;
|
||||
|
||||
case 0x50:
|
||||
case VCD_LO:
|
||||
state->vtx_desc.Hex &= ~0x1FFFF; // keep the Upper bits
|
||||
state->vtx_desc.Hex |= value;
|
||||
state->attr_dirty = BitSet32::AllTrue(8);
|
||||
state->attr_dirty = BitSet32::AllTrue(CP_NUM_VAT_REG);
|
||||
state->bases_dirty = true;
|
||||
break;
|
||||
|
||||
case 0x60:
|
||||
case VCD_HI:
|
||||
state->vtx_desc.Hex &= 0x1FFFF; // keep the lower 17Bits
|
||||
state->vtx_desc.Hex |= (u64)value << 17;
|
||||
state->attr_dirty = BitSet32::AllTrue(8);
|
||||
state->attr_dirty = BitSet32::AllTrue(CP_NUM_VAT_REG);
|
||||
state->bases_dirty = true;
|
||||
break;
|
||||
|
||||
case 0x70:
|
||||
ASSERT((sub_cmd & 0x0F) < 8);
|
||||
state->vtx_attr[sub_cmd & 7].g0.Hex = value;
|
||||
state->attr_dirty[sub_cmd & 7] = true;
|
||||
case CP_VAT_REG_A:
|
||||
if ((sub_cmd - CP_VAT_REG_A) >= CP_NUM_VAT_REG)
|
||||
WARN_LOG_FMT(VIDEO, "CP_VAT_REG_A: Invalid VAT {}", sub_cmd - CP_VAT_REG_A);
|
||||
state->vtx_attr[sub_cmd & CP_VAT_MASK].g0.Hex = value;
|
||||
state->attr_dirty[sub_cmd & CP_VAT_MASK] = true;
|
||||
break;
|
||||
|
||||
case 0x80:
|
||||
ASSERT((sub_cmd & 0x0F) < 8);
|
||||
state->vtx_attr[sub_cmd & 7].g1.Hex = value;
|
||||
state->attr_dirty[sub_cmd & 7] = true;
|
||||
case CP_VAT_REG_B:
|
||||
if ((sub_cmd - CP_VAT_REG_B) >= CP_NUM_VAT_REG)
|
||||
WARN_LOG_FMT(VIDEO, "CP_VAT_REG_B: Invalid VAT {}", sub_cmd - CP_VAT_REG_B);
|
||||
state->vtx_attr[sub_cmd & CP_VAT_MASK].g1.Hex = value;
|
||||
state->attr_dirty[sub_cmd & CP_VAT_MASK] = true;
|
||||
break;
|
||||
|
||||
case 0x90:
|
||||
ASSERT((sub_cmd & 0x0F) < 8);
|
||||
state->vtx_attr[sub_cmd & 7].g2.Hex = value;
|
||||
state->attr_dirty[sub_cmd & 7] = true;
|
||||
case CP_VAT_REG_C:
|
||||
if ((sub_cmd - CP_VAT_REG_C) >= CP_NUM_VAT_REG)
|
||||
WARN_LOG_FMT(VIDEO, "CP_VAT_REG_C: Invalid VAT {}", sub_cmd - CP_VAT_REG_C);
|
||||
state->vtx_attr[sub_cmd & CP_VAT_MASK].g2.Hex = value;
|
||||
state->attr_dirty[sub_cmd & CP_VAT_MASK] = true;
|
||||
break;
|
||||
|
||||
// Pointers to vertex arrays in GC RAM
|
||||
case 0xA0:
|
||||
state->array_bases[sub_cmd & 0xF] = value & CommandProcessor::GetPhysicalAddressMask();
|
||||
case ARRAY_BASE:
|
||||
state->array_bases[sub_cmd & CP_ARRAY_MASK] =
|
||||
value & CommandProcessor::GetPhysicalAddressMask();
|
||||
state->bases_dirty = true;
|
||||
break;
|
||||
|
||||
case 0xB0:
|
||||
state->array_strides[sub_cmd & 0xF] = value & 0xFF;
|
||||
case ARRAY_STRIDE:
|
||||
state->array_strides[sub_cmd & CP_ARRAY_MASK] = value & 0xFF;
|
||||
break;
|
||||
|
||||
default:
|
||||
WARN_LOG_FMT(VIDEO, "Unknown CP register {:02x} set to {:08x}", sub_cmd, value);
|
||||
}
|
||||
}
|
||||
|
||||
void FillCPMemoryArray(u32* memory)
|
||||
{
|
||||
memory[0x30] = g_main_cp_state.matrix_index_a.Hex;
|
||||
memory[0x40] = g_main_cp_state.matrix_index_b.Hex;
|
||||
memory[0x50] = (u32)g_main_cp_state.vtx_desc.Hex;
|
||||
memory[0x60] = (u32)(g_main_cp_state.vtx_desc.Hex >> 17);
|
||||
memory[MATINDEX_A] = g_main_cp_state.matrix_index_a.Hex;
|
||||
memory[MATINDEX_B] = g_main_cp_state.matrix_index_b.Hex;
|
||||
memory[VCD_LO] = (u32)g_main_cp_state.vtx_desc.Hex;
|
||||
memory[VCD_HI] = (u32)(g_main_cp_state.vtx_desc.Hex >> 17);
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
for (int i = 0; i < CP_NUM_VAT_REG; ++i)
|
||||
{
|
||||
memory[0x70 + i] = g_main_cp_state.vtx_attr[i].g0.Hex;
|
||||
memory[0x80 + i] = g_main_cp_state.vtx_attr[i].g1.Hex;
|
||||
memory[0x90 + i] = g_main_cp_state.vtx_attr[i].g2.Hex;
|
||||
memory[CP_VAT_REG_A + i] = g_main_cp_state.vtx_attr[i].g0.Hex;
|
||||
memory[CP_VAT_REG_B + i] = g_main_cp_state.vtx_attr[i].g1.Hex;
|
||||
memory[CP_VAT_REG_C + i] = g_main_cp_state.vtx_attr[i].g2.Hex;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
for (int i = 0; i < CP_NUM_ARRAYS; ++i)
|
||||
{
|
||||
memory[0xA0 + i] = g_main_cp_state.array_bases[i];
|
||||
memory[0xB0 + i] = g_main_cp_state.array_strides[i];
|
||||
memory[ARRAY_BASE + i] = g_main_cp_state.array_bases[i];
|
||||
memory[ARRAY_STRIDE + i] = g_main_cp_state.array_strides[i];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue