/* Set up video mode */
SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface *current,
				int width, int height, int bpp, Uint32 flags)
{
	if (flags & SDL_FULLSCREEN)
	{
	    RISCOS_StoreWimpMode();
		/* Dump wimp window on switch to full screen */
  	    if (this->hidden->window_handle) WIMP_DeleteWindow(this);

		return FULLSCREEN_SetVideoMode(this, current, width, height, bpp, flags);
	} else
	{
	    RISCOS_RestoreWimpMode();
		return WIMP_SetVideoMode(this, current, width, height, bpp, flags);
	}
}
/* Setup the Window to display the surface */
unsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface)
{
	_kernel_swi_regs regs;
	int window_data[23];
    int	*window_block = window_data+1;
	int x = (this->hidden->screen_width - surface->w) / 2;
	int y = (this->hidden->screen_height - surface->h) / 2;
	int xeig = this->hidden->xeig;
	int yeig = this->hidden->yeig;

    mouseInWindow = 0;
    
	/* Always delete the window and recreate on a change */
	if (this->hidden->window_handle) WIMP_DeleteWindow(this);

	/* Setup window co-ordinates */
   window_block[0] = x << xeig;
   window_block[1] = y << yeig;
   window_block[2] = window_block[0] + (surface->w << xeig);
   window_block[3] = window_block[1] + (surface->h << yeig);

   
   window_block[4] = 0;				  /* Scroll offsets */
   window_block[5] = 0;
   window_block[6] = -1;			  /* Open on top of window stack */

   window_block[7] = 0x85040042;      /* Window flags */
   if (riscos_closeaction != 0) window_block[7] |= 0x2000000;

   /* TODO: Take into account surface->flags */

   window_block[8] = 0xff070207;      /* Window colours */
   window_block[9] = 0x000c0103;
   window_block[10] = 0;                    /* Work area minimum */
   window_block[11] = -surface->h << yeig;
   window_block[12] = surface->w << xeig;   /* Work area maximum */
   window_block[13] = 0;
   window_block[14] = 0x2700013d;    /* Title icon flags */
   window_block[15] = 0x00003000;	 /* Work area flags - Mouse click down reported */
   window_block[16] = 1;             /* Sprite area control block pointer */
   window_block[17] = 0x00100010;	 /* Minimum window size (width & height) (16x16)*/
   window_block[18] = (int)this->hidden->title;    /* Title data */
   window_block[19] = -1;
   window_block[20] = 256;
   window_block[21] = 0;			 /* Number of icons */

   regs.r[1] = (unsigned int)(window_block);
   
   /* Create the window */
   if (_kernel_swi(Wimp_CreateWindow, &regs, &regs) == NULL)
   {
	   this->hidden->window_handle = window_data[0] = regs.r[0];

	   /* Show the window on the screen */
	   regs.r[1] = (unsigned int)window_data;
       if (_kernel_swi(Wimp_OpenWindow, &regs, &regs) == NULL)
       {
          WIMP_SetFocus(this->hidden->window_handle);
       } else
       {
		  WIMP_DeleteWindow(this);
	   }
   }
   
   return this->hidden->window_handle;
}