src/video/gem/SDL_gemvideo.c
author Patrice Mandin
Sun, 27 May 2007 08:54:38 +0000
changeset 2108 a930c8e4d8b0
parent 2107 757dfb38f574
child 2120 2c835d58faad
permissions -rw-r--r--
Allow creation of window bigger than visible size
slouken@281
     1
/*
slouken@281
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@281
     4
slouken@281
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@281
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@281
     9
slouken@281
    10
    This library is distributed in the hope that it will be useful,
slouken@281
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@281
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@281
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@281
    18
slouken@281
    19
    Sam Lantinga
slouken@281
    20
    slouken@libsdl.org
slouken@281
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@281
    23
slouken@281
    24
/*
patmandin@736
    25
	GEM video driver
patmandin@736
    26
patmandin@736
    27
	Patrice Mandin
patmandin@736
    28
	and work from
patmandin@736
    29
	Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
patmandin@736
    30
*/
slouken@281
    31
slouken@281
    32
/* Mint includes */
slouken@281
    33
#include <gem.h>
slouken@281
    34
#include <gemx.h>
slouken@281
    35
#include <mint/osbind.h>
slouken@557
    36
#include <mint/cookie.h>
slouken@281
    37
slouken@1358
    38
#include "SDL_endian.h"
slouken@281
    39
#include "SDL_video.h"
slouken@281
    40
#include "SDL_mouse.h"
slouken@1361
    41
#include "../SDL_sysvideo.h"
slouken@1361
    42
#include "../SDL_pixels_c.h"
slouken@1361
    43
#include "../../events/SDL_events_c.h"
slouken@1361
    44
#include "../SDL_cursor_c.h"
slouken@281
    45
patmandin@1412
    46
#include "../ataricommon/SDL_ataric2p_s.h"
patmandin@1412
    47
#include "../ataricommon/SDL_atarieddi_s.h"
patmandin@1412
    48
#include "../ataricommon/SDL_atarimxalloc_c.h"
patmandin@1412
    49
#include "../ataricommon/SDL_atarigl_c.h"
patmandin@989
    50
slouken@281
    51
#include "SDL_gemvideo.h"
slouken@281
    52
#include "SDL_gemevents_c.h"
slouken@281
    53
#include "SDL_gemmouse_c.h"
slouken@281
    54
#include "SDL_gemwm_c.h"
patmandin@1412
    55
#include "../ataricommon/SDL_xbiosevents_c.h"
patmandin@1420
    56
#include "../ataricommon/SDL_ataridevmouse_c.h"
slouken@281
    57
slouken@281
    58
/* Defines */
slouken@281
    59
patmandin@984
    60
/*#define DEBUG_VIDEO_GEM	1*/
patmandin@736
    61
slouken@281
    62
#define GEM_VID_DRIVER_NAME "gem"
slouken@281
    63
patmandin@737
    64
#undef MIN
patmandin@737
    65
#define MIN(a,b) (((a)<(b)) ? (a) : (b))
patmandin@737
    66
#undef MAX
patmandin@737
    67
#define MAX(a,b) (((a)>(b)) ? (a) : (b))
patmandin@737
    68
slouken@281
    69
/* Variables */
slouken@281
    70
slouken@281
    71
static unsigned char vdi_index[256] = {
slouken@1895
    72
    0, 2, 3, 6, 4, 7, 5, 8,
slouken@1895
    73
    9, 10, 11, 14, 12, 15, 13, 255
slouken@281
    74
};
slouken@281
    75
slouken@1895
    76
static const unsigned char empty_name[] = "";
slouken@281
    77
slouken@281
    78
/* Initialization/Query functions */
slouken@1895
    79
static int GEM_VideoInit(_THIS, SDL_PixelFormat * vformat);
slouken@1895
    80
static SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat * format,
slouken@1895
    81
                                Uint32 flags);
slouken@1895
    82
static SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface * current, int width,
slouken@1895
    83
                                     int height, int bpp, Uint32 flags);
slouken@1895
    84
static int GEM_SetColors(_THIS, int firstcolor, int ncolors,
slouken@1895
    85
                         SDL_Color * colors);
slouken@281
    86
static void GEM_VideoQuit(_THIS);
slouken@281
    87
slouken@281
    88
/* Hardware surface functions */
slouken@1895
    89
static int GEM_AllocHWSurface(_THIS, SDL_Surface * surface);
slouken@1895
    90
static int GEM_LockHWSurface(_THIS, SDL_Surface * surface);
slouken@1895
    91
static int GEM_FlipHWSurface(_THIS, SDL_Surface * surface);
slouken@1895
    92
static void GEM_UnlockHWSurface(_THIS, SDL_Surface * surface);
slouken@1895
    93
static void GEM_FreeHWSurface(_THIS, SDL_Surface * surface);
slouken@1895
    94
static void GEM_UpdateRects(_THIS, int numrects, SDL_Rect * rects);
slouken@281
    95
#if 0
slouken@281
    96
static int GEM_ToggleFullScreen(_THIS, int on);
slouken@281
    97
#endif
slouken@281
    98
slouken@281
    99
/* Internal functions */
slouken@281
   100
static void GEM_FreeBuffers(_THIS);
slouken@319
   101
static void GEM_ClearScreen(_THIS);
patmandin@736
   102
static void GEM_ClearRect(_THIS, short *rect);
patmandin@1074
   103
static void GEM_SetNewPalette(_THIS, Uint16 newpal[256][3]);
slouken@319
   104
static void GEM_LockScreen(_THIS);
slouken@319
   105
static void GEM_UnlockScreen(_THIS);
slouken@281
   106
static void refresh_window(_THIS, int winhandle, short *rect);
slouken@281
   107
slouken@1361
   108
#if SDL_VIDEO_OPENGL
patmandin@984
   109
/* OpenGL functions */
patmandin@984
   110
static void GEM_GL_SwapBuffers(_THIS);
patmandin@984
   111
#endif
patmandin@984
   112
slouken@281
   113
/* GEM driver bootstrap functions */
slouken@281
   114
slouken@1895
   115
static int
slouken@1895
   116
GEM_Available(void)
slouken@281
   117
{
slouken@1895
   118
    /* Test if AES available */
slouken@1895
   119
    if (appl_init() == -1)
slouken@1895
   120
        return 0;
slouken@281
   121
slouken@1895
   122
    appl_exit();
slouken@1895
   123
    return 1;
slouken@281
   124
}
slouken@281
   125
slouken@1895
   126
static void
slouken@1895
   127
GEM_DeleteDevice(SDL_VideoDevice * device)
slouken@281
   128
{
slouken@1895
   129
    SDL_free(device->hidden);
slouken@1895
   130
    SDL_free(device);
slouken@281
   131
}
slouken@281
   132
slouken@1895
   133
static SDL_VideoDevice *
slouken@1895
   134
GEM_CreateDevice(int devindex)
slouken@281
   135
{
slouken@1895
   136
    SDL_VideoDevice *device;
slouken@1895
   137
    int vectors_mask;
slouken@1895
   138
    unsigned long dummy;
slouken@281
   139
slouken@1895
   140
    /* Initialize all variables that we clean on shutdown */
slouken@1895
   141
    device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
slouken@1895
   142
    if (device) {
slouken@1895
   143
        SDL_memset(device, 0, (sizeof *device));
slouken@1895
   144
        device->hidden = (struct SDL_PrivateVideoData *)
slouken@1895
   145
            SDL_malloc((sizeof *device->hidden));
slouken@1895
   146
        device->gl_data = (struct SDL_PrivateGLData *)
slouken@1895
   147
            SDL_malloc((sizeof *device->gl_data));
slouken@1895
   148
    }
slouken@1895
   149
    if ((device == NULL) || (device->hidden == NULL)) {
slouken@1895
   150
        SDL_OutOfMemory();
slouken@1895
   151
        if (device) {
slouken@1895
   152
            SDL_free(device);
slouken@1895
   153
        }
slouken@1895
   154
        return (0);
slouken@1895
   155
    }
slouken@1895
   156
    SDL_memset(device->hidden, 0, (sizeof *device->hidden));
slouken@1895
   157
    SDL_memset(device->gl_data, 0, sizeof(*device->gl_data));
slouken@281
   158
slouken@1895
   159
    /* Set the function pointers */
slouken@1895
   160
    device->VideoInit = GEM_VideoInit;
slouken@1895
   161
    device->ListModes = GEM_ListModes;
slouken@1895
   162
    device->SetVideoMode = GEM_SetVideoMode;
slouken@1895
   163
    device->SetColors = GEM_SetColors;
slouken@1895
   164
    device->UpdateRects = NULL /*GEM_UpdateRects */ ;
slouken@1895
   165
    device->VideoQuit = GEM_VideoQuit;
slouken@1895
   166
    device->AllocHWSurface = GEM_AllocHWSurface;
slouken@1895
   167
    device->LockHWSurface = GEM_LockHWSurface;
slouken@1895
   168
    device->UnlockHWSurface = GEM_UnlockHWSurface;
slouken@1895
   169
    device->FlipHWSurface = GEM_FlipHWSurface;
slouken@1895
   170
    device->FreeHWSurface = GEM_FreeHWSurface;
slouken@1895
   171
    device->ToggleFullScreen = NULL /*GEM_ToggleFullScreen */ ;
slouken@281
   172
slouken@1895
   173
    /* Window manager */
slouken@1895
   174
    device->SetCaption = GEM_SetCaption;
slouken@1895
   175
    device->SetIcon = GEM_SetIcon;
slouken@1895
   176
    device->IconifyWindow = GEM_IconifyWindow;
slouken@1895
   177
    device->GrabInput = GEM_GrabInput;
slouken@281
   178
slouken@1895
   179
    /* Events */
slouken@1895
   180
    device->InitOSKeymap = GEM_InitOSKeymap;
slouken@1895
   181
    device->PumpEvents = GEM_PumpEvents;
slouken@281
   182
slouken@1895
   183
    /* Mouse */
slouken@1895
   184
    device->FreeWMCursor = GEM_FreeWMCursor;
slouken@1895
   185
    device->CreateWMCursor = GEM_CreateWMCursor;
slouken@1895
   186
    device->ShowWMCursor = GEM_ShowWMCursor;
slouken@1895
   187
    device->WarpWMCursor = NULL /*GEM_WarpWMCursor */ ;
slouken@1895
   188
    device->CheckMouseMode = GEM_CheckMouseMode;
slouken@281
   189
slouken@1361
   190
#if SDL_VIDEO_OPENGL
slouken@1895
   191
    /* OpenGL functions */
slouken@1895
   192
    device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary;
slouken@1895
   193
    device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress;
slouken@1895
   194
    device->GL_GetAttribute = SDL_AtariGL_GetAttribute;
slouken@1895
   195
    device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent;
slouken@1895
   196
    device->GL_SwapBuffers = GEM_GL_SwapBuffers;
patmandin@984
   197
#endif
patmandin@984
   198
slouken@1895
   199
    device->hidden->use_dev_mouse =
slouken@1895
   200
        (SDL_AtariDevMouse_Open() != 0) ? SDL_TRUE : SDL_FALSE;
patmandin@1420
   201
slouken@1895
   202
    vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;  /* XBIOS joystick events */
slouken@1895
   203
    if (!(device->hidden->use_dev_mouse)) {
slouken@1895
   204
        vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;        /* XBIOS mouse events */
slouken@1895
   205
    }
patmandin@2024
   206
    /*if (Getcookie(C_MiNT, &dummy) == C_FOUND) {
slouken@2043
   207
       vectors_mask = 0;
slouken@2043
   208
       } */
patmandin@1237
   209
slouken@1895
   210
    SDL_AtariXbios_InstallVectors(vectors_mask);
slouken@305
   211
slouken@1895
   212
    device->free = GEM_DeleteDevice;
slouken@281
   213
slouken@1895
   214
    return device;
slouken@281
   215
}
slouken@281
   216
