src/video/riscos/SDL_wimpvideo.c
author Cameron Cawley <ccawley2011@gmail.com>
Tue, 03 Sep 2019 23:11:10 +0300
branchSDL-1.2
changeset 13054 d07097a0e57e
parent 12913 d07b4feae69c
permissions -rw-r--r--
riscos: implement SDL_WM_IconifyWindow()
slouken@630
     1
/*
slouken@630
     2
    SDL - Simple DirectMedia Layer
slouken@6137
     3
    Copyright (C) 1997-2012 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"
ccawley2011@12779
    33
#include "SDL_timer.h"
slouken@1361
    34
#include "../SDL_sysvideo.h"
slouken@1361
    35
#include "../SDL_pixels_c.h"
slouken@1361
    36
#include "../../events/SDL_events_c.h"
slouken@630
    37
slouken@630
    38
#include "SDL_riscostask.h"
slouken@630
    39
#include "SDL_riscosvideo.h"
slouken@630
    40
#include "SDL_riscosevents_c.h"
slouken@630
    41
#include "SDL_riscosmouse_c.h"
slouken@630
    42
slouken@630
    43
#include "kernel.h"
slouken@630
    44
#include "swis.h"
slouken@630
    45
me@12786
    46
static int WIMP_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
me@12786
    47
static void WIMP_SetWMCaption(_THIS, const char *title, const char *icon);
ccawley2011@13054
    48
static int WIMP_IconifyWindow(_THIS);
slouken@630
    49
static void WIMP_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
slouken@630
    50
slouken@630
    51
/* RISC OS Wimp handling helpers */
me@12786
    52
static unsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface);
me@12786
    53
static void WIMP_SetDeviceMode(_THIS);
slouken@630
    54
slouken@630
    55
slouken@630
    56
SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current,
slouken@630
    57
				int width, int height, int bpp, Uint32 flags)
