all repos — mgba @ b4fa4fe77e23ed774e749608144fc0d1330b941c

mGBA Game Boy Advance Emulator

DS: Better BIOS config
Vicki Pfau vi@endrift.com
Mon, 20 Feb 2017 14:27:15 -0800
commit

b4fa4fe77e23ed774e749608144fc0d1330b941c

parent

249f28fbe909a6aedc92064eba774b02b40eb06e

M include/mgba/internal/ds/ds.hinclude/mgba/internal/ds/ds.h

@@ -157,6 +157,8 @@ bool DSLoadROM(struct DS* ds, struct VFile* vf);

void DSUnloadROM(struct DS* ds); void DSApplyPatch(struct DS* ds, struct Patch* patch); +bool DSIsBIOS7(struct VFile* vf); +bool DSIsBIOS9(struct VFile* vf); bool DSLoadBIOS(struct DS* ds, struct VFile* vf); bool DSIsROM(struct VFile* vf);
M src/ds/core.csrc/ds/core.c

@@ -100,6 +100,10 @@

static void _DSCoreLoadConfig(struct mCore* core, const struct mCoreConfig* config) { struct DS* ds = core->board; struct VFile* bios = NULL; + + mCoreConfigCopyValue(&core->config, config, "ds.bios7"); + mCoreConfigCopyValue(&core->config, config, "ds.bios9"); + if (core->opts.useBios && core->opts.bios) { bios = VFileOpen(core->opts.bios, O_RDONLY); }

@@ -170,6 +174,9 @@ static void _DSCoreUnloadROM(struct mCore* core) {

return DSUnloadROM(core->board); } +static void _DSCoreChecksum(const struct mCore* core, void* data, enum mCoreChecksumType type) { +} + static void _DSCoreReset(struct mCore* core) { struct DSCore* dscore = (struct DSCore*) core; struct DS* ds = (struct DS*) core->board;

@@ -180,19 +187,46 @@ DSVideoAssociateRenderer(&ds->video, renderer);

} #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 - struct VFile* bios7 = 0; - struct VFile* bios9 = 0; + struct VFile* bios7 = NULL; + struct VFile* bios9 = NULL; if (core->opts.useBios) { - if (!core->opts.bios) { + bool found7 = false; + bool found9 = false; + + if (!found7) { + const char* configPath = mCoreConfigGetValue(&core->config, "ds.bios7"); + bios7 = VFileOpen(configPath, O_RDONLY); + if (bios7 && DSIsBIOS7(bios7)) { + found7 = true; + } else if (bios7) { + bios7->close(bios7); + bios7 = NULL; + } + } + + if (!found9) { + const char* configPath = mCoreConfigGetValue(&core->config, "ds.bios9"); + bios9 = VFileOpen(configPath, O_RDONLY); + if (bios9 && DSIsBIOS9(bios9)) { + found9 = true; + } else if (bios9) { + bios9->close(bios9); + bios9 = NULL; + } + } + + if (!found7) { char path[PATH_MAX]; mCoreConfigDirectory(path, PATH_MAX); strncat(path, PATH_SEP "ds7_bios.bin", PATH_MAX - strlen(path)); bios7 = VFileOpen(path, O_RDONLY); + } + + if (!found9) { + char path[PATH_MAX]; mCoreConfigDirectory(path, PATH_MAX); strncat(path, PATH_SEP "ds9_bios.bin", PATH_MAX - strlen(path)); bios9 = VFileOpen(path, O_RDONLY); - } else { - bios7 = VFileOpen(core->opts.bios, O_RDONLY); } } if (bios7) {

@@ -325,15 +359,21 @@ cpu->memory.store32(cpu, address, value, 0);

} static uint32_t _DSCoreRawRead8(struct mCore* core, uint32_t address, int segment) { - return 0; + // TODO: Raw + struct ARMCore* cpu = core->cpu; + return cpu->memory.load8(cpu, address, 0); } static uint32_t _DSCoreRawRead16(struct mCore* core, uint32_t address, int segment) { - return 0; + // TODO: Raw + struct ARMCore* cpu = core->cpu; + return cpu->memory.load16(cpu, address, 0); } static uint32_t _DSCoreRawRead32(struct mCore* core, uint32_t address, int segment) { - return 0; + // TODO: Raw + struct ARMCore* cpu = core->cpu; + return cpu->memory.load32(cpu, address, 0); } static void _DSCoreRawWrite8(struct mCore* core, uint32_t address, int segment, uint8_t value) {

@@ -423,6 +463,7 @@ core->loadBIOS = _DSCoreLoadBIOS;

core->loadSave = _DSCoreLoadSave; core->loadPatch = _DSCoreLoadPatch; core->unloadROM = _DSCoreUnloadROM; + core->checksum = _DSCoreChecksum; core->reset = _DSCoreReset; core->runFrame = _DSCoreRunFrame; core->runLoop = _DSCoreRunLoop;
M src/ds/ds.csrc/ds/ds.c

@@ -445,6 +445,38 @@ }

