From a713d51e05e183e13acb7f537f1965ed977cf23a Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 1 May 2021 19:07:06 -0700 Subject: [PATCH] GB: Presets for Game Boy palettes --- CHANGES | 1 + include/mgba/internal/gb/overrides.h | 7 ++++++ src/gb/overrides.c | 36 ++++++++++++++++++++++++++++ src/platform/qt/AssetView.h | 21 ++++++++-------- src/platform/qt/OverrideView.cpp | 14 +++++++++++ src/platform/qt/OverrideView.ui | 24 +++++++++++++------ src/platform/qt/SettingsView.cpp | 15 ++++++++++++ src/platform/qt/SettingsView.ui | 34 ++++++++++++++++---------- 8 files changed, 122 insertions(+), 30 deletions(-) diff --git a/CHANGES b/CHANGES index bca7a805c..65ced1366 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,6 @@ 0.10.0: (Future) Features: + - Presets for Game Boy palettes - Tool for converting scanned pictures of e-Reader cards to raw dotcode data - Cheat code support in homebrew ports Emulation fixes: diff --git a/include/mgba/internal/gb/overrides.h b/include/mgba/internal/gb/overrides.h index 5e0b2bbc6..e24225a88 100644 --- a/include/mgba/internal/gb/overrides.h +++ b/include/mgba/internal/gb/overrides.h @@ -20,11 +20,18 @@ struct GBCartridgeOverride { uint32_t gbColors[12]; }; +struct GBColorPreset { + const char* name; + uint32_t colors[12]; +}; + struct Configuration; bool GBOverrideFind(const struct Configuration*, struct GBCartridgeOverride* override); bool GBOverrideColorFind(struct GBCartridgeOverride* override); void GBOverrideSave(struct Configuration*, const struct GBCartridgeOverride* override); +size_t GBColorPresetList(const struct GBColorPreset** presets); + struct GB; void GBOverrideApply(struct GB*, const struct GBCartridgeOverride*); void GBOverrideApplyDefaults(struct GB*); diff --git a/src/gb/overrides.c b/src/gb/overrides.c index 66673fe81..ada9402fb 100644 --- a/src/gb/overrides.c +++ b/src/gb/overrides.c @@ -500,6 +500,37 @@ static const struct GBCartridgeOverride _overrides[] = { { 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) { int 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) { if (override->model != GB_MODEL_AUTODETECT) { gb->model = override->model; diff --git a/src/platform/qt/AssetView.h b/src/platform/qt/AssetView.h index c3d3a92b2..96039866f 100644 --- a/src/platform/qt/AssetView.h +++ b/src/platform/qt/AssetView.h @@ -30,20 +30,9 @@ protected slots: void updateTiles(bool force); 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; std::shared_ptr m_controller; -protected: struct ObjInfo { unsigned tile; unsigned width; @@ -70,6 +59,16 @@ protected: 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: #ifdef M_CORE_GBA bool lookupObjGBA(int id, struct ObjInfo*); diff --git a/src/platform/qt/OverrideView.cpp b/src/platform/qt/OverrideView.cpp index c24576912..07e114c1c 100644 --- a/src/platform/qt/OverrideView.cpp +++ b/src/platform/qt/OverrideView.cpp @@ -83,6 +83,20 @@ OverrideView::OverrideView(ConfigController* config, QWidget* parent) 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(&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 #ifndef M_CORE_GBA diff --git a/src/platform/qt/OverrideView.ui b/src/platform/qt/OverrideView.ui index a1eb8a1d0..97061d6db 100644 --- a/src/platform/qt/OverrideView.ui +++ b/src/platform/qt/OverrideView.ui @@ -7,7 +7,7 @@ 0 0 444 - 284 + 288 @@ -249,14 +249,14 @@ - + Background Colors - + @@ -336,21 +336,21 @@ - + Sprite Colors 1 - + Sprite Colors 2 - + @@ -430,7 +430,7 @@ - + @@ -510,6 +510,16 @@ + + + + + + + Palette preset + + + diff --git a/src/platform/qt/SettingsView.cpp b/src/platform/qt/SettingsView.cpp index 579f11a30..668ebe920 100644 --- a/src/platform/qt/SettingsView.cpp +++ b/src/platform/qt/SettingsView.cpp @@ -17,6 +17,7 @@ #ifdef M_CORE_GB #include "GameBoy.h" +#include #endif #include @@ -258,6 +259,20 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC 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(&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 m_ui.gbBiosBrowse->hide(); m_ui.gbcBiosBrowse->hide(); diff --git a/src/platform/qt/SettingsView.ui b/src/platform/qt/SettingsView.ui index 20a7f13c0..b010649e5 100644 --- a/src/platform/qt/SettingsView.ui +++ b/src/platform/qt/SettingsView.ui @@ -1554,13 +1554,23 @@ + + + Preset: + + + + + + + Default BG colors: - + @@ -1640,14 +1650,14 @@ - + Default sprite colors 1: - + @@ -1727,14 +1737,14 @@ - + Default sprite colors 2: - + @@ -1814,35 +1824,35 @@ - + Use GBC colors in GB games - + Super Game Boy borders - + Qt::Horizontal - + Camera driver: - + @@ -1852,14 +1862,14 @@ - + Camera: - + false