diff --git a/360/frontend-xdk/menu.h b/360/frontend-xdk/menu.h index be612e44eb..055efe2257 100644 --- a/360/frontend-xdk/menu.h +++ b/360/frontend-xdk/menu.h @@ -220,8 +220,4 @@ class CRetroArchControls: public CXuiSceneImpl extern CRetroArch app; #endif -int menu_init (void); -void menu_free (void); -void menu_loop (void); - #endif diff --git a/360/xinput_360_input.c b/360/xinput_360_input.c index 2d6515375c..7b9b6aed62 100644 --- a/360/xinput_360_input.c +++ b/360/xinput_360_input.c @@ -17,9 +17,7 @@ #include #include -#ifdef _XBOX #include -#endif #include "../driver.h" #include "../general.h" @@ -29,6 +27,43 @@ static uint64_t state[4]; static unsigned pads_connected; +const struct platform_bind platform_keys[] = { + { XINPUT_GAMEPAD_B, "B button" }, + { XINPUT_GAMEPAD_A, "A button" }, + { XINPUT_GAMEPAD_Y, "Y button" }, + { XINPUT_GAMEPAD_X, "X button" }, + { XINPUT_GAMEPAD_DPAD_UP, "D-Pad Up" }, + { XINPUT_GAMEPAD_DPAD_DOWN, "D-Pad Down" }, + { XINPUT_GAMEPAD_DPAD_LEFT, "D-Pad Left" }, + { XINPUT_GAMEPAD_DPAD_RIGHT, "D-Pad Right" }, + { XINPUT_GAMEPAD_BACK, "Back button" }, + { XINPUT_GAMEPAD_START, "Start button" }, + { XINPUT_GAMEPAD_LEFT_SHOULDER, "Left Shoulder" }, + { XINPUT_GAMEPAD_LEFT_TRIGGER, "Left Trigger" }, + { XINPUT_GAMEPAD_LEFT_THUMB, "Left Thumb" }, + { XINPUT_GAMEPAD_RIGHT_SHOULDER, "Right Shoulder" }, + { XINPUT_GAMEPAD_RIGHT_TRIGGER, "Right Trigger" }, + { XINPUT_GAMEPAD_RIGHT_THUMB, "Right Thumb" }, + { XINPUT_GAMEPAD_LSTICK_LEFT_MASK, "LStick Left" }, + { XINPUT_GAMEPAD_LSTICK_RIGHT_MASK, "LStick Right" }, + { XINPUT_GAMEPAD_LSTICK_UP_MASK, "LStick Up" }, + { XINPUT_GAMEPAD_LSTICK_DOWN_MASK, "LStick Down" }, + { XINPUT_GAMEPAD_DPAD_LEFT | XINPUT_GAMEPAD_LSTICK_LEFT_MASK, "LStick D-Pad Left" }, + { XINPUT_GAMEPAD_DPAD_RIGHT | XINPUT_GAMEPAD_LSTICK_RIGHT_MASK, "LStick D-Pad Right" }, + { XINPUT_GAMEPAD_DPAD_UP | XINPUT_GAMEPAD_LSTICK_UP_MASK, "LStick D-Pad Up" }, + { XINPUT_GAMEPAD_DPAD_DOWN | XINPUT_GAMEPAD_LSTICK_DOWN_MASK, "LStick D-Pad Down" }, + { XINPUT_GAMEPAD_RSTICK_LEFT_MASK, "RStick Left" }, + { XINPUT_GAMEPAD_RSTICK_RIGHT_MASK, "RStick Right" }, + { XINPUT_GAMEPAD_RSTICK_UP_MASK, "RStick Up" }, + { XINPUT_GAMEPAD_RSTICK_DOWN_MASK, "RStick Down" }, + { XINPUT_GAMEPAD_DPAD_LEFT | XINPUT_GAMEPAD_RSTICK_LEFT_MASK, "RStick D-Pad Left" }, + { XINPUT_GAMEPAD_DPAD_RIGHT | XINPUT_GAMEPAD_RSTICK_RIGHT_MASK, "RStick D-Pad Right" }, + { XINPUT_GAMEPAD_DPAD_UP | XINPUT_GAMEPAD_RSTICK_UP_MASK, "RStick D-Pad Up" }, + { XINPUT_GAMEPAD_DPAD_DOWN | XINPUT_GAMEPAD_RSTICK_DOWN_MASK, "RStick D-Pad Down" }, +}; + +const unsigned int platform_keys_size = sizeof(platform_keys); + static void xinput_input_poll(void *data) { (void)data; @@ -73,7 +108,6 @@ static void xinput_input_free_input(void *data) (void)data; } -#ifdef _XBOX360 #include "../console/retroarch_console.h" void xdk360_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id) @@ -100,14 +134,11 @@ void xdk360_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_ break; } } -#endif static void* xinput_input_init(void) { -#ifdef _XBOX360 for(unsigned i = 0; i < 4; i++) xdk360_input_map_dpad_to_stick(g_settings.input.dpad_emulation[i], i); -#endif return (void*)-1; } @@ -116,7 +147,6 @@ static bool xinput_input_key_pressed(void *data, int key) { (void)data; bool retval = false; -#ifdef _XBOX360 XINPUT_STATE state; xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data; @@ -163,11 +193,37 @@ static bool xinput_input_key_pressed(void *data, int key) retval = g_console.ingame_menu_enable ? g_console.ingame_menu_enable : g_console.menu_enable; } } -#endif return retval; } +static void xinput_set_default_keybind_lut(void) +{ + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_B] = platform_keys[XDK_DEVICE_ID_JOYPAD_A].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_Y] = platform_keys[XDK_DEVICE_ID_JOYPAD_X].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_SELECT] = platform_keys[XDK_DEVICE_ID_JOYPAD_BACK].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_START] = platform_keys[XDK_DEVICE_ID_JOYPAD_START].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_UP] = platform_keys[XDK_DEVICE_ID_JOYPAD_UP].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_DOWN] = platform_keys[XDK_DEVICE_ID_JOYPAD_DOWN].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_LEFT] = platform_keys[XDK_DEVICE_ID_JOYPAD_LEFT].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_RIGHT] = platform_keys[XDK_DEVICE_ID_JOYPAD_RIGHT].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_A] = platform_keys[XDK_DEVICE_ID_JOYPAD_B].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_X] = platform_keys[XDK_DEVICE_ID_JOYPAD_Y].joykey; +#if defined(_XBOX1) + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L] = platform_keys[XDK_DEVICE_ID_JOYPAD_LEFT_TRIGGER].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R] = platform_keys[XDK_DEVICE_ID_JOYPAD_RIGHT_TRIGGER].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L2] = platform_keys[XDK_DEVICE_ID_JOYPAD_LB].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R2] = platform_keys[XDK_DEVICE_ID_JOYPAD_RB].joykey; +#elif defined(_XBOX360) + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L] = platform_keys[XDK_DEVICE_ID_JOYPAD_LB].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R] = platform_keys[XDK_DEVICE_ID_JOYPAD_RB].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L2] = platform_keys[XDK_DEVICE_ID_JOYPAD_LEFT_TRIGGER].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R2] = platform_keys[XDK_DEVICE_ID_JOYPAD_RIGHT_TRIGGER].joykey; +#endif + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L3] = platform_keys[XDK_DEVICE_ID_LSTICK_THUMB].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R3] = platform_keys[XDK_DEVICE_ID_RSTICK_THUMB].joykey; +} + const input_driver_t input_xinput = { xinput_input_init, @@ -175,5 +231,6 @@ const input_driver_t input_xinput = xinput_input_state, xinput_input_key_pressed, xinput_input_free_input, + xinput_set_default_keybind_lut, "xinput" }; diff --git a/360/xinput_360_input.h b/360/xinput_360_input.h index 53efa72f74..1c83129cd7 100644 --- a/360/xinput_360_input.h +++ b/360/xinput_360_input.h @@ -30,10 +30,46 @@ enum { XINPUT_GAMEPAD_RIGHT_TRIGGER = 1 << 25 }; +enum xdk_device_id +{ + XDK_DEVICE_ID_JOYPAD_B = 0, + XDK_DEVICE_ID_JOYPAD_A, + XDK_DEVICE_ID_JOYPAD_Y, + XDK_DEVICE_ID_JOYPAD_X, + XDK_DEVICE_ID_JOYPAD_UP, + XDK_DEVICE_ID_JOYPAD_DOWN, + XDK_DEVICE_ID_JOYPAD_LEFT, + XDK_DEVICE_ID_JOYPAD_RIGHT, + XDK_DEVICE_ID_JOYPAD_BACK, + XDK_DEVICE_ID_JOYPAD_START, + XDK_DEVICE_ID_JOYPAD_LB, + XDK_DEVICE_ID_JOYPAD_LEFT_TRIGGER, + XDK_DEVICE_ID_LSTICK_THUMB, + XDK_DEVICE_ID_JOYPAD_RB, + XDK_DEVICE_ID_JOYPAD_RIGHT_TRIGGER, + XDK_DEVICE_ID_RSTICK_THUMB, + XDK_DEVICE_ID_LSTICK_LEFT, + XDK_DEVICE_ID_LSTICK_RIGHT, + XDK_DEVICE_ID_LSTICK_UP, + XDK_DEVICE_ID_LSTICK_DOWN, + XDK_DEVICE_ID_LSTICK_LEFT_DPAD, + XDK_DEVICE_ID_LSTICK_RIGHT_DPAD, + XDK_DEVICE_ID_LSTICK_UP_DPAD, + XDK_DEVICE_ID_LSTICK_DOWN_DPAD, + XDK_DEVICE_ID_RSTICK_LEFT, + XDK_DEVICE_ID_RSTICK_RIGHT, + XDK_DEVICE_ID_RSTICK_UP, + XDK_DEVICE_ID_RSTICK_DOWN, + XDK_DEVICE_ID_RSTICK_LEFT_DPAD, + XDK_DEVICE_ID_RSTICK_RIGHT_DPAD, + XDK_DEVICE_ID_RSTICK_UP_DPAD, + XDK_DEVICE_ID_RSTICK_DOWN_DPAD, + + RARCH_LAST_PLATFORM_KEY +}; + #define DEADZONE (16000) -#ifdef _XBOX extern void xdk360_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id); -#endif #endif diff --git a/Makefile.ps3.retroarch b/Makefile.ps3.retroarch index f39189d309..31ca1f83ee 100644 --- a/Makefile.ps3.retroarch +++ b/Makefile.ps3.retroarch @@ -41,6 +41,8 @@ else PPU_CXXLD = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ld.exe endif +PPU_RANLIB = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ranlib.exe + DEFINES += -DHAVE_DEFAULT_RETROPAD_INPUT -DHAVE_THREAD -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OPENGL_TEXREF -DHAVE_HEADSET -DHAVE_VID_CONTEXT -DHAVE_OPENGLES11 -DHAVE_CG -DHAVE_CG_MENU -DHAVE_FILEBROWSER -DHAVE_HDD_CACHE_PARTITION -DHAVE_FBO -DHAVE_RARCH_MAIN_WRAP -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RGL -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_RSOUND -DHAVE_ZLIB -D__CELLOS_LV2__ -DHAVE_CONFIGFILE=1 -DHAVE_NETPLAY=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_OSKUTIL -DHAVE_MOUSE -DHAVE_GRIFFIN=1 -DHAVE_MULTIMAN=1 -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -Dmain=rarch_main -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) ifeq ($(DEBUG), 1) diff --git a/Makefile.ps3.rgl b/Makefile.ps3.rgl index 7fa4d70fc9..124a37a73a 100644 --- a/Makefile.ps3.rgl +++ b/Makefile.ps3.rgl @@ -34,6 +34,8 @@ else PPU_AR = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ar.exe endif +PPU_RANLIB = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ranlib.exe + PPU_LDLIBS = -lio_stub diff --git a/Makefile.psl1ght b/Makefile.psl1ght index 885b01a8f4..0d8c29b044 100644 --- a/Makefile.psl1ght +++ b/Makefile.psl1ght @@ -26,7 +26,7 @@ LIBS := -lretro_psl1ght -laudio -lEGL -lGL -lio -lm -ljpgdec -lpngdec -lsysutil OBJ = console/griffin/griffin.o console/rzlib/rzlib.o -#OBJ += console/rgl/ps3/device_ctx.o console/rgl/ps3/rgl.o console/rgl/ps3/cgbio.o console/rgl/ps3/cgnv2rt.o +OBJ += console/rgl/ps3/device_ctx.o console/rgl/ps3/rgl.o console/rgl/ps3/cgbio.o console/rgl/ps3/cgnv2rt.o ifeq ($(HAVE_LOGGER), 1) CFLAGS += -DHAVE_LOGGER diff --git a/audio/dsound.c b/audio/dsound.c index c4b5bdae89..d3668cf037 100644 --- a/audio/dsound.c +++ b/audio/dsound.c @@ -21,6 +21,18 @@ // The caller does not have the priority level required for the function to // succeed #define DSERR_PRIOLEVELNEEDED MAKE_DSHRESULT(70) +// Send the audio signal (stereo, without attenuation) to all existing speakers +DSMIXBINVOLUMEPAIR dsmbvp[8] = { + {DSMIXBIN_FRONT_LEFT, DSBVOLUME_MAX}, + {DSMIXBIN_FRONT_RIGHT, DSBVOLUME_MAX}, + {DSMIXBIN_FRONT_CENTER, DSBVOLUME_MAX}, + {DSMIXBIN_FRONT_CENTER, DSBVOLUME_MAX}, + {DSMIXBIN_BACK_LEFT, DSBVOLUME_MAX}, + {DSMIXBIN_BACK_RIGHT, DSBVOLUME_MAX}, + {DSMIXBIN_LOW_FREQUENCY, DSBVOLUME_MAX}, + {DSMIXBIN_LOW_FREQUENCY, DSBVOLUME_MAX}}; + +DSMIXBINS dsmb; #endif #include "../driver.h" @@ -338,6 +350,16 @@ static void *dsound_init(const char *device, unsigned rate, unsigned latency) if (IDirectSound_CreateSoundBuffer(ds->ds, &bufdesc, &ds->dsb, 0) != DS_OK) goto error; + IDirectSoundBuffer_SetVolume(ds->dsb, DSBVOLUME_MAX); + +#ifdef _XBOX + dsmb.dwMixBinCount = 8; + dsmb.lpMixBinVolumePairs = dsmbvp; + + IDirectSoundBuffer_SetHeadroom(ds->dsb, DSBHEADROOM_MIN); + IDirectSoundBuffer_SetMixBins(ds->dsb, &dsmb); +#endif + IDirectSoundBuffer_SetCurrentPosition(ds->dsb, 0); dsound_clear_buffer(ds); diff --git a/console/console_settings.c b/console/console_settings.c index 63cd2fab83..8d5fe67323 100644 --- a/console/console_settings.c +++ b/console/console_settings.c @@ -295,3 +295,76 @@ void rarch_settings_create_menu_item_label(char * str, unsigned setting, size_t break; } } + +void rarch_settings_set_default (const input_driver_t *input) +{ + // g_settings + g_settings.rewind_enable = false; + strlcpy(g_settings.cheat_database, default_paths.port_dir, sizeof(g_settings.cheat_database)); + +#if defined(HAVE_CG) || defined(HAVE_HLSL) || defined(HAVE_GLSL) + strlcpy(g_settings.video.cg_shader_path, default_paths.shader_file, sizeof(g_settings.video.cg_shader_path)); + strlcpy(g_settings.video.second_pass_shader, default_paths.shader_file, sizeof(g_settings.video.second_pass_shader)); + g_settings.video.second_pass_smooth = true; +#endif + +#ifdef HAVE_FBO + g_settings.video.fbo_scale_x = 2.0f; + g_settings.video.fbo_scale_y = 2.0f; +#endif + + g_settings.video.render_to_texture = true; + g_settings.video.smooth = true; + g_settings.video.vsync = true; + + strlcpy(g_settings.system_directory, default_paths.system_dir, sizeof(g_settings.system_directory)); + + g_settings.video.msg_pos_x = 0.05f; + g_settings.video.msg_pos_y = 0.90f; + g_settings.video.aspect_ratio = -1.0f; + + rarch_input_set_controls_default(input); + + // g_console + g_console.block_config_read = true; + g_console.frame_advance_enable = false; + g_console.emulator_initialized = 0; + g_console.screenshots_enable = true; + g_console.throttle_enable = true; + g_console.initialize_rarch_enable = false; + g_console.triple_buffering_enable = true; + g_console.default_savestate_dir_enable = false; + g_console.default_sram_dir_enable = false; + +#ifdef HAVE_FBO + g_console.fbo_enabled = true; +#else + g_console.fbo_enabled = false; +#endif + + g_console.mode_switch = MODE_MENU; + g_console.screen_orientation = ORIENTATION_NORMAL; + g_console.current_resolution_id = 0; + strlcpy(g_console.default_rom_startup_dir, default_paths.filesystem_root_dir, sizeof(g_console.default_rom_startup_dir)); + strlcpy(g_console.default_savestate_dir, default_paths.savestate_dir, sizeof(g_console.default_savestate_dir)); + strlcpy(g_console.default_sram_dir, default_paths.sram_dir, sizeof(g_console.default_sram_dir)); + g_console.aspect_ratio_index = 0; + g_console.menu_font_size = 1.0f; + g_console.overscan_enable = false; + g_console.overscan_amount = 0.0f; + g_console.sound_mode = SOUND_MODE_NORMAL; + g_console.viewports.custom_vp.width = 0; + g_console.viewports.custom_vp.height = 0; + g_console.viewports.custom_vp.x = 0; + g_console.viewports.custom_vp.y = 0; + g_console.custom_bgm_enable = true; + g_console.info_msg_enable = true; +#ifdef _XBOX360 + g_console.color_format = 0; +#endif + + // g_extern + g_extern.state_slot = 0; + g_extern.audio_data.mute = 0; + g_extern.verbose = true; +} diff --git a/console/console_settings.h b/console/console_settings.h index 824ce68df0..fa0affb200 100644 --- a/console/console_settings.h +++ b/console/console_settings.h @@ -105,6 +105,7 @@ enum void rarch_settings_change(unsigned setting); void rarch_settings_default(unsigned setting); void rarch_settings_msg(unsigned setting, unsigned delay); +void rarch_settings_set_default (const input_driver_t *input); void rarch_settings_create_menu_item_label(char * str, unsigned setting, size_t size); void rarch_settings_create_menu_item_label_w(wchar_t *strwbuf, unsigned setting, size_t size); diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index 2cd9fc6b4d..90ddaab09c 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -21,7 +21,19 @@ /*============================================================ CONSOLE EXTENSIONS ============================================================ */ +#include "../retroarch_rom_ext.c" #include "../retroarch_console.c" + +#ifdef HAVE_CONFIGFILE +#include "../retroarch_config.c" +#endif + +#include "../retroarch_console_input.c" + +#ifdef HAVE_ZLIB +#include "../retroarch_rzlib.c" +#endif + #include "../console_settings.c" #ifdef HAVE_LIBRETRO_MANAGEMENT @@ -259,6 +271,15 @@ MENU ============================================================ */ #if defined(_XBOX360) #include "../../360/frontend-xdk/menu.cpp" +#elif defined(_XBOX1) +#include "../../xbox1/frontend/menu.cpp" +#include "../../xbox1/frontend/RetroLaunch/Font.cpp" +#include "../../xbox1/frontend/RetroLaunch/IoSupport.cpp" +#include "../../xbox1/frontend/RetroLaunch/MenuMain.cpp" +#include "../../xbox1/frontend/RetroLaunch/MenuManager.cpp" +#include "../../xbox1/frontend/RetroLaunch/Rom.cpp" +#include "../../xbox1/frontend/RetroLaunch/RomList.cpp" +#include "../../xbox1/frontend/RetroLaunch/Surface.cpp" #elif defined(GEKKO) #include "../../wii/frontend/rgui.c" #include "../../wii/frontend/list.c" diff --git a/console/libretro_mgmt.c b/console/libretro_mgmt.c index 45aca72c18..87844ef4e3 100644 --- a/console/libretro_mgmt.c +++ b/console/libretro_mgmt.c @@ -65,7 +65,7 @@ static bool rarch_manage_libretro_install(char *libretro_core_installed, size_t return ret; } -bool rarch_configure_libretro_core(const char *full_path, const char *tmp_path, +static bool rarch_configure_libretro_core(const char *full_path, const char *tmp_path, const char *libretro_path, const char *config_path, const char *extension) { bool libretro_core_was_installed = false; @@ -139,3 +139,16 @@ void rarch_manage_libretro_set_first_file(char *first_file, size_t size_of_first end: dir_list_free(dir_list); } + +void rarch_configure_libretro(const input_driver_t *input, const char *path_prefix, const char * extension) +{ + char full_path[1024]; + snprintf(full_path, sizeof(full_path), "%sCORE%s", path_prefix, extension); + + bool find_libretro_file = rarch_configure_libretro_core(full_path, path_prefix, path_prefix, + default_paths.config_file, extension); + + rarch_settings_set_default(input); + rarch_config_load(default_paths.config_file, path_prefix, extension, find_libretro_file); + init_libretro_sym(); +} diff --git a/console/libretro_mgmt.h b/console/libretro_mgmt.h index 0ec47db851..07e486e8df 100644 --- a/console/libretro_mgmt.h +++ b/console/libretro_mgmt.h @@ -18,6 +18,7 @@ #define LIBRETRO_MGMT_H__ #include "../boolean.h" +#include "../driver.h" enum { @@ -28,7 +29,6 @@ enum }; void rarch_manage_libretro_set_first_file(char *first_file, size_t size_of_first_file, const char *libretro_path, const char * exe_ext); -bool rarch_configure_libretro_core(const char *full_path, const char *tmp_path, - const char *libretro_path, const char *config_path, const char *extension); +void rarch_configure_libretro(const input_driver_t *input, const char *path_prefix, const char * extension); #endif diff --git a/console/retroarch_config.c b/console/retroarch_config.c new file mode 100644 index 0000000000..e8e71b3317 --- /dev/null +++ b/console/retroarch_config.c @@ -0,0 +1,188 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include + +#include "retroarch_config.h" + +#include "../conf/config_file.h" +#include "../conf/config_file_macros.h" + +void rarch_config_create_default(const char * conf_name) +{ + FILE * f; + RARCH_WARN("Config file \"%s\" doesn't exist. Creating...\n", conf_name); + f = fopen(conf_name, "w"); + fclose(f); +} + +void rarch_config_load(const char * conf_name, const char * libretro_dir_path, const char * exe_ext, bool find_libretro_path) +{ + if(!path_file_exists(conf_name)) + rarch_config_create_default(conf_name); + else + { + config_file_t * conf = config_file_new(conf_name); + + // g_settings + +#ifdef HAVE_LIBRETRO_MANAGEMENT + if(find_libretro_path) + { + CONFIG_GET_STRING(libretro, "libretro_path"); + + if(strcmp(g_settings.libretro, "") == 0) + { + char first_file[PATH_MAX]; + rarch_manage_libretro_set_first_file(first_file, sizeof(first_file), libretro_dir_path, exe_ext); + if(first_file != NULL) + strlcpy(g_settings.libretro, first_file, sizeof(g_settings.libretro)); + } + } +#endif + + CONFIG_GET_STRING(system_directory, "system_directory"); + CONFIG_GET_STRING(cheat_database, "cheat_database"); + CONFIG_GET_BOOL(rewind_enable, "rewind_enable"); + CONFIG_GET_STRING(video.cg_shader_path, "video_cg_shader"); +#ifdef HAVE_FBO + CONFIG_GET_STRING(video.second_pass_shader, "video_second_pass_shader"); + CONFIG_GET_FLOAT(video.fbo_scale_x, "video_fbo_scale_x"); + CONFIG_GET_FLOAT(video.fbo_scale_y, "video_fbo_scale_y"); + CONFIG_GET_BOOL(video.render_to_texture, "video_render_to_texture"); + CONFIG_GET_BOOL(video.second_pass_smooth, "video_second_pass_smooth"); +#endif +#ifdef _XBOX360 + CONFIG_GET_BOOL_CONSOLE(gamma_correction_enable, "gamma_correction_enable"); + CONFIG_GET_INT_CONSOLE(color_format, "color_format"); +#endif + CONFIG_GET_BOOL(video.smooth, "video_smooth"); + CONFIG_GET_BOOL(video.vsync, "video_vsync"); + CONFIG_GET_FLOAT(video.aspect_ratio, "video_aspect_ratio"); + CONFIG_GET_STRING(audio.device, "audio_device"); + + for (unsigned i = 0; i < 7; i++) + { + char cfg[64]; + snprintf(cfg, sizeof(cfg), "input_dpad_emulation_p%u", i + 1); + CONFIG_GET_INT(input.dpad_emulation[i], cfg); + } + + // g_console + +#ifdef HAVE_FBO + CONFIG_GET_BOOL_CONSOLE(fbo_enabled, "fbo_enabled"); +#endif +#ifdef __CELLOS_LV2__ + CONFIG_GET_BOOL_CONSOLE(custom_bgm_enable, "custom_bgm_enable"); +#endif + CONFIG_GET_BOOL_CONSOLE(overscan_enable, "overscan_enable"); + CONFIG_GET_BOOL_CONSOLE(screenshots_enable, "screenshots_enable"); + CONFIG_GET_BOOL_CONSOLE(throttle_enable, "throttle_enable"); + CONFIG_GET_BOOL_CONSOLE(triple_buffering_enable, "triple_buffering_enable"); + CONFIG_GET_BOOL_CONSOLE(info_msg_enable, "info_msg_enable"); + CONFIG_GET_INT_CONSOLE(aspect_ratio_index, "aspect_ratio_index"); + CONFIG_GET_INT_CONSOLE(current_resolution_id, "current_resolution_id"); + CONFIG_GET_INT_CONSOLE(viewports.custom_vp.x, "custom_viewport_x"); + CONFIG_GET_INT_CONSOLE(viewports.custom_vp.y, "custom_viewport_y"); + CONFIG_GET_INT_CONSOLE(viewports.custom_vp.width, "custom_viewport_width"); + CONFIG_GET_INT_CONSOLE(viewports.custom_vp.height, "custom_viewport_height"); + CONFIG_GET_INT_CONSOLE(screen_orientation, "screen_orientation"); + CONFIG_GET_INT_CONSOLE(sound_mode, "sound_mode"); + CONFIG_GET_STRING_CONSOLE(default_rom_startup_dir, "default_rom_startup_dir"); + CONFIG_GET_FLOAT_CONSOLE(menu_font_size, "menu_font_size"); + CONFIG_GET_FLOAT_CONSOLE(overscan_amount, "overscan_amount"); + + // g_extern + CONFIG_GET_INT_EXTERN(state_slot, "state_slot"); + CONFIG_GET_INT_EXTERN(audio_data.mute, "audio_mute"); + } +} + +void rarch_config_save(const char * conf_name) +{ + if(!path_file_exists(conf_name)) + rarch_config_create_default(conf_name); + else + { + config_file_t * conf = config_file_new(conf_name); + + if(conf == NULL) + conf = config_file_new(NULL); + + // g_settings + config_set_string(conf, "libretro_path", g_settings.libretro); +#ifdef HAVE_XML + config_set_string(conf, "cheat_database_path", g_settings.cheat_database); +#endif + config_set_bool(conf, "rewind_enable", g_settings.rewind_enable); + config_set_string(conf, "video_cg_shader", g_settings.video.cg_shader_path); + config_set_float(conf, "video_aspect_ratio", g_settings.video.aspect_ratio); +#ifdef HAVE_FBO + config_set_float(conf, "video_fbo_scale_x", g_settings.video.fbo_scale_x); + config_set_float(conf, "video_fbo_scale_y", g_settings.video.fbo_scale_y); + config_set_string(conf, "video_second_pass_shader", g_settings.video.second_pass_shader); + config_set_bool(conf, "video_render_to_texture", g_settings.video.render_to_texture); + config_set_bool(conf, "video_second_pass_smooth", g_settings.video.second_pass_smooth); +#endif + config_set_bool(conf, "video_smooth", g_settings.video.smooth); + config_set_bool(conf, "video_vsync", g_settings.video.vsync); + config_set_string(conf, "audio_device", g_settings.audio.device); + + for (unsigned i = 0; i < 7; i++) + { + char cfg[64]; + snprintf(cfg, sizeof(cfg), "input_dpad_emulation_p%u", i + 1); + config_set_int(conf, cfg, g_settings.input.dpad_emulation[i]); + } + +#ifdef RARCH_CONSOLE + config_set_bool(conf, "fbo_enabled", g_console.fbo_enabled); +#ifdef __CELLOS_LV2__ + config_set_bool(conf, "custom_bgm_enable", g_console.custom_bgm_enable); +#endif + config_set_bool(conf, "overscan_enable", g_console.overscan_enable); + config_set_bool(conf, "screenshots_enable", g_console.screenshots_enable); +#ifdef _XBOX + config_set_bool(conf, "gamma_correction_enable", g_console.gamma_correction_enable); + config_set_int(conf, "color_format", g_console.color_format); +#endif + config_set_bool(conf, "throttle_enable", g_console.throttle_enable); + config_set_bool(conf, "triple_buffering_enable", g_console.triple_buffering_enable); + config_set_bool(conf, "info_msg_enable", g_console.info_msg_enable); + config_set_int(conf, "sound_mode", g_console.sound_mode); + config_set_int(conf, "aspect_ratio_index", g_console.aspect_ratio_index); + config_set_int(conf, "current_resolution_id", g_console.current_resolution_id); + config_set_int(conf, "custom_viewport_width", g_console.viewports.custom_vp.width); + config_set_int(conf, "custom_viewport_height", g_console.viewports.custom_vp.height); + config_set_int(conf, "custom_viewport_x", g_console.viewports.custom_vp.x); + config_set_int(conf, "custom_viewport_y", g_console.viewports.custom_vp.y); + config_set_int(conf, "screen_orientation", g_console.screen_orientation); + config_set_string(conf, "default_rom_startup_dir", g_console.default_rom_startup_dir); + config_set_float(conf, "menu_font_size", g_console.menu_font_size); + config_set_float(conf, "overscan_amount", g_console.overscan_amount); +#endif + + // g_extern + config_set_int(conf, "state_slot", g_extern.state_slot); + config_set_int(conf, "audio_mute", g_extern.audio_data.mute); + + if (!config_file_write(conf, conf_name)) + RARCH_ERR("Failed to write config file to \"%s\". Check permissions.\n", conf_name); + + free(conf); + } +} diff --git a/ps3/frontend/shared.h b/console/retroarch_config.h similarity index 55% rename from ps3/frontend/shared.h rename to console/retroarch_config.h index 3432973ba2..1ed691b422 100644 --- a/ps3/frontend/shared.h +++ b/console/retroarch_config.h @@ -14,22 +14,18 @@ * If not, see . */ -#ifndef _PS3_SHARED_H -#define _PS3_SHARED_H +#ifndef _RARCH_CONSOLE_CONFIG_H +#define _RARCH_CONSOLE_CONFIG_H -extern char usrDirPath[PATH_MAX]; -extern char systemDirPath[PATH_MAX]; -extern char DEFAULT_PRESET_FILE[PATH_MAX]; -extern char DEFAULT_BORDER_FILE[PATH_MAX]; -extern char DEFAULT_MENU_BORDER_FILE[PATH_MAX]; -extern char PRESETS_DIR_PATH[PATH_MAX]; -extern char INPUT_PRESETS_DIR_PATH[PATH_MAX]; -extern char BORDERS_DIR_PATH[PATH_MAX]; -extern char SHADERS_DIR_PATH[PATH_MAX]; -extern char DEFAULT_SHADER_FILE[PATH_MAX]; -extern char DEFAULT_MENU_SHADER_FILE[PATH_MAX]; -extern char LIBRETRO_DIR_PATH[PATH_MAX]; -extern char SYS_CONFIG_FILE[PATH_MAX]; -extern char MULTIMAN_EXECUTABLE[PATH_MAX]; +enum +{ + CONFIG_FILE, + SHADER_PRESET_FILE, + INPUT_PRESET_FILE +}; + +void rarch_config_create_default(const char * conf_name); +void rarch_config_load(const char * conf_name, const char * libretro_dir_path, const char * exe_ext, bool find_libretro_path); +void rarch_config_save(const char * conf_name); #endif diff --git a/console/retroarch_console.c b/console/retroarch_console.c index bf02ab41b7..30497ba745 100644 --- a/console/retroarch_console.c +++ b/console/retroarch_console.c @@ -18,7 +18,6 @@ #include #include #include -#include #include "../boolean.h" #include "../compat/strl.h" #include "../libretro.h" @@ -27,614 +26,9 @@ #include "retroarch_console.h" #include "../file.h" -#ifdef HAVE_CONFIGFILE -#include "../conf/config_file.h" -#include "../conf/config_file_macros.h" -#endif - -#ifdef HAVE_ZLIB -#include "rzlib/zlib.h" -#define WRITEBUFFERSIZE (1024 * 512) -#endif - -#ifdef _WIN32 -#include "../compat/posix_string.h" -#endif - #define MAX_ARGS 32 -/*============================================================ - ROM EXTENSIONS -============================================================ */ - -void rarch_console_load_game(const char *path) -{ - snprintf(g_console.rom_path, sizeof(g_console.rom_path), path); - rarch_settings_change(S_START_RARCH); -} - -const char *rarch_console_get_rom_ext(void) -{ - const char *retval = NULL; - - struct retro_system_info info; -#ifdef ANDROID - pretro_get_system_info(&info); -#else - retro_get_system_info(&info); -#endif - - if (info.valid_extensions) - retval = info.valid_extensions; - else - retval = "ZIP|zip"; - - return retval; -} - -void rarch_console_name_from_id(char *name, size_t size) -{ - if (size == 0) - return; - - struct retro_system_info info; -#ifdef ANDROID - pretro_get_system_info(&info); -#else - retro_get_system_info(&info); -#endif - const char *id = info.library_name ? info.library_name : "Unknown"; - - if (!id || strlen(id) >= size) - { - name[0] = '\0'; - return; - } - - name[strlen(id)] = '\0'; - - for (size_t i = 0; id[i] != '\0'; i++) - { - char c = id[i]; - if (isspace(c) || isblank(c)) - name[i] = '_'; - else - name[i] = tolower(c); - } -} - -#ifdef HAVE_ZLIB -static int rarch_extract_currentfile_in_zip(unzFile uf) -{ - char filename_inzip[PATH_MAX]; - FILE *fout = NULL; - - unz_file_info file_info; - int err = unzGetCurrentFileInfo(uf, - &file_info, filename_inzip, sizeof(filename_inzip), - NULL, 0, NULL, 0); - - if (err != UNZ_OK) - { - RARCH_ERR("Error %d with ZIP file in unzGetCurrentFileInfo.\n", err); - return err; - } - - size_t size_buf = WRITEBUFFERSIZE; - void *buf = malloc(size_buf); - if (!buf) - { - RARCH_ERR("Error allocating memory\n"); - return UNZ_INTERNALERROR; - } - - char write_filename[PATH_MAX]; - -#ifdef HAVE_HDD_CACHE_PARTITION - -#if defined(__CELLOS_LV2__) - snprintf(write_filename, sizeof(write_filename), "/dev_hdd1/%s", filename_inzip); -#elif defined(_XBOX) - snprintf(write_filename, sizeof(write_filename), "cache:\\%s", filename_inzip); -#endif - -#endif - - err = unzOpenCurrentFile(uf); - if (err != UNZ_OK) - RARCH_ERR("Error %d with ZIP file in unzOpenCurrentFile.\n", err); - else - { - /* success */ - fout = fopen(write_filename, "wb"); - - if (!fout) - RARCH_ERR("Error opening %s.\n", write_filename); - } - - if (fout) - { - RARCH_LOG("Extracting: %s\n", write_filename); - - do - { - err = unzReadCurrentFile(uf, buf, size_buf); - if (err < 0) - { - RARCH_ERR("error %d with ZIP file in unzReadCurrentFile.\n", err); - break; - } - - if (err > 0) - { - if (fwrite(buf, err, 1, fout) != 1) - { - RARCH_ERR("Error in writing extracted file.\n"); - err = UNZ_ERRNO; - break; - } - } - } while (err > 0); - - if (fout) - fclose(fout); - } - - if (err == UNZ_OK) - { - err = unzCloseCurrentFile (uf); - if (err != UNZ_OK) - RARCH_ERR("Error %d with ZIP file in unzCloseCurrentFile.\n", err); - } - else - unzCloseCurrentFile(uf); - - free(buf); - return err; -} - -int rarch_extract_zipfile(const char *zip_path) -{ - unzFile uf = unzOpen(zip_path); - - unz_global_info gi; - int err = unzGetGlobalInfo(uf, &gi); - if (err != UNZ_OK) - RARCH_ERR("error %d with ZIP file in unzGetGlobalInfo \n",err); - - for (unsigned i = 0; i < gi.number_entry; i++) - { - if (rarch_extract_currentfile_in_zip(uf) != UNZ_OK) - break; - - if ((i + 1) < gi.number_entry) - { - err = unzGoToNextFile(uf); - if (err != UNZ_OK) - { - RARCH_ERR("error %d with ZIP file in unzGoToNextFile\n",err); - break; - } - } - } - -#ifdef HAVE_HDD_CACHE_PARTITION - if(g_console.info_msg_enable) - rarch_settings_msg(S_MSG_EXTRACTED_ZIPFILE, S_DELAY_180); -#endif - - return 0; -} - -#endif - - -/*============================================================ - INPUT EXTENSIONS -============================================================ */ - -#include "retroarch_console_input.h" - -struct platform_bind -{ - uint64_t joykey; - const char *label; -}; - -uint64_t rarch_default_keybind_lut[RARCH_FIRST_META_KEY]; - -char rarch_default_libretro_keybind_name_lut[RARCH_FIRST_META_KEY][256] = { - "RetroPad Button B", /* RETRO_DEVICE_ID_JOYPAD_B */ - "RetroPad Button Y", /* RETRO_DEVICE_ID_JOYPAD_Y */ - "RetroPad Button Select", /* RETRO_DEVICE_ID_JOYPAD_SELECT */ - "RetroPad Button Start", /* RETRO_DEVICE_ID_JOYPAD_START */ - "RetroPad D-Pad Up", /* RETRO_DEVICE_ID_JOYPAD_UP */ - "RetroPad D-Pad Down", /* RETRO_DEVICE_ID_JOYPAD_DOWN */ - "RetroPad D-Pad Left", /* RETRO_DEVICE_ID_JOYPAD_LEFT */ - "RetroPad D-Pad Right", /* RETRO_DEVICE_ID_JOYPAD_RIGHT */ - "RetroPad Button A", /* RETRO_DEVICE_ID_JOYPAD_A */ - "RetroPad Button X", /* RETRO_DEVICE_ID_JOYPAD_X */ - "RetroPad Button L1", /* RETRO_DEVICE_ID_JOYPAD_L */ - "RetroPad Button R1", /* RETRO_DEVICE_ID_JOYPAD_R */ - "RetroPad Button L2", /* RETRO_DEVICE_ID_JOYPAD_L2 */ - "RetroPad Button R2", /* RETRO_DEVICE_ID_JOYPAD_R2 */ - "RetroPad Button L3", /* RETRO_DEVICE_ID_JOYPAD_L3 */ - "RetroPad Button R3", /* RETRO_DEVICE_ID_JOYPAD_R3 */ -}; - -#if defined(__CELLOS_LV2__) -static const struct platform_bind platform_keys[] = { - { CTRL_CIRCLE_MASK, "Circle button" }, - { CTRL_CROSS_MASK, "Cross button" }, - { CTRL_TRIANGLE_MASK, "Triangle button" }, - { CTRL_SQUARE_MASK, "Square button" }, - { CTRL_UP_MASK, "D-Pad Up" }, - { CTRL_DOWN_MASK, "D-Pad Down" }, - { CTRL_LEFT_MASK, "D-Pad Left" }, - { CTRL_RIGHT_MASK, "D-Pad Right" }, - { CTRL_SELECT_MASK, "Select button" }, - { CTRL_START_MASK, "Start button" }, - { CTRL_L1_MASK, "L1 button" }, - { CTRL_L2_MASK, "L2 button" }, - { CTRL_L3_MASK, "L3 button" }, - { CTRL_R1_MASK, "R1 button" }, - { CTRL_R2_MASK, "R2 button" }, - { CTRL_R3_MASK, "R3 button" }, - { CTRL_LSTICK_LEFT_MASK, "LStick Left" }, - { CTRL_LSTICK_RIGHT_MASK, "LStick Right" }, - { CTRL_LSTICK_UP_MASK, "LStick Up" }, - { CTRL_LSTICK_DOWN_MASK, "LStick Down" }, - { CTRL_LEFT_MASK | CTRL_LSTICK_LEFT_MASK, "LStick D-Pad Left" }, - { CTRL_RIGHT_MASK | CTRL_LSTICK_RIGHT_MASK, "LStick D-Pad Right" }, - { CTRL_UP_MASK | CTRL_LSTICK_UP_MASK, "LStick D-Pad Up" }, - { CTRL_DOWN_MASK | CTRL_LSTICK_DOWN_MASK, "LStick D-Pad Down" }, - { CTRL_RSTICK_LEFT_MASK, "RStick Left" }, - { CTRL_RSTICK_RIGHT_MASK, "RStick Right" }, - { CTRL_RSTICK_UP_MASK, "RStick Up" }, - { CTRL_RSTICK_DOWN_MASK, "RStick Down" }, - { CTRL_LEFT_MASK | CTRL_RSTICK_LEFT_MASK, "RStick D-Pad Left" }, - { CTRL_RIGHT_MASK | CTRL_RSTICK_RIGHT_MASK, "RStick D-Pad Right" }, - { CTRL_UP_MASK | CTRL_RSTICK_UP_MASK, "RStick D-Pad Up" }, - { CTRL_DOWN_MASK | CTRL_RSTICK_DOWN_MASK, "RStick D-Pad Down" }, -}; -#elif defined(_XBOX360) -static const struct platform_bind platform_keys[] = { - { XINPUT_GAMEPAD_B, "B button" }, - { XINPUT_GAMEPAD_A, "A button" }, - { XINPUT_GAMEPAD_Y, "Y button" }, - { XINPUT_GAMEPAD_X, "X button" }, - { XINPUT_GAMEPAD_DPAD_UP, "D-Pad Up" }, - { XINPUT_GAMEPAD_DPAD_DOWN, "D-Pad Down" }, - { XINPUT_GAMEPAD_DPAD_LEFT, "D-Pad Left" }, - { XINPUT_GAMEPAD_DPAD_RIGHT, "D-Pad Right" }, - { XINPUT_GAMEPAD_BACK, "Back button" }, - { XINPUT_GAMEPAD_START, "Start button" }, - { XINPUT_GAMEPAD_LEFT_SHOULDER, "Left Shoulder" }, - { XINPUT_GAMEPAD_LEFT_TRIGGER, "Left Trigger" }, - { XINPUT_GAMEPAD_LEFT_THUMB, "Left Thumb" }, - { XINPUT_GAMEPAD_RIGHT_SHOULDER, "Right Shoulder" }, - { XINPUT_GAMEPAD_RIGHT_TRIGGER, "Right Trigger" }, - { XINPUT_GAMEPAD_RIGHT_THUMB, "Right Thumb" }, - { XINPUT_GAMEPAD_LSTICK_LEFT_MASK, "LStick Left" }, - { XINPUT_GAMEPAD_LSTICK_RIGHT_MASK, "LStick Right" }, - { XINPUT_GAMEPAD_LSTICK_UP_MASK, "LStick Up" }, - { XINPUT_GAMEPAD_LSTICK_DOWN_MASK, "LStick Down" }, - { XINPUT_GAMEPAD_DPAD_LEFT | XINPUT_GAMEPAD_LSTICK_LEFT_MASK, "LStick D-Pad Left" }, - { XINPUT_GAMEPAD_DPAD_RIGHT | XINPUT_GAMEPAD_LSTICK_RIGHT_MASK, "LStick D-Pad Right" }, - { XINPUT_GAMEPAD_DPAD_UP | XINPUT_GAMEPAD_LSTICK_UP_MASK, "LStick D-Pad Up" }, - { XINPUT_GAMEPAD_DPAD_DOWN | XINPUT_GAMEPAD_LSTICK_DOWN_MASK, "LStick D-Pad Down" }, - { XINPUT_GAMEPAD_RSTICK_LEFT_MASK, "RStick Left" }, - { XINPUT_GAMEPAD_RSTICK_RIGHT_MASK, "RStick Right" }, - { XINPUT_GAMEPAD_RSTICK_UP_MASK, "RStick Up" }, - { XINPUT_GAMEPAD_RSTICK_DOWN_MASK, "RStick Down" }, - { XINPUT_GAMEPAD_DPAD_LEFT | XINPUT_GAMEPAD_RSTICK_LEFT_MASK, "RStick D-Pad Left" }, - { XINPUT_GAMEPAD_DPAD_RIGHT | XINPUT_GAMEPAD_RSTICK_RIGHT_MASK, "RStick D-Pad Right" }, - { XINPUT_GAMEPAD_DPAD_UP | XINPUT_GAMEPAD_RSTICK_UP_MASK, "RStick D-Pad Up" }, - { XINPUT_GAMEPAD_DPAD_DOWN | XINPUT_GAMEPAD_RSTICK_DOWN_MASK, "RStick D-Pad Down" }, -}; -#elif defined(_XBOX1) -static const struct platform_bind platform_keys[] = { - { XINPUT1_GAMEPAD_B, "B button" }, - { XINPUT1_GAMEPAD_A, "A button" }, - { XINPUT1_GAMEPAD_Y, "Y button" }, - { XINPUT1_GAMEPAD_X, "X button" }, - { XINPUT1_GAMEPAD_DPAD_UP, "D-Pad Up" }, - { XINPUT1_GAMEPAD_DPAD_DOWN, "D-Pad Down" }, - { XINPUT1_GAMEPAD_DPAD_LEFT, "D-Pad Left" }, - { XINPUT1_GAMEPAD_DPAD_RIGHT, "D-Pad Right" }, - { XINPUT1_GAMEPAD_BACK, "Back button" }, - { XINPUT1_GAMEPAD_START, "Start button" }, - { XINPUT1_GAMEPAD_WHITE, "White button" }, - { XINPUT1_GAMEPAD_LEFT_TRIGGER, "Left Trigger" }, - { XINPUT1_GAMEPAD_LEFT_THUMB, "Left Thumb" }, - { XINPUT1_GAMEPAD_BLACK, "Black button" }, - { XINPUT1_GAMEPAD_RIGHT_TRIGGER, "Right Trigger" }, - { XINPUT1_GAMEPAD_RIGHT_THUMB, "Right Thumb" }, - { XINPUT1_GAMEPAD_LSTICK_LEFT_MASK, "LStick Left" }, - { XINPUT1_GAMEPAD_LSTICK_RIGHT_MASK, "LStick Right" }, - { XINPUT1_GAMEPAD_LSTICK_UP_MASK, "LStick Up" }, - { XINPUT1_GAMEPAD_LSTICK_DOWN_MASK, "LStick Down" }, - { XINPUT1_GAMEPAD_DPAD_LEFT | XINPUT1_GAMEPAD_LSTICK_LEFT_MASK, "LStick D-Pad Left" }, - { XINPUT1_GAMEPAD_DPAD_RIGHT | XINPUT1_GAMEPAD_LSTICK_RIGHT_MASK, "LStick D-Pad Right" }, - { XINPUT1_GAMEPAD_DPAD_UP | XINPUT1_GAMEPAD_LSTICK_UP_MASK, "LStick D-Pad Up" }, - { XINPUT1_GAMEPAD_DPAD_DOWN | XINPUT1_GAMEPAD_LSTICK_DOWN_MASK, "LStick D-Pad Down" }, - { XINPUT1_GAMEPAD_RSTICK_LEFT_MASK, "RStick Left" }, - { XINPUT1_GAMEPAD_RSTICK_RIGHT_MASK, "RStick Right" }, - { XINPUT1_GAMEPAD_RSTICK_UP_MASK, "RStick Up" }, - { XINPUT1_GAMEPAD_RSTICK_DOWN_MASK, "RStick Down" }, - { XINPUT1_GAMEPAD_DPAD_LEFT | XINPUT1_GAMEPAD_RSTICK_LEFT_MASK, "RStick D-Pad Left" }, - { XINPUT1_GAMEPAD_DPAD_RIGHT | XINPUT1_GAMEPAD_RSTICK_RIGHT_MASK, "RStick D-Pad Right" }, - { XINPUT1_GAMEPAD_DPAD_UP | XINPUT1_GAMEPAD_RSTICK_UP_MASK, "RStick D-Pad Up" }, - { XINPUT1_GAMEPAD_DPAD_DOWN | XINPUT1_GAMEPAD_RSTICK_DOWN_MASK, "RStick D-Pad Down" }, -}; -#elif defined(GEKKO) -static const struct platform_bind platform_keys[] = { - { WII_GC_A, "GC A button" }, - { WII_GC_B, "GC B button" }, - { WII_GC_X, "GC X button" }, - { WII_GC_Y, "GC Y button" }, - { WII_GC_UP, "GC D-Pad Up" }, - { WII_GC_DOWN, "GC D-Pad Down" }, - { WII_GC_LEFT, "GC D-Pad Left" }, - { WII_GC_RIGHT, "GC D-Pad Right" }, - { WII_GC_Z_TRIGGER, "GC Z Trigger" }, - { WII_GC_START, "GC Start button" }, - { WII_GC_L_TRIGGER, "GC Left Trigger" }, - { WII_GC_R_TRIGGER, "GC Right Trigger" }, - { WII_GC_LSTICK_LEFT, "GC Main Stick Left" }, - { WII_GC_LSTICK_RIGHT, "GC Main Stick Right" }, - { WII_GC_LSTICK_UP, "GC Main Stick Up" }, - { WII_GC_LSTICK_DOWN, "GC Main Stick Down" }, - { WII_GC_LSTICK_LEFT | WII_GC_LEFT, "GC Main Stick D-Pad Left" }, - { WII_GC_LSTICK_RIGHT | WII_GC_RIGHT, "GC Main Stick D-Pad Right" }, - { WII_GC_LSTICK_UP | WII_GC_UP, "GC Main Stick D-Pad Up" }, - { WII_GC_LSTICK_DOWN | WII_GC_DOWN, "GC Main Stick D-Pad Down" }, - { WII_GC_RSTICK_LEFT, "GC C-Stick Left" }, - { WII_GC_RSTICK_RIGHT, "GC C-Stick Right" }, - { WII_GC_RSTICK_UP, "GC C-Stick Up" }, - { WII_GC_RSTICK_DOWN, "GC C-Stick Down" }, - { WII_GC_RSTICK_LEFT | WII_GC_LEFT, "GC C-Stick D-Pad Left" }, - { WII_GC_RSTICK_RIGHT | WII_GC_RIGHT, "GC C-Stick D-Pad Right" }, - { WII_GC_RSTICK_UP | WII_GC_UP, "GC C-Stick D-Pad Up" }, - { WII_GC_RSTICK_DOWN | WII_GC_DOWN, "GC C-Stick D-Pad Down" }, - -#ifdef HW_RVL - // CLASSIC CONTROLLER - { WII_CLASSIC_A, "Classic A button" }, - { WII_CLASSIC_B, "Classic B button" }, - { WII_CLASSIC_X, "Classic X button" }, - { WII_CLASSIC_Y, "Classic Y button" }, - { WII_CLASSIC_UP, "Classic D-Pad Up" }, - { WII_CLASSIC_DOWN, "Classic D-Pad Down" }, - { WII_CLASSIC_LEFT, "Classic D-Pad Left" }, - { WII_CLASSIC_RIGHT, "Classic D-Pad Right" }, - { WII_CLASSIC_PLUS, "Classic Plus button" }, - { WII_CLASSIC_MINUS, "Classic Minus button" }, - { WII_CLASSIC_HOME, "Classic Home button" }, - { WII_CLASSIC_L_TRIGGER, "Classic L Trigger" }, - { WII_CLASSIC_R_TRIGGER, "Classic R Trigger" }, - { WII_CLASSIC_ZL_TRIGGER, "Classic ZL Trigger" }, - { WII_CLASSIC_ZR_TRIGGER, "Classic ZR Trigger" }, - { WII_CLASSIC_LSTICK_LEFT, "Classic LStick Left" }, - { WII_CLASSIC_LSTICK_RIGHT, "Classic LStick Right" }, - { WII_CLASSIC_LSTICK_UP, "Classic LStick Up" }, - { WII_CLASSIC_LSTICK_DOWN, "Classic LStick Down" }, - { WII_CLASSIC_LSTICK_LEFT | WII_CLASSIC_LEFT, "Classic LStick D-Pad Left" }, - { WII_CLASSIC_LSTICK_RIGHT | WII_CLASSIC_RIGHT, "Classic LStick D-Pad Right" }, - { WII_CLASSIC_LSTICK_UP | WII_CLASSIC_UP, "Classic LStick D-Pad Up" }, - { WII_CLASSIC_LSTICK_DOWN | WII_CLASSIC_DOWN, "Classic LStick D-Pad Down" }, - { WII_CLASSIC_RSTICK_LEFT, "Classic RStick Left" }, - { WII_CLASSIC_RSTICK_RIGHT, "Classic RStick Right" }, - { WII_CLASSIC_RSTICK_UP, "Classic RStick Up" }, - { WII_CLASSIC_RSTICK_DOWN, "Classic RStick Down" }, - { WII_CLASSIC_RSTICK_LEFT | WII_CLASSIC_LEFT, "Classic RStick D-Pad Left" }, - { WII_CLASSIC_RSTICK_RIGHT | WII_CLASSIC_RIGHT, "Classic RStick D-Pad Right" }, - { WII_CLASSIC_RSTICK_UP | WII_CLASSIC_UP, "Classic RStick D-Pad Up" }, - { WII_CLASSIC_RSTICK_DOWN | WII_CLASSIC_DOWN, "Classic RStick D-Pad Down" }, - - // WIIMOTE (PLUS OPTIONAL NUNCHUK) - { WII_WIIMOTE_A, "Wiimote A button" }, - { WII_WIIMOTE_B, "Wiimote B button" }, - { WII_WIIMOTE_1, "Wiimote 1 button" }, - { WII_WIIMOTE_2, "Wiimote 2 button" }, - { WII_WIIMOTE_UP, "Wiimote D-Pad Up" }, - { WII_WIIMOTE_DOWN, "Wiimote D-Pad Down" }, - { WII_WIIMOTE_LEFT, "Wiimote D-Pad Left" }, - { WII_WIIMOTE_RIGHT, "Wiimote D-Pad Right" }, - { WII_WIIMOTE_PLUS, "Wiimote Plus button" }, - { WII_WIIMOTE_MINUS, "Wiimote Minus button" }, - { WII_WIIMOTE_HOME, "Wiimote Home button" }, - { WII_NUNCHUK_Z, "Nunchuk Z button" }, - { WII_NUNCHUK_C, "Nunchuk C button" }, - { WII_NUNCHUK_LEFT, "Nunchuk Stick Left" }, - { WII_NUNCHUK_RIGHT, "Nunchuk Stick Right" }, - { WII_NUNCHUK_UP, "Nunchuk Stick Up" }, - { WII_NUNCHUK_DOWN, "Nunchuk Stick Down" }, - { WII_NUNCHUK_LEFT | WII_WIIMOTE_LEFT, "Nunchuk Stick D-Pad Left" }, - { WII_NUNCHUK_RIGHT | WII_WIIMOTE_RIGHT, "Nunchuk Stick D-Pad Right" }, - { WII_NUNCHUK_UP | WII_WIIMOTE_UP, "Nunchuk Stick D-Pad Up" }, - { WII_NUNCHUK_DOWN | WII_WIIMOTE_DOWN, "Nunchuk Stick D-Pad Down" }, -#endif -}; -#endif - -#ifdef HAVE_DEFAULT_RETROPAD_INPUT - -uint64_t rarch_input_find_previous_platform_key(uint64_t joykey) -{ - size_t arr_size = sizeof(platform_keys) / sizeof(platform_keys[0]); - - if (platform_keys[0].joykey == joykey) - return joykey; - - for (size_t i = 1; i < arr_size; i++) - { - if (platform_keys[i].joykey == joykey) - return platform_keys[i - 1].joykey; - } - - return NO_BTN; -} - -uint64_t rarch_input_find_next_platform_key(uint64_t joykey) -{ - size_t arr_size = sizeof(platform_keys) / sizeof(platform_keys[0]); - if (platform_keys[arr_size - 1].joykey == joykey) - return joykey; - - for (size_t i = 0; i < arr_size - 1; i++) - { - if (platform_keys[i].joykey == joykey) - return platform_keys[i + 1].joykey; - } - - return NO_BTN; -} - -const char *rarch_input_find_platform_key_label(uint64_t joykey) -{ - if (joykey == NO_BTN) - return "No button"; - - size_t arr_size = sizeof(platform_keys) / sizeof(platform_keys[0]); - for (size_t i = 0; i < arr_size; i++) - { - if (platform_keys[i].joykey == joykey) - return platform_keys[i].label; - } - - return "Unknown"; -} - - -void rarch_input_set_keybind(unsigned player, unsigned keybind_action, uint64_t default_retro_joypad_id) -{ - uint64_t *key = &g_settings.input.binds[player][default_retro_joypad_id].joykey; - - switch (keybind_action) - { - case KEYBIND_DECREMENT: - *key = rarch_input_find_previous_platform_key(*key); - break; - - case KEYBIND_INCREMENT: - *key = rarch_input_find_next_platform_key(*key); - break; - - case KEYBIND_DEFAULT: - *key = rarch_default_keybind_lut[default_retro_joypad_id]; - break; - - default: - break; - } -} - -void rarch_input_set_default_keybinds(unsigned player) -{ - for (unsigned i = 0; i < RARCH_FIRST_META_KEY; i++) - { - g_settings.input.binds[player][i].id = i; - g_settings.input.binds[player][i].joykey = rarch_default_keybind_lut[i]; - } - g_settings.input.dpad_emulation[player] = DPAD_EMULATION_LSTICK; -} - -void rarch_input_set_controls_default (void) -{ -#if defined(__CELLOS_LV2__) - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_B] = platform_keys[PS3_DEVICE_ID_JOYPAD_CROSS].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_Y] = platform_keys[PS3_DEVICE_ID_JOYPAD_SQUARE].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_SELECT] = platform_keys[PS3_DEVICE_ID_JOYPAD_SELECT].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_START] = platform_keys[PS3_DEVICE_ID_JOYPAD_START].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_UP] = platform_keys[PS3_DEVICE_ID_JOYPAD_UP].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_DOWN] = platform_keys[PS3_DEVICE_ID_JOYPAD_DOWN].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_LEFT] = platform_keys[PS3_DEVICE_ID_JOYPAD_LEFT].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_RIGHT] = platform_keys[PS3_DEVICE_ID_JOYPAD_RIGHT].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_A] = platform_keys[PS3_DEVICE_ID_JOYPAD_CIRCLE].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_X] = platform_keys[PS3_DEVICE_ID_JOYPAD_TRIANGLE].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L] = platform_keys[PS3_DEVICE_ID_JOYPAD_L1].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R] = platform_keys[PS3_DEVICE_ID_JOYPAD_R1].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R2] = platform_keys[PS3_DEVICE_ID_JOYPAD_R2].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R3] = platform_keys[PS3_DEVICE_ID_JOYPAD_R3].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L2] = platform_keys[PS3_DEVICE_ID_JOYPAD_L2].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L3] = platform_keys[PS3_DEVICE_ID_JOYPAD_L3].joykey; -#elif defined(_XBOX) - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_B] = platform_keys[XDK_DEVICE_ID_JOYPAD_A].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_Y] = platform_keys[XDK_DEVICE_ID_JOYPAD_X].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_SELECT] = platform_keys[XDK_DEVICE_ID_JOYPAD_BACK].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_START] = platform_keys[XDK_DEVICE_ID_JOYPAD_START].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_UP] = platform_keys[XDK_DEVICE_ID_JOYPAD_UP].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_DOWN] = platform_keys[XDK_DEVICE_ID_JOYPAD_DOWN].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_LEFT] = platform_keys[XDK_DEVICE_ID_JOYPAD_LEFT].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_RIGHT] = platform_keys[XDK_DEVICE_ID_JOYPAD_RIGHT].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_A] = platform_keys[XDK_DEVICE_ID_JOYPAD_B].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_X] = platform_keys[XDK_DEVICE_ID_JOYPAD_Y].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L] = platform_keys[XDK_DEVICE_ID_JOYPAD_LB].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R] = platform_keys[XDK_DEVICE_ID_JOYPAD_RB].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L2] = platform_keys[XDK_DEVICE_ID_JOYPAD_LEFT_TRIGGER].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R2] = platform_keys[XDK_DEVICE_ID_JOYPAD_RIGHT_TRIGGER].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L3] = platform_keys[XDK_DEVICE_ID_LSTICK_THUMB].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R3] = platform_keys[XDK_DEVICE_ID_RSTICK_THUMB].joykey; -#elif defined(GEKKO) - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_B] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_B].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_Y] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_Y].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_SELECT] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_Z_TRIGGER].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_START] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_START].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_UP] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_UP].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_DOWN] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_DOWN].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_LEFT] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_LEFT].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_RIGHT] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_RIGHT].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_A] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_A].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_X] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_X].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_L_TRIGGER].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_R_TRIGGER].joykey; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L2] = 0; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R2] = 0; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L3] = 0; - rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R3] = 0; -#endif - for(uint32_t x = 0; x < MAX_PLAYERS; x++) - rarch_input_set_default_keybinds(x); -} - -const char *rarch_input_get_default_keybind_name(unsigned id) -{ - return rarch_default_libretro_keybind_name_lut[id]; -} - -#endif - -void rarch_input_set_default_keybind_names_for_emulator(void) -{ - struct retro_system_info info; -#ifdef ANDROID - pretro_get_system_info(&info); -#else - retro_get_system_info(&info); -#endif - const char *id = info.library_name ? info.library_name : "Unknown"; - - // Genesis Plus GX/Next - if (strstr(id, "Genesis Plus GX")) - { - strlcpy(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_B], - "B button", sizeof(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_B])); - strlcpy(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_A], - "C button", sizeof(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_A])); - strlcpy(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_X], - "Y button", sizeof(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_X])); - strlcpy(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_Y], - "A button", sizeof(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_Y])); - strlcpy(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_L], - "X button", sizeof(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_L])); - strlcpy(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_R], - "Z button", sizeof(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_R])); - strlcpy(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_SELECT], - "Mode button", sizeof(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_SELECT])); - } -} - +default_paths_t default_paths; /*============================================================ VIDEO EXTENSIONS @@ -672,10 +66,10 @@ struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END] = { char rotation_lut[ASPECT_RATIO_END][PATH_MAX] = { - "Normal", - "Vertical", - "Flipped", - "Flipped Rotated" + "Normal", + "Vertical", + "Flipped", + "Flipped Rotated" }; void rarch_set_auto_viewport(unsigned width, unsigned height) @@ -910,175 +304,3 @@ const char * rarch_convert_wchar_to_const_char(const wchar_t * wstr) wcstombs(str, wstr, sizeof(str)); return str; } - -/*============================================================ - CONFIG - ============================================================ */ - -#ifdef HAVE_CONFIGFILE -void rarch_config_create_default(const char * conf_name) -{ - FILE * f; - RARCH_WARN("Config file \"%s\" doesn't exist. Creating...\n", conf_name); - f = fopen(conf_name, "w"); - fclose(f); -} - -void rarch_config_load(const char * conf_name, const char * libretro_dir_path, const char * exe_ext, bool find_libretro_path) -{ - if(!path_file_exists(conf_name)) - rarch_config_create_default(conf_name); - else - { - config_file_t * conf = config_file_new(conf_name); - - // g_settings - -#ifdef HAVE_LIBRETRO_MANAGEMENT - if(find_libretro_path) - { - CONFIG_GET_STRING(libretro, "libretro_path"); - - if(strcmp(g_settings.libretro, "") == 0) - { - char first_file[PATH_MAX]; - rarch_manage_libretro_set_first_file(first_file, sizeof(first_file), libretro_dir_path, exe_ext); - if(first_file != NULL) - strlcpy(g_settings.libretro, first_file, sizeof(g_settings.libretro)); - } - } -#endif - - CONFIG_GET_STRING(system_directory, "system_directory"); - CONFIG_GET_STRING(cheat_database, "cheat_database"); - CONFIG_GET_BOOL(rewind_enable, "rewind_enable"); - CONFIG_GET_STRING(video.cg_shader_path, "video_cg_shader"); -#ifdef HAVE_FBO - CONFIG_GET_STRING(video.second_pass_shader, "video_second_pass_shader"); - CONFIG_GET_FLOAT(video.fbo_scale_x, "video_fbo_scale_x"); - CONFIG_GET_FLOAT(video.fbo_scale_y, "video_fbo_scale_y"); - CONFIG_GET_BOOL(video.render_to_texture, "video_render_to_texture"); - CONFIG_GET_BOOL(video.second_pass_smooth, "video_second_pass_smooth"); -#endif -#ifdef _XBOX - CONFIG_GET_BOOL_CONSOLE(gamma_correction_enable, "gamma_correction_enable"); - CONFIG_GET_INT_CONSOLE(color_format, "color_format"); -#endif - CONFIG_GET_BOOL(video.smooth, "video_smooth"); - CONFIG_GET_BOOL(video.vsync, "video_vsync"); - CONFIG_GET_FLOAT(video.aspect_ratio, "video_aspect_ratio"); - CONFIG_GET_STRING(audio.device, "audio_device"); - - for (unsigned i = 0; i < 7; i++) - { - char cfg[64]; - snprintf(cfg, sizeof(cfg), "input_dpad_emulation_p%u", i + 1); - CONFIG_GET_INT(input.dpad_emulation[i], cfg); - } - - // g_console - -#ifdef HAVE_FBO - CONFIG_GET_BOOL_CONSOLE(fbo_enabled, "fbo_enabled"); -#endif -#ifdef __CELLOS_LV2__ - CONFIG_GET_BOOL_CONSOLE(custom_bgm_enable, "custom_bgm_enable"); -#endif - CONFIG_GET_BOOL_CONSOLE(overscan_enable, "overscan_enable"); - CONFIG_GET_BOOL_CONSOLE(screenshots_enable, "screenshots_enable"); - CONFIG_GET_BOOL_CONSOLE(throttle_enable, "throttle_enable"); - CONFIG_GET_BOOL_CONSOLE(triple_buffering_enable, "triple_buffering_enable"); - CONFIG_GET_BOOL_CONSOLE(info_msg_enable, "info_msg_enable"); - CONFIG_GET_INT_CONSOLE(aspect_ratio_index, "aspect_ratio_index"); - CONFIG_GET_INT_CONSOLE(current_resolution_id, "current_resolution_id"); - CONFIG_GET_INT_CONSOLE(viewports.custom_vp.x, "custom_viewport_x"); - CONFIG_GET_INT_CONSOLE(viewports.custom_vp.y, "custom_viewport_y"); - CONFIG_GET_INT_CONSOLE(viewports.custom_vp.width, "custom_viewport_width"); - CONFIG_GET_INT_CONSOLE(viewports.custom_vp.height, "custom_viewport_height"); - CONFIG_GET_INT_CONSOLE(screen_orientation, "screen_orientation"); - CONFIG_GET_INT_CONSOLE(sound_mode, "sound_mode"); - CONFIG_GET_STRING_CONSOLE(default_rom_startup_dir, "default_rom_startup_dir"); - CONFIG_GET_FLOAT_CONSOLE(menu_font_size, "menu_font_size"); - CONFIG_GET_FLOAT_CONSOLE(overscan_amount, "overscan_amount"); - - // g_extern - CONFIG_GET_INT_EXTERN(state_slot, "state_slot"); - CONFIG_GET_INT_EXTERN(audio_data.mute, "audio_mute"); - } -} - -void rarch_config_save(const char * conf_name) -{ - if(!path_file_exists(conf_name)) - rarch_config_create_default(conf_name); - else - { - config_file_t * conf = config_file_new(conf_name); - - if(conf == NULL) - conf = config_file_new(NULL); - - // g_settings - config_set_string(conf, "libretro_path", g_settings.libretro); -#ifdef HAVE_XML - config_set_string(conf, "cheat_database_path", g_settings.cheat_database); -#endif - config_set_bool(conf, "rewind_enable", g_settings.rewind_enable); - config_set_string(conf, "video_cg_shader", g_settings.video.cg_shader_path); - config_set_float(conf, "video_aspect_ratio", g_settings.video.aspect_ratio); -#ifdef HAVE_FBO - config_set_float(conf, "video_fbo_scale_x", g_settings.video.fbo_scale_x); - config_set_float(conf, "video_fbo_scale_y", g_settings.video.fbo_scale_y); - config_set_string(conf, "video_second_pass_shader", g_settings.video.second_pass_shader); - config_set_bool(conf, "video_render_to_texture", g_settings.video.render_to_texture); - config_set_bool(conf, "video_second_pass_smooth", g_settings.video.second_pass_smooth); -#endif - config_set_bool(conf, "video_smooth", g_settings.video.smooth); - config_set_bool(conf, "video_vsync", g_settings.video.vsync); - config_set_string(conf, "audio_device", g_settings.audio.device); - - for (unsigned i = 0; i < 7; i++) - { - char cfg[64]; - snprintf(cfg, sizeof(cfg), "input_dpad_emulation_p%u", i + 1); - config_set_int(conf, cfg, g_settings.input.dpad_emulation[i]); - } - -#ifdef RARCH_CONSOLE - config_set_bool(conf, "fbo_enabled", g_console.fbo_enabled); -#ifdef __CELLOS_LV2__ - config_set_bool(conf, "custom_bgm_enable", g_console.custom_bgm_enable); -#endif - config_set_bool(conf, "overscan_enable", g_console.overscan_enable); - config_set_bool(conf, "screenshots_enable", g_console.screenshots_enable); -#ifdef _XBOX - config_set_bool(conf, "gamma_correction_enable", g_console.gamma_correction_enable); - config_set_int(conf, "color_format", g_console.color_format); -#endif - config_set_bool(conf, "throttle_enable", g_console.throttle_enable); - config_set_bool(conf, "triple_buffering_enable", g_console.triple_buffering_enable); - config_set_bool(conf, "info_msg_enable", g_console.info_msg_enable); - config_set_int(conf, "sound_mode", g_console.sound_mode); - config_set_int(conf, "aspect_ratio_index", g_console.aspect_ratio_index); - config_set_int(conf, "current_resolution_id", g_console.current_resolution_id); - config_set_int(conf, "custom_viewport_width", g_console.viewports.custom_vp.width); - config_set_int(conf, "custom_viewport_height", g_console.viewports.custom_vp.height); - config_set_int(conf, "custom_viewport_x", g_console.viewports.custom_vp.x); - config_set_int(conf, "custom_viewport_y", g_console.viewports.custom_vp.y); - config_set_int(conf, "screen_orientation", g_console.screen_orientation); - config_set_string(conf, "default_rom_startup_dir", g_console.default_rom_startup_dir); - config_set_float(conf, "menu_font_size", g_console.menu_font_size); - config_set_float(conf, "overscan_amount", g_console.overscan_amount); -#endif - - // g_extern - config_set_int(conf, "state_slot", g_extern.state_slot); - config_set_int(conf, "audio_mute", g_extern.audio_data.mute); - - if (!config_file_write(conf, conf_name)) - RARCH_ERR("Failed to write config file to \"%s\". Check permissions.\n", conf_name); - - free(conf); - } -} -#endif diff --git a/console/retroarch_console.h b/console/retroarch_console.h index 5a0e161131..7931eac951 100644 --- a/console/retroarch_console.h +++ b/console/retroarch_console.h @@ -114,12 +114,6 @@ extern struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END]; extern void rarch_set_auto_viewport(unsigned width, unsigned height); extern void rarch_load_shader(unsigned slot, const char *path); -#include "retroarch_console_input.h" - -/*============================================================ - SOUND -============================================================ */ - enum { SOUND_MODE_NORMAL, @@ -131,43 +125,35 @@ enum #endif }; -/*============================================================ - ROM EXTENSIONS -============================================================ */ - -void rarch_console_load_game(const char *path); - -// Get rom extensions for current library. -// Returns NULL if library doesn't have any preferences in particular. -const char *rarch_console_get_rom_ext(void); - -// Transforms a library id to a name suitable as a pathname. -void rarch_console_name_from_id(char *name, size_t size); - -#ifdef HAVE_ZLIB -int rarch_extract_zipfile(const char *zip_path); +typedef struct +{ + char menu_border_file[PATH_MAX]; + char border_file[PATH_MAX]; + char border_dir[PATH_MAX]; +#ifdef HAVE_HDD_CACHE_PARTITION + char cache_dir[PATH_MAX]; #endif - -/*============================================================ - INPUT EXTENSIONS -============================================================ */ - -#ifdef HAVE_DEFAULT_RETROPAD_INPUT -const char *rarch_input_find_platform_key_label(uint64_t joykey); -uint64_t rarch_input_find_previous_platform_key(uint64_t joykey); -uint64_t rarch_input_find_next_platform_key(uint64_t joykey); - -// Sets custom default keybind names (some systems emulated by the emulator -// will need different keybind names for buttons, etc.) -void rarch_input_set_default_keybind_names_for_emulator(void); -void rarch_input_set_default_keybinds(unsigned player); - -void rarch_input_set_keybind(unsigned player, unsigned keybind_action, uint64_t default_retro_joypad_id); - -void rarch_input_set_controls_default (void); -const char *rarch_input_get_default_keybind_name (unsigned id); + char cgp_dir[PATH_MAX]; + char config_file[PATH_MAX]; + char core_dir[PATH_MAX]; + char executable_extension[PATH_MAX]; + char filesystem_root_dir[PATH_MAX]; + char input_presets_dir[PATH_MAX]; +#ifdef HAVE_MULTIMAN + char multiman_self_file[PATH_MAX]; #endif + char port_dir[PATH_MAX]; + char savestate_dir[PATH_MAX]; +#if defined(HAVE_CG) || defined(HAVE_HLSL) || defined(HAVE_GLSL) + char menu_shader_file[PATH_MAX]; + char shader_file[PATH_MAX]; + char shader_dir[PATH_MAX]; +#endif + char sram_dir[PATH_MAX]; + char system_dir[PATH_MAX]; +} default_paths_t; +extern default_paths_t default_paths; /*============================================================ RetroArch @@ -226,13 +212,9 @@ const char * rarch_convert_wchar_to_const_char(const wchar_t * wstr); enum { - CONFIG_FILE, - SHADER_PRESET_FILE, - INPUT_PRESET_FILE + MODE_EMULATION = 0, + MODE_MENU, + MODE_EXIT }; -void rarch_config_create_default(const char * conf_name); -void rarch_config_load(const char * conf_name, const char * libretro_dir_path, const char * exe_ext, bool find_libretro_path); -void rarch_config_save(const char * conf_name); - #endif diff --git a/console/retroarch_console_input.c b/console/retroarch_console_input.c new file mode 100644 index 0000000000..a86977449a --- /dev/null +++ b/console/retroarch_console_input.c @@ -0,0 +1,182 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include +#include +#include +#include +#include "../boolean.h" +#include "retroarch_console_input.h" + +struct platform_bind +{ + uint64_t joykey; + const char *label; +}; + +uint64_t rarch_default_keybind_lut[RARCH_FIRST_META_KEY]; + +char rarch_default_libretro_keybind_name_lut[RARCH_FIRST_META_KEY][256] = { + "RetroPad Button B", /* RETRO_DEVICE_ID_JOYPAD_B */ + "RetroPad Button Y", /* RETRO_DEVICE_ID_JOYPAD_Y */ + "RetroPad Button Select", /* RETRO_DEVICE_ID_JOYPAD_SELECT */ + "RetroPad Button Start", /* RETRO_DEVICE_ID_JOYPAD_START */ + "RetroPad D-Pad Up", /* RETRO_DEVICE_ID_JOYPAD_UP */ + "RetroPad D-Pad Down", /* RETRO_DEVICE_ID_JOYPAD_DOWN */ + "RetroPad D-Pad Left", /* RETRO_DEVICE_ID_JOYPAD_LEFT */ + "RetroPad D-Pad Right", /* RETRO_DEVICE_ID_JOYPAD_RIGHT */ + "RetroPad Button A", /* RETRO_DEVICE_ID_JOYPAD_A */ + "RetroPad Button X", /* RETRO_DEVICE_ID_JOYPAD_X */ + "RetroPad Button L1", /* RETRO_DEVICE_ID_JOYPAD_L */ + "RetroPad Button R1", /* RETRO_DEVICE_ID_JOYPAD_R */ + "RetroPad Button L2", /* RETRO_DEVICE_ID_JOYPAD_L2 */ + "RetroPad Button R2", /* RETRO_DEVICE_ID_JOYPAD_R2 */ + "RetroPad Button L3", /* RETRO_DEVICE_ID_JOYPAD_L3 */ + "RetroPad Button R3", /* RETRO_DEVICE_ID_JOYPAD_R3 */ +}; + +#ifdef HAVE_DEFAULT_RETROPAD_INPUT + +extern const struct platform_bind platform_keys[]; +extern const unsigned int platform_keys_size; + +uint64_t rarch_input_find_previous_platform_key(uint64_t joykey) +{ + size_t arr_size = platform_keys_size / sizeof(platform_keys[0]); + + if (platform_keys[0].joykey == joykey) + return joykey; + + for (size_t i = 1; i < arr_size; i++) + { + if (platform_keys[i].joykey == joykey) + return platform_keys[i - 1].joykey; + } + + return NO_BTN; +} + +uint64_t rarch_input_find_next_platform_key(uint64_t joykey) +{ + size_t arr_size = platform_keys_size / sizeof(platform_keys[0]); + + if (platform_keys[arr_size - 1].joykey == joykey) + return joykey; + + for (size_t i = 0; i < arr_size - 1; i++) + { + if (platform_keys[i].joykey == joykey) + return platform_keys[i + 1].joykey; + } + + return NO_BTN; +} + +const char *rarch_input_find_platform_key_label(uint64_t joykey) +{ + if (joykey == NO_BTN) + return "No button"; + + size_t arr_size = platform_keys_size / sizeof(platform_keys[0]); + for (size_t i = 0; i < arr_size; i++) + { + if (platform_keys[i].joykey == joykey) + return platform_keys[i].label; + } + + return "Unknown"; +} + + +void rarch_input_set_keybind(unsigned player, unsigned keybind_action, uint64_t default_retro_joypad_id) +{ + uint64_t *key = &g_settings.input.binds[player][default_retro_joypad_id].joykey; + + switch (keybind_action) + { + case KEYBIND_DECREMENT: + *key = rarch_input_find_previous_platform_key(*key); + break; + + case KEYBIND_INCREMENT: + *key = rarch_input_find_next_platform_key(*key); + break; + + case KEYBIND_DEFAULT: + *key = rarch_default_keybind_lut[default_retro_joypad_id]; + break; + + default: + break; + } +} + +void rarch_input_set_default_keybinds(unsigned player) +{ + for (unsigned i = 0; i < RARCH_FIRST_META_KEY; i++) + { + g_settings.input.binds[player][i].id = i; + g_settings.input.binds[player][i].joykey = rarch_default_keybind_lut[i]; + } + g_settings.input.dpad_emulation[player] = DPAD_EMULATION_LSTICK; +} + +void rarch_input_set_controls_default (const input_driver_t *input) +{ + input->set_default_keybind_lut(); + + for(uint32_t x = 0; x < MAX_PLAYERS; x++) + rarch_input_set_default_keybinds(x); +} + +const char *rarch_input_get_default_keybind_name(unsigned id) +{ + return rarch_default_libretro_keybind_name_lut[id]; +} + +#endif + +/* TODO: Hackish, try to do this in a cleaner, more extensible and less hardcoded way */ + +void rarch_input_set_default_keybind_names_for_emulator(void) +{ + struct retro_system_info info; +#ifdef ANDROID + pretro_get_system_info(&info); +#else + retro_get_system_info(&info); +#endif + const char *id = info.library_name ? info.library_name : "Unknown"; + + // Genesis Plus GX/Next + if (strstr(id, "Genesis Plus GX")) + { + strlcpy(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_B], + "B button", sizeof(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_B])); + strlcpy(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_A], + "C button", sizeof(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_A])); + strlcpy(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_X], + "Y button", sizeof(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_X])); + strlcpy(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_Y], + "A button", sizeof(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_Y])); + strlcpy(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_L], + "X button", sizeof(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_L])); + strlcpy(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_R], + "Z button", sizeof(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_R])); + strlcpy(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_SELECT], + "Mode button", sizeof(rarch_default_libretro_keybind_name_lut[RETRO_DEVICE_ID_JOYPAD_SELECT])); + } +} diff --git a/console/retroarch_console_input.h b/console/retroarch_console_input.h index a296df62a5..4f2e86890c 100644 --- a/console/retroarch_console_input.h +++ b/console/retroarch_console_input.h @@ -27,13 +27,6 @@ enum keybind_set_id KEYBIND_DEFAULT }; -enum -{ - MODE_EMULATION = 0, - MODE_MENU, - MODE_EXIT -}; - enum { DPAD_EMULATION_NONE = 0, @@ -41,192 +34,23 @@ enum DPAD_EMULATION_RSTICK }; -#ifdef _XBOX360 -#include "../360/xinput_360_input.h" -#endif - -#if defined(__CELLOS_LV2__) -#include "../ps3/ps3_input.h" -enum ps3_device_id -{ - PS3_DEVICE_ID_JOYPAD_CIRCLE = 0, - PS3_DEVICE_ID_JOYPAD_CROSS, - PS3_DEVICE_ID_JOYPAD_TRIANGLE, - PS3_DEVICE_ID_JOYPAD_SQUARE, - PS3_DEVICE_ID_JOYPAD_UP, - PS3_DEVICE_ID_JOYPAD_DOWN, - PS3_DEVICE_ID_JOYPAD_LEFT, - PS3_DEVICE_ID_JOYPAD_RIGHT, - PS3_DEVICE_ID_JOYPAD_SELECT, - PS3_DEVICE_ID_JOYPAD_START, - PS3_DEVICE_ID_JOYPAD_L1, - PS3_DEVICE_ID_JOYPAD_L2, - PS3_DEVICE_ID_JOYPAD_L3, - PS3_DEVICE_ID_JOYPAD_R1, - PS3_DEVICE_ID_JOYPAD_R2, - PS3_DEVICE_ID_JOYPAD_R3, - PS3_DEVICE_ID_LSTICK_LEFT, - PS3_DEVICE_ID_LSTICK_RIGHT, - PS3_DEVICE_ID_LSTICK_UP, - PS3_DEVICE_ID_LSTICK_DOWN, - PS3_DEVICE_ID_LSTICK_LEFT_DPAD, - PS3_DEVICE_ID_LSTICK_RIGHT_DPAD, - PS3_DEVICE_ID_LSTICK_UP_DPAD, - PS3_DEVICE_ID_LSTICK_DOWN_DPAD, - PS3_DEVICE_ID_RSTICK_LEFT, - PS3_DEVICE_ID_RSTICK_RIGHT, - PS3_DEVICE_ID_RSTICK_UP, - PS3_DEVICE_ID_RSTICK_DOWN, - PS3_DEVICE_ID_RSTICK_LEFT_DPAD, - PS3_DEVICE_ID_RSTICK_RIGHT_DPAD, - PS3_DEVICE_ID_RSTICK_UP_DPAD, - PS3_DEVICE_ID_RSTICK_DOWN_DPAD, - - RARCH_LAST_PLATFORM_KEY -}; - -#elif defined(_XBOX) - -enum xdk_device_id -{ - XDK_DEVICE_ID_JOYPAD_B = 0, - XDK_DEVICE_ID_JOYPAD_A, - XDK_DEVICE_ID_JOYPAD_Y, - XDK_DEVICE_ID_JOYPAD_X, - XDK_DEVICE_ID_JOYPAD_UP, - XDK_DEVICE_ID_JOYPAD_DOWN, - XDK_DEVICE_ID_JOYPAD_LEFT, - XDK_DEVICE_ID_JOYPAD_RIGHT, - XDK_DEVICE_ID_JOYPAD_BACK, - XDK_DEVICE_ID_JOYPAD_START, - XDK_DEVICE_ID_JOYPAD_LB, - XDK_DEVICE_ID_JOYPAD_LEFT_TRIGGER, - XDK_DEVICE_ID_LSTICK_THUMB, - XDK_DEVICE_ID_JOYPAD_RB, - XDK_DEVICE_ID_JOYPAD_RIGHT_TRIGGER, - XDK_DEVICE_ID_RSTICK_THUMB, - XDK_DEVICE_ID_LSTICK_LEFT, - XDK_DEVICE_ID_LSTICK_RIGHT, - XDK_DEVICE_ID_LSTICK_UP, - XDK_DEVICE_ID_LSTICK_DOWN, - XDK_DEVICE_ID_LSTICK_LEFT_DPAD, - XDK_DEVICE_ID_LSTICK_RIGHT_DPAD, - XDK_DEVICE_ID_LSTICK_UP_DPAD, - XDK_DEVICE_ID_LSTICK_DOWN_DPAD, - XDK_DEVICE_ID_RSTICK_LEFT, - XDK_DEVICE_ID_RSTICK_RIGHT, - XDK_DEVICE_ID_RSTICK_UP, - XDK_DEVICE_ID_RSTICK_DOWN, - XDK_DEVICE_ID_RSTICK_LEFT_DPAD, - XDK_DEVICE_ID_RSTICK_RIGHT_DPAD, - XDK_DEVICE_ID_RSTICK_UP_DPAD, - XDK_DEVICE_ID_RSTICK_DOWN_DPAD, - - RARCH_LAST_PLATFORM_KEY -}; - -#ifdef _XBOX1 -#include "../xbox1/xinput_xbox_input.h" -#endif - -#elif defined(GEKKO) -#include "../wii/wii_input.h" - -enum wii_device_id -{ - WII_DEVICE_GC_ID_JOYPAD_A = 0, - WII_DEVICE_GC_ID_JOYPAD_B, - WII_DEVICE_GC_ID_JOYPAD_X, - WII_DEVICE_GC_ID_JOYPAD_Y, - WII_DEVICE_GC_ID_JOYPAD_UP, - WII_DEVICE_GC_ID_JOYPAD_DOWN, - WII_DEVICE_GC_ID_JOYPAD_LEFT, - WII_DEVICE_GC_ID_JOYPAD_RIGHT, - WII_DEVICE_GC_ID_JOYPAD_Z_TRIGGER, - WII_DEVICE_GC_ID_JOYPAD_START, - WII_DEVICE_GC_ID_JOYPAD_L_TRIGGER, - WII_DEVICE_GC_ID_JOYPAD_R_TRIGGER, - WII_DEVICE_GC_ID_LSTICK_LEFT, - WII_DEVICE_GC_ID_LSTICK_RIGHT, - WII_DEVICE_GC_ID_LSTICK_UP, - WII_DEVICE_GC_ID_LSTICK_DOWN, - WII_DEVICE_GC_ID_LSTICK_LEFT_DPAD, - WII_DEVICE_GC_ID_LSTICK_RIGHT_DPAD, - WII_DEVICE_GC_ID_LSTICK_UP_DPAD, - WII_DEVICE_GC_ID_LSTICK_DOWN_DPAD, - WII_DEVICE_GC_ID_RSTICK_LEFT, - WII_DEVICE_GC_ID_RSTICK_RIGHT, - WII_DEVICE_GC_ID_RSTICK_UP, - WII_DEVICE_GC_ID_RSTICK_DOWN, - WII_DEVICE_GC_ID_RSTICK_LEFT_DPAD, - WII_DEVICE_GC_ID_RSTICK_RIGHT_DPAD, - WII_DEVICE_GC_ID_RSTICK_UP_DPAD, - WII_DEVICE_GC_ID_RSTICK_DOWN_DPAD, - -#ifdef HW_RVL - // CLASSIC CONTROLLER - WII_DEVICE_CLASSIC_ID_JOYPAD_A, - WII_DEVICE_CLASSIC_ID_JOYPAD_B, - WII_DEVICE_CLASSIC_ID_JOYPAD_X, - WII_DEVICE_CLASSIC_ID_JOYPAD_Y, - WII_DEVICE_CLASSIC_ID_JOYPAD_UP, - WII_DEVICE_CLASSIC_ID_JOYPAD_DOWN, - WII_DEVICE_CLASSIC_ID_JOYPAD_LEFT, - WII_DEVICE_CLASSIC_ID_JOYPAD_RIGHT, - WII_DEVICE_CLASSIC_ID_JOYPAD_PLUS, - WII_DEVICE_CLASSIC_ID_JOYPAD_MINUS, - WII_DEVICE_CLASSIC_ID_JOYPAD_HOME, - WII_DEVICE_CLASSIC_ID_JOYPAD_L_TRIGGER, - WII_DEVICE_CLASSIC_ID_JOYPAD_R_TRIGGER, - WII_DEVICE_CLASSIC_ID_JOYPAD_ZL_TRIGGER, - WII_DEVICE_CLASSIC_ID_JOYPAD_ZR_TRIGGER, - WII_DEVICE_CLASSIC_ID_LSTICK_LEFT, - WII_DEVICE_CLASSIC_ID_LSTICK_RIGHT, - WII_DEVICE_CLASSIC_ID_LSTICK_UP, - WII_DEVICE_CLASSIC_ID_LSTICK_DOWN, - WII_DEVICE_CLASSIC_ID_LSTICK_LEFT_DPAD, - WII_DEVICE_CLASSIC_ID_LSTICK_RIGHT_DPAD, - WII_DEVICE_CLASSIC_ID_LSTICK_UP_DPAD, - WII_DEVICE_CLASSIC_ID_LSTICK_DOWN_DPAD, - WII_DEVICE_CLASSIC_ID_RSTICK_LEFT, - WII_DEVICE_CLASSIC_ID_RSTICK_RIGHT, - WII_DEVICE_CLASSIC_ID_RSTICK_UP, - WII_DEVICE_CLASSIC_ID_RSTICK_DOWN, - WII_DEVICE_CLASSIC_ID_RSTICK_LEFT_DPAD, - WII_DEVICE_CLASSIC_ID_RSTICK_RIGHT_DPAD, - WII_DEVICE_CLASSIC_ID_RSTICK_UP_DPAD, - WII_DEVICE_CLASSIC_ID_RSTICK_DOWN_DPAD, - - // WIIMOTE (PLUS OPTIONAL NUNCHUK) - WII_DEVICE_WIIMOTE_ID_JOYPAD_A, - WII_DEVICE_WIIMOTE_ID_JOYPAD_B, - WII_DEVICE_WIIMOTE_ID_JOYPAD_1, - WII_DEVICE_WIIMOTE_ID_JOYPAD_2, - WII_DEVICE_WIIMOTE_ID_JOYPAD_UP, - WII_DEVICE_WIIMOTE_ID_JOYPAD_DOWN, - WII_DEVICE_WIIMOTE_ID_JOYPAD_LEFT, - WII_DEVICE_WIIMOTE_ID_JOYPAD_RIGHT, - WII_DEVICE_WIIMOTE_ID_JOYPAD_PLUS, - WII_DEVICE_WIIMOTE_ID_JOYPAD_MINUS, - WII_DEVICE_WIIMOTE_ID_JOYPAD_HOME, - WII_DEVICE_WIIMOTE_ID_JOYPAD_Z, - WII_DEVICE_WIIMOTE_ID_JOYPAD_C, - WII_DEVICE_WIIMOTE_ID_LSTICK_LEFT, - WII_DEVICE_WIIMOTE_ID_LSTICK_RIGHT, - WII_DEVICE_WIIMOTE_ID_LSTICK_UP, - WII_DEVICE_WIIMOTE_ID_LSTICK_DOWN, - WII_DEVICE_WIIMOTE_ID_LSTICK_LEFT_DPAD, - WII_DEVICE_WIIMOTE_ID_LSTICK_RIGHT_DPAD, - WII_DEVICE_WIIMOTE_ID_LSTICK_UP_DPAD, - WII_DEVICE_WIIMOTE_ID_LSTICK_DOWN_DPAD, -#endif - - RARCH_LAST_PLATFORM_KEY -}; - -#endif - extern uint64_t rarch_default_keybind_lut[RARCH_FIRST_META_KEY]; extern char rarch_default_libretro_keybind_name_lut[RARCH_FIRST_META_KEY][256]; +#ifdef HAVE_DEFAULT_RETROPAD_INPUT +const char *rarch_input_find_platform_key_label(uint64_t joykey); +uint64_t rarch_input_find_previous_platform_key(uint64_t joykey); +uint64_t rarch_input_find_next_platform_key(uint64_t joykey); + +// Sets custom default keybind names (some systems emulated by the emulator +// will need different keybind names for buttons, etc.) +void rarch_input_set_default_keybind_names_for_emulator(void); +void rarch_input_set_default_keybinds(unsigned player); + +void rarch_input_set_keybind(unsigned player, unsigned keybind_action, uint64_t default_retro_joypad_id); + +void rarch_input_set_controls_default (const input_driver_t *input); +const char *rarch_input_get_default_keybind_name (unsigned id); +#endif + #endif diff --git a/console/retroarch_rom_ext.c b/console/retroarch_rom_ext.c new file mode 100644 index 0000000000..d49fa84a83 --- /dev/null +++ b/console/retroarch_rom_ext.c @@ -0,0 +1,84 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include +#include + +#ifdef _WIN32 +#include "../compat/posix_string.h" +#endif + +#include "../general.h" + +#include "console_settings.h" + +#include "retroarch_rom_ext.h" + +void rarch_console_load_game(const char *path) +{ + snprintf(g_console.rom_path, sizeof(g_console.rom_path), path); + rarch_settings_change(S_START_RARCH); +} + +const char *rarch_console_get_rom_ext(void) +{ + const char *retval = NULL; + + struct retro_system_info info; +#ifdef ANDROID + pretro_get_system_info(&info); +#else + retro_get_system_info(&info); +#endif + + if (info.valid_extensions) + retval = info.valid_extensions; + else + retval = "ZIP|zip"; + + return retval; +} + +void rarch_console_name_from_id(char *name, size_t size) +{ + if (size == 0) + return; + + struct retro_system_info info; +#ifdef ANDROID + pretro_get_system_info(&info); +#else + retro_get_system_info(&info); +#endif + const char *id = info.library_name ? info.library_name : "Unknown"; + + if (!id || strlen(id) >= size) + { + name[0] = '\0'; + return; + } + + name[strlen(id)] = '\0'; + + for (size_t i = 0; id[i] != '\0'; i++) + { + char c = id[i]; + if (isspace(c) || isblank(c)) + name[i] = '_'; + else + name[i] = tolower(c); + } +} diff --git a/console/retroarch_rom_ext.h b/console/retroarch_rom_ext.h new file mode 100644 index 0000000000..92a56a5e32 --- /dev/null +++ b/console/retroarch_rom_ext.h @@ -0,0 +1,29 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef RARCH_ROM_EXT_H__ +#define RARCH_ROM_EXT_H__ + +void rarch_console_load_game(const char *path); + +// Get rom extensions for current library. +// Returns NULL if library doesn't have any preferences in particular. +const char *rarch_console_get_rom_ext(void); + +// Transforms a library id to a name suitable as a pathname. +void rarch_console_name_from_id(char *name, size_t size); + +#endif diff --git a/console/retroarch_rzlib.c b/console/retroarch_rzlib.c new file mode 100644 index 0000000000..5576f0f97d --- /dev/null +++ b/console/retroarch_rzlib.c @@ -0,0 +1,139 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include +#include +#include +#include +#include "../boolean.h" + +#include "retroarch_rzlib.h" + +static int rarch_extract_currentfile_in_zip(unzFile uf) +{ + char filename_inzip[PATH_MAX]; + FILE *file_out = NULL; + + unz_file_info file_info; + int err = unzGetCurrentFileInfo(uf, + &file_info, filename_inzip, sizeof(filename_inzip), + NULL, 0, NULL, 0); + + if (err != UNZ_OK) + { + RARCH_ERR("Error %d while trying to get ZIP file information.\n", err); + return err; + } + + size_t size_buf = WRITEBUFFERSIZE; + void *buf = malloc(size_buf); + if (!buf) + { + RARCH_ERR("Error allocating memory for ZIP extract operation.\n"); + return UNZ_INTERNALERROR; + } + + char write_filename[PATH_MAX]; + +#ifdef HAVE_HDD_CACHE_PARTITION + snprintf(write_filename, sizeof(write_filename), "%s%s", default_paths.cache_dir, filename_inzip); +#endif + + err = unzOpenCurrentFile(uf); + if (err != UNZ_OK) + RARCH_ERR("Error %d while trying to open ZIP file.\n", err); + else + { + /* success */ + file_out = fopen(write_filename, "wb"); + + if (!file_out) + RARCH_ERR("Error opening %s.\n", write_filename); + } + + if (file_out) + { + RARCH_LOG("Extracting: %s..\n", write_filename); + + do + { + err = unzReadCurrentFile(uf, buf, size_buf); + if (err < 0) + { + RARCH_ERR("Error %d while reading from ZIP file.\n", err); + break; + } + + if (err > 0) + { + if (fwrite(buf, err, 1, file_out) != 1) + { + RARCH_ERR("Error while extracting file(s) from ZIP.\n"); + err = UNZ_ERRNO; + break; + } + } + }while (err > 0); + + if (file_out) + fclose(file_out); + } + + if (err == UNZ_OK) + { + err = unzCloseCurrentFile (uf); + if (err != UNZ_OK) + RARCH_ERR("Error %d while trying to close ZIP file.\n", err); + } + else + unzCloseCurrentFile(uf); + + free(buf); + return err; +} + +int rarch_extract_zipfile(const char *zip_path) +{ + unzFile uf = unzOpen(zip_path); + + unz_global_info gi; + int err = unzGetGlobalInfo(uf, &gi); + if (err != UNZ_OK) + RARCH_ERR("Error %d while trying to get ZIP file global info.\n",err); + + for (unsigned i = 0; i < gi.number_entry; i++) + { + if (rarch_extract_currentfile_in_zip(uf) != UNZ_OK) + break; + + if ((i + 1) < gi.number_entry) + { + err = unzGoToNextFile(uf); + if (err != UNZ_OK) + { + RARCH_ERR("Error %d while trying to go to the next file in the ZIP archive.\n",err); + break; + } + } + } + +#ifdef HAVE_HDD_CACHE_PARTITION + if(g_console.info_msg_enable) + rarch_settings_msg(S_MSG_EXTRACTED_ZIPFILE, S_DELAY_180); +#endif + + return 0; +} diff --git a/console/retroarch_rzlib.h b/console/retroarch_rzlib.h new file mode 100644 index 0000000000..440384d10a --- /dev/null +++ b/console/retroarch_rzlib.h @@ -0,0 +1,26 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef _RARCH_CONSOLE_RZLIB_H +#define _RARCH_CONSOLE_RZLIB_H + +#include "rzlib/zlib.h" + +#define WRITEBUFFERSIZE (1024 * 512) + +int rarch_extract_zipfile(const char *zip_path); + +#endif diff --git a/console/rgl/ps3/cgbio.hpp b/console/rgl/ps3/cgbio.hpp index 69a8525710..53b3915841 100644 --- a/console/rgl/ps3/cgbio.hpp +++ b/console/rgl/ps3/cgbio.hpp @@ -14,16 +14,17 @@ typedef size_t ptrdiff_t; typedef size_t ptrdiff_t; -typedef struct _Elf32_cgParameter { - unsigned int cgp_name; - unsigned int cgp_semantic; - unsigned short cgp_default; - unsigned short cgp_reloc; - unsigned short cgp_resource; - unsigned short cgp_resource_index; - unsigned char cgp_type; - unsigned short cgp_info; - unsigned char unused; +typedef struct _Elf32_cgParameter +{ + unsigned int cgp_name; + unsigned int cgp_semantic; + unsigned short cgp_default; + unsigned short cgp_reloc; + unsigned short cgp_resource; + unsigned short cgp_resource_index; + unsigned char cgp_type; + unsigned short cgp_info; + unsigned char unused; } Elf32_cgParameter; #define ET_NONE 0 @@ -173,21 +174,22 @@ typedef struct _Elf32_cgParameter { #define R_RSX_NONE 0 #define R_RSX_FLOAT4 1 -struct Elf32_Ehdr { - unsigned char e_ident[EI_NIDENT]; - unsigned short e_type; - unsigned short e_machine; - unsigned int e_version; - unsigned int e_entry; - unsigned int e_phoff; - unsigned int e_shoff; - unsigned int e_flags; - unsigned short e_ehsize; - unsigned short e_phentsize; - unsigned short e_phnum; - unsigned short e_shentsize; - unsigned short e_shnum; - unsigned short e_shstrndx; +struct Elf32_Ehdr +{ + unsigned char e_ident[EI_NIDENT]; + unsigned short e_type; + unsigned short e_machine; + unsigned int e_version; + unsigned int e_entry; + unsigned int e_phoff; + unsigned int e_shoff; + unsigned int e_flags; + unsigned short e_ehsize; + unsigned short e_phentsize; + unsigned short e_phnum; + unsigned short e_shentsize; + unsigned short e_shnum; + unsigned short e_shstrndx; }; struct Elf32_Shdr { @@ -223,30 +225,31 @@ struct Elf32_Sym { unsigned short st_shndx; }; -struct Elf32_Note { - unsigned int n_namesz; /* Name size */ - unsigned int n_descsz; /* Content size */ - unsigned int n_type; /* Content type */ +struct Elf32_Note +{ + unsigned int n_namesz; /* Name size */ + unsigned int n_descsz; /* Content size */ + unsigned int n_type; /* Content type */ }; struct Elf32_Rel { - unsigned int r_offset; - unsigned int r_info; + unsigned int r_offset; + unsigned int r_info; }; struct Elf32_Rela { - unsigned int r_offset; - unsigned int r_info; - signed int r_addend; + unsigned int r_offset; + unsigned int r_info; + signed int r_addend; }; struct Elf32_Dyn { - signed int d_tag; - union { - unsigned int d_val; - unsigned int d_ptr; - } d_un; + signed int d_tag; + union { + unsigned int d_val; + unsigned int d_ptr; + } d_un; }; using std::istream; @@ -255,21 +258,21 @@ namespace cgc { namespace bio { enum CGBIO_ERROR { - CGBIO_ERROR_NO_ERROR, - CGBIO_ERROR_LOADED, - CGBIO_ERROR_FILEIO, - CGBIO_ERROR_FORMAT, - CGBIO_ERROR_INDEX, - CGBIO_ERROR_MEMORY, - CGBIO_ERROR_RELOC, - CGBIO_ERROR_SYMBOL, - CGBIO_ERROR_UNKNOWN_TYPE + CGBIO_ERROR_NO_ERROR, + CGBIO_ERROR_LOADED, + CGBIO_ERROR_FILEIO, + CGBIO_ERROR_FORMAT, + CGBIO_ERROR_INDEX, + CGBIO_ERROR_MEMORY, + CGBIO_ERROR_RELOC, + CGBIO_ERROR_SYMBOL, + CGBIO_ERROR_UNKNOWN_TYPE }; typedef enum { - CGBIODATANONE = ELFDATANONE, - CGBIODATALSB = ELFDATA2LSB, - CGBIODATAMSB = ELFDATA2MSB + CGBIODATANONE = ELFDATANONE, + CGBIODATALSB = ELFDATA2LSB, + CGBIODATAMSB = ELFDATA2MSB } HOST_ENDIANNESS; class elf_reader diff --git a/console/rgl/ps3/cgnv2rt.h b/console/rgl/ps3/cgnv2rt.h index 7f015cfae1..dae42e632f 100644 --- a/console/rgl/ps3/cgnv2rt.h +++ b/console/rgl/ps3/cgnv2rt.h @@ -20,59 +20,61 @@ static unsigned int stringTableAdd( STL_NAMESPACE vector &stringTable, const char* str ) { - unsigned int ret = (unsigned int)stringTable.size(); + unsigned int ret = (unsigned int)stringTable.size(); - if ( ret == 0 ) - { - stringTable.push_back('\0'); - ret = 1; - } + if ( ret == 0 ) + { + stringTable.push_back('\0'); + ret = 1; + } - size_t stringLength = strlen(str) + 1; - stringTable.resize(ret + stringLength); - memcpy(&stringTable[0] + ret,str,stringLength); + size_t stringLength = strlen(str) + 1; + stringTable.resize(ret + stringLength); + memcpy(&stringTable[0] + ret,str,stringLength); - return ret; + return ret; } static unsigned int stringTableFind( STL_NAMESPACE vector &stringTable, const char* str ) { - const char* data = &stringTable[0]; - size_t size = stringTable.size(); - const char *end = data + size; + const char* data = &stringTable[0]; + size_t size = stringTable.size(); + const char *end = data + size; - size_t length = strlen(str); - if (length+1 > size) - return 0; - data += length; + size_t length = strlen(str); - const char *p = (char*)memchr(data,'\0',end-data); - while (p && (end-data)>0) - { - if (!memcmp(p - length, str, length)) - { - return (unsigned int)(p - length - &stringTable[0]); - } - data = p+1; - p = (char*)memchr(data,'\0',end-data); - } - return 0; + if (length+1 > size) + return 0; + + data += length; + + const char *p = (char*)memchr(data,'\0',end-data); + while (p && (end-data)>0) + { + if (!memcmp(p - length, str, length)) + return (unsigned int)(p - length - &stringTable[0]); + + data = p+1; + p = (char*)memchr(data,'\0',end-data); + } + return 0; } static unsigned int stringTableAddUnique( STL_NAMESPACE vector &stringTable, const char* str ) { - if ( stringTable.size() == 0 ) - stringTable.push_back('\0'); - unsigned int ret = stringTableFind(stringTable, str); - if (ret == 0 && str[0] != '\0') - ret = stringTableAdd(stringTable, str); - return ret; + if ( stringTable.size() == 0 ) + stringTable.push_back('\0'); + + unsigned int ret = stringTableFind(stringTable, str); + + if (ret == 0 && str[0] != '\0') + ret = stringTableAdd(stringTable, str); + + return ret; } -int convertNvToElfFromFile(const char *sourceFile, int endianness, int constTableOffset, void **binaryShader, int *size, - STL_NAMESPACE vector &stringTable, STL_NAMESPACE vector &defaultValues); -int convertNvToElfFromMemory(const void *sourceData, size_t size, int endianness, int constTableOffset, void **binaryShader, int *binarySize, - STL_NAMESPACE vector &stringTable, STL_NAMESPACE vector &defaultValues); +int convertNvToElfFromFile(const char *sourceFile, int endianness, int constTableOffset, void **binaryShader, int *size, STL_NAMESPACE vector &stringTable, STL_NAMESPACE vector &defaultValues); +int convertNvToElfFromMemory(const void *sourceData, size_t size, int endianness, int constTableOffset, void **binaryShader, int *binarySize, STL_NAMESPACE vector &stringTable, STL_NAMESPACE vector &defaultValues); int convertNvToElfFreeBinaryShader(void *binaryShader); diff --git a/console/rgl/ps3/device_ctx.cpp b/console/rgl/ps3/device_ctx.cpp index 967a51f911..34e3b2757e 100644 --- a/console/rgl/ps3/device_ctx.cpp +++ b/console/rgl/ps3/device_ctx.cpp @@ -18,7 +18,11 @@ #include #endif +#include "../../../general.h" + +#ifndef __PSL1GHT__ using namespace cell::Gcm; +#endif #define _RGL_MAX_TILED_REGIONS 15 @@ -185,8 +189,6 @@ void _RGLFifoFinish( RGLFifo *fifo ) { if ( !_RGLFifoReferenceInUse( fifo, ref ) ) break; - - sys_timer_usleep( 10 ); } } @@ -221,7 +223,6 @@ static void _RGLFifoInit( RGLFifo *fifo, void *dmaControl, unsigned long dmaPush { if ( _RGLFifoReadReference( fifo ) == 0 ) break; - sys_timer_usleep( 10 ); } } fifo->dmaPushBufferGPU = dmaPushBuffer; @@ -307,7 +308,7 @@ GLboolean _RGLInit( PSGLinitOptions* options, RGLResource *resource ) { if ( !_RGLInitFromRM( resource ) ) { - fprintf( stderr, "PSGL GCM failed initialisation" ); + RARCH_ERR("RGL GCM failed initialisation.\n"); return GL_FALSE; } @@ -318,7 +319,7 @@ GLboolean _RGLInit( PSGLinitOptions* options, RGLResource *resource ) resource->hostMemoryBase + resource->hostMemoryReserved, resource->hostMemorySize - resource->hostMemoryReserved ) == GMM_ERROR ) { - fprintf( stderr, "Could not init GPU memory manager" ); + RARCH_ERR("Could not initialize GPU memory manager.\n"); _RGLDestroy(); return GL_FALSE; } @@ -405,7 +406,7 @@ const VideoMode *_RGLDetectVideoMode (void) int ret = cellVideoOutGetState( CELL_VIDEO_OUT_PRIMARY, 0, &videoState ); if ( ret < 0 ) { - printf("RGL WARN: couldn't read the video configuration, using a default 720p resolution.\n"); + RARCH_WARN("Couldn't read the video configuration, using a default 720p resolution.\n"); videoState.displayMode.scanMode = CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE; videoState.displayMode.resolutionId = CELL_VIDEO_OUT_RESOLUTION_720; } @@ -473,9 +474,8 @@ static unsigned int findValidPitch( unsigned int pitch ) else { for ( GLuint i = 0;i < validPitchCount - 1;++i ) - { if (( pitch > validPitch[i] ) && ( pitch <= validPitch[i+1] ) ) return validPitch[i+1]; - } + return validPitch[validPitchCount-1]; } } @@ -518,7 +518,6 @@ int32_t _RGLOutOfSpaceCallback( struct CellGcmContextData* fifoContext, uint32_t || (get < fifo->dmaPushBufferOffset) || (get > fifo->dmaPushBufferOffset + fifo->dmaPushBufferSizeInWords*sizeof(uint32_t))) { - sys_timer_usleep(30); get = fifo->dmaControl->Get; } @@ -538,15 +537,15 @@ void _RGLGraphicsHandler( const uint32_t head ) uint32_t *tmp = ( uint32_t * )(( char* )fifo->dmaPushBufferBegin - fifo->dmaPushBufferOffset + ( *(( volatile GLuint* ) & fifo->dmaControl->Get ) ) ); if (( tmp >= fifo->begin ) && ( tmp <= fifo->end ) ) fifo->lastGetRead = tmp; - printf("RGL: Current PSGL FIFO info \n" ); - printf("RGL: Fifo Begin %p End %p Current %p and Get %p \n", + RARCH_ERR("Current PSGL FIFO info:\n" ); + RARCH_ERR("FIFO Begin %p End %p Current %p and Get %p \n", _RGLState.fifo.begin, _RGLState.fifo.end, _RGLState.fifo.current, _RGLState.fifo.lastGetRead ); - printf("RGL: Last 10 words of the PSGL Fifo from the ppu put/current position \n" ); + RARCH_ERR("Last 10 words of the PSGL Fifo from the ppu put/current position \n" ); _RGLPrintFifoFromPut( 10 ); - printf("RGL: Last 10 words of the PSGL Fifo from the gpu get position \n" ); + RARCH_ERR("Last 10 words of the PSGL Fifo from the gpu get position \n" ); _RGLPrintFifoFromGet( 10 ); } @@ -565,7 +564,7 @@ static int _RGLInitRM( RGLResource *gcmResource, unsigned int hostMemorySize, in if ( cellGcmInit( _RGL_FIFO_SIZE, gcmResource->hostMemorySize, gcmResource->hostMemoryBase ) != 0 ) { - printf("RGL: RSXIF failed initialization\n" ); + RARCH_ERR("RSXIF failed initialization.\n"); return GL_FALSE; } @@ -583,7 +582,7 @@ static int _RGLInitRM( RGLResource *gcmResource, unsigned int hostMemorySize, in gcmResource->semaphores = ( RGLSemaphoreMemory * )cellGcmGetLabelAddress( 0 ); gcmResource->dmaControl = ( char* ) cellGcmGetControlRegister() - (( char * ) & (( RGLControlDma* )0 )->Put - ( char * )0 ); - cellGcmFinish( 1 ); + cellGcmFinish(1); gcmResource->hostMemorySize -= dmaPushBufferSize + _RGL_DMA_PUSH_BUFFER_PREFETCH_PADDING; gcmResource->dmaPushBuffer = gcmResource->hostMemoryBase + gcmResource->hostMemorySize; @@ -595,13 +594,14 @@ static int _RGLInitRM( RGLResource *gcmResource, unsigned int hostMemorySize, in gCellGcmCurrentContext->callback = ( CellGcmContextCallback )_RGLOutOfSpaceCallback; - - printf( "RGL: MClk: %f Mhz NVClk: %f Mhz\n", ( float )gcmResource->MemoryClock / 1E6, ( float )gcmResource->GraphicsClock / 1E6 ); - printf( "RGL: Video Memory: %i MB\n", gcmResource->localSize / ( 1024*1024 ) ); - printf( "RGL: localAddress mapped at %p\n", gcmResource->localAddress ); - printf( "RGL: push buffer at %p - %p (size = 0x%X), offset=0x%lx\n", - gcmResource->dmaPushBuffer, ( char* )gcmResource->dmaPushBuffer + gcmResource->dmaPushBufferSize, gcmResource->dmaPushBufferSize, gcmResource->dmaPushBufferOffset ); - printf( "RGL: dma control at %p\n", gcmResource->dmaControl ); +#ifdef LOG_VERBOSE + RARCH_LOG("MClk: %f Mhz NVClk: %f Mhz.\n", ( float )gcmResource->MemoryClock / 1E6, ( float )gcmResource->GraphicsClock / 1E6 ); + RARCH_LOG("Video Memory: %i MB.\n", gcmResource->localSize / ( 1024*1024 ) ); + RARCH_LOG("Local address mapped at %p.\n", gcmResource->localAddress ); + RARCH_LOG("Push buffer at %p - %p (size = 0x%X), offset=0x%lx.\n", + gcmResource->dmaPushBuffer, ( char* )gcmResource->dmaPushBuffer + gcmResource->dmaPushBufferSize, gcmResource->dmaPushBufferSize, gcmResource->dmaPushBufferOffset ); + RARCH_LOG("DMA control at %p.\n", gcmResource->dmaControl ); +#endif return 1; } @@ -621,7 +621,7 @@ void _RGLDeviceInit( PSGLinitOptions* options ) if ( !_RGLInitRM( &_RGLResource, hostSize, 0, fifoSize ) ) { - printf("RGL: RM resource failed initialisation\n" ); + RARCH_ERR("RM resource failed initialization.\n" ); return; } @@ -714,7 +714,9 @@ GLboolean _RGLAllocateColorSurface( *pitchAllocated = 0; } else - printf("RGL: Allocating GPU memory (tiled): %d bytes allocated at id 0x%08x.\n", *bytesAllocated, *id ); + { + RARCH_LOG("Allocating GPU memory (tiled): %d bytes allocated at id 0x%08x.\n", *bytesAllocated, *id ); + } return *bytesAllocated > 0; } @@ -731,8 +733,7 @@ GLboolean _RGLAllocateColorSurface( static void rescInit( const PSGLdeviceParameters* params, RGLDevice *gcmDevice ) { - printf("RGL WARN: RESC is enabled.\n"); - GLboolean result = 0; + RARCH_WARN("RESC is enabled.\n"); CellRescBufferMode dstBufferMode; if ( params->width == 720 && params->height == 480 ) dstBufferMode = CELL_RESC_720x480; @@ -742,7 +743,7 @@ static void rescInit( const PSGLdeviceParameters* params, RGLDevice *gcmDevice ) else { dstBufferMode = CELL_RESC_720x480; - printf("RGL: Invalid display resolution for resolution conversion: %ux%u. Defaulting to 720x480...\n", params->width, params->height ); + RARCH_ERR("Invalid display resolution for resolution conversion: %ux%u. Defaulting to 720x480...\n", params->width, params->height ); } CellRescInitConfig conf; @@ -763,7 +764,7 @@ static void rescInit( const PSGLdeviceParameters* params, RGLDevice *gcmDevice ) GLuint colorBuffersPitch; uint32_t numColorBuffers = cellRescGetNumColorBuffers( dstBufferMode, ( CellRescPalTemporalMode )conf.palTemporalMode, 0 ); - result = _RGLAllocateColorSurface( params->width, params->height * numColorBuffers, + _RGLAllocateColorSurface( params->width, params->height * numColorBuffers, 4*8, &(gcmDevice->RescColorBuffersId), &colorBuffersPitch, &size ); CellRescDsts dsts = { CELL_RESC_SURFACE_A8R8G8B8, colorBuffersPitch, 1 }; @@ -814,13 +815,10 @@ static int _RGLPlatformCreateDevice( PSGLdevice* device ) jsTiledMemoryManager* mm = &_RGLTiledMemoryManager; _RGLDuringDestroyDevice = GL_FALSE; - GLboolean result = 0; - - int32_t retVal; memset( mm->region, 0, sizeof( mm->region ) ); for ( int i = 0;i < _RGL_MAX_TILED_REGIONS;++i ) - retVal = cellGcmUnbindTile( i ); + cellGcmUnbindTile( i ); const VideoMode *vm = NULL; @@ -873,7 +871,7 @@ static int _RGLPlatformCreateDevice( PSGLdevice* device ) gcmDevice->color[i].pool = _RGL_SURFACE_POOL_LINEAR; GLuint size; - result = _RGLAllocateColorSurface(width, height, + _RGLAllocateColorSurface(width, height, gcmDevice->color[i].bpp*8, &gcmDevice->color[i].dataId, &gcmDevice->color[i].pitch, &size ); } @@ -961,7 +959,7 @@ static int _RGLPlatformCreateDevice( PSGLdevice* device ) if ( cellRescSetSrc( i, &rescSrc ) != CELL_OK ) { - printf("RGL: Registering display buffer %d failed\n", i ); + RARCH_ERR("Registering display buffer %d failed.\n", i ); return -1; } } @@ -978,7 +976,7 @@ static int _RGLPlatformCreateDevice( PSGLdevice* device ) { if ( cellGcmSetDisplayBuffer( i, gmmIdToOffset( gcmDevice->color[i].dataId ), gcmDevice->color[i].pitch , width, height ) != CELL_OK ) { - printf("RGL: Registering display buffer %d failed\n", i ); + RARCH_ERR("Registering display buffer %d failed.\n", i ); return -1; } } @@ -1221,7 +1219,7 @@ GLAPI void psglSwap( void ) int32_t res = cellRescSetConvertAndFlip(( uint8_t ) drawBuffer ); if ( res != CELL_OK ) { - printf("RGL WARN: RESC cellRescSetConvertAndFlip returned error code %d.\n", res); + RARCH_WARN("RESC cellRescSetConvertAndFlip returned error code %d.\n", res); if ( _CurrentContext ) _CurrentContext->needValidate |= PSGL_VALIDATE_FRAMEBUFFER; return; } @@ -1292,8 +1290,7 @@ static inline void _RGLUtilWaitForIdle (void) cellGcmSetWriteBackEndLabelInline( &_RGLState.fifo, RGL_UTIL_LABEL_INDEX, _RGLState.labelValue); cellGcmFlush(); - while( *(cellGcmGetLabelAddress( RGL_UTIL_LABEL_INDEX)) != _RGLState.labelValue) - sys_timer_usleep(30); + while( *(cellGcmGetLabelAddress( RGL_UTIL_LABEL_INDEX)) != _RGLState.labelValue); _RGLState.labelValue++; } @@ -1301,7 +1298,6 @@ static inline void _RGLUtilWaitForIdle (void) GLboolean _RGLTryResizeTileRegion( GLuint address, GLuint size, void* data ) { jsTiledRegion* region = ( jsTiledRegion* )data; - int32_t retVal = 0; if ( size == 0 ) { @@ -1312,7 +1308,7 @@ GLboolean _RGLTryResizeTileRegion( GLuint address, GLuint size, void* data ) if ( ! _RGLDuringDestroyDevice ) { _RGLUtilWaitForIdle(); - retVal = cellGcmUnbindTile( region->id ); + cellGcmUnbindTile( region->id ); _RGLFifoFinish( &_RGLState.fifo ); } return GL_TRUE; @@ -1322,11 +1318,11 @@ GLboolean _RGLTryResizeTileRegion( GLuint address, GLuint size, void* data ) _RGLUtilWaitForIdle(); - retVal = cellGcmSetTileInfo(region->id, CELL_GCM_LOCATION_LOCAL, + cellGcmSetTileInfo(region->id, CELL_GCM_LOCATION_LOCAL, region->offset, region->size, region->pitch, CELL_GCM_COMPMODE_DISABLED, 0, region->bank ); - retVal = cellGcmBindTile( region->id ); + cellGcmBindTile( region->id ); _RGLFifoFinish( &_RGLState.fifo ); diff --git a/console/rgl/ps3/gl.h b/console/rgl/ps3/gl.h index dea55764a1..bfba05e1ca 100644 --- a/console/rgl/ps3/gl.h +++ b/console/rgl/ps3/gl.h @@ -57,22 +57,22 @@ extern "C" #define GLAPI extern #endif - typedef unsigned int GLenum; - typedef unsigned char GLboolean; - typedef unsigned int GLbitfield; - typedef signed char GLbyte; - typedef short GLshort; - typedef int GLint; - typedef int GLsizei; - typedef unsigned char GLubyte; - typedef unsigned short GLushort; - typedef unsigned int GLuint; - typedef float GLfloat; - typedef float GLclampf; - typedef void GLvoid; - typedef int GLfixed; - typedef int GLclampx; - typedef void( *_GLfuncptr )(); +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef signed char GLbyte; +typedef short GLshort; +typedef int GLint; +typedef int GLsizei; +typedef unsigned char GLubyte; +typedef unsigned short GLushort; +typedef unsigned int GLuint; +typedef float GLfloat; +typedef float GLclampf; +typedef void GLvoid; +typedef int GLfixed; +typedef int GLclampx; +typedef void( *_GLfuncptr )(); #define GL_OES_VERSION_1_0 1 #define GL_OES_read_format 1 @@ -290,35 +290,35 @@ extern "C" #define GL_REPEAT 0x2901 #define GL_CLAMP_TO_EDGE 0x812F - GLAPI void APIENTRY glActiveTexture( GLenum texture ); - GLAPI void APIENTRY glBindTexture( GLenum target, GLuint texture ); - GLAPI void APIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor ); - GLAPI void APIENTRY glClear( GLbitfield mask ); - GLAPI void APIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ); - GLAPI void APIENTRY glClearColorx( GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha ); - GLAPI void APIENTRY glClientActiveTexture( GLenum texture ); - GLAPI void APIENTRY glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ); - GLAPI void APIENTRY glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height ); - GLAPI void APIENTRY glDeleteTextures( GLsizei n, const GLuint *textures ); - GLAPI void APIENTRY glDisable( GLenum cap ); - GLAPI void APIENTRY glDisableClientState( GLenum array ); - GLAPI void APIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count ); - GLAPI void APIENTRY glEnable( GLenum cap ); - GLAPI void APIENTRY glEnableClientState( GLenum array ); - GLAPI void APIENTRY glFinish( void ); - GLAPI void APIENTRY glFlush( void ); - GLAPI void APIENTRY glGenTextures( GLsizei n, GLuint *textures ); - GLAPI GLenum APIENTRY glGetError( void ); - GLAPI const GLubyte * APIENTRY glGetString( GLenum name ); - GLAPI void APIENTRY glLoadIdentity( void ); - GLAPI void APIENTRY glMatrixMode( GLenum mode ); - GLAPI void APIENTRY glOrthof( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar ); - GLAPI void APIENTRY glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ); - GLAPI void APIENTRY glPixelStorei( GLenum pname, GLint param ); - GLAPI void APIENTRY glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ); - GLAPI void APIENTRY glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels ); - GLAPI void APIENTRY glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ); - GLAPI void APIENTRY glViewport( GLint x, GLint y, GLsizei width, GLsizei height ); +GLAPI void APIENTRY glActiveTexture( GLenum texture ); +GLAPI void APIENTRY glBindTexture( GLenum target, GLuint texture ); +GLAPI void APIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor ); +GLAPI void APIENTRY glClear( GLbitfield mask ); +GLAPI void APIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ); +GLAPI void APIENTRY glClearColorx( GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha ); +GLAPI void APIENTRY glClientActiveTexture( GLenum texture ); +GLAPI void APIENTRY glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ); +GLAPI void APIENTRY glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height ); +GLAPI void APIENTRY glDeleteTextures( GLsizei n, const GLuint *textures ); +GLAPI void APIENTRY glDisable( GLenum cap ); +GLAPI void APIENTRY glDisableClientState( GLenum array ); +GLAPI void APIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count ); +GLAPI void APIENTRY glEnable( GLenum cap ); +GLAPI void APIENTRY glEnableClientState( GLenum array ); +GLAPI void APIENTRY glFinish( void ); +GLAPI void APIENTRY glFlush( void ); +GLAPI void APIENTRY glGenTextures( GLsizei n, GLuint *textures ); +GLAPI GLenum APIENTRY glGetError( void ); +GLAPI const GLubyte * APIENTRY glGetString( GLenum name ); +GLAPI void APIENTRY glLoadIdentity( void ); +GLAPI void APIENTRY glMatrixMode( GLenum mode ); +GLAPI void APIENTRY glOrthof( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar ); +GLAPI void APIENTRY glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ); +GLAPI void APIENTRY glPixelStorei( GLenum pname, GLint param ); +GLAPI void APIENTRY glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ); +GLAPI void APIENTRY glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels ); +GLAPI void APIENTRY glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ); +GLAPI void APIENTRY glViewport( GLint x, GLint y, GLsizei width, GLsizei height ); #ifdef __cplusplus } diff --git a/console/rgl/ps3/glext.h b/console/rgl/ps3/glext.h index e2d87c6418..5561075f09 100644 --- a/console/rgl/ps3/glext.h +++ b/console/rgl/ps3/glext.h @@ -12,9 +12,9 @@ extern "C" { #endif - typedef intptr_t GLintptr; - typedef intptr_t GLsizeiptr; - typedef unsigned short GLhalfARB; +typedef intptr_t GLintptr; +typedef intptr_t GLsizeiptr; +typedef unsigned short GLhalfARB; #define GL_QUADS 0x0007 #define GL_QUAD_STRIP 0x0008 @@ -248,24 +248,24 @@ extern "C" #define GL_BUFFER_SIZE 0x8764 #define GL_BUFFER_PITCH_SCE 0x6041 - GLAPI void APIENTRY glBlendEquation( GLenum mode ); - GLAPI void APIENTRY glBlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ); - GLAPI void APIENTRY glGetFloatv( GLenum pname, GLfloat* params ); - GLAPI void APIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param ); +GLAPI void APIENTRY glBlendEquation( GLenum mode ); +GLAPI void APIENTRY glBlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ); +GLAPI void APIENTRY glGetFloatv( GLenum pname, GLfloat* params ); +GLAPI void APIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param ); - GLAPI void APIENTRY glBindBuffer( GLenum target, GLuint name ); - GLAPI void APIENTRY glDeleteBuffers( GLsizei n, const GLuint *buffers ); - GLAPI void APIENTRY glGenBuffers( GLsizei n, GLuint *buffers ); - GLAPI void APIENTRY glBufferData( GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage ); - GLAPI void APIENTRY glBufferSubData( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data ); +GLAPI void APIENTRY glBindBuffer( GLenum target, GLuint name ); +GLAPI void APIENTRY glDeleteBuffers( GLsizei n, const GLuint *buffers ); +GLAPI void APIENTRY glGenBuffers( GLsizei n, GLuint *buffers ); +GLAPI void APIENTRY glBufferData( GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage ); +GLAPI void APIENTRY glBufferSubData( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data ); - GLAPI void APIENTRY glBindFramebufferOES( GLenum, GLuint ); - GLAPI void APIENTRY glDeleteFramebuffersOES( GLsizei, const GLuint * ); - GLAPI void APIENTRY glGenFramebuffersOES( GLsizei, GLuint * ); - GLAPI GLenum APIENTRY glCheckFramebufferStatusOES( GLenum ); - GLAPI void APIENTRY glFramebufferTexture2DOES( GLenum, GLenum, GLenum, GLuint, GLint ); +GLAPI void APIENTRY glBindFramebufferOES( GLenum, GLuint ); +GLAPI void APIENTRY glDeleteFramebuffersOES( GLsizei, const GLuint * ); +GLAPI void APIENTRY glGenFramebuffersOES( GLsizei, GLuint * ); +GLAPI GLenum APIENTRY glCheckFramebufferStatusOES( GLenum ); +GLAPI void APIENTRY glFramebufferTexture2DOES( GLenum, GLenum, GLenum, GLuint, GLint ); - GLAPI void APIENTRY glTextureReferenceSCE( GLenum target, GLuint levels, GLuint baseWidth, GLuint baseHeight, GLuint baseDepth, GLenum internalFormat, GLuint pitch, GLintptr offset ); +GLAPI void APIENTRY glTextureReferenceSCE( GLenum target, GLuint levels, GLuint baseWidth, GLuint baseHeight, GLuint baseDepth, GLenum internalFormat, GLuint pitch, GLintptr offset ); #ifdef __cplusplus } diff --git a/console/rgl/ps3/private.h b/console/rgl/ps3/private.h index e368a9ec14..7faf1d6acf 100644 --- a/console/rgl/ps3/private.h +++ b/console/rgl/ps3/private.h @@ -12,7 +12,6 @@ extern "C" { #endif - #ifdef __cplusplus #define _RGL_EXTERN_C extern "C" #else @@ -52,8 +51,8 @@ extern PSGLdevice *_CurrentDevice; typedef union { - unsigned int i; - float f; + unsigned int i; + float f; } jsIntAndFloat; static const jsIntAndFloat _RGLNan = {i: 0x7fc00000U}; @@ -63,39 +62,36 @@ static const jsIntAndFloat _RGLInfinity = {i: 0x7f800000U}; typedef struct RGLRenderTargetEx RGLRenderTargetEx; struct RGLRenderTargetEx { - RGLEnum colorFormat; - GLuint colorBufferCount; - GLuint colorId[RGL_SETRENDERTARGET_MAXCOUNT]; - GLuint colorIdOffset[RGL_SETRENDERTARGET_MAXCOUNT]; - GLuint colorPitch[RGL_SETRENDERTARGET_MAXCOUNT]; - GLboolean yInverted; - GLuint xOffset; - GLuint yOffset; - GLuint width; - GLuint height; + RGLEnum colorFormat; + GLuint colorBufferCount; + GLuint colorId[RGL_SETRENDERTARGET_MAXCOUNT]; + GLuint colorIdOffset[RGL_SETRENDERTARGET_MAXCOUNT]; + GLuint colorPitch[RGL_SETRENDERTARGET_MAXCOUNT]; + GLboolean yInverted; + GLuint xOffset; + GLuint yOffset; + GLuint width; + GLuint height; }; struct jsPlatformFramebuffer: public jsFramebuffer { - RGLRenderTargetEx rt; - GLuint colorBufferMask; - GLboolean complete; - jsPlatformFramebuffer(): jsFramebuffer() - { - memset( &rt, 0, sizeof( rt ) ); - }; - virtual ~jsPlatformFramebuffer() {}; + RGLRenderTargetEx rt; + GLuint colorBufferMask; + GLboolean complete; + jsPlatformFramebuffer(): jsFramebuffer() { memset( &rt, 0, sizeof( rt ) ); }; + virtual ~jsPlatformFramebuffer() {}; }; typedef struct _RGLDriver_ { - RGLRenderTargetEx rt; - GLuint colorBufferMask; - GLboolean rtValid; - GLboolean invalidateVertexCache; - GLuint flushBufferCount; - GLuint fpLoadProgramId; - GLuint fpLoadProgramOffset; + RGLRenderTargetEx rt; + GLuint colorBufferMask; + GLboolean rtValid; + GLboolean invalidateVertexCache; + GLuint flushBufferCount; + GLuint fpLoadProgramId; + GLuint fpLoadProgramOffset; } RGLDriver; @@ -142,99 +138,99 @@ typedef struct typedef struct { - GLenum pool; - RGLTextureMethodParams gcmMethods; - CellGcmTexture gcmTexture; - GLuint gpuAddressId; - GLuint gpuAddressIdOffset; - GLuint gpuSize; - RGLTextureLayout gpuLayout; - jsBufferObject* pbo; + GLenum pool; + RGLTextureMethodParams gcmMethods; + CellGcmTexture gcmTexture; + GLuint gpuAddressId; + GLuint gpuAddressIdOffset; + GLuint gpuSize; + RGLTextureLayout gpuLayout; + jsBufferObject* pbo; } RGLTexture; typedef struct _tagMODESTRUC { - GLushort wHorizVisible; - GLushort wVertVisible; - GLushort wInterlacedMode; - GLushort wRefresh; - GLushort wHorizTotal; - GLushort wHorizBlankStart; - GLushort wHorizSyncStart; - GLushort wHorizSyncEnd; - GLushort wHorizBlankEnd; - GLushort wVertTotal; - GLushort wVertBlankStart; - GLushort wVertSyncStart; - GLushort wVertSyncEnd; - GLushort wVertBlankEnd; - GLuint dwDotClock; - GLushort wHSyncPolarity; - GLushort wVSyncPolarity; + GLushort wHorizVisible; + GLushort wVertVisible; + GLushort wInterlacedMode; + GLushort wRefresh; + GLushort wHorizTotal; + GLushort wHorizBlankStart; + GLushort wHorizSyncStart; + GLushort wHorizSyncEnd; + GLushort wHorizBlankEnd; + GLushort wVertTotal; + GLushort wVertBlankStart; + GLushort wVertSyncStart; + GLushort wVertSyncEnd; + GLushort wVertBlankEnd; + GLuint dwDotClock; + GLushort wHSyncPolarity; + GLushort wVSyncPolarity; } MODESTRUC; enum { - _RGL_SURFACE_SOURCE_TEMPORARY, - _RGL_SURFACE_SOURCE_DEVICE, - _RGL_SURFACE_SOURCE_TEXTURE, - _RGL_SURFACE_SOURCE_PBO, + _RGL_SURFACE_SOURCE_TEMPORARY, + _RGL_SURFACE_SOURCE_DEVICE, + _RGL_SURFACE_SOURCE_TEXTURE, + _RGL_SURFACE_SOURCE_PBO, }; enum { - _RGL_SURFACE_POOL_NONE, - _RGL_SURFACE_POOL_LINEAR, - _RGL_SURFACE_POOL_SYSTEM, + _RGL_SURFACE_POOL_NONE, + _RGL_SURFACE_POOL_LINEAR, + _RGL_SURFACE_POOL_SYSTEM, }; typedef struct { - GLenum source; - GLuint width, height; - GLuint bpp; - GLuint pitch; - RGLEnum format; - GLenum pool; - char* ppuData; - GLuint dataId; - GLuint dataIdOffset; + GLenum source; + GLuint width, height; + GLuint bpp; + GLuint pitch; + RGLEnum format; + GLenum pool; + char* ppuData; + GLuint dataId; + GLuint dataIdOffset; } RGLSurface; typedef struct { - RGLRenderTargetEx rt; - RGLSurface color[3]; - GLuint drawBuffer; - GLuint scanBuffer; - GLuint RescColorBuffersId; - GLuint RescVertexArrayId; - GLuint RescFragmentShaderId; + RGLRenderTargetEx rt; + RGLSurface color[3]; + GLuint drawBuffer; + GLuint scanBuffer; + GLuint RescColorBuffersId; + GLuint RescVertexArrayId; + GLuint RescFragmentShaderId; - const MODESTRUC *ms; - GLboolean vsync; - GLenum deviceType; - GLenum TVStandard; - GLenum TVFormat; - GLuint swapFifoRef; - GLuint swapFifoRef2; - GLboolean setOffset; - GLboolean signal; - GLuint semaValue; - unsigned int syncMethod; + const MODESTRUC *ms; + GLboolean vsync; + GLenum deviceType; + GLenum TVStandard; + GLenum TVFormat; + GLuint swapFifoRef; + GLuint swapFifoRef2; + GLboolean setOffset; + GLboolean signal; + GLuint semaValue; + unsigned int syncMethod; } RGLDevice; int32_t _RGLOutOfSpaceCallback( struct CellGcmContextData *con, uint32_t space ); typedef struct _RGLShader_ { - GLuint loadAddressId; - CgBinaryProgram __attribute__(( aligned( 16 ) ) ) program; + GLuint loadAddressId; + CgBinaryProgram __attribute__(( aligned( 16 ) ) ) program; } RGLShader; -void _RGLFifoFinish( RGLFifo *fifo ); +void _RGLFifoFinish( RGLFifo *fifo ); #define _RGLFifoFlush(fifo) \ { \ @@ -249,17 +245,16 @@ void _RGLFifoFinish( RGLFifo *fifo ); #define RGL_PAGE_SIZE 0x1000 #define RGL_LM_MAX_TOTAL_QUERIES 800 - - typedef struct RGLTextureState RGLTextureState; + struct RGLTextureState { - GLuint hwTexAddress; - GLuint hwTexFilter; - GLuint hwTexControl0; + GLuint hwTexAddress; + GLuint hwTexFilter; + GLuint hwTexControl0; }; -void _RGLDestroy( void ); +void _RGLDestroy( void ); typedef void( * RGLcontextHookFunction )( PSGLcontext *context ); extern RGLcontextHookFunction _RGLContextCreateHook; @@ -283,22 +278,23 @@ extern void _RGLDeviceExit (void); static inline GLuint RGL_QUICK_FLOAT2UINT( const GLfloat f ) { - union - { - GLfloat f; - GLuint ui; - } t; - t.f = f + RGL_F0_DOT_0; - return t.ui & 0xffff; + union + { + GLfloat f; + GLuint ui; + } t; + t.f = f + RGL_F0_DOT_0; + return t.ui & 0xffff; } -static inline void RGL_CALC_COLOR_LE_ARGB8( GLuint *color0, const GLfloat r, const GLfloat g, const GLfloat b, const GLfloat a ) +static inline void RGL_CALC_COLOR_LE_ARGB8( GLuint *color0, const GLfloat r, +const GLfloat g, const GLfloat b, const GLfloat a ) { - GLuint r2 = RGL_QUICK_FLOAT2UINT( r * 255.0f ); - GLuint g2 = RGL_QUICK_FLOAT2UINT( g * 255.0f ); - GLuint b2 = RGL_QUICK_FLOAT2UINT( b * 255.0f ); - GLuint a2 = RGL_QUICK_FLOAT2UINT( a * 255.0f ); - *color0 = ( a2 << 24 ) | ( r2 << 16 ) | ( g2 << 8 ) | ( b2 << 0 ); + GLuint r2 = RGL_QUICK_FLOAT2UINT( r * 255.0f ); + GLuint g2 = RGL_QUICK_FLOAT2UINT( g * 255.0f ); + GLuint b2 = RGL_QUICK_FLOAT2UINT( b * 255.0f ); + GLuint a2 = RGL_QUICK_FLOAT2UINT( a * 255.0f ); + *color0 = ( a2 << 24 ) | ( r2 << 16 ) | ( g2 << 8 ) | ( b2 << 0 ); } static inline GLuint _RGLMapMinTextureFilter( GLenum filter ) @@ -307,42 +303,30 @@ static inline GLuint _RGLMapMinTextureFilter( GLenum filter ) { case GL_NEAREST: return CELL_GCM_TEXTURE_NEAREST; - break; case GL_LINEAR: return CELL_GCM_TEXTURE_LINEAR; - break; case GL_NEAREST_MIPMAP_NEAREST: return CELL_GCM_TEXTURE_NEAREST_NEAREST; - break; case GL_NEAREST_MIPMAP_LINEAR: return CELL_GCM_TEXTURE_NEAREST_LINEAR; - break; case GL_LINEAR_MIPMAP_NEAREST: return CELL_GCM_TEXTURE_LINEAR_NEAREST; - break; case GL_LINEAR_MIPMAP_LINEAR: return CELL_GCM_TEXTURE_LINEAR_LINEAR; - break; - default: - return 0; } return filter; } static inline GLuint _RGLMapMagTextureFilter( GLenum filter ) { - switch ( filter ) - { - case GL_NEAREST: - return CELL_GCM_TEXTURE_NEAREST; - break; - case GL_LINEAR: - return CELL_GCM_TEXTURE_LINEAR; - break; - default: - return 0; - } - return filter; + switch ( filter ) + { + case GL_NEAREST: + return CELL_GCM_TEXTURE_NEAREST; + case GL_LINEAR: + return CELL_GCM_TEXTURE_LINEAR; + } + return filter; } static inline void _RGLMapTextureFormat( GLuint internalFormat, uint8_t & gcmFormat, uint32_t & remap ) @@ -351,71 +335,58 @@ static inline void _RGLMapTextureFormat( GLuint internalFormat, uint8_t & gcmFor switch ( internalFormat ) { - case RGL_ALPHA8: // in_rgba = xxAx, out_rgba = 000A - { - gcmFormat = CELL_GCM_TEXTURE_B8; - remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_ZERO, - CELL_GCM_TEXTURE_REMAP_ZERO, - CELL_GCM_TEXTURE_REMAP_ZERO ); + case RGL_ALPHA8: // in_rgba = xxAx, out_rgba = 000A + gcmFormat = CELL_GCM_TEXTURE_B8; + remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_ZERO, + CELL_GCM_TEXTURE_REMAP_ZERO, + CELL_GCM_TEXTURE_REMAP_ZERO ); - } break; - case RGL_ARGB8: // in_rgba = RGBA, out_rgba = RGBA - { - gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8; - remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, - CELL_GCM_TEXTURE_REMAP_FROM_A, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP ); - - } + case RGL_ARGB8: // in_rgba = RGBA, out_rgba = RGBA + gcmFormat = CELL_GCM_TEXTURE_A8R8G8B8; + remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XYXY, + CELL_GCM_TEXTURE_REMAP_FROM_A, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP ); break; - case RGL_RGB5_A1_SCE: // in_rgba = RGBA, out_rgba = RGBA - { - gcmFormat = CELL_GCM_TEXTURE_A1R5G5B5; - remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XXXY, - CELL_GCM_TEXTURE_REMAP_FROM_A, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP ); - - } + case RGL_RGB5_A1_SCE: // in_rgba = RGBA, out_rgba = RGBA + gcmFormat = CELL_GCM_TEXTURE_A1R5G5B5; + remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XXXY, + CELL_GCM_TEXTURE_REMAP_FROM_A, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP ); break; - case RGL_RGB565_SCE: // in_rgba = RGBA, out_rgba = RGBA - { - gcmFormat = CELL_GCM_TEXTURE_R5G6B5; - remap = CELL_GCM_REMAP_MODE( - CELL_GCM_TEXTURE_REMAP_ORDER_XXXY, - CELL_GCM_TEXTURE_REMAP_FROM_A, - CELL_GCM_TEXTURE_REMAP_FROM_R, - CELL_GCM_TEXTURE_REMAP_FROM_G, - CELL_GCM_TEXTURE_REMAP_FROM_B, - CELL_GCM_TEXTURE_REMAP_ONE, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP, - CELL_GCM_TEXTURE_REMAP_REMAP ); - - } - break; - default: + case RGL_RGB565_SCE: // in_rgba = RGBA, out_rgba = RGBA + gcmFormat = CELL_GCM_TEXTURE_R5G6B5; + remap = CELL_GCM_REMAP_MODE( + CELL_GCM_TEXTURE_REMAP_ORDER_XXXY, + CELL_GCM_TEXTURE_REMAP_FROM_A, + CELL_GCM_TEXTURE_REMAP_FROM_R, + CELL_GCM_TEXTURE_REMAP_FROM_G, + CELL_GCM_TEXTURE_REMAP_FROM_B, + CELL_GCM_TEXTURE_REMAP_ONE, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP, + CELL_GCM_TEXTURE_REMAP_REMAP ); break; }; diff --git a/console/rgl/ps3/readelf.h b/console/rgl/ps3/readelf.h index c33dd3373b..21c65c72d8 100644 --- a/console/rgl/ps3/readelf.h +++ b/console/rgl/ps3/readelf.h @@ -9,61 +9,61 @@ extern "C" { typedef struct _ELF_section_t { - Elf32_Shdr header; - const char* name; - char* data; + Elf32_Shdr header; + const char *name; + char *data; } ELF_section_t; typedef struct _ELF_segment_t { - Elf32_Phdr header; - unsigned char* pointer; - unsigned char* data; + Elf32_Phdr header; + unsigned char *pointer; + unsigned char *data; } ELF_segment_t; typedef struct { - const char* name; - unsigned int vma; - unsigned int size; - int section; - unsigned char resolved; - unsigned char foreign; + const char *name; + unsigned int vma; + unsigned int size; + int section; + unsigned char resolved; + unsigned char foreign; } ELF_symbol_t; typedef struct _ELF_t { - unsigned int endian; - unsigned int relocatable; - unsigned int sectionCount; - unsigned int segmentCount; - unsigned int symbolCount; - unsigned int entrypoint; - ELF_section_t* sections; - ELF_segment_t* segments; - ELF_symbol_t* symbols; - unsigned int symbolsSection; - unsigned int symbolNamesSection; - unsigned int paramSection; + unsigned int endian; + unsigned int relocatable; + unsigned int sectionCount; + unsigned int segmentCount; + unsigned int symbolCount; + unsigned int entrypoint; + ELF_section_t *sections; + ELF_segment_t *segments; + ELF_symbol_t *symbols; + unsigned int symbolsSection; + unsigned int symbolNamesSection; + unsigned int paramSection; } ELF_t; typedef struct { - unsigned int relative; - unsigned int shift; - unsigned int size; - unsigned int position; - unsigned int mask; + unsigned int relative; + unsigned int shift; + unsigned int size; + unsigned int position; + unsigned int mask; } ELF_rel_type_t; -ELF_section_t* findSection(const ELF_t* elf,const char* name); -int lookupSymbol(const ELF_t* elf,const char* name); -const Elf32_Sym* getSymbolByIndex(const ELF_t* elf,int idx); +ELF_section_t *findSection(const ELF_t *elf, const char *name); +int lookupSymbol(const ELF_t *elf, const char *name); +const Elf32_Sym *getSymbolByIndex(const ELF_t *elf, int idx); const char *findSectionInPlace(const char* memory,unsigned int size,const char *name,size_t *sectionSize); const char *findSymbolSectionInPlace(const char *memory, unsigned int size, size_t *symbolSize, size_t *symbolCount, const char **symbolstrtab); -int lookupSymbolValueInPlace(const char* symbolSection, size_t symbolSize, size_t symbolCount, const char *symbolstrtab, const char *name); -const char *getSymbolByIndexInPlace(const char* symbolSection, size_t symbolSize, size_t symbolCount, const char *symbolstrtab, int index); +int lookupSymbolValueInPlace(const char *symbolSection, size_t symbolSize, size_t symbolCount, const char *symbolstrtab, const char *name); +const char *getSymbolByIndexInPlace(const char *symbolSection, size_t symbolSize, size_t symbolCount, const char *symbolstrtab, int index); #ifdef __cplusplus } diff --git a/console/rgl/ps3/rgl.cpp b/console/rgl/ps3/rgl.cpp index 9967431270..6c3ce76112 100644 --- a/console/rgl/ps3/rgl.cpp +++ b/console/rgl/ps3/rgl.cpp @@ -21,6 +21,7 @@ #include #include "../../../compat/strl.h" +#include "../../../general.h" #define RGL_ALIGN_FAST_TRANSFER 128 @@ -132,9 +133,9 @@ typedef GLhalfARB type_GL_HALF_FLOAT_ARB; static const char *_getStringTable(const Elf32_Ehdr *ehdr) { - const char *sectionHeaderStart = (const char*)ehdr + ehdr->e_shoff; - const Elf32_Shdr *shstrtabHeader = (const Elf32_Shdr*)sectionHeaderStart + ehdr->e_shstrndx; - return (const char*)ehdr + shstrtabHeader->sh_offset; + const char *sectionHeaderStart = (const char*)ehdr + ehdr->e_shoff; + const Elf32_Shdr *shstrtabHeader = (const Elf32_Shdr*)sectionHeaderStart + ehdr->e_shstrndx; + return (const char*)ehdr + shstrtabHeader->sh_offset; } const char *findSectionInPlace(const char* memory,unsigned int /*size*/,const char *name, size_t *sectionSize) @@ -204,14 +205,14 @@ const char *getSymbolByIndexInPlace(const char* symbolSection, size_t symbolSize static inline type_GL_HALF_FLOAT_ARB _RGLFloatTo_GL_HALF_FLOAT_ARB( float x ) { - jsIntAndFloat V = {f: x}; - unsigned int S = ( V.i >> 31 ) & 1; - int E = (( V.i >> 23 ) & 0xff ) - 0x7f; - unsigned int M = V.i & 0x007fffff; - if (( E == 0x80 ) && ( M ) ) return 0x7fff; - else if ( E >= 15 ) return( S << 15 ) | 0x7c00; - else if ( E <= -14 ) return( S << 15 ) | (( 0x800000 + M ) >> ( -14 - E ) ); - else return( S << 15 ) | ((( E + 15 )&0x1f ) << 10 ) | ( M >> 13 ); + jsIntAndFloat V = {f: x}; + unsigned int S = ( V.i >> 31 ) & 1; + int E = (( V.i >> 23 ) & 0xff ) - 0x7f; + unsigned int M = V.i & 0x007fffff; + if (( E == 0x80 ) && ( M ) ) return 0x7fff; + else if ( E >= 15 ) return( S << 15 ) | 0x7c00; + else if ( E <= -14 ) return( S << 15 ) | (( 0x800000 + M ) >> ( -14 - E ) ); + else return( S << 15 ) | ((( E + 15 )&0x1f ) << 10 ) | ( M >> 13 ); } static inline float _RGLFloatFrom_GL_HALF_FLOAT_ARB( type_GL_HALF_FLOAT_ARB x ) @@ -933,7 +934,7 @@ static GLenum _RGLPlatformFramebufferCheckStatus( jsFramebuffer* framebuffer ) { if ( !_RGLTextureIsValid( colorTexture ) ) { - printf("RGL ERR: Framebuffer color attachment texture is not complete.\n"); + RARCH_ERR("Framebuffer color attachment texture is not complete.\n"); return GL_FRAMEBUFFER_UNSUPPORTED_OES; } @@ -941,7 +942,7 @@ static GLenum _RGLPlatformFramebufferCheckStatus( jsFramebuffer* framebuffer ) if ( colorFormat && colorFormat != image[nBuffers]->internalFormat ) { - printf("RGL ERR: Framebuffer attachments have inconsistent color formats.\n" ); + RARCH_ERR("Framebuffer attachments have inconsistent color formats.\n" ); return GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES; } colorFormat = image[nBuffers]->internalFormat; @@ -952,7 +953,7 @@ static GLenum _RGLPlatformFramebufferCheckStatus( jsFramebuffer* framebuffer ) if ( nBuffers && colorFormat != RGL_ARGB8) { - printf("RGL: Color attachment to framebuffer must be a supported drawable format (GL_ARGB_SCE)\n"); + RARCH_ERR("Color attachment to framebuffer must be a supported drawable format (GL_ARGB_SCE)\n"); return GL_FRAMEBUFFER_UNSUPPORTED_OES; } @@ -1911,7 +1912,7 @@ void _RGLFreeNameSpace( jsNameSpace * ns ) jsName _RGLCreateName( jsNameSpace * ns, void* object ) { - if ( NULL == ns->firstFree ) + if ( ns->firstFree == NULL ) { int newCapacity = ns->capacity + NAME_INCREMENT; @@ -1945,7 +1946,7 @@ jsName _RGLCreateName( jsNameSpace * ns, void* object ) unsigned int _RGLIsName( jsNameSpace* ns, jsName name ) { - if ( RGL_UNLIKELY( 0 == name ) ) + if ( RGL_UNLIKELY( name == 0 ) ) return 0; --name; @@ -1955,7 +1956,7 @@ unsigned int _RGLIsName( jsNameSpace* ns, jsName name ) void** value = ( void** )ns->data[name]; - if ( RGL_UNLIKELY( NULL == value || + if ( RGL_UNLIKELY( value == NULL || ( value >= ns->data && value < ns->data + ns->capacity ) ) ) return 0; @@ -2059,7 +2060,7 @@ void _RGLTexNameSpaceDeleteNames( jsTexNameSpace *ns, GLsizei n, const GLuint *n static inline unsigned int endianSwapWordByHalf( unsigned int v ) { - return ( v&0xffff ) << 16 | v >> 16; + return ( v&0xffff ) << 16 | v >> 16; } static uint32_t gmmInitFixedAllocator (void) @@ -2131,97 +2132,52 @@ static uint8_t gmmSizeToFreeIndex( ) { if (size >= GMM_FREE_BIN_0 && size < GMM_FREE_BIN_1) - { return 0; - } else if (size >= GMM_FREE_BIN_1 && size < GMM_FREE_BIN_2) - { return 1; - } else if (size >= GMM_FREE_BIN_2 && size < GMM_FREE_BIN_3) - { return 2; - } else if (size >= GMM_FREE_BIN_3 && size < GMM_FREE_BIN_4) - { return 3; - } else if (size >= GMM_FREE_BIN_4 && size < GMM_FREE_BIN_5) - { return 4; - } else if (size >= GMM_FREE_BIN_5 && size < GMM_FREE_BIN_6) - { return 5; - } else if (size >= GMM_FREE_BIN_6 && size < GMM_FREE_BIN_7) - { return 6; - } else if (size >= GMM_FREE_BIN_7 && size < GMM_FREE_BIN_8) - { return 7; - } else if (size >= GMM_FREE_BIN_8 && size < GMM_FREE_BIN_9) - { return 8; - } else if (size >= GMM_FREE_BIN_9 && size < GMM_FREE_BIN_10) - { return 9; - } else if (size >= GMM_FREE_BIN_10 && size < GMM_FREE_BIN_11) - { return 10; - } else if (size >= GMM_FREE_BIN_11 && size < GMM_FREE_BIN_12) - { return 11; - } else if (size >= GMM_FREE_BIN_12 && size < GMM_FREE_BIN_13) - { return 12; - } else if (size >= GMM_FREE_BIN_13 && size < GMM_FREE_BIN_14) - { return 13; - } else if (size >= GMM_FREE_BIN_14 && size < GMM_FREE_BIN_15) - { return 14; - } else if (size >= GMM_FREE_BIN_15 && size < GMM_FREE_BIN_16) - { return 15; - } else if (size >= GMM_FREE_BIN_16 && size < GMM_FREE_BIN_17) - { return 16; - } else if (size >= GMM_FREE_BIN_17 && size < GMM_FREE_BIN_18) - { return 17; - } else if (size >= GMM_FREE_BIN_18 && size < GMM_FREE_BIN_19) - { return 18; - } else if (size >= GMM_FREE_BIN_19 && size < GMM_FREE_BIN_20) - { return 19; - } else if (size >= GMM_FREE_BIN_20 && size < GMM_FREE_BIN_21) - { return 20; - } else return 21; } -static void gmmAddFree( - GmmAllocator *pAllocator, - GmmBlock *pBlock -) +static void gmmAddFree(GmmAllocator *pAllocator, GmmBlock *pBlock) { uint8_t freeIndex = gmmSizeToFreeIndex(pBlock->base.size); @@ -2431,22 +2387,18 @@ uint32_t gmmInit( return gmmInitFixedAllocator(); } -void gmmSetTileAttrib( - const uint32_t id, - const uint32_t tag, - void *pData -) +void gmmSetTileAttrib(const uint32_t id, const uint32_t tag, void *pData) { - GmmTileBlock *pTileBlock = (GmmTileBlock *)id; + GmmTileBlock *pTileBlock = (GmmTileBlock *)id; - pTileBlock->tileTag = tag; - pTileBlock->pData = pData; + pTileBlock->tileTag = tag; + pTileBlock->pData = pData; } uint32_t gmmIdToOffset(const uint32_t id) { - GmmBaseBlock *pBaseBlock = (GmmBaseBlock *)id; - return gmmAddressToOffset(pBaseBlock->address, pBaseBlock->isMain); + GmmBaseBlock *pBaseBlock = (GmmBaseBlock *)id; + return gmmAddressToOffset(pBaseBlock->address, pBaseBlock->isMain); } char *gmmIdToAddress(const uint32_t id) @@ -2462,8 +2414,6 @@ char *gmmIdToAddress(const uint32_t id) if (cachedLockValue == 0) break; - - sys_timer_usleep(30); }while(1); return (char *)pBaseBlock->address; @@ -2576,9 +2526,7 @@ static GmmTileBlock *gmmCreateTileBlock( if (pAllocator->pTail && pAllocator->pTail->base.address + pAllocator->pTail->base.size > address) - { return NULL; - } pAllocator->size = address - pAllocator->startAddress; pAllocator->tileSize = pAllocator->tileStartAddress + pAllocator->tileSize - address; @@ -2586,9 +2534,7 @@ static GmmTileBlock *gmmCreateTileBlock( pNewBlock = (GmmTileBlock *)gmmAllocFixed(1); if (pNewBlock == NULL) - { return NULL; - } memset(pNewBlock, 0, sizeof(GmmTileBlock)); @@ -2599,15 +2545,11 @@ static GmmTileBlock *gmmCreateTileBlock( pNewBlock->pNext = pAllocator->pTileHead; if (pAllocator->pTileHead) - { pAllocator->pTileHead->pPrev = pNewBlock; - pAllocator->pTileHead = pNewBlock; - } else - { - pAllocator->pTileHead = pNewBlock; pAllocator->pTileTail = pNewBlock; - } + + pAllocator->pTileHead = pNewBlock; return pNewBlock; } @@ -2763,9 +2705,7 @@ static GmmTileBlock *gmmAllocTileBlock( return pBlock; } -static void gmmFreeBlock( - GmmBlock *pBlock -) +static void gmmFreeBlock (GmmBlock *pBlock) { GmmAllocator *pAllocator; @@ -2851,7 +2791,6 @@ uint32_t gmmFree(const uint32_t freeId) { GmmBaseBlock *pBaseBlock = (GmmBaseBlock *)freeId; - if (pBaseBlock->isTile) { GmmTileBlock *pTileBlock = (GmmTileBlock *)pBaseBlock; @@ -2965,18 +2904,16 @@ static inline void gmmLocalMemcpy( static inline void gmmMemcpy(const uint32_t dstOffset, const uint32_t srcOffset, const uint32_t moveSize) { - if (dstOffset + moveSize <= srcOffset) - { - gmmLocalMemcpy(dstOffset, srcOffset, moveSize); - } - else - { - uint32_t moveBlockSize = srcOffset-dstOffset; - uint32_t iterations = (moveSize+moveBlockSize-1)/moveBlockSize; + if (dstOffset + moveSize <= srcOffset) + gmmLocalMemcpy(dstOffset, srcOffset, moveSize); + else + { + uint32_t moveBlockSize = srcOffset-dstOffset; + uint32_t iterations = (moveSize+moveBlockSize-1)/moveBlockSize; - for (uint32_t i=0; ipNextFree; } else if (++freeIndex < GMM_NUM_FREE_BINS) - { pBlock = pAllocator->pFreeHead[freeIndex]; - } } if (found) @@ -3247,10 +3182,10 @@ static uint32_t gmmFindFreeBlock( pNewBlock->base.size = pBlock->base.size - size; pNewBlock->pNext = pBlock->pNext; pNewBlock->pPrev = pBlock; + if (pBlock->pNext) - { pBlock->pNext->pPrev = pNewBlock; - } + pBlock->pNext = pNewBlock; if (pBlock == pAllocator->pTail) @@ -3375,22 +3310,10 @@ RGLparamUID getParamUIDByIndex( const RGLparamUIDTable* st, int index ) return st->uids[index]; } -void _RGLPlatformSetVertexRegister4fv( unsigned int reg, const float * __restrict v ) -{ -} - -void _RGLPlatformSetVertexRegisterBlock( unsigned int reg, unsigned int count, const float * __restrict v ) -{ -} - - -void _RGLPlatformSetFragmentRegister4fv( unsigned int reg, const float * __restrict v ) -{ -} - -void _RGLPlatformSetFragmentRegisterBlock( unsigned int reg, unsigned int count, const float * __restrict v ) -{ -} +void _RGLPlatformSetVertexRegister4fv( unsigned int reg, const float * __restrict v ) {} +void _RGLPlatformSetVertexRegisterBlock( unsigned int reg, unsigned int count, const float * __restrict v ) {} +void _RGLPlatformSetFragmentRegister4fv( unsigned int reg, const float * __restrict v ) {} +void _RGLPlatformSetFragmentRegisterBlock( unsigned int reg, unsigned int count, const float * __restrict v ) {} template inline static void swapandsetfp( int ucodeSize, unsigned int loadProgramId, unsigned int loadProgramOffset, unsigned short *ec, const unsigned int * __restrict v ) { @@ -3430,13 +3353,10 @@ template static void setVectorTypefp( CgRuntimeParameter* __restrict p } } -template static void setVectorTypeSharedfpIndex( CgRuntimeParameter* __restrict ptr, const void* __restrict v, const int ) -{ -} +template static void setVectorTypeSharedfpIndex( CgRuntimeParameter* __restrict ptr, const void* __restrict v, const int ) {} + +template static void setVectorTypeSharedfpIndexArray( CgRuntimeParameter* __restrict ptr, const void* __restrict v, const int index ) {} -template static void setVectorTypeSharedfpIndexArray( CgRuntimeParameter* __restrict ptr, const void* __restrict v, const int index ) -{ -} template static void setVectorTypeSharedvpIndex( CgRuntimeParameter* __restrict ptr, const void* __restrict v, const int ) { const float * __restrict f = ( const float * __restrict )v; @@ -4478,11 +4398,6 @@ int _RGLPlatformCopyProgram( _CGprogram* source, _CGprogram* destination ) return _RGLGenerateProgram( destination, profileIndex, &source->header, source->ucode, ¶meterHeader, source->parametersEntries, source->stringTable, source->defaultValues ); } - - - - - static char *_RGLPlatformBufferObjectMap( jsBufferObject* bufferObject, GLenum access ) { RGLBufferObject *jsBuffer = ( RGLBufferObject * )bufferObject->platformBufferObject; @@ -4711,21 +4626,21 @@ static void _RGLPlatformExpandInternalFormat( GLenum internalFormat, GLenum *for static GLenum _RGLPlatformChooseInternalStorage( jsImage* image, GLenum internalFormat ) { - image->storageSize = 0; + image->storageSize = 0; - GLenum platformInternalFormat = _RGLPlatformChooseInternalFormat( internalFormat ); + GLenum platformInternalFormat = _RGLPlatformChooseInternalFormat( internalFormat ); - if ( platformInternalFormat == GL_INVALID_ENUM ) - return GL_INVALID_ENUM; + if ( platformInternalFormat == GL_INVALID_ENUM ) + return GL_INVALID_ENUM; - image->internalFormat = platformInternalFormat; - _RGLPlatformExpandInternalFormat( platformInternalFormat, &image->format, &image->type ); + image->internalFormat = platformInternalFormat; + _RGLPlatformExpandInternalFormat( platformInternalFormat, &image->format, &image->type ); - image->storageSize = _RGLGetStorageSize( - image->format, image->type, - image->width, image->height, 1 ); + image->storageSize = _RGLGetStorageSize( + image->format, image->type, + image->width, image->height, 1 ); - return GL_NO_ERROR; + return GL_NO_ERROR; } static inline GLuint _RGLGetBufferObjectOrigin( GLuint buffer ) @@ -4813,7 +4728,7 @@ static GLboolean _RGLPlatformTexturePBOImage( LContext->unpackAlignment ); if (( pboPitch&3 ) != 0 ) { - printf("RGL WARN: PBO image pitch not a multiple of 4, using slow path.\n" ); + RARCH_WARN("PBO image pitch not a multiple of 4, using slow path.\n" ); return GL_FALSE; } @@ -4822,7 +4737,7 @@ static GLboolean _RGLPlatformTexturePBOImage( if ( gmmIdToOffset(gpuId)+gpuIdOffset & 63 ) { - printf("RGL: PBO offset not 64-byte aligned, using slow path.\n"); + RARCH_WARN("PBO offset not 64-byte aligned, using slow path.\n"); return GL_FALSE; } @@ -4850,13 +4765,13 @@ static GLboolean _RGLPlatformTexturePBOImage( if ( !formatOK ) { - printf("RGL: PBO format/type requires conversion to texture internal format, using slow path.\n"); + RARCH_WARN("PBO format/type requires conversion to texture internal format, using slow path.\n"); return GL_FALSE; } if ( !_RGLTextureIsValid( texture ) ) { - printf("RGL: PBO transfering to incomplete texture, using slow path.\n"); + RARCH_WARN("PBO transfering to incomplete texture, using slow path.\n"); return GL_FALSE; } @@ -4883,7 +4798,7 @@ static GLboolean _RGLPlatformTexturePBOImage( const GLuint bytesPerPixel = newLayout.pixelBits / 8; RGLSurface src = { -source: _RGL_SURFACE_SOURCE_PBO, + source: _RGL_SURFACE_SOURCE_PBO, width: image->width, height: image->height, bpp: bytesPerPixel, @@ -4900,7 +4815,7 @@ source: _RGL_SURFACE_SOURCE_PBO, RGLSurface dst = { -source: _RGL_SURFACE_SOURCE_TEXTURE, + source: _RGL_SURFACE_SOURCE_TEXTURE, width: image->width, height: image->height, bpp: bytesPerPixel, @@ -5063,9 +4978,7 @@ void _RGLFifoGlSetRenderTarget( RGLRenderTargetEx const * const args ) cellGcmSetDepthTestEnableInline( &_RGLState.fifo, CELL_GCM_FALSE); } -void _RGLSetError( GLenum error ) -{ -} +void _RGLSetError( GLenum error ) {} GLAPI GLenum APIENTRY glGetError() { @@ -5366,17 +5279,17 @@ PSGLcontext *psglGetCurrentContext() const GLfloat _RGLIdentityMatrixf[ELEMENTS_IN_MATRIX] = { - 1.f, 0.f, 0.f, 0.f, - 0.f, 1.f, 0.f, 0.f, - 0.f, 0.f, 1.f, 0.f, - 0.f, 0.f, 0.f, 1.f + 1.f, 0.f, 0.f, 0.f, + 0.f, 1.f, 0.f, 0.f, + 0.f, 0.f, 1.f, 0.f, + 0.f, 0.f, 0.f, 1.f }; static void _RGLMatrixStackReset( jsMatrixStack* LMatrixStack ) { - LMatrixStack->MatrixStackPtr = 0; - memcpy( LMatrixStack->MatrixStackf, _RGLIdentityMatrixf, jsMATRIX_SIZEf ); - LMatrixStack->dirty = GL_TRUE; + LMatrixStack->MatrixStackPtr = 0; + memcpy( LMatrixStack->MatrixStackf, _RGLIdentityMatrixf, jsMATRIX_SIZEf ); + LMatrixStack->dirty = GL_TRUE; } static void _RGLResetContext( PSGLcontext *LContext ) @@ -5600,7 +5513,8 @@ PSGLcontext* psglCreateContext (void) _RGLResetContext( LContext ); - if ( _RGLContextCreateHook ) _RGLContextCreateHook( LContext ); + if ( _RGLContextCreateHook ) + _RGLContextCreateHook( LContext ); return( LContext ); } @@ -5959,19 +5873,19 @@ void psglExit (void) GLAPI void APIENTRY glLoadIdentity() { - PSGLcontext* LContext = _CurrentContext; - jsMatrixStack* LMatrixStack = NULL; + PSGLcontext* LContext = _CurrentContext; + jsMatrixStack* LMatrixStack = NULL; - jsContextGetMatrixStack(LContext, LContext->MatrixMode, LMatrixStack); - memcpy( LMatrixStack->MatrixStackf + LMatrixStack->MatrixStackPtr*ELEMENTS_IN_MATRIX, _RGLIdentityMatrixf, jsMATRIX_SIZEf ); + jsContextGetMatrixStack(LContext, LContext->MatrixMode, LMatrixStack); + memcpy( LMatrixStack->MatrixStackf + LMatrixStack->MatrixStackPtr*ELEMENTS_IN_MATRIX, _RGLIdentityMatrixf, jsMATRIX_SIZEf ); - LMatrixStack->dirty = GL_TRUE; + LMatrixStack->dirty = GL_TRUE; } GLAPI void APIENTRY glMatrixMode( GLenum mode ) { - PSGLcontext* LContext = _CurrentContext; - LContext->MatrixMode = mode; + PSGLcontext* LContext = _CurrentContext; + LContext->MatrixMode = mode; } GLAPI void APIENTRY glOrthof( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar ) @@ -6083,7 +5997,7 @@ static GLboolean _RGLPlatformNeedsConversion( const jsAttributeState* as, GLuint default: break; } - printf("RGL WARN: Attribute %d needs conversion. Slow path ahead.\n", index); + RARCH_WARN("Attribute %d needs conversion. Slow path ahead.\n", index); return GL_TRUE; } @@ -6288,11 +6202,13 @@ GLAPI void APIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count ) if ( RGL_UNLIKELY( ! RGLBIT_GET( LContext->attribs->EnabledMask, _RGL_ATTRIB_POSITION_INDEX ) ) ) return; - uint32_t _tmp_clear_loop = c_rounded_size_of_RGLDrawParams>>7; + uint32_t _tmp_clear_loop = c_rounded_size_of_RGLDrawParams >> 7; + do{ - --_tmp_clear_loop; - __dcbz(s_dparams_buff+(_tmp_clear_loop<<7)); + --_tmp_clear_loop; + __dcbz(s_dparams_buff+(_tmp_clear_loop << 7)); }while(_tmp_clear_loop); + jsDrawParams *dparams = (jsDrawParams *)s_dparams_buff; dparams->mode = mode; dparams->firstVertex = first; @@ -6306,6 +6222,9 @@ GLAPI void APIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count ) { for ( int i = 0; i < _RGL_MAX_VERTEX_ATTRIBS; ++i ) { + dparams->attribXferOffset[i] = 0; + dparams->attribXferSize[i] = 0; + if ( clientSideMask & ( 1 << i ) ) { jsAttribute* attrib = as->attrib + i; @@ -6323,11 +6242,6 @@ GLAPI void APIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count ) dparams->xferTotalSize += numBytesPadded; dparams->attribXferTotalSize += numBytesPadded; } - else - { - dparams->attribXferOffset[i] = 0; - dparams->attribXferSize[i] = 0; - } } } @@ -6337,12 +6251,11 @@ GLAPI void APIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count ) GLboolean isMain = 0; if ( LContext->attribSetDirty && LContext->attribSetName ) - { - jsAttribSet* attribSet = _RGLGetAttribSet( LContext->attribSetName ); - } + jsAttribSet* attribSet = _RGLGetAttribSet( LContext->attribSetName ); + uint32_t totalXfer = 0; for ( GLuint i = 0; i < _RGL_MAX_VERTEX_ATTRIBS; ++i ) - totalXfer += dparams->attribXferSize[i]; + totalXfer += dparams->attribXferSize[i]; GLuint gpuOffset = _RGLValidateAttributesSlow( dparams, &isMain ); (void)gpuOffset; @@ -6610,43 +6523,43 @@ GLAPI void APIENTRY glPixelStorei( GLenum pname, GLint param ) GLAPI void APIENTRY glTextureReferenceSCE( GLenum target, GLuint levels, GLuint baseWidth, GLuint baseHeight, GLuint baseDepth, GLenum internalFormat, GLuint pitch, GLintptr offset ) { - PSGLcontext* LContext = _CurrentContext; + PSGLcontext* LContext = _CurrentContext; - jsTexture *texture = _RGLGetCurrentTexture( LContext->CurrentImageUnit, GL_TEXTURE_2D); - jsBufferObject *bufferObject = _RGLGetBufferObject( LContext, LContext->TextureBuffer ); - _RGLReallocateImages( texture, MAX( baseWidth, MAX( baseHeight, baseDepth ) ) ); + jsTexture *texture = _RGLGetCurrentTexture( LContext->CurrentImageUnit, GL_TEXTURE_2D); + jsBufferObject *bufferObject = _RGLGetBufferObject( LContext, LContext->TextureBuffer ); + _RGLReallocateImages( texture, MAX( baseWidth, MAX( baseHeight, baseDepth ) ) ); - GLuint width = baseWidth; - GLuint height = baseHeight; - _RGLSetImage(texture->image, GL_RGB5_A1, width, height, 0, LContext->unpackAlignment, - 0, 0, NULL ); - width = MAX( 1U, width / 2 ); - height = MAX( 1U, height / 2 ); - texture->usage = GL_TEXTURE_LINEAR_GPU_SCE; + GLuint width = baseWidth; + GLuint height = baseHeight; + _RGLSetImage(texture->image, GL_RGB5_A1, width, height, 0, LContext->unpackAlignment, + 0, 0, NULL ); + width = MAX( 1U, width / 2 ); + height = MAX( 1U, height / 2 ); + texture->usage = GL_TEXTURE_LINEAR_GPU_SCE; - GLboolean r = _RGLPlatformTextureReference( texture, pitch, bufferObject, offset ); + GLboolean r = _RGLPlatformTextureReference( texture, pitch, bufferObject, offset ); - if(!r) - return; + if(!r) + return; - bufferObject->textureReferences.pushBack( texture ); - texture->referenceBuffer = bufferObject; - texture->offset = offset; - _RGLTextureTouchFBOs( texture ); - LContext->needValidate |= PSGL_VALIDATE_TEXTURES_USED | PSGL_VALIDATE_VERTEX_TEXTURES_USED ; + bufferObject->textureReferences.pushBack( texture ); + texture->referenceBuffer = bufferObject; + texture->offset = offset; + _RGLTextureTouchFBOs( texture ); + LContext->needValidate |= PSGL_VALIDATE_TEXTURES_USED | PSGL_VALIDATE_VERTEX_TEXTURES_USED ; } GLAPI void APIENTRY glViewport( GLint x, GLint y, GLsizei width, GLsizei height ) { + PSGLcontext* LContext = _CurrentContext; - PSGLcontext* LContext = _CurrentContext; + LContext->ViewPort.X = x; + LContext->ViewPort.Y = y; + LContext->ViewPort.XSize = width; + LContext->ViewPort.YSize = height; - LContext->ViewPort.X = x; - LContext->ViewPort.Y = y; - LContext->ViewPort.XSize = width; - LContext->ViewPort.YSize = height; - _RGLFifoGlViewport(LContext->ViewPort.X, LContext->ViewPort.Y, - LContext->ViewPort.XSize, LContext->ViewPort.YSize, 0.0f, 1.0f); + _RGLFifoGlViewport(LContext->ViewPort.X, LContext->ViewPort.Y, + LContext->ViewPort.XSize, LContext->ViewPort.YSize, 0.0f, 1.0f); } jsTexture *_RGLGetCurrentTexture( const jsTextureImageUnit *unit, GLenum target ) @@ -6676,30 +6589,27 @@ CgparameterHookFunction _cgParameterDestroyHook = NULL; typedef struct RGLcgProfileMapType { - CGprofile id; - char* string; - int is_vertex_program; -} -RGLcgProfileMapType; + CGprofile id; + char* string; + int is_vertex_program; +} RGLcgProfileMapType; static void _RGLCgProgramPushFront( _CGcontext* ctx, _CGprogram* prog ) { - prog->next = ctx->programList; - ctx->programList = prog; - prog->parentContext = ctx; - ctx->programCount++; + prog->next = ctx->programList; + ctx->programList = prog; + prog->parentContext = ctx; + ctx->programCount++; } static _CGprogram* _RGLCgProgramFindPrev( _CGcontext* ctx, _CGprogram* prog ) { - _CGprogram* ptr = ctx->programList; + _CGprogram* ptr = ctx->programList; - while ( NULL != ptr && prog != ptr->next ) - { - ptr = ptr->next; - } + while ( NULL != ptr && prog != ptr->next ) + ptr = ptr->next; - return ptr; + return ptr; } void _RGLCgProgramErase( _CGprogram* prog ) @@ -6760,32 +6670,30 @@ bool _RGLCgCreateProgramChecks( CGcontext ctx, CGprofile profile, CGenum program typedef struct { - const char* elfFile; - size_t elfFileSize; + const char* elfFile; + size_t elfFileSize; - const char *symtab; - size_t symbolSize; - size_t symbolCount; - const char *symbolstrtab; + const char *symtab; + size_t symbolSize; + size_t symbolCount; + const char *symbolstrtab; - const char* shadertab; - size_t shadertabSize; - const char* strtab; - size_t strtabSize; - const char* consttab; - size_t consttabSize; -} -CGELFBinary; + const char* shadertab; + size_t shadertabSize; + const char* strtab; + size_t strtabSize; + const char* consttab; + size_t consttabSize; +} CGELFBinary; typedef struct { - const char *texttab; - size_t texttabSize; - const char *paramtab; - size_t paramtabSize; - int index; -} -CGELFProgram; + const char *texttab; + size_t texttabSize; + const char *paramtab; + size_t paramtabSize; + int index; +} CGELFProgram; static bool cgOpenElf( const void *ptr, size_t size, CGELFBinary *elfBinary ) { @@ -6881,7 +6789,7 @@ static CGprogram _RGLCgCreateProgram( CGcontext ctx, CGprofile profile, const Cg // The parameters and the actual program are generated from the ABI specific calls. _CGprogram* prog = ( _CGprogram* )malloc( sizeof( _CGprogram ) ); - if ( NULL == prog ) + if ( prog == NULL ) { _RGLCgRaiseError( CG_MEMORY_ALLOC_ERROR ); return NULL; @@ -6934,7 +6842,7 @@ static CGprogram _RGLCgCreateProgram( CGcontext ctx, CGprofile profile, const Cg // if the creation failed, free all resources. // the error was raised when the error was encoutered. - if ( 0 == success ) + if ( success == 0 ) { // free the program object free( prog ); @@ -7004,15 +6912,13 @@ CG_API CGprogram cgCreateProgram( CGcontext ctx, } else { - printf("RGL ERR: The CG runtime compiler hasn't been setup. cgRTCgcInit() should be called prior to this function.\n" ); + RARCH_ERR("The CG runtime compiler hasn't been setup. cgRTCgcInit() should be called prior to this function.\n" ); _RGLCgRaiseError( CG_INVALID_ENUMERANT_ERROR ); return NULL; } } else - { binaryBuffer = program; - } bool bConvertedToElf = false; @@ -7026,7 +6932,7 @@ CG_API CGprogram cgCreateProgram( CGcontext ctx, // don't throw the warning if it was source, cause clearly that would have been on purpose. if ( program_type == CG_BINARY ) { - printf("RGL WARN: A binary shader is being loaded using a deprecated binary format. Please use the cgnv2elf tool to convert to the new, memory-saving, faster-loading format.\n"); + RARCH_WARN("A binary shader is being loaded using a deprecated binary format. Please use the cgnv2elf tool to convert to the new, memory-saving, faster-loading format.\n"); } //convert from NV format to the runtime format @@ -7048,7 +6954,7 @@ CG_API CGprogram cgCreateProgram( CGcontext ctx, int res = convertNvToElfFromMemory( binaryBuffer, totalSize, 2, 0, ( void** ) & runtimeElfShader, &compiled_program_size, stringTableArray, defaultValuesArray ); if ( res != 0 ) { - printf("RGL ERR: invalid CG binary program.\n"); + RARCH_ERR("Invalid CG binary program.\n"); _RGLCgRaiseError( CG_COMPILER_ERROR ); if ( compiled_program ) _cgRTCgcFreeCompiledProgramHook( compiled_program ); @@ -7098,20 +7004,20 @@ CG_API CGprogram cgCreateProgram( CGcontext ctx, CGELFProgram elfProgram; if ((( intptr_t )binaryBuffer ) & 15 ) { - printf("RGL ERR: CG Binary not aligned on 16 bytes, needed for ucode section.\n"); + RARCH_ERR("CG Binary not aligned on 16 bytes, needed for ucode section.\n"); _RGLCgRaiseError( CG_PROGRAM_LOAD_ERROR ); return NULL; } bool res = cgOpenElf( binaryBuffer, 0, &elfBinary ); if ( !res ) { - printf("RGL ERR: not a valid ELF.\n"); + RARCH_ERR("Not a valid ELF.\n"); _RGLCgRaiseError( CG_PROGRAM_LOAD_ERROR ); return NULL; } if ( !cgGetElfProgramByName( &elfBinary, entry, &elfProgram ) ) { - printf("RGL ERR: couldn't find the shader entry in the CG binary.\n"); + RARCH_ERR("Couldn't find the shader entry in the CG binary.\n"); return NULL; } @@ -7133,8 +7039,6 @@ CG_API CGprogram cgCreateProgram( CGcontext ctx, return prog; } - - CG_API CGprogram cgCreateProgramFromFile( CGcontext ctx, CGenum program_type, const char* program_file, @@ -7191,7 +7095,7 @@ CG_API CGprogram cgCreateProgramFromFile( CGcontext ctx, { fp = fopen( program_file, "rb" ); - if ( NULL == fp ) + if ( fp == NULL ) { _RGLCgRaiseError( CG_FILE_READ_ERROR ); return ( CGprogram )NULL; @@ -7227,7 +7131,7 @@ CG_API CGprogram cgCreateProgramFromFile( CGcontext ctx, int index = _RGLCgGetProgramIndex( group, entry ); if ( index == -1 ) { - printf("RGL ERR: couldn't find the shader entry in the CG binary.\n"); + RARCH_ERR("Couldn't find the shader entry in the CG binary.\n"); } else { @@ -7243,7 +7147,7 @@ CG_API CGprogram cgCreateProgramFromFile( CGcontext ctx, if ( !fp ) { fp = fopen( program_file, "rb" ); - if ( NULL == fp ) + if ( fp == NULL ) { _RGLCgRaiseError( CG_FILE_READ_ERROR ); return ( CGprogram )NULL; @@ -7256,7 +7160,7 @@ CG_API CGprogram cgCreateProgramFromFile( CGcontext ctx, rewind( fp ); char* ptr = ( char* )malloc( file_size + 1 ); - if ( NULL == ptr ) + if ( ptr == NULL ) { _RGLCgRaiseError( CG_MEMORY_ALLOC_ERROR ); fclose( fp ); @@ -7286,7 +7190,7 @@ CG_API CGprogram cgCopyProgram( CGprogram program ) return NULL; } _CGprogram* prog = _cgGetProgPtr( program ); - if ( NULL == prog ) + if ( prog == NULL ) { _RGLCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR ); return ( CGprogram )NULL; @@ -7307,7 +7211,7 @@ CG_API CGprogram cgCopyProgram( CGprogram program ) newprog = ( _CGprogram* )malloc( sizeof( _CGprogram ) ); } - if ( NULL == newprog ) + if ( newprog == NULL ) { _RGLCgRaiseError( CG_MEMORY_ALLOC_ERROR ); return ( CGprogram )NULL; @@ -7370,7 +7274,7 @@ CG_API void cgDestroyProgram( CGprogram program ) return; } _CGprogram* ptr = _cgGetProgPtr( program ); - if ( NULL == ptr ) + if ( ptr == NULL ) { _RGLCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR ); return; @@ -7488,7 +7392,7 @@ CGprogramGroup _RGLCgCreateProgramGroupFromFile( CGcontext ctx, const char *grou { FILE* fp = fopen( group_file, "rb" ); - if ( NULL == fp ) + if ( fp == NULL ) { _RGLCgRaiseError( CG_FILE_READ_ERROR ); return ( CGprogramGroup )NULL; @@ -7500,7 +7404,7 @@ CGprogramGroup _RGLCgCreateProgramGroupFromFile( CGcontext ctx, const char *grou rewind( fp ); char* ptr = ( char* )malloc( file_size + 1 ); - if ( NULL == ptr ) + if ( ptr == NULL ) { _RGLCgRaiseError( CG_MEMORY_ALLOC_ERROR ); return ( CGprogramGroup )NULL; @@ -7650,16 +7554,14 @@ int _RGLCgGetProgramCount( CGprogramGroup group ) } static const RGLcgProfileMapType RGLcgProfileMap[] = - { - {( CGprofile )6144, "CG_PROFILE_START", 1 }, - {( CGprofile )6145, "unknown", 1 }, - +{ + {( CGprofile )6144, "CG_PROFILE_START", 1 }, + {( CGprofile )6145, "unknown", 1 }, #define CG_PROFILE_MACRO(name, compiler_id, compiler_id_caps, compiler_opt,int_id,vertex_profile) \ - {CG_PROFILE_ ## compiler_id_caps, compiler_opt, vertex_profile}, + {CG_PROFILE_ ## compiler_id_caps, compiler_opt, vertex_profile}, #include - - {( CGprofile )0, "", 0 } - }; + {( CGprofile )0, "", 0 } +}; CG_API const char* cgGetProfileString( CGprofile profile ) { @@ -7682,7 +7584,7 @@ CG_API CGprofile cgGetProfile( const char* profile_string ) unsigned int i = 0; while ( i < arraysize ) { - if ( 0 == strcmp( RGLcgProfileMap[i].string, profile_string ) ) + if ( strcmp( RGLcgProfileMap[i].string, profile_string ) == 0 ) { return RGLcgProfileMap[i].id; } @@ -7691,39 +7593,26 @@ CG_API CGprofile cgGetProfile( const char* profile_string ) return CG_PROFILE_UNKNOWN; } -CG_API CGerror cgGetError( void ) +CG_API CGerror cgGetError(void) { - CGerror err = _CurrentContext->RGLcgLastError; - _CurrentContext->RGLcgLastError = CG_NO_ERROR; - return err; + CGerror err = _CurrentContext->RGLcgLastError; + _CurrentContext->RGLcgLastError = CG_NO_ERROR; + return err; } + CG_API const char* cgGetErrorString( CGerror error ) { - return "cgGetErrorString: N/A\n"; -} - -CG_API const char* cgGetLastErrorString( CGerror* error ) -{ - return "cgGetErrorString: N/A\n"; -} - -CG_API void cgSetErrorCallback( CGerrorCallbackFunc func ) -{ - _CurrentContext->RGLcgErrorCallbackFunction = func; -} - - -CG_API CGerrorCallbackFunc cgGetErrorCallback( void ) -{ - return _CurrentContext->RGLcgErrorCallbackFunction; + static char strbuf[256]; + snprintf(strbuf, sizeof(strbuf), "%d", error); + return strbuf; } void _RGLCgDestroyContextParam( CgRuntimeParameter* ptr ) { - if ( _cgParameterDestroyHook ) _cgParameterDestroyHook( ptr ); - _RGLEraseName( &_CurrentContext->cgParameterNameSpace, ( jsName )( ptr->id ) ); - free( ptr ); + if ( _cgParameterDestroyHook ) _cgParameterDestroyHook( ptr ); + _RGLEraseName( &_CurrentContext->cgParameterNameSpace, ( jsName )( ptr->id ) ); + free( ptr ); } static int _RGLGetSizeofSubArray( const short *dimensions, int count ) @@ -8075,7 +7964,7 @@ CGGL_API void cgGLLoadProgram( CGprogram program ) CGGL_API CGbool cgGLIsProgramLoaded( CGprogram program ) { - return CG_TRUE; + return CG_TRUE; } @@ -8144,43 +8033,34 @@ CGGL_API void cgGLUnbindProgram( CGprofile profile ) CGGL_API GLuint cgGLGetProgramID( CGprogram program ) { - - return 0; -} - -CGGL_API void cgGLEnableProgramProfiles( CGprogram program ) -{ - return; -} - -CGGL_API void cgGLDisableProgramProfiles( CGprogram program ) -{ - return; + return 0; } +CGGL_API void cgGLEnableProgramProfiles( CGprogram program ) {} +CGGL_API void cgGLDisableProgramProfiles( CGprogram program ) {} CGGL_API void cgGLSetParameter1f( CGparameter param, float x ) { + CgRuntimeParameter *ptr = _RGLCgGLTestParameter( param ); - CgRuntimeParameter *ptr = _RGLCgGLTestParameter( param ); - - float v[4] = {x, x, x, x}; - ptr->setterIndex( ptr, v, CG_GETINDEX( param ) ); + float v[4] = {x, x, x, x}; + ptr->setterIndex( ptr, v, CG_GETINDEX( param ) ); } CGGL_API void cgGLSetParameter2f( CGparameter param, float x, float y ) { - CgRuntimeParameter *ptr = _RGLCgGLTestParameter( param ); + CgRuntimeParameter *ptr = _RGLCgGLTestParameter( param ); - float v[4] = {x, y, y, y}; - ptr->setterIndex( ptr, v, CG_GETINDEX( param ) ); + float v[4] = {x, y, y, y}; + ptr->setterIndex( ptr, v, CG_GETINDEX( param ) ); } -CGGL_API void cgGLSetParameterPointer( CGparameter param, - GLint fsize, - GLenum type, - GLsizei stride, - const GLvoid *pointer ) +CGGL_API void cgGLSetParameterPointer +( CGparameter param, + GLint fsize, + GLenum type, + GLsizei stride, + const GLvoid *pointer ) { CgRuntimeParameter *_ptr = _RGLCgGLTestParameter( param ); @@ -8199,13 +8079,12 @@ CGGL_API void cgGLSetParameterPointer( CGparameter param, CGGL_API void cgGLEnableClientState( CGparameter param ) { + CgRuntimeParameter *_ptr = _RGLCgGLTestParameter( param ); - CgRuntimeParameter *_ptr = _RGLCgGLTestParameter( param ); + const CgParameterResource *parameterResource = _RGLGetParameterResource( _ptr->program, _ptr->parameterEntry ); - const CgParameterResource *parameterResource = _RGLGetParameterResource( _ptr->program, _ptr->parameterEntry ); - - GLuint index = ( GLuint )( parameterResource->resource - CG_ATTR0 ); - _RGLEnableVertexAttribArrayNV( index ); + GLuint index = ( GLuint )( parameterResource->resource - CG_ATTR0 ); + _RGLEnableVertexAttribArrayNV( index ); } CGGL_API void cgGLDisableClientState( CGparameter param ) @@ -8290,9 +8169,8 @@ CGGL_API void cgGLEnableTextureParameter( CGparameter param ) static void _RGLCgContextZero( _CGcontext* p ) { - memset( p, 0, sizeof( *p ) ); - p->compileType = CG_UNKNOWN; - + memset( p, 0, sizeof( *p ) ); + p->compileType = CG_UNKNOWN; } static void _RGLCgContextPushFront( _CGcontext* ctx ) @@ -8318,7 +8196,7 @@ CG_API CGcontext cgCreateContext( void ) _CGcontext* ptr = NULL; ptr = ( _CGcontext* )malloc( sizeof( _CGcontext ) ); - if ( NULL == ptr ) + if ( ptr == NULL ) { _RGLCgRaiseError( CG_MEMORY_ALLOC_ERROR ); return ( CGcontext )NULL; @@ -8400,8 +8278,7 @@ void _RGLCgRaiseError( CGerror error ) { _CurrentContext->RGLcgLastError = error; - - printf("RGL: Cg error:%s.\n", cgGetErrorString( error ) ); + RARCH_ERR("Cg error: %d.\n", error); if ( _CurrentContext->RGLcgErrorCallbackFunction ) _CurrentContext->RGLcgErrorCallbackFunction(); @@ -8621,33 +8498,30 @@ unsigned int _RGLCountFloatsInCgType( CGtype type ) void _cgRaiseInvalidParam( CgRuntimeParameter*p, const void*v ) { - _RGLCgRaiseError( CG_INVALID_PARAMETER_ERROR ); + _RGLCgRaiseError( CG_INVALID_PARAMETER_ERROR ); } void _cgRaiseInvalidParamIndex( CgRuntimeParameter*p, const void*v, const int index ) { - _RGLCgRaiseError( CG_INVALID_PARAMETER_ERROR ); + _RGLCgRaiseError( CG_INVALID_PARAMETER_ERROR ); } void _cgRaiseNotMatrixParam( CgRuntimeParameter*p, const void*v ) { - _RGLCgRaiseError( CG_NOT_MATRIX_PARAM_ERROR ); -} -void _cgRaiseNotMatrixParamIndex( CgRuntimeParameter*p, const void*v, const int index ) -{ - _RGLCgRaiseError( CG_NOT_MATRIX_PARAM_ERROR ); + _RGLCgRaiseError( CG_NOT_MATRIX_PARAM_ERROR ); } -void _cgIgnoreSetParam( CgRuntimeParameter*p, const void*v ) -{ -} -void _cgIgnoreSetParamIndex( CgRuntimeParameter*p, const void*v, const int index ) +void _cgRaiseNotMatrixParamIndex( CgRuntimeParameter*p, const void*v, const int index ) { + _RGLCgRaiseError( CG_NOT_MATRIX_PARAM_ERROR ); } +void _cgIgnoreSetParam( CgRuntimeParameter*p, const void*v ) {} +void _cgIgnoreSetParamIndex( CgRuntimeParameter*p, const void*v, const int index ) {} + CgRuntimeParameter* _cgGLTestTextureParameter( CGparameter param ) { - CgRuntimeParameter* ptr = _RGLCgGLTestParameter( param ); - return ptr; + CgRuntimeParameter* ptr = _RGLCgGLTestParameter( param ); + return ptr; } diff --git a/console/rgl/ps3/rgl.h b/console/rgl/ps3/rgl.h index b85fd5303a..632f719cbd 100644 --- a/console/rgl/ps3/rgl.h +++ b/console/rgl/ps3/rgl.h @@ -6,7 +6,14 @@ #include "base.hpp" #ifdef __PSL1GHT__ +#include #include +#include +#include +#include "../../../ps3/sdk_defines.h" +#define CGerror int +typedef void (* CGerrorCallbackFunc)(void); +typedef struct _CGcontext *CGcontext; #else #include #endif @@ -25,104 +32,104 @@ extern "C" typedef enum RGLEnum { - RGL_NONE = 0x0000, - RGL_COLOR_BUFFER_BIT = 0x4000, - RGL_ZERO = 0, - RGL_ONE = 1, - RGL_SRC_COLOR = 0x0300, - RGL_ONE_MINUS_SRC_COLOR = 0x0301, - RGL_SRC_ALPHA = 0x0302, - RGL_ONE_MINUS_SRC_ALPHA = 0x0303, - RGL_DST_ALPHA = 0x0304, - RGL_ONE_MINUS_DST_ALPHA = 0x0305, - RGL_DST_COLOR = 0x0306, - RGL_ONE_MINUS_DST_COLOR = 0x0307, - RGL_SRC_ALPHA_SATURATE = 0x0308, - RGL_ONE_MINUS_CONSTANT_COLOR = 0x8002, - RGL_CONSTANT_ALPHA = 0x8003, - RGL_ONE_MINUS_CONSTANT_ALPHA = 0x8004, - RGL_MIN = 0x8007, - RGL_MAX = 0x8008, - RGL_FUNC_SUBTRACT = 0x800A, - RGL_FUNC_REVERSE_SUBTRACT = 0x800B, - RGL_LUMINANCE8 = 0x8040, - RGL_LUMINANCE16 = 0x8042, - RGL_ALPHA8 = 0x803C, - RGL_ALPHA16 = 0x803E, - RGL_INTENSITY8 = 0x804B, - RGL_INTENSITY16 = 0x804D, - RGL_LUMINANCE8_ALPHA8 = 0x8045, - RGL_LUMINANCE16_ALPHA16 = 0x8048, - RGL_HILO8 = 0x885E, - RGL_HILO16 = 0x86F8, - RGL_ARGB8 = 0x6007, - RGL_BGRA8 = 0xff01, - RGL_RGBA8 = 0x8058, - RGL_ABGR8 = 0xff02, - RGL_XBGR8 = 0xff03, - RGL_RGBX8 = 0xff07, - RGL_FLOAT_R32 = 0x8885, - RGL_FLOAT_RGBA16 = 0x888A, - RGL_FLOAT_RGBA32 = 0x888B, - RGL_FLOAT_RGBX16 = 0xff04, - RGL_FLOAT_RGBX32 = 0xff05, - RGL_LUMINANCE32F_ARB = 0x8818, - RGL_ALPHA_LUMINANCE16F_SCE = 0x600B, - RGL_RGB5_A1_SCE = 0x600C, - RGL_RGB565_SCE = 0x600D, - RGL_DITHER = 0x0bd0, - RGL_PSHADER_SRGB_REMAPPING = 0xff06, - RGL_VERTEX_ATTRIB_ARRAY0 = 0x8650, - RGL_VERTEX_ATTRIB_ARRAY1 = 0x8651, - RGL_VERTEX_ATTRIB_ARRAY2 = 0x8652, - RGL_VERTEX_ATTRIB_ARRAY3 = 0x8653, - RGL_VERTEX_ATTRIB_ARRAY4 = 0x8654, - RGL_VERTEX_ATTRIB_ARRAY5 = 0x8655, - RGL_VERTEX_ATTRIB_ARRAY6 = 0x8656, - RGL_VERTEX_ATTRIB_ARRAY7 = 0x8657, - RGL_VERTEX_ATTRIB_ARRAY8 = 0x8658, - RGL_VERTEX_ATTRIB_ARRAY9 = 0x8659, - RGL_VERTEX_ATTRIB_ARRAY10 = 0x865a, - RGL_VERTEX_ATTRIB_ARRAY11 = 0x865b, - RGL_VERTEX_ATTRIB_ARRAY12 = 0x865c, - RGL_VERTEX_ATTRIB_ARRAY13 = 0x865d, - RGL_VERTEX_ATTRIB_ARRAY14 = 0x865e, - RGL_VERTEX_ATTRIB_ARRAY15 = 0x865f, - RGL_CLAMP = 0x2900, - RGL_REPEAT = 0x2901, - RGL_CLAMP_TO_EDGE = 0x812F, - RGL_CLAMP_TO_BORDER = 0x812D, - RGL_MIRRORED_REPEAT = 0x8370, - RGL_MIRROR_CLAMP = 0x8742, - RGL_MIRROR_CLAMP_TO_EDGE = 0x8743, - RGL_MIRROR_CLAMP_TO_BORDER = 0x8912, - RGL_GAMMA_REMAP_RED_BIT = 0x0001, - RGL_GAMMA_REMAP_GREEN_BIT = 0x0002, - RGL_GAMMA_REMAP_BLUE_BIT = 0x0004, - RGL_GAMMA_REMAP_ALPHA_BIT = 0x0008, - RGL_TEXTURE_WRAP_S = 0x2802, - RGL_TEXTURE_WRAP_T = 0x2803, - RGL_TEXTURE_WRAP_R = 0x8072, - RGL_TEXTURE_MIN_FILTER = 0x2801, - RGL_TEXTURE_MAG_FILTER = 0x2800, - RGL_TEXTURE_MAX_ANISOTROPY = 0x84FE, - RGL_TEXTURE_COMPARE_FUNC = 0x884D, - RGL_TEXTURE_MIN_LOD = 0x813A, - RGL_TEXTURE_MAX_LOD = 0x813B, - RGL_TEXTURE_LOD_BIAS = 0x8501, - RGL_TEXTURE_BORDER_COLOR = 0x1004, - RGL_TEXTURE_GAMMA_REMAP = 0xff30, - RGL_VERTEX_PROGRAM = 0x8620, - RGL_FRAGMENT_PROGRAM = 0x8804, - RGL_FLOAT = 0x1406, - RGL_HALF_FLOAT = 0x140B, - RGL_SHORT = 0x1402, - RGL_UNSIGNED_BYTE = 0x1401, - RGL_UNSIGNED_SHORT = 0x1403, - RGL_UNSIGNED_INT = 0x1405, - RGL_BYTE = 0x1400, - RGL_INT = 0x1404, - RGL_CMP = 0x6020, + RGL_NONE = 0x0000, + RGL_COLOR_BUFFER_BIT = 0x4000, + RGL_ZERO = 0, + RGL_ONE = 1, + RGL_SRC_COLOR = 0x0300, + RGL_ONE_MINUS_SRC_COLOR = 0x0301, + RGL_SRC_ALPHA = 0x0302, + RGL_ONE_MINUS_SRC_ALPHA = 0x0303, + RGL_DST_ALPHA = 0x0304, + RGL_ONE_MINUS_DST_ALPHA = 0x0305, + RGL_DST_COLOR = 0x0306, + RGL_ONE_MINUS_DST_COLOR = 0x0307, + RGL_SRC_ALPHA_SATURATE = 0x0308, + RGL_ONE_MINUS_CONSTANT_COLOR = 0x8002, + RGL_CONSTANT_ALPHA = 0x8003, + RGL_ONE_MINUS_CONSTANT_ALPHA = 0x8004, + RGL_MIN = 0x8007, + RGL_MAX = 0x8008, + RGL_FUNC_SUBTRACT = 0x800A, + RGL_FUNC_REVERSE_SUBTRACT = 0x800B, + RGL_LUMINANCE8 = 0x8040, + RGL_LUMINANCE16 = 0x8042, + RGL_ALPHA8 = 0x803C, + RGL_ALPHA16 = 0x803E, + RGL_INTENSITY8 = 0x804B, + RGL_INTENSITY16 = 0x804D, + RGL_LUMINANCE8_ALPHA8 = 0x8045, + RGL_LUMINANCE16_ALPHA16 = 0x8048, + RGL_HILO8 = 0x885E, + RGL_HILO16 = 0x86F8, + RGL_ARGB8 = 0x6007, + RGL_BGRA8 = 0xff01, + RGL_RGBA8 = 0x8058, + RGL_ABGR8 = 0xff02, + RGL_XBGR8 = 0xff03, + RGL_RGBX8 = 0xff07, + RGL_FLOAT_R32 = 0x8885, + RGL_FLOAT_RGBA16 = 0x888A, + RGL_FLOAT_RGBA32 = 0x888B, + RGL_FLOAT_RGBX16 = 0xff04, + RGL_FLOAT_RGBX32 = 0xff05, + RGL_LUMINANCE32F_ARB = 0x8818, + RGL_ALPHA_LUMINANCE16F_SCE = 0x600B, + RGL_RGB5_A1_SCE = 0x600C, + RGL_RGB565_SCE = 0x600D, + RGL_DITHER = 0x0bd0, + RGL_PSHADER_SRGB_REMAPPING = 0xff06, + RGL_VERTEX_ATTRIB_ARRAY0 = 0x8650, + RGL_VERTEX_ATTRIB_ARRAY1 = 0x8651, + RGL_VERTEX_ATTRIB_ARRAY2 = 0x8652, + RGL_VERTEX_ATTRIB_ARRAY3 = 0x8653, + RGL_VERTEX_ATTRIB_ARRAY4 = 0x8654, + RGL_VERTEX_ATTRIB_ARRAY5 = 0x8655, + RGL_VERTEX_ATTRIB_ARRAY6 = 0x8656, + RGL_VERTEX_ATTRIB_ARRAY7 = 0x8657, + RGL_VERTEX_ATTRIB_ARRAY8 = 0x8658, + RGL_VERTEX_ATTRIB_ARRAY9 = 0x8659, + RGL_VERTEX_ATTRIB_ARRAY10 = 0x865a, + RGL_VERTEX_ATTRIB_ARRAY11 = 0x865b, + RGL_VERTEX_ATTRIB_ARRAY12 = 0x865c, + RGL_VERTEX_ATTRIB_ARRAY13 = 0x865d, + RGL_VERTEX_ATTRIB_ARRAY14 = 0x865e, + RGL_VERTEX_ATTRIB_ARRAY15 = 0x865f, + RGL_CLAMP = 0x2900, + RGL_REPEAT = 0x2901, + RGL_CLAMP_TO_EDGE = 0x812F, + RGL_CLAMP_TO_BORDER = 0x812D, + RGL_MIRRORED_REPEAT = 0x8370, + RGL_MIRROR_CLAMP = 0x8742, + RGL_MIRROR_CLAMP_TO_EDGE = 0x8743, + RGL_MIRROR_CLAMP_TO_BORDER = 0x8912, + RGL_GAMMA_REMAP_RED_BIT = 0x0001, + RGL_GAMMA_REMAP_GREEN_BIT = 0x0002, + RGL_GAMMA_REMAP_BLUE_BIT = 0x0004, + RGL_GAMMA_REMAP_ALPHA_BIT = 0x0008, + RGL_TEXTURE_WRAP_S = 0x2802, + RGL_TEXTURE_WRAP_T = 0x2803, + RGL_TEXTURE_WRAP_R = 0x8072, + RGL_TEXTURE_MIN_FILTER = 0x2801, + RGL_TEXTURE_MAG_FILTER = 0x2800, + RGL_TEXTURE_MAX_ANISOTROPY = 0x84FE, + RGL_TEXTURE_COMPARE_FUNC = 0x884D, + RGL_TEXTURE_MIN_LOD = 0x813A, + RGL_TEXTURE_MAX_LOD = 0x813B, + RGL_TEXTURE_LOD_BIAS = 0x8501, + RGL_TEXTURE_BORDER_COLOR = 0x1004, + RGL_TEXTURE_GAMMA_REMAP = 0xff30, + RGL_VERTEX_PROGRAM = 0x8620, + RGL_FRAGMENT_PROGRAM = 0x8804, + RGL_FLOAT = 0x1406, + RGL_HALF_FLOAT = 0x140B, + RGL_SHORT = 0x1402, + RGL_UNSIGNED_BYTE = 0x1401, + RGL_UNSIGNED_SHORT = 0x1403, + RGL_UNSIGNED_INT = 0x1405, + RGL_BYTE = 0x1400, + RGL_INT = 0x1404, + RGL_CMP = 0x6020, } RGLEnum; typedef struct PSGLdevice PSGLdevice; @@ -133,30 +140,26 @@ extern RGLState _RGLState; struct RGLViewportState { - GLint x, y, w, h; - - GLfloat xScale, xCenter; - GLfloat yScale, yCenter; + GLint x, y, w, h; + GLfloat xScale, xCenter; + GLfloat yScale, yCenter; }; struct jsFramebufferAttachment { - GLenum type; - GLuint name; - GLenum textureTarget; - jsFramebufferAttachment(): type( GL_NONE ), name( 0 ), textureTarget( GL_NONE ) - {}; + GLenum type; + GLuint name; + GLenum textureTarget; + jsFramebufferAttachment(): type( GL_NONE ), name( 0 ), textureTarget( GL_NONE ) {}; }; struct jsFramebuffer { - jsFramebufferAttachment color[_RGL_MAX_COLOR_ATTACHMENTS]; - GLboolean needValidate; - jsFramebuffer(): needValidate( GL_TRUE ) - {}; - virtual ~jsFramebuffer() - {}; + jsFramebufferAttachment color[_RGL_MAX_COLOR_ATTACHMENTS]; + GLboolean needValidate; + jsFramebuffer(): needValidate( GL_TRUE ) {}; + virtual ~jsFramebuffer() {}; }; #define RGLBIT_GET(f,n) ((f) & (1<<(n))) @@ -165,125 +168,115 @@ struct jsFramebuffer #define RGLBIT_ASSIGN(f,n,val) do { if(val) RGLBIT_TRUE(f,n); else RGLBIT_FALSE(f,n); } while(0) #ifndef MSVC - #define ALIGN16 __attribute__((aligned (16))) #define _RGL_RESTRICT __restrict - -#if defined(_WIN64) - typedef __int64 RGLintptr; - typedef __int64 RGLsizeiptr; #else - typedef long RGLintptr; - typedef long RGLsizeiptr; -#endif - -#else - #define ALIGN16 #define _RGL_RESTRICT #pragma warning( push ) #pragma warning ( disable : 4200 ) - typedef intptr_t RGLintptr; - typedef size_t RGLsizeiptr; #endif +typedef intptr_t RGLintptr; +typedef size_t RGLsizeiptr; + typedef struct { - GLfloat X, Y , Z, W; + GLfloat X, Y , Z, W; } jsPositionXYZW; typedef struct { - GLfloat X, Y , Z; + GLfloat X, Y , Z; } jsPositionXYZ; typedef struct { - GLfloat R, G, B, A; + GLfloat R, G, B, A; } jsColorRGBAf; typedef struct { - GLfloat * MatrixStackf; - int MatrixStackPtr; - GLboolean dirty; + GLfloat * MatrixStackf; + int MatrixStackPtr; + GLboolean dirty; } jsMatrixStack; typedef struct { - int X, Y, XSize, YSize; + int X, Y, XSize, YSize; } jsViewPort; #define _RGL_IMAGE_STORAGE_RASTER 0 #define _RGL_IMAGE_STORAGE_BLOCK 1 enum { - _RGL_IMAGE_DATASTATE_UNSET = 0x0, - _RGL_IMAGE_DATASTATE_HOST = 0x1, - _RGL_IMAGE_DATASTATE_GPU = 0x2 + _RGL_IMAGE_DATASTATE_UNSET = 0x0, + _RGL_IMAGE_DATASTATE_HOST = 0x1, + _RGL_IMAGE_DATASTATE_GPU = 0x2 }; typedef struct jsImage_ { - GLboolean isSet; + GLboolean isSet; - GLenum internalFormat; - GLenum format; - GLenum type; - GLsizei width; - GLsizei height; - GLsizei alignment; + GLenum internalFormat; + GLenum format; + GLenum type; + GLsizei width; + GLsizei height; + GLsizei alignment; - GLsizei storageSize; - GLsizei xstride, ystride; - GLuint xblk, yblk; + GLsizei storageSize; + GLsizei xstride, ystride; + GLuint xblk, yblk; - char *data; - char *mallocData; - GLsizei mallocStorageSize; - GLenum dataState; + char *data; + char *mallocData; + GLsizei mallocStorageSize; + GLenum dataState; } jsImage; typedef struct { - GLenum format; - GLenum type; - GLsizei width; - GLsizei height; - GLsizei xstride; - GLsizei ystride; - void* data; + GLenum format; + GLenum type; + GLsizei width; + GLsizei height; + GLsizei xstride; + GLsizei ystride; + void* data; } jsRaster; #define _RGL_TEXTURE_REVALIDATE_LAYOUT 0x01 #define _RGL_TEXTURE_REVALIDATE_IMAGES 0x02 #define _RGL_TEXTURE_REVALIDATE_PARAMETERS 0x04 - typedef struct jsBufferObject jsBufferObject; +typedef struct jsBufferObject jsBufferObject; - typedef struct - { - GLuint revalidate; - GLuint target; +typedef struct +{ + GLuint revalidate; + GLuint target; - GLuint minFilter; - GLuint magFilter; - GLuint gammaRemap; - GLenum usage; + GLuint minFilter; + GLuint magFilter; + GLuint gammaRemap; + GLenum usage; - GLboolean isRenderTarget; - GLboolean isComplete; + GLboolean isRenderTarget; + GLboolean isComplete; - jsBufferObject *referenceBuffer; - GLintptr offset; + jsBufferObject *referenceBuffer; + GLintptr offset; - RGL::Vector framebuffers; + RGL::Vector framebuffers; - GLuint imageCount; - jsImage* image; - void * platformTexture[]; - } - jsTexture; + GLuint imageCount; + jsImage* image; + void * platformTexture[]; +} +jsTexture; #define _RGL_MAX_TEXTURE_COORDS 8 #define _RGL_MAX_TEXTURE_IMAGE_UNITS 16 @@ -303,146 +296,145 @@ typedef struct typedef struct { - GLuint bound2D; + GLuint bound2D; - jsTexture* default2D; + jsTexture* default2D; - GLenum fragmentTarget; + GLenum fragmentTarget; - GLenum envMode; - jsColorRGBAf envColor; + GLenum envMode; + jsColorRGBAf envColor; - jsTexture* currentTexture; + jsTexture* currentTexture; } jsTextureImageUnit; typedef struct { - GLuint revalidate; - jsMatrixStack TextureMatrixStack; + GLuint revalidate; + jsMatrixStack TextureMatrixStack; } jsTextureCoordsUnit; enum { - _RGL_FRAMEBUFFER_ATTACHMENT_NONE, - _RGL_FRAMEBUFFER_ATTACHMENT_RENDERBUFFER, - _RGL_FRAMEBUFFER_ATTACHMENT_TEXTURE, + _RGL_FRAMEBUFFER_ATTACHMENT_NONE, + _RGL_FRAMEBUFFER_ATTACHMENT_RENDERBUFFER, + _RGL_FRAMEBUFFER_ATTACHMENT_TEXTURE, }; typedef enum PSGLtvStandard { - PSGL_TV_STANDARD_NONE, - PSGL_TV_STANDARD_NTSC_M, - PSGL_TV_STANDARD_NTSC_J, - PSGL_TV_STANDARD_PAL_M, - PSGL_TV_STANDARD_PAL_B, - PSGL_TV_STANDARD_PAL_D, - PSGL_TV_STANDARD_PAL_G, - PSGL_TV_STANDARD_PAL_H, - PSGL_TV_STANDARD_PAL_I, - PSGL_TV_STANDARD_PAL_N, - PSGL_TV_STANDARD_PAL_NC, - PSGL_TV_STANDARD_HD480I, - PSGL_TV_STANDARD_HD480P, - PSGL_TV_STANDARD_HD576I, - PSGL_TV_STANDARD_HD576P, - PSGL_TV_STANDARD_HD720P, - PSGL_TV_STANDARD_HD1080I, - PSGL_TV_STANDARD_HD1080P, - PSGL_TV_STANDARD_1280x720_ON_VESA_1280x768 = 128, - PSGL_TV_STANDARD_1280x720_ON_VESA_1280x1024, - PSGL_TV_STANDARD_1920x1080_ON_VESA_1920x1200, + PSGL_TV_STANDARD_NONE, + PSGL_TV_STANDARD_NTSC_M, + PSGL_TV_STANDARD_NTSC_J, + PSGL_TV_STANDARD_PAL_M, + PSGL_TV_STANDARD_PAL_B, + PSGL_TV_STANDARD_PAL_D, + PSGL_TV_STANDARD_PAL_G, + PSGL_TV_STANDARD_PAL_H, + PSGL_TV_STANDARD_PAL_I, + PSGL_TV_STANDARD_PAL_N, + PSGL_TV_STANDARD_PAL_NC, + PSGL_TV_STANDARD_HD480I, + PSGL_TV_STANDARD_HD480P, + PSGL_TV_STANDARD_HD576I, + PSGL_TV_STANDARD_HD576P, + PSGL_TV_STANDARD_HD720P, + PSGL_TV_STANDARD_HD1080I, + PSGL_TV_STANDARD_HD1080P, + PSGL_TV_STANDARD_1280x720_ON_VESA_1280x768 = 128, + PSGL_TV_STANDARD_1280x720_ON_VESA_1280x1024, + PSGL_TV_STANDARD_1920x1080_ON_VESA_1920x1200, } PSGLtvStandard; typedef enum PSGLdeviceConnector { - PSGL_DEVICE_CONNECTOR_NONE, - PSGL_DEVICE_CONNECTOR_VGA, - PSGL_DEVICE_CONNECTOR_DVI, - PSGL_DEVICE_CONNECTOR_HDMI, - PSGL_DEVICE_CONNECTOR_COMPOSITE, - PSGL_DEVICE_CONNECTOR_SVIDEO, - PSGL_DEVICE_CONNECTOR_COMPONENT, + PSGL_DEVICE_CONNECTOR_NONE, + PSGL_DEVICE_CONNECTOR_VGA, + PSGL_DEVICE_CONNECTOR_DVI, + PSGL_DEVICE_CONNECTOR_HDMI, + PSGL_DEVICE_CONNECTOR_COMPOSITE, + PSGL_DEVICE_CONNECTOR_SVIDEO, + PSGL_DEVICE_CONNECTOR_COMPONENT, } PSGLdeviceConnector; typedef enum PSGLbufferingMode { - PSGL_BUFFERING_MODE_SINGLE = 1, - PSGL_BUFFERING_MODE_DOUBLE = 2, - PSGL_BUFFERING_MODE_TRIPLE = 3, + PSGL_BUFFERING_MODE_SINGLE = 1, + PSGL_BUFFERING_MODE_DOUBLE = 2, + PSGL_BUFFERING_MODE_TRIPLE = 3, } PSGLbufferingMode; typedef enum RescRatioMode { - RESC_RATIO_MODE_FULLSCREEN, - RESC_RATIO_MODE_LETTERBOX, - RESC_RATIO_MODE_PANSCAN, + RESC_RATIO_MODE_FULLSCREEN, + RESC_RATIO_MODE_LETTERBOX, + RESC_RATIO_MODE_PANSCAN, } RescRatioMode; typedef enum RescPalTemporalMode { - RESC_PAL_TEMPORAL_MODE_50_NONE, - RESC_PAL_TEMPORAL_MODE_60_DROP, - RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE, - RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE_30_DROP, - RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE_DROP_FLEXIBLE, + RESC_PAL_TEMPORAL_MODE_50_NONE, + RESC_PAL_TEMPORAL_MODE_60_DROP, + RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE, + RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE_30_DROP, + RESC_PAL_TEMPORAL_MODE_60_INTERPOLATE_DROP_FLEXIBLE, } RescPalTemporalMode; typedef enum RescInterlaceMode { - RESC_INTERLACE_MODE_NORMAL_BILINEAR, - RESC_INTERLACE_MODE_INTERLACE_FILTER, + RESC_INTERLACE_MODE_NORMAL_BILINEAR, + RESC_INTERLACE_MODE_INTERLACE_FILTER, } RescInterlaceMode; typedef struct { - GLuint enable; - GLenum colorFormat; - GLenum depthFormat; - GLenum multisamplingMode; - PSGLtvStandard TVStandard; - PSGLdeviceConnector connector; - PSGLbufferingMode bufferingMode; - GLuint width; - GLuint height; - GLuint renderWidth; - GLuint renderHeight; - RescRatioMode rescRatioMode; - RescPalTemporalMode rescPalTemporalMode; - RescInterlaceMode rescInterlaceMode; - GLfloat horizontalScale; - GLfloat verticalScale; + GLuint enable; + GLenum colorFormat; + GLenum depthFormat; + GLenum multisamplingMode; + PSGLtvStandard TVStandard; + PSGLdeviceConnector connector; + PSGLbufferingMode bufferingMode; + GLuint width; + GLuint height; + GLuint renderWidth; + GLuint renderHeight; + RescRatioMode rescRatioMode; + RescPalTemporalMode rescPalTemporalMode; + RescInterlaceMode rescInterlaceMode; + GLfloat horizontalScale; + GLfloat verticalScale; } PSGLdeviceParameters; struct PSGLdevice { - PSGLdeviceParameters deviceParameters; - - GLvoid* rasterDriver; - char platformDevice[]; + PSGLdeviceParameters deviceParameters; + GLvoid* rasterDriver; + char platformDevice[]; }; typedef struct { - GLenum mode; - GLint firstVertex; - GLsizei vertexCount; + GLenum mode; + GLint firstVertex; + GLsizei vertexCount; - GLuint xferTotalSize; - GLuint indexXferOffset; - GLuint indexXferSize; - GLuint attribXferTotalSize; - GLuint attribXferOffset[_RGL_MAX_VERTEX_ATTRIBS]; - GLuint attribXferSize[_RGL_MAX_VERTEX_ATTRIBS]; + GLuint xferTotalSize; + GLuint indexXferOffset; + GLuint indexXferSize; + GLuint attribXferTotalSize; + GLuint attribXferOffset[_RGL_MAX_VERTEX_ATTRIBS]; + GLuint attribXferSize[_RGL_MAX_VERTEX_ATTRIBS]; } jsDrawParams; #define _RGL_ATTRIB_POSITION_INDEX 0 -#define _RGL_ATTRIB_WEIGHT_INDEX 1 -#define _RGL_ATTRIB_NORMAL_INDEX 2 -#define _RGL_ATTRIB_PRIMARY_COLOR_INDEX 3 -#define _RGL_ATTRIB_SECONDARY_COLOR_INDEX 4 +#define _RGL_ATTRIB_WEIGHT_INDEX 1 +#define _RGL_ATTRIB_NORMAL_INDEX 2 +#define _RGL_ATTRIB_PRIMARY_COLOR_INDEX 3 +#define _RGL_ATTRIB_SECONDARY_COLOR_INDEX 4 #define _RGL_ATTRIB_FOG_COORD_INDEX 5 #define _RGL_ATTRIB_POINT_SIZE_INDEX 6 -#define _RGL_ATTRIB_BLEND_INDICES_INDEX 7 +#define _RGL_ATTRIB_BLEND_INDICES_INDEX 7 #define _RGL_ATTRIB_TEX_COORD0_INDEX 8 #define _RGL_ATTRIB_TEX_COORD1_INDEX 9 #define _RGL_ATTRIB_TEX_COORD2_INDEX 10 @@ -452,54 +444,53 @@ typedef struct #define _RGL_ATTRIB_TEX_COORD6_INDEX 14 #define _RGL_ATTRIB_TEX_COORD7_INDEX 15 - typedef struct - { - GLvoid* clientData; - GLuint clientSize; - GLenum clientType; - GLsizei clientStride; - GLuint arrayBuffer; - GLfloat value[4]; - GLuint frequency; - GLboolean normalized; - } - ALIGN16 jsAttribute; +typedef struct +{ + GLvoid* clientData; + GLuint clientSize; + GLenum clientType; + GLsizei clientStride; + GLuint arrayBuffer; + GLfloat value[4]; + GLuint frequency; + GLboolean normalized; +} +ALIGN16 jsAttribute; - typedef struct - { - jsAttribute attrib[_RGL_MAX_VERTEX_ATTRIBS]; - unsigned int DirtyMask; - unsigned int EnabledMask; - unsigned int NeedsConversionMask; - unsigned int HasVBOMask; - unsigned int ModuloMask; - } - ALIGN16 jsAttributeState; +typedef struct +{ + jsAttribute attrib[_RGL_MAX_VERTEX_ATTRIBS]; + unsigned int DirtyMask; + unsigned int EnabledMask; + unsigned int NeedsConversionMask; + unsigned int HasVBOMask; + unsigned int ModuloMask; +} +ALIGN16 jsAttributeState; - typedef struct - { - jsAttributeState attribs; - GLboolean dirty; - unsigned int beenUpdatedMask; - GLvoid* cmdBuffer; - GLuint cmdNumWords; - } - ALIGN16 jsAttribSet; - - struct jsBufferObject - { - GLuint refCount; - GLsizeiptr size; - GLenum usage; - GLboolean mapped; - GLenum internalFormat; - GLuint width; - GLuint height; - RGL::Vector textureReferences; - RGL::Vector attribSets; - void *platformBufferObject[]; - }; +typedef struct +{ + jsAttributeState attribs; + GLboolean dirty; + unsigned int beenUpdatedMask; + GLvoid* cmdBuffer; + GLuint cmdNumWords; +} +ALIGN16 jsAttribSet; +struct jsBufferObject +{ + GLuint refCount; + GLsizeiptr size; + GLenum usage; + GLboolean mapped; + GLenum internalFormat; + GLuint width; + GLuint height; + RGL::Vector textureReferences; + RGL::Vector attribSets; + void *platformBufferObject[]; +}; #define _RGL_CONTEXT_RED_MASK 0x01 #define _RGL_CONTEXT_GREEN_MASK 0x02 @@ -510,86 +501,86 @@ typedef struct #define ELEMENTS_IN_MATRIX 16 - typedef struct jsNameSpace - { - void** data; - void** firstFree; - unsigned long capacity; - } - jsNameSpace; +typedef struct jsNameSpace +{ + void** data; + void** firstFree; + unsigned long capacity; +} +jsNameSpace; - typedef void *( *jsTexNameSpaceCreateFunction )( void ); - typedef void( *jsTexNameSpaceDestroyFunction )( void * ); +typedef void *( *jsTexNameSpaceCreateFunction )( void ); +typedef void( *jsTexNameSpaceDestroyFunction )( void * ); - typedef struct jsTexNameSpace - { - void** data; - GLuint capacity; - jsTexNameSpaceCreateFunction create; - jsTexNameSpaceDestroyFunction destroy; - } - jsTexNameSpace; +typedef struct jsTexNameSpace +{ + void** data; + GLuint capacity; + jsTexNameSpaceCreateFunction create; + jsTexNameSpaceDestroyFunction destroy; +} +jsTexNameSpace; - struct PSGLcontext - { - GLenum error; - int MatrixMode; - jsMatrixStack ModelViewMatrixStack; - jsMatrixStack ProjectionMatrixStack; - GLfloat LocalToScreenMatrixf[ELEMENTS_IN_MATRIX]; - GLfloat InverseModelViewMatrixf[ELEMENTS_IN_MATRIX]; - GLboolean InverseModelViewValid; - GLfloat ScalingFactor; - jsViewPort ViewPort; - jsAttributeState defaultAttribs0; - jsAttributeState *attribs; - jsTexNameSpace attribSetNameSpace; - GLuint attribSetName; - GLboolean attribSetDirty; - jsColorRGBAf ClearColor; - jsColorRGBAf AccumClearColor; - GLboolean ShaderSRGBRemap; - GLboolean Blending; - GLboolean BlendingMrt[3]; - GLenum BlendEquationRGB; - GLenum BlendEquationAlpha; - GLenum BlendFactorSrcRGB; - GLenum BlendFactorDestRGB; - GLenum BlendFactorSrcAlpha; - GLenum BlendFactorDestAlpha; - jsColorRGBAf BlendColor; - GLboolean Dithering; - jsTexNameSpace textureNameSpace; - GLuint ActiveTexture; - GLuint CS_ActiveTexture; - jsTextureImageUnit TextureImageUnits[_RGL_MAX_TEXTURE_IMAGE_UNITS]; - jsTextureImageUnit* CurrentImageUnit; - jsTextureCoordsUnit TextureCoordsUnits[_RGL_MAX_TEXTURE_COORDS]; - jsTextureCoordsUnit* CurrentCoordsUnit; - jsTexture *VertexTextureImages[_RGL_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; - GLsizei packAlignment; - GLsizei unpackAlignment; - jsTexNameSpace bufferObjectNameSpace; - GLuint ArrayBuffer; - GLuint PixelUnpackBuffer; - GLuint TextureBuffer; - GLuint framebuffer; - jsTexNameSpace framebufferNameSpace; - GLboolean VertexProgram; - struct _CGprogram* BoundVertexProgram; - GLboolean FragmentProgram; - struct _CGprogram* BoundFragmentProgram; - GLboolean AllowTXPDemotion; - GLboolean VSync; - GLuint needValidate; - GLboolean everAttached; - CGerror RGLcgLastError; - CGerrorCallbackFunc RGLcgErrorCallbackFunction; - CGcontext RGLcgContextHead; - jsNameSpace cgContextNameSpace; - jsNameSpace cgProgramNameSpace; - jsNameSpace cgParameterNameSpace; - }; +struct PSGLcontext +{ + GLenum error; + int MatrixMode; + jsMatrixStack ModelViewMatrixStack; + jsMatrixStack ProjectionMatrixStack; + GLfloat LocalToScreenMatrixf[ELEMENTS_IN_MATRIX]; + GLfloat InverseModelViewMatrixf[ELEMENTS_IN_MATRIX]; + GLboolean InverseModelViewValid; + GLfloat ScalingFactor; + jsViewPort ViewPort; + jsAttributeState defaultAttribs0; + jsAttributeState *attribs; + jsTexNameSpace attribSetNameSpace; + GLuint attribSetName; + GLboolean attribSetDirty; + jsColorRGBAf ClearColor; + jsColorRGBAf AccumClearColor; + GLboolean ShaderSRGBRemap; + GLboolean Blending; + GLboolean BlendingMrt[3]; + GLenum BlendEquationRGB; + GLenum BlendEquationAlpha; + GLenum BlendFactorSrcRGB; + GLenum BlendFactorDestRGB; + GLenum BlendFactorSrcAlpha; + GLenum BlendFactorDestAlpha; + jsColorRGBAf BlendColor; + GLboolean Dithering; + jsTexNameSpace textureNameSpace; + GLuint ActiveTexture; + GLuint CS_ActiveTexture; + jsTextureImageUnit TextureImageUnits[_RGL_MAX_TEXTURE_IMAGE_UNITS]; + jsTextureImageUnit* CurrentImageUnit; + jsTextureCoordsUnit TextureCoordsUnits[_RGL_MAX_TEXTURE_COORDS]; + jsTextureCoordsUnit* CurrentCoordsUnit; + jsTexture *VertexTextureImages[_RGL_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; + GLsizei packAlignment; + GLsizei unpackAlignment; + jsTexNameSpace bufferObjectNameSpace; + GLuint ArrayBuffer; + GLuint PixelUnpackBuffer; + GLuint TextureBuffer; + GLuint framebuffer; + jsTexNameSpace framebufferNameSpace; + GLboolean VertexProgram; + struct _CGprogram* BoundVertexProgram; + GLboolean FragmentProgram; + struct _CGprogram* BoundFragmentProgram; + GLboolean AllowTXPDemotion; + GLboolean VSync; + GLuint needValidate; + GLboolean everAttached; + CGerror RGLcgLastError; + CGerrorCallbackFunc RGLcgErrorCallbackFunction; + CGcontext RGLcgContextHead; + jsNameSpace cgContextNameSpace; + jsNameSpace cgProgramNameSpace; + jsNameSpace cgParameterNameSpace; +}; #define jsContextGetMatrixStack(mContext, mMatrixMode, mMatrixStack) do \ {\ @@ -620,98 +611,81 @@ typedef struct #pragma warning ( pop ) #endif -#ifndef MSVC -#define MAX(A,B) ({ \ - __typeof__(A) At=(A); \ - __typeof__(B) Bt=(B); \ - At>Bt?At:Bt; }) - -#define MIN(A,B) ({ \ - __typeof__(A) At=(A); \ - __typeof__(B) Bt=(B); \ - At(B)?(A):(B)) #define MIN(A,B) ((A)<(B)?(A):(B)) #define RGL_LIKELY(COND) (COND) #define RGL_UNLIKELY(COND) (COND) -#endif #define _RGL_ALLOC_FIRST_FIT 0 #define _RGL_ALLOC_BEST_FIT 1 - static inline float _RGLClampf( const float value ) - { - return MAX( MIN( value, 1.f ), 0.f ); - } +static inline float _RGLClampf( const float value ) +{ + return MAX( MIN( value, 1.f ), 0.f ); +} - static inline unsigned int endianSwapWord( unsigned int v ) - { - return ( v&0xff ) << 24 | ( v&0xff00 ) << 8 | - ( v&0xff0000 ) >> 8 | ( v&0xff000000 ) >> 24; - } +static inline unsigned int endianSwapWord( unsigned int v ) +{ + return ( v&0xff ) << 24 | ( v&0xff00 ) << 8 | + ( v&0xff0000 ) >> 8 | ( v&0xff000000 ) >> 24; +} - static inline int _RGLLog2( unsigned int i ) - { - int l = 0; - while ( i ) - { - ++l; - i >>= 1; - } - return l -1; - } +static inline int _RGLLog2( unsigned int i ) +{ + int l = 0; + while ( i ) + { + ++l; + i >>= 1; + } + return l -1; +} - static inline unsigned long _RGLPad( unsigned long x, unsigned long pad ) - { - return ( x + pad - 1 ) / pad*pad; - } +static inline unsigned long _RGLPad( unsigned long x, unsigned long pad ) +{ + return ( x + pad - 1 ) / pad*pad; +} - static inline char* _RGLPadPtr( const char* p, unsigned int pad ) - { - RGLintptr x = ( RGLintptr )p; - x = ( x + pad - 1 ) / pad * pad; - return ( char* )x; - } +static inline char* _RGLPadPtr( const char* p, unsigned int pad ) +{ + RGLintptr x = ( RGLintptr )p; + x = ( x + pad - 1 ) / pad * pad; + return ( char* )x; +} - typedef struct MemoryBlockManager_t_ - { - char *memory; - GLuint size; - GLuint minAlignment; - GLenum method; - GLuint *book; - GLint bookSize; - GLint bookAlloc; - } - MemoryBlockManager_t; +typedef struct MemoryBlockManager_t_ +{ + char *memory; + GLuint size; + GLuint minAlignment; + GLenum method; + GLuint *book; + GLint bookSize; + GLint bookAlloc; +} MemoryBlockManager_t; +typedef unsigned long jsName; - typedef unsigned long jsName; +void _RGLInitNameSpace( struct jsNameSpace * name ); +void _RGLFreeNameSpace( struct jsNameSpace * name ); +jsName _RGLCreateName( struct jsNameSpace * ns, void* object ); +unsigned int _RGLIsName( struct jsNameSpace* ns, jsName name ); +void _RGLEraseName( struct jsNameSpace* ns, jsName name ); - void _RGLInitNameSpace( struct jsNameSpace * name ); - void _RGLFreeNameSpace( struct jsNameSpace * name ); - jsName _RGLCreateName( struct jsNameSpace * ns, void* object ); - unsigned int _RGLIsName( struct jsNameSpace* ns, jsName name ); - void _RGLEraseName( struct jsNameSpace* ns, jsName name ); - static inline void * _RGLGetNamedValue( struct jsNameSpace* ns, jsName name ) - { - return ns->data[name - 1]; - } +static inline void * _RGLGetNamedValue( struct jsNameSpace* ns, jsName name ) +{ + return ns->data[name - 1]; +} - void _RGLTexNameSpaceInit( jsTexNameSpace *ns, jsTexNameSpaceCreateFunction create, jsTexNameSpaceDestroyFunction destroy ); - void _RGLTexNameSpaceFree( jsTexNameSpace *ns ); - void _RGLTexNameSpaceResetNames( jsTexNameSpace *ns ); - GLuint _RGLTexNameSpaceGetFree( jsTexNameSpace *ns ); - GLboolean _RGLTexNameSpaceCreateNameLazy( jsTexNameSpace *ns, GLuint name ); - GLboolean _RGLTexNameSpaceIsName( jsTexNameSpace *ns, GLuint name ); - void _RGLTexNameSpaceGenNames( jsTexNameSpace *ns, GLsizei n, GLuint *names ); - void _RGLTexNameSpaceDeleteNames( jsTexNameSpace *ns, GLsizei n, const GLuint *names ); - void _RGLTexNameSpaceReinit( jsTexNameSpace * saved, jsTexNameSpace * active ); +void _RGLTexNameSpaceInit( jsTexNameSpace *ns, jsTexNameSpaceCreateFunction create, jsTexNameSpaceDestroyFunction destroy ); +void _RGLTexNameSpaceFree( jsTexNameSpace *ns ); +void _RGLTexNameSpaceResetNames( jsTexNameSpace *ns ); +GLuint _RGLTexNameSpaceGetFree( jsTexNameSpace *ns ); +GLboolean _RGLTexNameSpaceCreateNameLazy( jsTexNameSpace *ns, GLuint name ); +GLboolean _RGLTexNameSpaceIsName( jsTexNameSpace *ns, GLuint name ); +void _RGLTexNameSpaceGenNames( jsTexNameSpace *ns, GLsizei n, GLuint *names ); +void _RGLTexNameSpaceDeleteNames( jsTexNameSpace *ns, GLsizei n, const GLuint *names ); +void _RGLTexNameSpaceReinit( jsTexNameSpace * saved, jsTexNameSpace * active ); #define RGL_MEMORY_ALLOC_ERROR 0 @@ -749,62 +723,63 @@ typedef struct typedef struct GmmFixedAllocData { - char **ppBlockList[2]; - uint16_t **ppFreeBlockList[2]; - uint16_t *pBlocksUsed[2]; - uint16_t BlockListCount[2]; -}GmmFixedAllocData; + char **ppBlockList[2]; + uint16_t **ppFreeBlockList[2]; + uint16_t *pBlocksUsed[2]; + uint16_t BlockListCount[2]; +} GmmFixedAllocData; typedef struct GmmBaseBlock { - uint8_t isTile; - uint8_t isMain; - uint32_t address; - uint32_t size; -}GmmBaseBlock; + uint8_t isTile; + uint8_t isMain; + uint32_t address; + uint32_t size; +} GmmBaseBlock; typedef struct GmmBlock { - GmmBaseBlock base; - struct GmmBlock *pPrev; - struct GmmBlock *pNext; - uint8_t isPinned; - struct GmmBlock *pPrevFree; - struct GmmBlock *pNextFree; - uint32_t fence; -}GmmBlock; + GmmBaseBlock base; + struct GmmBlock *pPrev; + struct GmmBlock *pNext; + uint8_t isPinned; + struct GmmBlock *pPrevFree; + struct GmmBlock *pNextFree; + uint32_t fence; +} GmmBlock; typedef struct GmmTileBlock { - GmmBaseBlock base; - struct GmmTileBlock *pPrev; - struct GmmTileBlock *pNext; + GmmBaseBlock base; + struct GmmTileBlock *pPrev; + struct GmmTileBlock *pNext; - uint32_t tileTag; - void *pData; -}GmmTileBlock; + uint32_t tileTag; + void *pData; +} GmmTileBlock; -typedef struct GmmAllocator{ - uint32_t memoryBase; +typedef struct GmmAllocator +{ + uint32_t memoryBase; - uint32_t startAddress; - uint32_t size; - uint32_t freeAddress; + uint32_t startAddress; + uint32_t size; + uint32_t freeAddress; - GmmBlock *pHead; - GmmBlock *pTail; - GmmBlock *pSweepHead; - uint32_t freedSinceSweep; - uint32_t tileStartAddress; - uint32_t tileSize; - GmmTileBlock *pTileHead; - GmmTileBlock *pTileTail; - GmmBlock *pPendingFreeHead; - GmmBlock *pPendingFreeTail; - GmmBlock *pFreeHead[GMM_NUM_FREE_BINS]; - GmmBlock *pFreeTail[GMM_NUM_FREE_BINS]; - uint32_t totalSize; -}GmmAllocator; + GmmBlock *pHead; + GmmBlock *pTail; + GmmBlock *pSweepHead; + uint32_t freedSinceSweep; + uint32_t tileStartAddress; + uint32_t tileSize; + GmmTileBlock *pTileHead; + GmmTileBlock *pTileTail; + GmmBlock *pPendingFreeHead; + GmmBlock *pPendingFreeTail; + GmmBlock *pFreeHead[GMM_NUM_FREE_BINS]; + GmmBlock *pFreeTail[GMM_NUM_FREE_BINS]; + uint32_t totalSize; +} GmmAllocator; uint32_t gmmInit( const void *localMemoryBase, @@ -876,73 +851,73 @@ void gmmSetTileAttrib( typedef struct PSGLinitOptions { - GLuint enable; - int errorConsole; - GLuint fifoSize; - GLuint hostMemorySize; + GLuint enable; + int errorConsole; + GLuint fifoSize; + GLuint hostMemorySize; } PSGLinitOptions; struct RGLSemaphore { - GLuint val; - GLuint pad0; - GLuint pad1; - GLuint pad2; + GLuint val; + GLuint pad0; + GLuint pad1; + GLuint pad2; }; struct RGLSemaphoreMemory { - RGLSemaphore userSemaphores[256]; + RGLSemaphore userSemaphores[256]; }; struct RGLResource { - char *localAddress; - GLuint localSize; - GLuint MemoryClock; - GLuint GraphicsClock; - char * hostMemoryBase; - GLuint hostMemorySize; - GLuint hostMemoryReserved; - unsigned long dmaPushBufferOffset; - char * dmaPushBuffer; - GLuint dmaPushBufferSize; - void* dmaControl; - RGLSemaphoreMemory *semaphores; + char *localAddress; + GLuint localSize; + GLuint MemoryClock; + GLuint GraphicsClock; + char * hostMemoryBase; + GLuint hostMemorySize; + GLuint hostMemoryReserved; + unsigned long dmaPushBufferOffset; + char * dmaPushBuffer; + GLuint dmaPushBufferSize; + void* dmaControl; + RGLSemaphoreMemory *semaphores; }; typedef volatile struct { - GLuint Ignored00[0x010]; - GLuint Put; - GLuint Get; - GLuint Reference; - GLuint Ignored01[0x1]; - GLuint SetReference; - GLuint TopLevelGet; - GLuint Ignored02[0x2]; - GLuint SetContextDmaSemaphore; - GLuint SetSemaphoreOffset; - GLuint SetSemaphoreAcquire; - GLuint SetSemaphoreRelease; - GLuint Ignored03[0x7e4]; + GLuint Ignored00[0x010]; + GLuint Put; + GLuint Get; + GLuint Reference; + GLuint Ignored01[0x1]; + GLuint SetReference; + GLuint TopLevelGet; + GLuint Ignored02[0x2]; + GLuint SetContextDmaSemaphore; + GLuint SetSemaphoreOffset; + GLuint SetSemaphoreAcquire; + GLuint SetSemaphoreRelease; + GLuint Ignored03[0x7e4]; } RGLControlDma; struct RGLFifo: public CellGcmContextData { - RGLControlDma *dmaControl; - uint32_t *dmaPushBufferBegin; - uint32_t *dmaPushBufferEnd; - GLuint fifoBlockSize; - unsigned long dmaPushBufferOffset; - GLuint dmaPushBufferSizeInWords; - uint32_t *lastPutWritten; - uint32_t *lastGetRead; - GLuint lastSWReferenceWritten; - GLuint lastSWReferenceFlushed; - GLuint lastHWReferenceRead; - uint32_t *dmaPushBufferGPU; - int spuid; + RGLControlDma *dmaControl; + uint32_t *dmaPushBufferBegin; + uint32_t *dmaPushBufferEnd; + GLuint fifoBlockSize; + unsigned long dmaPushBufferOffset; + GLuint dmaPushBufferSizeInWords; + uint32_t *lastPutWritten; + uint32_t *lastGetRead; + GLuint lastSWReferenceWritten; + GLuint lastSWReferenceFlushed; + GLuint lastHWReferenceRead; + uint32_t *dmaPushBufferGPU; + int spuid; }; typedef struct RGLRenderTarget RGLRenderTarget; @@ -952,44 +927,42 @@ typedef struct RGLInterpolantState RGLInterpolantState; struct RGLInterpolantState { - GLuint vertexProgramAttribMask; - GLuint fragmentProgramAttribMask; + GLuint vertexProgramAttribMask; + GLuint fragmentProgramAttribMask; }; struct RGLBlendState { - GLuint alphaFunc; - GLfloat alphaRef; + GLuint alphaFunc; + GLfloat alphaRef; }; struct RGLRenderTarget { - GLuint colorFormat; - GLuint colorBufferCount; - - GLuint yInverted; - - CellGcmSurface gcmRenderTarget; + GLuint colorFormat; + GLuint colorBufferCount; + GLuint yInverted; + CellGcmSurface gcmRenderTarget; }; struct RGLCachedState { - RGLBlendState blend; - RGLViewportState viewport; - RGLInterpolantState interpolant; + RGLBlendState blend; + RGLViewportState viewport; + RGLInterpolantState interpolant; }; struct RGLState { - char *localAddress; - void *hostMemoryBase; - GLuint hostMemorySize; - RGLSemaphoreMemory *semaphores; - RGLFifo fifo; - RGLRenderTarget renderTarget; - RGLCachedState state; - CellGcmConfig config; - GLuint labelValue; + char *localAddress; + void *hostMemoryBase; + GLuint hostMemorySize; + RGLSemaphoreMemory *semaphores; + RGLFifo fifo; + RGLRenderTarget renderTarget; + RGLCachedState state; + CellGcmConfig config; + GLuint labelValue; }; GLboolean _RGLInit( PSGLinitOptions* options, RGLResource *resource ); @@ -1002,99 +975,101 @@ void _RGLIncFenceRef( GLuint* ref ); typedef struct { - GLenum pool; - unsigned int bufferId; - unsigned int bufferSize; - unsigned int pitch; + GLenum pool; + unsigned int bufferId; + unsigned int bufferSize; + unsigned int pitch; - GLuint mapCount; - GLenum mapAccess; + GLuint mapCount; + GLenum mapAccess; } RGLBufferObject; void _RGLSetNativeCgVertexProgram( const void *header ); void _RGLSetNativeCgFragmentProgram( const void *header ); - GLboolean _RGLTryResizeTileRegion( GLuint address, GLuint size, void* data ); - void _RGLGetTileRegionInfo( void* data, GLuint *address, GLuint *size ); +GLboolean _RGLTryResizeTileRegion( GLuint address, GLuint size, void* data ); +void _RGLGetTileRegionInfo( void* data, GLuint *address, GLuint *size ); - static inline GLuint _RGLPlatformGetBitsPerPixel( GLenum internalFormat ) - { - switch ( internalFormat ) - { - case RGL_HILO8: - case RGL_RGB5_A1_SCE: - case RGL_RGB565_SCE: - return 16; - case RGL_ALPHA8: - return 8; - case RGL_RGBX8: - case RGL_RGBA8: - case RGL_ABGR8: - case RGL_ARGB8: - case RGL_BGRA8: - return 32; - default: - return 0; - } - } +static inline GLuint _RGLPlatformGetBitsPerPixel( GLenum internalFormat ) +{ + switch ( internalFormat ) + { + case RGL_HILO8: + case RGL_RGB5_A1_SCE: + case RGL_RGB565_SCE: + return 16; + case RGL_ALPHA8: + return 8; + case RGL_RGBX8: + case RGL_RGBA8: + case RGL_ABGR8: + case RGL_ARGB8: + case RGL_BGRA8: + return 32; + default: + return 0; + } +} - void static inline _RGLFifoGlViewport( GLint x, GLint y, GLsizei width, GLsizei height, GLclampf zNear = 0.0f, GLclampf zFar = 1.0f ) - { - RGLViewportState *vp = &_RGLState.state.viewport; - RGLRenderTarget *rt = &_RGLState.renderTarget; - GLint clipX0, clipX1, clipY0, clipY1; +void static inline _RGLFifoGlViewport( GLint x, GLint y, GLsizei width, GLsizei height, GLclampf zNear = 0.0f, GLclampf zFar = 1.0f ) +{ + RGLViewportState *vp = &_RGLState.state.viewport; + RGLRenderTarget *rt = &_RGLState.renderTarget; + GLint clipX0, clipX1, clipY0, clipY1; - vp->x = x; - vp->y = y; - vp->w = width; - vp->h = height; + vp->x = x; + vp->y = y; + vp->w = width; + vp->h = height; - clipX0 = x; - clipX1 = x + width; - clipY0 = y; - clipY1 = y + height; + clipX0 = x; + clipX1 = x + width; + clipY0 = y; + clipY1 = y + height; - if ( rt->yInverted ) - { - clipY0 = rt->gcmRenderTarget.height - ( y + height ); - clipY1 = rt->gcmRenderTarget.height - y; - } + if ( rt->yInverted ) + { + clipY0 = rt->gcmRenderTarget.height - ( y + height ); + clipY1 = rt->gcmRenderTarget.height - y; + } - if ( clipX0 < 0 ) - clipX0 = 0; + if ( clipX0 < 0 ) + clipX0 = 0; - if ( clipY0 < 0 ) - clipY0 = 0; + if ( clipY0 < 0 ) + clipY0 = 0; - if ( clipX1 >= CELL_GCM_MAX_RT_DIMENSION ) - clipX1 = CELL_GCM_MAX_RT_DIMENSION; + if ( clipX1 >= CELL_GCM_MAX_RT_DIMENSION ) + clipX1 = CELL_GCM_MAX_RT_DIMENSION; - if ( clipY1 >= CELL_GCM_MAX_RT_DIMENSION ) - clipY1 = CELL_GCM_MAX_RT_DIMENSION; + if ( clipY1 >= CELL_GCM_MAX_RT_DIMENSION ) + clipY1 = CELL_GCM_MAX_RT_DIMENSION; - if (( clipX1 <= clipX0 ) || ( clipY1 <= clipY0 ) ) - clipX0 = clipY0 = clipX1 = clipY1 = 0; + if (( clipX1 <= clipX0 ) || ( clipY1 <= clipY0 ) ) + clipX0 = clipY0 = clipX1 = clipY1 = 0; - vp->xScale = width * 0.5f; - vp->xCenter = ( GLfloat )( x + vp->xScale + RGL_SUBPIXEL_ADJUST ); - if ( rt->yInverted ) - { - vp->yScale = height * -0.5f; - vp->yCenter = ( GLfloat )( rt->gcmRenderTarget.height - RGL_VIEWPORT_EPSILON - y + vp->yScale + RGL_SUBPIXEL_ADJUST ); - } - else - { - vp->yScale = height * 0.5f; - vp->yCenter = ( GLfloat )( y + vp->yScale + RGL_SUBPIXEL_ADJUST ); - } + vp->xScale = width * 0.5f; + vp->xCenter = ( GLfloat )( x + vp->xScale + RGL_SUBPIXEL_ADJUST ); + vp->yScale = height; - float scale[4] = { vp->xScale, vp->yScale, 0.5f, 0.0f }; - float offset[4] = { vp->xCenter, vp->yCenter, 0.5f, 0.0f }; + if ( rt->yInverted ) + { + vp->yScale *= -0.5f; + vp->yCenter = ( GLfloat )( rt->gcmRenderTarget.height - RGL_VIEWPORT_EPSILON - y + vp->yScale + RGL_SUBPIXEL_ADJUST ); + } + else + { + vp->yScale *= 0.5f; + vp->yCenter = ( GLfloat )( y + vp->yScale + RGL_SUBPIXEL_ADJUST ); + } - cellGcmSetViewportInline( &_RGLState.fifo, clipX0, clipY0, clipX1 - clipX0, - clipY1 - clipY0, zNear, zFar, scale, offset ); - } + float scale[4] = { vp->xScale, vp->yScale, 0.5f, 0.0f }; + float offset[4] = { vp->xCenter, vp->yCenter, 0.5f, 0.0f }; + + cellGcmSetViewportInline( &_RGLState.fifo, clipX0, clipY0, clipX1 - clipX0, + clipY1 - clipY0, zNear, zFar, scale, offset ); +} #define PSGL_DEVICE_PARAMETERS_COLOR_FORMAT 0x0001 #define PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT 0x0002 @@ -1114,35 +1089,35 @@ void _RGLSetNativeCgFragmentProgram( const void *header ); #define PSGL_VALIDATE_FRAMEBUFFER 0x00000001 #define PSGL_VALIDATE_TEXTURES_USED 0x00000002 #define PSGL_VALIDATE_VERTEX_PROGRAM 0x00000004 -#define PSGL_VALIDATE_VERTEX_CONSTANTS 0x00000008 -#define PSGL_VALIDATE_VERTEX_TEXTURES_USED 0x00000010 -#define PSGL_VALIDATE_FFX_VERTEX_PROGRAM 0x00000020 -#define PSGL_VALIDATE_FRAGMENT_PROGRAM 0x00000040 -#define PSGL_VALIDATE_FFX_FRAGMENT_PROGRAM 0x00000080 -#define PSGL_VALIDATE_VIEWPORT 0x00000200 -#define PSGL_VALIDATE_FACE_CULL 0x00010000 -#define PSGL_VALIDATE_BLENDING 0x00020000 -#define PSGL_VALIDATE_POINT_RASTER 0x00040000 -#define PSGL_VALIDATE_LINE_RASTER 0x00080000 -#define PSGL_VALIDATE_POLYGON_OFFSET 0x00100000 -#define PSGL_VALIDATE_SHADE_MODEL 0x00200000 -#define PSGL_VALIDATE_LOGIC_OP 0x00400000 -#define PSGL_VALIDATE_MULTISAMPLING 0x00800000 -#define PSGL_VALIDATE_POLYGON_MODE 0x01000000 -#define PSGL_VALIDATE_PRIMITIVE_RESTART 0x02000000 -#define PSGL_VALIDATE_CLIP_PLANES 0x04000000 -#define PSGL_VALIDATE_SHADER_SRGB_REMAP 0x08000000 -#define PSGL_VALIDATE_POINT_SPRITE 0x10000000 -#define PSGL_VALIDATE_TWO_SIDE_COLOR 0x20000000 -#define PSGL_VALIDATE_ALL 0x3FFFFFFF +#define PSGL_VALIDATE_VERTEX_CONSTANTS 0x00000008 +#define PSGL_VALIDATE_VERTEX_TEXTURES_USED 0x00000010 +#define PSGL_VALIDATE_FFX_VERTEX_PROGRAM 0x00000020 +#define PSGL_VALIDATE_FRAGMENT_PROGRAM 0x00000040 +#define PSGL_VALIDATE_FFX_FRAGMENT_PROGRAM 0x00000080 +#define PSGL_VALIDATE_VIEWPORT 0x00000200 +#define PSGL_VALIDATE_FACE_CULL 0x00010000 +#define PSGL_VALIDATE_BLENDING 0x00020000 +#define PSGL_VALIDATE_POINT_RASTER 0x00040000 +#define PSGL_VALIDATE_LINE_RASTER 0x00080000 +#define PSGL_VALIDATE_POLYGON_OFFSET 0x00100000 +#define PSGL_VALIDATE_SHADE_MODEL 0x00200000 +#define PSGL_VALIDATE_LOGIC_OP 0x00400000 +#define PSGL_VALIDATE_MULTISAMPLING 0x00800000 +#define PSGL_VALIDATE_POLYGON_MODE 0x01000000 +#define PSGL_VALIDATE_PRIMITIVE_RESTART 0x02000000 +#define PSGL_VALIDATE_CLIP_PLANES 0x04000000 +#define PSGL_VALIDATE_SHADER_SRGB_REMAP 0x08000000 +#define PSGL_VALIDATE_POINT_SPRITE 0x10000000 +#define PSGL_VALIDATE_TWO_SIDE_COLOR 0x20000000 +#define PSGL_VALIDATE_ALL 0x3FFFFFFF #define PSGL_INIT_PERSISTENT_MEMORY_SIZE 0x0004 -#define PSGL_INIT_TRANSIENT_MEMORY_SIZE 0x0008 +#define PSGL_INIT_TRANSIENT_MEMORY_SIZE 0x0008 #define PSGL_INIT_ERROR_CONSOLE 0x0010 -#define PSGL_INIT_FIFO_SIZE 0x0020 -#define PSGL_INIT_HOST_MEMORY_SIZE 0x0040 -#define PSGL_INIT_USE_PMQUERIES 0x0080 +#define PSGL_INIT_FIFO_SIZE 0x0020 +#define PSGL_INIT_HOST_MEMORY_SIZE 0x0040 +#define PSGL_INIT_USE_PMQUERIES 0x0080 extern void psglInit( PSGLinitOptions* options ); @@ -1163,9 +1138,6 @@ PSGLcontext* psglGetCurrentContext(); PSGLdevice* psglGetCurrentDevice(); void psglSwap( void ); -static inline void psglRescAdjustAspectRatio( const float horizontalScale, const float verticalScale ) - { cellRescAdjustAspectRatio( horizontalScale, verticalScale ); } - #ifdef __cplusplus } #endif diff --git a/console/rgl/ps3/vector b/console/rgl/ps3/vector index d375ac48a2..ee56f4b5fd 100644 --- a/console/rgl/ps3/vector +++ b/console/rgl/ps3/vector @@ -1,10 +1,6 @@ -// vector standard header - #ifndef _VECTOR_ #define _VECTOR_ -#define RGL_STD_VECTOR - #include #include diff --git a/console/salamander/main.c b/console/salamander/main.c index 8502316d09..cfd179e603 100644 --- a/console/salamander/main.c +++ b/console/salamander/main.c @@ -171,7 +171,7 @@ static void init_settings(void) char core_executable[1024]; #if defined(_XBOX360) snprintf(core_executable, sizeof(core_executable), "game:\\CORE.xex"); -#if defined(_XBOX1) +#elif defined(_XBOX1) snprintf(core_executable, sizeof(core_executable), "D:\\CORE.xbe"); #elif defined(__CELLOS_LV2__) snprintf(core_executable, sizeof(core_executable), "%s/CORE.SELF", LIBRETRO_DIR_PATH); diff --git a/driver.h b/driver.h index 3399e22196..3fdf20befe 100644 --- a/driver.h +++ b/driver.h @@ -159,6 +159,9 @@ typedef struct input_driver int16_t (*input_state)(void *data, const struct retro_keybind **retro_keybinds, unsigned port, unsigned device, unsigned index, unsigned id); bool (*key_pressed)(void *data, int key); void (*free)(void *data); +#ifdef RARCH_CONSOLE + void (*set_default_keybind_lut)(void); +#endif const char *ident; } input_driver_t; diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 44e1e55cbd..3d4b307cc2 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -26,7 +26,6 @@ #include "../gl_common.h" #include "../image.h" -#include "../../ps3/frontend/shared.h" #include "ps3_ctx.h" @@ -137,7 +136,7 @@ bool gfx_ctx_menu_init(void) glGenTextures(1, &gl->menu_texture_id); RARCH_LOG("Loading texture image for menu...\n"); - if (!texture_image_load(DEFAULT_MENU_BORDER_FILE, &menu_texture)) + if (!texture_image_load(default_paths.menu_border_file, &menu_texture)) { RARCH_ERR("Failed to load texture image for menu.\n"); return false; diff --git a/gfx/gl.c b/gfx/gl.c index a97cbb19ce..93494a1e94 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1065,9 +1065,9 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo RARCH_LOG("GL: Using resolution %ux%u\n", gl->win_width, gl->win_height); -#ifdef HAVE_CG_MENU +#if defined(HAVE_CG_MENU) && defined(RARCH_CONSOLE) RARCH_LOG("Initializing menu shader ...\n"); - gl_cg_set_menu_shader(DEFAULT_MENU_SHADER_FILE); + gl_cg_set_menu_shader(default_paths.menu_shader_file); #endif if (!gl_shader_init()) diff --git a/gfx/gles.c b/gfx/gles.c deleted file mode 100644 index 69e3527f9a..0000000000 --- a/gfx/gles.c +++ /dev/null @@ -1,1292 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2012 - Hans-Kristian Arntzen - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -/* Non-FF OpenGL 3 / OpenGL ES 2.0 driver */ - -#include "../driver.h" - -#include -#include "../libretro.h" -#include -#include -#include "../general.h" -#include - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "gl_common.h" -#include "gl_font.h" -#include "gfx_common.h" -#include "gfx_context.h" -#include "../compat/strl.h" - -#ifdef HAVE_SDL -#define NO_SDL_GLEXT -#include "context/sdl_ctx.h" -#include "../input/rarch_sdl_input.h" -#endif - -#ifdef HAVE_CG -#include "shader_cg.h" -#endif - -#ifdef HAVE_XML -#include "shader_glsl.h" -#endif - -extern const GLfloat vertexes_flipped[]; -extern const GLfloat white_color[]; - -// Used for the last pass when rendering to the back buffer. -const GLfloat vertexes_flipped[] = { - 0, 0, - 0, 1, - 1, 1, - 1, 0 -}; - -// Used when rendering to an FBO. -// Texture coords have to be aligned with vertex coordinates. -static const GLfloat vertexes[] = { - 0, 1, - 0, 0, - 1, 0, - 1, 1 -}; - -static const GLfloat tex_coords[] = { - 0, 1, - 0, 0, - 1, 0, - 1, 1 -}; - -const GLfloat white_color[] = { - 1, 1, 1, 1, - 1, 1, 1, 1, - 1, 1, 1, 1, - 1, 1, 1, 1, -}; - -const GLfloat *vertex_ptr = vertexes_flipped; -const GLfloat *default_vertex_ptr = vertexes_flipped; - -#ifdef HAVE_SDL -#define LOAD_SYM(sym) if (!p##sym) { SDL_SYM_WRAP(p##sym, #sym) } -#endif - -#ifdef HAVE_FBO -#if defined(_WIN32) && !defined(RARCH_CONSOLE) -static PFNGLGENFRAMEBUFFERSPROC pglGenFramebuffers = NULL; -static PFNGLBINDFRAMEBUFFERPROC pglBindFramebuffer = NULL; -static PFNGLFRAMEBUFFERTEXTURE2DPROC pglFramebufferTexture2D = NULL; -static PFNGLCHECKFRAMEBUFFERSTATUSPROC pglCheckFramebufferStatus = NULL; -static PFNGLDELETEFRAMEBUFFERSPROC pglDeleteFramebuffers = NULL; - -static bool load_fbo_proc(void) -{ - LOAD_SYM(glGenFramebuffers); - LOAD_SYM(glBindFramebuffer); - LOAD_SYM(glFramebufferTexture2D); - LOAD_SYM(glCheckFramebufferStatus); - LOAD_SYM(glDeleteFramebuffers); - - return pglGenFramebuffers && pglBindFramebuffer && pglFramebufferTexture2D && - pglCheckFramebufferStatus && pglDeleteFramebuffers; -} -#elif defined(HAVE_OPENGLES) -#define pglGenFramebuffers glGenFramebuffersOES -#define pglBindFramebuffer glBindFramebufferOES -#define pglFramebufferTexture2D glFramebufferTexture2DOES -#define pglCheckFramebufferStatus glCheckFramebufferStatusOES -#define pglDeleteFramebuffers glDeleteFramebuffersOES -#define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES -#define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT -#define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES -#define glOrtho glOrthof -static bool load_fbo_proc(void) { return true; } -#else -#define pglGenFramebuffers glGenFramebuffers -#define pglBindFramebuffer glBindFramebuffer -#define pglFramebufferTexture2D glFramebufferTexture2D -#define pglCheckFramebufferStatus glCheckFramebufferStatus -#define pglDeleteFramebuffers glDeleteFramebuffers -static bool load_fbo_proc(void) { return true; } -#endif -#endif - -#if (defined(HAVE_XML) || defined(HAVE_CG)) && defined(_WIN32) -PFNGLCLIENTACTIVETEXTUREPROC pglClientActiveTexture = NULL; -PFNGLACTIVETEXTUREPROC pglActiveTexture = NULL; -static inline bool load_gl_proc(void) -{ - LOAD_SYM(glClientActiveTexture); - LOAD_SYM(glActiveTexture); - return pglClientActiveTexture && pglActiveTexture; -} -#else -static inline bool load_gl_proc(void) { return true; } -#endif - -////////////////// Shaders -static bool gl_shader_init(void) -{ - switch (g_settings.video.shader_type) - { - case RARCH_SHADER_AUTO: - { - if (*g_settings.video.cg_shader_path && *g_settings.video.bsnes_shader_path) - RARCH_WARN("Both Cg and bSNES XML shader are defined in config file. Cg shader will be selected by default.\n"); - -#ifdef HAVE_CG - if (*g_settings.video.cg_shader_path) - return gl_cg_init(g_settings.video.cg_shader_path); -#endif - -#ifdef HAVE_XML - if (*g_settings.video.bsnes_shader_path) - return gl_glsl_init(g_settings.video.bsnes_shader_path); -#endif - break; - } - -#ifdef HAVE_CG - case RARCH_SHADER_CG: - return gl_cg_init(g_settings.video.cg_shader_path); -#endif - -#ifdef HAVE_XML - case RARCH_SHADER_BSNES: - return gl_glsl_init(g_settings.video.bsnes_shader_path); -#endif - - default: - break; - } - - return true; -} - -void gl_shader_use(unsigned index) -{ -#ifdef HAVE_CG - gl_cg_use(index); -#endif - -#ifdef HAVE_XML - gl_glsl_use(index); -#endif -} - -static inline void gl_shader_deinit(void) -{ -#ifdef HAVE_CG - gl_cg_deinit(); -#endif - -#ifdef HAVE_XML - gl_glsl_deinit(); -#endif -} - -static inline void gl_shader_set_proj_matrix(void) -{ -#ifdef HAVE_CG - gl_cg_set_proj_matrix(); -#endif - -#ifdef HAVE_XML - gl_glsl_set_proj_matrix(); -#endif -} - -static inline void gl_shader_set_params(unsigned width, unsigned height, - unsigned tex_width, unsigned tex_height, - unsigned out_width, unsigned out_height, - unsigned frame_count, - const struct gl_tex_info *info, - const struct gl_tex_info *prev_info, - const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt) -{ -#ifdef HAVE_CG - gl_cg_set_params(width, height, - tex_width, tex_height, - out_width, out_height, - frame_count, info, prev_info, fbo_info, fbo_info_cnt); -#endif - -#ifdef HAVE_XML - gl_glsl_set_params(width, height, - tex_width, tex_height, - out_width, out_height, - frame_count, info, prev_info, fbo_info, fbo_info_cnt); -#endif -} - -static unsigned gl_shader_num(void) -{ -#ifdef HAVE_CG - unsigned cg_num = gl_cg_num(); - if (cg_num) - return cg_num; -#endif - -#ifdef HAVE_XML - unsigned glsl_num = gl_glsl_num(); - if (glsl_num) - return glsl_num; -#endif - - return 0; -} - -static bool gl_shader_filter_type(unsigned index, bool *smooth) -{ - bool valid = false; - -#ifdef HAVE_CG - if (!valid) - valid = gl_cg_filter_type(index, smooth); -#endif - -#ifdef HAVE_XML - if (!valid) - valid = gl_glsl_filter_type(index, smooth); -#endif - - return valid; -} - -#ifdef HAVE_FBO -static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale) -{ - scale->valid = false; - -#ifdef HAVE_CG - if (!scale->valid) - gl_cg_shader_scale(index, scale); -#endif - -#ifdef HAVE_XML - if (!scale->valid) - gl_glsl_shader_scale(index, scale); -#endif -} -#endif -/////////////////// - - -#ifdef HAVE_FBO -static void gl_compute_fbo_geometry(gl_t *gl, unsigned width, unsigned height, - unsigned vp_width, unsigned vp_height); - -static void gl_create_fbo_textures(gl_t *gl) -{ - glGenTextures(gl->fbo_pass, gl->fbo_texture); - - GLuint base_filt = g_settings.video.second_pass_smooth ? GL_LINEAR : GL_NEAREST; - for (int i = 0; i < gl->fbo_pass; i++) - { - glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - - GLuint filter_type = base_filt; - bool smooth = false; - if (gl_shader_filter_type(i + 2, &smooth)) - filter_type = smooth ? GL_LINEAR : GL_NEAREST; - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_type); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type); - - glTexImage2D(GL_TEXTURE_2D, - 0, RARCH_GL_INTERNAL_FORMAT, gl->fbo_rect[i].width, gl->fbo_rect[i].height, - 0, RARCH_GL_TEXTURE_TYPE, - RARCH_GL_FORMAT32, NULL); - } - - glBindTexture(GL_TEXTURE_2D, 0); -} - -static bool gl_create_fbo_targets(gl_t *gl) -{ - pglGenFramebuffers(gl->fbo_pass, gl->fbo); - for (int i = 0; i < gl->fbo_pass; i++) - { - pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[i]); - pglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gl->fbo_texture[i], 0); - - GLenum status = pglCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) - goto error; - } - - return true; - -error: - pglDeleteFramebuffers(gl->fbo_pass, gl->fbo); - RARCH_ERR("Failed to set up frame buffer objects. Multi-pass shading will not work.\n"); - return false; -} - -void gl_deinit_fbo(gl_t *gl) -{ - if (gl->fbo_inited) - { - glDeleteTextures(gl->fbo_pass, gl->fbo_texture); - pglDeleteFramebuffers(gl->fbo_pass, gl->fbo); - memset(gl->fbo_texture, 0, sizeof(gl->fbo_texture)); - memset(gl->fbo, 0, sizeof(gl->fbo)); - gl->fbo_inited = false; - gl->render_to_tex = false; - gl->fbo_pass = 0; - } -} - -void gl_init_fbo(gl_t *gl, unsigned width, unsigned height) -{ - // No need to use FBOs. - if (!g_settings.video.render_to_texture && gl_shader_num() == 0) - return; - - struct gl_fbo_scale scale, scale_last; - gl_shader_scale(1, &scale); - gl_shader_scale(gl_shader_num(), &scale_last); - - // No need to use FBOs. - if (gl_shader_num() == 1 && !scale.valid && !g_settings.video.render_to_texture) - return; - - if (!load_fbo_proc()) - { - RARCH_ERR("Failed to locate FBO functions. Won't be able to use render-to-texture.\n"); - return; - } - - gl->fbo_pass = gl_shader_num() - 1; - if (scale_last.valid) - gl->fbo_pass++; - - if (gl->fbo_pass <= 0) - gl->fbo_pass = 1; - - if (!scale.valid) - { - scale.scale_x = g_settings.video.fbo_scale_x; - scale.scale_y = g_settings.video.fbo_scale_y; - scale.type_x = scale.type_y = RARCH_SCALE_INPUT; - scale.valid = true; - } - - gl->fbo_scale[0] = scale; - - for (int i = 1; i < gl->fbo_pass; i++) - { - gl_shader_scale(i + 1, &gl->fbo_scale[i]); - - if (!gl->fbo_scale[i].valid) - { - gl->fbo_scale[i].scale_x = gl->fbo_scale[i].scale_y = 1.0f; - gl->fbo_scale[i].type_x = gl->fbo_scale[i].type_y = RARCH_SCALE_INPUT; - gl->fbo_scale[i].valid = true; - } - } - - gl_compute_fbo_geometry(gl, width, height, gl->win_width, gl->win_height); - - for (int i = 0; i < gl->fbo_pass; i++) - { - gl->fbo_rect[i].width = next_pow2(gl->fbo_rect[i].img_width); - gl->fbo_rect[i].height = next_pow2(gl->fbo_rect[i].img_height); - RARCH_LOG("Creating FBO %d @ %ux%u\n", i, gl->fbo_rect[i].width, gl->fbo_rect[i].height); - } - - gl_create_fbo_textures(gl); - if (!gl_create_fbo_targets(gl)) - { - glDeleteTextures(gl->fbo_pass, gl->fbo_texture); - return; - } - - gl->fbo_inited = true; -} -#endif - -//////////// - -void gl_set_projection(gl_t *gl, struct gl_ortho *ortho, bool allow_rotate) -{ -#ifdef RARCH_CONSOLE - if (g_console.overscan_enable) - { - ortho->left = -g_console.overscan_amount / 2; - ortho->right = 1 + g_console.overscan_amount / 2; - ortho->bottom = -g_console.overscan_amount / 2; - } -#endif - - gfx_ctx_set_projection(gl, ortho, allow_rotate); - gl_shader_set_proj_matrix(); -} - -void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate) -{ - unsigned x = 0, y = 0; - struct gl_ortho ortho = {0, 1, 0, 1, -1, 1}; - - if (gl->keep_aspect && !force_full) - { - float desired_aspect = g_settings.video.aspect_ratio; - float device_aspect = (float)width / height; - float delta; - -#ifdef RARCH_CONSOLE - if (g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM) - { - x = g_console.viewports.custom_vp.x; - y = g_console.viewports.custom_vp.y; - width = g_console.viewports.custom_vp.width; - height = g_console.viewports.custom_vp.height; - } - else -#endif - { - if (fabs(device_aspect - desired_aspect) < 0.0001) - { - // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), - // assume they are actually equal. - } - else if (device_aspect > desired_aspect) - { - delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; - x = (unsigned)(width * (0.5 - delta)); - width = (unsigned)(2.0 * width * delta); - } - else - { - delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5; - y = (unsigned)(height * (0.5 - delta)); - height = (unsigned)(2.0 * height * delta); - } - } - } - - glViewport(x, y, width, height); - - gl_set_projection(gl, &ortho, allow_rotate); - - gl->vp_width = width; - gl->vp_height = height; - - // Set last backbuffer viewport. - if (!force_full) - { - gl->vp_out_width = width; - gl->vp_out_height = height; - } - - //RARCH_LOG("Setting viewport @ %ux%u\n", width, height); -} - -static void gl_set_rotation(void *data, unsigned rotation) -{ - struct gl_ortho ortho = {0, 1, 0, 1, -1, 1}; - - gl_t *gl = (gl_t*)driver.video_data; - gl->rotation = 90 * rotation; - gl_set_projection(gl, &ortho, true); -} - -static inline void set_lut_texture_coords(const GLfloat *coords) -{ -#if defined(HAVE_XML) || defined(HAVE_CG) - // For texture images. - pglClientActiveTexture(GL_TEXTURE1); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, 0, coords); - pglClientActiveTexture(GL_TEXTURE0); -#else - (void)coords; -#endif -} - -static inline void set_texture_coords(GLfloat *coords, GLfloat xamt, GLfloat yamt) -{ - coords[1] = yamt; - coords[4] = xamt; - coords[6] = xamt; - coords[7] = yamt; -} - -#ifdef HAVE_FBO -static void gl_compute_fbo_geometry(gl_t *gl, unsigned width, unsigned height, - unsigned vp_width, unsigned vp_height) -{ - unsigned last_width = width; - unsigned last_height = height; - unsigned last_max_width = gl->tex_w; - unsigned last_max_height = gl->tex_h; - // Calculate viewports for FBOs. - for (int i = 0; i < gl->fbo_pass; i++) - { - switch (gl->fbo_scale[i].type_x) - { - case RARCH_SCALE_INPUT: - gl->fbo_rect[i].img_width = last_width * gl->fbo_scale[i].scale_x; - gl->fbo_rect[i].max_img_width = last_max_width * gl->fbo_scale[i].scale_x; - break; - - case RARCH_SCALE_ABSOLUTE: - gl->fbo_rect[i].img_width = gl->fbo_rect[i].max_img_width = gl->fbo_scale[i].abs_x; - break; - - case RARCH_SCALE_VIEWPORT: - gl->fbo_rect[i].img_width = gl->fbo_rect[i].max_img_width = gl->fbo_scale[i].scale_x * vp_width; - break; - - default: - break; - } - - switch (gl->fbo_scale[i].type_y) - { - case RARCH_SCALE_INPUT: - gl->fbo_rect[i].img_height = last_height * gl->fbo_scale[i].scale_y; - gl->fbo_rect[i].max_img_height = last_max_height * gl->fbo_scale[i].scale_y; - break; - - case RARCH_SCALE_ABSOLUTE: - gl->fbo_rect[i].img_height = gl->fbo_rect[i].max_img_height = gl->fbo_scale[i].abs_y; - break; - - case RARCH_SCALE_VIEWPORT: - gl->fbo_rect[i].img_height = gl->fbo_rect[i].max_img_height = gl->fbo_scale[i].scale_y * vp_height; - break; - - default: - break; - } - - last_width = gl->fbo_rect[i].img_width; - last_height = gl->fbo_rect[i].img_height; - last_max_width = gl->fbo_rect[i].max_img_width; - last_max_height = gl->fbo_rect[i].max_img_height; - } -} - -static inline void gl_start_frame_fbo(gl_t *gl) -{ - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[0]); - gl->render_to_tex = true; - gl_set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true, false); - - // Need to preserve the "flipped" state when in FBO as well to have - // consistent texture coordinates. - // We will "flip" it in place on last pass. - if (gl->render_to_tex) - glVertexPointer(2, GL_FLOAT, 0, vertexes); -} - -static void gl_check_fbo_dimensions(gl_t *gl) -{ - // Check if we have to recreate our FBO textures. - for (int i = 0; i < gl->fbo_pass; i++) - { - // Check proactively since we might suddently get sizes of tex_w width or tex_h height. - if (gl->fbo_rect[i].max_img_width > gl->fbo_rect[i].width || - gl->fbo_rect[i].max_img_height > gl->fbo_rect[i].height) - { - unsigned img_width = gl->fbo_rect[i].max_img_width; - unsigned img_height = gl->fbo_rect[i].max_img_height; - unsigned max = img_width > img_height ? img_width : img_height; - unsigned pow2_size = next_pow2(max); - gl->fbo_rect[i].width = gl->fbo_rect[i].height = pow2_size; - - pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[i]); - glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i]); - glTexImage2D(GL_TEXTURE_2D, - 0, RARCH_GL_INTERNAL_FORMAT, gl->fbo_rect[i].width, gl->fbo_rect[i].height, - 0, RARCH_GL_TEXTURE_TYPE, - RARCH_GL_FORMAT32, NULL); - - pglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gl->fbo_texture[i], 0); - - GLenum status = pglCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) - RARCH_WARN("Failed to reinit FBO texture.\n"); - - RARCH_LOG("Recreating FBO texture #%d: %ux%u\n", i, gl->fbo_rect[i].width, gl->fbo_rect[i].height); - } - } -} - -static void gl_frame_fbo(gl_t *gl, const struct gl_tex_info *tex_info) -{ - GLfloat fbo_tex_coords[8] = {0.0f}; - - // Render the rest of our passes. - glTexCoordPointer(2, GL_FLOAT, 0, fbo_tex_coords); - - // It's kinda handy ... :) - const struct gl_fbo_rect *prev_rect; - const struct gl_fbo_rect *rect; - struct gl_tex_info *fbo_info; - - struct gl_tex_info fbo_tex_info[MAX_SHADERS]; - unsigned fbo_tex_info_cnt = 0; - - // Calculate viewports, texture coordinates etc, and render all passes from FBOs, to another FBO. - for (int i = 1; i < gl->fbo_pass; i++) - { - prev_rect = &gl->fbo_rect[i - 1]; - rect = &gl->fbo_rect[i]; - fbo_info = &fbo_tex_info[i - 1]; - - GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; - GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; - - set_texture_coords(fbo_tex_coords, xamt, yamt); - - fbo_info->tex = gl->fbo_texture[i - 1]; - fbo_info->input_size[0] = prev_rect->img_width; - fbo_info->input_size[1] = prev_rect->img_height; - fbo_info->tex_size[0] = prev_rect->width; - fbo_info->tex_size[1] = prev_rect->height; - memcpy(fbo_info->coord, fbo_tex_coords, sizeof(fbo_tex_coords)); - - pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[i]); - gl_shader_use(i + 1); - glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i - 1]); - - glClear(GL_COLOR_BUFFER_BIT); - - // Render to FBO with certain size. - gl_set_viewport(gl, rect->img_width, rect->img_height, true, false); - gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, - prev_rect->width, prev_rect->height, - gl->vp_width, gl->vp_height, gl->frame_count, - tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); - - glDrawArrays(GL_QUADS, 0, 4); - - fbo_tex_info_cnt++; - } - - // Render our last FBO texture directly to screen. - prev_rect = &gl->fbo_rect[gl->fbo_pass - 1]; - GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; - GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; - - set_texture_coords(fbo_tex_coords, xamt, yamt); - - // Render our FBO texture to back buffer. - pglBindFramebuffer(GL_FRAMEBUFFER, 0); - gl_shader_use(gl->fbo_pass + 1); - - glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]); - - glClear(GL_COLOR_BUFFER_BIT); - gl->render_to_tex = false; - gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); - gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, - prev_rect->width, prev_rect->height, - gl->vp_width, gl->vp_height, gl->frame_count, - tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); - - glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); - glDrawArrays(GL_QUADS, 0, 4); - - glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); -} -#endif - -static void gl_update_resize(gl_t *gl) -{ -#ifdef HAVE_FBO - if (!gl->render_to_tex) - gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); - else - { - gl_check_fbo_dimensions(gl); - - // Go back to what we're supposed to do, render to FBO #0 :D - gl_start_frame_fbo(gl); - } -#else - gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); -#endif -} - -static void gl_update_input_size(gl_t *gl, unsigned width, unsigned height, unsigned pitch) -{ - // Res change. Need to clear out texture. - if ((width != gl->last_width[gl->tex_index] || height != gl->last_height[gl->tex_index]) && gl->empty_buf) - { - gl->last_width[gl->tex_index] = width; - gl->last_height[gl->tex_index] = height; - - glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(pitch)); - glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->tex_w); - - glTexSubImage2D(GL_TEXTURE_2D, - 0, 0, 0, gl->tex_w, gl->tex_h, gl->texture_type, - gl->texture_fmt, gl->empty_buf); - - GLfloat xamt = (GLfloat)width / gl->tex_w; - GLfloat yamt = (GLfloat)height / gl->tex_h; - - set_texture_coords(gl->tex_coords, xamt, yamt); - } - // We might have used different texture coordinates last frame. Edge case if resolution changes very rapidly. - else if (width != gl->last_width[(gl->tex_index - 1) & TEXTURES_MASK] || - height != gl->last_height[(gl->tex_index - 1) & TEXTURES_MASK]) - { - GLfloat xamt = (GLfloat)width / gl->tex_w; - GLfloat yamt = (GLfloat)height / gl->tex_h; - set_texture_coords(gl->tex_coords, xamt, yamt); - } -} - -static inline void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) -{ - glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / gl->base_size); - glTexSubImage2D(GL_TEXTURE_2D, - 0, 0, 0, width, height, gl->texture_type, - gl->texture_fmt, frame); -} - -static void gl_init_textures(gl_t *gl) -{ - glGenTextures(TEXTURES, gl->texture); - for (unsigned i = 0; i < TEXTURES; i++) - { - glBindTexture(GL_TEXTURE_2D, gl->texture[i]); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl->tex_filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter); - - glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->tex_w); - glTexImage2D(GL_TEXTURE_2D, - 0, RARCH_GL_INTERNAL_FORMAT, gl->tex_w, gl->tex_h, 0, gl->texture_type, - gl->texture_fmt, gl->empty_buf ? gl->empty_buf : NULL); - } - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); -} - -static inline void gl_next_texture_index(gl_t *gl, const struct gl_tex_info *tex_info) -{ - memmove(gl->prev_info + 1, gl->prev_info, sizeof(*tex_info) * (TEXTURES - 1)); - memcpy(&gl->prev_info[0], tex_info, sizeof(*tex_info)); - gl->tex_index = (gl->tex_index + 1) & TEXTURES_MASK; -} - -#ifdef HAVE_CG_MENU -static void gl_render_menu(gl_t *gl) -{ - gl_shader_use(RARCH_CG_MENU_SHADER_INDEX); - - gl_shader_set_params(gl->win_width, gl->win_height, gl->win_width, - gl->win_height, gl->win_width, gl->win_height, gl->frame_count, - NULL, NULL, NULL, 0); - - gl_set_viewport(gl, gl->win_width, gl->win_height, true, false); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id); - - glVertexPointer(2, GL_FLOAT, 0, default_vertex_ptr); - glDrawArrays(GL_QUADS, 0, 4); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); -} -#endif - -static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) -{ - gl_t *gl = (gl_t*)data; - - gl_shader_use(1); - gl->frame_count++; - - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - -#ifdef HAVE_FBO - // Render to texture in first pass. - if (gl->fbo_inited) - { - // Recompute FBO geometry. - // When width/height changes or window sizes change, we have to recalcuate geometry of our FBO. - gl_compute_fbo_geometry(gl, width, height, gl->vp_out_width, gl->vp_out_height); - gl_start_frame_fbo(gl); - } -#endif - - if (gl->should_resize) - { - gl->should_resize = false; - gfx_ctx_set_resize(gl->win_width, gl->win_height); - - // On resize, we might have to recreate our FBOs due to "Viewport" scale, and set a new viewport. - gl_update_resize(gl); - } - - if (frame) // Can be NULL for frame dupe / NULL render. - { - gl_update_input_size(gl, width, height, pitch); - gl_copy_frame(gl, frame, width, height, pitch); - } - - struct gl_tex_info tex_info = {0}; - tex_info.tex = gl->texture[gl->tex_index]; - tex_info.input_size[0] = width; - tex_info.input_size[1] = height; - tex_info.tex_size[0] = gl->tex_w; - tex_info.tex_size[1] = gl->tex_h; - - memcpy(tex_info.coord, gl->tex_coords, sizeof(gl->tex_coords)); - - glClear(GL_COLOR_BUFFER_BIT); - gl_shader_set_params(width, height, - gl->tex_w, gl->tex_h, - gl->vp_width, gl->vp_height, - gl->frame_count, - &tex_info, gl->prev_info, NULL, 0); - - glDrawArrays(GL_QUADS, 0, 4); - -#ifdef HAVE_FBO - if (gl->fbo_inited) - gl_frame_fbo(gl, &tex_info); -#endif - - gl_next_texture_index(gl, &tex_info); - - if (msg) - { - gl_render_msg(gl, msg); - gl_render_msg_post(gl); - } - -#ifndef RARCH_CONSOLE - gfx_ctx_update_window_title(false); -#endif - -#ifdef RARCH_CONSOLE - if (!gl->block_swap) -#endif - gfx_ctx_swap_buffers(); - -#ifdef HAVE_CG_MENU - if (gl->menu_render) - gl_render_menu(gl); -#endif - - return true; -} - -static void gl_free(void *data) -{ -#ifdef RARCH_CONSOLE - if (driver.video_data) - return; -#endif - - gl_t *gl = (gl_t*)data; - - gl_deinit_font(gl); - gl_shader_deinit(); - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDeleteTextures(TEXTURES, gl->texture); - -#ifdef HAVE_FBO - gl_deinit_fbo(gl); -#endif - - gfx_ctx_destroy(); - - if (gl->empty_buf) - free(gl->empty_buf); - - free(gl); -} - -static void gl_set_nonblock_state(void *data, bool state) -{ - gl_t *gl = (gl_t*)data; - if (gl->vsync) - { - RARCH_LOG("GL VSync => %s\n", state ? "off" : "on"); - gfx_ctx_set_swap_interval(state ? 0 : 1, true); - } -} - -static void *gl_init(const video_info_t *video, const input_driver_t **input, void **input_data) -{ -#ifdef _WIN32 - gfx_set_dwm(); -#endif - -#ifdef RARCH_CONSOLE - if (driver.video_data) - return driver.video_data; -#endif - - gl_t *gl = (gl_t*)calloc(1, sizeof(gl_t)); - if (!gl) - return NULL; - - if (!gfx_ctx_init()) - { - free(gl); - return NULL; - } - - unsigned full_x = 0, full_y = 0; - gfx_ctx_get_video_size(&full_x, &full_y); - RARCH_LOG("Detecting resolution %ux%u.\n", full_x, full_y); - - gfx_ctx_set_swap_interval(video->vsync ? 1 : 0, false); - - unsigned win_width = video->width; - unsigned win_height = video->height; - if (video->fullscreen && (win_width == 0) && (win_height == 0)) - { - win_width = full_x; - win_height = full_y; - } - - if (!gfx_ctx_set_video_mode(win_width, win_height, - g_settings.video.force_16bit ? 15 : 0, video->fullscreen)) - { - free(gl); - return NULL; - } - -#ifndef RARCH_CONSOLE - gfx_ctx_update_window_title(true); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -#endif - -#if (defined(HAVE_XML) || defined(HAVE_CG)) && defined(_WIN32) - // Win32 GL lib doesn't have some functions needed for XML shaders. - // Need to load dynamically :( - if (!load_gl_proc()) - { - gfx_ctx_destroy(); - free(gl); - return NULL; - } -#endif - - gl->vsync = video->vsync; - gl->fullscreen = video->fullscreen; - - gl->full_x = full_x; - gl->full_y = full_y; - gl->win_width = win_width; - gl->win_height = win_height; - - RARCH_LOG("GL: Using resolution %ux%u\n", gl->win_width, gl->win_height); - -#ifdef HAVE_CG_MENU - RARCH_LOG("Initializing menu shader ...\n"); - gl_cg_set_menu_shader(DEFAULT_MENU_SHADER_FILE); -#endif - - if (!gl_shader_init()) - { - RARCH_ERR("Shader init failed.\n"); - gfx_ctx_destroy(); - free(gl); - return NULL; - } - - RARCH_LOG("GL: Loaded %u program(s).\n", gl_shader_num()); - -#ifdef HAVE_FBO - // Set up render to texture. - gl_init_fbo(gl, RARCH_SCALE_BASE * video->input_scale, - RARCH_SCALE_BASE * video->input_scale); -#endif - - gl->keep_aspect = video->force_aspect; - - // Apparently need to set viewport for passes when we aren't using FBOs. - gl_shader_use(0); - gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); - gl_shader_use(1); - gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); - - bool force_smooth = false; - if (gl_shader_filter_type(1, &force_smooth)) - gl->tex_filter = force_smooth ? GL_LINEAR : GL_NEAREST; - else - gl->tex_filter = video->smooth ? GL_LINEAR : GL_NEAREST; - - gl->texture_type = RARCH_GL_TEXTURE_TYPE; - gl->texture_fmt = video->rgb32 ? RARCH_GL_FORMAT32 : RARCH_GL_FORMAT16; - gl->base_size = video->rgb32 ? sizeof(uint32_t) : sizeof(uint16_t); - - glEnable(GL_TEXTURE_2D); - glDisable(GL_DEPTH_TEST); - glDisable(GL_DITHER); - glClearColor(0, 0, 0, 1); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); - - memcpy(gl->tex_coords, tex_coords, sizeof(tex_coords)); - glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); - glColorPointer(4, GL_FLOAT, 0, white_color); - - set_lut_texture_coords(tex_coords); - - gl->tex_w = RARCH_SCALE_BASE * video->input_scale; - gl->tex_h = RARCH_SCALE_BASE * video->input_scale; - - // Empty buffer that we use to clear out the texture with on res change. - gl->empty_buf = calloc(gl->tex_w * gl->tex_h, gl->base_size); - gl_init_textures(gl); - - for (unsigned i = 0; i < TEXTURES; i++) - { - gl->last_width[i] = gl->tex_w; - gl->last_height[i] = gl->tex_h; - } - - for (unsigned i = 0; i < TEXTURES; i++) - { - gl->prev_info[i].tex = gl->texture[(gl->tex_index - (i + 1)) & TEXTURES_MASK]; - gl->prev_info[i].input_size[0] = gl->tex_w; - gl->prev_info[i].tex_size[0] = gl->tex_w; - gl->prev_info[i].input_size[1] = gl->tex_h; - gl->prev_info[i].tex_size[1] = gl->tex_h; - memcpy(gl->prev_info[i].coord, tex_coords, sizeof(tex_coords)); - } - - gfx_ctx_input_driver(input, input_data); - gl_init_font(gl, g_settings.video.font_path, g_settings.video.font_size); - - if (!gl_check_error()) - { - gfx_ctx_destroy(); - free(gl); - return NULL; - } - - return gl; -} - -static bool gl_alive(void *data) -{ - gl_t *gl = (gl_t*)data; - bool quit, resize; - - gfx_ctx_check_window(&quit, - &resize, &gl->win_width, &gl->win_height, - gl->frame_count); - - if (quit) - gl->quitting = true; - else if (resize) - gl->should_resize = true; - - return !gl->quitting; -} - -static bool gl_focus(void *data) -{ - (void)data; - return gfx_ctx_window_has_focus(); -} - -#ifdef HAVE_XML -static bool gl_xml_shader(void *data, const char *path) -{ - gl_t *gl = (gl_t*)data; - -#ifdef HAVE_FBO - gl_deinit_fbo(gl); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); -#endif - - gl_shader_deinit(); - - if (!gl_glsl_init(path)) - return false; - -#ifdef HAVE_FBO - // Set up render to texture again. - gl_init_fbo(gl, gl->tex_w, gl->tex_h); -#endif - - // Apparently need to set viewport for passes when we aren't using FBOs. - gl_shader_use(0); - gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); - gl_shader_use(1); - gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); - - return true; -} -#endif - -#ifndef HAVE_RGL -static void gl_viewport_size(void *data, unsigned *width, unsigned *height) -{ - (void)data; - - GLint vp[4]; - glGetIntegerv(GL_VIEWPORT, vp); - - *width = vp[2]; - *height = vp[3]; -} - -static bool gl_read_viewport(void *data, uint8_t *buffer) -{ - (void)data; - - GLint vp[4]; - glGetIntegerv(GL_VIEWPORT, vp); - - glPixelStorei(GL_PACK_ALIGNMENT, get_alignment(vp[2])); - glPixelStorei(GL_PACK_ROW_LENGTH, vp[2]); - - glReadPixels(vp[0], vp[1], - vp[2], vp[3], - GL_BGR, GL_UNSIGNED_BYTE, buffer); - - return true; -} -#endif - -#ifdef RARCH_CONSOLE -static void gl_start(void) -{ - video_info_t video_info = {0}; - - // Might have to supply correct values here. - video_info.vsync = g_settings.video.vsync; - video_info.force_aspect = false; - video_info.smooth = g_settings.video.smooth; - video_info.input_scale = 2; - video_info.fullscreen = true; - if (g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM) - { - video_info.width = g_console.viewports.custom_vp.width; - video_info.height = g_console.viewports.custom_vp.height; - } - driver.video_data = gl_init(&video_info, NULL, NULL); - -#ifdef HAVE_FBO - gfx_ctx_set_fbo(g_console.fbo_enabled); -#endif - - gfx_ctx_get_available_resolutions(); - -#ifdef HAVE_CG_MENU - gfx_ctx_menu_init(); -#endif -} - -static void gl_stop(void) -{ - void *data = driver.video_data; - driver.video_data = NULL; - gl_free(data); -} - -static void gl_restart(void) -{ -#ifdef HAVE_CG_MENU - bool should_menu_render; -#endif -#ifdef RARCH_CONSOLE - bool should_block_swap; -#endif - gl_t *gl = driver.video_data; - - if (!gl) - return; - -#ifdef RARCH_CONSOLE - should_block_swap = gl->block_swap; -#endif -#ifdef HAVE_CG_MENU - should_menu_render = gl->menu_render; -#endif - - gl_stop(); - gl_cg_invalidate_context(); - gl_start(); - -#ifdef HAVE_CG_MENU - gl->menu_render = should_menu_render; -#endif - - gl->frame_count = 0; - -#ifdef RARCH_CONSOLE - gl->block_swap = should_block_swap; - SET_TIMER_EXPIRATION(gl, 30); -#endif -} -#endif - -const video_driver_t video_gl = { - gl_init, - gl_frame, - gl_set_nonblock_state, - gl_alive, - gl_focus, - -#ifdef HAVE_XML - gl_xml_shader, -#else - NULL, -#endif - - gl_free, - "gles", - -#ifdef RARCH_CONSOLE - gl_start, - gl_stop, - gl_restart, -#endif - - gl_set_rotation, - -#ifndef HAVE_RGL - gl_viewport_size, - gl_read_viewport, -#else - NULL, - NULL, -#endif -}; - diff --git a/input/null.c b/input/null.c index a861b63d4b..4b228b4ad0 100644 --- a/input/null.c +++ b/input/null.c @@ -51,12 +51,17 @@ static void null_input_free(void *data) (void)data; } +static void null_set_default_keybind_lut(void) { } + const input_driver_t input_null = { null_input_init, null_input_poll, null_input_state, null_input_key_pressed, null_input_free, +#ifdef RARCH_CONSOLE + null_set_default_keybind_lut, +#endif "null", }; diff --git a/msvc/RetroArch-Xbox1/RetroArch-Xbox1.vcproj b/msvc/RetroArch-Xbox1/RetroArch-Xbox1.vcproj index 463b0679ef..8d947bc6c6 100644 --- a/msvc/RetroArch-Xbox1/RetroArch-Xbox1.vcproj +++ b/msvc/RetroArch-Xbox1/RetroArch-Xbox1.vcproj @@ -51,7 +51,9 @@ Name="VCPreLinkEventTool"/> + RemotePath="xe:\$(SolutionName)\CORE.xbe" + AdditionalFiles="..\..\xbox1\Media;roms;system" + ForceCopy="TRUE"/> + RemotePath="xe:\$(SolutionName)\CORE.xbe" + AdditionalFiles="..\..\xbox1\Media;roms;system" + ForceCopy="TRUE"/> + RemotePath="xe:\$(SolutionName)\CORE.xbe" + AdditionalFiles="..\..\xbox1\Media;roms;system" + ForceCopy="TRUE"/> + RemotePath="xe:\$(SolutionName)\CORE.xbe" + AdditionalFiles="..\..\xbox1\Media;roms;system" + ForceCopy="TRUE"/> @@ -265,7 +273,9 @@ Name="VCPreLinkEventTool"/> + RemotePath="xe:\$(SolutionName)\CORE.xbe" + AdditionalFiles="..\..\xbox1\Media;roms;system" + ForceCopy="TRUE"/> @@ -317,31 +327,31 @@ Name="Debug|Xbox"> + CompileAs="1"/> + CompileAs="1"/> + CompileAs="1"/> + CompileAs="1"/> + CompileAs="1"/> diff --git a/msvc/RetroArch-Xbox1/roms/.empty b/msvc/RetroArch-Xbox1/roms/.empty new file mode 100644 index 0000000000..e69de29bb2 diff --git a/msvc/RetroArch-Xbox1/system/.empty b/msvc/RetroArch-Xbox1/system/.empty new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ps3/frontend/main.c b/ps3/frontend/main.c index 1a14e5b68f..4cf8691ca9 100644 --- a/ps3/frontend/main.c +++ b/ps3/frontend/main.c @@ -46,39 +46,21 @@ #include "../../gfx/gl_common.h" #include "../../console/retroarch_console.h" +#include "../../console/retroarch_console_input.h" +#include "../../console/retroarch_config.h" #include "../../conf/config_file.h" #include "../../conf/config_file_macros.h" #include "../../general.h" #include "../../file.h" -#include "shared.h" - #include "menu.h" #define EMULATOR_CONTENT_DIR "SSNE10000" -#define EMULATOR_CORE_DIR "cores" #define CACHE_ID "ABCD12345" #define NP_POOL_SIZE (128*1024) static uint8_t np_pool[NP_POOL_SIZE]; -char systemDirPath[PATH_MAX]; -char usrDirPath[PATH_MAX]; -char DEFAULT_PRESET_FILE[PATH_MAX]; -char DEFAULT_BORDER_FILE[PATH_MAX]; -char DEFAULT_MENU_BORDER_FILE[PATH_MAX]; -char PRESETS_DIR_PATH[PATH_MAX]; -char INPUT_PRESETS_DIR_PATH[PATH_MAX]; -char BORDERS_DIR_PATH[PATH_MAX]; -char SHADERS_DIR_PATH[PATH_MAX]; -char LIBRETRO_DIR_PATH[PATH_MAX]; -char DEFAULT_SHADER_FILE[PATH_MAX]; -char DEFAULT_MENU_SHADER_FILE[PATH_MAX]; -char SYS_CONFIG_FILE[PATH_MAX]; -char EMULATOR_CORE_SELF[PATH_MAX]; -#ifdef HAVE_MULTIMAN -char MULTIMAN_EXECUTABLE[PATH_MAX]; -#endif int rarch_main(int argc, char *argv[]); @@ -86,62 +68,6 @@ SYS_PROCESS_PARAM(1001, 0x200000) #undef main -static void set_default_settings(void) -{ - // g_settings - strlcpy(g_settings.cheat_database, usrDirPath, sizeof(g_settings.cheat_database)); - g_settings.rewind_enable = false; - strlcpy(g_settings.video.cg_shader_path, DEFAULT_SHADER_FILE, sizeof(g_settings.video.cg_shader_path)); - g_settings.video.fbo_scale_x = 2.0f; - g_settings.video.fbo_scale_y = 2.0f; - g_settings.video.render_to_texture = true; - strlcpy(g_settings.video.second_pass_shader, DEFAULT_SHADER_FILE, sizeof(g_settings.video.second_pass_shader)); - g_settings.video.second_pass_smooth = true; - g_settings.video.smooth = true; - g_settings.video.vsync = true; - strlcpy(g_settings.cheat_database, usrDirPath, sizeof(g_settings.cheat_database)); - strlcpy(g_settings.system_directory, systemDirPath, sizeof(g_settings.system_directory)); - g_settings.video.msg_pos_x = 0.05f; - g_settings.video.msg_pos_y = 0.90f; - g_settings.video.aspect_ratio = -1.0f; - - rarch_input_set_controls_default(); - - // g_console - g_console.block_config_read = true; - g_console.frame_advance_enable = false; - g_console.emulator_initialized = 0; - g_console.screenshots_enable = true; - g_console.throttle_enable = true; - g_console.initialize_rarch_enable = false; - g_console.triple_buffering_enable = true; - g_console.default_savestate_dir_enable = false; - g_console.default_sram_dir_enable = false; - g_console.fbo_enabled = true; - g_console.mode_switch = MODE_MENU; - g_console.screen_orientation = ORIENTATION_NORMAL; - g_console.current_resolution_id = 0; - strlcpy(g_console.default_rom_startup_dir, "/", sizeof(g_console.default_rom_startup_dir)); - strlcpy(g_console.default_savestate_dir, usrDirPath, sizeof(g_console.default_savestate_dir)); - strlcpy(g_console.default_sram_dir, usrDirPath, sizeof(g_console.default_sram_dir)); - g_console.aspect_ratio_index = 0; - g_console.menu_font_size = 1.0f; - g_console.overscan_enable = false; - g_console.overscan_amount = 0.0f; - g_console.sound_mode = SOUND_MODE_NORMAL; - g_console.viewports.custom_vp.width = 0; - g_console.viewports.custom_vp.height = 0; - g_console.viewports.custom_vp.x = 0; - g_console.viewports.custom_vp.y = 0; - g_console.custom_bgm_enable = true; - g_console.info_msg_enable = true; - - // g_extern - g_extern.state_slot = 0; - g_extern.audio_data.mute = 0; - g_extern.verbose = true; -} - #ifdef HAVE_SYSUTILS static void callback_sysutil_exit(uint64_t status, uint64_t param, void *userdata) { @@ -195,16 +121,16 @@ static void get_environment_settings(int argc, char *argv[]) if(argc > 1) { /* launched from external launcher */ - strlcpy(MULTIMAN_EXECUTABLE, argv[2], sizeof(MULTIMAN_EXECUTABLE)); + strlcpy(default_paths.multiman_self_file, argv[2], sizeof(default_paths.multiman_self_file)); } else { /* not launched from external launcher, set default path */ - strlcpy(MULTIMAN_EXECUTABLE, "/dev_hdd0/game/BLES80608/USRDIR/RELOAD.SELF", - sizeof(MULTIMAN_EXECUTABLE)); + strlcpy(default_paths.multiman_self_file, "/dev_hdd0/game/BLES80608/USRDIR/RELOAD.SELF", + sizeof(default_paths.multiman_self_file)); } - if(path_file_exists(MULTIMAN_EXECUTABLE) && argc > 1 && path_file_exists(argv[1])) + if(path_file_exists(default_paths.multiman_self_file) && argc > 1 && path_file_exists(argv[1])) { g_console.external_launcher_support = EXTERN_LAUNCHER_MULTIMAN; RARCH_LOG("Started from multiMAN, auto-game start enabled.\n"); @@ -242,13 +168,13 @@ static void get_environment_settings(int argc, char *argv[]) if((get_attributes & CELL_GAME_ATTRIBUTE_APP_HOME) == CELL_GAME_ATTRIBUTE_APP_HOME) RARCH_LOG("RetroArch was launched from host machine (APP_HOME).\n"); - ret = cellGameContentPermit(contentInfoPath, usrDirPath); + ret = cellGameContentPermit(contentInfoPath, default_paths.port_dir); #ifdef HAVE_MULTIMAN if(g_console.external_launcher_support == EXTERN_LAUNCHER_MULTIMAN) { snprintf(contentInfoPath, sizeof(contentInfoPath), "/dev_hdd0/game/%s", EMULATOR_CONTENT_DIR); - snprintf(usrDirPath, sizeof(usrDirPath), "/dev_hdd0/game/%s/USRDIR", EMULATOR_CONTENT_DIR); + snprintf(default_paths.port_dir, sizeof(default_paths.port_dir), "/dev_hdd0/game/%s/USRDIR", EMULATOR_CONTENT_DIR); } #endif @@ -260,23 +186,30 @@ static void get_environment_settings(int argc, char *argv[]) { RARCH_LOG("cellGameContentPermit() OK.\n"); RARCH_LOG("contentInfoPath : [%s].\n", contentInfoPath); - RARCH_LOG("usrDirPath : [%s].\n", usrDirPath); + RARCH_LOG("usrDirPath : [%s].\n", default_paths.port_dir); } - snprintf(systemDirPath, sizeof(systemDirPath), "%s/%s/system", usrDirPath, EMULATOR_CORE_DIR); +#ifdef HAVE_HDD_CACHE_PARTITION + snprintf(default_paths.cache_dir, sizeof(default_paths.cache_dir), "/dev_hdd1/"); +#endif + snprintf(default_paths.core_dir, sizeof(default_paths.core_dir), "%s/cores", default_paths.port_dir); + snprintf(default_paths.executable_extension, sizeof(default_paths.executable_extension), ".SELF"); + snprintf(default_paths.savestate_dir, sizeof(default_paths.savestate_dir), "%s/savestates", default_paths.core_dir); + snprintf(default_paths.filesystem_root_dir, sizeof(default_paths.filesystem_root_dir), "/"); + snprintf(default_paths.sram_dir, sizeof(default_paths.sram_dir), "%s/sram", default_paths.core_dir); + + snprintf(default_paths.system_dir, sizeof(default_paths.system_dir), "%s/system", default_paths.core_dir); /* now we fill in all the variables */ - snprintf(DEFAULT_PRESET_FILE, sizeof(DEFAULT_PRESET_FILE), "%s/%s/presets/stock.conf", usrDirPath, EMULATOR_CORE_DIR); - snprintf(DEFAULT_BORDER_FILE, sizeof(DEFAULT_BORDER_FILE), "%s/%s/borders/Centered-1080p/mega-man-2.png", usrDirPath, EMULATOR_CORE_DIR); - snprintf(DEFAULT_MENU_BORDER_FILE, sizeof(DEFAULT_MENU_BORDER_FILE), "%s/%s/borders/Menu/main-menu.png", usrDirPath, EMULATOR_CORE_DIR); - snprintf(PRESETS_DIR_PATH, sizeof(PRESETS_DIR_PATH), "%s/%s/presets", usrDirPath, EMULATOR_CORE_DIR); - snprintf(INPUT_PRESETS_DIR_PATH, sizeof(INPUT_PRESETS_DIR_PATH), "%s/input", PRESETS_DIR_PATH); - snprintf(LIBRETRO_DIR_PATH, sizeof(LIBRETRO_DIR_PATH), "%s/%s", usrDirPath, EMULATOR_CORE_DIR); - snprintf(BORDERS_DIR_PATH, sizeof(BORDERS_DIR_PATH), "%s/%s/borders", usrDirPath, EMULATOR_CORE_DIR); - snprintf(SHADERS_DIR_PATH, sizeof(SHADERS_DIR_PATH), "%s/%s/shaders", usrDirPath, EMULATOR_CORE_DIR); - snprintf(DEFAULT_SHADER_FILE, sizeof(DEFAULT_SHADER_FILE), "%s/%s/shaders/stock.cg", usrDirPath, EMULATOR_CORE_DIR); - snprintf(DEFAULT_MENU_SHADER_FILE, sizeof(DEFAULT_MENU_SHADER_FILE), "%s/%s/shaders/Borders/Menu/border-only-rarch.cg", usrDirPath, EMULATOR_CORE_DIR); - snprintf(SYS_CONFIG_FILE, sizeof(SYS_CONFIG_FILE), "%s/retroarch.cfg", usrDirPath); + snprintf(default_paths.border_file, sizeof(default_paths.border_file), "%s/borders/Centered-1080p/mega-man-2.png", default_paths.core_dir); + snprintf(default_paths.menu_border_file, sizeof(default_paths.menu_border_file), "%s/borders/Menu/main-menu.png", default_paths.core_dir); + snprintf(default_paths.cgp_dir, sizeof(default_paths.cgp_dir), "%s/presets", default_paths.core_dir); + snprintf(default_paths.input_presets_dir, sizeof(default_paths.input_presets_dir), "%s/input", default_paths.cgp_dir); + snprintf(default_paths.border_dir, sizeof(default_paths.border_dir), "%s/borders", default_paths.core_dir); + snprintf(default_paths.shader_dir, sizeof(default_paths.shader_dir), "%s/shaders", default_paths.core_dir); + snprintf(default_paths.shader_file, sizeof(default_paths.shader_file), "%s/shaders/stock.cg", default_paths.core_dir); + snprintf(default_paths.menu_shader_file, sizeof(default_paths.menu_shader_file), "%s/shaders/Borders/Menu/border-only-rarch.cg", default_paths.core_dir); + snprintf(default_paths.config_file, sizeof(default_paths.config_file), "%s/retroarch.cfg", default_paths.port_dir); } g_extern.verbose = false; @@ -312,17 +245,11 @@ int main(int argc, char *argv[]) get_environment_settings(argc, argv); config_set_defaults(); + input_ps3.init(); - char full_path[1024], tmp_path[1024]; - snprintf(full_path, sizeof(full_path), "%s/%s/CORE.SELF", usrDirPath, EMULATOR_CORE_DIR); - snprintf(tmp_path, sizeof(tmp_path), "%s/%s/", usrDirPath, EMULATOR_CORE_DIR); - - bool find_libretro_file = rarch_configure_libretro_core(full_path, tmp_path, LIBRETRO_DIR_PATH, - SYS_CONFIG_FILE, ".SELF"); - - set_default_settings(); - rarch_config_load(SYS_CONFIG_FILE, LIBRETRO_DIR_PATH, ".SELF", find_libretro_file); - init_libretro_sym(); + char tmp_path[PATH_MAX]; + snprintf(tmp_path, sizeof(tmp_path), "%s/", default_paths.core_dir); + rarch_configure_libretro(&input_ps3, tmp_path, default_paths.executable_extension); #if(CELL_SDK_VERSION > 0x340000) if (g_console.screenshots_enable) @@ -347,7 +274,6 @@ int main(int argc, char *argv[]) video_gl.start(); - input_ps3.init(); #ifdef HAVE_OSKUTIL oskutil_init(&g_console.oskutil_handle, 0); @@ -367,7 +293,7 @@ int main(int argc, char *argv[]) RARCH_LOG("Started from multiMAN, will auto-start game.\n"); strlcpy(g_console.rom_path, argv[1], sizeof(g_console.rom_path)); rarch_settings_change(S_START_RARCH); - rarch_startup(SYS_CONFIG_FILE); + rarch_startup(default_paths.config_file); break; #endif default: @@ -390,7 +316,7 @@ begin_loop: else if(g_console.mode_switch == MODE_MENU) { menu_loop(); - rarch_startup(SYS_CONFIG_FILE); + rarch_startup(default_paths.config_file); } else goto begin_shutdown; @@ -398,8 +324,8 @@ begin_loop: goto begin_loop; begin_shutdown: - if(path_file_exists(SYS_CONFIG_FILE)) - rarch_config_save(SYS_CONFIG_FILE); + if(path_file_exists(default_paths.config_file)) + rarch_config_save(default_paths.config_file); if(g_console.emulator_initialized) rarch_main_deinit(); diff --git a/ps3/frontend/menu.c b/ps3/frontend/menu.c index c846f520e0..26c02f5052 100644 --- a/ps3/frontend/menu.c +++ b/ps3/frontend/menu.c @@ -27,6 +27,13 @@ #include "../../console/fileio/file_browser.h" #include "../../console/retroarch_console.h" +#include "../../console/retroarch_rom_ext.h" +#include "../../console/retroarch_console_input.h" +#include "../../console/retroarch_config.h" + +#ifdef HAVE_ZLIB +#include "../../console/retroarch_rzlib.h" +#endif #include "../../gfx/gl_common.h" #include "../../gfx/gl_font.h" @@ -34,7 +41,6 @@ #include "../../gfx/context/ps3_ctx.h" #include "../../gfx/shader_cg.h" -#include "shared.h" #include "../../file.h" #include "../../general.h" @@ -97,20 +103,20 @@ static void set_setting_label(menu * menu_obj, unsigned currentsetting) snprintf(items_generalsettings[currentsetting].setting_text, sizeof(items_generalsettings[currentsetting].setting_text), ps3_get_resolution_label(g_console.supported_resolutions[g_console.current_resolution_index])); break; case SETTING_SHADER_PRESETS: - set_setting_label_color(g_console.cgp_path == DEFAULT_PRESET_FILE, currentsetting); + set_setting_label_color(true, currentsetting); fill_pathname_base(fname, g_console.cgp_path, sizeof(fname)); snprintf(items_generalsettings[currentsetting].setting_text, sizeof(items_generalsettings[currentsetting].setting_text), fname); break; case SETTING_SHADER: fill_pathname_base(fname, g_settings.video.cg_shader_path, sizeof(fname)); snprintf(items_generalsettings[currentsetting].setting_text, sizeof(items_generalsettings[currentsetting].setting_text), "%s", fname); - set_setting_label_color(strcmp(g_settings.video.cg_shader_path,DEFAULT_SHADER_FILE) == 0, + set_setting_label_color(strcmp(g_settings.video.cg_shader_path, default_paths.shader_file) == 0, currentsetting); break; case SETTING_SHADER_2: fill_pathname_base(fname, g_settings.video.second_pass_shader, sizeof(fname)); snprintf(items_generalsettings[currentsetting].setting_text, sizeof(items_generalsettings[currentsetting].setting_text), "%s", fname); - set_setting_label_color(strcmp(g_settings.video.second_pass_shader,DEFAULT_SHADER_FILE) == 0, + set_setting_label_color(strcmp(g_settings.video.second_pass_shader, default_paths.shader_file) == 0, currentsetting); break; case SETTING_FONT_SIZE: @@ -239,19 +245,19 @@ static void set_setting_label(menu * menu_obj, unsigned currentsetting) snprintf(items_generalsettings[currentsetting].setting_text, sizeof(items_generalsettings[currentsetting].setting_text), g_console.default_rom_startup_dir); break; case SETTING_PATH_SAVESTATES_DIRECTORY: - set_setting_label_color(!(strcmp(g_console.default_savestate_dir, usrDirPath)), currentsetting); + set_setting_label_color(!(strcmp(g_console.default_savestate_dir, default_paths.port_dir)), currentsetting); snprintf(items_generalsettings[currentsetting].setting_text, sizeof(items_generalsettings[currentsetting].setting_text), g_console.default_savestate_dir); break; case SETTING_PATH_SRAM_DIRECTORY: - set_setting_label_color(!(strcmp(g_console.default_sram_dir, usrDirPath)), currentsetting); + set_setting_label_color(!(strcmp(g_console.default_sram_dir, default_paths.port_dir)), currentsetting); snprintf(items_generalsettings[currentsetting].setting_text, sizeof(items_generalsettings[currentsetting].setting_text), g_console.default_sram_dir); break; case SETTING_PATH_CHEATS: - set_setting_label_color(!(strcmp(g_settings.cheat_database, usrDirPath)), currentsetting); + set_setting_label_color(!(strcmp(g_settings.cheat_database, default_paths.port_dir)), currentsetting); snprintf(items_generalsettings[currentsetting].setting_text, sizeof(items_generalsettings[currentsetting].setting_text), g_settings.cheat_database); break; case SETTING_PATH_SYSTEM: - set_setting_label_color(!(strcmp(g_settings.system_directory, systemDirPath)), currentsetting); + set_setting_label_color(!(strcmp(g_settings.system_directory, default_paths.system_dir)), currentsetting); snprintf(items_generalsettings[currentsetting].setting_text, sizeof(items_generalsettings[currentsetting].setting_text), g_settings.system_directory); break; case SETTING_ENABLE_SRAM_PATH: @@ -394,7 +400,7 @@ static void menu_stack_push(unsigned stack_idx, unsigned menu_id) menuStack[stack_idx].category_id = CATEGORY_FILEBROWSER; menu_stack_refresh(items_generalsettings, stack_idx); strlcpy(tmpBrowser.extensions, "self|SELF|bin|BIN", sizeof(tmpBrowser.extensions)); - filebrowser_set_root(&tmpBrowser, LIBRETRO_DIR_PATH); + filebrowser_set_root(&tmpBrowser, default_paths.core_dir); filebrowser_iterate(&tmpBrowser, FILEBROWSER_ACTION_RESET); break; case PRESET_CHOICE: @@ -405,7 +411,7 @@ static void menu_stack_push(unsigned stack_idx, unsigned menu_id) menuStack[stack_idx].category_id = CATEGORY_FILEBROWSER; menu_stack_refresh(items_generalsettings, stack_idx); strlcpy(tmpBrowser.extensions, "cgp|CGP", sizeof(tmpBrowser.extensions)); - filebrowser_set_root(&tmpBrowser, PRESETS_DIR_PATH); + filebrowser_set_root(&tmpBrowser, default_paths.cgp_dir); filebrowser_iterate(&tmpBrowser, FILEBROWSER_ACTION_RESET); break; case INPUT_PRESET_CHOICE: @@ -416,7 +422,7 @@ static void menu_stack_push(unsigned stack_idx, unsigned menu_id) menuStack[stack_idx].category_id = CATEGORY_FILEBROWSER; menu_stack_refresh(items_generalsettings, stack_idx); strlcpy(tmpBrowser.extensions, "cfg|CFG", sizeof(tmpBrowser.extensions)); - filebrowser_set_root(&tmpBrowser, INPUT_PRESETS_DIR_PATH); + filebrowser_set_root(&tmpBrowser, default_paths.input_presets_dir); filebrowser_iterate(&tmpBrowser, FILEBROWSER_ACTION_RESET); break; case SHADER_CHOICE: @@ -427,7 +433,7 @@ static void menu_stack_push(unsigned stack_idx, unsigned menu_id) menuStack[stack_idx].category_id = CATEGORY_FILEBROWSER; menu_stack_refresh(items_generalsettings, stack_idx); strlcpy(tmpBrowser.extensions, "cg|CG", sizeof(tmpBrowser.extensions)); - filebrowser_set_root(&tmpBrowser, SHADERS_DIR_PATH); + filebrowser_set_root(&tmpBrowser, default_paths.shader_dir); filebrowser_iterate(&tmpBrowser, FILEBROWSER_ACTION_RESET); break; case BORDER_CHOICE: @@ -438,7 +444,7 @@ static void menu_stack_push(unsigned stack_idx, unsigned menu_id) menuStack[stack_idx].category_id = CATEGORY_FILEBROWSER; menu_stack_refresh(items_generalsettings, stack_idx); strlcpy(tmpBrowser.extensions, "png|PNG|jpg|JPG|JPEG|jpeg", sizeof(tmpBrowser.extensions)); - filebrowser_set_root(&tmpBrowser, BORDERS_DIR_PATH); + filebrowser_set_root(&tmpBrowser, default_paths.border_dir); filebrowser_iterate(&tmpBrowser, FILEBROWSER_ACTION_RESET); break; case PATH_DEFAULT_ROM_DIR_CHOICE: @@ -868,7 +874,7 @@ static void select_directory(void) } else if (input_state & (1 << RETRO_DEVICE_ID_JOYPAD_X)) { - strlcpy(path, usrDirPath, sizeof(path)); + strlcpy(path, default_paths.port_dir, sizeof(path)); switch(menu_id) { case PATH_SAVESTATES_DIR_CHOICE: @@ -952,10 +958,10 @@ static void rarch_filename_input_and_save (unsigned filename_type) case CONFIG_FILE: break; case SHADER_PRESET_FILE: - snprintf(filepath, sizeof(filepath), "%s/%s.cgp", PRESETS_DIR_PATH, filename_tmp); + snprintf(filepath, sizeof(filepath), "%s/%s.cgp", default_paths.cgp_dir, filename_tmp); break; case INPUT_PRESET_FILE: - snprintf(filepath, sizeof(filepath), "%s/%s.cfg", INPUT_PRESETS_DIR_PATH, filename_tmp); + snprintf(filepath, sizeof(filepath), "%s/%s.cfg", default_paths.input_presets_dir, filename_tmp); break; } @@ -1072,7 +1078,7 @@ static void producesettingentry(menu * menu_obj, unsigned switchvalue) if(input_state & (1 << RETRO_DEVICE_ID_JOYPAD_START)) { rarch_load_shader(1, NULL); - strlcpy(g_settings.video.cg_shader_path, DEFAULT_SHADER_FILE, sizeof(g_settings.video.cg_shader_path)); + strlcpy(g_settings.video.cg_shader_path, default_paths.shader_file, sizeof(g_settings.video.cg_shader_path)); menu_stack_refresh(items_generalsettings, menuStackindex); } break; @@ -1086,7 +1092,7 @@ static void producesettingentry(menu * menu_obj, unsigned switchvalue) if(input_state & (1 << RETRO_DEVICE_ID_JOYPAD_START)) { rarch_load_shader(2, NULL); - strlcpy(g_settings.video.second_pass_shader, DEFAULT_SHADER_FILE, sizeof(g_settings.video.second_pass_shader)); + strlcpy(g_settings.video.second_pass_shader, default_paths.shader_file, sizeof(g_settings.video.second_pass_shader)); menu_stack_refresh(items_generalsettings, menuStackindex); } break; @@ -1403,7 +1409,7 @@ static void producesettingentry(menu * menu_obj, unsigned switchvalue) } if(input_state & (1 << RETRO_DEVICE_ID_JOYPAD_START)) - strlcpy(g_console.default_savestate_dir, usrDirPath, sizeof(g_console.default_savestate_dir)); + strlcpy(g_console.default_savestate_dir, default_paths.savestate_dir, sizeof(g_console.default_savestate_dir)); break; case SETTING_PATH_SRAM_DIRECTORY: @@ -1414,7 +1420,7 @@ static void producesettingentry(menu * menu_obj, unsigned switchvalue) } if(input_state & (1 << RETRO_DEVICE_ID_JOYPAD_START)) - strlcpy(g_console.default_sram_dir, "", sizeof(g_console.default_sram_dir)); + strlcpy(g_console.default_sram_dir, default_paths.sram_dir, sizeof(g_console.default_sram_dir)); break; case SETTING_PATH_CHEATS: if((input_state & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT)) || (input_state & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT)) || (input_state & (1 << RETRO_DEVICE_ID_JOYPAD_B))) @@ -1424,7 +1430,7 @@ static void producesettingentry(menu * menu_obj, unsigned switchvalue) } if(input_state & (1 << RETRO_DEVICE_ID_JOYPAD_START)) - strlcpy(g_settings.cheat_database, usrDirPath, sizeof(g_settings.cheat_database)); + strlcpy(g_settings.cheat_database, default_paths.port_dir, sizeof(g_settings.cheat_database)); break; case SETTING_PATH_SYSTEM: if((input_state & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT)) || (input_state & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT)) || (input_state & (1 << RETRO_DEVICE_ID_JOYPAD_B))) @@ -1434,7 +1440,7 @@ static void producesettingentry(menu * menu_obj, unsigned switchvalue) } if(input_state & (1 << RETRO_DEVICE_ID_JOYPAD_START)) - strlcpy(g_settings.system_directory, systemDirPath, sizeof(g_settings.system_directory)); + strlcpy(g_settings.system_directory, default_paths.system_dir, sizeof(g_settings.system_directory)); break; case SETTING_ENABLE_SRAM_PATH: if((input_state & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT)) || (input_state & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT))) @@ -1464,8 +1470,8 @@ static void producesettingentry(menu * menu_obj, unsigned switchvalue) if((input_state & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT)) || (input_state & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT)) || (input_state & (1 << RETRO_DEVICE_ID_JOYPAD_B)) || (input_state & (1 << RETRO_DEVICE_ID_JOYPAD_START))) { strlcpy(g_console.default_rom_startup_dir, "/", sizeof(g_console.default_rom_startup_dir)); - strlcpy(g_console.default_savestate_dir, usrDirPath, sizeof(g_console.default_savestate_dir)); - strlcpy(g_settings.cheat_database, usrDirPath, sizeof(g_settings.cheat_database)); + strlcpy(g_console.default_savestate_dir, default_paths.port_dir, sizeof(g_console.default_savestate_dir)); + strlcpy(g_settings.cheat_database, default_paths.port_dir, sizeof(g_settings.cheat_database)); strlcpy(g_console.default_sram_dir, "", sizeof(g_console.default_sram_dir)); menu_stack_refresh(items_generalsettings, menuStackindex); @@ -1988,9 +1994,9 @@ static void ingame_menu(void) case MENU_ITEM_RETURN_TO_MULTIMAN: if(input_state & (1 << RETRO_DEVICE_ID_JOYPAD_B)) { - if(path_file_exists(MULTIMAN_EXECUTABLE)) + if(path_file_exists(default_paths.multiman_self_file)) { - strlcpy(g_console.launch_app_on_exit, MULTIMAN_EXECUTABLE, + strlcpy(g_console.launch_app_on_exit, default_paths.multiman_self_file, sizeof(g_console.launch_app_on_exit)); rarch_settings_change(S_RETURN_TO_DASHBOARD); diff --git a/ps3/pkg/USRDIR/cores/savestates/.empty b/ps3/pkg/USRDIR/cores/savestates/.empty new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ps3/pkg/USRDIR/cores/sram/.empty b/ps3/pkg/USRDIR/cores/sram/.empty new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ps3/ps3_audio.c b/ps3/ps3_audio.c index 993906e0a4..7c53fde37f 100644 --- a/ps3/ps3_audio.c +++ b/ps3/ps3_audio.c @@ -136,9 +136,7 @@ static void *ps3_audio_init(const char *device, unsigned rate, unsigned latency) sys_lwmutex_attribute_t lock_attr; sys_lwmutex_attribute_t cond_lock_attr; sys_lwcond_attribute_t cond_attr; -#endif -#ifndef __PSL1GHT__ sys_lwmutex_attribute_initialize(lock_attr); sys_lwmutex_attribute_initialize(cond_lock_attr); sys_lwcond_attribute_initialize(cond_attr); diff --git a/ps3/ps3_input.c b/ps3/ps3_input.c index 24b1511367..9a6454a484 100644 --- a/ps3/ps3_input.c +++ b/ps3/ps3_input.c @@ -97,6 +97,43 @@ CellMouseData ps3_mouse_input_poll_device(uint32_t id) #define MAP(x) (x & 0xFF) +const struct platform_bind platform_keys[] = { + { CTRL_CIRCLE_MASK, "Circle button" }, + { CTRL_CROSS_MASK, "Cross button" }, + { CTRL_TRIANGLE_MASK, "Triangle button" }, + { CTRL_SQUARE_MASK, "Square button" }, + { CTRL_UP_MASK, "D-Pad Up" }, + { CTRL_DOWN_MASK, "D-Pad Down" }, + { CTRL_LEFT_MASK, "D-Pad Left" }, + { CTRL_RIGHT_MASK, "D-Pad Right" }, + { CTRL_SELECT_MASK, "Select button" }, + { CTRL_START_MASK, "Start button" }, + { CTRL_L1_MASK, "L1 button" }, + { CTRL_L2_MASK, "L2 button" }, + { CTRL_L3_MASK, "L3 button" }, + { CTRL_R1_MASK, "R1 button" }, + { CTRL_R2_MASK, "R2 button" }, + { CTRL_R3_MASK, "R3 button" }, + { CTRL_LSTICK_LEFT_MASK, "LStick Left" }, + { CTRL_LSTICK_RIGHT_MASK, "LStick Right" }, + { CTRL_LSTICK_UP_MASK, "LStick Up" }, + { CTRL_LSTICK_DOWN_MASK, "LStick Down" }, + { CTRL_LEFT_MASK | CTRL_LSTICK_LEFT_MASK, "LStick D-Pad Left" }, + { CTRL_RIGHT_MASK | CTRL_LSTICK_RIGHT_MASK, "LStick D-Pad Right" }, + { CTRL_UP_MASK | CTRL_LSTICK_UP_MASK, "LStick D-Pad Up" }, + { CTRL_DOWN_MASK | CTRL_LSTICK_DOWN_MASK, "LStick D-Pad Down" }, + { CTRL_RSTICK_LEFT_MASK, "RStick Left" }, + { CTRL_RSTICK_RIGHT_MASK, "RStick Right" }, + { CTRL_RSTICK_UP_MASK, "RStick Up" }, + { CTRL_RSTICK_DOWN_MASK, "RStick Down" }, + { CTRL_LEFT_MASK | CTRL_RSTICK_LEFT_MASK, "RStick D-Pad Left" }, + { CTRL_RIGHT_MASK | CTRL_RSTICK_RIGHT_MASK, "RStick D-Pad Right" }, + { CTRL_UP_MASK | CTRL_RSTICK_UP_MASK, "RStick D-Pad Up" }, + { CTRL_DOWN_MASK | CTRL_RSTICK_DOWN_MASK, "RStick D-Pad Down" }, +}; + +const unsigned int platform_keys_size = sizeof(platform_keys); + static uint64_t state[MAX_PADS]; static unsigned pads_connected; #ifdef HAVE_MOUSE @@ -433,12 +470,33 @@ static bool ps3_key_pressed(void *data, int key) } } +static void ps3_set_default_keybind_lut(void) +{ + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_B] = platform_keys[PS3_DEVICE_ID_JOYPAD_CROSS].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_Y] = platform_keys[PS3_DEVICE_ID_JOYPAD_SQUARE].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_SELECT] = platform_keys[PS3_DEVICE_ID_JOYPAD_SELECT].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_START] = platform_keys[PS3_DEVICE_ID_JOYPAD_START].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_UP] = platform_keys[PS3_DEVICE_ID_JOYPAD_UP].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_DOWN] = platform_keys[PS3_DEVICE_ID_JOYPAD_DOWN].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_LEFT] = platform_keys[PS3_DEVICE_ID_JOYPAD_LEFT].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_RIGHT] = platform_keys[PS3_DEVICE_ID_JOYPAD_RIGHT].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_A] = platform_keys[PS3_DEVICE_ID_JOYPAD_CIRCLE].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_X] = platform_keys[PS3_DEVICE_ID_JOYPAD_TRIANGLE].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L] = platform_keys[PS3_DEVICE_ID_JOYPAD_L1].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R] = platform_keys[PS3_DEVICE_ID_JOYPAD_R1].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R2] = platform_keys[PS3_DEVICE_ID_JOYPAD_R2].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R3] = platform_keys[PS3_DEVICE_ID_JOYPAD_R3].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L2] = platform_keys[PS3_DEVICE_ID_JOYPAD_L2].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L3] = platform_keys[PS3_DEVICE_ID_JOYPAD_L3].joykey; +} + const input_driver_t input_ps3 = { .init = ps3_input_initialize, .poll = ps3_input_poll, .input_state = ps3_input_state, .key_pressed = ps3_key_pressed, .free = ps3_free_input, + .set_default_keybind_lut = ps3_set_default_keybind_lut, .ident = "ps3", }; diff --git a/ps3/ps3_input.h b/ps3/ps3_input.h index 66cdb5c7b1..5e4436168a 100644 --- a/ps3/ps3_input.h +++ b/ps3/ps3_input.h @@ -156,6 +156,44 @@ typedef struct CellOskDialogParam dialogParam; } oskutil_params; +enum ps3_device_id +{ + PS3_DEVICE_ID_JOYPAD_CIRCLE = 0, + PS3_DEVICE_ID_JOYPAD_CROSS, + PS3_DEVICE_ID_JOYPAD_TRIANGLE, + PS3_DEVICE_ID_JOYPAD_SQUARE, + PS3_DEVICE_ID_JOYPAD_UP, + PS3_DEVICE_ID_JOYPAD_DOWN, + PS3_DEVICE_ID_JOYPAD_LEFT, + PS3_DEVICE_ID_JOYPAD_RIGHT, + PS3_DEVICE_ID_JOYPAD_SELECT, + PS3_DEVICE_ID_JOYPAD_START, + PS3_DEVICE_ID_JOYPAD_L1, + PS3_DEVICE_ID_JOYPAD_L2, + PS3_DEVICE_ID_JOYPAD_L3, + PS3_DEVICE_ID_JOYPAD_R1, + PS3_DEVICE_ID_JOYPAD_R2, + PS3_DEVICE_ID_JOYPAD_R3, + PS3_DEVICE_ID_LSTICK_LEFT, + PS3_DEVICE_ID_LSTICK_RIGHT, + PS3_DEVICE_ID_LSTICK_UP, + PS3_DEVICE_ID_LSTICK_DOWN, + PS3_DEVICE_ID_LSTICK_LEFT_DPAD, + PS3_DEVICE_ID_LSTICK_RIGHT_DPAD, + PS3_DEVICE_ID_LSTICK_UP_DPAD, + PS3_DEVICE_ID_LSTICK_DOWN_DPAD, + PS3_DEVICE_ID_RSTICK_LEFT, + PS3_DEVICE_ID_RSTICK_RIGHT, + PS3_DEVICE_ID_RSTICK_UP, + PS3_DEVICE_ID_RSTICK_DOWN, + PS3_DEVICE_ID_RSTICK_LEFT_DPAD, + PS3_DEVICE_ID_RSTICK_RIGHT_DPAD, + PS3_DEVICE_ID_RSTICK_UP_DPAD, + PS3_DEVICE_ID_RSTICK_DOWN_DPAD, + + RARCH_LAST_PLATFORM_KEY +}; + void oskutil_write_message(oskutil_params *params, const wchar_t* msg); void oskutil_write_initial_message(oskutil_params *params, const wchar_t* msg); void oskutil_init(oskutil_params *params, unsigned int containersize); diff --git a/ps3/sdk_defines.h b/ps3/sdk_defines.h index 35c36c1988..72c5570d95 100644 --- a/ps3/sdk_defines.h +++ b/ps3/sdk_defines.h @@ -56,6 +56,7 @@ #define param_attrib attrib #define sys_lwmutex_attribute_t sys_lwmutex_attr_t #define sys_lwcond_attribute_t sys_lwcond_attr_t +#define sys_semaphore_t sys_sem_t #else #define numChannels nChannel @@ -288,6 +289,14 @@ #endif +/*============================================================ + TIMER PROTOTYPES +============================================================ */ + +#ifdef __PSL1GHT__ +#define sys_timer_usleep usleep +#endif + /*============================================================ THREADING PROTOTYPES ============================================================ */ @@ -318,17 +327,112 @@ #define CELL_GCM_FALSE GCM_FALSE #define CELL_GCM_TRUE GCM_TRUE -#define CELL_GCM_TEXTURE_NEAREST GCM_TEXTURE_NEAREST - #define CELL_GCM_ONE GCM_ONE #define CELL_GCM_ZERO GCM_ZERO +#define CELL_GCM_ALWAYS GCM_ALWAYS -#define CELL_GCM_SMOOTH GCM_SMOOTH +#define CELL_GCM_LOCATION_LOCAL GCM_LOCATION_RSX +#define CELL_GCM_LOCATION_MAIN GCM_LOCATION_CELL + +#define CELL_GCM_MAX_RT_DIMENSION (4096) + +#define CELL_GCM_TEXTURE_LINEAR_NEAREST GCM_TEXTURE_LINEAR_MIPMAP_NEAREST +#define CELL_GCM_TEXTURE_LINEAR_LINEAR GCM_TEXTURE_LINEAR_MIPMAP_LINEAR +#define CELL_GCM_TEXTURE_NEAREST_LINEAR GCM_TEXTURE_NEAREST_MIPMAP_LINEAR +#define CELL_GCM_TEXTURE_NEAREST_NEAREST GCM_TEXTURE_NEAREST_MIPMAP_NEAREST +#define CELL_GCM_TEXTURE_NEAREST GCM_TEXTURE_NEAREST +#define CELL_GCM_TEXTURE_LINEAR GCM_TEXTURE_LINEAR + +#define CELL_GCM_TEXTURE_A8R8G8B8 GCM_TEXTURE_FORMAT_A8R8G8B8 +#define CELL_GCM_TEXTURE_R5G6B5 GCM_TEXTURE_FORMAT_R5G6B5 +#define CELL_GCM_TEXTURE_A1R5G5B5 GCM_TEXTURE_FORMAT_A1R5G5B5 + +#define CELL_GCM_TEXTURE_CLAMP_TO_EDGE GCM_TEXTURE_CLAMP_TO_EDGE + +#define CELL_GCM_TEXTURE_MAX_ANISO_1 GCM_TEXTURE_MAX_ANISO_1 +#define CELL_GCM_TEXTURE_CONVOLUTION_QUINCUNX GCM_TEXTURE_CONVOLUTION_QUINCUNX +#define CELL_GCM_TEXTURE_ZFUNC_NEVER GCM_TEXTURE_ZFUNC_NEVER + +#define CELL_GCM_DISPLAY_HSYNC GCM_FLIP_HSYNC +#define CELL_GCM_DISPLAY_VSYNC GCM_FLIP_VSYNC + +#define CELL_GCM_CLEAR_R GCM_CLEAR_R +#define CELL_GCM_CLEAR_G GCM_CLEAR_G +#define CELL_GCM_CLEAR_B GCM_CLEAR_B +#define CELL_GCM_CLEAR_A GCM_CLEAR_A + +#define CELL_GCM_FUNC_ADD GCM_FUNC_ADD + +#define CELL_RESC_720x480 RESC_720x480 +#define CELL_RESC_720x576 RESC_720x576 +#define CELL_RESC_1280x720 RESC_1280x720 +#define CELL_RESC_1920x1080 RESC_1920x1080 + +#define CELL_RESC_FULLSCREEN RESC_FULLSCREEN +#define CELL_RESC_PANSCAN RESC_PANSCAN +#define CELL_RESC_LETTERBOX RESC_LETTERBOX +#define CELL_RESC_CONSTANT_VRAM RESC_CONSTANT_VRAM +#define CELL_RESC_MINIMUM_GPU_LOAD RESC_MINIMUM_GPU_LOAD + +#define CELL_RESC_PAL_50 RESC_PAL_50 +#define CELL_RESC_PAL_60_DROP RESC_PAL_60_DROP +#define CELL_RESC_PAL_60_INTERPOLATE RESC_PAL_60_INTERPOLATE +#define CELL_RESC_PAL_60_INTERPOLATE_30_DROP RESC_PAL_60_INTERPOLATE_30_DROP +#define CELL_RESC_PAL_60_INTERPOLATE_DROP_FLEXIBLE RESC_PAL_60_INTERPOLATE_DROP_FLEXIBLE + +#define CELL_RESC_INTERLACE_FILTER RESC_INTERLACE_FILTER +#define CELL_RESC_NORMAL_BILINEAR RESC_NORMAL_BILINEAR + +#define CELL_RESC_ELEMENT_HALF RESC_ELEMENT_HALF + +#define CELL_VIDEO_OUT_ASPECT_AUTO VIDEO_ASPECT_AUTO +#define CELL_VIDEO_OUT_ASPECT_4_3 VIDEO_ASPECT_4_3 +#define CELL_VIDEO_OUT_ASPECT_16_9 VIDEO_ASPECT_16_9 + +#define CELL_VIDEO_OUT_RESOLUTION_480 VIDEO_RESOLUTION_480 +#define CELL_VIDEO_OUT_RESOLUTION_576 VIDEO_RESOLUTION_576 +#define CELL_VIDEO_OUT_RESOLUTION_720 VIDEO_RESOLUTION_720 +#define CELL_VIDEO_OUT_RESOLUTION_1080 VIDEO_RESOLUTION_1080 +#define CELL_VIDEO_OUT_RESOLUTION_960x1080 VIDEO_RESOLUTION_960x1080 +#define CELL_VIDEO_OUT_RESOLUTION_1280x1080 VIDEO_RESOLUTION_1280x1080 +#define CELL_VIDEO_OUT_RESOLUTION_1440x1080 VIDEO_RESOLUTION_1440x1080 +#define CELL_VIDEO_OUT_RESOLUTION_1600x1080 VIDEO_RESOLUTION_1600x1080 + +#define CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE VIDEO_SCANMODE_PROGRESSIVE + +#define CELL_VIDEO_OUT_PRIMARY VIDEO_PRIMARY + +#define CELL_VIDEO_OUT_BUFFER_COLOR_FORMAT_X8R8G8B8 VIDEO_BUFFER_FORMAT_XRGB +#define CELL_VIDEO_OUT_BUFFER_COLOR_FORMAT_R16G16B16X16_FLOAT VIDEO_BUFFER_FORMAT_FLOAT #define CellGcmSurface gcmSurface #define CellGcmTexture gcmTexture +#define CellGcmContextData _gcmCtxData +#define CellGcmConfig gcmConfiguration +#define CellVideoOutConfiguration videoConfiguration +#define CellVideoOutResolution videoResolution +#define CellVideoOutState videoState +#define CellRescInitConfig rescInitConfig +#define CellRescSrc rescSrc +#define CellRescBufferMode rescBufferMode + +#define resolutionId resolution +#define memoryFrequency memoryFreq +#define coreFrequency coreFreq + +#define cellGcmFinish rsxFinish + +#define cellGcmGetFlipStatus gcmGetFlipStatus +#define cellGcmResetFlipStatus gcmResetFlipStatus #define cellGcmSetWaitFlip gcmSetWaitFlip +#define cellGcmSetDebugOutputLevel gcmSetDebugOutputLevel +#define cellGcmSetDisplayBuffer gcmSetDisplayBuffer +#define cellGcmSetGraphicsHandler gcmSetGraphicsHandler +#define cellGcmSetFlipHandler gcmSetFlipHandler +#define cellGcmSetVBlankHandler gcmSetVBlankHandler +#define cellGcmGetConfiguration gcmGetConfiguration +#define cellGcmSetJumpCommand rsxSetJumpCommand #define cellGcmFlush rsxFlushBuffer #define cellGcmSetFlipMode gcmSetFlipMode #define cellGcmSetFlip gcmSetFlip @@ -337,6 +441,42 @@ #define cellGcmBindTile gcmBindTile #define cellGcmSetTileInfo gcmSetTileInfo #define cellGcmAddressToOffset gcmAddressToOffset + +#define cellRescCreateInterlaceTable rescCreateInterlaceTable +#define cellRescSetDisplayMode rescSetDisplayMode +#define cellRescGetNumColorBuffers rescGetNumColorBuffers +#define cellRescGetBufferSize rescGetBufferSize +#define cellRescSetBufferAddress rescSetBufferAddress +#define cellRescGetFlipStatus rescGetFlipStatus +#define cellRescResetFlipStatus rescResetFlipStatus +#define cellRescSetConvertAndFlip rescSetConvertAndFlip +#define cellRescSetVBlankHandler rescSetVBlankHandler +#define cellRescSetFlipHandler rescSetFlipHandler +#define cellRescAdjustAspectRatio rescAdjustAspectRatio +#define cellRescSetWaitFlip rescSetWaitFlip +#define cellRescSetSrc rescSetSrc +#define cellRescInit rescInit +#define cellRescExit rescExit + +#define cellVideoOutConfigure videoConfigure +#define cellVideoOutGetState videoGetState +#define cellVideoOutGetResolution videoGetResolution + +#define cellGcmSetViewportInline rsxSetViewport +#define cellGcmSetReferenceCommandInline rsxSetReferenceCommand +#define cellGcmSetBlendEquationInline rsxSetBlendEquation +#define cellGcmSetWriteBackEndLabelInline rsxSetWriteBackendLabel +#define cellGcmSetWaitLabelInline rsxSetWaitLabel +#define cellGcmSetDepthTestEnableInline rsxSetDepthTestEnable +#define cellGcmSetScissorInline rsxSetScissor +#define cellGcmSetBlendEnableInline rsxSetBlendEnable +#define cellGcmSetClearColorInline rsxSetClearColor +#define cellGcmSetBlendFuncInline rsxSetBlendFunc +#define cellGcmSetBlendColorInline rsxSetBlendColor +#define cellGcmSetTextureFilterInline rsxTextureFilter +#define cellGcmSetTextureControlInline rsxTextureControl +#define cellGcmSetCullFaceEnableInline rsxSetCullFaceEnable +#define cellGcmSetShadeModeInline rxSetShadeModel #endif #endif diff --git a/wii/frontend/main.c b/wii/frontend/main.c index 941b6853be..8aa29ec551 100644 --- a/wii/frontend/main.c +++ b/wii/frontend/main.c @@ -200,7 +200,7 @@ int main(void) wii_video_init(); input_wii.init(); - rarch_input_set_controls_default(); + rarch_input_set_controls_default(&input_wii); rgui_handle_t *rgui = rgui_init("", menu_framebuf, RGUI_WIDTH * sizeof(uint16_t), diff --git a/wii/input.c b/wii/input.c index 75ad8955ae..7a72591156 100644 --- a/wii/input.c +++ b/wii/input.c @@ -34,6 +34,97 @@ #define JOYSTICK_THRESHOLD 64 static uint64_t pad_state[4]; + +const struct platform_bind platform_keys[] = { + { WII_GC_A, "GC A button" }, + { WII_GC_B, "GC B button" }, + { WII_GC_X, "GC X button" }, + { WII_GC_Y, "GC Y button" }, + { WII_GC_UP, "GC D-Pad Up" }, + { WII_GC_DOWN, "GC D-Pad Down" }, + { WII_GC_LEFT, "GC D-Pad Left" }, + { WII_GC_RIGHT, "GC D-Pad Right" }, + { WII_GC_Z_TRIGGER, "GC Z Trigger" }, + { WII_GC_START, "GC Start button" }, + { WII_GC_L_TRIGGER, "GC Left Trigger" }, + { WII_GC_R_TRIGGER, "GC Right Trigger" }, + { WII_GC_LSTICK_LEFT, "GC Main Stick Left" }, + { WII_GC_LSTICK_RIGHT, "GC Main Stick Right" }, + { WII_GC_LSTICK_UP, "GC Main Stick Up" }, + { WII_GC_LSTICK_DOWN, "GC Main Stick Down" }, + { WII_GC_LSTICK_LEFT | WII_GC_LEFT, "GC Main Stick D-Pad Left" }, + { WII_GC_LSTICK_RIGHT | WII_GC_RIGHT, "GC Main Stick D-Pad Right" }, + { WII_GC_LSTICK_UP | WII_GC_UP, "GC Main Stick D-Pad Up" }, + { WII_GC_LSTICK_DOWN | WII_GC_DOWN, "GC Main Stick D-Pad Down" }, + { WII_GC_RSTICK_LEFT, "GC C-Stick Left" }, + { WII_GC_RSTICK_RIGHT, "GC C-Stick Right" }, + { WII_GC_RSTICK_UP, "GC C-Stick Up" }, + { WII_GC_RSTICK_DOWN, "GC C-Stick Down" }, + { WII_GC_RSTICK_LEFT | WII_GC_LEFT, "GC C-Stick D-Pad Left" }, + { WII_GC_RSTICK_RIGHT | WII_GC_RIGHT, "GC C-Stick D-Pad Right" }, + { WII_GC_RSTICK_UP | WII_GC_UP, "GC C-Stick D-Pad Up" }, + { WII_GC_RSTICK_DOWN | WII_GC_DOWN, "GC C-Stick D-Pad Down" }, + +#ifdef HW_RVL + // CLASSIC CONTROLLER + { WII_CLASSIC_A, "Classic A button" }, + { WII_CLASSIC_B, "Classic B button" }, + { WII_CLASSIC_X, "Classic X button" }, + { WII_CLASSIC_Y, "Classic Y button" }, + { WII_CLASSIC_UP, "Classic D-Pad Up" }, + { WII_CLASSIC_DOWN, "Classic D-Pad Down" }, + { WII_CLASSIC_LEFT, "Classic D-Pad Left" }, + { WII_CLASSIC_RIGHT, "Classic D-Pad Right" }, + { WII_CLASSIC_PLUS, "Classic Plus button" }, + { WII_CLASSIC_MINUS, "Classic Minus button" }, + { WII_CLASSIC_HOME, "Classic Home button" }, + { WII_CLASSIC_L_TRIGGER, "Classic L Trigger" }, + { WII_CLASSIC_R_TRIGGER, "Classic R Trigger" }, + { WII_CLASSIC_ZL_TRIGGER, "Classic ZL Trigger" }, + { WII_CLASSIC_ZR_TRIGGER, "Classic ZR Trigger" }, + { WII_CLASSIC_LSTICK_LEFT, "Classic LStick Left" }, + { WII_CLASSIC_LSTICK_RIGHT, "Classic LStick Right" }, + { WII_CLASSIC_LSTICK_UP, "Classic LStick Up" }, + { WII_CLASSIC_LSTICK_DOWN, "Classic LStick Down" }, + { WII_CLASSIC_LSTICK_LEFT | WII_CLASSIC_LEFT, "Classic LStick D-Pad Left" }, + { WII_CLASSIC_LSTICK_RIGHT | WII_CLASSIC_RIGHT, "Classic LStick D-Pad Right" }, + { WII_CLASSIC_LSTICK_UP | WII_CLASSIC_UP, "Classic LStick D-Pad Up" }, + { WII_CLASSIC_LSTICK_DOWN | WII_CLASSIC_DOWN, "Classic LStick D-Pad Down" }, + { WII_CLASSIC_RSTICK_LEFT, "Classic RStick Left" }, + { WII_CLASSIC_RSTICK_RIGHT, "Classic RStick Right" }, + { WII_CLASSIC_RSTICK_UP, "Classic RStick Up" }, + { WII_CLASSIC_RSTICK_DOWN, "Classic RStick Down" }, + { WII_CLASSIC_RSTICK_LEFT | WII_CLASSIC_LEFT, "Classic RStick D-Pad Left" }, + { WII_CLASSIC_RSTICK_RIGHT | WII_CLASSIC_RIGHT, "Classic RStick D-Pad Right" }, + { WII_CLASSIC_RSTICK_UP | WII_CLASSIC_UP, "Classic RStick D-Pad Up" }, + { WII_CLASSIC_RSTICK_DOWN | WII_CLASSIC_DOWN, "Classic RStick D-Pad Down" }, + + // WIIMOTE (PLUS OPTIONAL NUNCHUK) + { WII_WIIMOTE_A, "Wiimote A button" }, + { WII_WIIMOTE_B, "Wiimote B button" }, + { WII_WIIMOTE_1, "Wiimote 1 button" }, + { WII_WIIMOTE_2, "Wiimote 2 button" }, + { WII_WIIMOTE_UP, "Wiimote D-Pad Up" }, + { WII_WIIMOTE_DOWN, "Wiimote D-Pad Down" }, + { WII_WIIMOTE_LEFT, "Wiimote D-Pad Left" }, + { WII_WIIMOTE_RIGHT, "Wiimote D-Pad Right" }, + { WII_WIIMOTE_PLUS, "Wiimote Plus button" }, + { WII_WIIMOTE_MINUS, "Wiimote Minus button" }, + { WII_WIIMOTE_HOME, "Wiimote Home button" }, + { WII_NUNCHUK_Z, "Nunchuk Z button" }, + { WII_NUNCHUK_C, "Nunchuk C button" }, + { WII_NUNCHUK_LEFT, "Nunchuk Stick Left" }, + { WII_NUNCHUK_RIGHT, "Nunchuk Stick Right" }, + { WII_NUNCHUK_UP, "Nunchuk Stick Up" }, + { WII_NUNCHUK_DOWN, "Nunchuk Stick Down" }, + { WII_NUNCHUK_LEFT | WII_WIIMOTE_LEFT, "Nunchuk Stick D-Pad Left" }, + { WII_NUNCHUK_RIGHT | WII_WIIMOTE_RIGHT, "Nunchuk Stick D-Pad Right" }, + { WII_NUNCHUK_UP | WII_WIIMOTE_UP, "Nunchuk Stick D-Pad Up" }, + { WII_NUNCHUK_DOWN | WII_WIIMOTE_DOWN, "Nunchuk Stick D-Pad Down" }, +#endif +}; + +const unsigned int platform_keys_size = sizeof(platform_keys); static bool g_quit; static int16_t wii_input_state(void *data, const struct retro_keybind **binds, @@ -279,12 +370,32 @@ static bool wii_key_pressed(void *data, int key) } } +static void wii_set_default_keybind_lut(void) +{ + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_B] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_B].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_Y] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_Y].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_SELECT] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_Z_TRIGGER].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_START] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_START].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_UP] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_UP].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_DOWN] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_DOWN].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_LEFT] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_LEFT].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_RIGHT] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_RIGHT].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_A] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_A].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_X] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_X].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_L_TRIGGER].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R] = platform_keys[WII_DEVICE_GC_ID_JOYPAD_R_TRIGGER].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L2] = 0; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R2] = 0; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L3] = 0; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R3] = 0; +} + const input_driver_t input_wii = { .init = wii_input_initialize, .poll = wii_input_poll, .input_state = wii_input_state, .key_pressed = wii_key_pressed, .free = wii_free_input, + .set_default_keybind_lut = wii_set_default_keybind_lut, .ident = "wii", }; - diff --git a/wii/wii_input.h b/wii/wii_input.h index a7dae52d4f..fe02ed4a3b 100644 --- a/wii/wii_input.h +++ b/wii/wii_input.h @@ -81,6 +81,98 @@ enum WII_NUNCHUK_RIGHT = 1ULL << 59, }; +enum wii_device_id +{ + WII_DEVICE_GC_ID_JOYPAD_A = 0, + WII_DEVICE_GC_ID_JOYPAD_B, + WII_DEVICE_GC_ID_JOYPAD_X, + WII_DEVICE_GC_ID_JOYPAD_Y, + WII_DEVICE_GC_ID_JOYPAD_UP, + WII_DEVICE_GC_ID_JOYPAD_DOWN, + WII_DEVICE_GC_ID_JOYPAD_LEFT, + WII_DEVICE_GC_ID_JOYPAD_RIGHT, + WII_DEVICE_GC_ID_JOYPAD_Z_TRIGGER, + WII_DEVICE_GC_ID_JOYPAD_START, + WII_DEVICE_GC_ID_JOYPAD_L_TRIGGER, + WII_DEVICE_GC_ID_JOYPAD_R_TRIGGER, + WII_DEVICE_GC_ID_LSTICK_LEFT, + WII_DEVICE_GC_ID_LSTICK_RIGHT, + WII_DEVICE_GC_ID_LSTICK_UP, + WII_DEVICE_GC_ID_LSTICK_DOWN, + WII_DEVICE_GC_ID_LSTICK_LEFT_DPAD, + WII_DEVICE_GC_ID_LSTICK_RIGHT_DPAD, + WII_DEVICE_GC_ID_LSTICK_UP_DPAD, + WII_DEVICE_GC_ID_LSTICK_DOWN_DPAD, + WII_DEVICE_GC_ID_RSTICK_LEFT, + WII_DEVICE_GC_ID_RSTICK_RIGHT, + WII_DEVICE_GC_ID_RSTICK_UP, + WII_DEVICE_GC_ID_RSTICK_DOWN, + WII_DEVICE_GC_ID_RSTICK_LEFT_DPAD, + WII_DEVICE_GC_ID_RSTICK_RIGHT_DPAD, + WII_DEVICE_GC_ID_RSTICK_UP_DPAD, + WII_DEVICE_GC_ID_RSTICK_DOWN_DPAD, + +#ifdef HW_RVL + // CLASSIC CONTROLLER + WII_DEVICE_CLASSIC_ID_JOYPAD_A, + WII_DEVICE_CLASSIC_ID_JOYPAD_B, + WII_DEVICE_CLASSIC_ID_JOYPAD_X, + WII_DEVICE_CLASSIC_ID_JOYPAD_Y, + WII_DEVICE_CLASSIC_ID_JOYPAD_UP, + WII_DEVICE_CLASSIC_ID_JOYPAD_DOWN, + WII_DEVICE_CLASSIC_ID_JOYPAD_LEFT, + WII_DEVICE_CLASSIC_ID_JOYPAD_RIGHT, + WII_DEVICE_CLASSIC_ID_JOYPAD_PLUS, + WII_DEVICE_CLASSIC_ID_JOYPAD_MINUS, + WII_DEVICE_CLASSIC_ID_JOYPAD_HOME, + WII_DEVICE_CLASSIC_ID_JOYPAD_L_TRIGGER, + WII_DEVICE_CLASSIC_ID_JOYPAD_R_TRIGGER, + WII_DEVICE_CLASSIC_ID_JOYPAD_ZL_TRIGGER, + WII_DEVICE_CLASSIC_ID_JOYPAD_ZR_TRIGGER, + WII_DEVICE_CLASSIC_ID_LSTICK_LEFT, + WII_DEVICE_CLASSIC_ID_LSTICK_RIGHT, + WII_DEVICE_CLASSIC_ID_LSTICK_UP, + WII_DEVICE_CLASSIC_ID_LSTICK_DOWN, + WII_DEVICE_CLASSIC_ID_LSTICK_LEFT_DPAD, + WII_DEVICE_CLASSIC_ID_LSTICK_RIGHT_DPAD, + WII_DEVICE_CLASSIC_ID_LSTICK_UP_DPAD, + WII_DEVICE_CLASSIC_ID_LSTICK_DOWN_DPAD, + WII_DEVICE_CLASSIC_ID_RSTICK_LEFT, + WII_DEVICE_CLASSIC_ID_RSTICK_RIGHT, + WII_DEVICE_CLASSIC_ID_RSTICK_UP, + WII_DEVICE_CLASSIC_ID_RSTICK_DOWN, + WII_DEVICE_CLASSIC_ID_RSTICK_LEFT_DPAD, + WII_DEVICE_CLASSIC_ID_RSTICK_RIGHT_DPAD, + WII_DEVICE_CLASSIC_ID_RSTICK_UP_DPAD, + WII_DEVICE_CLASSIC_ID_RSTICK_DOWN_DPAD, + + // WIIMOTE (PLUS OPTIONAL NUNCHUK) + WII_DEVICE_WIIMOTE_ID_JOYPAD_A, + WII_DEVICE_WIIMOTE_ID_JOYPAD_B, + WII_DEVICE_WIIMOTE_ID_JOYPAD_1, + WII_DEVICE_WIIMOTE_ID_JOYPAD_2, + WII_DEVICE_WIIMOTE_ID_JOYPAD_UP, + WII_DEVICE_WIIMOTE_ID_JOYPAD_DOWN, + WII_DEVICE_WIIMOTE_ID_JOYPAD_LEFT, + WII_DEVICE_WIIMOTE_ID_JOYPAD_RIGHT, + WII_DEVICE_WIIMOTE_ID_JOYPAD_PLUS, + WII_DEVICE_WIIMOTE_ID_JOYPAD_MINUS, + WII_DEVICE_WIIMOTE_ID_JOYPAD_HOME, + WII_DEVICE_WIIMOTE_ID_JOYPAD_Z, + WII_DEVICE_WIIMOTE_ID_JOYPAD_C, + WII_DEVICE_WIIMOTE_ID_LSTICK_LEFT, + WII_DEVICE_WIIMOTE_ID_LSTICK_RIGHT, + WII_DEVICE_WIIMOTE_ID_LSTICK_UP, + WII_DEVICE_WIIMOTE_ID_LSTICK_DOWN, + WII_DEVICE_WIIMOTE_ID_LSTICK_LEFT_DPAD, + WII_DEVICE_WIIMOTE_ID_LSTICK_RIGHT_DPAD, + WII_DEVICE_WIIMOTE_ID_LSTICK_UP_DPAD, + WII_DEVICE_WIIMOTE_ID_LSTICK_DOWN_DPAD, +#endif + + RARCH_LAST_PLATFORM_KEY +}; + uint64_t wii_input_update(unsigned port); #endif diff --git a/xbox1/Media/arial.ttf b/xbox1/Media/arial.ttf new file mode 100644 index 0000000000..25769bbf1b Binary files /dev/null and b/xbox1/Media/arial.ttf differ diff --git a/xbox1/Media/menuMainBG.png b/xbox1/Media/menuMainBG.png new file mode 100644 index 0000000000..8e6d54eee7 Binary files /dev/null and b/xbox1/Media/menuMainBG.png differ diff --git a/xbox1/Media/menuMainBG_720p.png b/xbox1/Media/menuMainBG_720p.png new file mode 100644 index 0000000000..2bd9482cc1 Binary files /dev/null and b/xbox1/Media/menuMainBG_720p.png differ diff --git a/xbox1/Media/menuMainRomSelectPanel.png b/xbox1/Media/menuMainRomSelectPanel.png new file mode 100644 index 0000000000..377a9bae5b Binary files /dev/null and b/xbox1/Media/menuMainRomSelectPanel.png differ diff --git a/xbox1/Media/titleimage.jpg b/xbox1/Media/titleimage.jpg new file mode 100644 index 0000000000..1b0bc9586d Binary files /dev/null and b/xbox1/Media/titleimage.jpg differ diff --git a/xbox1/frontend/RetroLaunch/Font.cpp b/xbox1/frontend/RetroLaunch/Font.cpp new file mode 100644 index 0000000000..7af35f7fb3 --- /dev/null +++ b/xbox1/frontend/RetroLaunch/Font.cpp @@ -0,0 +1,214 @@ +/** + * RetroLaunch 2012 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the + * authors: Surreal64 CE Team (http://www.emuxtras.net) + */ + + +#include "Font.h" + +#include "../../../general.h" +#include "../../xdk_d3d8.h" + +Font g_font; + +Font::Font(void) +{ + m_pFont = NULL; +} + +Font::~Font(void) +{ + if (m_pFont) + m_pFont->Release(); +} + +bool Font::Create() +{ + if (m_pFont) + m_pFont->Release(); + + HRESULT g_hResult = XFONT_OpenTrueTypeFont(L"D:\\Media\\arial.ttf", 256 * 1024, &m_pFont); + + if (FAILED(g_hResult)) + return false; + + return true; +} + +void Font::Render(const string &str, int x, int y, dword height, dword style, D3DXCOLOR color, int maxWidth, bool fade, Align alignment) +{ + CSurface texture; + RenderToTexture(texture, str, height, style, color, maxWidth, fade); + + if (alignment != Left) + { + word *wcBuf = StringToWChar(str); + dword dwRequiredWidth; + m_pFont->GetTextExtent(wcBuf, -1, &dwRequiredWidth); + delete [] wcBuf; + + if (alignment == Center) + x -= (dwRequiredWidth / 2); + else if (alignment == Right) + x -= dwRequiredWidth; + } + + texture.Render(x, y); +} + +void Font::RenderToTexture(CSurface &texture, const string &str, dword height, dword style, D3DXCOLOR color, int maxWidth, bool fade) +{ + xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data; + if (m_pFont == NULL) + return; + + m_pFont->SetTextHeight(height); + m_pFont->SetTextStyle(style); + m_pFont->SetTextColor(color); + + dword dwMaxWidth = (maxWidth <= 0) ? 1000 : maxWidth; + + // get the exact width and height required to display the string + dword dwRequiredWidth = GetRequiredWidth(str, height, style); + dword dwRequiredHeight = GetRequiredHeight(str, height, style);; + + // calculate the texture width and height needed to display the font + dword dwTextureWidth = dwRequiredWidth * 2; + dword dwTextureHeight = dwRequiredHeight * 2; + { + // because the textures are swizzled we make sure + // the dimensions are a power of two + for(dword wmask = 1; dwTextureWidth &(dwTextureWidth - 1); wmask = (wmask << 1 ) + 1) + dwTextureWidth = (dwTextureWidth + wmask) & ~wmask; + + for(dword hmask = 1; dwTextureHeight &(dwTextureHeight - 1); hmask = (hmask << 1) + 1) + dwTextureHeight = ( dwTextureHeight + hmask ) & ~hmask; + + // also enforce a minimum pitch of 64 bytes + dwTextureWidth = max(64 / XGBytesPerPixelFromFormat(D3DFMT_A8R8G8B8), dwTextureWidth); + } + + // create an temporary image surface to render to + D3DSurface *pTempSurface; + d3d->d3d_render_device->CreateImageSurface(dwTextureWidth, dwTextureHeight, D3DFMT_LIN_A8R8G8B8, &pTempSurface); + + // clear the temporary surface + { + D3DLOCKED_RECT tmpLr; + pTempSurface->LockRect(&tmpLr, NULL, 0); + memset(tmpLr.pBits, 0, dwTextureWidth * dwTextureHeight * XGBytesPerPixelFromFormat(D3DFMT_A8R8G8B8)); + pTempSurface->UnlockRect(); + } + + // render the text to the temporary surface + word *wcBuf = StringToWChar(str); + m_pFont->TextOut(pTempSurface, wcBuf, -1, 0, 0); + delete [] wcBuf; + + // create the texture that will be drawn to the screen + texture.Destroy(); + texture.Create(dwTextureWidth, dwTextureHeight); + + // copy from the temporary surface to the final texture + { + D3DLOCKED_RECT tmpLr; + D3DLOCKED_RECT txtLr; + + pTempSurface->LockRect(&tmpLr, NULL, 0); + texture.GetTexture()->LockRect(0, &txtLr, NULL, 0); + + if (fade) + { + // draw the last 35 pixels of the string fading out to max width or texture width + dword dwMinFadeDistance = min(static_cast(dwTextureWidth * 0.35), 35); + dword dwFadeStart = min(dwTextureWidth, dwMaxWidth - dwMinFadeDistance); + dword dwFadeEnd = min(dwTextureWidth, dwMaxWidth); + dword dwFadeDistance = dwFadeEnd - dwFadeStart; + + for (dword h = 0; h < dwTextureHeight; h++) + { + for (dword w = 0; w < dwFadeDistance; w++) + { + dword *pColor = reinterpret_cast(tmpLr.pBits); + dword offset = (h * dwTextureWidth) + (dwFadeStart + w); + + D3DXCOLOR color = D3DXCOLOR(pColor[offset]); + color.a = color.a * (1.0f - static_cast(w) / static_cast(dwFadeDistance)); + pColor[offset] = color; + } + } + } + + // dont draw anything > than max width + for (dword h = 0; h < dwTextureHeight; h++) + { + for (dword w = min(dwTextureWidth, dwMaxWidth); w < dwTextureWidth; w++) + { + dword *pColor = reinterpret_cast(tmpLr.pBits); + dword offset = (h * dwTextureWidth) + w; + + D3DXCOLOR color = D3DXCOLOR(pColor[offset]); + color.a = 0.0; + pColor[offset] = color; + } + } + + // copy and swizzle the linear surface to the swizzled texture + XGSwizzleRect(tmpLr.pBits, tmpLr.Pitch, NULL, txtLr.pBits, dwTextureWidth, dwTextureHeight, NULL, 4); + + texture.GetTexture()->UnlockRect(0); + pTempSurface->UnlockRect(); + } + + pTempSurface->Release(); +} + +int Font::GetRequiredWidth(const string &str, dword height, dword style) +{ + word *wcBuf = StringToWChar(str); + dword reqWidth; + + m_pFont->SetTextHeight(height); + m_pFont->SetTextStyle(style); + m_pFont->GetTextExtent(wcBuf, -1, &reqWidth); + + delete [] wcBuf; + + return reqWidth; +} + +int Font::GetRequiredHeight(const string &str, dword height, dword style) +{ + word *wcBuf = StringToWChar(str); + dword reqHeight; + + m_pFont->SetTextHeight(height); + m_pFont->SetTextStyle(style); + m_pFont->GetFontMetrics(&reqHeight, NULL); + + delete [] wcBuf; + + return reqHeight; +} + + +word *Font::StringToWChar(const string &str) +{ + word *retVal = new word[(str.length() + 1) * 2]; + memset(retVal, 0, (str.length() + 1) * 2 * sizeof(word)); + + if (str.length() > 0) + mbstowcs(retVal, str.c_str(), str.length()); + + return retVal; +} diff --git a/xbox1/frontend/RetroLaunch/Font.h b/xbox1/frontend/RetroLaunch/Font.h new file mode 100644 index 0000000000..5106a5ec8b --- /dev/null +++ b/xbox1/frontend/RetroLaunch/Font.h @@ -0,0 +1,46 @@ +/** + * RetroLaunch 2012 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the + * authors: Surreal64 CE Team (http://www.emuxtras.net) + */ + +#pragma once +#include "Global.h" +#include "Surface.h" + +enum Align +{ + Left, + Center, + Right +}; + +class Font +{ +public: + Font(void); + ~Font(void); + + bool Create(); + + void Render(const string &str, int x, int y, dword height, dword style = XFONT_NORMAL, D3DXCOLOR color = D3DCOLOR_XRGB(0, 0, 0), int dwMaxWidth = -1, bool fade = false, Align alignment = Left); + void RenderToTexture(CSurface &texture, const string &str, dword height, dword style = XFONT_NORMAL, D3DXCOLOR color = D3DCOLOR_XRGB(0, 0, 0), int maxWidth = -1, bool fade = false); + + int GetRequiredWidth(const string &str, dword height, dword style); + int GetRequiredHeight(const string &str, dword height, dword style); + + word *StringToWChar(const string &str); +private: + XFONT *m_pFont; +}; + +extern Font g_font; diff --git a/xbox1/frontend/RetroLaunch/Global.h b/xbox1/frontend/RetroLaunch/Global.h new file mode 100644 index 0000000000..4e16968715 --- /dev/null +++ b/xbox1/frontend/RetroLaunch/Global.h @@ -0,0 +1,41 @@ +/** + * RetroLaunch 2012 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the + * authors: Surreal64 CE Team (http://www.emuxtras.net) + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +#define XBUILD "Launcher CE" + +typedef unsigned __int8 byte; +typedef unsigned __int16 word; +typedef unsigned __int32 dword; +typedef unsigned __int64 qword; + + diff --git a/xbox1/frontend/RetroLaunch/IoSupport.cpp b/xbox1/frontend/RetroLaunch/IoSupport.cpp new file mode 100644 index 0000000000..cfeea542f5 --- /dev/null +++ b/xbox1/frontend/RetroLaunch/IoSupport.cpp @@ -0,0 +1,190 @@ +// IoSupport.cpp: implementation of the CIoSupport class. +// +////////////////////////////////////////////////////////////////////// +#include "iosupport.h" +#include "undocumented.h" + +#include + +#define CTLCODE(DeviceType, Function, Method, Access) ( ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) ) +#define FSCTL_DISMOUNT_VOLUME CTLCODE( FILE_DEVICE_FILE_SYSTEM, 0x08, METHOD_BUFFERED, FILE_ANY_ACCESS ) + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CIoSupport g_IOSupport; + +CIoSupport::CIoSupport() +{ + m_dwLastTrayState = 0; +} + +CIoSupport::~CIoSupport() +{ + +} + +// szDrive e.g. "D:" +// szDevice e.g. "Cdrom0" or "Harddisk0\Partition6" + +HRESULT CIoSupport::Mount(CHAR* szDrive, CHAR* szDevice) +{ + CHAR szSourceDevice[48]; + CHAR szDestinationDrive[16]; + + sprintf(szSourceDevice, "\\Device\\%s", szDevice); + sprintf(szDestinationDrive, "\\??\\%s", szDrive); + + STRING DeviceName = + { + strlen(szSourceDevice), + strlen(szSourceDevice) + 1, + szSourceDevice + }; + + STRING LinkName = + { + strlen(szDestinationDrive), + strlen(szDestinationDrive) + 1, + szDestinationDrive + }; + + IoCreateSymbolicLink(&LinkName, &DeviceName); + + return S_OK; +} + + + +// szDrive e.g. "D:" + +HRESULT CIoSupport::Unmount(CHAR* szDrive) +{ + char szDestinationDrive[16]; + sprintf(szDestinationDrive, "\\??\\%s", szDrive); + + STRING LinkName = + { + strlen(szDestinationDrive), + strlen(szDestinationDrive) + 1, + szDestinationDrive + }; + + IoDeleteSymbolicLink(&LinkName); + + return S_OK; +} + + + + + +HRESULT CIoSupport::Remount(CHAR* szDrive, CHAR* szDevice) +{ + CHAR szSourceDevice[48]; + sprintf(szSourceDevice, "\\Device\\%s", szDevice); + + Unmount(szDrive); + + ANSI_STRING filename; + OBJECT_ATTRIBUTES attributes; + IO_STATUS_BLOCK status; + HANDLE hDevice; + NTSTATUS error; + DWORD dummy; + + RtlInitAnsiString(&filename, szSourceDevice); + InitializeObjectAttributes(&attributes, &filename, OBJ_CASE_INSENSITIVE, NULL); + + if (!NT_SUCCESS(error = NtCreateFile(&hDevice, GENERIC_READ | + SYNCHRONIZE | FILE_READ_ATTRIBUTES, &attributes, &status, NULL, 0, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OPEN, + FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT))) + { + return E_FAIL; + } + + if (!DeviceIoControl(hDevice, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, &dummy, NULL)) + { + CloseHandle(hDevice); + return E_FAIL; + } + + CloseHandle(hDevice); + Mount(szDrive, szDevice); + + return S_OK; +} + +HRESULT CIoSupport::Remap(CHAR* szMapping) +{ + char szMap[32]; + strcpy(szMap, szMapping ); + + char* pComma = strstr(szMap, ","); + if (pComma) + { + *pComma = 0; + + // map device to drive letter + Unmount(szMap); + Mount(szMap, &pComma[1]); + return S_OK; + } + + return E_FAIL; +} + + +HRESULT CIoSupport::EjectTray() +{ + HalWriteSMBusValue(0x20, 0x0C, FALSE, 0); // eject tray + return S_OK; +} + +HRESULT CIoSupport::CloseTray() +{ + HalWriteSMBusValue(0x20, 0x0C, FALSE, 1); // close tray + return S_OK; +} + +DWORD CIoSupport::GetTrayState() +{ + HalReadSMCTrayState(&m_dwTrayState, &m_dwTrayCount); + + if(m_dwTrayState == TRAY_CLOSED_MEDIA_PRESENT) + { + if (m_dwLastTrayState != TRAY_CLOSED_MEDIA_PRESENT) + { + m_dwLastTrayState = m_dwTrayState; + return DRIVE_CLOSED_MEDIA_PRESENT; + } + else + { + return DRIVE_READY; + } + } + else if(m_dwTrayState == TRAY_CLOSED_NO_MEDIA) + { + m_dwLastTrayState = m_dwTrayState; + return DRIVE_CLOSED_NO_MEDIA; + } + else if(m_dwTrayState == TRAY_OPEN) + { + m_dwLastTrayState = m_dwTrayState; + return DRIVE_OPEN; + } + else + { + m_dwLastTrayState = m_dwTrayState; + } + + return DRIVE_NOT_READY; +} + +HRESULT CIoSupport::Shutdown() +{ + HalInitiateShutdown(); + return S_OK; +} \ No newline at end of file diff --git a/xbox1/frontend/RetroLaunch/IoSupport.h b/xbox1/frontend/RetroLaunch/IoSupport.h new file mode 100644 index 0000000000..14268e6b25 --- /dev/null +++ b/xbox1/frontend/RetroLaunch/IoSupport.h @@ -0,0 +1,49 @@ +// IoSupport.h: interface for the CIoSupport class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_IOSUPPORT_H__F084A488_BD6E_49D5_8CD3_0BE62149DB40__INCLUDED_) +#define AFX_IOSUPPORT_H__F084A488_BD6E_49D5_8CD3_0BE62149DB40__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 +#ifdef _XBOX +#include +#include "global.h" + +#define TRAY_OPEN 16 +#define TRAY_CLOSED_NO_MEDIA 64 +#define TRAY_CLOSED_MEDIA_PRESENT 96 + +#define DRIVE_OPEN 0 // Open... +#define DRIVE_NOT_READY 1 // Opening.. Closing... +#define DRIVE_READY 2 +#define DRIVE_CLOSED_NO_MEDIA 3 // CLOSED...but no media in drive +#define DRIVE_CLOSED_MEDIA_PRESENT 4 // Will be send once when the drive just have closed + +class CIoSupport +{ +public: + CIoSupport(); + virtual ~CIoSupport(); + + HRESULT Mount(CHAR* szDrive, CHAR* szDevice); + HRESULT Unmount(CHAR* szDrive); + + HRESULT Remount(CHAR* szDrive, CHAR* szDevice); + HRESULT Remap(CHAR* szMapping); + + DWORD GetTrayState(); + HRESULT EjectTray(); + HRESULT CloseTray(); + HRESULT Shutdown(); +private: + DWORD m_dwTrayState; + DWORD m_dwTrayCount; + DWORD m_dwLastTrayState; +}; + +extern CIoSupport g_IOSupport; +#endif +#endif // !defined(AFX_IOSUPPORT_H__F084A488_BD6E_49D5_8CD3_0BE62149DB40__INCLUDED_) diff --git a/xbox1/frontend/RetroLaunch/MenuMain.cpp b/xbox1/frontend/RetroLaunch/MenuMain.cpp new file mode 100644 index 0000000000..eed2cad4f9 --- /dev/null +++ b/xbox1/frontend/RetroLaunch/MenuMain.cpp @@ -0,0 +1,226 @@ +/** + * RetroLaunch 2012 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the + * authors: Surreal64 CE Team (http://www.emuxtras.net) + */ + +#include "MenuMain.h" +#include "Font.h" +#include "RomList.h" + +#include "../../console/retroarch_console.h" +#include "../../general.h" + +CMenuMain g_menuMain; + +CMenuMain::CMenuMain() +{ + // we think that the rom list is unloaded until we know otherwise + m_bRomListLoadedState = false; +} + +CMenuMain::~CMenuMain() +{ +} + +bool CMenuMain::Create() +{ + RARCH_LOG("CMenuMain::Create()."); + + xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data; + + width = d3d->d3dpp.BackBufferWidth; + //height = d3d->d3dpp.BackBufferHeight; + + // Title coords with color + m_menuMainTitle_x = 305; + m_menuMainTitle_y = 30; + m_menuMainTitle_c = 0xFFFFFFFF; + + m_menuMainBG_x = 0; + m_menuMainBG_y = 0; + //m_menuMainBG_w = width; + //m_menuMainBG_h = height; + + // Quick hack to properly center the romlist in 720p, + // it might need more work though (font size and rom selector size -> needs more memory) + // Init rom list coords + // Load background image + if(width == 640) + { + m_menuMainBG.Create("D:\\Media\\menuMainBG.png"); + m_menuMainRomListPos_x = 100; + m_menuMainRomListPos_y = 100; + } + else if(width == 1280) + { + m_menuMainBG.Create("D:\\Media\\menuMainBG_720p.png"); + m_menuMainRomListPos_x = 400; + m_menuMainRomListPos_y = 150; + } + + m_menuMainRomListSpacing = 20; + + // Load rom selector panel + m_menuMainRomSelectPanel.Create("D:\\Media\\menuMainRomSelectPanel.png"); + m_menuMainRomSelectPanel_x = m_menuMainRomListPos_x - 5; + m_menuMainRomSelectPanel_y = m_menuMainRomListPos_y - 2; + m_menuMainRomSelectPanel_w = 440; + m_menuMainRomSelectPanel_h = 20; + + m_romListSelectedRom = 0; + + //The first element in the romlist to render + m_romListBeginRender = 0; + + //The last element in the romlist to render + m_romListEndRender = 18; + + //The offset in the romlist + m_romListOffset = 0; + + if(m_romListEndRender > g_romList.GetRomListSize() - 1) + m_romListEndRender = g_romList.GetRomListSize() - 1; + + //Generate the rom list textures only once + vector::iterator i; + dword y = 0; + for (i = g_romList.m_romList.begin(); i != g_romList.m_romList.end(); i++) + { + Rom *rom = *i; + g_font.RenderToTexture(rom->GetTexture(), rom->GetFileName(), 18, XFONT_BOLD, 0xff808080, -1, false); + } + + return true; +} + + +void CMenuMain::Render() +{ + //Render background image + m_menuMainBG.Render(m_menuMainBG_x, m_menuMainBG_y); + + //Display some text + //Center the text (hardcoded) + int xpos = width == 640 ? 65 : 400; + int ypos = width == 640 ? 430 : 670; + + g_font.Render("Press RSTICK THUMB to exit. Press START and/or A to launch a rom.", xpos, ypos, 16, XFONT_NORMAL, m_menuMainTitle_c); + + //Begin with the rom selector panel + //FIXME: Width/Height needs to be current Rom texture width/height (or should we just leave it at a fixed size?) + m_menuMainRomSelectPanel.Render(m_menuMainRomSelectPanel_x, m_menuMainRomSelectPanel_y, m_menuMainRomSelectPanel_w, m_menuMainRomSelectPanel_h); + + dword dwSpacing = 0; + + for (int i = m_romListBeginRender; i <= m_romListEndRender; i++) + { + g_romList.GetRomAt(i + m_romListOffset)->GetTexture().Render(m_menuMainRomListPos_x, m_menuMainRomListPos_y + dwSpacing); + dwSpacing += m_menuMainRomListSpacing; + } +} + +static uint16_t old_input_state = 0; + +void CMenuMain::ProcessInput() +{ + uint16_t input_state = 0; + input_xinput.poll(NULL); + + static const struct retro_keybind *binds[MAX_PLAYERS] = { + g_settings.input.binds[0], + g_settings.input.binds[1], + g_settings.input.binds[2], + g_settings.input.binds[3], + g_settings.input.binds[4], + g_settings.input.binds[5], + g_settings.input.binds[6], + g_settings.input.binds[7], + }; + + for (unsigned i = 0; i < RARCH_FIRST_META_KEY; i++) + { + input_state |= input_xinput.input_state(NULL, binds, false, + RETRO_DEVICE_JOYPAD, 0, i) ? (1 << i) : 0; + } + + uint16_t trigger_state = input_state & ~old_input_state; + + if(trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN)) + { + if(m_romListSelectedRom < g_romList.GetRomListSize()) + { + if(m_menuMainRomSelectPanel_y < (m_menuMainRomListPos_y + (m_menuMainRomListSpacing * m_romListEndRender))) + { + m_menuMainRomSelectPanel_y += m_menuMainRomListSpacing; + m_romListSelectedRom++; + RARCH_LOG("SELECTED ROM: %d.\n", m_romListSelectedRom); + } + + if(m_menuMainRomSelectPanel_y > (m_menuMainRomListPos_y + (m_menuMainRomListSpacing * (m_romListEndRender)))) + { + m_menuMainRomSelectPanel_y -= m_menuMainRomListSpacing; + m_romListSelectedRom++; + if(m_romListSelectedRom > g_romList.GetRomListSize() - 1) + m_romListSelectedRom = g_romList.GetRomListSize() - 1; + + RARCH_LOG("SELECTED ROM AFTER CORRECTION: %d.\n", m_romListSelectedRom); + + if(m_romListSelectedRom < g_romList.GetRomListSize() - 1 && m_romListOffset < g_romList.GetRomListSize() - 1 - m_romListEndRender - 1) + { + m_romListOffset++; + RARCH_LOG("OFFSET: %d.\n", m_romListOffset); + } + } + } + } + + if(trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_UP)) + { + if(m_romListSelectedRom > -1) + { + if(m_menuMainRomSelectPanel_y > (m_menuMainRomListPos_y - m_menuMainRomListSpacing)) + { + m_menuMainRomSelectPanel_y -= m_menuMainRomListSpacing; + m_romListSelectedRom--; + RARCH_LOG("SELECTED ROM: %d.\n", m_romListSelectedRom); + } + + if(m_menuMainRomSelectPanel_y < (m_menuMainRomListPos_y - m_menuMainRomListSpacing)) + { + m_menuMainRomSelectPanel_y += m_menuMainRomListSpacing; + m_romListSelectedRom--; + if(m_romListSelectedRom < 0) + m_romListSelectedRom = 0; + + RARCH_LOG("SELECTED ROM AFTER CORRECTION: %d.\n", m_romListSelectedRom); + + if(m_romListSelectedRom > 0 && m_romListOffset > 0) + { + m_romListOffset--; + RARCH_LOG("OFFSET: %d.\n", m_romListOffset); + } + } + } + } + + // Press A to launch, selected rom filename is saved into T:\\tmp.retro + if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_B) || trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_START)) + rarch_console_load_game(g_romList.GetRomAt(m_romListSelectedRom)->GetFileName().c_str()); + + if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_R3)) + { + LD_LAUNCH_DASHBOARD LaunchData = { XLD_LAUNCH_DASHBOARD_MAIN_MENU }; + XLaunchNewImage( NULL, (LAUNCH_DATA*)&LaunchData ); + } +} + diff --git a/xbox1/frontend/RetroLaunch/MenuMain.h b/xbox1/frontend/RetroLaunch/MenuMain.h new file mode 100644 index 0000000000..22c16ebfcc --- /dev/null +++ b/xbox1/frontend/RetroLaunch/MenuMain.h @@ -0,0 +1,82 @@ +/** + * RetroLaunch 2012 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the + * authors: Surreal64 CE Team (http://www.emuxtras.net) + */ + +#pragma once +#include "Global.h" +#include "Surface.h" + +class CMenuMain +{ +public: +CMenuMain(); +~CMenuMain(); + +bool Create(); + +void Render(); + +void ProcessInput(); + +private: +/* +Texture, +_x = xpos, +_y = ypos, +_w = width, +_h = height, +_c = color, +*/ + +// Background image with coords +CSurface m_menuMainBG; +int m_menuMainBG_x; +int m_menuMainBG_y; +dword m_menuMainBG_w; +dword m_menuMainBG_h; + +// Rom selector panel with coords +CSurface m_menuMainRomSelectPanel; +int m_menuMainRomSelectPanel_x; +int m_menuMainRomSelectPanel_y; +dword m_menuMainRomSelectPanel_w; +dword m_menuMainRomSelectPanel_h; + +// Title coords with color +int m_menuMainTitle_x; +int m_menuMainTitle_y; +dword m_menuMainTitle_c; + +// Rom list coords +int m_menuMainRomListPos_x; +int m_menuMainRomListPos_y; +int m_menuMainRomListSpacing; + +/** +* The current loaded state the rom list is in +*/ +bool m_bRomListLoadedState; + +int m_romListBeginRender; +int m_romListEndRender; +int m_romListSelectedRom; +int m_romListOffset; + +// Backbuffer width, height +int width; +int height; + +}; + +extern CMenuMain g_menuMain; diff --git a/xbox1/frontend/RetroLaunch/MenuManager.cpp b/xbox1/frontend/RetroLaunch/MenuManager.cpp new file mode 100644 index 0000000000..ae2550e010 --- /dev/null +++ b/xbox1/frontend/RetroLaunch/MenuManager.cpp @@ -0,0 +1,77 @@ +/** + * RetroLaunch 2012 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the + * authors: Surreal64 CE Team (http://www.emuxtras.net) + */ + +#include "MenuManager.h" +#include "MenuMain.h" + +#include "../../general.h" + + +CMenuManager g_menuManager; + +CMenuManager::CMenuManager() +{ +} + +CMenuManager::~CMenuManager() +{ +} + +bool CMenuManager::Create() +{ + //Create the MenuManager, set to Main Menu + RARCH_LOG("Create MenuManager, set state to MENU_MAIN.\n"); + SetMenuState(MENU_MAIN); + + return true; +} + +bool CMenuManager::SetMenuState(int nMenuID) +{ + m_pMenuID = nMenuID; + + switch (m_pMenuID) + { + case MENU_MAIN: + //Create the Main Menu + g_menuMain.Create(); + break; + } + return true; +} + +void CMenuManager::Update() +{ + ProcessInput(); + + switch (m_pMenuID) + { + case MENU_MAIN: + g_menuMain.ProcessInput(); + g_menuMain.Render(); + break; + } +} + + +void CMenuManager::ProcessInput() +{ +} + +int CMenuManager::GetMenuState() +{ + return m_pMenuID; +} + diff --git a/xbox1/frontend/RetroLaunch/MenuManager.h b/xbox1/frontend/RetroLaunch/MenuManager.h new file mode 100644 index 0000000000..6f287b5c55 --- /dev/null +++ b/xbox1/frontend/RetroLaunch/MenuManager.h @@ -0,0 +1,49 @@ +/** + * RetroLaunch 2012 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the + * authors: Surreal64 CE Team (http://www.emuxtras.net) + */ + +#pragma once + +#include "Global.h" + +enum eMenuState +{ + MENU_MAIN = 0, + MENU_SETTINGS_SELECT, + MENU_SETTINGS_EMU, + MENU_SETTINGS_AUDIO, + MENU_SETTINGS_SKIN, + MENU_LAUNCHER +}; + +class CMenuManager +{ +public: +CMenuManager(); +~CMenuManager(); + +bool Create(); +bool SetMenuState(int nMenuID); +int GetMenuState(); +bool Destroy(); +void Update(); +void ProcessInput(); + + +private: +int m_pMenuID; + +}; + +extern CMenuManager g_menuManager; diff --git a/xbox1/frontend/RetroLaunch/Rom.cpp b/xbox1/frontend/RetroLaunch/Rom.cpp new file mode 100644 index 0000000000..cf7505d91d --- /dev/null +++ b/xbox1/frontend/RetroLaunch/Rom.cpp @@ -0,0 +1,47 @@ +/** + * Surreal 64 Launcher (C) 2003 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the + * authors: email: buttza@hotmail.com, lantus@lantus-x.com + */ + +#include "Rom.h" + +Rom::Rom() +{ + m_bLoaded = false; +} + +Rom::~Rom(void) +{ +} + +bool Rom::Load(const char *szFilename) +{ + if (m_bLoaded) + return true; + + m_szFilename = szFilename; + + m_bLoaded = true; + + return true; +} + +string Rom::GetFileName() +{ + return m_szFilename; +} + +CSurface &Rom::GetTexture() +{ + return m_texture; +} \ No newline at end of file diff --git a/xbox1/frontend/RetroLaunch/Rom.h b/xbox1/frontend/RetroLaunch/Rom.h new file mode 100644 index 0000000000..c0bf815e28 --- /dev/null +++ b/xbox1/frontend/RetroLaunch/Rom.h @@ -0,0 +1,35 @@ +/** + * Surreal 64 Launcher (C) 2003 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the + * authors: email: buttza@hotmail.com, lantus@lantus-x.com + */ + +#pragma once + +#include "Global.h" +#include "Surface.h" + +class Rom +{ +public: + Rom(); + ~Rom(); + + bool Load(const char *szFilename); + + string GetFileName(); + CSurface &GetTexture(); +private: + string m_szFilename; + bool m_bLoaded; + CSurface m_texture; +}; diff --git a/xbox1/frontend/RetroLaunch/RomList.cpp b/xbox1/frontend/RetroLaunch/RomList.cpp new file mode 100644 index 0000000000..c563173704 --- /dev/null +++ b/xbox1/frontend/RetroLaunch/RomList.cpp @@ -0,0 +1,185 @@ +/** + * RetroLaunch 2012 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the + * authors: Surreal64 CE Team (http://www.emuxtras.net) + */ + +#include "RomList.h" + +RomList g_romList; + +bool RLessThan(Rom *elem1, Rom *elem2) +{ + return (elem1->GetFileName() < elem2->GetFileName()); +} + +RomList::RomList(void) +{ + m_iBaseIndex = 0; + m_bLoaded = false; + m_szRomPath = "D:\\"; +} + +RomList::~RomList(void) +{ + Destroy(); +} + +void RomList::Refresh() +{ + Destroy(); +} + +bool RomList::IsLoaded() +{ + return m_bLoaded; +} + +void RomList::AddRomToList(Rom *rom, int mode) +{ + vector *pList; + + pList = &m_romList; + + // look to see if the rom is already in the list, we dont want duplicates + for (int i = 0; i < static_cast(pList->size()); i++) + { + if (rom == (*pList)[i]) + return; + } + + pList->push_back(rom); + sort(pList->begin(), pList->end(), RLessThan); +} + +void RomList::RemoveRomFromList(Rom *rom, int mode) +{ + vector *pList; + + pList = &m_romList; + + vector::iterator i; + + // look to see if the rom is already in the list, we dont want duplicates + for (i = pList->begin(); i != pList->end(); i++) + { + if (rom == *i) + { + pList->erase(i); + return; + } + } +} + +int RomList::GetBaseIndex() +{ + if (m_iBaseIndex > GetRomListSize() - 1) + m_iBaseIndex = GetRomListSize() - 1; + if (m_iBaseIndex < 0) + m_iBaseIndex = 0; + + return m_iBaseIndex; +} + +void RomList::SetBaseIndex(int index) +{ + if (index > GetRomListSize() - 1) + index = GetRomListSize() - 1; + if (index < 0) + index = 0; + + m_iBaseIndex = index; +} + +int RomList::GetRomListSize() +{ + return m_romList.size(); +} + +Rom *RomList::GetRomAt(int index) +{ + return m_romList[index]; +} + +void RomList::CleanUpTextures() +{ + if (!IsLoaded()) + return; + + // keep the 25 textures above and below the base index + for (int i = 0; i < m_iBaseIndex - 25; i++) + m_romList[i]->GetTexture().Destroy(); + + for (int i = m_iBaseIndex + 25; i < GetRomListSize(); i++) + m_romList[i]->GetTexture().Destroy(); +} + +void RomList::DestroyAllTextures() +{ + vector::iterator i; + + for (i = m_romList.begin(); i != m_romList.end(); i++) + { + Rom *rom = *i; + rom->GetTexture().Destroy(); + } +} + +void RomList::Build() +{ + WIN32_FIND_DATA fd; + + HANDLE hFF = FindFirstFile((m_szRomPath + "*.*").c_str(), &fd); + + do + { + char ext[_MAX_EXT]; + + // get the filename extension + _splitpath((m_szRomPath + fd.cFileName).c_str(), + NULL, NULL, NULL, ext); + + if ( + stricmp(ext, ".bin") == 0 + || stricmp(ext, ".cue") == 0 + || stricmp(ext, ".iso") == 0 + || stricmp(ext, ".mdf") == 0 + || stricmp(ext, ".gba") == 0 + ) + { + Rom *rom = new Rom(); + bool bSuccess = rom->Load((m_szRomPath + fd.cFileName).c_str()); + + if (bSuccess) + m_romList.push_back(rom); + else + delete rom; + } + } while (FindNextFile(hFF, &fd)); + + sort(m_romList.begin(), m_romList.end(), RLessThan); + + m_bLoaded = true; +} + +void RomList::Destroy() +{ + m_bLoaded = false; + m_iBaseIndex = 0; + + vector::iterator i; + + for (i = m_romList.begin(); i != m_romList.end(); i++) + delete *i; + + m_romList.clear(); +} diff --git a/xbox1/frontend/RetroLaunch/RomList.h b/xbox1/frontend/RetroLaunch/RomList.h new file mode 100644 index 0000000000..d7c0171256 --- /dev/null +++ b/xbox1/frontend/RetroLaunch/RomList.h @@ -0,0 +1,57 @@ +/** + * RetroLaunch 2012 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the + * authors: Surreal64 CE Team (http://www.emuxtras.net) + */ + +#pragma once + +#include "Global.h" +#include "Rom.h" + +class RomList +{ +public: + RomList(void); + ~RomList(void); + + void Refresh(); + void Build(); + + bool IsLoaded(); + + void AddRomToList(Rom *rom, int mode); + void RemoveRomFromList(Rom *rom, int mode); + + int GetBaseIndex(); + void SetBaseIndex(int index); + + int GetRomListSize(); + + Rom *GetRomAt(int index); + + void CleanUpTextures(); + void DestroyAllTextures(); + + int m_iBaseIndex; + + vector m_romList; + +private: + void Destroy(); + +private: + bool m_bLoaded; + string m_szRomPath; +}; + +extern RomList g_romList; \ No newline at end of file diff --git a/xbox1/frontend/RetroLaunch/Surface.cpp b/xbox1/frontend/RetroLaunch/Surface.cpp new file mode 100644 index 0000000000..d4be34b64f --- /dev/null +++ b/xbox1/frontend/RetroLaunch/Surface.cpp @@ -0,0 +1,242 @@ +/** + * Surreal 64 Launcher (C) 2003 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the + * authors: email: buttza@hotmail.com, lantus@lantus-x.com + * + * Additional code and cleanups: Surreal64 CE Team (http://www.emuxtras.net) + */ + +#include "Surface.h" + +#include "../../../general.h" +#include "../../xdk_d3d8.h" + +CSurface::CSurface() +{ + m_pTexture = NULL; + m_pVertexBuffer = NULL; + m_byOpacity = 255; + m_byR = 255; + m_byG = 255; + m_byB = 255; + m_bLoaded = false; + m_x = 0; + m_y = 0; +} + +CSurface::~CSurface() +{ + Destroy(); +} + +bool CSurface::Create(const char *szFilename) +{ + xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data; + if (m_bLoaded) + Destroy(); + + HRESULT g_hResult = D3DXCreateTextureFromFileExA(d3d->d3d_render_device, // d3d device + szFilename, // filename + D3DX_DEFAULT, D3DX_DEFAULT, // width/height + D3DX_DEFAULT, // mipmaps + 0, // usage + D3DFMT_A8R8G8B8, // format + D3DPOOL_MANAGED, // memory class + D3DX_DEFAULT, // texture filter + D3DX_DEFAULT, // mipmapping + 0, // colorkey + &m_imageInfo, // image info + NULL, // pallete + &m_pTexture); // texture + + if (FAILED(g_hResult)) + { + RARCH_ERR("Error occurred during D3DXCreateTextureFromFileExA().\n"); + return false; + } + + // create a vertex buffer for the quad that will display the texture + g_hResult = d3d->d3d_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), + D3DUSAGE_WRITEONLY, + D3DFVF_CUSTOMVERTEX, + D3DPOOL_MANAGED, &m_pVertexBuffer); + if (FAILED(g_hResult)) + { + RARCH_ERR("Error occurred during CreateVertexBuffer().\n"); + m_pTexture->Release(); + return false; + } + + m_bLoaded = true; + + return true; +} + +bool CSurface::Create(dword width, dword height) +{ + xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data; + if (m_bLoaded) + Destroy(); + + HRESULT g_hResult = d3d->d3d_render_device->CreateTexture(width, height, 1, 0, + D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, + &m_pTexture); + + if (FAILED(g_hResult)) + { + RARCH_ERR("Error occurred during CreateTexture().\n"); + return false; + } + + m_imageInfo.Width = width; + m_imageInfo.Height = height; + m_imageInfo.Format = D3DFMT_A8R8G8B8; + + // create a vertex buffer for the quad that will display the texture + g_hResult = d3d->d3d_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), + D3DUSAGE_WRITEONLY, + D3DFVF_CUSTOMVERTEX, + D3DPOOL_MANAGED, &m_pVertexBuffer); + if (FAILED(g_hResult)) + { + RARCH_ERR("Error occurred during CreateVertexBuffer().\n"); + m_pTexture->Release(); + return false; + } + + m_bLoaded = true; + + return true; +} + +void CSurface::Destroy() +{ + // free the vertex buffer + if (m_pVertexBuffer) + { + m_pVertexBuffer->Release(); + m_pVertexBuffer = NULL; + } + + // free the texture + if (m_pTexture) + { + m_pTexture->Release(); + m_pTexture = NULL; + } + + m_bLoaded = false; +} + +bool CSurface::IsLoaded() +{ + return m_bLoaded; +} + +bool CSurface::Render() +{ + return Render(m_x, m_y); +} + +bool CSurface::Render(int x, int y) +{ + return Render(x, y, m_imageInfo.Width, m_imageInfo.Height); +} + +bool CSurface::Render(int x, int y, dword w, dword h) +{ + xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data; + if (m_pTexture == NULL || m_pVertexBuffer == NULL || m_bLoaded == false) + return false; + + float fX = static_cast(x); + float fY = static_cast(y); + + // create the new vertices + /*CustomVertex*/DrawVerticeFormats newVerts[] = + { + // x, y, z, color, u ,v + {fX, fY, 0.0f, /*D3DCOLOR_ARGB(m_byOpacity, m_byR, m_byG, m_byB),*/ 0, 0, 0}, + {fX + w, fY, 0.0f, /*D3DCOLOR_ARGB(m_byOpacity, m_byR, m_byG, m_byB),*/ 0, 1, 0}, + {fX + w, fY + h, 0.0f, /*D3DCOLOR_ARGB(m_byOpacity, m_byR, m_byG, m_byB),*/ 0, 1, 1}, + {fX, fY + h, 0.0f, /*D3DCOLOR_ARGB(m_byOpacity, m_byR, m_byG, m_byB),*/ 0, 0, 1} + }; + + // load the existing vertices + /*CustomVertex*/DrawVerticeFormats *pCurVerts; + + HRESULT g_hResult = m_pVertexBuffer->Lock(0, 0, (byte **)&pCurVerts, 0); + + if (FAILED(g_hResult)) + { + RARCH_ERR("Error occurred during m_pVertexBuffer->Lock().\n"); + return false; + } + // copy the new verts over the old verts + memcpy(pCurVerts, newVerts, 4 * sizeof(DrawVerticeFormats)); + + m_pVertexBuffer->Unlock(); + + + d3d->d3d_render_device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); + d3d->d3d_render_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); + d3d->d3d_render_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); + + // also blend the texture with the set alpha value + d3d->d3d_render_device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); + d3d->d3d_render_device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE); + d3d->d3d_render_device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE); + + // draw the quad + d3d->d3d_render_device->SetTexture(0, m_pTexture); + d3d->d3d_render_device->SetStreamSource(0, m_pVertexBuffer, sizeof(DrawVerticeFormats)); + d3d->d3d_render_device->SetVertexShader(D3DFVF_CUSTOMVERTEX); + d3d->d3d_render_device->DrawPrimitive(D3DPT_QUADLIST, 0, 1); + return true; +} + +void CSurface::SetOpacity(byte opacity) +{ + m_byOpacity = opacity; +} + +void CSurface::MoveTo(int x, int y) +{ + m_x = x; + m_y = y; +} + +dword CSurface::GetWidth() +{ + if (m_pTexture == NULL || m_pVertexBuffer == NULL) + return 0; + + return m_imageInfo.Width; +} + +dword CSurface::GetHeight() +{ + if (m_pTexture == NULL || m_pVertexBuffer == NULL) + return 0; + + return m_imageInfo.Height; +} + +byte CSurface::GetOpacity() +{ + return m_byOpacity; +} + +IDirect3DTexture8 *CSurface::GetTexture() +{ + return m_pTexture; +} diff --git a/xbox1/frontend/RetroLaunch/Surface.h b/xbox1/frontend/RetroLaunch/Surface.h new file mode 100644 index 0000000000..13766af62f --- /dev/null +++ b/xbox1/frontend/RetroLaunch/Surface.h @@ -0,0 +1,87 @@ +/** + * Surreal 64 Launcher (C) 2003 + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the + * authors: email: buttza@hotmail.com, lantus@lantus-x.com + * + * Additional code and cleanups: Surreal64 CE Team (http://www.emuxtras.net) + */ + +#pragma once + +#include "Global.h" + +class CSurface +{ +public: + CSurface(); + ~CSurface(); + + /** + * Do functions + */ + bool Create(const char *szFilename); + bool Create(dword width, dword height); + void Destroy(); + + bool IsLoaded(); + + bool Render(); + bool Render(int x, int y); + bool Render(int x, int y, dword w, dword h); + + /** + * Set functions + */ + void SetOpacity(byte opacity); + + void MoveTo(int x, int y); + + /** + * Get functions + */ + dword GetWidth(); + dword GetHeight(); + + byte GetOpacity(); + + IDirect3DTexture8 *GetTexture(); + +private: + /** + * A d3d texture object that will contain the loaded texture + * and a d3d vertex buffer object that will contain the vertex + * buffer for the quad which will display the texture + */ + IDirect3DTexture8 *m_pTexture; + IDirect3DVertexBuffer8 *m_pVertexBuffer; + + /** + * The default render position of the texture + */ + int m_x, m_y; + + /** + * The width and height of the texture + */ + D3DXIMAGE_INFO m_imageInfo; + + /** + * The opacity of the texture + */ + byte m_byOpacity; + byte m_byR, m_byG, m_byB; + + /** + * Whether the texture has been created or not + */ + bool m_bLoaded; +}; diff --git a/xbox1/frontend/RetroLaunch/Undocumented.h b/xbox1/frontend/RetroLaunch/Undocumented.h new file mode 100644 index 0000000000..927280241d --- /dev/null +++ b/xbox1/frontend/RetroLaunch/Undocumented.h @@ -0,0 +1,1373 @@ +// Thanks and credit to everlame, Team Evox, and Woodoo. +// +// This file contains declarations for accessing the internal NT API. +// Some calls have changed from NT, so be careful! +// +// For the most part, all NT calls use ANSI instead of Unicode strings now. +// +// It is not known which flags work. You will have to experiment. + +#ifndef __XBOX_INTERNAL_H__ +#define __XBOX_INTERNAL_H__ + +#include + +// Do extern "C" for C++ +#if defined(__cplusplus) && !defined(XBOXINTERNAL_NO_EXTERN_C) +extern "C" { +#endif // __cplusplus + + +// Don't do __declspec(dllimport) for things like emulators +#if defined(NTSYSAPI) && defined(DONT_IMPORT_INTERNAL) +#undef NTSYSAPI +#endif +#ifdef DONT_IMPORT_INTERNAL +#define NTSYSAPI +#endif + +// The normal headers don't have this...? +#define FASTCALL __fastcall + +// The usual NTSTATUS +typedef LONG NTSTATUS; + +// The usual NT_SUCCESS +#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0) + +// Just for documentation +#define EXPORTNUM(x) + + +// Needed for object structures and related things +typedef CONST SHORT CSHORT; + + +// String types +typedef CHAR *PSZ; +typedef CONST CHAR *PCSZ; + +// ANSI_STRING +// Differences from NT: None. +typedef struct _STRING { + USHORT Length; + USHORT MaximumLength; + PCHAR Buffer; +} STRING; +typedef STRING *PSTRING; + +typedef STRING ANSI_STRING; +typedef PSTRING PANSI_STRING; + + +// IO Status Block type (UNVERIFIED) +// Differences from NT: None. +typedef struct _IO_STATUS_BLOCK { + union { + NTSTATUS Status; + PVOID Pointer; + }; + + ULONG_PTR Information; +} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK; + +// APC routine +typedef +VOID +(NTAPI *PIO_APC_ROUTINE) ( + IN PVOID ApcContext, + IN PIO_STATUS_BLOCK IoStatusBlock, + IN ULONG Reserved + ); + + +// Header for dispatcher objects +// Differences from NT: None. +typedef struct _DISPATCHER_HEADER { + UCHAR Type; + UCHAR Absolute; + UCHAR Size; + UCHAR Inserted; + LONG SignalState; + LIST_ENTRY WaitListHead; +} DISPATCHER_HEADER; + + +// Object types +#define NotificationTimerObject 8 +#define SynchronizationTimerObject 9 +#define DpcObject 19 + + +// Object Attributes type +// Differences from NT: There are no Length, SecurityDescriptor, or +// SecurityQualityOfService fields. Also, ObjectName is ANSI, not +// Unicode. +typedef struct _OBJECT_ATTRIBUTES { + HANDLE RootDirectory; + PANSI_STRING ObjectName; + ULONG Attributes; +} OBJECT_ATTRIBUTES; +typedef OBJECT_ATTRIBUTES *POBJECT_ATTRIBUTES; + +// Flags for OBJECT_ATTRIBUTES::Attributes +#define OBJ_INHERIT 0x00000002L +#define OBJ_PERMANENT 0x00000010L +#define OBJ_EXCLUSIVE 0x00000020L +#define OBJ_CASE_INSENSITIVE 0x00000040L +#define OBJ_OPENIF 0x00000080L +#define OBJ_OPENLINK 0x00000100L +#define OBJ_KERNEL_HANDLE 0x00000200L +#define OBJ_VALID_ATTRIBUTES 0x000003F2L + +// Initializes an OBJECT_ATTRIBUTES. +// Works as if it were this function: +// VOID +// InitializeObjectAttributes( +// OUT POBJECT_ATTRIBUTES p, +// IN PANSI_STRING n, +// IN ULONG a, +// IN HANDLE r +// ) +// Differences from NT: SECURITY_DESCRIPTOR support is gone. +#define InitializeObjectAttributes( p, n, a, r ) { \ + (p)->RootDirectory = r; \ + (p)->Attributes = a; \ + (p)->ObjectName = n; \ + } + + +// CreateDisposition values for NtCreateFile() +#define FILE_SUPERSEDE 0x00000000 +#define FILE_OPEN 0x00000001 +#define FILE_CREATE 0x00000002 +#define FILE_OPEN_IF 0x00000003 +#define FILE_OVERWRITE 0x00000004 +#define FILE_OVERWRITE_IF 0x00000005 +#define FILE_MAXIMUM_DISPOSITION 0x00000005 + +// CreateOption values for NtCreateFile() +// FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT is what CreateFile +// uses for most things when translating to NtCreateFile. +#define FILE_DIRECTORY_FILE 0x00000001 +#define FILE_WRITE_THROUGH 0x00000002 +#define FILE_SEQUENTIAL_ONLY 0x00000004 +#define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008 +#define FILE_SYNCHRONOUS_IO_ALERT 0x00000010 +#define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020 +#define FILE_NON_DIRECTORY_FILE 0x00000040 +#define FILE_CREATE_TREE_CONNECTION 0x00000080 +#define FILE_COMPLETE_IF_OPLOCKED 0x00000100 +#define FILE_NO_EA_KNOWLEDGE 0x00000200 +#define FILE_OPEN_FOR_RECOVERY 0x00000400 +#define FILE_RANDOM_ACCESS 0x00000800 +#define FILE_DELETE_ON_CLOSE 0x00001000 +#define FILE_OPEN_BY_FILE_ID 0x00002000 +#define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000 +#define FILE_NO_COMPRESSION 0x00008000 +#define FILE_RESERVE_OPFILTER 0x00100000 +#define FILE_OPEN_REPARSE_POINT 0x00200000 +#define FILE_OPEN_NO_RECALL 0x00400000 +#define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000 +#define FILE_COPY_STRUCTURED_STORAGE 0x00000041 +#define FILE_STRUCTURED_STORAGE 0x00000441 +#define FILE_VALID_OPTION_FLAGS 0x00ffffff +#define FILE_VALID_PIPE_OPTION_FLAGS 0x00000032 +#define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032 +#define FILE_VALID_SET_FLAGS 0x00000036 + + +// NtQueryVolumeInformation / NtSetVolumeInformation stuff +// Type of information to retrieve; FileFsSizeInformation and +// FileFsDeviceInformation are the only ones confirmed to work. +typedef enum _FSINFOCLASS { + FileFsVolumeInformation = 1, + FileFsLabelInformation, + FileFsSizeInformation, + FileFsDeviceInformation, + FileFsAttributeInformation, + FileFsControlInformation, + FileFsFullSizeInformation, + FileFsObjectInformation +} FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS; + +// Structure of FileFsSizeInformation +typedef struct _FILE_FS_SIZE_INFORMATION { + LARGE_INTEGER TotalAllocationUnits; + LARGE_INTEGER AvailableAllocationUnits; + ULONG SectorsPerAllocationUnit; + ULONG BytesPerSector; +} FILE_FS_SIZE_INFORMATION, *PFILE_FS_SIZE_INFORMATION; + +#define DEVICE_TYPE ULONG + +// Structure of FileFsDeviceInformation +typedef struct _FILE_FS_DEVICE_INFORMATION { + DEVICE_TYPE DeviceType; + ULONG Characteristics; +} FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION; + +// DEVICE_TYPEs (I took a guess as to which the XBOX might have.) +#define FILE_DEVICE_CD_ROM 0x00000002 +#define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003 +#define FILE_DEVICE_CONTROLLER 0x00000004 +#define FILE_DEVICE_DISK 0x00000007 +#define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008 +#define FILE_DEVICE_FILE_SYSTEM 0x00000009 +#define FILE_DEVICE_NULL 0x00000015 +#define FILE_DEVICE_SCREEN 0x0000001c +#define FILE_DEVICE_SOUND 0x0000001d +#define FILE_DEVICE_UNKNOWN 0x00000022 +#define FILE_DEVICE_VIDEO 0x00000023 +#define FILE_DEVICE_VIRTUAL_DISK 0x00000024 +#define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034 + +// Characteristics +#define FILE_REMOVABLE_MEDIA 0x00000001 +#define FILE_READ_ONLY_DEVICE 0x00000002 +#define FILE_FLOPPY_DISKETTE 0x00000004 +#define FILE_WRITE_ONCE_MEDIA 0x00000008 +#define FILE_REMOTE_DEVICE 0x00000010 +#define FILE_DEVICE_IS_MOUNTED 0x00000020 +#define FILE_VIRTUAL_VOLUME 0x00000040 +#define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080 +#define FILE_DEVICE_SECURE_OPEN 0x00000100 + + + +// Physical address +// Differences from NT: 32 bit address instead of 64. +typedef ULONG PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS; + + +// NtCreateFile/NtOpenFile stuff +#define FILE_SUPERSEDED 0x00000000 +#define FILE_OPENED 0x00000001 +#define FILE_CREATED 0x00000002 +#define FILE_OVERWRITTEN 0x00000003 +#define FILE_EXISTS 0x00000004 +#define FILE_DOES_NOT_EXIST 0x00000005 + +// NtReadFile/NtWriteFile stuff +#define FILE_WRITE_TO_END_OF_FILE 0xffffffff +#define FILE_USE_FILE_POINTER_POSITION 0xfffffffe + + + +// DeviceIoControl stuff + +// Device types +#define FILE_DEVICE_CD_ROM 0x00000002 +#define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003 +#define FILE_DEVICE_CONTROLLER 0x00000004 +#define FILE_DEVICE_SCSI FILE_DEVICE_CONTROLLER +#define IOCTL_SCSI_BASE FILE_DEVICE_CONTROLLER +#define FILE_DEVICE_DISK 0x00000007 +#define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008 +#define FILE_DEVICE_DVD 0x00000033 + +// Access types +#define FILE_ANY_ACCESS 0 +#define FILE_READ_ACCESS ( 0x0001 ) // file & pipe +#define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe + +// Method types +#define METHOD_BUFFERED 0 +#define METHOD_IN_DIRECT 1 +#define METHOD_OUT_DIRECT 2 +#define METHOD_NEITHER 3 + +// The all-important CTL_CODE +#define CTL_CODE( DeviceType, Function, Method, Access ) ( \ + ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \ +) + +// IDE/SCSI codes +// IOCTL_SCSI_PASS_THROUGH_DIRECT is the only one known to be used. +// Differences from NT: None. +#define IOCTL_SCSI_PASS_THROUGH CTL_CODE(IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) +#define IOCTL_SCSI_MINIPORT CTL_CODE(IOCTL_SCSI_BASE, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) +#define IOCTL_SCSI_GET_INQUIRY_DATA CTL_CODE(IOCTL_SCSI_BASE, 0x0403, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE(IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE(IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) +#define IOCTL_SCSI_GET_ADDRESS CTL_CODE(IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_SCSI_RESCAN_BUS CTL_CODE(IOCTL_SCSI_BASE, 0x0407, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_SCSI_GET_DUMP_POINTERS CTL_CODE(IOCTL_SCSI_BASE, 0x0408, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_SCSI_FREE_DUMP_POINTERS CTL_CODE(IOCTL_SCSI_BASE, 0x0409, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_IDE_PASS_THROUGH CTL_CODE(IOCTL_SCSI_BASE, 0x040a, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) + +// Special XBOX code? +#define IOCTL_CDROM_AUTHENTICATE_DISK CTL_CODE(FILE_DEVICE_CD_ROM, 0x0020, METHOD_BUFFERED, FILE_READ_ACCESS) + +// Structure for IOCTL_SCSI_PASS_THROUGH_DIRECT +// Differences from NT: None, believe it or not. +typedef struct _SCSI_PASS_THROUGH_DIRECT { + /*000*/ USHORT Length; + /*002*/ UCHAR ScsiStatus; + /*003*/ UCHAR PathId; + /*004*/ UCHAR TargetId; + /*005*/ UCHAR Lun; + /*006*/ UCHAR CdbLength; + /*007*/ UCHAR SenseInfoLength; + /*008*/ UCHAR DataIn; + /*00C*/ ULONG DataTransferLength; + /*010*/ ULONG TimeOutValue; + /*014*/ PVOID DataBuffer; + /*018*/ ULONG SenseInfoOffset; + /*01C*/ UCHAR Cdb[16]; +}SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT; + +// DataIn fields for IOCTL_SCSI_PASS_THROUGH_DIRECT +#define SCSI_IOCTL_DATA_OUT 0 +#define SCSI_IOCTL_DATA_IN 1 +#define SCSI_IOCTL_DATA_UNSPECIFIED 2 + +// Kernel object type (unsure about the structure...) +typedef struct _OBJECT_TYPE +{ + // Same prototype as ExAllocatePoolWithTag, because that's the usual one + PVOID + (NTAPI *AllocationFunction)( + SIZE_T NumberOfBytes, + ULONG Tag + ); + + // Same prototype as ExFreePool, because that's the usual one + VOID + (NTAPI *FreeFunction)( + IN PVOID P + ); + + // The prototypes of these are unknown + void *CloseFunction; + void *DeleteFunction; + void *ParseFunction; + + // Unknown DWORD... Size of this object type maybe? + void *DefaultObjectMaybe; + + // 4 letter tag for this object type + CHAR Tag[4]; +} OBJECT_TYPE; +typedef OBJECT_TYPE *POBJECT_TYPE; + +// Object types +extern POBJECT_TYPE IoFileObjectType; +extern POBJECT_TYPE ExEventObjectType; +extern POBJECT_TYPE ExSemaphoreObjectType; +extern POBJECT_TYPE IoCompletionObjectType; +extern POBJECT_TYPE IoDeviceObjectType; + + +// *_OBJECT and related structures (mostly opaque since I'm lazy) +typedef struct _DRIVER_OBJECT { + CSHORT Type; + CSHORT Size; + struct _DEVICE_OBJECT *DeviceObject; + // ... +} DRIVER_OBJECT; +typedef DRIVER_OBJECT *PDRIVER_OBJECT; + +typedef struct _DEVICE_OBJECT { + CSHORT Type; + USHORT Size; + LONG ReferenceCount; + PDRIVER_OBJECT DriverObject; + // ... +} DEVICE_OBJECT; +typedef DEVICE_OBJECT *PDEVICE_OBJECT; + +typedef struct _FILE_OBJECT { + CSHORT Type; + CSHORT Size; + PDEVICE_OBJECT DeviceObject; + // ... +} FILE_OBJECT; +typedef FILE_OBJECT *PFILE_OBJECT; + + +// Thread information structures + +// IRQL +typedef UCHAR KIRQL, *PKIRQL; +#define PASSIVE_LEVEL 0 // Passive release level +#define LOW_LEVEL 0 // Lowest interrupt level +#define APC_LEVEL 1 // APC interrupt level +#define DISPATCH_LEVEL 2 // Dispatcher level + +// Thread entry point +// NOTE: This is not a standard call! You can't call this function from C code! +// You push registers like stdcall, but ebp + 4 must point to the first argument before the call! +// +// Differences from NT: 2 parameters instead of 1; strange calling convention +typedef +VOID +(NTAPI *PKSTART_ROUTINE) ( + IN PVOID StartContext1, + IN PVOID StartContext2 + ); + +// Structure of a critical section +// Same as the XBOX's RTL_CRITICAL_SECTION, but with the more explicit header +typedef struct _KCRITICAL_SECTION +{ + // 000 Dispatcher header + DISPATCHER_HEADER Header; + // 010 Lock count of the critical section + LONG LockCount; + // 014 Recursion count of the critical section + LONG RecursionCount; + // 018 Thread ID of the thread that currently owns this critical section + ULONG OwningThread; +} KCRITICAL_SECTION, *PKCRITICAL_SECTION; + +// Structure of a thread object +typedef struct _KTHREAD +{ + // 000 Dispatcher header + DISPATCHER_HEADER Header; + // 010 Unknown + BYTE unknown[0x18]; + // 028 Pointer to TLS data + PVOID TlsData; + // ??? just padding - real size is unknown + BYTE unknown2[0x100]; +} KTHREAD, *PKTHREAD; + +// Structure of the data at FS +typedef struct _FS_STRUCTURE +{ + // 000 Current exception handler information + PVOID *ExceptionFrame; + // 004 Pointer to current TLS data top + PVOID TlsDataTop; + // 008 + BYTE unknown2[0x1C]; + // 024 Current IRQL of the OS + KIRQL CurrentIrql; + // 028 Thread structure of the current thread + PKTHREAD ThreadObject; + // ??? just padding - real size is unknown + BYTE unknown3[0x100]; +} FS_STRUCTURE, *PFS_STRUCTURE; + +// DPC routine +typedef +VOID +(*PKDEFERRED_ROUTINE) ( + IN struct _KDPC *Dpc, + IN PVOID DeferredContext, + IN PVOID SystemArgument1, + IN PVOID SystemArgument2 + ); + +// DPC information +// It's not known which of these fields are used on XBOX. +typedef struct _KDPC { + CSHORT Type; + UCHAR Number; + UCHAR Importance; + LIST_ENTRY DpcListEntry; + PKDEFERRED_ROUTINE DeferredRoutine; + PVOID DeferredContext; + PVOID SystemArgument1; + PVOID SystemArgument2; + PULONG_PTR Lock; +} KDPC, *PKDPC; + + +// Timers +typedef enum _TIMER_TYPE { + NotificationTimer, + SynchronizationTimer + } TIMER_TYPE; + +typedef struct _KTIMER { + DISPATCHER_HEADER Header; + ULARGE_INTEGER DueTime; + LIST_ENTRY TimerListEntry; + struct _KDPC *Dpc; + LONG Period; +} KTIMER, *PKTIMER; + + + +// XBE stuff +// Not used in any exported kernel calls, but still useful. + + +// XBE header information +typedef struct _XBE_HEADER { + // 000 "XBEH" + CHAR Magic[4]; + // 004 RSA digital signature of the entire header area + UCHAR HeaderSignature[256]; + // 104 Base address of XBE image (must be 0x00010000?) + PVOID BaseAddress; + // 108 Size of all headers combined - other headers must be within this + ULONG HeaderSize; + // 10C Size of entire image + ULONG ImageSize; + // 110 Size of this header (always 0x178?) + ULONG XbeHeaderSize; + // 114 Image timestamp - unknown format + ULONG Timestamp; + // 118 Pointer to certificate data (must be within HeaderSize) + struct _XBE_CERTIFICATE *Certificate; + // 11C Number of sections + DWORD NumSections; + // 120 Pointer to section headers (must be within HeaderSize) + struct _XBE_SECTION *Sections; + // 124 Initialization flags + ULONG InitFlags; + // 128 Entry point (XOR'd; see xboxhacker.net) + PVOID EntryPoint; + // 12C Pointer to TLS directory + struct _XBE_TLS_DIRECTORY *TlsDirectory; + // 130 Stack commit size + ULONG StackCommit; + // 134 Heap reserve size + ULONG HeapReserve; + // 138 Heap commit size + ULONG HeapCommit; + // 13C PE base address (?) + PVOID PeBaseAddress; + // 140 PE image size (?) + ULONG PeImageSize; + // 144 PE checksum (?) + ULONG PeChecksum; + // 148 PE timestamp (?) + ULONG PeTimestamp; + // 14C PC path and filename to EXE file from which XBE is derived + PCSZ PcExePath; + // 150 PC filename (last part of PcExePath) from which XBE is derived + PCSZ PcExeFilename; + // 154 PC filename (Unicode version of PcExeFilename) + PWSTR PcExeFilenameUnicode; + // 158 Pointer to kernel thunk table (XOR'd; EFB1F152 debug) + ULONG_PTR *KernelThunkTable; + // 15C Non-kernel import table (debug only) + PVOID DebugImportTable; + // 160 Number of library headers + ULONG NumLibraries; + // 164 Pointer to library headers + struct _XBE_LIBRARY *Libraries; + // 168 Pointer to kernel library header + struct _XBE_LIBRARY *KernelLibrary; + // 16C Pointer to XAPI library + struct _XBE_LIBRARY *XapiLibrary; + // 170 Pointer to logo bitmap (NULL = use default of Microsoft) + PVOID LogoBitmap; + // 174 Size of logo bitmap + ULONG LogoBitmapSize; + // 178 +} XBE_HEADER, *PXBE_HEADER; + +// Certificate structure +typedef struct _XBE_CERTIFICATE { + // 000 Size of certificate + ULONG Size; + // 004 Certificate timestamp (unknown format) + ULONG Timestamp; + // 008 Title ID + ULONG TitleId; + // 00C Name of the game (Unicode) + WCHAR TitleName[40]; + // 05C Alternate title ID's (0-terminated) + ULONG AlternateTitleIds[16]; + // 09C Allowed media types - 1 bit match between XBE and media = boots + ULONG MediaTypes; + // 0A0 Allowed game regions - 1 bit match between this and XBOX = boots + ULONG GameRegion; + // 0A4 Allowed game ratings - 1 bit match between this and XBOX = boots + ULONG GameRating; + // 0A8 Disk number (?) + ULONG DiskNumber; + // 0AC Version (?) + ULONG Version; + // 0B0 LAN key for this game + UCHAR LanKey[16]; + // 0C0 Signature key for this game + UCHAR SignatureKey[16]; + // 0D0 Signature keys for the alternate title ID's + UCHAR AlternateSignatureKeys[16][16]; + // 1D0 +} XBE_CERTIFICATE, *PXBE_CERTIFICATE; + +// Section headers +typedef struct _XBE_SECTION { + // 000 Flags + ULONG Flags; + // 004 Virtual address (where this section loads in RAM) + PVOID VirtualAddress; + // 008 Virtual size (size of section in RAM; after FileSize it's 00'd) + ULONG VirtualSize; + // 00C File address (where in the file from which this section comes) + ULONG FileAddress; + // 010 File size (size of the section in the XBE file) + ULONG FileSize; + // 014 Pointer to section name + PCSZ SectionName; + // 018 Section reference count - when >= 1, section is loaded + LONG SectionReferenceCount; + // 01C Pointer to head shared page reference count + WORD *HeadReferenceCount; + // 020 Pointer to tail shared page reference count + WORD *TailReferenceCount; + // 024 SHA hash. Hash DWORD containing FileSize, then hash section. + DWORD ShaHash[5]; + // 038 +} XBE_SECTION, *PXBE_SECTION; + +// TLS directory information needed later +// Library version data needed later + +// Initialization flags +#define XBE_INIT_MOUNT_UTILITY 0x00000001 +#define XBE_INIT_FORMAT_UTILITY 0x00000002 +#define XBE_INIT_64M_RAM_ONLY 0x00000004 +#define XBE_INIT_DONT_SETUP_HDD 0x00000008 + +// Region codes +#define XBE_REGION_US_CANADA 0x00000001 +#define XBE_REGION_JAPAN 0x00000002 +#define XBE_REGION_ELSEWHERE 0x00000004 +#define XBE_REGION_DEBUG 0x80000000 + +// Media types +#define XBE_MEDIA_HDD 0x00000001 +#define XBE_MEDIA_XBOX_DVD 0x00000002 +#define XBE_MEDIA_ANY_CD_OR_DVD 0x00000004 +#define XBE_MEDIA_CD 0x00000008 +#define XBE_MEDIA_1LAYER_DVDROM 0x00000010 +#define XBE_MEDIA_2LAYER_DVDROM 0x00000020 +#define XBE_MEDIA_1LAYER_DVDR 0x00000040 +#define XBE_MEDIA_2LAYER_DVDR 0x00000080 +#define XBE_MEDIA_USB 0x00000100 +#define XBE_MEDIA_ALLOW_UNLOCKED_HDD 0x40000000 + +// Section flags +#define XBE_SEC_WRITABLE 0x00000001 +#define XBE_SEC_PRELOAD 0x00000002 +#define XBE_SEC_EXECUTABLE 0x00000004 +#define XBE_SEC_INSERTED_FILE 0x00000008 +#define XBE_SEC_RO_HEAD_PAGE 0x00000010 +#define XBE_SEC_RO_TAIL_PAGE 0x00000020 + + +// x86 page size +#define PAGE_SIZE 0x1000 + + +// Native NT API calls on the XBOX + + +// PAGE_ALIGN: +// Returns an address rounded down to the nearest page boundary. +// +// Differences from NT: None. +#define PAGE_ALIGN(Va) ((PVOID)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1))) + + +// RtlInitAnsiString: +// Fills an ANSI_STRING structure to use the specified string. +// +// Differences from NT: None. +NTSYSAPI +EXPORTNUM(289) +VOID +NTAPI +RtlInitAnsiString( + OUT PANSI_STRING DestinationString, + IN PCSZ SourceString + ); + + +// NtCreateFile: +// Creates or opens a file or device object. +// +// Differences from NT: The EaBuffer and EaLength options are gone. +// OBJECT_ATTRIBUTES uses ANSI_STRING, so only ANSI filenames work. +NTSYSAPI +EXPORTNUM(190) +NTSTATUS +NTAPI +NtCreateFile( + OUT PHANDLE FileHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN PLARGE_INTEGER AllocationSize OPTIONAL, + IN ULONG FileAttributes, + IN ULONG ShareAccess, + IN ULONG CreateDisposition, + IN ULONG CreateOptions + ); + +// NtOpenFile: +// Opens a file or device object. Same as calling: +// NtCreateFile(FileHandle, DesiredAccess, ObjectAttributes, +// IoStatusBlock, NULL, 0, ShareAccess, OPEN_EXISTING, OpenOptions); +// +// Differences from NT: See NtCreateFile. +NTSYSAPI +EXPORTNUM(202) +NTSTATUS +NTAPI +NtOpenFile( + OUT PHANDLE FileHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN ULONG ShareAccess, + IN ULONG OpenOptions + ); + +// NtReadFile: +// Reads a file. +// +// Differences from NT: There is no Key parameter. +NTSYSAPI +EXPORTNUM(219) +NTSTATUS +NTAPI +NtReadFile( + IN HANDLE FileHandle, + IN HANDLE Event OPTIONAL, + IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, + IN PVOID ApcContext OPTIONAL, + OUT PIO_STATUS_BLOCK IoStatusBlock, + OUT PVOID Buffer, + IN ULONG Length, + IN PLARGE_INTEGER ByteOffset + ); + +// NtWriteFile: +// Writes a file. +// +// Differences from NT: There is no Key parameter. +NTSYSAPI +EXPORTNUM(236) +NTSTATUS +NTAPI +NtWriteFile( + IN HANDLE FileHandle, + IN HANDLE Event OPTIONAL, + IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, + IN PVOID ApcContext OPTIONAL, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN PVOID Buffer, + IN ULONG Length, + IN PLARGE_INTEGER ByteOffset + ); + +// NtQueryVolumeInformation: +// Queries information about a file system. This is not documented by +// Microsoft even under NT. +// +// Differences from NT: None known. +NTSYSAPI +EXPORTNUM(218) +NTSTATUS +NTAPI +NtQueryVolumeInformationFile( + IN HANDLE FileHandle, + OUT PIO_STATUS_BLOCK IoStatusBlock, + OUT PVOID VolumeInformation, + IN ULONG VolumeInformationLength, + IN FS_INFORMATION_CLASS VolumeInformationClass + ); + +// NtDeviceIoControl: +// Does an IOCTL on a device. +// +// Differences from NT: None known. +NTSYSAPI +EXPORTNUM(196) +NTSTATUS +NTAPI +NtDeviceIoControlFile( + IN HANDLE FileHandle, + IN HANDLE Event OPTIONAL, + IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, + IN PVOID ApcContext OPTIONAL, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN ULONG IoControlCode, + IN PVOID InputBuffer OPTIONAL, + IN ULONG InputBufferLength, + OUT PVOID OutputBuffer OPTIONAL, + IN ULONG OutputBufferLength + ); + +// NtClose: +// Closes a file or other handle. +// +// Differences from NT: None. +NTSYSAPI +EXPORTNUM(187) +NTSTATUS +NTAPI +NtClose( + IN HANDLE Handle + ); + +// NtAllocateVirtualMemory: +// Allocates virtual memory. +// +// Differences from NT: There is no ProcessHandle parameter. +NTSYSAPI +EXPORTNUM(184) +NTSTATUS +NTAPI +NtAllocateVirtualMemory( + IN OUT PVOID *BaseAddress, + IN ULONG ZeroBits, + IN OUT PULONG AllocationSize, + IN ULONG AllocationType, + IN ULONG Protect + ); + +// NtFreeVirtualMemory: +// Frees virtual memory. +// +// Differences from NT: There is no ProcessHandle parameter. +NTSYSAPI +EXPORTNUM(199) +NTSTATUS +NTAPI +NtFreeVirtualMemory( + IN OUT PVOID *BaseAddress, + IN OUT PULONG FreeSize, + IN ULONG FreeType + ); + + +// Kernel-level routines + + +// KeBugCheck: +// Bug checks the kernel. +// Same as KeBugCheckEx(BugCheckCode, 0, 0, 0, 0); +// +// Differences from NT: None, other than the reaction. +NTSYSAPI +EXPORTNUM(95) +VOID +NTAPI +KeBugCheck( + IN ULONG BugCheckCode + ); + +// KeBugCheckEx: +// Bug checks the kernel. +// +// Differences from NT: None, other than the reaction. +NTSYSAPI +EXPORTNUM(96) +VOID +NTAPI +KeBugCheckEx( + IN ULONG BugCheckCode, + IN ULONG_PTR BugCheckParameter1, + IN ULONG_PTR BugCheckParameter2, + IN ULONG_PTR BugCheckParameter3, + IN ULONG_PTR BugCheckParameter4 + ); + +// KeInitializeDpc: +// Initializes a DPC structure. +// +// Differences from NT: This function sets less fields than the NT version. +NTSYSAPI +EXPORTNUM(107) +VOID +NTAPI +KeInitializeDpc( + IN PKDPC Dpc, + IN PKDEFERRED_ROUTINE DeferredRoutine, + IN PVOID DeferredContext + ); + +// KeInitializeTimerEx: +// Initializes a timer. +// +// Differences from NT: None. +NTSYSAPI +EXPORTNUM(113) +VOID +KeInitializeTimerEx( + IN OUT PKTIMER Timer, + IN TIMER_TYPE Type + ); + +// KeRaiseIrql: +// Raises IRQL to some value. +// +// Differences from NT: None. +#define KeRaiseIrql KfRaiseIrql +NTSYSAPI +EXPORTNUM(190) +VOID +__fastcall +KfRaiseIrql( + IN KIRQL NewIrql, + OUT PKIRQL OldIrql + ); + +// KeRaiseIrqlToDpcLevel: +// Raises IRQL to DISPATCH_LEVEL. Like KeRaiseIrql except returns old level directly. +// +// Differences from NT: None. +NTSYSAPI +EXPORTNUM(129) +KIRQL +NTAPI +KeRaiseIrqlToDpcLevel( + VOID + ); + +// KeLowerIrql: +// Lowers IRQL. +#define KeLowerIrql KfLowerIrql +NTSYSAPI +EXPORTNUM(161) +VOID +__fastcall +KfLowerIrql( + IN KIRQL NewIrql + ); + + +// MmMapIoSpace: +// Maps a physical address area into the virtual address space. +// DO NOT USE MEMORY MAPPED WITH THIS AS A BUFFER TO OTHER CALLS. For +// example, don't WriteFile or NtWriteFile these buffers. Copy them first. +// +// Differences from NT: PhysicalAddress is 32 bit, not 64. ProtectionType +// specifies the page protections, but it's a Win32 PAGE_ macro instead +// of the normal NT enumeration. PAGE_READWRITE is probably what you +// want... +NTSYSAPI +EXPORTNUM(177) +PVOID +NTAPI +MmMapIoSpace( + IN PHYSICAL_ADDRESS PhysicalAddress, + IN ULONG NumberOfBytes, + IN ULONG ProtectionType + ); + +// MmGetPhysicalAddress: +// Translates a virtual address into a physical address. +// +// Differences from NT: PhysicalAddress is 32 bit, not 64. +NTSYSAPI +EXPORTNUM(173) +PHYSICAL_ADDRESS +NTAPI +MmGetPhysicalAddress( + IN PVOID BaseAddress + ); + +// MmUnmapIoSpace: +// Unmaps a virtual address mapping made by MmMapIoSpace. +// +// Differences from NT: None. +NTSYSAPI +EXPORTNUM(183) +PVOID +NTAPI +MmUnmapIoSpace( + IN PVOID BaseAddress, + IN ULONG NumberOfBytes + ); + +// MmAllocateContiguousMemory: +// Allocates a range of physically contiguous, cache-aligned memory from the +// non-paged pool (= main pool on XBOX). +// +// Differences from NT: HighestAcceptableAddress was deleted, opting instead +// to not care about the highest address. +NTSYSAPI +EXPORTNUM(165) +PVOID +NTAPI +MmAllocateContiguousMemory( + IN ULONG NumberOfBytes + ); + +// MmFreeContiguousMemory: +// Frees memory allocated with MmAllocateContiguousMemory. +// +// Differences from NT: None. +NTSYSAPI +EXPORTNUM(171) +VOID +NTAPI +MmFreeContiguousMemory( + IN PVOID BaseAddress + ); + + +// DbgPrint +// Displays a message on the debugger. +// +// Differences from NT: Only how this information is displayed changed. +NTSYSAPI +EXPORTNUM(8) +ULONG +__cdecl +DbgPrint( + IN PCSZ Format, + ... + ); + + +// ExAllocatePoolWithTag: +// Allocates memory from the memory pool. The Tag parameter is a 4-letter +// character constant to which to associate the allocation. +// +// Differences from NT: There is no PoolType field, as the XBOX only has 1 +// pool, the non-paged pool. +NTSYSAPI +EXPORTNUM(15) +PVOID +NTAPI +ExAllocatePoolWithTag( + IN SIZE_T NumberOfBytes, + IN ULONG Tag + ); + +// ExFreePool: +// Frees memory allocated by ExAllocatePool* functions. +// +// Differences from NT: None. +NTSYSAPI +EXPORTNUM(17) +VOID +NTAPI +ExFreePool( + IN PVOID P + ); + + +// IoCreateSymbolicLink: +// Creates a symbolic link in the object namespace. +// NtCreateSymbolicLinkObject is much harder to use than this simple +// function, so just use this one. +// +// Differences from NT: Uses ANSI_STRING instead of UNICODE_STRING. +NTSYSAPI +EXPORTNUM(67) +NTSTATUS +NTAPI +IoCreateSymbolicLink( + IN PANSI_STRING SymbolicLinkName, + IN PANSI_STRING DeviceName + ); + +// IoDeleteSymbolicLink: +// Creates a symbolic link in the object namespace. Deleting symbolic links +// through the Nt* functions is a pain, so use this instead. +// +// Differences from NT: Uses ANSI_STRING instead of UNICODE_STRING. +NTSYSAPI +EXPORTNUM(69) +NTSTATUS +NTAPI +IoDeleteSymbolicLink( + IN PANSI_STRING SymbolicLinkName + ); + + +// ObReferenceObjectByHandle: +// Turns a handle into a kernel object pointer. The ObjectType parameter +// specifies what type of object it is. This function also increments the +// object's reference count. +// +// Differences from NT: There are no DesiredAccess, AccessMode, or +// HandleInformation parameters. +NTSYSAPI +EXPORTNUM(246) +NTSTATUS +NTAPI +ObReferenceObjectByHandle( + IN HANDLE Handle, + IN POBJECT_TYPE ObjectType OPTIONAL, + OUT PVOID *Object + ); + +// ObfReferenceObject/ObReferenceObject: +// Increments the object's reference count. +// +// Differences from NT: None. +#define ObReferenceObject(Object) ObfReferenceObject(Object) +NTSYSAPI +EXPORTNUM(251) +VOID +FASTCALL +ObfReferenceObject( + IN PVOID Object + ); + +// ObfDereferenceObject/ObDereferenceObject: +// Decrements the object's reference count, deleting it if it is now unused. +// +// Differences from NT: None. +#define ObDereferenceObject(a) ObfDereferenceObject(a) +NTSYSAPI +EXPORTNUM(250) +VOID +FASTCALL +ObfDereferenceObject( + IN PVOID Object + ); + + +// PsTerminateSystemThread: +// Exits the current system thread. Must be called from a system thread. +// +// Differences from NT: None. +NTSYSAPI +EXPORTNUM(258) +__declspec(noreturn) +NTSTATUS +PsTerminateSystemThread( + NTSTATUS ExitCode + ); + + + +// Kernel routines only in the XBOX + +// IoSynchronousDeviceIoControlRequest: +// NICE. Makes kernel driver stuff sooooo much easier. This does a +// blocking IOCTL on the specified device. +// +// New to the XBOX. +NTSYSAPI +EXPORTNUM(84) +NTSTATUS +NTAPI +IoSynchronousDeviceIoControlRequest( + IN ULONG IoControlCode, + IN PDEVICE_OBJECT DeviceObject, + IN PVOID InputBuffer OPTIONAL, + IN ULONG InputBufferLength, + OUT PVOID OutputBuffer OPTIONAL, + IN ULONG OutputBufferLength, + OUT PDWORD unknown_use_zero OPTIONAL, + IN BOOLEAN InternalDeviceIoControl + ); + +// ExQueryNonVolatileSettings +// Queries saved information, such as the region code. +// +// New to the XBOX. +NTSYSAPI +EXPORTNUM(24) +NTSTATUS +NTAPI +ExQueryNonVolatileSetting( + IN ULONG ValueIndex, + OUT PULONG Type, + OUT PVOID Value, + IN ULONG ValueLength, + OUT PULONG ResultLength OPTIONAL + ); + +// ExSaveNonVolatileSettings +// Writes saved information, such as the region code. +// +// New to the XBOX. +NTSYSAPI +EXPORTNUM(29) +NTSTATUS +NTAPI +ExSaveNonVolatileSetting( + IN ULONG ValueIndex, + IN PULONG Type OPTIONAL, + IN PVOID Value, + IN ULONG ValueLength + ); + +// HalEnableSecureTrayEject: +// Notifies the SMBUS that ejecting the DVD-ROM should not reset the system. +// Note that this function can't really be called directly... +// +// New to the XBOX. +NTSYSAPI +EXPORTNUM(365) +VOID +NTAPI +HalEnableSecureTrayEject( + VOID + ); + +// XeLoadSection: +// Adds one to the reference count of the specified section and loads if the +// count is now above zero. +// +// New to the XBOX. +NTSYSAPI +EXPORTNUM(327) +NTSTATUS +NTAPI +XeLoadSection( + IN OUT PXBE_SECTION section + ); + +// XeUnloadSection: +// Subtracts one from the reference count of the specified section and loads +// if the count is now below zero. +// +// New to the XBOX. +NTSYSAPI +EXPORTNUM(328) +NTSTATUS +NTAPI +XeUnloadSection( + IN OUT PXBE_SECTION section + ); + +// RtlRip: +// Traps to the debugger with a certain message, then crashes. +// +// New to the XBOX. +NTSYSAPI +EXPORTNUM(352) +VOID +NTAPI +RtlRip( + IN PCSZ Part1, + IN PCSZ Part2, + IN PCSZ Part3 + ); + +// PsCreateSystemThread: +// Creates a system thread. Same as: +// PsCreateSystemThreadEx(ThreadHandle, NULL, 0x3000, 0, ThreadId, StartContext1, +// StartContext2, FALSE, DebugStack, PspSystemThreadStartup); +// +// New to the XBOX. (It is too different from NT to be considered the same) +NTSYSAPI +EXPORTNUM(254) +NTSTATUS +NTAPI +PsCreateSystemThread( + OUT PHANDLE ThreadHandle, + OUT PULONG ThreadId OPTIONAL, + IN PVOID StartContext1, + IN PVOID StartContext2, + IN BOOLEAN DebugStack + ); + +// PsCreateSystemThreadEx: +// Creates a system thread. +// ThreadHandle: Receives the thread handle +// ObjectAttributes: Unsure how this works (everything I've seen uses NULL) +// KernelStackSize: Size of the allocation for both stack and TLS data +// TlsDataSize: Size within KernelStackSize to use as TLS data +// ThreadId: Receives the thread ID number +// StartContext1: Parameter 1 to StartRoutine +// StartContext2: Parameter 2 to StartRoutine +// CreateSuspended: TRUE to create the thread as a suspended thread +// DebugStack: TRUE to allocate the stack from Debug Kit memory +// StartRoutine: Called when the thread is created +// +// New to the XBOX. +NTSYSAPI +EXPORTNUM(255) +NTSTATUS +NTAPI +PsCreateSystemThreadEx( + OUT PHANDLE ThreadHandle, + IN PVOID ObjectAttributes OPTIONAL, + IN ULONG KernelStackSize, + IN ULONG TlsDataSize, + OUT PULONG ThreadId OPTIONAL, + IN PVOID StartContext1, + IN PVOID StartContext2, + IN BOOLEAN CreateSuspended, + IN BOOLEAN DebugStack, + IN PKSTART_ROUTINE StartRoutine + ); + + + +// Error codes +#define STATUS_SUCCESS 0x00000000 +#define STATUS_UNSUCCESSFUL 0xC0000001 +#define STATUS_UNRECOGNIZED_MEDIA 0xC0000014 +// The SCSI input buffer was too large (not necessarily an error!) +#define STATUS_DATA_OVERRUN 0xC000003C +#define STATUS_INVALID_IMAGE_FORMAT 0xC000007B +#define STATUS_INSUFFICIENT_RESOURCES 0xC000009A +#define STATUS_TOO_MANY_SECRETS 0xC0000156 +#define STATUS_REGION_MISMATCH 0xC0050001 + +// End extern "C" for C++ +#if defined(__cplusplus) && !defined(XBOXINTERNAL_NO_EXTERN_C) +}; +#endif // __cplusplus + +#include + +// Thanks and credit go to Team Evox +typedef struct +{ + DWORD Data_00; // Check Block Start + DWORD Data_04; + DWORD Data_08; + DWORD Data_0c; + DWORD Data_10; // Check Block End + + DWORD V1_IP; // 0x14 + DWORD V1_Subnetmask; // 0x18 + DWORD V1_Defaultgateway; // 0x1c + DWORD V1_DNS1; // 0x20 + DWORD V1_DNS2; // 0x24 + + DWORD Data_28; // Check Block Start + DWORD Data_2c; + DWORD Data_30; + DWORD Data_34; + DWORD Data_38; // Check Block End + + DWORD V2_Tag; // V2 Tag "XBV2" + + DWORD Flag; // 0x40 + DWORD Data_44; + + DWORD V2_IP; // 0x48 + DWORD V2_Subnetmask; // 0x4c + DWORD V2_Defaultgateway; // 0x50 + DWORD V2_DNS1; // 0x54 + DWORD V2_DNS2; // 0x58 + + DWORD Data_xx[0x200-0x5c]; + +} TXNetConfigParams,*PTXNetConfigParams; + + +extern "C" +{ + // Thanks and credit go to Woodoo + extern VOID WINAPI HalInitiateShutdown(VOID); + extern VOID WINAPI HalWriteSMBusValue(BYTE, BYTE, BOOL, BYTE); + extern VOID WINAPI HalReadSMCTrayState(DWORD* state, DWORD* count); + + // Thanks and credit go to Team Evox + extern VOID WINAPI HalReturnToFirmware(DWORD); + + extern INT WINAPI XNetLoadConfigParams(LPBYTE); + extern INT WINAPI XNetSaveConfigParams(LPBYTE); + + extern INT WINAPI XWriteTitleInfoNoReboot(LPVOID,LPVOID,DWORD,DWORD,LPVOID); + + extern DWORD* LaunchDataPage; +} + + + +#endif // __XBOX_INTERNAL_H__ diff --git a/xbox1/frontend/RetroLaunch/titleimage.bmp b/xbox1/frontend/RetroLaunch/titleimage.bmp new file mode 100644 index 0000000000..a7d3e62ff6 Binary files /dev/null and b/xbox1/frontend/RetroLaunch/titleimage.bmp differ diff --git a/xbox1/frontend/menu.cpp b/xbox1/frontend/menu.cpp new file mode 100644 index 0000000000..d16015ae30 --- /dev/null +++ b/xbox1/frontend/menu.cpp @@ -0,0 +1,78 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include "RetroLaunch/Global.h" +#include "RetroLaunch/IoSupport.h" +#include "RetroLaunch/Font.h" +#include "RetroLaunch/MenuManager.h" +#include "RetroLaunch/RomList.h" + +int menu_init(void) +{ + RARCH_LOG("Starting RetroLaunch.\n"); + + // Set file cache size + XSetFileCacheSize(8 * 1024 * 1024); + + // Mount drives + g_IOSupport.Mount("A:", "cdrom0"); + g_IOSupport.Mount("E:", "Harddisk0\\Partition1"); + g_IOSupport.Mount("Z:", "Harddisk0\\Partition2"); + g_IOSupport.Mount("F:", "Harddisk0\\Partition6"); + g_IOSupport.Mount("G:", "Harddisk0\\Partition7"); + + // Load the rom list if it isn't already loaded + if (!g_romList.IsLoaded()) + g_romList.Build(); + + // Load the font here + g_font.Create(); + + // Build menu here (Menu state -> Main Menu) + g_menuManager.Create(); + + g_console.mode_switch = MODE_MENU; + + return 0; +} + +void menu_free(void) {} + +void menu_loop(void) +{ + xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data; + + g_console.menu_enable = true; + + do + { + d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, + D3DCOLOR_ARGB(0, 0, 0, 0), + 1.0f, 0); + + d3d->d3d_render_device->BeginScene(); + d3d->d3d_render_device->SetFlickerFilter(1); + d3d->d3d_render_device->SetSoftDisplayFilter(1); + + //g_input.GetInput(); + g_menuManager.Update(); + + d3d->d3d_render_device->EndScene(); + d3d->d3d_render_device->Present(NULL, NULL, NULL, NULL); + }while(g_console.menu_enable); + + g_console.ingame_menu_enable = false; +} diff --git a/xbox1/xdk_d3d8.h b/xbox1/xdk_d3d8.h index 64e720d58a..a6e867d9e1 100644 --- a/xbox1/xdk_d3d8.h +++ b/xbox1/xdk_d3d8.h @@ -18,6 +18,11 @@ #define _XDK_VIDEO_H #include + +#ifdef _XBOX1 +#define XFONT_TRUETYPE // use true type fonts +#endif + #include #include "../xdk/xdk_defines.h" @@ -25,8 +30,7 @@ #define SHOW_DEBUG_INFO #define DFONT_MAX 4096 -#define PRIM_FVF (D3DFVF_XYZRHW | D3DFVF_TEX1) -#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_NORMAL) +#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW | D3DFVF_TEX1) #define MIN_SCALING_FACTOR (1.0f) #define MAX_SCALING_FACTOR (2.0f) @@ -44,6 +48,7 @@ typedef struct typedef struct DrawVerticeFormats { float x, y, z; + float rhw; float u, v; } DrawVerticeFormats; diff --git a/xbox1/xinput_xbox_input.c b/xbox1/xinput_xbox_input.c index 7947a0aabc..f9af267ba2 100644 --- a/xbox1/xinput_xbox_input.c +++ b/xbox1/xinput_xbox_input.c @@ -26,12 +26,48 @@ #include "../libretro.h" #include "xinput_xbox_input.h" -static XINPUT_STATE state[4]; +static uint64_t real_state[4]; HANDLE gamepads[4]; DWORD dwDeviceMask; bool bInserted[4]; bool bRemoved[4]; -XINPUT_CAPABILITIES caps[4]; + +const struct platform_bind platform_keys[] = { + { XINPUT1_GAMEPAD_B, "B button" }, + { XINPUT1_GAMEPAD_A, "A button" }, + { XINPUT1_GAMEPAD_Y, "Y button" }, + { XINPUT1_GAMEPAD_X, "X button" }, + { XINPUT1_GAMEPAD_DPAD_UP, "D-Pad Up" }, + { XINPUT1_GAMEPAD_DPAD_DOWN, "D-Pad Down" }, + { XINPUT1_GAMEPAD_DPAD_LEFT, "D-Pad Left" }, + { XINPUT1_GAMEPAD_DPAD_RIGHT, "D-Pad Right" }, + { XINPUT1_GAMEPAD_BACK, "Back button" }, + { XINPUT1_GAMEPAD_START, "Start button" }, + { XINPUT1_GAMEPAD_WHITE, "White button" }, + { XINPUT1_GAMEPAD_LEFT_TRIGGER, "Left Trigger" }, + { XINPUT1_GAMEPAD_LEFT_THUMB, "Left Thumb" }, + { XINPUT1_GAMEPAD_BLACK, "Black button" }, + { XINPUT1_GAMEPAD_RIGHT_TRIGGER, "Right Trigger" }, + { XINPUT1_GAMEPAD_RIGHT_THUMB, "Right Thumb" }, + { XINPUT1_GAMEPAD_LSTICK_LEFT_MASK, "LStick Left" }, + { XINPUT1_GAMEPAD_LSTICK_RIGHT_MASK, "LStick Right" }, + { XINPUT1_GAMEPAD_LSTICK_UP_MASK, "LStick Up" }, + { XINPUT1_GAMEPAD_LSTICK_DOWN_MASK, "LStick Down" }, + { XINPUT1_GAMEPAD_DPAD_LEFT | XINPUT1_GAMEPAD_LSTICK_LEFT_MASK, "LStick D-Pad Left" }, + { XINPUT1_GAMEPAD_DPAD_RIGHT | XINPUT1_GAMEPAD_LSTICK_RIGHT_MASK, "LStick D-Pad Right" }, + { XINPUT1_GAMEPAD_DPAD_UP | XINPUT1_GAMEPAD_LSTICK_UP_MASK, "LStick D-Pad Up" }, + { XINPUT1_GAMEPAD_DPAD_DOWN | XINPUT1_GAMEPAD_LSTICK_DOWN_MASK, "LStick D-Pad Down" }, + { XINPUT1_GAMEPAD_RSTICK_LEFT_MASK, "RStick Left" }, + { XINPUT1_GAMEPAD_RSTICK_RIGHT_MASK, "RStick Right" }, + { XINPUT1_GAMEPAD_RSTICK_UP_MASK, "RStick Up" }, + { XINPUT1_GAMEPAD_RSTICK_DOWN_MASK, "RStick Down" }, + { XINPUT1_GAMEPAD_DPAD_LEFT | XINPUT1_GAMEPAD_RSTICK_LEFT_MASK, "RStick D-Pad Left" }, + { XINPUT1_GAMEPAD_DPAD_RIGHT | XINPUT1_GAMEPAD_RSTICK_RIGHT_MASK, "RStick D-Pad Right" }, + { XINPUT1_GAMEPAD_DPAD_UP | XINPUT1_GAMEPAD_RSTICK_UP_MASK, "RStick D-Pad Up" }, + { XINPUT1_GAMEPAD_DPAD_DOWN | XINPUT1_GAMEPAD_RSTICK_DOWN_MASK, "RStick D-Pad Down" }, +}; + +const unsigned int platform_keys_size = sizeof(platform_keys); #define DEADZONE (16000) @@ -48,6 +84,10 @@ static void xinput_input_poll(void *data) for (unsigned i = 0; i < 4; i++) { + XINPUT_STATE state[4]; + XINPUT_CAPABILITIES caps[4]; + (void)caps; + real_state[i] = 0; // handle removed devices bRemoved[i] = (dwRemovals & (1< DEADZONE) ? XINPUT1_GAMEPAD_DPAD_RIGHT : 0); + real_state[i] |= ((state[i].Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) || (state[i].Gamepad.sThumbLY > DEADZONE) ? XINPUT1_GAMEPAD_DPAD_UP : 0); + real_state[i] |= ((state[i].Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN)|| (state[i].Gamepad.sThumbLY < -DEADZONE) ? XINPUT1_GAMEPAD_DPAD_DOWN : 0); + real_state[i] |= ((state[i].Gamepad.wButtons & XINPUT_GAMEPAD_START) ? XINPUT1_GAMEPAD_START : 0); + real_state[i] |= ((state[i].Gamepad.wButtons & XINPUT_GAMEPAD_BACK) ? XINPUT1_GAMEPAD_BACK : 0); + real_state[i] |= ((state[i].Gamepad.bAnalogButtons[XINPUT_GAMEPAD_LEFT_TRIGGER]) ? XINPUT1_GAMEPAD_LEFT_TRIGGER : 0); + real_state[i] |= ((state[i].Gamepad.bAnalogButtons[XINPUT_GAMEPAD_RIGHT_TRIGGER]) ? XINPUT1_GAMEPAD_RIGHT_TRIGGER : 0); + real_state[i] |= ((state[i].Gamepad.bAnalogButtons[XINPUT_GAMEPAD_WHITE]) ? XINPUT1_GAMEPAD_WHITE : 0); + real_state[i] |= ((state[i].Gamepad.bAnalogButtons[XINPUT_GAMEPAD_BLACK]) ? XINPUT1_GAMEPAD_BLACK : 0); + real_state[i] |= ((state[i].Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) ? XINPUT1_GAMEPAD_LEFT_THUMB : 0); + real_state[i] |= ((state[i].Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) ? XINPUT1_GAMEPAD_RIGHT_THUMB : 0); + } } } } @@ -93,65 +152,9 @@ static int16_t xinput_input_state(void *data, const struct retro_keybind **binds { (void)data; unsigned player = port; - DWORD button = binds[player][id].joykey; - int16_t retval = 0; + uint64_t button = binds[player][id].joykey; - //FIXME: Hardcoded binds - switch(id) - { - case RETRO_DEVICE_ID_JOYPAD_A: - retval = (state[player].Gamepad.bAnalogButtons[XINPUT_GAMEPAD_B]) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_B: - retval = (state[player].Gamepad.bAnalogButtons[XINPUT_GAMEPAD_A]) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_X: - retval = (state[player].Gamepad.bAnalogButtons[XINPUT_GAMEPAD_Y]) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_Y: - retval = (state[player].Gamepad.bAnalogButtons[XINPUT_GAMEPAD_X]) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_LEFT: - retval = (state[player].Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) || (state[player].Gamepad.sThumbLX < -DEADZONE) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_RIGHT: - retval = (state[player].Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) || (state[player].Gamepad.sThumbLX > DEADZONE) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_UP: - retval = (state[player].Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) || (state[player].Gamepad.sThumbLY > DEADZONE) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_DOWN: - retval = (state[player].Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN)|| (state[player].Gamepad.sThumbLY < -DEADZONE) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_START: - retval = (state[player].Gamepad.wButtons & XINPUT_GAMEPAD_START) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_SELECT: - retval = (state[player].Gamepad.wButtons & XINPUT_GAMEPAD_BACK) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_L: - retval = (state[player].Gamepad.bAnalogButtons[XINPUT_GAMEPAD_LEFT_TRIGGER]) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_R: - retval = (state[player].Gamepad.bAnalogButtons[XINPUT_GAMEPAD_RIGHT_TRIGGER]) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_L2: - retval = (state[player].Gamepad.bAnalogButtons[XINPUT_GAMEPAD_WHITE]) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_R2: - retval = (state[player].Gamepad.bAnalogButtons[XINPUT_GAMEPAD_BLACK]) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_L3: - retval = (state[player].Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) ? 1 : 0; - break; - case RETRO_DEVICE_ID_JOYPAD_R3: - retval = (state[player].Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) ? 1 : 0; - break; - default: - break; - } - - return retval; + return (real_state[player] & button) ? 1 : 0; } static void xinput_input_free_input(void *data) @@ -189,6 +192,33 @@ static bool xinput_input_key_pressed(void *data, int key) return retval; } +static void xinput_set_default_keybind_lut(void) +{ + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_B] = platform_keys[XDK_DEVICE_ID_JOYPAD_A].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_Y] = platform_keys[XDK_DEVICE_ID_JOYPAD_X].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_SELECT] = platform_keys[XDK_DEVICE_ID_JOYPAD_BACK].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_START] = platform_keys[XDK_DEVICE_ID_JOYPAD_START].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_UP] = platform_keys[XDK_DEVICE_ID_JOYPAD_UP].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_DOWN] = platform_keys[XDK_DEVICE_ID_JOYPAD_DOWN].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_LEFT] = platform_keys[XDK_DEVICE_ID_JOYPAD_LEFT].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_RIGHT] = platform_keys[XDK_DEVICE_ID_JOYPAD_RIGHT].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_A] = platform_keys[XDK_DEVICE_ID_JOYPAD_B].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_X] = platform_keys[XDK_DEVICE_ID_JOYPAD_Y].joykey; +#if defined(_XBOX1) + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L] = platform_keys[XDK_DEVICE_ID_JOYPAD_LEFT_TRIGGER].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R] = platform_keys[XDK_DEVICE_ID_JOYPAD_RIGHT_TRIGGER].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L2] = platform_keys[XDK_DEVICE_ID_JOYPAD_LB].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R2] = platform_keys[XDK_DEVICE_ID_JOYPAD_RB].joykey; +#elif defined(_XBOX360) + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L] = platform_keys[XDK_DEVICE_ID_JOYPAD_LB].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R] = platform_keys[XDK_DEVICE_ID_JOYPAD_RB].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L2] = platform_keys[XDK_DEVICE_ID_JOYPAD_LEFT_TRIGGER].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R2] = platform_keys[XDK_DEVICE_ID_JOYPAD_RIGHT_TRIGGER].joykey; +#endif + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L3] = platform_keys[XDK_DEVICE_ID_LSTICK_THUMB].joykey; + rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R3] = platform_keys[XDK_DEVICE_ID_RSTICK_THUMB].joykey; +} + const input_driver_t input_xinput = { xinput_input_init, @@ -196,5 +226,6 @@ const input_driver_t input_xinput = xinput_input_state, xinput_input_key_pressed, xinput_input_free_input, + xinput_set_default_keybind_lut, "xinput" }; diff --git a/xbox1/xinput_xbox_input.h b/xbox1/xinput_xbox_input.h index 34bf1a8719..be7bc64782 100644 --- a/xbox1/xinput_xbox_input.h +++ b/xbox1/xinput_xbox_input.h @@ -44,4 +44,42 @@ enum { XINPUT1_GAMEPAD_RSTICK_DOWN_MASK = 1 << 23, }; +enum xdk_device_id +{ + XDK_DEVICE_ID_JOYPAD_B = 0, + XDK_DEVICE_ID_JOYPAD_A, + XDK_DEVICE_ID_JOYPAD_Y, + XDK_DEVICE_ID_JOYPAD_X, + XDK_DEVICE_ID_JOYPAD_UP, + XDK_DEVICE_ID_JOYPAD_DOWN, + XDK_DEVICE_ID_JOYPAD_LEFT, + XDK_DEVICE_ID_JOYPAD_RIGHT, + XDK_DEVICE_ID_JOYPAD_BACK, + XDK_DEVICE_ID_JOYPAD_START, + XDK_DEVICE_ID_JOYPAD_LB, + XDK_DEVICE_ID_JOYPAD_LEFT_TRIGGER, + XDK_DEVICE_ID_LSTICK_THUMB, + XDK_DEVICE_ID_JOYPAD_RB, + XDK_DEVICE_ID_JOYPAD_RIGHT_TRIGGER, + XDK_DEVICE_ID_RSTICK_THUMB, + XDK_DEVICE_ID_LSTICK_LEFT, + XDK_DEVICE_ID_LSTICK_RIGHT, + XDK_DEVICE_ID_LSTICK_UP, + XDK_DEVICE_ID_LSTICK_DOWN, + XDK_DEVICE_ID_LSTICK_LEFT_DPAD, + XDK_DEVICE_ID_LSTICK_RIGHT_DPAD, + XDK_DEVICE_ID_LSTICK_UP_DPAD, + XDK_DEVICE_ID_LSTICK_DOWN_DPAD, + XDK_DEVICE_ID_RSTICK_LEFT, + XDK_DEVICE_ID_RSTICK_RIGHT, + XDK_DEVICE_ID_RSTICK_UP, + XDK_DEVICE_ID_RSTICK_DOWN, + XDK_DEVICE_ID_RSTICK_LEFT_DPAD, + XDK_DEVICE_ID_RSTICK_RIGHT_DPAD, + XDK_DEVICE_ID_RSTICK_UP_DPAD, + XDK_DEVICE_ID_RSTICK_DOWN_DPAD, + + RARCH_LAST_PLATFORM_KEY +}; + #endif diff --git a/xdk/frontend/main.c b/xdk/frontend/main.c index 12f88a38b4..82baaaba7e 100644 --- a/xdk/frontend/main.c +++ b/xdk/frontend/main.c @@ -20,6 +20,8 @@ #include #include +#include "../../xdk/menu_shared.h" + #ifdef _XBOX360 #include #include "../../360/frontend-xdk/menu.h" @@ -36,174 +38,20 @@ #endif #include "../../console/retroarch_console.h" +#include "../../console/retroarch_config.h" #include "../../conf/config_file.h" #include "../../conf/config_file_macros.h" #include "../../file.h" #include "../../general.h" -#define DEVICE_MEMORY_UNIT0 1 -#define DEVICE_MEMORY_UNIT1 2 -#define DEVICE_MEMORY_ONBOARD 3 -#define DEVICE_CDROM0 4 -#define DEVICE_HARDISK0_PART1 5 -#define DEVICE_HARDISK0_SYSPART 6 -#define DEVICE_USB0 7 -#define DEVICE_USB1 8 -#define DEVICE_USB2 9 -#define DEVICE_TEST 10 -#define DEVICE_CACHE 11 - -typedef struct _STRING { - unsigned short Length; - unsigned short MaximumLength; - char * Buffer; -} STRING; - -char DEFAULT_SHADER_FILE[PATH_MAX]; -char SYS_CONFIG_FILE[PATH_MAX]; - -#ifdef _XBOX360 -extern "C" int __stdcall ObCreateSymbolicLink( STRING*, STRING*); -#endif - -int Mounted[20]; - int rarch_main(int argc, char *argv[]); #undef main -#ifdef _XBOX360 -static int DriveMounted(std::string path) -{ - WIN32_FIND_DATA findFileData; - memset(&findFileData,0,sizeof(WIN32_FIND_DATA)); - std::string searchcmd = path + "\\*.*"; - HANDLE hFind = FindFirstFile(searchcmd.c_str(), &findFileData); - - if (hFind == INVALID_HANDLE_VALUE) - return 0; - - FindClose(hFind); - - return 1; -} - -static int Mount( int Device, char* MountPoint ) -{ - char MountConv[260]; - char * SysPath = NULL; - - snprintf( MountConv, sizeof(MountConv), "\\??\\%s", MountPoint ); - - switch( Device ) - { - case DEVICE_MEMORY_UNIT0: - SysPath = "\\Device\\Mu0"; - break; - case DEVICE_MEMORY_UNIT1: - SysPath = "\\Device\\Mu1"; - break; - case DEVICE_MEMORY_ONBOARD: - SysPath = "\\Device\\BuiltInMuSfc"; - break; - case DEVICE_CDROM0: - SysPath = "\\Device\\Cdrom0"; - break; - case DEVICE_HARDISK0_PART1: - SysPath = "\\Device\\Harddisk0\\Partition1"; - break; - case DEVICE_HARDISK0_SYSPART: - SysPath = "\\Device\\Harddisk0\\SystemPartition"; - break; - case DEVICE_USB0: - SysPath = "\\Device\\Mass0"; - break; - case DEVICE_USB1: - SysPath = "\\Device\\Mass1"; - break; - case DEVICE_USB2: - SysPath = "\\Device\\Mass2"; - break; - case DEVICE_CACHE: - SysPath = "\\Device\\Harddisk0\\Cache0"; - break; - } - - STRING sSysPath = { (USHORT)strlen( SysPath ), (USHORT)strlen( SysPath ) + 1, SysPath }; - STRING sMountConv = { (USHORT)strlen( MountConv ), (USHORT)strlen( MountConv ) + 1, MountConv }; - int res = ObCreateSymbolicLink( &sMountConv, &sSysPath ); - - if (res != 0) - return res; - - return DriveMounted(MountPoint); -} -#endif - -static void set_default_settings (void) -{ - //g_settings - g_settings.rewind_enable = false; - strlcpy(g_settings.video.cg_shader_path, DEFAULT_SHADER_FILE, sizeof(g_settings.video.cg_shader_path)); - g_settings.video.fbo_scale_x = 2.0f; - g_settings.video.fbo_scale_y = 2.0f; - g_settings.video.render_to_texture = true; - strlcpy(g_settings.video.second_pass_shader, DEFAULT_SHADER_FILE, sizeof(g_settings.video.second_pass_shader)); - g_settings.video.second_pass_smooth = true; - g_settings.video.smooth = true; - g_settings.video.vsync = true; - strlcpy(g_settings.cheat_database, "game:", sizeof(g_settings.cheat_database)); - g_settings.video.aspect_ratio = -1.0f; - - rarch_input_set_controls_default(); - - //g_console - g_console.block_config_read = true; - g_console.frame_advance_enable = false; - g_console.emulator_initialized = 0; - g_console.gamma_correction_enable = true; - g_console.initialize_rarch_enable = false; - g_console.fbo_enabled = true; - g_console.mode_switch = MODE_MENU; - g_console.screen_orientation = ORIENTATION_NORMAL; - g_console.throttle_enable = true; - g_console.aspect_ratio_index = 0; - strlcpy(g_console.default_rom_startup_dir, "game:", sizeof(g_console.default_rom_startup_dir)); - g_console.viewports.custom_vp.width = 0; - g_console.viewports.custom_vp.height = 0; - g_console.viewports.custom_vp.x = 0; - g_console.viewports.custom_vp.y = 0; - g_console.color_format = 0; - g_console.info_msg_enable = true; - - //g_extern - g_extern.state_slot = 0; - g_extern.audio_data.mute = 0; - g_extern.verbose = true; -} - static void get_environment_settings (void) { -#ifdef _XBOX360 - DWORD ret; - - //for devkits only, we will need to mount all partitions for retail - //in a different way - //DmMapDevkitDrive(); - - memset(&Mounted, 0, 20); - - Mounted[DEVICE_USB0] = Mount(DEVICE_USB0,"Usb0:"); - Mounted[DEVICE_USB1] = Mount(DEVICE_USB1,"Usb1:"); - Mounted[DEVICE_USB2] = Mount(DEVICE_USB2,"Usb2:"); - Mounted[DEVICE_HARDISK0_PART1] = Mount(DEVICE_HARDISK0_PART1,"Hdd1:"); - Mounted[DEVICE_HARDISK0_SYSPART] = Mount(DEVICE_HARDISK0_SYSPART,"HddX:"); - Mounted[DEVICE_MEMORY_UNIT0] = Mount(DEVICE_MEMORY_UNIT0,"Memunit0:"); - Mounted[DEVICE_MEMORY_UNIT1] = Mount(DEVICE_MEMORY_UNIT1,"Memunit1:"); - Mounted[DEVICE_MEMORY_ONBOARD] = Mount(DEVICE_MEMORY_ONBOARD,"OnBoardMU:"); - Mounted[DEVICE_CDROM0] = Mount(DEVICE_CDROM0,"Dvd:"); -#endif - + HRESULT ret; + (void)ret; #ifdef HAVE_HDD_CACHE_PARTITION ret = XSetFileCacheSize(0x100000); @@ -252,39 +100,24 @@ static void get_environment_settings (void) } #endif - strlcpy(DEFAULT_SHADER_FILE, "game:\\media\\shaders\\stock.cg", sizeof(DEFAULT_SHADER_FILE)); -#ifdef _XBOX1 +#if defined(_XBOX1) /* FIXME: Hardcoded */ - strlcpy(SYS_CONFIG_FILE, "D:\\retroarch.cfg", sizeof(SYS_CONFIG_FILE)); + strlcpy(default_paths.config_file, "D:\\retroarch.cfg", sizeof(default_paths.config_file)); strlcpy(g_settings.system_directory, "D:\\system\\", sizeof(g_settings.system_directory)); -#else - strlcpy(SYS_CONFIG_FILE, "game:\\retroarch.cfg", sizeof(SYS_CONFIG_FILE)); + strlcpy(default_paths.filesystem_root_dir, "D:\\", sizeof(default_paths.filesystem_root_dir)); + strlcpy(default_paths.executable_extension, ".xbe", sizeof(default_paths.executable_extension)); +#elif defined(_XBOX360) +#ifdef HAVE_HDD_CACHE_PARTITION + strlcpy(default_paths.cache_dir, "cache:\\", sizeof(default_paths.cache_dir)); +#endif + strlcpy(default_paths.filesystem_root_dir, "game:\\", sizeof(default_paths.filesystem_root_dir)); + strlcpy(default_paths.shader_file, "game:\\media\\shaders\\stock.cg", sizeof(default_paths.shader_file)); + strlcpy(default_paths.config_file, "game:\\retroarch.cfg", sizeof(default_paths.config_file)); strlcpy(g_settings.system_directory, "game:\\system\\", sizeof(g_settings.system_directory)); + strlcpy(default_paths.executable_extension, ".xex", sizeof(default_paths.executable_extension)); #endif } -static void configure_libretro(const char *path_prefix, const char * extension) -{ - char full_path[1024]; - snprintf(full_path, sizeof(full_path), "%sCORE%s", path_prefix, extension); - - bool find_libretro_file = rarch_configure_libretro_core(full_path, path_prefix, path_prefix, - SYS_CONFIG_FILE, extension); - - set_default_settings(); - rarch_config_load(SYS_CONFIG_FILE, path_prefix, extension, find_libretro_file); - init_libretro_sym(); -} - -#ifdef _XBOX1 -static void menu_init(void) {} -static void menu_free(void) {} -static void menu_loop(void) -{ - rarch_console_load_game("D:\\ssf2x.gba"); -} -#endif - int main(int argc, char *argv[]) { rarch_main_clear_state(); @@ -292,18 +125,14 @@ int main(int argc, char *argv[]) config_set_defaults(); -#ifdef _XBOX1 - configure_libretro("D:\\", ".xbe"); -#else - configure_libretro("game:\\", ".xex"); -#endif + input_xinput.init(); + rarch_configure_libretro(&input_xinput, default_paths.filesystem_root_dir, default_paths.executable_extension); #if defined(HAVE_D3D8) || defined(HAVE_D3D9) video_xdk_d3d.start(); #else video_null.start(); #endif - input_xinput.init(); rarch_input_set_default_keybind_names_for_emulator(); @@ -325,7 +154,7 @@ begin_loop: else if(g_console.mode_switch == MODE_MENU) { menu_loop(); - rarch_startup(SYS_CONFIG_FILE); + rarch_startup(default_paths.config_file); } else goto begin_shutdown; @@ -333,8 +162,8 @@ begin_loop: goto begin_loop; begin_shutdown: - if(path_file_exists(SYS_CONFIG_FILE)) - rarch_config_save(SYS_CONFIG_FILE); + if(path_file_exists(default_paths.config_file)) + rarch_config_save(default_paths.config_file); menu_free(); #if defined(HAVE_D3D8) || defined(HAVE_D3D9) diff --git a/xdk/menu_shared.h b/xdk/menu_shared.h new file mode 100644 index 0000000000..9487fea619 --- /dev/null +++ b/xdk/menu_shared.h @@ -0,0 +1,24 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef _XDK_MENU_SHARED_H +#define _XDK_MENU_SHARED_H + +int menu_init (void); +void menu_free (void); +void menu_loop (void); + +#endif