From 59d107bfb0ae6b5f8d683890010885ff35050ff6 Mon Sep 17 00:00:00 2001
From: StapleButter <thetotalworm@gmail.com>
Date: Sun, 19 Mar 2017 19:07:39 +0100
Subject: make ROM path not be hardcoded.

---
 src/NDS.cpp     | 14 +++++++-------
 src/NDS.h       |  1 +
 src/NDSCart.cpp | 13 +++++++------
 src/NDSCart.h   |  2 +-
 src/wx/main.cpp |  9 ++++++++-
 5 files changed, 24 insertions(+), 15 deletions(-)

(limited to 'src')

diff --git a/src/NDS.cpp b/src/NDS.cpp
index 574f557..52a1de0 100644
--- a/src/NDS.cpp
+++ b/src/NDS.cpp
@@ -135,7 +135,6 @@ bool Init()
     if (!SPI::Init()) return false;
     if (!RTC::Init()) return false;
 
-    Reset();
     return true;
 }
 
@@ -307,13 +306,14 @@ void Reset()
     KeyInput = 0x007F03FF;
 
     _soundbias = 0;
+}
+
+void LoadROM(const char* path, bool direct)
+{
+    Reset();
 
-    // test
-    //LoadROM();
-    //LoadFirmware();
-    // a_interp2.nds a_rounding (10) (11)    a_slope (5)
-    if (NDSCart::LoadROM("rom/nsmb.nds"))
-        Running = true; // hax
+    if (NDSCart::LoadROM(path, direct))
+        Running = true;
 }
 
 
diff --git a/src/NDS.h b/src/NDS.h
index ed706af..976bd26 100644
--- a/src/NDS.h
+++ b/src/NDS.h
@@ -116,6 +116,7 @@ bool Init();
 void DeInit();
 void Reset();
 
+void LoadROM(const char* path, bool direct);
 void SetupDirectBoot();
 
 void RunFrame();
diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp
index 416da26..16e8435 100644
--- a/src/NDSCart.cpp
+++ b/src/NDSCart.cpp
@@ -601,7 +601,7 @@ void Reset()
 }
 
 
-bool LoadROM(char* path)
+bool LoadROM(const char* path, bool direct)
 {
     // TODO: streaming mode? for really big ROMs or systems with limited RAM
     // for now we're lazy
@@ -632,10 +632,11 @@ bool LoadROM(char* path)
     fclose(f);
     //CartROM = f;
 
-    // temp. TODO: later make this user selectable
-    // calling this sets up shit for booting from the cart directly.
-    // normal behavior is booting from the BIOS.
-    NDS::SetupDirectBoot();
+    if (direct)
+    {
+        NDS::SetupDirectBoot();
+        CmdEncMode = 2;
+    }
 
     CartInserted = true;
 
@@ -650,7 +651,7 @@ bool LoadROM(char* path)
         if (arm9base >= 0x4000)
         {
             // reencrypt secure area if needed
-            if (*(u32*)&CartROM[arm9base] == 0xE7FFDEFF)
+            if (*(u32*)&CartROM[arm9base] == 0xE7FFDEFF && *(u32*)&CartROM[arm9base+0x10] != 0xE7FFDEFF)
             {
                 printf("Re-encrypting cart secure area\n");
 
diff --git a/src/NDSCart.h b/src/NDSCart.h
index 61dd11a..5125ffa 100644
--- a/src/NDSCart.h
+++ b/src/NDSCart.h
@@ -40,7 +40,7 @@ bool Init();
 void DeInit();
 void Reset();
 
-bool LoadROM(char* path);
+bool LoadROM(const char* path, bool direct);
 
 void WriteROMCnt(u32 val);
 u32 ReadROMData();
diff --git a/src/wx/main.cpp b/src/wx/main.cpp
index b31af1d..987491b 100644
--- a/src/wx/main.cpp
+++ b/src/wx/main.cpp
@@ -86,11 +86,18 @@ MainFrame::MainFrame()
 
     sdlrend = SDL_CreateRenderer(sdlwin, -1, SDL_RENDERER_ACCELERATED); // SDL_RENDERER_PRESENTVSYNC
     sdltex = SDL_CreateTexture(sdlrend, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING, 256, 384);
+
+    NDS::Init();
 }
 
 void MainFrame::OnOpenROM(wxCommandEvent& event)
 {
-    NDS::Init();
+    wxFileDialog opener(this, _("Open ROM"), "", "", "DS ROM (*.nds)|*.nds;*.srl|Any file|*.*", wxFD_OPEN|wxFD_FILE_MUST_EXIST);
+    if (opener.ShowModal() == wxID_CANCEL)
+        return;
+
+    wxString filename = opener.GetPath();
+    NDS::LoadROM(filename.mb_str(), true);
 
     emuthread->EmuStatus = 1;
     emumutex->Lock();
-- 
cgit v1.2.3