slouken@630
    58
{
me@12786
    59
	unsigned char *buffer = NULL;
me@12786
    60
	int bytesPerPixel;
me@12786
    61
	const RISCOS_SDL_PixelFormat *fmt;
slouken@630
    62
me@12786
    63
	/* Don't support double buffering in Wimp mode */
me@12786
    64
	flags &= ~SDL_DOUBLEBUF;
me@12786
    65
	flags &= ~SDL_HWSURFACE;
slouken@630
    66
me@12786
    67
	/* Identify the current pixel format */
me@12786
    68
	fmt = RISCOS_CurrentPixelFormat();
me@12786
    69
	/* If it's the same (approximate) BPP as the desired BPP, use it directly (less overhead in sprite rendering) */
me@12786
    70
	if ((fmt == NULL) || (fmt->sdl_bpp != ((bpp+1)&~1)))
me@12786
    71
	{
me@12786
    72
		/* Not a good match - look for a supported format which is correct */
me@12786
    73
		fmt = WIMP_FindSupportedSpriteFormat(bpp);
me@12786
    74
		if (fmt == NULL)
me@12786
    75
		{
ccawley2011@12913
    76
			SDL_SetError("Pixel depth %d not supported", bpp);
me@12786
    77
			return NULL;
me@12786
    78
		}
me@12786
    79
	}
me@12786
    80
me@12786
    81
	if (fmt->sdl_bpp == 8)
me@12786
    82
	{
slouken@630
    83
		/* Emulated palette using ColourTrans */
slouken@630
    84
		flags |= SDL_HWPALETTE;
me@12786
    85
	}
me@12786
    86
	bytesPerPixel = 1 << (fmt->ro.log2bpp - 3);
slouken@630
    87
slouken@630
    88
/* 	printf("Setting mode %dx%d\n", width, height);*/
slouken@630
    89
slouken@630
    90
	/* Allocate the new pixel format for the screen */
me@12786
    91
	if ( ! SDL_ReallocFormat(current, fmt->sdl_bpp, fmt->rmask, fmt->gmask, fmt->bmask, 0) ) {
slouken@630
    92
		return(NULL);
slouken@630
    93
	}
slouken@630
    94
slouken@630
    95
	/* Set up the new mode framebuffer */
slouken@630
    96
	current->w = width;
slouken@630
    97
	this->hidden->height = current->h = height;
slouken@630
    98
slouken@630
    99
	if (bpp == 15) bpp = 16;
me@12786
   100
	buffer = WIMP_CreateBuffer(width, height, &fmt->ro);
slouken@630
   101
	if (buffer == NULL)
slouken@630
   102
	{
slouken@630
   103
		return (NULL);
slouken@630
   104
	}
slouken@630
   105
slouken@630
   106
	this->hidden->bank[0] = buffer + 60; /* Start of sprite data */
slouken@630
   107
	if (bpp == 8) this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */
slouken@630
   108
slouken@630
   109
	this->hidden->bank[1] = buffer;      /* Start of buffer */
slouken@630
   110
slouken@630
   111
	/* Remember sprite buffer so it can be freed later */
slouken@1336
   112
	if (this->hidden->alloc_bank) SDL_free(this->hidden->alloc_bank);
slouken@630
   113
	this->hidden->alloc_bank = buffer;
slouken@630
   114
slouken@630
   115
	current->pitch = width * bytesPerPixel;
slouken@630
   116
	if ((current->pitch & 3))
slouken@630
   117
	{
slouken@630
   118
		/* Sprites are 32bit word aligned */
slouken@630
   119
		current->pitch += (4 - (current->pitch & 3));
slouken@630
   120
	}
me@12786
   121
	this->hidden->format = fmt;
slouken@630
   122
slouken@630
   123
  	current->flags = flags | SDL_PREALLOC;
slouken@630
   124
slouken@630
   125
	WIMP_ReadModeInfo(this);
slouken@630
   126
	
slouken@1336
   127
    SDL_memset(this->hidden->bank[0], 0, height * current->pitch);
slouken@630
   128
slouken@630
   129
	this->hidden->current_bank = 0;
slouken@630
   130
	current->pixels = this->hidden->bank[0];
slouken@630
   131
slouken@630
   132
slouken@630
   133
	if (WIMP_SetupWindow(this, current) == 0)
slouken@630
   134
	{
slouken@630
   135
		return NULL;
slouken@630
   136
	}
slouken@630
   137
slouken@630
   138
	/* Reset device functions for the wimp */
slouken@630
   139
	WIMP_SetDeviceMode(this);
slouken@630
   140
slouken@634
   141
	/* Needs to set up plot info after window has been created */
slouken@634
   142
	/* Not sure why, but plots don't work if I do it earlier */
slouken@634
   143
	WIMP_SetupPlotInfo(this);
slouken@634
   144
slouken@634
   145
	/* Poll until window is shown */
slouken@634
   146
	{
slouken@634
   147
	   /* We wait until it gets the focus, but give up after 5 seconds
slouken@634
   148
	      in case the focus is prevented in any way.
slouken@634
   149
	   */
slouken@634
   150
	   Uint32 now = SDL_GetTicks();
slouken@634
   151
	   while (!hasFocus && SDL_GetTicks() - now < 5000)
slouken@634
   152
	   {
slouken@634
   153
	      WIMP_Poll(this, 0);
slouken@634
   154
	   }
slouken@634
   155
	}
slouken@630
   156
slouken@630
   157
	/* We're done */
slouken@630
   158
	return(current);
slouken@630
   159
}
slouken@630
   160
slouken@630
   161
slouken@630
   162
void WIMP_ReadModeInfo(_THIS)
slouken@630
   163
{
slouken@630
   164
	_kernel_swi_regs regs;
slouken@630
   165
	int vars[6];
slouken@630
   166
	int vals[5];
slouken@630
   167
slouken@630
   168
	vars[0] = 4;  /* XEig */
slouken@630
   169
	vars[1] = 5;  /* YEig */
slouken@630
   170
	vars[2] = 9;  /* Log base 2 bpp */
slouken@630
   171
	vars[3] = 11; /* Screen Width - 1 */
slouken@630
   172
	vars[4] = 12; /* Screen Depth - 1 */
slouken@630
   173
	vars[5] = -1; /* Terminate list */
slouken@630
   174
slouken@630
   175
	regs.r[0] = (int)vars;
slouken@630
   176
	regs.r[1] = (int)vals;
slouken@630
   177
	_kernel_swi(OS_ReadVduVariables, &regs, &regs);
slouken@630
   178
	this->hidden->xeig = vals[0];
slouken@630
   179
	this->hidden->yeig = vals[1];
slouken@630
   180
	this->hidden->screen_width = vals[3] + 1;
slouken@630
   181
	this->hidden->screen_height = vals[4] + 1;
slouken@630
   182
}
slouken@630
   183
