Change S9xInterlaceField to an inline function.

This commit is contained in:
BearOso 2023-03-04 14:15:48 -06:00
parent daf8fba09c
commit 9972e2df56
5 changed files with 21 additions and 18 deletions

View File

@ -284,7 +284,7 @@ void S9xDoHEventProcessing (void)
// [PAL] <PAL info is unverified on hardware>
// interlace mode has 625 scanlines: 313 on the even frame, and 312 on the odd.
// non-interlace mode has 624 scanlines: 312 scanlines on both even and odd frames.
if (IPPU.Interlace && S9xInterlaceField)
if (IPPU.Interlace && S9xInterlaceField())
Timings.V_Max = Timings.V_Max_Master + 1; // 263 (NTSC), 313?(PAL)
else
Timings.V_Max = Timings.V_Max_Master; // 262 (NTSC), 312?(PAL)
@ -305,14 +305,14 @@ void S9xDoHEventProcessing (void)
// In interlace mode, there are always 341 dots per scanline. Even frames have 263 scanlines,
// and odd frames have 262 scanlines.
// Interlace mode scanline 240 on odd frames is not missing a dot.
if (CPU.V_Counter == 240 && !IPPU.Interlace && S9xInterlaceField) // V=240
if (CPU.V_Counter == 240 && !IPPU.Interlace && S9xInterlaceField()) // V=240
Timings.H_Max = Timings.H_Max_Master - ONE_DOT_CYCLE; // HC=1360
else
Timings.H_Max = Timings.H_Max_Master; // HC=1364
if (Model->_5A22 == 2)
{
if (CPU.V_Counter != 240 || IPPU.Interlace || !S9xInterlaceField) // V=240
if (CPU.V_Counter != 240 || IPPU.Interlace || !S9xInterlaceField()) // V=240
{
if (Timings.WRAMRefreshPos == SNES_WRAM_REFRESH_HC_v2 - ONE_DOT_CYCLE) // HC=534
Timings.WRAMRefreshPos = SNES_WRAM_REFRESH_HC_v2; // HC=538

16
gfx.cpp
View File

@ -165,7 +165,7 @@ void S9xStartScreenRefresh (void)
if (IPPU.RenderThisFrame)
{
if (!GFX.DoInterlace || !S9xInterlaceField)
if (!GFX.DoInterlace || !S9xInterlaceField())
{
if (!S9xInitUpdate())
{
@ -205,7 +205,7 @@ void S9xEndScreenRefresh (void)
{
FLUSH_REDRAW();
if (GFX.DoInterlace && S9xInterlaceField == 0)
if (GFX.DoInterlace && S9xInterlaceField() == 0)
{
S9xControlEOF();
S9xContinueUpdate(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight);
@ -328,7 +328,7 @@ static inline void RenderScreen (bool8 sub)
if (!sub)
{
GFX.S = GFX.Screen;
if (GFX.DoInterlace && S9xInterlaceField)
if (GFX.DoInterlace && S9xInterlaceField())
GFX.S += GFX.RealPPL;
GFX.DB = GFX.ZBuffer;
GFX.Clip = IPPU.Clip[0];
@ -514,7 +514,7 @@ void S9xUpdateScreen (void)
const uint16 black = BUILD_PIXEL(0, 0, 0);
GFX.S = GFX.Screen + GFX.StartY * GFX.PPL;
if (GFX.DoInterlace && S9xInterlaceField)
if (GFX.DoInterlace && S9xInterlaceField())
GFX.S += GFX.RealPPL;
for (uint32 l = GFX.StartY; l <= GFX.EndY; l++, GFX.S += GFX.PPL)
@ -575,7 +575,7 @@ static void SetupOBJ (void)
int inc = IPPU.InterlaceOBJ ? 2 : 1;
int startline = (IPPU.InterlaceOBJ && S9xInterlaceField) ? 1 : 0;
int startline = (IPPU.InterlaceOBJ && S9xInterlaceField()) ? 1 : 0;
// OK, we have three cases here. Either there's no priority, priority is
// normal FirstSprite, or priority is FirstSprite+Y. The first two are
@ -770,7 +770,7 @@ static void DrawOBJS (int D)
void (*DrawClippedTile) (uint32, uint32, uint32, uint32, uint32, uint32) = NULL;
int PixWidth = IPPU.DoubleWidthPixels ? 2 : 1;
BG.InterlaceLine = S9xInterlaceField ? 8 : 0;
BG.InterlaceLine = S9xInterlaceField() ? 8 : 0;
GFX.Z1 = 2;
int sprite_limit = (Settings.MaxSpriteTilesPerLine == 128) ? 128 : 32;
@ -905,7 +905,7 @@ static void DrawBackground (int bg, uint8 Zh, uint8 Zl)
for (uint32 Y = GFX.StartY; Y <= GFX.EndY; Y += Lines)
{
uint32 Y2 = HiresInterlace ? Y * 2 + S9xInterlaceField : Y;
uint32 Y2 = HiresInterlace ? Y * 2 + S9xInterlaceField() : Y;
uint32 VOffset = LineData[Y].BG[bg].VOffset + (HiresInterlace ? 1 : 0);
uint32 HOffset = LineData[Y].BG[bg].HOffset;
int VirtAlign = ((Y2 + VOffset) & 7) >> (HiresInterlace ? 1 : 0);
@ -1299,7 +1299,7 @@ static void DrawBackgroundOffset (int bg, uint8 Zh, uint8 Zl, int VOffOff)
for (uint32 Y = GFX.StartY; Y <= GFX.EndY; Y++)
{
uint32 Y2 = HiresInterlace ? Y * 2 + S9xInterlaceField : Y;
uint32 Y2 = HiresInterlace ? Y * 2 + S9xInterlaceField() : Y;
uint32 VOff = LineData[Y].BG[2].VOffset - 1;
uint32 HOff = LineData[Y].BG[2].HOffset;
uint32 HOffsetRow = VOff >> Offset2Shift;

View File

@ -197,6 +197,11 @@ struct SMulti
extern CMemory Memory;
extern SMulti Multi;
inline bool S9xInterlaceField()
{
return (Memory.FillRAM[0x213F] & 0x80) >> 7;
}
void S9xAutoSaveSRAM (void);
bool8 LoadZip(const char *, uint32 *, uint8 *);

10
ppu.cpp
View File

@ -94,7 +94,7 @@ static int CyclesUntilNext (int hc, int vc)
// Add number of lines
total += (vc - vpos) * Timings.H_Max_Master;
// If line 240 is in there and we're odd, subtract a dot
if (vpos <= 240 && vc > 240 && S9xInterlaceField & !IPPU.Interlace)
if (vpos <= 240 && vc > 240 && S9xInterlaceField() & !IPPU.Interlace)
total -= ONE_DOT_CYCLE;
}
else
@ -105,11 +105,11 @@ static int CyclesUntilNext (int hc, int vc)
}
total += (Timings.V_Max - vpos) * Timings.H_Max_Master;
if (vpos <= 240 && S9xInterlaceField && !IPPU.Interlace)
if (vpos <= 240 && S9xInterlaceField() && !IPPU.Interlace)
total -= ONE_DOT_CYCLE;
total += (vc) * Timings.H_Max_Master;
if (vc > 240 && !S9xInterlaceField && !IPPU.Interlace)
if (vc > 240 && !S9xInterlaceField() && !IPPU.Interlace)
total -= ONE_DOT_CYCLE;
}
@ -146,7 +146,7 @@ void S9xUpdateIRQPositions (bool initial)
}
// Check for short dot scanline
if (v_pos == 240 && S9xInterlaceField && !IPPU.Interlace)
if (v_pos == 240 && S9xInterlaceField() && !IPPU.Interlace)
{
Timings.NextIRQTimer -= PPU.IRQHBeamPos <= 322 ? ONE_DOT_CYCLE / 2 : 0;
Timings.NextIRQTimer -= PPU.IRQHBeamPos <= 326 ? ONE_DOT_CYCLE / 2 : 0;
@ -164,7 +164,7 @@ void S9xUpdateIRQPositions (bool initial)
Timings.NextIRQTimer = CyclesUntilNext (PPU.HTimerPosition, PPU.VTimerPosition);
// Check for short dot scanline
int field = S9xInterlaceField;
int field = S9xInterlaceField();
if (PPU.VTimerPosition < CPU.V_Counter ||
(PPU.VTimerPosition == CPU.V_Counter && Timings.NextIRQTimer > Timings.H_Max))

View File

@ -187,8 +187,6 @@ struct STimings
bool8 APUAllowTimeOverflow;
};
#define S9xInterlaceField ((Memory.FillRAM[0x213F] & 0x80) >> 7)
struct SSettings
{
bool8 TraceDMA;