src/video/riscos/SDL_wimpvideo.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 29 May 2006 04:04:35 +0000
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
permissions -rw-r--r--
more tweaking indent options
slouken@630
     1
/*
slouken@630
     2
    SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 Sam Lantinga
slouken@630
     4
slouken@630
     5
    This library is free software; you can redistribute it and/or
slouken@630
     6
    modify it under the terms of the GNU Library General Public
slouken@630
     7
    License as published by the Free Software Foundation; either
slouken@630
     8
    version 2 of the License, or (at your option) any later version.
slouken@630
     9
slouken@630
    10
    This library is distributed in the hope that it will be useful,
slouken@630
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@630
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@630
    13
    Library General Public License for more details.
slouken@630
    14
slouken@630
    15
    You should have received a copy of the GNU Library General Public
slouken@630
    16
    License along with this library; if not, write to the Free
slouken@630
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@630
    18
slouken@630
    19
    Sam Lantinga
slouken@1312
    20
    slouken@libsdl.org
slouken@630
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@630
    23
slouken@630
    24
/*
slouken@1035
    25
     File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability
slouken@630
    26
	 27 March 2003
slouken@630
    27
slouken@1035
    28
     Implements RISC OS Wimp display.
slouken@630
    29
*/
slouken@630
    30
slouken@630
    31
#include "SDL_video.h"
slouken@630
    32
#include "SDL_mouse.h"
slouken@1361
    33
#include "../SDL_sysvideo.h"
slouken@1361
    34
#include "../SDL_pixels_c.h"
slouken@1361
    35
#include "../../events/SDL_events_c.h"
slouken@630
    36
slouken@630
    37
#include "SDL_riscostask.h"
slouken@630
    38
#include "SDL_riscosvideo.h"
slouken@630
    39
#include "SDL_riscosevents_c.h"
slouken@630
    40
#include "SDL_riscosmouse_c.h"
slouken@630
    41
slouken@630
    42
#include "kernel.h"
slouken@630
    43
#include "swis.h"
slouken@630
    44
slouken@630
    45
/* Initialization/Query functions */
slouken@1668
    46
SDL_Rect **WIMP_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags);
slouken@1668
    47
SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface * current, int width,
slouken@1668
    48
                               int height, int bpp, Uint32 flags);
slouken@1668
    49
int WIMP_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors);
slouken@1668
    50
void WIMP_SetWMCaption(_THIS, const char *title, const char *icon);
slouken@630
    51
slouken@630
    52
slouken@1668
    53
extern unsigned char *WIMP_CreateBuffer(int width, int height, int bpp);
slouken@1668
    54
extern void WIMP_PumpEvents(_THIS);
slouken@1668
    55
extern void WIMP_PlotSprite(_THIS, int x, int y);
slouken@1668
    56
extern void WIMP_SetupPlotInfo(_THIS);
slouken@1668
    57
extern void WIMP_SetFocus(int win);
slouken@630
    58
slouken@630
    59
/* etc. */
slouken@1668
    60
static void WIMP_UpdateRects(_THIS, int numrects, SDL_Rect * rects);
slouken@630
    61
slouken@630
    62
/* RISC OS Wimp handling helpers */
slouken@1668
    63
void WIMP_ReadModeInfo(_THIS);
slouken@1668
    64
unsigned int WIMP_SetupWindow(_THIS, SDL_Surface * surface);
slouken@1668
    65
void WIMP_SetDeviceMode(_THIS);
slouken@1668
    66
void WIMP_DeleteWindow(_THIS);
slouken@630
    67
slouken@630
    68
/* FULLSCREEN function required for wimp/fullscreen toggling */
slouken@1668
    69
extern int FULLSCREEN_SetMode(int width, int height, int bpp);
slouken@630
    70
slouken@630
    71
/* Currently need to set this up here as it only works if you
slouken@630
    72
   start up in a Wimp mode */
slouken@1668
    73
extern int RISCOS_ToggleFullScreen(_THIS, int fullscreen);
slouken@630
    74
slouken@630
    75
extern int riscos_backbuffer;
slouken@630
    76
extern int mouseInWindow;
slouken@630
    77
