Cleaned up some code..

It almost compiles without any warnings now. Only fix left for it that
is to redo slot reset code. Original code is too much of a mess to
compile with the  "-Wall -Wextra -Werror" flag.

That flag has been added to makefile of arm9/bootloader. Once arm7 is
fixed it will be added there as well.
This commit is contained in:
ApacheThunder 2017-02-24 16:53:36 -06:00
parent a14a73c7d1
commit 02b267152a
13 changed files with 33 additions and 114 deletions

View File

@ -26,6 +26,7 @@ ARCH := -mthumb-interwork -march=armv4t -mtune=arm7tdmi
CFLAGS := -g -Wall -O2\ CFLAGS := -g -Wall -O2\
-fomit-frame-pointer\ -fomit-frame-pointer\
-ffast-math \ -ffast-math \
-Wall -Wextra -Werror \
$(ARCH) $(ARCH)
CFLAGS += $(INCLUDE) -DARM7 CFLAGS += $(INCLUDE) -DARM7

View File

@ -36,6 +36,7 @@
#include <nds/dma.h> #include <nds/dma.h>
#include <nds/arm7/audio.h> #include <nds/arm7/audio.h>
#include <nds/ipc.h> #include <nds/ipc.h>
// #include <nds/registers_alt.h> // #include <nds/registers_alt.h>
// #include <nds/memory.h> // #include <nds/memory.h>
// #include <nds/card.h> // #include <nds/card.h>
@ -217,11 +218,9 @@ void arm7_startBinary (void)
while(REG_VCOUNT!=191); while(REG_VCOUNT!=191);
while(REG_VCOUNT==191); while(REG_VCOUNT==191);
// Start ARM7 // Start ARM7
((void (*)())(*(u32*)(0x27FFE34)))();
void (*foo)() = *(u32*)(0x27FFE34);
foo();
} }

View File

@ -37,8 +37,14 @@
#include <nds/system.h> #include <nds/system.h>
#include <nds/ipc.h> #include <nds/ipc.h>
#include <nds/dma.h>
#include <stdlib.h>
#include "common.h" #include "common.h"
#define resetCpu_arm9() \
__asm volatile("swi 0x000000")
volatile int arm9_stateFlag = ARM9_BOOT; volatile int arm9_stateFlag = ARM9_BOOT;
volatile u32 arm9_errorCode = 0xFFFFFFFF; volatile u32 arm9_errorCode = 0xFFFFFFFF;
volatile bool arm9_errorClearBG = false; volatile bool arm9_errorClearBG = false;
@ -232,12 +238,8 @@ void arm9_main (void) {
while(REG_VCOUNT!=191); while(REG_VCOUNT!=191);
while(REG_VCOUNT==191); while(REG_VCOUNT==191);
u32 first = *(u32*)(0x27FFE34);
// arm9_errorOutput (*(u32*)(first), true); // arm9_errorOutput (*(u32*)(first), true);
void (*newReset)() = *(u32*)(0x27FFE24); ((void (*)())(*(u32*)(0x27FFE24)))();
newReset();
} }

View File

@ -31,7 +31,7 @@ $(TARGET).nds : $(TARGET).arm7 $(TARGET).arm9
-b $(CURDIR)/icon.bmp "NTR Launcher;NitroHax provided by Chishm;Modified by Apache Thunder" \ -b $(CURDIR)/icon.bmp "NTR Launcher;NitroHax provided by Chishm;Modified by Apache Thunder" \
-g KKGP 01 "NTR LAUNCHER" -z 80040000 -u 00030004 -g KKGP 01 "NTR LAUNCHER" -z 80040000 -u 00030004
python patch_ndsheader_dsiware.py $(CURDIR)/$(TARGET).nds --accessControl 0x00000038 python patch_ndsheader_dsiware.py $(CURDIR)/$(TARGET).nds --accessControl 0x00000038
make_cia --srl=$(CURDIR)/$(TARGET).nds makerom -srl $(CURDIR)/$(TARGET).nds
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
$(TARGET).arm7 : arm7/$(TARGET).elf $(TARGET).arm7 : arm7/$(TARGET).elf

View File

