src/video/gem/SDL_gemvideo.c
author Patrice Mandin
Sat, 26 May 2007 19:46:04 +0000
changeset 2106 2714a8976e37
parent 2043 adf732f1f016
child 2107 757dfb38f574
permissions -rw-r--r--
GEM has a window manager, of course
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
    int maxwidth, maxheight;
slouken@1895
   643
    Uint32 modeflags, screensize;
slouken@1895
   644
    SDL_bool use_shadow1, use_shadow2;
slouken@281
   645
slouken@1895
   646
        /*--- Verify if asked mode can be used ---*/
slouken@1895
   647
    if (flags & SDL_FULLSCREEN) {
slouken@1895
   648
        maxwidth = VDI_w;
slouken@1895
   649
        maxheight = VDI_h;
slouken@1895
   650
    } else {
slouken@1895
   651
        /* Windowed mode */
slouken@1895
   652
        maxwidth = GEM_desk_w;
slouken@1895
   653
        maxheight = GEM_desk_h;
slouken@1895
   654
    }
slouken@281
   655
slouken@1895
   656
    /* width must be multiple of 16, for vro_cpyfm() and c2p_convert() */
slouken@1895
   657
    if ((width & 15) != 0) {
slouken@1895
   658
        width = (width | 15) + 1;
slouken@1895
   659
    }
slouken@1895
   660
slouken@1895
   661
    if ((maxwidth < width) || (maxheight < height) || (VDI_bpp != bpp)) {
slouken@1895
   662
        SDL_SetError("Couldn't find requested mode in list");
slouken@1895
   663
        return (NULL);
slouken@1895
   664
    }
patmandin@799
   665
slouken@1895
   666
        /*--- Allocate the new pixel format for the screen ---*/
slouken@1895
   667
    if (!SDL_ReallocFormat
slouken@1895
   668
        (current, VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask,
slouken@1895
   669
         VDI_alphamask)) {
slouken@1895
   670
        SDL_SetError("Couldn't allocate new pixel format for requested mode");
slouken@1895
   671
        return (NULL);
slouken@1895
   672
    }
slouken@281
   673
slouken@1895
   674
    screensize = width * height * VDI_pixelsize;
patmandin@736
   675
patmandin@799
   676
#ifdef DEBUG_VIDEO_GEM
slouken@1895
   677
    printf("sdl:video:gem: setvideomode(): %dx%dx%d = %d\n", width, height,
slouken@1895
   678
           bpp, screensize);
patmandin@799
   679
#endif
patmandin@799
   680
slouken@1895
   681
        /*--- Allocate shadow buffers if needed, and conversion operations ---*/
slouken@1895
   682
    GEM_FreeBuffers(this);
patmandin@925
   683
slouken@1895
   684
    GEM_bufops = 0;
slouken@1895
   685
    use_shadow1 = use_shadow2 = SDL_FALSE;
slouken@1895
   686
    if (VDI_screen && (flags & SDL_FULLSCREEN)) {
slouken@1895
   687
        if (VDI_format == VDI_FORMAT_INTER) {
slouken@1895
   688
            use_shadow1 = SDL_TRUE;
slouken@1895
   689
            GEM_bufops = B2S_C2P_1TOS;
slouken@1895
   690
        }
slouken@1895
   691
    } else {
slouken@1895
   692
        use_shadow1 = SDL_TRUE;
slouken@1895
   693
        if (VDI_format == VDI_FORMAT_PACK) {
slouken@1895
   694
            GEM_bufops = B2S_VROCPYFM_1TOS;
slouken@1895
   695
        } else {
slouken@1895
   696
            use_shadow2 = SDL_TRUE;
slouken@1895
   697
            GEM_bufops = B2S_C2P_1TO2 | B2S_VROCPYFM_2TOS;
slouken@1895
   698
        }
slouken@1895
   699
    }
slouken@1895
   700
slouken@1895
   701
    if (use_shadow1) {
slouken@1895
   702
        GEM_buffer1 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
slouken@1895
   703
        if (GEM_buffer1 == NULL) {
slouken@1895
   704
            SDL_SetError("Can not allocate %d KB for frame buffer",
slouken@1895
   705
                         screensize >> 10);
slouken@1895
   706
            return NULL;
slouken@1895
   707
        }
slouken@1895
   708
        SDL_memset(GEM_buffer1, 0, screensize);
slouken@1895
   709
#ifdef DEBUG_VIDEO_GEM
slouken@1895
   710
        printf("sdl:video:gem: setvideomode(): allocated buffer 1\n");
slouken@1895
   711
#endif
slouken@1895
   712
    }
slouken@281
   713
slouken@1895
   714
    if (use_shadow2) {
slouken@1895
   715
        GEM_buffer2 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
slouken@1895
   716
        if (GEM_buffer2 == NULL) {
slouken@1895
   717
            SDL_SetError("Can not allocate %d KB for shadow buffer",
slouken@1895
   718
                         screensize >> 10);
slouken@1895
   719
            return NULL;
slouken@1895
   720
        }
slouken@1895
   721
        SDL_memset(GEM_buffer2, 0, screensize);
patmandin@736
   722
#ifdef DEBUG_VIDEO_GEM
slouken@1895
   723
        printf("sdl:video:gem: setvideomode(): allocated buffer 2\n");
patmandin@736
   724
#endif
slouken@1895
   725
    }
