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(); }
void S9xInitDisplay (int argc, char **argv) { #if 0 // AWH - Already initialized in GUI if (SDL_Init(SDL_INIT_VIDEO) != 0) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); } #endif // AWH atexit(SDL_Quit); /* * domaemon * * we just go along with RGB565 for now, nothing else.. */ S9xSetRenderPixelFormat(RGB565); S9xBlitFilterInit(); #if 0 // AWH S9xBlit2xSaIFilterInit(); S9xBlitHQ2xFilterInit(); #endif // AWH /* * domaemon * * FIXME: The secreen size should be flexible * FIXME: Check if the SDL screen is really in RGB565 mode. screen->fmt */ if (GUI.fullscreen == TRUE) { GUI.sdl_screen = SDL_SetVideoMode(0, 0, 16, SDL_FULLSCREEN); } else { /* AWH - Modified */ // NTSC GUI.sdl_screen = SDL_SetVideoMode(512 + 104, 478, 16, 0); #if defined(CAPE_LCD3) GUI.sdl_screen = SDL_SetVideoMode(320, 240, 16, 0); #else GUI.sdl_screen = SDL_SetVideoMode(640, 480, 16, 0); #endif //GUI.sdl_screen = SDL_SetVideoMode(SNES_WIDTH, SNES_HEIGHT, 16, 0); } if (GUI.sdl_screen == NULL) { printf("Unable to set video mode: %s\n", SDL_GetError()); exit(1); } fprintf(stderr, "screen %dx%d, pitch: %d\n", GUI.sdl_screen->w, GUI.sdl_screen->h, GUI.sdl_screen->pitch); /* * domaemon * * buffer allocation, quite important */ SetupImage(); }
void COpenGL::SetSnes9xColorFormat() { GUI.ScreenDepth = 16; GUI.BlueShift = 0; GUI.GreenShift = 6; GUI.RedShift = 11; S9xSetRenderPixelFormat (RGB565); S9xBlit2xSaIFilterInit(); S9xBlitHQ2xFilterInit(); GUI.NeedDepthConvert = FALSE; GUI.DepthConverted = TRUE; return; }
void S9xInitDisplay (int argc, char **argv) { if (SDL_Init(SDL_INIT_VIDEO) != 0) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); } atexit(SDL_Quit); /* * domaemon * * we just go along with RGB565 for now, nothing else.. */ S9xSetRenderPixelFormat(RGB565); S9xBlitFilterInit(); S9xBlit2xSaIFilterInit(); S9xBlitHQ2xFilterInit(); /* * domaemon * * FIXME: The secreen size should be flexible * FIXME: Check if the SDL screen is really in RGB565 mode. screen->fmt */ if (GUI.fullscreen == TRUE) { GUI.sdl_screen = SDL_SetVideoMode(0, 0, 16, SDL_FULLSCREEN); } else { GUI.sdl_screen = SDL_SetVideoMode(SNES_WIDTH * 2, SNES_HEIGHT_EXTENDED * 2, 16, 0); } if (GUI.sdl_screen == NULL) { printf("Unable to set video mode: %s\n", SDL_GetError()); exit(1); } /* * domaemon * * buffer allocation, quite important */ SetupImage(); }
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(); }
void CDirectDraw::SetSnes9xColorFormat() { GUI.ScreenDepth = DDPixelFormat.dwRGBBitCount; if (GUI.ScreenDepth == 15) GUI.ScreenDepth = 16; GUI.RedShift = ffs (DDPixelFormat.dwRBitMask); GUI.GreenShift = ffs (DDPixelFormat.dwGBitMask); GUI.BlueShift = ffs (DDPixelFormat.dwBBitMask); if((DDPixelFormat.dwFlags&DDPF_RGB) != 0 && GUI.ScreenDepth == 16 && DDPixelFormat.dwRBitMask == 0xF800 && DDPixelFormat.dwGBitMask == 0x07E0 && DDPixelFormat.dwBBitMask == 0x001F) { S9xSetRenderPixelFormat (RGB565); } else if( (DDPixelFormat.dwFlags&DDPF_RGB) != 0 && GUI.ScreenDepth == 16 && DDPixelFormat.dwRBitMask == 0x7C00 && DDPixelFormat.dwGBitMask == 0x03E0 && DDPixelFormat.dwBBitMask == 0x001F) { S9xSetRenderPixelFormat (RGB555); } else if((DDPixelFormat.dwFlags&DDPF_RGB) != 0 && GUI.ScreenDepth == 16 && DDPixelFormat.dwRBitMask == 0x001F && DDPixelFormat.dwGBitMask == 0x07E0 && DDPixelFormat.dwBBitMask == 0xF800) { S9xSetRenderPixelFormat (BGR565); } else if( (DDPixelFormat.dwFlags&DDPF_RGB) != 0 && GUI.ScreenDepth == 16 && DDPixelFormat.dwRBitMask == 0x001F && DDPixelFormat.dwGBitMask == 0x03E0 && DDPixelFormat.dwBBitMask == 0x7C00) { S9xSetRenderPixelFormat (BGR555); } else if (DDPixelFormat.dwRGBBitCount == 8 || DDPixelFormat.dwRGBBitCount == 24 || DDPixelFormat.dwRGBBitCount == 32) { S9xSetRenderPixelFormat (RGB565); } if ((GUI.ScreenDepth == 24 || GUI.ScreenDepth == 32)) GUI.NeedDepthConvert = TRUE; GUI.DepthConverted = !GUI.NeedDepthConvert; if ((GUI.ScreenDepth == 24 || GUI.ScreenDepth == 32)) { GUI.RedShift += 3; GUI.GreenShift += 3; GUI.BlueShift += 3; } S9xBlit2xSaIFilterInit(); S9xBlitHQ2xFilterInit(); }
void S9xInitDisplay (int argc, char **argv) { GUI.display = XOpenDisplay(NULL); if (GUI.display == NULL) FatalError("Failed to connect to X server."); GUI.screen = DefaultScreenOfDisplay(GUI.display); GUI.screen_num = XScreenNumberOfScreen(GUI.screen); GUI.visual = DefaultVisualOfScreen(GUI.screen); XVisualInfo plate, *matches; int count; plate.visualid = XVisualIDFromVisual(GUI.visual); matches = XGetVisualInfo(GUI.display, VisualIDMask, &plate, &count); if (!count) FatalError("Your X Window System server is unwell!"); GUI.depth = matches[0].depth; if ((GUI.depth != 15 && GUI.depth != 16 && GUI.depth != 24) || (matches[0].c_class != TrueColor)) FatalError("Requiers 15, 16, 24 or 32-bit color depth supporting TrueColor."); GUI.red_shift = ffs(matches[0].red_mask) - 1; GUI.green_shift = ffs(matches[0].green_mask) - 1; GUI.blue_shift = ffs(matches[0].blue_mask) - 1; GUI.red_size = matches[0].red_mask >> GUI.red_shift; GUI.green_size = matches[0].green_mask >> GUI.green_shift; GUI.blue_size = matches[0].blue_mask >> GUI.blue_shift; if (GUI.depth == 16 && GUI.green_size == 63) GUI.green_shift++; XFree(matches); switch (GUI.depth) { default: case 32: case 24: S9xSetRenderPixelFormat(RGB555); GUI.pixel_format = 555; break; case 16: if (GUI.red_size != GUI.green_size || GUI.blue_size != GUI.green_size) { // 565 format if (GUI.green_shift > GUI.blue_shift && GUI.green_shift > GUI.red_shift) S9xSetRenderPixelFormat(GBR565); else if (GUI.red_shift > GUI.blue_shift) S9xSetRenderPixelFormat(RGB565); else S9xSetRenderPixelFormat(BGR565); GUI.pixel_format = 565; break; } // FALL ... case 15: if (GUI.green_shift > GUI.blue_shift && GUI.green_shift > GUI.red_shift) S9xSetRenderPixelFormat(GBR555); else if (GUI.red_shift > GUI.blue_shift) S9xSetRenderPixelFormat(RGB555); else S9xSetRenderPixelFormat(BGR555); GUI.pixel_format = 555; break; } S9xBlitFilterInit(); S9xBlit2xSaIFilterInit(); S9xBlitHQ2xFilterInit(); XSetWindowAttributes attrib; memset(&attrib, 0, sizeof(attrib)); attrib.background_pixel = BlackPixelOfScreen(GUI.screen); attrib.colormap = XCreateColormap(GUI.display, RootWindowOfScreen(GUI.screen), GUI.visual, AllocNone); GUI.window = XCreateWindow(GUI.display, RootWindowOfScreen(GUI.screen), (WidthOfScreen(GUI.screen) - SNES_WIDTH * 2) / 2, (HeightOfScreen(GUI.screen) - SNES_HEIGHT_EXTENDED * 2) / 2, SNES_WIDTH * 2, SNES_HEIGHT_EXTENDED * 2, 0, GUI.depth, InputOutput, GUI.visual, CWBackPixel | CWColormap, &attrib); static XColor bg, fg; static char data[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; Pixmap bitmap; bitmap = XCreateBitmapFromData(GUI.display, GUI.window, data, 8, 8); GUI.point_cursor = XCreatePixmapCursor(GUI.display, bitmap, bitmap, &fg, &bg, 0, 0); XDefineCursor(GUI.display, GUI.window, GUI.point_cursor); GUI.cross_hair_cursor = XCreateFontCursor(GUI.display, XC_crosshair); GUI.gc = DefaultGCOfScreen(GUI.screen); XSizeHints Hints; XWMHints WMHints; memset((void *) &Hints, 0, sizeof(XSizeHints)); memset((void *) &WMHints, 0, sizeof(XWMHints)); Hints.flags = PSize | PMinSize | PMaxSize; Hints.min_width = Hints.max_width = Hints.base_width = SNES_WIDTH * 2; Hints.min_height = Hints.max_height = Hints.base_height = SNES_HEIGHT_EXTENDED * 2; WMHints.input = True; WMHints.flags = InputHint; XSetWMHints(GUI.display, GUI.window, &WMHints); XSetWMNormalHints(GUI.display, GUI.window, &Hints); XSelectInput(GUI.display, GUI.window, FocusChangeMask | ExposureMask | KeyPressMask | KeyReleaseMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask); XMapRaised(GUI.display, GUI.window); XClearWindow(GUI.display, GUI.window); SetupImage(); switch (GUI.depth) { default: case 32: GUI.bytes_per_pixel = 4; break; case 24: if (GUI.image->bits_per_pixel == 24) GUI.bytes_per_pixel = 3; else GUI.bytes_per_pixel = 4; break; case 15: case 16: GUI.bytes_per_pixel = 2; break; } }
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); }
bool8 S9xOpenGLInit2 () { glXMakeCurrent (GUI.display, GUI.window, GUI.glcontext); glGetIntegerv (GL_MAX_TEXTURE_SIZE, &OpenGL.max_texture_size); if (OpenGL.max_texture_size >= 512) { OpenGL.texture_size = 512; OpenGL.num_textures = 2; } else { OpenGL.texture_size = OpenGL.max_texture_size; OpenGL.num_textures = 1; } Settings.OpenGLEnable = TRUE; const char *ext = (const char *) glGetString (GL_EXTENSIONS); if (ext && strstr (ext, "EXT_packed_pixels") != NULL) OpenGL.packed_pixels_extension_present = TRUE; const char *version = (const char *) glGetString (GL_VERSION); if (version && strlen (version) < 100) { char ver [100]; strcpy (ver, version); // Strip dots from the version string char *ptr; while (ptr = strchr (ver, '.')) memmove (ptr, ptr + 1, strlen (ptr + 1) + 1); // Pad the string with zeros to 4 digits while (strlen (ver) < 4) strcat (ver, "0"); OpenGL.version = atoi (ver); } else OpenGL.version = 1100; #ifndef GL_UNSIGNED_SHORT_5_5_5_1_EXT #define GL_UNSIGNED_SHORT_5_5_5_1_EXT 0x8034 #endif if (OpenGL.version >= 1200) { OpenGL.internal_format = GL_RGB5_A1; OpenGL.format = GL_RGBA; OpenGL.type = GL_UNSIGNED_SHORT_5_5_5_1_EXT; S9xSetRenderPixelFormat (RGB5551); } else if (OpenGL.packed_pixels_extension_present) { OpenGL.internal_format = GL_RGB5_A1; OpenGL.format = GL_RGBA; OpenGL.type = GL_UNSIGNED_SHORT_5_5_5_1_EXT; S9xSetRenderPixelFormat (RGB5551); } else { OpenGL.internal_format = GL_RGB; OpenGL.format = GL_RGB; OpenGL.type = GL_UNSIGNED_BYTE; } glGenTextures (OpenGL.num_textures, OpenGL.textures); if (OpenGL.num_textures == 2) { glBindTexture (GL_TEXTURE_2D, OpenGL.textures [1]); glTexImage2D (GL_TEXTURE_2D, 0, OpenGL.internal_format, 256, 256, 0, OpenGL.format, OpenGL.type, NULL); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } glBindTexture (GL_TEXTURE_2D, OpenGL.textures [0]); glTexImage2D (GL_TEXTURE_2D, 0, OpenGL.internal_format, OpenGL.texture_size, OpenGL.texture_size, 0, OpenGL.format, OpenGL.type, NULL); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glPolygonMode (GL_FRONT, GL_FILL); glEnable (GL_CULL_FACE); glCullFace (GL_BACK); glEnable (GL_DITHER); glEnable (GL_LIGHTING); glEnable (GL_LIGHT0); glEnable (GL_POINT_SMOOTH); glHint (GL_POINT_SMOOTH_HINT, GL_NICEST); glEnable (GL_TEXTURE_2D); glShadeModel (GL_SMOOTH); glEnable (GL_POLYGON_SMOOTH); glClearColor (0.0f, 0.0f, 0.0f, 0.0f); glClearDepth (1.0f); glDisable (GL_DEPTH_TEST); glDepthFunc (GL_LESS); glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glMatrixMode (GL_MODELVIEW); glClearColor (0, 0, 0, 1); glClear (GL_COLOR_BUFFER_BIT); glFlush (); return (TRUE); }