From 9902256814785f0b3f08d336a98c481c296ac7e5 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Wed, 19 Jan 2011 03:07:39 +0100 Subject: [PATCH] removing lots of unused code --- clip.cpp | 2 +- display.h | 62 ------- gfx.cpp | 5 +- gfx.h | 8 +- hacks.cpp | 3 +- memmap.cpp | 1 - netplay.cpp | 1 - platform/config.cpp | 1 - platform/sdl.cpp | 1 - platform/sdli.cpp | 19 +-- platform/sdlv.cpp | 5 +- platform/sdlvscalers.cpp | 1 - port.h | 13 +- ppu.cpp | 8 +- ppu.h | 2 + screenshot.cpp | 1 - sdd1.cpp | 31 ++-- snaporig.cpp | 414 ---------------------------------------------- snaporig.h | 330 ------------------------------------ snapshot.cpp | 3 +- spc700.cpp | 1 - srtc.h | 4 +- tile.cpp | 1 - 23 files changed, 53 insertions(+), 864 deletions(-) delete mode 100644 display.h delete mode 100644 snaporig.cpp delete mode 100644 snaporig.h diff --git a/clip.cpp b/clip.cpp index 52859b5..45ad860 100644 --- a/clip.cpp +++ b/clip.cpp @@ -156,7 +156,7 @@ void ComputeClipWindows () struct Band Win2[3]; uint32 Window1Enabled = 0; uint32 Window2Enabled = 0; - bool8_32 invert = (w == 5 && + bool invert = (w == 5 && ((c == 1 && (Memory.FillRAM [0x2130] & 0x30) == 0x10) || (c == 0 && (Memory.FillRAM [0x2130] & 0xc0) == 0x40))); diff --git a/display.h b/display.h deleted file mode 100644 index 1b75875..0000000 --- a/display.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - * - * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and - * Jerremy Koot (jkoot@snes9x.com) - * - * Super FX C emulator code - * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and - * Gary Henderson. - * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_. - * - * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson. - * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_. - * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com). - * - * DOS port code contains the works of other authors. See headers in - * individual files. - * - * Snes9x homepage: http://www.snes9x.com - * - * Permission to use, copy, modify and distribute Snes9x in both binary and - * source form, for non-commercial purposes, is hereby granted without fee, - * providing that this license information and copyright notice appear with - * all copies and any derived work. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event shall the authors be held liable for any damages - * arising from the use of this software. - * - * Snes9x is freeware for PERSONAL USE only. Commercial users should - * seek permission of the copyright holders first. Commercial use includes - * charging money for Snes9x or software derived from Snes9x. - * - * The copyright holders request that bug fixes and improvements to the code - * should be forwarded to them so everyone can benefit from the modifications - * in future versions. - * - * Super NES and Super Nintendo Entertainment System are trademarks of - * Nintendo Co., Limited and its subsidiary companies. - */ -#ifndef _DISPLAY_H_ -#define _DISPLAY_H_ - -START_EXTERN_C -void S9xTextMode (); -void S9xGraphicsMode (); -const char *S9xParseArgs (int argc, const char **argv); -void S9xParseArg (char **argv, int &index, int argc); -void S9xExtraUsage (); -uint32 S9xReadJoypad (int which1_0_to_4); -bool8_32 S9xReadMousePosition (int which1_0_to_1, int &x, int &y, uint32 &buttons); -bool8_32 S9xReadSuperScopePosition (int &x, int &y, uint32 &buttons); - -void S9xSetInfoString (const char * fmt, ...); - -void S9xNextController (); - -bool8_32 S9xOpenSnapshotFile (const char *base, bool8_32 read_only, STREAM *file); -void S9xCloseSnapshotFile (STREAM file); -END_EXTERN_C - -#endif diff --git a/gfx.cpp b/gfx.cpp index a2714f5..44dd230 100644 --- a/gfx.cpp +++ b/gfx.cpp @@ -46,7 +46,6 @@ #include "memmap.h" #include "ppu.h" #include "cpuexec.h" -#include "display.h" #include "gfx.h" #include "apu.h" #include "cheats.h" @@ -107,7 +106,7 @@ extern uint8 Mode7Depths [2]; #define BLACK BUILD_PIXEL(0,0,0) -bool8_32 S9xGraphicsInit () +bool8 S9xGraphicsInit () { register uint32 PixelOdd = 1; register uint32 PixelEven = 2; @@ -368,7 +367,7 @@ bool8_32 S9xGraphicsInit () } } - return (TRUE); + return TRUE; } void S9xGraphicsDeinit (void) diff --git a/gfx.h b/gfx.h index 85b4416..6df3a05 100644 --- a/gfx.h +++ b/gfx.h @@ -225,16 +225,18 @@ void S9xBuildDirectColourMaps (); // port. extern struct SGFX GFX; -bool8_32 S9xGraphicsInit (); +bool8 S9xGraphicsInit (); void S9xGraphicsDeinit(); -bool8_32 S9xInitUpdate (void); -bool8_32 S9xDeinitUpdate (int Width, int Height); +bool8 S9xInitUpdate (void); +bool8 S9xDeinitUpdate (int Width, int Height); void S9xSyncSpeed (); #ifdef GFX_MULTI_FORMAT bool8_32 S9xSetRenderPixelFormat (int format); #endif +void S9xSetInfoString(const char * fmt, ...); + END_EXTERN_C #endif diff --git a/hacks.cpp b/hacks.cpp index 191c704..7226738 100644 --- a/hacks.cpp +++ b/hacks.cpp @@ -151,7 +151,8 @@ void S9xHacksLoadFile(const char * file) line = (char*) malloc(kLineBufferSize + 1); do { - fgets(line, kLineBufferSize, fp); + line = fgets(line, kLineBufferSize, fp); + if (!line) break; char *pos = strchr(line, '|'); if (!pos) continue; diff --git a/memmap.cpp b/memmap.cpp index 9113f41..95bfab2 100644 --- a/memmap.cpp +++ b/memmap.cpp @@ -47,7 +47,6 @@ #include "memmap.h" #include "cpuexec.h" #include "ppu.h" -#include "display.h" #include "cheats.h" #include "apu.h" #include "sa1.h" diff --git a/netplay.cpp b/netplay.cpp index 55f3671..8981188 100644 --- a/netplay.cpp +++ b/netplay.cpp @@ -191,7 +191,6 @@ #include "netplay.h" #include "memmap.h" #include "snapshot.h" -#include "display.h" void S9xNPClientLoop (void *); bool8 S9xNPLoadROM (uint32 len); diff --git a/platform/config.cpp b/platform/config.cpp index 91b3a47..acb44ec 100644 --- a/platform/config.cpp +++ b/platform/config.cpp @@ -6,7 +6,6 @@ #include "platform.h" #include "port.h" #include "snes9x.h" -#include "display.h" #if CONF_GUI #include "osso.h" diff --git a/platform/sdl.cpp b/platform/sdl.cpp index 46786b2..c9d641c 100644 --- a/platform/sdl.cpp +++ b/platform/sdl.cpp @@ -9,7 +9,6 @@ #include "cpuexec.h" #include "gfx.h" #include "ppu.h" -#include "display.h" #include "memmap.h" #include "soundux.h" #include "hacks.h" diff --git a/platform/sdli.cpp b/platform/sdli.cpp index 63265b3..9c63398 100644 --- a/platform/sdli.cpp +++ b/platform/sdli.cpp @@ -3,7 +3,6 @@ #include "platform.h" #include "snes9x.h" -#include "display.h" #include "sdlv.h" // Dispatching video-related events #if CONF_ZEEMOTE @@ -194,22 +193,22 @@ uint32 S9xReadJoypad (int which) @param buttons The buttons return value is a bit-wise mask of the two SNES mouse buttons, bit 0 for button 1 (left) and bit 1 for button 2 (right). */ -bool8 S9xReadMousePosition(int which1, int& x, int& y, uint32& buttons) +bool8 S9xReadMousePosition(int which, int *x, int *y, uint32 *buttons) { - if (which1 != 0) return FALSE; + if (which != 0) return FALSE; - x = mouse.x; - y = mouse.y; - buttons = mouse.pressed ? 1 : 0; + *x = mouse.x; + *y = mouse.y; + *buttons = mouse.pressed ? 1 : 0; return TRUE; } -bool8 S9xReadSuperScopePosition(int& x, int& y, uint32& buttons) +bool8 S9xReadSuperScopePosition(int *x, int *y, uint32 *buttons) { - x = mouse.x; - y = mouse.y; - buttons = mouse.pressed ? 8 : 0; + *x = mouse.x; + *y = mouse.y; + *buttons = mouse.pressed ? 8 : 0; return TRUE; } diff --git a/platform/sdlv.cpp b/platform/sdlv.cpp index 5b54a1d..7504231 100644 --- a/platform/sdlv.cpp +++ b/platform/sdlv.cpp @@ -7,7 +7,6 @@ #include "snes9x.h" #include "platform.h" -#include "display.h" #include "gfx.h" #include "ppu.h" #include "sdlv.h" @@ -228,7 +227,7 @@ bool videoEventFilter(const SDL_Event& event) while initializing video output. @return TRUE if we should render the frame. */ -bool8_32 S9xInitUpdate () +bool8 S9xInitUpdate () { scaler->prepare(); @@ -247,7 +246,7 @@ bool8_32 S9xInitUpdate () 478 if hi-res. SNES screen modes are being supported. */ // TODO Above. -bool8_32 S9xDeinitUpdate (int width, int height) +bool8 S9xDeinitUpdate (int width, int height) { scaler->finish(); diff --git a/platform/sdlvscalers.cpp b/platform/sdlvscalers.cpp index dd65495..8afbdf8 100644 --- a/platform/sdlvscalers.cpp +++ b/platform/sdlvscalers.cpp @@ -14,7 +14,6 @@ #endif #include "snes9x.h" -#include "display.h" #include "platform.h" #include "sdlv.h" diff --git a/port.h b/port.h index b24a6e2..b1cf4a6 100644 --- a/port.h +++ b/port.h @@ -73,13 +73,7 @@ typedef int16_t int16; typedef int32_t int32; typedef int64_t int64; -//For Debugging Purposes: - typedef uint8_t bool8_32; -typedef uint8_t uint8_32; -typedef uint16_t uint16_32; -typedef int8_t int8_32; -typedef int16_t int16_32; //Defines for Extern C #ifdef __cplusplus @@ -149,6 +143,13 @@ void PathSplit(const char *path, char *drive, char *dir, char *fname, char *ext) const char * PathBasename(const char * path); END_EXTERN_C +// Input / output functions +START_EXTERN_C +uint32 S9xReadJoypad(int which1_0_to_4); +bool8 S9xReadMousePosition(int which1_0_to_1, int *x, int *y, uint32 *buttons); +bool8 S9xReadSuperScopePosition(int *x, int *y, uint32 *buttons); +END_EXTERN_C + // Stream functions, used when opening ROMs and snapshots. #ifdef ZLIB #include diff --git a/ppu.cpp b/ppu.cpp index 7dcc9cf..7c22d69 100644 --- a/ppu.cpp +++ b/ppu.cpp @@ -46,11 +46,7 @@ #include "apu.h" #include "dma.h" #include "gfx.h" -#include "display.h" #include "sa1.h" -#ifndef _SNESPPC -//#include "netplay.h" -#endif #include "sdd1.h" #include "srtc.h" @@ -2399,7 +2395,7 @@ void S9xProcessMouse(int which1) if ((IPPU.Controller == SNES_MOUSE || IPPU.Controller == SNES_MOUSE_SWAPPED) - && S9xReadMousePosition(which1, x, y, buttons)) + && S9xReadMousePosition(which1, &x, &y, &buttons)) { int delta_x, delta_y; #define MOUSE_SIGNATURE 0x1 @@ -2467,7 +2463,7 @@ void ProcessSuperScope() uint32 buttons; if (IPPU.Controller == SNES_SUPERSCOPE - && S9xReadSuperScopePosition(x, y, buttons)) + && S9xReadSuperScopePosition(&x, &y, &buttons)) { #define SUPERSCOPE_SIGNATURE 0x00ff uint32 scope; diff --git a/ppu.h b/ppu.h index 8a84838..4cde0e6 100644 --- a/ppu.h +++ b/ppu.h @@ -237,6 +237,8 @@ struct SDMA { }; START_EXTERN_C +void S9xNextController (); + void S9xUpdateScreen (); void S9xResetPPU (); void S9xFixColourBrightness (); diff --git a/screenshot.cpp b/screenshot.cpp index c810a55..157533a 100644 --- a/screenshot.cpp +++ b/screenshot.cpp @@ -107,7 +107,6 @@ #include "snes9x.h" #include "memmap.h" -#include "display.h" #include "gfx.h" #include "ppu.h" #include "screenshot.h" diff --git a/sdd1.cpp b/sdd1.cpp index fee2389..54f395e 100644 --- a/sdd1.cpp +++ b/sdd1.cpp @@ -46,7 +46,6 @@ #include "memmap.h" #include "ppu.h" #include "sdd1.h" -#include "display.h" static int S9xCompareSDD1IndexEntries (const void *p1, const void *p2) { @@ -123,7 +122,7 @@ void S9xLoadSDD1Data () if (strlen (index) && strlen (data)) { FILE *fs = fopen (index, "rb"); - int len = 0; + size_t len = 0; if (fs) { // Index is stored as a sequence of entries, each entry being @@ -136,7 +135,10 @@ void S9xLoadSDD1Data () len = ftell (fs); rewind (fs); Memory.SDD1Index = (uint8 *) malloc (len); - fread (Memory.SDD1Index, 1, len, fs); + if (fread (Memory.SDD1Index, 1, len, fs) < len) { + fprintf(stderr, "Failed to fully read SDD1 index file %s\n", + data); + } fclose (fs); Memory.SDD1Entries = len / 12; } else { @@ -156,7 +158,10 @@ void S9xLoadSDD1Data () len = ftell (fs); rewind (fs); Memory.SDD1Data = (uint8 *) malloc (len); - fread (Memory.SDD1Data, 1, len, fs); + if (fread (Memory.SDD1Data, 1, len, fs) < len) { + fprintf(stderr, "Failed to fully read SDD1 data file %s\n", + data); + } fclose (fs); } printf("SDD1: data pack: %s\n", PathBasename(data)); @@ -242,16 +247,16 @@ void S9xSDD1SaveLoggedData () S9xCompareSDD1LoggedDataEntries); const char * sdd1_dat_file = S9xGetFilename(FILE_SDD1_DAT); - FILE *fs = fopen (sdd1_dat_file, "wb"); + FILE *fs = fopen(sdd1_dat_file, "wb"); if (fs) { - fwrite (Memory.SDD1LoggedData, 8, - Memory.SDD1LoggedDataCount, fs); - fclose (fs); -#if defined(__linux) - chown (sdd1_dat_file, getuid (), getgid ()); -#endif + long c = fwrite(Memory.SDD1LoggedData, 8, + Memory.SDD1LoggedDataCount, fs); + if (c < Memory.SDD1LoggedDataCount) { + fprintf(stderr, "Failed to write sdd1 log data\n"); + } + fclose(fs); } Memory.SDD1LoggedDataCountPrev = Memory.SDD1LoggedDataCount; } @@ -265,8 +270,8 @@ void S9xSDD1LoadLoggedData () if (fs) { - int c = fread (Memory.SDD1LoggedData, 8, - MEMMAP_MAX_SDD1_LOGGED_ENTRIES, fs); + long c = fread (Memory.SDD1LoggedData, 8, + MEMMAP_MAX_SDD1_LOGGED_ENTRIES, fs); if (c != EOF) Memory.SDD1LoggedDataCount = Memory.SDD1LoggedDataCountPrev = c; diff --git a/snaporig.cpp b/snaporig.cpp deleted file mode 100644 index 833e1f9..0000000 --- a/snaporig.cpp +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - * - * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and - * Jerremy Koot (jkoot@snes9x.com) - * - * Super FX C emulator code - * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and - * Gary Henderson. - * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_. - * - * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson. - * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_. - * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com). - * - * DOS port code contains the works of other authors. See headers in - * individual files. - * - * Snes9x homepage: http://www.snes9x.com - * - * Permission to use, copy, modify and distribute Snes9x in both binary and - * source form, for non-commercial purposes, is hereby granted without fee, - * providing that this license information and copyright notice appear with - * all copies and any derived work. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event shall the authors be held liable for any damages - * arising from the use of this software. - * - * Snes9x is freeware for PERSONAL USE only. Commercial users should - * seek permission of the copyright holders first. Commercial use includes - * charging money for Snes9x or software derived from Snes9x. - * - * The copyright holders request that bug fixes and improvements to the code - * should be forwarded to them so everyone can benefit from the modifications - * in future versions. - * - * Super NES and Super Nintendo Entertainment System are trademarks of - * Nintendo Co., Limited and its subsidiary companies. - */ -#include -#include -#include - -#if defined(__unix) || defined(__linux) || defined(__sun) || defined(__DJGPP) -//#include -#include -#include -#endif - -#include "snapshot.h" -#include "snaporig.h" -#include "memmap.h" -#include "snes9x.h" -#include "65c816.h" -#include "ppu.h" -#include "cpuexec.h" -#include "display.h" -#include "apu.h" -#include "soundux.h" - -struct SOrigPPU OrigPPU; -struct SOrigDMA OrigDMA [8]; -struct SOrigRegisters OrigRegisters; -struct SOrigCPUState OrigCPU; -struct SOrigAPU OrigAPU; -SOrigSoundData OrigSoundData; -struct SOrigAPURegisters OrigAPURegisters; -char ROMFilename [1025]; - -static int ReadOrigSnapshot (STREAM); - -bool8_32 S9xLoadOrigSnapshot (const char *filename) -{ - STREAM snapshot = NULL; - if (S9xOpenSnapshotFile (filename, TRUE, &snapshot)) - { - int result; - if ((result = ReadOrigSnapshot (snapshot)) != SUCCESS) - { - S9xCloseSnapshotFile (snapshot); - return (FALSE); - } - S9xCloseSnapshotFile (snapshot); - return (TRUE); - } - return (FALSE); -} - -#ifdef _SNESPPC -#pragma warning(disable : 4018) -#endif -static int ReadBlock (const char *key, void *block, int max_len, STREAM snap) -{ - char buffer [20]; - int len = 0; - int rem = 0; - - if (READ_STREAM (buffer, 11, snap) != 11 || - strncmp (buffer, key, 4) != 0 || - (len = atoi (&buffer [4])) == 0) - return (WRONG_FORMAT); - - if (len > max_len) - { - rem = len - max_len; - len = max_len; - } - if (READ_STREAM (block, len, snap) != len) - return (WRONG_FORMAT); - - if (rem) - { - char *junk = new char [rem]; - READ_STREAM (junk, rem, snap); - delete junk; - } - - return (SUCCESS); -} - -static int ReadOrigSnapshot (STREAM snap) -{ - char buffer [_MAX_PATH]; - char rom_filename [_MAX_PATH]; - int result; - int i; - int j; - - int version; - int len = strlen (ORIG_SNAPSHOT_MAGIC) + 1 + 4 + 1; - if (READ_STREAM (buffer, len, snap) != len) - return (WRONG_FORMAT); - if (strncmp (buffer, ORIG_SNAPSHOT_MAGIC, strlen (ORIG_SNAPSHOT_MAGIC)) != 0) - return (WRONG_FORMAT); - if ((version = atoi (&buffer [strlen (SNAPSHOT_MAGIC) + 1])) > ORIG_SNAPSHOT_VERSION) - return (WRONG_VERSION); - - if ((result = ReadBlock ("NAM:", rom_filename, _MAX_PATH, snap)) != SUCCESS) - return (result); - - if ((result = ReadBlock ("HiR:", buffer, 0x41, snap)) != SUCCESS) - return (result); - - if (strcasecmp (rom_filename, Memory.ROMFilename) != 0 && - strcasecmp (S9xBasename (rom_filename), S9xBasename (Memory.ROMFilename)) != 0) - { - S9xMessage (S9X_WARNING, S9X_FREEZE_ROM_NAME, - "Current loaded ROM image doesn't match that required by freeze-game file."); - } - - S9xReset (); - S9xSetSoundMute (TRUE); - if ((result = ReadBlock ("CPU:", &OrigCPU, sizeof (OrigCPU), snap)) != SUCCESS) - return (result); - OrigCPU.FastROMSpeed = OrigCPU.FastROMSpeed_old; - Memory.FixROMSpeed (); - if (version == 3) - { - OrigCPU.Cycles = OrigCPU.Cycles_old; - OrigCPU.NextEvent = OrigCPU.NextEvent_old; - OrigCPU.V_Counter = OrigCPU.V_Counter_old; - OrigCPU.MemSpeed = OrigCPU.MemSpeed_old; - OrigCPU.MemSpeedx2 = OrigCPU.MemSpeedx2_old; - OrigCPU.FastROMSpeed = OrigCPU.FastROMSpeed_old; - } - CPU.Flags = OrigCPU.Flags; - CPU.BranchSkip = OrigCPU.BranchSkip; - CPU.NMIActive = OrigCPU.NMIActive; - CPU.IRQActive = OrigCPU.IRQActive; - CPU.WaitingForInterrupt = OrigCPU.WaitingForInterrupt; - CPU.WhichEvent = OrigCPU.WhichEvent; - CPU.Cycles = OrigCPU.Cycles; - CPU.NextEvent = OrigCPU.NextEvent; - CPU.V_Counter = OrigCPU.V_Counter; - CPU.MemSpeed = OrigCPU.MemSpeed; - CPU.MemSpeedx2 = OrigCPU.MemSpeedx2; - CPU.FastROMSpeed = OrigCPU.FastROMSpeed; - - if ((result = ReadBlock ("REG:", &OrigRegisters, sizeof (OrigRegisters), snap)) != SUCCESS) - return (result); - - Registers = *(struct SRegisters *) &OrigRegisters; - - if ((result = ReadBlock ("PPU:", &OrigPPU, sizeof (OrigPPU), snap)) != SUCCESS) - return (result); - - if (version == 2) - { - OrigPPU.OBJNameSelect = OrigPPU.OBJNameSelect_old << 13; - OrigPPU.OBJNameBase <<= 1; - OrigPPU.OBJNameSelect <<= 13; - } - PPU.BGMode = OrigPPU.BGMode; - PPU.BG3Priority = OrigPPU.BG3Priority; - PPU.Brightness = OrigPPU.Brightness; - - PPU.VMA.High = OrigPPU.VMA.High; - PPU.VMA.Increment = OrigPPU.VMA.Increment; - PPU.VMA.Address = OrigPPU.VMA.Address; - PPU.VMA.Mask1 = OrigPPU.VMA.Mask1; - PPU.VMA.FullGraphicCount = OrigPPU.VMA.FullGraphicCount; - PPU.VMA.Shift = OrigPPU.VMA.Shift; - - for (i = 0; i < 4; i++) - { - PPU.BG[i].SCBase = OrigPPU.BG[i].SCBase; - PPU.BG[i].VOffset = OrigPPU.BG[i].VOffset; - PPU.BG[i].HOffset = OrigPPU.BG[i].HOffset; - PPU.BG[i].BGSize = OrigPPU.BG[i].BGSize; - PPU.BG[i].NameBase = OrigPPU.BG[i].NameBase; - PPU.BG[i].SCSize = OrigPPU.BG[i].SCSize; - } - - PPU.CGFLIP = OrigPPU.CGFLIP; - for (i = 0; i < 256; i++) - PPU.CGDATA [i] = OrigPPU.CGDATA [i]; - PPU.FirstSprite = OrigPPU.FirstSprite; - for (i = 0; i < 128; i++) - { - PPU.OBJ[i].HPos = OrigPPU.OBJ [i].HPos; - PPU.OBJ[i].VPos = OrigPPU.OBJ [i].VPos; - PPU.OBJ[i].Name = OrigPPU.OBJ [i].Name; - PPU.OBJ[i].VFlip = OrigPPU.OBJ [i].VFlip; - PPU.OBJ[i].HFlip = OrigPPU.OBJ [i].HFlip; - PPU.OBJ[i].Priority = OrigPPU.OBJ [i].Priority; - PPU.OBJ[i].Palette = OrigPPU.OBJ [i].Palette; - PPU.OBJ[i].Size = OrigPPU.OBJ [i].Size; - } - PPU.OAMPriorityRotation = OrigPPU.OAMPriorityRotation; - PPU.OAMAddr = OrigPPU.OAMAddr; - - PPU.OAMFlip = OrigPPU.OAMFlip; - PPU.OAMTileAddress = OrigPPU.OAMTileAddress; - PPU.IRQVBeamPos = OrigPPU.IRQVBeamPos; - PPU.IRQHBeamPos = OrigPPU.IRQHBeamPos; - PPU.VBeamPosLatched = OrigPPU.VBeamPosLatched; - PPU.HBeamPosLatched = OrigPPU.HBeamPosLatched; - - PPU.HBeamFlip = OrigPPU.HBeamFlip; - PPU.VBeamFlip = OrigPPU.VBeamFlip; - PPU.HVBeamCounterLatched = OrigPPU.HVBeamCounterLatched; - - PPU.MatrixA = OrigPPU.MatrixA; - PPU.MatrixB = OrigPPU.MatrixB; - PPU.MatrixC = OrigPPU.MatrixC; - PPU.MatrixD = OrigPPU.MatrixD; - PPU.CentreX = OrigPPU.CentreX; - PPU.CentreY = OrigPPU.CentreY; - PPU.Joypad1ButtonReadPos = OrigPPU.Joypad1ButtonReadPos; - PPU.Joypad2ButtonReadPos = OrigPPU.Joypad2ButtonReadPos; - PPU.Joypad3ButtonReadPos = OrigPPU.Joypad3ButtonReadPos; - - PPU.CGADD = OrigPPU.CGADD; - PPU.FixedColourRed = OrigPPU.FixedColourRed; - PPU.FixedColourGreen = OrigPPU.FixedColourGreen; - PPU.FixedColourBlue = OrigPPU.FixedColourBlue; - PPU.SavedOAMAddr = OrigPPU.SavedOAMAddr; - PPU.ScreenHeight = OrigPPU.ScreenHeight; - PPU.WRAM = OrigPPU.WRAM; - PPU.ForcedBlanking = OrigPPU.ForcedBlanking; - PPU.OBJNameSelect = OrigPPU.OBJNameSelect; - PPU.OBJSizeSelect = OrigPPU.OBJSizeSelect; - PPU.OBJNameBase = OrigPPU.OBJNameBase; - PPU.OAMReadFlip = OrigPPU.OAMReadFlip; - memmove (PPU.OAMData, OrigPPU.OAMData, sizeof (PPU.OAMData)); - PPU.VTimerEnabled = OrigPPU.VTimerEnabled; - PPU.HTimerEnabled = OrigPPU.HTimerEnabled; - PPU.HTimerPosition = OrigPPU.HTimerPosition; - PPU.Mosaic = OrigPPU.Mosaic; - memmove (PPU.BGMosaic, OrigPPU.BGMosaic, sizeof (PPU.BGMosaic)); - PPU.Mode7HFlip = OrigPPU.Mode7HFlip; - PPU.Mode7VFlip = OrigPPU.Mode7VFlip; - PPU.Mode7Repeat = OrigPPU.Mode7Repeat; - PPU.Window1Left = OrigPPU.Window1Left; - PPU.Window1Right = OrigPPU.Window1Right; - PPU.Window2Left = OrigPPU.Window2Left; - PPU.Window2Right = OrigPPU.Window2Right; - for (i = 0; i < 6; i++) - { - PPU.ClipWindowOverlapLogic [i] = OrigPPU.ClipWindowOverlapLogic [i]; - PPU.ClipWindow1Enable [i] = OrigPPU.ClipWindow1Enable [i]; - PPU.ClipWindow2Enable [i] = OrigPPU.ClipWindow2Enable [i]; - PPU.ClipWindow1Inside [i] = OrigPPU.ClipWindow1Inside [i]; - PPU.ClipWindow2Inside [i] = OrigPPU.ClipWindow2Inside [i]; - } - PPU.CGFLIPRead = OrigPPU.CGFLIPRead; - PPU.Need16x8Mulitply = OrigPPU.Need16x8Mulitply; - - IPPU.ColorsChanged = TRUE; - IPPU.OBJChanged = TRUE; - S9xFixColourBrightness (); - IPPU.RenderThisFrame = FALSE; - - if ((result = ReadBlock ("DMA:", OrigDMA, sizeof (OrigDMA), snap)) != SUCCESS) - return (result); - - for (i = 0; i < 8; i++) - { - DMA[i].TransferDirection = OrigDMA[i].TransferDirection; - DMA[i].AAddressFixed = OrigDMA[i].AAddressFixed; - DMA[i].AAddressDecrement = OrigDMA[i].AAddressDecrement; - DMA[i].TransferMode = OrigDMA[i].TransferMode; - DMA[i].ABank = OrigDMA[i].ABank; - DMA[i].AAddress = OrigDMA[i].AAddress; - DMA[i].Address = OrigDMA[i].Address; - DMA[i].BAddress = OrigDMA[i].BAddress; - DMA[i].TransferBytes = OrigDMA[i].TransferBytes; - DMA[i].HDMAIndirectAddressing = OrigDMA[i].HDMAIndirectAddressing; - DMA[i].IndirectAddress = OrigDMA[i].IndirectAddress; - DMA[i].IndirectBank = OrigDMA[i].IndirectBank; - DMA[i].Repeat = OrigDMA[i].Repeat; - DMA[i].LineCount = OrigDMA[i].LineCount; - DMA[i].FirstLine = OrigDMA[i].FirstLine; - } - - if ((result = ReadBlock ("VRA:", Memory.VRAM, 0x10000, snap)) != SUCCESS) - return (result); - if ((result = ReadBlock ("RAM:", Memory.RAM, 0x20000, snap)) != SUCCESS) - return (result); - if ((result = ReadBlock ("SRA:", ::SRAM, 0x10000, snap)) != SUCCESS) - return (result); - if ((result = ReadBlock ("FIL:", Memory.FillRAM, 0x8000, snap)) != SUCCESS) - return (result); - if (ReadBlock ("APU:", &OrigAPU, sizeof (OrigAPU), snap) == SUCCESS) - { - APU = *(struct SAPU *) &OrigAPU; - - if ((result = ReadBlock ("ARE:", &OrigAPURegisters, - sizeof (OrigAPURegisters), snap)) != SUCCESS) - return (result); - APURegisters = *(struct SAPURegisters *) &OrigAPURegisters; - if ((result = ReadBlock ("ARA:", IAPU.RAM, 0x10000, snap)) != SUCCESS) - return (result); - if ((result = ReadBlock ("SOU:", &OrigSoundData, - sizeof (SOrigSoundData), snap)) != SUCCESS) - return (result); - - SoundData.master_volume_left = OrigSoundData.master_volume_left; - SoundData.master_volume_right = OrigSoundData.master_volume_right; - SoundData.echo_volume_left = OrigSoundData.echo_volume_left; - SoundData.echo_volume_right = OrigSoundData.echo_volume_right; - SoundData.echo_enable = OrigSoundData.echo_enable; - SoundData.echo_feedback = OrigSoundData.echo_feedback; - SoundData.echo_ptr = OrigSoundData.echo_ptr; - SoundData.echo_buffer_size = OrigSoundData.echo_buffer_size; - SoundData.echo_write_enabled = OrigSoundData.echo_write_enabled; - SoundData.echo_channel_enable = OrigSoundData.echo_channel_enable; - SoundData.pitch_mod = OrigSoundData.pitch_mod; - - for (i = 0; i < 3; i++) - SoundData.dummy [i] = OrigSoundData.dummy [i]; - for (i = 0; i < NUM_CHANNELS; i++) - { - SoundData.channels [i].state = OrigSoundData.channels [i].state; - SoundData.channels [i].type = OrigSoundData.channels [i].type; - SoundData.channels [i].volume_left = OrigSoundData.channels [i].volume_left; - SoundData.channels [i].volume_right = OrigSoundData.channels [i].volume_right; - SoundData.channels [i].hertz = OrigSoundData.channels [i].frequency; - SoundData.channels [i].count = OrigSoundData.channels [i].count; - SoundData.channels [i].loop = OrigSoundData.channels [i].loop; - SoundData.channels [i].envx = OrigSoundData.channels [i].envx; - SoundData.channels [i].left_vol_level = OrigSoundData.channels [i].left_vol_level; - SoundData.channels [i].right_vol_level = OrigSoundData.channels [i].right_vol_level; - SoundData.channels [i].envx_target = OrigSoundData.channels [i].envx_target; - SoundData.channels [i].env_error = OrigSoundData.channels [i].env_error; - SoundData.channels [i].erate = OrigSoundData.channels [i].erate; - SoundData.channels [i].direction = OrigSoundData.channels [i].direction; - SoundData.channels [i].attack_rate = OrigSoundData.channels [i].attack_rate; - SoundData.channels [i].decay_rate = OrigSoundData.channels [i].decay_rate; - SoundData.channels [i].sustain_rate = OrigSoundData.channels [i].sustain_rate; - SoundData.channels [i].release_rate = OrigSoundData.channels [i].release_rate; - SoundData.channels [i].sustain_level = OrigSoundData.channels [i].sustain_level; - SoundData.channels [i].sample = OrigSoundData.channels [i].sample; - for (j = 0; j < 16; j++) - SoundData.channels [i].decoded [j] = OrigSoundData.channels [i].decoded [j]; - - for (j = 0; j < 2; j++) - SoundData.channels [i].previous [j] = OrigSoundData.channels [i].previous [j]; - - SoundData.channels [i].sample_number = OrigSoundData.channels [i].sample_number; - SoundData.channels [i].last_block = OrigSoundData.channels [i].last_block; - SoundData.channels [i].needs_decode = OrigSoundData.channels [i].needs_decode; - SoundData.channels [i].block_pointer = OrigSoundData.channels [i].block_pointer; - SoundData.channels [i].sample_pointer = OrigSoundData.channels [i].sample_pointer; - SoundData.channels [i].mode = OrigSoundData.channels [i].mode; - } - - S9xSetSoundMute (FALSE); - IAPU.PC = IAPU.RAM + IAPU.PC; - S9xAPUUnpackStatus (); - if (APUCheckDirectPage ()) - IAPU.DirectPage = IAPU.RAM + 0x100; - else - IAPU.DirectPage = IAPU.RAM; - Settings.APUEnabled = TRUE; - CPU.APU_APUExecuting = TRUE; - } - else - { - Settings.APUEnabled = FALSE; - CPU.APU_APUExecuting = FALSE; - S9xSetSoundMute (TRUE); - } - S9xFixSoundAfterSnapshotLoad (); - ICPU.ShiftedPB = Registers.PB << 16; - ICPU.ShiftedDB = Registers.DB << 16; - S9xSetPCBase (ICPU.ShiftedPB + Registers.PC, &CPU); - S9xUnpackStatus (); - S9xFixCycles (&Registers, &ICPU); - S9xReschedule (); - - return (SUCCESS); -} diff --git a/snaporig.h b/snaporig.h deleted file mode 100644 index b83a71f..0000000 --- a/snaporig.h +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - * - * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and - * Jerremy Koot (jkoot@snes9x.com) - * - * Super FX C emulator code - * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and - * Gary Henderson. - * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_. - * - * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson. - * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_. - * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com). - * - * DOS port code contains the works of other authors. See headers in - * individual files. - * - * Snes9x homepage: http://www.snes9x.com - * - * Permission to use, copy, modify and distribute Snes9x in both binary and - * source form, for non-commercial purposes, is hereby granted without fee, - * providing that this license information and copyright notice appear with - * all copies and any derived work. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event shall the authors be held liable for any damages - * arising from the use of this software. - * - * Snes9x is freeware for PERSONAL USE only. Commercial users should - * seek permission of the copyright holders first. Commercial use includes - * charging money for Snes9x or software derived from Snes9x. - * - * The copyright holders request that bug fixes and improvements to the code - * should be forwarded to them so everyone can benefit from the modifications - * in future versions. - * - * Super NES and Super Nintendo Entertainment System are trademarks of - * Nintendo Co., Limited and its subsidiary companies. - */ -#ifndef _SNAPORIG_H_ -#define _SNAPORIG_H_ - -#define ORIG_SNAPSHOT_MAGIC "#!snes96" -#define ORIG_SNAPSHOT_VERSION 4 - -EXTERN_C bool8_32 S9xLoadOrigSnapshot (const char *filename); - -struct SOrigCPUState{ - uint32 Flags; - short Cycles_old; - short NextEvent_old; - uint8 CurrentFrame; - uint8 FastROMSpeed_old_old; - uint16 V_Counter_old; - bool8_32 BranchSkip; - bool8_32 NMIActive; - bool8_32 IRQActive; - bool8_32 WaitingForInterrupt; - bool8_32 InDMA; - uint8 WhichEvent; - uint8 *PC; - uint8 *PCBase; - uint16 MemSpeed_old; - uint16 MemSpeedx2_old; - uint16 FastROMSpeed_old; - bool8_32 FastDP; - uint8 *PCAtOpcodeStart; - uint8 *WaitAddress; - uint32 WaitCounter; - long Cycles; - long NextEvent; - long V_Counter; - long MemSpeed; - long MemSpeedx2; - long FastROMSpeed; -}; - -struct SOrigAPU -{ - uint32 Cycles; - bool8_32 ShowROM; - uint8 Flags; - uint8 KeyedChannels; - uint8 OutPorts [4]; - uint8 DSP [0x80]; - uint8 ExtraRAM [64]; - uint16 Timer [3]; - uint16 TimerTarget [3]; - bool8_32 TimerEnabled [3]; - bool8_32 TimerValueWritten [3]; -}; - -typedef union -{ -#ifdef LSB_FIRST - struct { uint8 A, Y; } B; -#else - struct { uint8 Y, A; } B; -#endif - uint16 W; -} OrigYAndA; - -struct SOrigAPURegisters{ - uint8 P; - OrigYAndA YA; - uint8 X; - uint8 S; - uint16 PC; -}; - -#define ORIG_MAX_BUFFER_SIZE (1024 * 4) -#define NUM_CHANNELS 8 - -typedef struct { - int state; - int type; - short volume_left; - short volume_right; - int frequency; - int count; - signed short wave [ORIG_MAX_BUFFER_SIZE]; - bool8_32 loop; - int envx; - short left_vol_level; - short right_vol_level; - short envx_target; - unsigned long int env_error; - unsigned long erate; - int direction; - unsigned long attack_rate; - unsigned long decay_rate; - unsigned long sustain_rate; - unsigned long release_rate; - unsigned long sustain_level; - signed short sample; - signed short decoded [16]; - signed short previous [2]; - uint16 sample_number; - bool8_32 last_block; - bool8_32 needs_decode; - uint32 block_pointer; - uint32 sample_pointer; - int *echo_buf_ptr; - int mode; - uint32 dummy [8]; -} OrigChannel; - -typedef struct -{ - short master_volume_left; - short master_volume_right; - short echo_volume_left; - short echo_volume_right; - int echo_enable; - int echo_feedback; - int echo_ptr; - int echo_buffer_size; - int echo_write_enabled; - int echo_channel_enable; - int pitch_mod; - // Just incase they are needed in the future, for snapshot compatibility. - uint32 dummy [3]; - OrigChannel channels [NUM_CHANNELS]; -} SOrigSoundData; - -struct SOrigOBJ -{ - short HPos; - uint16 VPos; - uint16 Name; - uint8 VFlip; - uint8 HFlip; - uint8 Priority; - uint8 Palette; - uint8 Size; - uint8 Prev; - uint8 Next; -}; - -struct SOrigPPU { - uint8 BGMode; - uint8 BG3Priority; - uint8 Brightness; - - struct { - bool8_32 High; - uint8 Increment; - uint16 Address; - uint16 Mask1; - uint16 FullGraphicCount; - uint16 Shift; - } VMA; - - struct { - uint8 TileSize; - uint16 TileAddress; - uint8 Width; - uint8 Height; - uint16 SCBase; - uint16 VOffset; - uint16 HOffset; - bool8_32 ThroughMain; - bool8_32 ThroughSub; - uint8 BGSize; - uint16 NameBase; - uint16 SCSize; - bool8_32 Addition; - } BG [4]; - - bool8_32 CGFLIP; - uint16 CGDATA [256]; - uint8 FirstSprite; - uint8 LastSprite; - struct SOrigOBJ OBJ [129]; - uint8 OAMPriorityRotation; - uint16 OAMAddr; - - uint8 OAMFlip; - uint16 OAMTileAddress; - uint16 IRQVBeamPos; - uint16 IRQHBeamPos; - uint16 VBeamPosLatched; - uint16 HBeamPosLatched; - - uint8 HBeamFlip; - uint8 VBeamFlip; - uint8 HVBeamCounterLatched; - - short MatrixA; - short MatrixB; - short MatrixC; - short MatrixD; - short CentreX; - short CentreY; - uint8 Joypad1ButtonReadPos; - uint8 Joypad2ButtonReadPos; - - uint8 CGADD; - uint8 FixedColourRed; - uint8 FixedColourGreen; - uint8 FixedColourBlue; - uint16 SavedOAMAddr; - uint16 ScreenHeight; - uint32 WRAM; - uint8 BG_Forced; - bool8_32 ForcedBlanking; - bool8_32 OBJThroughMain; - bool8_32 OBJThroughSub; - uint8 OBJSizeSelect; - uint8 OBJNameSelect_old; - uint16 OBJNameBase; - bool8_32 OBJAddition; - uint8 OAMReadFlip; - uint8 OAMData [512 + 32]; - bool8_32 VTimerEnabled; - bool8_32 HTimerEnabled; - short HTimerPosition; - uint8 Mosaic; - bool8_32 BGMosaic [4]; - bool8_32 Mode7HFlip; - bool8_32 Mode7VFlip; - uint8 Mode7Repeat; - uint8 Window1Left; - uint8 Window1Right; - uint8 Window2Left; - uint8 Window2Right; - uint8 ClipCounts [6]; - uint8 ClipLeftEdges [3][6]; - uint8 ClipRightEdges [3][6]; - uint8 ClipWindowOverlapLogic [6]; - uint8 ClipWindow1Enable [6]; - uint8 ClipWindow2Enable [6]; - bool8_32 ClipWindow1Inside [6]; - bool8_32 ClipWindow2Inside [6]; - bool8_32 RecomputeClipWindows; - uint8 CGFLIPRead; - uint16 OBJNameSelect; - bool8_32 Need16x8Mulitply; - uint8 Joypad3ButtonReadPos; - uint8 MouseSpeed[2]; -}; - -struct SOrigDMA { - bool8_32 TransferDirection; - bool8_32 AAddressFixed; - bool8_32 AAddressDecrement; - uint8 TransferMode; - - uint8 ABank; - uint16 AAddress; - uint16 Address; - uint8 BAddress; - - // General DMA only: - uint16 TransferBytes; - - // H-DMA only: - bool8_32 HDMAIndirectAddressing; - uint16 IndirectAddress; - uint8 IndirectBank; - uint8 Repeat; - uint8 LineCount; - uint8 FirstLine; - bool8_32 JustStarted; -}; - -typedef union -{ -#ifdef LSB_FIRST - struct { uint8 l,h; } B; -#else - struct { uint8 h,l; } B; -#endif - uint16 W; -} OrigPair; - -struct SOrigRegisters{ - uint8 PB; - uint8 DB; - OrigPair P; - OrigPair A; - OrigPair D; - OrigPair S; - OrigPair X; - OrigPair Y; - uint16 PC; -}; - -#endif diff --git a/snapshot.cpp b/snapshot.cpp index 94ae8d0..b968a09 100644 --- a/snapshot.cpp +++ b/snapshot.cpp @@ -55,7 +55,6 @@ #include "65c816.h" #include "ppu.h" #include "cpuexec.h" -#include "display.h" #include "apu.h" #include "soundux.h" #ifdef USE_SA1 @@ -473,7 +472,7 @@ static void Freeze () } sprintf (buffer, "%s:%04d\n", SNAPSHOT_MAGIC, SNAPSHOT_VERSION); WRITE_STREAM(buffer, strlen(buffer), ss_st); - sprintf (buffer, "NAM:%06d:%s%c", strlen (Memory.ROMFilename) + 1, + sprintf (buffer, "NAM:%06zu:%s%c", strlen(Memory.ROMFilename) + 1, Memory.ROMFilename, 0); WRITE_STREAM(buffer, strlen(buffer) + 1, ss_st); FreezeStruct ("CPU", &CPU, SnapCPU, COUNT (SnapCPU)); diff --git a/spc700.cpp b/spc700.cpp index 2b203a8..a1c1683 100644 --- a/spc700.cpp +++ b/spc700.cpp @@ -40,7 +40,6 @@ */ #include "snes9x.h" #include "memmap.h" -#include "display.h" #include "cpuexec.h" #include "apu.h" #include "spc700.h" diff --git a/srtc.h b/srtc.h index a7eb331..faa7a1b 100644 --- a/srtc.h +++ b/srtc.h @@ -81,8 +81,8 @@ Index Description Range (nibble) typedef struct { - bool8_32 needs_init; - bool8_32 count_enable; // Does RTC mark time or is it frozen + bool8 needs_init; + bool8 count_enable; // Does RTC mark time or is it frozen uint8 data [MAX_RTC_INDEX+1]; int8 index; uint8 mode; diff --git a/tile.cpp b/tile.cpp index 34d7769..90b4c4f 100644 --- a/tile.cpp +++ b/tile.cpp @@ -42,7 +42,6 @@ #include "memmap.h" #include "ppu.h" -#include "display.h" #include "gfx.h" #include "tile.h" -- 1.7.9.5