slouken@1895
   726
slouken@1895
   727
        /*--- Initialize screen ---*/
slouken@1895
   728
    modeflags = SDL_PREALLOC;
slouken@1895
   729
    if (VDI_bpp == 8) {
slouken@1895
   730
        modeflags |= SDL_HWPALETTE;
slouken@1895
   731
    }
slouken@1895
   732
slouken@1895
   733
    if (flags & SDL_FULLSCREEN) {
slouken@1895
   734
        GEM_LockScreen(this);
slouken@1895
   735
slouken@1895
   736
        GEM_ClearScreen(this);
patmandin@736
   737
slouken@1895
   738
        modeflags |= SDL_FULLSCREEN;
slouken@1895
   739
        if (VDI_screen && (VDI_format == VDI_FORMAT_PACK) && !use_shadow1) {
slouken@1895
   740
            modeflags |= SDL_HWSURFACE;
slouken@1895
   741
        } else {
slouken@1895
   742
            modeflags |= SDL_SWSURFACE;
slouken@1895
   743
        }
slouken@1895
   744
slouken@1895
   745
        GEM_fullscreen = SDL_TRUE;
slouken@1895
   746
    } else {
slouken@1895
   747
        int old_win_type;
slouken@1895
   748
        short x2, y2, w2, h2;
slouken@1895
   749
slouken@1895
   750
        GEM_UnlockScreen(this);
slouken@281
   751
slouken@1895
   752
        /* Set window gadgets */
slouken@1895
   753
        old_win_type = GEM_win_type;
slouken@1895
   754
        if (!(flags & SDL_NOFRAME)) {
slouken@1895
   755
            GEM_win_type = NAME | MOVER | CLOSER | SMALLER;
slouken@1895
   756
            if (flags & SDL_RESIZABLE) {
slouken@1895
   757
                GEM_win_type |= FULLER | SIZER;
slouken@1895
   758
                modeflags |= SDL_RESIZABLE;
slouken@1895
   759
            }
slouken@1895
   760
        } else {
slouken@1895
   761
            GEM_win_type = 0;
slouken@1895
   762
            modeflags |= SDL_NOFRAME;
slouken@1895
   763
        }
slouken@1895
   764
        modeflags |= SDL_SWSURFACE;
slouken@281
   765
slouken@1895
   766
        /* Recreate window ? only for different widget or non-created window */
slouken@1895
   767
        if ((old_win_type != GEM_win_type) || (GEM_handle < 0)) {
slouken@1895
   768
            /* Calculate window size */
slouken@1895
   769
            if (!wind_calc
slouken@1895
   770
                (WC_BORDER, GEM_win_type, 0, 0, width, height, &x2, &y2,
slouken@1895
   771
                 &w2, &h2)) {
slouken@1895
   772
                GEM_FreeBuffers(this);
slouken@1895
   773
                SDL_SetError("Can not calculate window attributes");
slouken@1895
   774
                return NULL;
slouken@1895
   775
            }
slouken@1895
   776
slouken@1895
   777
            /* Center window */
slouken@1895
   778
            x2 = GEM_desk_x + ((GEM_desk_w - w2) >> 1);
slouken@1895
   779
            y2 = GEM_desk_y + ((GEM_desk_h - h2) >> 1);
patmandin@926
   780
slouken@1895
   781
            /* Destroy existing window */
slouken@1895
   782
            if (GEM_handle >= 0) {
slouken@1895
   783
                wind_close(GEM_handle);
slouken@1895
   784
                wind_delete(GEM_handle);
slouken@1895
   785
            }
slouken@281
   786
slouken@1895
   787
            /* Create window */
slouken@1895
   788
            GEM_handle = wind_create(GEM_win_type, x2, y2, w2, h2);
slouken@1895
   789
            if (GEM_handle < 0) {
slouken@1895
   790
                GEM_FreeBuffers(this);
slouken@1895
   791
                SDL_SetError("Can not create window");
slouken@1895
   792
                return NULL;
slouken@1895
   793
            }
slouken@1895
   794
#ifdef DEBUG_VIDEO_GEM
slouken@1895
   795
            printf("sdl:video:gem: handle=%d\n", GEM_handle);
slouken@1895
   796
#endif
slouken@1895
   797
slouken@1895
   798
            /* Setup window name */
slouken@1895
   799
            wind_set(GEM_handle, WF_NAME,
slouken@1895
   800
                     (short) (((unsigned long) GEM_title_name) >> 16),
slouken@1895
   801
                     (short) (((unsigned long) GEM_title_name) & 0xffff),
slouken@1895
   802
                     0, 0);
slouken@1895
   803
            GEM_refresh_name = SDL_FALSE;
slouken@281
   804
slouken@1895
   805
            /* Open the window */
slouken@1895
   806
            wind_open(GEM_handle, x2, y2, w2, h2);
slouken@1895
   807
        } else {
slouken@1895
   808
            /* Resize window if needed, to fit asked video mode */
slouken@1895
   809
            if (modeflags & SDL_RESIZABLE) {
slouken@1895
   810
                wind_get(GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
slouken@1895
   811
                if ((w2 & 15) != 0) {
slouken@1895
   812
                    w2 = (w2 | 15) + 1;
slouken@1895
   813
                }
slouken@1895
   814
                if ((w2 != width) || (h2 != height)) {
slouken@1895
   815
                    if (wind_calc
slouken@1895
   816
                        (WC_BORDER, GEM_win_type, x2, y2, width,
slouken@1895
   817
                         height, &x2, &y2, &w2, &h2)) {
slouken@1895
   818
                        wind_set(GEM_handle, WF_CURRXYWH, x2, y2, w2, h2);
slouken@1895
   819
                    }
slouken@1895
   820
                }
slouken@1895
   821
            }
slouken@1895
   822
        }
slouken@1895
   823
slouken@1895
   824
        GEM_fullscreen = SDL_FALSE;
slouken@1895
   825
    }
slouken@281
   826
slouken@1895
   827
    /* Set up the new mode framebuffer */
slouken@1895
   828
    current->w = width;
slouken@1895
   829
    current->h = height;
slouken@1895
   830
    if (use_shadow1) {
slouken@1895
   831
        current->pixels = GEM_buffer1;
slouken@1895
   832
        current->pitch = width * VDI_pixelsize;
slouken@1895
   833
    } else {
slouken@1895
   834
        current->pixels = VDI_screen;
slouken@1895
   835
        current->pitch = VDI_pitch;
slouken@1895
   836
    }
patmandin@923
   837
slouken@1895
   838
#if SDL_VIDEO_OPENGL
slouken@1895
   839
    if (flags & SDL_INTERNALOPENGL) {
slouken@1895
   840
        if (!SDL_AtariGL_Init(this, current)) {
slouken@1895
   841
            GEM_FreeBuffers(this);
slouken@1895
   842
            SDL_SetError("Can not create OpenGL context");
slouken@1895
   843
            return NULL;
slouken@1895
   844
        }
patmandin@925
   845
slouken@1895
   846
        modeflags |= SDL_INTERNALOPENGL;
slouken@1895
   847
    }
slouken@1895
   848
#endif
slouken@1895
   849
slouken@1895
   850
    current->flags = modeflags;
slouken@281
   851
patmandin@736
   852
#ifdef DEBUG_VIDEO_GEM
slouken@1895
   853
    printf("sdl:video:gem: surface: %dx%d\n", current->w, current->h);
patmandin@736
   854
#endif
patmandin@736
   855
slouken@1895
   856
    this->UpdateRects = GEM_UpdateRects;
slouken@1895
   857
    GEM_lock_redraw = SDL_FALSE;        /* Enable redraw */
slouken@281
   858
slouken@1895
   859
    /* We're done */
slouken@1895
   860
    return (current);
slouken@281
   861
}
slouken@281
   862