slouken@281
   217
VideoBootStrap GEM_bootstrap = {
slouken@1895
   218
    GEM_VID_DRIVER_NAME, "Atari GEM video driver",
slouken@1895
   219
    GEM_Available, GEM_CreateDevice
slouken@281
   220
};
slouken@281
   221
slouken@1895
   222
static void
slouken@1895
   223
VDI_ReadExtInfo(_THIS, short *work_out)
slouken@281
   224
{
slouken@1895
   225
    unsigned long EdDI_version;
slouken@1895
   226
    unsigned long cookie_EdDI;
slouken@1895
   227
    Uint32 num_colours;
slouken@1895
   228
    Uint16 clut_type, num_bits;
slouken@281
   229
slouken@1895
   230
    /* Read EdDI informations */
slouken@1895
   231
    if (Getcookie(C_EdDI, &cookie_EdDI) == C_NOTFOUND) {
slouken@1895
   232
        return;
slouken@1895
   233
    }
slouken@281
   234
slouken@1895
   235
    EdDI_version = Atari_get_EdDI_version((void *) cookie_EdDI);
slouken@1895
   236
slouken@1895
   237
    vq_scrninfo(VDI_handle, work_out);
slouken@281
   238
slouken@1895
   239
    VDI_format = work_out[0];
slouken@1895
   240
    clut_type = work_out[1];
slouken@1895
   241
    num_bits = work_out[2];
slouken@1895
   242
    num_colours = *((Uint32 *) & work_out[3]);
slouken@281
   243
slouken@1895
   244
    /* With EdDI>=1.1, we can have screen pitch, address and format
slouken@1895
   245
     * so we can directly write to screen without using vro_cpyfm
slouken@1895
   246
     */
slouken@1895
   247
    if (EdDI_version >= EDDI_11) {
slouken@1895
   248
        VDI_pitch = work_out[5];
slouken@1895
   249
        VDI_screen = (void *) *((unsigned long *) &work_out[6]);
slouken@1895
   250
    }
slouken@281
   251
slouken@1895
   252
    switch (clut_type) {
slouken@1895
   253
    case VDI_CLUT_HARDWARE:
slouken@1895
   254
        {
slouken@1895
   255
            int i;
slouken@1895
   256
            Uint16 *tmp_p;
slouken@281
   257
slouken@1895
   258
            tmp_p = (Uint16 *) & work_out[16];
slouken@281
   259
slouken@1895
   260
            for (i = 0; i < 256; i++) {
slouken@1895
   261
                vdi_index[*tmp_p++] = i;
slouken@1895
   262
            }
slouken@1895
   263
        }
slouken@1895
   264
        break;
slouken@1895
   265
    case VDI_CLUT_SOFTWARE:
slouken@1895
   266
        {
slouken@1895
   267
            int component;      /* red, green, blue, alpha, overlay */
slouken@1895
   268
            int num_bit;
slouken@1895
   269
            unsigned short *tmp_p;
slouken@281
   270
slouken@1895
   271
            /* We can build masks with info here */
slouken@1895
   272
            tmp_p = (unsigned short *) &work_out[16];
slouken@1895
   273
            for (component = 0; component < 5; component++) {
slouken@1895
   274
                for (num_bit = 0; num_bit < 16; num_bit++) {
slouken@1895
   275
                    unsigned short valeur;
slouken@281
   276
slouken@1895
   277
                    valeur = *tmp_p++;
slouken@281
   278
slouken@1895
   279
                    if (valeur == 0xffff) {
slouken@1895
   280
                        continue;
slouken@1895
   281
                    }
slouken@281
   282
slouken@1895
   283
                    switch (component) {
slouken@1895
   284
                    case 0:
slouken@1895
   285
                        VDI_redmask |= 1 << valeur;
slouken@1895
   286
                        break;
slouken@1895
   287
                    case 1:
slouken@1895
   288
                        VDI_greenmask |= 1 << valeur;
slouken@1895
   289
                        break;
slouken@1895
   290
                    case 2:
slouken@1895
   291
                        VDI_bluemask |= 1 << valeur;
slouken@1895
   292
                        break;
slouken@1895
   293
                    case 3:
slouken@1895
   294
                        VDI_alphamask |= 1 << valeur;
slouken@1895
   295
                        break;
slouken@1895
   296
                    }
slouken@1895
   297
                }
slouken@1895
   298
            }
slouken@1895
   299
        }
slouken@281
   300
slouken@1895
   301
        /* Remove lower green bits for Intel endian screen */
slouken@1895
   302
        if ((VDI_greenmask == ((7 << 13) | 3))
slouken@1895
   303
            || (VDI_greenmask == ((7 << 13) | 7))) {
slouken@1895
   304
            VDI_greenmask &= ~(7 << 13);
slouken@1895
   305
        }
slouken@1895
   306
        break;
slouken@1895
   307
    case VDI_CLUT_NONE:
slouken@1895
   308
        break;
slouken@1895
   309
    }
slouken@281
   310
}
slouken@281
   311
slouken@1895
   312
int
slouken@1895
   313
GEM_VideoInit(_THIS, SDL_PixelFormat * vformat)
slouken@281
   314
{
slouken@1895
   315
    int i, menubar_size;
slouken@1895
   316
    short work_in[12], work_out[272], dummy;
slouken@281
   317
slouken@1895
   318
    /* Open AES (Application Environment Services) */
slouken@1895
   319
    if (appl_init() == -1) {
slouken@1895
   320
        fprintf(stderr, "Can not open AES\n");
slouken@1895
   321
        return 1;
slouken@1895
   322
    }
slouken@281
   323
slouken@1895
   324
    /* Read version and features */
slouken@1895
   325
    GEM_version = aes_global[0];
slouken@1895
   326
    if (GEM_version >= 0x0410) {
slouken@1895
   327
        short ap_gout[4], errorcode;
patmandin@736
   328
slouken@1895
   329
        GEM_wfeatures = 0;
slouken@1895
   330
        errorcode =
slouken@1895
   331
            appl_getinfo(AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2],
slouken@1895
   332
                         &ap_gout[3]);
slouken@1895
   333
slouken@1895
   334
        if (errorcode == 0) {
slouken@1895
   335
            GEM_wfeatures = ap_gout[0];
slouken@1895
   336
        }
slouken@1895
   337
    }
slouken@281
   338
slouken@1895
   339
    /* Ask VDI physical workstation handle opened by AES */
slouken@1895
   340
    VDI_handle = graf_handle(&dummy, &dummy, &dummy, &dummy);
slouken@1895
   341
    if (VDI_handle < 1) {
slouken@1895
   342
        fprintf(stderr, "Wrong VDI handle %d returned by AES\n", VDI_handle);
slouken@1895
   343
        return 1;
slouken@1895
   344
    }
slouken@281
   345
slouken@1895
   346
    /* Open virtual VDI workstation */
slouken@1895
   347
    work_in[0] = Getrez() + 2;
slouken@1895
   348
    for (i = 1; i < 10; i++)
slouken@1895
   349
        work_in[i] = 1;
slouken@1895
   350
    work_in[10] = 2;
slouken@281
   351
slouken@1895
   352
    v_opnvwk(work_in, &VDI_handle, work_out);
slouken@1895
   353
    if (VDI_handle == 0) {
slouken@1895
   354
        fprintf(stderr, "Can not open VDI virtual workstation\n");
slouken@1895
   355
        return 1;
slouken@1895
   356
    }
