diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 90dc874d..e775390d 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -84,6 +84,17 @@ void retro_get_system_info(struct retro_system_info *info) void retro_get_system_av_info(struct retro_system_av_info *info) { + int pixel_format = RGB555; + if(environ_cb) { + pixel_format = RGB565; + enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; + if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) + pixel_format = RGB555; + } + S9xGraphicsDeinit(); + S9xSetRenderPixelFormat(pixel_format); + S9xGraphicsInit(); + memset(info,0,sizeof(retro_system_av_info)); info->geometry.base_width = SNES_WIDTH; @@ -275,7 +286,6 @@ void retro_init() S9xSetSoundMute(FALSE); S9xSetSamplesAvailableCallback(S9xAudioCallback, NULL); - S9xSetRenderPixelFormat(RGB555); GFX.Pitch = MAX_SNES_WIDTH * sizeof(uint16); GFX.Screen = (uint16*) calloc(1, GFX.Pitch * MAX_SNES_HEIGHT); S9xGraphicsInit(); diff --git a/libretro/libretro.h b/libretro/libretro.h index 44ba52df..581023fe 100644 --- a/libretro/libretro.h +++ b/libretro/libretro.h @@ -3,6 +3,7 @@ #include "snes9x.h" #include +#include // Hack applied for MSVC when compiling in C89 mode as it isn't C99 compliant. #ifdef __cplusplus @@ -298,7 +299,7 @@ enum retro_key // Boolean value whether or not the implementation should use overscan, or crop away overscan. // #define RETRO_ENVIRONMENT_GET_CAN_DUPE 3 // bool * -- - // Boolean value whether or not RetroArch supports frame duping, + // Boolean value whether or not frontend supports frame duping, // passing NULL to video frame callback. // #define RETRO_ENVIRONMENT_GET_VARIABLE 4 // struct retro_variable * -- @@ -354,14 +355,36 @@ enum retro_key #define RETRO_ENVIRONMENT_SET_PIXEL_FORMAT 10 // const enum retro_pixel_format * -- // Sets the internal pixel format used by the implementation. - // The default pixel format is RETRO_PIXEL_FORMAT_XRGB1555. + // The default pixel format is RETRO_PIXEL_FORMAT_0RGB1555. + // This pixel format however, is deprecated (see enum retro_pixel_format). // If the call returns false, the frontend does not support this pixel format. // This function should be called inside retro_load_game() or retro_get_system_av_info(). + // +#define RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS 11 + // const struct retro_input_descriptor * -- + // Sets an array of retro_input_descriptors. + // It is up to the frontend to present this in a usable way. + // The array is terminated by retro_input_descriptor::description being set to NULL. + // This function can be called at any time, but it is recommended to call it as early as possible. + enum retro_pixel_format { - RETRO_PIXEL_FORMAT_0RGB1555 = 0, // 0RGB1555, native endian. 0 bit must be set to 0. - RETRO_PIXEL_FORMAT_XRGB8888 // XRGB8888, native endian. X bits are ignored. + // 0RGB1555, native endian. 0 bit must be set to 0. + // This pixel format is default for compatibility concerns only. + // If a 15/16-bit pixel format is desired, consider using RGB565. + RETRO_PIXEL_FORMAT_0RGB1555 = 0, + + // XRGB8888, native endian. X bits are ignored. + RETRO_PIXEL_FORMAT_XRGB8888 = 1, + + // RGB565, native endian. This pixel format is the recommended format to use if a 15/16-bit format is desired + // as it is the pixel format that is typically available on a wide range of low-power devices. + // It is also natively supported in APIs like OpenGL ES. + RETRO_PIXEL_FORMAT_RGB565 = 2, + + // Ensure sizeof() == sizeof(int). + RETRO_PIXEL_FORMAT_UNKNOWN = INT_MAX }; struct retro_message @@ -370,8 +393,25 @@ struct retro_message unsigned frames; // Duration in frames of message. }; +// Describes how the libretro implementation maps a libretro input bind +// to its internal input system through a human readable string. +// This string can be used to better let a user configure input. +struct retro_input_descriptor +{ + // Associates given parameters with a description. + unsigned port; + unsigned device; + unsigned index; + unsigned id; + + const char *description; // Human readable description for parameters. + // The pointer must remain valid until retro_unload_game() is called. +}; + struct retro_system_info { + // All pointers are owned by libretro implementation, and pointers must remain valid until retro_deinit() is called. + const char *library_name; // Descriptive name of library. Should not contain any version numbers, etc. const char *library_version; // Descriptive version of core. @@ -440,6 +480,8 @@ typedef bool (*retro_environment_t)(unsigned cmd, void *data); // Render a frame. Pixel format is 15-bit 0RGB1555 native endian unless changed (see RETRO_ENVIRONMENT_SET_PIXEL_FORMAT). // Width and height specify dimensions of buffer. // Pitch specifices length in bytes between two lines in buffer. +// For performance reasons, it is highly recommended to have a frame that is packed in memory, i.e. pitch == width * byte_per_pixel. +// Certain graphic APIs, such as OpenGL ES, do not like textures that are not packed in memory. typedef void (*retro_video_refresh_t)(const void *data, unsigned width, unsigned height, size_t pitch); // Renders a single audio frame. Should only be used if implementation generates a single sample at a time. @@ -479,6 +521,8 @@ void retro_get_system_info(struct retro_system_info *info); // Gets information about system audio/video timings and geometry. // Can be called only after retro_load_game() has successfully completed. +// NOTE: The implementation of this function might not initialize every variable if needed. +// E.g. geom.aspect_ratio might not be initialized if core doesn't desire a particular aspect ratio. void retro_get_system_av_info(struct retro_system_av_info *info); // Sets device to be used for player 'port'.