From 436358a51bc207ae9a15e17a24457a5fbb54a279 Mon Sep 17 00:00:00 2001 From: mtabachenko Date: Sat, 25 Sep 2010 14:30:23 +0000 Subject: [PATCH] - add save firmware settings (User, WiFi, WiFi AP); - fix OpenGL shader for texture blending on decal mode; --- desmume/src/MMU.cpp | 1 + desmume/src/armcpu.h | 16 ++++++++-------- desmume/src/firmware.cpp | 36 ++++++++++++++++++++++++++++++++++++ desmume/src/mc.cpp | 21 +++++++++++++++++++++ desmume/src/mc.h | 4 ++++ desmume/src/shaders.h | 10 ++++++++-- 6 files changed, 78 insertions(+), 10 deletions(-) diff --git a/desmume/src/MMU.cpp b/desmume/src/MMU.cpp index c8a168e9b..b7be7e9e8 100644 --- a/desmume/src/MMU.cpp +++ b/desmume/src/MMU.cpp @@ -846,6 +846,7 @@ void MMU_Init(void) { mc_init(&MMU.fw, MC_TYPE_FLASH); /* init fw device */ mc_alloc(&MMU.fw, NDS_FW_SIZE_V1); MMU.fw.fp = NULL; + MMU.fw.isFirmware = true; // Init Backup Memory device, this should really be done when the rom is loaded //mc_init(&MMU.bupmem, MC_TYPE_AUTODETECT); diff --git a/desmume/src/armcpu.h b/desmume/src/armcpu.h index c25301353..0aca4c6da 100644 --- a/desmume/src/armcpu.h +++ b/desmume/src/armcpu.h @@ -269,15 +269,15 @@ static INLINE void setIF(int PROCNUM, u32 flag) extern void NDS_Reschedule(); NDS_Reschedule(); - //TODO SEP - was this necessary??? + //TODO SEP - was this necessary??? - CrazyMax 2010/09/25: needs for boot firmware //generate the interrupt if enabled - //if ((MMU.reg_IE[PROCNUM] & (flag)) && MMU.reg_IME[PROCNUM]) - //{ - // if(PROCNUM==0) - // NDS_ARM9.waitIRQ = FALSE; - // else - // NDS_ARM7.waitIRQ = FALSE; - //} + if ((MMU.reg_IE[PROCNUM] & (flag)) && MMU.reg_IME[PROCNUM]) + { + if(PROCNUM==0) + NDS_ARM9.waitIRQ = FALSE; + else + NDS_ARM7.waitIRQ = FALSE; + } } static INLINE void NDS_makeARM9Int(u32 num) diff --git a/desmume/src/firmware.cpp b/desmume/src/firmware.cpp index 8d50dd35e..523c2641e 100644 --- a/desmume/src/firmware.cpp +++ b/desmume/src/firmware.cpp @@ -19,6 +19,7 @@ #include "firmware.h" #include "NDSSystem.h" +#include "path.h" #define DWNUM(i) ((i) >> 2) @@ -565,6 +566,41 @@ bool CFIRMWARE::load() INFO(" * ARM7 unpacked size: 0x%08X (%i) bytes\n", size7, size7); } + PathInfo path; + path.init(CommonSettings.Firmware); + path.getpathnoext(path.FIRMWARE, &MMU.fw.userfile[0]); + strcat(MMU.fw.userfile, ".dfc"); // DeSmuME Firmware Config + + fp = fopen(MMU.fw.userfile, "rb"); + if (fp) + { + char buf[0x300]; + memset(buf, 0, 0x300); + if (fread(buf, 1, 0x100, fp) == 0x100) + { + printf("- loaded from %s:\n", MMU.fw.userfile); + memcpy(&data[0x3FE00], &buf[0], 0x100); + memcpy(&data[0x3FF00], &buf[0], 0x100); + printf(" * User settings\n"); + memset(buf, 0, 0x100); + if (fread(buf, 1, 0x1D6, fp) == 0x1D6) + { + memcpy(&data[0x002A], &buf[0], 0x1D6); + printf(" * WiFi settings\n"); + + memset(buf, 0, 0x1D6); + if (fread(buf, 1, 0x300, fp) == 0x300) + { + memcpy(&data[0x3FA00], &buf[0], 0x300); + printf(" * WiFi AP settings\n"); + } + } + + } + fclose(fp); + } + printf("\n"); + // TODO: add 512Kb support memcpy(MMU.fw.data, data, 256*1024); MMU.fw.fp = NULL; diff --git a/desmume/src/mc.cpp b/desmume/src/mc.cpp index 4ce5bdd32..ccb861cfd 100644 --- a/desmume/src/mc.cpp +++ b/desmume/src/mc.cpp @@ -191,6 +191,27 @@ void fw_reset_com(memory_chip_t *mc) fwrite(mc->data, mc->size, 1, mc->fp); } + if (mc->isFirmware&&CommonSettings.UseExtFirmware) + { + // copy User Settings 1 to User Settings 0 area + memcpy(&mc->data[0x3FE00], &mc->data[0x3FF00], 0x100); + + printf("Firmware: save config"); + FILE *fp = fopen(mc->userfile, "wb"); + if (fp) + { + if (fwrite(&mc->data[0x3FF00], 1, 0x100, fp) == 0x100) // User Settings + if (fwrite(&mc->data[0x0002A], 1, 0x1D6, fp) == 0x1D6) // WiFi Settings + if (fwrite(&mc->data[0x3FA00], 1, 0x300, fp) == 0x300) // WiFi AP Settings + printf(" - done\n"); + else + printf(" - failed\n"); + fclose(fp); + } + else + printf(" - failed\n"); + } + mc->write_enable = FALSE; } diff --git a/desmume/src/mc.h b/desmume/src/mc.h index e0ee4a481..c05122cec 100644 --- a/desmume/src/mc.h +++ b/desmume/src/mc.h @@ -67,6 +67,10 @@ struct memory_chip_t FILE *fp; u8 autodetectbuf[32768]; int autodetectsize; + + // needs only for firmware + bool isFirmware; + char userfile[260]; }; //the new backup system by zeromus diff --git a/desmume/src/shaders.h b/desmume/src/shaders.h index 9a3160288..7949458e4 100644 --- a/desmume/src/shaders.h +++ b/desmume/src/shaders.h @@ -35,8 +35,14 @@ const char *fragmentShader = {"\ else \n\ if(texBlending == 1) \n\ { \n\ - flagColor.rgb = gl_Color.rgb * (1.0-texColor.a) + texColor.rgb * texColor.a;\n\ - flagColor.a = texColor.a;\n\ + if (texColor.a == 0.0 || hasTexture == 0) \n\ + flagColor.rgb = gl_Color.rgb;\n\ + else \n\ + if (texColor.a == 1.0) \n\ + flagColor.rgb = texColor.rgb;\n\ + else \n\ + flagColor.rgb = texColor.rgb * (1.0-texColor.a) + gl_Color.rgb * texColor.a;\n\ + flagColor.a = gl_Color.a; \n\ } \n\ else \n\ if(texBlending == 2) \n\