slouken@630
   184
/* Set device function to call the correct versions for running
slouken@630
   185
   in a wimp window */
slouken@630
   186
slouken@630
   187
void WIMP_SetDeviceMode(_THIS)
slouken@630
   188
{
slouken@630
   189
	if (this->UpdateRects == WIMP_UpdateRects) return; /* Already set up */
slouken@630
   190
slouken@630
   191
	this->SetColors   = WIMP_SetColors;
slouken@630
   192
	this->UpdateRects = WIMP_UpdateRects;
slouken@630
   193
slouken@630
   194
	this->FlipHWSurface = NULL;
slouken@630
   195
slouken@630
   196
	this->SetCaption = WIMP_SetWMCaption;
slouken@630
   197
	this->SetIcon = NULL;
ccawley2011@13054
   198
	this->IconifyWindow = WIMP_IconifyWindow;
slouken@630
   199
	
slouken@630
   200
	this->ShowWMCursor = WIMP_ShowWMCursor;
slouken@630
   201
	this->WarpWMCursor = WIMP_WarpWMCursor;
slouken@630
   202
me@12786
   203
/* Currently need to set this up here as it only works if you
me@12786
   204
   start up in a Wimp mode */
slouken@630
   205
        this->ToggleFullScreen = RISCOS_ToggleFullScreen;
slouken@630
   206
slouken@630
   207
	this->PumpEvents = WIMP_PumpEvents;	
slouken@630
   208
}
slouken@630
   209
slouken@630
   210
/* Setup the Window to display the surface */
slouken@630
   211
unsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface)
slouken@630
   212
{
slouken@630
   213
	_kernel_swi_regs regs;
ccawley2011@12913
   214
	_kernel_oserror *error;
slouken@630
   215
	int window_data[23];
slouken@630
   216
    int	*window_block = window_data+1;
me@12782
   217
	int x = ((this->hidden->screen_width << this->hidden->xeig) - (surface->w << 1)) / 2;
me@12782
   218
	int y = ((this->hidden->screen_height << this->hidden->yeig) - (surface->h << 1)) / 2;    
me@12782
   219
slouken@630
   220
	/* Always delete the window and recreate on a change */
slouken@630
   221
	if (this->hidden->window_handle) WIMP_DeleteWindow(this);
slouken@630
   222
slouken@630
   223
	/* Setup window co-ordinates */
me@12782
   224
   window_block[0] = x;
me@12782
   225
   window_block[1] = y;
me@12782
   226
   window_block[2] = window_block[0] + (surface->w << 1);
me@12782
   227
   window_block[3] = window_block[1] + (surface->h << 1);
slouken@630
   228
slouken@630
   229
   
slouken@630
   230
   window_block[4] = 0;				  /* Scroll offsets */
slouken@630
   231
   window_block[5] = 0;
slouken@630
   232
   window_block[6] = -1;			  /* Open on top of window stack */
slouken@630
   233
slouken@630
   234
   window_block[7] = 0x85040042;      /* Window flags */
slouken@630
   235
   if (riscos_closeaction != 0) window_block[7] |= 0x2000000;
slouken@630
   236
slouken@630
   237
   /* TODO: Take into account surface->flags */
slouken@630
   238
slouken@630
   239
   window_block[8] = 0xff070207;      /* Window colours */
slouken@630
   240
   window_block[9] = 0x000c0103;
slouken@630
   241
   window_block[10] = 0;                    /* Work area minimum */
me@12782
   242
   window_block[11] = -surface->h << 1;
me@12782
   243
   window_block[12] = surface->w << 1;   /* Work area maximum */
slouken@630
   244
   window_block[13] = 0;
slouken@630
   245
   window_block[14] = 0x2700013d;    /* Title icon flags */
slouken@630
   246
   window_block[15] = 0x00003000;	 /* Work area flags - Mouse click down reported */
slouken@630
   247
   window_block[16] = 1;             /* Sprite area control block pointer */
slouken@630
   248
   window_block[17] = 0x00100010;	 /* Minimum window size (width & height) (16x16)*/
slouken@630
   249
   window_block[18] = (int)this->hidden->title;    /* Title data */
slouken@630
   250
   window_block[19] = -1;
slouken@630
   251
   window_block[20] = 256;
slouken@630
   252
   window_block[21] = 0;			 /* Number of icons */
slouken@630
   253
slouken@630
   254
   regs.r[1] = (unsigned int)(window_block);
slouken@630
   255
   
slouken@630
   256
   /* Create the window */
ccawley2011@12913
   257
   error = _kernel_swi(Wimp_CreateWindow, &regs, &regs);
ccawley2011@12913
   258
   if (error == NULL)
slouken@630
   259
   {
slouken@630
   260
	   this->hidden->window_handle = window_data[0] = regs.r[0];
slouken@630
   261
slouken@630
   262
	   /* Show the window on the screen */
slouken@630
   263
	   regs.r[1] = (unsigned int)window_data;
slouken@630
   264
       if (_kernel_swi(Wimp_OpenWindow, &regs, &regs) == NULL)
slouken@630
   265
       {
slouken@630
   266
          WIMP_SetFocus(this->hidden->window_handle);
slouken@630
   267
       } else
slouken@630
   268
       {
slouken@630
   269
		  WIMP_DeleteWindow(this);
slouken@630
   270
	   }
ccawley2011@12913
   271
   } else {
ccawley2011@12913
   272
       SDL_SetError("Unable to create window: %s (%i)", error->errmess, error->errnum);
slouken@630
   273
   }
ccawley2011@12913
   274
slouken@630
   275
   return this->hidden->window_handle;
slouken@630
   276
}
slouken@630
   277
