From dbea6bfe75a9e7e0daf9b0be94556ae74bc955dc Mon Sep 17 00:00:00 2001 From: mtabachenko Date: Fri, 6 Aug 2010 09:39:36 +0000 Subject: [PATCH] SLOT1: - separated slot1 handler to new files; - fix boot games from firmware; --- desmume/src/Makefile.am | 1 + desmume/src/addons.cpp | 45 +---------- desmume/src/addons.h | 19 +---- desmume/src/addons/slot1_none.cpp | 16 ++-- desmume/src/addons/slot1_r4.cpp | 16 ++-- desmume/src/addons/slot1_retail.cpp | 37 ++++++---- desmume/src/commandline.cpp | 1 + desmume/src/slot1.cpp | 59 +++++++++++++++ desmume/src/slot1.h | 74 +++++++++++++++++++ desmume/src/windows/DeSmuME_2005.vcproj | 8 ++ desmume/src/windows/DeSmuME_2008.vcproj | 8 ++ desmume/src/windows/DeSmuME_2010.vcxproj | 2 + .../src/windows/DeSmuME_2010.vcxproj.filters | 6 ++ 13 files changed, 198 insertions(+), 94 deletions(-) create mode 100644 desmume/src/slot1.cpp create mode 100644 desmume/src/slot1.h diff --git a/desmume/src/Makefile.am b/desmume/src/Makefile.am index 6fdd84aa1..948ae6806 100644 --- a/desmume/src/Makefile.am +++ b/desmume/src/Makefile.am @@ -33,6 +33,7 @@ libdesmume_a_SOURCES = \ render3D.cpp render3D.h \ rtc.cpp rtc.h \ saves.cpp saves.h \ + slot1.cpp slot1.h \ SPU.cpp SPU.h \ matrix.cpp matrix.h \ gfx3d.cpp gfx3d.h \ diff --git a/desmume/src/addons.cpp b/desmume/src/addons.cpp index 41ce3d8b8..447eddc64 100644 --- a/desmume/src/addons.cpp +++ b/desmume/src/addons.cpp @@ -1,5 +1,4 @@ -/* Copyright (C) 2009 CrazyMax - Copyright (C) 2009 DeSmuME team +/* Copyright (C) 2009-2010 DeSmuME team This file is part of DeSmuME @@ -76,45 +75,3 @@ BOOL addonsChangePak(NDS_ADDON_TYPE type) addon_type = type; return addon.init(); } - -//-------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------- - -extern ADDONINTERFACE slot1None; -extern ADDONINTERFACE slot1Retail; -extern ADDONINTERFACE slot1R4; - -ADDONINTERFACE slot1List[NDS_SLOT1_COUNT] = { - slot1None, - slot1Retail, - slot1R4 -}; - -ADDONINTERFACE slot1_device = slot1Retail; //default for frontends that dont even configure this -u8 slot1_device_type = NDS_SLOT1_RETAIL; - -BOOL slot1Init() -{ - return slot1_device.init(); -} - -void slot1Close() -{ - slot1_device.close(); -} - -void slot1Reset() -{ - slot1_device.reset(); -} - -BOOL slot1Change(NDS_SLOT1_TYPE changeToType) -{ - printf("slot1Change to: %d\n", changeToType); - if (changeToType > NDS_SLOT1_COUNT || changeToType < 0) return FALSE; - slot1_device.close(); - slot1_device_type = changeToType; - slot1_device = slot1List[slot1_device_type]; - return slot1_device.init(); -} \ No newline at end of file diff --git a/desmume/src/addons.h b/desmume/src/addons.h index ad69c21d9..ea165b723 100644 --- a/desmume/src/addons.h +++ b/desmume/src/addons.h @@ -1,5 +1,4 @@ -/* Copyright (C) 2009 CrazyMax - Copyright (C) 2009-2010 DeSmuME team +/* Copyright (C) 2009-2010 DeSmuME team This file is part of DeSmuME @@ -93,20 +92,4 @@ extern BOOL addonsChangePak(NDS_ADDON_TYPE type); // change current adddon extern void guitarGrip_setKey(bool green, bool red, bool yellow, bool blue); // Guitar grip keys extern void piano_setKey(bool c, bool cs, bool d, bool ds, bool e, bool f, bool fs, bool g, bool gs, bool a, bool as, bool b, bool hic); //piano keys -extern ADDONINTERFACE slot1_device; // current slot1 device - -enum NDS_SLOT1_TYPE -{ - NDS_SLOT1_NONE, - NDS_SLOT1_RETAIL, - NDS_SLOT1_R4, - NDS_SLOT1_COUNT // use for counter addons - MUST TO BE LAST!!! -}; - -BOOL slot1Init(); -void slot1Close(); -void slot1Reset(); -BOOL slot1Change(NDS_SLOT1_TYPE type); // change current adddon - - #endif //__ADDONS_H__ diff --git a/desmume/src/addons/slot1_none.cpp b/desmume/src/addons/slot1_none.cpp index 1d27eb9cb..36ea49611 100644 --- a/desmume/src/addons/slot1_none.cpp +++ b/desmume/src/addons/slot1_none.cpp @@ -17,7 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../addons.h" +#include "../slot1.h" static void slot1_info(char *info) { strcpy(info, "Slot1 no-card emulation (card ejected!)"); } static void slot1_config(void) {} @@ -29,25 +29,25 @@ static void slot1_reset() {} static void slot1_close() {} -static void slot1_write08(u32 adr, u8 val) {} -static void slot1_write16(u32 adr, u16 val) {} -static void slot1_write32(u32 adr, u32 val) {} +static void slot1_write08(u8 PROCNUM, u32 adr, u8 val) {} +static void slot1_write16(u8 PROCNUM, u32 adr, u16 val) {} +static void slot1_write32(u8 PROCNUM, u32 adr, u32 val) {} -static u8 slot1_read08(u32 adr) +static u8 slot1_read08(u8 PROCNUM, u32 adr) { return 0xFF; } -static u16 slot1_read16(u32 adr) +static u16 slot1_read16(u8 PROCNUM, u32 adr) { return 0xFFFF; } -static u32 slot1_read32(u32 adr) +static u32 slot1_read32(u8 PROCNUM, u32 adr) { return 0xFFFFFFFF; } -ADDONINTERFACE slot1None = { +SLOT1INTERFACE slot1None = { "Slot1None", slot1_init, slot1_reset, diff --git a/desmume/src/addons/slot1_r4.cpp b/desmume/src/addons/slot1_r4.cpp index 5ea041e02..b02acab19 100644 --- a/desmume/src/addons/slot1_r4.cpp +++ b/desmume/src/addons/slot1_r4.cpp @@ -17,7 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../addons.h" +#include "../slot1.h" #include "../registers.h" #include "../MMU.h" #include "../NDSSystem.h" @@ -53,8 +53,8 @@ static void reset() {} static void close() {} -static void write08(u32 adr, u8 val) {} -static void write16(u32 adr, u16 val) {} +static void write08(u8 PROCNUM, u32 adr, u8 val) {} +static void write16(u8 PROCNUM, u32 adr, u16 val) {} static void write32_GCROMCTRL(u32 val) { @@ -137,7 +137,7 @@ static void write32_GCDATAIN(u32 val) }*/ } -static void write32(u32 adr, u32 val) +static void write32(u8 PROCNUM, u32 adr, u32 val) { switch(adr) { @@ -150,11 +150,11 @@ static void write32(u32 adr, u32 val) } } -static u8 read08(u32 adr) +static u8 read08(u8 PROCNUM, u32 adr) { return 0xFF; } -static u16 read16(u32 adr) +static u16 read16(u8 PROCNUM, u32 adr) { return 0xFFFF; } @@ -205,7 +205,7 @@ static u32 read32_GCDATAIN() } //read32_GCDATAIN -static u32 read32(u32 adr) +static u32 read32(u8 PROCNUM, u32 adr) { switch(adr) { @@ -216,7 +216,7 @@ static u32 read32(u32 adr) } } -ADDONINTERFACE slot1R4 = { +SLOT1INTERFACE slot1R4 = { "Slot1R4", init, reset, diff --git a/desmume/src/addons/slot1_retail.cpp b/desmume/src/addons/slot1_retail.cpp index e7b7a5016..ef0abb8c5 100644 --- a/desmume/src/addons/slot1_retail.cpp +++ b/desmume/src/addons/slot1_retail.cpp @@ -17,7 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../addons.h" +#include "../slot1.h" #include "../registers.h" #include "../MMU.h" #include "../NDSSystem.h" @@ -32,12 +32,12 @@ static void reset() {} static void close() {} -static void write08(u32 adr, u8 val) {} -static void write16(u32 adr, u16 val) {} +static void write08(u8 PROCNUM, u32 adr, u8 val) {} +static void write16(u8 PROCNUM, u32 adr, u16 val) {} -static void write32_GCROMCTRL(u32 val) +static void write32_GCROMCTRL(u8 PROCNUM, u32 val) { - nds_dscard& card = MMU.dscard[0]; + nds_dscard& card = MMU.dscard[PROCNUM]; switch(card.command[0]) { @@ -46,34 +46,41 @@ static void write32_GCROMCTRL(u32 val) card.address = (card.command[1] << 24) | (card.command[2] << 16) | (card.command[3] << 8) | card.command[4]; card.transfer_count = 0x80; break; + + case 0xB8: // Chip ID + card.address = 0; + card.transfer_count = 1; + break; + default: card.address = 0; + card.transfer_count = 0; break; } } -static void write32(u32 adr, u32 val) +static void write32(u8 PROCNUM, u32 adr, u32 val) { switch(adr) { case REG_GCROMCTRL: - write32_GCROMCTRL(val); + write32_GCROMCTRL(PROCNUM, val); break; } } -static u8 read08(u32 adr) +static u8 read08(u8 PROCNUM, u32 adr) { return 0xFF; } -static u16 read16(u32 adr) +static u16 read16(u8 PROCNUM, u32 adr) { return 0xFFFF; } -static u32 read32_GCDATAIN() +static u32 read32_GCDATAIN(u8 PROCNUM) { - nds_dscard& card = MMU.dscard[0]; + nds_dscard& card = MMU.dscard[PROCNUM]; switch(card.command[0]) { @@ -118,10 +125,8 @@ static u32 read32_GCDATAIN() DEBUG_Notify.ReadBeyondEndOfCart(card.address,gameInfo.romsize); return 0xFFFFFFFF; } - else //but, this is actually handled by the cart rom buffer being oversized and full of 0xFF. //is this a good idea? We think so. - return T1ReadLong(MMU.CART_ROM, card.address & MMU.CART_ROM_MASK); } break; @@ -130,19 +135,19 @@ static u32 read32_GCDATAIN() } //switch(card.command[0]) } //read32_GCDATAIN -static u32 read32(u32 adr) +static u32 read32(u8 PROCNUM, u32 adr) { switch(adr) { case REG_GCDATAIN: - return read32_GCDATAIN(); + return read32_GCDATAIN(PROCNUM); default: return 0; } } -ADDONINTERFACE slot1Retail = { +SLOT1INTERFACE slot1Retail = { "Slot1Retail", init, reset, diff --git a/desmume/src/commandline.cpp b/desmume/src/commandline.cpp index c851b2007..d305cebf6 100644 --- a/desmume/src/commandline.cpp +++ b/desmume/src/commandline.cpp @@ -28,6 +28,7 @@ #include "types.h" #include "movie.h" #include "addons.h" +#include "slot1.h" #include "NDSSystem.h" #include "utils/xstring.h" diff --git a/desmume/src/slot1.cpp b/desmume/src/slot1.cpp new file mode 100644 index 000000000..5bf223719 --- /dev/null +++ b/desmume/src/slot1.cpp @@ -0,0 +1,59 @@ +/* Copyright (C) 2010 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 "slot1.h" +#include + +extern SLOT1INTERFACE slot1None; +extern SLOT1INTERFACE slot1Retail; +extern SLOT1INTERFACE slot1R4; + +SLOT1INTERFACE slot1List[NDS_SLOT1_COUNT] = { + slot1None, + slot1Retail, + slot1R4 +}; + +SLOT1INTERFACE slot1_device = slot1Retail; //default for frontends that dont even configure this +u8 slot1_device_type = NDS_SLOT1_RETAIL; + +BOOL slot1Init() +{ + return slot1_device.init(); +} + +void slot1Close() +{ + slot1_device.close(); +} + +void slot1Reset() +{ + slot1_device.reset(); +} + +BOOL slot1Change(NDS_SLOT1_TYPE changeToType) +{ + printf("slot1Change to: %d\n", changeToType); + if (changeToType > NDS_SLOT1_COUNT || changeToType < 0) return FALSE; + slot1_device.close(); + slot1_device_type = changeToType; + slot1_device = slot1List[slot1_device_type]; + return slot1_device.init(); +} \ No newline at end of file diff --git a/desmume/src/slot1.h b/desmume/src/slot1.h new file mode 100644 index 000000000..c9afac4d8 --- /dev/null +++ b/desmume/src/slot1.h @@ -0,0 +1,74 @@ +/* Copyright (C) 2010 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 +*/ + +#ifndef __SLOT1_H__ +#define __SLOT1_H__ + +#include "common.h" +#include "types.h" +#include "debug.h" + +struct SLOT1INTERFACE +{ + // The name of the plugin, this name will appear in the plugins list + const char * name; + + //called once when the plugin starts up + BOOL (*init)(void); + + //called when the emulator resets + void (*reset)(void); + + //called when the plugin shuts down + void (*close)(void); + + //called when the user configurating plugin + void (*config)(void); + + //called when the emulator write to addon + void (*write08)(u8 PROCNUM, u32 adr, u8 val); + void (*write16)(u8 PROCNUM, u32 adr, u16 val); + void (*write32)(u8 PROCNUM, u32 adr, u32 val); + + //called when the emulator read from addon + u8 (*read08)(u8 PROCNUM, u32 adr); + u16 (*read16)(u8 PROCNUM, u32 adr); + u32 (*read32)(u8 PROCNUM, u32 adr); + + //called when the user get info about addon pak (description) + void (*info)(char *info); +}; + +extern SLOT1INTERFACE slot1_device; // current slot1 device + +enum NDS_SLOT1_TYPE +{ + NDS_SLOT1_NONE, + NDS_SLOT1_RETAIL, + NDS_SLOT1_R4, + NDS_SLOT1_COUNT // use for counter addons - MUST TO BE LAST!!! +}; + +extern BOOL slot1Init(); +extern void slot1Close(); +extern void slot1Reset(); +extern BOOL slot1Change(NDS_SLOT1_TYPE type); // change current adddon + + +#endif //__ADDONS_H__ diff --git a/desmume/src/windows/DeSmuME_2005.vcproj b/desmume/src/windows/DeSmuME_2005.vcproj index 85f066776..8fe81c105 100644 --- a/desmume/src/windows/DeSmuME_2005.vcproj +++ b/desmume/src/windows/DeSmuME_2005.vcproj @@ -2094,6 +2094,14 @@ RelativePath="..\shaders.h" > + + + + diff --git a/desmume/src/windows/DeSmuME_2008.vcproj b/desmume/src/windows/DeSmuME_2008.vcproj index cff8ad951..8e752893c 100644 --- a/desmume/src/windows/DeSmuME_2008.vcproj +++ b/desmume/src/windows/DeSmuME_2008.vcproj @@ -902,6 +902,14 @@ RelativePath="..\shaders.h" > + + + + diff --git a/desmume/src/windows/DeSmuME_2010.vcxproj b/desmume/src/windows/DeSmuME_2010.vcxproj index 904380bb6..d3efd9b05 100644 --- a/desmume/src/windows/DeSmuME_2010.vcxproj +++ b/desmume/src/windows/DeSmuME_2010.vcxproj @@ -465,6 +465,7 @@ + @@ -585,6 +586,7 @@ + diff --git a/desmume/src/windows/DeSmuME_2010.vcxproj.filters b/desmume/src/windows/DeSmuME_2010.vcxproj.filters index 6be385b80..3aa8aa5b1 100644 --- a/desmume/src/windows/DeSmuME_2010.vcxproj.filters +++ b/desmume/src/windows/DeSmuME_2010.vcxproj.filters @@ -144,6 +144,9 @@ Core + + Core + Core @@ -512,6 +515,9 @@ Core + + Core + Core