slouken@1895
   863
static int
slouken@1895
   864
GEM_AllocHWSurface(_THIS, SDL_Surface * surface)
slouken@281
   865
{
slouken@1895
   866
    return -1;
slouken@281
   867
}
patmandin@800
   868
slouken@1895
   869
static void
slouken@1895
   870
GEM_FreeHWSurface(_THIS, SDL_Surface * surface)
slouken@281
   871
{
slouken@1895
   872
    return;
slouken@281
   873
}
slouken@281
   874
slouken@1895
   875
static int
slouken@1895
   876
GEM_LockHWSurface(_THIS, SDL_Surface * surface)
slouken@281
   877
{
slouken@1895
   878
    return (0);
slouken@1895
   879
}
slouken@1895
   880
slouken@1895
   881
static void
slouken@1895
   882
GEM_UnlockHWSurface(_THIS, SDL_Surface * surface)
slouken@1895
   883
{
slouken@1895
   884
    return;
slouken@281
   885
}
slouken@281
   886
slouken@1895
   887
static void
slouken@1895
   888
GEM_UpdateRectsFullscreen(_THIS, int numrects, SDL_Rect * rects)
slouken@281
   889
{
slouken@1895
   890
    SDL_Surface *surface;
slouken@1895
   891
    int i, surf_width;
slouken@281
   892
slouken@1895
   893
    surface = this->screen;
slouken@1895
   894
    /* Need to be a multiple of 16 pixels */
slouken@1895
   895
    surf_width = surface->w;
slouken@1895
   896
    if ((surf_width & 15) != 0) {
slouken@1895
   897
        surf_width = (surf_width | 15) + 1;
slouken@1895
   898
    }
slouken@281
   899
slouken@1895
   900
    if (GEM_bufops & (B2S_C2P_1TO2 | B2S_C2P_1TOS)) {
slouken@1895
   901
        void *destscr;
slouken@1895
   902
        int destpitch;
patmandin@736
   903
slouken@1895
   904
        if (GEM_bufops & B2S_C2P_1TOS) {
slouken@1895
   905
            destscr = VDI_screen;
slouken@1895
   906
            destpitch = VDI_pitch;
slouken@1895
   907
        } else {
slouken@1895
   908
            destscr = GEM_buffer2;
slouken@1895
   909
            destpitch = surface->pitch;
slouken@1895
   910
        }
slouken@319
   911
slouken@1895
   912
        for (i = 0; i < numrects; i++) {
slouken@1895
   913
            void *source, *destination;
slouken@1895
   914
            int x1, x2;
slouken@319
   915
slouken@1895
   916
            x1 = rects[i].x & ~15;
slouken@1895
   917
            x2 = rects[i].x + rects[i].w;
slouken@1895
   918
            if (x2 & 15) {
slouken@1895
   919
                x2 = (x2 | 15) + 1;
slouken@1895
   920
            }
slouken@319
   921
slouken@1895
   922
            source = surface->pixels;
slouken@1895
   923
            source += surface->pitch * rects[i].y;
slouken@1895
   924
            source += x1;
slouken@1895
   925
slouken@1895
   926
            destination = destscr;
slouken@1895
   927
            destination += destpitch * rects[i].y;
slouken@1895
   928
            destination += x1;
patmandin@736
   929
slouken@1895
   930
            SDL_Atari_C2pConvert(source, destination,
slouken@1895
   931
                                 x2 - x1, rects[i].h,
slouken@1895
   932
                                 SDL_FALSE, surface->pitch, destpitch);
slouken@1895
   933
        }
slouken@1895
   934
    }
slouken@281
   935
slouken@1895
   936
    if (GEM_bufops & (B2S_VROCPYFM_1TOS | B2S_VROCPYFM_2TOS)) {
slouken@1895
   937
        MFDB mfdb_src;
slouken@1895
   938
        short blitcoords[8];
slouken@281
   939
slouken@1895
   940
        mfdb_src.fd_addr = surface->pixels;
slouken@1895
   941
        mfdb_src.fd_w = surf_width;
slouken@1895
   942
        mfdb_src.fd_h = surface->h;
slouken@1895
   943
        mfdb_src.fd_wdwidth = (surface->pitch / VDI_pixelsize) >> 4;
slouken@1895
   944
        mfdb_src.fd_nplanes = surface->format->BitsPerPixel;
slouken@1895
   945
        mfdb_src.fd_stand =
slouken@1895
   946
            mfdb_src.fd_r1 = mfdb_src.fd_r2 = mfdb_src.fd_r3 = 0;
slouken@1895
   947
        if (GEM_bufops & B2S_VROCPYFM_2TOS) {
slouken@1895
   948
            mfdb_src.fd_addr = GEM_buffer2;
slouken@1895
   949
        }
slouken@281
   950
slouken@1895
   951
        for (i = 0; i < numrects; ++i) {
slouken@1895
   952
            blitcoords[0] = blitcoords[4] = rects[i].x;
slouken@1895
   953
            blitcoords[1] = blitcoords[5] = rects[i].y;
slouken@1895
   954
            blitcoords[2] = blitcoords[6] = rects[i].x + rects[i].w - 1;
slouken@1895
   955
            blitcoords[3] = blitcoords[7] = rects[i].y + rects[i].h - 1;
patmandin@736
   956
slouken@1895
   957
            vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src,
slouken@1895
   958
                      &VDI_dst_mfdb);
slouken@1895
   959
        }
slouken@1895
   960
    }
