From a8f10201bf41d1f0e088a424c1a7e3f0fc11261c Mon Sep 17 00:00:00 2001 From: yz70s Date: Sun, 24 May 2020 08:29:18 +0200 Subject: [PATCH] xbox.cpp: add debugger command "xbox vdeclaration" (nw) Used to decode the vertex shader declaration stored at a certain address. --- src/mame/includes/xbox.h | 1 + src/mame/machine/xbox.cpp | 96 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/src/mame/includes/xbox.h b/src/mame/includes/xbox.h index c116f7e8639..97530e920e9 100644 --- a/src/mame/includes/xbox.h +++ b/src/mame/includes/xbox.h @@ -164,6 +164,7 @@ private: void grab_texture_command(int ref, const std::vector ¶ms); void grab_vprog_command(int ref, const std::vector ¶ms); void vprogdis_command(int ref, const std::vector ¶ms); + void vdeclaration_command(int ref, const std::vector ¶ms); void help_command(int ref, const std::vector ¶ms); void xbox_debug_commands(int ref, const std::vector ¶ms); int find_bios_index(); diff --git a/src/mame/machine/xbox.cpp b/src/mame/machine/xbox.cpp index 1fc2761acff..95d14f42167 100644 --- a/src/mame/machine/xbox.cpp +++ b/src/mame/machine/xbox.cpp @@ -21,6 +21,18 @@ const xbox_base_state::debugger_constants xbox_base_state::debugp[] = { { 0x49d8055a, {0x8003aae0, 0x5c, 0x1c, 0x28, 0x210, 8, 0x28, 0x1c} } }; +const struct { + const char *name; + const int value; +} vertex_format_names[] = { + {"NONE", 0x02}, {"NORMSHORT1", 0x11}, {"FLOAT1", 0x12}, {"PBYTE1", 0x14}, + {"SHORT1", 0x15}, {"NORMPACKED3", 0x16}, {"NORMSHORT2", 0x21}, + {"FLOAT2", 0x22}, {"PBYTE2", 0x24}, {"SHORT2", 0x25}, {"NORMSHORT3", 0x31}, + {"FLOAT3", 0x32}, {"PBYTE3", 0x34}, {"SHORT3", 0x35}, {"D3DCOLOR", 0x40}, + {"FLOAT4", 0x42}, {"NORMSHORT4", 0x41}, {"PBYTE4", 0x44}, {"SHORT4", 0x45}, + {"FLOAT2H", 0x72}, { nullptr, 0} +}; + int xbox_base_state::find_bios_index() { u8 sb = system_bios(); @@ -450,6 +462,87 @@ void xbox_base_state::vprogdis_command(int ref, const std::vector & } } +void xbox_base_state::vdeclaration_command(int ref, const std::vector ¶ms) +{ + address_space &space = m_maincpu->space(); + + if (params.size() < 1) + return; + + uint64_t addr; + if (!machine().debugger().commands().validate_number_parameter(params[1], addr)) + return; + + debugger_console &con = machine().debugger().console(); + for (int n = 128; n > 0; n--) + { + offs_t address = (offs_t)addr; + if (!m_maincpu->translate(AS_PROGRAM, TRANSLATE_READ_DEBUG, address)) + return; + uint32_t w = space.read_dword_unaligned(address); + + if (w == 0xffffffff) + { + con.printf("D3DVSD_END()\n"); + break; + } + switch ((w >> 29) & 7) + { + case 0: + con.printf("D3DVSD_NOP()\n"); + break; + case 1: + if (w & (1 << 28)) + con.printf("D3DVSD_STREAM_TESS()\n"); + else + con.printf("D3DVSD_STREAM(%d)\n", w & 0x1fffffff); + break; + case 2: + if (w & 0x18000000) + con.printf("D3DVSD_SKIPBYTES(%d)\n", (w >> 16) & 0xfff); + else if (w & 0x10000000) + con.printf("D3DVSD_SKIP(%d)\n", (w >> 16) & 0xfff); + else + { + const char *t = "???"; + + for (int s = 0; vertex_format_names[s].value != 0; s++) + { + if (vertex_format_names[s].value == ((w >> 16) & 0xfff)) + { + t = vertex_format_names[s].name; + break; + } + } + con.printf("D3DVSD_REG(%d, D3DVSDT_%s)\n", w & 0xffff, t); + } + break; + case 3: + if (w & 0x10000000) + con.printf("D3DVSD_TESSUV(%d)\n", w & 0xf); + else + con.printf("D3DVSD_TESSNORMAL(%d, %d)\n", (w >> 20) & 0xf, w & 0xf); + break; + case 4: + con.printf("D3DVSD_CONST(%d, %d)\n", (w & 0xff) - 96, (w >> 25) & 0xf); + for (int n = 0; n < ((w >> 23) & 0x3c); n++) + { + addr += 4; + address = (offs_t)addr; + if (!m_maincpu->translate(AS_PROGRAM, TRANSLATE_READ_DEBUG, address)) + return; + w = space.read_dword_unaligned(address); + con.printf("%08x\n", w); + } + break; + default: + con.printf("??? %08x\n", w); + n = 0; + } + addr += 4; + } +} + void xbox_base_state::help_command(int ref, const std::vector ¶ms) { debugger_console &con = machine().debugger().console(); @@ -469,6 +562,7 @@ void xbox_base_state::help_command(int ref, const std::vector ¶ con.printf(" xbox grab_texture,, -- Save to the next used texture of type \n"); con.printf(" xbox grab_vprog, -- save current vertex program instruction slots to \n"); con.printf(" xbox vprogdis,
,[,] -- disassemble vertex program instructions at
of \n"); + con.printf(" xbox vdeclaration,
-- decode vertex program declaration at
\n"); con.printf(" xbox help -- this list\n"); } @@ -504,6 +598,8 @@ void xbox_base_state::xbox_debug_commands(int ref, const std::vector