comparison src/video/riscos/SDL_riscosFullScreenVideo.c @ 1668:4da1ee79c9af SDL-1.3

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