extern int riscos_closeaction;
slouken@630
    78
slouken@634
    79
/* Following needed to ensure window is shown immediately */
slouken@634
    80
extern int hasFocus;
slouken@1668
    81
extern void WIMP_Poll(_THIS, int waitTime);
slouken@630
    82
slouken@1662
    83
SDL_Surface *
slouken@1668
    84
WIMP_SetVideoMode(_THIS, SDL_Surface * current,
slouken@1668
    85
                  int width, int height, int bpp, Uint32 flags)
slouken@630
    86
{
slouken@1662
    87
    Uint32 Rmask = 0;
slouken@1662
    88
    Uint32 Gmask = 0;
slouken@1662
    89
    Uint32 Bmask = 0;
slouken@1662
    90
    char *buffer = NULL;
slouken@1662
    91
    int bytesPerPixel = 1;
slouken@630
    92
slouken@1662
    93
    /* Don't support double buffering in Wimp mode */
slouken@1662
    94
    flags &= ~SDL_DOUBLEBUF;
slouken@1662
    95
    flags &= ~SDL_HWSURFACE;
slouken@630
    96
slouken@1662
    97
    switch (bpp) {
slouken@1662
    98
    case 8:
slouken@1662
    99
        /* Emulated palette using ColourTrans */
slouken@1662
   100
        flags |= SDL_HWPALETTE;
slouken@1662
   101
        break;
slouken@630
   102
slouken@1662
   103
    case 15:
slouken@1662
   104
    case 16:
slouken@1662
   105
        Bmask = 0x00007c00;
slouken@1662
   106
        Gmask = 0x000003e0;
slouken@1662
   107
        Rmask = 0x0000001f;
slouken@1662
   108
        bytesPerPixel = 2;
slouken@1662
   109
        break;
slouken@630
   110
slouken@1662
   111
    case 32:
slouken@1662
   112
        Bmask = 0x00ff0000;
slouken@1662
   113
        Gmask = 0x0000ff00;
slouken@1662
   114
        Rmask = 0x000000ff;
slouken@1662
   115
        bytesPerPixel = 4;
slouken@1662
   116
        break;
slouken@630
   117
slouken@1662
   118
    default:
slouken@1668
   119
        SDL_SetError("Pixel depth not supported");
slouken@1662
   120
        return NULL;
slouken@1662
   121
        break;
slouken@1662
   122
    }
slouken@630
   123
slouken@630
   124
/* 	printf("Setting mode %dx%d\n", width, height);*/
slouken@630
   125
slouken@1662
   126
    /* Allocate the new pixel format for the screen */
slouken@1668
   127
    if (!SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0)) {
slouken@1668
   128
        SDL_SetError("Couldn't allocate new pixel format for requested mode");
slouken@1662
   129
        return (NULL);
slouken@1662
   130
    }
slouken@630
   131
slouken@1662
   132
    /* Set up the new mode framebuffer */
slouken@1662
   133
    current->w = width;
slouken@1662
   134
    this->hidden->height = current->h = height;
slouken@630
   135
slouken@1662
   136
    if (bpp == 15)
slouken@1662
   137
        bpp = 16;
slouken@1668
   138
    buffer = WIMP_CreateBuffer(width, height, bpp);
slouken@1662
   139
    if (buffer == NULL) {
slouken@1668
   140
        SDL_SetError("Couldn't create sprite for video memory");
slouken@1662
   141
        return (NULL);
slouken@1662
   142
    }
slouken@630
   143
slouken@1662
   144
    this->hidden->bank[0] = buffer + 60;        /* Start of sprite data */
slouken@1662
   145
    if (bpp == 8)
slouken@1662
   146
        this->hidden->bank[0] += 2048;  /* 8bpp sprite have palette first */
slouken@630
   147
slouken@1662
   148
    this->hidden->bank[1] = buffer;     /* Start of buffer */
slouken@630
   149
slouken@1662
   150
    /* Remember sprite buffer so it can be freed later */
slouken@1662
   151
    if (this->hidden->alloc_bank)
slouken@1668
   152
        SDL_free(this->hidden->alloc_bank);
slouken@1662
   153
    this->hidden->alloc_bank = buffer;