slouken@281
   357
slouken@1895
   358
    /* Read fullscreen size */
slouken@1895
   359
    VDI_w = work_out[0] + 1;
slouken@1895
   360
    VDI_h = work_out[1] + 1;
slouken@281
   361
slouken@1895
   362
    /* Read desktop size and position */
slouken@1895
   363
    if (!wind_get
slouken@1895
   364
        (DESKTOP_HANDLE, WF_WORKXYWH, &GEM_desk_x, &GEM_desk_y, &GEM_desk_w,
slouken@1895
   365
         &GEM_desk_h)) {
slouken@1895
   366
        fprintf(stderr, "Can not read desktop properties\n");
slouken@1895
   367
        return 1;
slouken@1895
   368
    }
slouken@281
   369
slouken@1895
   370
    /* Read bit depth */
slouken@1895
   371
    vq_extnd(VDI_handle, 1, work_out);
slouken@1895
   372
    VDI_bpp = work_out[4];
slouken@1895
   373
    VDI_oldnumcolors = 0;
slouken@281
   374
slouken@1895
   375
    switch (VDI_bpp) {
slouken@1895
   376
    case 8:
slouken@1895
   377
        VDI_pixelsize = 1;
slouken@1895
   378
        break;
slouken@1895
   379
    case 15:
slouken@1895
   380
    case 16:
slouken@1895
   381
        VDI_pixelsize = 2;
slouken@1895
   382
        break;
slouken@1895
   383
    case 24:
slouken@1895
   384
        VDI_pixelsize = 3;
slouken@1895
   385
        break;
slouken@1895
   386
    case 32:
slouken@1895
   387
        VDI_pixelsize = 4;
slouken@1895
   388
        break;
slouken@1895
   389
    default:
slouken@1895
   390
        fprintf(stderr, "%d bits colour depth not supported\n", VDI_bpp);
slouken@1895
   391
        return 1;
slouken@1895
   392
    }
slouken@1895
   393
slouken@1895
   394
    /* Setup hardware -> VDI palette mapping */
slouken@1895
   395
    for (i = 16; i < 255; i++) {
slouken@1895
   396
        vdi_index[i] = i;
slouken@1895
   397
    }
slouken@1895
   398
    vdi_index[255] = 1;
slouken@281
   399
slouken@1895
   400
    /* Save current palette */
slouken@1895
   401
    if (VDI_bpp > 8) {
slouken@1895
   402
        VDI_oldnumcolors = 1 << 8;
slouken@1895
   403
    } else {
slouken@1895
   404
        VDI_oldnumcolors = 1 << VDI_bpp;
slouken@1895
   405
    }
slouken@281
   406
slouken@1895
   407
    for (i = 0; i < VDI_oldnumcolors; i++) {
slouken@1895
   408
        short rgb[3];
slouken@1895
   409
slouken@1895
   410
        vq_color(VDI_handle, i, 0, rgb);
slouken@281
   411
slouken@1895
   412
        VDI_oldpalette[i][0] = rgb[0];
slouken@1895
   413
        VDI_oldpalette[i][1] = rgb[1];
slouken@1895
   414
        VDI_oldpalette[i][2] = rgb[2];
slouken@1895
   415
    }
slouken@1895
   416
    VDI_setpalette = GEM_SetNewPalette;
slouken@1895
   417
    SDL_memcpy(VDI_curpalette, VDI_oldpalette, sizeof(VDI_curpalette));
slouken@281
   418
slouken@1895
   419
    /* Setup screen info */
slouken@1895
   420
    GEM_title_name = empty_name;
slouken@1895
   421
    GEM_icon_name = empty_name;
slouken@281
   422
slouken@1895
   423
    GEM_handle = -1;
slouken@1895
   424
    GEM_locked = SDL_FALSE;
slouken@1895
   425
    GEM_win_fulled = SDL_FALSE;
slouken@1895
   426
    GEM_fullscreen = SDL_FALSE;
slouken@1895
   427
    GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers are setup */
slouken@281
   428
slouken@1895
   429
    VDI_screen = NULL;
slouken@1895
   430
    VDI_pitch = VDI_w * VDI_pixelsize;
slouken@1895
   431
    VDI_format = ((VDI_bpp <= 8) ? VDI_FORMAT_INTER : VDI_FORMAT_PACK);
slouken@1895
   432
    VDI_redmask = VDI_greenmask = VDI_bluemask = VDI_alphamask = 0;
slouken@1895
   433
    VDI_ReadExtInfo(this, work_out);
patmandin@799
   434
patmandin@799
   435
#ifdef DEBUG_VIDEO_GEM
slouken@1895
   436
    printf("sdl:video:gem: screen: address=0x%08x, pitch=%d\n", VDI_screen,
slouken@1895
   437
           VDI_pitch);
slouken@1895
   438
    printf("sdl:video:gem: format=%d\n", VDI_format);
slouken@1895
   439
    printf("sdl:video:gem: masks: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
slouken@1895
   440
           VDI_alphamask, VDI_redmask, VDI_greenmask, VDI_bluemask);
patmandin@799
   441
#endif
slouken@281
   442
slouken@1895
   443
    /* Setup destination mfdb */
slouken@1895
   444
    VDI_dst_mfdb.fd_addr = NULL;
slouken@281
   445
slouken@1895
   446
    /* Determine the current screen size */
slouken@1895
   447
    this->info.current_w = VDI_w;
slouken@1895
   448
    this->info.current_h = VDI_h;
slouken@281
   449
slouken@1895
   450
    /* Determine the screen depth */
slouken@1895
   451
    /* we change this during the SDL_SetVideoMode implementation... */
slouken@1895
   452
    vformat->BitsPerPixel = VDI_bpp;
slouken@281
   453
slouken@1895
   454
    /* Set mouse cursor to arrow */
slouken@1895
   455
    graf_mouse(ARROW, NULL);
slouken@281
   456
slouken@1895
   457
    /* Init chunky to planar routine */
slouken@1895
   458
    SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
patmandin@736
   459
slouken@1895
   460
    /* Setup VDI fill functions */
slouken@1895
   461
    vsf_color(VDI_handle, 0);
slouken@1895
   462
    vsf_interior(VDI_handle, 1);
slouken@1895
   463
    vsf_perimeter(VDI_handle, 0);
patmandin@736
   464
slouken@1895
   465
    /* Menu bar save buffer */
slouken@1895
   466
    menubar_size = GEM_desk_w * GEM_desk_y * VDI_pixelsize;
slouken@1895
   467
    GEM_menubar = Atari_SysMalloc(menubar_size, MX_PREFTTRAM);
patmandin@1069
   468
slouken@1895
   469
    /* Fill video modes list */
slouken@1895
   470
    SDL_modelist[0] = SDL_malloc(sizeof(SDL_Rect));
slouken@1895
   471
    SDL_modelist[0]->x = 0;
slouken@1895
   472
    SDL_modelist[0]->y = 0;
slouken@1895
   473
    SDL_modelist[0]->w = VDI_w;
slouken@1895
   474
    SDL_modelist[0]->h = VDI_h;
patmandin@902
   475
slouken@1895
   476
    SDL_modelist[1] = NULL;
patmandin@902
   477
slouken@1361
   478
#if SDL_VIDEO_OPENGL
slouken@1895
   479
    SDL_AtariGL_InitPointers(this);
patmandin@736
   480
#endif
slouken@281
   481
patmandin@2106
   482
    this->info.wm_available = 1;
patmandin@2106
   483
slouken@1895
   484
    /* We're done! */
slouken@1895
   485
    return (0);
slouken@281
   486
}
slouken@281
   487
slouken@1895
   488
SDL_Rect **
slouken@1895
   489
GEM_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
slouken@281
   490
{
slouken@1895
   491
    if (format->BitsPerPixel != VDI_bpp) {
slouken@1895
   492
        return ((SDL_Rect **) NULL);
slouken@1895
   493
    }
patmandin@902
   494
slouken@1895
   495
    if (flags & SDL_FULLSCREEN) {
slouken@1895
   496
        return (SDL_modelist);
slouken@1895
   497
    }
patmandin@902
   498
slouken@1895
   499
    return ((SDL_Rect **) - 1);
slouken@281
   500
}
slouken@281
   501
slouken@1895
   502
static void
slouken@1895
   503
GEM_FreeBuffers(_THIS)
slouken@281
   504
{
slouken@1895
   505
    /* Release buffer */
slouken@1895
   506
    if (GEM_buffer2) {
slouken@1895
   507
        Mfree(GEM_buffer2);
slouken@1895
   508
        GEM_buffer2 = NULL;
slouken@1895
   509
    }
patmandin@736
   510
slouken@1895
   511
    if (GEM_buffer1) {
slouken@1895
   512
        Mfree(GEM_buffer1);
slouken@1895
   513
        GEM_buffer1 = NULL;
slouken@1895
   514
    }
slouken@281
   515
}
slouken@281
   516
slouken@1895
   517
static void
slouken@1895
   518
GEM_ClearRect(_THIS, short *rect)
patmandin@736
   519
{
slouken@1895
   520
    short oldrgb[3], rgb[3] = { 0, 0, 0 };
patmandin@736
   521
slouken@1895
   522
    vq_color(VDI_handle, vdi_index[0], 0, oldrgb);
slouken@1895
   523
    vs_color(VDI_handle, vdi_index[0], rgb);
patmandin@736
   524
slouken@1895
   525
    vsf_color(VDI_handle, 0);
slouken@1895
   526
    vsf_interior(VDI_handle, 1);
slouken@1895
   527
    vsf_perimeter(VDI_handle, 0);
slouken@1895
   528
    v_bar(VDI_handle, rect);
slouken@1895
   529
slouken@1895
   530
    vs_color(VDI_handle, vdi_index[0], oldrgb);
patmandin@736
   531
}
patmandin@736
   532
