Skip to content

Commit

Permalink
Make it optional to keep ROM in RAM
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydr8gon committed Jul 31, 2024
1 parent fff29ac commit f08dcff
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 57 deletions.
30 changes: 20 additions & 10 deletions src/android/cpp/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getFpsLimite
return Settings::fpsLimiter;
}

extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getMicEnable(JNIEnv* env, jobject obj)
{
return micEnable;
}

extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getRomInRam(JNIEnv* env, jobject obj)
{
return Settings::romInRam;
}

extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getThreaded2D(JNIEnv* env, jobject obj)
{
return Settings::threaded2D;
Expand All @@ -334,11 +344,6 @@ extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getHighRes3D
return Settings::highRes3D;
}

extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getMicEnable(JNIEnv* env, jobject obj)
{
return micEnable;
}

extern "C" JNIEXPORT jint JNICALL Java_com_hydra_noods_SettingsMenu_getShowFpsCounter(JNIEnv* env, jobject obj)
{
return showFpsCounter;
Expand Down Expand Up @@ -429,6 +434,16 @@ extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setFpsLimite
Settings::fpsLimiter = value;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setMicEnable(JNIEnv* env, jobject obj, jint value)
{
micEnable = value;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setRomInRam(JNIEnv* env, jobject obj, jint value)
{
Settings::romInRam = value;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setThreaded2D(JNIEnv* env, jobject obj, jint value)
{
Settings::threaded2D = value;
Expand All @@ -444,11 +459,6 @@ extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setHighRes3D
Settings::highRes3D = value;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setMicEnable(JNIEnv* env, jobject obj, jint value)
{
micEnable = value;
}

extern "C" JNIEXPORT void JNICALL Java_com_hydra_noods_SettingsMenu_setShowFpsCounter(JNIEnv* env, jobject obj, jint value)
{
showFpsCounter = value;
Expand Down
12 changes: 8 additions & 4 deletions src/android/java/com/hydra/noods/SettingsMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ protected void onCreate(Bundle savedInstanceState)
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("direct_boot", (getDirectBoot() == 0) ? false : true);
editor.putBoolean("fps_limiter", (getFpsLimiter() == 0) ? false : true);
editor.putBoolean("mic_enable", (getMicEnable() == 0) ? false : true);
editor.putBoolean("rom_in_ram", (getRomInRam() == 0) ? false : true);
editor.putBoolean("threaded_2d", (getThreaded2D() == 0) ? false : true);
editor.putString("threaded_3d", Integer.toString(getThreaded3D()));
editor.putBoolean("high_res_3d", (getHighRes3D() == 0) ? false : true);
editor.putBoolean("mic_enable", (getMicEnable() == 0) ? false : true);
editor.putBoolean("show_fps_counter", (getShowFpsCounter() == 0) ? false : true);
editor.putBoolean("saves_folder", (getSavesFolder() == 0) ? false : true);
editor.putBoolean("states_folder", (getStatesFolder() == 0) ? false : true);
Expand Down Expand Up @@ -142,10 +143,11 @@ public void onBackPressed()
// Save the settings to the core
setDirectBoot(prefs.getBoolean("direct_boot", true) ? 1 : 0);
setFpsLimiter(prefs.getBoolean("fps_limiter", true) ? 1 : 0);
setMicEnable(prefs.getBoolean("mic_enable", false) ? 1 : 0);
setRomInRam(prefs.getBoolean("rom_in_ram", false) ? 1 : 0);
setThreaded2D(prefs.getBoolean("threaded_2d", true) ? 1 : 0);
setThreaded3D(Integer.parseInt(prefs.getString("threaded_3d", "1")));
setHighRes3D(prefs.getBoolean("high_res_3d", false) ? 1 : 0);
setMicEnable(prefs.getBoolean("mic_enable", false) ? 1 : 0);
setShowFpsCounter(prefs.getBoolean("show_fps_counter", false) ? 1 : 0);
setSavesFolder(prefs.getBoolean("saves_folder", false) ? 1 : 0);
setStatesFolder(prefs.getBoolean("states_folder", true) ? 1 : 0);
Expand All @@ -170,10 +172,11 @@ public void onBackPressed()

public static native int getDirectBoot();
public static native int getFpsLimiter();
public static native int getMicEnable();
public static native int getRomInRam();
public static native int getThreaded2D();
public static native int getThreaded3D();
public static native int getHighRes3D();
public static native int getMicEnable();
public static native int getShowFpsCounter();
public static native int getSavesFolder();
public static native int getStatesFolder();
Expand All @@ -192,10 +195,11 @@ public void onBackPressed()
public static native int getVibrateStrength();
public static native void setDirectBoot(int value);
public static native void setFpsLimiter(int value);
public static native void setMicEnable(int value);
public static native void setRomInRam(int value);
public static native void setThreaded2D(int value);
public static native void setThreaded3D(int value);
public static native void setHighRes3D(int value);
public static native void setMicEnable(int value);
public static native void setShowFpsCounter(int value);
public static native void setSavesFolder(int value);
public static native void setStatesFolder(int value);
Expand Down
21 changes: 14 additions & 7 deletions src/android/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
app:allowDividerAbove="true"
app:allowDividerBelow="true" />

<SwitchPreference
app:key="mic_enable"
app:title="Use Microphone"
app:iconSpaceReserved="false"
app:allowDividerAbove="true"
app:allowDividerBelow="true" />

<SwitchPreference
app:key="rom_in_ram"
app:title="Keep ROM in RAM"
app:iconSpaceReserved="false"
app:allowDividerAbove="true"
app:allowDividerBelow="true" />

<SwitchPreference
app:key="threaded_2d"
app:title="Threaded 2D"
Expand All @@ -44,13 +58,6 @@
app:allowDividerAbove="true"
app:allowDividerBelow="true" />

<SwitchPreference
app:key="mic_enable"
app:title="Use Microphone"
app:iconSpaceReserved="false"
app:allowDividerAbove="true"
app:allowDividerBelow="true" />

<SwitchPreference
app:key="show_fps_counter"
app:title="Show FPS Counter"
Expand Down
4 changes: 2 additions & 2 deletions src/cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ bool CartridgeNds::loadRom()
saveSizes.push_back(0x800000); // FLASH 8192KB
}

// If the ROM is 512MB or smaller, try to load it into memory; otherwise fall back to file-based loading
// Try to load the ROM into RAM if enabled; otherwise fall back to file-based loading
if (!Cartridge::loadRom())
{
return false;
}
else if (romSize <= 0x20000000) // 512MB
else if (Settings::romInRam)
{
try
{
Expand Down
38 changes: 20 additions & 18 deletions src/console/console_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ void ConsoleUI::settingsMenu()
{
MenuItem("Direct Boot", toggle[Settings::directBoot]),
MenuItem("FPS Limiter", toggle[Settings::fpsLimiter]),
MenuItem("Keep ROM in RAM", toggle[Settings::romInRam]),
MenuItem("Threaded 2D", toggle[Settings::threaded2D]),
MenuItem("Threaded 3D", threads[Settings::threaded3D]),
MenuItem("High-Resolution 3D", toggle[Settings::highRes3D]),
Expand Down Expand Up @@ -860,24 +861,25 @@ void ConsoleUI::settingsMenu()
{
case 0: Settings::directBoot = (Settings::directBoot + 1) % 2; break;
case 1: Settings::fpsLimiter = (Settings::fpsLimiter + 1) % 2; break;
case 2: Settings::threaded2D = (Settings::threaded2D + 1) % 2; break;
case 3: Settings::threaded3D = (Settings::threaded3D + 1) % 3; break;
case 4: Settings::highRes3D = (Settings::highRes3D + 1) % 2; break;
case 5: showFpsCounter = (showFpsCounter + 1) % 2; break;
case 6: Settings::savesFolder = (Settings::savesFolder + 1) % 2; break;
case 7: Settings::statesFolder = (Settings::statesFolder + 1) % 2; break;
case 8: Settings::cheatsFolder = (Settings::cheatsFolder + 1) % 2; break;
case 9: ScreenLayout::screenPosition = (ScreenLayout::screenPosition + 1) % 5; break;
case 10: ScreenLayout::screenRotation = (ScreenLayout::screenRotation + 1) % 3; break;
case 11: ScreenLayout::screenArrangement = (ScreenLayout::screenArrangement + 1) % 4; break;
case 12: ScreenLayout::screenSizing = (ScreenLayout::screenSizing + 1) % 3; break;
case 13: ScreenLayout::screenGap = (ScreenLayout::screenGap + 1) % 4; break;
case 14: Settings::screenFilter = (Settings::screenFilter + 1) % 3; break;
case 15: ScreenLayout::integerScale = (ScreenLayout::integerScale + 1) % 2; break;
case 16: ScreenLayout::gbaCrop = (ScreenLayout::gbaCrop + 1) % 2; break;
case 17: Settings::screenGhost = (Settings::screenGhost + 1) % 2; break;

case 18:
case 2: Settings::romInRam = (Settings::romInRam + 1) % 2; break;
case 3: Settings::threaded2D = (Settings::threaded2D + 1) % 2; break;
case 4: Settings::threaded3D = (Settings::threaded3D + 1) % 3; break;
case 5: Settings::highRes3D = (Settings::highRes3D + 1) % 2; break;
case 6: showFpsCounter = (showFpsCounter + 1) % 2; break;
case 7: Settings::savesFolder = (Settings::savesFolder + 1) % 2; break;
case 8: Settings::statesFolder = (Settings::statesFolder + 1) % 2; break;
case 9: Settings::cheatsFolder = (Settings::cheatsFolder + 1) % 2; break;
case 10: ScreenLayout::screenPosition = (ScreenLayout::screenPosition + 1) % 5; break;
case 11: ScreenLayout::screenRotation = (ScreenLayout::screenRotation + 1) % 3; break;
case 12: ScreenLayout::screenArrangement = (ScreenLayout::screenArrangement + 1) % 4; break;
case 13: ScreenLayout::screenSizing = (ScreenLayout::screenSizing + 1) % 3; break;
case 14: ScreenLayout::screenGap = (ScreenLayout::screenGap + 1) % 4; break;
case 15: Settings::screenFilter = (Settings::screenFilter + 1) % 3; break;
case 16: ScreenLayout::integerScale = (ScreenLayout::integerScale + 1) % 2; break;
case 17: ScreenLayout::gbaCrop = (ScreenLayout::gbaCrop + 1) % 2; break;
case 18: Settings::screenGhost = (Settings::screenGhost + 1) % 2; break;

case 19:
// Update the palette when changing themes
menuTheme = (menuTheme + 1) % 2;
palette = &themeColors[menuTheme * 6];
Expand Down
4 changes: 2 additions & 2 deletions src/console/main_vita.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

#include "console_ui.h"

// Reserve 128MB of allocatable memory (can do more, but loading larger ROMs into RAM is slow)
int _newlib_heap_size_user = 128 * 1024 * 1024;
// Reserve 192MB of allocatable memory
int _newlib_heap_size_user = 192 * 1024 * 1024;

uint32_t audioBuffer[1024];
int audioPort;
Expand Down
36 changes: 23 additions & 13 deletions src/desktop/noo_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ enum FrameEvent
SCREEN_LAYOUT,
DIRECT_BOOT,
FPS_LIMITER,
MIC_ENABLE,
ROM_IN_RAM,
THREADED_2D,
THREADED_3D_0,
THREADED_3D_1,
THREADED_3D_2,
THREADED_3D_3,
THREADED_3D_4,
HIGH_RES_3D,
MIC_ENABLE,
UPDATE_JOY
};

Expand All @@ -76,14 +77,15 @@ EVT_MENU(INPUT_BINDINGS, NooFrame::inputSettings)
EVT_MENU(SCREEN_LAYOUT, NooFrame::layoutSettings)
EVT_MENU(DIRECT_BOOT, NooFrame::directBootToggle)
EVT_MENU(FPS_LIMITER, NooFrame::fpsLimiter)
EVT_MENU(MIC_ENABLE, NooFrame::micEnable)
EVT_MENU(ROM_IN_RAM, NooFrame::romInRam)
EVT_MENU(THREADED_2D, NooFrame::threaded2D)
EVT_MENU(THREADED_3D_0, NooFrame::threaded3D0)
EVT_MENU(THREADED_3D_1, NooFrame::threaded3D1)
EVT_MENU(THREADED_3D_2, NooFrame::threaded3D2)
EVT_MENU(THREADED_3D_3, NooFrame::threaded3D3)
EVT_MENU(THREADED_3D_4, NooFrame::threaded3D4)
EVT_MENU(HIGH_RES_3D, NooFrame::highRes3D)
EVT_MENU(MIC_ENABLE, NooFrame::micEnable)
EVT_TIMER(UPDATE_JOY, NooFrame::updateJoystick)
EVT_DROP_FILES(NooFrame::dropFiles)
EVT_CLOSE(NooFrame::close)
Expand Down Expand Up @@ -156,19 +158,20 @@ NooFrame::NooFrame(NooApp *app, int id, std::string path, NooFrame *partner):
settingsMenu->AppendSeparator();
settingsMenu->AppendCheckItem(DIRECT_BOOT, "&Direct Boot");
settingsMenu->AppendCheckItem(FPS_LIMITER, "&FPS Limiter");
settingsMenu->AppendCheckItem(MIC_ENABLE, "&Use Microphone");
settingsMenu->AppendCheckItem(ROM_IN_RAM, "&Keep ROM in RAM");
settingsMenu->AppendSeparator();
settingsMenu->AppendCheckItem(THREADED_2D, "&Threaded 2D");
settingsMenu->AppendSubMenu(threaded3D, "&Threaded 3D");
settingsMenu->AppendSeparator();
settingsMenu->AppendCheckItem(HIGH_RES_3D, "&High-Resolution 3D");
settingsMenu->AppendCheckItem(MIC_ENABLE, "&Use Microphone");

// Set the current values of the checkboxes
settingsMenu->Check(DIRECT_BOOT, Settings::directBoot);
settingsMenu->Check(FPS_LIMITER, Settings::fpsLimiter);
settingsMenu->Check(MIC_ENABLE, NooApp::micEnable);
settingsMenu->Check(ROM_IN_RAM, Settings::romInRam);
settingsMenu->Check(THREADED_2D, Settings::threaded2D);
settingsMenu->Check(HIGH_RES_3D, Settings::highRes3D);
settingsMenu->Check(MIC_ENABLE, NooApp::micEnable);

// Set up the menu bar
wxMenuBar *menuBar = new wxMenuBar();
Expand Down Expand Up @@ -711,6 +714,21 @@ void NooFrame::fpsLimiter(wxCommandEvent &event)
Settings::save();
}

void NooFrame::romInRam(wxCommandEvent &event)
{
// Toggle the ROM in RAM setting
Settings::romInRam = !Settings::romInRam;
Settings::save();
}

void NooFrame::micEnable(wxCommandEvent &event)
{
// Toggle the use microphone setting
NooApp::micEnable = !NooApp::micEnable;
NooApp::micEnable ? app->startStream(1) : app->stopStream(1);
Settings::save();
}

void NooFrame::threaded2D(wxCommandEvent &event)
{
// Toggle the threaded 2D setting
Expand Down Expand Up @@ -760,14 +778,6 @@ void NooFrame::highRes3D(wxCommandEvent &event)
Settings::save();
}

void NooFrame::micEnable(wxCommandEvent &event)
{
// Toggle the use microphone setting
NooApp::micEnable = !NooApp::micEnable;
NooApp::micEnable ? app->startStream(1) : app->stopStream(1);
Settings::save();
}

void NooFrame::updateJoystick(wxTimerEvent &event)
{
// Check the status of mapped joystick inputs and trigger key presses and releases accordingly
Expand Down
3 changes: 2 additions & 1 deletion src/desktop/noo_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@ class NooFrame: public wxFrame
void layoutSettings(wxCommandEvent &event);
void directBootToggle(wxCommandEvent &event);
void fpsLimiter(wxCommandEvent &event);
void micEnable(wxCommandEvent &event);
void romInRam(wxCommandEvent &event);
void threaded2D(wxCommandEvent &event);
void threaded3D0(wxCommandEvent &event);
void threaded3D1(wxCommandEvent &event);
void threaded3D2(wxCommandEvent &event);
void threaded3D3(wxCommandEvent &event);
void threaded3D4(wxCommandEvent &event);
void highRes3D(wxCommandEvent &event);
void micEnable(wxCommandEvent &event);
void updateJoystick(wxTimerEvent &event);
void dropFiles(wxDropFilesEvent &event);
void close(wxCloseEvent &event);
Expand Down
2 changes: 2 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

int Settings::directBoot = 1;
int Settings::fpsLimiter = 1;
int Settings::romInRam = 0;
int Settings::threaded2D = 1;
int Settings::threaded3D = 1;
int Settings::highRes3D = 0;
Expand All @@ -43,6 +44,7 @@ std::vector<Setting> Settings::settings =
{
Setting("directBoot", &directBoot, false),
Setting("fpsLimiter", &fpsLimiter, false),
Setting("romInRam", &romInRam, false),
Setting("threaded2D", &threaded2D, false),
Setting("threaded3D", &threaded3D, false),
Setting("highRes3D", &highRes3D, false),
Expand Down
1 change: 1 addition & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Settings
public:
static int directBoot;
static int fpsLimiter;
static int romInRam;
static int threaded2D;
static int threaded3D;
static int highRes3D;
Expand Down

0 comments on commit f08dcff

Please sign in to comment.