slouken@630
   154
slouken@1662
   155
    current->pitch = width * bytesPerPixel;
slouken@1662
   156
    if ((current->pitch & 3)) {
slouken@1662
   157
        /* Sprites are 32bit word aligned */
slouken@1662
   158
        current->pitch += (4 - (current->pitch & 3));
slouken@1662
   159
    }
slouken@630
   160
slouken@1662
   161
    current->flags = flags | SDL_PREALLOC;
slouken@630
   162
slouken@1668
   163
    WIMP_ReadModeInfo(this);
slouken@630
   164
slouken@1668
   165
    SDL_memset(this->hidden->bank[0], 0, height * current->pitch);
slouken@630
   166
slouken@1662
   167
    this->hidden->current_bank = 0;
slouken@1662
   168
    current->pixels = this->hidden->bank[0];
slouken@630
   169
slouken@630
   170
slouken@1668
   171
    if (WIMP_SetupWindow(this, current) == 0) {
slouken@1668
   172
        SDL_SetError("Unable to create window to display surface");
slouken@1662
   173
        return NULL;
slouken@1662
   174
    }
slouken@630
   175
slouken@1662
   176
    /* Reset device functions for the wimp */
slouken@1668
   177
    WIMP_SetDeviceMode(this);
slouken@634
   178
slouken@1662
   179
    /* Needs to set up plot info after window has been created */
slouken@1662
   180
    /* Not sure why, but plots don't work if I do it earlier */
slouken@1668
   181
    WIMP_SetupPlotInfo(this);
slouken@630
   182
slouken@1662
   183
    /* Poll until window is shown */
slouken@1662
   184
    {
slouken@1662
   185
        /* We wait until it gets the focus, but give up after 5 seconds
slouken@1662
   186
           in case the focus is prevented in any way.
slouken@1662
   187
         */
slouken@1668
   188
        Uint32 now = SDL_GetTicks();
slouken@1668
   189
        while (!hasFocus && SDL_GetTicks() - now < 5000) {
slouken@1668
   190
            WIMP_Poll(this, 0);
slouken@1662
   191
        }
slouken@1662
   192
    }
slouken@1662
   193
slouken@1662
   194
    /* We're done */
slouken@1662
   195
    return (current);
slouken@630
   196
}
slouken@630
   197
slouken@630
   198
slouken@1662
   199
void
slouken@1668
   200
WIMP_ReadModeInfo(_THIS)
slouken@630
   201
{
slouken@1662
   202
    _kernel_swi_regs regs;
slouken@1662
   203
    int vars[6];
slouken@1662
   204
    int vals[5];
slouken@630
   205
slouken@1662
   206
    vars[0] = 4;                /* XEig */
slouken@1662
   207
    vars[1] = 5;                /* YEig */
slouken@1662
   208
    vars[2] = 9;                /* Log base 2 bpp */
slouken@1662
   209
    vars[3] = 11;               /* Screen Width - 1 */
slouken@1662
   210
    vars[4] = 12;               /* Screen Depth - 1 */
slouken@1662
   211
    vars[5] = -1;               /* Terminate list */
slouken@630
   212
slouken@1662
   213
    regs.r[0] = (int) vars;
slouken@1662
   214
    regs.r[1] = (int) vals;
slouken@1668
   215
    _kernel_swi(OS_ReadVduVariables, &regs, &regs);
slouken@1662
   216
    this->hidden->xeig = vals[0];
slouken@1662
   217
    this->hidden->yeig = vals[1];
slouken@1662
   218
    this->hidden->screen_bpp = 1 << vals[2];
slouken@1662
   219
    this->hidden->screen_width = vals[3] + 1;
slouken@1662
   220
    this->hidden->screen_height = vals[4] + 1;
slouken@630
   221
}
slouken@630
   222
slouken@630
   223
/* Set device function to call the correct versions for running
slouken@630
   224
   in a wimp window */
slouken@630
   225
slouken@1662
   226
void
slouken@1668
   227
