📄 win32.cpp
字号:
/******************************************************************************* Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2001 - 2004 John Weidman (jweidman@slip.net) (c) Copyright 2002 - 2004 Brad Jorsch (anomie@users.sourceforge.net), funkyass (funkyass@spam.shaw.ca), Joel Yliluoma (http://iki.fi/bisqwit/) Kris Bleakley (codeviolation@hotmail.com), Matthew Kendora, Nach (n-a-c-h@users.sourceforge.net), Peter Bortas (peter@bortas.org) and zones (kasumitokoduck@yahoo.com) C4 x86 assembler and some C emulation code (c) Copyright 2000 - 2003 zsKnight (zsknight@zsnes.com), _Demo_ (_demo_@zsnes.com), and Nach C4 C++ code (c) Copyright 2003 Brad Jorsch DSP-1 emulator code (c) Copyright 1998 - 2004 Ivar (ivar@snes9x.com), _Demo_, Gary Henderson, John Weidman, neviksti (neviksti@hotmail.com), Kris Bleakley, Andreas Naive DSP-2 emulator code (c) Copyright 2003 Kris Bleakley, John Weidman, neviksti, Matthew Kendora, and Lord Nightmare (lord_nightmare@users.sourceforge.net OBC1 emulator code (c) Copyright 2001 - 2004 zsKnight, pagefault (pagefault@zsnes.com) and Kris Bleakley Ported from x86 assembler to C by sanmaiwashi SPC7110 and RTC C++ emulator code (c) Copyright 2002 Matthew Kendora with research by zsKnight, John Weidman, and Dark Force S-DD1 C emulator code (c) Copyright 2003 Brad Jorsch with research by Andreas Naive and John Weidman S-RTC C emulator code (c) Copyright 2001 John Weidman ST010 C++ emulator code (c) Copyright 2003 Feather, Kris Bleakley, John Weidman and Matthew Kendora Super FX x86 assembler emulator code (c) Copyright 1998 - 2003 zsKnight, _Demo_, and pagefault Super FX C emulator code (c) Copyright 1997 - 1999 Ivar, Gary Henderson and John Weidman SH assembler code partly based on x86 assembler code (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) Specific ports 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 "snes9x.h"#include "..\directx.h"#include "..\Render.h"#include "memmap.h"#include "debug.h"#include "cpuexec.h"#include "ppu.h"#include "snapshot.h"#include "apu.h"#include "display.h"#include "gfx.h"#include "soundux.h"#include "netplay.h"#include "movie.h"#include "..\AVIOutput.h"
#include "..\language.h"#include <direct.h>#include <io.h>//#define DEBUGGER#ifdef FMOD_SUPPORT#include "fmod.h"#endif//#define GENERATE_OFFSETS_H#ifdef GENERATE_OFFSETS_HFILE *offsets_h = NULL;#define main generate_offsets_h#define S9xSTREAM offsets_h#include "offsets.cpp"#endifstruct SJoyState Joystick [16];uint32 joypads [5];bool8 do_frame_adjust=false;// avi variablesstatic uint8* avi_buffer = NULL;static uint8* avi_sound_buffer = NULL;static int avi_sound_bytes_per_sample = 0;static int avi_sound_samples_per_update = 0;static int avi_width = 0;static int avi_height = 0;static uint32 avi_skip_frames = 0;void Convert8To24Packed (SSurface *src, SSurface *dst, RECT *srect);void Convert16To24Packed (SSurface *src, SSurface *dst, RECT *srect);void DoAVIOpen(const char* filename);void DoAVIClose(int reason);static void DoAVIVideoFrame(SSurface* source_surface, int width, int height, bool8 sixteen_bit);static void S9xWinScanJoypads ();typedef struct{ uint8 red; uint8 green; uint8 blue;} Colour;void ConvertDepth (SSurface *src, SSurface *dst, RECT *);static Colour FixedColours [256];static uint8 palette [0x10000];FILE *trace_fs = NULL;int __fastcall Normalize (int cur, int min, int max){ int Result = 0; if ((max - min) == 0) return (Result); Result = cur - min; Result = (Result * 200) / (max - min); Result -= 100; return (Result);}void S9xTextMode( void){}void S9xGraphicsMode (){}void S9xExit( void){ if(Settings.SPC7110) (*CleanUp7110)(); SendMessage (GUI.hWnd, WM_COMMAND, ID_FILE_EXIT, 0);}extern "C" const char *S9xGetFilename (const char *e){ static char filename [_MAX_PATH + 1]; char drive [_MAX_DRIVE + 1]; char dir [_MAX_DIR + 1]; char fname [_MAX_FNAME + 1]; char ext [_MAX_EXT + 1]; if (strlen (GUI.FreezeFileDir)) { _splitpath (Memory.ROMFilename, drive, dir, fname, ext); strcpy (filename, GUI.FreezeFileDir); strcat (filename, TEXT("\\")); strcat (filename, fname); strcat (filename, e); } else { _splitpath (Memory.ROMFilename, drive, dir, fname, ext); _makepath (filename, drive, dir, fname, e); } return (filename);}const char *S9xGetFilenameInc (const char *e){ static char filename [_MAX_PATH + 1]; char drive [_MAX_DRIVE + 1]; char dir [_MAX_DIR + 1]; char fname [_MAX_FNAME + 1]; char ext [_MAX_EXT + 1]; char *ptr; if (strlen (GUI.FreezeFileDir)) { _splitpath (Memory.ROMFilename, drive, dir, fname, ext); strcpy (filename, GUI.FreezeFileDir); strcat (filename, TEXT("\\")); strcat (filename, fname); ptr = filename + strlen (filename); strcat (filename, TEXT("00/")); strcat (filename, e); } else { _splitpath (Memory.ROMFilename, drive, dir, fname, ext); strcat (fname, TEXT("00/")); _makepath (filename, drive, dir, fname, e); ptr = strstr (filename, TEXT("00/")); } do { if (++*(ptr + 2) > '9') { *(ptr + 2) = '0'; if (++*(ptr + 1) > '9') { *(ptr + 1) = '0'; if (++*ptr > '9') break; } } } while (_access (filename, 0) == 0); return (filename);}bool8 S9xOpenSnapshotFile( const char *fname, bool8 read_only, STREAM *file){ char filename [_MAX_PATH + 1]; char drive [_MAX_DRIVE + 1]; char dir [_MAX_DIR + 1]; char fn [_MAX_FNAME + 1]; char ext [_MAX_EXT + 1]; _splitpath( fname, drive, dir, fn, ext); _makepath( filename, drive, dir, fn, ext[0] == '\0' ? ".000" : ext); if (read_only) { if ((*file = OPEN_STREAM (filename, "rb"))) return (TRUE); } else { if ((*file = OPEN_STREAM (filename, "wb"))) return (TRUE); FILE *fs = fopen (filename, "rb"); if (fs) { sprintf (String, "Freeze file \"%s\" exists but is read only", filename); fclose (fs); S9xMessage (S9X_ERROR, S9X_FREEZE_FILE_NOT_FOUND, String); } else { sprintf (String, "Cannot create freeze file \"%s\". Directory is read-only or does not exist.", filename); S9xMessage (S9X_ERROR, S9X_FREEZE_FILE_NOT_FOUND, String); } } return (FALSE);}void S9xCloseSnapshotFile( STREAM file){ CLOSE_STREAM (file);}void S9xMessage (int, int, const char *str){#ifdef DEBUGGER static FILE *out = NULL; if (out == NULL) out = fopen ("out.txt", "w"); fprintf (out, "%s\n", str);#endif S9xSetInfoString (str);}unsigned long _interval = 10;long _buffernos = 4;long _blocksize = 4400;long _samplecount = 440;long _maxsamplecount = 0;long _buffersize = 0;uint8 *SoundBuffer = NULL;bool StartPlaying = false;DWORD _lastblock = 0;bool8 pending_setup = false;long pending_rate = 0;bool8 pending_16bit = false;bool8 pending_stereo = false;bool8 SetupSound (long rate, bool8 sixteen_bit, bool8 stereo){#ifdef FMOD_SUPPORT if (Settings.SoundDriver >= WIN_FMOD_DIRECT_SOUND_DRIVER) { so.mute_sound = TRUE; if (SoundBuffer) { SoundBuffer -= 32 * 1024; delete SoundBuffer; SoundBuffer = NULL; } _interval = 20; if (Settings.SoundBufferSize < 1) Settings.SoundBufferSize = 1; if (Settings.SoundBufferSize > 64) Settings.SoundBufferSize = 64; _buffernos = 4 * Settings.SoundBufferSize; int s = (rate * _interval * (Settings.Stereo ? 2 : 1) * (Settings.SixteenBitSound ? 2 : 1)) / 1000; _blocksize = 64; while (_blocksize < s) _blocksize *= 2; _buffersize = _blocksize * _buffernos; _lastblock = 0; StartPlaying = false; so.playback_rate = Settings.SoundPlaybackRate; so.stereo = Settings.Stereo; so.sixteen_bit = Settings.SixteenBitSound; so.buffer_size = _blocksize; so.encoded = FALSE; if (DirectX.SetSoundMode ()) { SoundBuffer = new uint8 [_blocksize * _buffernos + 1024 * 64]; ZeroMemory (SoundBuffer, _blocksize * _buffernos + 1024 * 64); SoundBuffer += 32 * 1024; S9xSetPlaybackRate (so.playback_rate); } _samplecount = so.sixteen_bit ? _blocksize / 2 : _blocksize; _maxsamplecount = SOUND_BUFFER_SIZE; if (so.sixteen_bit) _maxsamplecount /= 2; if (so.stereo) _maxsamplecount /= 2; if (so.samples_mixed_so_far >= _maxsamplecount) so.samples_mixed_so_far = 0; so.mute_sound = FALSE; return (SoundBuffer != NULL); } else {#endif pending_setup = TRUE; pending_rate = rate; pending_16bit = sixteen_bit; pending_stereo = stereo;#ifdef FMOD_SUPPORT }#endif return (TRUE);}bool8 RealSetupSound (long rate, bool8 sixteen_bit, bool8 stereo){ so.mute_sound = TRUE; if (SoundBuffer) { SoundBuffer -= 32 * 1024; delete SoundBuffer; SoundBuffer = NULL; }#if 0 OSVERSIONINFO info; info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); if (GetVersionEx (&info) && info.dwPlatformId == VER_PLATFORM_WIN32_NT && info.dwMajorVersion == 4) { _interval = 20; } else { _interval = 10; }#endif _interval = Settings.SoundMixInterval; if (Settings.SoundBufferSize < 1) Settings.SoundBufferSize = 1; if (Settings.SoundBufferSize > 64) Settings.SoundBufferSize = 64; _buffernos = 4 * Settings.SoundBufferSize; int s = (rate * _interval * (Settings.Stereo ? 2 : 1) * (Settings.SixteenBitSound ? 2 : 1)) / 1000; _blocksize = 64; while (_blocksize < s) _blocksize *= 2; _buffersize = _blocksize * _buffernos; _lastblock = 0; StartPlaying = false; so.playback_rate = Settings.SoundPlaybackRate; so.stereo = Settings.Stereo; so.sixteen_bit = Settings.SixteenBitSound; so.buffer_size = _blocksize; so.encoded = FALSE; if (!DirectX.DSAvailable) return (false); if (DirectX.SetSoundMode ()) { SoundBuffer = new uint8 [_blocksize * _buffernos + 1024 * 64]; ZeroMemory (SoundBuffer, _blocksize * _buffernos + 1024 * 64); SoundBuffer += 32 * 1024; S9xSetPlaybackRate (so.playback_rate); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -