GB: Presets for Game Boy palettes

This commit is contained in:
Vicki Pfau 2021-05-01 19:07:06 -07:00
parent fe195923a4
commit a713d51e05
8 changed files with 122 additions and 30 deletions

View File

@ -1,5 +1,6 @@
0.10.0: (Future) 0.10.0: (Future)
Features: Features:
- Presets for Game Boy palettes
- Tool for converting scanned pictures of e-Reader cards to raw dotcode data - Tool for converting scanned pictures of e-Reader cards to raw dotcode data
- Cheat code support in homebrew ports - Cheat code support in homebrew ports
Emulation fixes: Emulation fixes:

View File

@ -20,11 +20,18 @@ struct GBCartridgeOverride {
uint32_t gbColors[12]; uint32_t gbColors[12];
}; };
struct GBColorPreset {
const char* name;
uint32_t colors[12];
};
struct Configuration; struct Configuration;
bool GBOverrideFind(const struct Configuration*, struct GBCartridgeOverride* override); bool GBOverrideFind(const struct Configuration*, struct GBCartridgeOverride* override);
bool GBOverrideColorFind(struct GBCartridgeOverride* override); bool GBOverrideColorFind(struct GBCartridgeOverride* override);
void GBOverrideSave(struct Configuration*, const struct GBCartridgeOverride* override); void GBOverrideSave(struct Configuration*, const struct GBCartridgeOverride* override);
size_t GBColorPresetList(const struct GBColorPreset** presets);
struct GB; struct GB;
void GBOverrideApply(struct GB*, const struct GBCartridgeOverride*); void GBOverrideApply(struct GB*, const struct GBCartridgeOverride*);
void GBOverrideApplyDefaults(struct GB*); void GBOverrideApplyDefaults(struct GB*);

View File