slouken@281
   961
}
slouken@281
   962
slouken@1895
   963
static void
slouken@1895
   964
GEM_UpdateRectsWindowed(_THIS, int numrects, SDL_Rect * rects)
slouken@281
   965
{
slouken@1895
   966
    short pxy[4], wind_pxy[4];
slouken@1895
   967
    int i;
slouken@281
   968
slouken@1895
   969
    if (wind_get
slouken@1895
   970
        (GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2],
slouken@1895
   971
         &wind_pxy[3]) == 0) {
slouken@1895
   972
        return;
slouken@1895
   973
    }
slouken@281
   974
slouken@1895
   975
    for (i = 0; i < numrects; ++i) {
slouken@1895
   976
        pxy[0] = wind_pxy[0] + rects[i].x;
slouken@1895
   977
        pxy[1] = wind_pxy[1] + rects[i].y;
slouken@1895
   978
        pxy[2] = rects[i].w;
slouken@1895
   979
        pxy[3] = rects[i].h;
slouken@1895
   980
slouken@1895
   981
        GEM_wind_redraw(this, GEM_handle, pxy);
slouken@1895
   982
    }
slouken@281
   983
}
slouken@281
   984
slouken@1895
   985
static void
slouken@1895
   986
GEM_UpdateRects(_THIS, int numrects, SDL_Rect * rects)
slouken@281
   987
{
slouken@1895
   988
    SDL_Surface *surface;
patmandin@964
   989
slouken@1895
   990
    if (GEM_lock_redraw) {
slouken@1895
   991
        return;
slouken@1895
   992
    }
slouken@1895
   993
slouken@1895
   994
    surface = this->screen;
slouken@281
   995
slouken@1895
   996
    if (surface->flags & SDL_FULLSCREEN) {
slouken@1895
   997
        GEM_UpdateRectsFullscreen(this, numrects, rects);
slouken@1895
   998
    } else {
slouken@1895
   999
        GEM_UpdateRectsWindowed(this, numrects, rects);
slouken@1895
  1000
    }
slouken@281
  1001
}
slouken@281
  1002
slouken@1895
  1003
static int
slouken@1895
  1004
