forked from Mirror/SafeB9SInstaller
Misc cosmetics and cleanup
This commit is contained in:
parent
61abd4857c
commit
243f98a3f2
@ -11,7 +11,7 @@ For usage instructions, refer to [Plailect's guide](https://3ds.guide/).
|
|||||||
* **Normmatt**, for sdmmc.c / sdmmc.h
|
* **Normmatt**, for sdmmc.c / sdmmc.h
|
||||||
* **Cha(N)**, **Kane49**, and all other FatFS contributors for FatFS
|
* **Cha(N)**, **Kane49**, and all other FatFS contributors for FatFS
|
||||||
* **SciresM** for being the first fearless person to test this
|
* **SciresM** for being the first fearless person to test this
|
||||||
* **TuxSH** for FIRM research and usefule hints
|
* **TuxSH** for FIRM research and useful hints
|
||||||
* **hedgeberg** for dumping the bootrom (when it's done)
|
* **hedgeberg** for dumping the bootrom (when it's done)
|
||||||
* **Plailect** for providing the guide and making this accessible to the common user
|
* **Plailect** for providing the guide and making this accessible to the common user
|
||||||
* **stuckpixel** for his tireless behind-the-scenes work
|
* **stuckpixel** for his tireless behind-the-scenes work
|
||||||
|
@ -6,6 +6,7 @@ u32 InputWait() {
|
|||||||
static u64 delay = 0;
|
static u64 delay = 0;
|
||||||
u32 pad_state_old = HID_STATE;
|
u32 pad_state_old = HID_STATE;
|
||||||
u32 cart_state_old = CART_STATE;
|
u32 cart_state_old = CART_STATE;
|
||||||
|
u32 sd_state_old = SD_STATE;
|
||||||
delay = (delay) ? 72 : 128;
|
delay = (delay) ? 72 : 128;
|
||||||
timer_start();
|
timer_start();
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -14,6 +15,9 @@ u32 InputWait() {
|
|||||||
u32 cart_state = CART_STATE;
|
u32 cart_state = CART_STATE;
|
||||||
if (cart_state != cart_state_old)
|
if (cart_state != cart_state_old)
|
||||||
return cart_state ? CART_INSERT : CART_EJECT;
|
return cart_state ? CART_INSERT : CART_EJECT;
|
||||||
|
u32 sd_state = SD_STATE;
|
||||||
|
if (sd_state != sd_state_old)
|
||||||
|
return sd_state ? SD_INSERT : SD_EJECT;
|
||||||
u32 special_key = i2cReadRegister(I2C_DEV_MCU, 0x10);
|
u32 special_key = i2cReadRegister(I2C_DEV_MCU, 0x10);
|
||||||
if (special_key == 0x01)
|
if (special_key == 0x01)
|
||||||
return pad_state | BUTTON_POWER;
|
return pad_state | BUTTON_POWER;
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
// see: http://3dbrew.org/wiki/CONFIG9_Registers
|
||||||
|
// see: http://3dbrew.org/wiki/EMMC_Registers
|
||||||
#define HID_STATE (~(*(volatile u32*)0x10146000) & BUTTON_ANY)
|
#define HID_STATE (~(*(volatile u32*)0x10146000) & BUTTON_ANY)
|
||||||
#define CART_STATE (~(*(volatile u8*)0x10000010) & 0x1)
|
#define CART_STATE (~(*(volatile u8*)0x10000010) & 0x1)
|
||||||
|
#define SD_STATE ((*(volatile u16*)0x1000601C) & (0x1<<5))
|
||||||
|
|
||||||
|
|
||||||
#define BUTTON_A (1 << 0)
|
#define BUTTON_A (1 << 0)
|
||||||
@ -21,11 +24,13 @@
|
|||||||
#define BUTTON_ANY 0x00000FFF
|
#define BUTTON_ANY 0x00000FFF
|
||||||
#define BUTTON_ARROW (BUTTON_RIGHT|BUTTON_LEFT|BUTTON_UP|BUTTON_DOWN)
|
#define BUTTON_ARROW (BUTTON_RIGHT|BUTTON_LEFT|BUTTON_UP|BUTTON_DOWN)
|
||||||
|
|
||||||
// special buttons / cart handling
|
// special buttons / cart / sd
|
||||||
#define BUTTON_POWER (1 << 12)
|
#define BUTTON_POWER (1 << 12)
|
||||||
#define BUTTON_HOME (1 << 13)
|
#define BUTTON_HOME (1 << 13)
|
||||||
#define CART_INSERT (1 << 14)
|
#define CART_INSERT (1 << 14)
|
||||||
#define CART_EJECT (1 << 15)
|
#define CART_EJECT (1 << 15)
|
||||||
|
#define SD_INSERT (1 << 16)
|
||||||
|
#define SD_EJECT (1 << 17)
|
||||||
|
|
||||||
u32 InputWait();
|
u32 InputWait();
|
||||||
bool CheckButton(u32 button);
|
bool CheckButton(u32 button);
|
||||||
|
@ -71,7 +71,9 @@ void DrawCharacter(u8* screen, int character, int x, int y, int color, int bgcol
|
|||||||
|
|
||||||
void DrawString(u8* screen, const char *str, int x, int y, int color, int bgcolor)
|
void DrawString(u8* screen, const char *str, int x, int y, int color, int bgcolor)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < strlen(str); i++)
|
size_t max_len = (((screen == TOP_SCREEN) ? SCREEN_WIDTH_TOP : SCREEN_WIDTH_BOT) - x) / FONT_WIDTH;
|
||||||
|
size_t len = (strlen(str) > max_len) ? max_len : strlen(str);
|
||||||
|
for (size_t i = 0; i < len; i++)
|
||||||
DrawCharacter(screen, str[i], x + i * FONT_WIDTH, y, color, bgcolor);
|
DrawCharacter(screen, str[i], x + i * FONT_WIDTH, y, color, bgcolor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,10 +96,10 @@ u32 GetDrawStringHeight(const char* str) {
|
|||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GetDrawStringWidth(char* str) {
|
u32 GetDrawStringWidth(const char* str) {
|
||||||
u32 width = 0;
|
u32 width = 0;
|
||||||
char* old_lf = str;
|
char* old_lf = (char*) str;
|
||||||
char* str_end = str + strnlen(str, STRBUF_SIZE);
|
char* str_end = (char*) str + strnlen(str, STRBUF_SIZE);
|
||||||
for (char* lf = strchr(str, '\n'); lf != NULL; lf = strchr(lf + 1, '\n')) {
|
for (char* lf = strchr(str, '\n'); lf != NULL; lf = strchr(lf + 1, '\n')) {
|
||||||
if ((u32) (lf - old_lf) > width) width = lf - old_lf;
|
if ((u32) (lf - old_lf) > width) width = lf - old_lf;
|
||||||
old_lf = lf;
|
old_lf = lf;
|
||||||
@ -236,6 +238,11 @@ bool ShowUnlockSequence(u32 seqlvl, const char *format, ...) {
|
|||||||
{ '\x18', '\x19', '\x1B', '\x1A', 'A' }
|
{ '\x18', '\x19', '\x1B', '\x1A', 'A' }
|
||||||
};
|
};
|
||||||
const u32 len = 5;
|
const u32 len = 5;
|
||||||
|
|
||||||
|
u32 color_bg = COLOR_STD_BG;
|
||||||
|
u32 color_font = COLOR_STD_FONT;
|
||||||
|
u32 color_off = COLOR_GREY;
|
||||||
|
u32 color_on = seqcolors[seqlvl];
|
||||||
u32 lvl = 0;
|
u32 lvl = 0;
|
||||||
|
|
||||||
u32 str_width, str_height;
|
u32 str_width, str_height;
|
||||||
@ -253,14 +260,21 @@ bool ShowUnlockSequence(u32 seqlvl, const char *format, ...) {
|
|||||||
x = (str_width >= SCREEN_WIDTH_TOP) ? 0 : (SCREEN_WIDTH_TOP - str_width) / 2;
|
x = (str_width >= SCREEN_WIDTH_TOP) ? 0 : (SCREEN_WIDTH_TOP - str_width) / 2;
|
||||||
y = (str_height >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - str_height) / 2;
|
y = (str_height >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - str_height) / 2;
|
||||||
|
|
||||||
ClearScreenF(true, false, COLOR_STD_BG);
|
if (seqlvl >= 6) { // special handling
|
||||||
DrawStringF(TOP_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, str);
|
color_bg = seqcolors[seqlvl];
|
||||||
DrawStringF(TOP_SCREEN, x, y + str_height - 28, COLOR_STD_FONT, COLOR_STD_BG, "To proceed, enter this:");
|
color_font = COLOR_BLACK;
|
||||||
|
color_off = COLOR_BLACK;
|
||||||
|
color_on = COLOR_DARKGREY;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClearScreenF(true, false, color_bg);
|
||||||
|
DrawStringF(TOP_SCREEN, x, y, color_font, color_bg, str);
|
||||||
|
DrawStringF(TOP_SCREEN, x, y + str_height - 28, color_font, color_bg, "To proceed, enter this:");
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
for (u32 n = 0; n < len; n++) {
|
for (u32 n = 0; n < len; n++) {
|
||||||
DrawStringF(TOP_SCREEN, x + (n*4*8), y + str_height - 18,
|
DrawStringF(TOP_SCREEN, x + (n*4*8), y + str_height - 18,
|
||||||
(lvl > n) ? seqcolors[seqlvl] : COLOR_GREY, COLOR_STD_BG, "<%c>", seqsymbols[seqlvl][n]);
|
(lvl > n) ? color_on : color_off, color_bg, "<%c>", seqsymbols[seqlvl][n]);
|
||||||
}
|
}
|
||||||
if (lvl == len)
|
if (lvl == len)
|
||||||
break;
|
break;
|
||||||
|
@ -64,7 +64,7 @@ void DrawString(unsigned char *screen, const char *str, int x, int y, int color,
|
|||||||
void DrawStringF(unsigned char *screen, int x, int y, int color, int bgcolor, const char *format, ...);
|
void DrawStringF(unsigned char *screen, int x, int y, int color, int bgcolor, const char *format, ...);
|
||||||
|
|
||||||
u32 GetDrawStringHeight(const char* str);
|
u32 GetDrawStringHeight(const char* str);
|
||||||
u32 GetDrawStringWidth(char* str);
|
u32 GetDrawStringWidth(const char* str);
|
||||||
|
|
||||||
void ResizeString(char* dest, const char* orig, int nsize, int tpos, bool align_right);
|
void ResizeString(char* dest, const char* orig, int nsize, int tpos, bool align_right);
|
||||||
void TruncateString(char* dest, const char* orig, int nsize, int tpos);
|
void TruncateString(char* dest, const char* orig, int nsize, int tpos);
|
||||||
|
@ -11,9 +11,12 @@
|
|||||||
#include "nand.h"
|
#include "nand.h"
|
||||||
#include "sdmmc.h"
|
#include "sdmmc.h"
|
||||||
|
|
||||||
|
#define PART_TYPE(pdrv) (DriveInfo[pdrv].type)
|
||||||
|
#define PART_SUBTYPE(pdrv) (DriveInfo[pdrv].subtype)
|
||||||
|
|
||||||
#define TYPE_NONE 0
|
#define TYPE_NONE 0
|
||||||
#define TYPE_SYSNAND NAND_SYSNAND
|
#define TYPE_SYSNAND NAND_SYSNAND
|
||||||
#define TYPE_SDCARD (1<<4)
|
#define TYPE_SDCARD (1UL<<4)
|
||||||
|
|
||||||
#define SUBTYPE_CTRN 0
|
#define SUBTYPE_CTRN 0
|
||||||
#define SUBTYPE_CTRN_N 1
|
#define SUBTYPE_CTRN_N 1
|
||||||
@ -41,31 +44,17 @@ FATpartition DriveInfo[4] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SubtypeDesc SubTypes[5] = {
|
SubtypeDesc SubTypes[5] = {
|
||||||
{ 0x05C980, 0x17AE80, 0x4 }, // O3DS CTRNAND
|
{ 0x05C980, 0x17AE80, 0x04 }, // O3DS CTRNAND
|
||||||
{ 0x05C980, 0x20F680, 0x5 }, // N3DS CTRNAND
|
{ 0x05C980, 0x20F680, 0x05 }, // N3DS CTRNAND
|
||||||
{ 0x05C980, 0x20F680, 0x4 }, // N3DS CTRNAND (downgraded)
|
{ 0x05C980, 0x20F680, 0x04 }, // N3DS CTRNAND (downgraded)
|
||||||
{ 0x000097, 0x047DA9, 0x3 }, // TWLN
|
{ 0x000097, 0x047DA9, 0x03 }, // TWLN
|
||||||
{ 0x04808D, 0x0105B3, 0x3 } // TWLP
|
{ 0x04808D, 0x0105B3, 0x03 } // TWLP
|
||||||
};
|
};
|
||||||
|
|
||||||
static BYTE nand_type_sys = 0;
|
static BYTE nand_type_sys = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Get actual FAT partition type helper */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
static inline BYTE get_partition_type(
|
|
||||||
__attribute__((unused))
|
|
||||||
BYTE pdrv /* Physical drive number to identify the drive */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return DriveInfo[pdrv].type;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* Get Drive Subtype helper */
|
/* Get Drive Subtype helper */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
@ -75,8 +64,7 @@ static inline SubtypeDesc* get_subtype_desc(
|
|||||||
BYTE pdrv /* Physical drive number to identify the drive */
|
BYTE pdrv /* Physical drive number to identify the drive */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BYTE type = get_partition_type(pdrv);
|
BYTE subtype = PART_SUBTYPE(pdrv);
|
||||||
BYTE subtype = (type) ? DriveInfo[pdrv].subtype : SUBTYPE_NONE;
|
|
||||||
|
|
||||||
if (subtype == SUBTYPE_NONE) {
|
if (subtype == SUBTYPE_NONE) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -136,7 +124,7 @@ DRESULT disk_read (
|
|||||||
UINT count /* Number of sectors to read */
|
UINT count /* Number of sectors to read */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BYTE type = get_partition_type(pdrv);
|
BYTE type = PART_TYPE(pdrv);
|
||||||
|
|
||||||
if (type == TYPE_NONE) {
|
if (type == TYPE_NONE) {
|
||||||
return RES_PARERR;
|
return RES_PARERR;
|
||||||
@ -170,7 +158,7 @@ DRESULT disk_write (
|
|||||||
UINT count /* Number of sectors to write */
|
UINT count /* Number of sectors to write */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BYTE type = get_partition_type(pdrv);
|
BYTE type = PART_TYPE(pdrv);
|
||||||
|
|
||||||
if (type == TYPE_NONE) {
|
if (type == TYPE_NONE) {
|
||||||
return RES_PARERR;
|
return RES_PARERR;
|
||||||
@ -206,7 +194,7 @@ DRESULT disk_ioctl (
|
|||||||
void *buff /* Buffer to send/receive control data */
|
void *buff /* Buffer to send/receive control data */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BYTE type = get_partition_type(pdrv);
|
BYTE type = PART_TYPE(pdrv);
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case GET_SECTOR_SIZE:
|
case GET_SECTOR_SIZE:
|
||||||
|
@ -4941,7 +4941,7 @@ FRESULT f_setlabel (
|
|||||||
dj.obj.fs = fs;
|
dj.obj.fs = fs;
|
||||||
|
|
||||||
/* Get length of given volume label */
|
/* Get length of given volume label */
|
||||||
for (slen = 0; (UINT)label[slen] >= ' '; slen++) ; /* Get name length */
|
for (slen = 0; (UINT)label[slen] >= ' '; slen++) {} /* Get name length */
|
||||||
|
|
||||||
#if _FS_EXFAT
|
#if _FS_EXFAT
|
||||||
if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
|
if (fs->fs_type == FS_EXFAT) { /* On the exFAT volume */
|
||||||
|
@ -229,7 +229,7 @@
|
|||||||
/ These options have no effect at read-only configuration (_FS_READONLY = 1). */
|
/ These options have no effect at read-only configuration (_FS_READONLY = 1). */
|
||||||
|
|
||||||
|
|
||||||
#define _FS_LOCK 8
|
#define _FS_LOCK 32
|
||||||
/* The option _FS_LOCK switches file lock function to control duplicated file open
|
/* The option _FS_LOCK switches file lock function to control duplicated file open
|
||||||
/ and illegal operation to open objects. This option must be 0 when _FS_READONLY
|
/ and illegal operation to open objects. This option must be 0 when _FS_READONLY
|
||||||
/ is 1.
|
/ is 1.
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
static FATFS* fs = (FATFS*) 0x20316000;
|
static FATFS* fs = (FATFS*) 0x20316000;
|
||||||
|
|
||||||
// currently open file systems
|
// currently open file systems
|
||||||
static FRESULT fs_mounted[NUM_FS] = { FR_NOT_READY };
|
static FRESULT fs_mounted[NUM_FS];
|
||||||
|
|
||||||
FRESULT f_qread (const TCHAR* path, void* buff, FSIZE_t ofs, UINT btr, UINT* br) {
|
FRESULT f_qread (const TCHAR* path, void* buff, FSIZE_t ofs, UINT btr, UINT* br) {
|
||||||
FIL fp;
|
FIL fp;
|
||||||
@ -80,7 +80,6 @@ FRESULT fs_init(void) {
|
|||||||
for (UINT i = 0; i < NUM_FS; i++) {
|
for (UINT i = 0; i < NUM_FS; i++) {
|
||||||
TCHAR* fsname = "X:";
|
TCHAR* fsname = "X:";
|
||||||
*fsname = (TCHAR) ('0' + i);
|
*fsname = (TCHAR) ('0' + i);
|
||||||
if (fs_mounted[i] == FR_OK) continue;
|
|
||||||
fs_mounted[i] = f_mount(fs + i, fsname, 1);
|
fs_mounted[i] = f_mount(fs + i, fsname, 1);
|
||||||
if ((fs_mounted[i] != FR_OK) && (i == 0)) return fs_mounted[i]; // SD can't fail
|
if ((fs_mounted[i] != FR_OK) && (i == 0)) return fs_mounted[i]; // SD can't fail
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "qff.h"
|
#include "qff.h"
|
||||||
|
|
||||||
|
|
||||||
void Reboot()
|
void Reboot()
|
||||||
{
|
{
|
||||||
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2);
|
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user