2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 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"
29 Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
35 #include <mint/osbind.h>
36 #include <mint/cookie.h>
38 #include "SDL_endian.h"
39 #include "SDL_video.h"
40 #include "SDL_mouse.h"
41 #include "../SDL_sysvideo.h"
42 #include "../SDL_pixels_c.h"
43 #include "../../events/SDL_events_c.h"
44 #include "../SDL_cursor_c.h"
46 #include "../ataricommon/SDL_ataric2p_s.h"
47 #include "../ataricommon/SDL_atarieddi_s.h"
48 #include "../ataricommon/SDL_atarimxalloc_c.h"
49 #include "../ataricommon/SDL_atarigl_c.h"
51 #include "SDL_gemvideo.h"
52 #include "SDL_gemevents_c.h"
53 #include "SDL_gemmouse_c.h"
54 #include "SDL_gemwm_c.h"
55 #include "../ataricommon/SDL_xbiosevents_c.h"
56 #include "../ataricommon/SDL_ataridevmouse_c.h"
60 /*#define DEBUG_VIDEO_GEM 1*/
62 #define GEM_VID_DRIVER_NAME "gem"
65 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
67 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
71 static unsigned char vdi_index[256] = {
72 0, 2, 3, 6, 4, 7, 5, 8,
73 9, 10, 11, 14, 12, 15, 13, 255
76 static const char empty_name[]="";
78 /* Initialization/Query functions */
79 static int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat);
80 static SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
81 static SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
82 static int GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
83 static void GEM_VideoQuit(_THIS);
85 /* Hardware surface functions */
86 static int GEM_AllocHWSurface(_THIS, SDL_Surface *surface);
87 static int GEM_LockHWSurface(_THIS, SDL_Surface *surface);
88 static int GEM_FlipHWSurface(_THIS, SDL_Surface *surface);
89 static void GEM_UnlockHWSurface(_THIS, SDL_Surface *surface);
90 static void GEM_FreeHWSurface(_THIS, SDL_Surface *surface);
91 static void GEM_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
93 static int GEM_ToggleFullScreen(_THIS, int on);
96 /* Internal functions */
97 static void GEM_FreeBuffers(_THIS);
98 static void GEM_ClearScreen(_THIS);
99 static void GEM_ClearRect(_THIS, short *rect);
100 static void GEM_SetNewPalette(_THIS, Uint16 newpal[256][3]);
101 static void GEM_LockScreen(_THIS);
102 static void GEM_UnlockScreen(_THIS);
103 static void refresh_window(_THIS, int winhandle, short *rect);
106 /* OpenGL functions */
107 static void GEM_GL_SwapBuffers(_THIS);
110 /* GEM driver bootstrap functions */
112 static int GEM_Available(void)
114 /* Test if AES available */
115 if (appl_init() == -1)
122 static void GEM_DeleteDevice(SDL_VideoDevice *device)
124 SDL_free(device->hidden);
128 static SDL_VideoDevice *GEM_CreateDevice(int devindex)
130 SDL_VideoDevice *device;
132 /* unsigned long dummy;*/
134 /* Initialize all variables that we clean on shutdown */
135 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
137 SDL_memset(device, 0, (sizeof *device));
138 device->hidden = (struct SDL_PrivateVideoData *)
139 SDL_malloc((sizeof *device->hidden));
140 device->gl_data = (struct SDL_PrivateGLData *)
141 SDL_malloc((sizeof *device->gl_data));
143 if ( (device == NULL) || (device->hidden == NULL) ) {
150 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
151 SDL_memset(device->gl_data, 0, sizeof(*device->gl_data));
153 /* Set the function pointers */
154 device->VideoInit = GEM_VideoInit;
155 device->ListModes = GEM_ListModes;
156 device->SetVideoMode = GEM_SetVideoMode;
157 device->SetColors = GEM_SetColors;
158 device->UpdateRects = NULL /*GEM_UpdateRects*/;
159 device->VideoQuit = GEM_VideoQuit;
160 device->AllocHWSurface = GEM_AllocHWSurface;
161 device->LockHWSurface = GEM_LockHWSurface;
162 device->UnlockHWSurface = GEM_UnlockHWSurface;
163 device->FlipHWSurface = GEM_FlipHWSurface;
164 device->FreeHWSurface = GEM_FreeHWSurface;
165 device->ToggleFullScreen = NULL /*GEM_ToggleFullScreen*/;
168 device->SetCaption = GEM_SetCaption;
169 device->SetIcon = GEM_SetIcon;
170 device->IconifyWindow = GEM_IconifyWindow;
171 device->GrabInput = GEM_GrabInput;
174 device->InitOSKeymap = GEM_InitOSKeymap;
175 device->PumpEvents = GEM_PumpEvents;
178 device->FreeWMCursor = GEM_FreeWMCursor;
179 device->CreateWMCursor = GEM_CreateWMCursor;
180 device->ShowWMCursor = GEM_ShowWMCursor;
181 device->WarpWMCursor = NULL /*GEM_WarpWMCursor*/;
182 device->CheckMouseMode = GEM_CheckMouseMode;
185 /* OpenGL functions */
186 device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary;
187 device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress;
188 device->GL_GetAttribute = SDL_AtariGL_GetAttribute;
189 device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent;
190 device->GL_SwapBuffers = GEM_GL_SwapBuffers;
193 device->hidden->use_dev_mouse =
194 (SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE;
196 vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS; /* XBIOS joystick events */
197 if (!(device->hidden->use_dev_mouse)) {
198 vectors_mask |= ATARI_XBIOS_MOUSEEVENTS; /* XBIOS mouse events */
200 /* if (Getcookie(C_MiNT, &dummy)==C_FOUND) {
204 SDL_AtariXbios_InstallVectors(vectors_mask);
206 device->free = GEM_DeleteDevice;
211 VideoBootStrap GEM_bootstrap = {
212 GEM_VID_DRIVER_NAME, "Atari GEM video driver",
213 GEM_Available, GEM_CreateDevice
216 static void VDI_ReadExtInfo(_THIS, short *work_out)
218 unsigned long EdDI_version;
222 /* Read EdDI informations */
223 if (Getcookie(C_EdDI, &cookie_EdDI) == C_NOTFOUND) {
227 EdDI_version = Atari_get_EdDI_version( (void *)cookie_EdDI);
229 vq_scrninfo(VDI_handle, work_out);
231 VDI_format = work_out[0];
232 clut_type = work_out[1];
234 /* With EdDI>=1.1, we can have screen pitch, address and format
235 * so we can directly write to screen without using vro_cpyfm
237 if (EdDI_version >= EDDI_11) {
238 VDI_pitch = work_out[5];
239 VDI_screen = (void *) *((unsigned long *) &work_out[6]);
243 case VDI_CLUT_HARDWARE:
248 tmp_p = (Uint16 *)&work_out[16];
250 for (i=0;i<256;i++) {
251 vdi_index[*tmp_p++] = i;
255 case VDI_CLUT_SOFTWARE:
257 int component; /* red, green, blue, alpha, overlay */
259 unsigned short *tmp_p;
261 /* We can build masks with info here */
262 tmp_p = (unsigned short *) &work_out[16];
263 for (component=0;component<5;component++) {
264 for (num_bit=0;num_bit<16;num_bit++) {
265 unsigned short valeur;
269 if (valeur == 0xffff) {
275 VDI_redmask |= 1<< valeur;
278 VDI_greenmask |= 1<< valeur;
281 VDI_bluemask |= 1<< valeur;
284 VDI_alphamask |= 1<< valeur;
291 /* Remove lower green bits for Intel endian screen */
292 if ((VDI_greenmask == ((7<<13)|3)) || (VDI_greenmask == ((7<<13)|7))) {
293 VDI_greenmask &= ~(7<<13);
301 int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat)
304 short work_in[12], work_out[272], dummy;
306 /* Open AES (Application Environment Services) */
307 if (appl_init() == -1) {
308 fprintf(stderr,"Can not open AES\n");
312 /* Read version and features */
313 GEM_version = aes_global[0];
314 if (GEM_version >= 0x0410) {
315 short ap_gout[4], errorcode;
318 errorcode=appl_getinfo(AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2], &ap_gout[3]);
321 GEM_wfeatures=ap_gout[0];
325 /* Ask VDI physical workstation handle opened by AES */
326 VDI_handle = graf_handle(&dummy, &dummy, &dummy, &dummy);
328 fprintf(stderr,"Wrong VDI handle %d returned by AES\n",VDI_handle);
332 /* Open virtual VDI workstation */
333 work_in[0]=Getrez()+2;
334 for(i = 1; i < 10; i++)
338 v_opnvwk(work_in, &VDI_handle, work_out);
339 if (VDI_handle == 0) {
340 fprintf(stderr,"Can not open VDI virtual workstation\n");
344 /* Read fullscreen size */
345 VDI_w = work_out[0] + 1;
346 VDI_h = work_out[1] + 1;
348 /* Read desktop size and position */
349 if (!wind_get(DESKTOP_HANDLE, WF_WORKXYWH, &GEM_desk_x, &GEM_desk_y, &GEM_desk_w, &GEM_desk_h)) {
350 fprintf(stderr,"Can not read desktop properties\n");
355 vq_extnd(VDI_handle, 1, work_out);
356 VDI_bpp = work_out[4];
374 fprintf(stderr,"%d bits colour depth not supported\n",VDI_bpp);
378 /* Setup hardware -> VDI palette mapping */
379 for(i = 16; i < 255; i++) {
384 /* Save current palette */
386 VDI_oldnumcolors=1<<8;
388 VDI_oldnumcolors=1<<VDI_bpp;
391 for(i = 0; i < VDI_oldnumcolors; i++) {
394 vq_color(VDI_handle, i, 0, rgb);
396 VDI_oldpalette[i][0] = rgb[0];
397 VDI_oldpalette[i][1] = rgb[1];
398 VDI_oldpalette[i][2] = rgb[2];
400 VDI_setpalette = GEM_SetNewPalette;
401 SDL_memcpy(VDI_curpalette,VDI_oldpalette,sizeof(VDI_curpalette));
403 /* Setup screen info */
404 GEM_title_name = empty_name;
405 GEM_icon_name = empty_name;
408 GEM_locked = SDL_FALSE;
409 GEM_win_fulled = SDL_FALSE;
410 GEM_fullscreen = SDL_FALSE;
411 GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers are setup */
414 VDI_pitch = VDI_w * VDI_pixelsize;
415 VDI_format = ( (VDI_bpp <= 8) ? VDI_FORMAT_INTER : VDI_FORMAT_PACK);
416 VDI_redmask = VDI_greenmask = VDI_bluemask = VDI_alphamask = 0;
417 VDI_ReadExtInfo(this, work_out);
419 #ifdef DEBUG_VIDEO_GEM
420 printf("sdl:video:gem: screen: address=0x%08x, pitch=%d\n", VDI_screen, VDI_pitch);
421 printf("sdl:video:gem: format=%d\n", VDI_format);
422 printf("sdl:video:gem: masks: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
423 VDI_alphamask, VDI_redmask, VDI_greenmask, VDI_bluemask
427 /* Setup destination mfdb */
428 VDI_dst_mfdb.fd_addr = NULL;
430 /* Determine the current screen size */
431 this->info.current_w = VDI_w;
432 this->info.current_h = VDI_h;
434 /* Determine the screen depth */
435 /* we change this during the SDL_SetVideoMode implementation... */
436 vformat->BitsPerPixel = VDI_bpp;
438 /* Set mouse cursor to arrow */
439 graf_mouse(ARROW, NULL);
442 /* Init chunky to planar routine */
443 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
445 /* Setup VDI fill functions */
446 vsf_color(VDI_handle,0);
447 vsf_interior(VDI_handle,1);
448 vsf_perimeter(VDI_handle,0);
450 /* Menu bar save buffer */
451 menubar_size = GEM_desk_w * GEM_desk_y * VDI_pixelsize;
452 GEM_menubar=Atari_SysMalloc(menubar_size,MX_PREFTTRAM);
454 /* Fill video modes list */
455 SDL_modelist[0] = SDL_malloc(sizeof(SDL_Rect));
456 SDL_modelist[0]->x = 0;
457 SDL_modelist[0]->y = 0;
458 SDL_modelist[0]->w = VDI_w;
459 SDL_modelist[0]->h = VDI_h;
461 SDL_modelist[1] = NULL;
464 SDL_AtariGL_InitPointers(this);
467 this->info.wm_available = 1;
473 SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
475 if (format->BitsPerPixel != VDI_bpp) {
476 return ((SDL_Rect **)NULL);
479 if (flags & SDL_FULLSCREEN) {
480 return (SDL_modelist);
483 return((SDL_Rect **)-1);
486 static void GEM_FreeBuffers(_THIS)
490 Mfree( GEM_buffer2 );
495 Mfree( GEM_buffer1 );
500 static void GEM_ClearRect(_THIS, short *rect)
502 short oldrgb[3], rgb[3]={0,0,0};
504 vq_color(VDI_handle, vdi_index[0], 0, oldrgb);
505 vs_color(VDI_handle, vdi_index[0], rgb);
507 vsf_color(VDI_handle,0);
508 vsf_interior(VDI_handle,1);
509 vsf_perimeter(VDI_handle,0);
510 v_bar(VDI_handle, rect);
512 vs_color(VDI_handle, vdi_index[0], oldrgb);
515 static void GEM_ClearScreen(_THIS)
519 v_hide_c(VDI_handle);
524 GEM_ClearRect(this, pxy);
526 v_show_c(VDI_handle, 1);
529 static void GEM_SetNewPalette(_THIS, Uint16 newpal[256][3])
534 if (VDI_oldnumcolors==0)
537 for(i = 0; i < VDI_oldnumcolors; i++) {
538 rgb[0] = newpal[i][0];
539 rgb[1] = newpal[i][1];
540 rgb[2] = newpal[i][2];
542 vs_color(VDI_handle, i, rgb);
546 static void GEM_LockScreen(_THIS)
550 wind_update(BEG_UPDATE);
551 wind_update(BEG_MCTRL);
552 /* Reserve memory space, used to be sure of compatibility */
553 form_dial( FMD_START, 0,0,0,0, 0,0,VDI_w,VDI_h);
560 mfdb_src.fd_addr=GEM_menubar;
561 mfdb_src.fd_w=GEM_desk_w;
562 mfdb_src.fd_h=GEM_desk_y;
563 mfdb_src.fd_wdwidth=GEM_desk_w>>4;
564 mfdb_src.fd_nplanes=VDI_bpp;
570 blitcoords[0] = blitcoords[4] = 0;
571 blitcoords[1] = blitcoords[5] = 0;
572 blitcoords[2] = blitcoords[6] = GEM_desk_w-1;
573 blitcoords[3] = blitcoords[7] = GEM_desk_y-1;
575 vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &VDI_dst_mfdb, &mfdb_src);
582 static void GEM_UnlockScreen(_THIS)
585 /* Restore menu bar */
590 mfdb_src.fd_addr=GEM_menubar;
591 mfdb_src.fd_w=GEM_desk_w;
592 mfdb_src.fd_h=GEM_desk_y;
593 mfdb_src.fd_wdwidth=GEM_desk_w>>4;
594 mfdb_src.fd_nplanes=VDI_bpp;
600 blitcoords[0] = blitcoords[4] = 0;
601 blitcoords[1] = blitcoords[5] = 0;
602 blitcoords[2] = blitcoords[6] = GEM_desk_w-1;
603 blitcoords[3] = blitcoords[7] = GEM_desk_y-1;
605 vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
608 /* Restore screen memory, and send REDRAW to all apps */
609 form_dial( FMD_FINISH, 0,0,0,0, 0,0,VDI_w,VDI_h);
611 wind_update(END_MCTRL);
612 wind_update(END_UPDATE);
614 GEM_locked=SDL_FALSE;
618 SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current,
619 int width, int height, int bpp, Uint32 flags)
621 Uint32 modeflags, screensize;
622 SDL_bool use_shadow1, use_shadow2;
624 /* width must be multiple of 16, for vro_cpyfm() and c2p_convert() */
625 if ((width & 15) != 0) {
626 width = (width | 15) +1;
629 /*--- Verify if asked mode can be used ---*/
630 if (VDI_bpp != bpp) {
631 SDL_SetError("%d bpp mode not supported", bpp);
635 if (flags & SDL_FULLSCREEN) {
636 if ((VDI_w < width) || (VDI_h < height)) {
637 SDL_SetError("%dx%d mode is too large", width, height);
642 /*--- Allocate the new pixel format for the screen ---*/
643 if ( ! SDL_ReallocFormat(current, VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask, VDI_alphamask) ) {
644 SDL_SetError("Couldn't allocate new pixel format for requested mode");
648 screensize = width * height * VDI_pixelsize;
650 #ifdef DEBUG_VIDEO_GEM
651 printf("sdl:video:gem: setvideomode(): %dx%dx%d = %d\n", width, height, bpp, screensize);
654 /*--- Allocate shadow buffers if needed, and conversion operations ---*/
655 GEM_FreeBuffers(this);
658 use_shadow1=use_shadow2=SDL_FALSE;
659 if (VDI_screen && (flags & SDL_FULLSCREEN)) {
660 if (VDI_format==VDI_FORMAT_INTER) {
661 use_shadow1=SDL_TRUE;
662 GEM_bufops = B2S_C2P_1TOS;
665 use_shadow1=SDL_TRUE;
666 if (VDI_format==VDI_FORMAT_PACK) {
667 GEM_bufops = B2S_VROCPYFM_1TOS;
669 use_shadow2=SDL_TRUE;
670 GEM_bufops = B2S_C2P_1TO2|B2S_VROCPYFM_2TOS;
675 GEM_buffer1 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
676 if (GEM_buffer1==NULL) {
677 SDL_SetError("Can not allocate %d KB for frame buffer", screensize>>10);
680 SDL_memset(GEM_buffer1, 0, screensize);
681 #ifdef DEBUG_VIDEO_GEM
682 printf("sdl:video:gem: setvideomode(): allocated buffer 1\n");
687 GEM_buffer2 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
688 if (GEM_buffer2==NULL) {
689 SDL_SetError("Can not allocate %d KB for shadow buffer", screensize>>10);
692 SDL_memset(GEM_buffer2, 0, screensize);
693 #ifdef DEBUG_VIDEO_GEM
694 printf("sdl:video:gem: setvideomode(): allocated buffer 2\n");
698 /*--- Initialize screen ---*/
699 modeflags = SDL_PREALLOC;
701 modeflags |= SDL_HWPALETTE;
704 if (flags & SDL_FULLSCREEN) {
705 GEM_LockScreen(this);
707 GEM_ClearScreen(this);
709 modeflags |= SDL_FULLSCREEN;
710 if (VDI_screen && (VDI_format==VDI_FORMAT_PACK) && !use_shadow1) {
711 modeflags |= SDL_HWSURFACE;
713 modeflags |= SDL_SWSURFACE;
716 GEM_fullscreen = SDL_TRUE;
721 GEM_UnlockScreen(this);
723 /* Set window gadgets */
724 old_win_type = GEM_win_type;
725 if (!(flags & SDL_NOFRAME)) {
726 GEM_win_type=NAME|MOVER|CLOSER|SMALLER;
727 if (flags & SDL_RESIZABLE) {
728 GEM_win_type |= FULLER|SIZER;
729 modeflags |= SDL_RESIZABLE;
733 modeflags |= SDL_NOFRAME;
735 modeflags |= SDL_SWSURFACE;
737 /* Recreate window ? only for different widget or non-created window */
738 if ((old_win_type != GEM_win_type) || (GEM_handle < 0)) {
739 /* Calculate window size */
740 if (!wind_calc(WC_BORDER, GEM_win_type, 0,0,width,height, &x2,&y2,&w2,&h2)) {
741 GEM_FreeBuffers(this);
742 SDL_SetError("Can not calculate window attributes");
747 x2 = (GEM_desk_w-w2)>>1;
748 y2 = (GEM_desk_h-h2)>>1;
758 /* Destroy existing window */
759 if (GEM_handle >= 0) {
760 wind_close(GEM_handle);
761 wind_delete(GEM_handle);
765 GEM_handle=wind_create(GEM_win_type, x2,y2,w2,h2);
767 GEM_FreeBuffers(this);
768 SDL_SetError("Can not create window");
772 #ifdef DEBUG_VIDEO_GEM
773 printf("sdl:video:gem: handle=%d\n", GEM_handle);
776 /* Setup window name */
777 wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
778 GEM_refresh_name = SDL_FALSE;
780 /* Open the window */
781 wind_open(GEM_handle,x2,y2,w2,h2);
783 /* Resize window to fit asked video mode */
784 wind_get (GEM_handle, WF_WORKXYWH, &x2,&y2,&w2,&h2);
785 if (wind_calc(WC_BORDER, GEM_win_type, x2,y2,width,height, &x2,&y2,&w2,&h2)) {
786 wind_set (GEM_handle, WF_CURRXYWH, x2,y2,w2,h2);
790 GEM_fullscreen = SDL_FALSE;
793 /* Set up the new mode framebuffer */
797 current->pixels = GEM_buffer1;
798 current->pitch = width * VDI_pixelsize;
800 current->pixels = VDI_screen;
801 current->pitch = VDI_pitch;
805 if (flags & SDL_OPENGL) {
806 if (!SDL_AtariGL_Init(this, current)) {
807 GEM_FreeBuffers(this);
808 SDL_SetError("Can not create OpenGL context");
812 modeflags |= SDL_OPENGL;
816 current->flags = modeflags;
818 #ifdef DEBUG_VIDEO_GEM
819 printf("sdl:video:gem: surface: %dx%d\n", current->w, current->h);
822 this->UpdateRects = GEM_UpdateRects;
823 GEM_lock_redraw = SDL_FALSE; /* Enable redraw */
829 static int GEM_AllocHWSurface(_THIS, SDL_Surface *surface)
834 static void GEM_FreeHWSurface(_THIS, SDL_Surface *surface)
839 static int GEM_LockHWSurface(_THIS, SDL_Surface *surface)
844 static void GEM_UnlockHWSurface(_THIS, SDL_Surface *surface)
849 static void GEM_UpdateRectsFullscreen(_THIS, int numrects, SDL_Rect *rects)
851 SDL_Surface *surface;
854 surface = this->screen;
855 /* Need to be a multiple of 16 pixels */
856 surf_width=surface->w;
857 if ((surf_width & 15) != 0) {
858 surf_width = (surf_width | 15) + 1;
861 if (GEM_bufops & (B2S_C2P_1TO2|B2S_C2P_1TOS)) {
865 if (GEM_bufops & B2S_C2P_1TOS) {
866 destscr = VDI_screen;
867 destpitch = VDI_pitch;
869 destscr = GEM_buffer2;
870 destpitch = surface->pitch;
873 for (i=0;i<numrects;i++) {
874 void *source,*destination;
877 x1 = rects[i].x & ~15;
878 x2 = rects[i].x+rects[i].w;
883 source = surface->pixels;
884 source += surface->pitch * rects[i].y;
887 destination = destscr;
888 destination += destpitch * rects[i].y;
891 SDL_Atari_C2pConvert(
895 surface->pitch, destpitch
900 if (GEM_bufops & (B2S_VROCPYFM_1TOS|B2S_VROCPYFM_2TOS)) {
904 mfdb_src.fd_addr=surface->pixels;
905 mfdb_src.fd_w=surf_width;
906 mfdb_src.fd_h=surface->h;
907 mfdb_src.fd_wdwidth= (surface->pitch/VDI_pixelsize) >> 4;
908 mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
913 if (GEM_bufops & B2S_VROCPYFM_2TOS) {
914 mfdb_src.fd_addr=GEM_buffer2;
917 for ( i=0; i<numrects; ++i ) {
918 blitcoords[0] = blitcoords[4] = rects[i].x;
919 blitcoords[1] = blitcoords[5] = rects[i].y;
920 blitcoords[2] = blitcoords[6] = rects[i].x + rects[i].w - 1;
921 blitcoords[3] = blitcoords[7] = rects[i].y + rects[i].h - 1;
923 vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
928 static void GEM_UpdateRectsWindowed(_THIS, int numrects, SDL_Rect *rects)
930 short pxy[4], wind_pxy[4];
933 if (wind_get(GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3])==0) {
937 for ( i=0; i<numrects; ++i ) {
938 pxy[0] = wind_pxy[0] + rects[i].x;
939 pxy[1] = wind_pxy[1] + rects[i].y;
943 GEM_wind_redraw(this, GEM_handle, pxy);
947 static void GEM_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
949 SDL_Surface *surface;
951 if (GEM_lock_redraw) {
955 surface = this->screen;
957 if (surface->flags & SDL_FULLSCREEN) {
958 GEM_UpdateRectsFullscreen(this, numrects, rects);
960 GEM_UpdateRectsWindowed(this, numrects, rects);
964 static int GEM_FlipHWSurfaceFullscreen(_THIS, SDL_Surface *surface)
968 /* Need to be a multiple of 16 pixels */
969 surf_width=surface->w;
970 if ((surf_width & 15) != 0) {
971 surf_width = (surf_width | 15) + 1;
974 if (GEM_bufops & (B2S_C2P_1TO2|B2S_C2P_1TOS)) {
978 if (GEM_bufops & B2S_C2P_1TOS) {
979 destscr = VDI_screen;
980 destpitch = VDI_pitch;
982 destscr = GEM_buffer2;
983 destpitch = surface->pitch;
986 SDL_Atari_C2pConvert(
987 surface->pixels, destscr,
988 surf_width, surface->h,
990 surface->pitch, destpitch
994 if (GEM_bufops & (B2S_VROCPYFM_1TOS|B2S_VROCPYFM_2TOS)) {
998 mfdb_src.fd_w=surf_width;
999 mfdb_src.fd_h=surface->h;
1000 mfdb_src.fd_wdwidth=mfdb_src.fd_w >> 4;
1001 mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
1006 if (GEM_bufops & B2S_VROCPYFM_1TOS) {
1007 mfdb_src.fd_addr=surface->pixels;
1009 mfdb_src.fd_addr=GEM_buffer2;
1012 blitcoords[0] = blitcoords[4] = 0;
1013 blitcoords[1] = blitcoords[5] = 0;
1014 blitcoords[2] = blitcoords[6] = surface->w - 1;
1015 blitcoords[3] = blitcoords[7] = surface->h - 1;
1017 vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
1023 static int GEM_FlipHWSurfaceWindowed(_THIS, SDL_Surface *surface)
1027 /* Update the whole window */
1028 wind_get(GEM_handle, WF_WORKXYWH, &pxy[0], &pxy[1], &pxy[2], &pxy[3]);
1030 GEM_wind_redraw(this, GEM_handle, pxy);
1035 static int GEM_FlipHWSurface(_THIS, SDL_Surface *surface)
1037 if (GEM_lock_redraw) {
1041 if (surface->flags & SDL_FULLSCREEN) {
1042 return GEM_FlipHWSurfaceFullscreen(this, surface);
1044 return GEM_FlipHWSurfaceWindowed(this, surface);
1048 static int GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
1051 SDL_Surface *surface;
1053 #ifdef DEBUG_VIDEO_GEM
1054 printf("sdl:video:gem: setcolors()\n");
1057 /* Do not change palette in True Colour */
1058 surface = this->screen;
1059 if (surface->format->BitsPerPixel > 8) {
1063 for(i = 0; i < ncolors; i++)
1072 rgb[0] = VDI_curpalette[i][0] = (1000 * r) / 255;
1073 rgb[1] = VDI_curpalette[i][1] =(1000 * g) / 255;
1074 rgb[2] = VDI_curpalette[i][2] =(1000 * b) / 255;
1076 vs_color(VDI_handle, vdi_index[firstcolor+i], rgb);
1083 static int GEM_ToggleFullScreen(_THIS, int on)
1086 GEM_LockScreen(this);
1088 GEM_UnlockScreen(this);
1095 /* Note: If we are terminated, this could be called in the middle of
1096 another SDL video routine -- notably UpdateRects.
1098 void GEM_VideoQuit(_THIS)
1100 SDL_AtariXbios_RestoreVectors();
1101 if (GEM_usedevmouse) {
1102 SDL_AtariDevMouse_Close();
1105 GEM_FreeBuffers(this);
1107 #if SDL_VIDEO_OPENGL
1109 SDL_AtariGL_Quit(this, SDL_TRUE);
1113 /* Destroy window */
1114 if (GEM_handle>=0) {
1115 wind_close(GEM_handle);
1116 wind_delete(GEM_handle);
1120 GEM_UnlockScreen(this);
1128 GEM_SetNewPalette(this, VDI_oldpalette);
1130 /* Close VDI workstation */
1132 v_clsvwk(VDI_handle);
1135 /* Free mode list */
1136 if (SDL_modelist[0]) {
1137 SDL_free(SDL_modelist[0]);
1138 SDL_modelist[0]=NULL;
1141 this->screen->pixels = NULL;
1144 void GEM_wind_redraw(_THIS, int winhandle, short *inside)
1148 /* Tell AES we are going to update */
1149 wind_update(BEG_UPDATE);
1151 v_hide_c(VDI_handle);
1153 /* Browse the rectangle list to redraw */
1154 if (wind_get(winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])!=0) {
1156 while (todo[2] && todo[3]) {
1158 if (rc_intersect((GRECT *)inside,(GRECT *)todo)) {
1159 todo[2] += todo[0]-1;
1160 todo[3] += todo[1]-1;
1161 refresh_window(this, winhandle, todo);
1164 if (wind_get(winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])==0) {
1171 /* Update finished */
1172 wind_update(END_UPDATE);
1174 v_show_c(VDI_handle,1);
1177 static void refresh_window(_THIS, int winhandle, short *rect)
1180 short pxy[8],wind_pxy[8];
1181 SDL_Surface *surface;
1184 /* Is window iconified ? */
1186 /* if (GEM_wfeatures & (1<<WF_ICONIFY))*/ {
1187 if (wind_get(winhandle, WF_ICONIFY, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3])!=0) {
1188 iconified = wind_pxy[0];
1192 if (wind_get(winhandle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3])==0) {
1196 if (iconified && GEM_icon) {
1197 short icon_rect[4], dst_rect[4];
1202 GEM_ClearRect(this, rect);
1204 /* Calculate centered icon(x,y,w,h) relative to window */
1205 iconx = (wind_pxy[2]-surface->w)>>1;
1206 icony = (wind_pxy[3]-surface->h)>>1;
1208 icon_rect[0] = iconx;
1209 icon_rect[1] = icony;
1210 icon_rect[2] = surface->w;
1211 icon_rect[3] = surface->h;
1213 /* Calculate redraw rectangle(x,y,w,h) relative to window */
1214 dst_rect[0] = rect[0]-wind_pxy[0];
1215 dst_rect[1] = rect[1]-wind_pxy[1];
1216 dst_rect[2] = rect[2]-rect[0]+1;
1217 dst_rect[3] = rect[3]-rect[1]+1;
1219 /* Does the icon rectangle must be redrawn ? */
1220 if (!rc_intersect((GRECT *)icon_rect, (GRECT *)dst_rect)) {
1225 printf("sdl:video:gem: clip(0,0,%d,%d) to (%d,%d,%d,%d)\n",
1226 surface->w-1,surface->h-1, dst_rect[0],dst_rect[1],dst_rect[2],dst_rect[3]);
1227 printf("sdl:video:gem: icon(%d,%d,%d,%d)\n",
1228 icon_rect[0], icon_rect[1], icon_rect[2], icon_rect[3]);
1229 printf("sdl:video:gem: refresh_window(): draw icon\n");
1232 /* Calculate icon(x1,y1,x2,y2) relative to screen */
1233 icon_rect[0] += wind_pxy[0];
1234 icon_rect[1] += wind_pxy[1];
1235 icon_rect[2] += icon_rect[0]-1;
1236 icon_rect[3] += icon_rect[1]-1;
1238 /* Calculate intersection rectangle to redraw */
1239 pxy[4]=pxy[0]=MAX(icon_rect[0],rect[0]);
1240 pxy[5]=pxy[1]=MAX(icon_rect[1],rect[1]);
1241 pxy[6]=pxy[2]=MIN(icon_rect[2],rect[2]);
1242 pxy[7]=pxy[3]=MIN(icon_rect[3],rect[3]);
1244 /* Calculate icon source image pos relative to window */
1245 pxy[0] -= wind_pxy[0]+iconx;
1246 pxy[1] -= wind_pxy[1]+icony;
1247 pxy[2] -= wind_pxy[0]+iconx;
1248 pxy[3] -= wind_pxy[1]+icony;
1251 surface = this->screen;
1254 printf("sdl:video:gem: refresh_window(): draw frame buffer\n");
1257 /* Redraw all window content */
1258 pxy[0] = rect[0]-wind_pxy[0];
1259 pxy[1] = rect[1]-wind_pxy[1];
1260 pxy[2] = rect[2]-wind_pxy[0];
1261 pxy[3] = rect[3]-wind_pxy[1];
1269 if (GEM_bufops & B2S_C2P_1TO2) {
1273 x1 = (rect[0]-wind_pxy[0]) & ~15;
1274 x2 = rect[2]-wind_pxy[0];
1279 src = surface->pixels;
1280 src += surface->pitch * (rect[1]-wind_pxy[1]);
1284 dest += surface->pitch * (rect[1]-wind_pxy[1]);
1287 SDL_Atari_C2pConvert(
1289 x2-x1, rect[3]-rect[1]+1,
1291 surface->pitch, surface->pitch
1295 mfdb_src.fd_addr=surface->pixels;
1299 /* Need to be a multiple of 16 pixels */
1301 if ((width & 15) != 0) {
1302 width = (width | 15) + 1;
1304 mfdb_src.fd_w=width;
1306 mfdb_src.fd_h=surface->h;
1307 mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
1308 mfdb_src.fd_wdwidth=mfdb_src.fd_w>>4;
1314 if (GEM_bufops & B2S_VROCPYFM_2TOS) {
1315 mfdb_src.fd_addr=GEM_buffer2;
1319 printf("sdl:video:gem: redraw %dx%d: (%d,%d,%d,%d) to (%d,%d,%d,%d)\n",
1320 surface->w, surface->h,
1321 pxy[0],pxy[1],pxy[2],pxy[3],
1322 pxy[4],pxy[5],pxy[6],pxy[7]
1326 vro_cpyfm( VDI_handle, S_ONLY, pxy, &mfdb_src, &VDI_dst_mfdb);
1329 #if SDL_VIDEO_OPENGL
1331 static void GEM_GL_SwapBuffers(_THIS)
1333 SDL_AtariGL_SwapBuffers(this);
1334 GEM_FlipHWSurface(this, this->screen);