From 8438a5a6478879612acca108ec800c49e53916f2 Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 17 Jan 2023 23:32:47 -0600 Subject: [PATCH] crude hack to fix problem where loadstate could crash if the GPU hasn't ever booted up. see TODO TODO TODO TODO in gfx3d.cpp -- somebody needs to revise the tables so they arent memory mapped but so that they work rather like shininess tables. if they aren't truly latched when the gpu is flushed, then put them in a table anyway and simply reference the live values instead of the latched ones. How to keep from accidentally referencing the latched ones? perhaps the 3d state could be divided into a latched part and an unlatched part via base classes. Could also be done by embedding a "latched" and "unlatched" struct in the gpu but that would involve touching every line of code that used something from it. --- desmume/src/gfx3d.cpp | 9 ++++++++- desmume/src/gfx3d.h | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index 3464a96b2..3bf13beae 100644 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -529,7 +529,13 @@ void gfx3d_init() gfx3d.state.savedDISP3DCNT.value = 0; gfx3d.state.fogDensityTable = MMU.ARM9_REG+0x0360; gfx3d.state.edgeMarkColorTable = (u16 *)(MMU.ARM9_REG+0x0330); - + + //TODO: these should probably be copied into renderState when it's latched.. + //THIS IS A SUPER BAD HACK + //see TODO TODO TODO TODO + gfx3d.renderState.fogDensityTable = MMU.ARM9_REG+0x0360; + gfx3d.renderState.edgeMarkColorTable = (u16 *)(MMU.ARM9_REG+0x0330); + gfx3d.render3DFrameCount = 0; makeTables(); @@ -2443,6 +2449,7 @@ static void gfx3d_doFlush() //latch the current renderer and geometry engine states //NOTE: the geometry lists are copied elsewhere by another operation. //that's pretty annoying. + //TODO: see TODO TODO TODO TODO gfx3d.renderState = gfx3d.state; gfx3d.state.activeFlushCommand = gfx3d.state.pendingFlushCommand; diff --git a/desmume/src/gfx3d.h b/desmume/src/gfx3d.h index e5fb1ad3f..eb99dea05 100644 --- a/desmume/src/gfx3d.h +++ b/desmume/src/gfx3d.h @@ -589,6 +589,8 @@ struct GFX3D_State bool invalidateToon; CACHE_ALIGN u16 u16ToonTable[32]; u8 shininessTable[128]; + + //TODO: copy these in instead of this sloppy memory mapping u8 *fogDensityTable; // Alias to MMU.ARM9_REG+0x0360 u16 *edgeMarkColorTable; // Alias to MMU.ARM9_REG+0x0330 };