lay base for SD shit

This commit is contained in:
Arisotura 2019-06-16 17:01:49 +02:00
parent 566a8df6cd
commit d4dd97638d
7 changed files with 189 additions and 1 deletions

View File

@ -106,6 +106,8 @@
<Unit filename="src/DSiCrypto.h" /> <Unit filename="src/DSiCrypto.h" />
<Unit filename="src/DSi_I2C.cpp" /> <Unit filename="src/DSi_I2C.cpp" />
<Unit filename="src/DSi_I2C.h" /> <Unit filename="src/DSi_I2C.h" />
<Unit filename="src/DSi_SD.cpp" />
<Unit filename="src/DSi_SD.h" />
<Unit filename="src/FIFO.h" /> <Unit filename="src/FIFO.h" />
<Unit filename="src/GPU.cpp" /> <Unit filename="src/GPU.cpp" />
<Unit filename="src/GPU.h" /> <Unit filename="src/GPU.h" />

View File

@ -26,6 +26,7 @@
#include "Platform.h" #include "Platform.h"
#include "DSi_I2C.h" #include "DSi_I2C.h"
#include "DSi_SD.h"
namespace NDS namespace NDS
@ -56,6 +57,27 @@ u32 NWRAMStart[2][3];
u32 NWRAMEnd[2][3]; u32 NWRAMEnd[2][3];
u32 NWRAMMask[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() void Reset()
{ {
@ -67,6 +89,9 @@ void Reset()
NDS::ARM7->JumpTo(BootAddr[1]); NDS::ARM7->JumpTo(BootAddr[1]);
DSi_I2C::Reset(); DSi_I2C::Reset();
SDMMC->Reset();
SDIO->Reset();
} }
bool LoadBIOS() bool LoadBIOS()
@ -904,6 +929,15 @@ u16 ARM7IORead16(u32 addr)
case 0x04004006: return 0; // JTAG register 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); return NDS::ARM7IORead16(addr);
} }
@ -917,6 +951,15 @@ u32 ARM7IORead32(u32 addr)
case 0x04004008: return 0x80000000; // HAX 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); return NDS::ARM7IORead32(addr);
} }
@ -939,6 +982,17 @@ void ARM7IOWrite16(u32 addr, u16 val)
case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; 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); 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; 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); return NDS::ARM7IOWrite32(addr, val);
} }

View File

@ -24,6 +24,8 @@
namespace DSi namespace DSi
{ {
bool Init();
void DeInit();
void Reset(); void Reset();
bool LoadBIOS(); bool LoadBIOS();

72
src/DSi_SD.cpp Normal file
View File

@ -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);
}

41
src/DSi_SD.h Normal file
View File

@ -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

View File

@ -178,6 +178,8 @@ bool Init()
if (!RTC::Init()) return false; if (!RTC::Init()) return false;
if (!Wifi::Init()) return false; if (!Wifi::Init()) return false;
if (!DSi::Init()) return false;
return true; return true;
} }
@ -198,6 +200,8 @@ void DeInit()
SPI::DeInit(); SPI::DeInit();
RTC::DeInit(); RTC::DeInit();
Wifi::DeInit(); Wifi::DeInit();
DSi::DeInit();
} }

View File

@ -19,7 +19,7 @@
#ifndef VERSION_H #ifndef VERSION_H
#define 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/" #define MELONDS_URL "http://melonds.kuribo64.net/"