Fallback to FreeBIOS when BIOS files are not found. (v2) (#1174)

* Fallback to FreeBIOS when BIOS files are not found.

* Add sources of drastic bios files.

* Move FreeBIOS/external BIOS choice to configuration option/checkbox.

* Fix indentation

Co-authored-by: Filippo Scognamiglio <flscogna@gmail.com>
Co-authored-by: Filippo Scognamiglio <filippo.scognamiglio@felgo.com>
This commit is contained in:
Adrian Siekierka 2021-10-02 12:06:22 +02:00 committed by GitHub
parent 243077722b
commit b7992cc084
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 3065 additions and 93 deletions

17
freebios/Makefile Executable file
View File

@ -0,0 +1,17 @@
TC_PREFIX = /home/exophase/pandora-dev
PREFIX = $(TC_PREFIX)/arm-2011.03
AS = $(PREFIX)/bin/arm-none-linux-gnueabi-gcc
OBJCOPY = $(PREFIX)/bin/arm-none-linux-gnueabi-objcopy
BIN_ARM7 = drastic_bios_arm7
BIN_ARM9 = drastic_bios_arm9
all:
$(AS) bios_common.S -DBIOS_ARM7 -march=armv4 -c -Wa,-asl=$(BIN_ARM7).list -o $(BIN_ARM7).o
$(AS) bios_common.S -DBIOS_ARM9 -march=armv5 -c -Wa,-asl=$(BIN_ARM9).list -o $(BIN_ARM9).o
$(OBJCOPY) -O binary $(BIN_ARM7).o $(BIN_ARM7).bin
$(OBJCOPY) -O binary $(BIN_ARM9).o $(BIN_ARM9).bin
clean:
rm -f $(BIN_ARM7).bin $(BIN_ARM7).o $(BIN_ARM9).bin $(BIN_ARM9).o

1135
freebios/bios_common.S Executable file

File diff suppressed because it is too large Load Diff

BIN
freebios/drastic_bios_arm7.bin Executable file

Binary file not shown.

BIN
freebios/drastic_bios_arm9.bin Executable file

Binary file not shown.

View File

@ -0,0 +1,36 @@
Custom NDS ARM7/ARM9 BIOS replacement
Copyright (c) 2013, Gilead Kutnick
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2) Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-- Info --
This archive contains source code and assembly for a custom BIOS replacement
for the Nintendo DS system. This code is in no way affiliated with Nintendo
and is not derived from Nintendo's BIOS implementation but has been implemented
using publically available documentation.
It can be assembled using the included Makefile along with a proper ARM gcc
toolchain. Change the first four lines to point to the proper toolchain of your
choice.

View File

