Optimize code (#1060)

This commit is contained in:
bladeoner 2023-03-17 17:14:53 +01:00 committed by GitHub
parent c4633bad27
commit 4e73f18af9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 27 additions and 58 deletions

View File

@ -2,7 +2,7 @@
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
This file is licensed under the Snes9x License. This file is licensed under the Snes9x License.
For further information, consult the LICENSE file in the root directory. For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/ \*****************************************************************************/
#ifndef _65C816_H_ #ifndef _65C816_H_
#define _65C816_H_ #define _65C816_H_

View File

@ -1307,7 +1307,7 @@ void S9xInitBSX (void)
uint8 *header = r1 ? Memory.ROM + 0x7FC0 : Memory.ROM + 0xFFC0; uint8 *header = r1 ? Memory.ROM + 0x7FC0 : Memory.ROM + 0xFFC0;
FlashMode = (header[0x18] & 0xEF) == 0x20 ? FALSE : TRUE; FlashMode = (header[0x18] & 0xEF) == 0x20 ? FALSE : TRUE;
FlashSize = (header[0x19] & 0x20) ? PSRAM_SIZE : FLASH_SIZE; FlashSize = FLASH_SIZE;
// Fix Block Allocation Flags // Fix Block Allocation Flags
// (for games that don't have it setup properly, // (for games that don't have it setup properly,
@ -1376,38 +1376,12 @@ void S9xResetBSX (void)
BSX.out_index = 0; BSX.out_index = 0;
memset(BSX.output, 0, sizeof(BSX.output)); memset(BSX.output, 0, sizeof(BSX.output));
if(bsxBiosLoadFailed) { // starting from the bios
BSX.MMC[0x02] = FlashMode ? 0x80: 0; BSX.MMC[0x02] = BSX.MMC[0x03] = BSX.MMC[0x05] = BSX.MMC[0x06] = 0x80;
BSX.MMC[0x09] = BSX.MMC[0x0B] = 0x80;
// per bios: run from psram or flash card BSX.MMC[0x07] = BSX.MMC[0x08] = 0x80;
if (FlashSize == PSRAM_SIZE) BSX.MMC[0x0E] = 0x80;
{
memcpy(PSRAM, FlashROM, PSRAM_SIZE);
BSX.MMC[0x01] = 0x80;
BSX.MMC[0x03] = 0x80;
BSX.MMC[0x04] = 0x80;
BSX.MMC[0x0C] = 0x80;
BSX.MMC[0x0D] = 0x80;
}
else
{
BSX.MMC[0x03] = 0x80;
BSX.MMC[0x05] = 0x80;
BSX.MMC[0x06] = 0x80;
BSX.MMC[0x09] = BSX.MMC[0x0B] = 0x80;
}
BSX.MMC[0x0E] = 0x80;
}
else {
// starting from the bios
BSX.MMC[0x02] = BSX.MMC[0x03] = BSX.MMC[0x05] = BSX.MMC[0x06] = 0x80;
BSX.MMC[0x09] = BSX.MMC[0x0B] = 0x80;
BSX.MMC[0x07] = BSX.MMC[0x08] = 0x80;
BSX.MMC[0x0E] = 0x80;
}
// default register values // default register values
BSX.PPU[0x2196 - BSXPPUBASE] = 0x10; BSX.PPU[0x2196 - BSXPPUBASE] = 0x10;

View File

@ -1406,7 +1406,7 @@ bOP(70Slow, RelativeSlow, CheckOverflow(), 0, CheckEmulation())
static void Op82 (void) static void Op82 (void)
{ {
S9xSetPCBase(ICPU.ShiftedPB + RelativeLong(JUMP)); S9xSetPCBase(ICPU.ShiftedPB + RelativeLong(JUMP));
AddCycles(ONE_CYCLE); AddCycles(ONE_CYCLE);
} }
static void Op82Slow (void) static void Op82Slow (void)

View File

@ -4,7 +4,6 @@
For further information, consult the LICENSE file in the root directory. For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/ \*****************************************************************************/
#ifndef _CPUOPS_H_ #ifndef _CPUOPS_H_
#define _CPUOPS_H_ #define _CPUOPS_H_

View File

@ -137,7 +137,7 @@ static const char *font[] =
" .###. .###. .###. .###. ", " .###. .###. .###. .###. ",
" .##. .##. .#####. .#. ", " .##. .##. .#####. .#. ",
" .#. .#. ..... . ", " .#. .#. ..... . ",
" . . ", " . . ",
" ", " ",
//2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678 //2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678
" ", " ",

View File

@ -793,7 +793,7 @@ static void DrawOBJS (int D)
BG.InterlaceLine = GFX.InterlaceFrame ? 8 : 0; BG.InterlaceLine = GFX.InterlaceFrame ? 8 : 0;
GFX.Z1 = 2; GFX.Z1 = 2;
int sprite_limit = (Settings.MaxSpriteTilesPerLine == 128) ? 128 : 32; int sprite_limit = (Settings.MaxSpriteTilesPerLine == 128) ? 128 : 32;
for (uint32 Y = GFX.StartY, Offset = Y * GFX.PPL; Y <= GFX.EndY; Y++, Offset += GFX.PPL) for (uint32 Y = GFX.StartY, Offset = Y * GFX.PPL; Y <= GFX.EndY; Y++, Offset += GFX.PPL)
{ {
int I = 0; int I = 0;

View File

@ -1421,7 +1421,7 @@ bool8 CMemory::LoadROM (const char *filename)
return FALSE; return FALSE;
S9xResetSaveTimer(FALSE); // reset oops timer here so that .oops file has rom name of previous rom S9xResetSaveTimer(FALSE); // reset oops timer here so that .oops file has rom name of previous rom
int32 totalFileSize; int32 totalFileSize;
do do
@ -1925,7 +1925,7 @@ bool8 CMemory::LoadSRTC (void)
return (FALSE); return (FALSE);
if (fread(RTCData.reg, 1, 20, fp) < 20) if (fread(RTCData.reg, 1, 20, fp) < 20)
memset (RTCData.reg, 0, 20); memset (RTCData.reg, 0, 20);
fclose(fp); fclose(fp);
return (TRUE); return (TRUE);
@ -1955,7 +1955,7 @@ void CMemory::ClearSRAM (bool8 onlyNonSavedSRAM)
return; return;
// TODO: If SRAM size changes change this value as well // TODO: If SRAM size changes change this value as well
memset(SRAM, SNESGameFixes.SRAMInitialValue, (32,0x80000)); memset(SRAM, SNESGameFixes.SRAMInitialValue, 0x80000);
} }
bool8 CMemory::LoadSRAM (const char *filename) bool8 CMemory::LoadSRAM (const char *filename)
@ -2621,8 +2621,8 @@ void CMemory::InitROM (void)
Settings.DisplayColor = BUILD_PIXEL(31, 31, 0); Settings.DisplayColor = BUILD_PIXEL(31, 31, 0);
SET_UI_COLOR(255, 255, 0); SET_UI_COLOR(255, 255, 0);
} }
// Use slight blue tint to indicate ROM was patched. // Use slight blue tint to indicate ROM was patched.
if (Settings.IsPatched) if (Settings.IsPatched)
{ {
Settings.DisplayColor = BUILD_PIXEL(26, 26, 31); Settings.DisplayColor = BUILD_PIXEL(26, 26, 31);
@ -3228,7 +3228,7 @@ void CMemory::Map_SA1LoROMMap (void)
SA1.WriteMap[c + 0] = SA1.WriteMap[c + 0x800] = FillRAM + 0x3000; SA1.WriteMap[c + 0] = SA1.WriteMap[c + 0x800] = FillRAM + 0x3000;
SA1.WriteMap[c + 1] = SA1.WriteMap[c + 0x801] = (uint8 *) MAP_NONE; SA1.WriteMap[c + 1] = SA1.WriteMap[c + 0x801] = (uint8 *) MAP_NONE;
} }
// SA-1 Banks 40->4f // SA-1 Banks 40->4f
for (int c = 0x400; c < 0x500; c++) for (int c = 0x400; c < 0x500; c++)
SA1.Map[c] = SA1.WriteMap[c] = (uint8*)MAP_HIROM_SRAM; SA1.Map[c] = SA1.WriteMap[c] = (uint8*)MAP_HIROM_SRAM;
@ -3769,7 +3769,6 @@ void CMemory::ApplyROMFixes (void)
if (Timings.DMACPUSync != 18) if (Timings.DMACPUSync != 18)
printf("DMA sync: %d\n", Timings.DMACPUSync); printf("DMA sync: %d\n", Timings.DMACPUSync);
// SRAM initial value // SRAM initial value
if (match_na("HITOMI3")) if (match_na("HITOMI3"))
{ {

View File

@ -393,7 +393,7 @@ static void flush_movie (void)
fseek(Movie.File, Movie.ControllerDataOffset, SEEK_SET); fseek(Movie.File, Movie.ControllerDataOffset, SEEK_SET);
if (!fwrite(Movie.InputBuffer, 1, Movie.BytesPerSample * (Movie.MaxSample + 1), Movie.File)) if (!fwrite(Movie.InputBuffer, 1, Movie.BytesPerSample * (Movie.MaxSample + 1), Movie.File))
printf ("Movie flush failed.\n"); printf ("Movie flush failed.\n");
} }
static void truncate_movie (void) static void truncate_movie (void)
@ -405,7 +405,7 @@ static void truncate_movie (void)
return; return;
if (ftruncate(fileno(Movie.File), Movie.ControllerDataOffset + Movie.BytesPerSample * (Movie.MaxSample + 1))) if (ftruncate(fileno(Movie.File), Movie.ControllerDataOffset + Movie.BytesPerSample * (Movie.MaxSample + 1)))
printf ("Couldn't truncate file.\n"); printf ("Couldn't truncate file.\n");
} }
static int read_movie_header (FILE *fd, SMovie *movie) static int read_movie_header (FILE *fd, SMovie *movie)
@ -492,7 +492,7 @@ static void write_movie_header (FILE *fd, SMovie *movie)
} }
if (!fwrite(buf, 1, SMV_HEADER_SIZE, fd)) if (!fwrite(buf, 1, SMV_HEADER_SIZE, fd))
printf ("Couldn't write movie header.\n"); printf ("Couldn't write movie header.\n");
} }
static void write_movie_extrarominfo (FILE *fd, SMovie *movie) static void write_movie_extrarominfo (FILE *fd, SMovie *movie)
@ -762,7 +762,7 @@ int S9xMovieCreate (const char *filename, uint8 controllers_mask, uint8 opts, co
} }
if (!fwrite(meta_buf, sizeof(uint16), metadata_length, fd)) if (!fwrite(meta_buf, sizeof(uint16), metadata_length, fd))
printf ("Failed writing movie metadata.\n"); printf ("Failed writing movie metadata.\n");
} }
Movie.ROMCRC32 = Memory.ROMCRC32; Movie.ROMCRC32 = Memory.ROMCRC32;
@ -930,7 +930,7 @@ void S9xMovieUpdate (bool addFrame)
Movie.MaxFrame = ++Movie.CurrentFrame; Movie.MaxFrame = ++Movie.CurrentFrame;
if (!fwrite((Movie.InputBufferPtr - Movie.BytesPerSample), 1, Movie.BytesPerSample, Movie.File)) if (!fwrite((Movie.InputBufferPtr - Movie.BytesPerSample), 1, Movie.BytesPerSample, Movie.File))
printf ("Error writing control data.\n"); printf ("Error writing control data.\n");
break; break;
} }
@ -956,7 +956,7 @@ void S9xMovieUpdateOnReset (void)
Movie.MaxFrame = ++Movie.CurrentFrame; Movie.MaxFrame = ++Movie.CurrentFrame;
if (!fwrite((Movie.InputBufferPtr - Movie.BytesPerSample), 1, Movie.BytesPerSample, Movie.File)) if (!fwrite((Movie.InputBufferPtr - Movie.BytesPerSample), 1, Movie.BytesPerSample, Movie.File))
printf ("Failed writing reset data.\n"); printf ("Failed writing reset data.\n");
} }
} }

