comparison src/video/riscos/SDL_riscosFullScreenVideo.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents d910939febfa
children 99210400e8b9
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
45 #include "unixlib/local.h" 45 #include "unixlib/local.h"
46 46
47 /* Private structures */ 47 /* Private structures */
48 typedef struct tagScreenModeBlock 48 typedef struct tagScreenModeBlock
49 { 49 {
50 int flags; // mode selector flags, bit 0 = 1, bit 1-7 format specifier, 8-31 reserved 50 int flags; // mode selector flags, bit 0 = 1, bit 1-7 format specifier, 8-31 reserved
51 int x_pixels; 51 int x_pixels;
52 int y_pixels; 52 int y_pixels;
53 int pixel_depth; // 2^pixel_depth = bpp,i.e. 0 = 1, 1 = 2, 4 = 16, 5 = 32 53 int pixel_depth; // 2^pixel_depth = bpp,i.e. 0 = 1, 1 = 2, 4 = 16, 5 = 32
54 int frame_rate; // -1 use first match 54 int frame_rate; // -1 use first match
55 int mode_vars[5]; // array of index, value pairs terminated by -1 55 int mode_vars[5]; // array of index, value pairs terminated by -1
56 } SCREENMODEBLOCK; 56 } SCREENMODEBLOCK;
57 57
58 58
59 /* Helper functions */ 59 /* Helper functions */
60 void FULLSCREEN_SetDeviceMode(_THIS); 60 void FULLSCREEN_SetDeviceMode(_THIS);
61 int FULLSCREEN_SetMode(int width, int height, int bpp); 61 int FULLSCREEN_SetMode(int width, int height, int bpp);
62 void FULLSCREEN_SetupBanks(_THIS); 62 void FULLSCREEN_SetupBanks(_THIS);
63 63
64 /* SDL video device functions for fullscreen mode */ 64 /* SDL video device functions for fullscreen mode */
65 static int FULLSCREEN_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); 65 static int FULLSCREEN_SetColors(_THIS, int firstcolor, int ncolors,
66 static int FULLSCREEN_FlipHWSurface(_THIS, SDL_Surface *surface); 66 SDL_Color * colors);
67 static int FULLSCREEN_FlipHWSurface(_THIS, SDL_Surface * surface);
67 void FULLSCREEN_SetWMCaption(_THIS, const char *title, const char *icon); 68 void FULLSCREEN_SetWMCaption(_THIS, const char *title, const char *icon);
68 extern int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo *info); 69 extern int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo * info);
69 70
70 /* UpdateRects variants */ 71 /* UpdateRects variants */
71 static void FULLSCREEN_UpdateRects(_THIS, int numrects, SDL_Rect *rects); 72 static void FULLSCREEN_UpdateRects(_THIS, int numrects, SDL_Rect * rects);
72 static void FULLSCREEN_UpdateRectsMemCpy(_THIS, int numrects, SDL_Rect *rects); 73 static void FULLSCREEN_UpdateRectsMemCpy(_THIS, int numrects,
73 static void FULLSCREEN_UpdateRects8bpp(_THIS, int numrects, SDL_Rect *rects); 74 SDL_Rect * rects);
74 static void FULLSCREEN_UpdateRects16bpp(_THIS, int numrects, SDL_Rect *rects); 75 static void FULLSCREEN_UpdateRects8bpp(_THIS, int numrects, SDL_Rect * rects);
75 static void FULLSCREEN_UpdateRects32bpp(_THIS, int numrects, SDL_Rect *rects); 76 static void FULLSCREEN_UpdateRects16bpp(_THIS, int numrects,
76 static void FULLSCREEN_UpdateRectsOS(_THIS, int numrects, SDL_Rect *rects); 77 SDL_Rect * rects);
78 static void FULLSCREEN_UpdateRects32bpp(_THIS, int numrects,
79 SDL_Rect * rects);
80 static void FULLSCREEN_UpdateRectsOS(_THIS, int numrects, SDL_Rect * rects);
77 81
78 /* Local helper functions */ 82 /* Local helper functions */
79 static int cmpmodes(const void *va, const void *vb); 83 static int cmpmodes(const void *va, const void *vb);
80 static int FULLSCREEN_AddMode(_THIS, int bpp, int w, int h); 84 static int FULLSCREEN_AddMode(_THIS, int bpp, int w, int h);
81 void FULLSCREEN_SetWriteBank(int bank); 85 void FULLSCREEN_SetWriteBank(int bank);
83 static void FULLSCREEN_DisableEscape(); 87 static void FULLSCREEN_DisableEscape();
84 static void FULLSCREEN_EnableEscape(); 88 static void FULLSCREEN_EnableEscape();
85 void FULLSCREEN_BuildModeList(_THIS); 89 void FULLSCREEN_BuildModeList(_THIS);
86 90
87 /* Following variable is set up in riskosTask.c */ 91 /* Following variable is set up in riskosTask.c */
88 extern int riscos_backbuffer; /* Create a back buffer in system memory for full screen mode */ 92 extern int riscos_backbuffer; /* Create a back buffer in system memory for full screen mode */
89 93
90 /* Following is used to create a sprite back buffer */ 94 /* Following is used to create a sprite back buffer */
91 extern unsigned char *WIMP_CreateBuffer(int width, int height, int bpp); 95 extern unsigned char *WIMP_CreateBuffer(int width, int height, int bpp);
92 96
93 /* Fast assembler copy */ 97 /* Fast assembler copy */
94 extern void RISCOS_Put32(void *to, int pixels, int pitch, int rows, void *from, int src_skip_bytes); 98 extern void RISCOS_Put32(void *to, int pixels, int pitch, int rows,
95 99 void *from, int src_skip_bytes);
96 SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface *current, 100
97 int width, int height, int bpp, Uint32 flags) 101 SDL_Surface *
98 { 102 FULLSCREEN_SetVideoMode(_THIS, SDL_Surface * current,
99 _kernel_swi_regs regs; 103 int width, int height, int bpp, Uint32 flags)
100 Uint32 Rmask = 0; 104 {
101 Uint32 Gmask = 0; 105 _kernel_swi_regs regs;
102 Uint32 Bmask = 0; 106 Uint32 Rmask = 0;
103 int create_back_buffer = riscos_backbuffer; 107 Uint32 Gmask = 0;
104 108 Uint32 Bmask = 0;
105 switch(bpp) 109 int create_back_buffer = riscos_backbuffer;
106 { 110
107 case 8: 111 switch (bpp) {
108 flags |= SDL_HWPALETTE; 112 case 8:
109 break; 113 flags |= SDL_HWPALETTE;
110 114 break;
111 case 15: 115
112 case 16: 116 case 15:
113 Bmask = 0x00007c00; 117 case 16:
114 Gmask = 0x000003e0; 118 Bmask = 0x00007c00;
115 Rmask = 0x0000001f; 119 Gmask = 0x000003e0;
116 break; 120 Rmask = 0x0000001f;
117 121 break;
118 case 32: 122
119 Bmask = 0x00ff0000; 123 case 32:
120 Gmask = 0x0000ff00; 124 Bmask = 0x00ff0000;
121 Rmask = 0x000000ff; 125 Gmask = 0x0000ff00;
122 break; 126 Rmask = 0x000000ff;
123 127 break;
124 default: 128
125 SDL_SetError("Pixel depth not supported"); 129 default:
126 return NULL; 130 SDL_SetError("Pixel depth not supported");
127 break; 131 return NULL;
128 } 132 break;
129 133 }
130 if (FULLSCREEN_SetMode(width, height, bpp) == 0) 134
131 { 135 if (FULLSCREEN_SetMode(width, height, bpp) == 0) {
132 SDL_SetError("Couldn't set requested mode"); 136 SDL_SetError("Couldn't set requested mode");
133 return (NULL); 137 return (NULL);
134 } 138 }
135 139
136 /* printf("Setting mode %dx%d\n", width, height); */ 140 /* printf("Setting mode %dx%d\n", width, height); */
137 141
138 /* Allocate the new pixel format for the screen */ 142 /* Allocate the new pixel format for the screen */
139 if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) { 143 if (!SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0)) {
140 RISCOS_RestoreWimpMode(); 144 RISCOS_RestoreWimpMode();
141 SDL_SetError("Couldn't allocate new pixel format for requested mode"); 145 SDL_SetError("Couldn't allocate new pixel format for requested mode");
142 return(NULL); 146 return (NULL);
143 } 147 }
144 148
145 /* Set up the new mode framebuffer */ 149 /* Set up the new mode framebuffer */
146 current->w = width; 150 current->w = width;
147 this->hidden->height = current->h = height; 151 this->hidden->height = current->h = height;
148 152
149 regs.r[0] = -1; /* -1 for current screen mode */ 153 regs.r[0] = -1; /* -1 for current screen mode */
150 154
151 /* Get screen width in bytes */ 155 /* Get screen width in bytes */
152 regs.r[1] = 6; // Screen Width in bytes 156 regs.r[1] = 6; // Screen Width in bytes
153 _kernel_swi(OS_ReadModeVariable, &regs, &regs); 157 _kernel_swi(OS_ReadModeVariable, &regs, &regs);
154 158
155 current->pitch = regs.r[2]; 159 current->pitch = regs.r[2];
156 160
157 if (flags & SDL_DOUBLEBUF) 161 if (flags & SDL_DOUBLEBUF) {
158 { 162 regs.r[0] = 2; /* Screen area */
159 regs.r[0] = 2; /* Screen area */ 163 _kernel_swi(OS_ReadDynamicArea, &regs, &regs);
160 _kernel_swi(OS_ReadDynamicArea, &regs, &regs); 164
161 165 /* Reg 1 has amount of memory currently used for display */
162 /* Reg 1 has amount of memory currently used for display */ 166 regs.r[0] = 2; /* Screen area */
163 regs.r[0] = 2; /* Screen area */ 167 regs.r[1] = (current->pitch * height * 2) - regs.r[1];
164 regs.r[1] = (current->pitch * height * 2) - regs.r[1]; 168 if (_kernel_swi(OS_ChangeDynamicArea, &regs, &regs) != NULL) {
165 if (_kernel_swi(OS_ChangeDynamicArea, &regs, &regs) != NULL) 169 /* Can't allocate enough screen memory for double buffer */
166 { 170 flags &= ~SDL_DOUBLEBUF;
167 /* Can't allocate enough screen memory for double buffer */ 171 }
168 flags &= ~SDL_DOUBLEBUF; 172 }
169 } 173
170 } 174 current->flags = flags | SDL_FULLSCREEN | SDL_HWSURFACE | SDL_PREALLOC;
171 175
172 current->flags = flags | SDL_FULLSCREEN | SDL_HWSURFACE | SDL_PREALLOC; 176
173 177 /* Need to set display banks here for double buffering */
174 178 if (flags & SDL_DOUBLEBUF) {
175 /* Need to set display banks here for double buffering */ 179 FULLSCREEN_SetWriteBank(0);
176 if (flags & SDL_DOUBLEBUF) 180 FULLSCREEN_SetDisplayBank(1);
177 { 181
178 FULLSCREEN_SetWriteBank(0); 182 create_back_buffer = 0; /* Don't need a back buffer for a double buffered display */
179 FULLSCREEN_SetDisplayBank(1);
180
181 create_back_buffer = 0; /* Don't need a back buffer for a double buffered display */
182 } 183 }
183 184
184 FULLSCREEN_SetupBanks(this); 185 FULLSCREEN_SetupBanks(this);
185 186
186 if (create_back_buffer) 187 if (create_back_buffer) {
187 { 188 /* If not double buffered we may need to create a memory
188 /* If not double buffered we may need to create a memory
189 ** back buffer to simulate processing on other OSes. 189 ** back buffer to simulate processing on other OSes.
190 ** This is turned on by setting the enviromental variable 190 ** This is turned on by setting the enviromental variable
191 ** SDL$<name>$BackBuffer >= 1 191 ** SDL$<name>$BackBuffer >= 1
192 */ 192 */
193 if (riscos_backbuffer == 3) 193 if (riscos_backbuffer == 3)
194 this->hidden->bank[0] = WIMP_CreateBuffer(width, height, bpp); 194 this->hidden->bank[0] = WIMP_CreateBuffer(width, height, bpp);
195 else 195 else
196 this->hidden->bank[0] = SDL_malloc(height * current->pitch); 196 this->hidden->bank[0] = SDL_malloc(height * current->pitch);
197 if (this->hidden->bank[0] == 0) 197 if (this->hidden->bank[0] == 0) {
198 { 198 RISCOS_RestoreWimpMode();
199 RISCOS_RestoreWimpMode(); 199 SDL_SetError("Couldnt allocate memory for back buffer");
200 SDL_SetError("Couldnt allocate memory for back buffer"); 200 return (NULL);
201 return (NULL); 201 }
202 } 202 /* Surface updated in programs is now a software surface */
203 /* Surface updated in programs is now a software surface */ 203 current->flags &= ~SDL_HWSURFACE;
204 current->flags &= ~SDL_HWSURFACE;
205 } 204 }
206 205
207 /* Store address of allocated screen bank to be freed later */ 206 /* Store address of allocated screen bank to be freed later */
208 if (this->hidden->alloc_bank) SDL_free(this->hidden->alloc_bank); 207 if (this->hidden->alloc_bank)
209 if (create_back_buffer) 208 SDL_free(this->hidden->alloc_bank);
210 { 209 if (create_back_buffer) {
211 this->hidden->alloc_bank = this->hidden->bank[0]; 210 this->hidden->alloc_bank = this->hidden->bank[0];
212 if (riscos_backbuffer == 3) 211 if (riscos_backbuffer == 3) {
213 { 212 this->hidden->bank[0] += 60; /* Start of sprite data */
214 this->hidden->bank[0] += 60; /* Start of sprite data */ 213 if (bpp == 8)
215 if (bpp == 8) this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */ 214 this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */
216 } 215 }
217 } else 216 } else
218 this->hidden->alloc_bank = 0; 217 this->hidden->alloc_bank = 0;
219 218
220 // Clear both banks to black 219 // Clear both banks to black
221 SDL_memset(this->hidden->bank[0], 0, height * current->pitch); 220 SDL_memset(this->hidden->bank[0], 0, height * current->pitch);
222 SDL_memset(this->hidden->bank[1], 0, height * current->pitch); 221 SDL_memset(this->hidden->bank[1], 0, height * current->pitch);
223 222
224 this->hidden->current_bank = 0; 223 this->hidden->current_bank = 0;
225 current->pixels = this->hidden->bank[0]; 224 current->pixels = this->hidden->bank[0];
226 225
227 /* Have to set the screen here, so SetDeviceMode will pick it up */ 226 /* Have to set the screen here, so SetDeviceMode will pick it up */
228 this->screen = current; 227 this->screen = current;
229 228
230 /* Reset device functions for the wimp */ 229 /* Reset device functions for the wimp */
231 FULLSCREEN_SetDeviceMode(this); 230 FULLSCREEN_SetDeviceMode(this);
232 231
233 /* FULLSCREEN_DisableEscape(); */ 232 /* FULLSCREEN_DisableEscape(); */
234 233
235 /* We're done */ 234 /* We're done */
236 return(current); 235 return (current);
237 } 236 }
238 237
239 /* Reset any device functions that have been changed because we have run in WIMP mode */ 238 /* Reset any device functions that have been changed because we have run in WIMP mode */
240 void FULLSCREEN_SetDeviceMode(_THIS) 239 void
241 { 240 FULLSCREEN_SetDeviceMode(_THIS)
242 /* Update rects is different if we have a backbuffer */ 241 {
243 242 /* Update rects is different if we have a backbuffer */
244 if (riscos_backbuffer && (this->screen->flags & SDL_DOUBLEBUF) == 0) 243
245 { 244 if (riscos_backbuffer && (this->screen->flags & SDL_DOUBLEBUF) == 0) {
246 switch(riscos_backbuffer) 245 switch (riscos_backbuffer) {
247 { 246 case 2: /* ARM code full word copy */
248 case 2: /* ARM code full word copy */ 247 switch (this->screen->format->BytesPerPixel) {
249 switch(this->screen->format->BytesPerPixel) 248 case 1: /* 8bpp modes */
250 { 249 this->UpdateRects = FULLSCREEN_UpdateRects8bpp;
251 case 1: /* 8bpp modes */ 250 break;
252 this->UpdateRects = FULLSCREEN_UpdateRects8bpp; 251 case 2: /* 15/16bpp modes */
253 break; 252 this->UpdateRects = FULLSCREEN_UpdateRects16bpp;
254 case 2: /* 15/16bpp modes */ 253 break;
255 this->UpdateRects = FULLSCREEN_UpdateRects16bpp; 254 case 4: /* 32 bpp modes */
256 break; 255 this->UpdateRects = FULLSCREEN_UpdateRects32bpp;
257 case 4: /* 32 bpp modes */ 256 break;
258 this->UpdateRects = FULLSCREEN_UpdateRects32bpp; 257
259 break; 258 default: /* Just default to the memcpy routine */
260 259 this->UpdateRects = FULLSCREEN_UpdateRectsMemCpy;
261 default: /* Just default to the memcpy routine */ 260 break;
262 this->UpdateRects = FULLSCREEN_UpdateRectsMemCpy; 261 }
263 break; 262 break;
264 } 263
265 break; 264 case 3: /* Use OS sprite plot routine */
266 265 this->UpdateRects = FULLSCREEN_UpdateRectsOS;
267 case 3: /* Use OS sprite plot routine */ 266 break;
268 this->UpdateRects = FULLSCREEN_UpdateRectsOS; 267
269 break; 268 default: /* Old but safe memcpy */
270 269 this->UpdateRects = FULLSCREEN_UpdateRectsMemCpy;
271 default: /* Old but safe memcpy */ 270 break;
272 this->UpdateRects = FULLSCREEN_UpdateRectsMemCpy; 271 }
273 break; 272 } else
274 } 273 this->UpdateRects = FULLSCREEN_UpdateRects; /* Default do nothing implementation */
275 } else 274
276 this->UpdateRects = FULLSCREEN_UpdateRects; /* Default do nothing implementation */ 275 this->SetColors = FULLSCREEN_SetColors;
277 276
278 this->SetColors = FULLSCREEN_SetColors; 277 this->FlipHWSurface = FULLSCREEN_FlipHWSurface;
279 278
280 this->FlipHWSurface = FULLSCREEN_FlipHWSurface; 279 this->SetCaption = FULLSCREEN_SetWMCaption;
281 280 this->SetIcon = NULL;
282 this->SetCaption = FULLSCREEN_SetWMCaption; 281 this->IconifyWindow = NULL;
283 this->SetIcon = NULL; 282
284 this->IconifyWindow = NULL; 283 this->ShowWMCursor = RISCOS_ShowWMCursor;
285 284 this->WarpWMCursor = FULLSCREEN_WarpWMCursor;
286 this->ShowWMCursor = RISCOS_ShowWMCursor; 285
287 this->WarpWMCursor = FULLSCREEN_WarpWMCursor; 286 this->PumpEvents = FULLSCREEN_PumpEvents;
288
289 this->PumpEvents = FULLSCREEN_PumpEvents;
290 } 287 }
291 288
292 /* Query for the list of available video modes */ 289 /* Query for the list of available video modes */
293 void FULLSCREEN_BuildModeList(_THIS) 290 void
294 { 291 FULLSCREEN_BuildModeList(_THIS)
295 _kernel_swi_regs regs; 292 {
296 char *enumInfo = NULL; 293 _kernel_swi_regs regs;
297 char *enum_ptr; 294 char *enumInfo = NULL;
298 int *blockInfo; 295 char *enum_ptr;
299 int j; 296 int *blockInfo;
300 int num_modes; 297 int j;
301 298 int num_modes;
302 /* Find out how much space we need */ 299
303 regs.r[0] = 2; /* Reason code */ 300 /* Find out how much space we need */
304 regs.r[2] = 0; /* Number of modes to skip */ 301 regs.r[0] = 2; /* Reason code */
305 regs.r[6] = 0; /* pointer to block or 0 for count */ 302 regs.r[2] = 0; /* Number of modes to skip */
306 regs.r[7] = 0; /* Size of block in bytes */ 303 regs.r[6] = 0; /* pointer to block or 0 for count */
307 _kernel_swi(OS_ScreenMode, &regs, &regs); 304 regs.r[7] = 0; /* Size of block in bytes */
305 _kernel_swi(OS_ScreenMode, &regs, &regs);
308 306
309 num_modes = -regs.r[2]; 307 num_modes = -regs.r[2];
310 308
311 /* Video memory should be in r[5] */ 309 /* Video memory should be in r[5] */
312 this->info.video_mem = regs.r[5]/1024; 310 this->info.video_mem = regs.r[5] / 1024;
313 311
314 enumInfo = (unsigned char *)SDL_malloc(-regs.r[7]); 312 enumInfo = (unsigned char *) SDL_malloc(-regs.r[7]);
315 if (enumInfo == NULL) 313 if (enumInfo == NULL) {
316 { 314 SDL_OutOfMemory();
317 SDL_OutOfMemory(); 315 return;
318 return; 316 }
319 } 317 /* Read mode information into block */
320 /* Read mode information into block */ 318 regs.r[2] = 0;
321 regs.r[2] = 0; 319 regs.r[6] = (int) enumInfo;
322 regs.r[6] = (int)enumInfo; 320 regs.r[7] = -regs.r[7];
323 regs.r[7] = -regs.r[7]; 321 _kernel_swi(OS_ScreenMode, &regs, &regs);
324 _kernel_swi(OS_ScreenMode, &regs, &regs); 322
325 323 enum_ptr = enumInfo;
326 enum_ptr = enumInfo; 324
327 325 for (j = 0; j < num_modes; j++) {
328 for (j =0; j < num_modes;j++) 326 blockInfo = (int *) enum_ptr;
329 { 327 if ((blockInfo[1] & 255) == 1) { /* We understand this format */
330 blockInfo = (int *)enum_ptr; 328 switch (blockInfo[4]) {
331 if ((blockInfo[1] & 255) == 1) /* We understand this format */ 329 case 3: /* 8 bits per pixel */
332 { 330 FULLSCREEN_AddMode(this, 8, blockInfo[2], blockInfo[3]);
333 switch(blockInfo[4]) 331 break;
334 { 332 case 4: /* 15 bits per pixel */
335 case 3: /* 8 bits per pixel */ 333 FULLSCREEN_AddMode(this, 15, blockInfo[2], blockInfo[3]);
336 FULLSCREEN_AddMode(this, 8, blockInfo[2], blockInfo[3]); 334 break;
337 break; 335 case 5: /* 32 bits per pixel */
338 case 4: /* 15 bits per pixel */ 336 FULLSCREEN_AddMode(this, 32, blockInfo[2], blockInfo[3]);
339 FULLSCREEN_AddMode(this, 15, blockInfo[2], blockInfo[3]); 337 break;
340 break; 338 }
341 case 5: /* 32 bits per pixel */ 339 }
342 FULLSCREEN_AddMode(this, 32, blockInfo[2], blockInfo[3]); 340
343 break; 341 enum_ptr += blockInfo[0];
344 } 342 }
345 } 343
346 344 SDL_free(enumInfo);
347 enum_ptr += blockInfo[0]; 345
348 } 346 /* Sort the mode lists */
349 347 for (j = 0; j < NUM_MODELISTS; ++j) {
350 SDL_free(enumInfo); 348 if (SDL_nummodes[j] > 0) {
351 349 SDL_qsort(SDL_modelist[j], SDL_nummodes[j],
352 /* Sort the mode lists */ 350 sizeof *SDL_modelist[j], cmpmodes);
353 for ( j=0; j<NUM_MODELISTS; ++j ) { 351 }
354 if ( SDL_nummodes[j] > 0 ) { 352 }
355 SDL_qsort(SDL_modelist[j], SDL_nummodes[j], sizeof *SDL_modelist[j], cmpmodes); 353 }
356 } 354
357 } 355 static int
358 } 356 FULLSCREEN_FlipHWSurface(_THIS, SDL_Surface * surface)
359 357 {
360 static int FULLSCREEN_FlipHWSurface(_THIS, SDL_Surface *surface) 358 _kernel_swi_regs regs;
361 { 359 regs.r[0] = 19;
362 _kernel_swi_regs regs; 360
363 regs.r[0] = 19; 361 FULLSCREEN_SetDisplayBank(this->hidden->current_bank);
364 362 this->hidden->current_bank ^= 1;
365 FULLSCREEN_SetDisplayBank(this->hidden->current_bank); 363 FULLSCREEN_SetWriteBank(this->hidden->current_bank);
366 this->hidden->current_bank ^= 1; 364 surface->pixels = this->hidden->bank[this->hidden->current_bank];
367 FULLSCREEN_SetWriteBank(this->hidden->current_bank); 365
368 surface->pixels = this->hidden->bank[this->hidden->current_bank]; 366 /* Wait for Vsync */
369 367 _kernel_swi(OS_Byte, &regs, &regs);
370 /* Wait for Vsync */ 368
371 _kernel_swi(OS_Byte, &regs, &regs); 369 return (0);
372
373 return(0);
374 } 370 }
375 371
376 /* Nothing to do if we are writing direct to hardware */ 372 /* Nothing to do if we are writing direct to hardware */
377 static void FULLSCREEN_UpdateRects(_THIS, int numrects, SDL_Rect *rects) 373 static void
374 FULLSCREEN_UpdateRects(_THIS, int numrects, SDL_Rect * rects)
378 { 375 {
379 } 376 }
380 377
381 /* Safe but slower Memory copy from our allocated back buffer */ 378 /* Safe but slower Memory copy from our allocated back buffer */
382 static void FULLSCREEN_UpdateRectsMemCpy(_THIS, int numrects, SDL_Rect *rects) 379 static void
383 { 380 FULLSCREEN_UpdateRectsMemCpy(_THIS, int numrects, SDL_Rect * rects)
384 int j; 381 {
385 char *to, *from; 382 int j;
386 int pitch = this->screen->pitch; 383 char *to, *from;
387 int row; 384 int pitch = this->screen->pitch;
388 int xmult = this->screen->format->BytesPerPixel; 385 int row;
389 for (j = 0; j < numrects; j++) 386 int xmult = this->screen->format->BytesPerPixel;
390 { 387 for (j = 0; j < numrects; j++) {
391 from = this->hidden->bank[0] + rects->x * xmult + rects->y * pitch; 388 from = this->hidden->bank[0] + rects->x * xmult + rects->y * pitch;
392 to = this->hidden->bank[1] + rects->x * xmult + rects->y * pitch; 389 to = this->hidden->bank[1] + rects->x * xmult + rects->y * pitch;
393 for (row = 0; row < rects->h; row++) 390 for (row = 0; row < rects->h; row++) {
394 { 391 SDL_memcpy(to, from, rects->w * xmult);
395 SDL_memcpy(to, from, rects->w * xmult); 392 from += pitch;
396 from += pitch; 393 to += pitch;
397 to += pitch; 394 }
398 } 395 rects++;
399 rects++; 396 }
400 }
401 } 397 }
402 398
403 /* Use optimized assembler memory copy. Deliberately copies extra columns if 399 /* Use optimized assembler memory copy. Deliberately copies extra columns if
404 necessary to ensure the rectangle is word aligned. */ 400 necessary to ensure the rectangle is word aligned. */
405 static void FULLSCREEN_UpdateRects8bpp(_THIS, int numrects, SDL_Rect *rects) 401 static void
406 { 402 FULLSCREEN_UpdateRects8bpp(_THIS, int numrects, SDL_Rect * rects)
407 int j; 403 {
408 char *to, *from; 404 int j;
409 int pitch = this->screen->pitch; 405 char *to, *from;
410 int width_bytes; 406 int pitch = this->screen->pitch;
411 int src_skip_bytes; 407 int width_bytes;
412 408 int src_skip_bytes;
413 for (j = 0; j < numrects; j++) 409
414 { 410 for (j = 0; j < numrects; j++) {
415 from = this->hidden->bank[0] + rects->x + rects->y * pitch; 411 from = this->hidden->bank[0] + rects->x + rects->y * pitch;
416 to = this->hidden->bank[1] + rects->x + rects->y * pitch; 412 to = this->hidden->bank[1] + rects->x + rects->y * pitch;
417 width_bytes = rects->w; 413 width_bytes = rects->w;
418 if ((int)from & 3) 414 if ((int) from & 3) {
419 { 415 int extra = ((int) from & 3);
420 int extra = ((int)from & 3); 416 from -= extra;
421 from -= extra; 417 to -= extra;
422 to -= extra; 418 width_bytes += extra;
423 width_bytes += extra; 419 }
424 } 420 if (width_bytes & 3)
425 if (width_bytes & 3) width_bytes += 4 - (width_bytes & 3); 421 width_bytes += 4 - (width_bytes & 3);
426 src_skip_bytes = pitch - width_bytes; 422 src_skip_bytes = pitch - width_bytes;
427 423
428 RISCOS_Put32(to, (width_bytes >> 2), pitch, (int)rects->h, from, src_skip_bytes); 424 RISCOS_Put32(to, (width_bytes >> 2), pitch, (int) rects->h, from,
429 rects++; 425 src_skip_bytes);
430 } 426 rects++;
427 }
431 } 428 }
432 429
433 /* Use optimized assembler memory copy. Deliberately copies extra columns if 430 /* Use optimized assembler memory copy. Deliberately copies extra columns if
434 necessary to ensure the rectangle is word aligned. */ 431 necessary to ensure the rectangle is word aligned. */
435 static void FULLSCREEN_UpdateRects16bpp(_THIS, int numrects, SDL_Rect *rects) 432 static void
436 { 433 FULLSCREEN_UpdateRects16bpp(_THIS, int numrects, SDL_Rect * rects)
437 int j; 434 {
438 char *to, *from; 435 int j;
439 int pitch = this->screen->pitch; 436 char *to, *from;
440 int width_bytes; 437 int pitch = this->screen->pitch;
441 int src_skip_bytes; 438 int width_bytes;
442 439 int src_skip_bytes;
443 for (j = 0; j < numrects; j++) 440
444 { 441 for (j = 0; j < numrects; j++) {
445 from = this->hidden->bank[0] + (rects->x << 1) + rects->y * pitch; 442 from = this->hidden->bank[0] + (rects->x << 1) + rects->y * pitch;
446 to = this->hidden->bank[1] + (rects->x << 1) + rects->y * pitch; 443 to = this->hidden->bank[1] + (rects->x << 1) + rects->y * pitch;
447 width_bytes = (((int)rects->w) << 1); 444 width_bytes = (((int) rects->w) << 1);
448 if ((int)from & 3) 445 if ((int) from & 3) {
449 { 446 from -= 2;
450 from -= 2; 447 to -= 2;
451 to -= 2; 448 width_bytes += 2;
452 width_bytes += 2; 449 }
453 } 450 if (width_bytes & 3)
454 if (width_bytes & 3) width_bytes += 2; 451 width_bytes += 2;
455 src_skip_bytes = pitch - width_bytes; 452 src_skip_bytes = pitch - width_bytes;
456 453
457 RISCOS_Put32(to, (width_bytes >> 2), pitch, (int)rects->h, from, src_skip_bytes); 454 RISCOS_Put32(to, (width_bytes >> 2), pitch, (int) rects->h, from,
458 rects++; 455 src_skip_bytes);
459 } 456 rects++;
457 }
460 } 458 }
461 459
462 /* Use optimized assembler memory copy. 32 bpp modes are always word aligned */ 460 /* Use optimized assembler memory copy. 32 bpp modes are always word aligned */
463 static void FULLSCREEN_UpdateRects32bpp(_THIS, int numrects, SDL_Rect *rects) 461 static void
464 { 462 FULLSCREEN_UpdateRects32bpp(_THIS, int numrects, SDL_Rect * rects)
465 int j; 463 {
466 char *to, *from; 464 int j;
467 int pitch = this->screen->pitch; 465 char *to, *from;
468 int width; 466 int pitch = this->screen->pitch;
469 467 int width;
470 for (j = 0; j < numrects; j++) 468
471 { 469 for (j = 0; j < numrects; j++) {
472 from = this->hidden->bank[0] + (rects->x << 2) + rects->y * pitch; 470 from = this->hidden->bank[0] + (rects->x << 2) + rects->y * pitch;
473 to = this->hidden->bank[1] + (rects->x << 2) + rects->y * pitch; 471 to = this->hidden->bank[1] + (rects->x << 2) + rects->y * pitch;
474 width = (int)rects->w ; 472 width = (int) rects->w;
475 473
476 RISCOS_Put32(to, width, pitch, (int)rects->h, from, pitch - (width << 2)); 474 RISCOS_Put32(to, width, pitch, (int) rects->h, from,
477 rects++; 475 pitch - (width << 2));
478 } 476 rects++;
477 }
479 } 478 }
480 479
481 /* Use operating system sprite plots. Currently this is much slower than the 480 /* Use operating system sprite plots. Currently this is much slower than the
482 other variants however accelerated sprite plotting can be seen on the horizon 481 other variants however accelerated sprite plotting can be seen on the horizon
483 so this prepares for it. */ 482 so this prepares for it. */
484 static void FULLSCREEN_UpdateRectsOS(_THIS, int numrects, SDL_Rect *rects) 483 static void
485 { 484 FULLSCREEN_UpdateRectsOS(_THIS, int numrects, SDL_Rect * rects)
486 _kernel_swi_regs regs; 485 {
487 _kernel_oserror *err; 486 _kernel_swi_regs regs;
488 int j; 487 _kernel_oserror *err;
489 int y; 488 int j;
490 489 int y;
491 regs.r[0] = 28 + 512; 490
492 regs.r[1] = (unsigned int)this->hidden->alloc_bank; 491 regs.r[0] = 28 + 512;
493 regs.r[2] = (unsigned int)this->hidden->alloc_bank+16; 492 regs.r[1] = (unsigned int) this->hidden->alloc_bank;
494 regs.r[5] = 0; 493 regs.r[2] = (unsigned int) this->hidden->alloc_bank + 16;
495 494 regs.r[5] = 0;
496 for (j = 0; j < numrects; j++) 495
497 { 496 for (j = 0; j < numrects; j++) {
498 y = this->screen->h - rects->y; /* top of clipping region */ 497 y = this->screen->h - rects->y; /* top of clipping region */
499 _kernel_oswrch(24); /* Set graphics clip region */ 498 _kernel_oswrch(24); /* Set graphics clip region */
500 _kernel_oswrch((rects->x << this->hidden->xeig) & 0xFF); /* left */ 499 _kernel_oswrch((rects->x << this->hidden->xeig) & 0xFF); /* left */
501 _kernel_oswrch(((rects->x << this->hidden->xeig) >> 8) & 0xFF); 500 _kernel_oswrch(((rects->x << this->hidden->xeig) >> 8) & 0xFF);
502 _kernel_oswrch(((y - rects->h) << this->hidden->yeig) & 0xFF); /* bottom */ 501 _kernel_oswrch(((y - rects->h) << this->hidden->yeig) & 0xFF); /* bottom */
503 _kernel_oswrch((((y - rects->h) << this->hidden->yeig)>> 8) & 0xFF); 502 _kernel_oswrch((((y - rects->h) << this->hidden->yeig) >> 8) & 0xFF);
504 _kernel_oswrch(((rects->x + rects->w - 1) << this->hidden->xeig) & 0xFF); /* right */ 503 _kernel_oswrch(((rects->x + rects->w - 1) << this->hidden->xeig) & 0xFF); /* right */
505 _kernel_oswrch((((rects->x + rects->w - 1)<< this->hidden->xeig) >> 8) & 0xFF); 504 _kernel_oswrch((((rects->x + rects->w -
506 _kernel_oswrch(((y-1) << this->hidden->yeig) & 0xFF); /* top */ 505 1) << this->hidden->xeig) >> 8) & 0xFF);
507 _kernel_oswrch((((y-1) << this->hidden->yeig) >> 8) & 0xFF); 506 _kernel_oswrch(((y - 1) << this->hidden->yeig) & 0xFF); /* top */
508 507 _kernel_oswrch((((y - 1) << this->hidden->yeig) >> 8) & 0xFF);
509 regs.r[3] = 0; 508
510 regs.r[4] = 0; 509 regs.r[3] = 0;
511 510 regs.r[4] = 0;
512 if ((err = _kernel_swi(OS_SpriteOp, &regs, &regs)) != 0) 511
513 { 512 if ((err = _kernel_swi(OS_SpriteOp, &regs, &regs)) != 0) {
514 printf("OS_SpriteOp failed \n%s\n",err->errmess); 513 printf("OS_SpriteOp failed \n%s\n", err->errmess);
515 } 514 }
516 515
517 rects++; 516 rects++;
518 517
519 /* Reset to full screen clipping */ 518 /* Reset to full screen clipping */
520 _kernel_oswrch(24); /* Set graphics clip region */ 519 _kernel_oswrch(24); /* Set graphics clip region */
521 _kernel_oswrch(0); /* left */ 520 _kernel_oswrch(0); /* left */
522 _kernel_oswrch(0); 521 _kernel_oswrch(0);
523 _kernel_oswrch(0); /* bottom */ 522 _kernel_oswrch(0); /* bottom */
524 _kernel_oswrch(0); 523 _kernel_oswrch(0);
525 _kernel_oswrch(((this->screen->w-1) << this->hidden->xeig) & 0xFF); /* right */ 524 _kernel_oswrch(((this->screen->w - 1) << this->hidden->xeig) & 0xFF); /* right */
526 _kernel_oswrch((((this->screen->w-1) << this->hidden->xeig) >> 8) & 0xFF); 525 _kernel_oswrch((((this->screen->w -
527 _kernel_oswrch(((this->screen->h-1) << this->hidden->yeig) & 0xFF); /* top */ 526 1) << this->hidden->xeig) >> 8) & 0xFF);
528 _kernel_oswrch((((this->screen->h-1) << this->hidden->yeig) >> 8) & 0xFF); 527 _kernel_oswrch(((this->screen->h - 1) << this->hidden->yeig) & 0xFF); /* top */
529 } 528 _kernel_oswrch((((this->screen->h -
530 } 529 1) << this->hidden->yeig) >> 8) & 0xFF);
531 530 }
532 531 }
533 int FULLSCREEN_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 532
534 { 533
535 _kernel_swi_regs regs; 534 int
536 int palette[256]; 535 FULLSCREEN_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
537 536 {
538 regs.r[0] = -1; 537 _kernel_swi_regs regs;
539 regs.r[1] = -1; 538 int palette[256];
540 regs.r[2] = (int)palette; 539
541 regs.r[3] = 1024; 540 regs.r[0] = -1;
542 regs.r[4] = 0; 541 regs.r[1] = -1;
543 _kernel_swi(ColourTrans_ReadPalette, &regs, &regs); 542 regs.r[2] = (int) palette;
544 543 regs.r[3] = 1024;
545 while(ncolors--) 544 regs.r[4] = 0;
546 { 545 _kernel_swi(ColourTrans_ReadPalette, &regs, &regs);
547 palette[firstcolor] = ((colors->b) << 24) | ((colors->g) << 16) | ((colors->r) << 8); 546
548 firstcolor++; 547 while (ncolors--) {
549 colors++; 548 palette[firstcolor] =
550 } 549 ((colors->b) << 24) | ((colors->g) << 16) | ((colors->r) << 8);
551 550 firstcolor++;
552 regs.r[0] = -1; 551 colors++;
553 regs.r[1] = -1; 552 }
554 regs.r[2] = (int)palette; 553
555 regs.r[3] = 0; 554 regs.r[0] = -1;
556 regs.r[4] = 0; 555 regs.r[1] = -1;
557 _kernel_swi(ColourTrans_WritePalette, &regs, &regs); 556 regs.r[2] = (int) palette;
558 557 regs.r[3] = 0;
559 return(1); 558 regs.r[4] = 0;
560 } 559 _kernel_swi(ColourTrans_WritePalette, &regs, &regs);
561 560
562 561 return (1);
563 static int cmpmodes(const void *va, const void *vb) 562 }
564 { 563
565 SDL_Rect *a = *(SDL_Rect **)va; 564
566 SDL_Rect *b = *(SDL_Rect **)vb; 565 static int
567 if(a->w == b->w) 566 cmpmodes(const void *va, const void *vb)
567 {
568 SDL_Rect *a = *(SDL_Rect **) va;
569 SDL_Rect *b = *(SDL_Rect **) vb;
570 if (a->w == b->w)
568 return b->h - a->h; 571 return b->h - a->h;
569 else 572 else
570 return b->w - a->w; 573 return b->w - a->w;
571 } 574 }
572 575
573 static int FULLSCREEN_AddMode(_THIS, int bpp, int w, int h) 576 static int
574 { 577 FULLSCREEN_AddMode(_THIS, int bpp, int w, int h)
575 SDL_Rect *mode; 578 {
576 int i, index; 579 SDL_Rect *mode;
577 int next_mode; 580 int i, index;
578 581 int next_mode;
579 /* Check to see if we already have this mode */ 582
580 if ( bpp < 8 ) { /* Not supported */ 583 /* Check to see if we already have this mode */
581 return(0); 584 if (bpp < 8) { /* Not supported */
582 } 585 return (0);
583 index = ((bpp+7)/8)-1; 586 }
584 for ( i=0; i<SDL_nummodes[index]; ++i ) { 587 index = ((bpp + 7) / 8) - 1;
585 mode = SDL_modelist[index][i]; 588 for (i = 0; i < SDL_nummodes[index]; ++i) {
586 if ( (mode->w == w) && (mode->h == h) ) { 589 mode = SDL_modelist[index][i];
587 return(0); 590 if ((mode->w == w) && (mode->h == h)) {
588 } 591 return (0);
589 } 592 }
590 593 }
591 /* Set up the new video mode rectangle */ 594
592 mode = (SDL_Rect *)SDL_malloc(sizeof *mode); 595 /* Set up the new video mode rectangle */
593 if ( mode == NULL ) { 596 mode = (SDL_Rect *) SDL_malloc(sizeof *mode);
594 SDL_OutOfMemory(); 597 if (mode == NULL) {
595 return(-1); 598 SDL_OutOfMemory();
596 } 599 return (-1);
597 mode->x = 0; 600 }
598 mode->y = 0; 601 mode->x = 0;
599 mode->w = w; 602 mode->y = 0;
600 mode->h = h; 603 mode->w = w;
601 604 mode->h = h;
602 /* Allocate the new list of modes, and fill in the new mode */ 605
603 next_mode = SDL_nummodes[index]; 606 /* Allocate the new list of modes, and fill in the new mode */
604 SDL_modelist[index] = (SDL_Rect **) 607 next_mode = SDL_nummodes[index];
605 SDL_realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); 608 SDL_modelist[index] = (SDL_Rect **)
606 if ( SDL_modelist[index] == NULL ) { 609 SDL_realloc(SDL_modelist[index],
607 SDL_OutOfMemory(); 610 (1 + next_mode + 1) * sizeof(SDL_Rect *));
608 SDL_nummodes[index] = 0; 611 if (SDL_modelist[index] == NULL) {
609 SDL_free(mode); 612 SDL_OutOfMemory();
610 return(-1); 613 SDL_nummodes[index] = 0;
611 } 614 SDL_free(mode);
612 SDL_modelist[index][next_mode] = mode; 615 return (-1);
613 SDL_modelist[index][next_mode+1] = NULL; 616 }
614 SDL_nummodes[index]++; 617 SDL_modelist[index][next_mode] = mode;
615 618 SDL_modelist[index][next_mode + 1] = NULL;
616 return(0); 619 SDL_nummodes[index]++;
617 } 620
618 621 return (0);
619 void FULLSCREEN_SetWriteBank(int bank) 622 }
620 { 623
621 _kernel_swi_regs regs; 624 void
622 regs.r[0] = 112; 625 FULLSCREEN_SetWriteBank(int bank)
623 regs.r[1] = bank+1; 626 {
624 _kernel_swi(OS_Byte, &regs, &regs); 627 _kernel_swi_regs regs;
625 } 628 regs.r[0] = 112;
626 629 regs.r[1] = bank + 1;
627 void FULLSCREEN_SetDisplayBank(int bank) 630 _kernel_swi(OS_Byte, &regs, &regs);
628 { 631 }
629 _kernel_swi_regs regs; 632
630 regs.r[0] = 113; 633 void
631 regs.r[1] = bank+1; 634 FULLSCREEN_SetDisplayBank(int bank)
632 _kernel_swi(OS_Byte, &regs, &regs); 635 {
636 _kernel_swi_regs regs;
637 regs.r[0] = 113;
638 regs.r[1] = bank + 1;
639 _kernel_swi(OS_Byte, &regs, &regs);
633 } 640 }
634 641
635 642
636 /** Disable special escape key processing */ 643 /** Disable special escape key processing */
637 static void FULLSCREEN_DisableEscape() 644 static void
638 { 645 FULLSCREEN_DisableEscape()
639 _kernel_swi_regs regs; 646 {
640 regs.r[0] = 229; 647 _kernel_swi_regs regs;
641 regs.r[1] = 1; 648 regs.r[0] = 229;
642 regs.r[2] = 0; 649 regs.r[1] = 1;
643 _kernel_swi(OS_Byte, &regs, &regs); 650 regs.r[2] = 0;
644 651 _kernel_swi(OS_Byte, &regs, &regs);
652
645 } 653 }
646 654
647 /** Enable special escape key processing */ 655 /** Enable special escape key processing */
648 static void FULLSCREEN_EnableEscape() 656 static void
649 { 657 FULLSCREEN_EnableEscape()
650 _kernel_swi_regs regs; 658 {
651 regs.r[0] = 229; 659 _kernel_swi_regs regs;
652 regs.r[1] = 0; 660 regs.r[0] = 229;
653 regs.r[2] = 0; 661 regs.r[1] = 0;
654 _kernel_swi(OS_Byte, &regs, &regs); 662 regs.r[2] = 0;
655 663 _kernel_swi(OS_Byte, &regs, &regs);
664
656 } 665 }
657 666
658 /** Store caption in case this is called before we create a window */ 667 /** Store caption in case this is called before we create a window */
659 void FULLSCREEN_SetWMCaption(_THIS, const char *title, const char *icon) 668 void
660 { 669 FULLSCREEN_SetWMCaption(_THIS, const char *title, const char *icon)
661 SDL_strlcpy(this->hidden->title, title, SDL_arraysize(this->hidden->title)); 670 {
671 SDL_strlcpy(this->hidden->title, title,
672 SDL_arraysize(this->hidden->title));
662 } 673 }
663 674
664 /* Set screen mode 675 /* Set screen mode
665 * 676 *
666 * Returns 1 if mode is set ok, otherwise 0 677 * Returns 1 if mode is set ok, otherwise 0
667 */ 678 */
668 679
669 int FULLSCREEN_SetMode(int width, int height, int bpp) 680 int
670 { 681 FULLSCREEN_SetMode(int width, int height, int bpp)
671 SCREENMODEBLOCK smb; 682 {
672 _kernel_swi_regs regs; 683 SCREENMODEBLOCK smb;
673 684 _kernel_swi_regs regs;
674 smb.flags = 1; 685
675 smb.x_pixels = width; 686 smb.flags = 1;
676 smb.y_pixels = height; 687 smb.x_pixels = width;
677 smb.mode_vars[0] = -1; 688 smb.y_pixels = height;
678 689 smb.mode_vars[0] = -1;
679 switch(bpp) 690
680 { 691 switch (bpp) {
681 case 8: 692 case 8:
682 smb.pixel_depth = 3; 693 smb.pixel_depth = 3;
683 /* Note: Need to set ModeFlags to 128 and NColour variables to 255 get full 8 bit palette */ 694 /* Note: Need to set ModeFlags to 128 and NColour variables to 255 get full 8 bit palette */
684 smb.mode_vars[0] = 0; smb.mode_vars[1] = 128; /* Mode flags */ 695 smb.mode_vars[0] = 0;
685 smb.mode_vars[2] = 3; smb.mode_vars[3] = 255; /* NColour (number of colours -1) */ 696 smb.mode_vars[1] = 128; /* Mode flags */
686 smb.mode_vars[4] = -1; /* End of list */ 697 smb.mode_vars[2] = 3;
687 break; 698 smb.mode_vars[3] = 255; /* NColour (number of colours -1) */
688 699 smb.mode_vars[4] = -1; /* End of list */
689 case 15: 700 break;
690 case 16: 701
691 smb.pixel_depth = 4; 702 case 15:
692 break; 703 case 16:
693 704 smb.pixel_depth = 4;
694 case 32: 705 break;
695 smb.pixel_depth = 5; 706
696 break; 707 case 32:
697 708 smb.pixel_depth = 5;
698 default: 709 break;
699 SDL_SetError("Pixel depth not supported"); 710
700 return 0; 711 default:
701 break; 712 SDL_SetError("Pixel depth not supported");
702 } 713 return 0;
703 714 break;
704 smb.frame_rate = -1; 715 }
705 716
706 regs.r[0] = 0; 717 smb.frame_rate = -1;
707 regs.r[1] = (int)&smb; 718
708 719 regs.r[0] = 0;
709 if (_kernel_swi(OS_ScreenMode, &regs, &regs) != 0) 720 regs.r[1] = (int) &smb;
710 { 721
711 SDL_SetError("Couldn't set requested mode"); 722 if (_kernel_swi(OS_ScreenMode, &regs, &regs) != 0) {
712 return 0; 723 SDL_SetError("Couldn't set requested mode");
713 } 724 return 0;
714 725 }
715 /* Turn cursor off*/ 726
716 _kernel_oswrch(23);_kernel_oswrch(1);_kernel_oswrch(0); 727 /* Turn cursor off */
717 _kernel_oswrch(0);_kernel_oswrch(0);_kernel_oswrch(0); 728 _kernel_oswrch(23);
718 _kernel_oswrch(0);_kernel_oswrch(0);_kernel_oswrch(0); 729 _kernel_oswrch(1);
719 _kernel_oswrch(0);_kernel_oswrch(0); 730 _kernel_oswrch(0);
720 731 _kernel_oswrch(0);
721 return 1; 732 _kernel_oswrch(0);
733 _kernel_oswrch(0);
734 _kernel_oswrch(0);
735 _kernel_oswrch(0);
736 _kernel_oswrch(0);
737 _kernel_oswrch(0);
738 _kernel_oswrch(0);
739
740 return 1;
722 } 741 }
723 742
724 /* Get Start addresses for the screen banks */ 743 /* Get Start addresses for the screen banks */
725 void FULLSCREEN_SetupBanks(_THIS) 744 void
726 { 745 FULLSCREEN_SetupBanks(_THIS)
727 _kernel_swi_regs regs; 746 {
728 int block[5]; 747 _kernel_swi_regs regs;
729 block[0] = 148; /* Write screen start */ 748 int block[5];
730 block[1] = 149; /* Display screen start */ 749 block[0] = 148; /* Write screen start */
731 block[2] = 4; /* X eig factor */ 750 block[1] = 149; /* Display screen start */
732 block[3] = 5; /* Y eig factor */ 751 block[2] = 4; /* X eig factor */
733 block[4] = -1; /* End of list of variables to request */ 752 block[3] = 5; /* Y eig factor */
734 753 block[4] = -1; /* End of list of variables to request */
735 regs.r[0] = (int)block; 754
736 regs.r[1] = (int)block; 755 regs.r[0] = (int) block;
737 _kernel_swi(OS_ReadVduVariables, &regs, &regs); 756 regs.r[1] = (int) block;
738 757 _kernel_swi(OS_ReadVduVariables, &regs, &regs);
739 this->hidden->bank[0] = (void *)block[0]; 758
740 this->hidden->bank[1] = (void *)block[1]; 759 this->hidden->bank[0] = (void *) block[0];
741 this->hidden->xeig = block[2]; 760 this->hidden->bank[1] = (void *) block[1];
742 this->hidden->yeig = block[3]; 761 this->hidden->xeig = block[2];
762 this->hidden->yeig = block[3];
743 } 763 }
744 764
745 /* Toggle to full screen mode from the WIMP */ 765 /* Toggle to full screen mode from the WIMP */
746 766
747 int FULLSCREEN_ToggleFromWimp(_THIS) 767 int
748 { 768 FULLSCREEN_ToggleFromWimp(_THIS)
749 int width = this->screen->w; 769 {
750 int height = this->screen->h; 770 int width = this->screen->w;
751 int bpp = this->screen->format->BitsPerPixel; 771 int height = this->screen->h;
752 772 int bpp = this->screen->format->BitsPerPixel;
753 RISCOS_StoreWimpMode(); 773
754 if (FULLSCREEN_SetMode(width, height, bpp)) 774 RISCOS_StoreWimpMode();
755 { 775 if (FULLSCREEN_SetMode(width, height, bpp)) {
756 char *buffer = this->hidden->alloc_bank; /* This is start of sprite data */ 776 char *buffer = this->hidden->alloc_bank; /* This is start of sprite data */
757 /* Support back buffer mode only */ 777 /* Support back buffer mode only */
758 if (riscos_backbuffer == 0) riscos_backbuffer = 1; 778 if (riscos_backbuffer == 0)
759 779 riscos_backbuffer = 1;
760 FULLSCREEN_SetupBanks(this); 780
761 781 FULLSCREEN_SetupBanks(this);
762 this->hidden->bank[0] = buffer + 60; /* Start of sprite data */ 782
763 if (bpp == 8) this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */ 783 this->hidden->bank[0] = buffer + 60; /* Start of sprite data */
764 784 if (bpp == 8)
765 this->hidden->current_bank = 0; 785 this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */
766 this->screen->pixels = this->hidden->bank[0]; 786
767 787 this->hidden->current_bank = 0;
768 /* Copy back buffer to screen memory */ 788 this->screen->pixels = this->hidden->bank[0];
769 SDL_memcpy(this->hidden->bank[1], this->hidden->bank[0], width * height * this->screen->format->BytesPerPixel); 789
770 790 /* Copy back buffer to screen memory */
771 FULLSCREEN_SetDeviceMode(this); 791 SDL_memcpy(this->hidden->bank[1], this->hidden->bank[0],
772 return 1; 792 width * height * this->screen->format->BytesPerPixel);
773 } else 793
774 RISCOS_RestoreWimpMode(); 794 FULLSCREEN_SetDeviceMode(this);
775 795 return 1;
776 return 0; 796 } else
777 } 797 RISCOS_RestoreWimpMode();
798
799 return 0;
800 }
801
802 /* vi: set ts=4 sw=4 expandtab: */