comparison src/video/ps2gs/SDL_gsvideo.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
40 #include "SDL_gsevents_c.h" 40 #include "SDL_gsevents_c.h"
41 #include "SDL_gsyuv_c.h" 41 #include "SDL_gsyuv_c.h"
42 42
43 43
44 /* Initialization/Query functions */ 44 /* Initialization/Query functions */
45 static int GS_VideoInit (_THIS, SDL_PixelFormat * vformat); 45 static int GS_VideoInit(_THIS, SDL_PixelFormat * vformat);
46 static SDL_Rect **GS_ListModes (_THIS, SDL_PixelFormat * format, 46 static SDL_Rect **GS_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags);
47 Uint32 flags); 47 static SDL_Surface *GS_SetVideoMode(_THIS, SDL_Surface * current, int width,
48 static SDL_Surface *GS_SetVideoMode (_THIS, SDL_Surface * current, int width, 48 int height, int bpp, Uint32 flags);
49 int height, int bpp, Uint32 flags); 49 static int GS_SetColors(_THIS, int firstcolor, int ncolors,
50 static int GS_SetColors (_THIS, int firstcolor, int ncolors, 50 SDL_Color * colors);
51 SDL_Color * colors); 51 static void GS_VideoQuit(_THIS);
52 static void GS_VideoQuit (_THIS);
53 52
54 /* Hardware surface functions */ 53 /* Hardware surface functions */
55 static int GS_AllocHWSurface (_THIS, SDL_Surface * surface); 54 static int GS_AllocHWSurface(_THIS, SDL_Surface * surface);
56 static int GS_LockHWSurface (_THIS, SDL_Surface * surface); 55 static int GS_LockHWSurface(_THIS, SDL_Surface * surface);
57 static void GS_UnlockHWSurface (_THIS, SDL_Surface * surface); 56 static void GS_UnlockHWSurface(_THIS, SDL_Surface * surface);
58 static void GS_FreeHWSurface (_THIS, SDL_Surface * surface); 57 static void GS_FreeHWSurface(_THIS, SDL_Surface * surface);
59 58
60 /* GS driver bootstrap functions */ 59 /* GS driver bootstrap functions */
61 60
62 static int 61 static int
63 GS_Available (void) 62 GS_Available(void)
64 { 63 {
65 int console, memory; 64 int console, memory;
66 65
67 console = open (PS2_DEV_GS, O_RDWR, 0); 66 console = open(PS2_DEV_GS, O_RDWR, 0);
68 if (console >= 0) { 67 if (console >= 0) {
69 close (console); 68 close(console);
70 } 69 }
71 memory = open (PS2_DEV_MEM, O_RDWR, 0); 70 memory = open(PS2_DEV_MEM, O_RDWR, 0);
72 if (memory >= 0) { 71 if (memory >= 0) {
73 close (memory); 72 close(memory);
74 } 73 }
75 return ((console >= 0) && (memory >= 0)); 74 return ((console >= 0) && (memory >= 0));
76 } 75 }
77 76
78 static void 77 static void
79 GS_DeleteDevice (SDL_VideoDevice * device) 78 GS_DeleteDevice(SDL_VideoDevice * device)
80 { 79 {
81 SDL_free (device->hidden); 80 SDL_free(device->hidden);
82 SDL_free (device); 81 SDL_free(device);
83 } 82 }
84 83
85 static SDL_VideoDevice * 84 static SDL_VideoDevice *
86 GS_CreateDevice (int devindex) 85 GS_CreateDevice(int devindex)
87 { 86 {
88 SDL_VideoDevice *this; 87 SDL_VideoDevice *this;
89 88
90 /* Initialize all variables that we clean on shutdown */ 89 /* Initialize all variables that we clean on shutdown */
91 this = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); 90 this = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
92 if (this) { 91 if (this) {
93 SDL_memset (this, 0, (sizeof *this)); 92 SDL_memset(this, 0, (sizeof *this));
94 this->hidden = (struct SDL_PrivateVideoData *) 93 this->hidden = (struct SDL_PrivateVideoData *)
95 SDL_malloc ((sizeof *this->hidden)); 94 SDL_malloc((sizeof *this->hidden));
96 } 95 }
97 if ((this == NULL) || (this->hidden == NULL)) { 96 if ((this == NULL) || (this->hidden == NULL)) {
98 SDL_OutOfMemory (); 97 SDL_OutOfMemory();
99 if (this) { 98 if (this) {
100 SDL_free (this); 99 SDL_free(this);
101 } 100 }
102 return (0); 101 return (0);
103 } 102 }
104 SDL_memset (this->hidden, 0, (sizeof *this->hidden)); 103 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
105 mouse_fd = -1; 104 mouse_fd = -1;
106 keyboard_fd = -1; 105 keyboard_fd = -1;
107 106
108 /* Set the function pointers */ 107 /* Set the function pointers */
109 this->VideoInit = GS_VideoInit; 108 this->VideoInit = GS_VideoInit;
165 PS2_GS_PSMCT16, /* 16 bpp */ 164 PS2_GS_PSMCT16, /* 16 bpp */
166 PS2_GS_PSMCT24, /* 24 bpp */ 165 PS2_GS_PSMCT24, /* 24 bpp */
167 PS2_GS_PSMCT32 /* 32 bpp */ 166 PS2_GS_PSMCT32 /* 32 bpp */
168 }; 167 };
169 168
170 static unsigned long long head_tags[] __attribute__ ((aligned (16))) = { 169 static unsigned long long head_tags[] __attribute__ ((aligned(16))) = {
171 4 | (1LL << 60), /* GIFtag */ 170 4 | (1LL << 60), /* GIFtag */
172 0x0e, /* A+D */ 171 0x0e, /* A+D */
173 0, /* 2 */ 172 0, /* 2 */
174 PS2_GS_BITBLTBUF, 0, /* 4 */ 173 PS2_GS_BITBLTBUF, 0, /* 4 */
175 PS2_GS_TRXPOS, 0, /* 6 */ 174 PS2_GS_TRXPOS, 0, /* 6 */
178 177
179 #define MAXIMG (32767 * 16) 178 #define MAXIMG (32767 * 16)
180 #define MAXTAGS 8 179 #define MAXTAGS 8
181 180
182 static inline int 181 static inline int
183 loadimage_nonblock (int fd, struct ps2_image *image, int size, 182 loadimage_nonblock(int fd, struct ps2_image *image, int size,
184 unsigned long long *hm, unsigned long long *im) 183 unsigned long long *hm, unsigned long long *im)
185 { 184 {
186 struct ps2_plist plist; 185 struct ps2_plist plist;
187 struct ps2_packet packet[1 + MAXTAGS * 2]; 186 struct ps2_packet packet[1 + MAXTAGS * 2];
188 int isize; 187 int isize;
189 int pnum, it, eop; 188 int pnum, it, eop;
194 pnum = it = eop = 0; 193 pnum = it = eop = 0;
195 plist.packet = packet; 194 plist.packet = packet;
196 195
197 /* make BITBLT packet */ 196 /* make BITBLT packet */
198 packet[pnum].ptr = hm; 197 packet[pnum].ptr = hm;
199 packet[pnum].len = sizeof (head_tags); 198 packet[pnum].len = sizeof(head_tags);
200 pnum++; 199 pnum++;
201 hm[2] = ((unsigned long long) image->fbp << 32) | 200 hm[2] = ((unsigned long long) image->fbp << 32) |
202 ((unsigned long long) image->fbw << 48) | 201 ((unsigned long long) image->fbw << 48) |
203 ((unsigned long long) image->psm << 56); 202 ((unsigned long long) image->psm << 56);
204 hm[4] = ((unsigned long long) image->x << 32) | 203 hm[4] = ((unsigned long long) image->x << 32) |
211 isize = size > MAXIMG ? MAXIMG : size; 210 isize = size > MAXIMG ? MAXIMG : size;
212 size -= isize; 211 size -= isize;
213 eop = (size == 0); 212 eop = (size == 0);
214 213
215 packet[pnum].ptr = &im[it]; 214 packet[pnum].ptr = &im[it];
216 packet[pnum].len = sizeof (unsigned long long) * 2; 215 packet[pnum].len = sizeof(unsigned long long) * 2;
217 pnum++; 216 pnum++;
218 im[it++] = (isize >> 4) | (eop ? (1 << 15) : 0) | (2LL << 58); 217 im[it++] = (isize >> 4) | (eop ? (1 << 15) : 0) | (2LL << 58);
219 im[it++] = 0; 218 im[it++] = 0;
220 219
221 packet[pnum].ptr = (void *) data; 220 packet[pnum].ptr = (void *) data;
223 pnum++; 222 pnum++;
224 data += isize; 223 data += isize;
225 } 224 }
226 plist.num = pnum; 225 plist.num = pnum;
227 226
228 return ioctl (fd, PS2IOC_SENDL, &plist); 227 return ioctl(fd, PS2IOC_SENDL, &plist);
229 } 228 }
230 229
231 static unsigned long long tex_tags[] __attribute__ ((aligned (16))) = { 230 static unsigned long long tex_tags[] __attribute__ ((aligned(16))) = {
232 3 | (1LL << 60), /* GIFtag */ 231 3 | (1LL << 60), /* GIFtag */
233 0x0e, /* A+D */ 232 0x0e, /* A+D */
234 0, /* 2 */ 233 0, /* 2 */
235 PS2_GS_TEX0_1, (1 << 5) + (1 << 6), PS2_GS_TEX1_1, 0, PS2_GS_TEXFLUSH}; 234 PS2_GS_TEX0_1, (1 << 5) + (1 << 6), PS2_GS_TEX1_1, 0, PS2_GS_TEXFLUSH};
236 static unsigned long long scale_tags[] __attribute__ ((aligned (16))) = { 235 static unsigned long long scale_tags[] __attribute__ ((aligned(16))) = {
237 5 | (1LL << 60), /* GIFtag */ 236 5 | (1LL << 60), /* GIFtag */
238 0x0e, /* A+D */ 237 0x0e, /* A+D */
239 6 + (1 << 4) + (1 << 8), PS2_GS_PRIM, ((unsigned long long) 0 * 16) + (((unsigned long long) 0 * 16) << 16), PS2_GS_UV, ((unsigned long long) 0 * 16) + (((unsigned long long) 0 * 16) << 16), PS2_GS_XYZ2, 0, /* 8 */ 238 6 + (1 << 4) + (1 << 8), PS2_GS_PRIM, ((unsigned long long) 0 * 16) + (((unsigned long long) 0 * 16) << 16), PS2_GS_UV, ((unsigned long long) 0 * 16) + (((unsigned long long) 0 * 16) << 16), PS2_GS_XYZ2, 0, /* 8 */
240 PS2_GS_UV, 0, /* 10 */ 239 PS2_GS_UV, 0, /* 10 */
241 PS2_GS_XYZ2}; 240 PS2_GS_XYZ2};
242 241
243 242
244 int 243 int
245 scaleimage_nonblock (int fd, unsigned long long *tm, unsigned long long *sm) 244 scaleimage_nonblock(int fd, unsigned long long *tm, unsigned long long *sm)
246 { 245 {
247 struct ps2_plist plist; 246 struct ps2_plist plist;
248 struct ps2_packet packet[2]; 247 struct ps2_packet packet[2];
249 248
250 /* initialize the variables */ 249 /* initialize the variables */
251 plist.num = 2; 250 plist.num = 2;
252 plist.packet = packet; 251 plist.packet = packet;
253 252
254 packet[0].ptr = tm; 253 packet[0].ptr = tm;
255 packet[0].len = sizeof (tex_tags); 254 packet[0].len = sizeof(tex_tags);
256 packet[1].ptr = sm; 255 packet[1].ptr = sm;
257 packet[1].len = sizeof (scale_tags); 256 packet[1].len = sizeof(scale_tags);
258 257
259 return ioctl (fd, PS2IOC_SENDL, &plist); 258 return ioctl(fd, PS2IOC_SENDL, &plist);
260 } 259 }
261 260
262 static int 261 static int
263 power_of_2 (int value) 262 power_of_2(int value)
264 { 263 {
265 int shift; 264 int shift;
266 265
267 for (shift = 0; (1 << shift) < value; ++shift) { 266 for (shift = 0; (1 << shift) < value; ++shift) {
268 /* Keep looking */ ; 267 /* Keep looking */ ;
269 } 268 }
270 return (shift); 269 return (shift);
271 } 270 }
272 271
273 static int 272 static int
274 GS_VideoInit (_THIS, SDL_PixelFormat * vformat) 273 GS_VideoInit(_THIS, SDL_PixelFormat * vformat)
275 { 274 {
276 struct ps2_screeninfo vinfo; 275 struct ps2_screeninfo vinfo;
277 276
278 /* Initialize the library */ 277 /* Initialize the library */
279 console_fd = open (PS2_DEV_GS, O_RDWR, 0); 278 console_fd = open(PS2_DEV_GS, O_RDWR, 0);
280 if (console_fd < 0) { 279 if (console_fd < 0) {
281 SDL_SetError ("Unable to open %s", PS2_DEV_GS); 280 SDL_SetError("Unable to open %s", PS2_DEV_GS);
282 return (-1); 281 return (-1);
283 } 282 }
284 memory_fd = open (PS2_DEV_MEM, O_RDWR, 0); 283 memory_fd = open(PS2_DEV_MEM, O_RDWR, 0);
285 if (memory_fd < 0) { 284 if (memory_fd < 0) {
286 close (console_fd); 285 close(console_fd);
287 console_fd = -1; 286 console_fd = -1;
288 SDL_SetError ("Unable to open %s", PS2_DEV_MEM); 287 SDL_SetError("Unable to open %s", PS2_DEV_MEM);
289 return (-1); 288 return (-1);
290 } 289 }
291 290
292 if (ioctl (console_fd, PS2IOC_GSCREENINFO, &vinfo) < 0) { 291 if (ioctl(console_fd, PS2IOC_GSCREENINFO, &vinfo) < 0) {
293 close (memory_fd); 292 close(memory_fd);
294 close (console_fd); 293 close(console_fd);
295 console_fd = -1; 294 console_fd = -1;
296 SDL_SetError ("Couldn't get console pixel format"); 295 SDL_SetError("Couldn't get console pixel format");
297 return (-1); 296 return (-1);
298 } 297 }
299 298
300 /* Determine the current screen size */ 299 /* Determine the current screen size */
301 this->info.current_w = vinfo.w; 300 this->info.current_w = vinfo.w;
307 case PS2_GS_PSMCT32: 306 case PS2_GS_PSMCT32:
308 case PS2_GS_PSMCT24: 307 case PS2_GS_PSMCT24:
309 case PS2_GS_PSMCT16: 308 case PS2_GS_PSMCT16:
310 break; 309 break;
311 default: 310 default:
312 GS_VideoQuit (this); 311 GS_VideoQuit(this);
313 SDL_SetError ("Unknown console pixel format: %d", vinfo.psm); 312 SDL_SetError("Unknown console pixel format: %d", vinfo.psm);
314 return (-1); 313 return (-1);
315 } 314 }
316 vformat->BitsPerPixel = GS_pixelmasks[vinfo.psm].bpp; 315 vformat->BitsPerPixel = GS_pixelmasks[vinfo.psm].bpp;
317 vformat->Rmask = GS_pixelmasks[vinfo.psm].r; 316 vformat->Rmask = GS_pixelmasks[vinfo.psm].r;
318 vformat->Gmask = GS_pixelmasks[vinfo.psm].g; 317 vformat->Gmask = GS_pixelmasks[vinfo.psm].g;
319 vformat->Bmask = GS_pixelmasks[vinfo.psm].b; 318 vformat->Bmask = GS_pixelmasks[vinfo.psm].b;
320 saved_vinfo = vinfo; 319 saved_vinfo = vinfo;
321 320
322 /* Enable mouse and keyboard support */ 321 /* Enable mouse and keyboard support */
323 if (GS_OpenKeyboard (this) < 0) { 322 if (GS_OpenKeyboard(this) < 0) {
324 GS_VideoQuit (this); 323 GS_VideoQuit(this);
325 SDL_SetError ("Unable to open keyboard"); 324 SDL_SetError("Unable to open keyboard");
326 return (-1); 325 return (-1);
327 } 326 }
328 if (GS_OpenMouse (this) < 0) { 327 if (GS_OpenMouse(this) < 0) {
329 const char *sdl_nomouse; 328 const char *sdl_nomouse;
330 329
331 sdl_nomouse = SDL_getenv ("SDL_NOMOUSE"); 330 sdl_nomouse = SDL_getenv("SDL_NOMOUSE");
332 if (!sdl_nomouse) { 331 if (!sdl_nomouse) {
333 GS_VideoQuit (this); 332 GS_VideoQuit(this);
334 SDL_SetError ("Unable to open mouse"); 333 SDL_SetError("Unable to open mouse");
335 return (-1); 334 return (-1);
336 } 335 }
337 } 336 }
338 337
339 /* We're done! */ 338 /* We're done! */
340 return (0); 339 return (0);
341 } 340 }
342 341
343 static SDL_Rect ** 342 static SDL_Rect **
344 GS_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) 343 GS_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
345 { 344 {
346 static SDL_Rect GS_vesa_mode_list[] = { 345 static SDL_Rect GS_vesa_mode_list[] = {
347 {0, 0, 1280, 1024}, 346 {0, 0, 1280, 1024},
348 {0, 0, 1024, 768}, 347 {0, 0, 1024, 768},
349 {0, 0, 800, 600}, 348 {0, 0, 800, 600},
398 } 397 }
399 return (modes); 398 return (modes);
400 } 399 }
401 400
402 /* Various screen update functions available */ 401 /* Various screen update functions available */
403 static void GS_DMAFullUpdate (_THIS, int numrects, SDL_Rect * rects); 402 static void GS_DMAFullUpdate(_THIS, int numrects, SDL_Rect * rects);
404 403
405 static SDL_Surface * 404 static SDL_Surface *
406 GS_SetVideoMode (_THIS, SDL_Surface * current, 405 GS_SetVideoMode(_THIS, SDL_Surface * current,
407 int width, int height, int bpp, Uint32 flags) 406 int width, int height, int bpp, Uint32 flags)
408 { 407 {
409 struct ps2_screeninfo vinfo; 408 struct ps2_screeninfo vinfo;
410 409
411 /* Set the terminal into graphics mode */ 410 /* Set the terminal into graphics mode */
412 if (GS_EnterGraphicsMode (this) < 0) { 411 if (GS_EnterGraphicsMode(this) < 0) {
413 return (NULL); 412 return (NULL);
414 } 413 }
415 414
416 /* Set the video mode and get the final screen format */ 415 /* Set the video mode and get the final screen format */
417 if (ioctl (console_fd, PS2IOC_GSCREENINFO, &vinfo) < 0) { 416 if (ioctl(console_fd, PS2IOC_GSCREENINFO, &vinfo) < 0) {
418 SDL_SetError ("Couldn't get console screen info"); 417 SDL_SetError("Couldn't get console screen info");
419 return (NULL); 418 return (NULL);
420 } 419 }
421 if ((vinfo.w != width) || (vinfo.h != height) || 420 if ((vinfo.w != width) || (vinfo.h != height) ||
422 (GS_pixelmasks[vinfo.psm].bpp != bpp)) { 421 (GS_pixelmasks[vinfo.psm].bpp != bpp)) {
423 /* If we're not in VESA mode, we have to scale resolution */ 422 /* If we're not in VESA mode, we have to scale resolution */
434 break; 433 break;
435 case 1280: 434 case 1280:
436 vinfo.res = PS2_GS_1280x1024; 435 vinfo.res = PS2_GS_1280x1024;
437 break; 436 break;
438 default: 437 default:
439 SDL_SetError ("Unsupported resolution: %dx%d\n", 438 SDL_SetError("Unsupported resolution: %dx%d\n",
440 width, height); 439 width, height);
441 return (NULL); 440 return (NULL);
442 } 441 }
443 vinfo.res |= (PS2_GS_75Hz << 8); 442 vinfo.res |= (PS2_GS_75Hz << 8);
444 vinfo.w = width; 443 vinfo.w = width;
445 vinfo.h = height; 444 vinfo.h = height;
446 } 445 }
447 vinfo.fbp = 0; 446 vinfo.fbp = 0;
448 vinfo.psm = GS_formatmap[bpp / 8]; 447 vinfo.psm = GS_formatmap[bpp / 8];
449 if (vinfo.psm < 0) { 448 if (vinfo.psm < 0) {
450 SDL_SetError ("Unsupported depth: %d bpp\n", bpp); 449 SDL_SetError("Unsupported depth: %d bpp\n", bpp);
451 return (NULL); 450 return (NULL);
452 } 451 }
453 if (ioctl (console_fd, PS2IOC_SSCREENINFO, &vinfo) < 0) { 452 if (ioctl(console_fd, PS2IOC_SSCREENINFO, &vinfo) < 0) {
454 SDL_SetError ("Couldn't set console screen info"); 453 SDL_SetError("Couldn't set console screen info");
455 return (NULL); 454 return (NULL);
456 } 455 }
457 456
458 /* Unmap the previous DMA buffer */ 457 /* Unmap the previous DMA buffer */
459 if (mapped_mem) { 458 if (mapped_mem) {
460 munmap (mapped_mem, mapped_len); 459 munmap(mapped_mem, mapped_len);
461 mapped_mem = NULL; 460 mapped_mem = NULL;
462 } 461 }
463 } 462 }
464 if (!SDL_ReallocFormat (current, GS_pixelmasks[vinfo.psm].bpp, 463 if (!SDL_ReallocFormat(current, GS_pixelmasks[vinfo.psm].bpp,
465 GS_pixelmasks[vinfo.psm].r, 464 GS_pixelmasks[vinfo.psm].r,
466 GS_pixelmasks[vinfo.psm].g, 465 GS_pixelmasks[vinfo.psm].g,
467 GS_pixelmasks[vinfo.psm].b, 0)) { 466 GS_pixelmasks[vinfo.psm].b, 0)) {
468 return (NULL); 467 return (NULL);
469 } 468 }
470 469
471 /* Set up the new mode framebuffer */ 470 /* Set up the new mode framebuffer */
472 current->flags = SDL_FULLSCREEN; 471 current->flags = SDL_FULLSCREEN;
473 current->w = width; 472 current->w = width;
474 current->h = height; 473 current->h = height;
475 current->pitch = SDL_CalculatePitch (current); 474 current->pitch = SDL_CalculatePitch(current);
476 475
477 /* Memory map the DMA area for block memory transfer */ 476 /* Memory map the DMA area for block memory transfer */
478 if (!mapped_mem) { 477 if (!mapped_mem) {
479 pixels_len = height * current->pitch; 478 pixels_len = height * current->pitch;
480 mapped_len = pixels_len + 479 mapped_len = pixels_len +
481 /* Screen update DMA command area */ 480 /* Screen update DMA command area */
482 sizeof (head_tags) + ((2 * MAXTAGS) * 16); 481 sizeof(head_tags) + ((2 * MAXTAGS) * 16);
483 if (saved_vinfo.mode != PS2_GS_VESA) { 482 if (saved_vinfo.mode != PS2_GS_VESA) {
484 mapped_len += sizeof (tex_tags) + sizeof (scale_tags); 483 mapped_len += sizeof(tex_tags) + sizeof(scale_tags);
485 } 484 }
486 mapped_mem = mmap (0, mapped_len, PROT_READ | PROT_WRITE, 485 mapped_mem = mmap(0, mapped_len, PROT_READ | PROT_WRITE,
487 MAP_SHARED, memory_fd, 0); 486 MAP_SHARED, memory_fd, 0);
488 if (mapped_mem == MAP_FAILED) { 487 if (mapped_mem == MAP_FAILED) {
489 SDL_SetError ("Unable to map %d bytes for DMA", mapped_len); 488 SDL_SetError("Unable to map %d bytes for DMA", mapped_len);
490 mapped_mem = NULL; 489 mapped_mem = NULL;
491 return (NULL); 490 return (NULL);
492 } 491 }
493 492
494 /* Set up the entire screen for DMA transfer */ 493 /* Set up the entire screen for DMA transfer */
522 screen_image_size = (screen_image_size + 15) & ~15; 521 screen_image_size = (screen_image_size + 15) & ~15;
523 522
524 /* Set up the memory for screen update DMA commands */ 523 /* Set up the memory for screen update DMA commands */
525 head_tags_mem = (unsigned long long *) (mapped_mem + pixels_len); 524 head_tags_mem = (unsigned long long *) (mapped_mem + pixels_len);
526 image_tags_mem = (unsigned long long *) 525 image_tags_mem = (unsigned long long *)
527 ((caddr_t) head_tags_mem + sizeof (head_tags)); 526 ((caddr_t) head_tags_mem + sizeof(head_tags));
528 SDL_memcpy (head_tags_mem, head_tags, sizeof (head_tags)); 527 SDL_memcpy(head_tags_mem, head_tags, sizeof(head_tags));
529 if (saved_vinfo.mode != PS2_GS_VESA) { 528 if (saved_vinfo.mode != PS2_GS_VESA) {
530 tex_tags_mem = (unsigned long long *) 529 tex_tags_mem = (unsigned long long *)
531 ((caddr_t) image_tags_mem + ((2 * MAXTAGS) * 16)); 530 ((caddr_t) image_tags_mem + ((2 * MAXTAGS) * 16));
532 scale_tags_mem = (unsigned long long *) 531 scale_tags_mem = (unsigned long long *)
533 ((caddr_t) tex_tags_mem + sizeof (tex_tags)); 532 ((caddr_t) tex_tags_mem + sizeof(tex_tags));
534 SDL_memcpy (tex_tags_mem, tex_tags, sizeof (tex_tags)); 533 SDL_memcpy(tex_tags_mem, tex_tags, sizeof(tex_tags));
535 tex_tags_mem[2] = 534 tex_tags_mem[2] =
536 (vinfo.h * vinfo.w) / 64 + 535 (vinfo.h * vinfo.w) / 64 +
537 ((unsigned long long) screen_image.fbw << 14) + 536 ((unsigned long long) screen_image.fbw << 14) +
538 ((unsigned long long) screen_image.psm << 20) + 537 ((unsigned long long) screen_image.psm << 20) +
539 ((unsigned long long) power_of_2 (screen_image.w) << 26) + 538 ((unsigned long long) power_of_2(screen_image.w) << 26) +
540 ((unsigned long long) power_of_2 (screen_image.h) << 30) + 539 ((unsigned long long) power_of_2(screen_image.h) << 30) +
541 ((unsigned long long) 1 << 34) + 540 ((unsigned long long) 1 << 34) +
542 ((unsigned long long) 1 << 35); 541 ((unsigned long long) 1 << 35);
543 SDL_memcpy (scale_tags_mem, scale_tags, sizeof (scale_tags)); 542 SDL_memcpy(scale_tags_mem, scale_tags, sizeof(scale_tags));
544 scale_tags_mem[8] = 543 scale_tags_mem[8] =
545 ((unsigned long long) screen_image.w * 16) + 544 ((unsigned long long) screen_image.w * 16) +
546 (((unsigned long long) screen_image.h * 16) << 16); 545 (((unsigned long long) screen_image.h * 16) << 16);
547 scale_tags_mem[10] = 546 scale_tags_mem[10] =
548 ((unsigned long long) vinfo.w * 16) + 547 ((unsigned long long) vinfo.w * 16) +
549 (((unsigned long long) vinfo.h * 16) << 16); 548 (((unsigned long long) vinfo.h * 16) << 16);
550 } 549 }
551 } 550 }
552 current->pixels = NULL; 551 current->pixels = NULL;
553 if (SDL_getenv ("SDL_FULLSCREEN_UPDATE")) { 552 if (SDL_getenv("SDL_FULLSCREEN_UPDATE")) {
554 /* Correct semantics */ 553 /* Correct semantics */
555 current->flags |= SDL_ASYNCBLIT; 554 current->flags |= SDL_ASYNCBLIT;
556 } else { 555 } else {
557 /* We lie here - the screen memory isn't really the visible 556 /* We lie here - the screen memory isn't really the visible
558 display memory and still requires an update, but this 557 display memory and still requires an update, but this
568 return (current); 567 return (current);
569 } 568 }
570 569
571 /* We don't support hardware surfaces yet */ 570 /* We don't support hardware surfaces yet */
572 static int 571 static int
573 GS_AllocHWSurface (_THIS, SDL_Surface * surface) 572 GS_AllocHWSurface(_THIS, SDL_Surface * surface)
574 { 573 {
575 return (-1); 574 return (-1);
576 } 575 }
577 static void 576 static void
578 GS_FreeHWSurface (_THIS, SDL_Surface * surface) 577 GS_FreeHWSurface(_THIS, SDL_Surface * surface)
579 { 578 {
580 return; 579 return;
581 } 580 }
582 static int 581 static int
583 GS_LockHWSurface (_THIS, SDL_Surface * surface) 582 GS_LockHWSurface(_THIS, SDL_Surface * surface)
584 { 583 {
585 if (surface == this->screen) { 584 if (surface == this->screen) {
586 /* Since mouse motion affects 'pixels', lock it */ 585 /* Since mouse motion affects 'pixels', lock it */
587 SDL_LockCursor (); 586 SDL_LockCursor();
588 587
589 /* Make sure any pending DMA has completed */ 588 /* Make sure any pending DMA has completed */
590 if (dma_pending) { 589 if (dma_pending) {
591 ioctl (console_fd, PS2IOC_SENDQCT, 1); 590 ioctl(console_fd, PS2IOC_SENDQCT, 1);
592 dma_pending = 0; 591 dma_pending = 0;
593 } 592 }
594 593
595 /* If the cursor is drawn on the DMA area, remove it */ 594 /* If the cursor is drawn on the DMA area, remove it */
596 if (cursor_drawn) { 595 if (cursor_drawn) {
597 surface->pixels = mapped_mem + surface->offset; 596 surface->pixels = mapped_mem + surface->offset;
598 SDL_EraseCursorNoLock (this->screen); 597 SDL_EraseCursorNoLock(this->screen);
599 cursor_drawn = 0; 598 cursor_drawn = 0;
600 } 599 }
601 600
602 /* Set the surface pixels to the base of the DMA area */ 601 /* Set the surface pixels to the base of the DMA area */
603 surface->pixels = mapped_mem; 602 surface->pixels = mapped_mem;
604 603
605 /* We're finished! */ 604 /* We're finished! */
606 SDL_UnlockCursor (); 605 SDL_UnlockCursor();
607 } 606 }
608 return (0); 607 return (0);
609 } 608 }
610 static void 609 static void
611 GS_UnlockHWSurface (_THIS, SDL_Surface * surface) 610 GS_UnlockHWSurface(_THIS, SDL_Surface * surface)
612 { 611 {
613 if (surface == this->screen) { 612 if (surface == this->screen) {
614 /* Since mouse motion affects 'pixels', lock it */ 613 /* Since mouse motion affects 'pixels', lock it */
615 SDL_LockCursor (); 614 SDL_LockCursor();
616 surface->pixels = NULL; 615 surface->pixels = NULL;
617 SDL_UnlockCursor (); 616 SDL_UnlockCursor();
618 } 617 }
619 } 618 }
620 619
621 static void 620 static void
622 GS_DMAFullUpdate (_THIS, int numrects, SDL_Rect * rects) 621 GS_DMAFullUpdate(_THIS, int numrects, SDL_Rect * rects)
623 { 622 {
624 /* Lock so we aren't interrupted by a mouse update */ 623 /* Lock so we aren't interrupted by a mouse update */
625 SDL_LockCursor (); 624 SDL_LockCursor();
626 625
627 /* Make sure any pending DMA has completed */ 626 /* Make sure any pending DMA has completed */
628 if (dma_pending) { 627 if (dma_pending) {
629 ioctl (console_fd, PS2IOC_SENDQCT, 1); 628 ioctl(console_fd, PS2IOC_SENDQCT, 1);
630 dma_pending = 0; 629 dma_pending = 0;
631 } 630 }
632 631
633 /* If the mouse is visible, draw it on the DMA area */ 632 /* If the mouse is visible, draw it on the DMA area */
634 if ((SDL_cursorstate & CURSOR_VISIBLE) && !cursor_drawn) { 633 if ((SDL_cursorstate & CURSOR_VISIBLE) && !cursor_drawn) {
635 this->screen->pixels = mapped_mem + this->screen->offset; 634 this->screen->pixels = mapped_mem + this->screen->offset;
636 SDL_DrawCursorNoLock (this->screen); 635 SDL_DrawCursorNoLock(this->screen);
637 this->screen->pixels = NULL; 636 this->screen->pixels = NULL;
638 cursor_drawn = 1; 637 cursor_drawn = 1;
639 } 638 }
640 639
641 /* Put the image onto the screen */ 640 /* Put the image onto the screen */
642 loadimage_nonblock (console_fd, 641 loadimage_nonblock(console_fd,
643 &screen_image, screen_image_size, 642 &screen_image, screen_image_size,
644 head_tags_mem, image_tags_mem); 643 head_tags_mem, image_tags_mem);
645 if (screen_image.y > 0) { 644 if (screen_image.y > 0) {
646 /* Need to scale offscreen image to TV output */ 645 /* Need to scale offscreen image to TV output */
647 ioctl (console_fd, PS2IOC_SENDQCT, 1); 646 ioctl(console_fd, PS2IOC_SENDQCT, 1);
648 dma_pending = 0; 647 dma_pending = 0;
649 scaleimage_nonblock (console_fd, tex_tags_mem, scale_tags_mem); 648 scaleimage_nonblock(console_fd, tex_tags_mem, scale_tags_mem);
650 } else { 649 } else {
651 dma_pending = 1; 650 dma_pending = 1;
652 } 651 }
653 652
654 /* We're finished! */ 653 /* We're finished! */
655 SDL_UnlockCursor (); 654 SDL_UnlockCursor();
656 } 655 }
657 656
658 static int 657 static int
659 GS_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) 658 GS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
660 { 659 {
661 return (0); 660 return (0);
662 } 661 }
663 662
664 static void 663 static void
665 GS_VideoQuit (_THIS) 664 GS_VideoQuit(_THIS)
666 { 665 {
667 /* Close console and input file descriptors */ 666 /* Close console and input file descriptors */
668 if (console_fd > 0) { 667 if (console_fd > 0) {
669 /* Unmap the video framebuffer */ 668 /* Unmap the video framebuffer */
670 if (mapped_mem) { 669 if (mapped_mem) {
671 /* Unmap the video framebuffer */ 670 /* Unmap the video framebuffer */
672 munmap (mapped_mem, mapped_len); 671 munmap(mapped_mem, mapped_len);
673 mapped_mem = NULL; 672 mapped_mem = NULL;
674 } 673 }
675 close (memory_fd); 674 close(memory_fd);
676 675
677 /* Restore the original video mode */ 676 /* Restore the original video mode */
678 if (GS_InGraphicsMode (this)) { 677 if (GS_InGraphicsMode(this)) {
679 ioctl (console_fd, PS2IOC_SSCREENINFO, &saved_vinfo); 678 ioctl(console_fd, PS2IOC_SSCREENINFO, &saved_vinfo);
680 } 679 }
681 680
682 /* We're all done with the graphics device */ 681 /* We're all done with the graphics device */
683 close (console_fd); 682 close(console_fd);
684 console_fd = -1; 683 console_fd = -1;
685 } 684 }
686 GS_CloseMouse (this); 685 GS_CloseMouse(this);
687 GS_CloseKeyboard (this); 686 GS_CloseKeyboard(this);
688 } 687 }
689 688
690 /* vi: set ts=4 sw=4 expandtab: */ 689 /* vi: set ts=4 sw=4 expandtab: */