2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
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.
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.
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
22 #include "SDL_config.h"
25 * Xbios SDL video driver
34 #include <mint/cookie.h>
35 #include <mint/osbind.h>
36 #include <mint/falcon.h>
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"
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_xbios_blowup.h"
50 #include "SDL_xbios_centscreen.h"
51 #include "SDL_xbios_sb3.h"
52 #include "SDL_xbios_tveille.h"
53 #include "SDL_xbios_milan.h"
55 #define XBIOS_VID_DRIVER_NAME "xbios"
58 #define C_fVDI 0x66564449L
61 /* Debug print info */
63 #define DEBUG_PRINT(what) \
67 #define DEBUG_VIDEO_XBIOS 1
69 #define DEBUG_PRINT(what)
70 #undef DEBUG_VIDEO_XBIOS
73 /* Initialization/Query functions */
74 static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat);
75 static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
76 static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
77 static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
78 static void XBIOS_VideoQuit(_THIS);
80 /* Hardware surface functions */
81 static int XBIOS_AllocHWSurface(_THIS, SDL_Surface *surface);
82 static int XBIOS_LockHWSurface(_THIS, SDL_Surface *surface);
83 static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface);
84 static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface);
85 static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface);
86 static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
89 /* OpenGL functions */
90 static void XBIOS_GL_SwapBuffers(_THIS);
93 /* To setup palette */
95 static unsigned short TT_palette[256];
96 static unsigned long F30_palette[256];
98 /* Default list of video modes */
100 static const xbiosmode_t stmodes[1]={
101 {ST_LOW>>8,320,200,4, XBIOSMODE_C2P}
104 static const xbiosmode_t ttmodes[2]={
105 {TT_LOW,320,480,8, XBIOSMODE_C2P},
106 {TT_LOW,320,240,8, XBIOSMODE_C2P|XBIOSMODE_DOUBLELINE}
109 static const xbiosmode_t falconrgbmodes[16]={
110 {BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,0},
111 {BPS16|COL80|OVERSCAN,768,240,16,0},
112 {BPS16|COL80|VERTFLAG,640,400,16,0},
113 {BPS16|COL80,640,200,16,0},
114 {BPS16|OVERSCAN|VERTFLAG,384,480,16,0},
115 {BPS16|OVERSCAN,384,240,16,0},
116 {BPS16|VERTFLAG,320,400,16,0},
117 {BPS16,320,200,16,0},
118 {BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,XBIOSMODE_C2P},
119 {BPS8|COL80|OVERSCAN,768,240,8,XBIOSMODE_C2P},
120 {BPS8|COL80|VERTFLAG,640,400,8,XBIOSMODE_C2P},
121 {BPS8|COL80,640,200,8,XBIOSMODE_C2P},
122 {BPS8|OVERSCAN|VERTFLAG,384,480,8,XBIOSMODE_C2P},
123 {BPS8|OVERSCAN,384,240,8,XBIOSMODE_C2P},
124 {BPS8|VERTFLAG,320,400,8,XBIOSMODE_C2P},
125 {BPS8,320,200,8,XBIOSMODE_C2P}
128 static const xbiosmode_t falconvgamodes[6]={
129 {BPS16,320,480,16,0},
130 {BPS16|VERTFLAG,320,240,16,0},
131 {BPS8|COL80,640,480,8,XBIOSMODE_C2P},
132 {BPS8|COL80|VERTFLAG,640,240,8,XBIOSMODE_C2P},
133 {BPS8,320,480,8,XBIOSMODE_C2P},
134 {BPS8|VERTFLAG,320,240,8,XBIOSMODE_C2P}
137 /* Xbios driver bootstrap functions */
139 static int XBIOS_Available(void)
141 unsigned long cookie_vdo, cookie_mil, cookie_hade, cookie_scpn;
142 unsigned long cookie_fvdi;
143 const char *envr = SDL_getenv("SDL_VIDEODRIVER");
145 /* Milan/Hades Atari clones do not have an Atari video chip */
146 if ( /*(Getcookie(C__MIL, &cookie_mil) == C_FOUND) ||*/
147 (Getcookie(C_hade, &cookie_hade) == C_FOUND) ) {
151 /* fVDI means graphic card, so no Xbios with it */
152 if (Getcookie(C_fVDI, &cookie_fvdi) == C_FOUND) {
156 if (SDL_strcmp(envr, XBIOS_VID_DRIVER_NAME)!=0) {
159 /* Except if we force Xbios usage, through env var */
162 /* Cookie _VDO present ? if not, assume ST machine */
163 if (Getcookie(C__VDO, &cookie_vdo) != C_FOUND) {
164 cookie_vdo = VDO_ST << 16;
167 /* Test if we have a monochrome monitor plugged in */
168 switch( cookie_vdo >>16) {
171 if ( Getrez() == (ST_HIGH>>8) )
175 if ( (EgetShift() & ES_MODE) == TT_HIGH)
179 if ( VgetMonitor() == MONITOR_MONO)
181 if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) {
182 if (!SDL_XBIOS_SB3Usable((scpn_cookie_t *)cookie_scpn)) {
196 static void XBIOS_DeleteDevice(SDL_VideoDevice *device)
198 SDL_free(device->hidden);
202 static SDL_VideoDevice *XBIOS_CreateDevice(int devindex)
204 SDL_VideoDevice *device;
206 /* Initialize all variables that we clean on shutdown */
207 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
209 SDL_memset(device, 0, (sizeof *device));
210 device->hidden = (struct SDL_PrivateVideoData *)
211 SDL_malloc((sizeof *device->hidden));
212 device->gl_data = (struct SDL_PrivateGLData *)
213 SDL_malloc((sizeof *device->gl_data));
215 if ( (device == NULL) || (device->hidden == NULL) ) {
222 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
223 SDL_memset(device->gl_data, 0, sizeof(*device->gl_data));
225 /* Video functions */
226 device->VideoInit = XBIOS_VideoInit;
227 device->ListModes = XBIOS_ListModes;
228 device->SetVideoMode = XBIOS_SetVideoMode;
229 device->SetColors = XBIOS_SetColors;
230 device->UpdateRects = NULL;
231 device->VideoQuit = XBIOS_VideoQuit;
232 device->AllocHWSurface = XBIOS_AllocHWSurface;
233 device->LockHWSurface = XBIOS_LockHWSurface;
234 device->UnlockHWSurface = XBIOS_UnlockHWSurface;
235 device->FlipHWSurface = XBIOS_FlipHWSurface;
236 device->FreeHWSurface = XBIOS_FreeHWSurface;
239 /* OpenGL functions */
240 device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary;
241 device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress;
242 device->GL_GetAttribute = SDL_AtariGL_GetAttribute;
243 device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent;
244 device->GL_SwapBuffers = XBIOS_GL_SwapBuffers;
248 device->InitOSKeymap = Atari_InitOSKeymap;
249 device->PumpEvents = Atari_PumpEvents;
251 device->free = XBIOS_DeleteDevice;
256 VideoBootStrap XBIOS_bootstrap = {
257 XBIOS_VID_DRIVER_NAME, "Atari Xbios driver",
258 XBIOS_Available, XBIOS_CreateDevice
261 void SDL_XBIOS_AddMode(_THIS, int actually_add, const xbiosmode_t *modeinfo)
265 switch(modeinfo->depth) {
278 if ( actually_add ) {
279 SDL_Rect saved_rect[2];
280 xbiosmode_t saved_mode[2];
283 /* Add the mode, sorted largest to smallest */
286 while ( (SDL_modelist[i][j]->w > modeinfo->width) ||
287 (SDL_modelist[i][j]->h > modeinfo->height) ) {
290 /* Skip modes that are already in our list */
291 if ( (SDL_modelist[i][j]->w == modeinfo->width) &&
292 (SDL_modelist[i][j]->h == modeinfo->height) ) {
295 /* Insert the new mode */
296 saved_rect[b] = *SDL_modelist[i][j];
297 SDL_memcpy(&saved_mode[b], SDL_xbiosmode[i][j], sizeof(xbiosmode_t));
298 SDL_modelist[i][j]->w = modeinfo->width;
299 SDL_modelist[i][j]->h = modeinfo->height;
300 SDL_memcpy(SDL_xbiosmode[i][j], modeinfo, sizeof(xbiosmode_t));
301 /* Everybody scoot down! */
302 if ( saved_rect[b].w && saved_rect[b].h ) {
303 for ( ++j; SDL_modelist[i][j]->w; ++j ) {
304 saved_rect[!b] = *SDL_modelist[i][j];
305 memcpy(&saved_mode[!b], SDL_xbiosmode[i][j], sizeof(xbiosmode_t));
306 *SDL_modelist[i][j] = saved_rect[b];
307 SDL_memcpy(SDL_xbiosmode[i][j], &saved_mode[b], sizeof(xbiosmode_t));
310 *SDL_modelist[i][j] = saved_rect[b];
311 SDL_memcpy(SDL_xbiosmode[i][j], &saved_mode[b], sizeof(xbiosmode_t));
318 static void XBIOS_ListSTModes(_THIS, int actually_add)
320 SDL_XBIOS_AddMode(this, actually_add, &stmodes[0]);
323 static void XBIOS_ListTTModes(_THIS, int actually_add)
327 for (i=0; i<2; i++) {
328 SDL_XBIOS_AddMode(this, actually_add, &ttmodes[i]);
332 static void XBIOS_ListFalconRgbModes(_THIS, int actually_add)
336 for (i=0; i<16; i++) {
337 xbiosmode_t modeinfo;
339 SDL_memcpy(&modeinfo, &falconrgbmodes[i], sizeof(xbiosmode_t));
340 modeinfo.number &= ~(VGA|PAL);
341 modeinfo.number |= XBIOS_oldvmode & (VGA|PAL);
343 SDL_XBIOS_AddMode(this, actually_add, &modeinfo);
347 static void XBIOS_ListFalconVgaModes(_THIS, int actually_add)
351 for (i=0; i<6; i++) {
352 xbiosmode_t modeinfo;
354 SDL_memcpy(&modeinfo, &falconvgamodes[i], sizeof(xbiosmode_t));
355 modeinfo.number &= ~(VGA|PAL);
356 modeinfo.number |= XBIOS_oldvmode & (VGA|PAL);
358 SDL_XBIOS_AddMode(this, actually_add, &modeinfo);
362 static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
365 xbiosmode_t *current_mode;
366 unsigned long cookie_blow, cookie_scpn, cookie_cnts;
368 /* Initialize all variables that we clean on shutdown */
369 for ( i=0; i<NUM_MODELISTS; ++i ) {
371 SDL_modelist[i] = NULL;
372 SDL_xbiosmode[i] = NULL;
375 /* Cookie _VDO present ? if not, assume ST machine */
376 if (Getcookie(C__VDO, &XBIOS_cvdo) != C_FOUND) {
377 XBIOS_cvdo = VDO_ST << 16;
380 /* Allocate memory for old palette */
381 XBIOS_oldpalette = (void *)SDL_malloc(256*sizeof(long));
382 if ( !XBIOS_oldpalette ) {
383 SDL_SetError("Unable to allocate memory for old palette\n");
387 /* Initialize video mode list */
388 /* and save current screen status (palette, screen address, video mode) */
389 XBIOS_centscreen = SDL_FALSE;
390 XBIOS_oldvbase = Physbase();
392 /* Determine the current screen size */
393 this->info.current_w = 0;
394 this->info.current_h = 0;
396 /* Determine the screen depth (use default 8-bit depth) */
397 vformat->BitsPerPixel = 8;
399 /* First allocate room for needed video modes */
400 switch (XBIOS_cvdo >>16) {
406 XBIOS_oldvmode=Getrez();
407 switch(XBIOS_oldvmode << 8) {
419 oldpalette= (short *) XBIOS_oldpalette;
420 for (i=0;i<XBIOS_oldnumcol;i++) {
421 *oldpalette++=Setcolor(i,-1);
424 XBIOS_ListSTModes(this, 0);
428 XBIOS_oldvmode=EgetShift();
430 switch(XBIOS_oldvmode & ES_MODE) {
446 if (XBIOS_oldnumcol) {
447 EgetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette);
450 XBIOS_ListTTModes(this, 0);
453 XBIOS_oldvmode=VsetMode(-1);
455 XBIOS_oldnumcol= 1<< (1 << (XBIOS_oldvmode & NUMCOLS));
456 if (XBIOS_oldnumcol > 256) {
459 if (XBIOS_oldnumcol) {
460 VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
463 vformat->BitsPerPixel = 16;
465 /* ScreenBlaster 3 ? */
466 if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) {
467 SDL_XBIOS_ListSB3Modes(this, 0, (scpn_cookie_t *)cookie_scpn);
470 if (Getcookie(C_CNTS, &cookie_cnts) == C_FOUND) {
471 XBIOS_oldvmode = SDL_XBIOS_ListCentscreenModes(this, 0);
472 XBIOS_centscreen = SDL_TRUE;
474 /* Standard, with or without Blowup */
476 switch (VgetMonitor())
480 XBIOS_ListFalconRgbModes(this, 0);
483 XBIOS_ListFalconVgaModes(this, 0);
487 if (Getcookie(C_BLOW, &cookie_blow) == C_FOUND) {
488 SDL_XBIOS_ListBlowupModes(this, 0, (blow_cookie_t *)cookie_blow);
496 /* Read infos about current mode */
497 VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_GETMODE);
499 si.size = sizeof(SCREENINFO);
500 si.devID = XBIOS_oldvmode;
502 VsetScreen(-1, &si, MI_MAGIC, CMD_GETINFO);
504 this->info.current_w = si.scrWidth;
505 this->info.current_h = si.scrHeight;
508 if (si.scrFlags & SCRINFO_OK) {
509 if (si.scrPlanes <= 8) {
510 XBIOS_oldnumcol = 1<<si.scrPlanes;
513 if (XBIOS_oldnumcol) {
514 VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
517 SDL_XBIOS_ListMilanModes(this, 0);
522 for ( i=0; i<NUM_MODELISTS; ++i ) {
525 SDL_xbiosmode[i] = (xbiosmode_t **)
526 SDL_malloc((SDL_nummodes[i]+1)*sizeof(xbiosmode_t *));
527 if ( SDL_xbiosmode[i] == NULL ) {
531 for ( j=0; j<SDL_nummodes[i]; ++j ) {
532 SDL_xbiosmode[i][j]=(xbiosmode_t *)SDL_malloc(sizeof(xbiosmode_t));
533 if ( SDL_xbiosmode[i][j] == NULL ) {
537 SDL_memset(SDL_xbiosmode[i][j], 0, sizeof(xbiosmode_t));
539 SDL_xbiosmode[i][j] = NULL;
541 SDL_modelist[i] = (SDL_Rect **)
542 SDL_malloc((SDL_nummodes[i]+1)*sizeof(SDL_Rect *));
543 if ( SDL_modelist[i] == NULL ) {
547 for ( j=0; j<SDL_nummodes[i]; ++j ) {
548 SDL_modelist[i][j]=(SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
549 if ( SDL_modelist[i][j] == NULL ) {
553 SDL_memset(SDL_modelist[i][j], 0, sizeof(SDL_Rect));
555 SDL_modelist[i][j] = NULL;
558 /* Now fill the mode list */
559 switch (XBIOS_cvdo >>16) {
562 XBIOS_ListSTModes(this, 1);
565 XBIOS_ListTTModes(this, 1);
568 /* ScreenBlaster 3 ? */
569 if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) {
570 SDL_XBIOS_ListSB3Modes(this, 1, (scpn_cookie_t *)cookie_scpn);
573 if (Getcookie(C_CNTS, &cookie_cnts) == C_FOUND) {
574 XBIOS_oldvmode = SDL_XBIOS_ListCentscreenModes(this, 1);
575 XBIOS_centscreen = SDL_TRUE;
577 /* Standard, with or without Blowup */
579 switch (VgetMonitor())
583 XBIOS_ListFalconRgbModes(this, 1);
586 XBIOS_ListFalconVgaModes(this, 1);
590 if (Getcookie(C_BLOW, &cookie_blow) == C_FOUND) {
591 SDL_XBIOS_ListBlowupModes(this, 1, (blow_cookie_t *)cookie_blow);
596 SDL_XBIOS_ListMilanModes(this, 1);
600 XBIOS_screens[0]=NULL;
601 XBIOS_screens[1]=NULL;
602 XBIOS_shadowscreen=NULL;
604 /* Update hardware info */
605 this->info.hw_available = 1;
606 this->info.video_mem = (Uint32) Atari_SysMalloc(-1L, MX_STRAM);
608 /* Init chunky to planar routine */
609 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
612 SDL_AtariGL_InitPointers(this);
615 /* Disable screensavers */
616 if (SDL_XBIOS_TveillePresent(this)) {
617 SDL_XBIOS_TveilleDisable(this);
624 static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
626 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
629 static void XBIOS_FreeBuffers(_THIS)
634 if (XBIOS_screensmem[i]!=NULL) {
635 if ((XBIOS_cvdo>>16) == VDO_MILAN) {
637 VsetScreen(-1, -1, MI_MAGIC, CMD_FREEPAGE);
640 Mfree(XBIOS_screensmem[i]);
642 XBIOS_screensmem[i]=NULL;
646 if (XBIOS_shadowscreen!=NULL) {
647 Mfree(XBIOS_shadowscreen);
648 XBIOS_shadowscreen=NULL;
652 static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
653 int width, int height, int bpp, Uint32 flags)
657 xbiosmode_t *new_video_mode;
658 Uint32 new_screen_size;
661 /* Free current buffers */
662 XBIOS_FreeBuffers(this);
664 /* Try to set the requested linear video mode */
666 for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) {
667 if ( (SDL_modelist[bpp][mode]->w == width) &&
668 (SDL_modelist[bpp][mode]->h == height) ) {
672 if ( SDL_modelist[bpp][mode] == NULL ) {
673 SDL_SetError("Couldn't find requested mode in list");
676 new_video_mode = SDL_xbiosmode[bpp][mode];
678 modeflags = SDL_FULLSCREEN | SDL_PREALLOC;
680 /* Allocate needed buffers: simple/double buffer and shadow surface */
681 new_depth = new_video_mode->depth;
682 if (new_depth == 4) {
683 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert4;
685 modeflags |= SDL_SWSURFACE|SDL_HWPALETTE;
686 } else if (new_depth == 8) {
687 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
688 modeflags |= SDL_SWSURFACE|SDL_HWPALETTE;
690 modeflags |= SDL_HWSURFACE;
693 new_screen_size = width * height * ((new_depth)>>3);
694 new_screen_size += 256; /* To align on a 256 byte adress */
696 if (new_video_mode->flags & XBIOSMODE_C2P) {
697 XBIOS_shadowscreen = Atari_SysMalloc(new_screen_size, MX_PREFTTRAM);
699 if (XBIOS_shadowscreen == NULL) {
700 SDL_SetError("Can not allocate %d KB for shadow buffer", new_screen_size>>10);
703 SDL_memset(XBIOS_shadowscreen, 0, new_screen_size);
706 /* Output buffer needs to be twice in size for the software double-line mode */
707 if (new_video_mode->flags & XBIOSMODE_DOUBLELINE) {
708 new_screen_size <<= 1;
711 /* Double buffer ? */
715 if (flags & SDL_OPENGL) {
716 if (this->gl_config.double_buffer) {
717 flags |= SDL_DOUBLEBUF;
721 if ((flags & SDL_DOUBLEBUF) && ((XBIOS_cvdo>>16) != VDO_MILAN)) {
723 modeflags |= SDL_DOUBLEBUF;
726 /* Allocate buffers */
727 for (i=0; i<num_buffers; i++) {
728 if ((XBIOS_cvdo>>16) == VDO_MILAN) {
730 XBIOS_screensmem[i] = XBIOS_oldvbase;
732 VsetScreen(-1, &XBIOS_screensmem[i], MI_MAGIC, CMD_ALLOCPAGE);
735 XBIOS_screensmem[i] = Atari_SysMalloc(new_screen_size, MX_STRAM);
738 if (XBIOS_screensmem[i]==NULL) {
739 XBIOS_FreeBuffers(this);
740 SDL_SetError("Can not allocate %d KB for buffer %d", new_screen_size>>10, i);
743 SDL_memset(XBIOS_screensmem[i], 0, new_screen_size);
745 XBIOS_screens[i]=(void *) (( (long) XBIOS_screensmem[i]+256) & 0xFFFFFF00UL);
748 /* Allocate the new pixel format for the screen */
749 if ( ! SDL_ReallocFormat(current, new_depth, 0, 0, 0, 0) ) {
750 XBIOS_FreeBuffers(this);
751 SDL_SetError("Couldn't allocate new pixel format for requested mode");
755 XBIOS_current = new_video_mode;
758 current->pitch = (width * new_depth)>>3;
760 /* this is for C2P conversion */
761 XBIOS_pitch = (new_video_mode->width * new_video_mode->depth)>>3;
763 if (new_video_mode->flags & XBIOSMODE_C2P)
764 current->pixels = XBIOS_shadowscreen;
766 current->pixels = XBIOS_screens[0];
771 if (flags & SDL_OPENGL) {
772 if (!SDL_AtariGL_Init(this, current)) {
773 XBIOS_FreeBuffers(this);
774 SDL_SetError("Can not create OpenGL context");
778 modeflags |= SDL_OPENGL;
782 current->flags = modeflags;
784 #ifndef DEBUG_VIDEO_XBIOS
785 /* Now set the video mode */
786 if ((XBIOS_cvdo>>16) == VDO_MILAN) {
787 VsetScreen(-1, XBIOS_screens[0], MI_MAGIC, CMD_SETADR);
789 Setscreen(-1,XBIOS_screens[0],-1);
792 switch(XBIOS_cvdo >> 16) {
794 Setscreen(-1,-1,new_video_mode->number);
798 TT_palette[i]= ((i>>1)<<8) | (((i*8)/17)<<4) | (i>>1);
800 Setpalette(TT_palette);
803 Setscreen(-1,-1,new_video_mode->number);
810 c=((i&1)<<3)|((i>>1)&7);
811 TT_palette[i]=(c<<8)|(c<<4)|c;
813 Setpalette(TT_palette);
816 EsetShift(new_video_mode->number);
819 if (XBIOS_centscreen) {
820 SDL_XBIOS_CentscreenSetmode(this, width, height, new_depth);
822 VsetMode(new_video_mode->number);
825 /* Set hardware palette to black in True Colour */
827 SDL_memset(F30_palette, 0, sizeof(F30_palette));
828 VsetRGB(0,256,F30_palette);
832 VsetScreen(-1, new_video_mode->number, MI_MAGIC, CMD_SETMODE);
834 /* Set hardware palette to black in True Colour */
836 SDL_memset(F30_palette, 0, sizeof(F30_palette));
837 VsetRGB(0,256,F30_palette);
845 this->UpdateRects = XBIOS_UpdateRects;
850 /* We don't actually allow hardware surfaces other than the main one */
851 static int XBIOS_AllocHWSurface(_THIS, SDL_Surface *surface)
856 static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface)
861 static int XBIOS_LockHWSurface(_THIS, SDL_Surface *surface)
866 static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface)
871 static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
873 SDL_Surface *surface;
875 surface = this->screen;
877 if (XBIOS_current->flags & XBIOSMODE_C2P) {
879 int doubleline = (XBIOS_current->flags & XBIOSMODE_DOUBLELINE ? 1 : 0);
881 for (i=0;i<numrects;i++) {
882 void *source,*destination;
885 x1 = rects[i].x & ~15;
886 x2 = rects[i].x+rects[i].w;
891 source = surface->pixels;
892 source += surface->pitch * rects[i].y;
895 destination = XBIOS_screens[XBIOS_fbnum];
896 destination += XBIOS_pitch * rects[i].y;
899 /* Convert chunky to planar screen */
900 SDL_Atari_C2pConvert(
912 #ifndef DEBUG_VIDEO_XBIOS
913 if ((XBIOS_cvdo>>16) == VDO_MILAN) {
914 VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], MI_MAGIC, CMD_SETADR);
916 Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
922 if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
924 if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
925 surface->pixels=XBIOS_screens[XBIOS_fbnum];
930 static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface)
932 if (XBIOS_current->flags & XBIOSMODE_C2P) {
935 int doubleline = (XBIOS_current->flags & XBIOSMODE_DOUBLELINE ? 1 : 0);
937 /* Center on destination screen */
938 destscr = XBIOS_screens[XBIOS_fbnum];
939 destscr += XBIOS_pitch * ((XBIOS_current->height - surface->h) >> 1);
940 destx = (XBIOS_current->width - surface->w) >> 1;
944 /* Convert chunky to planar screen */
945 SDL_Atari_C2pConvert(
956 #ifndef DEBUG_VIDEO_XBIOS
957 if ((XBIOS_cvdo>>16) == VDO_MILAN) {
958 VsetScreen(-1, XBIOS_screens[XBIOS_fbnum], MI_MAGIC, CMD_SETADR);
960 Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
966 if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
968 if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
969 surface->pixels=XBIOS_screens[XBIOS_fbnum];
976 static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
978 #ifndef DEBUG_VIDEO_XBIOS
982 switch( XBIOS_cvdo >> 16) {
985 for (i=0;i<ncolors;i++)
991 TT_palette[firstcolor+i]=((r*30)+(v*59)+(b*11))/100;
993 SDL_Atari_C2pConvert4_pal(TT_palette); /* convert the lighting */
996 for(i = 0; i < ncolors; i++)
1002 TT_palette[i]=((r>>4)<<8)|((v>>4)<<4)|(b>>4);
1004 EsetPalette(firstcolor,ncolors,TT_palette);
1008 for(i = 0; i < ncolors; i++)
1014 F30_palette[i]=(r<<16)|(v<<8)|b;
1016 VsetRGB(firstcolor,ncolors,F30_palette);
1024 /* Note: If we are terminated, this could be called in the middle of
1025 another SDL video routine -- notably UpdateRects.
1027 static void XBIOS_VideoQuit(_THIS)
1031 Atari_ShutdownEvents();
1033 /* Restore video mode and palette */
1034 #ifndef DEBUG_VIDEO_XBIOS
1035 switch(XBIOS_cvdo >> 16) {
1038 Setscreen(-1,XBIOS_oldvbase,XBIOS_oldvmode);
1039 if (XBIOS_oldnumcol) {
1040 Setpalette(XBIOS_oldpalette);
1044 Setscreen(-1,XBIOS_oldvbase,-1);
1045 EsetShift(XBIOS_oldvmode);
1046 if (XBIOS_oldnumcol) {
1047 EsetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette);
1051 Setscreen(-1, XBIOS_oldvbase, -1);
1052 if (XBIOS_centscreen) {
1053 SDL_XBIOS_CentscreenRestore(this, XBIOS_oldvmode);
1055 VsetMode(XBIOS_oldvmode);
1057 if (XBIOS_oldnumcol) {
1058 VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
1062 VsetScreen(-1, &XBIOS_oldvbase, MI_MAGIC, CMD_SETADR);
1063 VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_SETMODE);
1064 if (XBIOS_oldnumcol) {
1065 VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
1072 #if SDL_VIDEO_OPENGL
1074 SDL_AtariGL_Quit(this, SDL_TRUE);
1078 if (XBIOS_oldpalette) {
1079 SDL_free(XBIOS_oldpalette);
1080 XBIOS_oldpalette=NULL;
1082 XBIOS_FreeBuffers(this);
1084 /* Free mode list */
1085 for ( i=0; i<NUM_MODELISTS; ++i ) {
1086 if ( SDL_modelist[i] != NULL ) {
1087 for ( j=0; SDL_modelist[i][j]; ++j )
1088 SDL_free(SDL_modelist[i][j]);
1089 SDL_free(SDL_modelist[i]);
1090 SDL_modelist[i] = NULL;
1092 if ( SDL_xbiosmode[i] != NULL ) {
1093 for ( j=0; SDL_xbiosmode[i][j]; ++j )
1094 SDL_free(SDL_xbiosmode[i][j]);
1095 SDL_free(SDL_xbiosmode[i]);
1096 SDL_xbiosmode[i] = NULL;
1100 this->screen->pixels = NULL;
1102 /* Restore screensavers */
1103 if (SDL_XBIOS_TveillePresent(this)) {
1104 SDL_XBIOS_TveilleRestore(this);
1108 #if SDL_VIDEO_OPENGL
1110 static void XBIOS_GL_SwapBuffers(_THIS)
1112 SDL_AtariGL_SwapBuffers(this);
1113 XBIOS_FlipHWSurface(this, this->screen);
1114 SDL_AtariGL_MakeCurrent(this);