WIMP_SetDeviceMode(_THIS)
slouken@630
   228
{
slouken@1662
   229
    if (this->UpdateRects == WIMP_UpdateRects)
slouken@1662
   230
        return;                 /* Already set up */
slouken@630
   231
slouken@1662
   232
    this->SetColors = WIMP_SetColors;
slouken@1662
   233
    this->UpdateRects = WIMP_UpdateRects;
slouken@630
   234
slouken@1662
   235
    this->FlipHWSurface = NULL;
slouken@630
   236
slouken@1662
   237
    this->SetCaption = WIMP_SetWMCaption;
slouken@1662
   238
    this->SetIcon = NULL;
slouken@1662
   239
    this->IconifyWindow = NULL;
slouken@630
   240
slouken@1662
   241
    this->ShowWMCursor = WIMP_ShowWMCursor;
slouken@1662
   242
    this->WarpWMCursor = WIMP_WarpWMCursor;
slouken@630
   243
slouken@1662
   244
    this->ToggleFullScreen = RISCOS_ToggleFullScreen;
slouken@1662
   245
slouken@1662
   246
    this->PumpEvents = WIMP_PumpEvents;
slouken@630
   247
}
slouken@630
   248
slouken@630
   249
/* Setup the Window to display the surface */
slouken@1662
   250
unsigned int
slouken@1668
   251
WIMP_SetupWindow(_THIS, SDL_Surface * surface)
slouken@630
   252
{
slouken@1662
   253
    _kernel_swi_regs regs;
slouken@1662
   254
    int window_data[23];
slouken@1662
   255
    int *window_block = window_data + 1;
slouken@1662
   256
    int x = (this->hidden->screen_width - surface->w) / 2;
slouken@1662
   257
    int y = (this->hidden->screen_height - surface->h) / 2;
slouken@1662
   258
    int xeig = this->hidden->xeig;
slouken@1662
   259
    int yeig = this->hidden->yeig;
slouken@630
   260
slouken@630
   261
    mouseInWindow = 0;
slouken@630
   262
slouken@1662
   263
    /* Always delete the window and recreate on a change */
slouken@1662
   264
    if (this->hidden->window_handle)
slouken@1668
   265
        WIMP_DeleteWindow(this);
slouken@630
   266
slouken@1662
   267
    /* Setup window co-ordinates */
slouken@1662
   268
    window_block[0] = x << xeig;
slouken@1662
   269
    window_block[1] = y << yeig;
slouken@1662
   270
    window_block[2] = window_block[0] + (surface->w << xeig);
slouken@1662
   271
    window_block[3] = window_block[1] + (surface->h << yeig);
slouken@630
   272
slouken@630
   273
slouken@1662
   274
    window_block[4] = 0;        /* Scroll offsets */
slouken@1662
   275
    window_block[5] = 0;
slouken@1662
   276
    window_block[6] = -1;       /* Open on top of window stack */
slouken@630
   277
slouken@1662
   278
    window_block[7] = 0x85040042;       /* Window flags */
slouken@1662
   279
    if (riscos_closeaction != 0)
slouken@1662
   280
        window_block[7] |= 0x2000000;
slouken@630
   281
slouken@1662
   282
    /* TODO: Take into account surface->flags */
slouken@630
   283
slouken@1662
   284
    window_block[8] = 0xff070207;       /* Window colours */
slouken@1662
   285
    window_block[9] = 0x000c0103;
slouken@1662
   286
    window_block[10] = 0;       /* Work area minimum */
slouken@1662
   287
    window_block[11] = -surface->h << yeig;
slouken@1662
   288
    window_block[12] = surface->w << xeig;      /* Work area maximum */
slouken@1662
   289
    window_block[13] = 0;
slouken@1662
   290
    window_block[14] = 0x2700013d;      /* Title icon flags */
slouken@1662
   291
    window_block[15] = 0x00003000;      /* Work area flags - Mouse click down reported */
slouken@1662
   292
    window_block[16] = 1;       /* Sprite area control block pointer */
slouken@1662
   293
    window_block[17] = 0x00100010;      /* Minimum window size (width & height) (16x16) */
slouken@1662
   294
    window_block[18] = (int) this->hidden->title;       /* Title data */
slouken@1662
   295
    window_block[19] = -1;
slouken@1662
   296
    window_block[20] = 256;
slouken@1662
   297
    window_block[21] = 0;       /* Number of icons */
slouken@1662
   298
slouken@1662
   299
    regs.r[1] = (unsigned int) (window_block);
slouken@1662
   300
slouken@1662
   301
    /* Create the window */
slouken@1668
   302
    if (_kernel_swi(Wimp_CreateWindow, &regs, &regs) == NULL) {
slouken@1662
   303
        this->hidden->window_handle = window_data[0] = regs.r[0];
slouken@1662
   304
slouken@1662
   305
        /* Show the window on the screen */
slouken@1662
   306
        regs.r[1] = (unsigned int) window_data;
slouken@1668
   307
        if (_kernel_swi(Wimp_OpenWindow, &regs, &regs) == NULL) {
slouken@1668
   308
            WIMP_SetFocus(this->hidden->window_handle);
slouken@1662
   309
        } else {
slouken@1668
   310
            WIMP_DeleteWindow(this);
slouken@1662
   311
        }
slouken@1662
   312
    }
slouken@1662
   313
slouken@1662
   314
    return this->hidden->window_handle;
slouken@630
   315
}
slouken@630
   316