@ -500,6 +500,37 @@ static const struct GBCartridgeOverride _overrides[] = {
{ 0, 0, 0, { 0 } } { 0, 0, 0, { 0 } }
}; };
static const struct GBColorPreset _colorPresets[] = {
{
"Grayscale",
{
PAL_ENTRY(0x7FFF, 0x56B5, 0x294A, 0x0000),
PAL_ENTRY(0x7FFF, 0x56B5, 0x294A, 0x0000),
PAL_ENTRY(0x7FFF, 0x56B5, 0x294A, 0x0000)
}
},
{
"DMG Green",
{
PAL_ENTRY(0x2691, 0x19A9, 0x1105, 0x04A3),
PAL_ENTRY(0x2691, 0x19A9, 0x1105, 0x04A3),
PAL_ENTRY(0x2691, 0x19A9, 0x1105, 0x04A3)
}
},
{ "GBC Right", PALETTE(18, 18, 18), },
{ "GBC Left", PALETTE(4, 3, 28), },
{ "GBC Up", PALETTE(0, 0, 0), },
{ "GBC Down", PALETTE(12, 12, 12), },
{ "GBC Right + A", PALETTE(4, 4, 29), },
{ "GBC Left + A", PALETTE(4, 0, 2), },
{ "GBC Up + A", PALETTE(3, 28, 4), },
{ "GBC Down + A", PALETTE(24, 24, 24), },
{ "GBC Right + B", PALETTE(27, 27, 27), },
{ "GBC Left + B", PALETTE(5, 5, 5), },
{ "GBC Up + B", PALETTE(0, 0, 1), },
{ "GBC Down + B", PALETTE(28, 3, 6), },
};
bool GBOverrideColorFind(struct GBCartridgeOverride* override) { bool GBOverrideColorFind(struct GBCartridgeOverride* override) {
int i; int i;
for (i = 0; _colorOverrides[i].headerCrc32; ++i) { for (i = 0; _colorOverrides[i].headerCrc32; ++i) {
@ -635,6 +666,11 @@ void GBOverrideSave(struct Configuration* config, const struct GBCartridgeOverri
} }
} }
size_t GBColorPresetList(const struct GBColorPreset** presets) {
*presets = _colorPresets;
return sizeof(_colorPresets) / sizeof(*_colorPresets);
}
void GBOverrideApply(struct GB* gb, const struct GBCartridgeOverride* override) { void GBOverrideApply(struct GB* gb, const struct GBCartridgeOverride* override) {
if (override->model != GB_MODEL_AUTODETECT) { if (override->model != GB_MODEL_AUTODETECT) {
gb->model = override->model; gb->model = override->model;

View File

@ -30,20 +30,9 @@ protected slots:
void updateTiles(bool force); void updateTiles(bool force);
protected: protected:
#ifdef M_CORE_GBA
virtual void updateTilesGBA(bool force) = 0;
#endif
#ifdef M_CORE_GB
virtual void updateTilesGB(bool force) = 0;
#endif
void resizeEvent(QResizeEvent*) override;
void showEvent(QShowEvent*) override;
mCacheSet* const m_cacheSet; mCacheSet* const m_cacheSet;
std::shared_ptr<CoreController> m_controller; std::shared_ptr<CoreController> m_controller;
protected:
struct ObjInfo { struct ObjInfo {
unsigned tile; unsigned tile;
unsigned width; unsigned width;
@ -70,6 +59,16 @@ protected:
bool lookupObj(int id, struct ObjInfo*); bool lookupObj(int id, struct ObjInfo*);
#ifdef M_CORE_GBA
virtual void updateTilesGBA(bool force) = 0;
#endif
#ifdef M_CORE_GB
virtual void updateTilesGB(bool force) = 0;
#endif
void resizeEvent(QResizeEvent*) override;
void showEvent(QShowEvent*) override;
private: private:
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
bool lookupObjGBA(int id, struct ObjInfo*); bool lookupObjGBA(int id, struct ObjInfo*);

View File

@ -83,6 +83,20 @@ OverrideView::OverrideView(ConfigController* config, QWidget* parent)
m_gbColors[colorId] = color.rgb() | 0xFF000000; m_gbColors[colorId] = color.rgb() | 0xFF000000;
}); });
} }
const GBColorPreset* colorPresets;
size_t nPresets = GBColorPresetList(&colorPresets);
for (size_t i = 0; i < nPresets; ++i) {
m_ui.colorPreset->addItem(QString(colorPresets[i].name));
}
connect(m_ui.colorPreset, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this, colorPresets](int n) {
const GBColorPreset* preset = &colorPresets[n];
for (int colorId = 0; colorId < 12; ++colorId) {
uint32_t color = preset->colors[colorId] | 0xFF000000;
m_colorPickers[colorId].setColor(color);
m_gbColors[colorId] = color;
}
});
#endif #endif
#ifndef M_CORE_GBA #ifndef M_CORE_GBA

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>444</width> <width>444</width>
<height>284</height> <height>288</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -249,14 +249,14 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="3" column="0">
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="text"> <property name="text">
<string>Background Colors</string> <string>Background Colors</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QFrame" name="color0"> <widget class="QFrame" name="color0">
@ -336,21 +336,21 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="3" column="0"> <item row="4" column="0">
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="label_6">
<property name="text"> <property name="text">
<string>Sprite Colors 1</string> <string>Sprite Colors 1</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="5" column="0">
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="label_7">
<property name="text"> <property name="text">
<string>Sprite Colors 2</string> <string>Sprite Colors 2</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<widget class="QFrame" name="color4"> <widget class="QFrame" name="color4">
@ -430,7 +430,7 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="4" column="1"> <item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<item> <item>
<widget class="QFrame" name="color8"> <widget class="QFrame" name="color8">
@ -510,6 +510,16 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="2" column="1">
<widget class="QComboBox" name="colorPreset"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Palette preset</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>

View File