@ -39,6 +39,7 @@ add_library(core STATIC
NDSCart_SRAMManager.cpp NDSCart_SRAMManager.cpp
Platform.h Platform.h
ROMList.h ROMList.h
FreeBIOS.h
RTC.cpp RTC.cpp
Savestate.cpp Savestate.cpp
SPI.cpp SPI.cpp

View File

@ -28,6 +28,7 @@ namespace Config
const char* kConfigFile = "melonDS.ini"; const char* kConfigFile = "melonDS.ini";
int ExternalBIOSEnable;
char BIOS9Path[1024]; char BIOS9Path[1024];
char BIOS7Path[1024]; char BIOS7Path[1024];
char FirmwarePath[1024]; char FirmwarePath[1024];
@ -54,9 +55,11 @@ int JIT_FastMemory = true;
ConfigEntry ConfigFile[] = ConfigEntry ConfigFile[] =
{ {
{"ExternalBIOSEnable", 0, &ExternalBIOSEnable, 0, NULL, 0},
{"BIOS9Path", 1, BIOS9Path, 0, "", 1023}, {"BIOS9Path", 1, BIOS9Path, 0, "", 1023},
{"BIOS7Path", 1, BIOS7Path, 0, "", 1023}, {"BIOS7Path", 1, BIOS7Path, 0, "", 1023},
{"FirmwarePath", 1, FirmwarePath, 0, "", 1023}, {"FirmwarePath", 1, FirmwarePath, 0, "", 1023},
{"DLDIEnable", 0, &DLDIEnable, 0, NULL, 0}, {"DLDIEnable", 0, &DLDIEnable, 0, NULL, 0},
{"DLDISDPath", 1, DLDISDPath, 0, "", 1023}, {"DLDISDPath", 1, DLDISDPath, 0, "", 1023},

View File

@ -41,6 +41,7 @@ bool HasConfigFile(const char* fileName);
void Load(); void Load();
void Save(); void Save();
extern int ExternalBIOSEnable;
extern char BIOS9Path[1024]; extern char BIOS9Path[1024];
extern char BIOS7Path[1024]; extern char BIOS7Path[1024];
extern char FirmwarePath[1024]; extern char FirmwarePath[1024];

1747
src/FreeBIOS.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -34,6 +34,7 @@
#include "AREngine.h" #include "AREngine.h"
#include "Platform.h" #include "Platform.h"
#include "NDSCart_SRAMManager.h" #include "NDSCart_SRAMManager.h"
#include "FreeBIOS.h"
#ifdef JIT_ENABLED #ifdef JIT_ENABLED
#include "ARMJIT.h" #include "ARMJIT.h"
@ -464,6 +465,8 @@ void Reset()
// DS BIOSes are always loaded, even in DSi mode // DS BIOSes are always loaded, even in DSi mode
// we need them for DS-compatible mode // we need them for DS-compatible mode
if (Config::ExternalBIOSEnable)
{
f = Platform::OpenLocalFile(Config::BIOS9Path, "rb"); f = Platform::OpenLocalFile(Config::BIOS9Path, "rb");
if (!f) if (!f)
{ {
@ -497,6 +500,12 @@ void Reset()
printf("ARM7 BIOS loaded\n"); printf("ARM7 BIOS loaded\n");
fclose(f); fclose(f);
} }
}
else
{
memcpy(ARM9BIOS, bios_arm9_bin, bios_arm9_bin_len);
memcpy(ARM7BIOS, bios_arm7_bin, bios_arm7_bin_len);
}
#ifdef JIT_ENABLED #ifdef JIT_ENABLED
ARMJIT::Reset(); ARMJIT::Reset();

View File

@ -92,6 +92,8 @@ int VerifyDSBIOS()
FILE* f; FILE* f;
long len; long len;
if (!Config::ExternalBIOSEnable) return Load_OK;
f = Platform::OpenLocalFile(Config::BIOS9Path, "rb"); f = Platform::OpenLocalFile(Config::BIOS9Path, "rb");
if (!f) return Load_BIOS9Missing; if (!f) return Load_BIOS9Missing;

View File

@ -41,9 +41,11 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new
ui->setupUi(this); ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
ui->chkExternalBIOS->setChecked(Config::ExternalBIOSEnable != 0);
ui->txtBIOS9Path->setText(Config::BIOS9Path); ui->txtBIOS9Path->setText(Config::BIOS9Path);
ui->txtBIOS7Path->setText(Config::BIOS7Path); ui->txtBIOS7Path->setText(Config::BIOS7Path);
ui->txtFirmwarePath->setText(Config::FirmwarePath); ui->txtFirmwarePath->setText(Config::FirmwarePath);
ui->cbDLDIEnable->setChecked(Config::DLDIEnable != 0); ui->cbDLDIEnable->setChecked(Config::DLDIEnable != 0);
ui->txtDLDISDPath->setText(Config::DLDISDPath); ui->txtDLDISDPath->setText(Config::DLDISDPath);
@ -78,6 +80,7 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new
#endif #endif
on_chkEnableJIT_toggled(); on_chkEnableJIT_toggled();
on_chkExternalBIOS_toggled();
} }
EmuSettingsDialog::~EmuSettingsDialog() EmuSettingsDialog::~EmuSettingsDialog()
@ -145,6 +148,7 @@ void EmuSettingsDialog::done(int r)
int jitLiteralOptimisations = ui->chkJITLiteralOptimisations->isChecked() ? 1:0; int jitLiteralOptimisations = ui->chkJITLiteralOptimisations->isChecked() ? 1:0;
int jitFastMemory = ui->chkJITFastMemory->isChecked() ? 1:0; int jitFastMemory = ui->chkJITFastMemory->isChecked() ? 1:0;
int externalBiosEnable = ui->chkExternalBIOS->isChecked() ? 1:0;
std::string bios9Path = ui->txtBIOS9Path->text().toStdString(); std::string bios9Path = ui->txtBIOS9Path->text().toStdString();
std::string bios7Path = ui->txtBIOS7Path->text().toStdString(); std::string bios7Path = ui->txtBIOS7Path->text().toStdString();
std::string firmwarePath = ui->txtFirmwarePath->text().toStdString(); std::string firmwarePath = ui->txtFirmwarePath->text().toStdString();
@ -166,6 +170,7 @@ void EmuSettingsDialog::done(int r)
|| jitLiteralOptimisations != Config::JIT_LiteralOptimisations || jitLiteralOptimisations != Config::JIT_LiteralOptimisations
|| jitFastMemory != Config::JIT_FastMemory || jitFastMemory != Config::JIT_FastMemory
#endif #endif
|| externalBiosEnable != Config::ExternalBIOSEnable
|| strcmp(Config::BIOS9Path, bios9Path.c_str()) != 0 || strcmp(Config::BIOS9Path, bios9Path.c_str()) != 0
|| strcmp(Config::BIOS7Path, bios7Path.c_str()) != 0 || strcmp(Config::BIOS7Path, bios7Path.c_str()) != 0
|| strcmp(Config::FirmwarePath, firmwarePath.c_str()) != 0 || strcmp(Config::FirmwarePath, firmwarePath.c_str()) != 0
@ -184,6 +189,7 @@ void EmuSettingsDialog::done(int r)
QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok) QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok)
return; return;
Config::ExternalBIOSEnable = externalBiosEnable;
strncpy(Config::BIOS9Path, bios9Path.c_str(), 1023); Config::BIOS9Path[1023] = '\0'; strncpy(Config::BIOS9Path, bios9Path.c_str(), 1023); Config::BIOS9Path[1023] = '\0';
strncpy(Config::BIOS7Path, bios7Path.c_str(), 1023); Config::BIOS7Path[1023] = '\0'; strncpy(Config::BIOS7Path, bios7Path.c_str(), 1023); Config::BIOS7Path[1023] = '\0';
strncpy(Config::FirmwarePath, firmwarePath.c_str(), 1023); Config::FirmwarePath[1023] = '\0'; strncpy(Config::FirmwarePath, firmwarePath.c_str(), 1023); Config::FirmwarePath[1023] = '\0';
@ -337,3 +343,10 @@ void EmuSettingsDialog::on_chkEnableJIT_toggled()
#endif #endif
ui->spnJITMaximumBlockSize->setDisabled(disabled); ui->spnJITMaximumBlockSize->setDisabled(disabled);
} }
void EmuSettingsDialog::on_chkExternalBIOS_toggled()
{
bool disabled = !ui->chkExternalBIOS->isChecked();
ui->txtBIOS7Path->setDisabled(disabled);
ui->txtBIOS9Path->setDisabled(disabled);
}