slouken@630
   317
/* Destroy the Window */
slouken@630
   318
slouken@1662
   319
void
slouken@1668
   320
WIMP_DeleteWindow(_THIS)
slouken@630
   321
{
slouken@1662
   322
    _kernel_swi_regs regs;
slouken@1662
   323
    regs.r[1] = (unsigned int) &(this->hidden->window_handle);
slouken@1668
   324
    _kernel_swi(Wimp_DeleteWindow, &regs, &regs);
slouken@1662
   325
    this->hidden->window_handle = 0;
slouken@630
   326
}
slouken@630
   327
slouken@630
   328
slouken@1662
   329
void
slouken@1668
   330
WIMP_UpdateRects(_THIS, int numrects, SDL_Rect * rects)
slouken@630
   331
{
slouken@1662
   332
    _kernel_swi_regs regs;
slouken@1662
   333
    int update_block[12];
slouken@1662
   334
    int xeig = this->hidden->xeig;
slouken@1662
   335
    int yeig = this->hidden->yeig;
slouken@1662
   336
    int j;
slouken@1662
   337
    update_block[0] = this->hidden->window_handle;
slouken@630
   338
slouken@1662
   339
    for (j = 0; j < numrects; j++) {
slouken@1662
   340
        update_block[1] = rects[j].x << xeig;   /* Min X */
slouken@1662
   341
        update_block[4] = -(rects[j].y << yeig);
slouken@1662
   342
        update_block[3] = update_block[1] + (rects[j].w << xeig);
slouken@1662
   343
        update_block[2] = update_block[4] - (rects[j].h << yeig);
slouken@630
   344
slouken@1662
   345
        regs.r[1] = (int) update_block;
slouken@1662
   346
        /* Update window can fail if called before first poll */
slouken@1668
   347
        if (_kernel_swi(Wimp_UpdateWindow, &regs, &regs) == 0) {
slouken@1662
   348
            while (regs.r[0]) {
slouken@1668
   349
                WIMP_PlotSprite(this, update_block[1], update_block[2]);
slouken@1668
   350
                _kernel_swi(Wimp_GetRectangle, &regs, &regs);
slouken@1662
   351
            }
slouken@1662
   352
        }
slouken@1662
   353
    }
slouken@630
   354
}
slouken@630
   355
slouken@630
   356
slouken@1662
   357
int
slouken@1668
   358
