19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL - Simple DirectMedia Layer 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 1997-2012 Sam Lantinga 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is free software; you can redistribute it and/or 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modify it under the terms of the GNU Library General Public 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License as published by the Free Software Foundation; either 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall version 2 of the License, or (at your option) any later version. 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is distributed in the hope that it will be useful, 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall but WITHOUT ANY WARRANTY; without even the implied warranty of 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Library General Public License for more details. 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall You should have received a copy of the GNU Library General Public 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License along with this library; if not, write to the Free 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sam Lantinga 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slouken@libsdl.org 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h" 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 27 March 2003 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Implements RISC OS Wimp display. 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_video.h" 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_mouse.h" 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_sysvideo.h" 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_pixels_c.h" 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_events_c.h" 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_riscostask.h" 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_riscosvideo.h" 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_riscosevents_c.h" 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_riscosmouse_c.h" 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "kernel.h" 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "swis.h" 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Initialization/Query functions */ 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Rect **WIMP_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint WIMP_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIMP_SetWMCaption(_THIS, const char *title, const char *icon); 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern unsigned char *WIMP_CreateBuffer(int width, int height, int bpp); 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern void WIMP_PumpEvents(_THIS); 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern void WIMP_PlotSprite(_THIS, int x, int y); 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern void WIMP_SetupPlotInfo(_THIS); 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern void WIMP_SetFocus(int win); 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* etc. */ 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void WIMP_UpdateRects(_THIS, int numrects, SDL_Rect *rects); 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* RISC OS Wimp handling helpers */ 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIMP_ReadModeInfo(_THIS); 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallunsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface); 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIMP_SetDeviceMode(_THIS); 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIMP_DeleteWindow(_THIS); 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* FULLSCREEN function required for wimp/fullscreen toggling */ 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern int FULLSCREEN_SetMode(int width, int height, int bpp); 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Currently need to set this up here as it only works if you 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall start up in a Wimp mode */ 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern int RISCOS_ToggleFullScreen(_THIS, int fullscreen); 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern int riscos_backbuffer; 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern int mouseInWindow; 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern int riscos_closeaction; 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Following needed to ensure window is shown immediately */ 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern int hasFocus; 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern void WIMP_Poll(_THIS, int waitTime); 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current, 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int width, int height, int bpp, Uint32 flags) 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 Rmask = 0; 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 Gmask = 0; 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 Bmask = 0; 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall char *buffer = NULL; 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int bytesPerPixel = 1; 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Don't support double buffering in Wimp mode */ 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags &= ~SDL_DOUBLEBUF; 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags &= ~SDL_HWSURFACE; 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall switch(bpp) 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 8: 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Emulated palette using ColourTrans */ 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall flags |= SDL_HWPALETTE; 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 15: 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 16: 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Bmask = 0x00007c00; 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Gmask = 0x000003e0; 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Rmask = 0x0000001f; 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bytesPerPixel = 2; 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall case 32: 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Bmask = 0x00ff0000; 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Gmask = 0x0000ff00; 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Rmask = 0x000000ff; 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall bytesPerPixel = 4; 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall default: 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Pixel depth not supported"); 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return NULL; 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall break; 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* printf("Setting mode %dx%d\n", width, height);*/ 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Allocate the new pixel format for the screen */ 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) { 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Couldn't allocate new pixel format for requested mode"); 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(NULL); 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Set up the new mode framebuffer */ 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->w = width; 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->height = current->h = height; 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (bpp == 15) bpp = 16; 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall buffer = WIMP_CreateBuffer(width, height, bpp); 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (buffer == NULL) 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Couldn't create sprite for video memory"); 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return (NULL); 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->bank[0] = buffer + 60; /* Start of sprite data */ 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (bpp == 8) this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */ 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->bank[1] = buffer; /* Start of buffer */ 1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Remember sprite buffer so it can be freed later */ 1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (this->hidden->alloc_bank) SDL_free(this->hidden->alloc_bank); 1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->alloc_bank = buffer; 1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->pitch = width * bytesPerPixel; 1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ((current->pitch & 3)) 1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Sprites are 32bit word aligned */ 1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->pitch += (4 - (current->pitch & 3)); 1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->flags = flags | SDL_PREALLOC; 1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WIMP_ReadModeInfo(this); 1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(this->hidden->bank[0], 0, height * current->pitch); 1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->current_bank = 0; 1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall current->pixels = this->hidden->bank[0]; 1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (WIMP_SetupWindow(this, current) == 0) 1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_SetError("Unable to create window to display surface"); 1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return NULL; 1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Reset device functions for the wimp */ 1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WIMP_SetDeviceMode(this); 1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Needs to set up plot info after window has been created */ 1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Not sure why, but plots don't work if I do it earlier */ 1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WIMP_SetupPlotInfo(this); 1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Poll until window is shown */ 1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We wait until it gets the focus, but give up after 5 seconds 1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall in case the focus is prevented in any way. 1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint32 now = SDL_GetTicks(); 1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while (!hasFocus && SDL_GetTicks() - now < 5000) 1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WIMP_Poll(this, 0); 1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* We're done */ 1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(current); 1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIMP_ReadModeInfo(_THIS) 2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi_regs regs; 2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int vars[6]; 2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int vals[5]; 2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vars[0] = 4; /* XEig */ 2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vars[1] = 5; /* YEig */ 2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vars[2] = 9; /* Log base 2 bpp */ 2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vars[3] = 11; /* Screen Width - 1 */ 2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vars[4] = 12; /* Screen Depth - 1 */ 2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall vars[5] = -1; /* Terminate list */ 2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[0] = (int)vars; 2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[1] = (int)vals; 2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi(OS_ReadVduVariables, ®s, ®s); 2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->xeig = vals[0]; 2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->yeig = vals[1]; 2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->screen_bpp = 1 << vals[2]; 2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->screen_width = vals[3] + 1; 2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->screen_height = vals[4] + 1; 2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Set device function to call the correct versions for running 2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall in a wimp window */ 2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIMP_SetDeviceMode(_THIS) 2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (this->UpdateRects == WIMP_UpdateRects) return; /* Already set up */ 2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->SetColors = WIMP_SetColors; 2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->UpdateRects = WIMP_UpdateRects; 2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->FlipHWSurface = NULL; 2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->SetCaption = WIMP_SetWMCaption; 2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->SetIcon = NULL; 2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->IconifyWindow = NULL; 2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->ShowWMCursor = WIMP_ShowWMCursor; 2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->WarpWMCursor = WIMP_WarpWMCursor; 2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->ToggleFullScreen = RISCOS_ToggleFullScreen; 2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->PumpEvents = WIMP_PumpEvents; 2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Setup the Window to display the surface */ 2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallunsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface) 2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi_regs regs; 2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int window_data[23]; 2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int *window_block = window_data+1; 2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int x = (this->hidden->screen_width - surface->w) / 2; 2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int y = (this->hidden->screen_height - surface->h) / 2; 2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int xeig = this->hidden->xeig; 2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int yeig = this->hidden->yeig; 2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall mouseInWindow = 0; 2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Always delete the window and recreate on a change */ 2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (this->hidden->window_handle) WIMP_DeleteWindow(this); 2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Setup window co-ordinates */ 2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[0] = x << xeig; 2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[1] = y << yeig; 2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[2] = window_block[0] + (surface->w << xeig); 2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[3] = window_block[1] + (surface->h << yeig); 2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[4] = 0; /* Scroll offsets */ 2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[5] = 0; 2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[6] = -1; /* Open on top of window stack */ 2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[7] = 0x85040042; /* Window flags */ 2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (riscos_closeaction != 0) window_block[7] |= 0x2000000; 2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* TODO: Take into account surface->flags */ 2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[8] = 0xff070207; /* Window colours */ 2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[9] = 0x000c0103; 2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[10] = 0; /* Work area minimum */ 2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[11] = -surface->h << yeig; 2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[12] = surface->w << xeig; /* Work area maximum */ 2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[13] = 0; 2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[14] = 0x2700013d; /* Title icon flags */ 2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[15] = 0x00003000; /* Work area flags - Mouse click down reported */ 2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[16] = 1; /* Sprite area control block pointer */ 2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[17] = 0x00100010; /* Minimum window size (width & height) (16x16)*/ 2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[18] = (int)this->hidden->title; /* Title data */ 2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[19] = -1; 2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[20] = 256; 2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall window_block[21] = 0; /* Number of icons */ 2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[1] = (unsigned int)(window_block); 2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Create the window */ 2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (_kernel_swi(Wimp_CreateWindow, ®s, ®s) == NULL) 2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->window_handle = window_data[0] = regs.r[0]; 2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Show the window on the screen */ 3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[1] = (unsigned int)window_data; 3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (_kernel_swi(Wimp_OpenWindow, ®s, ®s) == NULL) 3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WIMP_SetFocus(this->hidden->window_handle); 3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WIMP_DeleteWindow(this); 3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return this->hidden->window_handle; 3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Destroy the Window */ 3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIMP_DeleteWindow(_THIS) 3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi_regs regs; 3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[1] = (unsigned int)&(this->hidden->window_handle); 3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi(Wimp_DeleteWindow, ®s, ®s); 3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->window_handle = 0; 3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIMP_UpdateRects(_THIS, int numrects, SDL_Rect *rects) 3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi_regs regs; 3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int update_block[12]; 3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int xeig = this->hidden->xeig; 3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int yeig = this->hidden->yeig; 3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int j; 3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update_block[0] = this->hidden->window_handle; 3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (j = 0; j < numrects; j++) 3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update_block[1] = rects[j].x << xeig; /* Min X */ 3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update_block[4] = -(rects[j].y << yeig); 3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update_block[3] = update_block[1] + (rects[j].w << xeig); 3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update_block[2] = update_block[4] - (rects[j].h << yeig); 3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[1] = (int)update_block; 3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Update window can fail if called before first poll */ 3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (_kernel_swi(Wimp_UpdateWindow, ®s, ®s) == 0) 3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall while (regs.r[0]) 3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WIMP_PlotSprite(this, update_block[1], update_block[2]); 3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi(Wimp_GetRectangle, ®s, ®s); 3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint WIMP_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall unsigned int *pal = (unsigned int *)(this->hidden->bank[1]+60); 3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int j; 3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Rect update; 3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal += firstcolor*2; 3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall for (j = 0; j < ncolors; j++) 3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *pal = (((unsigned int)colors->r) << 8) 3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + (((unsigned int)colors->g) << 16) 3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall + (((unsigned int)colors->b) << 24); 3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal[1] = *pal; 3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall pal += 2; 3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall colors++; 3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WIMP_SetupPlotInfo(this); 3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Need to refresh the window */ 3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update.x = 0; 3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update.y = 0; 3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update.w = SDL_VideoSurface->w; 3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall update.h = SDL_VideoSurface->h; 3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WIMP_UpdateRects(this, 1, &update); 3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 1; 3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIMP_SetWMCaption(_THIS, const char *title, const char *icon) 3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi_regs regs; 3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_strlcpy(this->hidden->title, title, SDL_arraysize(this->hidden->title)); 3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (RISCOS_GetWimpVersion() < 380) 3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int block[6]; 3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[1] = (int)block; 3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi(Wimp_GetCaretPosition, ®s, ®s); 3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (block[0] == (int)this->hidden->window_handle) 3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[0] = -1; 3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi(Wimp_SetCaretPosition, ®s,®s); 4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[0] = this->hidden->window_handle; 4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[1] = -1; 4049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[2] = -1; 4059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[3] = -1; 4069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi(Wimp_SetCaretPosition, ®s,®s); 4079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[0] = block[0]; 4099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[1] = block[1]; 4109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[2] = block[2]; 4119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[3] = block[3]; 4129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[4] = block[4]; 4139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[5] = block[5]; 4149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi(Wimp_SetCaretPosition, ®s,®s); 4159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 4169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 4179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[0] = this->hidden->window_handle; 4189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[1] = 0x4b534154; /* "TASK" */ 4199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[2] = 3; /* Redraw title */ 4209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi(Wimp_ForceRedraw, ®s, ®s); 4219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 4239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid WIMP_RefreshDesktop(_THIS) 4259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 4269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int width = this->hidden->screen_width << this->hidden->xeig; 4279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int height = this->hidden->screen_height << this->hidden->yeig; 4289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi_regs regs; 4299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[0] = -1; /* Whole screen */ 4309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[1] = 0; 4319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[2] = 0; 4329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[3] = width; 4339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall regs.r[4] = height; 4349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall _kernel_swi(Wimp_ForceRedraw, ®s, ®s); 4359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 4369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Toggle to window from full screen */ 4389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint WIMP_ToggleFromFullScreen(_THIS) 4399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 4409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int width = this->screen->w; 4419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int height = this->screen->h; 4429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int bpp = this->screen->format->BitsPerPixel; 4439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall char *buffer = NULL; 4449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall char *old_bank[2]; 4459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall char *old_alloc_bank; 4469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Ensure flags are OK */ 4489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->screen->flags &= ~(SDL_DOUBLEBUF|SDL_HWSURFACE); 4499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (this->hidden->bank[0] == this->hidden->alloc_bank || riscos_backbuffer == 0) 4519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 4529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Need to create a sprite for the screen and copy the data to it */ 4539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall char *data; 4549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall buffer = WIMP_CreateBuffer(width, height, bpp); 4559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall data = buffer + 60; /* Start of sprite data */ 4569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (bpp == 8) data += 2048; /* 8bpp sprite have palette first */ 4579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (buffer == NULL) return 0; 4599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memcpy(data, this->hidden->bank[0], width * height * this->screen->format->BytesPerPixel); 4609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* else We've switch to full screen before so we already have a sprite */ 4629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall old_bank[0] = this->hidden->bank[0]; 4649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall old_bank[1] = this->hidden->bank[1]; 4659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall old_alloc_bank = this->hidden->alloc_bank; 4669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (buffer != NULL) this->hidden->alloc_bank = buffer; 4689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->bank[1] = this->hidden->alloc_bank; 4709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->bank[0] = this->hidden->bank[1] + 60; /* Start of sprite data */ 4719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (bpp == 8) this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */ 4729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->current_bank = 0; 4749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->screen->pixels = this->hidden->bank[0]; 4759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall RISCOS_RestoreWimpMode(); 4779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WIMP_ReadModeInfo(this); 4789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (WIMP_SetupWindow(this, this->screen)) 4799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 4809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WIMP_SetDeviceMode(this); 4819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall WIMP_SetupPlotInfo(this); 4829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (riscos_backbuffer == 0) riscos_backbuffer = 1; 4849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (buffer && old_alloc_bank) SDL_free(old_alloc_bank); 4869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 1; 4889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else 4899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 4909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Drop back to full screen mode on failure */ 4919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->bank[0] = old_bank[0]; 4929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->bank[1] = old_bank[1]; 4939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall this->hidden->alloc_bank = old_alloc_bank; 4949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (buffer) SDL_free(buffer); 4959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 4969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall RISCOS_StoreWimpMode(); 4979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall FULLSCREEN_SetMode(width, height, bpp); 4989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 4999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 5009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 0; 5019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 502