src/video/riscos/SDL_riscossprite.c
changeset 630 550bccdf04bd
child 769 b8d311d90021
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/riscos/SDL_riscossprite.c	Thu May 29 04:44:13 2003 +0000
     1.3 @@ -0,0 +1,263 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +/*
    1.27 +     File added by Alan Buckley (alan_baa@hotmail.com) for RISCOS compatability
    1.28 +	 27 March 2003
    1.29 +
    1.30 +     Implements Sprite plotting code for wimp display.window
    1.31 +*/
    1.32 +
    1.33 +#include <stdlib.h>
    1.34 +#include "kernel.h"
    1.35 +#include "swis.h"
    1.36 +#include "SDL_riscosvideo.h"
    1.37 +
    1.38 +extern void WIMP_ReadModeInfo(_THIS);
    1.39 +
    1.40 +void WIMP_PaletteChanged(_THIS);
    1.41 +
    1.42 +
    1.43 +/* Create sprite buffer for screen */
    1.44 +
    1.45 +unsigned char *WIMP_CreateBuffer(int width, int height, int bpp)
    1.46 +{
    1.47 +	int size;
    1.48 +	char sprite_name[12] = "display";
    1.49 +	unsigned char *buffer;
    1.50 +	_kernel_swi_regs regs;
    1.51 +	int bytesPerPixel;
    1.52 +	int bytesPerRow;
    1.53 +	int offsetToSpriteData = 60;
    1.54 +
    1.55 +	switch(bpp)
    1.56 +	{
    1.57 +	case 32: bytesPerPixel = 4; break;
    1.58 +	case 16: bytesPerPixel = 2; break;
    1.59 +	case 8:
    1.60 +	    bytesPerPixel = 1;
    1.61 +	    offsetToSpriteData += 2048; /* Add in size of palette */
    1.62 +	    break;
    1.63 +	default:
    1.64 +		return NULL;
    1.65 +		break;
    1.66 +	}
    1.67 +
    1.68 +	bytesPerRow = bytesPerPixel * width;
    1.69 +
    1.70 +	if ((bytesPerRow & 3) != 0)
    1.71 +	{
    1.72 +		bytesPerRow += 4 - (bytesPerRow & 3);
    1.73 +	}
    1.74 +	size = bytesPerRow * height;
    1.75 +
    1.76 +	buffer = malloc( (size_t) size + offsetToSpriteData );
    1.77 +	if (!buffer) return NULL;
    1.78 +
    1.79 +   /* Initialise a sprite area */
    1.80 +
    1.81 +	*(unsigned int *)buffer		= size + offsetToSpriteData;
    1.82 +	*(unsigned int *)(buffer + 8)	= 16;
    1.83 +
    1.84 +	regs.r[0] = 256+9;
    1.85 +	regs.r[1] = (unsigned int)buffer;
    1.86 +   _kernel_swi(OS_SpriteOp, &regs, &regs);
    1.87 +
    1.88 +	regs.r[0] = 256+15;
    1.89 +	regs.r[1] = (unsigned int)buffer;
    1.90 +	regs.r[2] = (unsigned int)&sprite_name;
    1.91 +	regs.r[3] = 0; /* Palette flag: 0 = no palette */
    1.92 +	regs.r[4] = width;
    1.93 +	regs.r[5] = height;
    1.94 +	if (bpp == 8)
    1.95 +	{
    1.96 +		/* Use old style mode number */
    1.97 +		regs.r[6] = 28; /* 8bpp 90x90dpi */
    1.98 +	} else
    1.99 +	{
   1.100 +		regs.r[6] = (((bpp == 16) ? 5 : 6) << 27) /* Type 6 = 32bpp sprite, 5 = 16bpp sprite */
   1.101 +					| (90 << 14) /* Vertical dpi */
   1.102 +					| (90 << 1)  /* Horizontal dpi */
   1.103 +					| 1; /* Marker to distinguish between mode selectors and sprite modes */
   1.104 +	}
   1.105 +   if (_kernel_swi(OS_SpriteOp, &regs, &regs) == NULL)
   1.106 +   {
   1.107 +       if (bpp == 8)
   1.108 +       {
   1.109 +          /* Modify sprite to take into account 256 colour palette */
   1.110 +          int *sprite = (int *)(buffer + 16);
   1.111 +          /* Adjust sprite offsets */
   1.112 +          sprite[0] += 2048;
   1.113 +          sprite[8] += 2048;
   1.114 +          sprite[9] += 2048;
   1.115 +          /* Adjust sprite area next free pointer */
   1.116 +          (*(int *)(buffer+12)) += 2048;
   1.117 +
   1.118 +          /* Don't need to set up palette as SDL sets up the default
   1.119 +             256 colour palette */
   1.120 +/*          {
   1.121 +             int *pal = sprite + 11;
   1.122 +             unsigned int j;
   1.123 +             unsigned int entry;
   1.124 +             for (j = 0; j < 255; j++)
   1.125 +             {
   1.126 +                entry = (j << 24) | (j << 16) | (j << 8);
   1.127 +                *pal++ = entry;
   1.128 +                *pal++ = entry;
   1.129 +             }
   1.130 +          }
   1.131 +*/
   1.132 +       }
   1.133 +   } else
   1.134 +   {
   1.135 +      free(buffer);
   1.136 +      buffer = NULL;
   1.137 +   }
   1.138 +
   1.139 +   return buffer;
   1.140 +}
   1.141 +
   1.142 +
   1.143 +/* Setup translation buffers for the sprite plotting */
   1.144 +
   1.145 +void WIMP_SetupPlotInfo(_THIS)
   1.146 +{
   1.147 +   _kernel_swi_regs regs;
   1.148 +   int *sprite = ((int *)this->hidden->bank[1])+4;
   1.149 +
   1.150 +   regs.r[0] = (unsigned int)this->hidden->bank[1];
   1.151 +   regs.r[1] = (unsigned int)sprite;
   1.152 +   regs.r[2] = -1; /* Current mode */
   1.153 +   regs.r[3] = -1; /* Current palette */
   1.154 +   regs.r[4] = 0; /* Get size of buffer */
   1.155 +   regs.r[5] = 1|2|16; /* R1 - pointer to sprite and can use full palette words */
   1.156 +   regs.r[6] = 0;
   1.157 +   regs.r[7] = 0;
   1.158 +
   1.159 +   if (this->hidden->pixtrans) free(this->hidden->pixtrans);
   1.160 +   this->hidden->pixtrans = 0;
   1.161 +
   1.162 +   /* Get the size required for the buffer */
   1.163 +   _kernel_swi(ColourTrans_GenerateTable, &regs, &regs);
   1.164 +   if (regs.r[4])
   1.165 +   {
   1.166 +      this->hidden->pixtrans = malloc(regs.r[4]);
   1.167 +    
   1.168 +      regs.r[4] = (unsigned int)this->hidden->pixtrans;
   1.169 +      /* Actually read the buffer */
   1.170 +      _kernel_swi(ColourTrans_GenerateTable, &regs, &regs);
   1.171 +   }
   1.172 +}
   1.173 +
   1.174 +/* Plot the sprite in the given context */
   1.175 +void WIMP_PlotSprite(_THIS, int x, int y)
   1.176 +{
   1.177 +   _kernel_swi_regs regs;
   1.178 +   _kernel_oserror *err;
   1.179 +
   1.180 +   regs.r[0] =  52 + 512;
   1.181 +   regs.r[1] = (unsigned int)this->hidden->bank[1];
   1.182 +   regs.r[2] = (unsigned int)this->hidden->bank[1]+16;
   1.183 +   regs.r[3] = x;
   1.184 +   regs.r[4] = y;
   1.185 +   regs.r[5] = 0|32; /* Overwrite screen and pixtrans contains wide colour entries */
   1.186 +   regs.r[6] = 0; /* No scale factors i.e. 1:1 */
   1.187 +   regs.r[7] = (int)this->hidden->pixtrans;
   1.188 +
   1.189 +   if ((err = _kernel_swi(OS_SpriteOp, &regs, &regs)) != 0)
   1.190 +   {
   1.191 +      int *p = (int *)this->hidden->pixtrans;
   1.192 +      printf("OS_SpriteOp failed \n%s\n",err->errmess);
   1.193 +      printf("pixtrans %d\n", (int)this->hidden->pixtrans);
   1.194 +      printf("%x %x %x\n", p[0], p[1], p[2]);
   1.195 +   }
   1.196 +}
   1.197 +
   1.198 +
   1.199 +/* Wimp mode has changes so update colour mapping and pixel sizes 
   1.200 +   of windows and the sprites they plot */
   1.201 +
   1.202 +void WIMP_ModeChanged(_THIS)
   1.203 +{
   1.204 +	int oldXeig = this->hidden->xeig;
   1.205 +	int oldYeig = this->hidden->yeig;
   1.206 +
   1.207 +	WIMP_ReadModeInfo(this);
   1.208 +
   1.209 +	if (oldXeig == this->hidden->xeig && oldYeig == this->hidden->yeig)
   1.210 +	{
   1.211 +		/* Only need to update the palette */
   1.212 +		WIMP_PaletteChanged(this);
   1.213 +	} else
   1.214 +	{
   1.215 +		_kernel_swi_regs regs;
   1.216 +		int window_state[9];
   1.217 +		int extent[4];
   1.218 +		int currWidth, currHeight;
   1.219 +		int newWidth, newHeight;
   1.220 +		
   1.221 +		/* Need to resize windows and update the palette */
   1.222 +		WIMP_SetupPlotInfo(this);
   1.223 +
   1.224 +
   1.225 +		window_state[0] = this->hidden->window_handle;
   1.226 +		regs.r[1] = (unsigned int)window_state;
   1.227 +		_kernel_swi(Wimp_GetWindowState, &regs, &regs);
   1.228 +						
   1.229 +		currWidth = window_state[3] - window_state[1];
   1.230 +		currHeight = window_state[4] - window_state[2];
   1.231 +		
   1.232 +		newWidth = (currWidth >> oldXeig) << this->hidden->xeig;
   1.233 +		newHeight = (currHeight >> oldYeig) << this->hidden->yeig;
   1.234 +		/* Need to avoid extent getting too small for visible part
   1.235 +		of window */
   1.236 +		extent[0] = 0;
   1.237 +		if (currHeight <= newHeight)
   1.238 +		{
   1.239 +			extent[1] = -newHeight;
   1.240 +		} else
   1.241 +		{
   1.242 +			extent[1] = -currHeight;
   1.243 +		}
   1.244 +		if (currWidth <= newWidth)
   1.245 +		{
   1.246 +			extent[2] = newWidth;
   1.247 +		} else
   1.248 +		{
   1.249 +			extent[2] = currWidth;
   1.250 +		}
   1.251 +		extent[3] = 0;
   1.252 +		
   1.253 +		regs.r[0] = this->hidden->window_handle;
   1.254 +		regs.r[1] = (int)extent;
   1.255 +		_kernel_swi(Wimp_SetExtent, &regs, &regs);
   1.256 +
   1.257 +		/*TODO: May need to set flag to resize window on next open */
   1.258 +	}
   1.259 +}
   1.260 +
   1.261 +/* Palette has changed so update palettes used for windows sprites */
   1.262 +
   1.263 +void WIMP_PaletteChanged(_THIS)
   1.264 +{
   1.265 +	WIMP_SetupPlotInfo(this);
   1.266 +}