View File

@ -67,6 +67,7 @@ private slots:
void on_btnDSiSDBrowse_clicked(); void on_btnDSiSDBrowse_clicked();
void on_chkEnableJIT_toggled(); void on_chkEnableJIT_toggled();
void on_chkExternalBIOS_toggled();
private: private:
void verifyFirmware(); void verifyFirmware();

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>575</width> <width>575</width>
<height>254</height> <height>260</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -26,7 +26,7 @@
<item> <item>
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
@ -89,72 +89,41 @@
<string>DS-mode</string> <string>DS-mode</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="1" column="1"> <item row="3" column="2">
<widget class="QPathInput" name="txtBIOS7Path">
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;DS-mode ARM7 BIOS&lt;/p&gt;&lt;p&gt;Size should be 16 KB&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPathInput" name="txtFirmwarePath">
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;DS-mode firmware&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Possible firmwares:&lt;/p&gt;&lt;p&gt;* 128 KB: DS-mode firmware from a DSi or 3DS. Not bootable.&lt;/p&gt;&lt;p&gt;* 256 KB: regular DS firmware.&lt;/p&gt;&lt;p&gt;* 512 KB: iQue DS firmware.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>DS firmware:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>DS ARM7 BIOS:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="btnBIOS7Browse">
<property name="text">
<string>Browse...</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="btnFirmwareBrowse"> <widget class="QPushButton" name="btnFirmwareBrowse">
<property name="text"> <property name="text">
<string>Browse...</string> <string>Browse...</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="4" column="0">
<widget class="QPushButton" name="btnBIOS9Browse"> <spacer name="verticalSpacer_5">
<property name="sizePolicy"> <property name="orientation">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <enum>Qt::Vertical</enum>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>DS firmware:</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="btnBIOS7Browse">
<property name="text"> <property name="text">
<string>Browse...</string> <string>Browse...</string>
</property> </property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="1" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>DS ARM9 BIOS:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPathInput" name="txtBIOS9Path"> <widget class="QPathInput" name="txtBIOS9Path">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -176,18 +145,56 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="2" column="0">
<spacer name="verticalSpacer_5"> <widget class="QLabel" name="label_2">
<property name="orientation"> <property name="text">
<enum>Qt::Vertical</enum> <string>DS ARM7 BIOS:</string>
</property> </property>
<property name="sizeHint" stdset="0"> </widget>
<size> </item>
<width>20</width> <item row="2" column="1">
<height>40</height> <widget class="QPathInput" name="txtBIOS7Path">
</size> <property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;DS-mode ARM7 BIOS&lt;/p&gt;&lt;p&gt;Size should be 16 KB&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
</spacer> </widget>
</item>
<item row="3" column="1">
<widget class="QPathInput" name="txtFirmwarePath">
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;DS-mode firmware&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Possible firmwares:&lt;/p&gt;&lt;p&gt;* 128 KB: DS-mode firmware from a DSi or 3DS. Not bootable.&lt;/p&gt;&lt;p&gt;* 256 KB: regular DS firmware.&lt;/p&gt;&lt;p&gt;* 512 KB: iQue DS firmware.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>DS ARM9 BIOS:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="btnBIOS9Browse">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Browse...</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QCheckBox" name="chkExternalBIOS">
<property name="text">
<string>Use external BIOS files</string>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>