comparison src/video/riscos/SDL_riscossprite.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents d910939febfa
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
32 #include "swis.h" 32 #include "swis.h"
33 33
34 #include "SDL_stdinc.h" 34 #include "SDL_stdinc.h"
35 #include "SDL_riscosvideo.h" 35 #include "SDL_riscosvideo.h"
36 36
37 extern void WIMP_ReadModeInfo(_THIS); 37 extern void WIMP_ReadModeInfo (_THIS);
38 38
39 void WIMP_PaletteChanged(_THIS); 39 void WIMP_PaletteChanged (_THIS);
40 40
41 41
42 /* Create sprite buffer for screen */ 42 /* Create sprite buffer for screen */
43 43
44 unsigned char *WIMP_CreateBuffer(int width, int height, int bpp) 44 unsigned char *
45 { 45 WIMP_CreateBuffer (int width, int height, int bpp)
46 int size; 46 {
47 char sprite_name[12] = "display"; 47 int size;
48 unsigned char *buffer; 48 char sprite_name[12] = "display";
49 _kernel_swi_regs regs; 49 unsigned char *buffer;
50 int bytesPerPixel; 50 _kernel_swi_regs regs;
51 int bytesPerRow; 51 int bytesPerPixel;
52 int offsetToSpriteData = 60; 52 int bytesPerRow;
53 53 int offsetToSpriteData = 60;
54 switch(bpp) 54
55 { 55 switch (bpp) {
56 case 32: bytesPerPixel = 4; break; 56 case 32:
57 case 16: bytesPerPixel = 2; break; 57 bytesPerPixel = 4;
58 case 8: 58 break;
59 bytesPerPixel = 1; 59 case 16:
60 offsetToSpriteData += 2048; /* Add in size of palette */ 60 bytesPerPixel = 2;
61 break; 61 break;
62 default: 62 case 8:
63 return NULL; 63 bytesPerPixel = 1;
64 break; 64 offsetToSpriteData += 2048; /* Add in size of palette */
65 } 65 break;
66 66 default:
67 bytesPerRow = bytesPerPixel * width; 67 return NULL;
68 68 break;
69 if ((bytesPerRow & 3) != 0) 69 }
70 { 70
71 bytesPerRow += 4 - (bytesPerRow & 3); 71 bytesPerRow = bytesPerPixel * width;
72 } 72
73 size = bytesPerRow * height; 73 if ((bytesPerRow & 3) != 0) {
74 74 bytesPerRow += 4 - (bytesPerRow & 3);
75 buffer = SDL_malloc( (size_t) size + offsetToSpriteData ); 75 }
76 if (!buffer) return NULL; 76 size = bytesPerRow * height;
77 77
78 /* Initialise a sprite area */ 78 buffer = SDL_malloc ((size_t) size + offsetToSpriteData);
79 79 if (!buffer)
80 *(unsigned int *)buffer = size + offsetToSpriteData; 80 return NULL;
81 *(unsigned int *)(buffer + 8) = 16; 81
82 82 /* Initialise a sprite area */
83 regs.r[0] = 256+9; 83
84 regs.r[1] = (unsigned int)buffer; 84 *(unsigned int *) buffer = size + offsetToSpriteData;
85 _kernel_swi(OS_SpriteOp, &regs, &regs); 85 *(unsigned int *) (buffer + 8) = 16;
86 86
87 regs.r[0] = 256+15; 87 regs.r[0] = 256 + 9;
88 regs.r[1] = (unsigned int)buffer; 88 regs.r[1] = (unsigned int) buffer;
89 regs.r[2] = (unsigned int)&sprite_name; 89 _kernel_swi (OS_SpriteOp, &regs, &regs);
90 regs.r[3] = 0; /* Palette flag: 0 = no palette */ 90
91 regs.r[4] = width; 91 regs.r[0] = 256 + 15;
92 regs.r[5] = height; 92 regs.r[1] = (unsigned int) buffer;
93 if (bpp == 8) 93 regs.r[2] = (unsigned int) &sprite_name;
94 { 94 regs.r[3] = 0; /* Palette flag: 0 = no palette */
95 /* Use old style mode number */ 95 regs.r[4] = width;
96 regs.r[6] = 28; /* 8bpp 90x90dpi */ 96 regs.r[5] = height;
97 } else 97 if (bpp == 8) {
98 { 98 /* Use old style mode number */
99 regs.r[6] = (((bpp == 16) ? 5 : 6) << 27) /* Type 6 = 32bpp sprite, 5 = 16bpp sprite */ 99 regs.r[6] = 28; /* 8bpp 90x90dpi */
100 | (90 << 14) /* Vertical dpi */ 100 } else {
101 | (90 << 1) /* Horizontal dpi */ 101 regs.r[6] = (((bpp == 16) ? 5 : 6) << 27) /* Type 6 = 32bpp sprite, 5 = 16bpp sprite */
102 | 1; /* Marker to distinguish between mode selectors and sprite modes */ 102 |(90 << 14) /* Vertical dpi */
103 } 103 |(90 << 1) /* Horizontal dpi */
104 if (_kernel_swi(OS_SpriteOp, &regs, &regs) == NULL) 104 |1; /* Marker to distinguish between mode selectors and sprite modes */
105 { 105 }
106 if (bpp == 8) 106 if (_kernel_swi (OS_SpriteOp, &regs, &regs) == NULL) {
107 { 107 if (bpp == 8) {
108 /* Modify sprite to take into account 256 colour palette */ 108 /* Modify sprite to take into account 256 colour palette */
109 int *sprite = (int *)(buffer + 16); 109 int *sprite = (int *) (buffer + 16);
110 /* Adjust sprite offsets */ 110 /* Adjust sprite offsets */
111 sprite[0] += 2048; 111 sprite[0] += 2048;
112 sprite[8] += 2048; 112 sprite[8] += 2048;
113 sprite[9] += 2048; 113 sprite[9] += 2048;
114 /* Adjust sprite area next free pointer */ 114 /* Adjust sprite area next free pointer */
115 (*(int *)(buffer+12)) += 2048; 115 (*(int *) (buffer + 12)) += 2048;
116 116
117 /* Don't need to set up palette as SDL sets up the default 117 /* Don't need to set up palette as SDL sets up the default
118 256 colour palette */ 118 256 colour palette */
119 /* { 119 /* {
120 int *pal = sprite + 11; 120 int *pal = sprite + 11;
121 unsigned int j; 121 unsigned int j;
122 unsigned int entry; 122 unsigned int entry;
123 for (j = 0; j < 255; j++) 123 for (j = 0; j < 255; j++)
126 *pal++ = entry; 126 *pal++ = entry;
127 *pal++ = entry; 127 *pal++ = entry;
128 } 128 }
129 } 129 }
130 */ 130 */
131 } 131 }
132 } else 132 } else {
133 { 133 SDL_free (buffer);
134 SDL_free(buffer); 134 buffer = NULL;
135 buffer = NULL; 135 }
136 } 136
137 137 return buffer;
138 return buffer;
139 } 138 }
140 139
141 140
142 /* Setup translation buffers for the sprite plotting */ 141 /* Setup translation buffers for the sprite plotting */
143 142
144 void WIMP_SetupPlotInfo(_THIS) 143 void
145 { 144 WIMP_SetupPlotInfo (_THIS)
146 _kernel_swi_regs regs; 145 {
147 int *sprite = ((int *)this->hidden->bank[1])+4; 146 _kernel_swi_regs regs;
148 147 int *sprite = ((int *) this->hidden->bank[1]) + 4;
149 regs.r[0] = (unsigned int)this->hidden->bank[1]; 148
150 regs.r[1] = (unsigned int)sprite; 149 regs.r[0] = (unsigned int) this->hidden->bank[1];
151 regs.r[2] = -1; /* Current mode */ 150 regs.r[1] = (unsigned int) sprite;
152 regs.r[3] = -1; /* Current palette */ 151 regs.r[2] = -1; /* Current mode */
153 regs.r[4] = 0; /* Get size of buffer */ 152 regs.r[3] = -1; /* Current palette */
154 regs.r[5] = 1|2|16; /* R1 - pointer to sprite and can use full palette words */ 153 regs.r[4] = 0; /* Get size of buffer */
155 regs.r[6] = 0; 154 regs.r[5] = 1 | 2 | 16; /* R1 - pointer to sprite and can use full palette words */
156 regs.r[7] = 0; 155 regs.r[6] = 0;
157 156 regs.r[7] = 0;
158 if (this->hidden->pixtrans) SDL_free(this->hidden->pixtrans); 157
159 this->hidden->pixtrans = 0; 158 if (this->hidden->pixtrans)
160 159 SDL_free (this->hidden->pixtrans);
161 /* Get the size required for the buffer */ 160 this->hidden->pixtrans = 0;
162 _kernel_swi(ColourTrans_GenerateTable, &regs, &regs); 161
163 if (regs.r[4]) 162 /* Get the size required for the buffer */
164 { 163 _kernel_swi (ColourTrans_GenerateTable, &regs, &regs);
165 this->hidden->pixtrans = SDL_malloc(regs.r[4]); 164 if (regs.r[4]) {
166 165 this->hidden->pixtrans = SDL_malloc (regs.r[4]);
167 regs.r[4] = (unsigned int)this->hidden->pixtrans; 166
168 /* Actually read the buffer */ 167 regs.r[4] = (unsigned int) this->hidden->pixtrans;
169 _kernel_swi(ColourTrans_GenerateTable, &regs, &regs); 168 /* Actually read the buffer */
170 } 169 _kernel_swi (ColourTrans_GenerateTable, &regs, &regs);
170 }
171 } 171 }
172 172
173 /* Plot the sprite in the given context */ 173 /* Plot the sprite in the given context */
174 void WIMP_PlotSprite(_THIS, int x, int y) 174 void
175 { 175 WIMP_PlotSprite (_THIS, int x, int y)
176 _kernel_swi_regs regs; 176 {
177 _kernel_oserror *err; 177 _kernel_swi_regs regs;
178 178 _kernel_oserror *err;
179 regs.r[0] = 52 + 512; 179
180 regs.r[1] = (unsigned int)this->hidden->bank[1]; 180 regs.r[0] = 52 + 512;
181 regs.r[2] = (unsigned int)this->hidden->bank[1]+16; 181 regs.r[1] = (unsigned int) this->hidden->bank[1];
182 regs.r[3] = x; 182 regs.r[2] = (unsigned int) this->hidden->bank[1] + 16;
183 regs.r[4] = y; 183 regs.r[3] = x;
184 regs.r[5] = 0|32; /* Overwrite screen and pixtrans contains wide colour entries */ 184 regs.r[4] = y;
185 regs.r[6] = 0; /* No scale factors i.e. 1:1 */ 185 regs.r[5] = 0 | 32; /* Overwrite screen and pixtrans contains wide colour entries */
186 regs.r[7] = (int)this->hidden->pixtrans; 186 regs.r[6] = 0; /* No scale factors i.e. 1:1 */
187 187 regs.r[7] = (int) this->hidden->pixtrans;
188 if ((err = _kernel_swi(OS_SpriteOp, &regs, &regs)) != 0) 188
189 { 189 if ((err = _kernel_swi (OS_SpriteOp, &regs, &regs)) != 0) {
190 int *p = (int *)this->hidden->pixtrans; 190 int *p = (int *) this->hidden->pixtrans;
191 printf("OS_SpriteOp failed \n%s\n",err->errmess); 191 printf ("OS_SpriteOp failed \n%s\n", err->errmess);
192 printf("pixtrans %d\n", (int)this->hidden->pixtrans); 192 printf ("pixtrans %d\n", (int) this->hidden->pixtrans);
193 printf("%x %x %x\n", p[0], p[1], p[2]); 193 printf ("%x %x %x\n", p[0], p[1], p[2]);
194 } 194 }
195 } 195 }
196 196
197 197
198 /* Wimp mode has changes so update colour mapping and pixel sizes 198 /* Wimp mode has changes so update colour mapping and pixel sizes
199 of windows and the sprites they plot */ 199 of windows and the sprites they plot */
200 200
201 void WIMP_ModeChanged(_THIS) 201 void
202 { 202 WIMP_ModeChanged (_THIS)
203 int oldXeig = this->hidden->xeig; 203 {
204 int oldYeig = this->hidden->yeig; 204 int oldXeig = this->hidden->xeig;
205 205 int oldYeig = this->hidden->yeig;
206 WIMP_ReadModeInfo(this); 206
207 207 WIMP_ReadModeInfo (this);
208 if (oldXeig == this->hidden->xeig && oldYeig == this->hidden->yeig) 208
209 { 209 if (oldXeig == this->hidden->xeig && oldYeig == this->hidden->yeig) {
210 /* Only need to update the palette */ 210 /* Only need to update the palette */
211 WIMP_PaletteChanged(this); 211 WIMP_PaletteChanged (this);
212 } else 212 } else {
213 { 213 _kernel_swi_regs regs;
214 _kernel_swi_regs regs; 214 int window_state[9];
215 int window_state[9]; 215 int extent[4];
216 int extent[4]; 216 int currWidth, currHeight;
217 int currWidth, currHeight; 217 int newWidth, newHeight;
218 int newWidth, newHeight; 218
219 219 /* Need to resize windows and update the palette */
220 /* Need to resize windows and update the palette */ 220 WIMP_SetupPlotInfo (this);
221 WIMP_SetupPlotInfo(this); 221
222 222
223 223 window_state[0] = this->hidden->window_handle;
224 window_state[0] = this->hidden->window_handle; 224 regs.r[1] = (unsigned int) window_state;
225 regs.r[1] = (unsigned int)window_state; 225 _kernel_swi (Wimp_GetWindowState, &regs, &regs);
226 _kernel_swi(Wimp_GetWindowState, &regs, &regs); 226
227 227 currWidth = window_state[3] - window_state[1];
228 currWidth = window_state[3] - window_state[1]; 228 currHeight = window_state[4] - window_state[2];
229 currHeight = window_state[4] - window_state[2]; 229
230 230 newWidth = (currWidth >> oldXeig) << this->hidden->xeig;
231 newWidth = (currWidth >> oldXeig) << this->hidden->xeig; 231 newHeight = (currHeight >> oldYeig) << this->hidden->yeig;
232 newHeight = (currHeight >> oldYeig) << this->hidden->yeig; 232 /* Need to avoid extent getting too small for visible part
233 /* Need to avoid extent getting too small for visible part 233 of window */
234 of window */ 234 extent[0] = 0;
235 extent[0] = 0; 235 if (currHeight <= newHeight) {
236 if (currHeight <= newHeight) 236 extent[1] = -newHeight;
237 { 237 } else {
238 extent[1] = -newHeight; 238 extent[1] = -currHeight;
239 } else 239 }
240 { 240 if (currWidth <= newWidth) {
241 extent[1] = -currHeight; 241 extent[2] = newWidth;
242 } 242 } else {
243 if (currWidth <= newWidth) 243 extent[2] = currWidth;
244 { 244 }
245 extent[2] = newWidth; 245 extent[3] = 0;
246 } else 246
247 { 247 regs.r[0] = this->hidden->window_handle;
248 extent[2] = currWidth; 248 regs.r[1] = (int) extent;
249 } 249 _kernel_swi (Wimp_SetExtent, &regs, &regs);
250 extent[3] = 0; 250
251 251 /*TODO: May need to set flag to resize window on next open */
252 regs.r[0] = this->hidden->window_handle; 252 }
253 regs.r[1] = (int)extent;
254 _kernel_swi(Wimp_SetExtent, &regs, &regs);
255
256 /*TODO: May need to set flag to resize window on next open */
257 }
258 } 253 }
259 254
260 /* Palette has changed so update palettes used for windows sprites */ 255 /* Palette has changed so update palettes used for windows sprites */
261 256
262 void WIMP_PaletteChanged(_THIS) 257 void
263 { 258 WIMP_PaletteChanged (_THIS)
264 WIMP_SetupPlotInfo(this); 259 {
265 } 260 WIMP_SetupPlotInfo (this);
261 }
262
263 /* vi: set ts=4 sw=4 expandtab: */