slouken@1895
   533
static void
slouken@1895
   534
GEM_ClearScreen(_THIS)
slouken@319
   535
{
slouken@1895
   536
    short pxy[4];
slouken@319
   537
slouken@1895
   538
    v_hide_c(VDI_handle);
slouken@319
   539
slouken@1895
   540
    pxy[0] = pxy[1] = 0;
slouken@1895
   541
    pxy[2] = VDI_w - 1;
slouken@1895
   542
    pxy[3] = VDI_h - 1;
slouken@1895
   543
    GEM_ClearRect(this, pxy);
slouken@319
   544
slouken@1895
   545
    v_show_c(VDI_handle, 1);
slouken@319
   546
}
slouken@319
   547
slouken@1895
   548
static void
slouken@1895
   549
GEM_SetNewPalette(_THIS, Uint16 newpal[256][3])
patmandin@1074
   550
{
slouken@1895
   551
    int i;
slouken@1895
   552
    short rgb[3];
patmandin@1074
   553
slouken@1895
   554
    if (VDI_oldnumcolors == 0)
slouken@1895
   555
        return;
patmandin@1074
   556
slouken@1895
   557
    for (i = 0; i < VDI_oldnumcolors; i++) {
slouken@1895
   558
        rgb[0] = newpal[i][0];
slouken@1895
   559
        rgb[1] = newpal[i][1];
slouken@1895
   560
        rgb[2] = newpal[i][2];
slouken@1895
   561
slouken@1895
   562
        vs_color(VDI_handle, i, rgb);
slouken@1895
   563
    }
patmandin@1074
   564
}
patmandin@1074
   565
slouken@1895
   566
static void
slouken@1895
   567
GEM_LockScreen(_THIS)
slouken@319
   568
{
slouken@1895
   569
    if (!GEM_locked) {
slouken@1895
   570
        /* Lock AES */
slouken@1895
   571
        wind_update(BEG_UPDATE);
slouken@1895
   572
        wind_update(BEG_MCTRL);
slouken@1895
   573
        /* Reserve memory space, used to be sure of compatibility */
slouken@1895
   574
        form_dial(FMD_START, 0, 0, 0, 0, 0, 0, VDI_w, VDI_h);
slouken@319
   575
slouken@1895
   576
        /* Save menu bar */
slouken@1895
   577
        if (GEM_menubar) {
slouken@1895
   578
            MFDB mfdb_src;
slouken@1895
   579
            short blitcoords[8];
patmandin@1069
   580
slouken@1895
   581
            mfdb_src.fd_addr = GEM_menubar;
slouken@1895
   582
            mfdb_src.fd_w = GEM_desk_w;
slouken@1895
   583
            mfdb_src.fd_h = GEM_desk_y;
slouken@1895
   584
            mfdb_src.fd_wdwidth = GEM_desk_w >> 4;
slouken@1895
   585
            mfdb_src.fd_nplanes = VDI_bpp;
slouken@1895
   586
            mfdb_src.fd_stand =
slouken@1895
   587
                mfdb_src.fd_r1 = mfdb_src.fd_r2 = mfdb_src.fd_r3 = 0;
patmandin@1069
   588
slouken@1895
   589
            blitcoords[0] = blitcoords[4] = 0;
slouken@1895
   590
            blitcoords[1] = blitcoords[5] = 0;
slouken@1895
   591
            blitcoords[2] = blitcoords[6] = GEM_desk_w - 1;
slouken@1895
   592
            blitcoords[3] = blitcoords[7] = GEM_desk_y - 1;
patmandin@1069
   593
slouken@1895
   594
            vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &VDI_dst_mfdb,
slouken@1895
   595
                      &mfdb_src);
slouken@1895
   596
        }
patmandin@1069
   597
slouken@1895
   598
        GEM_locked = SDL_TRUE;
slouken@1895
   599
    }
slouken@319
   600
}
slouken@319
   601
slouken@1895
   602
static void
slouken@1895
   603
GEM_UnlockScreen(_THIS)
slouken@319
   604
{
slouken@1895
   605
    if (GEM_locked) {
slouken@1895
   606
        /* Restore menu bar */
slouken@1895
   607
        if (GEM_menubar) {
slouken@1895
   608
            MFDB mfdb_src;
slouken@1895
   609
            short blitcoords[8];
slouken@1895
   610
slouken@1895
   611
            mfdb_src.fd_addr = GEM_menubar;
slouken@1895
   612
            mfdb_src.fd_w = GEM_desk_w;
slouken@1895
   613
            mfdb_src.fd_h = GEM_desk_y;
slouken@1895
   614
            mfdb_src.fd_wdwidth = GEM_desk_w >> 4;
slouken@1895
   615
            mfdb_src.fd_nplanes = VDI_bpp;
slouken@1895
   616
            mfdb_src.fd_stand =
slouken@1895
   617
                mfdb_src.fd_r1 = mfdb_src.fd_r2 = mfdb_src.fd_r3 = 0;
patmandin@1069
   618
slouken@1895
   619
            blitcoords[0] = blitcoords[4] = 0;
slouken@1895
   620
            blitcoords[1] = blitcoords[5] = 0;
slouken@1895
   621
            blitcoords[2] = blitcoords[6] = GEM_desk_w - 1;
slouken@1895
   622
            blitcoords[3] = blitcoords[7] = GEM_desk_y - 1;
slouken@1895
   623
slouken@1895
   624
            vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src,
slouken@1895
   625
                      &VDI_dst_mfdb);
slouken@1895
   626
        }
patmandin@1069
   627
slouken@1895
   628
        /* Restore screen memory, and send REDRAW to all apps */
slouken@1895
   629
        form_dial(FMD_FINISH, 0, 0, 0, 0, 0, 0, VDI_w, VDI_h);
slouken@1895
   630
        /* Unlock AES */
slouken@1895
   631
        wind_update(END_MCTRL);
slouken@1895
   632
        wind_update(END_UPDATE);
patmandin@1069
   633
slouken@1895
   634
        GEM_locked = SDL_FALSE;
slouken@1895
   635
    }
slouken@319
   636
}
slouken@319
   637
slouken@1895
   638
SDL_Surface *
slouken@1895
   639
GEM_SetVideoMode(_THIS, SDL_Surface * current,
slouken@1895
   640
                 int width, int height, int bpp, Uint32 flags)