GEM_FlipHWSurfaceFullscreen(_THIS, SDL_Surface * surface)
slouken@281
  1005
{
slouken@1895
  1006
    int surf_width;
patmandin@799
  1007
slouken@1895
  1008
    /* Need to be a multiple of 16 pixels */
slouken@1895
  1009
    surf_width = surface->w;
slouken@1895
  1010
    if ((surf_width & 15) != 0) {
slouken@1895
  1011
        surf_width = (surf_width | 15) + 1;
slouken@1895
  1012
    }
patmandin@799
  1013
slouken@1895
  1014
    if (GEM_bufops & (B2S_C2P_1TO2 | B2S_C2P_1TOS)) {
slouken@1895
  1015
        void *destscr;
slouken@1895
  1016
        int destpitch;
slouken@319
  1017
slouken@1895
  1018
        if (GEM_bufops & B2S_C2P_1TOS) {
slouken@1895
  1019
            destscr = VDI_screen;
slouken@1895
  1020
            destpitch = VDI_pitch;
slouken@1895
  1021
        } else {
slouken@1895
  1022
            destscr = GEM_buffer2;
slouken@1895
  1023
            destpitch = surface->pitch;
slouken@1895
  1024
        }
slouken@281
  1025
slouken@1895
  1026
        SDL_Atari_C2pConvert(surface->pixels, destscr,
slouken@1895
  1027
                             surf_width, surface->h,
slouken@1895
  1028
                             SDL_FALSE, surface->pitch, destpitch);
slouken@1895
  1029
    }
patmandin@736
  1030
slouken@1895
  1031
    if (GEM_bufops & (B2S_VROCPYFM_1TOS | B2S_VROCPYFM_2TOS)) {
slouken@1895
  1032
        MFDB mfdb_src;
slouken@1895
  1033
        short blitcoords[8];
slouken@281
  1034
slouken@1895
  1035
        mfdb_src.fd_w = surf_width;
slouken@1895
  1036
        mfdb_src.fd_h = surface->h;
slouken@1895
  1037
        mfdb_src.fd_wdwidth = mfdb_src.fd_w >> 4;
slouken@1895
  1038
        mfdb_src.fd_nplanes = surface->format->BitsPerPixel;
slouken@1895
  1039
        mfdb_src.fd_stand =
slouken@1895
  1040
            mfdb_src.fd_r1 = mfdb_src.fd_r2 = mfdb_src.fd_r3 = 0;
slouken@1895
  1041
        if (GEM_bufops & B2S_VROCPYFM_1TOS) {
slouken@1895
  1042
            mfdb_src.fd_addr = surface->pixels;
slouken@1895
  1043
        } else {
slouken@1895
  1044
            mfdb_src.fd_addr = GEM_buffer2;
slouken@1895
  1045
        }
slouken@281
  1046
slouken@1895
  1047
        blitcoords[0] = blitcoords[4] = 0;
slouken@1895
  1048
        blitcoords[1] = blitcoords[5] = 0;
slouken@1895
  1049
        blitcoords[2] = blitcoords[6] = surface->w - 1;
slouken@1895
  1050
        blitcoords[3] = blitcoords[7] = surface->h - 1;
patmandin@736
  1051
slouken@1895
  1052
        vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
slouken@1895
  1053
    }
slouken@281
  1054
slouken@1895
  1055
    return (0);
slouken@281
  1056
}
slouken@281
  1057
slouken@1895
  1058
static int
slouken@1895
  1059
GEM_FlipHWSurfaceWindowed(_THIS, SDL_Surface * surface)
slouken@281
  1060
{
slouken@1895
  1061
    short pxy[8];
slouken@281
  1062
slouken@1895
  1063
    /* Update the whole window */
slouken@1895
  1064
    wind_get(GEM_handle, WF_WORKXYWH, &pxy[0], &pxy[1], &pxy[2], &pxy[3]);
slouken@281
  1065
slouken@1895
  1066
    GEM_wind_redraw(this, GEM_handle, pxy);
slouken@281
  1067
slouken@1895
  1068
    return (0);
slouken@281
  1069
}
slouken@281
  1070
slouken@1895
  1071
static int
slouken@1895
  1072
GEM_FlipHWSurface(_THIS, SDL_Surface * surface)
slouken@281
  1073
{
slouken@1895
  1074
    if (GEM_lock_redraw) {
slouken@1895
  1075
        return (0);
slouken@1895
  1076
    }
patmandin@964
  1077
slouken@1895
  1078
    if (surface->flags & SDL_FULLSCREEN) {
slouken@1895
  1079
        return GEM_FlipHWSurfaceFullscreen(this, surface);
slouken@1895
  1080
    } else {
slouken@1895
  1081
        return GEM_FlipHWSurfaceWindowed(this, surface);
slouken@1895
  1082
    }
slouken@281
  1083
}
slouken@281
  1084
slouken@1895
  1085
static int
slouken@1895
  1086
GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
slouken@281
  1087
{
slouken@1895
  1088
    int i;
slouken@1895
  1089
    SDL_Surface *surface;
slouken@281
  1090
patmandin@736
  1091
#ifdef DEBUG_VIDEO_GEM
slouken@1895
  1092
    printf("sdl:video:gem: setcolors()\n");
patmandin@736
  1093
#endif
patmandin@736
  1094
slouken@1895
  1095
    /* Do not change palette in True Colour */
slouken@1895
  1096
    surface = this->screen;
slouken@1895
  1097
    if (surface->format->BitsPerPixel > 8) {
slouken@1895
  1098
        return 1;
slouken@1895
  1099
    }
slouken@281
  1100
slouken@1895
  1101
    for (i = 0; i < ncolors; i++) {
slouken@1895
  1102
        int r, g, b;
slouken@1895
  1103
        short rgb[3];
slouken@281
  1104
slouken@1895
  1105
        r = colors[i].r;
slouken@1895
  1106
        g = colors[i].g;
slouken@1895
  1107
        b = colors[i].b;
slouken@281
  1108
slouken@1895
  1109
        rgb[0] = VDI_curpalette[i][0] = (1000 * r) / 255;
slouken@1895
  1110
        rgb[1] = VDI_curpalette[i][1] = (1000 * g) / 255;
slouken@1895
  1111
        rgb[2] = VDI_curpalette[i][2] = (1000 * b) / 255;
slouken@281
  1112
slouken@1895
  1113
        vs_color(VDI_handle, vdi_index[firstcolor + i], rgb);
slouken@1895
  1114
    }
slouken@281
  1115
slouken@1895
  1116
    return (1);
slouken@281
  1117
}
slouken@281
  1118
