diff --git a/desmume/src/addons.cpp b/desmume/src/addons.cpp index 41100a168..2463496b8 100644 --- a/desmume/src/addons.cpp +++ b/desmume/src/addons.cpp @@ -41,6 +41,7 @@ extern ADDONINTERFACE addonCFlash; extern ADDONINTERFACE addonRumblePak; extern ADDONINTERFACE addonGBAgame; extern ADDONINTERFACE addonGuitarGrip; +extern ADDONINTERFACE addonExpMemory; //extern ADDONINTERFACE addonExternalMic; ADDONINTERFACE addonList[NDS_ADDON_COUNT] = { @@ -48,7 +49,8 @@ ADDONINTERFACE addonList[NDS_ADDON_COUNT] = { addonCFlash, addonRumblePak, addonGBAgame, - addonGuitarGrip + addonGuitarGrip, + addonExpMemory }; ADDONINTERFACE addon = addonCFlash; // default none pak diff --git a/desmume/src/addons.h b/desmume/src/addons.h index 4b6a7b2ff..9c5dbfc52 100644 --- a/desmume/src/addons.h +++ b/desmume/src/addons.h @@ -66,6 +66,7 @@ enum { NDS_ADDON_RUMBLEPAK, // rumble pack NDS_ADDON_GBAGAME, // gba game in slot NDS_ADDON_GUITARGRIP, // Guitar Grip + NDS_ADDON_EXPMEMORY, // Memory Expansion //NDS_ADDON_EXTERNALMIC, NDS_ADDON_COUNT // use for counter addons - MUST TO BE LAST!!! }; diff --git a/desmume/src/addons/expMemory.cpp b/desmume/src/addons/expMemory.cpp new file mode 100644 index 000000000..9b5ee670d --- /dev/null +++ b/desmume/src/addons/expMemory.cpp @@ -0,0 +1,151 @@ +/* Copyright (C) 2006 yopyop + yopyop156@ifrance.com + yopyop156.ifrance.com + + Copyright (C) 2009 CrazyMax + Copyright (C) 2009 DeSmuME team + + This file is part of DeSmuME + + DeSmuME is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DeSmuME is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DeSmuME; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "../addons.h" +#include "../mem.h" +#include +#include "../MMU.h" + +u8 *expMemory = NULL; +u32 expMemSize = 8 * 1024 * 1024; // 8Mb + +#if 0 +#define EXPINFO(...) INFO(__VA_ARGS__) +#else +#define EXPINFO(...) +#endif + +static BOOL ExpMemory_init(void) { return (TRUE); } +static void ExpMemory_reset(void) +{ + if (expMemory) + { + delete [] expMemory; + expMemory = NULL; + } + expMemory = new u8 [expMemSize]; + memset(expMemory, 0xFF, expMemSize); +} +static void ExpMemory_close(void) +{ + if (expMemory) + { + delete [] expMemory; + expMemory = NULL; + } +} +static void ExpMemory_config(void) {} +static void ExpMemory_write08(u32 adr, u8 val) +{ + + if (adr >= 0x09000000) + { + u32 offs = (adr - 0x09000000); + if (offs >= expMemSize) return; + T1WriteByte(expMemory, offs, val); + } + EXPINFO("ExpMemory: write 08 at 0x%08X = 0x%02X\n", adr, val); +} +static void ExpMemory_write16(u32 adr, u16 val) +{ + + if (adr >= 0x09000000) + { + u32 offs = (adr - 0x09000000); + if (offs >= expMemSize) return; + T1WriteWord(expMemory, offs, val); + } + EXPINFO("ExpMemory: write 16 at 0x%08X = 0x%04X\n", adr, val); +} +static void ExpMemory_write32(u32 adr, u32 val) +{ + + if (adr >= 0x09000000) + { + u32 offs = (adr - 0x09000000); + if (offs >= expMemSize) return; + T1WriteLong(expMemory, offs, val); + } + EXPINFO("ExpMemory: write 32 at 0x%08X = 0x%08X\n", adr, val); +} +static u8 ExpMemory_read08(u32 adr) +{ + if (adr == 0x080000B2) return(0x96); + + if (adr >= 0x09000000) + { + u32 offs = (adr - 0x09000000); + if (offs >= expMemSize) return (0); + return (T1ReadByte(expMemory, offs)); + } + + EXPINFO("ExpMemory: read 08 at 0x%08X\n", adr); + return (0); +} +static u16 ExpMemory_read16(u32 adr) +{ + if (adr == 0x080000B6) return(0x2424); + if (adr == 0x080000BC) return(0x7FFF); + if (adr == 0x080000BE) return(0x0096); + if (adr == 0x0801FFFC) return(0x7FFF); + + if (adr >= 0x09000000) + { + u32 offs = (adr - 0x09000000); + if (offs >= expMemSize) return (0); + return (T1ReadWord(expMemory, offs)); + } + + EXPINFO("ExpMemory: read 16 at 0x%08X\n", adr); + return (0); +} +static u32 ExpMemory_read32(u32 adr) +{ + if (adr == 0x080000AC) return(0x027FFC30); + + if (adr >= 0x09000000) + { + u32 offs = (adr - 0x09000000); + if (offs >= expMemSize) return (0); + return (T1ReadLong(expMemory, offs)); + } + + EXPINFO("ExpMemory: read 32 at 0x%08X\n", adr); + return (0); +} +static void ExpMemory_info(char *info) { strcpy(info, "Memory Expansion Pak"); } + +ADDONINTERFACE addonExpMemory = { + "Memory Expansion Pak", + ExpMemory_init, + ExpMemory_reset, + ExpMemory_close, + ExpMemory_config, + ExpMemory_write08, + ExpMemory_write16, + ExpMemory_write32, + ExpMemory_read08, + ExpMemory_read16, + ExpMemory_read32, + ExpMemory_info}; diff --git a/desmume/src/addons/gbagame.cpp b/desmume/src/addons/gbagame.cpp index 1cec71e58..e68252432 100644 --- a/desmume/src/addons/gbagame.cpp +++ b/desmume/src/addons/gbagame.cpp @@ -38,12 +38,17 @@ static u8 *GBArom = NULL; static BOOL GBAgame_init(void) { - GBArom = new u8 [GBA_SIZE]; return (TRUE); } static void GBAgame_reset(void) { + if (GBArom) + { + delete [] GBArom; + GBArom = NULL; + } + GBArom = new u8 [GBA_SIZE]; memset(GBArom, 0, GBA_SIZE); if (!strlen(GBAgameName)) return; @@ -80,8 +85,11 @@ static void GBAgame_reset(void) static void GBAgame_close(void) { - delete[] GBArom; - GBArom = NULL; + if (GBArom) + { + delete [] GBArom; + GBArom = NULL; + } } static void GBAgame_config(void) {} diff --git a/desmume/src/bios.cpp b/desmume/src/bios.cpp index 2ae04a9ac..226c830f5 100644 --- a/desmume/src/bios.cpp +++ b/desmume/src/bios.cpp @@ -328,7 +328,7 @@ TEMPLATE static u32 divide() cpu->R[0] = (u32)(num / dnum); cpu->R[1] = (u32)(num % dnum); cpu->R[3] = (u32) (((s32)cpu->R[0])<0 ? -(s32)cpu->R[0] : cpu->R[0]); - + return 6; } @@ -857,17 +857,37 @@ TEMPLATE static u32 BitUnPack() dest = cpu->R[1]; header = cpu->R[2]; - //INFO("swi bitunpack\n"); - len = _MMU_read16(header); - // check address bits = _MMU_read08(header+2); + switch (bits) + { + case 1: + case 2: + case 4: + case 8: + break; + default: return (0); // error + } + dataSize = _MMU_read08(header+3); + switch (dataSize) + { + case 1: + case 2: + case 4: + case 8: + case 16: + case 32: + break; + default: return (0); // error + } + revbits = 8 - bits; // u32 value = 0; base = _MMU_read08(header+4); addBase = (base & 0x80000000) ? 1 : 0; base &= 0x7fffffff; - dataSize = _MMU_read08(header+3); + + //INFO("SWI10: bitunpack src 0x%08X dst 0x%08X hdr 0x%08X (src len %05i src bits %02i dst bits %02i)\n\n", source, dest, header, len, bits, dataSize); data = 0; bitwritecount = 0; diff --git a/desmume/src/emufile.h b/desmume/src/emufile.h index 5218bea16..2ec209689 100644 --- a/desmume/src/emufile.h +++ b/desmume/src/emufile.h @@ -132,7 +132,7 @@ public: virtual size_t _fread(const void *ptr, size_t bytes){ u32 remain = len-pos; - u32 todo = std::min(remain,bytes); + u32 todo = std::min(remain,bytes); memcpy((void*)ptr,buf()+pos,todo); pos += todo; if(todo + + diff --git a/desmume/src/windows/DeSmuME_2008.vcproj b/desmume/src/windows/DeSmuME_2008.vcproj index a698ac381..e31b5273a 100644 --- a/desmume/src/windows/DeSmuME_2008.vcproj +++ b/desmume/src/windows/DeSmuME_2008.vcproj @@ -832,6 +832,10 @@ RelativePath="..\addons\compactFlash.cpp" > + + diff --git a/desmume/src/windows/DeSmuME_2010.vcxproj b/desmume/src/windows/DeSmuME_2010.vcxproj index 92b0afd68..8a471e79d 100644 --- a/desmume/src/windows/DeSmuME_2010.vcxproj +++ b/desmume/src/windows/DeSmuME_2010.vcxproj @@ -183,6 +183,7 @@ + diff --git a/desmume/src/windows/gbaslot_config.cpp b/desmume/src/windows/gbaslot_config.cpp index 648f86379..776f7bde3 100644 --- a/desmume/src/windows/gbaslot_config.cpp +++ b/desmume/src/windows/gbaslot_config.cpp @@ -355,7 +355,9 @@ u32 GBAslot_IDDs[NDS_ADDON_COUNT] = { IDD_GBASLOT_CFLASH, IDD_GBASLOT_RUMBLEPAK, IDD_GBASLOT_GBAGAME, - IDD_GBASLOT_GUITARGRIP + IDD_GBASLOT_GUITARGRIP, + // todo + IDD_GBASLOT_NONE }; DLGPROC GBAslot_Procs[NDS_ADDON_COUNT] = { @@ -363,7 +365,9 @@ DLGPROC GBAslot_Procs[NDS_ADDON_COUNT] = { GbaSlotCFlash, GbaSlotRumblePak, GbaSlotGBAgame, - GbaSlotGuitarGrip + //todo + GbaSlotGuitarGrip, + GbaSlotNone }; @@ -504,6 +508,8 @@ void GBAslotDialog(HWND hwnd) else needReset = false; break; + case NDS_ADDON_EXPMEMORY: + break; default: return; } diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 95710d1b7..d6209dfe7 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -1979,6 +1979,8 @@ int _main() break; case NDS_ADDON_GUITARGRIP: break; + case NDS_ADDON_EXPMEMORY: + break; default: addon_type = NDS_ADDON_NONE; break;