slouken@630
   278
/* Destroy the Window */
slouken@630
   279
slouken@630
   280
void WIMP_DeleteWindow(_THIS)
slouken@630
   281
{
slouken@630
   282
	_kernel_swi_regs regs;
slouken@630
   283
    regs.r[1] = (unsigned int)&(this->hidden->window_handle);
slouken@630
   284
	_kernel_swi(Wimp_DeleteWindow, &regs, &regs);
slouken@630
   285
	this->hidden->window_handle = 0;
slouken@630
   286
}
slouken@630
   287
slouken@630
   288
slouken@630
   289
void WIMP_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
slouken@630
   290
{
slouken@630
   291
	_kernel_swi_regs regs;
slouken@630
   292
	int update_block[12];
slouken@630
   293
	int j;
slouken@630
   294
	update_block[0] = this->hidden->window_handle;
slouken@630
   295
slouken@630
   296
	for (j = 0; j < numrects; j++)
slouken@630
   297
	{
me@12782
   298
		update_block[1] = rects[j].x << 1; /* Min X */
me@12782
   299
		update_block[4] = -(rects[j].y << 1);
me@12782
   300
		update_block[3] = update_block[1] + (rects[j].w << 1);
me@12782
   301
		update_block[2] = update_block[4] - (rects[j].h << 1);
slouken@630
   302
slouken@630
   303
		regs.r[1] = (int)update_block;
slouken@630
   304
		/* Update window can fail if called before first poll */
slouken@630
   305
		if (_kernel_swi(Wimp_UpdateWindow, &regs, &regs) == 0)
slouken@630
   306
		{
slouken@630
   307
			while (regs.r[0])
slouken@630
   308
			{
slouken@630
   309
				WIMP_PlotSprite(this, update_block[1], update_block[2]);
slouken@630
   310
				_kernel_swi(Wimp_GetRectangle, &regs, &regs);
slouken@630
   311
			}
slouken@630
   312
		}
slouken@630
   313
	}
slouken@630
   314
}
slouken@630
   315
slouken@630
   316
slouken@630
   317
