void sdl_window_create() { if (SDL_WasInit(SDL_INIT_VIDEO) == 0) { if(SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) { die("error initializing SDL Joystick subsystem"); } } int window_width = cfgLoadInt("x11","width", WINDOW_WIDTH); int window_height = cfgLoadInt("x11","height", WINDOW_HEIGHT); #ifdef TARGET_PANDORA int flags = SDL_FULLSCREEN; #else int flags = SDL_SWSURFACE; #endif screen = SDL_SetVideoMode(window_width, window_height, 0, flags); if (!screen) { die("error creating SDL screen"); } x11_disp = EGL_DEFAULT_DISPLAY; printf("Created SDL Windows (%ix%i) successfully\n", window_width, window_height); }
void mcfg_CreateDevices() { #if DC_PLATFORM == DC_PLATFORM_DREAMCAST #if defined(USE_EVDEV) int i, deviceId, size_needed; for(i = 0; i < 4; i++) { size_needed = snprintf(NULL, 0, EVDEV_DEVICE_CONFIG_KEY, i+1) + 1; char* evdev_config_key = (char*)malloc(size_needed); sprintf(evdev_config_key, EVDEV_DEVICE_CONFIG_KEY, i+1); deviceId = cfgLoadInt("input", evdev_config_key, EVDEV_DEFAULT_DEVICE_ID(i+1)); free(evdev_config_key); if (deviceId >= 0) { mcfg_Create(MDT_SegaController,i,5); } } #else mcfg_Create(MDT_SegaController,0,5); #endif mcfg_Create(MDT_SegaVMU,0,0); mcfg_Create(MDT_SegaVMU,0,1); #else mcfg_Create(MDT_NaomiJamma, 0, 5); #endif }
void os_CreateWindow() { #ifdef TARGET_PANDORA int width=800; int height=480; int flags=SDL_FULLSCREEN; #else int width=cfgLoadInt("x11","width", WINDOW_WIDTH); int height=cfgLoadInt("x11","height", WINDOW_HEIGHT); int flags=SDL_SWSURFACE; #endif screen = SDL_SetVideoMode(width, height, 0, flags); if (!screen) die("error creating SDL screen"); printf("Created SDL Windows (%ix%i) successfully\n", width, height); }
void input_x11_init() { x11_keymap[KEY_LEFT] = DC_DPAD_LEFT; x11_keymap[KEY_RIGHT] = DC_DPAD_RIGHT; x11_keymap[KEY_UP] = DC_DPAD_UP; x11_keymap[KEY_DOWN] = DC_DPAD_DOWN; // Layout on a real DC controller // Y // X B // A x11_keymap[KEY_S] = DC_BTN_X; x11_keymap[KEY_X] = DC_BTN_A; x11_keymap[KEY_D] = DC_BTN_Y; x11_keymap[KEY_C] = DC_BTN_B; // Used by some "arcade" controllers x11_keymap[KEY_Q] = DC_BTN_Z; x11_keymap[KEY_W] = DC_BTN_C; x11_keymap[KEY_E] = DC_BTN_D; // Start button (triangle) x11_keymap[KEY_RETURN] = DC_BTN_START; // Shoulder trigger x11_keymap[KEY_F] = DC_AXIS_LT; x11_keymap[KEY_V] = DC_AXIS_RT; x11_keyboard_input = (cfgLoadInt("input", "enable_x11_keyboard", 1) >= 1); if (!x11_keyboard_input) printf("X11 Keyboard input disabled by config.\n"); }
void mcfg_CreateDevices() { int numberOfControl = cfgLoadInt("players", "nb", 1); #if DC_PLATFORM == DC_PLATFORM_DREAMCAST if (numberOfControl <= 0) numberOfControl = 1; if (numberOfControl > 4) numberOfControl = 4; for (int i = 0; i < numberOfControl; i++){ mcfg_Create(MDT_SegaController, i, 5); } mcfg_Create(MDT_SegaVMU,0,0); mcfg_Create(MDT_SegaVMU,0,1); #else mcfg_Create(MDT_NaomiJamma, 0, 5); #endif }
void x11_window_create() { if (cfgLoadInt("pvr", "nox11", 0) == 0) { XInitThreads(); // X11 variables Window x11Window = 0; Display* x11Display = 0; long x11Screen = 0; XVisualInfo* x11Visual = 0; Colormap x11Colormap = 0; /* Step 0 - Create a NativeWindowType that we can use it for OpenGL ES output */ Window sRootWindow; XSetWindowAttributes sWA; unsigned int ui32Mask; int i32Depth; // Initializes the display and screen x11Display = XOpenDisplay(NULL); if (!x11Display && !(x11Display = XOpenDisplay(":0"))) { printf("Error: Unable to open X display\n"); return; } x11Screen = XDefaultScreen(x11Display); // Gets the window parameters sRootWindow = RootWindow(x11Display, x11Screen); int depth = CopyFromParent; #if !defined(GLES) // Get a matching FB config static int visual_attribs[] = { GLX_X_RENDERABLE , True, GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT, GLX_RENDER_TYPE , GLX_RGBA_BIT, GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR, GLX_RED_SIZE , 8, GLX_GREEN_SIZE , 8, GLX_BLUE_SIZE , 8, GLX_ALPHA_SIZE , 8, GLX_DEPTH_SIZE , 24, GLX_STENCIL_SIZE , 8, GLX_DOUBLEBUFFER , True, //GLX_SAMPLE_BUFFERS , 1, //GLX_SAMPLES , 4, None }; int glx_major, glx_minor; // FBConfigs were added in GLX version 1.3. if (!glXQueryVersion(x11Display, &glx_major, &glx_minor) || ((glx_major == 1) && (glx_minor < 3)) || (glx_major < 1)) { printf("Invalid GLX version"); exit(1); } int fbcount; GLXFBConfig* fbc = glXChooseFBConfig(x11Display, x11Screen, visual_attribs, &fbcount); if (!fbc) { printf("Failed to retrieve a framebuffer config\n"); exit(1); } printf("Found %d matching FB configs.\n", fbcount); GLXFBConfig bestFbc = fbc[0]; XFree(fbc); // Get a visual XVisualInfo *vi = glXGetVisualFromFBConfig(x11Display, bestFbc); printf("Chosen visual ID = 0x%lx\n", vi->visualid); depth = vi->depth; x11Visual = vi; x11Colormap = XCreateColormap(x11Display, RootWindow(x11Display, x11Screen), vi->visual, AllocNone); #else i32Depth = DefaultDepth(x11Display, x11Screen); x11Visual = new XVisualInfo; XMatchVisualInfo(x11Display, x11Screen, i32Depth, TrueColor, x11Visual); if (!x11Visual) { printf("Error: Unable to acquire visual\n"); return; } x11Colormap = XCreateColormap(x11Display, sRootWindow, x11Visual->visual, AllocNone); #endif sWA.colormap = x11Colormap; // Add to these for handling other events sWA.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask; ui32Mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap; x11_width = cfgLoadInt("x11", "width", DEFAULT_WINDOW_WIDTH); x11_height = cfgLoadInt("x11", "height", DEFAULT_WINDOW_HEIGHT); x11_fullscreen = (cfgLoadInt("x11", "fullscreen", DEFAULT_FULLSCREEN) > 0); if (x11_width < 0 || x11_height < 0) { x11_width = XDisplayWidth(x11Display, x11Screen); x11_height = XDisplayHeight(x11Display, x11Screen); } // Creates the X11 window x11Window = XCreateWindow(x11Display, RootWindow(x11Display, x11Screen), (ndcid%3)*640, (ndcid/3)*480, x11_width, x11_height, 0, depth, InputOutput, x11Visual->visual, ui32Mask, &sWA); // Capture the close window event wmDeleteMessage = XInternAtom(x11Display, "WM_DELETE_WINDOW", False); XSetWMProtocols(x11Display, x11Window, &wmDeleteMessage, 1); if(x11_fullscreen) { // fullscreen Atom wmState = XInternAtom(x11Display, "_NET_WM_STATE", False); Atom wmFullscreen = XInternAtom(x11Display, "_NET_WM_STATE_FULLSCREEN", False); XChangeProperty(x11Display, x11Window, wmState, XA_ATOM, 32, PropModeReplace, (unsigned char *)&wmFullscreen, 1); XMapRaised(x11Display, x11Window); } else { XMapWindow(x11Display, x11Window); } #if !defined(GLES) #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB"); verify(glXCreateContextAttribsARB != 0); int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 1, GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, None }; x11_glc = glXCreateContextAttribsARB(x11Display, bestFbc, 0, True, context_attribs); XSync(x11Display, False); if (!x11_glc) { die("Failed to create GL3.1 context\n"); } #endif XFlush(x11Display); //(EGLNativeDisplayType)x11Display; x11_disp = (void*)x11Display; x11_win = (void*)x11Window; x11_vis = (void*)x11Visual->visual; } else { printf("Not creating X11 window ..\n"); } }
/* Loads a joystick map from a section in the configuration file */ void load_joystick_map(joystick_map & js_map, char const * section_name) { // Initialize the file descriptor for the current joystick in case // no joystick is found js_map.js.file_descriptor = -1; if (cfgOpen()) { // Find the desired controller's name char target_name[128]; cfgLoadStr(section_name, "controller.name", target_name, "None"); printf("Using following controller: %s\n", target_name); // We find the corresponding controller for (int i = 0; i <= 3; ++i) { // We check if the names match if (strcmp(js[i].name, target_name) == 0) { js_map.js = js[i]; // We erase the name so the same controller is not used twice js[i].name[0] = '\0'; // And we stop looking for other controllers break; } } if (js_map.js.file_descriptor < 0) { // If no controller was found, no need to load the configuration return; } // Loading axis mapping int id_axis_x = cfgLoadInt(section_name, "js.axis_x", -1); int id_axis_y = cfgLoadInt(section_name, "js.axis_y", -1); int id_axis_lt = cfgLoadInt(section_name, "js.axis_lt", -1); int id_axis_rt = cfgLoadInt(section_name, "js.axis_rt", -1); int id_axis_dpad_x = cfgLoadInt(section_name, "js.axis_dpad_x", -1); int id_axis_dpad_y = cfgLoadInt(section_name, "js.axis_dpad_y", -1); js_map.id_axis_x = id_axis_x; js_map.id_axis_y = id_axis_y; js_map.id_axis_lt = id_axis_lt; js_map.id_axis_rt = id_axis_rt; js_map.id_axis_dpad_x = id_axis_dpad_x; js_map.id_axis_dpad_y = id_axis_dpad_y; // Loading buttons mapping int button_A = cfgLoadInt(section_name, "js.button_A", -1); int button_B = cfgLoadInt(section_name, "js.button_B", -1); int button_C = cfgLoadInt(section_name, "js.button_C", -1); int button_X = cfgLoadInt(section_name, "js.button_X", -1); int button_Y = cfgLoadInt(section_name, "js.button_Y", -1); int button_Z = cfgLoadInt(section_name, "js.button_Z", -1); int button_start = cfgLoadInt(section_name, "js.button_start", -1); js_map.button_map[button_A] = Btn_A; js_map.button_map[button_B] = Btn_B; js_map.button_map[button_C] = Btn_C; js_map.button_map[button_X] = Btn_X; js_map.button_map[button_Y] = Btn_Y; js_map.button_map[button_Z] = Btn_Z; js_map.button_map[button_start] = Btn_Start; } }
/* Loads a keyboard map from a section in the configuration file */ void load_keyboard_map(keyboard_map & kb_map, char const * section_name) { if (cfgOpen()) { // Loading analog keys kb_map.key_axis_up = cfgLoadInt(section_name, "keyboard.axis_up", -1); kb_map.key_axis_down = cfgLoadInt(section_name, "keyboard.axis_down", -1); kb_map.key_axis_left = cfgLoadInt(section_name, "keyboard.axis_left", -1); kb_map.key_axis_right = cfgLoadInt(section_name, "keyboard.axis_right", -1); kb_map.key_axis_lt = cfgLoadInt(section_name, "keyboard.axis_lt", -1); kb_map.key_axis_rt = cfgLoadInt(section_name, "keyboard.axis_rt", -1); // Loading buttons keys unsigned int dpad_up = cfgLoadInt(section_name, "keyboard.dpad_up", -1); unsigned int dpad_down = cfgLoadInt(section_name, "keyboard.dpad_down", -1); unsigned int dpad_left = cfgLoadInt(section_name, "keyboard.dpad_left", -1); unsigned int dpad_right = cfgLoadInt(section_name, "keyboard.dpad_right", -1); unsigned int button_A = cfgLoadInt(section_name, "keyboard.A", -1); unsigned int button_B = cfgLoadInt(section_name, "keyboard.B", -1); //unsigned int button_C = cfgLoadInt(section_name, "keyboard.C", -1); unsigned int button_X = cfgLoadInt(section_name, "keyboard.X", -1); unsigned int button_Y = cfgLoadInt(section_name, "keyboard.Y", -1); //unsigned int button_Z = cfgLoadInt(section_name, "keyboard.Z", -1); unsigned int button_start = cfgLoadInt(section_name, "keyboard.start", -1); kb_map.keymap[dpad_up] = DPad_Up; kb_map.keymap[dpad_down] = DPad_Down; kb_map.keymap[dpad_left] = DPad_Left; kb_map.keymap[dpad_right] = DPad_Right; kb_map.keymap[button_A] = Btn_A; kb_map.keymap[button_B] = Btn_B; //kb_map.keymap[button_C] = Btn_C; kb_map.keymap[button_X] = Btn_X; kb_map.keymap[button_Y] = Btn_Y; //kb_map.keymap[button_Z] = Btn_Z; kb_map.keymap[button_start] = Btn_Start; } }
void LoadSettings() { #ifndef _ANDROID settings.dynarec.Enable = cfgLoadInt("config","Dynarec.Enabled", 1)!=0; settings.dynarec.idleskip = cfgLoadInt("config","Dynarec.idleskip",1)!=0; settings.dynarec.unstable_opt = cfgLoadInt("config","Dynarec.unstable-opt",0); settings.dreamcast.cable = cfgLoadInt("config","Dreamcast.Cable",3); settings.dreamcast.RTC = cfgLoadInt("config","Dreamcast.RTC",GetRTC_now()); settings.dreamcast.region = cfgLoadInt("config","Dreamcast.Region",3); settings.dreamcast.broadcast = cfgLoadInt("config","Dreamcast.Broadcast",4); settings.aica.LimitFPS = cfgLoadInt("config","aica.LimitFPS",1); settings.aica.NoBatch = cfgLoadInt("config","aica.NoBatch",0); settings.aica.NoSound = cfgLoadInt("config","aica.NoSound",0); settings.rend.UseMipmaps = cfgLoadInt("config","rend.UseMipmaps",1); settings.rend.WideScreen = cfgLoadInt("config","rend.WideScreen",0); settings.pvr.subdivide_transp = cfgLoadInt("config","pvr.Subdivide",0); settings.pvr.ta_skip = cfgLoadInt("config","ta.skip",0); settings.pvr.rend = cfgLoadInt("config","pvr.rend",0); settings.debug.SerialConsole = cfgLoadInt("config", "Debug.SerialConsoleEnabled", 0) != 0; settings.reios.ElfFile = cfgLoadStr("reios", "ElfFile",""); settings.validate.OpenGlChecks = cfgLoadInt("validate", "OpenGlChecks", 0) != 0; #endif settings.bios.UseReios = cfgLoadInt("config", "bios.UseReios", 0); #if (HOST_OS != OS_LINUX || defined(_ANDROID) || defined(TARGET_PANDORA)) settings.aica.BufferSize=2048; #else settings.aica.BufferSize=1024; #endif /* //make sure values are valid settings.dreamcast.cable = min(max(settings.dreamcast.cable, 0),3); settings.dreamcast.region = min(max(settings.dreamcast.region, 0),3); settings.dreamcast.broadcast= min(max(settings.dreamcast.broadcast,0),4); */ }
void os_InitAudio() { if (cfgLoadInt("audio","disable",0)) return; cfgSaveInt("audio","disable",0); long loops; int size; snd_pcm_hw_params_t *params; unsigned int val; int dir; snd_pcm_uframes_t frames; /* Open PCM device for playback. */ int rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0); if (rc<0) rc = snd_pcm_open(&handle, "plughw:0,0,0", SND_PCM_STREAM_PLAYBACK, 0); if (rc<0) rc = snd_pcm_open(&handle, "plughw:0,0", SND_PCM_STREAM_PLAYBACK, 0); if (rc < 0) { fprintf(stderr, "unable to open pcm device: %s\n", snd_strerror(rc)); return; } /* Allocate a hardware parameters object. */ snd_pcm_hw_params_alloca(¶ms); /* Fill it in with default values. */ rc=snd_pcm_hw_params_any(handle, params); if (rc < 0) { fprintf(stderr, "Error:snd_pcm_hw_params_any %s\n", snd_strerror(rc)); return; } /* Set the desired hardware parameters. */ /* Interleaved mode */ rc=snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); if (rc < 0) { fprintf(stderr, "Error:snd_pcm_hw_params_set_access %s\n", snd_strerror(rc)); return; } /* Signed 16-bit little-endian format */ rc=snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE); if (rc < 0) { fprintf(stderr, "Error:snd_pcm_hw_params_set_format %s\n", snd_strerror(rc)); return; } /* Two channels (stereo) */ rc=snd_pcm_hw_params_set_channels(handle, params, 2); if (rc < 0) { fprintf(stderr, "Error:snd_pcm_hw_params_set_channels %s\n", snd_strerror(rc)); return; } /* 44100 bits/second sampling rate (CD quality) */ val = 44100; rc=snd_pcm_hw_params_set_rate_near(handle, params, &val, &dir); if (rc < 0) { fprintf(stderr, "Error:snd_pcm_hw_params_set_rate_near %s\n", snd_strerror(rc)); return; } /* Set period size to settings.aica.BufferSize frames. */ frames = settings.aica.BufferSize; rc=snd_pcm_hw_params_set_period_size_near(handle, params, &frames, &dir); if (rc < 0) { fprintf(stderr, "Error:snd_pcm_hw_params_set_buffer_size_near %s\n", snd_strerror(rc)); return; } frames*=4; rc=snd_pcm_hw_params_set_buffer_size_near(handle, params, &frames); if (rc < 0) { fprintf(stderr, "Error:snd_pcm_hw_params_set_buffer_size_near %s\n", snd_strerror(rc)); return; } /* Write the parameters to the driver */ rc = snd_pcm_hw_params(handle, params); if (rc < 0) { fprintf(stderr, "unable to set hw parameters: %s\n", snd_strerror(rc)); return; } aud_thread.Start(); }