Save/restore current video mode and palette
authorPatrice Mandin <patmandin@gmail.com>
Mon, 13 Nov 2006 20:34:18 +0000
changeset 2073790726541708
parent 2072 4b3f98a9a2c1
child 2074 9e6dc39f48b6
Save/restore current video mode and palette
src/video/xbios/SDL_xbios.c
src/video/xbios/SDL_xbios.h
src/video/xbios/SDL_xbiosmodes.c
src/video/xbios/SDL_xbiosmodes.h
     1.1 --- a/src/video/xbios/SDL_xbios.c	Mon Nov 13 19:59:28 2006 +0000
     1.2 +++ b/src/video/xbios/SDL_xbios.c	Mon Nov 13 20:34:18 2006 +0000
     1.3 @@ -174,7 +174,7 @@
     1.4  {
     1.5      /* Save screensaver settings */
     1.6  
     1.7 -    /* Init video mode list */
     1.8 +    /* Init video mode list, save current video mode settings */
     1.9      SDL_XBIOS_InitModes(_this);
    1.10  
    1.11      return (0);
    1.12 @@ -187,5 +187,6 @@
    1.13  
    1.14      /* Restore screensaver settings */
    1.15  
    1.16 +    /* Restore previous video mode settings */
    1.17      SDL_XBIOS_QuitModes(_this);
    1.18  }
     2.1 --- a/src/video/xbios/SDL_xbios.h	Mon Nov 13 19:59:28 2006 +0000
     2.2 +++ b/src/video/xbios/SDL_xbios.h	Mon Nov 13 20:34:18 2006 +0000
     2.3 @@ -29,7 +29,12 @@
     2.4  
     2.5  typedef struct SDL_VideoData
     2.6  {
     2.7 -    long cookie_vdo;
     2.8 +    long cookie_vdo;		/* _VDO cookie */
     2.9 +
    2.10 +    Uint16 old_modecode;	/* Current video mode */
    2.11 +    void *old_vbase;		/* Current pointer to video RAM */
    2.12 +    int old_numcol;		/* Number of colors in saved palette */
    2.13 +    Uint32 old_palette[256];	/* Buffer to save current palette */
    2.14  
    2.15  #if 0
    2.16      int old_video_mode;         /* Old video mode before entering SDL */
     3.1 --- a/src/video/xbios/SDL_xbiosmodes.c	Mon Nov 13 19:59:28 2006 +0000
     3.2 +++ b/src/video/xbios/SDL_xbiosmodes.c	Mon Nov 13 20:34:18 2006 +0000
     3.3 @@ -105,11 +105,146 @@
     3.4      SDL_AddVideoDisplay(&display);
     3.5  }
     3.6  
     3.7 +/* Current video mode save/restore */
     3.8 +
     3.9 +static void
    3.10 +SDL_XBIOS_ModeSave(_THIS)
    3.11 +{
    3.12 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    3.13 +
    3.14 +    data->old_vbase = Physbase();
    3.15 +
    3.16 +    switch (data->cookie_vdo >> 16) {
    3.17 +    case VDO_ST:
    3.18 +    case VDO_STE:
    3.19 +        data->old_modecode = Getrez();
    3.20 +        break;
    3.21 +    case VDO_TT:
    3.22 +        data->old_modecode = EgetShift();
    3.23 +        break;
    3.24 +    case VDO_F30:
    3.25 +        data->old_modecode = VsetMode(-1);
    3.26 +        break;
    3.27 +    }
    3.28 +}
    3.29 +
    3.30 +static void
    3.31 +SDL_XBIOS_ModeRestore(_THIS)
    3.32 +{
    3.33 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    3.34 +
    3.35 +    switch (data->cookie_vdo >> 16) {
    3.36 +    case VDO_ST:
    3.37 +    case VDO_STE:
    3.38 +        Setscreen(-1, data->old_vbase, data->old_modecode);
    3.39 +        break;
    3.40 +    case VDO_TT:
    3.41 +        Setscreen(-1, data->old_vbase, -1);
    3.42 +	EsetShift(data->old_modecode);
    3.43 +        break;
    3.44 +    case VDO_F30:
    3.45 +        Setscreen(-1, data->old_vbase, -1);
    3.46 +        VsetMode(data->old_modecode);
    3.47 +        break;
    3.48 +    }
    3.49 +}
    3.50 +
    3.51 +/* Current palette save/restore */
    3.52 +
    3.53 +static void
    3.54 +SDL_XBIOS_PaletteSave(_THIS)
    3.55 +{
    3.56 +    int i;
    3.57 +    Uint16 *palette;
    3.58 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    3.59 +
    3.60 +    data->old_numcol = 0;
    3.61 +
    3.62 +    switch (data->cookie_vdo >> 16) {
    3.63 +    case VDO_ST:
    3.64 +    case VDO_STE:
    3.65 +        switch (data->old_modecode << 8) {
    3.66 +        case ST_LOW:
    3.67 +            data->old_numcol = 16;
    3.68 +            break;
    3.69 +        case ST_MED:
    3.70 +            data->old_numcol = 4;
    3.71 +            break;
    3.72 +        case ST_HIGH:
    3.73 +            data->old_numcol = 2;
    3.74 +            break;
    3.75 +        }
    3.76 +
    3.77 +        palette = (Uint16 *) data->old_palette;
    3.78 +        for (i = 0; i < data->old_numcol; i++) {
    3.79 +            *palette++ = Setcolor(i, -1);
    3.80 +        }
    3.81 +        break;
    3.82 +    case VDO_TT:
    3.83 +        switch (data->old_modecode & ES_MODE) {
    3.84 +        case TT_LOW:
    3.85 +            data->old_numcol = 256;
    3.86 +            break;
    3.87 +        case ST_LOW:
    3.88 +        case TT_MED:
    3.89 +            data->old_numcol = 16;
    3.90 +            break;
    3.91 +        case ST_MED:
    3.92 +            data->old_numcol = 4;
    3.93 +            break;
    3.94 +        case ST_HIGH:
    3.95 +        case TT_HIGH:
    3.96 +            data->old_numcol = 2;
    3.97 +            break;
    3.98 +        }
    3.99 +        if (data->old_numcol) {
   3.100 +            EgetPalette(0, data->old_numcol, data->old_palette);
   3.101 +        }
   3.102 +        break;
   3.103 +    case VDO_F30:
   3.104 +        data->old_numcol = 1 << (1 << (data->old_modecode & NUMCOLS));
   3.105 +        if (data->old_numcol > 256) {
   3.106 +	    data->old_numcol = 0;
   3.107 +	} else {
   3.108 +            VgetRGB(0, data->old_numcol, data->old_palette);
   3.109 +        }
   3.110 +        break;
   3.111 +    }
   3.112 +}
   3.113 +
   3.114 +static void
   3.115 +SDL_XBIOS_PaletteRestore(_THIS)
   3.116 +{
   3.117 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   3.118 +
   3.119 +    if (data->old_numcol == 0) {
   3.120 +        return;
   3.121 +    }
   3.122 +
   3.123 +    switch (data->cookie_vdo >> 16) {
   3.124 +    case VDO_ST:
   3.125 +    case VDO_STE:
   3.126 +        Setpalette(data->old_palette);
   3.127 +        break;
   3.128 +    case VDO_TT:
   3.129 +        EsetPalette(0, data->old_numcol, data->old_palette);
   3.130 +        break;
   3.131 +    case VDO_F30:
   3.132 +        VsetRGB(0, data->old_numcol, data->old_palette);
   3.133 +        break;
   3.134 +    }
   3.135 +}
   3.136 +
   3.137 +/* Public functions for use by the driver */
   3.138 +
   3.139  void
   3.140  SDL_XBIOS_InitModes(_THIS)
   3.141  {
   3.142      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   3.143  
   3.144 +    SDL_XBIOS_PaletteSave(_this);
   3.145 +    SDL_XBIOS_ModeSave(_this);
   3.146 +
   3.147      switch (data->cookie_vdo >> 16) {
   3.148      case VDO_ST:
   3.149      case VDO_STE:
   3.150 @@ -126,7 +261,7 @@
   3.151          break;
   3.152      case VDO_F30:
   3.153          {
   3.154 -	    Uint16 modecodemask = VsetMode(-1) & (VGA | PAL);
   3.155 +	    Uint16 modecodemask = data->old_modecode & (VGA | PAL);
   3.156              int i;
   3.157  
   3.158              switch (VgetMonitor()) {
   3.159 @@ -172,6 +307,9 @@
   3.160  void
   3.161  SDL_XBIOS_QuitModes(_THIS)
   3.162  {
   3.163 +    SDL_XBIOS_ModeRestore(_this);
   3.164 +    SDL_XBIOS_PaletteRestore(_this);
   3.165 +    Vsync();
   3.166  }
   3.167  
   3.168  /* vi: set ts=4 sw=4 expandtab: */
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/video/xbios/SDL_xbiosmodes.h	Mon Nov 13 20:34:18 2006 +0000
     4.3 @@ -0,0 +1,41 @@
     4.4 +/*
     4.5 +    SDL - Simple DirectMedia Layer
     4.6 +    Copyright (C) 1997-2006 Sam Lantinga
     4.7 +
     4.8 +    This library is free software; you can redistribute it and/or
     4.9 +    modify it under the terms of the GNU Lesser General Public
    4.10 +    License as published by the Free Software Foundation; either
    4.11 +    version 2.1 of the License, or (at your option) any later version.
    4.12 +
    4.13 +    This library is distributed in the hope that it will be useful,
    4.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 +    Lesser General Public License for more details.
    4.17 +
    4.18 +    You should have received a copy of the GNU Lesser General Public
    4.19 +    License along with this library; if not, write to the Free Software
    4.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    4.21 +
    4.22 +    Sam Lantinga
    4.23 +    slouken@libsdl.org
    4.24 +*/
    4.25 +#include "SDL_config.h"
    4.26 +
    4.27 +#ifndef _SDL_xbiosmodes_h
    4.28 +#define _SDL_xbiosmodes_h
    4.29 +
    4.30 +typedef struct
    4.31 +{
    4.32 +    Uint16 modecode;
    4.33 +    SDL_bool doubleline;
    4.34 +    SDL_bool c2p4;
    4.35 +} SDL_DisplayData;
    4.36 +
    4.37 +extern void SDL_XBIOS_InitModes(_THIS);
    4.38 +extern void SDL_XBIOS_GetDisplayModes(_THIS);
    4.39 +extern int SDL_XBIOS_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
    4.40 +extern void SDL_XBIOS_QuitModes(_THIS);
    4.41 +
    4.42 +#endif /* _SDL_xbiosmodes_h */
    4.43 +
    4.44 +/* vi: set ts=4 sw=4 expandtab: */