slouken@281
   641
{
slouken@1895
   642
    Uint32 modeflags, screensize;
slouken@1895
   643
    SDL_bool use_shadow1, use_shadow2;
slouken@281
   644
slouken@1895
   645
    /* width must be multiple of 16, for vro_cpyfm() and c2p_convert() */
slouken@1895
   646
    if ((width & 15) != 0) {
slouken@1895
   647
        width = (width | 15) + 1;
slouken@1895
   648
    }
slouken@1895
   649
patmandin@2108
   650
        /*--- Verify if asked mode can be used ---*/
patmandin@2108
   651
    if (VDI_bpp != bpp) {
patmandin@2108
   652
        SDL_SetError("%d bpp mode not supported", bpp);
patmandin@2108
   653
        return(NULL);
patmandin@2108
   654
    }
patmandin@2108
   655
patmandin@2108
   656
    if (flags & SDL_FULLSCREEN) {
patmandin@2108
   657
        if ((VDI_w < width) || (VDI_h < height)) {
patmandin@2108
   658
            SDL_SetError("%dx%d mode is too large", width, height);
patmandin@2108
   659
            return (NULL);
patmandin@2108
   660
        }
slouken@1895
   661
    }
patmandin@799
   662
slouken@1895
   663
        /*--- Allocate the new pixel format for the screen ---*/
slouken@1895
   664
    if (!SDL_ReallocFormat
slouken@1895
   665
        (current, VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask,
slouken@1895
   666
         VDI_alphamask)) {
slouken@1895
   667
        SDL_SetError("Couldn't allocate new pixel format for requested mode");
slouken@1895
   668
        return (NULL);
slouken@1895
   669
    }
slouken@281
   670
slouken@1895
   671
    screensize = width * height * VDI_pixelsize;
patmandin@736
   672
patmandin@799
   673
#ifdef DEBUG_VIDEO_GEM
slouken@1895
   674
    printf("sdl:video:gem: setvideomode(): %dx%dx%d = %d\n", width, height,
slouken@1895
   675
           bpp, screensize);
patmandin@799
   676
#endif
patmandin@799
   677
slouken@1895
   678
        /*--- Allocate shadow buffers if needed, and conversion operations ---*/
slouken@1895
   679
    GEM_FreeBuffers(this);
patmandin@925
   680
slouken@1895
   681
    GEM_bufops = 0;
slouken@1895
   682
    use_shadow1 = use_shadow2 = SDL_FALSE;
slouken@1895
   683
    if (VDI_screen && (flags & SDL_FULLSCREEN)) {
slouken@1895
   684
        if (VDI_format == VDI_FORMAT_INTER) {
slouken@1895
   685
            use_shadow1 = SDL_TRUE;
slouken@1895
   686
            GEM_bufops = B2S_C2P_1TOS;
slouken@1895
   687
        }
slouken@1895
   688
    } else {
slouken@1895
   689
        use_shadow1 = SDL_TRUE;
slouken@1895
   690
        if (VDI_format == VDI_FORMAT_PACK) {
slouken@1895
   691
            GEM_bufops = B2S_VROCPYFM_1TOS;
slouken@1895
   692
        } else {
slouken@1895
   693
            use_shadow2 = SDL_TRUE;
slouken@1895
   694
            GEM_bufops = B2S_C2P_1TO2 | B2S_VROCPYFM_2TOS;
slouken@1895
   695
        }
slouken@1895
   696
    }
slouken@1895
   697
slouken@1895
   698
    if (use_shadow1) {
slouken@1895
   699
        GEM_buffer1 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
slouken@1895
   700
        if (GEM_buffer1 == NULL) {
slouken@1895
   701
            SDL_SetError("Can not allocate %d KB for frame buffer",
slouken@1895
   702
                         screensize >> 10);
slouken@1895
   703
            return NULL;
slouken@1895
   704
        }
slouken@1895
   705
        SDL_memset(GEM_buffer1, 0, screensize);
slouken@1895
   706
#ifdef DEBUG_VIDEO_GEM
slouken@1895
   707
        printf("sdl:video:gem: setvideomode(): allocated buffer 1\n");
slouken@1895
   708
#endif
slouken@1895
   709
    }
slouken@281
   710
slouken@1895
   711
    if (use_shadow2) {
slouken@1895
   712
        GEM_buffer2 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
slouken@1895
   713
        if (GEM_buffer2 == NULL) {
slouken@1895
   714
            SDL_SetError("Can not allocate %d KB for shadow buffer",
slouken@1895
   715
                         screensize >> 10);
slouken@1895
   716
            return NULL;
slouken@1895
   717
        }
slouken@1895
   718
        SDL_memset(GEM_buffer2, 0, screensize);
patmandin@736
   719
#ifdef DEBUG_VIDEO_GEM
slouken@1895
   720
        printf("sdl:video:gem: setvideomode(): allocated buffer 2\n");
patmandin@736
   721
#endif
slouken@1895
   722
    }
slouken@1895
   723
slouken@1895
   724
        /*--- Initialize screen ---*/
slouken@1895
   725
    modeflags = SDL_PREALLOC;
slouken@1895
   726
    if (VDI_bpp == 8) {
slouken@1895
   727
        modeflags |= SDL_HWPALETTE;
slouken@1895
   728
    }
slouken@1895
   729
slouken@1895
   730
    if (flags & SDL_FULLSCREEN) {
slouken@1895
   731
        GEM_LockScreen(this);
slouken@1895
   732
slouken@1895
   733
        GEM_ClearScreen(this);
patmandin@736
   734
slouken@1895
   735
        modeflags |= SDL_FULLSCREEN;
slouken@1895
   736
        if (VDI_screen && (VDI_format == VDI_FORMAT_PACK) && !use_shadow1) {
slouken@1895
   737
            modeflags |= SDL_HWSURFACE;
slouken@1895
   738
        } else {
slouken@1895
   739
            modeflags |= SDL_SWSURFACE;
slouken@1895
   740
        }
slouken@1895
   741
slouken@1895
   742
        GEM_fullscreen = SDL_TRUE;
slouken@1895
   743
    } else {
slouken@1895
   744
        int old_win_type;
slouken@1895
   745
        short x2, y2, w2, h2;
slouken@1895
   746
slouken@1895
   747
        GEM_UnlockScreen(this);
slouken@281
   748
slouken@1895
   749
        /* Set window gadgets */
slouken@1895
   750
        old_win_type = GEM_win_type;
slouken@1895
   751
        if (!(flags & SDL_NOFRAME)) {
slouken@1895
   752
            GEM_win_type = NAME | MOVER | CLOSER | SMALLER;
slouken@1895
   753
            if (flags & SDL_RESIZABLE) {
slouken@1895
   754
                GEM_win_type |= FULLER | SIZER;
slouken@1895
   755
                modeflags |= SDL_RESIZABLE;
slouken@1895
   756
            }
slouken@1895
   757
        } else {
slouken@1895
   758
            GEM_win_type = 0;
slouken@1895
   759
            modeflags |= SDL_NOFRAME;
slouken@1895
   760
        }
slouken@1895
   761
        modeflags |= SDL_SWSURFACE;
slouken@281
   762
slouken@1895
   763
        /* Recreate window ? only for different widget or non-created window */
slouken@1895
   764
        if ((old_win_type != GEM_win_type) || (GEM_handle < 0)) {
slouken@1895
   765
            /* Calculate window size */
slouken@1895
   766
            if (!wind_calc
slouken@1895
   767
                (WC_BORDER, GEM_win_type, 0, 0, width, height, &x2, &y2,
slouken@1895
   768
                 &w2, &h2)) {
slouken@1895
   769
                GEM_FreeBuffers(this);
slouken@1895
   770
                SDL_SetError("Can not calculate window attributes");
slouken@1895
   771
                return NULL;
slouken@1895
   772
            }
slouken@1895
   773
slouken@1895
   774
            /* Center window */
patmandin@2108
   775
            x2 = (GEM_desk_w - w2) >> 1;
patmandin@2108
   776
            y2 = (GEM_desk_h - h2) >> 1;
patmandin@2108
   777
            if (x2<0) {
patmandin@2108
   778
                x2 = 0;
patmandin@2108
   779
            }
patmandin@2108
   780
            if (y2<0) {
patmandin@2108
   781
                y2 = 0;
patmandin@2108
   782
            }
patmandin@2108
   783
            x2 += GEM_desk_x;
patmandin@2108
   784
            y2 += GEM_desk_y;
patmandin@926
   785
slouken@1895
   786
            /* Destroy existing window */
slouken@1895
   787
            if (GEM_handle >= 0) {
slouken@1895
   788
                wind_close(GEM_handle);
slouken@1895
   789
                wind_delete(GEM_handle);
slouken@1895
   790
            }
slouken@281
   791
slouken@1895
   792
            /* Create window */
slouken@1895
   793
            GEM_handle = wind_create(GEM_win_type, x2, y2, w2, h2);
slouken@1895
   794
            if (GEM_handle < 0) {
slouken@1895
   795
                GEM_FreeBuffers(this);
slouken@1895
   796
                SDL_SetError("Can not create window");
slouken@1895
   797
                return NULL;
slouken@1895
   798
            }
slouken@1895
   799
#ifdef DEBUG_VIDEO_GEM
slouken@1895
   800
            printf("sdl:video:gem: handle=%d\n", GEM_handle);
slouken@1895
   801
#endif
slouken@1895
   802
slouken@1895
   803
            /* Setup window name */
slouken@1895
   804
            wind_set(GEM_handle, WF_NAME,
slouken@1895
   805
                     (short) (((unsigned long) GEM_title_name) >> 16),
slouken@1895
   806
                     (short) (((unsigned long) GEM_title_name) & 0xffff),
slouken@1895
   807
                     0, 0);
slouken@1895
   808
            GEM_refresh_name = SDL_FALSE;
slouken@281
   809
slouken@1895
   810
            /* Open the window */
slouken@1895
   811
            wind_open(GEM_handle, x2, y2, w2, h2);
slouken@1895
   812
        } else {
patmandin@2107
   813
            /* Resize window to fit asked video mode */
patmandin@2107
   814
            wind_get (GEM_handle, WF_WORKXYWH, &x2,&y2,&w2,&h2);
patmandin@2107
   815
            if (wind_calc(WC_BORDER, GEM_win_type, x2,y2,width,height, &x2,&y2,&w2,&h2)) {
patmandin@2107
   816
                wind_set (GEM_handle, WF_CURRXYWH, x2,y2,w2,h2);
slouken@1895
   817
            }
slouken@1895
   818
        }
slouken@1895
   819
slouken@1895
   820
        GEM_fullscreen = SDL_FALSE;
slouken@1895
   821
    }
slouken@281
   822
slouken@1895
   823
    /* Set up the new mode framebuffer */
slouken@1895
   824
    current->w = width;
slouken@1895
   825
    current->h = height;
slouken@1895
   826
    if (use_shadow1) {
slouken@1895
   827
        current->pixels = GEM_buffer1;
slouken@1895
   828
        current->pitch = width * VDI_pixelsize;
slouken@1895
   829
    } else {
slouken@1895
   830
        current->pixels = VDI_screen;
slouken@1895
   831
        current->pitch = VDI_pitch;
slouken@1895
   832
    }
patmandin@923
   833
slouken@1895
   834
#if SDL_VIDEO_OPENGL
slouken@1895
   835
    if (flags & SDL_INTERNALOPENGL) {
slouken@1895
   836
        if (!SDL_AtariGL_Init(this, current)) {
slouken@1895
   837
            GEM_FreeBuffers(this);
slouken@1895
   838
            SDL_SetError("Can not create OpenGL context");
slouken@1895
   839
            return NULL;
slouken@1895
   840
        }
patmandin@925
   841
slouken@1895
   842
        modeflags |= SDL_INTERNALOPENGL;
slouken@1895
   843
    }
slouken@1895
   844
#endif
slouken@1895
   845
slouken@1895
   846
    current->flags = modeflags;
slouken@281
   847
patmandin@736
   848
#ifdef DEBUG_VIDEO_GEM
slouken@1895
   849
    printf("sdl:video:gem: surface: %dx%d\n", current->w, current->h);
patmandin@736
   850
#endif
patmandin@736
   851
slouken@1895
   852
    this->UpdateRects = GEM_UpdateRects;
slouken@1895
   853
    GEM_lock_redraw = SDL_FALSE;        /* Enable redraw */
slouken@281
   854
slouken@1895
   855
    /* We're done */
slouken@1895
   856
    return (current);
slouken@281
   857
}
slouken@281
   858
slouken@1895
   859
static int
slouken@1895
   860
GEM_AllocHWSurface(_THIS, SDL_Surface * surface)
slouken@281
   861
{
slouken@1895
   862
    return -1;
slouken@281
   863
}
patmandin@800
   864
slouken@1895
   865
static void
slouken@1895
   866
