Skip to content

Commit

Permalink
Merge pull request #283 from ds22x/master
Browse files Browse the repository at this point in the history
Fix hi-res mode crashing + sync to upstream
  • Loading branch information
LibretroAdmin authored May 12, 2022
2 parents bc65c09 + a415195 commit ae16176
Show file tree
Hide file tree
Showing 31 changed files with 56 additions and 294 deletions.
2 changes: 0 additions & 2 deletions cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "srtc.h"
#include "snapshot.h"
#include "cheats.h"
#include "logger.h"
#ifdef DEBUGGER
#include "debug.h"
#endif
Expand Down Expand Up @@ -99,7 +98,6 @@ static void S9xSoftResetCPU (void)
void S9xReset (void)
{
S9xResetSaveTimer(FALSE);
S9xResetLogger();

memset(Memory.RAM, 0x55, 0x20000);
memset(Memory.VRAM, 0x00, 0x10000);
Expand Down
45 changes: 21 additions & 24 deletions gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void S9xGraphicsScreenResize (void)
IPPU.InterlaceOBJ = Memory.FillRAM[0x2133] & 2;
IPPU.PseudoHires = Memory.FillRAM[0x2133] & 8;

if (Settings.SupportHiRes && (PPU.BGMode == 5 || PPU.BGMode == 6 || IPPU.PseudoHires))
if (PPU.BGMode == 5 || PPU.BGMode == 6 || IPPU.PseudoHires)
{
IPPU.DoubleWidthPixels = TRUE;
IPPU.RenderedScreenWidth = SNES_WIDTH << 1;
Expand All @@ -134,7 +134,7 @@ void S9xGraphicsScreenResize (void)
IPPU.RenderedScreenWidth = SNES_WIDTH;
}

if (Settings.SupportHiRes && IPPU.Interlace)
if (IPPU.Interlace)
{
GFX.PPL = GFX.RealPPL << 1;
IPPU.DoubleHeightPixels = TRUE;
Expand Down Expand Up @@ -472,34 +472,31 @@ void S9xUpdateScreen (void)
PPU.RecomputeClipWindows = FALSE;
}

if (Settings.SupportHiRes)
if (!IPPU.DoubleWidthPixels && (PPU.BGMode == 5 || PPU.BGMode == 6 || IPPU.PseudoHires))
{
if (!IPPU.DoubleWidthPixels && (PPU.BGMode == 5 || PPU.BGMode == 6 || IPPU.PseudoHires))
// Have to back out of the regular speed hack
for (uint32 y = 0; y < GFX.StartY; y++)
{
// Have to back out of the regular speed hack
for (uint32 y = 0; y < GFX.StartY; y++)
{
uint16 *p = GFX.Screen + y * GFX.PPL + 255;
uint16 *q = GFX.Screen + y * GFX.PPL + 510;

for (int x = 255; x >= 0; x--, p--, q -= 2)
*q = *(q + 1) = *p;
}
uint16 *p = GFX.Screen + y * GFX.PPL + 255;
uint16 *q = GFX.Screen + y * GFX.PPL + 510;

IPPU.DoubleWidthPixels = TRUE;
IPPU.RenderedScreenWidth = 512;
for (int x = 255; x >= 0; x--, p--, q -= 2)
*q = *(q + 1) = *p;
}

if (!IPPU.DoubleHeightPixels && IPPU.Interlace && (PPU.BGMode == 5 || PPU.BGMode == 6))
{
IPPU.DoubleHeightPixels = TRUE;
IPPU.RenderedScreenHeight = PPU.ScreenHeight << 1;
GFX.PPL = GFX.RealPPL << 1;
GFX.DoInterlace = 2;
IPPU.DoubleWidthPixels = TRUE;
IPPU.RenderedScreenWidth = 512;
}

for (int32 y = (int32) GFX.StartY - 2; y >= 0; y--)
memmove(GFX.Screen + (y + 1) * GFX.PPL, GFX.Screen + y * GFX.RealPPL, GFX.PPL * sizeof(uint16));
}
if (!IPPU.DoubleHeightPixels && IPPU.Interlace && (PPU.BGMode == 5 || PPU.BGMode == 6))
{
IPPU.DoubleHeightPixels = TRUE;
IPPU.RenderedScreenHeight = PPU.ScreenHeight << 1;
GFX.PPL = GFX.RealPPL << 1;
GFX.DoInterlace = 2;

for (int32 y = (int32) GFX.StartY - 2; y >= 0; y--)
memmove(GFX.Screen + (y + 1) * GFX.PPL, GFX.Screen + y * GFX.RealPPL, GFX.PPL * sizeof(uint16));
}

if ((Memory.FillRAM[0x2130] & 0x30) != 0x30 && (Memory.FillRAM[0x2131] & 0x3f))
Expand Down
4 changes: 2 additions & 2 deletions gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ struct SGFX

const uint32 Pitch = sizeof(uint16) * MAX_SNES_WIDTH;
const uint32 RealPPL = MAX_SNES_WIDTH; // true PPL of Screen buffer
const uint32 ScreenSize = MAX_SNES_WIDTH * SNES_HEIGHT_EXTENDED;
uint16 ScreenBuffer[512 * (478 + 64)];
const uint32 ScreenSize = MAX_SNES_WIDTH * MAX_SNES_HEIGHT;
uint16 ScreenBuffer[MAX_SNES_WIDTH * (MAX_SNES_HEIGHT + 64)];
uint16 *Screen;
uint16 *SubScreen;
uint8 *ZBuffer;
Expand Down
23 changes: 9 additions & 14 deletions gtk/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
cmake_minimum_required(VERSION 3.20)
project(snes9x-gtk VERSION 1.61)

option(USE_OPENGL "Build support for OpenGL" ON)
option(USE_SLANG "Build support for slang-type shaders" ON)
option(USE_XV "Build support for XVideo output" ON)
option(USE_PORTAUDIO "Build PortAudio sound driver" ON)
Expand Down Expand Up @@ -56,17 +55,14 @@ find_library(DL dl REQUIRED)
list(APPEND ARGS ${SDL2_CFLAGS} ${GTK_CFLAGS} ${XRANDR_CFLAGS})
list(APPEND LIBS ${X11} ${XEXT} ${DL} ${SDL2_LIBRARIES} ${GTK_LIBRARIES} ${XRANDR_LIBRARIES})

if(USE_OPENGL)
pkg_check_modules(EPOXY REQUIRED epoxy)
list(APPEND ARGS ${EPOXY_CFLAGS})
list(APPEND LIBS ${EPOXY_LIBRARIES})
list(APPEND SOURCES src/gtk_display_driver_opengl.cpp
src/gtk_glx_context.cpp
../shaders/glsl.cpp
../shaders/shader_helpers.cpp
src/gtk_shader_parameters.cpp)
list(APPEND DEFINES "USE_OPENGL")
endif()
pkg_check_modules(EPOXY REQUIRED epoxy)
list(APPEND ARGS ${EPOXY_CFLAGS})
list(APPEND LIBS ${EPOXY_LIBRARIES})
list(APPEND SOURCES src/gtk_display_driver_opengl.cpp
src/gtk_glx_context.cpp
../shaders/glsl.cpp
../shaders/shader_helpers.cpp
src/gtk_shader_parameters.cpp)

if(USE_SLANG)
list(APPEND SOURCES ../shaders/slang.cpp)
Expand Down Expand Up @@ -259,7 +255,6 @@ list(APPEND SOURCES
../stream.cpp
../conffile.cpp
../bsx.cpp
../logger.cpp
../snapshot.cpp
../screenshot.cpp
../movie.cpp
Expand Down Expand Up @@ -325,4 +320,4 @@ install(FILES data/snes9x_32x32.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/ico
install(FILES data/snes9x_64x64.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/64x64/apps RENAME snes9x.png)
install(FILES data/snes9x_128x128.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps RENAME snes9x.png)
install(FILES data/snes9x_256x256.png DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/256x256/apps RENAME snes9x.png)
install(FILES data/snes9x.svg DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
install(FILES data/snes9x.svg DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
34 changes: 11 additions & 23 deletions gtk/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,18 @@ deps += dl_dep
xrandr_dep = dependency('xrandr')
deps += xrandr_dep

opengl = get_option('opengl')
if opengl
opengl_dep = dependency('epoxy', required: false)

if opengl_dep.found()
args += '-DUSE_OPENGL'
srcs += [ 'src/gtk_display_driver_opengl.cpp',
'src/gtk_display_driver_opengl.h',
'src/gtk_glx_context.cpp',
'src/gtk_glx_context.h',
'../shaders/glsl.cpp',
'../shaders/shader_helpers.cpp',
'src/gtk_shader_parameters.cpp' ]
deps += opengl_dep
else
opengl = false
warns += 'libepoxy not found. OpenGL will disabled.'
endif
endif
opengl_dep = dependency('epoxy', required: true)
srcs += [ 'src/gtk_display_driver_opengl.cpp',
'src/gtk_display_driver_opengl.h',
'src/gtk_glx_context.cpp',
'src/gtk_glx_context.h',
'../shaders/glsl.cpp',
'../shaders/shader_helpers.cpp',
'src/gtk_shader_parameters.cpp' ]
deps += opengl_dep

slang = get_option('slang')
if slang and opengl
if slang

cmake = import('cmake')

Expand Down Expand Up @@ -323,7 +313,6 @@ srcs += [
'../stream.cpp',
'../conffile.cpp',
'../bsx.cpp',
'../logger.cpp',
'../snapshot.cpp',
'../screenshot.cpp',
'../movie.cpp',
Expand Down Expand Up @@ -397,8 +386,7 @@ summary = [
' localedir: ' + localedir,
'[Options] Build type: ' + get_option('buildtype'),
' Wayland: ' + wayland.to_string(),
' OpenGL: ' + opengl.to_string(),
' slang shaders: ' + slang.to_string(),
' slang shaders: ' + slang.to_string(),
' XVideo: ' + xv.to_string(),
' ALSA: ' + alsa.to_string(),
' Open Sound System: ' + oss.to_string(),
Expand Down
1 change: 0 additions & 1 deletion gtk/meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
option('opengl', type: 'boolean', value: true, description: 'Build support for OpenGL')
option('slang', type: 'boolean', value: true, description: 'Build support for slang-type shaders')
option('xv', type: 'boolean', value: true, description: 'Build support for XV')
option('portaudio', type: 'boolean', value: true, description: 'Build PortAudio sound driver')
Expand Down
9 changes: 0 additions & 9 deletions gtk/src/gtk_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ int Snes9xConfig::load_defaults()
rewind_buffer_size = 0;
Settings.Rewinding = false;

#ifdef USE_OPENGL
sync_to_vblank = true;
use_pbos = true;
pbo_format = 0;
Expand All @@ -157,7 +156,6 @@ int Snes9xConfig::load_defaults()
shader_filename.clear();
use_glfinish = false;
use_sync_control = false;
#endif

/* Snes9x Variables */
Settings.MouseMaster = true;
Expand All @@ -177,7 +175,6 @@ int Snes9xConfig::load_defaults()
Settings.StopEmulation = true;
Settings.FrameTimeNTSC = 16639;
Settings.FrameTimePAL = 20000;
Settings.SupportHiRes = true;
Settings.FrameTime = Settings.FrameTimeNTSC;
Settings.BlockInvalidVRAMAccessMaster = true;
Settings.SoundSync = false;
Expand Down Expand Up @@ -256,7 +253,6 @@ int Snes9xConfig::save_config_file()
outbool("MergeFields", ntsc_setup.merge_fields);
outint("ScanlineIntensity", ntsc_scanline_intensity);

#ifdef USE_OPENGL
section = "OpenGL";
outbool("VSync", sync_to_vblank);
outbool("glFinish", use_glfinish);
Expand All @@ -266,7 +262,6 @@ int Snes9xConfig::save_config_file()
outbool("UsePixelBufferObjects", use_pbos);
outint("PixelBufferObjectBitDepth", pbo_format);
outstring("ShaderFile", shader_filename);
#endif

section = "Sound";
outbool("MuteSound", mute_sound);
Expand Down Expand Up @@ -490,7 +485,6 @@ int Snes9xConfig::load_config_file()
inbool("MergeFields", ntsc_setup.merge_fields);
inint("ScanlineIntensity", ntsc_scanline_intensity);

#ifdef USE_OPENGL
section = "OpenGL";
inbool("VSync", sync_to_vblank);
inbool("glFinish", use_glfinish);
Expand All @@ -500,7 +494,6 @@ int Snes9xConfig::load_config_file()
inbool("UseNonPowerOfTwoTextures", npot_textures);
inbool("EnableCustomShaders", use_shaders);
instr("ShaderFile", shader_filename);
#endif

section = "Sound";
inbool("MuteSound", mute_sound);
Expand Down Expand Up @@ -664,10 +657,8 @@ int Snes9xConfig::load_config_file()
scale_method = 0;
#endif /* USE_XBRZ */

#ifdef USE_OPENGL
if (pbo_format != 32)
pbo_format = 16;
#endif

if (Settings.SkipFrames == THROTTLE_SOUND_SYNC)
Settings.SoundSync = true;
Expand Down
3 changes: 0 additions & 3 deletions gtk/src/gtk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ class Snes9xConfig
XRRScreenResources *xrr_screen_resources;
XRRCrtcInfo *xrr_crtc_info;

#ifdef USE_OPENGL
bool sync_to_vblank;
bool use_pbos;
int pbo_format;
Expand All @@ -163,8 +162,6 @@ class Snes9xConfig
std::string shader_filename;
bool use_glfinish;
bool use_sync_control;
#endif


JoyDevices joysticks;
int joystick_threshold;
Expand Down
9 changes: 0 additions & 9 deletions gtk/src/gtk_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
#include "gtk_display_driver_xv.h"
#endif

#ifdef USE_OPENGL
#include "gtk_display_driver_opengl.h"
#endif

static S9xDisplayDriver *driver;
static snes_ntsc_t snes_ntsc;
Expand Down Expand Up @@ -1299,11 +1297,7 @@ void S9xQueryDrivers()
gui_config->allow_xv = S9xXVDisplayDriver::query_availability();
#endif

#ifdef USE_OPENGL
gui_config->allow_opengl = S9xOpenGLDisplayDriver::query_availability();
#else
gui_config->allow_opengl = false;
#endif

gui_config->allow_xrandr = false;
#ifdef GDK_WINDOWING_X11
Expand Down Expand Up @@ -1414,11 +1408,9 @@ static void S9xInitDriver()

switch (gui_config->hw_accel)
{
#ifdef USE_OPENGL
case HWA_OPENGL:
driver = new S9xOpenGLDisplayDriver(top_level, gui_config);
break;
#endif

#if defined(USE_XV) && defined(GDK_WINDOWING_X11)
case HWA_XV:
Expand Down Expand Up @@ -1624,7 +1616,6 @@ static void S9xGTKDisplayString(const char *string, int linesFromBottom,

void S9xInitDisplay(int argc, char **argv)
{
Settings.SupportHiRes = true;
S9xBlit2xSaIFilterInit();
#ifdef USE_HQ2X
S9xBlitHQ2xFilterInit();
Expand Down
6 changes: 3 additions & 3 deletions gtk/src/gtk_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const char *S9xGetFilenameInc(const char *e, enum s9x_getdirtype dirtype)
fs::path rom_filename(Memory.ROMFilename);

fs::path filename_base(S9xGetDirectory(dirtype));
filename_base.replace_filename(rom_filename.filename());
filename_base /= rom_filename.filename();

fs::path new_filename;

Expand Down Expand Up @@ -120,7 +120,7 @@ const char *S9xGetFilename(const char *ex, enum s9x_getdirtype dirtype)
{
static std::string filename;
fs::path path(S9xGetDirectory(dirtype));
path.replace_filename(fs::path(Memory.ROMFilename));
path /= fs::path(Memory.ROMFilename).filename();
path.replace_extension(ex);
filename = path.string();
return filename.c_str();
Expand Down Expand Up @@ -243,7 +243,7 @@ static fs::path save_slot_path(int slot)
while (extension.length() < 3)
extension = "0"s + extension;
fs::path path(S9xGetDirectory(SNAPSHOT_DIR));
path.replace_filename(fs::path(Memory.ROMFilename).filename());
path /= fs::path(Memory.ROMFilename).filename();
path.replace_extension(extension);
return path;
}
Expand Down
Loading

0 comments on commit ae16176

Please sign in to comment.