View File

@ -99,11 +99,7 @@ __extension__
#endif #endif
typedef long long int64; typedef long long int64;
typedef unsigned long long uint64; typedef unsigned long long uint64;
#ifdef PTR_NOT_INT
typedef size_t pint; typedef size_t pint;
#else // __PTR_NOT_INT
typedef size_t pint;
#endif // __PTR_NOT_INT
#endif // __WIN32__ #endif // __WIN32__
#endif // HAVE_STDINT_H #endif // HAVE_STDINT_H
#endif // snes9x_types_defined #endif // snes9x_types_defined

View File

@ -786,7 +786,7 @@ uint8 S9xSA1GetByte (uint32 address)
case CMemory::MAP_BWRAM_BITMAP: case CMemory::MAP_BWRAM_BITMAP:
SA1.Cycles += ONE_CYCLE * 2; SA1.Cycles += ONE_CYCLE * 2;
address -= 0x600000; address -= 0x600000;
if (SA1.VirtualBitmapFormat == 2) if (SA1.VirtualBitmapFormat == 2)
return ((Memory.SRAM[(address >> 2) & 0x3ffff] >> ((address & 3) << 1)) & 3); return ((Memory.SRAM[(address >> 2) & 0x3ffff] >> ((address & 3) << 1)) & 3);
@ -795,7 +795,7 @@ uint8 S9xSA1GetByte (uint32 address)
case CMemory::MAP_BWRAM_BITMAP2: case CMemory::MAP_BWRAM_BITMAP2:
SA1.Cycles += ONE_CYCLE * 2; SA1.Cycles += ONE_CYCLE * 2;
address = (address & 0xffff) - 0x6000; address = (address & 0xffff) - 0x6000;
if (SA1.VirtualBitmapFormat == 2) if (SA1.VirtualBitmapFormat == 2)
return ((SA1.BWRAM[(address >> 2) & 0x3ffff] >> ((address & 3) << 1)) & 3); return ((SA1.BWRAM[(address >> 2) & 0x3ffff] >> ((address & 3) << 1)) & 3);

View File

@ -125,6 +125,7 @@ void S9xSA1MainLoop (void)
S9xSA1Opcode_IRQ(); S9xSA1Opcode_IRQ();
} }
} }
#undef CPU #undef CPU
int cycles = CPU.Cycles * 3; int cycles = CPU.Cycles * 3;
#define CPU SA1 #define CPU SA1

View File

@ -305,9 +305,9 @@ struct SSettings
bool8 OpenGLEnable; bool8 OpenGLEnable;
float SuperFXSpeedPerLine; float SuperFXSpeedPerLine;
bool8 SeparateEchoBuffer; bool8 SeparateEchoBuffer;
uint32 SuperFXClockMultiplier; uint32 SuperFXClockMultiplier;
int OverclockMode; int OverclockMode;
int OneClockCycle; int OneClockCycle;
int OneSlowClockCycle; int OneSlowClockCycle;
int TwoClockCycles; int TwoClockCycles;