GEM_FreeHWSurface(_THIS, SDL_Surface * surface)
slouken@281
   867
{
slouken@1895
   868
    return;
slouken@281
   869
}
slouken@281
   870
slouken@1895
   871
static int
slouken@1895
   872
GEM_LockHWSurface(_THIS, SDL_Surface * surface)
slouken@281
   873
{
slouken@1895
   874
    return (0);
slouken@1895
   875
}
slouken@1895
   876
slouken@1895
   877
static void
slouken@1895
   878
GEM_UnlockHWSurface(_THIS, SDL_Surface * surface)
slouken@1895
   879
{
slouken@1895
   880
    return;
slouken@281
   881
}
slouken@281
   882
slouken@1895
   883
static void
slouken@1895
   884
GEM_UpdateRectsFullscreen(_THIS, int numrects, SDL_Rect * rects)
slouken@281
   885
{
slouken@1895
   886
    SDL_Surface *surface;
slouken@1895
   887
    int i, surf_width;
slouken@281
   888
slouken@1895
   889
    surface = this->screen;
slouken@1895
   890
    /* Need to be a multiple of 16 pixels */
slouken@1895
   891
    surf_width = surface->w;
slouken@1895
   892
    if ((surf_width & 15) != 0) {
slouken@1895
   893
        surf_width = (surf_width | 15) + 1;
slouken@1895
   894
    }
slouken@281
   895
slouken@1895
   896
    if (GEM_bufops & (B2S_C2P_1TO2 | B2S_C2P_1TOS)) {
slouken@1895
   897
        void *destscr;
slouken@1895
   898
        int destpitch;
patmandin@736
   899
slouken@1895
   900
        if (GEM_bufops & B2S_C2P_1TOS) {
slouken@1895
   901
            destscr = VDI_screen;
slouken@1895
   902
            destpitch = VDI_pitch;
slouken@1895
   903
        } else {
slouken@1895
   904
            destscr = GEM_buffer2;
slouken@1895
   905
            destpitch = surface->pitch;
slouken@1895
   906
        }
slouken@319
   907
slouken@1895
   908
        for (i = 0; i < numrects; i++) {
slouken@1895
   909
            void *source, *destination;
slouken@1895
   910
            int x1, x2;
slouken@319
   911
slouken@1895
   912
            x1 = rects[i].x & ~15;
slouken@1895
   913
            x2 = rects[i].x + rects[i].w;
slouken@1895
   914
            if (x2 & 15) {
slouken@1895
   915
                x2 = (x2 | 15) + 1;
slouken@1895
   916
            }
slouken@319
   917
slouken@1895
   918
            source = surface->pixels;
slouken@1895
   919
            source += surface->pitch * rects[i].y;
slouken@1895
   920
            source += x1;
slouken@1895
   921
slouken@1895
   922
            destination = destscr;
slouken@1895
   923
            destination += destpitch * rects[i].y;
slouken@1895
   924
            destination += x1;
patmandin@736
   925
slouken@1895
   926
            SDL_Atari_C2pConvert(source, destination,
slouken@1895
   927
                                 x2 - x1, rects[i].h,
slouken@1895
   928
                                 SDL_FALSE, surface->pitch, destpitch);
slouken@1895
   929
        }
slouken@1895
   930
    }
slouken@281
   931
slouken@1895
   932
    if (GEM_bufops & (B2S_VROCPYFM_1TOS | B2S_VROCPYFM_2TOS)) {
slouken@1895
   933
        MFDB mfdb_src;
slouken@1895
   934
        short blitcoords[8];
slouken@281
   935
slouken@1895
   936
        mfdb_src.fd_addr = surface->pixels;
slouken@1895
   937
        mfdb_src.fd_w = surf_width;
slouken@1895
   938
        mfdb_src.fd_h = surface->h;
slouken@1895
   939
        mfdb_src.fd_wdwidth = (surface->pitch / VDI_pixelsize) >> 4;
slouken@1895
   940
        mfdb_src.fd_nplanes = surface->format->BitsPerPixel;
slouken@1895
   941
        mfdb_src.fd_stand =
slouken@1895
   942
            mfdb_src.fd_r1 = mfdb_src.fd_r2 = mfdb_src.fd_r3 = 0;
slouken@1895
   943
        if (GEM_bufops & B2S_VROCPYFM_2TOS) {
slouken@1895
   944
            mfdb_src.fd_addr = GEM_buffer2;
slouken@1895
   945
        }
slouken@281
   946
slouken@1895
   947
        for (i = 0; i < numrects; ++i) {
slouken@1895
   948
            blitcoords[0] = blitcoords[4] = rects[i].x;
slouken@1895
   949
            blitcoords[1] = blitcoords[5] = rects[i].y;
slouken@1895
   950
            blitcoords[2] = blitcoords[6] = rects[i].x + rects[i].w - 1;
slouken@1895
   951
            blitcoords[3] = blitcoords[7] = rects[i].y + rects[i].h - 1;
patmandin@736
   952
slouken@1895
   953
            vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src,
slouken@1895
   954
                      &VDI_dst_mfdb);
slouken@1895
   955
        }
slouken@1895
   956
    }
slouken@281
   957
}
slouken@281
   958
slouken@1895
   959
static void
slouken@1895
   960
GEM_UpdateRectsWindowed(_THIS, int numrects, SDL_Rect * rects)
slouken@281
   961
{
slouken@1895
   962
    short pxy[4], wind_pxy[4];
slouken@1895
   963
    int i;
slouken@281
   964
slouken@1895
   965
    if (wind_get
slouken@1895
   966
        (GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2],
slouken@1895
   967
         &wind_pxy[3]) == 0) {
slouken@1895
   968
        return;
slouken@1895
   969
    }
slouken@281
   970
slouken@1895
   971
    for (i = 0; i < numrects; ++i) {
slouken@1895
   972
        pxy[0] = wind_pxy[0] + rects[i].x;
slouken@1895
   973
        pxy[1] = wind_pxy[1] + rects[i].y;
slouken@1895
   974
        pxy[2] = rects[i].w;
slouken@1895
   975
        pxy[3] = rects[i].h;
slouken@1895
   976
slouken@1895
   977
        GEM_wind_redraw(this, GEM_handle, pxy);
slouken@1895
   978
    }
slouken@281
   979
}
slouken@281
   980
slouken@1895
   981
static void
slouken@1895
   982
GEM_UpdateRects(_THIS, int numrects, SDL_Rect * rects)
slouken@281
   983
{
slouken@1895
   984
    SDL_Surface *surface;
patmandin@964
   985
slouken@1895
   986
    if (GEM_lock_redraw) {
slouken@1895
   987
        return;
slouken@1895
   988
    }
slouken@1895
   989
slouken@1895
   990
    surface = this->screen;
slouken@281
   991
slouken@1895
   992
    if (surface->flags & SDL_FULLSCREEN) {
slouken@1895
   993
        GEM_UpdateRectsFullscreen(this, numrects, rects);
slouken@1895
   994
    } else {
slouken@1895
   995
        GEM_UpdateRectsWindowed(this, numrects, rects);
slouken@1895
   996
    }
slouken@281
   997
}
slouken@281
   998
slouken@1895
   999
static int
slouken@1895
  1000
GEM_FlipHWSurfaceFullscreen(_THIS, SDL_Surface * surface)
slouken@281
  1001
{
slouken@1895
  1002
    int surf_width;
patmandin@799
  1003
slouken@1895
  1004
    /* Need to be a multiple of 16 pixels */
slouken@1895
  1005
    surf_width = surface->w;
slouken@1895
  1006
    if ((surf_width & 15) != 0) {
slouken@1895
  1007
        surf_width = (surf_width | 15) + 1;
slouken@1895
  1008
    }
patmandin@799
  1009
slouken@1895
  1010
    if (GEM_bufops & (B2S_C2P_1TO2 | B2S_C2P_1TOS)) {
slouken@1895
  1011
        void *destscr;
slouken@1895
  1012
        int destpitch;
slouken@319
  1013
slouken@1895
  1014
        if (GEM_bufops & B2S_C2P_1TOS) {
slouken@1895
  1015
            destscr = VDI_screen;
slouken@1895
  1016
            destpitch = VDI_pitch;
slouken@1895
  1017
        } else {
slouken@1895
  1018
            destscr = GEM_buffer2;
slouken@1895
  1019
            destpitch = surface->pitch;
slouken@1895
  1020
        }
slouken@281
  1021
slouken@1895
  1022
        SDL_Atari_C2pConvert(surface->pixels, destscr,
slouken@1895
  1023
                             surf_width, surface->h,
slouken@1895
  1024
                             SDL_FALSE, surface->pitch, destpitch);
slouken@1895
  1025
    }
patmandin@736
  1026
slouken@1895
  1027
    if (GEM_bufops & (B2S_VROCPYFM_1TOS | B2S_VROCPYFM_2TOS)) {
slouken@1895
  1028
        MFDB mfdb_src;
slouken@1895
  1029
        short blitcoords[8];
slouken@281
  1030
slouken@1895
  1031
        mfdb_src.fd_w = surf_width;
slouken@1895
  1032
        mfdb_src.fd_h = surface->h;
slouken@1895
  1033
        mfdb_src.fd_wdwidth = mfdb_src.fd_w >> 4;
slouken@1895
  1034
        mfdb_src.fd_nplanes = surface->format->BitsPerPixel;
slouken@1895
  1035
        mfdb_src.fd_stand =
slouken@1895
  1036
            mfdb_src.fd_r1 = mfdb_src.fd_r2 = mfdb_src.fd_r3 = 0;
slouken@1895
  1037
        if (GEM_bufops & B2S_VROCPYFM_1TOS) {
slouken@1895
  1038
            mfdb_src.fd_addr = surface->pixels;
slouken@1895
  1039
        } else {
slouken@1895
  1040
            mfdb_src.fd_addr = GEM_buffer2;
slouken@1895
  1041
        }
slouken@281
  1042
slouken@1895
  1043
        blitcoords[0] = blitcoords[4] = 0;
slouken@1895
  1044
        blitcoords[1] = blitcoords[5] = 0;
slouken@1895
  1045
        blitcoords[2] = blitcoords[6] = surface->w - 1;
slouken@1895
  1046
        blitcoords[3] = blitcoords[7] = surface->h - 1;
patmandin@736
  1047
slouken@1895
  1048
        vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
slouken@1895
  1049
    }
slouken@281
  1050
slouken@1895
  1051
    return (0);
slouken@281
  1052
}
slouken@281
  1053