slouken@281
  1119
#if 0
slouken@1895
  1120
static int
slouken@1895
  1121
GEM_ToggleFullScreen(_THIS, int on)
slouken@281
  1122
{
slouken@1895
  1123
    if (on) {
slouken@1895
  1124
        GEM_LockScreen(this);
slouken@1895
  1125
    } else {
slouken@1895
  1126
        GEM_UnlockScreen(this);
slouken@1895
  1127
    }
slouken@281
  1128
slouken@1895
  1129
    return (1);
slouken@281
  1130
}
slouken@281
  1131
#endif
slouken@281
  1132
slouken@281
  1133
/* Note:  If we are terminated, this could be called in the middle of
slouken@281
  1134
   another SDL video routine -- notably UpdateRects.
slouken@281
  1135
*/
slouken@1895
  1136
void
slouken@1895
  1137
GEM_VideoQuit(_THIS)
slouken@281
  1138
{
slouken@1895
  1139
    SDL_AtariXbios_RestoreVectors();
slouken@1895
  1140
    if (GEM_usedevmouse) {
slouken@1895
  1141
        SDL_AtariDevMouse_Close();
slouken@1895
  1142
    }
slouken@305
  1143
slouken@1895
  1144
    GEM_FreeBuffers(this);
slouken@281
  1145
slouken@1361
  1146
#if SDL_VIDEO_OPENGL
slouken@1895
  1147
    if (gl_active) {
slouken@1895
  1148
        SDL_AtariGL_Quit(this, SDL_TRUE);
slouken@1895
  1149
    }
patmandin@992
  1150
#endif
patmandin@992
  1151
slouken@1895
  1152
    /* Destroy window */
slouken@1895
  1153
    if (GEM_handle >= 0) {
slouken@1895
  1154
        wind_close(GEM_handle);
slouken@1895
  1155
        wind_delete(GEM_handle);
slouken@1895
  1156
        GEM_handle = -1;
slouken@1895
  1157
    }
patmandin@925
  1158
slouken@1895
  1159
    GEM_UnlockScreen(this);
slouken@1895
  1160
    if (GEM_menubar) {
slouken@1895
  1161
        Mfree(GEM_menubar);
slouken@1895
  1162
        GEM_menubar = NULL;
slouken@1895
  1163
    }
slouken@281
  1164
slouken@1895
  1165
    appl_exit();
slouken@281
  1166
slouken@1895
  1167
    GEM_SetNewPalette(this, VDI_oldpalette);
slouken@281
  1168
slouken@1895
  1169
    /* Close VDI workstation */
slouken@1895
  1170
    if (VDI_handle) {
slouken@1895
  1171
        v_clsvwk(VDI_handle);
slouken@1895
  1172
    }
slouken@281
  1173
slouken@1895
  1174
    /* Free mode list */
slouken@1895
  1175
    if (SDL_modelist[0]) {
slouken@1895
  1176
        SDL_free(SDL_modelist[0]);
slouken@1895
  1177
        SDL_modelist[0] = NULL;
slouken@1895
  1178
    }
slouken@281
  1179
slouken@1895
  1180
    this->screen->pixels = NULL;
slouken@281
  1181
}
slouken@281
  1182
slouken@1895
  1183
void
slouken@1895
  1184
GEM_wind_redraw(_THIS, int winhandle, short *inside)
slouken@281
  1185
{
slouken@1895
  1186
    short todo[4];
slouken@281
  1187
slouken@1895
  1188
    /* Tell AES we are going to update */
slouken@1895
  1189
    wind_update(BEG_UPDATE);
slouken@281
  1190
slouken@1895
  1191
    v_hide_c(VDI_handle);
slouken@281
  1192
slouken@1895
  1193
    /* Browse the rectangle list to redraw */
slouken@1895
  1194
    if (wind_get
slouken@1895
  1195
        (winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2],
slouken@1895
  1196
         &todo[3]) != 0) {
slouken@281
  1197
slouken@1895
  1198
        while (todo[2] && todo[3]) {
slouken@281
  1199
slouken@1895
  1200
            if (rc_intersect((GRECT *) inside, (GRECT *) todo)) {
slouken@1895
  1201
                todo[2] += todo[0] - 1;
slouken@1895
  1202
                todo[3] += todo[1] - 1;
slouken@1895
  1203
                refresh_window(this, winhandle, todo);
slouken@1895
  1204
            }
patmandin@736
  1205
slouken@1895
  1206
            if (wind_get
slouken@1895
  1207
                (winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2],
slouken@1895
  1208
                 &todo[3]) == 0) {
slouken@1895
  1209
                break;
slouken@1895
  1210
            }
slouken@1895
  1211
        }
slouken@281
  1212
slouken@1895
  1213
    }
