From 5a069cd44bbef2a890dbea77154d5724ecd1006d Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Mon, 11 May 2020 14:57:01 -0230 Subject: [PATCH] Fixes for warnings in latest g++ and clang, and update libretro port to latest changes. --- src/common/PKeyboardHandler.cxx | 2 ++ src/common/PaletteHandler.cxx | 37 +++++++++++++++-------------- src/common/PaletteHandler.hxx | 26 ++++++++++---------- src/debugger/gui/CartARWidget.cxx | 2 ++ src/debugger/gui/CartE0Widget.cxx | 2 +- src/debugger/gui/DebuggerDialog.hxx | 2 +- src/emucore/PointingDevice.cxx | 2 ++ src/emucore/TIASurface.hxx | 2 +- src/emucore/Thumbulator.cxx | 1 + src/gui/ColorWidget.cxx | 4 ++-- src/gui/DialogContainer.cxx | 1 - src/gui/EmulationDialog.cxx | 2 +- src/gui/VideoAudioDialog.cxx | 6 ++--- src/gui/VideoAudioDialog.hxx | 4 ++-- src/libretro/Makefile.common | 1 + src/libretro/StellaLIBRETRO.cxx | 13 +++------- src/libretro/StellaLIBRETRO.hxx | 2 +- src/libretro/libretro.cxx | 18 ++++++-------- 18 files changed, 61 insertions(+), 66 deletions(-) diff --git a/src/common/PKeyboardHandler.cxx b/src/common/PKeyboardHandler.cxx index 3edd7698d..9384d3232 100644 --- a/src/common/PKeyboardHandler.cxx +++ b/src/common/PKeyboardHandler.cxx @@ -15,6 +15,8 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ +#include "OSystem.hxx" +#include "Console.hxx" #include "EventHandler.hxx" #include "PKeyboardHandler.hxx" diff --git a/src/common/PaletteHandler.cxx b/src/common/PaletteHandler.cxx index 3f1066724..2aecc6abf 100644 --- a/src/common/PaletteHandler.cxx +++ b/src/common/PaletteHandler.cxx @@ -15,6 +15,7 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ +#include #include "Console.hxx" #include "FrameBuffer.hxx" @@ -303,7 +304,7 @@ PaletteArray PaletteHandler::adjustedPalette(const PaletteArray& palette) adjust[i] = powf(i * toFloat, gamma) * contrast + brightness; // Transform original palette into destination palette - for(int i = 0; i < destPalette.size(); i += 2) + for(size_t i = 0; i < destPalette.size(); i += 2) { const uInt32 pixel = palette[i]; int r = (pixel >> 16) & 0xff; @@ -396,8 +397,8 @@ void PaletteHandler::generateCustomPalette(ConsoleTiming timing) // color 0 is grayscale for(int chroma = 1; chroma < NUM_CHROMA; chroma++) { - color[chroma][0] = SATURATION * sin(offset + shift * (chroma - 1)); - color[chroma][1] = SATURATION * sin(offset + shift * (chroma - 1 - BSPF::PI_f)); + color[chroma][0] = SATURATION * sinf(offset + shift * (chroma - 1)); + color[chroma][1] = SATURATION * sinf(offset + shift * (chroma - 1 - BSPF::PI_f)); } for(int chroma = 0; chroma < NUM_CHROMA; chroma++) @@ -488,17 +489,17 @@ void PaletteHandler::adjustHueSaturation(int& R, int& G, int& B, float H, float // Adapted from http://beesbuzz.biz/code/16-hsv-color-transforms // (C) J. “Fluffy” Shagam // License: CC BY-SA 4.0 - const float su = S * cos(-H * BSPF::PI_f); - const float sw = S * sin(-H * BSPF::PI_f); - const float r = (.299 + .701 * su + .168 * sw) * R - + (.587 - .587 * su + .330 * sw) * G - + (.114 - .114 * su - .497 * sw) * B; - const float g = (.299 - .299 * su - .328 * sw) * R - + (.587 + .413 * su + .035 * sw) * G - + (.114 - .114 * su + .292 * sw) * B; - const float b = (.299 - .300 * su + 1.25 * sw) * R - + (.587 - .588 * su - 1.05 * sw) * G - + (.114 + .886 * su - .203 * sw) * B; + const float su = S * cosf(-H * BSPF::PI_f); + const float sw = S * sinf(-H * BSPF::PI_f); + const float r = (.299F + .701F * su + .168F * sw) * R + + (.587F - .587F * su + .330F * sw) * G + + (.114F - .114F * su - .497F * sw) * B; + const float g = (.299F - .299F * su - .328F * sw) * R + + (.587F + .413F * su + .035F * sw) * G + + (.114F - .114F * su + .292F * sw) * B; + const float b = (.299F - .300F * su + 1.25F * sw) * R + + (.587F - .588F * su - 1.05F * sw) * G + + (.114F + .886F * su - .203F * sw) * B; R = BSPF::clamp(r, 0.F, 255.F); G = BSPF::clamp(g, 0.F, 255.F); @@ -724,14 +725,14 @@ const PaletteArray PaletteHandler::ourSECAMPaletteZ26 = { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PaletteArray PaletteHandler::ourUserNTSCPalette = { 0 }; // filled from external file - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PaletteArray PaletteHandler::ourUserPALPalette = { 0 }; // filled from external file - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PaletteArray PaletteHandler::ourUserSECAMPalette = { 0 }; // filled from external file - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PaletteArray PaletteHandler::ourCustomNTSCPalette = { 0 }; // filled by function - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PaletteArray PaletteHandler::ourCustomPALPalette = { 0 }; // filled by function diff --git a/src/common/PaletteHandler.hxx b/src/common/PaletteHandler.hxx index 237d9b878..3a8c5c9e3 100644 --- a/src/common/PaletteHandler.hxx +++ b/src/common/PaletteHandler.hxx @@ -38,8 +38,8 @@ class PaletteHandler // Externally used adjustment parameters struct Adjustable { - float phaseNtsc, phasePal; - uInt32 hue, saturation, contrast, brightness, gamma; + float phaseNtsc{0.F}, phasePal{0.F}; + uInt32 hue{0}, saturation{0}, contrast{0}, brightness{0}, gamma{0}; }; public: @@ -54,14 +54,14 @@ class PaletteHandler void cyclePalette(bool next = true); /* - Cycle through each palette adjustable + Cycle through each palette adjustable. @param next Select next adjustable, else previous one */ void cycleAdjustable(bool next = true); /* - Increase or decrease current palette adjustable + Increase or decrease current palette adjustable. @param increase Increase adjustable if true, else decrease */ @@ -82,7 +82,7 @@ class PaletteHandler /** Sets the palette according to the given palette name. - @param palette The palette to switch to. + @param name The palette to switch to */ void setPalette(const string& name); @@ -107,11 +107,11 @@ class PaletteHandler /** Convert adjustables from/to 100% scale */ - float scaleFrom100(float x) const { return (x / 50.F) - 1.F; } - uInt32 scaleTo100(float x) const { return uInt32(50 * (x + 1.F)); } + constexpr float scaleFrom100(float x) const { return (x / 50.F) - 1.F; } + constexpr uInt32 scaleTo100(float x) const { return uInt32(50 * (x + 1.F)); } /** - Convert palette settings name to enumeration + Convert palette settings name to enumeration. @param name The given palette's settings name @@ -120,7 +120,7 @@ class PaletteHandler PaletteType toPaletteType(const string& name) const; /** - Convert enumeration to palette settings name + Convert enumeration to palette settings name. @param type The given palette type @@ -133,7 +133,7 @@ class PaletteHandler Note that there are two of these (NTSC and PAL). The currently active mode will determine which one is used. - @param increase Increase if true, else decrease. + @param increase Increase if true, else decrease */ void changeColorPhaseShift(bool increase = true); @@ -145,16 +145,16 @@ class PaletteHandler void generateCustomPalette(ConsoleTiming timing); /** - Create new palette by applying palette adjustments on given palette + Create new palette by applying palette adjustments on given palette. - @param type The palette which should be adjusted + @param source The palette which should be adjusted @return An adjusted palette */ PaletteArray adjustedPalette(const PaletteArray& source); /** - Adjust hue and saturation for given RGB values + Adjust hue and saturation for given RGB values. @param R The red value to adjust @param G The green value to adjust diff --git a/src/debugger/gui/CartARWidget.cxx b/src/debugger/gui/CartARWidget.cxx index 6037849f6..aa552d78e 100644 --- a/src/debugger/gui/CartARWidget.cxx +++ b/src/debugger/gui/CartARWidget.cxx @@ -16,6 +16,8 @@ //============================================================================ #include "CartAR.hxx" +#include "Debugger.hxx" +#include "CartDebug.hxx" #include "PopUpWidget.hxx" #include "CartARWidget.hxx" diff --git a/src/debugger/gui/CartE0Widget.cxx b/src/debugger/gui/CartE0Widget.cxx index 12205c463..08ccc802a 100644 --- a/src/debugger/gui/CartE0Widget.cxx +++ b/src/debugger/gui/CartE0Widget.cxx @@ -49,7 +49,7 @@ string CartridgeE0Widget::romDescription() info << "Segment #" << seg << " accessible @ $" << Common::Base::HEX4 << (ADDR_BASE | segmentOffset) - << " - $" << (ADDR_BASE | segmentOffset + /*myCart.myBankSize - 1*/ 0x3FF) << ",\n"; + << " - $" << (ADDR_BASE | (segmentOffset + /*myCart.myBankSize - 1*/ 0x3FF)) << ",\n"; if (seg < 3) info << " Hotspots " << hotspotStr(0, seg, true) << " - " << hotspotStr(7, seg, true) << "\n"; else diff --git a/src/debugger/gui/DebuggerDialog.hxx b/src/debugger/gui/DebuggerDialog.hxx index bfd7c332b..b66ae37a6 100644 --- a/src/debugger/gui/DebuggerDialog.hxx +++ b/src/debugger/gui/DebuggerDialog.hxx @@ -33,7 +33,6 @@ class TiaOutputWidget; class TiaZoomWidget; class CartDebugWidget; class CartRamWidget; -class OptionsDialog; namespace Common { struct Rect; @@ -41,6 +40,7 @@ namespace Common { #include "Dialog.hxx" #include "MessageBox.hxx" +#include "OptionsDialog.hxx" class DebuggerDialog : public Dialog { diff --git a/src/emucore/PointingDevice.cxx b/src/emucore/PointingDevice.cxx index 1a2c781b4..4d91d010c 100644 --- a/src/emucore/PointingDevice.cxx +++ b/src/emucore/PointingDevice.cxx @@ -15,6 +15,8 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ +#include + #include "Control.hxx" #include "Event.hxx" #include "System.hxx" diff --git a/src/emucore/TIASurface.hxx b/src/emucore/TIASurface.hxx index 9dbda5b14..6552c26ca 100644 --- a/src/emucore/TIASurface.hxx +++ b/src/emucore/TIASurface.hxx @@ -22,13 +22,13 @@ class TIA; class Console; class OSystem; class FBSurface; -class PaletteHandler; #include #include "Rect.hxx" #include "FrameBuffer.hxx" #include "NTSCFilter.hxx" +#include "PaletteHandler.hxx" #include "PhosphorHandler.hxx" #include "bspf.hxx" #include "TIAConstants.hxx" diff --git a/src/emucore/Thumbulator.cxx b/src/emucore/Thumbulator.cxx index c5bd3e637..2984159cd 100644 --- a/src/emucore/Thumbulator.cxx +++ b/src/emucore/Thumbulator.cxx @@ -108,6 +108,7 @@ void Thumbulator::setConsoleTiming(ConsoleTiming timing) case ConsoleTiming::ntsc: timing_factor = NTSC; break; case ConsoleTiming::secam: timing_factor = SECAM; break; case ConsoleTiming::pal: timing_factor = PAL; break; + default: break; // satisfy compiler } } diff --git a/src/gui/ColorWidget.cxx b/src/gui/ColorWidget.cxx index 8052bf029..27f4bc3cf 100644 --- a/src/gui/ColorWidget.cxx +++ b/src/gui/ColorWidget.cxx @@ -28,8 +28,8 @@ ColorWidget::ColorWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, int cmd, bool framed) : Widget(boss, font, x, y, w, h), CommandSender(boss), - _cmd(cmd), - _framed(framed) + _framed(framed), + _cmd(cmd) { _flags = Widget::FLAG_ENABLED | Widget::FLAG_CLEARBG | Widget::FLAG_RETAIN_FOCUS; } diff --git a/src/gui/DialogContainer.cxx b/src/gui/DialogContainer.cxx index b60faf6d4..950d71c06 100644 --- a/src/gui/DialogContainer.cxx +++ b/src/gui/DialogContainer.cxx @@ -384,4 +384,3 @@ void DialogContainer::reset() uInt64 DialogContainer::_DOUBLE_CLICK_DELAY = 500; uInt64 DialogContainer::_REPEAT_INITIAL_DELAY = 400; uInt64 DialogContainer::_REPEAT_SUSTAIN_DELAY = 50; - diff --git a/src/gui/EmulationDialog.cxx b/src/gui/EmulationDialog.cxx index 111fa12f9..ad86e2e60 100644 --- a/src/gui/EmulationDialog.cxx +++ b/src/gui/EmulationDialog.cxx @@ -280,4 +280,4 @@ void EmulationDialog::handleCommand(CommandSender* sender, int cmd, Dialog::handleCommand(sender, cmd, data, 0); break; } -} \ No newline at end of file +} diff --git a/src/gui/VideoAudioDialog.cxx b/src/gui/VideoAudioDialog.cxx index b5f155f40..5d569014a 100644 --- a/src/gui/VideoAudioDialog.cxx +++ b/src/gui/VideoAudioDialog.cxx @@ -112,8 +112,7 @@ void VideoAudioDialog::addDisplayTab() { const int lineHeight = _font.getLineHeight(), fontHeight = _font.getFontHeight(), - fontWidth = _font.getMaxCharWidth(), - buttonHeight = _font.getLineHeight() * 1.25; + fontWidth = _font.getMaxCharWidth(); const int VGAP = fontHeight / 4; const int VBORDER = fontHeight / 2; const int HBORDER = fontWidth * 1.25; @@ -186,8 +185,7 @@ void VideoAudioDialog::addPaletteTab() { const int lineHeight = _font.getLineHeight(), fontHeight = _font.getFontHeight(), - fontWidth = _font.getMaxCharWidth(), - buttonHeight = _font.getLineHeight() * 1.25; + fontWidth = _font.getMaxCharWidth(); const int VBORDER = fontHeight / 2; const int HBORDER = fontWidth * 1.25; const int INDENT = fontWidth * 2; diff --git a/src/gui/VideoAudioDialog.hxx b/src/gui/VideoAudioDialog.hxx index 6380ae352..f46740ae6 100644 --- a/src/gui/VideoAudioDialog.hxx +++ b/src/gui/VideoAudioDialog.hxx @@ -110,7 +110,7 @@ class VideoAudioDialog : public Dialog SliderWidget* myTVContrast{nullptr}; SliderWidget* myTVGamma{nullptr}; std::array myColorLbl{nullptr}; - ColorWidget* myColor[16][8]{nullptr}; + ColorWidget* myColor[16][8]{{nullptr}}; // Audio CheckboxWidget* mySoundEnableCheckbox{nullptr}; @@ -125,7 +125,7 @@ class VideoAudioDialog : public Dialog SliderWidget* myDpcPitch{nullptr}; string myPalette; - PaletteHandler::Adjustable myPaletteAdj{0.0F}; + PaletteHandler::Adjustable myPaletteAdj; enum { kZoomChanged = 'VDZo', diff --git a/src/libretro/Makefile.common b/src/libretro/Makefile.common index 1893fa57b..5fafdd855 100644 --- a/src/libretro/Makefile.common +++ b/src/libretro/Makefile.common @@ -23,6 +23,7 @@ SOURCES_CXX := \ $(CORE_DIR)/common/KeyMap.cxx \ $(CORE_DIR)/common/Logger.cxx \ $(CORE_DIR)/common/MouseControl.cxx \ + $(CORE_DIR)/common/PaletteHandler.cxx \ $(CORE_DIR)/common/PhosphorHandler.cxx \ $(CORE_DIR)/common/PhysicalJoystick.cxx \ $(CORE_DIR)/common/PJoystickHandler.cxx \ diff --git a/src/libretro/StellaLIBRETRO.cxx b/src/libretro/StellaLIBRETRO.cxx index e3cb5073a..065917c15 100644 --- a/src/libretro/StellaLIBRETRO.cxx +++ b/src/libretro/StellaLIBRETRO.cxx @@ -40,7 +40,7 @@ StellaLIBRETRO::StellaLIBRETRO() video_aspect_ntsc = 0; video_aspect_pal = 0; - video_palette = "standard"; + video_palette = PaletteHandler::SETTING_STANDARD; video_filter = NTSCFilter::Preset::OFF; video_ready = false; @@ -374,19 +374,12 @@ void StellaLIBRETRO::setVideoFilter(NTSCFilter::Preset mode) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void StellaLIBRETRO::setVideoPalette(uInt32 mode) +void StellaLIBRETRO::setVideoPalette(const string& mode) { - switch (mode) - { - case 0: video_palette = "standard"; break; - case 1: video_palette = "z26"; break; - case 2: video_palette = "user"; break; - } - if (system_ready) { myOSystem->settings().setValue("palette", video_palette); - myOSystem->console().setPalette(video_palette); + myOSystem->frameBuffer().tiaSurface().paletteHandler().setPalette(video_palette); } } diff --git a/src/libretro/StellaLIBRETRO.hxx b/src/libretro/StellaLIBRETRO.hxx index f48a13708..3078e8eb1 100644 --- a/src/libretro/StellaLIBRETRO.hxx +++ b/src/libretro/StellaLIBRETRO.hxx @@ -104,7 +104,7 @@ class StellaLIBRETRO void setVideoAspectPAL(uInt32 value) { video_aspect_pal = value; }; void setVideoFilter(NTSCFilter::Preset mode); - void setVideoPalette(uInt32 mode); + void setVideoPalette(const string& mode); void setVideoPhosphor(uInt32 mode, uInt32 blend); void setAudioStereo(int mode); diff --git a/src/libretro/libretro.cxx b/src/libretro/libretro.cxx index 6babbf07f..8caae3765 100644 --- a/src/libretro/libretro.cxx +++ b/src/libretro/libretro.cxx @@ -15,6 +15,7 @@ #include "StellaLIBRETRO.hxx" #include "Event.hxx" #include "NTSCFilter.hxx" +#include "PaletteHandler.hxx" #include "Version.hxx" @@ -30,11 +31,12 @@ static retro_audio_sample_batch_t audio_batch_cb; // libretro UI settings static int setting_ntsc, setting_pal; -static int setting_stereo, setting_palette; +static int setting_stereo; static int setting_phosphor, setting_console, setting_phosphor_blend; static int stella_paddle_joypad_sensitivity; static int setting_crop_hoverscan, crop_left; static NTSCFilter::Preset setting_filter; +static const char* setting_palette; static bool system_reset; @@ -275,17 +277,11 @@ static void update_variables(bool init = false) RETRO_GET("stella_palette") { - int value = 0; - - if(!strcmp(var.value, "standard")) value = 0; - else if(!strcmp(var.value, "z26")) value = 1; - else if(!strcmp(var.value, "user")) value = 2; - - if(setting_palette != value) + if(setting_palette != var.value) { - stella.setVideoPalette(value); + stella.setVideoPalette(var.value); - setting_palette = value; + setting_palette = var.value; } } @@ -494,7 +490,7 @@ void retro_set_environment(retro_environment_t cb) static struct retro_variable variables[] = { // Adding more variables and rearranging them is safe. { "stella_console", "Console display; auto|ntsc|pal|secam|ntsc50|pal60|secam60" }, - { "stella_palette", "Palette colors; standard|z26|user" }, + { "stella_palette", "Palette colors; standard|z26|user|custom" }, { "stella_filter", "TV effects; disabled|composite|s-video|rgb|badly adjusted" }, { "stella_ntsc_aspect", "NTSC aspect %; par|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|50|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99" }, { "stella_pal_aspect", "PAL aspect %; par|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|50|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99" },