@ -17,6 +17,7 @@
#ifdef M_CORE_GB #ifdef M_CORE_GB
#include "GameBoy.h" #include "GameBoy.h"
#include <mgba/internal/gb/overrides.h>
#endif #endif
#include <mgba/core/serialize.h> #include <mgba/core/serialize.h>
@ -258,6 +259,20 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC
m_gbColors[colorId] = color.rgb(); m_gbColors[colorId] = color.rgb();
}); });
} }
const GBColorPreset* colorPresets;
size_t nPresets = GBColorPresetList(&colorPresets);
for (size_t i = 0; i < nPresets; ++i) {
m_ui.colorPreset->addItem(QString(colorPresets[i].name));
}
connect(m_ui.colorPreset, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this, colorPresets](int n) {
const GBColorPreset* preset = &colorPresets[n];
for (int colorId = 0; colorId < 12; ++colorId) {
uint32_t color = preset->colors[colorId] | 0xFF000000;
m_colorPickers[colorId].setColor(color);
m_gbColors[colorId] = color;
}
});
#else #else
m_ui.gbBiosBrowse->hide(); m_ui.gbBiosBrowse->hide();
m_ui.gbcBiosBrowse->hide(); m_ui.gbcBiosBrowse->hide();

View File

@ -1554,13 +1554,23 @@
</widget> </widget>
</item> </item>
<item row="6" column="0"> <item row="6" column="0">
<widget class="QLabel" name="label_40">
<property name="text">
<string>Preset:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QComboBox" name="colorPreset"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_28"> <widget class="QLabel" name="label_28">
<property name="text"> <property name="text">
<string>Default BG colors:</string> <string>Default BG colors:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="1"> <item row="7" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_9"> <layout class="QHBoxLayout" name="horizontalLayout_9">
<item> <item>
<widget class="QFrame" name="color0"> <widget class="QFrame" name="color0">
@ -1640,14 +1650,14 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="7" column="0"> <item row="8" column="0">
<widget class="QLabel" name="label_69"> <widget class="QLabel" name="label_69">
<property name="text"> <property name="text">
<string>Default sprite colors 1:</string> <string>Default sprite colors 1:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="8" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_15"> <layout class="QHBoxLayout" name="horizontalLayout_15">
<item> <item>
<widget class="QFrame" name="color4"> <widget class="QFrame" name="color4">
@ -1727,14 +1737,14 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="8" column="0"> <item row="9" column="0">
<widget class="QLabel" name="label_70"> <widget class="QLabel" name="label_70">
<property name="text"> <property name="text">
<string>Default sprite colors 2:</string> <string>Default sprite colors 2:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="1"> <item row="9" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_37"> <layout class="QHBoxLayout" name="horizontalLayout_37">
<item> <item>
<widget class="QFrame" name="color8"> <widget class="QFrame" name="color8">
@ -1814,35 +1824,35 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="9" column="1"> <item row="10" column="1">
<widget class="QCheckBox" name="useCgbColors"> <widget class="QCheckBox" name="useCgbColors">
<property name="text"> <property name="text">
<string>Use GBC colors in GB games</string> <string>Use GBC colors in GB games</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="10" column="1"> <item row="11" column="1">
<widget class="QCheckBox" name="sgbBorders"> <widget class="QCheckBox" name="sgbBorders">
<property name="text"> <property name="text">
<string>Super Game Boy borders</string> <string>Super Game Boy borders</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="11" column="0" colspan="2"> <item row="12" column="0" colspan="2">
<widget class="Line" name="line_11"> <widget class="Line" name="line_11">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item row="12" column="0"> <item row="13" column="0">
<widget class="QLabel" name="label_27"> <widget class="QLabel" name="label_27">
<property name="text"> <property name="text">
<string>Camera driver:</string> <string>Camera driver:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="12" column="1"> <item row="13" column="1">
<widget class="QComboBox" name="cameraDriver"> <widget class="QComboBox" name="cameraDriver">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -1852,14 +1862,14 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="13" column="0"> <item row="14" column="0">
<widget class="QLabel" name="label_35"> <widget class="QLabel" name="label_35">
<property name="text"> <property name="text">
<string>Camera:</string> <string>Camera:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="13" column="1"> <item row="14" column="1">
<widget class="QComboBox" name="camera"> <widget class="QComboBox" name="camera">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>