Skip to content

Commit f46dddd

Browse files
committed
SNES: Adjusted many types to make Xtensa happier (significant perf gain)
1 parent 558dc3e commit f46dddd

File tree

15 files changed

+78
-369
lines changed

15 files changed

+78
-369
lines changed

snes9x-go/components/snes9x/apu/apu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void S9xDeinitAPU(void)
214214

215215
uint8 S9xAPUReadPort(uint32 port)
216216
{
217-
#if RETRO_LESS_ACCURATE
217+
#if RETRO_LESS_ACCURATE_APU
218218
if (++consecutive_accesses == 2)
219219
#endif
220220
S9xAPUExecute();
@@ -224,7 +224,7 @@ uint8 S9xAPUReadPort(uint32 port)
224224

225225
void S9xAPUWritePort(uint32 port, uint8 byte)
226226
{
227-
#if RETRO_LESS_ACCURATE
227+
#if RETRO_LESS_ACCURATE_APU
228228
if (++consecutive_accesses == 2)
229229
#endif
230230
S9xAPUExecute();

snes9x-go/components/snes9x/cpuexec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ IRAM_ATTR void S9xMainLoop (void)
4141

4242
for (;;)
4343
{
44-
#if RETRO_LESS_ACCURATE
44+
#if (RETRO_LESS_ACCURATE_CPU || RETRO_LESS_ACCURATE_MEM)
4545
while (CPU.Cycles >= CPU.NextEvent)
4646
S9xDoHEventProcessing();
4747
#endif
@@ -138,7 +138,7 @@ IRAM_ATTR void S9xMainLoop (void)
138138
if (!(CPU.Flags & FRAME_ADVANCE_FLAG))
139139
#endif
140140
{
141-
S9xSyncSpeed();
141+
// S9xSyncSpeed();
142142
}
143143

144144
break;

snes9x-go/components/snes9x/cpuops.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@
1616
#include "missing.h"
1717
#endif
1818

19-
#if RETRO_LESS_ACCURATE
19+
#if RETRO_LESS_ACCURATE_CPU
2020
#define AddCycles(n) { CPU.Cycles += (n); }
2121
#else
22-
// #define AddCycles(n) { CPU.Cycles += (n); while (CPU.Cycles >= CPU.NextEvent) S9xDoHEventProcessing(); }
22+
#define AddCycles(n) { CPU.Cycles += (n); while (CPU.Cycles >= CPU.NextEvent) S9xDoHEventProcessing(); }
2323
#endif
2424

2525
#include "cpuaddr.h"
2626
#include "cpuops.h"
2727
#include "cpumacro.h"
2828

29-
#include <esp_attr.h>
30-
3129
/* ADC ********************************************************************* */
3230

3331
static void Op69M1 (void)

snes9x-go/components/snes9x/getset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "cpuexec.h"
1111
#include "dsp.h"
1212

13-
#if RETRO_LESS_ACCURATE
13+
#if RETRO_LESS_ACCURATE_MEM
1414
#define addCyclesInMemoryAccess \
1515
if (!CPU.InDMAorHDMA) \
1616
{ \

snes9x-go/components/snes9x/gfx.cpp

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,18 @@ void S9xBuildDirectColourMaps (void)
136136
void S9xStartScreenRefresh (void)
137137
{
138138
GFX.InterlaceFrame = !GFX.InterlaceFrame;
139-
if (GFX.DoInterlace)
140-
GFX.DoInterlace--;
141139

142140
if (IPPU.RenderThisFrame)
143141
{
144-
if (!GFX.DoInterlace || !GFX.InterlaceFrame)
142+
if (!S9xInitUpdate())
145143
{
146-
if (!S9xInitUpdate())
147-
{
148-
IPPU.RenderThisFrame = FALSE;
149-
return;
150-
}
144+
IPPU.RenderThisFrame = FALSE;
145+
return;
146+
}
151147

152-
S9xGraphicsScreenResize();
148+
S9xGraphicsScreenResize();
153149

154-
IPPU.RenderedFramesCount++;
155-
}
150+
IPPU.RenderedFramesCount++;
156151

157152
PPU.MosaicStart = 0;
158153
PPU.RecomputeClipWindows = TRUE;
@@ -181,28 +176,20 @@ void S9xEndScreenRefresh (void)
181176
{
182177
FLUSH_REDRAW();
183178

184-
if (GFX.DoInterlace && GFX.InterlaceFrame == 0)
179+
if (IPPU.ColorsChanged)
185180
{
186-
S9xControlEOF();
187-
S9xContinueUpdate(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight);
181+
uint32 saved = PPU.CGDATA[0];
182+
IPPU.ColorsChanged = FALSE;
183+
S9xSetPalette();
184+
PPU.CGDATA[0] = saved;
188185
}
189-
else
190-
{
191-
if (IPPU.ColorsChanged)
192-
{
193-
uint32 saved = PPU.CGDATA[0];
194-
IPPU.ColorsChanged = FALSE;
195-
S9xSetPalette();
196-
PPU.CGDATA[0] = saved;
197-
}
198186

199-
S9xControlEOF();
187+
S9xControlEOF();
200188

201-
if (Settings.AutoDisplayMessages)
202-
S9xDisplayMessages(GFX.Screen, GFX.RealPPL, IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, 1);
189+
if (Settings.AutoDisplayMessages)
190+
S9xDisplayMessages(GFX.Screen, GFX.RealPPL, IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, 1);
203191

204-
S9xDeinitUpdate(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight);
205-
}
192+
S9xDeinitUpdate(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight);
206193
}
207194
else
208195
S9xControlEOF();
@@ -291,8 +278,6 @@ static inline void RenderScreen (bool8 sub)
291278
if (!sub)
292279
{
293280
GFX.S = GFX.Screen;
294-
if (GFX.DoInterlace && GFX.InterlaceFrame)
295-
GFX.S += GFX.RealPPL;
296281
GFX.DB = GFX.ZBuffer;
297282
GFX.Clip = IPPU.Clip[0];
298283
BGActive = Memory.FillRAM[0x212c] & ~Settings.BG_Forced;
@@ -450,8 +435,6 @@ void S9xUpdateScreen (void)
450435
const uint16 black = BUILD_PIXEL(0, 0, 0);
451436

452437
GFX.S = GFX.Screen + GFX.StartY * GFX.PPL;
453-
if (GFX.DoInterlace && GFX.InterlaceFrame)
454-
GFX.S += GFX.RealPPL;
455438

456439
for (int l = GFX.StartY; l <= GFX.EndY; l++, GFX.S += GFX.PPL)
457440
for (int x = 0; x < IPPU.RenderedScreenWidth; x++)

snes9x-go/components/snes9x/gfx.h

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ struct SGFX
2828
uint8 Z1; // depth for comparison
2929
uint8 Z2; // depth to save
3030
uint32 FixedColour;
31-
uint8 DoInterlace;
32-
uint8 InterlaceFrame;
31+
uint32 InterlaceFrame;
3332
uint32 StartY;
3433
uint32 EndY;
35-
bool8 ClipColors;
34+
uint32 ClipColors;
3635
uint8 OBJWidths[128];
3736
uint8 OBJVisibleTiles[128];
3837

@@ -45,8 +44,8 @@ struct SGFX
4544

4645
struct
4746
{
48-
int8 Sprite;
49-
uint8 Line;
47+
int32 Sprite;
48+
uint32 Line;
5049
} OBJ[32];
5150
} OBJLines[SNES_HEIGHT_EXTENDED];
5251

@@ -65,7 +64,6 @@ struct SGFX
6564

6665
const char *InfoString;
6766
uint32 InfoStringTimeout;
68-
char FrameDisplayString[256];
6967
};
7068

7169
struct SBG
@@ -85,8 +83,8 @@ struct SBG
8583
uint32 StartPalette;
8684
uint32 PaletteShift;
8785
uint32 PaletteMask;
88-
uint8 EnableMath;
89-
uint8 InterlaceLine;
86+
uint32 EnableMath;
87+
uint32 InterlaceLine;
9088

9189
uint32 Buffered;
9290
uint32 BufferedFlip;
@@ -104,14 +102,14 @@ struct SLineData
104102

105103
struct SLineMatrixData
106104
{
107-
short MatrixA;
108-
short MatrixB;
109-
short MatrixC;
110-
short MatrixD;
111-
short CentreX;
112-
short CentreY;
113-
short M7HOFS;
114-
short M7VOFS;
105+
int16 MatrixA;
106+
int16 MatrixB;
107+
int16 MatrixC;
108+
int16 MatrixD;
109+
int16 CentreX;
110+
int16 CentreY;
111+
int16 M7HOFS;
112+
int16 M7VOFS;
115113
};
116114

117115
extern uint16 BlackColourMap[256];

snes9x-go/components/snes9x/memmap.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
#include <string>
88
#include <numeric>
99
#include <assert.h>
10-
1110
#include <ctype.h>
12-
#include <sys/stat.h>
13-
#include <rg_system.h>
1411

1512
#include "snes9x.h"
1613
#include "memmap.h"

snes9x-go/components/snes9x/ppu.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,9 +1734,6 @@ void S9xSoftResetPPU (void)
17341734
PPU.OBJ[c].Size = 0;
17351735
}
17361736

1737-
PPU.OBJThroughMain = FALSE;
1738-
PPU.OBJThroughSub = FALSE;
1739-
PPU.OBJAddition = FALSE;
17401737
PPU.OBJNameBase = 0;
17411738
PPU.OBJNameSelect = 0;
17421739
PPU.OBJSizeSelect = 0;
@@ -1825,7 +1822,6 @@ void S9xSoftResetPPU (void)
18251822
memset(IPPU.TileCache, 0, sizeof(IPPU.TileCache));
18261823
PPU.VRAMReadBuffer = 0; // XXX: FIXME: anything better?
18271824
GFX.InterlaceFrame = 0;
1828-
GFX.DoInterlace = 0;
18291825
IPPU.Interlace = FALSE;
18301826
IPPU.InterlaceOBJ = FALSE;
18311827
IPPU.DoubleWidthPixels = FALSE;

snes9x-go/components/snes9x/ppu.h

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ struct SPPU
8383
struct
8484
{
8585
bool8 High;
86-
uint8 Increment;
87-
uint16 Address;
88-
uint16 Mask1;
89-
uint16 FullGraphicCount;
90-
uint16 Shift;
86+
uint32 Increment;
87+
uint32 Address;
88+
uint32 Mask1;
89+
uint32 FullGraphicCount;
90+
uint32 Shift;
9191
} VMA;
9292

9393
uint32 WRAM;
@@ -112,9 +112,6 @@ struct SPPU
112112
uint16 CGDATA[256];
113113

114114
struct SOBJ OBJ[128];
115-
bool8 OBJThroughMain;
116-
bool8 OBJThroughSub;
117-
bool8 OBJAddition;
118115
uint16 OBJNameBase;
119116
uint16 OBJNameSelect;
120117
uint8 OBJSizeSelect;
@@ -150,14 +147,14 @@ struct SPPU
150147
bool8 Mode7HFlip;
151148
bool8 Mode7VFlip;
152149
uint8 Mode7Repeat;
153-
short MatrixA;
154-
short MatrixB;
155-
short MatrixC;
156-
short MatrixD;
157-
short CentreX;
158-
short CentreY;
159-
short M7HOFS;
160-
short M7VOFS;
150+
int16 MatrixA;
151+
int16 MatrixB;
152+
int16 MatrixC;
153+
int16 MatrixD;
154+
int16 CentreX;
155+
int16 CentreY;
156+
int16 M7HOFS;
157+
int16 M7VOFS;
161158

162159
uint8 Mosaic;
163160
uint8 MosaicStart;
@@ -250,7 +247,7 @@ static inline void S9xUpdateVRAMReadBuffer()
250247

251248
static inline void REGISTER_2104 (uint8 Byte)
252249
{
253-
const uint16 SignExtend[2] = {0x0000, 0xff00};
250+
const uint32 SignExtend[2] = {0x0000, 0xff00};
254251

255252
if (!(PPU.OAMFlip & 1))
256253
{
@@ -260,7 +257,7 @@ static inline void REGISTER_2104 (uint8 Byte)
260257

261258
if (PPU.OAMAddr & 0x100)
262259
{
263-
int addr = ((PPU.OAMAddr & 0x10f) << 1) + (PPU.OAMFlip & 1);
260+
uint32 addr = ((PPU.OAMAddr & 0x10f) << 1) + (PPU.OAMFlip & 1);
264261
if (Byte != PPU.OAMData[addr])
265262
{
266263
FLUSH_REDRAW();
@@ -283,8 +280,8 @@ static inline void REGISTER_2104 (uint8 Byte)
283280
else if (PPU.OAMFlip & 1)
284281
{
285282
PPU.OAMWriteRegister &= 0x00ff;
286-
uint8 lowbyte = (uint8) (PPU.OAMWriteRegister);
287-
uint8 highbyte = Byte;
283+
uint32 lowbyte = (uint8) (PPU.OAMWriteRegister);
284+
uint32 highbyte = Byte;
288285
PPU.OAMWriteRegister |= Byte << 8;
289286

290287
int addr = (PPU.OAMAddr << 1);

snes9x-go/components/snes9x/snapshot.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,6 @@ static FreezeData SnapPPU[] =
266266
O(112), O(113), O(114), O(115), O(116), O(117), O(118), O(119),
267267
O(120), O(121), O(122), O(123), O(124), O(125), O(126), O(127),
268268
#undef O
269-
INT_ENTRY(6, OBJThroughMain),
270-
INT_ENTRY(6, OBJThroughSub),
271-
INT_ENTRY(6, OBJAddition),
272269
INT_ENTRY(6, OBJNameBase),
273270
INT_ENTRY(6, OBJNameSelect),
274271
INT_ENTRY(6, OBJSizeSelect),
@@ -669,14 +666,6 @@ uint32 S9xFreezeSize()
669666
return stream.size();
670667
}
671668

672-
bool8 S9xFreezeGameMem (uint8 *buf, uint32 bufSize)
673-
{
674-
memStream mStream(buf, bufSize);
675-
S9xFreezeToStream(&mStream);
676-
677-
return (TRUE);
678-
}
679-
680669
bool8 S9xFreezeGame (const char *filename)
681670
{
682671
STREAM stream = NULL;
@@ -699,14 +688,6 @@ bool8 S9xFreezeGame (const char *filename)
699688

700689
// QuickLoad
701690

702-
int S9xUnfreezeGameMem (const uint8 *buf, uint32 bufSize)
703-
{
704-
memStream stream(buf, bufSize);
705-
int result = S9xUnfreezeFromStream(&stream);
706-
707-
return result;
708-
}
709-
710691
bool8 S9xUnfreezeGame (const char *filename)
711692
{
712693
STREAM stream = NULL;
@@ -1028,12 +1009,11 @@ int S9xUnfreezeFromStream (STREAM stream)
10281009
IPPU.RenderThisFrame = TRUE;
10291010

10301011
GFX.InterlaceFrame = Timings.InterlaceField;
1031-
GFX.DoInterlace = 0;
10321012

10331013
S9xGraphicsScreenResize();
10341014

10351015
if (Settings.FastSavestates == 0)
1036-
memset(GFX.Screen,0,GFX.Pitch * MAX_SNES_HEIGHT);
1016+
memset(GFX.Screen,0,GFX.Pitch * SNES_HEIGHT_EXTENDED);
10371017

10381018
S9xControlPostLoadState(&ctl_snap);
10391019
}

snes9x-go/components/snes9x/snapshot.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525

2626
bool8 S9xFreezeGame (const char *);
2727
uint32 S9xFreezeSize (void);
28-
bool8 S9xFreezeGameMem (uint8 *,uint32);
2928
bool8 S9xUnfreezeGame (const char *);
30-
int S9xUnfreezeGameMem (const uint8 *,uint32);
3129
void S9xFreezeToStream (STREAM);
3230
int S9xUnfreezeFromStream (STREAM);
3331

0 commit comments

Comments
 (0)