WIMP_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
slouken@630
   359
{
slouken@1662
   360
    unsigned int *pal = (unsigned int *) (this->hidden->bank[1] + 60);
slouken@1662
   361
    int j;
slouken@1662
   362
    SDL_Rect update;
slouken@630
   363
slouken@1662
   364
    pal += firstcolor * 2;
slouken@1662
   365
    for (j = 0; j < ncolors; j++) {
slouken@1662
   366
        *pal = (((unsigned int) colors->r) << 8)
slouken@1662
   367
            + (((unsigned int) colors->g) << 16)
slouken@1662
   368
            + (((unsigned int) colors->b) << 24);
slouken@1662
   369
        pal[1] = *pal;
slouken@1662
   370
        pal += 2;
slouken@1662
   371
        colors++;
slouken@1662
   372
    }
slouken@630
   373
slouken@1668
   374
    WIMP_SetupPlotInfo(this);
slouken@630
   375
slouken@1662
   376
    /* Need to refresh the window */
slouken@1662
   377
    update.x = 0;
slouken@1662
   378
    update.y = 0;
slouken@1662
   379
    update.w = SDL_VideoSurface->w;
slouken@1662
   380
    update.h = SDL_VideoSurface->h;
slouken@1668
   381
    WIMP_UpdateRects(this, 1, &update);
slouken@1662
   382
slouken@1662
   383
    return 1;
slouken@630
   384
}
slouken@630
   385
slouken@1662
   386
void
slouken@1668
   387
WIMP_SetWMCaption(_THIS, const char *title, const char *icon)
slouken@630
   388
{
slouken@1662
   389
    _kernel_swi_regs regs;
slouken@630
   390
slouken@1668
   391
    SDL_strlcpy(this->hidden->title, title,
slouken@1668
   392
                SDL_arraysize(this->hidden->title));
slouken@630
   393
slouken@1668
   394
    if (RISCOS_GetWimpVersion() < 380) {
slouken@1662
   395
        int block[6];
slouken@630
   396
slouken@1662
   397
        regs.r[1] = (int) block;
slouken@1668
   398
        _kernel_swi(Wimp_GetCaretPosition, &regs, &regs);
slouken@1662
   399
        if (block[0] == (int) this->hidden->window_handle) {
slouken@1662
   400
            regs.r[0] = -1;
slouken@1668
   401
            _kernel_swi(Wimp_SetCaretPosition, &regs, &regs);
slouken@1662
   402
        } else {
slouken@1662
   403
            regs.r[0] = this->hidden->window_handle;
slouken@1662
   404
            regs.r[1] = -1;
slouken@1662
   405
            regs.r[2] = -1;
slouken@1662
   406
            regs.r[3] = -1;
slouken@1668
   407
            _kernel_swi(Wimp_SetCaretPosition, &regs, &regs);
slouken@1662
   408
        }
slouken@1662
   409
        regs.r[0] = block[0];
slouken@1662
   410
        regs.r[1] = block[1];
slouken@1662
   411
        regs.r[2] = block[2];
slouken@1662
   412
        regs.r[3] = block[3];
slouken@1662
   413
        regs.r[4] = block[4];
slouken@1662
   414
        regs.r[5] = block[5];
slouken@1668
   415
        _kernel_swi(Wimp_SetCaretPosition, &regs, &regs);
slouken@1662
   416
    } else {
slouken@1662
   417
        regs.r[0] = this->hidden->window_handle;
slouken@1662
   418
        regs.r[1] = 0x4b534154; /* "TASK" */
slouken@1662
   419
        regs.r[2] = 3;          /* Redraw title */
slouken@1668
   420
        _kernel_swi(Wimp_ForceRedraw, &regs, &regs);
slouken@1662
   421
    }
slouken@630
   422
}
slouken@630
   423
slouken@1662
   424
void
slouken@1668
   425
WIMP_RefreshDesktop(_THIS)
slouken@630
   426
{
slouken@1662
   427
    int width = this->hidden->screen_width << this->hidden->xeig;
slouken@1662
   428
    int height = this->hidden->screen_height << this->hidden->yeig;
slouken@1662
   429
    _kernel_swi_regs regs;
slouken@1662
   430
    regs.r[0] = -1;             /* Whole screen */
slouken@1662
   431
    regs.r[1] = 0;
slouken@1662
   432
    regs.r[2] = 0;
slouken@1662
   433
    regs.r[3] = width;
slouken@1662
   434
    regs.r[4] = height;
slouken@1668
   435
    _kernel_swi(Wimp_ForceRedraw, &regs, &regs);
slouken@630
   436
}
slouken@630
   437
slouken@630
   438
/* Toggle to window from full screen */
slouken@1662
   439
int
slouken@1668
   440