slouken@1895
  1054
static int
slouken@1895
  1055
GEM_FlipHWSurfaceWindowed(_THIS, SDL_Surface * surface)
slouken@281
  1056
{
slouken@1895
  1057
    short pxy[8];
slouken@281
  1058
slouken@1895
  1059
    /* Update the whole window */
slouken@1895
  1060
    wind_get(GEM_handle, WF_WORKXYWH, &pxy[0], &pxy[1], &pxy[2], &pxy[3]);
slouken@281
  1061
slouken@1895
  1062
    GEM_wind_redraw(this, GEM_handle, pxy);
slouken@281
  1063
slouken@1895
  1064
    return (0);
slouken@281
  1065
}
slouken@281
  1066
slouken@1895
  1067
static int
slouken@1895
  1068
GEM_FlipHWSurface(_THIS, SDL_Surface * surface)
slouken@281
  1069
{
slouken@1895
  1070
    if (GEM_lock_redraw) {
slouken@1895
  1071
        return (0);
slouken@1895
  1072
    }
patmandin@964
  1073
slouken@1895
  1074
    if (surface->flags & SDL_FULLSCREEN) {
slouken@1895
  1075
        return GEM_FlipHWSurfaceFullscreen(this, surface);
slouken@1895
  1076
    } else {
slouken@1895
  1077
        return GEM_FlipHWSurfaceWindowed(this, surface);
slouken@1895
  1078
    }
slouken@281
  1079
}
slouken@281
  1080
slouken@1895
  1081
static int
slouken@1895
  1082
GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
slouken@281
  1083
{
slouken@1895
  1084
    int i;
slouken@1895
  1085
    SDL_Surface *surface;
slouken@281
  1086
patmandin@736
  1087
#ifdef DEBUG_VIDEO_GEM
slouken@1895
  1088
    printf("sdl:video:gem: setcolors()\n");
patmandin@736
  1089
#endif
patmandin@736
  1090
slouken@1895
  1091
    /* Do not change palette in True Colour */
slouken@1895
  1092
    surface = this->screen;
slouken@1895
  1093
    if (surface->format->BitsPerPixel > 8) {
slouken@1895
  1094
        return 1;
slouken@1895
  1095
    }
slouken@281
  1096
slouken@1895
  1097
    for (i = 0; i < ncolors; i++) {
slouken@1895
  1098
        int r, g, b;
slouken@1895
  1099
        short rgb[3];
slouken@281
  1100
slouken@1895
  1101
        r = colors[i].r;
slouken@1895
  1102
        g = colors[i].g;
slouken@1895
  1103
        b = colors[i].b;
slouken@281
  1104
slouken@1895
  1105
        rgb[0] = VDI_curpalette[i][0] = (1000 * r) / 255;
slouken@1895
  1106
        rgb[1] = VDI_curpalette[i][1] = (1000 * g) / 255;
slouken@1895
  1107
        rgb[2] = VDI_curpalette[i][2] = (1000 * b) / 255;
slouken@281
  1108
slouken@1895
  1109
        vs_color(VDI_handle, vdi_index[firstcolor + i], rgb);
slouken@1895
  1110
    }
slouken@281
  1111
slouken@1895
  1112
    return (1);
slouken@281
  1113
}
slouken@281
  1114
slouken@281
  1115
#if 0
slouken@1895
  1116
static int
slouken@1895
  1117
GEM_ToggleFullScreen(_THIS, int on)
slouken@281
  1118
{
slouken@1895
  1119
    if (on) {
slouken@1895
  1120
        GEM_LockScreen(this);
slouken@1895
  1121
    } else {
slouken@1895
  1122
        GEM_UnlockScreen(this);
slouken@1895
  1123
    }
slouken@281
  1124
slouken@1895
  1125
    return (1);
slouken@281
  1126
}
slouken@281
  1127
#endif
slouken@281
  1128
slouken@281
  1129
/* Note:  If we are terminated, this could be called in the middle of
slouken@281
  1130
   another SDL video routine -- notably UpdateRects.
slouken@281
  1131
*/
slouken@1895
  1132
void
slouken@1895
  1133
GEM_VideoQuit(_THIS)
slouken@281
  1134
{
slouken@1895
  1135
    SDL_AtariXbios_RestoreVectors();
slouken@1895
  1136
    if (GEM_usedevmouse) {
slouken@1895
  1137
        SDL_AtariDevMouse_Close();
slouken@1895
  1138
    }
slouken@305
  1139
slouken@1895
  1140
    GEM_FreeBuffers(this);
slouken@281
  1141
slouken@1361
  1142
#if SDL_VIDEO_OPENGL
slouken@1895
  1143
    if (gl_active) {
slouken@1895
  1144
        SDL_AtariGL_Quit(this, SDL_TRUE);
slouken@1895
  1145
    }
patmandin@992
  1146
#endif
patmandin@992
  1147
slouken@1895
  1148
    /* Destroy window */
slouken@1895
  1149
    if (GEM_handle >= 0) {
slouken@1895
  1150
        wind_close(GEM_handle);
slouken@1895
  1151
        wind_delete(GEM_handle);
slouken@1895
  1152
        GEM_handle = -1;
slouken@1895
  1153
    }
patmandin@925
  1154
slouken@1895
  1155
    GEM_UnlockScreen(this);
slouken@1895
  1156
    if (GEM_menubar) {
slouken@1895
  1157
        Mfree(GEM_menubar);
slouken@1895
  1158
        GEM_menubar = NULL;
slouken@1895
  1159
    }
slouken@281
  1160
slouken@1895
  1161
    appl_exit();
slouken@281
  1162
slouken@1895
  1163
    GEM_SetNewPalette(this, VDI_oldpalette);
slouken@281
  1164
slouken@1895
  1165
    /* Close VDI workstation */
slouken@1895
  1166
    if (VDI_handle) {
slouken@1895
  1167
        v_clsvwk(VDI_handle);
slouken@1895
  1168
    }
slouken@281
  1169
slouken@1895
  1170
    /* Free mode list */
slouken@1895
  1171
    if (SDL_modelist[0]) {
slouken@1895
  1172
        SDL_free(SDL_modelist[0]);
slouken@1895
  1173
        SDL_modelist[0] = NULL;
slouken@1895
  1174
    }
slouken@281
  1175
slouken@1895
  1176
    this->screen->pixels = NULL;
slouken@281
  1177
}
slouken@281
  1178
slouken@1895
  1179
void
slouken@1895
  1180
GEM_wind_redraw(_THIS, int winhandle, short *inside)
slouken@281
  1181
{
slouken@1895
  1182
    short todo[4];
slouken@281
  1183
slouken@1895
  1184
    /* Tell AES we are going to update */
slouken@1895
  1185
    wind_update(BEG_UPDATE);
slouken@281
  1186
slouken@1895
  1187
    v_hide_c(VDI_handle);
slouken@281
  1188
slouken@1895
  1189
    /* Browse the rectangle list to redraw */
slouken@1895
  1190
    if (wind_get
slouken@1895
  1191
        (winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2],
slouken@1895
  1192
         &todo[3]) != 0) {
slouken@281
  1193
slouken@1895
  1194
        while (todo[2] && todo[3]) {
slouken@281
  1195
slouken@1895
  1196
            if (rc_intersect((GRECT *) inside, (GRECT *) todo)) {
slouken@1895
  1197
                todo[2] += todo[0] - 1;
slouken@1895
  1198
                todo[3] += todo[1] - 1;
slouken@1895
  1199
                refresh_window(this, winhandle, todo);
slouken@1895
  1200
            }
patmandin@736
  1201
slouken@1895
  1202
            if (wind_get
slouken@1895
  1203
                (winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2],
slouken@1895
  1204
                 &todo[3]) == 0) {
slouken@1895
  1205
                break;
slouken@1895
  1206
            }
slouken@1895
  1207
        }
slouken@281
  1208
slouken@1895
  1209
    }
slouken@281
  1210
slouken@1895
  1211
    /* Update finished */
slouken@1895
  1212
    wind_update(END_UPDATE);
slouken@281
  1213
slouken@1895
  1214
    v_show_c(VDI_handle, 1);
slouken@281
  1215
}
slouken@281
  1216
slouken@1895
  1217
static void
slouken@1895
  1218
refresh_window(_THIS, int winhandle, short *rect)
slouken@281
  1219
{
slouken@1895
  1220
    MFDB mfdb_src;
slouken@1895
  1221
    short pxy[8], wind_pxy[8];
slouken@1895
  1222
    SDL_Surface *surface;
slouken@1895
  1223
    int iconified;
slouken@281
  1224
slouken@1895
  1225
    /* Is window iconified ? */
slouken@1895
  1226
    iconified = 0;
slouken@1895
  1227
/*	if (GEM_wfeatures & (1<<WF_ICONIFY))*/
slouken@1895
  1228
    {
slouken@1895
  1229
        if (wind_get
slouken@1895
  1230
            (winhandle, WF_ICONIFY, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2],
slouken@1895
  1231
             &wind_pxy[3]) != 0) {
slouken@1895
  1232
            iconified = wind_pxy[0];
slouken@1895
  1233
        }
slouken@1895
  1234
    }
