EXPORT m64p_error CALL VidExt_ResizeWindow(int Width, int Height) { const SDL_VideoInfo *videoInfo; int videoFlags = 0; /* call video extension override if necessary */ if (l_VideoExtensionActive) { m64p_error rval; // shut down the OSD osd_exit(); // re-create the OGL context rval = (*l_ExternalVideoFuncTable.VidExtFuncResizeWindow)(Width, Height); if (rval == M64ERR_SUCCESS) { StateChanged(M64CORE_VIDEO_SIZE, (Width << 16) | Height); // re-create the On-Screen Display osd_init(Width, Height); } return rval; } if (!l_VideoOutputActive || !SDL_WasInit(SDL_INIT_VIDEO)) return M64ERR_NOT_INIT; if (l_Fullscreen) { DebugMessage(M64MSG_ERROR, "VidExt_ResizeWindow() called in fullscreen mode."); return M64ERR_INVALID_STATE; } /* Get SDL video flags to use */ videoFlags = SDL_OPENGL | SDL_RESIZABLE; if ((videoInfo = SDL_GetVideoInfo()) == NULL) { DebugMessage(M64MSG_ERROR, "SDL_GetVideoInfo query failed: %s", SDL_GetError()); return M64ERR_SYSTEM_FAIL; } if (videoInfo->hw_available) videoFlags |= SDL_HWSURFACE; else videoFlags |= SDL_SWSURFACE; // destroy the On-Screen Display osd_exit(); /* set the re-sizing the screen will create a new OpenGL context */ l_pScreen = SDL_SetVideoMode(Width, Height, 0, videoFlags); if (l_pScreen == NULL) { DebugMessage(M64MSG_ERROR, "SDL_SetVideoMode failed: %s", SDL_GetError()); return M64ERR_SYSTEM_FAIL; } StateChanged(M64CORE_VIDEO_SIZE, (Width << 16) | Height); // re-create the On-Screen Display osd_init(Width, Height); return M64ERR_SUCCESS; }
/** * @brief Destroys an OSD. * * @param osd ID of the OSD to destroy. */ int osd_destroy( unsigned int osd ) { int i; OSD_t *ll; for (i=0; i<array_size( osd_list ); i++) { ll = &osd_list[i]; if (ll->id != osd) continue; /* Clean up. */ osd_free( &osd_list[i] ); /* Remove. */ array_erase( &osd_list, &osd_list[i], &osd_list[i+1] ); /* Recalculate dimensions. */ osd_calcDimensions(); /* Remove the OSD, if empty. */ if (array_size(osd_list) == 0) osd_exit(); /* Done here. */ return 0; } WARN("OSD '%u' not found to destroy.", osd ); return 0; }
int main(int argc,char **argv) { int i,list,log,success; list = 0; for (i = 1;i < argc;i++) { if (stricmp(argv[i],"-list") == 0) list = 1; } if (list) { printf("\nMAME currently supports the following games:\n\n"); i = 0; while (drivers[i]) { printf("%10s",drivers[i]->name); i++; if (!(i % 7)) printf("\n"); } if (i % 7) printf("\n"); printf("\nTotal games supported: %4d\n", i); return 0; } success = 1; log = 0; for (i = 1;i < argc;i++) { if (stricmp(argv[i],"-log") == 0) log = 1; } if (log) errorlog = fopen("error.log","wa"); if (init_machine(argc > 1 && argv[1][0] != '-' ? argv[1] : DEFAULT_NAME,argc,argv) == 0) { if (osd_init(argc,argv) == 0) { if (run_machine(argc > 1 && argv[1][0] != '-' ? argv[1] : DEFAULT_NAME) == 0) success = 0; else printf("Unable to start emulation\n"); osd_exit(); } else printf("Unable to initialize system\n"); shutdown_machine(); } else printf("Unable to initialize machine emulation\n"); if (errorlog) fclose(errorlog); return success; }
void sdl_osd_interface::init(running_machine &machine) { // call our parent osd_interface::init(machine); sdl_options &options = downcast<sdl_options &>(machine.options()); const char *stemp; // Switchres if (machine.options().modeline()) switchres_modeline_setup(machine); // determine if we are benchmarking, and adjust options appropriately int bench = options.bench(); astring error_string; if (bench > 0) { options.set_value(OPTION_THROTTLE, false, OPTION_PRIORITY_MAXIMUM, error_string); options.set_value(OPTION_SOUND, false, OPTION_PRIORITY_MAXIMUM, error_string); options.set_value(SDLOPTION_VIDEO, "none", OPTION_PRIORITY_MAXIMUM, error_string); options.set_value(OPTION_SECONDS_TO_RUN, bench, OPTION_PRIORITY_MAXIMUM, error_string); assert(!error_string); } // Some driver options - must be before audio init! stemp = options.audio_driver(); if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) { mame_printf_verbose("Setting SDL audiodriver '%s' ...\n", stemp); osd_setenv(SDLENV_AUDIODRIVER, stemp, 1); } stemp = options.video_driver(); if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) { mame_printf_verbose("Setting SDL videodriver '%s' ...\n", stemp); osd_setenv(SDLENV_VIDEODRIVER, stemp, 1); } #if (SDLMAME_SDL2) stemp = options.render_driver(); if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) { mame_printf_verbose("Setting SDL renderdriver '%s' ...\n", stemp); //osd_setenv(SDLENV_RENDERDRIVER, stemp, 1); SDL_SetHint(SDL_HINT_RENDER_DRIVER, stemp); } #endif /* Set the SDL environment variable for drivers wanting to load the * lib at startup. */ #if USE_OPENGL /* FIXME: move lib loading code from drawogl.c here */ stemp = options.gl_lib(); if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) { osd_setenv("SDL_VIDEO_GL_DRIVER", stemp, 1); mame_printf_verbose("Setting SDL_VIDEO_GL_DRIVER = '%s' ...\n", stemp); } #endif /* get number of processors */ stemp = options.numprocessors(); osd_num_processors = 0; if (strcmp(stemp, "auto") != 0) { osd_num_processors = atoi(stemp); if (osd_num_processors < 1) { mame_printf_warning("Warning: numprocessors < 1 doesn't make much sense. Assuming auto ...\n"); osd_num_processors = 0; } } /* Initialize SDL */ if (!SDLMAME_INIT_IN_WORKER_THREAD) { #if (SDLMAME_SDL2) if (SDL_InitSubSystem(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) { #else if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) { #endif mame_printf_error("Could not initialize SDL %s\n", SDL_GetError()); exit(-1); } osd_sdl_info(); } // must be before sdlvideo_init! machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(osd_exit), &machine)); defines_verbose(); if (!SDLMAME_HAS_DEBUGGER) if (machine.debug_flags & DEBUG_FLAG_OSD_ENABLED) { mame_printf_error("sdlmame: -debug not supported on X11-less builds\n\n"); osd_exit(machine); exit(-1); } if (sdlvideo_init(machine)) { osd_exit(machine); mame_printf_error("sdlvideo_init: Initialization failed!\n\n\n"); fflush(stderr); fflush(stdout); exit(-1); } sdlinput_init(machine); sdlaudio_init(machine); sdloutput_init(machine); #ifdef SDLMAME_NETWORK sdlnetdev_init(machine); #endif if (options.oslog()) machine.add_logerror_callback(output_oslog); /* now setup watchdog */ int watchdog_timeout = options.watchdog(); int str = options.seconds_to_run(); /* only enable watchdog if seconds_to_run is enabled *and* relatively short (time taken from ui.c) */ if ((watchdog_timeout != 0) && (str > 0) && (str < 60*5 )) { m_watchdog = auto_alloc(machine, watchdog); m_watchdog->setTimeout(watchdog_timeout); } #if (SDLMAME_SDL2) SDL_EventState(SDL_TEXTINPUT, SDL_TRUE); #else SDL_EnableUNICODE(SDL_TRUE); #endif } #ifdef SDLMAME_UNIX #define POINT_SIZE 144.0 #ifdef SDLMAME_MACOSX #define EXTRA_HEIGHT 1.0 #define EXTRA_WIDTH 1.15 //------------------------------------------------- // font_open - attempt to "open" a handle to the // font with the given name //------------------------------------------------- osd_font sdl_osd_interface::font_open(const char *_name, int &height) { CFStringRef font_name = NULL; CTFontRef ct_font = NULL; CTFontDescriptorRef font_descriptor; CGAffineTransform affine_transform = CGAffineTransformIdentity; astring name(_name); if (name == "default") { name = "LucidaGrande"; } /* handle bdf fonts in the core */ if (name.len() > 4) if (name.makeupper().substr(name.len()-4,4) == ".BDF" ) return NULL; font_name = CFStringCreateWithCString( NULL, _name, kCFStringEncodingUTF8 ); if( font_name != NULL ) { font_descriptor = CTFontDescriptorCreateWithNameAndSize( font_name, POINT_SIZE ); if( font_descriptor != NULL ) { ct_font = CTFontCreateWithFontDescriptor( font_descriptor, POINT_SIZE, &affine_transform ); CFRelease( font_descriptor ); } } CFRelease( font_name ); if (!ct_font) { printf("WARNING: Couldn't find/open font %s, using MAME default\n", name.cstr()); return NULL; } CFStringRef real_name = CTFontCopyPostScriptName( ct_font ); char real_name_c_string[255]; CFStringGetCString ( real_name, real_name_c_string, 255, kCFStringEncodingUTF8 ); mame_printf_verbose("Matching font: %s\n", real_name_c_string); CFRelease( real_name ); CGFloat line_height = 0.0; line_height += CTFontGetAscent(ct_font); line_height += CTFontGetDescent(ct_font); line_height += CTFontGetLeading(ct_font); height = ceilf(line_height * EXTRA_HEIGHT); return (osd_font)ct_font; }
void osd_init(running_machine *machine) { const char *stemp; // Some driver options - must be before audio init! stemp = options_get_string(machine->options(), SDLOPTION_AUDIODRIVER); if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) { mame_printf_verbose("Setting SDL audiodriver '%s' ...\n", stemp); osd_setenv(SDLENV_AUDIODRIVER, stemp, 1); } stemp = options_get_string(machine->options(), SDLOPTION_VIDEODRIVER); if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) { mame_printf_verbose("Setting SDL videodriver '%s' ...\n", stemp); osd_setenv(SDLENV_VIDEODRIVER, stemp, 1); } if (SDL_VERSION_ATLEAST(1,3,0)) { stemp = options_get_string(machine->options(), SDLOPTION_RENDERDRIVER); if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) { mame_printf_verbose("Setting SDL renderdriver '%s' ...\n", stemp); osd_setenv(SDLENV_RENDERDRIVER, stemp, 1); } } /* Set the SDL environment variable for drivers wanting to load the * lib at startup. */ /* FIXME: move lib loading code from drawogl.c here */ stemp = options_get_string(machine->options(), SDLOPTION_GL_LIB); if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) != 0) { osd_setenv("SDL_VIDEO_GL_DRIVER", stemp, 1); mame_printf_verbose("Setting SDL_VIDEO_GL_DRIVER = '%s' ...\n", stemp); } /* get number of processors */ stemp = options_get_string(machine->options(), SDLOPTION_NUMPROCESSORS); sdl_num_processors = 0; if (strcmp(stemp, "auto") != 0) { sdl_num_processors = atoi(stemp); if (sdl_num_processors < 1) { mame_printf_warning("Warning: numprocessors < 1 doesn't make much sense. Assuming auto ...\n"); sdl_num_processors = 0; } } /* Initialize SDL */ if (!SDLMAME_INIT_IN_WORKER_THREAD) { #if (SDL_VERSION_ATLEAST(1,3,0)) if (SDL_InitSubSystem(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) { #else if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_AUDIO| SDL_INIT_VIDEO| SDL_INIT_JOYSTICK|SDL_INIT_NOPARACHUTE)) { #endif mame_printf_error("Could not initialize SDL %s\n", SDL_GetError()); exit(-1); } osd_sdl_info(); } // must be before sdlvideo_init! machine->add_notifier(MACHINE_NOTIFY_EXIT, osd_exit); defines_verbose(); if (!SDLMAME_HAS_DEBUGGER) if (machine->debug_flags & DEBUG_FLAG_OSD_ENABLED) { mame_printf_error("sdlmame: -debug not supported on X11-less builds\n\n"); osd_exit(*machine); exit(-1); } if (sdlvideo_init(machine)) { osd_exit(*machine); mame_printf_error("sdlvideo_init: Initialization failed!\n\n\n"); fflush(stderr); fflush(stdout); exit(-1); } sdlinput_init(machine); sdlaudio_init(machine); sdloutput_init(machine); if (options_get_bool(machine->options(), SDLOPTION_OSLOG)) machine->add_logerror_callback(output_oslog); #if (SDL_VERSION_ATLEAST(1,3,0)) SDL_EventState(SDL_TEXTINPUT, SDL_TRUE); #else SDL_EnableUNICODE(SDL_TRUE); #endif }
int run_game(int game) { int err; /* copy some settings into easier-to-handle variables */ record = options.record; playback = options.playback; mame_debug = options.mame_debug; Machine->gamedrv = gamedrv = drivers[game]; Machine->drv = drv = gamedrv->drv; /* copy configuration */ if (options.color_depth == 16 || (options.color_depth != 8 && (Machine->gamedrv->flags & GAME_REQUIRES_16BIT))) Machine->color_depth = 16; else Machine->color_depth = 8; //if (options.vector_width == 0) options.vector_width = 640; //if (options.vector_height == 0) options.vector_height = 480; if (options.vector_width == 0) options.vector_width = 320; if (options.vector_height == 0) options.vector_height = 240; Machine->sample_rate = options.samplerate; /* get orientation right */ Machine->orientation = gamedrv->flags & ORIENTATION_MASK; Machine->ui_orientation = ROT0; if (options.norotate) Machine->orientation = ROT0; if (options.ror) { /* if only one of the components is inverted, switch them */ if ((Machine->orientation & ROT180) == ORIENTATION_FLIP_X || (Machine->orientation & ROT180) == ORIENTATION_FLIP_Y) Machine->orientation ^= ROT180; Machine->orientation ^= ROT90; /* if only one of the components is inverted, switch them */ if ((Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_X || (Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_Y) Machine->ui_orientation ^= ROT180; Machine->ui_orientation ^= ROT90; } if (options.rol) { /* if only one of the components is inverted, switch them */ if ((Machine->orientation & ROT180) == ORIENTATION_FLIP_X || (Machine->orientation & ROT180) == ORIENTATION_FLIP_Y) Machine->orientation ^= ROT180; Machine->orientation ^= ROT270; /* if only one of the components is inverted, switch them */ if ((Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_X || (Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_Y) Machine->ui_orientation ^= ROT180; Machine->ui_orientation ^= ROT270; } if (options.flipx) { Machine->orientation ^= ORIENTATION_FLIP_X; Machine->ui_orientation ^= ORIENTATION_FLIP_X; } if (options.flipy) { Machine->orientation ^= ORIENTATION_FLIP_Y; Machine->ui_orientation ^= ORIENTATION_FLIP_Y; } set_pixel_functions(); /* Do the work*/ err = 1; bailing = 0; #ifdef MESS if (get_filenames()) return err; #endif if (osd_init() == 0) { if (init_machine() == 0) { if (run_machine() == 0) err = 0; else if (!bailing) { bailing = 1; printf("Unable to start machine emulation\n"); } shutdown_machine(); } else if (!bailing) { bailing = 1; printf("Unable to initialize machine emulation\n"); } osd_exit(); } else if (!bailing) { bailing = 1; printf ("Unable to initialize system\n"); } return err; }
/********************************************************************************************************* * emulation thread - runs the core */ m64p_error main_run(void) { VILimit = (float) GetVILimit(); VILimitMilliseconds = (double) 1000.0/VILimit; /* take the r4300 emulator mode from the config file at this point and cache it in a global variable */ r4300emu = ConfigGetParamInt(g_CoreConfig, "R4300Emulator"); /* set some other core parameters based on the config file values */ savestates_set_autoinc_slot(ConfigGetParamBool(g_CoreConfig, "AutoStateSlotIncrement")); savestates_select_slot(ConfigGetParamInt(g_CoreConfig, "CurrentStateSlot")); no_compiled_jump = ConfigGetParamBool(g_CoreConfig, "NoCompiledJump"); /* set up the SDL key repeat and event filter to catch keyboard/joystick commands for the core */ event_initialize(); // initialize memory, and do byte-swapping if it's not been done yet if (g_MemHasBeenBSwapped == 0) { init_memory(1); g_MemHasBeenBSwapped = 1; } else { init_memory(0); } // Attach rom to plugins if (!romOpen_gfx()) { free_memory(); SDL_Quit(); return M64ERR_PLUGIN_FAIL; } if (!romOpen_audio()) { romClosed_gfx(); free_memory(); SDL_Quit(); return M64ERR_PLUGIN_FAIL; } if (!romOpen_input()) { romClosed_audio(); romClosed_gfx(); free_memory(); SDL_Quit(); return M64ERR_PLUGIN_FAIL; } if (ConfigGetParamBool(g_CoreConfig, "OnScreenDisplay")) { // init on-screen display int width = 640, height = 480; readScreen(NULL, &width, &height, 0); // read screen to get width and height osd_init(width, height); } // setup rendering callback from video plugin to the core, for screenshots and On-Screen-Display setRenderingCallback(video_plugin_render_callback); #ifdef WITH_LIRC lircStart(); #endif // WITH_LIRC #ifdef DBG if (ConfigGetParamBool(g_CoreConfig, "EnableDebugger")) init_debugger(); #endif /* Startup message on the OSD */ osd_new_message(OSD_MIDDLE_CENTER, "Mupen64Plus Started..."); g_EmulatorRunning = 1; StateChanged(M64CORE_EMU_STATE, M64EMU_RUNNING); /* call r4300 CPU core and run the game */ r4300_reset_hard(); r4300_reset_soft(); r4300_execute(); #ifdef WITH_LIRC lircStop(); #endif // WITH_LIRC #ifdef DBG if (g_DebuggerActive) destroy_debugger(); #endif if (ConfigGetParamBool(g_CoreConfig, "OnScreenDisplay")) { osd_exit(); } romClosed_RSP(); romClosed_input(); romClosed_audio(); romClosed_gfx(); free_memory(); // clean up g_EmulatorRunning = 0; StateChanged(M64CORE_EMU_STATE, M64EMU_STOPPED); SDL_Quit(); return M64ERR_SUCCESS; }