WIMP_ToggleFromFullScreen(_THIS)
slouken@1662
   441
{
slouken@1662
   442
    int width = this->screen->w;
slouken@1662
   443
    int height = this->screen->h;
slouken@1662
   444
    int bpp = this->screen->format->BitsPerPixel;
slouken@1662
   445
    char *buffer = NULL;
slouken@1662
   446
    char *old_bank[2];
slouken@1662
   447
    char *old_alloc_bank;
slouken@630
   448
slouken@1662
   449
    /* Ensure flags are OK */
slouken@1662
   450
    this->screen->flags &= ~(SDL_DOUBLEBUF | SDL_HWSURFACE);
slouken@630
   451
slouken@1662
   452
    if (this->hidden->bank[0] == this->hidden->alloc_bank
slouken@1662
   453
        || riscos_backbuffer == 0) {
slouken@1662
   454
        /* Need to create a sprite for the screen and copy the data to it */
slouken@1662
   455
        char *data;
slouken@1668
   456
        buffer = WIMP_CreateBuffer(width, height, bpp);
slouken@1662
   457
        data = buffer + 60;     /* Start of sprite data */
slouken@1662
   458
        if (bpp == 8)
slouken@1662
   459
            data += 2048;       /* 8bpp sprite have palette first */
slouken@630
   460
slouken@1662
   461
        if (buffer == NULL)
slouken@1662
   462
            return 0;
slouken@1668
   463
        SDL_memcpy(data, this->hidden->bank[0],
slouken@1668
   464
                   width * height * this->screen->format->BytesPerPixel);
slouken@1662
   465
    }
slouken@1662
   466
    /* else We've switch to full screen before so we already have a sprite */
slouken@630
   467
slouken@1662
   468
    old_bank[0] = this->hidden->bank[0];
slouken@1662
   469
    old_bank[1] = this->hidden->bank[1];
slouken@1662
   470
    old_alloc_bank = this->hidden->alloc_bank;
slouken@630
   471
slouken@1662
   472
    if (buffer != NULL)
slouken@1662
   473
        this->hidden->alloc_bank = buffer;
slouken@630
   474
slouken@1662
   475
    this->hidden->bank[1] = this->hidden->alloc_bank;
slouken@1662
   476
    this->hidden->bank[0] = this->hidden->bank[1] + 60; /* Start of sprite data */
slouken@1662
   477
    if (bpp == 8)
slouken@1662
   478
        this->hidden->bank[0] += 2048;  /* 8bpp sprite have palette first */
slouken@630
   479
slouken@1662
   480
    this->hidden->current_bank = 0;
slouken@1662
   481
    this->screen->pixels = this->hidden->bank[0];
slouken@630
   482
slouken@1668
   483
    RISCOS_RestoreWimpMode();
slouken@1668
   484
    WIMP_ReadModeInfo(this);
slouken@1668
   485
    if (WIMP_SetupWindow(this, this->screen)) {
slouken@1668
   486
        WIMP_SetDeviceMode(this);
slouken@1668
   487
        WIMP_SetupPlotInfo(this);
slouken@630
   488
slouken@1662
   489
        if (riscos_backbuffer == 0)
slouken@1662
   490
            riscos_backbuffer = 1;
slouken@630
   491
slouken@1662
   492
        if (buffer && old_alloc_bank)
slouken@1668
   493
            SDL_free(old_alloc_bank);
slouken@630
   494
slouken@1662
   495
        return 1;
slouken@1662
   496
    } else {
slouken@1662
   497
        /* Drop back to full screen mode on failure */
slouken@1662
   498
        this->hidden->bank[0] = old_bank[0];
slouken@1662
   499
        this->hidden->bank[1] = old_bank[1];
slouken@1662
   500
        this->hidden->alloc_bank = old_alloc_bank;
slouken@1662
   501
        if (buffer)
slouken@1668
   502
            SDL_free(buffer);
slouken@630
   503
slouken@1668
   504
        RISCOS_StoreWimpMode();
slouken@1668
   505
        FULLSCREEN_SetMode(width, height, bpp);
slouken@1662
   506
    }
slouken@1662
   507
slouken@1662
   508
    return 0;
slouken@630
   509
}
slouken@1662
   510
slouken@1662
   511
/* vi: set ts=4 sw=4 expandtab: */