return memcmp(signature, DS_ROM_MAGIC, sizeof(signature)) == 0 || memcmp(signature, DS_ROM_MAGIC_2, sizeof(signature)) == 0; } +bool DSIsBIOS7(struct VFile* vf) { + size_t size = vf->size(vf); + void* data = NULL; + uint32_t crc; + if (size == DS7_SIZE_BIOS) { + data = vf->map(vf, size, MAP_READ); + } + if (!data) { + return false; + } + crc = doCrc32(data, size); + vf->unmap(vf, data, size); + return crc == DS7_BIOS_CHECKSUM; +} + +bool DSIsBIOS9(struct VFile* vf) { + size_t size = vf->size(vf); + void* data = NULL; + uint32_t crc; + if (size == DS9_SIZE_BIOS) { + data = vf->map(vf, 0x1000, MAP_READ); + } else if (size == 0x1000) { + data = vf->map(vf, 0x1000, MAP_READ); + } + if (!data) { + return false; + } + crc = doCrc32(data, 0x1000); + vf->unmap(vf, data, 0x1000); + return crc == DS9_BIOS_CHECKSUM; +} + bool DSLoadBIOS(struct DS* ds, struct VFile* vf) { size_t size = vf->size(vf); void* data = NULL;
M src/platform/qt/SettingsView.cppsrc/platform/qt/SettingsView.cpp

@@ -130,6 +130,12 @@

connect(m_ui.gbaBiosBrowse, &QPushButton::clicked, [this]() { selectBios(m_ui.gbaBios); }); + connect(m_ui.dsBios7Browse, &QPushButton::clicked, [this]() { + selectBios(m_ui.dsBios7); + }); + connect(m_ui.dsBios9Browse, &QPushButton::clicked, [this]() { + selectBios(m_ui.dsBios9); + }); connect(m_ui.gbBiosBrowse, &QPushButton::clicked, [this]() { selectBios(m_ui.gbBios); });

@@ -181,6 +187,8 @@ void SettingsView::updateConfig() {

saveSetting("gba.bios", m_ui.gbaBios); saveSetting("gb.bios", m_ui.gbBios); saveSetting("gbc.bios", m_ui.gbcBios); + saveSetting("ds.bios7", m_ui.dsBios7); + saveSetting("ds.bios9", m_ui.dsBios9); saveSetting("useBios", m_ui.useBios); saveSetting("skipBios", m_ui.skipBios); saveSetting("audioBuffers", m_ui.audioBufferSize);

@@ -259,6 +267,8 @@ loadSetting("bios", m_ui.gbaBios);

loadSetting("gba.bios", m_ui.gbaBios); loadSetting("gb.bios", m_ui.gbBios); loadSetting("gbc.bios", m_ui.gbcBios); + loadSetting("ds.bios7", m_ui.dsBios7); + loadSetting("ds.bios9", m_ui.dsBios9); loadSetting("useBios", m_ui.useBios); loadSetting("skipBios", m_ui.skipBios); loadSetting("audioBuffers", m_ui.audioBufferSize);
M src/platform/qt/SettingsView.uisrc/platform/qt/SettingsView.ui

@@ -77,7 +77,7 @@ </item>

<item row="1" column="1"> <widget class="QStackedWidget" name="stackedWidget"> <property name="currentIndex"> - <number>1</number> + <number>0</number> </property> <widget class="QWidget" name="av"> <layout class="QFormLayout" name="formLayout">

@@ -654,6 +654,9 @@ </layout>

</widget> <widget class="QWidget" name="bios"> <layout class="QFormLayout" name="formLayout_5"> + <property name="fieldGrowthPolicy"> + <enum>QFormLayout::FieldsStayAtSizeHint</enum> + </property> <item row="0" column="0"> <widget class="QLabel" name="label"> <property name="text">

@@ -682,20 +685,38 @@ </widget>

</item> </layout> </item> - <item row="3" column="1"> - <widget class="QCheckBox" name="useBios"> + <item row="1" column="0"> + <widget class="QLabel" name="label_5"> <property name="text"> - <string>Use BIOS file if found</string> - </property> - <property name="checked"> - <bool>true</bool> + <string>GBC BIOS file:</string> </property> </widget> </item> - <item row="4" column="1"> - <widget class="QCheckBox" name="skipBios"> + <item row="1" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_30"> + <item> + <widget class="QLineEdit" name="gbcBios"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="gbcBiosBrowse"> + <property name="text"> + <string>Browse</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_4"> <property name="text"> - <string>Skip BIOS intro</string> + <string>GBA BIOS file:</string> </property> </widget> </item>

@@ -720,24 +741,55 @@ </widget>

</item> </layout> </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_4"> + <item row="3" column="0"> + <widget class="QLabel" name="label_26"> + <property name="text"> + <string>DS BIOS 7 file:</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_9"> + <item> + <widget class="QLineEdit" name="dsBios7"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="dsBios7Browse"> + <property name="text"> + <string>Browse</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="5" column="1"> + <widget class="QCheckBox" name="useBios"> <property name="text"> - <string>GBA BIOS file:</string> + <string>Use BIOS file if found</string> + </property> + <property name="checked"> + <bool>true</bool> </property> </widget> </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_5"> + <item row="6" column="1"> + <widget class="QCheckBox" name="skipBios"> <property name="text"> - <string>GBC BIOS file:</string> + <string>Skip BIOS intro</string> </property> </widget> </item> - <item row="1" column="1"> - <layout class="QHBoxLayout" name="horizontalLayout_30"> + <item row="4" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_15"> <item> - <widget class="QLineEdit" name="gbcBios"> + <widget class="QLineEdit" name="dsBios9"> <property name="sizePolicy"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <horstretch>0</horstretch>

@@ -747,13 +799,20 @@ </property>

</widget> </item> <item> - <widget class="QPushButton" name="gbcBiosBrowse"> + <widget class="QPushButton" name="dsBios9Browse"> <property name="text"> <string>Browse</string> </property> </widget> </item> </layout> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="label_27"> + <property name="text"> + <string>DS BIOS 9 file:</string> + </property> + </widget> </item> </layout> </widget>