From 9439b1b4005343fb9a963d1e9c26214edc611665 Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Fri, 3 Dec 2021 18:46:23 +0000 Subject: [PATCH] Incorporate VidHD fro AW. Signed-off-by: Andrea Odetti --- source/CMakeLists.txt | 2 + source/frontends/common2/commonframe.cpp | 6 +- source/frontends/common2/commonframe.h | 2 +- source/frontends/common2/utils.cpp | 1 + source/frontends/libretro/game.cpp | 2 +- source/frontends/libretro/retroframe.cpp | 4 +- source/frontends/libretro/retroframe.h | 2 +- source/frontends/ncurses/main.cpp | 2 +- source/frontends/ncurses/nframe.cpp | 4 +- source/frontends/ncurses/nframe.h | 2 +- source/frontends/qt/qapple.cpp | 2 +- source/frontends/qt/qtframe.cpp | 4 +- source/frontends/qt/qtframe.h | 2 +- source/frontends/sdl/imgui/sdlimguiframe.cpp | 29 ++++--- source/frontends/sdl/imgui/sdlimguiframe.h | 1 + source/frontends/sdl/imgui/settingshelper.cpp | 87 ++++++++++--------- source/frontends/sdl/main.cpp | 2 +- .../sdl/renderer/sdlrendererframe.cpp | 9 +- .../frontends/sdl/renderer/sdlrendererframe.h | 4 + source/frontends/sdl/sdlframe.cpp | 4 +- source/frontends/sdl/sdlframe.h | 2 +- source/linux/linuxframe.cpp | 14 ++- source/linux/linuxframe.h | 5 +- 23 files changed, 108 insertions(+), 84 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 34bed4c64..c1c35200f 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -47,6 +47,7 @@ set(SOURCE_FILES Debugger/Debugger_Commands.cpp Debugger/Util_MemoryTextFile.cpp + VidHD.cpp SSI263.cpp Speaker.cpp SoundCore.cpp @@ -115,6 +116,7 @@ set(SOURCE_FILES ) set(HEADER_FILES + VidHD.cpp SSI263.h SSI263Phonemes.h Speaker.h diff --git a/source/frontends/common2/commonframe.cpp b/source/frontends/common2/commonframe.cpp index 3917a7246..8c1a598b3 100644 --- a/source/frontends/common2/commonframe.cpp +++ b/source/frontends/common2/commonframe.cpp @@ -77,10 +77,10 @@ namespace common2 g_sProgramDir = getResourcePath("/bin/"); } - void CommonFrame::Initialize() + void CommonFrame::Initialize(bool resetVideoState) { InitialiseEmulator(); - LinuxFrame::Initialize(); + LinuxFrame::Initialize(resetVideoState); } void CommonFrame::Destroy() @@ -93,7 +93,7 @@ namespace common2 void CommonFrame::Restart() { Destroy(); - Initialize(); + Initialize(false); } BYTE* CommonFrame::GetResource(WORD id, LPCSTR lpType, DWORD expectedSize) diff --git a/source/frontends/common2/commonframe.h b/source/frontends/common2/commonframe.h index 102391df7..e5fe00457 100644 --- a/source/frontends/common2/commonframe.h +++ b/source/frontends/common2/commonframe.h @@ -12,7 +12,7 @@ namespace common2 public: CommonFrame(); - void Initialize() override; + void Initialize(bool resetVideoState) override; void Destroy() override; void Restart() override; diff --git a/source/frontends/common2/utils.cpp b/source/frontends/common2/utils.cpp index 7c7d62c4b..462c2b7c6 100644 --- a/source/frontends/common2/utils.cpp +++ b/source/frontends/common2/utils.cpp @@ -90,6 +90,7 @@ namespace common2 g_bFullSpeed = false; + GetVideo().SetVidHD(false); LoadConfiguration(); LoadUthernet2(); SetCurrentCLK6502(); diff --git a/source/frontends/libretro/game.cpp b/source/frontends/libretro/game.cpp index a5fc8445b..74fc1a33b 100644 --- a/source/frontends/libretro/game.cpp +++ b/source/frontends/libretro/game.cpp @@ -36,7 +36,7 @@ namespace ra2 myFrame.reset(new ra2::RetroFrame()); SetFrame(myFrame); - myFrame->Initialize(); + myFrame->Initialize(true); Video & video = GetVideo(); // should the user be allowed to tweak 0.75 diff --git a/source/frontends/libretro/retroframe.cpp b/source/frontends/libretro/retroframe.cpp index 3b857387a..9c9c4c3c2 100644 --- a/source/frontends/libretro/retroframe.cpp +++ b/source/frontends/libretro/retroframe.cpp @@ -106,9 +106,9 @@ namespace ra2 video_cb(myVideoBuffer.data() + myOffset, myBorderlessWidth, myBorderlessHeight, myPitch); } - void RetroFrame::Initialize() + void RetroFrame::Initialize(bool resetVideoState) { - CommonFrame::Initialize(); + CommonFrame::Initialize(resetVideoState); FrameRefreshStatus(DRAW_TITLE); Video & video = GetVideo(); diff --git a/source/frontends/libretro/retroframe.h b/source/frontends/libretro/retroframe.h index 376dd34b0..7df2f3a81 100644 --- a/source/frontends/libretro/retroframe.h +++ b/source/frontends/libretro/retroframe.h @@ -15,7 +15,7 @@ namespace ra2 void VideoPresentScreen() override; void FrameRefreshStatus(int drawflags) override; - void Initialize() override; + void Initialize(bool resetVideoState) override; void Destroy() override; int FrameMessageBox(LPCSTR lpText, LPCSTR lpCaption, UINT uType) override; void GetBitmap(LPCSTR lpBitmapName, LONG cb, LPVOID lpvBits) override; diff --git a/source/frontends/ncurses/main.cpp b/source/frontends/ncurses/main.cpp index 56e078e1d..1fa451c58 100644 --- a/source/frontends/ncurses/main.cpp +++ b/source/frontends/ncurses/main.cpp @@ -152,7 +152,7 @@ namespace const Initialisation init(frame, paddle); applyOptions(options); - frame->Initialize(); + frame->Initialize(true); na2::SetCtrlCHandler(options.headless); diff --git a/source/frontends/ncurses/nframe.cpp b/source/frontends/ncurses/nframe.cpp index c2231a9f9..b7417b2a8 100644 --- a/source/frontends/ncurses/nframe.cpp +++ b/source/frontends/ncurses/nframe.cpp @@ -47,9 +47,9 @@ namespace na2 // so we can run headless } - void NFrame::Initialize() + void NFrame::Initialize(bool resetVideoState) { - CommonFrame::Initialize(); + CommonFrame::Initialize(resetVideoState); myTextFlashCounter = 0; myTextFlashState = 0; myAsciiArt.reset(new ASCIIArt()); diff --git a/source/frontends/ncurses/nframe.h b/source/frontends/ncurses/nframe.h index fdfb912cb..533fd3078 100644 --- a/source/frontends/ncurses/nframe.h +++ b/source/frontends/ncurses/nframe.h @@ -21,7 +21,7 @@ namespace na2 WINDOW * GetWindow(); WINDOW * GetStatus(); - void Initialize() override; + void Initialize(bool resetVideoState) override; void Destroy() override; void VideoPresentScreen() override; int FrameMessageBox(LPCSTR lpText, LPCSTR lpCaption, UINT uType) override; diff --git a/source/frontends/qt/qapple.cpp b/source/frontends/qt/qapple.cpp index 557e00ace..b2a3c6b7a 100644 --- a/source/frontends/qt/qapple.cpp +++ b/source/frontends/qt/qapple.cpp @@ -104,7 +104,7 @@ namespace MB_Initialize(); SpkrInitialize(); MemInitialize(); - frame->Initialize(); + frame->Initialize(true); CardManager & cardManager = GetCardMgr(); cardManager.GetDisk2CardMgr().Reset(); diff --git a/source/frontends/qt/qtframe.cpp b/source/frontends/qt/qtframe.cpp index 305de1b9c..f6d8fec86 100644 --- a/source/frontends/qt/qtframe.cpp +++ b/source/frontends/qt/qtframe.cpp @@ -36,9 +36,9 @@ void QtFrame::FrameRefreshStatus(int drawflags) } } -void QtFrame::Initialize() +void QtFrame::Initialize(bool resetVideoState) { - LinuxFrame::Initialize(); + LinuxFrame::Initialize(resetVideoState); FrameRefreshStatus(DRAW_TITLE); myEmulator->loadVideoSettings(); myEmulator->displayLogo(); diff --git a/source/frontends/qt/qtframe.h b/source/frontends/qt/qtframe.h index d0c5cf1a7..2a0aa163b 100644 --- a/source/frontends/qt/qtframe.h +++ b/source/frontends/qt/qtframe.h @@ -16,7 +16,7 @@ class QtFrame : public LinuxFrame void VideoPresentScreen() override; void FrameRefreshStatus(int drawflags) override; - void Initialize() override; + void Initialize(bool resetVideoState) override; void Destroy() override; int FrameMessageBox(LPCSTR lpText, LPCSTR lpCaption, UINT uType) override; diff --git a/source/frontends/sdl/imgui/sdlimguiframe.cpp b/source/frontends/sdl/imgui/sdlimguiframe.cpp index d0462ab2a..ec0827a52 100644 --- a/source/frontends/sdl/imgui/sdlimguiframe.cpp +++ b/source/frontends/sdl/imgui/sdlimguiframe.cpp @@ -96,9 +96,25 @@ namespace sa2 ImGui::StyleColorsDark(); ImGui_ImplSDL2_InitForOpenGL(myWindow.get(), myGLContext); - ImGui_ImplOpenGL3_Init(); + myDeadTopZone = 0; + myTexture = 0; + } + + SDLImGuiFrame::~SDLImGuiFrame() + { + glDeleteTextures(1, &myTexture); + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplSDL2_Shutdown(); + ImGui::DestroyContext(); + SDL_GL_DeleteContext(myGLContext); + } + + void SDLImGuiFrame::Initialize(bool resetVideoState) + { + SDLFrame::Initialize(resetVideoState); + glDeleteTextures(1, &myTexture); glGenTextures(1, &myTexture); Video & video = GetVideo(); @@ -114,17 +130,6 @@ namespace sa2 myOffset = (width * borderHeight + borderWidth) * sizeof(bgra_t); allocateTexture(myTexture, myBorderlessWidth, myBorderlessHeight); - - myDeadTopZone = 0; - } - - SDLImGuiFrame::~SDLImGuiFrame() - { - glDeleteTextures(1, &myTexture); - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplSDL2_Shutdown(); - ImGui::DestroyContext(); - SDL_GL_DeleteContext(myGLContext); } void SDLImGuiFrame::UpdateTexture() diff --git a/source/frontends/sdl/imgui/sdlimguiframe.h b/source/frontends/sdl/imgui/sdlimguiframe.h index b18472f59..41bc6a920 100644 --- a/source/frontends/sdl/imgui/sdlimguiframe.h +++ b/source/frontends/sdl/imgui/sdlimguiframe.h @@ -21,6 +21,7 @@ namespace sa2 void VideoPresentScreen() override; void ResetSpeed() override; + void Initialize(bool resetVideoState) override; protected: diff --git a/source/frontends/sdl/imgui/settingshelper.cpp b/source/frontends/sdl/imgui/settingshelper.cpp index df42e7333..03e15f714 100644 --- a/source/frontends/sdl/imgui/settingshelper.cpp +++ b/source/frontends/sdl/imgui/settingshelper.cpp @@ -16,60 +16,61 @@ namespace { const std::map cards = { - {CT_Empty, "CT_Empty"}, - {CT_Disk2, "CT_Disk2"}, - {CT_SSC, "CT_SSC"}, - {CT_MockingboardC, "CT_MockingboardC"}, - {CT_GenericPrinter, "CT_GenericPrinter"}, - {CT_GenericHDD, "CT_GenericHDD"}, - {CT_GenericClock, "CT_GenericClock"}, - {CT_MouseInterface, "CT_MouseInterface"}, - {CT_Z80, "CT_Z80"}, - {CT_Phasor, "CT_Phasor"}, - {CT_Echo, "CT_Echo"}, - {CT_SAM, "CT_SAM"}, - {CT_80Col, "CT_80Col"}, - {CT_Extended80Col, "CT_Extended80Col"}, - {CT_RamWorksIII, "CT_RamWorksIII"}, - {CT_Uthernet, "CT_Uthernet"}, - {CT_LanguageCard, "CT_LanguageCard"}, - {CT_LanguageCardIIe, "CT_LanguageCardIIe"}, - {CT_Saturn128K, "CT_Saturn128K"}, - {CT_FourPlay, "CT_FourPlay"}, - {CT_SNESMAX, "CT_SNESMAX"}, - {CT_Uthernet2, "CT_Uthernet2"}, + {CT_Empty, "Empty"}, + {CT_Disk2, "Disk2"}, + {CT_SSC, "SSC"}, + {CT_MockingboardC, "MockingboardC"}, + {CT_GenericPrinter, "GenericPrinter"}, + {CT_GenericHDD, "GenericHDD"}, + {CT_GenericClock, "GenericClock"}, + {CT_MouseInterface, "MouseInterface"}, + {CT_Z80, "Z80"}, + {CT_Phasor, "Phasor"}, + {CT_Echo, "Echo"}, + {CT_SAM, "SAM"}, + {CT_80Col, "80Col"}, + {CT_Extended80Col, "Extended80Col"}, + {CT_RamWorksIII, "RamWorksIII"}, + {CT_Uthernet, "Uthernet"}, + {CT_LanguageCard, "LanguageCard"}, + {CT_LanguageCardIIe, "LanguageCardIIe"}, + {CT_Saturn128K, "Saturn128K"}, + {CT_FourPlay, "FourPlay"}, + {CT_SNESMAX, "SNESMAX"}, + {CT_VidHD, "VidHD"}, + {CT_Uthernet2, "Uthernet2"}, }; const std::map apple2Types = { - {A2TYPE_APPLE2, "A2TYPE_APPLE2"}, - {A2TYPE_APPLE2PLUS, "A2TYPE_APPLE2PLUS"}, - {A2TYPE_APPLE2JPLUS, "A2TYPE_APPLE2JPLUS"}, - {A2TYPE_APPLE2E, "A2TYPE_APPLE2E"}, - {A2TYPE_APPLE2EENHANCED, "A2TYPE_APPLE2EENHANCED"}, - {A2TYPE_APPLE2C, "A2TYPE_APPLE2C"}, - {A2TYPE_PRAVETS8M, "A2TYPE_PRAVETS8M"}, - {A2TYPE_PRAVETS82, "A2TYPE_PRAVETS82"}, - {A2TYPE_BASE64A, "A2TYPE_BASE64A"}, - {A2TYPE_PRAVETS8A, "A2TYPE_PRAVETS8A"}, - {A2TYPE_TK30002E, "A2TYPE_TK30002E"}, + {A2TYPE_APPLE2, "APPLE2"}, + {A2TYPE_APPLE2PLUS, "APPLE2PLUS"}, + {A2TYPE_APPLE2JPLUS, "APPLE2JPLUS"}, + {A2TYPE_APPLE2E, "APPLE2E"}, + {A2TYPE_APPLE2EENHANCED, "APPLE2EENHANCED"}, + {A2TYPE_APPLE2C, "APPLE2C"}, + {A2TYPE_PRAVETS8M, "PRAVETS8M"}, + {A2TYPE_PRAVETS82, "PRAVETS82"}, + {A2TYPE_BASE64A, "BASE64A"}, + {A2TYPE_PRAVETS8A, "PRAVETS8A"}, + {A2TYPE_TK30002E, "TK30002E"}, }; const std::map cpuTypes = { - {CPU_6502, "CPU_6502"}, - {CPU_65C02, "CPU_65C02"}, - {CPU_Z80, "CPU_Z80"}, + {CPU_6502, "6502"}, + {CPU_65C02, "65C02"}, + {CPU_Z80, "Z80"}, }; const std::map appModes = { - {MODE_LOGO, "MODE_LOGO"}, - {MODE_PAUSED, "MODE_PAUSED"}, - {MODE_RUNNING, "MODE_RUNNING"}, - {MODE_DEBUG, "MODE_DEBUG"}, - {MODE_STEPPING, "MODE_STEPPING"}, - {MODE_BENCHMARK, "MODE_BENCHMARCK"}, + {MODE_LOGO, "LOGO"}, + {MODE_PAUSED, "PAUSED"}, + {MODE_RUNNING, "RUNNING"}, + {MODE_DEBUG, "DEBUG"}, + {MODE_STEPPING, "STEPPING"}, + {MODE_BENCHMARK, "BENCHMARCK"}, }; const std::map statuses = @@ -98,7 +99,7 @@ namespace {0, {CT_Empty, CT_LanguageCard, CT_Saturn128K}}, {1, {CT_Empty, CT_GenericPrinter, CT_Uthernet2}}, {2, {CT_Empty, CT_SSC, CT_Uthernet2}}, - {3, {CT_Empty, CT_Uthernet, CT_Uthernet2}}, + {3, {CT_Empty, CT_Uthernet, CT_Uthernet2, CT_VidHD}}, {4, {CT_Empty, CT_MockingboardC, CT_MouseInterface, CT_Phasor, CT_Uthernet2}}, {5, {CT_Empty, CT_MockingboardC, CT_Z80, CT_SAM, CT_Disk2, CT_FourPlay, CT_SNESMAX, CT_Uthernet2}}, {6, {CT_Empty, CT_Disk2}}, diff --git a/source/frontends/sdl/main.cpp b/source/frontends/sdl/main.cpp index 516190842..5a17326c1 100644 --- a/source/frontends/sdl/main.cpp +++ b/source/frontends/sdl/main.cpp @@ -95,7 +95,7 @@ void run_sdl(int argc, const char * argv []) std::shared_ptr paddle(new sa2::Gamepad(0)); const Initialisation init(frame, paddle); applyOptions(options); - frame->Initialize(); + frame->Initialize(true); std::cerr << "Default GL swap interval: " << SDL_GL_GetSwapInterval() << std::endl; diff --git a/source/frontends/sdl/renderer/sdlrendererframe.cpp b/source/frontends/sdl/renderer/sdlrendererframe.cpp index cc87c2d91..be0c8fb49 100644 --- a/source/frontends/sdl/renderer/sdlrendererframe.cpp +++ b/source/frontends/sdl/renderer/sdlrendererframe.cpp @@ -30,9 +30,12 @@ namespace sa2 throw std::runtime_error(SDL_GetError()); } - const Uint32 format = SDL_PIXELFORMAT_ARGB8888; - printRendererInfo(std::cerr, myRenderer, format, options.sdlDriver); + printRendererInfo(std::cerr, myRenderer, ourFormat, options.sdlDriver); + } + void SDLRendererFrame::Initialize(bool resetVideoState) + { + SDLFrame::Initialize(resetVideoState); Video & video = GetVideo(); const int width = video.GetFrameBufferWidth(); @@ -40,7 +43,7 @@ namespace sa2 const int sw = video.GetFrameBufferBorderlessWidth(); const int sh = video.GetFrameBufferBorderlessHeight(); - myTexture.reset(SDL_CreateTexture(myRenderer.get(), format, SDL_TEXTUREACCESS_STATIC, width, height), SDL_DestroyTexture); + myTexture.reset(SDL_CreateTexture(myRenderer.get(), ourFormat, SDL_TEXTUREACCESS_STATIC, width, height), SDL_DestroyTexture); myRect.x = video.GetFrameBufferBorderWidth(); myRect.y = video.GetFrameBufferBorderHeight(); diff --git a/source/frontends/sdl/renderer/sdlrendererframe.h b/source/frontends/sdl/renderer/sdlrendererframe.h index c3a41c8a1..775e5fd60 100644 --- a/source/frontends/sdl/renderer/sdlrendererframe.h +++ b/source/frontends/sdl/renderer/sdlrendererframe.h @@ -16,11 +16,15 @@ namespace sa2 SDLRendererFrame(const common2::EmulatorOptions & options); void VideoPresentScreen() override; + void Initialize(bool resetVideoState) override; protected: void GetRelativeMousePosition(const SDL_MouseMotionEvent & motion, double & x, double & y) const override; private: + + static constexpr Uint32 ourFormat = SDL_PIXELFORMAT_ARGB8888; + SDL_Rect myRect; int myPitch; diff --git a/source/frontends/sdl/sdlframe.cpp b/source/frontends/sdl/sdlframe.cpp index 376a81aea..4dd93ebd0 100644 --- a/source/frontends/sdl/sdlframe.cpp +++ b/source/frontends/sdl/sdlframe.cpp @@ -159,9 +159,9 @@ namespace sa2 } } - void SDLFrame::Initialize() + void SDLFrame::Initialize(bool resetVideoState) { - CommonFrame::Initialize(); + CommonFrame::Initialize(resetVideoState); mySpeed.reset(); setGLSwapInterval(myTargetGLSwap); ResetHardware(); diff --git a/source/frontends/sdl/sdlframe.h b/source/frontends/sdl/sdlframe.h index 7995419c1..06d5c24f3 100644 --- a/source/frontends/sdl/sdlframe.h +++ b/source/frontends/sdl/sdlframe.h @@ -19,7 +19,7 @@ namespace sa2 public: SDLFrame(const common2::EmulatorOptions & options); - void Initialize() override; + void Initialize(bool resetVideoState) override; void Destroy() override; void FrameRefreshStatus(int drawflags) override; diff --git a/source/linux/linuxframe.cpp b/source/linux/linuxframe.cpp index cdbc9cf7b..566037350 100644 --- a/source/linux/linuxframe.cpp +++ b/source/linux/linuxframe.cpp @@ -28,7 +28,7 @@ void LinuxFrame::SetFullScreenShowSubunitStatus(bool /* bShow */) { } -bool LinuxFrame::GetBestDisplayResolutionForFullScreen(UINT& /* bestWidth */, UINT& /* bestHeight */ , UINT /* userSpecifiedHeight */) +bool LinuxFrame::GetBestDisplayResolutionForFullScreen(UINT& /* bestWidth */, UINT& /* bestHeight */, UINT /* userSpecifiedWidth */, UINT /* userSpecifiedHeight */) { return false; } @@ -46,15 +46,21 @@ void LinuxFrame::SetLoadedSaveStateFlag(const bool /* bFlag */) { } -void LinuxFrame::Initialize() +void LinuxFrame::ResizeWindow() +{ +} + +void LinuxFrame::Initialize(bool resetVideoState) { - static_assert(sizeof(bgra_t) == 4, "Invalid size of bgra_t"); Video & video = GetVideo(); const size_t numberOfPixels = video.GetFrameBufferWidth() * video.GetFrameBufferHeight(); + + static_assert(sizeof(bgra_t) == 4, "Invalid size of bgra_t"); const size_t numberOfBytes = sizeof(bgra_t) * numberOfPixels; + myFramebuffer.resize(numberOfBytes); - video.Initialize(myFramebuffer.data()); + video.Initialize(myFramebuffer.data(), resetVideoState); LogFileTimeUntilFirstKeyReadReset(); } diff --git a/source/linux/linuxframe.h b/source/linux/linuxframe.h index eb1650cf4..205291e4c 100644 --- a/source/linux/linuxframe.h +++ b/source/linux/linuxframe.h @@ -7,7 +7,7 @@ class LinuxFrame : public FrameBase { public: - void Initialize() override; + void Initialize(bool resetVideoState) override; void Destroy() override; void FrameDrawDiskLEDS() override; @@ -15,9 +15,10 @@ class LinuxFrame : public FrameBase void FrameRefreshStatus(int drawflags) override; void FrameUpdateApple2Type() override; void FrameSetCursorPosByMousePos() override; + void ResizeWindow() override; void SetFullScreenShowSubunitStatus(bool bShow) override; - bool GetBestDisplayResolutionForFullScreen(UINT& bestWidth, UINT& bestHeight, UINT userSpecifiedHeight = 0) override; + bool GetBestDisplayResolutionForFullScreen(UINT& bestWidth, UINT& bestHeight, UINT userSpecifiedWidth = 0, UINT userSpecifiedHeight = 0) override; int SetViewportScale(int nNewScale, bool bForce = false) override; void SetAltEnterToggleFullScreen(bool mode) override;