Skip to content

Commit

Permalink
readmes and gx cmd viewing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaklyy committed Jan 26, 2024
1 parent 2e29a82 commit 152ae3c
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 75 deletions.
81 changes: 81 additions & 0 deletions format implementation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
Frame Dump File Structure:
Note 1: Data can optionally be embedded into a png, if so, it should be done in a chunk with the name: "ndSf". (capitalization matters.)
Note 2: All data fields should be formatted in little endian.
arrays (tables?) should be formatted as data 0 > 1 > 2 > 3. (though individual entries in the array should still be little endian.)


Header:
Note: Header should remain uncompressed.

5 bytes - magic number ---- should always be "NTRFD". (maybe we'll add TWLFD in the future if any key dsi specific quirks are discovered?)
2 bytes - version --------- check main.h for CUR_FD_REV define.
1 byte - compressiontype -- currently unused, should always be set to 0. (uncompressed)


Global Variables:
Should be saved when registers are latched. (ie. right before rendering.)

2 bytes - disp3dcnt
16 bytes - edge colors
1 byte - alpha test ref
4 bytes - clear color
4 bytes - clear depth/offset (stored in one variable)
4 bytes - fog color
2 bytes - fog offset
32 bytes - fog table
64 bytes - toon table


Initial State Variables:
Should be saved before the first command in a frame is sent.
(Should we only define the used bits of the command, or the full 32 bits?)

2 bytes - zero dot display
4 bytes - polygon attributes
4 bytes - polygon attributes unset
4 bytes - vertex color
4 bytes - viewport
64 bytes - projection stack
2048 bytes - position stack
2048 bytes - vector stack
64 bytes - texture stack
64 bytes - projection mtx
64 bytes - position mtx
64 bytes - vector mtx
64 bytes - texture mtx
4 bytes - matrix mode
4 bytes - polygon
4 bytes - vertex xy
2 bytes - vertex z
4 bytes - texture coordinates
4 bytes - texture parameters
4 bytes - texture palette
4 bytes - diffuse/ambient
4 bytes - specular/emissive
128 bytes - shininess table
16 bytes - light vectors
16 bytes - light colors
4 bytes - swap buffers params
7 bytes - vram control regs - only 7 are actually saved/loaded/used. banks h and i are ignored


Vram State:
(Up to) 608 KiB of vram state
Note: vram state is ONLY saved/loaded for ACTIVE vram banks that're being used for 3d textures/texture palettes
(ie. Last bit of vramcnt must be set and the value of the mst must be 3).
(Additionally banks H and I are ignored due to not being allocatable to the 3d engine).


Param/Cmd Counts:

4 bytes - number of cmds submitted
4 bytes - number of params submitted

Cmd/Param Data:
only store a maximum of 500KB of param/cmd data
all cmds should be stored in one consecutive block followed by a block of param data
nops and vec/box tests should not be added to any of these trackers
id 0x72 is repurposed to store zero dot disp reg writes

1 byte per - cmd
4 bytes per - param
16 changes: 16 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
A tool to replay frame dumps captured in emulator, supports playback on real hardware.
- By Jakly

Building:
Use blocksds.
Also make a folder called "fs" because i think it needs that to build without complaining.
Frame dump data can be embedded into the romfs by building with it placed into a folder named "fs".

Loading Frame Dumps:
Frame dumps can be loaded from either root of sd, romfs, or flashcart.
Frame dumps will be loaded from a folder in root called "framedumps", should it exist. (does not apply to romfs).

Generating Frame Dumps:
Frame dumps can be generated from certain emulators.
Supported Emulators Include:
melonDS (not merged yet) --- https://github.com/melonDS-emu/melonDS/actions?query=branch%3Aframedump
16 changes: 10 additions & 6 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ void initVram(FILE* file)
// nab vramcontrols
fread(vramcontrol, 1, 7, file);

for (int i = 0; i < 7; i++)
{
(&VRAM_A_CR)[i] = 0;
}
// init vram banks
// ignore H & I because irrelevant to 3d gfx
// todo: avoid activating the first 4 banks if unneeded?
Expand Down Expand Up @@ -406,9 +410,9 @@ u32 runGX(bool finish)
for (u32 i = 0, j = 0; i < numcmds; i++)
{
// handle zerodotdisp reg writes
if (cmd[i] == 255)
if (cmd[i] == ZDotDisp)
GFX_CUTOFF_DEPTH = param[j++];
else if (finish || cmd[i] != 0x50)
else if (finish || cmd[i] != SwapBuffer)
{
vu32* finaladdr = (vu32*)((u32)&GFX_FIFO + (cmd[i] << 2));
if (paramcount[cmd[i]] != 0)
Expand All @@ -421,10 +425,10 @@ u32 runGX(bool finish)

if (!finish)
{
if (cmd[i] == 0x29) currpolyattrunset = param[j-1]; // polyattr
else if (cmd[i] == 0x40) currpolyattr = currpolyattrunset; // begin poly
else if (cmd[i] == 0x2A) currtexparam = param[j-1]; // texparam
else if (cmd[i] >= 0x23 && cmd[i] <= 0x28) // vtx cmds
if (cmd[i] == PolyAttr) currpolyattrunset = param[j-1]; // polyattr
else if (cmd[i] == BeginPoly) currpolyattr = currpolyattrunset; // begin poly
else if (cmd[i] == TexParam) currtexparam = param[j-1]; // texparam
else if (cmd[i] >= Vtx16 && cmd[i] <= VtxYZ) // vtx cmds
{
// create a mask of translucent polygon ids
u8 texmode = ((currtexparam >> 26) & 0x7);
Expand Down
2 changes: 1 addition & 1 deletion source/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum Cmd_IDs
Vtx10,
VtxXY,
VtxXZ,
VTXYZ,
VtxYZ,
VtxDiff,
PolyAttr,
TexParam,
Expand Down
82 changes: 81 additions & 1 deletion source/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ u32 menuInputs(struct MenuDat m)
}
if (!m.Inputs.DisableReset && MENU_RESET & keys)
{

// TODO
}
if (!m.Inputs.DisableExit && MENU_BACK & keys)
{
Expand All @@ -390,3 +390,83 @@ u32 menuInputs(struct MenuDat m)
#undef ENTRY
#endif
}

/*void menuColor(u8* header, u8* string, u16* colorvar, u16 numcolors)
{
u8* headers[] =
{
header,
NULL,
};
struct MenuEntry entries* = malloc(numcolors);
memset(entries, 0, sizeof(struct MenuEntry) * numcolors);
for (int i = 0; i < numcolors; i++)
{
u8 color = 0xC0 | (i+1);
entries[i].String = malloc(31);
entries[i].Type = Entry_Button;
sprintf(entries[i].String, "%s %i: \xFF%c\n", string, i, color);
}
u8* headers2[] =
{
str_sub_color,
NULL,
};
s32 cursor = 0;
while (true)
{
for (int i = 0; i < numcolors; i++)
BG_PALETTE_SUB[(PALETTE_SIZE*15)+1+i] = colorvar[i];
u32 sel = menuInputs((struct MenuDat){&cursor, headers, entries, ARRSIZE(entries), InputsCommon});
if (sel == Ret_Exit) break;
else
{
u32 var = edgecolor[sel];
struct MenuEntry entries2[] =
{
{
.Addr = inputEdgeColor,
.AddrOffs = sel,
.String = str_opt_r,
.Type = Entry_Var,
.SubType = Sub_Red,
.Var = &var,
.Shift = 0,
.Mask = 0x1F,
},
{
.Addr = inputEdgeColor,
.AddrOffs = sel,
.String = str_opt_g,
.Type = Entry_Var,
.SubType = Sub_Green,
.Var = &var,
.Shift = 5,
.Mask = 0x1F,
},
{
.Addr = inputEdgeColor,
.AddrOffs = sel,
.String = str_opt_b,
.Type = Entry_Var,
.SubType = Sub_Blue,
.Var = &var,
.Shift = 10,
.Mask = 0x1F,
},
};
u32 cursor2 = 0;
menuInputs((struct MenuDat){&cursor2, headers2, entries2, ARRSIZE(entries2), InputsCommon});
edgecolor[sel] = var;
}
}
for (int i = 0; i < 8; i++)
free(entries[i].String);
}*/
2 changes: 1 addition & 1 deletion source/menu/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ struct MenuEntry
u32* Var;
u32 VarFrag; // the part of the var that's actually incremented
u16 SubType;
u16 Mask;
u8 Type;
u8 Shift;
u8 Mask;
u8 AddrOffs;
};

Expand Down
Loading

0 comments on commit 152ae3c

Please sign in to comment.