2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2004 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * Xbios SDL video driver
41 #include <mint/cookie.h>
42 #include <mint/osbind.h>
43 #include <mint/falcon.h>
46 #include "SDL_error.h"
47 #include "SDL_video.h"
48 #include "SDL_mouse.h"
49 #include "SDL_sysvideo.h"
50 #include "SDL_pixels_c.h"
51 #include "SDL_events_c.h"
53 #include "SDL_ataric2p_s.h"
54 #include "SDL_atarievents_c.h"
55 #include "SDL_atarimxalloc_c.h"
56 #include "SDL_atarigl_c.h"
57 #include "SDL_xbios.h"
58 #include "SDL_xbios_blowup.h"
59 #include "SDL_xbios_centscreen.h"
60 #include "SDL_xbios_sb3.h"
62 #define XBIOS_VID_DRIVER_NAME "xbios"
64 /* Debug print info */
66 #define DEBUG_PRINT(what) \
70 #define DEBUG_VIDEO_XBIOS 1
72 #define DEBUG_PRINT(what)
73 #undef DEBUG_VIDEO_XBIOS
76 /* Initialization/Query functions */
77 static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat);
78 static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
79 static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
80 static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
81 static void XBIOS_VideoQuit(_THIS);
83 /* Hardware surface functions */
84 static int XBIOS_AllocHWSurface(_THIS, SDL_Surface *surface);
85 static int XBIOS_LockHWSurface(_THIS, SDL_Surface *surface);
86 static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface);
87 static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface);
88 static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface);
89 static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
92 /* OpenGL functions */
93 static void XBIOS_GL_SwapBuffers(_THIS);
96 /* To setup palette */
98 static unsigned short TT_palette[256];
99 static unsigned long F30_palette[256];
101 /* Xbios driver bootstrap functions */
103 static int XBIOS_Available(void)
105 unsigned long cookie_vdo, cookie_mil, cookie_hade, cookie_scpn;
107 /* Milan/Hades Atari clones do not have an Atari video chip */
108 if ( (Getcookie(C__MIL, &cookie_mil) == C_FOUND) ||
109 (Getcookie(C_hade, &cookie_hade) == C_FOUND) ) {
113 /* Cookie _VDO present ? if not, assume ST machine */
114 if (Getcookie(C__VDO, &cookie_vdo) != C_FOUND) {
115 cookie_vdo = VDO_ST << 16;
118 /* Test if we have a monochrome monitor plugged in */
119 switch( cookie_vdo >>16) {
122 if ( Getrez() == (ST_HIGH>>8) )
126 if ( (EgetShift() & ES_MODE) == TT_HIGH)
130 if ( Montype() == MONITOR_MONO)
132 if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) {
133 if (!SDL_XBIOS_SB3Usable((scpn_cookie_t *)cookie_scpn)) {
145 static void XBIOS_DeleteDevice(SDL_VideoDevice *device)
147 free(device->hidden);
151 static SDL_VideoDevice *XBIOS_CreateDevice(int devindex)
153 SDL_VideoDevice *device;
155 /* Initialize all variables that we clean on shutdown */
156 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
158 memset(device, 0, (sizeof *device));
159 device->hidden = (struct SDL_PrivateVideoData *)
160 malloc((sizeof *device->hidden));
161 device->gl_data = (struct SDL_PrivateGLData *)
162 malloc((sizeof *device->gl_data));
164 if ( (device == NULL) || (device->hidden == NULL) ) {
171 memset(device->hidden, 0, (sizeof *device->hidden));
172 memset(device->gl_data, 0, sizeof(*device->gl_data));
174 /* Video functions */
175 device->VideoInit = XBIOS_VideoInit;
176 device->ListModes = XBIOS_ListModes;
177 device->SetVideoMode = XBIOS_SetVideoMode;
178 device->SetColors = XBIOS_SetColors;
179 device->UpdateRects = NULL;
180 device->VideoQuit = XBIOS_VideoQuit;
181 device->AllocHWSurface = XBIOS_AllocHWSurface;
182 device->LockHWSurface = XBIOS_LockHWSurface;
183 device->UnlockHWSurface = XBIOS_UnlockHWSurface;
184 device->FlipHWSurface = XBIOS_FlipHWSurface;
185 device->FreeHWSurface = XBIOS_FreeHWSurface;
188 /* OpenGL functions */
189 device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary;
190 device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress;
191 device->GL_GetAttribute = SDL_AtariGL_GetAttribute;
192 device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent;
193 device->GL_SwapBuffers = XBIOS_GL_SwapBuffers;
197 device->InitOSKeymap = Atari_InitOSKeymap;
198 device->PumpEvents = Atari_PumpEvents;
200 device->free = XBIOS_DeleteDevice;
205 VideoBootStrap XBIOS_bootstrap = {
206 XBIOS_VID_DRIVER_NAME, "Atari Xbios driver",
207 XBIOS_Available, XBIOS_CreateDevice
210 void SDL_XBIOS_AddMode(_THIS, Uint16 modecode, Uint16 width, Uint16 height,
211 Uint16 depth, SDL_bool flags)
214 xbiosmode_t *current_mode;
216 /* Check if mode already exists */
217 if (XBIOS_modelist) {
218 current_mode = XBIOS_modelist;
219 for (i=0;i<XBIOS_nummodes; i++, current_mode++) {
220 if (current_mode->width != width)
222 if (current_mode->height != height)
224 if (current_mode->depth != depth)
231 XBIOS_modelist = (xbiosmode_t *) realloc(XBIOS_modelist, XBIOS_nummodes * sizeof(xbiosmode_t));
233 /* Keep the list sorted: bpp, width, height */
236 for(i=0; i<XBIOS_nummodes-1; i++) {
237 if (XBIOS_modelist[i].depth <= depth) {
238 if (XBIOS_modelist[i].width < width) {
240 } else if (XBIOS_modelist[i].width == width) {
241 if (XBIOS_modelist[i].height <= height) {
249 /* Push remaining modes further */
250 for(i=XBIOS_nummodes-1; i>curpos; i--) {
251 memcpy(&XBIOS_modelist[i], &XBIOS_modelist[i-1], sizeof(xbiosmode_t));
254 XBIOS_modelist[curpos].number = modecode;
255 XBIOS_modelist[curpos].width = width;
256 XBIOS_modelist[curpos].height = height;
257 XBIOS_modelist[curpos].depth = depth;
258 XBIOS_modelist[curpos].doubleline = flags;
261 static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
264 xbiosmode_t *current_mode;
265 unsigned long cookie_blow, cookie_scpn, cookie_cnts;
267 /* Initialize all variables that we clean on shutdown */
268 memset (SDL_modelist, 0, sizeof(SDL_modelist));
270 /* Cookie _VDO present ? if not, assume ST machine */
271 if (Getcookie(C__VDO, &XBIOS_cvdo) != C_FOUND) {
272 XBIOS_cvdo = VDO_ST << 16;
275 /* Allocate memory for old palette */
276 XBIOS_oldpalette = (void *)malloc(256*sizeof(long));
277 if ( !XBIOS_oldpalette ) {
278 SDL_SetError("Unable to allocate memory for old palette\n");
282 /* Initialize video mode list */
283 /* and save current screen status (palette, screen address, video mode) */
285 XBIOS_modelist = NULL;
286 XBIOS_centscreen = SDL_FALSE;
288 switch (XBIOS_cvdo >>16) {
294 SDL_XBIOS_AddMode(this, ST_LOW>>8,320,200,4,SDL_FALSE);
296 XBIOS_oldvbase=Physbase();
297 XBIOS_oldvmode=Getrez();
298 switch(XBIOS_oldvmode << 8) {
313 oldpalette= (short *) XBIOS_oldpalette;
314 for (i=0;i<XBIOS_oldnumcol;i++) {
315 *oldpalette++=Setcolor(i,-1);
318 vformat->BitsPerPixel = 8;
323 SDL_XBIOS_AddMode(this, TT_LOW,320,480,8,SDL_FALSE);
324 /* Software double-lined mode */
325 SDL_XBIOS_AddMode(this, TT_LOW,320,240,8,SDL_TRUE);
327 XBIOS_oldvbase=Logbase();
328 XBIOS_oldvmode=EgetShift();
330 switch(XBIOS_oldvmode & ES_MODE) {
349 if (XBIOS_oldnumcol) {
350 EgetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette);
353 vformat->BitsPerPixel = 8;
363 SDL_XBIOS_AddMode(this, BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,SDL_FALSE);
364 SDL_XBIOS_AddMode(this, BPS16|COL80|OVERSCAN,768,240,16,SDL_FALSE);
365 SDL_XBIOS_AddMode(this, BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE);
366 SDL_XBIOS_AddMode(this, BPS16|COL80,640,200,16,SDL_FALSE);
367 SDL_XBIOS_AddMode(this, BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE);
368 SDL_XBIOS_AddMode(this, BPS16|OVERSCAN,384,240,16,SDL_FALSE);
369 SDL_XBIOS_AddMode(this, BPS16|VERTFLAG,320,400,16,SDL_FALSE);
370 SDL_XBIOS_AddMode(this, BPS16,320,200,16,SDL_FALSE);
371 SDL_XBIOS_AddMode(this, BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,SDL_FALSE);
372 SDL_XBIOS_AddMode(this, BPS8|COL80|OVERSCAN,768,240,8,SDL_FALSE);
373 SDL_XBIOS_AddMode(this, BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE);
374 SDL_XBIOS_AddMode(this, BPS8|COL80,640,200,8,SDL_FALSE);
375 SDL_XBIOS_AddMode(this, BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE);
376 SDL_XBIOS_AddMode(this, BPS8|OVERSCAN,384,240,8,SDL_FALSE);
377 SDL_XBIOS_AddMode(this, BPS8|VERTFLAG,320,400,8,SDL_FALSE);
378 SDL_XBIOS_AddMode(this, BPS8,320,200,8,SDL_FALSE);
381 SDL_XBIOS_AddMode(this, BPS16,320,480,16,SDL_FALSE);
382 SDL_XBIOS_AddMode(this, BPS16|VERTFLAG,320,240,16,SDL_FALSE);
383 SDL_XBIOS_AddMode(this, BPS8|COL80,640,480,8,SDL_FALSE);
384 SDL_XBIOS_AddMode(this, BPS8|COL80|VERTFLAG,640,240,8,SDL_FALSE);
385 SDL_XBIOS_AddMode(this, BPS8,320,480,8,SDL_FALSE);
386 SDL_XBIOS_AddMode(this, BPS8|VERTFLAG,320,240,8,SDL_FALSE);
389 XBIOS_oldvbase=Logbase();
390 XBIOS_oldvmode=Vsetmode(-1);
392 XBIOS_oldnumcol= 1<< (1 << (XBIOS_oldvmode & NUMCOLS));
393 if (XBIOS_oldnumcol > 256) {
396 if (XBIOS_oldnumcol) {
397 VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
400 vformat->BitsPerPixel = 16;
402 /* Keep vga/rvb, and pal/ntsc bits */
403 current_mode = XBIOS_modelist;
404 for (i=0;i<XBIOS_nummodes;i++) {
407 newvmode = current_mode->number;
408 newvmode &= ~(VGA|PAL);
409 newvmode |= XBIOS_oldvmode & (VGA|PAL);
410 current_mode->number = newvmode;
415 /* Initialize BlowUp/SB3/Centscreen stuff if present */
416 if (Getcookie(C_BLOW, &cookie_blow) == C_FOUND) {
417 SDL_XBIOS_BlowupInit(this, (blow_cookie_t *)cookie_blow);
418 } else if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) {
419 SDL_XBIOS_SB3Init(this, (scpn_cookie_t *)cookie_scpn);
420 } else if (Getcookie(C_CNTS, &cookie_cnts) == C_FOUND) {
421 XBIOS_oldvmode = SDL_XBIOS_CentscreenInit(this);
422 XBIOS_centscreen = SDL_TRUE;
428 current_mode = XBIOS_modelist;
430 for (i=0; i<XBIOS_nummodes; i++, current_mode++) {
431 switch (current_mode->depth) {
434 SDL_modelist[0][j8] = malloc(sizeof(SDL_Rect));
435 SDL_modelist[0][j8]->x = SDL_modelist[0][j8]->y = 0;
436 SDL_modelist[0][j8]->w = current_mode->width;
437 SDL_modelist[0][j8]->h = current_mode->height;
438 XBIOS_videomodes[0][j8]=current_mode;
442 SDL_modelist[1][j16] = malloc(sizeof(SDL_Rect));
443 SDL_modelist[1][j16]->x = SDL_modelist[1][j16]->y = 0;
444 SDL_modelist[1][j16]->w = current_mode->width;
445 SDL_modelist[1][j16]->h = current_mode->height;
446 XBIOS_videomodes[1][j16]=current_mode;
451 SDL_modelist[0][j8] = NULL;
452 SDL_modelist[1][j16] = NULL;
454 XBIOS_screens[0]=NULL;
455 XBIOS_screens[1]=NULL;
456 XBIOS_shadowscreen=NULL;
458 /* Update hardware info */
459 this->info.hw_available = 1;
460 this->info.video_mem = (Uint32) Atari_SysMalloc(-1L, MX_STRAM);
462 /* Init chunky to planar routine */
463 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
466 SDL_AtariGL_InitPointers(this);
473 static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
475 /* 8 bits -> list 0 */
476 /* 16 bits -> list 1 */
477 if ((format->BitsPerPixel != 8) && (format->BitsPerPixel !=16)) {
481 return(SDL_modelist[(format->BitsPerPixel)>>4]);
484 static void XBIOS_FreeBuffers(_THIS)
489 if (XBIOS_screensmem[i]!=NULL) {
490 Mfree(XBIOS_screensmem[i]);
491 XBIOS_screensmem[i]=NULL;
495 if (XBIOS_shadowscreen!=NULL) {
496 Mfree(XBIOS_shadowscreen);
497 XBIOS_shadowscreen=NULL;
501 static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
502 int width, int height, int bpp, Uint32 flags)
506 xbiosmode_t *new_video_mode;
507 Uint32 new_screen_size;
510 /* Free current buffers */
511 XBIOS_FreeBuffers(this);
519 /* Search if the mode exists (width, height, bpp) */
520 for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) {
521 if ( (SDL_modelist[bpp][mode]->w == width) &&
522 (SDL_modelist[bpp][mode]->h == height) ) {
527 if ( SDL_modelist[bpp][mode] == NULL ) {
528 SDL_SetError("Couldn't find requested mode in list");
532 modeflags = SDL_FULLSCREEN | SDL_PREALLOC;
534 /* Allocate needed buffers: simple/double buffer and shadow surface */
535 new_video_mode = XBIOS_videomodes[bpp][mode];
536 new_depth = new_video_mode->depth;
537 if (new_depth == 4) {
538 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert4;
540 modeflags |= SDL_SWSURFACE|SDL_HWPALETTE;
541 } else if (new_depth == 8) {
542 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
543 modeflags |= SDL_SWSURFACE|SDL_HWPALETTE;
545 modeflags |= SDL_HWSURFACE;
548 new_screen_size = width * height * ((new_depth)>>3);
549 new_screen_size += 256; /* To align on a 256 byte adress */
551 if (new_depth == 8) {
552 XBIOS_shadowscreen = Atari_SysMalloc(new_screen_size, MX_PREFTTRAM);
554 if (XBIOS_shadowscreen == NULL) {
555 SDL_SetError("Can not allocate %d KB for shadow buffer", new_screen_size>>10);
558 memset(XBIOS_shadowscreen, 0, new_screen_size);
561 /* Output buffer needs to be twice in size for the software double-line mode */
562 XBIOS_doubleline = SDL_FALSE;
563 if (new_video_mode->doubleline) {
564 new_screen_size <<= 1;
565 XBIOS_doubleline = SDL_TRUE;
568 XBIOS_screensmem[0] = Atari_SysMalloc(new_screen_size, MX_STRAM);
570 if (XBIOS_screensmem[0]==NULL) {
571 XBIOS_FreeBuffers(this);
572 SDL_SetError("Can not allocate %d KB for frame buffer", new_screen_size>>10);
575 memset(XBIOS_screensmem[0], 0, new_screen_size);
577 XBIOS_screens[0]=(void *) (( (long) XBIOS_screensmem[0]+256) & 0xFFFFFF00UL);
580 if (flags & SDL_OPENGL) {
581 if (this->gl_config.double_buffer) {
582 flags |= SDL_DOUBLEBUF;
587 /* Double buffer ? */
588 if (flags & SDL_DOUBLEBUF) {
589 XBIOS_screensmem[1] = Atari_SysMalloc(new_screen_size, MX_STRAM);
591 if (XBIOS_screensmem[1]==NULL) {
592 XBIOS_FreeBuffers(this);
593 SDL_SetError("Can not allocate %d KB for double buffer", new_screen_size>>10);
596 memset(XBIOS_screensmem[1], 0, new_screen_size);
598 XBIOS_screens[1]=(void *) (( (long) XBIOS_screensmem[1]+256) & 0xFFFFFF00UL);
599 modeflags |= SDL_DOUBLEBUF;
602 /* Allocate the new pixel format for the screen */
603 if ( ! SDL_ReallocFormat(current, new_depth, 0, 0, 0, 0) ) {
604 XBIOS_FreeBuffers(this);
605 SDL_SetError("Couldn't allocate new pixel format for requested mode");
609 current->w = XBIOS_width = width;
610 current->h = XBIOS_height = height;
611 current->pitch = (width * new_depth)>>3;
613 /* this is for C2P conversion */
614 XBIOS_pitch = (new_video_mode->width * new_video_mode->depth)>>3;
617 current->pixels = XBIOS_shadowscreen;
619 current->pixels = XBIOS_screens[0];
624 if (flags & SDL_OPENGL) {
625 if (!SDL_AtariGL_Init(this, current)) {
626 XBIOS_FreeBuffers(this);
627 SDL_SetError("Can not create OpenGL context");
631 modeflags |= SDL_OPENGL;
635 current->flags = modeflags;
637 /* Now set the video mode */
638 #ifndef DEBUG_VIDEO_XBIOS
639 Setscreen(-1,XBIOS_screens[0],-1);
642 switch(XBIOS_cvdo >> 16) {
644 #ifndef DEBUG_VIDEO_XBIOS
645 Setscreen(-1,-1,new_video_mode->number);
649 TT_palette[i]= ((i>>1)<<8) | (((i*8)/17)<<4) | (i>>1);
651 #ifndef DEBUG_VIDEO_XBIOS
652 Setpalette(TT_palette);
656 #ifndef DEBUG_VIDEO_XBIOS
657 Setscreen(-1,-1,new_video_mode->number);
664 c=((i&1)<<3)|((i>>1)&7);
665 TT_palette[i]=(c<<8)|(c<<4)|c;
667 #ifndef DEBUG_VIDEO_XBIOS
668 Setpalette(TT_palette);
672 #ifndef DEBUG_VIDEO_XBIOS
673 EsetShift(new_video_mode->number);
677 #ifndef DEBUG_VIDEO_XBIOS
678 if (XBIOS_centscreen) {
679 SDL_XBIOS_CentscreenSetmode(this, width, height, new_depth);
681 Vsetmode(new_video_mode->number);
684 /* Set hardware palette to black in True Colour */
685 if (new_depth == 16) {
686 memset(F30_palette, 0, sizeof(F30_palette));
687 VsetRGB(0,256,F30_palette);
694 this->UpdateRects = XBIOS_UpdateRects;
699 /* We don't actually allow hardware surfaces other than the main one */
700 static int XBIOS_AllocHWSurface(_THIS, SDL_Surface *surface)
705 static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface)
710 static int XBIOS_LockHWSurface(_THIS, SDL_Surface *surface)
715 static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface)
720 static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
722 SDL_Surface *surface;
724 surface = this->screen;
726 if ((surface->format->BitsPerPixel) == 8) {
731 /* Center on destination screen */
732 destscr = XBIOS_screens[XBIOS_fbnum];
733 destscr += XBIOS_pitch * ((XBIOS_height - surface->h) >> 1);
734 destx = (XBIOS_width - surface->w) >> 1;
738 for (i=0;i<numrects;i++) {
739 void *source,*destination;
742 x1 = rects[i].x & ~15;
743 x2 = rects[i].x+rects[i].w;
748 source = surface->pixels;
749 source += surface->pitch * rects[i].y;
752 destination = destscr;
753 destination += XBIOS_pitch * rects[i].y;
756 /* Convert chunky to planar screen */
757 SDL_Atari_C2pConvert(
769 #ifndef DEBUG_VIDEO_XBIOS
770 Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
774 if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
776 if ((surface->format->BitsPerPixel) > 8) {
777 surface->pixels=XBIOS_screens[XBIOS_fbnum];
782 static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface)
784 if ((surface->format->BitsPerPixel) == 8) {
788 /* Center on destination screen */
789 destscr = XBIOS_screens[XBIOS_fbnum];
790 destscr += XBIOS_pitch * ((XBIOS_height - surface->h) >> 1);
791 destx = (XBIOS_width - surface->w) >> 1;
795 /* Convert chunky to planar screen */
796 SDL_Atari_C2pConvert(
807 #ifndef DEBUG_VIDEO_XBIOS
808 Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
812 if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
814 if ((surface->format->BitsPerPixel) > 8) {
815 surface->pixels=XBIOS_screens[XBIOS_fbnum];
822 static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
827 switch( XBIOS_cvdo >> 16) {
830 for (i=0;i<ncolors;i++)
836 TT_palette[firstcolor+i]=((r*30)+(v*59)+(b*11))/100;
838 SDL_Atari_C2pConvert4_pal(TT_palette); /* convert the lighting */
841 for(i = 0; i < ncolors; i++)
847 TT_palette[i]=((r>>4)<<8)|((v>>4)<<4)|(b>>4);
849 #ifndef DEBUG_VIDEO_XBIOS
850 EsetPalette(firstcolor,ncolors,TT_palette);
854 for(i = 0; i < ncolors; i++)
860 F30_palette[i]=(r<<16)|(v<<8)|b;
862 #ifndef DEBUG_VIDEO_XBIOS
863 VsetRGB(firstcolor,ncolors,F30_palette);
871 /* Note: If we are terminated, this could be called in the middle of
872 another SDL video routine -- notably UpdateRects.
874 static void XBIOS_VideoQuit(_THIS)
878 Atari_ShutdownEvents();
880 /* Restore video mode and palette */
881 #ifndef DEBUG_VIDEO_XBIOS
882 switch(XBIOS_cvdo >> 16) {
885 Setscreen(-1,XBIOS_oldvbase,XBIOS_oldvmode);
886 if (XBIOS_oldnumcol) {
887 Setpalette(XBIOS_oldpalette);
891 Setscreen(-1,XBIOS_oldvbase,-1);
892 EsetShift(XBIOS_oldvmode);
893 if (XBIOS_oldnumcol) {
894 EsetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette);
898 Setscreen(-1, XBIOS_oldvbase, -1);
899 if (XBIOS_centscreen) {
900 SDL_XBIOS_CentscreenRestore(this, XBIOS_oldvmode);
902 Vsetmode(XBIOS_oldvmode);
904 if (XBIOS_oldnumcol) {
905 VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
915 SDL_AtariGL_Quit(this, SDL_TRUE);
919 if (XBIOS_oldpalette) {
920 free(XBIOS_oldpalette);
921 XBIOS_oldpalette=NULL;
923 XBIOS_FreeBuffers(this);
926 for (j=0;j<NUM_MODELISTS;j++) {
927 for (i=0;i<SDL_NUMMODES;i++) {
928 if (SDL_modelist[j][i]!=NULL) {
929 free(SDL_modelist[j][i]);
930 SDL_modelist[j][i]=NULL;
935 if (XBIOS_modelist) {
936 free(XBIOS_modelist);
941 this->screen->pixels = NULL;
946 static void XBIOS_GL_SwapBuffers(_THIS)
948 SDL_AtariGL_SwapBuffers(this);
949 XBIOS_FlipHWSurface(this, this->screen);
950 SDL_AtariGL_MakeCurrent(this);