bool SnesEmu::init(const QString &diskPath, QString *error) { S9xSetSoundMute(FALSE); setDefaultSettings(); S9xSetPlaybackRate(); m_frame = QImage(512, 239, QImage::Format_RGB16); setVideoSrcRect(QRectF(0.0f, 0.0f, 256.0f, 224.f)); setFrameRate(60); GFX.Pitch = 512 * 2; GFX.RealPitch = 512 * 2; GFX.PPL = GFX.Pitch >> 1; GFX.PPLx2 = GFX.Pitch; GFX.Screen = (u8 *)m_frame.bits(); GFX.SubScreen = (u8 *) malloc(GFX.RealPitch * 239); GFX.ZBuffer = (u8 *) malloc(GFX.PPL * 239); GFX.SubZBuffer = (u8 *) malloc(GFX.PPL * 239); GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1; if (!GFX.Screen || !GFX.SubScreen || !GFX.ZBuffer || !Memory.Init() || !S9xInitAPU() || !GFX.SubZBuffer ) { *error = tr("SNES emulation init failed!"); return false; } S9xInitSound(); if (!S9xGraphicsInit()) { *error = tr("SNES emulation init failed!"); return false; } S9xReset(); setDefaultSettings(); *error = setDisk(diskPath); return error->isEmpty(); }
void snes_init() { memset(&Settings, 0, sizeof(Settings)); Settings.MouseMaster = TRUE; Settings.SuperScopeMaster = TRUE; Settings.JustifierMaster = TRUE; Settings.MultiPlayer5Master = TRUE; Settings.FrameTimePAL = 20000; Settings.FrameTimeNTSC = 16667; Settings.SixteenBitSound = TRUE; Settings.Stereo = TRUE; Settings.SoundPlaybackRate = 32000; Settings.SoundInputRate = 32000; Settings.SupportHiRes = TRUE; Settings.Transparency = TRUE; Settings.AutoDisplayMessages = TRUE; Settings.InitialInfoStringTimeout = 120; Settings.HDMATimingHack = 100; Settings.BlockInvalidVRAMAccessMaster = TRUE; Settings.StopEmulation = TRUE; Settings.WrongMovieStateProtection = TRUE; Settings.DumpStreamsMaxFrames = -1; Settings.StretchScreenshots = 1; Settings.SnapshotScreenshots = TRUE; Settings.SkipFrames = AUTO_FRAMERATE; Settings.TurboSkipFrames = 15; Settings.CartAName[0] = 0; Settings.CartBName[0] = 0; Settings.AutoSaveDelay = 1; CPU.Flags = 0; if (!Memory.Init() || !S9xInitAPU()) { Memory.Deinit(); S9xDeinitAPU(); fprintf(stderr, "[libsnes]: Failed to init Memory or APU.\n"); exit(1); } S9xInitSound(64, 0); S9xSetSoundMute(FALSE); S9xSetSamplesAvailableCallback(S9xAudioCallback, NULL); S9xSetRenderPixelFormat(RGB555); GFX.Pitch = 2048; GFX.Screen = (uint16*) calloc(1, GFX.Pitch * 512 * sizeof(uint16)); S9xGraphicsInit(); S9xInitInputDevices(); for (int i = 0; i < 2; i++) { S9xSetController(i, CTL_JOYPAD, i, 0, 0, 0); snes_devices[i] = SNES_DEVICE_JOYPAD; } S9xUnmapAllControls(); map_buttons(); }
static void snes_init (void) { memset(&Settings, 0, sizeof(Settings)); Settings.SpeedhackGameID = SPEEDHACK_NONE; Settings.Transparency = TRUE; Settings.FrameTimePAL = 20000; Settings.FrameTimeNTSC = 16667; Settings.SoundPlaybackRate = 32000; Settings.SoundInputRate = 32000; Settings.HDMATimingHack = 100; Settings.BlockInvalidVRAMAccessMaster = TRUE; Settings.CartAName[0] = 0; Settings.CartBName[0] = 0; Settings.Crosshair = 1; CPU.Flags = 0; if (!Init() || !S9xInitAPU()) { Deinit(); S9xDeinitAPU(); if (log_cb) log_cb(RETRO_LOG_ERROR, "Failed to init Memory or APU.\n"); exit(1); } //very slow devices will still pop //this needs to be applied to all snes9x cores //increasing the buffer size does not cause extra lag(tested with 1000ms buffer) //bool8 S9xInitSound (int buffer_ms, int lag_ms) S9xInitSound(1000, 0);//just give it a 1 second buffer S9xSetSamplesAvailableCallback(S9xAudioCallback); GFX.Pitch = use_overscan ? 1024 : 2048; // FIXME: What is this supposed to do? Overscan has nothing to do with anything like this. If this is the Wii performance hack, it should be done differently. #if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) /* request 128-bit alignment here if possible */ posix_memalign((void**)&GFX.Screen, 16, GFX.Pitch * 512 * sizeof(uint16)); #else GFX.Screen = (uint16*) calloc(1, GFX.Pitch * 512 * sizeof(uint16)); #endif S9xGraphicsInit(); retro_set_controller_port_device(0, RETRO_DEVICE_JOYPAD); retro_set_controller_port_device(1, RETRO_DEVICE_JOYPAD); S9xUnmapAllControls(); map_buttons(); /* Initialize SuperFX CPU to normal speed by default */ Settings.SuperFXSpeedPerLine = 0.417 * 10.5e6; }
EXPORT void snes_init() { int i; if(environ_cb) { unsigned pitch; if (!environ_cb(SNES_ENVIRONMENT_GET_OVERSCAN, &use_overscan)) use_overscan = FALSE; if (use_overscan) { struct snes_geometry geom = {256, 239, 512, 512}; environ_cb(SNES_ENVIRONMENT_SET_GEOMETRY, &geom); pitch = 1024; environ_cb(SNES_ENVIRONMENT_SET_PITCH, &pitch); } } memset(&Settings, 0, sizeof(Settings)); Settings.FrameTimePAL = 20000; Settings.FrameTimeNTSC = 16667; Settings.SoundPlaybackRate = 32000; Settings.SoundInputRate = 32000; Settings.HDMATimingHack = 100; Settings.BlockInvalidVRAMAccessMaster = TRUE; Settings.CartAName[0] = 0; Settings.CartBName[0] = 0; Settings.Crosshair = 1; CPU.Flags = 0; if (!Init() || !S9xInitAPU()) { Deinit(); S9xDeinitAPU(); fprintf(stderr, "[libsnes]: Failed to init Memory or APU.\n"); exit(1); } S9xInitSound(16, 0); S9xSetSamplesAvailableCallback(S9xAudioCallback); GFX.Pitch = use_overscan ? 1024 : 2048; GFX.Screen = (uint16*) calloc(1, GFX.Pitch * 512 * sizeof(uint16)); S9xGraphicsInit(); for ( i = 0; i < 2; i++) { S9xSetController(i, CTL_JOYPAD, i, 0, 0, 0); snes_devices[i] = SNES_DEVICE_JOYPAD; } S9xUnmapAllControls(); map_buttons(); }
void snes_init() { memset(&Settings, 0, sizeof(Settings)); Settings.MouseMaster = TRUE; Settings.SuperScopeMaster = TRUE; Settings.JustifierMaster = TRUE; Settings.MultiPlayer5Master = TRUE; Settings.FrameTimePAL = 20000; Settings.FrameTimeNTSC = 16667; Settings.SoundPlaybackRate = 32000; Settings.SoundInputRate = 32000; Settings.AutoDisplayMessages = TRUE; Settings.InitialInfoStringTimeout = 120; Settings.HDMATimingHack = 100; Settings.BlockInvalidVRAMAccessMaster = TRUE; Settings.CartAName[0] = 0; Settings.CartBName[0] = 0; Settings.AutoSaveDelay = 1; CPU.Flags = 0; if (!Memory.Init() || !S9xInitAPU()) { Memory.Deinit(); S9xDeinitAPU(); fprintf(stderr, "[libsnes]: Failed to init Memory or APU.\n"); exit(1); } S9xInitSound(16, 0); S9xSetSamplesAvailableCallback(S9xAudioCallback); S9xSetRenderPixelFormat(RGB555); GFX.Pitch = 2048; GFX.Screen = (uint16*) calloc(1, GFX.Pitch * 512 * sizeof(uint16)); S9xGraphicsInit(); S9xInitInputDevices(); for (int i = 0; i < 2; i++) { S9xSetController(i, CTL_JOYPAD, i, 0, 0, 0); snes_devices[i] = SNES_DEVICE_JOYPAD; } S9xUnmapAllControls(); map_buttons(); }
static void SetupImage (void) { TakedownImage(); // domaemon: The whole unix code basically assumes output=(original * 2); // This way the code can handle the SNES filters, which does the 2X. GFX.Pitch = SNES_WIDTH * 2 * 2; GUI.snes_buffer = (uint8 *) calloc(GFX.Pitch * ((SNES_HEIGHT_EXTENDED + 4) * 2), 1); if (!GUI.snes_buffer) FatalError("Failed to allocate GUI.snes_buffer."); // domaemon: Add 2 lines before drawing. GFX.Screen = (uint16 *) (GUI.snes_buffer + (GFX.Pitch * 2 * 2)); if (GUI.fullscreen == TRUE) { fprintf(stderr, "Using fullscreen mode\n"); int offset_height_pix; int offset_width_pix; int offset_byte; offset_height_pix = (GUI.sdl_screen->h - (SNES_HEIGHT * 2)) / 2; offset_width_pix = (GUI.sdl_screen->w - (SNES_WIDTH * 2)) / 2; offset_byte = (GUI.sdl_screen->w * offset_height_pix + offset_width_pix) * 2; GUI.blit_screen = (uint8 *) GUI.sdl_screen->pixels + offset_byte; GUI.blit_screen_pitch = GUI.sdl_screen->pitch; } else { #if 0 // AWH GUI.blit_screen = (uint8 *) GUI.sdl_screen->pixels; GUI.blit_screen_pitch = SNES_WIDTH * 2 * 2; // window size =(*2); 2 byte pir pixel =(*2) #else // NTSC GUI.blit_screen = (uint8 *) GUI.sdl_screen->pixels + 208 + GUI.sdl_screen->pitch * 14; #if defined(CAPE_LCD3) GUI.blit_screen = (uint8 *) GUI.sdl_screen->pixels + 64 + GUI.sdl_screen->pitch * 7; #else GUI.blit_screen = (uint8 *) GUI.sdl_screen->pixels + 128 + GUI.sdl_screen->pitch * 14; #endif GUI.blit_screen_pitch = GUI.sdl_screen->pitch; #endif // AWH } S9xGraphicsInit(); }
static void SetupImage (void) { TakedownImage(); // domaemon: The whole unix code basically assumes output=(original * 2); // This way the code can handle the SNES filters, which does the 2X. GFX.Pitch = SNES_WIDTH * 2 * GFX_SCALE; GUI.snes_buffer = (uint8 *) calloc(GFX.Pitch * ((SNES_HEIGHT_EXTENDED + 4) * GFX_SCALE), 1); if (!GUI.snes_buffer) FatalError("Failed to allocate GUI.snes_buffer."); // domaemon: Add 2 lines before drawing. GFX.Screen = (uint16 *) (GUI.snes_buffer + (GFX.Pitch * 2 * GFX_SCALE)); #ifdef USE_SDL GUI.blit_screen = (uint8 *) GUI.sdl_screen->pixels; GUI.blit_screen_pitch = SNES_WIDTH * GFX_SCALE * (BPP/8); #endif S9xGraphicsInit(); }
static void SetupImage (void) { TakedownImage(); #ifdef MITSHM GUI.use_shared_memory = TRUE; int major, minor; Bool shared; if (!XShmQueryVersion(GUI.display, &major, &minor, &shared) || !shared) GUI.image = NULL; else GUI.image = XShmCreateImage(GUI.display, GUI.visual, GUI.depth, ZPixmap, NULL, &GUI.sm_info, SNES_WIDTH * 2, SNES_HEIGHT_EXTENDED * 2); if (!GUI.image) GUI.use_shared_memory = FALSE; else { GUI.sm_info.shmid = shmget(IPC_PRIVATE, GUI.image->bytes_per_line * GUI.image->height, IPC_CREAT | 0777); if (GUI.sm_info.shmid < 0) { XDestroyImage(GUI.image); GUI.use_shared_memory = FALSE; } else { GUI.image->data = GUI.sm_info.shmaddr = (char *) shmat(GUI.sm_info.shmid, 0, 0); if (!GUI.image->data) { XDestroyImage(GUI.image); shmctl(GUI.sm_info.shmid, IPC_RMID, 0); GUI.use_shared_memory = FALSE; } else { GUI.sm_info.readOnly = False; XSetErrorHandler(ErrorHandler); XShmAttach(GUI.display, &GUI.sm_info); XSync(GUI.display, False); // X Error handler might clear GUI.use_shared_memory if XShmAttach failed. if (!GUI.use_shared_memory) { XDestroyImage(GUI.image); shmdt(GUI.sm_info.shmaddr); shmctl(GUI.sm_info.shmid, IPC_RMID, 0); } } } } if (!GUI.use_shared_memory) { fprintf(stderr, "use_shared_memory failed, switching to XPutImage.\n"); #endif GUI.image = XCreateImage(GUI.display, GUI.visual, GUI.depth, ZPixmap, 0, NULL, SNES_WIDTH * 2, SNES_HEIGHT_EXTENDED * 2, BitmapUnit(GUI.display), 0); GUI.image->data = (char *) malloc(GUI.image->bytes_per_line * GUI.image->height); if (!GUI.image || !GUI.image->data) FatalError("XCreateImage failed."); #ifdef MITSHM } #endif #ifdef LSB_FIRST GUI.image->byte_order = LSBFirst; #else GUI.image->byte_order = MSBFirst; #endif GFX.Pitch = SNES_WIDTH * 2 * 2; GUI.snes_buffer = (uint8 *) calloc(GFX.Pitch * ((SNES_HEIGHT_EXTENDED + 4) * 2), 1); if (!GUI.snes_buffer) FatalError("Failed to allocate GUI.snes_buffer."); GFX.Screen = (uint16 *) (GUI.snes_buffer + (GFX.Pitch * 2 * 2)); GUI.filter_buffer = (uint8 *) calloc((SNES_WIDTH * 2) * 2 * (SNES_HEIGHT_EXTENDED * 2), 1); if (!GUI.filter_buffer) FatalError("Failed to allocate GUI.filter_buffer."); if (GUI.depth == 15 || GUI.depth == 16) { GUI.blit_screen_pitch = GUI.image->bytes_per_line; GUI.blit_screen = (uint8 *) GUI.image->data; GUI.need_convert = FALSE; } else { GUI.blit_screen_pitch = (SNES_WIDTH * 2) * 2; GUI.blit_screen = GUI.filter_buffer; GUI.need_convert = TRUE; } S9xGraphicsInit(); }
void ConfigurePreferences (void) { OSStatus err; IBNibRef nibRef; err = CreateNibReference(kMacS9XCFString, &nibRef); if (err == noErr) { WindowRef tWindowRef; SInt32 oldVolume; uint32 oldPlaybackRate, oldInputRate, oldInterval, oldBufferSize; bool8 oldSynchronize, old16BitPlayback, oldStereo, oldReverseStereo, oldLagEnable; oldSynchronize = Settings.SoundSync; old16BitPlayback = Settings.SixteenBitSound; oldStereo = Settings.Stereo; oldReverseStereo = Settings.ReverseStereo; oldPlaybackRate = Settings.SoundPlaybackRate; oldInputRate = Settings.SoundInputRate; oldInterval = macSoundInterval_ms; oldBufferSize = macSoundBuffer_ms; oldLagEnable = macSoundLagEnable; oldVolume = macSoundVolume; if (cartOpen) DeinitGameWindow(); S9xGraphicsDeinit(); err = CreateWindowFromNib(nibRef, CFSTR("Preferences"), &tWindowRef); if (err == noErr) { EventHandlerUPP tUPP, iUPP, aUPP, pUPP; EventHandlerRef tRef, iRef, aRef, pRef; EventTypeSpec tEvents[] = { { kEventClassControl, kEventControlHit } }, iEvents[] = { { kEventClassControl, kEventControlClick } }, aEvents[] = { { kEventClassControl, kEventControlClick } }, pEvents[] = { { kEventClassWindow, kEventWindowClose }, { kEventClassCommand, kEventCommandProcess }, { kEventClassCommand, kEventCommandUpdateStatus } }; ControlActionUPP arrowsUPP, sliderUPP; HIViewRef ctl, root; HIViewID cid; MenuRef menu; char num[16]; root = HIViewGetRoot(tWindowRef); cid.signature = 'tabs'; cid.id = 128; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, lastTabIndex); SelectTabPane(ctl, lastTabIndex); tUPP = NewEventHandlerUPP(TabEventHandler); err = InstallControlEventHandler(ctl, tUPP, GetEventTypeCount(tEvents), tEvents, 0, &tRef); cid.signature = 'snd_'; cid.id = iNibSInputRateText; HIViewFindByID(root, cid, &ctl); iUPP = NewEventHandlerUPP(InputRateTextEventHandler); err = InstallControlEventHandler(ctl, iUPP, GetEventTypeCount(iEvents), iEvents, 0, &iRef); cid.signature = 'grap'; cid.id = iNibGAspectRatioText; HIViewFindByID(root, cid, &ctl); aUPP = NewEventHandlerUPP(AspectRatioTextEventHandler); err = InstallControlEventHandler(ctl, aUPP, GetEventTypeCount(aEvents), aEvents, 0, &aRef); pUPP = NewEventHandlerUPP(PreferencesEventHandler); err = InstallWindowEventHandler(tWindowRef, pUPP, GetEventTypeCount(pEvents), pEvents, (void *) tWindowRef, &pRef); sliderUPP = NewControlActionUPP(InputRateSliderActionProc); arrowsUPP = NewControlActionUPP(LittleArrowsActionProc); cid.signature = 'grap'; cid.id = iNibGFullScreen; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, fullscreen); cid.id = iNibGSwitchResolution; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, autoRes); cid.id = iNibGShowFrameRate; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.DisplayFrameRate); cid.id = iNibGTransparency; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.Transparency); cid.id = iNibGGL32bit; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, gl32bit); cid.id = iNibGGLStretch; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, glstretch); cid.id = iNibGVideoMode; HIViewFindByID(root, cid, &ctl); switch (videoMode) { case VIDEOMODE_BLOCKY: SetControl32BitValue(ctl, iOpenGLBlocky); break; case VIDEOMODE_TV: SetControl32BitValue(ctl, iOpenGLTVMode); break; case VIDEOMODE_SMOOTH: SetControl32BitValue(ctl, iOpenGLSmoothMode); break; case VIDEOMODE_BLEND: SetControl32BitValue(ctl, iOpenGLBlendMode); break; case VIDEOMODE_SUPEREAGLE: SetControl32BitValue(ctl, iOpenGLEagleMode); break; case VIDEOMODE_2XSAI: SetControl32BitValue(ctl, iOpenGL2xSAIMode); break; case VIDEOMODE_SUPER2XSAI: SetControl32BitValue(ctl, iOpenGLSuper2xSAIMode); break; case VIDEOMODE_EPX: SetControl32BitValue(ctl, iOpenGLEPXMode); break; case VIDEOMODE_HQ2X: SetControl32BitValue(ctl, iOpenGLHQ2xMode); break; case VIDEOMODE_HQ3X: SetControl32BitValue(ctl, iOpenGLHQ3xMode); break; case VIDEOMODE_HQ4X: SetControl32BitValue(ctl, iOpenGLHQ4xMode); break; case VIDEOMODE_NTSC_C: SetControl32BitValue(ctl, iOpenGLNTSC_CMode); break; case VIDEOMODE_NTSC_S: SetControl32BitValue(ctl, iOpenGLNTSC_SMode); break; case VIDEOMODE_NTSC_R: SetControl32BitValue(ctl, iOpenGLNTSC_RMode); break; case VIDEOMODE_NTSC_M: SetControl32BitValue(ctl, iOpenGLNTSC_MMode); break; case VIDEOMODE_NTSC_TV_C: SetControl32BitValue(ctl, iOpenGLNTSC_TV_CMode); break; case VIDEOMODE_NTSC_TV_S: SetControl32BitValue(ctl, iOpenGLNTSC_TV_SMode); break; case VIDEOMODE_NTSC_TV_R: SetControl32BitValue(ctl, iOpenGLNTSC_TV_RMode); break; case VIDEOMODE_NTSC_TV_M: SetControl32BitValue(ctl, iOpenGLNTSC_TV_MMode); break; } cid.id = iNibGDirectMP; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, multiprocessor); cid.id = iNibGGLVSync; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, vsync); cid.id = iNibGDrawOverscan; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, drawoverscan); cid.id = iNibGScreenCurvature; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, screencurvature); cid.id = iNibGCurvatureWarp; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, macCurvatureWarp); if (!screencurvature) DeactivateControl(ctl); cid.id = iNibGAspectRatio; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, macAspectRatio); if (!glstretch) DeactivateControl(ctl); cid.id = iNibGCIFilterEnable; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, ciFilterEnable); if (systemVersion < 0x1040) DisableControl(ctl); if (systemVersion < 0x1040) { cid.id = iNibGCoreImageFilter; HIViewFindByID(root, cid, &ctl); DisableControl(ctl); } cid.signature = 'snd_'; cid.id = iNibSSynchronize; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.SoundSync); cid.id = iNibS16BitPlayback; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.SixteenBitSound); DeactivateControl(ctl); cid.id = iNibSStereo; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.Stereo); DeactivateControl(ctl); cid.id = iNibSReverseStereo; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.ReverseStereo); DeactivateControl(ctl); cid.id = iNibSPlaybackRate; HIViewFindByID(root, cid, &ctl); switch (Settings.SoundPlaybackRate) { case 48000: SetControl32BitValue(ctl, 1); break; case 44100: SetControl32BitValue(ctl, 2); break; case 35000: SetControl32BitValue(ctl, 3); break; case 32000: SetControl32BitValue(ctl, 4); break; case 30000: SetControl32BitValue(ctl, 5); break; case 22050: SetControl32BitValue(ctl, 6); break; case 16000: SetControl32BitValue(ctl, 7); break; case 11025: SetControl32BitValue(ctl, 8); break; case 8000: SetControl32BitValue(ctl, 9); break; } cid.id = iNibSInputRate; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.SoundInputRate); SetControlAction(ctl, sliderUPP); cid.id = iNibSInputRateText; HIViewFindByID(root, cid, &ctl); sprintf(num, "%d", Settings.SoundInputRate); SetStaticTextCStr(ctl, num, false); cid.id = iNibSInterval; HIViewFindByID(root, cid, &ctl); switch (macSoundInterval_ms) { case 8: SetControl32BitValue(ctl, 1); break; case 16: SetControl32BitValue(ctl, 2); break; case 32: SetControl32BitValue(ctl, 3); break; case 64: SetControl32BitValue(ctl, 4); break; case 0: default: SetControl32BitValue(ctl, 6); break; } cid.id = iNibSBufferSize; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, macSoundBuffer_ms / 20); cid.id = iNibSAllowLag; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, macSoundLagEnable); DeactivateControl(ctl); cid.id = iNibSVolume; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, macSoundVolume); cid.signature = 'othe'; cid.id = iNibOSaveFolder; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, saveInROMFolder + 1); err = GetControlData(ctl, kControlMenuPart, kControlPopupButtonMenuRefTag, sizeof(MenuRef), &menu, NULL); if (saveFolderPath) { CFURLRef url; CFStringRef ref; url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, saveFolderPath, kCFURLPOSIXPathStyle, true); ref = CFURLCopyLastPathComponent(url); err = SetMenuItemTextWithCFString(menu, iNibSaveFolderNameMenuItem, ref); CFRelease(ref); CFRelease(url); EnableMenuItem(menu, iNibSaveFolderNameMenuItem); } else { CFStringRef ref; ref = CFCopyLocalizedString(CFSTR("NoneSelected"), "NoneSelected"); err = SetMenuItemTextWithCFString(menu, iNibSaveFolderNameMenuItem, ref); CFRelease(ref); DisableMenuItem(menu, iNibSaveFolderNameMenuItem); } cid.id = iNibOAutoSaveInterval; HIViewFindByID(root, cid, &ctl); sprintf(num, "%d", Settings.AutoSaveDelay); SetEditTextCStr(ctl, num, false); cid.signature = 'msc2'; cid.id = iNibMCPUCycles; HIViewFindByID(root, cid, &ctl); sprintf(num, "%" PRIi32, Settings.HDMATimingHack); SetEditTextCStr(ctl, num, false); cid.id = iNibMTurboSkipArrows; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, macFastForwardRate); SetControlAction(ctl, arrowsUPP); cid.id = iNibMTurboSkipText; HIViewFindByID(root, cid, &ctl); sprintf(num, "%d", macFastForwardRate); SetStaticTextCStr(ctl, num, false); cid.id = iNibMFrameSkip; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, macFrameSkip + 2); cid.id = iNibMAllowInvalidVRAMAccess; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, !Settings.BlockInvalidVRAMAccessMaster); cid.id = iNibMAllowSpecificGameHacks; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, !Settings.DisableGameSpecificHacks); cid.signature = 'osx_'; cid.id = iNibXStartOpenDialog; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, startopendlog); cid.id = iNibXShowTimeInFrz; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, showtimeinfrz); cid.id = iNibXMusicBoxMode; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, musicboxmode); cid.id = iNibXEnableToggle; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, enabletoggle); cid.id = iNibXSaveWindowPos; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, savewindowpos); cid.id = iNibXUseIPSPatch; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, !Settings.NoPatch); cid.id = iNibXOnScreenInfo; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, onscreeninfo); cid.id = iNibXInactiveMode; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, inactiveMode); cid.id = iNibXBSXBootup; HIViewFindByID(root, cid, &ctl); SetControl32BitValue(ctl, Settings.BSXBootup); MoveWindowPosition(tWindowRef, kWindowPreferences, false); ShowWindow(tWindowRef); err = RunAppModalLoopForWindow(tWindowRef); HideWindow(tWindowRef); SaveWindowPosition(tWindowRef, kWindowPreferences); cid.signature = 'grap'; cid.id = iNibGFullScreen; HIViewFindByID(root, cid, &ctl); fullscreen = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGSwitchResolution; HIViewFindByID(root, cid, &ctl); autoRes = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGShowFrameRate; HIViewFindByID(root, cid, &ctl); Settings.DisplayFrameRate = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGTransparency; HIViewFindByID(root, cid, &ctl); Settings.Transparency = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGGL32bit; HIViewFindByID(root, cid, &ctl); gl32bit = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGGLStretch; HIViewFindByID(root, cid, &ctl); glstretch = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGVideoMode; HIViewFindByID(root, cid, &ctl); switch (GetControl32BitValue(ctl)) { case iOpenGLBlocky: drawingMethod = kDrawingOpenGL; videoMode = VIDEOMODE_BLOCKY; break; case iOpenGLTVMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_TV; break; case iOpenGLSmoothMode: drawingMethod = kDrawingOpenGL; videoMode = VIDEOMODE_SMOOTH; break; case iOpenGLBlendMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_BLEND; break; case iOpenGLEagleMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_SUPEREAGLE; break; case iOpenGL2xSAIMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_2XSAI; break; case iOpenGLSuper2xSAIMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_SUPER2XSAI; break; case iOpenGLEPXMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_EPX; break; case iOpenGLHQ2xMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_HQ2X; break; case iOpenGLHQ3xMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_HQ3X; break; case iOpenGLHQ4xMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_HQ4X; break; case iOpenGLNTSC_CMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_C; S9xBlitNTSCFilterSet(&snes_ntsc_composite); break; case iOpenGLNTSC_SMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_S; S9xBlitNTSCFilterSet(&snes_ntsc_svideo); break; case iOpenGLNTSC_RMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_R; S9xBlitNTSCFilterSet(&snes_ntsc_rgb); break; case iOpenGLNTSC_MMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_M; S9xBlitNTSCFilterSet(&snes_ntsc_monochrome); break; case iOpenGLNTSC_TV_CMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_TV_C; S9xBlitNTSCFilterSet(&snes_ntsc_composite); break; case iOpenGLNTSC_TV_SMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_TV_S; S9xBlitNTSCFilterSet(&snes_ntsc_svideo); break; case iOpenGLNTSC_TV_RMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_TV_R; S9xBlitNTSCFilterSet(&snes_ntsc_rgb); break; case iOpenGLNTSC_TV_MMode: drawingMethod = kDrawingBlitGL; videoMode = VIDEOMODE_NTSC_TV_M; S9xBlitNTSCFilterSet(&snes_ntsc_monochrome); break; } cid.id = iNibGDirectMP; HIViewFindByID(root, cid, &ctl); multiprocessor = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGGLVSync; HIViewFindByID(root, cid, &ctl); vsync = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGDrawOverscan; HIViewFindByID(root, cid, &ctl); drawoverscan = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGScreenCurvature; HIViewFindByID(root, cid, &ctl); screencurvature = GetControl32BitValue(ctl) ? true : false; cid.id = iNibGCurvatureWarp; HIViewFindByID(root, cid, &ctl); macCurvatureWarp = GetControl32BitValue(ctl); cid.id = iNibGAspectRatio; HIViewFindByID(root, cid, &ctl); macAspectRatio = GetControl32BitValue(ctl); cid.id = iNibGCIFilterEnable; HIViewFindByID(root, cid, &ctl); ciFilterEnable = GetControl32BitValue(ctl) ? true : false; cid.signature = 'snd_'; cid.id = iNibSSynchronize; HIViewFindByID(root, cid, &ctl); Settings.SoundSync = GetControl32BitValue(ctl) ? true : false; cid.id = iNibS16BitPlayback; HIViewFindByID(root, cid, &ctl); Settings.SixteenBitSound = GetControl32BitValue(ctl) ? true : false; cid.id = iNibSStereo; HIViewFindByID(root, cid, &ctl); Settings.Stereo = GetControl32BitValue(ctl) ? true : false; cid.id = iNibSReverseStereo; HIViewFindByID(root, cid, &ctl); Settings.ReverseStereo = GetControl32BitValue(ctl) ? true : false; cid.id = iNibSPlaybackRate; HIViewFindByID(root, cid, &ctl); switch (GetControl32BitValue(ctl)) { case 1: Settings.SoundPlaybackRate = 48000; break; case 2: Settings.SoundPlaybackRate = 44100; break; case 3: Settings.SoundPlaybackRate = 35000; break; case 4: Settings.SoundPlaybackRate = 32000; break; case 5: Settings.SoundPlaybackRate = 30000; break; case 6: Settings.SoundPlaybackRate = 22050; break; case 7: Settings.SoundPlaybackRate = 16000; break; case 8: Settings.SoundPlaybackRate = 11025; break; case 9: Settings.SoundPlaybackRate = 8000; break; } cid.id = iNibSInputRate; HIViewFindByID(root, cid, &ctl); Settings.SoundInputRate = GetControl32BitValue(ctl); cid.id = iNibSInterval; HIViewFindByID(root, cid, &ctl); switch (GetControl32BitValue(ctl)) { case 1: macSoundInterval_ms = 8; break; case 2: macSoundInterval_ms = 16; break; case 3: macSoundInterval_ms = 32; break; case 4: macSoundInterval_ms = 64; break; case 6: default: macSoundInterval_ms = 0; break; } cid.id = iNibSBufferSize; HIViewFindByID(root, cid, &ctl); macSoundBuffer_ms = GetControl32BitValue(ctl) * 20; cid.id = iNibSAllowLag; HIViewFindByID(root, cid, &ctl); macSoundLagEnable = GetControl32BitValue(ctl); cid.id = iNibSVolume; HIViewFindByID(root, cid, &ctl); macSoundVolume = GetControl32BitValue(ctl); cid.signature = 'othe'; cid.id = iNibOSaveFolder; HIViewFindByID(root, cid, &ctl); saveInROMFolder = GetControl32BitValue(ctl) - 1; cid.id = iNibOAutoSaveInterval; HIViewFindByID(root, cid, &ctl); GetEditTextCStr(ctl, num); Settings.AutoSaveDelay = atoi(num); cid.signature = 'msc2'; cid.id = iNibMCPUCycles; HIViewFindByID(root, cid, &ctl); GetEditTextCStr(ctl, num); Settings.HDMATimingHack = atoi(num); if ((Settings.HDMATimingHack <= 0) || (Settings.HDMATimingHack >= 200)) Settings.HDMATimingHack = 100; cid.id = iNibMTurboSkipArrows; HIViewFindByID(root, cid, &ctl); macFastForwardRate = GetControl32BitValue(ctl); cid.id = iNibMFrameSkip; HIViewFindByID(root, cid, &ctl); macFrameSkip = GetControl32BitValue(ctl) - 2; cid.id = iNibMAllowInvalidVRAMAccess; HIViewFindByID(root, cid, &ctl); Settings.BlockInvalidVRAMAccessMaster = GetControl32BitValue(ctl) ? false : true; cid.id = iNibMAllowSpecificGameHacks; HIViewFindByID(root, cid, &ctl); Settings.DisableGameSpecificHacks = GetControl32BitValue(ctl) ? false : true; cid.signature = 'osx_'; cid.id = iNibXStartOpenDialog; HIViewFindByID(root, cid, &ctl); startopendlog = GetControl32BitValue(ctl) ? true : false; cid.id = iNibXShowTimeInFrz; HIViewFindByID(root, cid, &ctl); showtimeinfrz = GetControl32BitValue(ctl) ? true : false; cid.id = iNibXMusicBoxMode; HIViewFindByID(root, cid, &ctl); musicboxmode = GetControl32BitValue(ctl); cid.id = iNibXEnableToggle; HIViewFindByID(root, cid, &ctl); enabletoggle = GetControl32BitValue(ctl) ? true : false; cid.id = iNibXSaveWindowPos; HIViewFindByID(root, cid, &ctl); savewindowpos = GetControl32BitValue(ctl) ? true : false; cid.id = iNibXUseIPSPatch; HIViewFindByID(root, cid, &ctl); Settings.NoPatch = GetControl32BitValue(ctl) ? false : true; cid.id = iNibXOnScreenInfo; HIViewFindByID(root, cid, &ctl); onscreeninfo = GetControl32BitValue(ctl) ? true : false; cid.id = iNibXInactiveMode; HIViewFindByID(root, cid, &ctl); inactiveMode = GetControl32BitValue(ctl); cid.id = iNibXBSXBootup; HIViewFindByID(root, cid, &ctl); Settings.BSXBootup = GetControl32BitValue(ctl) ? true : false; DisposeControlActionUPP(arrowsUPP); DisposeControlActionUPP(sliderUPP); err = RemoveEventHandler(pRef); DisposeEventHandlerUPP(pUPP); err = RemoveEventHandler(aRef); DisposeEventHandlerUPP(aUPP); err = RemoveEventHandler(iRef); DisposeEventHandlerUPP(iUPP); err = RemoveEventHandler(tRef); DisposeEventHandlerUPP(tUPP); CFRelease(tWindowRef); } DisposeNibReference(nibRef); S9xGraphicsInit(); if (((oldSynchronize != Settings.SoundSync ) || (old16BitPlayback != Settings.SixteenBitSound ) || (oldStereo != Settings.Stereo ) || (oldReverseStereo != Settings.ReverseStereo ) || (oldPlaybackRate != Settings.SoundPlaybackRate) || (oldInputRate != Settings.SoundInputRate ) || (oldInterval != macSoundInterval_ms ) || (oldBufferSize != macSoundBuffer_ms ) || (oldLagEnable != macSoundLagEnable ) || (oldVolume != macSoundVolume )) && cartOpen) SNES9X_InitSound(); if (!fullscreen && cartOpen) { InitGameWindow(); ShowWindow(gWindow); } if (cartOpen) { FSRef ref; err = FSPathMakeRef((unsigned char *) Memory.ROMFilename, &ref, NULL); if (err == noErr) CheckSaveFolder(&ref); } } }
extern "C" int SIStartWithROM(char* rom_filename) { // notify that we're running SI_EmulationIsRunning = 1; // frameskip settings reset SI_NextFrameTime = (timeval){0, 0}; SI_FrameTimeDebt = 0; SI_SleptLastFrame = 0; // ensure dirs exist mode_t dir_mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH; mkdir(SI_SRAMPath, dir_mode); // unix init ZeroMemory(&Settings, sizeof(Settings)); Settings.MouseMaster = TRUE; Settings.SuperScopeMaster = TRUE; Settings.JustifierMaster = TRUE; Settings.MultiPlayer5Master = TRUE; Settings.FrameTimePAL = 20000; Settings.FrameTimeNTSC = 16667; Settings.SixteenBitSound = TRUE; Settings.Stereo = TRUE; //Settings.Stereo = FALSE; Settings.SoundPlaybackRate = 32000; //Settings.SoundPlaybackRate = 22050; //Settings.SoundInputRate = 32000; Settings.SoundInputRate = 32000; Settings.SoundSync = FALSE; Settings.SupportHiRes = TRUE; Settings.Transparency = TRUE; Settings.AutoDisplayMessages = TRUE; Settings.InitialInfoStringTimeout = 120; Settings.HDMATimingHack = 100; Settings.BlockInvalidVRAMAccessMaster = TRUE; Settings.StopEmulation = TRUE; Settings.WrongMovieStateProtection = TRUE; Settings.DumpStreamsMaxFrames = -1; Settings.StretchScreenshots = 1; Settings.SnapshotScreenshots = TRUE; if(SI_AutoFrameskip) Settings.SkipFrames = AUTO_FRAMERATE; else Settings.SkipFrames = SI_Frameskip; //Settings.SkipFrames = 1; Settings.TurboSkipFrames = 15; Settings.CartAName[0] = 0; Settings.CartBName[0] = 0; #ifdef NETPLAY_SUPPORT Settings.ServerName[0] = 0; #endif CPU.Flags = 0; /*S9xLoadConfigFiles(argv, argc); rom_filename = S9xParseArgs(argv, argc); make_snes9x_dirs();*/ if (!Memory.Init() || !S9xInitAPU()) { fprintf(stderr, "Snes9x: Memory allocation failure - not enough RAM/virtual memory available.\nExiting...\n"); Memory.Deinit(); S9xDeinitAPU(); exit(1); } int samplecount = Settings.SoundPlaybackRate/(Settings.PAL ? 50 : 60); int soundBufferSize = samplecount<<(1+(Settings.Stereo?1:0)); S9xInitSound(soundBufferSize, 0); S9xSetSoundMute(TRUE); S9xReset(); S9xUnmapAllControls(); S9xSetController(0, CTL_JOYPAD, 0, 0, 0, 0); //S9xSetController(1, CTL_JOYPAD, 1, 0, 0, 0); s9xcommand_t cmd; ASSIGN_BUTTONf(SIOS_X, "Joypad1 X"); ASSIGN_BUTTONf(SIOS_A, "Joypad1 A"); ASSIGN_BUTTONf(SIOS_B, "Joypad1 B"); ASSIGN_BUTTONf(SIOS_Y, "Joypad1 Y"); ASSIGN_BUTTONf(SIOS_L, "Joypad1 L"); ASSIGN_BUTTONf(SIOS_R, "Joypad1 R"); ASSIGN_BUTTONf(SIOS_SELECT, "Joypad1 Select"); ASSIGN_BUTTONf(SIOS_START, "Joypad1 Start"); ASSIGN_BUTTONf(SIOS_UP, "Joypad1 Up"); ASSIGN_BUTTONf(SIOS_DOWN, "Joypad1 Down"); ASSIGN_BUTTONf(SIOS_LEFT, "Joypad1 Left"); ASSIGN_BUTTONf(SIOS_RIGHT, "Joypad1 Right"); S9xReportControllers(); #ifdef GFX_MULTI_FORMAT S9xSetRenderPixelFormat(RGB565); #endif uint32 saved_flags = CPU.Flags; bool8 loaded = FALSE; if (Settings.Multi) { loaded = Memory.LoadMultiCart(Settings.CartAName, Settings.CartBName); if (!loaded) { char s1[PATH_MAX + 1], s2[PATH_MAX + 1]; char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1]; s1[0] = s2[0] = 0; if (Settings.CartAName[0]) { _splitpath(Settings.CartAName, drive, dir, fname, ext); snprintf(s1, PATH_MAX + 1, "%s%s%s", S9xGetDirectory(ROM_DIR), SLASH_STR, fname); if (ext[0] && (strlen(s1) <= PATH_MAX - 1 - strlen(ext))) { strcat(s1, "."); strcat(s1, ext); } } if (Settings.CartBName[0]) { _splitpath(Settings.CartBName, drive, dir, fname, ext); snprintf(s2, PATH_MAX + 1, "%s%s%s", S9xGetDirectory(ROM_DIR), SLASH_STR, fname); if (ext[0] && (strlen(s2) <= PATH_MAX - 1 - strlen(ext))) { strcat(s2, "."); strcat(s2, ext); } } loaded = Memory.LoadMultiCart(s1, s2); } } else if (rom_filename) { char rom_path[1024] = {0}; sprintf(rom_path,"%s%s%s",SI_DocumentsPath,DIR_SEPERATOR,rom_filename); loaded = Memory.LoadROM(rom_path); /*if (!loaded && rom_filename[0]) { char s[PATH_MAX + 1]; char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1]; _splitpath(rom_filename, drive, dir, fname, ext); snprintf(s, PATH_MAX + 1, "%s%s%s", S9xGetDirectory(ROM_DIR), SLASH_STR, fname); if (ext[0] && (strlen(s) <= PATH_MAX - 1 - strlen(ext))) { strcat(s, "."); strcat(s, ext); } loaded = Memory.LoadROM(s); }*/ } if (!loaded) { fprintf(stderr, "Error opening the ROM file.\n"); exit(1); } //NSRTControllerSetup(); //Memory.LoadSRAM(S9xGetFilename(".srm", SRAM_DIR)); SILoadSRAM(); //S9xLoadCheatFile(S9xGetFilename(".cht", CHEAT_DIR)); CPU.Flags = saved_flags; Settings.StopEmulation = FALSE; #ifdef DEBUGGER struct sigaction sa; sa.sa_handler = sigbrkhandler; #ifdef SA_RESTART sa.sa_flags = SA_RESTART; #else sa.sa_flags = 0; #endif sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, NULL); #endif GFX.Pitch = SNES_WIDTH*2; /*vrambuffer = (uint8*) malloc (GFX.Pitch * SNES_HEIGHT_EXTENDED*2); memset (vrambuffer, 0, GFX.Pitch * SNES_HEIGHT_EXTENDED*2); GFX.Screen = (uint16*)vrambuffer;*/ S9xGraphicsInit(); #ifdef NETPLAY_SUPPORT if (strlen(Settings.ServerName) == 0) { char *server = getenv("S9XSERVER"); if (server) { strncpy(Settings.ServerName, server, 127); Settings.ServerName[127] = 0; } } char *port = getenv("S9XPORT"); if (Settings.Port >= 0 && port) Settings.Port = atoi(port); else if (Settings.Port < 0) Settings.Port = -Settings.Port; if (Settings.NetPlay) { NetPlay.MaxFrameSkip = 10; if (!S9xNPConnectToServer(Settings.ServerName, Settings.Port, Memory.ROMName)) { fprintf(stderr, "Failed to connect to server %s on port %d.\n", Settings.ServerName, Settings.Port); S9xExit(); } fprintf(stderr, "Connected to server %s on port %d as player #%d playing %s.\n", Settings.ServerName, Settings.Port, NetPlay.Player, Memory.ROMName); } #endif // HACK: disabling SMV /*if (play_smv_filename) { uint32 flags = CPU.Flags & (DEBUG_MODE_FLAG | TRACE_FLAG); if (S9xMovieOpen(play_smv_filename, TRUE) != SUCCESS) exit(1); CPU.Flags |= flags; } else if (record_smv_filename) { uint32 flags = CPU.Flags & (DEBUG_MODE_FLAG | TRACE_FLAG); if (S9xMovieCreate(record_smv_filename, 0xFF, MOVIE_OPT_FROM_RESET, NULL, 0) != SUCCESS) exit(1); CPU.Flags |= flags; } else if (snapshot_filename) { uint32 flags = CPU.Flags & (DEBUG_MODE_FLAG | TRACE_FLAG); if (!S9xUnfreezeGame(snapshot_filename)) exit(1); CPU.Flags |= flags; }*/ //S9xGraphicsMode(); sprintf(String, "\"%s\" %s: %s", Memory.ROMName, TITLE, VERSION); //S9xSetTitle(String); #ifdef JOYSTICK_SUPPORT uint32 JoypadSkip = 0; #endif SILoadRunningStateForGameNamed(rom_filename); SI_EmulationPaused = 0; //if(SI_SoundOn) SIDemuteSound(soundBufferSize); S9xSetSoundMute(FALSE); #ifdef NETPLAY_SUPPORT bool8 NP_Activated = Settings.NetPlay; #endif while (1) { #ifdef NETPLAY_SUPPORT if (NP_Activated) { if (NetPlay.PendingWait4Sync && !S9xNPWaitForHeartBeatDelay(100)) { S9xProcessEvents(FALSE); continue; } for (int J = 0; J < 8; J++) old_joypads[J] = MovieGetJoypad(J); for (int J = 0; J < 8; J++) MovieSetJoypad(J, joypads[J]); if (NetPlay.Connected) { if (NetPlay.PendingWait4Sync) { NetPlay.PendingWait4Sync = FALSE; NetPlay.FrameCount++; S9xNPStepJoypadHistory(); } } else { fprintf(stderr, "Lost connection to server.\n"); S9xExit(); } } #endif #ifdef DEBUGGER if (!Settings.Paused || (CPU.Flags & (DEBUG_MODE_FLAG | SINGLE_STEP_FLAG))) #else if (!Settings.Paused && !SI_EmulationPaused) #endif { S9xMainLoop(); } #ifdef NETPLAY_SUPPORT if (NP_Activated) { for (int J = 0; J < 8; J++) MovieSetJoypad(J, old_joypads[J]); } #endif #ifdef DEBUGGER if(Settings.Paused || (CPU.Flags & DEBUG_MODE_FLAG)) #else if(Settings.Paused || SI_EmulationPaused) #endif S9xSetSoundMute(TRUE); #ifdef DEBUGGER if (CPU.Flags & DEBUG_MODE_FLAG) S9xDoDebug(); else #endif if(Settings.Paused || SI_EmulationPaused || !SI_EmulationRun) { SISaveSRAM(); SISaveRunningStateForGameNamed(rom_filename); SI_EmulationDidPause = 1; do { //S9xProcessEvents(FALSE); if(!SI_EmulationRun) break; usleep(100000); } while (SI_EmulationPaused); if(!SI_EmulationRun) { SISaveSRAM(); SISaveRunningStateForGameNamed(rom_filename); SIMuteSound(); S9xGraphicsDeinit(); Memory.Deinit(); S9xDeinitAPU(); break; } } #ifdef JOYSTICK_SUPPORT if (unixSettings.JoystickEnabled && (JoypadSkip++ & 1) == 0) ReadJoysticks(); #endif //S9xProcessEvents(FALSE); #ifdef DEBUGGER if(!Settings.Paused && !(CPU.Flags & DEBUG_MODE_FLAG)) #else if(!Settings.Paused && !SI_EmulationPaused) #endif S9xSetSoundMute(FALSE); } SI_EmulationIsRunning = 0; return (0); }
void S9xInitDisplay (int argc, char **argv) { Screen *scrn; XSetWindowAttributes xattr; signal (SIGINT, quit); signal (SIGTERM, quit); if ((ourdisp = XOpenDisplay(NULL)) == NULL) { printf ("Can't connect to X server!\n"); S9xExit (); } ourscreen = DefaultScreen (ourdisp); scrn = DefaultScreenOfDisplay (ourdisp); ourvideo.bitdepth = DefaultDepth (ourdisp, ourscreen); ourvideo.screendepth = ourvideo.bitdepth / 8; rootWindow = RootWindowOfScreen (scrn); xattr.override_redirect = True; inputwin = XCreateWindow (ourdisp, RootWindowOfScreen(scrn), 10, 10, 100, 100, 0, 0, InputOutput, DefaultVisualOfScreen(scrn), CWOverrideRedirect, &xattr); XMapWindow (ourdisp, inputwin); ourvideo.height = HeightOfScreen (scrn); switch (ourvideo.bitdepth) { case 8: Settings.SixteenBit = FALSE; Settings.Transparency = FALSE; cmap = XCreateColormap (ourdisp, rootWindow, DefaultVisualOfScreen (scrn), AllocAll); XSetWindowColormap (ourdisp, inputwin, cmap); for (int i=0; i<256; i++) { colors[i].pixel = i; colors[i].flags = DoRed | DoGreen | DoBlue; } break; case 16: Settings.SixteenBit = TRUE; if (!Settings.ForceNoTransparency) Settings.Transparency = TRUE; break; case 24: if (is32or24 == 32) { ourvideo.bitdepth = 32; ourvideo.screendepth = 4; } Settings.SixteenBit = TRUE; if (!Settings.ForceNoTransparency) Settings.Transparency = TRUE; break; default: printf ("Color depth %d not supported!\n"); S9xExit (); break; } printf ("Found %d bit display\n", ourvideo.bitdepth); XFree(scrn); XF86DGAGetVideo (ourdisp, ourscreen, &(ourvideo.vidMemBegin), &(ourvideo.width), &(ourvideo.banksize), &(ourvideo.memsize)); #ifdef USE_XF86VIDMODE { XF86VidModeModeInfo **all_modes; int mode_count; XF86VidModeModeLine mod_tmp; int dotclock_tmp; int x; XF86VidModeGetModeLine (ourdisp, ourscreen, &dotclock_tmp, &mod_tmp); orig_mode = ModeLine2ModeInfo (mod_tmp, dotclock_tmp); if (orig_mode->hdisplay == 320 && orig_mode->vdisplay == 240) { mod320x240 = orig_mode; } else { XF86VidModeGetAllModeLines (ourdisp,ourscreen, &mode_count, &all_modes); for (x = 0; x < mode_count; x++) if (all_modes[x]->hdisplay == 320 && all_modes[x]->vdisplay == 240) { mod320x240 = (XF86VidModeModeInfo *) malloc ( sizeof(XF86VidModeModeInfo)); *mod320x240 = *(all_modes[x]); break; } else XFree (all_modes[x]->c_private); if (mod320x240 == NULL) { printf ("No 320x240 mode available!\n"); S9xExit (); } } XFree(all_modes); } #endif GFX.Pitch = IMAGE_WIDTH * (Settings.SixteenBit ? 2 : 1); GFX.Screen = (uint8 *) malloc (IMAGE_HEIGHT * GFX.Pitch); if (Settings.Transparency) GFX.SubScreen = (uint8 *) malloc (IMAGE_HEIGHT * GFX.Pitch); switch (ourvideo.bitdepth) { case 8: mWide = IMAGE_WIDTH / 4; mHigh = IMAGE_HEIGHT; mEtoE = (ourvideo.width - IMAGE_WIDTH) /4; break; case 16: mWide = IMAGE_WIDTH / 2; mHigh = IMAGE_HEIGHT; mEtoE = (ourvideo.width - IMAGE_WIDTH) / 2; break; case 24: mWide = IMAGE_WIDTH; mHigh = IMAGE_HEIGHT; mEtoE = (ourvideo.width - IMAGE_WIDTH) * 3; break; case 32: mWide = IMAGE_WIDTH; mHigh = IMAGE_HEIGHT; mEtoE = (ourvideo.width - IMAGE_WIDTH) * 4; default: break; } ourvideo.scrnBegin = ourvideo.vidMemBegin + (320 - IMAGE_WIDTH) * ourvideo.screendepth / 2 + ourvideo.width * ourvideo.screendepth * 8; S9xGraphicsInit (); }
int main(int argc, char ** argv) { // Initialise SDL if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0) DIE("SDL_Init: %s", SDL_GetError()); GL_Init(); //Init SDL_TTF to print text to the screen... if ( TTF_Init() ) { fprintf( stderr, "Error initializing SDL_ttf!\n" ); exit ( 1 ); } S9xInitDisplay(argc, argv); // Configure snes9x #if CONF_GUI OssoInit(); // Hildon-games-wrapper initialization. #endif S9xLoadConfig(argc, argv); // Load config files and parse cmd line. readOptions(); #if CONF_GUI OssoConfig(); // Apply specific hildon-games config. #endif // S9x initialization S9xInitDisplay(argc, argv); S9xInitAudioOutput(); S9xInitInputDevices(); while(1) { S9xInit(); S9xReset(); char * rom = romSelector(); S9xSetRomFile(rom); free(rom); // Load rom and related files: state, unfreeze if needed loadRom(); resumeGame(); // Late initialization sprintf(String, "DrNokSnes - %s", Memory.ROMName); S9xSetTitle(String); S9xHacksLoadFile(Config.hacksFile); if (!S9xGraphicsInit()) DIE("S9xGraphicsInit failed"); S9xAudioOutputEnable(true); SDL_PauseAudio(0); S9xVideoReset(); Config.running = true; do { frameSync(); // May block, or set frameskip to true. S9xMainLoop(); // Does CPU things, renders if needed. pollEvents(); //Ouch that this is going here... updateBindingMessage(); } while (Config.running); S9xVideoReset(); S9xGraphicsDeinit(); // Save state Memory.SaveSRAM(S9xGetFilename(FILE_SRAM)); pauseGame(); Memory.Deinit(); S9xDeinitAPU(); } // Deinitialization S9xAudioOutputEnable(false); S9xDeinitInputDevices(); S9xDeinitAudioOutput(); S9xDeinitDisplay(); // Late deinitialization S9xUnloadConfig(); #if CONF_GUI OssoDeinit(); #endif SDL_Quit(); return 0; }
int SnesInit() { ZeroMemory (&Settings, sizeof (Settings)); Settings.JoystickEnabled = FALSE; Settings.SoundPlaybackRate = 44100; Settings.Stereo = TRUE; Settings.SoundBufferSize = 0; Settings.CyclesPercentage = 100; Settings.DisableSoundEcho = FALSE; Settings.APUEnabled = TRUE; Settings.H_Max = SNES_CYCLES_PER_SCANLINE; Settings.SkipFrames = AUTO_FRAMERATE; Settings.Shutdown = Settings.ShutdownMaster = TRUE; Settings.FrameTimePAL = 20000; Settings.FrameTimeNTSC = 16667; Settings.FrameTime = Settings.FrameTimeNTSC; Settings.DisableSampleCaching = FALSE; Settings.DisableMasterVolume = TRUE; Settings.Mouse = FALSE; Settings.SuperScope = FALSE; Settings.MultiPlayer5 = FALSE; // Settings.ControllerOption = SNES_MULTIPLAYER5; Settings.ControllerOption = 0; Settings.InterpolatedSound = TRUE; Settings.StarfoxHack = TRUE; Settings.ForceTransparency = FALSE; Settings.Transparency = TRUE; Settings.SixteenBit = TRUE; Settings.SupportHiRes = FALSE; Settings.NetPlay = FALSE; Settings.ServerName [0] = 0; Settings.AutoSaveDelay = 30; Settings.ApplyCheats = TRUE; Settings.TurboMode = FALSE; Settings.TurboSkipFrames = 15; Settings.ThreadSound = FALSE; Settings.SoundSync = FALSE; //Settings.NoPatch = true; Settings.SuperFX = TRUE; Settings.DSP1Master = TRUE; Settings.SA1 = TRUE; Settings.C4 = TRUE; Settings.SDD1 = TRUE; GFX.Pitch = 320 * 2; GFX.RealPitch = 320 * 2; GFX.Screen = (uint8 *) sal_VideoGetBuffer(); GFX.SubScreen = (uint8 *)malloc(GFX.RealPitch * 480 * 2); GFX.ZBuffer = (uint8 *)malloc(GFX.RealPitch * 480 * 2); GFX.SubZBuffer = (uint8 *)malloc(GFX.RealPitch * 480 * 2); GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1; GFX.PPL = GFX.Pitch >> 1; GFX.PPLx2 = GFX.Pitch; GFX.ZPitch = GFX.Pitch >> 1; if (Settings.ForceNoTransparency) Settings.Transparency = FALSE; if (Settings.Transparency) Settings.SixteenBit = TRUE; Settings.HBlankStart = (256 * Settings.H_Max) / SNES_HCOUNTER_MAX; if (!Memory.Init () || !S9xInitAPU()) { S9xMessage (0,0,"Failed to init memory"); return SAL_ERROR; } //S9xInitSound (); //S9xSetRenderPixelFormat (RGB565); S9xSetSoundMute (TRUE); if (!S9xGraphicsInit ()) { S9xMessage (0,0,"Failed to init graphics"); return SAL_ERROR; } return SAL_OK; }