From 1067b3d0cabcd2c3e2e494dee0b9b5889bca0264 Mon Sep 17 00:00:00 2001 From: retrotalker <42415066+retrotalker@users.noreply.github.com> Date: Thu, 23 Aug 2018 17:35:15 -0500 Subject: [PATCH] resize viewport on load state --- gfx.cpp | 81 ++++++++++++++++++++++++++++------------------------ gfx.h | 1 + snapshot.cpp | 9 ++++++ 3 files changed, 53 insertions(+), 38 deletions(-) diff --git a/gfx.cpp b/gfx.cpp index 95e22896..7c6a9cfe 100644 --- a/gfx.cpp +++ b/gfx.cpp @@ -329,6 +329,48 @@ void S9xGraphicsDeinit (void) if (GFX.SubZBuffer) { free(GFX.SubZBuffer); GFX.SubZBuffer = NULL; } } +void S9xGraphicsScreenResize (void) +{ + IPPU.MaxBrightness = PPU.Brightness; + + IPPU.Interlace = Memory.FillRAM[0x2133] & 1; + IPPU.InterlaceOBJ = Memory.FillRAM[0x2133] & 2; + IPPU.PseudoHires = Memory.FillRAM[0x2133] & 8; + + if (Settings.SupportHiRes && (PPU.BGMode == 5 || PPU.BGMode == 6 || IPPU.PseudoHires)) + { + GFX.RealPPL = GFX.Pitch >> 1; + IPPU.DoubleWidthPixels = TRUE; + IPPU.RenderedScreenWidth = SNES_WIDTH << 1; + } + else + { + #ifdef USE_OPENGL + if (Settings.OpenGLEnable) + GFX.RealPPL = SNES_WIDTH; + else + #endif + GFX.RealPPL = GFX.Pitch >> 1; + + IPPU.DoubleWidthPixels = FALSE; + IPPU.RenderedScreenWidth = SNES_WIDTH; + } + + if (Settings.SupportHiRes && IPPU.Interlace) + { + GFX.PPL = GFX.RealPPL << 1; + IPPU.DoubleHeightPixels = TRUE; + IPPU.RenderedScreenHeight = PPU.ScreenHeight << 1; + GFX.DoInterlace++; + } + else + { + GFX.PPL = GFX.RealPPL; + IPPU.DoubleHeightPixels = FALSE; + IPPU.RenderedScreenHeight = PPU.ScreenHeight; + } +} + void S9xBuildDirectColourMaps (void) { IPPU.XB = mul_brightness[PPU.Brightness]; @@ -355,44 +397,7 @@ void S9xStartScreenRefresh (void) if (GFX.DoInterlace) GFX.DoInterlace--; - IPPU.MaxBrightness = PPU.Brightness; - - IPPU.Interlace = Memory.FillRAM[0x2133] & 1; - IPPU.InterlaceOBJ = Memory.FillRAM[0x2133] & 2; - IPPU.PseudoHires = Memory.FillRAM[0x2133] & 8; - - if (Settings.SupportHiRes && (PPU.BGMode == 5 || PPU.BGMode == 6 || IPPU.PseudoHires)) - { - GFX.RealPPL = GFX.Pitch >> 1; - IPPU.DoubleWidthPixels = TRUE; - IPPU.RenderedScreenWidth = SNES_WIDTH << 1; - } - else - { - #ifdef USE_OPENGL - if (Settings.OpenGLEnable) - GFX.RealPPL = SNES_WIDTH; - else - #endif - GFX.RealPPL = GFX.Pitch >> 1; - - IPPU.DoubleWidthPixels = FALSE; - IPPU.RenderedScreenWidth = SNES_WIDTH; - } - - if (Settings.SupportHiRes && IPPU.Interlace) - { - GFX.PPL = GFX.RealPPL << 1; - IPPU.DoubleHeightPixels = TRUE; - IPPU.RenderedScreenHeight = PPU.ScreenHeight << 1; - GFX.DoInterlace++; - } - else - { - GFX.PPL = GFX.RealPPL; - IPPU.DoubleHeightPixels = FALSE; - IPPU.RenderedScreenHeight = PPU.ScreenHeight; - } + S9xGraphicsScreenResize(); IPPU.RenderedFramesCount++; } diff --git a/gfx.h b/gfx.h index 64e93b3e..4c4d5945 100644 --- a/gfx.h +++ b/gfx.h @@ -359,6 +359,7 @@ void S9xBuildDirectColourMaps (void); void RenderLine (uint8); void S9xComputeClipWindows (void); void S9xDisplayChar (uint16 *, uint8); +void S9xGraphicsScreenResize (void); // called automatically unless Settings.AutoDisplayMessages is false void S9xDisplayMessages (uint16 *, int, int, int, int); #ifdef GFX_MULTI_FORMAT diff --git a/snapshot.cpp b/snapshot.cpp index c62c5079..2b71c449 100644 --- a/snapshot.cpp +++ b/snapshot.cpp @@ -204,6 +204,7 @@ #include "movie.h" #include "display.h" #include "language.h" +#include "gfx.h" #ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) @@ -1843,6 +1844,14 @@ int S9xUnfreezeFromStream (STREAM stream) IPPU.ColorsChanged = TRUE; IPPU.OBJChanged = TRUE; IPPU.RenderThisFrame = TRUE; + + GFX.InterlaceFrame = Timings.InterlaceField; + GFX.DoInterlace = 0; + + S9xGraphicsScreenResize(); + + if (Settings.FastSavestates == 0) + memset(GFX.Screen,0,GFX.Pitch * MAX_SNES_HEIGHT); uint8 hdma_byte = Memory.FillRAM[0x420c]; S9xSetCPU(hdma_byte, 0x420c);