patmandin@736
  1235
slouken@1895
  1236
    if (wind_get
slouken@1895
  1237
        (winhandle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2],
slouken@1895
  1238
         &wind_pxy[3]) == 0) {
slouken@1895
  1239
        return;
slouken@1895
  1240
    }
slouken@281
  1241
slouken@1895
  1242
    if (iconified && GEM_icon) {
slouken@1895
  1243
        short icon_rect[4], dst_rect[4];
slouken@1895
  1244
        short iconx, icony;
patmandin@736
  1245
slouken@1895
  1246
        surface = GEM_icon;
slouken@1895
  1247
slouken@1895
  1248
        GEM_ClearRect(this, rect);
patmandin@737
  1249
slouken@1895
  1250
        /* Calculate centered icon(x,y,w,h) relative to window */
slouken@1895
  1251
        iconx = (wind_pxy[2] - surface->w) >> 1;
slouken@1895
  1252
        icony = (wind_pxy[3] - surface->h) >> 1;
slouken@1895
  1253
slouken@1895
  1254
        icon_rect[0] = iconx;
slouken@1895
  1255
        icon_rect[1] = icony;
slouken@1895
  1256
        icon_rect[2] = surface->w;
slouken@1895
  1257
        icon_rect[3] = surface->h;
patmandin@736
  1258
slouken@1895
  1259
        /* Calculate redraw rectangle(x,y,w,h) relative to window */
slouken@1895
  1260
        dst_rect[0] = rect[0] - wind_pxy[0];
slouken@1895
  1261
        dst_rect[1] = rect[1] - wind_pxy[1];
slouken@1895
  1262
        dst_rect[2] = rect[2] - rect[0] + 1;
slouken@1895
  1263
        dst_rect[3] = rect[3] - rect[1] + 1;
patmandin@736
  1264
slouken@1895
  1265
        /* Does the icon rectangle must be redrawn ? */
slouken@1895
  1266
        if (!rc_intersect((GRECT *) icon_rect, (GRECT *) dst_rect)) {
slouken@1895
  1267
            return;
slouken@1895
  1268
        }
patmandin@799
  1269
#if DEBUG_VIDEO_GEM
slouken@1895
  1270
        printf("sdl:video:gem:  clip(0,0,%d,%d) to (%d,%d,%d,%d)\n",
slouken@1895
  1271
               surface->w - 1, surface->h - 1, dst_rect[0], dst_rect[1],
slouken@1895
  1272
               dst_rect[2], dst_rect[3]);
slouken@1895
  1273
        printf("sdl:video:gem:  icon(%d,%d,%d,%d)\n", icon_rect[0],
slouken@1895
  1274
               icon_rect[1], icon_rect[2], icon_rect[3]);
slouken@1895
  1275
        printf("sdl:video:gem: refresh_window(): draw icon\n");
patmandin@736
  1276
#endif
patmandin@736
  1277
slouken@1895
  1278
        /* Calculate icon(x1,y1,x2,y2) relative to screen */
slouken@1895
  1279
        icon_rect[0] += wind_pxy[0];
slouken@1895
  1280
        icon_rect[1] += wind_pxy[1];
slouken@1895
  1281
        icon_rect[2] += icon_rect[0] - 1;
slouken@1895
  1282
        icon_rect[3] += icon_rect[1] - 1;
slouken@281
  1283
slouken@1895
  1284
        /* Calculate intersection rectangle to redraw */
slouken@1895
  1285
        pxy[4] = pxy[0] = MAX(icon_rect[0], rect[0]);
slouken@1895
  1286
        pxy[5] = pxy[1] = MAX(icon_rect[1], rect[1]);
slouken@1895
  1287
        pxy[6] = pxy[2] = MIN(icon_rect[2], rect[2]);
slouken@1895
  1288
        pxy[7] = pxy[3] = MIN(icon_rect[3], rect[3]);
patmandin@736
  1289
slouken@1895
  1290
        /* Calculate icon source image pos relative to window */
slouken@1895
  1291
        pxy[0] -= wind_pxy[0] + iconx;
slouken@1895
  1292
        pxy[1] -= wind_pxy[1] + icony;
slouken@1895
  1293
        pxy[2] -= wind_pxy[0] + iconx;
slouken@1895
  1294
        pxy[3] -= wind_pxy[1] + icony;
patmandin@736
  1295
slouken@1895
  1296
    } else {
slouken@1895
  1297
        surface = this->screen;
patmandin@736
  1298
patmandin@799
  1299
#if DEBUG_VIDEO_GEM
slouken@1895
  1300
        printf("sdl:video:gem: refresh_window(): draw frame buffer\n");
patmandin@736
  1301
#endif
patmandin@736
  1302
slouken@1895
  1303
        /* Redraw all window content */
slouken@1895
  1304
        pxy[0] = rect[0] - wind_pxy[0];
slouken@1895
  1305
        pxy[1] = rect[1] - wind_pxy[1];
slouken@1895
  1306
        pxy[2] = rect[2] - wind_pxy[0];
slouken@1895
  1307
        pxy[3] = rect[3] - wind_pxy[1];
patmandin@736
  1308
slouken@1895
  1309
        pxy[4] = rect[0];
slouken@1895
  1310
        pxy[5] = rect[1];
slouken@1895
  1311
        pxy[6] = rect[2];
slouken@1895
  1312
        pxy[7] = rect[3];
slouken@1895
  1313
    }
slouken@281
  1314
slouken@1895
  1315
    if (GEM_bufops & B2S_C2P_1TO2) {
slouken@1895
  1316
        void *src, *dest;
slouken@1895
  1317
        int x1, x2;
patmandin@736
  1318
slouken@1895
  1319
        x1 = (rect[0] - wind_pxy[0]) & ~15;
slouken@1895
  1320
        x2 = rect[2] - wind_pxy[0];
slouken@1895
  1321
        if (x2 & 15) {
slouken@1895
  1322
            x2 = (x2 | 15) + 1;
slouken@1895
  1323
        }
patmandin@736
  1324
slouken@1895
  1325
        src = surface->pixels;
slouken@1895
  1326
        src += surface->pitch * (rect[1] - wind_pxy[1]);
slouken@1895
  1327
        src += x1;
slouken@281
  1328
slouken@1895
  1329
        dest = GEM_buffer2;
slouken@1895
  1330
        dest += surface->pitch * (rect[1] - wind_pxy[1]);
slouken@1895
  1331
        dest += x1;
patmandin@736
  1332
slouken@1895
  1333
        SDL_Atari_C2pConvert(src, dest,
slouken@1895
  1334
                             x2 - x1, rect[3] - rect[1] + 1,
slouken@1895
  1335
                             SDL_FALSE, surface->pitch, surface->pitch);
slouken@1895
  1336
    }
slouken@1895
  1337
slouken@1895
  1338
    mfdb_src.fd_addr = surface->pixels;
slouken@1895
  1339
    {
slouken@1895
  1340
        int width;
patmandin@799
  1341
slouken@1895
  1342
        /* Need to be a multiple of 16 pixels */
slouken@1895
  1343
        width = surface->w;
slouken@1895
  1344
        if ((width & 15) != 0) {
slouken@1895
  1345
            width = (width | 15) + 1;
slouken@1895
  1346
        }
slouken@1895
  1347
        mfdb_src.fd_w = width;
slouken@1895
  1348
    }
slouken@1895
  1349
    mfdb_src.fd_h = surface->h;
slouken@1895
  1350
    mfdb_src.fd_nplanes = surface->format->BitsPerPixel;
slouken@1895
  1351
    mfdb_src.fd_wdwidth = mfdb_src.fd_w >> 4;
slouken@1895
  1352
    mfdb_src.fd_stand = mfdb_src.fd_r1 = mfdb_src.fd_r2 = mfdb_src.fd_r3 = 0;
patmandin@736
  1353
slouken@1895
  1354
    if (GEM_bufops & B2S_VROCPYFM_2TOS) {
slouken@1895
  1355
        mfdb_src.fd_addr = GEM_buffer2;
slouken@1895
  1356
    }
patmandin@799
  1357
#if DEBUG_VIDEO_GEM
slouken@1895
  1358
    printf("sdl:video:gem: redraw %dx%d: (%d,%d,%d,%d) to (%d,%d,%d,%d)\n",
slouken@1895
  1359
           surface->w, surface->h,
slouken@1895
  1360
           pxy[0], pxy[1], pxy[2], pxy[3], pxy[4], pxy[5], pxy[6], pxy[7]);
patmandin@736
  1361
#endif
slouken@281
  1362
slouken@1895
  1363
    vro_cpyfm(VDI_handle, S_ONLY, pxy, &mfdb_src, &VDI_dst_mfdb);
slouken@281
  1364
}
patmandin@984
  1365
slouken@1361
  1366
#if SDL_VIDEO_OPENGL
patmandin@984
  1367
slouken@1895
  1368
static void
slouken@1895
  1369
GEM_GL_SwapBuffers(_THIS)
patmandin@984
  1370
{
slouken@1895
  1371
    SDL_AtariGL_SwapBuffers(this);
slouken@1895
  1372
    GEM_FlipHWSurface(this, this->screen);
patmandin@984
  1373
}
patmandin@984
  1374
patmandin@984
  1375
#endif
slouken@1895
  1376
/* vi: set ts=4 sw=4 expandtab: */