slouken@281
  1214
slouken@1895
  1215
    /* Update finished */
slouken@1895
  1216
    wind_update(END_UPDATE);
slouken@281
  1217
slouken@1895
  1218
    v_show_c(VDI_handle, 1);
slouken@281
  1219
}
slouken@281
  1220
slouken@1895
  1221
static void
slouken@1895
  1222
refresh_window(_THIS, int winhandle, short *rect)
slouken@281
  1223
{
slouken@1895
  1224
    MFDB mfdb_src;
slouken@1895
  1225
    short pxy[8], wind_pxy[8];
slouken@1895
  1226
    SDL_Surface *surface;
slouken@1895
  1227
    int iconified;
slouken@281
  1228
slouken@1895
  1229
    /* Is window iconified ? */
slouken@1895
  1230
    iconified = 0;
slouken@1895
  1231
/*	if (GEM_wfeatures & (1<<WF_ICONIFY))*/
slouken@1895
  1232
    {
slouken@1895
  1233
        if (wind_get
slouken@1895
  1234
            (winhandle, WF_ICONIFY, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2],
slouken@1895
  1235
             &wind_pxy[3]) != 0) {
slouken@1895
  1236
            iconified = wind_pxy[0];
slouken@1895
  1237
        }
slouken@1895
  1238
    }
patmandin@736
  1239
slouken@1895
  1240
    if (wind_get
slouken@1895
  1241
        (winhandle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2],
slouken@1895
  1242
         &wind_pxy[3]) == 0) {
slouken@1895
  1243
        return;
slouken@1895
  1244
    }
slouken@281
  1245
slouken@1895
  1246
    if (iconified && GEM_icon) {
slouken@1895
  1247
        short icon_rect[4], dst_rect[4];
slouken@1895
  1248
        short iconx, icony;
patmandin@736
  1249
slouken@1895
  1250
        surface = GEM_icon;
slouken@1895
  1251
slouken@1895
  1252
        GEM_ClearRect(this, rect);
patmandin@737
  1253
slouken@1895
  1254
        /* Calculate centered icon(x,y,w,h) relative to window */
slouken@1895
  1255
        iconx = (wind_pxy[2] - surface->w) >> 1;
slouken@1895
  1256
        icony = (wind_pxy[3] - surface->h) >> 1;
slouken@1895
  1257
slouken@1895
  1258
        icon_rect[0] = iconx;
slouken@1895
  1259
        icon_rect[1] = icony;
slouken@1895
  1260
        icon_rect[2] = surface->w;
slouken@1895
  1261
        icon_rect[3] = surface->h;
patmandin@736
  1262
slouken@1895
  1263
        /* Calculate redraw rectangle(x,y,w,h) relative to window */
slouken@1895
  1264
        dst_rect[0] = rect[0] - wind_pxy[0];
slouken@1895
  1265
        dst_rect[1] = rect[1] - wind_pxy[1];
slouken@1895
  1266
        dst_rect[2] = rect[2] - rect[0] + 1;
slouken@1895
  1267
        dst_rect[3] = rect[3] - rect[1] + 1;
patmandin@736
  1268
slouken@1895
  1269
        /* Does the icon rectangle must be redrawn ? */
slouken@1895
  1270
        if (!rc_intersect((GRECT *) icon_rect, (GRECT *) dst_rect)) {
slouken@1895
  1271
            return;
slouken@1895
  1272
        }
patmandin@799
  1273
#if DEBUG_VIDEO_GEM
slouken@1895
  1274
        printf("sdl:video:gem:  clip(0,0,%d,%d) to (%d,%d,%d,%d)\n",
slouken@1895
  1275
               surface->w - 1, surface->h - 1, dst_rect[0], dst_rect[1],
slouken@1895
  1276
               dst_rect[2], dst_rect[3]);
slouken@1895
  1277
        printf("sdl:video:gem:  icon(%d,%d,%d,%d)\n", icon_rect[0],
slouken@1895
  1278
               icon_rect[1], icon_rect[2], icon_rect[3]);
slouken@1895
  1279
        printf("sdl:video:gem: refresh_window(): draw icon\n");
patmandin@736
  1280
#endif
patmandin@736
  1281
slouken@1895
  1282
        /* Calculate icon(x1,y1,x2,y2) relative to screen */
slouken@1895
  1283
        icon_rect[0] += wind_pxy[0];
slouken@1895
  1284
        icon_rect[1] += wind_pxy[1];
slouken@1895
  1285
        icon_rect[2] += icon_rect[0] - 1;
slouken@1895
  1286
        icon_rect[3] += icon_rect[1] - 1;
slouken@281
  1287
slouken@1895
  1288
        /* Calculate intersection rectangle to redraw */
slouken@1895
  1289
        pxy[4] = pxy[0] = MAX(icon_rect[0], rect[0]);
slouken@1895
  1290
        pxy[5] = pxy[1] = MAX(icon_rect[1], rect[1]);
slouken@1895
  1291
        pxy[6] = pxy[2] = MIN(icon_rect[2], rect[2]);
slouken@1895
  1292
        pxy[7] = pxy[3] = MIN(icon_rect[3], rect[3]);
patmandin@736
  1293
slouken@1895
  1294
        /* Calculate icon source image pos relative to window */
slouken@1895
  1295
        pxy[0] -= wind_pxy[0] + iconx;
slouken@1895
  1296
        pxy[1] -= wind_pxy[1] + icony;
slouken@1895
  1297
        pxy[2] -= wind_pxy[0] + iconx;
slouken@1895
  1298
        pxy[3] -= wind_pxy[1] + icony;
patmandin@736
  1299
slouken@1895
  1300
    } else {
slouken@1895
  1301
        surface = this->screen;
patmandin@736
  1302
patmandin@799
  1303
#if DEBUG_VIDEO_GEM
slouken@1895
  1304
        printf("sdl:video:gem: refresh_window(): draw frame buffer\n");
patmandin@736
  1305
#endif
patmandin@736
  1306
slouken@1895
  1307
        /* Redraw all window content */
slouken@1895
  1308
        pxy[0] = rect[0] - wind_pxy[0];
slouken@1895
  1309
        pxy[1] = rect[1] - wind_pxy[1];
slouken@1895
  1310
        pxy[2] = rect[2] - wind_pxy[0];
slouken@1895
  1311
        pxy[3] = rect[3] - wind_pxy[1];
patmandin@736
  1312
slouken@1895
  1313
        pxy[4] = rect[0];
slouken@1895
  1314
        pxy[5] = rect[1];
slouken@1895
  1315
        pxy[6] = rect[2];
slouken@1895
  1316
        pxy[7] = rect[3];
slouken@1895
  1317
    }