int WIMP_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
slouken@630
   318
{
slouken@630
   319
   unsigned int *pal = (unsigned int *)(this->hidden->bank[1]+60);
slouken@630
   320
   int j;
slouken@630
   321
   SDL_Rect update;
slouken@630
   322
slouken@630
   323
   pal += firstcolor*2;
slouken@630
   324
   for (j = 0; j < ncolors; j++)
slouken@630
   325
   {
slouken@630
   326
      *pal = (((unsigned int)colors->r) << 8)
slouken@630
   327
             + (((unsigned int)colors->g) << 16)
slouken@630
   328
             + (((unsigned int)colors->b) << 24);
slouken@630
   329
      pal[1] = *pal;
slouken@630
   330
      pal += 2;
slouken@630
   331
      colors++;
slouken@630
   332
   }
slouken@630
   333
slouken@630
   334
   WIMP_SetupPlotInfo(this);
slouken@630
   335
slouken@630
   336
   /* Need to refresh the window */
slouken@630
   337
   update.x = 0;
slouken@630
   338
   update.y = 0;
slouken@630
   339
   update.w = SDL_VideoSurface->w;
slouken@630
   340
   update.h = SDL_VideoSurface->h;
slouken@630
   341
   WIMP_UpdateRects(this, 1, &update);
slouken@630
   342
      
slouken@630
   343
	return 1;
slouken@630
   344
}
slouken@630
   345
slouken@630
   346
void WIMP_SetWMCaption(_THIS, const char *title, const char *icon)
slouken@630
   347
{
slouken@630
   348
	_kernel_swi_regs regs;
slouken@630
   349
slouken@1379
   350
	SDL_strlcpy(this->hidden->title, title, SDL_arraysize(this->hidden->title));
slouken@630
   351
slouken@630
   352
	if (RISCOS_GetWimpVersion() < 380)
slouken@630
   353
	{
slouken@630
   354
		int block[6];
slouken@630
   355
slouken@630
   356
		regs.r[1] = (int)block;
slouken@630
   357
		_kernel_swi(Wimp_GetCaretPosition, &regs, &regs);
slouken@630
   358
		if (block[0] == (int)this->hidden->window_handle)
slouken@630
   359
		{
slouken@630
   360
			regs.r[0] = -1;
slouken@630
   361
			_kernel_swi(Wimp_SetCaretPosition, &regs,&regs);
slouken@630
   362
		} else
slouken@630
   363
		{
slouken@630
   364
			regs.r[0] = this->hidden->window_handle;
slouken@630
   365
			regs.r[1] = -1;
slouken@630
   366
			regs.r[2] = -1;
slouken@630
   367
			regs.r[3] = -1;
slouken@630
   368
			_kernel_swi(Wimp_SetCaretPosition, &regs,&regs);
slouken@630
   369
		}
slouken@630
   370
		regs.r[0] = block[0];
slouken@630
   371
		regs.r[1] = block[1];
slouken@630
   372
		regs.r[2] = block[2];
slouken@630
   373
		regs.r[3] = block[3];
slouken@630
   374
		regs.r[4] = block[4];
slouken@630
   375
		regs.r[5] = block[5];
slouken@630
   376
		_kernel_swi(Wimp_SetCaretPosition, &regs,&regs);
slouken@630
   377
	} else
slouken@630
   378
	{
slouken@630
   379
		regs.r[0] = this->hidden->window_handle;
slouken@630
   380
		regs.r[1] = 0x4b534154; /* "TASK" */
slouken@630
   381
		regs.r[2] = 3; /* Redraw title */
slouken@630
   382
		_kernel_swi(Wimp_ForceRedraw, &regs, &regs);
slouken@630
   383
	}
slouken@630
   384
}
slouken@630
   385
ccawley2011@13054
   386
int WIMP_IconifyWindow(_THIS)
ccawley2011@13054
   387
{
ccawley2011@13054
   388
	_kernel_swi_regs regs;
ccawley2011@13054
   389
ccawley2011@13054
   390
	int block[12];
ccawley2011@13054
   391
	block[0] = 48;
ccawley2011@13054
   392
	block[1] = RISCOS_GetTaskHandle();
ccawley2011@13054
   393
	block[2] = 0;
ccawley2011@13054
   394
	block[3] = 0;
ccawley2011@13054
   395
	block[4] = 0x400ca; /* Message_Iconize */
ccawley2011@13054
   396
	block[5] = this->hidden->window_handle;
ccawley2011@13054
   397
	block[6] = RISCOS_GetTaskHandle();
ccawley2011@13054
   398
ccawley2011@13054
   399
	SDL_strlcpy((char *)&block[7], this->hidden->title, 20);
ccawley2011@13054
   400
ccawley2011@13054
   401
	regs.r[0] = 17; /* User_Message */
ccawley2011@13054
   402
	regs.r[1] = (int)block;
ccawley2011@13054
   403
	regs.r[2] = 0;
ccawley2011@13054
   404
	_kernel_swi(Wimp_SendMessage, &regs, &regs);
ccawley2011@13054
   405
ccawley2011@13054
   406
	return 1;
ccawley2011@13054
   407
}
ccawley2011@13054
   408
