Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions arm7/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../../share/fifotool.h"
#include "../../share/memtool.h"
#include "picoLoader7.h"
#include "my_i2c.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -121,6 +122,20 @@ static u8 checkSD(void) {
return status & (1u << 5);
}

static u8 check3DS(void) {
if (!isDSiMode()) {
return 0;
}

u8 byteBak = my_i2cReadRegister(0x4A, 0x71);
my_i2cWriteRegister(0x4A, 0x71, 0xD2);
u8 byteNew = my_i2cReadRegister(0x4A, 0x71);
u8 is3DS = (byteNew != 0xD2) ? 1 : 0;
my_i2cWriteRegister(0x4A, 0x71, byteBak);

return is3DS;
}

static void menuValue32Handler(u32 value, void* data) {
switch (value) {
case MENU_MSG_GBA: {
Expand Down Expand Up @@ -167,6 +182,8 @@ static void menuValue32Handler(u32 value, void* data) {
case MENU_MSG_IS_SD_INSERTED:
fifoSendValue32(FIFO_USER_01, checkSD());
break;
case MENU_MSG_IS_3DS:
fifoSendValue32(FIFO_USER_01, check3DS());
default:
break;
}
Expand Down
133 changes: 133 additions & 0 deletions arm7/source/my_i2c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*---------------------------------------------------------------------------------

I2C control for the ARM7

Copyright (C) 2011
Dave Murphy (WinterMute)

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.

Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.

---------------------------------------------------------------------------------*/

#include <nds/arm7/i2c.h>
#include <nds/bios.h>
#include "my_i2c.h"

static u32 i2cCurrentDelay = 0;

//---------------------------------------------------------------------------------
void my_i2cDelay() {
//---------------------------------------------------------------------------------
i2cWaitBusy();
swiDelay(i2cCurrentDelay);
}

//---------------------------------------------------------------------------------
void my_i2cStop(u8 arg0) {
//---------------------------------------------------------------------------------
if (i2cCurrentDelay) {
REG_I2CCNT = (arg0 << 5) | 0xC0;
my_i2cDelay();
REG_I2CCNT = 0xC5;
} else REG_I2CCNT = (arg0 << 5) | 0xC1;
}


//---------------------------------------------------------------------------------
u8 my_i2cGetResult() {
//---------------------------------------------------------------------------------
i2cWaitBusy();
return (REG_I2CCNT >> 4) & 0x01;
}

//---------------------------------------------------------------------------------
u8 my_i2cGetData() {
//---------------------------------------------------------------------------------
i2cWaitBusy();
return REG_I2CDATA;
}

//---------------------------------------------------------------------------------
void my_i2cSetDelay(u8 device) {
//---------------------------------------------------------------------------------
if (device == I2C_PM ) {
i2cCurrentDelay = 0x180;
} else {
i2cCurrentDelay = 0;
}
}

//---------------------------------------------------------------------------------
u8 my_i2cSelectDevice(u8 device) {
//---------------------------------------------------------------------------------
i2cWaitBusy();
REG_I2CDATA = device;
REG_I2CCNT = 0xC2;
return my_i2cGetResult();
}

//---------------------------------------------------------------------------------
u8 my_i2cSelectRegister(u8 reg) {
//---------------------------------------------------------------------------------
my_i2cDelay();
REG_I2CDATA = reg;
REG_I2CCNT = 0xC0;
return my_i2cGetResult();
}

//---------------------------------------------------------------------------------
u8 my_i2cWriteRegister(u8 device, u8 reg, u8 data) {
//---------------------------------------------------------------------------------
my_i2cSetDelay(device);
int i;

for (i = 0; i < 8; i++) {
if ((my_i2cSelectDevice(device) != 0) && (my_i2cSelectRegister(reg) != 0)) {
my_i2cDelay();
REG_I2CDATA = data;
my_i2cStop(0);
if (my_i2cGetResult() != 0) return 1;
}
REG_I2CCNT = 0xC5;
}

return 0;
}

//---------------------------------------------------------------------------------
u8 my_i2cReadRegister(u8 device, u8 reg) {
//---------------------------------------------------------------------------------
my_i2cSetDelay(device);
int i;

for (i = 0; i < 8; i++) {

if ((my_i2cSelectDevice(device) != 0) && (my_i2cSelectRegister(reg) != 0)) {
my_i2cDelay();
if (my_i2cSelectDevice(device | 1)) {
my_i2cDelay();
my_i2cStop(1);
return my_i2cGetData();
}
}

REG_I2CCNT = 0xC5;
}

return 0xff;
}
19 changes: 19 additions & 0 deletions arm7/source/my_i2c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#include <nds.h>

#ifdef __cplusplus
extern "C" {
#endif

void my_i2cDelay();
void my_i2cStop(u8 arg0);
u8 my_i2cGetResult();
u8 my_i2cGetData();
void my_i2cSetDelay(u8 device);
u8 my_i2cSelectDevice(u8 device);
u8 my_i2cSelectRegister(u8 reg);
u8 my_i2cWriteRegister(u8 device, u8 reg, u8 data);
u8 my_i2cReadRegister(u8 device, u8 reg);
#ifdef __cplusplus
}
#endif
6 changes: 4 additions & 2 deletions arm9/source/fsmngr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ void cFSManager::init(int argc, char* argv[]) {
}

// Mount devices
if (isFlashcart()) {
fatMountSimple("fat", dldiGetInternal());
// If we can mount fat, we're on a flashcart
if (fatMountSimple("fat", dldiGetInternal())) {
chdir("fat:/");

_isFlashcart = true;
_fsRoot = "fat:";
}

Expand Down
16 changes: 16 additions & 0 deletions arm9/source/launcher/NdsBootstrapLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ bool NdsBootstrapLauncher::prepareIni(bool hb) {

ini.SetString("NDS-BOOTSTRAP", "QUIT_PATH", fsManager().resolveSystemPath("/_nds/akmenunext/launcher.nds"));

ini.SetString("NDS-BOOTSTRAP", "CONSOLE_MODEL", is3DS() ? "2" : "0");

std::string custIniPath = fsManager().resolveSystemPath("/_nds/akmenunext/ndsbs.ini");

if(access(custIniPath.c_str(), F_OK) != 0){
Expand Down Expand Up @@ -230,6 +232,20 @@ bool NdsBootstrapLauncher::prepareIni(bool hb) {
return true;
}

bool NdsBootstrapLauncher::is3DS(void) {
if (!isDSiMode()) {
return false;
}

fifoSendValue32(FIFO_USER_01, MENU_MSG_IS_3DS);

fifoWaitValue32(FIFO_USER_01);

int result = fifoGetValue32(FIFO_USER_01);

return result != 0;
}

bool launchHbStrap(std::string romPath){
progressWnd().setPercent(100);
std::string ndsHbBootstrapPath = fsManager().resolveSystemPath("/_nds/nds-bootstrap-hb-release.nds");
Expand Down
1 change: 1 addition & 0 deletions arm9/source/launcher/NdsBootstrapLauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class NdsBootstrapLauncher : public ILauncher {
private:
bool prepareCheats(void);
bool prepareIni(bool hb);
bool is3DS(void);
bool hotkeyCheck;
std::string mRomPath;
std::string mSavePath;
Expand Down
1 change: 1 addition & 0 deletions share/fifotool.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
#define MENU_MSG_ARM7_REBOOT_TT 13
#define MENU_MSG_ARM7_REBOOT_PICOLOADER 14
#define MENU_MSG_IS_SD_INSERTED 15
#define MENU_MSG_IS_3DS 16
Loading