src/video/xbios/SDL_xbios.c
changeset 3283 1ed5d432e468
parent 3282 10a12f77f597
child 3284 2b95b2c0b6d4
equal deleted inserted replaced
3282:10a12f77f597 3283:1ed5d432e468
     1 /*
       
     2     SDL - Simple DirectMedia Layer
       
     3     Copyright (C) 1997-2009 Sam Lantinga
       
     4 
       
     5     This library is free software; you can redistribute it and/or
       
     6     modify it under the terms of the GNU Lesser General Public
       
     7     License as published by the Free Software Foundation; either
       
     8     version 2.1 of the License, or (at your option) any later version.
       
     9 
       
    10     This library is distributed in the hope that it will be useful,
       
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    13     Lesser General Public License for more details.
       
    14 
       
    15     You should have received a copy of the GNU Lesser General Public
       
    16     License along with this library; if not, write to the Free Software
       
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    18 
       
    19     Sam Lantinga
       
    20     slouken@libsdl.org
       
    21 */
       
    22 #include "SDL_config.h"
       
    23 
       
    24 /*
       
    25  * Xbios SDL video driver
       
    26  * 
       
    27  * Patrice Mandin
       
    28  */
       
    29 
       
    30 #include <sys/stat.h>
       
    31 #include <unistd.h>
       
    32 
       
    33 /* Mint includes */
       
    34 #include <mint/cookie.h>
       
    35 #include <mint/osbind.h>
       
    36 #include <mint/falcon.h>
       
    37 
       
    38 #include "SDL_video.h"
       
    39 #include "SDL_mouse.h"
       
    40 #include "../SDL_sysvideo.h"
       
    41 #include "../SDL_pixels_c.h"
       
    42 #include "../../events/SDL_events_c.h"
       
    43 
       
    44 #include "../ataricommon/SDL_ataric2p_s.h"
       
    45 #include "../ataricommon/SDL_atarievents_c.h"
       
    46 #include "../ataricommon/SDL_atarimxalloc_c.h"
       
    47 #include "../ataricommon/SDL_atarigl_c.h"
       
    48 #include "SDL_xbios.h"
       
    49 #include "SDL_xbiosmodes.h"
       
    50 
       
    51 /* Debug print info */
       
    52 #if 0
       
    53 #define DEBUG_PRINT(what) \
       
    54 	{ \
       
    55 		printf what; \
       
    56 	}
       
    57 #define DEBUG_VIDEO_XBIOS 1
       
    58 #else
       
    59 #define DEBUG_PRINT(what)
       
    60 #undef DEBUG_VIDEO_XBIOS
       
    61 #endif
       
    62 
       
    63 /* Initialization/Query functions */
       
    64 static int XBIOS_VideoInit(_THIS);
       
    65 static void XBIOS_VideoQuit(_THIS);
       
    66 
       
    67 /* Xbios driver bootstrap functions */
       
    68 
       
    69 static int
       
    70 XBIOS_Available(void)
       
    71 {
       
    72     unsigned long cookie_vdo, cookie_mil, cookie_hade, cookie_scpn;
       
    73 
       
    74     /* Milan/Hades Atari clones do not have an Atari video chip */
       
    75     if ((Getcookie(C__MIL, &cookie_mil) == C_FOUND) ||
       
    76         (Getcookie(C_hade, &cookie_hade) == C_FOUND)) {
       
    77         return 0;
       
    78     }
       
    79 
       
    80     /* Cookie _VDO present ? if not, assume ST machine */
       
    81     if (Getcookie(C__VDO, &cookie_vdo) != C_FOUND) {
       
    82         cookie_vdo = VDO_ST << 16;
       
    83     }
       
    84 
       
    85     /* Test if we have a monochrome monitor plugged in */
       
    86     switch (cookie_vdo >> 16) {
       
    87     case VDO_ST:
       
    88     case VDO_STE:
       
    89         if (Getrez() == (ST_HIGH >> 8))
       
    90             return 0;
       
    91         break;
       
    92     case VDO_TT:
       
    93         if ((EgetShift() & ES_MODE) == TT_HIGH)
       
    94             return 0;
       
    95         break;
       
    96     case VDO_F30:
       
    97         if (VgetMonitor() == MONITOR_MONO)
       
    98             return 0;
       
    99         /*if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) {
       
   100            if (!SDL_XBIOS_SB3Usable((scpn_cookie_t *) cookie_scpn)) {
       
   101            return 0;
       
   102            }
       
   103            } */
       
   104         break;
       
   105     default:
       
   106         return 0;
       
   107     }
       
   108 
       
   109     return 1;
       
   110 }
       
   111 
       
   112 static void
       
   113 XBIOS_DeleteDevice(SDL_VideoDevice * device)
       
   114 {
       
   115     SDL_free(device->driverdata);
       
   116     SDL_free(device);
       
   117 }
       
   118 
       
   119 static SDL_VideoDevice *
       
   120 XBIOS_CreateDevice(int devindex)
       
   121 {
       
   122     SDL_VideoDevice *device;
       
   123     SDL_VideoData *data;
       
   124 
       
   125     /* Initialize all variables that we clean on shutdown */
       
   126     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
       
   127     if (device) {
       
   128         data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
       
   129     }
       
   130     if (!device || !data) {
       
   131         SDL_OutOfMemory();
       
   132         if (device) {
       
   133             SDL_free(device);
       
   134         }
       
   135         return NULL;
       
   136     }
       
   137     device->driverdata = data;
       
   138 
       
   139     /* Video functions */
       
   140     device->VideoInit = XBIOS_VideoInit;
       
   141     device->VideoQuit = XBIOS_VideoQuit;
       
   142 
       
   143     /* Modes */
       
   144     device->GetDisplayModes = SDL_XBIOS_GetDisplayModes;
       
   145     device->SetDisplayMode = SDL_XBIOS_SetDisplayMode;
       
   146 
       
   147     /* Events */
       
   148     device->PumpEvents = SDL_Atari_PumpEvents;
       
   149 
       
   150 #if SDL_VIDEO_OPENGL
       
   151     /* OpenGL functions */
       
   152     device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary;
       
   153     device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress;
       
   154     device->GL_CreateContext = NULL;
       
   155     device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent;
       
   156     device->GL_SetSwapInterval = NULL;
       
   157     device->GL_GetSwapInterval = NULL;
       
   158     device->GL_SwapWindow = XBIOS_GL_SwapBuffers;
       
   159     device->GL_DeleteContext = NULL;
       
   160 #endif
       
   161 
       
   162     device->free = XBIOS_DeleteDevice;
       
   163 
       
   164     return device;
       
   165 }
       
   166 
       
   167 VideoBootStrap XBIOS_bootstrap = {
       
   168     "xbios", "Atari Xbios driver",
       
   169     XBIOS_Available, XBIOS_CreateDevice
       
   170 };
       
   171 
       
   172 static int
       
   173 XBIOS_VideoInit(_THIS)
       
   174 {
       
   175     /* Save screensaver settings */
       
   176 
       
   177     /* Init video mode list, save current video mode settings */
       
   178     SDL_XBIOS_InitModes(_this);
       
   179 
       
   180     return (0);
       
   181 }
       
   182 
       
   183 static void
       
   184 XBIOS_VideoQuit(_THIS)
       
   185 {
       
   186     Atari_ShutdownEvents();
       
   187 
       
   188     /* Restore screensaver settings */
       
   189 
       
   190     /* Restore previous video mode settings */
       
   191     SDL_XBIOS_QuitModes(_this);
       
   192 }