slouken@630
   409
/* Toggle to window from full screen */
slouken@630
   410
int WIMP_ToggleFromFullScreen(_THIS)
slouken@630
   411
{     
slouken@630
   412
   int width = this->screen->w;
slouken@630
   413
   int height = this->screen->h;
slouken@630
   414
   int bpp = this->screen->format->BitsPerPixel;
ccawley2011@12779
   415
   unsigned char *buffer = NULL;
ccawley2011@12779
   416
   unsigned char *old_bank[2];
ccawley2011@12779
   417
   unsigned char *old_alloc_bank;
slouken@630
   418
slouken@630
   419
   /* Ensure flags are OK */
slouken@630
   420
   this->screen->flags &= ~(SDL_DOUBLEBUF|SDL_HWSURFACE);
slouken@630
   421
slouken@630
   422
   if (this->hidden->bank[0] == this->hidden->alloc_bank || riscos_backbuffer == 0)
slouken@630
   423
   {
slouken@630
   424
      /* Need to create a sprite for the screen and copy the data to it */
ccawley2011@12779
   425
      unsigned char *data;
me@12786
   426
      buffer = WIMP_CreateBuffer(width, height, &this->hidden->format->ro);
slouken@630
   427
      data = buffer + 60;         /* Start of sprite data */
slouken@630
   428
      if (bpp == 8) data += 2048;  /* 8bpp sprite have palette first */
slouken@630
   429
slouken@630
   430
      if (buffer == NULL) return 0;
slouken@1336
   431
      SDL_memcpy(data, this->hidden->bank[0], width * height * this->screen->format->BytesPerPixel);
slouken@630
   432
   }
slouken@630
   433
   /* else We've switch to full screen before so we already have a sprite */
slouken@630
   434
slouken@630
   435
   old_bank[0] = this->hidden->bank[0];
slouken@630
   436
   old_bank[1] = this->hidden->bank[1];
slouken@630
   437
   old_alloc_bank = this->hidden->alloc_bank;
slouken@630
   438
slouken@630
   439
   if (buffer != NULL) this->hidden->alloc_bank = buffer;
slouken@630
   440
slouken@630
   441
   this->hidden->bank[1] = this->hidden->alloc_bank;
slouken@630
   442
   this->hidden->bank[0] = this->hidden->bank[1] + 60; /* Start of sprite data */
slouken@630
   443
   if (bpp == 8) this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */
slouken@630
   444
slouken@630
   445
   this->hidden->current_bank = 0;
slouken@630
   446
   this->screen->pixels = this->hidden->bank[0];
slouken@630
   447
slouken@630
   448
   RISCOS_RestoreWimpMode();
slouken@630
   449
   WIMP_ReadModeInfo(this);
slouken@630
   450
   if (WIMP_SetupWindow(this, this->screen))
slouken@630
   451
   {
slouken@630
   452
      WIMP_SetDeviceMode(this);
slouken@630
   453
      WIMP_SetupPlotInfo(this);
slouken@630
   454
slouken@1035
   455
      if (riscos_backbuffer == 0) riscos_backbuffer = 1;
slouken@630
   456
slouken@1336
   457
      if (buffer && old_alloc_bank) SDL_free(old_alloc_bank);
slouken@630
   458
slouken@630
   459
      return 1;
slouken@630
   460
   } else
slouken@630
   461
   {
slouken@630
   462
      /* Drop back to full screen mode on failure */
slouken@630
   463
      this->hidden->bank[0] = old_bank[0];
slouken@630
   464
      this->hidden->bank[1] = old_bank[1];
slouken@630
   465
      this->hidden->alloc_bank = old_alloc_bank;
slouken@1336
   466
      if (buffer) SDL_free(buffer);
slouken@630
   467
      
slouken@630
   468
      RISCOS_StoreWimpMode();
slouken@630
   469
      FULLSCREEN_SetMode(width, height, bpp);
slouken@630
   470
   }
slouken@630
   471
slouken@630
   472
   return 0;
slouken@630
   473
}