Mercurial > sdl-ios-xcode
changeset 2073:790726541708
Save/restore current video mode and palette
author | Patrice Mandin <patmandin@gmail.com> |
---|---|
date | Mon, 13 Nov 2006 20:34:18 +0000 |
parents | 4b3f98a9a2c1 |
children | 9e6dc39f48b6 |
files | src/video/xbios/SDL_xbios.c src/video/xbios/SDL_xbios.h src/video/xbios/SDL_xbiosmodes.c src/video/xbios/SDL_xbiosmodes.h |
diffstat | 4 files changed, 188 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/video/xbios/SDL_xbios.c Mon Nov 13 19:59:28 2006 +0000 +++ b/src/video/xbios/SDL_xbios.c Mon Nov 13 20:34:18 2006 +0000 @@ -174,7 +174,7 @@ { /* Save screensaver settings */ - /* Init video mode list */ + /* Init video mode list, save current video mode settings */ SDL_XBIOS_InitModes(_this); return (0); @@ -187,5 +187,6 @@ /* Restore screensaver settings */ + /* Restore previous video mode settings */ SDL_XBIOS_QuitModes(_this); }
--- a/src/video/xbios/SDL_xbios.h Mon Nov 13 19:59:28 2006 +0000 +++ b/src/video/xbios/SDL_xbios.h Mon Nov 13 20:34:18 2006 +0000 @@ -29,7 +29,12 @@ typedef struct SDL_VideoData { - long cookie_vdo; + long cookie_vdo; /* _VDO cookie */ + + Uint16 old_modecode; /* Current video mode */ + void *old_vbase; /* Current pointer to video RAM */ + int old_numcol; /* Number of colors in saved palette */ + Uint32 old_palette[256]; /* Buffer to save current palette */ #if 0 int old_video_mode; /* Old video mode before entering SDL */
--- a/src/video/xbios/SDL_xbiosmodes.c Mon Nov 13 19:59:28 2006 +0000 +++ b/src/video/xbios/SDL_xbiosmodes.c Mon Nov 13 20:34:18 2006 +0000 @@ -105,11 +105,146 @@ SDL_AddVideoDisplay(&display); } +/* Current video mode save/restore */ + +static void +SDL_XBIOS_ModeSave(_THIS) +{ + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; + + data->old_vbase = Physbase(); + + switch (data->cookie_vdo >> 16) { + case VDO_ST: + case VDO_STE: + data->old_modecode = Getrez(); + break; + case VDO_TT: + data->old_modecode = EgetShift(); + break; + case VDO_F30: + data->old_modecode = VsetMode(-1); + break; + } +} + +static void +SDL_XBIOS_ModeRestore(_THIS) +{ + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; + + switch (data->cookie_vdo >> 16) { + case VDO_ST: + case VDO_STE: + Setscreen(-1, data->old_vbase, data->old_modecode); + break; + case VDO_TT: + Setscreen(-1, data->old_vbase, -1); + EsetShift(data->old_modecode); + break; + case VDO_F30: + Setscreen(-1, data->old_vbase, -1); + VsetMode(data->old_modecode); + break; + } +} + +/* Current palette save/restore */ + +static void +SDL_XBIOS_PaletteSave(_THIS) +{ + int i; + Uint16 *palette; + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; + + data->old_numcol = 0; + + switch (data->cookie_vdo >> 16) { + case VDO_ST: + case VDO_STE: + switch (data->old_modecode << 8) { + case ST_LOW: + data->old_numcol = 16; + break; + case ST_MED: + data->old_numcol = 4; + break; + case ST_HIGH: + data->old_numcol = 2; + break; + } + + palette = (Uint16 *) data->old_palette; + for (i = 0; i < data->old_numcol; i++) { + *palette++ = Setcolor(i, -1); + } + break; + case VDO_TT: + switch (data->old_modecode & ES_MODE) { + case TT_LOW: + data->old_numcol = 256; + break; + case ST_LOW: + case TT_MED: + data->old_numcol = 16; + break; + case ST_MED: + data->old_numcol = 4; + break; + case ST_HIGH: + case TT_HIGH: + data->old_numcol = 2; + break; + } + if (data->old_numcol) { + EgetPalette(0, data->old_numcol, data->old_palette); + } + break; + case VDO_F30: + data->old_numcol = 1 << (1 << (data->old_modecode & NUMCOLS)); + if (data->old_numcol > 256) { + data->old_numcol = 0; + } else { + VgetRGB(0, data->old_numcol, data->old_palette); + } + break; + } +} + +static void +SDL_XBIOS_PaletteRestore(_THIS) +{ + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; + + if (data->old_numcol == 0) { + return; + } + + switch (data->cookie_vdo >> 16) { + case VDO_ST: + case VDO_STE: + Setpalette(data->old_palette); + break; + case VDO_TT: + EsetPalette(0, data->old_numcol, data->old_palette); + break; + case VDO_F30: + VsetRGB(0, data->old_numcol, data->old_palette); + break; + } +} + +/* Public functions for use by the driver */ + void SDL_XBIOS_InitModes(_THIS) { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; + SDL_XBIOS_PaletteSave(_this); + SDL_XBIOS_ModeSave(_this); + switch (data->cookie_vdo >> 16) { case VDO_ST: case VDO_STE: @@ -126,7 +261,7 @@ break; case VDO_F30: { - Uint16 modecodemask = VsetMode(-1) & (VGA | PAL); + Uint16 modecodemask = data->old_modecode & (VGA | PAL); int i; switch (VgetMonitor()) { @@ -172,6 +307,9 @@ void SDL_XBIOS_QuitModes(_THIS) { + SDL_XBIOS_ModeRestore(_this); + SDL_XBIOS_PaletteRestore(_this); + Vsync(); } /* vi: set ts=4 sw=4 expandtab: */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/xbios/SDL_xbiosmodes.h Mon Nov 13 20:34:18 2006 +0000 @@ -0,0 +1,41 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#ifndef _SDL_xbiosmodes_h +#define _SDL_xbiosmodes_h + +typedef struct +{ + Uint16 modecode; + SDL_bool doubleline; + SDL_bool c2p4; +} SDL_DisplayData; + +extern void SDL_XBIOS_InitModes(_THIS); +extern void SDL_XBIOS_GetDisplayModes(_THIS); +extern int SDL_XBIOS_SetDisplayMode(_THIS, SDL_DisplayMode * mode); +extern void SDL_XBIOS_QuitModes(_THIS); + +#endif /* _SDL_xbiosmodes_h */ + +/* vi: set ts=4 sw=4 expandtab: */