diff options
author | Arisotura <thetotalworm@gmail.com> | 2019-06-16 17:01:49 +0200 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2019-06-16 17:01:49 +0200 |
commit | d4dd97638d1615f51bcadd256d390a895519d565 (patch) | |
tree | b095994489c2cf55d058f86b84215c9a37f73598 /src | |
parent | 566a8df6cd5af057a77cf8bed091e1b7a18bfecd (diff) |
lay base for SD shit
Diffstat (limited to 'src')
-rw-r--r-- | src/DSi.cpp | 67 | ||||
-rw-r--r-- | src/DSi.h | 2 | ||||
-rw-r--r-- | src/DSi_SD.cpp | 72 | ||||
-rw-r--r-- | src/DSi_SD.h | 41 | ||||
-rw-r--r-- | src/NDS.cpp | 4 | ||||
-rw-r--r-- | src/version.h | 2 |
6 files changed, 187 insertions, 1 deletions
diff --git a/src/DSi.cpp b/src/DSi.cpp index 206c253..e30e3e1 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -26,6 +26,7 @@ #include "Platform.h" #include "DSi_I2C.h" +#include "DSi_SD.h" namespace NDS @@ -56,6 +57,27 @@ u32 NWRAMStart[2][3]; u32 NWRAMEnd[2][3]; u32 NWRAMMask[2][3]; +DSi_SD* SDMMC; +DSi_SD* SDIO; + + +bool Init() +{ + if (!DSi_I2C::Init()) return false; + + SDMMC = new DSi_SD(0); + SDIO = new DSi_SD(1); + + return true; +} + +void DeInit() +{ + DSi_I2C::DeInit(); + + delete SDMMC; + delete SDIO; +} void Reset() { @@ -67,6 +89,9 @@ void Reset() NDS::ARM7->JumpTo(BootAddr[1]); DSi_I2C::Reset(); + + SDMMC->Reset(); + SDIO->Reset(); } bool LoadBIOS() @@ -904,6 +929,15 @@ u16 ARM7IORead16(u32 addr) case 0x04004006: return 0; // JTAG register } + if (addr >= 0x04004800 && addr < 0x04004A00) + { + return SDMMC->Read(addr); + } + if (addr >= 0x04004A00 && addr < 0x04004C00) + { + return SDIO->Read(addr); + } + return NDS::ARM7IORead16(addr); } @@ -917,6 +951,15 @@ u32 ARM7IORead32(u32 addr) case 0x04004008: return 0x80000000; // HAX } + if (addr >= 0x04004800 && addr < 0x04004A00) + { + return SDMMC->Read(addr) | (SDMMC->Read(addr+2) << 16); + } + if (addr >= 0x04004A00 && addr < 0x04004C00) + { + return SDIO->Read(addr) | (SDIO->Read(addr+2) << 16); + } + return NDS::ARM7IORead32(addr); } @@ -939,6 +982,17 @@ void ARM7IOWrite16(u32 addr, u16 val) case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; } + if (addr >= 0x04004800 && addr < 0x04004A00) + { + SDMMC->Write(addr, val); + return; + } + if (addr >= 0x04004A00 && addr < 0x04004C00) + { + SDIO->Write(addr, val); + return; + } + return NDS::ARM7IOWrite16(addr, val); } @@ -950,6 +1004,19 @@ void ARM7IOWrite32(u32 addr, u32 val) case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; } + if (addr >= 0x04004800 && addr < 0x04004A00) + { + SDMMC->Write(addr, val & 0xFFFF); + SDMMC->Write(addr+2, val >> 16); + return; + } + if (addr >= 0x04004A00 && addr < 0x04004C00) + { + SDIO->Write(addr, val & 0xFFFF); + SDIO->Write(addr+2, val >> 16); + return; + } + return NDS::ARM7IOWrite32(addr, val); } @@ -24,6 +24,8 @@ namespace DSi { +bool Init(); +void DeInit(); void Reset(); bool LoadBIOS(); diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp new file mode 100644 index 0000000..58b733c --- /dev/null +++ b/src/DSi_SD.cpp @@ -0,0 +1,72 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include <stdio.h> +#include <string.h> +#include "DSi.h" +#include "DSi_SD.h" + + +DSi_SD::DSi_SD(u32 num) +{ + Num = num; +} + +DSi_SD::~DSi_SD() +{ + // +} + +void DSi_SD::Reset() +{ + if (Num == 0) + { + PortSelect = 0x0200; // CHECKME + } + else + { + PortSelect = 0x0100; // CHECKME + } +} + +void DSi_SD::DoSavestate(Savestate* file) +{ + // TODO! +} + + +u16 DSi_SD::Read(u32 addr) +{ + switch (addr & 0x1FF) + { + case 0x002: return PortSelect & 0x030F; + } + + printf("unknown %s read %08X\n", Num?"SDIO":"SD/MMC", addr); + return 0; +} + +void DSi_SD::Write(u32 addr, u16 val) +{ + switch (addr & 0x1FF) + { + case 0x002: PortSelect = val; return; + } + + printf("unknown %s write %08X %04X\n", Num?"SDIO":"SD/MMC", addr, val); +} diff --git a/src/DSi_SD.h b/src/DSi_SD.h new file mode 100644 index 0000000..ce3eb84 --- /dev/null +++ b/src/DSi_SD.h @@ -0,0 +1,41 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef DSI_SD_H +#define DSI_SD_H + +class DSi_SD +{ +public: + DSi_SD(u32 num); + ~DSi_SD(); + + void Reset(); + + void DoSavestate(Savestate* file); + + u16 Read(u32 addr); + void Write(u32 addr, u16 val); + +private: + u32 Num; + + u16 PortSelect; +}; + +#endif // DSI_SD_H diff --git a/src/NDS.cpp b/src/NDS.cpp index 5ca55f3..414f87c 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -178,6 +178,8 @@ bool Init() if (!RTC::Init()) return false; if (!Wifi::Init()) return false; + if (!DSi::Init()) return false; + return true; } @@ -198,6 +200,8 @@ void DeInit() SPI::DeInit(); RTC::DeInit(); Wifi::DeInit(); + + DSi::DeInit(); } diff --git a/src/version.h b/src/version.h index cc15c89..bb97c3c 100644 --- a/src/version.h +++ b/src/version.h @@ -19,7 +19,7 @@ #ifndef VERSION_H #define VERSION_H -#define MELONDS_VERSION "0.8.1" +#define MELONDS_VERSION "0.8.1-DSi" #define MELONDS_URL "http://melonds.kuribo64.net/" |