Skip to content

Commit

Permalink
Merge pull request #281 from ds22x/master
Browse files Browse the repository at this point in the history
Sync to upstream
  • Loading branch information
inactive123 authored Apr 14, 2022
2 parents 92e5907 + bb8c0e5 commit bc65c09
Show file tree
Hide file tree
Showing 20 changed files with 536 additions and 447 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ snes9x_linux-gtk-amd64_task:

setup_script:
- git submodule update --init --recursive
- apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install meson gettext libsdl2-dev libgtkmm-3.0-dev libgtk-3-dev libminizip-dev portaudio19-dev glslang-dev
- apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install meson gettext libsdl2-dev libgtkmm-3.0-dev libgtk-3-dev libminizip-dev portaudio19-dev glslang-dev cmake

compile_script:
- meson build gtk --buildtype=release --strip
Expand Down
48 changes: 16 additions & 32 deletions gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@ bool8 S9xGraphicsInit (void)
S9xInitTileRenderer();
memset(BlackColourMap, 0, 256 * sizeof(uint16));

GFX.RealPPL = GFX.Pitch >> 1;
IPPU.OBJChanged = TRUE;
Settings.BG_Forced = 0;
S9xFixColourBrightness();
S9xBuildDirectColourMaps();

GFX.Screen = &GFX.ScreenBuffer[GFX.RealPPL * 32];
GFX.ZERO = (uint16 *) malloc(sizeof(uint16) * 0x10000);

GFX.ScreenSize = GFX.Pitch / 2 * SNES_HEIGHT_EXTENDED * (Settings.SupportHiRes ? 2 : 1);
GFX.SubScreen = (uint16 *) malloc(GFX.ScreenSize * sizeof(uint16));
GFX.ZBuffer = (uint8 *) malloc(GFX.ScreenSize);
GFX.SubZBuffer = (uint8 *) malloc(GFX.ScreenSize);
Expand Down Expand Up @@ -100,6 +98,9 @@ bool8 S9xGraphicsInit (void)
}
}

GFX.EndScreenRefreshCallback = NULL;
GFX.EndScreenRefreshCallbackData = NULL;

return (TRUE);
}

Expand All @@ -109,6 +110,9 @@ void S9xGraphicsDeinit (void)
if (GFX.SubScreen) { free(GFX.SubScreen); GFX.SubScreen = NULL; }
if (GFX.ZBuffer) { free(GFX.ZBuffer); GFX.ZBuffer = NULL; }
if (GFX.SubZBuffer) { free(GFX.SubZBuffer); GFX.SubZBuffer = NULL; }

GFX.EndScreenRefreshCallback = NULL;
GFX.EndScreenRefreshCallbackData = NULL;
}

void S9xGraphicsScreenResize (void)
Expand All @@ -121,19 +125,11 @@ void S9xGraphicsScreenResize (void)

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;
}
Expand Down Expand Up @@ -273,6 +269,15 @@ void S9xEndScreenRefresh (void)
}
}
}

if (GFX.EndScreenRefreshCallback)
GFX.EndScreenRefreshCallback(GFX.EndScreenRefreshCallbackData);
}

void S9xSetEndScreenRefreshCallback(const SGFX::Callback cb, void *const data)
{
GFX.EndScreenRefreshCallback = cb;
GFX.EndScreenRefreshCallbackData = data;
}

void RenderLine (uint8 C)
Expand Down Expand Up @@ -471,27 +476,6 @@ void S9xUpdateScreen (void)
{
if (!IPPU.DoubleWidthPixels && (PPU.BGMode == 5 || PPU.BGMode == 6 || IPPU.PseudoHires))
{
#ifdef USE_OPENGL
if (Settings.OpenGLEnable && GFX.RealPPL == 256)
{
// Have to back out of the speed up hack where the low res.
// SNES image was rendered into a 256x239 sized buffer,
// ignoring the true, larger size of the buffer.
GFX.RealPPL = GFX.Pitch >> 1;

for (int32 y = (int32) GFX.StartY - 1; y >= 0; y--)
{
uint16 *p = GFX.Screen + y * GFX.PPL + 255;
uint16 *q = GFX.Screen + y * GFX.RealPPL + 510;

for (int x = 255; x >= 0; x--, p--, q -= 2)
*q = *(q + 1) = *p;
}

GFX.PPL = GFX.RealPPL; // = GFX.Pitch >> 1 above
}
else
#endif
// Have to back out of the regular speed hack
for (uint32 y = 0; y < GFX.StartY; y++)
{
Expand Down
13 changes: 10 additions & 3 deletions gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@

struct SGFX
{
typedef void (*Callback)(void *);

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)];
uint16 *Screen;
uint16 *SubScreen;
uint8 *ZBuffer;
uint8 *SubZBuffer;
uint32 Pitch;
uint32 ScreenSize;
uint16 *S;
uint8 *DB;
uint16 *ZERO;
uint32 RealPPL; // true PPL of Screen buffer
uint32 PPL; // number of pixels on each of Screen buffer
uint32 LinesPerTile; // number of lines in 1 tile (4 or 8 due to interlace)
uint16 *ScreenColors; // screen colors for rendering main
Expand Down Expand Up @@ -66,6 +69,9 @@ struct SGFX
const char *InfoString;
uint32 InfoStringTimeout;
char FrameDisplayString[256];

Callback EndScreenRefreshCallback;
void *EndScreenRefreshCallbackData;
};

struct SBG
Expand Down Expand Up @@ -201,6 +207,7 @@ struct COLOR_SUB

void S9xStartScreenRefresh (void);
void S9xEndScreenRefresh (void);
void S9xSetEndScreenRefreshCallback(SGFX::Callback cb, void *data);
void S9xBuildDirectColourMaps (void);
void RenderLine (uint8);
void S9xComputeClipWindows (void);
Expand Down
Loading

0 comments on commit bc65c09

Please sign in to comment.