summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/src/video/ps2gs
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2018-02-07 20:04:46 -0500
committerFranklin Wei <git@fwei.tk>2018-03-12 20:52:01 -0400
commit6039eb05ba6d82ef56f2868c96654c552d117bf9 (patch)
tree9db7016bcbf66cfdf7b9bc998d84c6eaff9c8378 /apps/plugins/sdl/src/video/ps2gs
parentef373c03b96b0be08babca581d9f10bccfd4931f (diff)
downloadrockbox-6039eb05ba6d82ef56f2868c96654c552d117bf9.tar.gz
rockbox-6039eb05ba6d82ef56f2868c96654c552d117bf9.zip
sdl: remove non-rockbox drivers
We never use any of these other drivers, so having them around just takes up space. Change-Id: Iced812162df1fef3fd55522b7e700acb6c3bcd41
Diffstat (limited to 'apps/plugins/sdl/src/video/ps2gs')
-rw-r--r--apps/plugins/sdl/src/video/ps2gs/SDL_gsevents.c977
-rw-r--r--apps/plugins/sdl/src/video/ps2gs/SDL_gsevents_c.h38
-rw-r--r--apps/plugins/sdl/src/video/ps2gs/SDL_gskeys.h139
-rw-r--r--apps/plugins/sdl/src/video/ps2gs/SDL_gsmouse.c146
-rw-r--r--apps/plugins/sdl/src/video/ps2gs/SDL_gsmouse_c.h37
-rw-r--r--apps/plugins/sdl/src/video/ps2gs/SDL_gsvideo.c689
-rw-r--r--apps/plugins/sdl/src/video/ps2gs/SDL_gsvideo.h95
-rw-r--r--apps/plugins/sdl/src/video/ps2gs/SDL_gsyuv.c461
-rw-r--r--apps/plugins/sdl/src/video/ps2gs/SDL_gsyuv_c.h37
9 files changed, 0 insertions, 2619 deletions
diff --git a/apps/plugins/sdl/src/video/ps2gs/SDL_gsevents.c b/apps/plugins/sdl/src/video/ps2gs/SDL_gsevents.c
deleted file mode 100644
index 1b842afe39..0000000000
--- a/apps/plugins/sdl/src/video/ps2gs/SDL_gsevents.c
+++ /dev/null
@@ -1,977 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/* Handle the event stream, converting console events into SDL events */
25
26#include <sys/types.h>
27#include <sys/time.h>
28#include <sys/ioctl.h>
29#include <unistd.h>
30#include <fcntl.h>
31#include <errno.h>
32#include <limits.h>
33
34/* For parsing /proc */
35#include <dirent.h>
36#include <ctype.h>
37
38#include <linux/vt.h>
39#include <linux/kd.h>
40#include <linux/keyboard.h>
41
42#include "SDL_mutex.h"
43#include "../SDL_sysvideo.h"
44#include "../../events/SDL_sysevents.h"
45#include "../../events/SDL_events_c.h"
46#include "SDL_gsvideo.h"
47#include "SDL_gsevents_c.h"
48#include "SDL_gskeys.h"
49
50#ifndef GPM_NODE_FIFO
51#define GPM_NODE_FIFO "/dev/gpmdata"
52#endif
53
54/* The translation tables from a console scancode to a SDL keysym */
55#define NUM_VGAKEYMAPS (1<<KG_CAPSSHIFT)
56static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS];
57static SDLKey keymap[128];
58static Uint16 keymap_temp[128]; /* only used at startup */
59static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym);
60
61/* Ugh, we have to duplicate the kernel's keysym mapping code...
62 Oh, it's not so bad. :-)
63
64 FIXME: Add keyboard LED handling code
65 */
66static void GS_vgainitkeymaps(int fd)
67{
68 struct kbentry entry;
69 int map, i;
70
71 /* Don't do anything if we are passed a closed keyboard */
72 if ( fd < 0 ) {
73 return;
74 }
75
76 /* Load all the keysym mappings */
77 for ( map=0; map<NUM_VGAKEYMAPS; ++map ) {
78 SDL_memset(vga_keymap[map], 0, NR_KEYS*sizeof(Uint16));
79 for ( i=0; i<NR_KEYS; ++i ) {
80 entry.kb_table = map;
81 entry.kb_index = i;
82 if ( ioctl(fd, KDGKBENT, &entry) == 0 ) {
83 /* fill keytemp. This replaces SDL_fbkeys.h */
84 if ( (map == 0) && (i<128) ) {
85 keymap_temp[i] = entry.kb_value;
86 }
87 /* The "Enter" key is a special case */
88 if ( entry.kb_value == K_ENTER ) {
89 entry.kb_value = K(KT_ASCII,13);
90 }
91 /* Handle numpad specially as well */
92 if ( KTYP(entry.kb_value) == KT_PAD ) {
93 switch ( entry.kb_value ) {
94 case K_P0:
95 case K_P1:
96 case K_P2:
97 case K_P3:
98 case K_P4:
99 case K_P5:
100 case K_P6:
101 case K_P7:
102 case K_P8:
103 case K_P9:
104 vga_keymap[map][i]=entry.kb_value;
105 vga_keymap[map][i]+= '0';
106 break;
107 case K_PPLUS:
108 vga_keymap[map][i]=K(KT_ASCII,'+');
109 break;
110 case K_PMINUS:
111 vga_keymap[map][i]=K(KT_ASCII,'-');
112 break;
113 case K_PSTAR:
114 vga_keymap[map][i]=K(KT_ASCII,'*');
115 break;
116 case K_PSLASH:
117 vga_keymap[map][i]=K(KT_ASCII,'/');
118 break;
119 case K_PENTER:
120 vga_keymap[map][i]=K(KT_ASCII,'\r');
121 break;
122 case K_PCOMMA:
123 vga_keymap[map][i]=K(KT_ASCII,',');
124 break;
125 case K_PDOT:
126 vga_keymap[map][i]=K(KT_ASCII,'.');
127 break;
128 default:
129 break;
130 }
131 }
132 /* Do the normal key translation */
133 if ( (KTYP(entry.kb_value) == KT_LATIN) ||
134 (KTYP(entry.kb_value) == KT_ASCII) ||
135 (KTYP(entry.kb_value) == KT_LETTER) ) {
136 vga_keymap[map][i] = entry.kb_value;
137 }
138 }
139 }
140 }
141}
142
143int GS_InGraphicsMode(_THIS)
144{
145 return((keyboard_fd >= 0) && (saved_kbd_mode >= 0));
146}
147
148int GS_EnterGraphicsMode(_THIS)
149{
150 struct termios keyboard_termios;
151
152 /* Set medium-raw keyboard mode */
153 if ( (keyboard_fd >= 0) && !GS_InGraphicsMode(this) ) {
154
155 /* Switch to the correct virtual terminal */
156 if ( current_vt > 0 ) {
157 struct vt_stat vtstate;
158
159 if ( ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0 ) {
160 saved_vt = vtstate.v_active;
161 }
162 if ( ioctl(keyboard_fd, VT_ACTIVATE, current_vt) == 0 ) {
163 ioctl(keyboard_fd, VT_WAITACTIVE, current_vt);
164 }
165 }
166
167 /* Set the terminal input mode */
168 if ( tcgetattr(keyboard_fd, &saved_kbd_termios) < 0 ) {
169 SDL_SetError("Unable to get terminal attributes");
170 if ( keyboard_fd > 0 ) {
171 close(keyboard_fd);
172 }
173 keyboard_fd = -1;
174 return(-1);
175 }
176 if ( ioctl(keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0 ) {
177 SDL_SetError("Unable to get current keyboard mode");
178 if ( keyboard_fd > 0 ) {
179 close(keyboard_fd);
180 }
181 keyboard_fd = -1;
182 return(-1);
183 }
184 keyboard_termios = saved_kbd_termios;
185 keyboard_termios.c_lflag &= ~(ICANON | ECHO | ISIG);
186 keyboard_termios.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
187 keyboard_termios.c_cc[VMIN] = 0;
188 keyboard_termios.c_cc[VTIME] = 0;
189 if (tcsetattr(keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) {
190 GS_CloseKeyboard(this);
191 SDL_SetError("Unable to set terminal attributes");
192 return(-1);
193 }
194 /* This will fail if we aren't root or this isn't our tty */
195 if ( ioctl(keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0 ) {
196 GS_CloseKeyboard(this);
197 SDL_SetError("Unable to set keyboard in raw mode");
198 return(-1);
199 }
200 if ( ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0 ) {
201 GS_CloseKeyboard(this);
202 SDL_SetError("Unable to set keyboard in graphics mode");
203 return(-1);
204 }
205 }
206 return(keyboard_fd);
207}
208
209void GS_LeaveGraphicsMode(_THIS)
210{
211 if ( GS_InGraphicsMode(this) ) {
212 ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
213 ioctl(keyboard_fd, KDSKBMODE, saved_kbd_mode);
214 tcsetattr(keyboard_fd, TCSAFLUSH, &saved_kbd_termios);
215 saved_kbd_mode = -1;
216
217 /* Head back over to the original virtual terminal */
218 if ( saved_vt > 0 ) {
219 ioctl(keyboard_fd, VT_ACTIVATE, saved_vt);
220 }
221 }
222}
223
224void GS_CloseKeyboard(_THIS)
225{
226 if ( keyboard_fd >= 0 ) {
227 GS_LeaveGraphicsMode(this);
228 if ( keyboard_fd > 0 ) {
229 close(keyboard_fd);
230 }
231 }
232 keyboard_fd = -1;
233}
234
235int GS_OpenKeyboard(_THIS)
236{
237 /* Open only if not already opened */
238 if ( keyboard_fd < 0 ) {
239 char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL };
240 char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
241 int i, tty0_fd;
242
243 /* Try to query for a free virtual terminal */
244 tty0_fd = -1;
245 for ( i=0; tty0[i] && (tty0_fd < 0); ++i ) {
246 tty0_fd = open(tty0[i], O_WRONLY, 0);
247 }
248 if ( tty0_fd < 0 ) {
249 tty0_fd = dup(0); /* Maybe stdin is a VT? */
250 }
251 ioctl(tty0_fd, VT_OPENQRY, &current_vt);
252 close(tty0_fd);
253 if ( (geteuid() == 0) && (current_vt > 0) ) {
254 for ( i=0; vcs[i] && (keyboard_fd < 0); ++i ) {
255 char vtpath[12];
256
257 SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], current_vt);
258 keyboard_fd = open(vtpath, O_RDWR, 0);
259#ifdef DEBUG_KEYBOARD
260 fprintf(stderr, "vtpath = %s, fd = %d\n",
261 vtpath, keyboard_fd);
262#endif /* DEBUG_KEYBOARD */
263
264 /* This needs to be our controlling tty
265 so that the kernel ioctl() calls work
266 */
267 if ( keyboard_fd >= 0 ) {
268 tty0_fd = open("/dev/tty", O_RDWR, 0);
269 if ( tty0_fd >= 0 ) {
270 ioctl(tty0_fd, TIOCNOTTY, 0);
271 close(tty0_fd);
272 }
273 }
274 }
275 }
276 if ( keyboard_fd < 0 ) {
277 /* Last resort, maybe our tty is a usable VT */
278 current_vt = 0;
279 keyboard_fd = open("/dev/tty", O_RDWR);
280 }
281#ifdef DEBUG_KEYBOARD
282 fprintf(stderr, "Current VT: %d\n", current_vt);
283#endif
284 saved_kbd_mode = -1;
285
286 /* Make sure that our input is a console terminal */
287 { int dummy;
288 if ( ioctl(keyboard_fd, KDGKBMODE, &dummy) < 0 ) {
289 close(keyboard_fd);
290 keyboard_fd = -1;
291 SDL_SetError("Unable to open a console terminal");
292 }
293 }
294
295 /* Set up keymap */
296 GS_vgainitkeymaps(keyboard_fd);
297 }
298 return(keyboard_fd);
299}
300
301static enum {
302 MOUSE_NONE = -1,
303 MOUSE_GPM, /* Note: GPM uses the MSC protocol */
304 MOUSE_PS2,
305 MOUSE_IMPS2,
306 MOUSE_MS,
307 MOUSE_BM,
308 NUM_MOUSE_DRVS
309} mouse_drv = MOUSE_NONE;
310
311void GS_CloseMouse(_THIS)
312{
313 if ( mouse_fd > 0 ) {
314 close(mouse_fd);
315 }
316 mouse_fd = -1;
317}
318
319/* Returns processes listed in /proc with the desired name */
320static int find_pid(DIR *proc, const char *wanted_name)
321{
322 struct dirent *entry;
323 int pid;
324
325 /* First scan proc for the gpm process */
326 pid = 0;
327 while ( (pid == 0) && ((entry=readdir(proc)) != NULL) ) {
328 if ( isdigit(entry->d_name[0]) ) {
329 FILE *status;
330 char path[PATH_MAX];
331 char name[PATH_MAX];
332
333 SDL_snprintf(path, SDL_arraysize(path), "/proc/%s/status", entry->d_name);
334 status=fopen(path, "r");
335 if ( status ) {
336 name[0] = '\0';
337 fscanf(status, "Name: %s", name);
338 if ( SDL_strcmp(name, wanted_name) == 0 ) {
339 pid = atoi(entry->d_name);
340 }
341 fclose(status);
342 }
343 }
344 }
345 return pid;
346}
347
348/* Returns true if /dev/gpmdata is being written to by gpm */
349static int gpm_available(void)
350{
351 int available;
352 DIR *proc;
353 int pid;
354 int cmdline, len, arglen;
355 char path[PATH_MAX];
356 char args[PATH_MAX], *arg;
357
358 /* Don't bother looking if the fifo isn't there */
359 if ( access(GPM_NODE_FIFO, F_OK) < 0 ) {
360 return(0);
361 }
362
363 available = 0;
364 proc = opendir("/proc");
365 if ( proc ) {
366 while ( (pid=find_pid(proc, "gpm")) > 0 ) {
367 SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid);
368 cmdline = open(path, O_RDONLY, 0);
369 if ( cmdline >= 0 ) {
370 len = read(cmdline, args, sizeof(args));
371 arg = args;
372 while ( len > 0 ) {
373 if ( SDL_strcmp(arg, "-R") == 0 ) {
374 available = 1;
375 }
376 arglen = SDL_strlen(arg)+1;
377 len -= arglen;
378 arg += arglen;
379 }
380 close(cmdline);
381 }
382 }
383 closedir(proc);
384 }
385 return available;
386}
387
388
389/* rcg06112001 Set up IMPS/2 mode, if possible. This gives
390 * us access to the mousewheel, etc. Returns zero if
391 * writes to device failed, but you still need to query the
392 * device to see which mode it's actually in.
393 */
394static int set_imps2_mode(int fd)
395{
396 /* If you wanted to control the mouse mode (and we do :) ) ...
397 Set IMPS/2 protocol:
398 {0xf3,200,0xf3,100,0xf3,80}
399 Reset mouse device:
400 {0xFF}
401 */
402 Uint8 set_imps2[] = {0xf3, 200, 0xf3, 100, 0xf3, 80};
403 Uint8 reset = 0xff;
404 fd_set fdset;
405 struct timeval tv;
406 int retval = 0;
407
408 if ( write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2) ) {
409 if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) {
410 retval = 1;
411 }
412 }
413
414 /* Get rid of any chatter from the above */
415 FD_ZERO(&fdset);
416 FD_SET(fd, &fdset);
417 tv.tv_sec = 0;
418 tv.tv_usec = 0;
419 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) {
420 char temp[32];
421 read(fd, temp, sizeof(temp));
422 }
423
424 return retval;
425}
426
427
428/* Returns true if the mouse uses the IMPS/2 protocol */
429static int detect_imps2(int fd)
430{
431 int imps2;
432
433 imps2 = 0;
434
435 if ( SDL_getenv("SDL_MOUSEDEV_IMPS2") ) {
436 imps2 = 1;
437 }
438 if ( ! imps2 ) {
439 Uint8 query_ps2 = 0xF2;
440 fd_set fdset;
441 struct timeval tv;
442
443 /* Get rid of any mouse motion noise */
444 FD_ZERO(&fdset);
445 FD_SET(fd, &fdset);
446 tv.tv_sec = 0;
447 tv.tv_usec = 0;
448 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) {
449 char temp[32];
450 read(fd, temp, sizeof(temp));
451 }
452
453 /* Query for the type of mouse protocol */
454 if ( write(fd, &query_ps2, sizeof (query_ps2)) == sizeof (query_ps2)) {
455 Uint8 ch = 0;
456
457 /* Get the mouse protocol response */
458 do {
459 FD_ZERO(&fdset);
460 FD_SET(fd, &fdset);
461 tv.tv_sec = 1;
462 tv.tv_usec = 0;
463 if ( select(fd+1, &fdset, 0, 0, &tv) < 1 ) {
464 break;
465 }
466 } while ( (read(fd, &ch, sizeof (ch)) == sizeof (ch)) &&
467 ((ch == 0xFA) || (ch == 0xAA)) );
468
469 /* Experimental values (Logitech wheelmouse) */
470#ifdef DEBUG_MOUSE
471fprintf(stderr, "Last mouse mode: 0x%x\n", ch);
472#endif
473 if ( ch == 3 ) {
474 imps2 = 1;
475 }
476 }
477 }
478 return imps2;
479}
480
481int GS_OpenMouse(_THIS)
482{
483 int i;
484 const char *mousedev;
485 const char *mousedrv;
486
487 mousedrv = SDL_getenv("SDL_MOUSEDRV");
488 mousedev = SDL_getenv("SDL_MOUSEDEV");
489 mouse_fd = -1;
490
491 /* STD MICE */
492
493 if ( mousedev == NULL ) {
494 /* FIXME someday... allow multiple mice in this driver */
495 char *ps2mice[] = {
496 "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL
497 };
498 /* First try to use GPM in repeater mode */
499 if ( mouse_fd < 0 ) {
500 if ( gpm_available() ) {
501 mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0);
502 if ( mouse_fd >= 0 ) {
503#ifdef DEBUG_MOUSE
504fprintf(stderr, "Using GPM mouse\n");
505#endif
506 mouse_drv = MOUSE_GPM;
507 }
508 }
509 }
510 /* Now try to use a modern PS/2 mouse */
511 for ( i=0; (mouse_fd < 0) && ps2mice[i]; ++i ) {
512 mouse_fd = open(ps2mice[i], O_RDWR, 0);
513 if (mouse_fd < 0) {
514 mouse_fd = open(ps2mice[i], O_RDONLY, 0);
515 }
516 if (mouse_fd >= 0) {
517 /* rcg06112001 Attempt to set IMPS/2 mode */
518 if ( i == 0 ) {
519 set_imps2_mode(mouse_fd);
520 }
521 if (detect_imps2(mouse_fd)) {
522#ifdef DEBUG_MOUSE
523fprintf(stderr, "Using IMPS2 mouse\n");
524#endif
525 mouse_drv = MOUSE_IMPS2;
526 } else {
527 mouse_drv = MOUSE_PS2;
528#ifdef DEBUG_MOUSE
529fprintf(stderr, "Using PS2 mouse\n");
530#endif
531 }
532 }
533 }
534 /* Next try to use a PPC ADB port mouse */
535 if ( mouse_fd < 0 ) {
536 mouse_fd = open("/dev/adbmouse", O_RDONLY, 0);
537 if ( mouse_fd >= 0 ) {
538#ifdef DEBUG_MOUSE
539fprintf(stderr, "Using ADB mouse\n");
540#endif
541 mouse_drv = MOUSE_BM;
542 }
543 }
544 }
545 /* Default to a serial Microsoft mouse */
546 if ( mouse_fd < 0 ) {
547 if ( mousedev == NULL ) {
548 mousedev = "/dev/mouse";
549 }
550 mouse_fd = open(mousedev, O_RDONLY, 0);
551 if ( mouse_fd >= 0 ) {
552 struct termios mouse_termios;
553
554 /* Set the sampling speed to 1200 baud */
555 tcgetattr(mouse_fd, &mouse_termios);
556 mouse_termios.c_iflag = IGNBRK | IGNPAR;
557 mouse_termios.c_oflag = 0;
558 mouse_termios.c_lflag = 0;
559 mouse_termios.c_line = 0;
560 mouse_termios.c_cc[VTIME] = 0;
561 mouse_termios.c_cc[VMIN] = 1;
562 mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL;
563 mouse_termios.c_cflag |= CS8;
564 mouse_termios.c_cflag |= B1200;
565 tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios);
566#ifdef DEBUG_MOUSE
567fprintf(stderr, "Using Microsoft mouse on %s\n", mousedev);
568#endif
569 mouse_drv = MOUSE_MS;
570 }
571 }
572 if ( mouse_fd < 0 ) {
573 mouse_drv = MOUSE_NONE;
574 }
575 return(mouse_fd);
576}
577
578static int posted = 0;
579
580void GS_vgamousecallback(int button, int dx, int dy)
581{
582 int button_1, button_3;
583 int button_state;
584 int state_changed;
585 int i;
586 Uint8 state;
587
588 if ( dx || dy ) {
589 posted += SDL_PrivateMouseMotion(0, 1, dx, dy);
590 }
591
592 /* Swap button 1 and 3 */
593 button_1 = (button & 0x04) >> 2;
594 button_3 = (button & 0x01) << 2;
595 button &= ~0x05;
596 button |= (button_1|button_3);
597
598 /* See what changed */
599 button_state = SDL_GetMouseState(NULL, NULL);
600 state_changed = button_state ^ button;
601 for ( i=0; i<8; ++i ) {
602 if ( state_changed & (1<<i) ) {
603 if ( button & (1<<i) ) {
604 state = SDL_PRESSED;
605 } else {
606 state = SDL_RELEASED;
607 }
608 posted += SDL_PrivateMouseButton(state, i+1, 0, 0);
609 }
610 }
611}
612
613/* For now, use GPM, PS/2, and MS protocols
614 Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.)
615 */
616static void handle_mouse(_THIS)
617{
618 static int start = 0;
619 static unsigned char mousebuf[BUFSIZ];
620 int i, nread;
621 int button = 0;
622 int dx = 0, dy = 0;
623 int packetsize = 0;
624
625 /* Figure out the mouse packet size */
626 switch (mouse_drv) {
627 case MOUSE_NONE:
628 /* Ack! */
629 read(mouse_fd, mousebuf, BUFSIZ);
630 return;
631 case MOUSE_GPM:
632 packetsize = 5;
633 break;
634 case MOUSE_IMPS2:
635 packetsize = 4;
636 break;
637 case MOUSE_PS2:
638 case MOUSE_MS:
639 case MOUSE_BM:
640 packetsize = 3;
641 break;
642 case NUM_MOUSE_DRVS:
643 /* Uh oh.. */
644 packetsize = 0;
645 break;
646 }
647
648 /* Read as many packets as possible */
649 nread = read(mouse_fd, &mousebuf[start], BUFSIZ-start);
650 if ( nread < 0 ) {
651 return;
652 }
653 nread += start;
654#ifdef DEBUG_MOUSE
655 fprintf(stderr, "Read %d bytes from mouse, start = %d\n", nread, start);
656#endif
657 for ( i=0; i<(nread-(packetsize-1)); i += packetsize ) {
658 switch (mouse_drv) {
659 case MOUSE_NONE:
660 break;
661 case MOUSE_GPM:
662 /* GPM protocol has 0x80 in high byte */
663 if ( (mousebuf[i] & 0xF8) != 0x80 ) {
664 /* Go to next byte */
665 i -= (packetsize-1);
666 continue;
667 }
668 /* Get current mouse state */
669 button = (~mousebuf[i]) & 0x07;
670 dx = (signed char)(mousebuf[i+1]) +
671 (signed char)(mousebuf[i+3]);
672 dy = -((signed char)(mousebuf[i+2]) +
673 (signed char)(mousebuf[i+4]));
674 break;
675 case MOUSE_PS2:
676 /* PS/2 protocol has nothing in high byte */
677 if ( (mousebuf[i] & 0xC0) != 0 ) {
678 /* Go to next byte */
679 i -= (packetsize-1);
680 continue;
681 }
682 /* Get current mouse state */
683 button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/
684 (mousebuf[i] & 0x02) >> 1 | /*Right*/
685 (mousebuf[i] & 0x01) << 2; /*Left*/
686 dx = (mousebuf[i] & 0x10) ?
687 mousebuf[i+1] - 256 : mousebuf[i+1];
688 dy = (mousebuf[i] & 0x20) ?
689 -(mousebuf[i+2] - 256) : -mousebuf[i+2];
690 break;
691 case MOUSE_IMPS2:
692 /* Get current mouse state */
693 button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/
694 (mousebuf[i] & 0x02) >> 1 | /*Right*/
695 (mousebuf[i] & 0x01) << 2 | /*Left*/
696 (mousebuf[i] & 0x40) >> 3 | /* 4 */
697 (mousebuf[i] & 0x80) >> 3; /* 5 */
698 dx = (mousebuf[i] & 0x10) ?
699 mousebuf[i+1] - 256 : mousebuf[i+1];
700 dy = (mousebuf[i] & 0x20) ?
701 -(mousebuf[i+2] - 256) : -mousebuf[i+2];
702 switch (mousebuf[i+3]&0x0F) {
703 case 0x0E: /* DX = +1 */
704 case 0x02: /* DX = -1 */
705 break;
706 case 0x0F: /* DY = +1 (map button 4) */
707 FB_vgamousecallback(button | (1<<3),
708 1, 0, 0);
709 break;
710 case 0x01: /* DY = -1 (map button 5) */
711 FB_vgamousecallback(button | (1<<4),
712 1, 0, 0);
713 break;
714 }
715 break;
716 case MOUSE_MS:
717 /* Microsoft protocol has 0x40 in high byte */
718 if ( (mousebuf[i] & 0x40) != 0x40 ) {
719 /* Go to next byte */
720 i -= (packetsize-1);
721 continue;
722 }
723 /* Get current mouse state */
724 button = ((mousebuf[i] & 0x20) >> 3) |
725 ((mousebuf[i] & 0x10) >> 4);
726 dx = (signed char)(((mousebuf[i] & 0x03) << 6) |
727 (mousebuf[i + 1] & 0x3F));
728 dy = (signed char)(((mousebuf[i] & 0x0C) << 4) |
729 (mousebuf[i + 2] & 0x3F));
730 break;
731 case MOUSE_BM:
732 /* BusMouse protocol has 0xF8 in high byte */
733 if ( (mousebuf[i] & 0xF8) != 0x80 ) {
734 /* Go to next byte */
735 i -= (packetsize-1);
736 continue;
737 }
738 /* Get current mouse state */
739 button = (~mousebuf[i]) & 0x07;
740 dx = (signed char)mousebuf[i+1];
741 dy = -(signed char)mousebuf[i+2];
742 break;
743 case NUM_MOUSE_DRVS:
744 /* Uh oh.. */
745 dx = 0;
746 dy = 0;
747 break;
748 }
749 GS_vgamousecallback(button, dx, dy);
750 }
751 if ( i < nread ) {
752 SDL_memcpy(mousebuf, &mousebuf[i], (nread-i));
753 start = (nread-i);
754 } else {
755 start = 0;
756 }
757 return;
758}
759
760static void handle_keyboard(_THIS)
761{
762 unsigned char keybuf[BUFSIZ];
763 int i, nread;
764 int pressed;
765 int scancode;
766 SDL_keysym keysym;
767
768 nread = read(keyboard_fd, keybuf, BUFSIZ);
769 for ( i=0; i<nread; ++i ) {
770 scancode = keybuf[i] & 0x7F;
771 if ( keybuf[i] & 0x80 ) {
772 pressed = SDL_RELEASED;
773 } else {
774 pressed = SDL_PRESSED;
775 }
776 TranslateKey(scancode, &keysym);
777 posted += SDL_PrivateKeyboard(pressed, &keysym);
778 }
779}
780
781void GS_PumpEvents(_THIS)
782{
783 fd_set fdset;
784 int max_fd;
785 static struct timeval zero;
786
787 do {
788 posted = 0;
789
790 FD_ZERO(&fdset);
791 max_fd = 0;
792 if ( keyboard_fd >= 0 ) {
793 FD_SET(keyboard_fd, &fdset);
794 if ( max_fd < keyboard_fd ) {
795 max_fd = keyboard_fd;
796 }
797 }
798 if ( mouse_fd >= 0 ) {
799 FD_SET(mouse_fd, &fdset);
800 if ( max_fd < mouse_fd ) {
801 max_fd = mouse_fd;
802 }
803 }
804 if ( select(max_fd+1, &fdset, NULL, NULL, &zero) > 0 ) {
805 if ( keyboard_fd >= 0 ) {
806 if ( FD_ISSET(keyboard_fd, &fdset) ) {
807 handle_keyboard(this);
808 }
809 }
810 if ( mouse_fd >= 0 ) {
811 if ( FD_ISSET(mouse_fd, &fdset) ) {
812 handle_mouse(this);
813 }
814 }
815 }
816 } while ( posted );
817}
818
819void GS_InitOSKeymap(_THIS)
820{
821 int i;
822
823 /* Initialize the Linux key translation table */
824
825 /* First get the ascii keys and others not well handled */
826 for (i=0; i<SDL_arraysize(keymap); ++i) {
827 switch(i) {
828 /* These aren't handled by the x86 kernel keymapping (?) */
829 case SCANCODE_PRINTSCREEN:
830 keymap[i] = SDLK_PRINT;
831 break;
832 case SCANCODE_BREAK:
833 keymap[i] = SDLK_BREAK;
834 break;
835 case SCANCODE_BREAK_ALTERNATIVE:
836 keymap[i] = SDLK_PAUSE;
837 break;
838 case SCANCODE_LEFTSHIFT:
839 keymap[i] = SDLK_LSHIFT;
840 break;
841 case SCANCODE_RIGHTSHIFT:
842 keymap[i] = SDLK_RSHIFT;
843 break;
844 case SCANCODE_LEFTCONTROL:
845 keymap[i] = SDLK_LCTRL;
846 break;
847 case SCANCODE_RIGHTCONTROL:
848 keymap[i] = SDLK_RCTRL;
849 break;
850 case SCANCODE_RIGHTWIN:
851 keymap[i] = SDLK_RSUPER;
852 break;
853 case SCANCODE_LEFTWIN:
854 keymap[i] = SDLK_LSUPER;
855 break;
856 case 127:
857 keymap[i] = SDLK_MENU;
858 break;
859 /* this should take care of all standard ascii keys */
860 default:
861 keymap[i] = KVAL(vga_keymap[0][i]);
862 break;
863 }
864 }
865 for (i=0; i<SDL_arraysize(keymap); ++i) {
866 switch(keymap_temp[i]) {
867 case K_F1: keymap[i] = SDLK_F1; break;
868 case K_F2: keymap[i] = SDLK_F2; break;
869 case K_F3: keymap[i] = SDLK_F3; break;
870 case K_F4: keymap[i] = SDLK_F4; break;
871 case K_F5: keymap[i] = SDLK_F5; break;
872 case K_F6: keymap[i] = SDLK_F6; break;
873 case K_F7: keymap[i] = SDLK_F7; break;
874 case K_F8: keymap[i] = SDLK_F8; break;
875 case K_F9: keymap[i] = SDLK_F9; break;
876 case K_F10: keymap[i] = SDLK_F10; break;
877 case K_F11: keymap[i] = SDLK_F11; break;
878 case K_F12: keymap[i] = SDLK_F12; break;
879
880 case K_DOWN: keymap[i] = SDLK_DOWN; break;
881 case K_LEFT: keymap[i] = SDLK_LEFT; break;
882 case K_RIGHT: keymap[i] = SDLK_RIGHT; break;
883 case K_UP: keymap[i] = SDLK_UP; break;
884
885 case K_P0: keymap[i] = SDLK_KP0; break;
886 case K_P1: keymap[i] = SDLK_KP1; break;
887 case K_P2: keymap[i] = SDLK_KP2; break;
888 case K_P3: keymap[i] = SDLK_KP3; break;
889 case K_P4: keymap[i] = SDLK_KP4; break;
890 case K_P5: keymap[i] = SDLK_KP5; break;
891 case K_P6: keymap[i] = SDLK_KP6; break;
892 case K_P7: keymap[i] = SDLK_KP7; break;
893 case K_P8: keymap[i] = SDLK_KP8; break;
894 case K_P9: keymap[i] = SDLK_KP9; break;
895 case K_PPLUS: keymap[i] = SDLK_KP_PLUS; break;
896 case K_PMINUS: keymap[i] = SDLK_KP_MINUS; break;
897 case K_PSTAR: keymap[i] = SDLK_KP_MULTIPLY; break;
898 case K_PSLASH: keymap[i] = SDLK_KP_DIVIDE; break;
899 case K_PENTER: keymap[i] = SDLK_KP_ENTER; break;
900 case K_PDOT: keymap[i] = SDLK_KP_PERIOD; break;
901
902 case K_SHIFT: if ( keymap[i] != SDLK_RSHIFT )
903 keymap[i] = SDLK_LSHIFT;
904 break;
905 case K_SHIFTL: keymap[i] = SDLK_LSHIFT; break;
906 case K_SHIFTR: keymap[i] = SDLK_RSHIFT; break;
907 case K_CTRL: if ( keymap[i] != SDLK_RCTRL )
908 keymap[i] = SDLK_LCTRL;
909 break;
910 case K_CTRLL: keymap[i] = SDLK_LCTRL; break;
911 case K_CTRLR: keymap[i] = SDLK_RCTRL; break;
912 case K_ALT: keymap[i] = SDLK_LALT; break;
913 case K_ALTGR: keymap[i] = SDLK_RALT; break;
914
915 case K_INSERT: keymap[i] = SDLK_INSERT; break;
916 case K_REMOVE: keymap[i] = SDLK_DELETE; break;
917 case K_PGUP: keymap[i] = SDLK_PAGEUP; break;
918 case K_PGDN: keymap[i] = SDLK_PAGEDOWN; break;
919 case K_FIND: keymap[i] = SDLK_HOME; break;
920 case K_SELECT: keymap[i] = SDLK_END; break;
921
922 case K_NUM: keymap[i] = SDLK_NUMLOCK; break;
923 case K_CAPS: keymap[i] = SDLK_CAPSLOCK; break;
924
925 case K_F13: keymap[i] = SDLK_PRINT; break;
926 case K_HOLD: keymap[i] = SDLK_SCROLLOCK; break;
927 case K_PAUSE: keymap[i] = SDLK_PAUSE; break;
928
929 case 127: keymap[i] = SDLK_BACKSPACE; break;
930
931 default: break;
932 }
933 }
934}
935
936static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym)
937{
938 /* Set the keysym information */
939 keysym->scancode = scancode;
940 keysym->sym = keymap[scancode];
941 keysym->mod = KMOD_NONE;
942
943 /* If UNICODE is on, get the UNICODE value for the key */
944 keysym->unicode = 0;
945 if ( SDL_TranslateUNICODE ) {
946 int map;
947 SDLMod modstate;
948
949 modstate = SDL_GetModState();
950 map = 0;
951 if ( modstate & KMOD_SHIFT ) {
952 map |= (1<<KG_SHIFT);
953 }
954 if ( modstate & KMOD_CTRL ) {
955 map |= (1<<KG_CTRL);
956 }
957 if ( modstate & KMOD_ALT ) {
958 map |= (1<<KG_ALT);
959 }
960 if ( modstate & KMOD_MODE ) {
961 map |= (1<<KG_ALTGR);
962 }
963 if ( KTYP(vga_keymap[map][scancode]) == KT_LETTER ) {
964 if ( modstate & KMOD_CAPS ) {
965 map ^= (1<<KG_SHIFT);
966 }
967 }
968 if ( KTYP(vga_keymap[map][scancode]) == KT_PAD ) {
969 if ( modstate & KMOD_NUM ) {
970 keysym->unicode=KVAL(vga_keymap[map][scancode]);
971 }
972 } else {
973 keysym->unicode = KVAL(vga_keymap[map][scancode]);
974 }
975 }
976 return(keysym);
977}
diff --git a/apps/plugins/sdl/src/video/ps2gs/SDL_gsevents_c.h b/apps/plugins/sdl/src/video/ps2gs/SDL_gsevents_c.h
deleted file mode 100644
index 6758ab3e9e..0000000000
--- a/apps/plugins/sdl/src/video/ps2gs/SDL_gsevents_c.h
+++ /dev/null
@@ -1,38 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include "SDL_gsvideo.h"
25
26/* Variables and functions exported by SDL_sysevents.c to other parts
27 of the native video subsystem (SDL_sysvideo.c)
28*/
29extern int GS_OpenKeyboard(_THIS);
30extern void GS_CloseKeyboard(_THIS);
31extern int GS_OpenMouse(_THIS);
32extern void GS_CloseMouse(_THIS);
33extern int GS_EnterGraphicsMode(_THIS);
34extern int GS_InGraphicsMode(_THIS);
35extern void GS_LeaveGraphicsMode(_THIS);
36
37extern void GS_InitOSKeymap(_THIS);
38extern void GS_PumpEvents(_THIS);
diff --git a/apps/plugins/sdl/src/video/ps2gs/SDL_gskeys.h b/apps/plugins/sdl/src/video/ps2gs/SDL_gskeys.h
deleted file mode 100644
index 2b01b6b2e3..0000000000
--- a/apps/plugins/sdl/src/video/ps2gs/SDL_gskeys.h
+++ /dev/null
@@ -1,139 +0,0 @@
1
2/* Scancodes for the Linux framebuffer console
3 - Taken with thanks from SVGAlib 1.4.0
4*/
5
6#define SCANCODE_ESCAPE 1
7
8#define SCANCODE_1 2
9#define SCANCODE_2 3
10#define SCANCODE_3 4
11#define SCANCODE_4 5
12#define SCANCODE_5 6
13#define SCANCODE_6 7
14#define SCANCODE_7 8
15#define SCANCODE_8 9
16#define SCANCODE_9 10
17#define SCANCODE_0 11
18
19#define SCANCODE_MINUS 12
20#define SCANCODE_EQUAL 13
21
22#define SCANCODE_BACKSPACE 14
23#define SCANCODE_TAB 15
24
25#define SCANCODE_Q 16
26#define SCANCODE_W 17
27#define SCANCODE_E 18
28#define SCANCODE_R 19
29#define SCANCODE_T 20
30#define SCANCODE_Y 21
31#define SCANCODE_U 22
32#define SCANCODE_I 23
33#define SCANCODE_O 24
34#define SCANCODE_P 25
35#define SCANCODE_BRACKET_LEFT 26
36#define SCANCODE_BRACKET_RIGHT 27
37
38#define SCANCODE_ENTER 28
39
40#define SCANCODE_LEFTCONTROL 29
41
42#define SCANCODE_A 30
43#define SCANCODE_S 31
44#define SCANCODE_D 32
45#define SCANCODE_F 33
46#define SCANCODE_G 34
47#define SCANCODE_H 35
48#define SCANCODE_J 36
49#define SCANCODE_K 37
50#define SCANCODE_L 38
51#define SCANCODE_SEMICOLON 39
52#define SCANCODE_APOSTROPHE 40
53#define SCANCODE_GRAVE 41
54
55#define SCANCODE_LEFTSHIFT 42
56#define SCANCODE_BACKSLASH 43
57
58#define SCANCODE_Z 44
59#define SCANCODE_X 45
60#define SCANCODE_C 46
61#define SCANCODE_V 47
62#define SCANCODE_B 48
63#define SCANCODE_N 49
64#define SCANCODE_M 50
65#define SCANCODE_COMMA 51
66#define SCANCODE_PERIOD 52
67#define SCANCODE_SLASH 53
68
69#define SCANCODE_RIGHTSHIFT 54
70#define SCANCODE_KEYPADMULTIPLY 55
71
72#define SCANCODE_LEFTALT 56
73#define SCANCODE_SPACE 57
74#define SCANCODE_CAPSLOCK 58
75
76#define SCANCODE_F1 59
77#define SCANCODE_F2 60
78#define SCANCODE_F3 61
79#define SCANCODE_F4 62
80#define SCANCODE_F5 63
81#define SCANCODE_F6 64
82#define SCANCODE_F7 65
83#define SCANCODE_F8 66
84#define SCANCODE_F9 67
85#define SCANCODE_F10 68
86
87#define SCANCODE_NUMLOCK 69
88#define SCANCODE_SCROLLLOCK 70
89
90#define SCANCODE_KEYPAD7 71
91#define SCANCODE_CURSORUPLEFT 71
92#define SCANCODE_KEYPAD8 72
93#define SCANCODE_CURSORUP 72
94#define SCANCODE_KEYPAD9 73
95#define SCANCODE_CURSORUPRIGHT 73
96#define SCANCODE_KEYPADMINUS 74
97#define SCANCODE_KEYPAD4 75
98#define SCANCODE_CURSORLEFT 75
99#define SCANCODE_KEYPAD5 76
100#define SCANCODE_KEYPAD6 77
101#define SCANCODE_CURSORRIGHT 77
102#define SCANCODE_KEYPADPLUS 78
103#define SCANCODE_KEYPAD1 79
104#define SCANCODE_CURSORDOWNLEFT 79
105#define SCANCODE_KEYPAD2 80
106#define SCANCODE_CURSORDOWN 80
107#define SCANCODE_KEYPAD3 81
108#define SCANCODE_CURSORDOWNRIGHT 81
109#define SCANCODE_KEYPAD0 82
110#define SCANCODE_KEYPADPERIOD 83
111
112#define SCANCODE_LESS 86
113
114#define SCANCODE_F11 87
115#define SCANCODE_F12 88
116
117#define SCANCODE_KEYPADENTER 96
118#define SCANCODE_RIGHTCONTROL 97
119#define SCANCODE_CONTROL 97
120#define SCANCODE_KEYPADDIVIDE 98
121#define SCANCODE_PRINTSCREEN 99
122#define SCANCODE_RIGHTALT 100
123#define SCANCODE_BREAK 101 /* Beware: is 119 */
124#define SCANCODE_BREAK_ALTERNATIVE 119 /* on some keyboards! */
125
126#define SCANCODE_HOME 102
127#define SCANCODE_CURSORBLOCKUP 103 /* Cursor key block */
128#define SCANCODE_PAGEUP 104
129#define SCANCODE_CURSORBLOCKLEFT 105 /* Cursor key block */
130#define SCANCODE_CURSORBLOCKRIGHT 106 /* Cursor key block */
131#define SCANCODE_END 107
132#define SCANCODE_CURSORBLOCKDOWN 108 /* Cursor key block */
133#define SCANCODE_PAGEDOWN 109
134#define SCANCODE_INSERT 110
135#define SCANCODE_REMOVE 111
136
137#define SCANCODE_RIGHTWIN 126
138#define SCANCODE_LEFTWIN 125
139
diff --git a/apps/plugins/sdl/src/video/ps2gs/SDL_gsmouse.c b/apps/plugins/sdl/src/video/ps2gs/SDL_gsmouse.c
deleted file mode 100644
index e0d320d660..0000000000
--- a/apps/plugins/sdl/src/video/ps2gs/SDL_gsmouse.c
+++ /dev/null
@@ -1,146 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include <sys/ioctl.h>
25
26#include "SDL_mouse.h"
27#include "../../events/SDL_events_c.h"
28#include "../SDL_cursor_c.h"
29#include "SDL_gsvideo.h"
30#include "SDL_gsmouse_c.h"
31
32
33/* The implementation dependent data for the window manager cursor */
34struct WMcursor {
35 int unused;
36};
37
38/* There isn't any implementation dependent data */
39void GS_FreeWMCursor(_THIS, WMcursor *cursor)
40{
41 return;
42}
43
44/* There isn't any implementation dependent data */
45WMcursor *GS_CreateWMCursor(_THIS,
46 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
47{
48 return((WMcursor *)0x01);
49}
50
51static void GS_MoveCursor(_THIS, SDL_Cursor *cursor, int x, int y)
52{
53 SDL_Surface *screen;
54 struct ps2_image image;
55 SDL_Rect area;
56 int mouse_y1, mouse_y2;
57 void *saved_pixels;
58 int screen_updated;
59
60 /* Lock so we don't interrupt an update with mouse motion */
61 SDL_LockCursor();
62
63 /* Make sure any pending DMA has completed */
64 if ( dma_pending ) {
65 ioctl(console_fd, PS2IOC_SENDQCT, 1);
66 dma_pending = 0;
67 }
68
69 /* Remove the cursor image from the DMA area */
70 screen = this->screen;
71 saved_pixels = screen->pixels;
72 screen->pixels = mapped_mem + screen->offset;
73 screen_updated = 0;
74 if ( cursor_drawn ) {
75 SDL_EraseCursorNoLock(screen);
76 cursor_drawn = 0;
77 screen_updated = 1;
78 }
79
80 /* Save the current mouse area */
81 SDL_MouseRect(&area);
82 mouse_y1 = area.y;
83 mouse_y2 = area.y+area.h;
84
85 /* Only draw the new cursor if there was one passed in */
86 if ( cursor ) {
87 /* Set the new location */
88 cursor->area.x = (x - cursor->hot_x);
89 cursor->area.y = (y - cursor->hot_y);
90
91 /* Draw the cursor at the new location */
92 if ( (SDL_cursorstate & CURSOR_VISIBLE) && screen->pixels ) {
93 SDL_DrawCursorNoLock(screen);
94 cursor_drawn = 1;
95 screen_updated = 1;
96 }
97 }
98 screen->pixels = saved_pixels;
99
100 /* Update the affected area of the screen */
101 if ( screen_updated ) {
102 SDL_MouseRect(&area);
103 if ( area.y < mouse_y1 ) {
104 mouse_y1 = area.y;
105 }
106 if ( (area.y+area.h) > mouse_y2 ) {
107 mouse_y2 = area.y+area.h;
108 }
109 image = screen_image;
110 image.y += screen->offset / screen->pitch + mouse_y1;
111 image.h = mouse_y2 - mouse_y1;
112 image.ptr = mapped_mem +
113 (image.y - screen_image.y) * screen->pitch;
114 ioctl(console_fd, PS2IOC_LOADIMAGE, &image);
115
116 /* Need to scale offscreen image to TV output */
117 if ( image.y > 0 ) {
118 scaleimage_nonblock(console_fd,
119 tex_tags_mem, scale_tags_mem);
120 }
121 }
122
123 /* We're finished */
124 SDL_UnlockCursor();
125}
126
127void GS_MoveWMCursor(_THIS, int x, int y)
128{
129 GS_MoveCursor(this, SDL_cursor, x, y);
130}
131
132int GS_ShowWMCursor(_THIS, WMcursor *wmcursor)
133{
134 SDL_Cursor *cursor;
135 int x, y;
136
137 /* Draw the cursor at the appropriate location */
138 SDL_GetMouseState(&x, &y);
139 if ( wmcursor ) {
140 cursor = SDL_cursor;
141 } else {
142 cursor = NULL;
143 }
144 GS_MoveCursor(this, cursor, x, y);
145 return(1);
146}
diff --git a/apps/plugins/sdl/src/video/ps2gs/SDL_gsmouse_c.h b/apps/plugins/sdl/src/video/ps2gs/SDL_gsmouse_c.h
deleted file mode 100644
index c507ed4a60..0000000000
--- a/apps/plugins/sdl/src/video/ps2gs/SDL_gsmouse_c.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#include "SDL_gsvideo.h"
25
26/* This is the maximum size of the cursor sprite */
27#define CURSOR_W 32
28#define CURSOR_H 32
29#define CURSOR_W_POW 5 /* 32 = 2^5 */
30#define CURSOR_H_POW 5 /* 32 = 2^5 */
31
32/* Functions to be exported */
33extern void GS_FreeWMCursor(_THIS, WMcursor *cursor);
34extern WMcursor *GS_CreateWMCursor(_THIS,
35 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
36extern void GS_MoveWMCursor(_THIS, int x, int y);
37extern int GS_ShowWMCursor(_THIS, WMcursor *cursor);
diff --git a/apps/plugins/sdl/src/video/ps2gs/SDL_gsvideo.c b/apps/plugins/sdl/src/video/ps2gs/SDL_gsvideo.c
deleted file mode 100644
index e172c60dc1..0000000000
--- a/apps/plugins/sdl/src/video/ps2gs/SDL_gsvideo.c
+++ /dev/null
@@ -1,689 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/* Framebuffer console based SDL video driver implementation.
25*/
26
27#include <fcntl.h>
28#include <unistd.h>
29#include <sys/ioctl.h>
30#include <sys/mman.h>
31
32#include "SDL_video.h"
33#include "SDL_mouse.h"
34#include "../SDL_sysvideo.h"
35#include "../SDL_pixels_c.h"
36#include "../../events/SDL_events_c.h"
37#include "../SDL_cursor_c.h"
38#include "SDL_gsvideo.h"
39#include "SDL_gsmouse_c.h"
40#include "SDL_gsevents_c.h"
41#include "SDL_gsyuv_c.h"
42
43
44/* Initialization/Query functions */
45static int GS_VideoInit(_THIS, SDL_PixelFormat *vformat);
46static SDL_Rect **GS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
47static SDL_Surface *GS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
48static int GS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
49static void GS_VideoQuit(_THIS);
50
51/* Hardware surface functions */
52static int GS_AllocHWSurface(_THIS, SDL_Surface *surface);
53static int GS_LockHWSurface(_THIS, SDL_Surface *surface);
54static void GS_UnlockHWSurface(_THIS, SDL_Surface *surface);
55static void GS_FreeHWSurface(_THIS, SDL_Surface *surface);
56
57/* GS driver bootstrap functions */
58
59static int GS_Available(void)
60{
61 int console, memory;
62
63 console = open(PS2_DEV_GS, O_RDWR, 0);
64 if ( console >= 0 ) {
65 close(console);
66 }
67 memory = open(PS2_DEV_MEM, O_RDWR, 0);
68 if ( memory >= 0 ) {
69 close(memory);
70 }
71 return((console >= 0) && (memory >= 0));
72}
73
74static void GS_DeleteDevice(SDL_VideoDevice *device)
75{
76 SDL_free(device->hidden);
77 SDL_free(device);
78}
79
80static SDL_VideoDevice *GS_CreateDevice(int devindex)
81{
82 SDL_VideoDevice *this;
83
84 /* Initialize all variables that we clean on shutdown */
85 this = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
86 if ( this ) {
87 SDL_memset(this, 0, (sizeof *this));
88 this->hidden = (struct SDL_PrivateVideoData *)
89 SDL_malloc((sizeof *this->hidden));
90 }
91 if ( (this == NULL) || (this->hidden == NULL) ) {
92 SDL_OutOfMemory();
93 if ( this ) {
94 SDL_free(this);
95 }
96 return(0);
97 }
98 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
99 mouse_fd = -1;
100 keyboard_fd = -1;
101
102 /* Set the function pointers */
103 this->VideoInit = GS_VideoInit;
104 this->ListModes = GS_ListModes;
105 this->SetVideoMode = GS_SetVideoMode;
106 this->CreateYUVOverlay = GS_CreateYUVOverlay;
107 this->SetColors = GS_SetColors;
108 this->UpdateRects = NULL;
109 this->VideoQuit = GS_VideoQuit;
110 this->AllocHWSurface = GS_AllocHWSurface;
111 this->CheckHWBlit = NULL;
112 this->FillHWRect = NULL;
113 this->SetHWColorKey = NULL;
114 this->SetHWAlpha = NULL;
115 this->LockHWSurface = GS_LockHWSurface;
116 this->UnlockHWSurface = GS_UnlockHWSurface;
117 this->FlipHWSurface = NULL;
118 this->FreeHWSurface = GS_FreeHWSurface;
119 this->SetIcon = NULL;
120 this->SetCaption = NULL;
121 this->GetWMInfo = NULL;
122 this->FreeWMCursor = GS_FreeWMCursor;
123 this->CreateWMCursor = GS_CreateWMCursor;
124 this->ShowWMCursor = GS_ShowWMCursor;
125 this->MoveWMCursor = GS_MoveWMCursor;
126 this->InitOSKeymap = GS_InitOSKeymap;
127 this->PumpEvents = GS_PumpEvents;
128
129 this->free = GS_DeleteDevice;
130
131 return this;
132}
133
134VideoBootStrap PS2GS_bootstrap = {
135 "ps2gs", "PlayStation 2 Graphics Synthesizer",
136 GS_Available, GS_CreateDevice
137};
138
139/* These are the pixel formats for the 32, 24, and 16 bit video modes */
140static struct {
141 int bpp;
142 Uint32 r;
143 Uint32 g;
144 Uint32 b;
145} GS_pixelmasks[] = {
146 { 32, 0x000000FF, /* RGB little-endian */
147 0x0000FF00,
148 0x00FF0000 },
149 { 24, 0x000000FF, /* RGB little-endian */
150 0x0000FF00,
151 0x00FF0000 },
152 { 16, 0x0000001f, /* RGB little-endian */
153 0x000003e0,
154 0x00007c00 },
155};
156/* This is a mapping from SDL bytes-per-pixel to GS pixel format */
157static int GS_formatmap[] = {
158 -1, /* 0 bpp, not a legal value */
159 -1, /* 8 bpp, not supported (yet?) */
160 PS2_GS_PSMCT16, /* 16 bpp */
161 PS2_GS_PSMCT24, /* 24 bpp */
162 PS2_GS_PSMCT32 /* 32 bpp */
163};
164
165static unsigned long long head_tags[] __attribute__((aligned(16))) = {
166 4 | (1LL << 60), /* GIFtag */
167 0x0e, /* A+D */
168 0, /* 2 */
169 PS2_GS_BITBLTBUF,
170 0, /* 4 */
171 PS2_GS_TRXPOS,
172 0, /* 6 */
173 PS2_GS_TRXREG,
174 0, /* 8 */
175 PS2_GS_TRXDIR
176};
177
178#define MAXIMG (32767 * 16)
179#define MAXTAGS 8
180
181static inline int loadimage_nonblock(int fd, struct ps2_image *image, int size,
182 unsigned long long *hm,
183 unsigned long long *im)
184{
185 struct ps2_plist plist;
186 struct ps2_packet packet[1 + MAXTAGS * 2];
187 int isize;
188 int pnum, it, eop;
189 char *data;
190
191 /* initialize the variables */
192 data = (char *)image->ptr;
193 pnum = it = eop = 0;
194 plist.packet = packet;
195
196 /* make BITBLT packet */
197 packet[pnum].ptr = hm;
198 packet[pnum].len = sizeof(head_tags);
199 pnum++;
200 hm[2] = ((unsigned long long)image->fbp << 32) |
201 ((unsigned long long)image->fbw << 48) |
202 ((unsigned long long)image->psm << 56);
203 hm[4] = ((unsigned long long)image->x << 32) |
204 ((unsigned long long)image->y << 48);
205 hm[6] = (unsigned long long)image->w |
206 ((unsigned long long)image->h << 32);
207
208 /* make image mode tags */
209 while (!eop) {
210 isize = size > MAXIMG ? MAXIMG : size;
211 size -= isize;
212 eop = (size == 0);
213
214 packet[pnum].ptr = &im[it];
215 packet[pnum].len = sizeof(unsigned long long) * 2;
216 pnum++;
217 im[it++] = (isize >> 4) | (eop ? (1 << 15) : 0) | (2LL << 58);
218 im[it++] = 0;
219
220 packet[pnum].ptr = (void *)data;
221 packet[pnum].len = isize;
222 pnum++;
223 data += isize;
224 }
225 plist.num = pnum;
226
227 return ioctl(fd, PS2IOC_SENDL, &plist);
228}
229
230static unsigned long long tex_tags[] __attribute__((aligned(16))) = {
231 3 | (1LL << 60), /* GIFtag */
232 0x0e, /* A+D */
233 0, /* 2 */
234 PS2_GS_TEX0_1,
235 (1 << 5) + (1 << 6),
236 PS2_GS_TEX1_1,
237 0,
238 PS2_GS_TEXFLUSH
239};
240static unsigned long long scale_tags[] __attribute__((aligned(16))) = {
241 5 | (1LL << 60), /* GIFtag */
242 0x0e, /* A+D */
243 6 + (1 << 4) + (1 << 8),
244 PS2_GS_PRIM,
245 ((unsigned long long)0 * 16) + (((unsigned long long)0 * 16) << 16),
246 PS2_GS_UV,
247 ((unsigned long long)0 * 16) + (((unsigned long long)0 * 16) << 16),
248 PS2_GS_XYZ2,
249 0, /* 8 */
250 PS2_GS_UV,
251 0, /* 10 */
252 PS2_GS_XYZ2
253};
254
255
256int scaleimage_nonblock(int fd, unsigned long long *tm, unsigned long long *sm)
257{
258 struct ps2_plist plist;
259 struct ps2_packet packet[2];
260
261 /* initialize the variables */
262 plist.num = 2;
263 plist.packet = packet;
264
265 packet[0].ptr = tm;
266 packet[0].len = sizeof(tex_tags);
267 packet[1].ptr = sm;
268 packet[1].len = sizeof(scale_tags);
269
270 return ioctl(fd, PS2IOC_SENDL, &plist);
271}
272
273static int power_of_2(int value)
274{
275 int shift;
276
277 for ( shift = 0; (1<<shift) < value; ++shift ) {
278 /* Keep looking */ ;
279 }
280 return(shift);
281}
282
283static int GS_VideoInit(_THIS, SDL_PixelFormat *vformat)
284{
285 struct ps2_screeninfo vinfo;
286
287 /* Initialize the library */
288 console_fd = open(PS2_DEV_GS, O_RDWR, 0);
289 if ( console_fd < 0 ) {
290 SDL_SetError("Unable to open %s", PS2_DEV_GS);
291 return(-1);
292 }
293 memory_fd = open(PS2_DEV_MEM, O_RDWR, 0);
294 if ( memory_fd < 0 ) {
295 close(console_fd);
296 console_fd = -1;
297 SDL_SetError("Unable to open %s", PS2_DEV_MEM);
298 return(-1);
299 }
300
301 if ( ioctl(console_fd, PS2IOC_GSCREENINFO, &vinfo) < 0 ) {
302 close(memory_fd);
303 close(console_fd);
304 console_fd = -1;
305 SDL_SetError("Couldn't get console pixel format");
306 return(-1);
307 }
308
309 /* Determine the current screen size */
310 this->info.current_w = vinfo.w;
311 this->info.current_h = vinfo.h;
312
313 /* Determine the current screen depth */
314 switch (vinfo.psm) {
315 /* Supported pixel formats */
316 case PS2_GS_PSMCT32:
317 case PS2_GS_PSMCT24:
318 case PS2_GS_PSMCT16:
319 break;
320 default:
321 GS_VideoQuit(this);
322 SDL_SetError("Unknown console pixel format: %d", vinfo.psm);
323 return(-1);
324 }
325 vformat->BitsPerPixel = GS_pixelmasks[vinfo.psm].bpp;
326 vformat->Rmask = GS_pixelmasks[vinfo.psm].r;
327 vformat->Gmask = GS_pixelmasks[vinfo.psm].g;
328 vformat->Bmask = GS_pixelmasks[vinfo.psm].b;
329 saved_vinfo = vinfo;
330
331 /* Enable mouse and keyboard support */
332 if ( GS_OpenKeyboard(this) < 0 ) {
333 GS_VideoQuit(this);
334 SDL_SetError("Unable to open keyboard");
335 return(-1);
336 }
337 if ( GS_OpenMouse(this) < 0 ) {
338 const char *sdl_nomouse;
339
340 sdl_nomouse = SDL_getenv("SDL_NOMOUSE");
341 if ( ! sdl_nomouse ) {
342 GS_VideoQuit(this);
343 SDL_SetError("Unable to open mouse");
344 return(-1);
345 }
346 }
347
348 /* We're done! */
349 return(0);
350}
351
352static SDL_Rect **GS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
353{
354 static SDL_Rect GS_vesa_mode_list[] = {
355 { 0, 0, 1280, 1024 },
356 { 0, 0, 1024, 768 },
357 { 0, 0, 800, 600 },
358 { 0, 0, 640, 480 }
359 };
360 static SDL_Rect *GS_vesa_modes[] = {
361 &GS_vesa_mode_list[0],
362 &GS_vesa_mode_list[1],
363 &GS_vesa_mode_list[2],
364 &GS_vesa_mode_list[3],
365 NULL
366 };
367 static SDL_Rect GS_tvout_stretch;
368 static SDL_Rect GS_tvout_mode;
369 static SDL_Rect *GS_tvout_modes[3];
370 SDL_Rect **modes = NULL;
371
372 switch (format->BitsPerPixel) {
373 case 16:
374 case 24:
375 case 32:
376 if ( saved_vinfo.mode == PS2_GS_VESA ) {
377 modes = GS_vesa_modes;
378 } else {
379 int i, j = 0;
380
381// FIXME - what's wrong with the stretch code at 16 bpp?
382if ( format->BitsPerPixel != 32 ) break;
383 /* Add a mode that we could possibly stretch to */
384 for ( i=0; GS_vesa_modes[i]; ++i ) {
385 if ( (GS_vesa_modes[i]->w == saved_vinfo.w) &&
386 (GS_vesa_modes[i]->h != saved_vinfo.h) ) {
387 GS_tvout_stretch.w=GS_vesa_modes[i]->w;
388 GS_tvout_stretch.h=GS_vesa_modes[i]->h;
389 GS_tvout_modes[j++] = &GS_tvout_stretch;
390 break;
391 }
392 }
393 /* Add the current TV video mode */
394 GS_tvout_mode.w = saved_vinfo.w;
395 GS_tvout_mode.h = saved_vinfo.h;
396 GS_tvout_modes[j++] = &GS_tvout_mode;
397 GS_tvout_modes[j++] = NULL;
398
399 /* Return the created list of modes */
400 modes = GS_tvout_modes;
401 }
402 break;
403 default:
404 break;
405 }
406 return(modes);
407}
408
409/* Various screen update functions available */
410static void GS_DMAFullUpdate(_THIS, int numrects, SDL_Rect *rects);
411
412static SDL_Surface *GS_SetVideoMode(_THIS, SDL_Surface *current,
413 int width, int height, int bpp, Uint32 flags)
414{
415 struct ps2_screeninfo vinfo;
416
417 /* Set the terminal into graphics mode */
418 if ( GS_EnterGraphicsMode(this) < 0 ) {
419 return(NULL);
420 }
421
422 /* Set the video mode and get the final screen format */
423 if ( ioctl(console_fd, PS2IOC_GSCREENINFO, &vinfo) < 0 ) {
424 SDL_SetError("Couldn't get console screen info");
425 return(NULL);
426 }
427 if ( (vinfo.w != width) || (vinfo.h != height) ||
428 (GS_pixelmasks[vinfo.psm].bpp != bpp) ) {
429 /* If we're not in VESA mode, we have to scale resolution */
430 if ( saved_vinfo.mode == PS2_GS_VESA ) {
431 switch (width) {
432 case 640:
433 vinfo.res = PS2_GS_640x480;
434 break;
435 case 800:
436 vinfo.res = PS2_GS_800x600;
437 break;
438 case 1024:
439 vinfo.res = PS2_GS_1024x768;
440 break;
441 case 1280:
442 vinfo.res = PS2_GS_1280x1024;
443 break;
444 default:
445 SDL_SetError("Unsupported resolution: %dx%d\n",
446 width, height);
447 return(NULL);
448 }
449 vinfo.res |= (PS2_GS_75Hz << 8);
450 vinfo.w = width;
451 vinfo.h = height;
452 }
453 vinfo.fbp = 0;
454 vinfo.psm = GS_formatmap[bpp/8];
455 if ( vinfo.psm < 0 ) {
456 SDL_SetError("Unsupported depth: %d bpp\n", bpp);
457 return(NULL);
458 }
459 if ( ioctl(console_fd, PS2IOC_SSCREENINFO, &vinfo) < 0 ) {
460 SDL_SetError("Couldn't set console screen info");
461 return(NULL);
462 }
463
464 /* Unmap the previous DMA buffer */
465 if ( mapped_mem ) {
466 munmap(mapped_mem, mapped_len);
467 mapped_mem = NULL;
468 }
469 }
470 if ( ! SDL_ReallocFormat(current, GS_pixelmasks[vinfo.psm].bpp,
471 GS_pixelmasks[vinfo.psm].r,
472 GS_pixelmasks[vinfo.psm].g,
473 GS_pixelmasks[vinfo.psm].b, 0) ) {
474 return(NULL);
475 }
476
477 /* Set up the new mode framebuffer */
478 current->flags = SDL_FULLSCREEN;
479 current->w = width;
480 current->h = height;
481 current->pitch = SDL_CalculatePitch(current);
482
483 /* Memory map the DMA area for block memory transfer */
484 if ( ! mapped_mem ) {
485 pixels_len = height * current->pitch;
486 mapped_len = pixels_len +
487 /* Screen update DMA command area */
488 sizeof(head_tags) + ((2 * MAXTAGS) * 16);
489 if ( saved_vinfo.mode != PS2_GS_VESA ) {
490 mapped_len += sizeof(tex_tags) + sizeof(scale_tags);
491 }
492 mapped_mem = mmap(0, mapped_len, PROT_READ|PROT_WRITE,
493 MAP_SHARED, memory_fd, 0);
494 if ( mapped_mem == MAP_FAILED ) {
495 SDL_SetError("Unable to map %d bytes for DMA",
496 mapped_len);
497 mapped_mem = NULL;
498 return(NULL);
499 }
500
501 /* Set up the entire screen for DMA transfer */
502 screen_image.ptr = mapped_mem;
503 screen_image.fbp = 0;
504 screen_image.fbw = (vinfo.w + 63) / 64;
505 screen_image.psm = vinfo.psm;
506 screen_image.x = 0;
507 if ( vinfo.h == height ) {
508 screen_image.y = 0;
509 } else {
510 /* Put image offscreen and scale to screen height */
511 screen_image.y = vinfo.h;
512 }
513 screen_image.w = current->w;
514 screen_image.h = current->h;
515
516 /* get screen image data size (qword aligned) */
517 screen_image_size = (screen_image.w * screen_image.h);
518 switch (screen_image.psm) {
519 case PS2_GS_PSMCT32:
520 screen_image_size *= 4;
521 break;
522 case PS2_GS_PSMCT24:
523 screen_image_size *= 3;
524 break;
525 case PS2_GS_PSMCT16:
526 screen_image_size *= 2;
527 break;
528 }
529 screen_image_size = (screen_image_size + 15) & ~15;
530
531 /* Set up the memory for screen update DMA commands */
532 head_tags_mem = (unsigned long long *)
533 (mapped_mem + pixels_len);
534 image_tags_mem = (unsigned long long *)
535 ((caddr_t)head_tags_mem + sizeof(head_tags));
536 SDL_memcpy(head_tags_mem, head_tags, sizeof(head_tags));
537 if ( saved_vinfo.mode != PS2_GS_VESA ) {
538 tex_tags_mem = (unsigned long long *)
539 ((caddr_t)image_tags_mem + ((2*MAXTAGS)*16));
540 scale_tags_mem = (unsigned long long *)
541 ((caddr_t)tex_tags_mem + sizeof(tex_tags));
542 SDL_memcpy(tex_tags_mem, tex_tags, sizeof(tex_tags));
543 tex_tags_mem[2] =
544 (vinfo.h * vinfo.w) / 64 +
545 ((unsigned long long)screen_image.fbw << 14) +
546 ((unsigned long long)screen_image.psm << 20) +
547 ((unsigned long long)power_of_2(screen_image.w) << 26) +
548 ((unsigned long long)power_of_2(screen_image.h) << 30) +
549 ((unsigned long long)1 << 34) +
550 ((unsigned long long)1 << 35);
551 SDL_memcpy(scale_tags_mem, scale_tags, sizeof(scale_tags));
552 scale_tags_mem[8] =
553 ((unsigned long long)screen_image.w * 16) +
554 (((unsigned long long)screen_image.h * 16) << 16);
555 scale_tags_mem[10] =
556 ((unsigned long long)vinfo.w * 16) +
557 (((unsigned long long)vinfo.h * 16) << 16);
558 }
559 }
560 current->pixels = NULL;
561 if ( SDL_getenv("SDL_FULLSCREEN_UPDATE") ) {
562 /* Correct semantics */
563 current->flags |= SDL_ASYNCBLIT;
564 } else {
565 /* We lie here - the screen memory isn't really the visible
566 display memory and still requires an update, but this
567 has the desired effect for most applications.
568 */
569 current->flags |= SDL_HWSURFACE;
570 }
571
572 /* Set the update rectangle function */
573 this->UpdateRects = GS_DMAFullUpdate;
574
575 /* We're done */
576 return(current);
577}
578
579/* We don't support hardware surfaces yet */
580static int GS_AllocHWSurface(_THIS, SDL_Surface *surface)
581{
582 return(-1);
583}
584static void GS_FreeHWSurface(_THIS, SDL_Surface *surface)
585{
586 return;
587}
588static int GS_LockHWSurface(_THIS, SDL_Surface *surface)
589{
590 if ( surface == this->screen ) {
591 /* Since mouse motion affects 'pixels', lock it */
592 SDL_LockCursor();
593
594 /* Make sure any pending DMA has completed */
595 if ( dma_pending ) {
596 ioctl(console_fd, PS2IOC_SENDQCT, 1);
597 dma_pending = 0;
598 }
599
600 /* If the cursor is drawn on the DMA area, remove it */
601 if ( cursor_drawn ) {
602 surface->pixels = mapped_mem + surface->offset;
603 SDL_EraseCursorNoLock(this->screen);
604 cursor_drawn = 0;
605 }
606
607 /* Set the surface pixels to the base of the DMA area */
608 surface->pixels = mapped_mem;
609
610 /* We're finished! */
611 SDL_UnlockCursor();
612 }
613 return(0);
614}
615static void GS_UnlockHWSurface(_THIS, SDL_Surface *surface)
616{
617 if ( surface == this->screen ) {
618 /* Since mouse motion affects 'pixels', lock it */
619 SDL_LockCursor();
620 surface->pixels = NULL;
621 SDL_UnlockCursor();
622 }
623}
624
625static void GS_DMAFullUpdate(_THIS, int numrects, SDL_Rect *rects)
626{
627 /* Lock so we aren't interrupted by a mouse update */
628 SDL_LockCursor();
629
630 /* Make sure any pending DMA has completed */
631 if ( dma_pending ) {
632 ioctl(console_fd, PS2IOC_SENDQCT, 1);
633 dma_pending = 0;
634 }
635
636 /* If the mouse is visible, draw it on the DMA area */
637 if ( (SDL_cursorstate & CURSOR_VISIBLE) && !cursor_drawn ) {
638 this->screen->pixels = mapped_mem + this->screen->offset;
639 SDL_DrawCursorNoLock(this->screen);
640 this->screen->pixels = NULL;
641 cursor_drawn = 1;
642 }
643
644 /* Put the image onto the screen */
645 loadimage_nonblock(console_fd,
646 &screen_image, screen_image_size,
647 head_tags_mem, image_tags_mem);
648 if ( screen_image.y > 0 ) {
649 /* Need to scale offscreen image to TV output */
650 ioctl(console_fd, PS2IOC_SENDQCT, 1);
651 dma_pending = 0;
652 scaleimage_nonblock(console_fd, tex_tags_mem, scale_tags_mem);
653 } else {
654 dma_pending = 1;
655 }
656
657 /* We're finished! */
658 SDL_UnlockCursor();
659}
660
661static int GS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
662{
663 return(0);
664}
665
666static void GS_VideoQuit(_THIS)
667{
668 /* Close console and input file descriptors */
669 if ( console_fd > 0 ) {
670 /* Unmap the video framebuffer */
671 if ( mapped_mem ) {
672 /* Unmap the video framebuffer */
673 munmap(mapped_mem, mapped_len);
674 mapped_mem = NULL;
675 }
676 close(memory_fd);
677
678 /* Restore the original video mode */
679 if ( GS_InGraphicsMode(this) ) {
680 ioctl(console_fd, PS2IOC_SSCREENINFO, &saved_vinfo);
681 }
682
683 /* We're all done with the graphics device */
684 close(console_fd);
685 console_fd = -1;
686 }
687 GS_CloseMouse(this);
688 GS_CloseKeyboard(this);
689}
diff --git a/apps/plugins/sdl/src/video/ps2gs/SDL_gsvideo.h b/apps/plugins/sdl/src/video/ps2gs/SDL_gsvideo.h
deleted file mode 100644
index 8972d70366..0000000000
--- a/apps/plugins/sdl/src/video/ps2gs/SDL_gsvideo.h
+++ /dev/null
@@ -1,95 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef _SDL_gsvideo_h
25#define _SDL_gsvideo_h
26
27#include <sys/types.h>
28#include <termios.h>
29#include <linux/ps2/dev.h>
30#include <linux/ps2/gs.h>
31
32#include "SDL_mouse.h"
33#include "SDL_mutex.h"
34#include "../SDL_sysvideo.h"
35
36/* Hidden "this" pointer for the video functions */
37#define _THIS SDL_VideoDevice *this
38
39
40/* Private display data */
41struct SDL_PrivateVideoData {
42 /* Gotta love that simple PS2 graphics interface. :) */
43 int console_fd;
44 int memory_fd;
45 struct ps2_screeninfo saved_vinfo;
46
47 /* Ye olde linux keyboard code */
48 int current_vt;
49 int saved_vt;
50 int keyboard_fd;
51 int saved_kbd_mode;
52 struct termios saved_kbd_termios;
53
54 /* Ye olde linux mouse code */
55 int mouse_fd;
56 int cursor_drawn;
57
58 /* The memory mapped DMA area and associated variables */
59 caddr_t mapped_mem;
60 int pixels_len;
61 int mapped_len;
62 struct ps2_image screen_image;
63 int screen_image_size;
64 unsigned long long *head_tags_mem;
65 unsigned long long *image_tags_mem;
66 unsigned long long *tex_tags_mem;
67 unsigned long long *scale_tags_mem;
68 int dma_pending;
69};
70/* Old variable names */
71#define console_fd (this->hidden->console_fd)
72#define memory_fd (this->hidden->memory_fd)
73#define saved_vinfo (this->hidden->saved_vinfo)
74#define current_vt (this->hidden->current_vt)
75#define saved_vt (this->hidden->saved_vt)
76#define keyboard_fd (this->hidden->keyboard_fd)
77#define saved_kbd_mode (this->hidden->saved_kbd_mode)
78#define saved_kbd_termios (this->hidden->saved_kbd_termios)
79#define mouse_fd (this->hidden->mouse_fd)
80#define cursor_drawn (this->hidden->cursor_drawn)
81#define mapped_mem (this->hidden->mapped_mem)
82#define pixels_len (this->hidden->pixels_len)
83#define mapped_len (this->hidden->mapped_len)
84#define screen_image (this->hidden->screen_image)
85#define screen_image_size (this->hidden->screen_image_size)
86#define head_tags_mem (this->hidden->head_tags_mem)
87#define image_tags_mem (this->hidden->image_tags_mem)
88#define tex_tags_mem (this->hidden->tex_tags_mem)
89#define scale_tags_mem (this->hidden->scale_tags_mem)
90#define dma_pending (this->hidden->dma_pending)
91
92/* Shared between the mouse and video code for screen update scaling */
93extern int scaleimage_nonblock(int fd,
94 unsigned long long *tm, unsigned long long *sm);
95#endif /* _SDL_gsvideo_h */
diff --git a/apps/plugins/sdl/src/video/ps2gs/SDL_gsyuv.c b/apps/plugins/sdl/src/video/ps2gs/SDL_gsyuv.c
deleted file mode 100644
index ec52a69b25..0000000000
--- a/apps/plugins/sdl/src/video/ps2gs/SDL_gsyuv.c
+++ /dev/null
@@ -1,461 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/* This is the Playstation 2 implementation of YUV video overlays */
25
26#include <fcntl.h>
27#include <unistd.h>
28#include <sys/ioctl.h>
29#include <sys/mman.h>
30#include <asm/page.h> /* For definition of PAGE_SIZE */
31
32#include "SDL_video.h"
33#include "SDL_gsyuv_c.h"
34#include "../SDL_yuvfuncs.h"
35
36/* The maximum number of 16x16 pixel block converted at once */
37#define MAX_MACROBLOCKS 1024 /* 2^10 macroblocks at once */
38
39/* The functions used to manipulate video overlays */
40static struct private_yuvhwfuncs gs_yuvfuncs = {
41 GS_LockYUVOverlay,
42 GS_UnlockYUVOverlay,
43 GS_DisplayYUVOverlay,
44 GS_FreeYUVOverlay
45};
46
47struct private_yuvhwdata {
48 int ipu_fd;
49 Uint8 *pixels;
50 int macroblocks;
51 int dma_len;
52 caddr_t dma_mem;
53 caddr_t ipu_imem;
54 caddr_t ipu_omem;
55 caddr_t dma_tags;
56 unsigned long long *stretch_x1y1;
57 unsigned long long *stretch_x2y2;
58 struct ps2_plist plist;
59
60 /* These are just so we don't have to allocate them separately */
61 Uint16 pitches[3];
62 Uint8 *planes[3];
63};
64
65static int power_of_2(int value)
66{
67 int shift;
68
69 for ( shift = 0; (1<<shift) < value; ++shift ) {
70 /* Keep looking */ ;
71 }
72 return(shift);
73}
74
75SDL_Overlay *GS_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display)
76{
77 SDL_Overlay *overlay;
78 struct private_yuvhwdata *hwdata;
79 int map_offset;
80 unsigned long long *tags;
81 caddr_t base;
82 int bpp;
83 int fbp, fbw, psm;
84 int x, y, w, h;
85 int pnum;
86 struct ps2_packet *packet;
87 struct ps2_packet tex_packet;
88
89 /* We can only decode blocks of 16x16 pixels */
90 if ( (width & 15) || (height & 15) ) {
91 SDL_SetError("Overlay width/height must be multiples of 16");
92 return(NULL);
93 }
94 /* Make sure the image isn't too large for a single DMA transfer */
95 if ( ((width/16) * (height/16)) > MAX_MACROBLOCKS ) {
96 SDL_SetError("Overlay too large (maximum size: %d pixels)",
97 MAX_MACROBLOCKS * 16 * 16);
98 return(NULL);
99 }
100
101 /* Double-check the requested format. For simplicity, we'll only
102 support planar YUV formats.
103 */
104 switch (format) {
105 case SDL_YV12_OVERLAY:
106 case SDL_IYUV_OVERLAY:
107 /* Supported planar YUV format */
108 break;
109 default:
110 SDL_SetError("Unsupported YUV format");
111 return(NULL);
112 }
113
114 /* Create the overlay structure */
115 overlay = (SDL_Overlay *)SDL_malloc(sizeof *overlay);
116 if ( overlay == NULL ) {
117 SDL_OutOfMemory();
118 return(NULL);
119 }
120 SDL_memset(overlay, 0, (sizeof *overlay));
121
122 /* Fill in the basic members */
123 overlay->format = format;
124 overlay->w = width;
125 overlay->h = height;
126
127 /* Set up the YUV surface function structure */
128 overlay->hwfuncs = &gs_yuvfuncs;
129 overlay->hw_overlay = 1;
130
131 /* Create the pixel data */
132 hwdata = (struct private_yuvhwdata *)SDL_malloc(sizeof *hwdata);
133 overlay->hwdata = hwdata;
134 if ( hwdata == NULL ) {
135 SDL_FreeYUVOverlay(overlay);
136 SDL_OutOfMemory();
137 return(NULL);
138 }
139 hwdata->ipu_fd = -1;
140 hwdata->pixels = (Uint8 *)SDL_malloc(width*height*2);
141 if ( hwdata->pixels == NULL ) {
142 SDL_FreeYUVOverlay(overlay);
143 SDL_OutOfMemory();
144 return(NULL);
145 }
146 hwdata->macroblocks = (width/16) * (height/16);
147
148 /* Find the pitch and offset values for the overlay */
149 overlay->pitches = hwdata->pitches;
150 overlay->pixels = hwdata->planes;
151 switch (format) {
152 case SDL_YV12_OVERLAY:
153 case SDL_IYUV_OVERLAY:
154 overlay->pitches[0] = overlay->w;
155 overlay->pitches[1] = overlay->pitches[0] / 2;
156 overlay->pitches[2] = overlay->pitches[0] / 2;
157 overlay->pixels[0] = hwdata->pixels;
158 overlay->pixels[1] = overlay->pixels[0] +
159 overlay->pitches[0] * overlay->h;
160 overlay->pixels[2] = overlay->pixels[1] +
161 overlay->pitches[1] * overlay->h / 2;
162 overlay->planes = 3;
163 break;
164 default:
165 /* We should never get here (caught above) */
166 break;
167 }
168
169 /* Theoretically we could support several concurrent decode
170 streams queueing up on the same file descriptor, but for
171 simplicity we'll support only one. Opening the IPU more
172 than once will fail with EBUSY.
173 */
174 hwdata->ipu_fd = open("/dev/ps2ipu", O_RDWR);
175 if ( hwdata->ipu_fd < 0 ) {
176 SDL_FreeYUVOverlay(overlay);
177 SDL_SetError("Playstation 2 IPU busy");
178 return(NULL);
179 }
180
181 /* Allocate a DMA area for pixel conversion */
182 bpp = this->screen->format->BytesPerPixel;
183 map_offset = (mapped_len + (sysconf(_SC_PAGESIZE) - 1)) & ~(sysconf(_SC_PAGESIZE) - 1);
184 hwdata->dma_len = hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8) +
185 width * height * bpp +
186 hwdata->macroblocks * (16 * sizeof(long long)) +
187 12 * sizeof(long long);
188 hwdata->dma_mem = mmap(0, hwdata->dma_len, PROT_READ|PROT_WRITE,
189 MAP_SHARED, memory_fd, map_offset);
190 if ( hwdata->dma_mem == MAP_FAILED ) {
191 hwdata->ipu_imem = (caddr_t)0;
192 SDL_FreeYUVOverlay(overlay);
193 SDL_SetError("Unable to map %d bytes for DMA", hwdata->dma_len);
194 return(NULL);
195 }
196 hwdata->ipu_imem = hwdata->dma_mem;
197 hwdata->ipu_omem = hwdata->ipu_imem +
198 hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8);
199 hwdata->dma_tags = hwdata->ipu_omem + width * height * bpp;
200
201 /* Allocate memory for the DMA packets */
202 hwdata->plist.num = hwdata->macroblocks * 4 + 1;
203 hwdata->plist.packet = (struct ps2_packet *)SDL_malloc(
204 hwdata->plist.num*sizeof(struct ps2_packet));
205 if ( ! hwdata->plist.packet ) {
206 SDL_FreeYUVOverlay(overlay);
207 SDL_OutOfMemory();
208 return(NULL);
209 }
210 pnum = 0;
211 packet = hwdata->plist.packet;
212
213 /* Set up the tags to send the image to the screen */
214 tags = (unsigned long long *)hwdata->dma_tags;
215 base = hwdata->ipu_omem;
216 fbp = screen_image.fbp;
217 fbw = screen_image.fbw;
218 psm = screen_image.psm;
219 y = screen_image.y + screen_image.h; /* Offscreen video memory */
220 for ( h=height/16; h; --h ) {
221 x = 0; /* Visible video memory */
222 for ( w=width/16; w; --w ) {
223 /* The head tag */
224 packet[pnum].ptr = &tags[0];
225 packet[pnum].len = 10 * sizeof(*tags);
226 ++pnum;
227 tags[0] = 4 | (1LL << 60); /* GIFtag */
228 tags[1] = 0x0e; /* A+D */
229 tags[2] = ((unsigned long long)fbp << 32) |
230 ((unsigned long long)fbw << 48) |
231 ((unsigned long long)psm << 56);
232 tags[3] = PS2_GS_BITBLTBUF;
233 tags[4] = ((unsigned long long)x << 32) |
234 ((unsigned long long)y << 48);
235 tags[5] = PS2_GS_TRXPOS;
236 tags[6] = (unsigned long long)16 |
237 ((unsigned long long)16 << 32);
238 tags[7] = PS2_GS_TRXREG;
239 tags[8] = 0;
240 tags[9] = PS2_GS_TRXDIR;
241 /* Now the actual image data */
242 packet[pnum].ptr = &tags[10];
243 packet[pnum].len = 2 * sizeof(*tags);
244 ++pnum;
245 tags[10] = ((16*16*bpp) >> 4) | (2LL << 58);
246 tags[11] = 0;
247 packet[pnum].ptr = (void *)base;
248 packet[pnum].len = 16 * 16 * bpp;
249 ++pnum;
250 packet[pnum].ptr = &tags[12];
251 packet[pnum].len = 2 * sizeof(*tags);
252 ++pnum;
253 tags[12] = (0 >> 4) | (1 << 15) | (2LL << 58);
254 tags[13] = 0;
255
256 tags += 16;
257 base += 16 * 16 * bpp;
258
259 x += 16;
260 }
261 y += 16;
262 }
263
264 /* Set up the texture memory area for the video */
265 tex_packet.ptr = tags;
266 tex_packet.len = 8 * sizeof(*tags);
267 tags[0] = 3 | (1LL << 60); /* GIFtag */
268 tags[1] = 0x0e; /* A+D */
269 tags[2] = ((screen_image.y + screen_image.h) * screen_image.w) / 64 +
270 ((unsigned long long)fbw << 14) +
271 ((unsigned long long)psm << 20) +
272 ((unsigned long long)power_of_2(width) << 26) +
273 ((unsigned long long)power_of_2(height) << 30) +
274 ((unsigned long long)1 << 34) +
275 ((unsigned long long)1 << 35);
276 tags[3] = PS2_GS_TEX0_1;
277 tags[4] = (1 << 5) + (1 << 6);
278 tags[5] = PS2_GS_TEX1_1;
279 tags[6] = 0;
280 tags[7] = PS2_GS_TEXFLUSH;
281 ioctl(console_fd, PS2IOC_SEND, &tex_packet);
282
283 /* Set up the tags for scaling the image */
284 packet[pnum].ptr = tags;
285 packet[pnum].len = 12 * sizeof(*tags);
286 ++pnum;
287 tags[0] = 5 | (1LL << 60); /* GIFtag */
288 tags[1] = 0x0e; /* A+D */
289 tags[2] = 6 + (1 << 4) + (1 << 8);
290 tags[3] = PS2_GS_PRIM;
291 tags[4] = ((unsigned long long)0 * 16) +
292 (((unsigned long long)0 * 16) << 16);
293 tags[5] = PS2_GS_UV;
294 tags[6] = 0; /* X1, Y1 */
295 tags[7] = PS2_GS_XYZ2;
296 hwdata->stretch_x1y1 = &tags[6];
297 tags[8] = ((unsigned long long)overlay->w * 16) +
298 (((unsigned long long)overlay->h * 16) << 16);
299 tags[9] = PS2_GS_UV;
300 tags[10] = 0; /* X2, Y2 */
301 tags[11] = PS2_GS_XYZ2;
302 hwdata->stretch_x2y2 = &tags[10];
303
304 /* We're all done.. */
305 return(overlay);
306}
307
308int GS_LockYUVOverlay(_THIS, SDL_Overlay *overlay)
309{
310 return(0);
311}
312
313void GS_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay)
314{
315 return;
316}
317
318int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
319{
320 struct private_yuvhwdata *hwdata;
321 __u32 cmd;
322 struct ps2_packet packet;
323 int h, w, i;
324 Uint32 *lum, *Cr, *Cb;
325 int lum_pitch;
326 int crb_pitch;
327 Uint32 *lum_src, *Cr_src, *Cb_src;
328 Uint32 *srcp, *dstp;
329 unsigned int x, y;
330 SDL_Surface *screen;
331
332 /* Find out where the various portions of the image are */
333 hwdata = overlay->hwdata;
334 switch (overlay->format) {
335 case SDL_YV12_OVERLAY:
336 lum = (Uint32 *)overlay->pixels[0];
337 Cr = (Uint32 *)overlay->pixels[1];
338 Cb = (Uint32 *)overlay->pixels[2];
339 break;
340 case SDL_IYUV_OVERLAY:
341 lum = (Uint32 *)overlay->pixels[0];
342 Cr = (Uint32 *)overlay->pixels[2];
343 Cb = (Uint32 *)overlay->pixels[1];
344 default:
345 SDL_SetError("Unsupported YUV format in blit (?)");
346 return(-1);
347 }
348 dstp = (Uint32 *)hwdata->ipu_imem;
349 lum_pitch = overlay->w/4;
350 crb_pitch = (overlay->w/2)/4;
351
352 /* Copy blocks of 16x16 pixels to the DMA area */
353 for ( h=overlay->h/16; h; --h ) {
354 lum_src = lum;
355 Cr_src = Cr;
356 Cb_src = Cb;
357 for ( w=overlay->w/16; w; --w ) {
358 srcp = lum_src;
359 for ( i=0; i<16; ++i ) {
360 dstp[0] = srcp[0];
361 dstp[1] = srcp[1];
362 dstp[2] = srcp[2];
363 dstp[3] = srcp[3];
364 srcp += lum_pitch;
365 dstp += 4;
366 }
367 srcp = Cb_src;
368 for ( i=0; i<8; ++i ) {
369 dstp[0] = srcp[0];
370 dstp[1] = srcp[1];
371 srcp += crb_pitch;
372 dstp += 2;
373 }
374 srcp = Cr_src;
375 for ( i=0; i<8; ++i ) {
376 dstp[0] = srcp[0];
377 dstp[1] = srcp[1];
378 srcp += crb_pitch;
379 dstp += 2;
380 }
381 lum_src += 16 / 4;
382 Cb_src += 8 / 4;
383 Cr_src += 8 / 4;
384 }
385 lum += lum_pitch * 16;
386 Cr += crb_pitch * 8;
387 Cb += crb_pitch * 8;
388 }
389
390 /* Send the macroblock data to the IPU */
391#ifdef DEBUG_YUV
392 fprintf(stderr, "Sending data to IPU..\n");
393#endif
394 packet.ptr = hwdata->ipu_imem;
395 packet.len = hwdata->macroblocks * (16 * 16 + 8 * 8 + 8 * 8);
396 ioctl(hwdata->ipu_fd, PS2IOC_SENDA, &packet);
397
398 /* Trigger the DMA to the IPU for conversion */
399#ifdef DEBUG_YUV
400 fprintf(stderr, "Trigging conversion command\n");
401#endif
402 cmd = (7 << 28) + hwdata->macroblocks;
403 if ( screen_image.psm == PS2_GS_PSMCT16 ) {
404 cmd += (1 << 27) + /* Output RGB 555 */
405 (1 << 26); /* Dither output */
406 }
407 ioctl(hwdata->ipu_fd, PS2IOC_SIPUCMD, &cmd);
408
409 /* Retrieve the converted image from the IPU */
410#ifdef DEBUG_YUV
411 fprintf(stderr, "Retrieving data from IPU..\n");
412#endif
413 packet.ptr = hwdata->ipu_omem;
414 packet.len = overlay->w * overlay->h *
415 this->screen->format->BytesPerPixel;
416 ioctl(hwdata->ipu_fd, PS2IOC_RECV, &packet);
417
418#ifdef DEBUG_YUV
419 fprintf(stderr, "Copying image to screen..\n");
420#endif
421 /* Wait for previous DMA to complete */
422 ioctl(console_fd, PS2IOC_SENDQCT, 1);
423
424 /* Send the current image to the screen and scale it */
425 screen = this->screen;
426 x = (unsigned int)dst->x;
427 y = (unsigned int)dst->y;
428 if ( screen->offset ) {
429 x += (screen->offset % screen->pitch) /
430 screen->format->BytesPerPixel;
431 y += (screen->offset / screen->pitch);
432 }
433 y += screen_image.y;
434 *hwdata->stretch_x1y1 = (x * 16) + ((y * 16) << 16);
435 x += (unsigned int)dst->w;
436 y += (unsigned int)dst->h;
437 *hwdata->stretch_x2y2 = (x * 16) + ((y * 16) << 16);
438 return ioctl(console_fd, PS2IOC_SENDL, &hwdata->plist);
439}
440
441void GS_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
442{
443 struct private_yuvhwdata *hwdata;
444
445 hwdata = overlay->hwdata;
446 if ( hwdata ) {
447 if ( hwdata->ipu_fd >= 0 ) {
448 close(hwdata->ipu_fd);
449 }
450 if ( hwdata->dma_mem ) {
451 munmap(hwdata->dma_mem, hwdata->dma_len);
452 }
453 if ( hwdata->plist.packet ) {
454 SDL_free(hwdata->plist.packet);
455 }
456 if ( hwdata->pixels ) {
457 SDL_free(hwdata->pixels);
458 }
459 SDL_free(hwdata);
460 }
461}
diff --git a/apps/plugins/sdl/src/video/ps2gs/SDL_gsyuv_c.h b/apps/plugins/sdl/src/video/ps2gs/SDL_gsyuv_c.h
deleted file mode 100644
index d9ffad6f5c..0000000000
--- a/apps/plugins/sdl/src/video/ps2gs/SDL_gsyuv_c.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/* This is the Playstation 2 implementation of YUV video overlays */
25
26#include "SDL_video.h"
27#include "SDL_gsvideo.h"
28
29extern SDL_Overlay *GS_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display);
30
31extern int GS_LockYUVOverlay(_THIS, SDL_Overlay *overlay);
32
33extern void GS_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay);
34
35extern int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst);
36
37extern void GS_FreeYUVOverlay(_THIS, SDL_Overlay *overlay);