diff --git a/src/inc/callbacks.h b/src/inc/callbacks.h index 50b67a661..de260c72c 100644 --- a/src/inc/callbacks.h +++ b/src/inc/callbacks.h @@ -26,8 +26,8 @@ #if !defined(API_CALLBACKS_H) #define API_CALLBACKS_H -#include "m64p_types.h" #include "m64p_frontend.h" +#include "m64p_types.h" /* Functions for use by the Core, to send information back to the front-end app */ extern m64p_error SetDebugCallback(ptr_DebugCallback pFunc, void *Context); diff --git a/src/inc/m64p_config.h b/src/inc/m64p_config.h index ad2a418c7..043d21551 100644 --- a/src/inc/m64p_config.h +++ b/src/inc/m64p_config.h @@ -120,6 +120,16 @@ typedef m64p_error (*ptr_ConfigSetParameter)(m64p_handle, const char *, m64p_typ EXPORT m64p_error CALL ConfigSetParameter(m64p_handle, const char *, m64p_type, const void *); #endif +/* ConfigSetParameterHelp() + * + * This function sets the help string of one of the emulator's configuration + * parameters. + */ +typedef m64p_error (*ptr_ConfigSetParameterHelp)(m64p_handle, const char *, const char *); +#if defined(M64P_CORE_PROTOTYPES) +EXPORT m64p_error CALL ConfigSetParameterHelp(m64p_handle, const char *, const char *); +#endif + /* ConfigGetParameter() * * This function retrieves the value of one of the emulator's parameters. diff --git a/src/inc/m64p_debugger.h b/src/inc/m64p_debugger.h index 8ca00e0ff..c8644d3cc 100644 --- a/src/inc/m64p_debugger.h +++ b/src/inc/m64p_debugger.h @@ -58,9 +58,9 @@ EXPORT m64p_error CALL DebugSetCoreCompare(void (*)(unsigned int), void (*)(int, * * This function sets the run state of the R4300 CPU emulator. */ -typedef m64p_error (*ptr_DebugSetRunState)(int); +typedef m64p_error (*ptr_DebugSetRunState)(m64p_dbg_runstate); #if defined(M64P_CORE_PROTOTYPES) -EXPORT m64p_error CALL DebugSetRunState(int); +EXPORT m64p_error CALL DebugSetRunState(m64p_dbg_runstate); #endif /* DebugGetState() @@ -189,9 +189,9 @@ EXPORT int CALL DebugBreakpointLookup(unsigned int, unsigned int, unsigned int); * removing, or searching the breakpoints. The meanings of the index and ptr * input parameters vary by command. */ -typedef int (*ptr_DebugBreakpointCommand)(m64p_dbg_bkp_command, unsigned int, void *); +typedef int (*ptr_DebugBreakpointCommand)(m64p_dbg_bkp_command, unsigned int, m64p_breakpoint *); #if defined(M64P_CORE_PROTOTYPES) -EXPORT int CALL DebugBreakpointCommand(m64p_dbg_bkp_command, unsigned int, void *); +EXPORT int CALL DebugBreakpointCommand(m64p_dbg_bkp_command, unsigned int, m64p_breakpoint *); #endif #ifdef __cplusplus diff --git a/src/inc/m64p_plugin.h b/src/inc/m64p_plugin.h index 718482312..dfe6f32a5 100644 --- a/src/inc/m64p_plugin.h +++ b/src/inc/m64p_plugin.h @@ -245,6 +245,7 @@ typedef void (*ptr_InitiateControllers)(CONTROL_INFO ControlInfo); typedef void (*ptr_ReadController)(int Control, unsigned char *Command); typedef void (*ptr_SDL_KeyDown)(int keymod, int keysym); typedef void (*ptr_SDL_KeyUp)(int keymod, int keysym); +typedef void (*ptr_RenderCallback)(void); #if defined(M64P_PLUGIN_PROTOTYPES) EXPORT void CALL ControllerCommand(int Control, unsigned char *Command); EXPORT void CALL GetKeys(int Control, BUTTONS *Keys); @@ -252,6 +253,7 @@ EXPORT void CALL InitiateControllers(CONTROL_INFO ControlInfo); EXPORT void CALL ReadController(int Control, unsigned char *Command); EXPORT void CALL SDL_KeyDown(int keymod, int keysym); EXPORT void CALL SDL_KeyUp(int keymod, int keysym); +EXPORT void CALL RenderCallback(void); #endif /* RSP plugin function pointers */ diff --git a/src/inc/m64p_types.h b/src/inc/m64p_types.h index 8e82457bd..a8efd3578 100644 --- a/src/inc/m64p_types.h +++ b/src/inc/m64p_types.h @@ -28,6 +28,7 @@ /* ----------------------------------------- */ /* necessary headers */ +#include #if defined(WIN32) #include #endif @@ -159,8 +160,8 @@ typedef enum { } m64p_command; typedef struct { - unsigned int address; - int value; + uint32_t address; + int value; } m64p_cheat_code; /* ----------------------------------------- */ @@ -176,21 +177,21 @@ typedef enum typedef struct { - unsigned char init_PI_BSB_DOM1_LAT_REG; /* 0x00 */ - unsigned char init_PI_BSB_DOM1_PGS_REG; /* 0x01 */ - unsigned char init_PI_BSB_DOM1_PWD_REG; /* 0x02 */ - unsigned char init_PI_BSB_DOM1_PGS_REG2; /* 0x03 */ - unsigned int ClockRate; /* 0x04 */ - unsigned int PC; /* 0x08 */ - unsigned int Release; /* 0x0C */ - unsigned int CRC1; /* 0x10 */ - unsigned int CRC2; /* 0x14 */ - unsigned int Unknown[2]; /* 0x18 */ - unsigned char Name[20]; /* 0x20 */ - unsigned int unknown; /* 0x34 */ - unsigned int Manufacturer_ID; /* 0x38 */ - unsigned short Cartridge_ID; /* 0x3C - Game serial number */ - unsigned short Country_code; /* 0x3E */ + uint8_t init_PI_BSB_DOM1_LAT_REG; /* 0x00 */ + uint8_t init_PI_BSB_DOM1_PGS_REG; /* 0x01 */ + uint8_t init_PI_BSB_DOM1_PWD_REG; /* 0x02 */ + uint8_t init_PI_BSB_DOM1_PGS_REG2; /* 0x03 */ + uint32_t ClockRate; /* 0x04 */ + uint32_t PC; /* 0x08 */ + uint32_t Release; /* 0x0C */ + uint32_t CRC1; /* 0x10 */ + uint32_t CRC2; /* 0x14 */ + uint32_t Unknown[2]; /* 0x18 */ + uint8_t Name[20]; /* 0x20 */ + uint32_t unknown; /* 0x34 */ + uint32_t Manufacturer_ID; /* 0x38 */ + uint16_t Cartridge_ID; /* 0x3C - Game serial number */ + uint16_t Country_code; /* 0x3E */ } m64p_rom_header; typedef struct @@ -215,6 +216,12 @@ typedef enum { M64P_DBG_CPU_NEXT_INTERRUPT } m64p_dbg_state; +typedef enum { + M64P_DBG_RUNSTATE_PAUSED = 0, + M64P_DBG_RUNSTATE_STEPPING, + M64P_DBG_RUNSTATE_RUNNING +} m64p_dbg_runstate; + typedef enum { M64P_DBG_MEM_TYPE = 1, M64P_DBG_MEM_FLAGS, @@ -250,7 +257,7 @@ typedef enum { typedef enum { M64P_MEM_FLAG_READABLE = 0x01, M64P_MEM_FLAG_WRITABLE = 0x02, - M64P_MEM_FLAG_READABLE_EMUONLY = 0x04, // the EMUONLY flags signify that emulated code can read/write here, but debugger cannot + M64P_MEM_FLAG_READABLE_EMUONLY = 0x04, /* the EMUONLY flags signify that emulated code can read/write here, but debugger cannot */ M64P_MEM_FLAG_WRITABLE_EMUONLY = 0x08 } m64p_dbg_mem_flags; @@ -286,29 +293,28 @@ typedef enum { M64P_BKP_CMD_CHECK } m64p_dbg_bkp_command; -#define M64P_MEM_INVALID 0xFFFFFFFF // invalid memory read will return this +#define M64P_MEM_INVALID 0xFFFFFFFF /* invalid memory read will return this */ #define BREAKPOINTS_MAX_NUMBER 128 -#define BPT_FLAG_ENABLED 0x01 -#define BPT_FLAG_CONDITIONAL 0x02 -#define BPT_FLAG_COUNTER 0x04 -#define BPT_FLAG_READ 0x08 -#define BPT_FLAG_WRITE 0x10 -#define BPT_FLAG_EXEC 0x20 -#define BPT_FLAG_LOG 0x40 //Log to the console when this breakpoint hits. +typedef enum { + M64P_BKP_FLAG_ENABLED = 0x01, + M64P_BKP_FLAG_READ = 0x02, + M64P_BKP_FLAG_WRITE = 0x04, + M64P_BKP_FLAG_EXEC = 0x08, + M64P_BKP_FLAG_LOG = 0x10 /* Log to the console when this breakpoint hits */ +} m64p_dbg_bkp_flags; #define BPT_CHECK_FLAG(a, b) ((a.flags & b) == b) #define BPT_SET_FLAG(a, b) a.flags = (a.flags | b); #define BPT_CLEAR_FLAG(a, b) a.flags = (a.flags & (~b)); #define BPT_TOGGLE_FLAG(a, b) a.flags = (a.flags ^ b); -typedef struct _breakpoint { - unsigned int address; - unsigned int endaddr; - unsigned int flags; - //unsigned int condition; //Placeholder for breakpoint condition - } breakpoint; +typedef struct { + uint32_t address; + uint32_t endaddr; + unsigned int flags; +} m64p_breakpoint; /* ------------------------------------------------- */ /* Structures and Types for Core Video Extension API */ @@ -329,9 +335,18 @@ typedef enum { M64P_GL_ALPHA_SIZE, M64P_GL_SWAP_CONTROL, M64P_GL_MULTISAMPLEBUFFERS, - M64P_GL_MULTISAMPLESAMPLES + M64P_GL_MULTISAMPLESAMPLES, + M64P_GL_CONTEXT_MAJOR_VERSION, + M64P_GL_CONTEXT_MINOR_VERSION, + M64P_GL_CONTEXT_PROFILE_MASK } m64p_GLattr; +typedef enum { + M64P_GL_CONTEXT_PROFILE_CORE, + M64P_GL_CONTEXT_PROFILE_COMPATIBILITY, + M64P_GL_CONTEXT_PROFILE_ES +} m64p_GLContextType; + typedef struct { unsigned int Functions; m64p_error (*VidExtFuncInit)(void); diff --git a/src/inc/vidext_sdl2_compat.h b/src/inc/vidext_sdl2_compat.h index 9c6804082..81dbc2fa5 100644 --- a/src/inc/vidext_sdl2_compat.h +++ b/src/inc/vidext_sdl2_compat.h @@ -19,40 +19,22 @@ 3. This notice may not be removed or altered from any source distribution. */ +#include #include -typedef struct -{ - Uint8 *src; - int src_w, src_h; - int src_pitch; - int src_skip; - Uint8 *dst; - int dst_w, dst_h; - int dst_pitch; - int dst_skip; - SDL_PixelFormat *src_fmt; - SDL_PixelFormat *dst_fmt; - Uint8 *table; - int flags; - Uint32 colorkey; - Uint8 r, g, b, a; -} SDL_BlitInfo; - -/* Blit mapping definition */ -typedef struct SDL_BlitMap -{ - SDL_Surface *dst; - int identity; - SDL_blit blit; - void *data; - SDL_BlitInfo info; - - /* the version count matches the destination; mismatch indicates - an invalid mapping */ - Uint32 dst_palette_version; - Uint32 src_palette_version; -} SDL_BlitMap; +#ifndef USE_GLES + +#ifndef SDL_VIDEO_OPENGL +#error SDL is not build with OpenGL support. Try USE_GLES=1 +#endif + +#else // !USE_GLES + +#ifndef SDL_VIDEO_OPENGL_ES2 +#error SDL is not build with OpenGL ES2 support. Try USE_GLES=0 +#endif + +#endif // !USE_GLES typedef struct SDL_VideoInfo { @@ -76,8 +58,6 @@ typedef struct SDL_VideoInfo int current_h; } SDL_VideoInfo; -#define SDL_ANYFORMAT 0x00100000 -#define SDL_HWPALETTE 0x00200000 #define SDL_FULLSCREEN 0x00800000 #define SDL_RESIZABLE 0x01000000 #define SDL_NOFRAME 0x02000000 @@ -90,9 +70,7 @@ typedef struct SDL_VideoInfo int initialized_video = 0; static SDL_Window *SDL_VideoWindow = NULL; -static SDL_Surface *SDL_WindowSurface = NULL; static SDL_Surface *SDL_VideoSurface = NULL; -static SDL_Surface *SDL_ShadowSurface = NULL; static SDL_Surface *SDL_PublicSurface = NULL; static SDL_Rect SDL_VideoViewport; static char *wm_title = NULL; @@ -208,110 +186,6 @@ SDL_ListModes(const SDL_PixelFormat * format, Uint32 flags) return modes; } -static void -SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects) -{ - int i; - - if (screen == SDL_ShadowSurface) { - for (i = 0; i < numrects; ++i) { - SDL_BlitSurface(SDL_ShadowSurface, &rects[i], SDL_VideoSurface, - &rects[i]); - } - - /* Fall through to video surface update */ - screen = SDL_VideoSurface; - } - if (screen == SDL_VideoSurface) { - if (SDL_VideoViewport.x || SDL_VideoViewport.y) { - SDL_Rect *stackrects = SDL_stack_alloc(SDL_Rect, numrects); - SDL_Rect *stackrect; - const SDL_Rect *rect; - - /* Offset all the rectangles before updating */ - for (i = 0; i < numrects; ++i) { - rect = &rects[i]; - stackrect = &stackrects[i]; - stackrect->x = SDL_VideoViewport.x + rect->x; - stackrect->y = SDL_VideoViewport.y + rect->y; - stackrect->w = rect->w; - stackrect->h = rect->h; - } - SDL_UpdateWindowSurfaceRects(SDL_VideoWindow, stackrects, numrects); - SDL_stack_free(stackrects); - } else { - SDL_UpdateWindowSurfaceRects(SDL_VideoWindow, rects, numrects); - } - } -} - -static void -SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h) -{ - if (screen) { - SDL_Rect rect; - - /* Fill the rectangle */ - rect.x = (int) x; - rect.y = (int) y; - rect.w = (int) (w ? w : screen->w); - rect.h = (int) (h ? h : screen->h); - SDL_UpdateRects(screen, 1, &rect); - } -} - -static int -SDL_Flip(SDL_Surface * screen) -{ - SDL_UpdateRect(screen, 0, 0, 0, 0); - return 0; -} - -/* - * Calculate the pad-aligned scanline width of a surface - */ -static int -SDL_CalculatePitch(SDL_Surface * surface) -{ - int pitch; - - /* Surface should be 4-byte aligned for speed */ - pitch = surface->w * surface->format->BytesPerPixel; - switch (surface->format->BitsPerPixel) { - case 1: - pitch = (pitch + 7) / 8; - break; - case 4: - pitch = (pitch + 1) / 2; - break; - default: - break; - } - pitch = (pitch + 3) & ~3; /* 4-byte aligning */ - return (pitch); -} - -static void -SDL_InvalidateMap(SDL_BlitMap * map) -{ - if (!map) { - return; - } - if (map->dst) { - /* Release our reference to the surface - see the note below */ - if (--map->dst->refcount <= 0) { - SDL_FreeSurface(map->dst); - } - } - map->dst = NULL; - map->src_palette_version = 0; - map->dst_palette_version = 0; - if (map->info.table) { - SDL_free(map->info.table); - map->info.table = NULL; - } -} - static void SDL_GL_SwapBuffers(void) { @@ -321,10 +195,6 @@ SDL_GL_SwapBuffers(void) static int SDL_WM_ToggleFullScreen(SDL_Surface * surface) { - int length; - void *pixels; - Uint8 *src, *dst; - int row; int window_w; int window_h; @@ -333,19 +203,6 @@ SDL_WM_ToggleFullScreen(SDL_Surface * surface) return 0; } - /* Copy the old bits out */ - length = SDL_PublicSurface->w * SDL_PublicSurface->format->BytesPerPixel; - pixels = SDL_malloc(SDL_PublicSurface->h * length); - if (pixels && SDL_PublicSurface->pixels) { - src = (Uint8*)SDL_PublicSurface->pixels; - dst = (Uint8*)pixels; - for (row = 0; row < SDL_PublicSurface->h; ++row) { - SDL_memcpy(dst, src, length); - src += SDL_PublicSurface->pitch; - dst += length; - } - } - /* Do the physical mode switch */ if (SDL_GetWindowFlags(SDL_VideoWindow) & SDL_WINDOW_FULLSCREEN) { if (SDL_SetWindowFullscreen(SDL_VideoWindow, 0) < 0) { @@ -359,103 +216,24 @@ SDL_WM_ToggleFullScreen(SDL_Surface * surface) SDL_PublicSurface->flags |= SDL_FULLSCREEN; } - /* Recreate the screen surface */ - SDL_WindowSurface = SDL_GetWindowSurface(SDL_VideoWindow); - if (!SDL_WindowSurface) { - /* We're totally hosed... */ - return 0; - } - /* Center the public surface in the window surface */ SDL_GetWindowSize(SDL_VideoWindow, &window_w, &window_h); - SDL_VideoViewport.x = (window_w - SDL_VideoSurface->w)/2; - SDL_VideoViewport.y = (window_h - SDL_VideoSurface->h)/2; - SDL_VideoViewport.w = SDL_VideoSurface->w; - SDL_VideoViewport.h = SDL_VideoSurface->h; - - /* Do some shuffling behind the application's back if format changes */ - if (SDL_VideoSurface->format->format != SDL_WindowSurface->format->format) { - if (SDL_ShadowSurface) { - if (SDL_ShadowSurface->format->format == SDL_WindowSurface->format->format) { - /* Whee! We don't need a shadow surface anymore! */ - SDL_VideoSurface->flags &= ~SDL_DONTFREE; - SDL_FreeSurface(SDL_VideoSurface); - SDL_free(SDL_ShadowSurface->pixels); - SDL_VideoSurface = SDL_ShadowSurface; - SDL_VideoSurface->flags |= SDL_PREALLOC; - SDL_ShadowSurface = NULL; - } else { - /* No problem, just change the video surface format */ - SDL_FreeFormat(SDL_VideoSurface->format); - SDL_VideoSurface->format = SDL_WindowSurface->format; - SDL_VideoSurface->format->refcount++; - SDL_InvalidateMap(SDL_ShadowSurface->map); - } - } else { - /* We can make the video surface the shadow surface */ - SDL_ShadowSurface = SDL_VideoSurface; - SDL_ShadowSurface->pitch = SDL_CalculatePitch(SDL_ShadowSurface); - SDL_ShadowSurface->pixels = SDL_malloc(SDL_ShadowSurface->h * SDL_ShadowSurface->pitch); - if (!SDL_ShadowSurface->pixels) { - /* Uh oh, we're hosed */ - SDL_ShadowSurface = NULL; - return 0; - } - SDL_ShadowSurface->flags &= ~SDL_PREALLOC; - - SDL_VideoSurface = SDL_CreateRGBSurfaceFrom(NULL, 0, 0, 32, 0, 0, 0, 0, 0); - SDL_VideoSurface->flags = SDL_ShadowSurface->flags; - SDL_VideoSurface->flags |= SDL_PREALLOC; - SDL_FreeFormat(SDL_VideoSurface->format); - SDL_VideoSurface->format = SDL_WindowSurface->format; - SDL_VideoSurface->format->refcount++; - SDL_VideoSurface->w = SDL_ShadowSurface->w; - SDL_VideoSurface->h = SDL_ShadowSurface->h; - } - } - - /* Update the video surface */ - SDL_VideoSurface->pitch = SDL_WindowSurface->pitch; - SDL_VideoSurface->pixels = (void *)((Uint8 *)SDL_WindowSurface->pixels + - SDL_VideoViewport.y * SDL_VideoSurface->pitch + - SDL_VideoViewport.x * SDL_VideoSurface->format->BytesPerPixel); - SDL_SetClipRect(SDL_VideoSurface, NULL); - - /* Copy the old bits back */ - if (pixels) { - src = (Uint8*)pixels; - dst = (Uint8*)SDL_PublicSurface->pixels; - for (row = 0; row < SDL_PublicSurface->h; ++row) { - SDL_memcpy(dst, src, length); - src += length; - dst += SDL_PublicSurface->pitch; - } - SDL_Flip(SDL_PublicSurface); - SDL_free(pixels); - } + SDL_VideoViewport.x = 0; + SDL_VideoViewport.y = 0; + SDL_VideoViewport.w = window_w; + SDL_VideoViewport.h = window_h; /* We're done! */ return 1; } -static void -ClearVideoSurface() -{ - if (SDL_ShadowSurface) { - SDL_FillRect(SDL_ShadowSurface, NULL, - SDL_MapRGB(SDL_ShadowSurface->format, 0, 0, 0)); - } - SDL_FillRect(SDL_WindowSurface, NULL, 0); - SDL_UpdateWindowSurface(SDL_VideoWindow); -} - static int SDL_ResizeVideoMode(int width, int height, int bpp, Uint32 flags) { int w, h; /* We can't resize something we don't have... */ - if (!SDL_VideoSurface) { + if (!SDL_PublicSurface) { return -1; } @@ -478,40 +256,8 @@ SDL_ResizeVideoMode(int width, int height, int bpp, Uint32 flags) SDL_SetWindowSize(SDL_VideoWindow, width, height); } - /* If we're in OpenGL mode, just resize the stub surface and we're done! */ - if (flags & SDL_OPENGL) { - SDL_VideoSurface->w = width; - SDL_VideoSurface->h = height; - return 0; - } - - SDL_WindowSurface = SDL_GetWindowSurface(SDL_VideoWindow); - if (!SDL_WindowSurface) { - return -1; - } - if (SDL_VideoSurface->format != SDL_WindowSurface->format) { - return -1; - } SDL_VideoSurface->w = width; SDL_VideoSurface->h = height; - SDL_VideoSurface->pixels = SDL_WindowSurface->pixels; - SDL_VideoSurface->pitch = SDL_WindowSurface->pitch; - SDL_SetClipRect(SDL_VideoSurface, NULL); - - if (SDL_ShadowSurface) { - SDL_ShadowSurface->w = width; - SDL_ShadowSurface->h = height; - SDL_ShadowSurface->pitch = SDL_CalculatePitch(SDL_ShadowSurface); - SDL_ShadowSurface->pixels = - SDL_realloc(SDL_ShadowSurface->pixels, - SDL_ShadowSurface->h * SDL_ShadowSurface->pitch); - SDL_SetClipRect(SDL_ShadowSurface, NULL); - SDL_InvalidateMap(SDL_ShadowSurface->map); - } else { - SDL_PublicSurface = SDL_VideoSurface; - } - - ClearVideoSurface(); return 0; } @@ -604,6 +350,26 @@ GetEnvironmentWindowPosition(int w, int h, int *x, int *y) } } +static void SDL2_DestroyWindow(void) +{ + /* Destroy existing window */ + SDL_PublicSurface = NULL; + if (SDL_VideoSurface) { + SDL_VideoSurface->flags &= ~SDL_DONTFREE; + SDL_FreeSurface(SDL_VideoSurface); + SDL_VideoSurface = NULL; + } + if (SDL_VideoContext) { + /* SDL_GL_MakeCurrent(0, NULL); *//* Doesn't do anything */ + SDL_GL_DeleteContext(SDL_VideoContext); + SDL_VideoContext = NULL; + } + if (SDL_VideoWindow) { + SDL_DestroyWindow(SDL_VideoWindow); + SDL_VideoWindow = NULL; + } +} + static SDL_Surface * SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) { @@ -611,8 +377,6 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) int display = GetVideoDisplay(); int window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(display); int window_y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(display); - int window_w; - int window_h; Uint32 window_flags; Uint32 surface_flags; @@ -641,32 +405,23 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) } /* Destroy existing window */ - SDL_PublicSurface = NULL; - if (SDL_ShadowSurface) { - SDL_ShadowSurface->flags &= ~SDL_DONTFREE; - SDL_FreeSurface(SDL_ShadowSurface); - SDL_ShadowSurface = NULL; - } - if (SDL_VideoSurface) { - SDL_VideoSurface->flags &= ~SDL_DONTFREE; - SDL_FreeSurface(SDL_VideoSurface); - SDL_VideoSurface = NULL; - } - if (SDL_VideoContext) { - /* SDL_GL_MakeCurrent(0, NULL); *//* Doesn't do anything */ - SDL_GL_DeleteContext(SDL_VideoContext); - SDL_VideoContext = NULL; - } - if (SDL_VideoWindow) { + if (SDL_VideoWindow) SDL_GetWindowPosition(SDL_VideoWindow, &window_x, &window_y); - SDL_DestroyWindow(SDL_VideoWindow); - } + SDL2_DestroyWindow(); /* Set up the event filter */ if (!SDL_GetEventFilter(NULL, NULL)) { SDL_SetEventFilter(SDL_CompatEventFilter, NULL); } +#ifndef USE_GLES + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); +#else // !USE_GLES + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); + //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); +#endif // !USE_GLES + /* Create a new window */ window_flags = SDL_WINDOW_SHOWN; if (flags & SDL_FULLSCREEN) { @@ -726,58 +481,6 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) return SDL_PublicSurface; } - /* Create the screen surface */ - SDL_WindowSurface = SDL_GetWindowSurface(SDL_VideoWindow); - if (!SDL_WindowSurface) { - return NULL; - } - - /* Center the public surface in the window surface */ - SDL_GetWindowSize(SDL_VideoWindow, &window_w, &window_h); - SDL_VideoViewport.x = (window_w - width)/2; - SDL_VideoViewport.y = (window_h - height)/2; - SDL_VideoViewport.w = width; - SDL_VideoViewport.h = height; - - SDL_VideoSurface = SDL_CreateRGBSurfaceFrom(NULL, 0, 0, 32, 0, 0, 0, 0, 0); - SDL_VideoSurface->flags |= surface_flags; - SDL_VideoSurface->flags |= SDL_DONTFREE; - SDL_FreeFormat(SDL_VideoSurface->format); - SDL_VideoSurface->format = SDL_WindowSurface->format; - SDL_VideoSurface->format->refcount++; - SDL_VideoSurface->w = width; - SDL_VideoSurface->h = height; - SDL_VideoSurface->pitch = SDL_WindowSurface->pitch; - SDL_VideoSurface->pixels = (void *)((Uint8 *)SDL_WindowSurface->pixels + - SDL_VideoViewport.y * SDL_VideoSurface->pitch + - SDL_VideoViewport.x * SDL_VideoSurface->format->BytesPerPixel); - SDL_SetClipRect(SDL_VideoSurface, NULL); - - /* Create a shadow surface if necessary */ - if ((bpp != SDL_VideoSurface->format->BitsPerPixel) - && !(flags & SDL_ANYFORMAT)) { - SDL_ShadowSurface = - SDL_CreateRGBSurface(0, width, height, bpp, 0, 0, 0, 0); - if (!SDL_ShadowSurface) { - return NULL; - } - SDL_ShadowSurface->flags |= surface_flags; - SDL_ShadowSurface->flags |= SDL_DONTFREE; - - /* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */ - if (SDL_ShadowSurface->format->palette) { - SDL_ShadowSurface->flags |= SDL_HWPALETTE; - //TODO SDL_DitherColors(SDL_ShadowSurface->format->palette->colors, - // SDL_ShadowSurface->format->BitsPerPixel); - } - SDL_FillRect(SDL_ShadowSurface, NULL, - SDL_MapRGB(SDL_ShadowSurface->format, 0, 0, 0)); - } - SDL_PublicSurface = - (SDL_ShadowSurface ? SDL_ShadowSurface : SDL_VideoSurface); - - ClearVideoSurface(); - /* We're finally done! */ - return SDL_PublicSurface; + return NULL; }