@ -14,7 +14,7 @@ int PowerOnSlot() {
REG_ROMCTRL = 0x20000000; // wait 27ms, then set ROMCTRL=20000000h REG_ROMCTRL = 0x20000000; // wait 27ms, then set ROMCTRL=20000000h
while(REG_ROMCTRL&0x8000000 != 0x8000000); while(REG_ROMCTRL&0x8000000 != 0x8000000);
return 0;
} }
int PowerOffSlot() { int PowerOffSlot() {
@ -23,11 +23,13 @@ int PowerOffSlot() {
REG_SCFG_MC = 0x0C; // set state=3 REG_SCFG_MC = 0x0C; // set state=3
while(REG_SCFG_MC&0x0C != 0x00); // wait until state=0 while(REG_SCFG_MC&0x0C != 0x00); // wait until state=0
return 0;
} }
void TWL_ResetSlot1() { int TWL_ResetSlot1() {
PowerOffSlot(); PowerOffSlot();
for (int i = 0; i < 30; i++) { swiWaitForVBlank(); } for (int i = 0; i < 30; i++) { swiWaitForVBlank(); }
PowerOnSlot(); PowerOnSlot();
return 0;
} }

View File

@ -8,7 +8,7 @@ extern "C" {
int PowerOnSlot(void); int PowerOnSlot(void);
int PowerOffSlot(void); int PowerOffSlot(void);
void TWL_ResetSlot1(void); int TWL_ResetSlot1(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -29,6 +29,7 @@ ARCH := -march=armv5te -mtune=arm946e-s -mthumb -mthumb-interwork
CFLAGS := -g -Wall -O2\ CFLAGS := -g -Wall -O2\
-fomit-frame-pointer\ -fomit-frame-pointer\
-ffast-math \ -ffast-math \
-Wall -Wextra -Werror \
$(ARCH) $(ARCH)
CFLAGS += $(INCLUDE) -DARM9 -fno-strict-aliasing CFLAGS += $(INCLUDE) -DARM9 -fno-strict-aliasing
@ -106,6 +107,7 @@ $(BUILD):
clean: clean:
@echo clean ... @echo clean ...
@rm -fr $(BUILD) *.elf *.nds* *.bin @rm -fr $(BUILD) *.elf *.nds* *.bin
@rm -fr $(DATA) *.elf *.nds* *.bin
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
else else

View File

@ -20,6 +20,8 @@
#include "errorsplash.h" #include "errorsplash.h"
#include "bootsplash.h"
#include "bios_decompress_callback.h" #include "bios_decompress_callback.h"
#include "fade00.h" #include "fade00.h"

View File

@ -21,7 +21,6 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include "inifile.h" #include "inifile.h"
#include "stringtool.h"
static bool freadLine(FILE* f,std::string& str) static bool freadLine(FILE* f,std::string& str)
{ {
@ -104,7 +103,9 @@ void CIniFile::SetString(const std::string& Section,const std::string& Item,cons
void CIniFile::SetInt(const std::string& Section,const std::string& Item,int Value) void CIniFile::SetInt(const std::string& Section,const std::string& Item,int Value)
{ {
std::string strtemp=formatString("%d",Value); char buf[16];
snprintf(buf, sizeof(buf), "%d", Value);
std::string strtemp(buf);
if(GetFileString(Section,Item)!=strtemp) if(GetFileString(Section,Item)!=strtemp)
{ {
@ -275,7 +276,7 @@ std::string CIniFile::GetFileString(const std::string& Section,const std::string
m_bLastResult=false; m_bLastResult=false;
if(iFileLines>=0) if(iFileLines>0)
{ {
while(ii<iFileLines) while(ii<iFileLines)
{ {
@ -389,3 +390,4 @@ bool CIniFile::ReplaceLine(size_t line,const std::string& str)
m_FileContainer[line]=str; m_FileContainer[line]=str;
return true; return true;
} }

View File

@ -29,7 +29,7 @@ class CIniFile
{ {
public: public:
CIniFile(); CIniFile();
CIniFile(const std::string& filename); explicit CIniFile(const std::string& filename);
virtual ~CIniFile(); virtual ~CIniFile();
public: public:

View File

@ -39,7 +39,7 @@
// #define REG_SCFG_MC (*(vu32*)0x4004010) // #define REG_SCFG_MC (*(vu32*)0x4004010)
int main(int argc, const char* argv[]) { int main() {
// NTR Mode/Splash used by default // NTR Mode/Splash used by default
bool UseNTRSplash = true; bool UseNTRSplash = true;
@ -59,7 +59,6 @@ int main(int argc, const char* argv[]) {
u32 ndsHeader[0x80]; u32 ndsHeader[0x80];
char gameid[4]; char gameid[4];
uint32_t headerCRC;
scanKeys(); scanKeys();
int pressed = keysDown(); int pressed = keysDown();
@ -77,9 +76,9 @@ int main(int argc, const char* argv[]) {
if( UseNTRSplash == true ) { if( UseNTRSplash == true ) {
fifoSendValue32(FIFO_USER_04, 1); fifoSendValue32(FIFO_USER_04, 1);
// REG_SCFG_CLK = 0x80; // Disabled for now. Doesn't result in correct SCFG_CLK configuration during testing. Will go back to old method.
// New libnds function for going back to NTR clock speeds // setCpuClock(false);
setCpuClock(false); REG_SCFG_CLK = 0x80;
swiWaitForVBlank(); swiWaitForVBlank();
} }
@ -119,7 +118,6 @@ int main(int argc, const char* argv[]) {
for (int i = 0; i < 20; i++) { swiWaitForVBlank(); } for (int i = 0; i < 20; i++) { swiWaitForVBlank(); }
memcpy (gameid, ((const char*)ndsHeader) + 12, 4); memcpy (gameid, ((const char*)ndsHeader) + 12, 4);
headerCRC = crc32((const char*)ndsHeader, sizeof(ndsHeader));
while(1) { while(1) {
if(REG_SCFG_MC == 0x11) { if(REG_SCFG_MC == 0x11) {

View File

@ -1,45 +0,0 @@
/*---------------------------------------------------------------------------------
Copyright (C) 2007 Acekard, www.acekard.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
---------------------------------------------------------------------------------*/
#include "stringtool.h"
#include <cstdarg>
#include <cstdio>
#include <malloc.h>
std::string formatString( const char* fmt, ... )
{
const char * f = fmt;
va_list argList;
va_start(argList, fmt);
char * ptempStr = NULL;
size_t max_len = vasiprintf( &ptempStr, f, argList);
std::string str( ptempStr );
str.resize( max_len );
free( ptempStr );
va_end(argList);
return str;
}

View File

@ -1,44 +0,0 @@
/*---------------------------------------------------------------------------------
Copyright (C) 2007 Acekard, www.acekard.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
---------------------------------------------------------------------------------*/
#ifndef _STRINGTOOL_H_
#define _STRINGTOOL_H_
#include <string>
std::string formatString( const char* fmt, ... );
#endif//_STRINGTOOL_H_