slouken@281
  1318
slouken@1895
  1319
    if (GEM_bufops & B2S_C2P_1TO2) {
slouken@1895
  1320
        void *src, *dest;
slouken@1895
  1321
        int x1, x2;
patmandin@736
  1322
slouken@1895
  1323
        x1 = (rect[0] - wind_pxy[0]) & ~15;
slouken@1895
  1324
        x2 = rect[2] - wind_pxy[0];
slouken@1895
  1325
        if (x2 & 15) {
slouken@1895
  1326
            x2 = (x2 | 15) + 1;
slouken@1895
  1327
        }
patmandin@736
  1328
slouken@1895
  1329
        src = surface->pixels;
slouken@1895
  1330
        src += surface->pitch * (rect[1] - wind_pxy[1]);
slouken@1895
  1331
        src += x1;
slouken@281
  1332
slouken@1895
  1333
        dest = GEM_buffer2;
slouken@1895
  1334
        dest += surface->pitch * (rect[1] - wind_pxy[1]);
slouken@1895
  1335
        dest += x1;
patmandin@736
  1336
slouken@1895
  1337
        SDL_Atari_C2pConvert(src, dest,
slouken@1895
  1338
                             x2 - x1, rect[3] - rect[1] + 1,
slouken@1895
  1339
                             SDL_FALSE, surface->pitch, surface->pitch);
slouken@1895
  1340
    }
slouken@1895
  1341
slouken@1895
  1342
    mfdb_src.fd_addr = surface->pixels;
slouken@1895
  1343
    {
slouken@1895
  1344
        int width;
patmandin@799
  1345
slouken@1895
  1346
        /* Need to be a multiple of 16 pixels */
slouken@1895
  1347
        width = surface->w;
slouken@1895
  1348
        if ((width & 15) != 0) {
slouken@1895
  1349
            width = (width | 15) + 1;
slouken@1895
  1350
        }
slouken@1895
  1351
        mfdb_src.fd_w = width;
slouken@1895
  1352
    }
slouken@1895
  1353
    mfdb_src.fd_h = surface->h;
slouken@1895
  1354
    mfdb_src.fd_nplanes = surface->format->BitsPerPixel;
slouken@1895
  1355
    mfdb_src.fd_wdwidth = mfdb_src.fd_w >> 4;
slouken@1895
  1356
    mfdb_src.fd_stand = mfdb_src.fd_r1 = mfdb_src.fd_r2 = mfdb_src.fd_r3 = 0;
patmandin@736
  1357
slouken@1895
  1358
    if (GEM_bufops & B2S_VROCPYFM_2TOS) {
slouken@1895
  1359
        mfdb_src.fd_addr = GEM_buffer2;
slouken@1895
  1360
    }
patmandin@799
  1361
#if DEBUG_VIDEO_GEM
slouken@1895
  1362
    printf("sdl:video:gem: redraw %dx%d: (%d,%d,%d,%d) to (%d,%d,%d,%d)\n",
slouken@1895
  1363
           surface->w, surface->h,
slouken@1895
  1364
           pxy[0], pxy[1], pxy[2], pxy[3], pxy[4], pxy[5], pxy[6], pxy[7]);
patmandin@736
  1365
#endif
slouken@281
  1366
slouken@1895
  1367
    vro_cpyfm(VDI_handle, S_ONLY, pxy, &mfdb_src, &VDI_dst_mfdb);
slouken@281
  1368
}
patmandin@984
  1369
slouken@1361
  1370
#if SDL_VIDEO_OPENGL
patmandin@984
  1371
slouken@1895
  1372
static void
slouken@1895
  1373
GEM_GL_SwapBuffers(_THIS)
patmandin@984
  1374
{
slouken@1895
  1375
    SDL_AtariGL_SwapBuffers(this);
slouken@1895
  1376
    GEM_FlipHWSurface(this, this->screen);
patmandin@984
  1377
}
patmandin@984
  1378
patmandin@984
  1379
#endif
slouken@1895
  1380
/* vi: set ts=4 sw=4 expandtab: */