|
|
1.1.1.3 root 1: /*
1.1 root 2: * UAE - The Un*x Amiga Emulator
1.1.1.3 root 3: *
1.1 root 4: * X interface
1.1.1.3 root 5: *
1.1 root 6: * Copyright 1995, 1996 Bernd Schmidt
7: * Copyright 1996 Ed Hanway, Andre Beck, Samuel Devulder, Bruno Coste
1.1.1.5 root 8: * Copyright 1998 Marcus Sundberg
1.1.1.2 root 9: * DGA support by Kai Kollmorgen
1.1.1.5 root 10: * X11/DGA merge, hotkeys and grabmouse by Marcus Sundberg
1.1 root 11: */
12:
13: #include "sysconfig.h"
14: #include "sysdeps.h"
15:
16: #include <X11/Xlib.h>
17: #include <X11/Xutil.h>
18: #include <X11/keysym.h>
19: #include <X11/cursorfont.h>
20:
21: #include <ctype.h>
22: #include <signal.h>
23:
24: #include "config.h"
25: #include "options.h"
1.1.1.3 root 26: #include "threaddep/penguin.h"
27: #include "uae.h"
1.1 root 28: #include "memory.h"
1.1.1.6 root 29: #include "xwin.h"
1.1 root 30: #include "custom.h"
1.1.1.6 root 31: #include "drawing.h"
1.1 root 32: #include "newcpu.h"
33: #include "keyboard.h"
34: #include "keybuf.h"
35: #include "gui.h"
36: #include "debug.h"
1.1.1.3 root 37: #include "picasso96.h"
38:
39: #ifdef __cplusplus
40: #define VI_CLASS c_class
41: #else
42: #define VI_CLASS class
43: #endif
1.1 root 44:
1.1.1.2 root 45: #ifdef USE_DGA_EXTENSION
1.1.1.3 root 46:
47: #ifdef USE_VIDMODE_EXTENSION
48: #include <X11/extensions/xf86vmode.h>
49: #define VidMode_MINMAJOR 0
50: #define VidMode_MINMINOR 0
51: #endif
52:
1.1.1.2 root 53: #include <X11/extensions/xf86dga.h>
54: #define DGA_MINMAJOR 0
55: #define DGA_MINMINOR 0
1.1.1.3 root 56:
1.1.1.5 root 57: #endif /* USE_DGA_EXTENSION */
58:
59: #if SHM_SUPPORT_LINKS == 1
1.1.1.3 root 60:
61: #include <sys/ipc.h>
62: #include <sys/shm.h>
63: #include <X11/extensions/XShm.h>
64:
65: #define DO_PUTIMAGE(IMG, SRCX, SRCY, DSTX, DSTY, WIDTH, HEIGHT) \
66: do { \
1.1.1.12 root 67: if (currprefs.x11_use_mitshm && shmavail) \
1.1.1.5 root 68: XShmPutImage (display, mywin, mygc, (IMG), (SRCX), (SRCY), (DSTX), (DSTY), (WIDTH), (HEIGHT), 0); \
1.1.1.3 root 69: else \
1.1.1.5 root 70: XPutImage (display, mywin, mygc, (IMG), (SRCX), (SRCY), (DSTX), (DSTY), (WIDTH), (HEIGHT)); \
1.1.1.3 root 71: } while (0)
72: #else
73: #define DO_PUTIMAGE(IMG, SRCX, SRCY, DSTX, DSTY, WIDTH, HEIGHT) \
1.1.1.5 root 74: XPutImage (display, mywin, mygc, (IMG), (SRCX), (SRCY), (DSTX), (DSTY), (WIDTH), (HEIGHT))
1.1.1.2 root 75: #endif
76:
1.1 root 77: #ifdef __cplusplus
78: static RETSIGTYPE sigbrkhandler(...)
79: #else
1.1.1.5 root 80: static RETSIGTYPE sigbrkhandler (int foo)
1.1 root 81: #endif
82: {
83: activate_debugger();
84:
85: #if !defined(__unix) || defined(__NeXT__)
1.1.1.5 root 86: signal (SIGINT, sigbrkhandler);
1.1 root 87: #endif
88: }
89:
1.1.1.5 root 90: void setup_brkhandler (void)
1.1 root 91: {
92: #if defined(__unix) && !defined(__NeXT__)
93: struct sigaction sa;
94: sa.sa_handler = sigbrkhandler;
95: sa.sa_flags = 0;
96: #ifdef SA_RESTART
97: sa.sa_flags = SA_RESTART;
98: #endif
1.1.1.5 root 99: sigemptyset (&sa.sa_mask);
100: sigaction (SIGINT, &sa, NULL);
1.1 root 101: #else
1.1.1.5 root 102: signal (SIGINT, sigbrkhandler);
1.1.1.2 root 103: #endif
1.1.1.3 root 104: }
1.1.1.2 root 105:
1.1.1.5 root 106: struct disp_info {
107: XImage *ximg;
108: char *image_mem;
109: #if SHM_SUPPORT_LINKS == 1
110: XShmSegmentInfo shminfo;
111: #endif
112: };
113:
1.1 root 114: static Display *display;
115: static int screen;
116: static Window rootwin, mywin;
1.1.1.7 root 117: static Atom delete_win;
1.1 root 118:
1.1.1.5 root 119: static GC mygc;
120: static XColor black, white;
1.1.1.3 root 121: static Colormap cmap, cmap2;
1.1.1.5 root 122: static int red_bits, green_bits, blue_bits;
123: static int red_shift, green_shift, blue_shift;
1.1.1.3 root 124:
1.1.1.5 root 125: /* Kludge-O-Matic.
126: * Unfortunately the X server loses colormap changes in DGA mode. Switching
127: * back and forth between two identical colormaps fixes this problem. */
1.1.1.3 root 128: static int dga_colormap_installed;
1.1 root 129:
130: static int need_dither;
131:
1.1.1.3 root 132: static int screen_is_picasso;
133: static char picasso_invalid_lines[1201];
1.1.1.5 root 134: static int picasso_has_invalid_lines;
135: static int picasso_invalid_start, picasso_invalid_stop;
136: static int picasso_maxw = 0, picasso_maxh = 0;
1.1.1.3 root 137:
1.1 root 138: static int autorepeatoff = 0;
1.1.1.5 root 139: static struct disp_info ami_dinfo, pic_dinfo;
1.1 root 140: static Visual *vis;
141: static XVisualInfo visualInfo;
142: static int bitdepth, bit_unit;
143: static Cursor blankCursor, xhairCursor;
144: static int cursorOn;
1.1.1.3 root 145: static int inverse_byte_order = 0;
1.1 root 146:
1.1.1.3 root 147: static int current_width, current_height;
1.1 root 148:
1.1.1.2 root 149: static int x11_init_ok;
1.1.1.5 root 150: static int dgaavail = 0, vidmodeavail = 0, shmavail = 0;
151: static int dgamode;
1.1.1.2 root 152:
1.1.1.6 root 153: /* Keyboard and mouse */
1.1 root 154:
155: static int keystate[256];
156:
1.1.1.5 root 157: static int oldx, oldy;
158: static int grabbed;
159:
160: struct uae_hotkeys {
161: KeySym syms[4];
162: void (*handler)(void);
163: int retval;
164: int mask;
165: };
166:
1.1.1.6 root 167: static void handle_modeswitch (void);
1.1.1.5 root 168: static void handle_mousegrab (void);
169: static void handle_inhibit (void);
170: static void framerate_up (void);
171: static void framerate_down (void);
172:
1.1.1.7 root 173: static void handle_interpol (void);
1.1.1.5 root 174: static struct uae_hotkeys hotkeys[] = {
1.1.1.6 root 175: #ifdef USE_DGA_EXTENSION
176: {{ XK_F12, XK_s, 0 }, handle_modeswitch, -1, 0 },
177: #endif
178: {{ XK_F12, XK_q, 0 }, uae_quit, -1, 0 },
179: {{ XK_F12, XK_m, 0 }, togglemouse, -1, 0 },
180: {{ XK_F12, XK_g, 0 }, handle_mousegrab, -1, 0 },
181: {{ XK_F12, XK_i, 0 }, handle_inhibit, -1, 0 },
1.1.1.7 root 182: {{ XK_F12, XK_p, 0 }, handle_interpol, -1, 0 },
1.1.1.6 root 183: {{ XK_F12, XK_KP_Add, 0 }, framerate_up, -1, 0 },
184: {{ XK_F12, XK_KP_Subtract, 0 }, framerate_down, -1, 0 },
185: {{ XK_Scroll_Lock, 0 }, handle_inhibit, -1, 0 },
186: {{ 0 }, NULL, -1, 0 } /* List must be terminated */
1.1.1.5 root 187: };
188:
1.1 root 189: static int inwindow;
1.1.1.5 root 190: #define EVENTMASK (KeyPressMask|KeyReleaseMask|ButtonPressMask \
191: |ButtonReleaseMask|PointerMotionMask \
192: |FocusChangeMask|EnterWindowMask \
193: |ExposureMask |LeaveWindowMask)
194: #define DGA_EVENTMASK (KeyPressMask|KeyReleaseMask|ButtonPressMask \
195: |ButtonReleaseMask|PointerMotionMask)
196:
197: #if SHM_SUPPORT_LINKS == 1
198: /* Hack to detect shm-failure, probably due to displaying on a
199: * remote server. */
200: static int shmerror;
201: static int (*oldshmerrorhandler) (Display *, XErrorEvent *);
202:
203: static int shmerrorhandler (Display *dsp, XErrorEvent *ev)
204: {
205: if (ev->error_code == BadAccess)
206: shmerror=1;
207: else
208: (*oldshmerrorhandler) (dsp, ev);
209: return 0;
210: }
1.1.1.2 root 211: #endif
1.1 root 212:
1.1.1.5 root 213: static void get_image (int w, int h, struct disp_info *dispi)
1.1.1.3 root 214: {
215: XImage *new_img;
216: char *p;
217:
218: #if SHM_SUPPORT_LINKS == 1
1.1.1.6 root 219: if (currprefs.x11_use_mitshm && shmavail) {
1.1.1.5 root 220: XShmSegmentInfo *shminfo = &dispi->shminfo;
1.1.1.3 root 221:
222: new_img = XShmCreateImage (display, vis, bitdepth, ZPixmap, 0, shminfo, w, h);
223:
224: shminfo->shmid = shmget (IPC_PRIVATE, h * new_img->bytes_per_line,
225: IPC_CREAT | 0777);
226: shminfo->shmaddr = new_img->data = (char *)shmat (shminfo->shmid, 0, 0);
1.1.1.5 root 227: dispi->image_mem = new_img->data;
1.1.1.3 root 228: shminfo->readOnly = False;
1.1.1.5 root 229: /* Try to let the Xserver attach */
230: shmerror = 0;
231: oldshmerrorhandler = XSetErrorHandler (shmerrorhandler);
1.1.1.3 root 232: XShmAttach (display, shminfo);
1.1.1.5 root 233: XSync (display, 0);
234: XSetErrorHandler (oldshmerrorhandler);
235: if (shmerror) {
236: shmdt (shminfo->shmaddr);
237: XDestroyImage (new_img);
238: shminfo->shmid = -1;
239: shmavail = 0;
240: fprintf (stderr, "MIT-SHM extension failed, trying fallback.\n");
241: } else {
242: /* now deleting means making it temporary */
243: shmctl (shminfo->shmid, IPC_RMID, 0);
244: dispi->ximg = new_img;
245: printf ("Using MIT-SHM extension.\n");
246: return;
247: }
1.1.1.3 root 248: }
249: #endif
250:
251: /* Question for people who know about X: Could we allocate the buffer
252: * after creating the image and then do new_img->data = buffer, as above in
253: * the SHM case?
254: */
255: printf ("Using normal image buffer.\n");
256: p = (char *)xmalloc (h * w * ((bit_unit + 7) / 8)); /* ??? */
257: new_img = XCreateImage (display, vis, bitdepth, ZPixmap, 0, p,
258: w, h, 32, 0);
259: if (new_img->bytes_per_line != w * ((bit_unit + 7) / 8))
260: fprintf (stderr, "Possible bug here... graphics may look strange.\n");
261:
1.1.1.5 root 262: dispi->image_mem = p;
263: dispi->ximg = new_img;
1.1.1.3 root 264: }
265:
266: #ifdef USE_VIDMODE_EXTENSION
267: static XF86VidModeModeInfo **allmodes;
268: static int vidmodecount;
269:
270: static int get_vidmodes (void)
271: {
272: return XF86VidModeGetAllModeLines (display, screen, &vidmodecount, &allmodes);
273: }
1.1.1.4 root 274: #endif
1.1.1.3 root 275:
1.1.1.5 root 276: #ifdef USE_DGA_EXTENSION
277:
278: static int fb_bank, fb_banks, fb_mem;
279: static char *fb_addr;
280: static int fb_width;
281:
1.1.1.3 root 282: static void switch_to_best_mode (void)
283: {
284: int i, best;
1.1.1.5 root 285: #ifdef USE_VIDMODE_EXTENSION
286: if (vidmodeavail) {
287: best = 0;
288: for (i = 1; i < vidmodecount; i++) {
289: if (allmodes[i]->hdisplay >= current_width
290: && allmodes[i]->vdisplay >= current_height
291: && allmodes[i]->hdisplay <= allmodes[best]->hdisplay
292: && allmodes[i]->vdisplay <= allmodes[best]->vdisplay)
293: best = i;
294: }
295: printf ("entering DGA mode: %dx%d (%d, %d)\n",
296: allmodes[best]->hdisplay, allmodes[best]->vdisplay,
297: current_width, current_height);
298: XF86VidModeSwitchToMode (display, screen, allmodes[best]);
299: XF86VidModeSetViewPort (display, screen, 0, 0);
300: }
1.1.1.4 root 301: #endif
1.1.1.3 root 302: XMoveWindow (display, mywin, 0, 0);
303: XWarpPointer (display, None, rootwin, 0, 0, 0, 0, 0, 0);
1.1.1.5 root 304: XF86DGADirectVideo (display, screen, XF86DGADirectGraphics | XF86DGADirectMouse | XF86DGADirectKeyb);
305: XF86DGASetViewPort (display, screen, 0, 0);
306: memset (fb_addr, 0, fb_mem * 1024);
1.1.1.3 root 307: }
308:
309: static void enter_dga_mode (void)
310: {
311: Screen *scr = ScreenOfDisplay (display, screen);
312: int w = WidthOfScreen (scr);
313: int h = HeightOfScreen (scr);
314:
315: XRaiseWindow (display, mywin);
316:
317: /* We want all the key presses */
318: XGrabKeyboard (display, rootwin, 1, GrabModeAsync,
319: GrabModeAsync, CurrentTime);
320:
321: /* and all the mouse moves */
322: XGrabPointer (display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
323: GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
324:
325: switch_to_best_mode ();
326:
327: gfxvidinfo.rowbytes = fb_width*gfxvidinfo.pixbytes;
328: gfxvidinfo.bufmem = fb_addr;
1.1.1.5 root 329: gfxvidinfo.linemem = 0;
330: gfxvidinfo.emergmem = malloc (gfxvidinfo.rowbytes);
331: gfxvidinfo.maxblocklines = 10000;
1.1.1.3 root 332: }
333:
334: static void leave_dga_mode (void)
335: {
336: #ifdef USE_VIDMODE_EXTENSION
1.1.1.5 root 337: if (vidmodeavail)
338: XF86VidModeSwitchToMode (display, screen, allmodes[0]);
1.1.1.3 root 339: #endif
340: XF86DGADirectVideo (display, screen, 0);
341: XUngrabPointer (display, CurrentTime);
342: XUngrabKeyboard (display, CurrentTime);
343: }
344: #endif
1.1.1.5 root 345:
1.1.1.3 root 346: static char *oldpixbuf;
1.1 root 347:
1.1.1.5 root 348: void flush_line (int y)
1.1 root 349: {
1.1.1.5 root 350: char *linebuf = gfxvidinfo.linemem;
351: int xs, xe;
1.1.1.3 root 352: int len;
1.1 root 353:
1.1.1.3 root 354: if (linebuf == NULL)
355: linebuf = y*gfxvidinfo.rowbytes + gfxvidinfo.bufmem;
356:
1.1.1.5 root 357: #ifdef USE_DGA_EXTENSION
358: if (dgamode && need_dither) {
359: DitherLine ((unsigned char *)(fb_addr + fb_width*y),
360: (uae_u16 *)linebuf, 0, y, gfxvidinfo.width, bit_unit);
361: return;
362: }
363: #endif
364: xs = 0;
365: xe = gfxvidinfo.width - 1;
1.1.1.3 root 366:
1.1.1.6 root 367: if (currprefs.x11_use_low_bandwidth) {
1.1.1.3 root 368: char *src, *dst;
1.1.1.5 root 369: switch (gfxvidinfo.pixbytes) {
1.1.1.3 root 370: case 4:
371: {
372: uae_u32 *newp = (uae_u32 *)linebuf;
1.1.1.5 root 373: uae_u32 *oldp = (uae_u32 *)((uae_u8 *)ami_dinfo.image_mem + y*ami_dinfo.ximg->bytes_per_line);
1.1.1.3 root 374: while (newp[xs] == oldp[xs]) {
375: if (xs == xe)
376: return;
377: xs++;
378: }
379: while (newp[xe] == oldp[xe]) xe--;
380:
381: dst = (char *)(oldp + xs); src = (char *)(newp + xs);
1.1 root 382: }
1.1.1.3 root 383: break;
384: case 2:
385: {
386: uae_u16 *newp = (uae_u16 *)linebuf;
1.1.1.5 root 387: uae_u16 *oldp = (uae_u16 *)((uae_u8 *)ami_dinfo.image_mem + y*ami_dinfo.ximg->bytes_per_line);
1.1.1.3 root 388: while (newp[xs] == oldp[xs]) {
389: if (xs == xe)
390: return;
391: xs++;
392: }
393: while (newp[xe] == oldp[xe]) xe--;
394:
395: dst = (char *)(oldp + xs); src = (char *)(newp + xs);
1.1 root 396: }
1.1.1.3 root 397: break;
398: case 1:
399: {
400: uae_u8 *newp = (uae_u8 *)linebuf;
1.1.1.5 root 401: uae_u8 *oldp = (uae_u8 *)((uae_u8 *)ami_dinfo.image_mem + y*ami_dinfo.ximg->bytes_per_line);
1.1.1.3 root 402: while (newp[xs] == oldp[xs]) {
403: if (xs == xe)
404: return;
405: xs++;
406: }
407: while (newp[xe] == oldp[xe]) xe--;
1.1 root 408:
1.1.1.3 root 409: dst = (char *)(oldp + xs); src = (char *)(newp + xs);
1.1 root 410: }
1.1.1.3 root 411: break;
1.1 root 412:
1.1.1.3 root 413: default:
1.1.1.5 root 414: abort ();
1.1.1.3 root 415: break;
1.1 root 416: }
417:
418: len = xe - xs + 1;
1.1.1.3 root 419: memcpy (dst, src, len * gfxvidinfo.pixbytes);
420: } else if (need_dither) {
1.1.1.5 root 421: uae_u8 *target = (uae_u8 *)ami_dinfo.image_mem + ami_dinfo.ximg->bytes_per_line * y;
1.1.1.3 root 422: len = currprefs.gfx_width;
1.1.1.5 root 423: DitherLine (target, (uae_u16 *)linebuf, 0, y, gfxvidinfo.width, bit_unit);
1.1.1.3 root 424: } else {
1.1.1.5 root 425: fprintf (stderr, "Bug!\n");
1.1.1.3 root 426: abort();
1.1 root 427: }
1.1.1.2 root 428:
1.1.1.5 root 429: DO_PUTIMAGE (ami_dinfo.ximg, xs, y, xs, y, len, 1);
1.1 root 430: }
431:
432: void flush_block (int ystart, int ystop)
433: {
1.1.1.5 root 434: if (dgamode)
435: return;
1.1.1.3 root 436:
1.1.1.5 root 437: DO_PUTIMAGE (ami_dinfo.ximg, 0, ystart, 0, ystart, gfxvidinfo.width, ystop - ystart + 1);
1.1 root 438: }
439:
440: void flush_screen (int ystart, int ystop)
441: {
1.1.1.5 root 442: if (dgamode)
443: return;
444:
1.1.1.3 root 445: #if SHM_SUPPORT_LINKS == 1
1.1.1.12 root 446: if (currprefs.x11_use_mitshm && shmavail)
1.1.1.5 root 447: XSync (display, 0);
1.1.1.2 root 448: #endif
1.1 root 449: }
450:
1.1.1.8 root 451: STATIC_INLINE int bitsInMask (unsigned long mask)
1.1 root 452: {
453: /* count bits in mask */
454: int n = 0;
1.1.1.5 root 455: while (mask) {
456: n += mask & 1;
1.1 root 457: mask >>= 1;
458: }
459: return n;
460: }
461:
1.1.1.8 root 462: STATIC_INLINE int maskShift (unsigned long mask)
1.1 root 463: {
464: /* determine how far mask is shifted */
465: int n = 0;
1.1.1.5 root 466: while (!(mask & 1)) {
1.1 root 467: n++;
468: mask >>= 1;
469: }
470: return n;
471: }
472:
1.1.1.3 root 473: static unsigned long pixel_return[256];
474: static XColor parsed_xcolors[256];
475: static int ncolors = 0;
476:
477: static int blackval = 32767;
478: static int whiteval = 0;
479:
1.1.1.5 root 480: static int get_color (int r, int g, int b, xcolnr *cnp)
1.1 root 481: {
1.1.1.3 root 482: XColor *col = parsed_xcolors + ncolors;
1.1 root 483: char str[10];
1.1.1.3 root 484:
1.1.1.5 root 485: sprintf (str, "rgb:%x/%x/%x", r, g, b);
486: XParseColor (display, cmap, str, col);
1.1.1.3 root 487: *cnp = col->pixel = pixel_return[ncolors];
488: XStoreColor (display, cmap, col);
489: XStoreColor (display, cmap2, col);
490:
491: if (r + g + b < blackval)
492: blackval = r + g + b, black = *col;
493: if (r + g + b > whiteval)
494: whiteval = r + g + b, white = *col;
495:
496: ncolors++;
497: return 1;
1.1 root 498: }
499:
1.1.1.5 root 500: static int init_colors (void)
1.1 root 501: {
1.1.1.3 root 502: int i;
503:
1.1.1.5 root 504: if (visualInfo.VI_CLASS == TrueColor) {
505: red_bits = bitsInMask (visualInfo.red_mask);
506: green_bits = bitsInMask (visualInfo.green_mask);
507: blue_bits = bitsInMask (visualInfo.blue_mask);
508: red_shift = maskShift (visualInfo.red_mask);
509: green_shift = maskShift (visualInfo.green_mask);
510: blue_shift = maskShift (visualInfo.blue_mask);
511: }
512:
1.1 root 513: if (need_dither) {
514: if (bitdepth == 1)
515: setup_greydither (1, get_color);
516: else
517: setup_dither (bitdepth, get_color);
1.1.1.3 root 518: } else {
519: if (bitdepth != 8 && bitdepth != 12 && bitdepth != 15
520: && bitdepth != 16 && bitdepth != 24) {
1.1.1.5 root 521: fprintf (stderr, "Unsupported bit depth (%d)\n", bitdepth);
1.1.1.3 root 522: return 0;
1.1 root 523: }
524:
1.1.1.3 root 525: switch (visualInfo.VI_CLASS) {
526: case TrueColor:
1.1.1.5 root 527: alloc_colors64k (red_bits, green_bits, blue_bits, red_shift,
528: green_shift, blue_shift);
529:
530: XParseColor (display, cmap, "#000000", &black);
531: if (! XAllocColor (display, cmap, &black))
532: fprintf (stderr, "Whoops??\n");
533: XParseColor (display, cmap, "#ffffff", &white);
534: if (! XAllocColor (display, cmap, &white))
535: fprintf (stderr, "Whoops??\n");
1.1.1.3 root 536: break;
537:
538: case GrayScale:
539: case PseudoColor:
1.1.1.5 root 540: alloc_colors256 (get_color);
1.1.1.3 root 541: break;
542:
543: default:
544: fprintf (stderr, "Unsupported visual class (%d)\n", visualInfo.VI_CLASS);
545: return 0;
546: }
547: }
548: switch (gfxvidinfo.pixbytes) {
549: case 2:
550: for (i = 0; i < 4096; i++)
551: xcolors[i] = xcolors[i] * 0x00010001;
552: gfxvidinfo.can_double = 1;
553: break;
554: case 1:
555: for (i = 0; i < 4096; i++)
556: xcolors[i] = xcolors[i] * 0x01010101;
557: gfxvidinfo.can_double = 1;
1.1 root 558: break;
559: default:
1.1.1.3 root 560: gfxvidinfo.can_double = 0;
561: break;
1.1 root 562: }
1.1.1.5 root 563: if (inverse_byte_order)
564: switch (gfxvidinfo.pixbytes) {
1.1.1.3 root 565: case 4:
566: for(i = 0; i < 4096; i++)
567: xcolors[i] = ((((xcolors[i]>>0)&255) << 24)
568: | (((xcolors[i]>>8)&255) << 16)
569: | (((xcolors[i]>>16)&255) << 8)
570: | (((xcolors[i]>>24)&255) << 0));
571: break;
572: case 2:
573: for (i = 0; i < 4096; i++)
574: xcolors[i] = (xcolors[i]>>8) | ((xcolors[i]&255)<<8);
575: break;
576: default:
577: break;
578: }
1.1 root 579: return 1;
580: }
581:
1.1.1.5 root 582: static int dga_available (void)
1.1 root 583: {
1.1.1.2 root 584: #ifdef USE_DGA_EXTENSION
585: int MajorVersion, MinorVersion;
586: int EventBase, ErrorBase;
1.1.1.3 root 587:
1.1.1.5 root 588: if (! XF86DGAQueryVersion (display, &MajorVersion, &MinorVersion)) {
589: fprintf (stderr, "Unable to query video extension version\n");
1.1.1.3 root 590: return 0;
1.1.1.2 root 591: }
1.1.1.5 root 592: if (! XF86DGAQueryExtension (display, &EventBase, &ErrorBase)) {
593: fprintf (stderr, "Unable to query video extension information\n");
1.1.1.3 root 594: return 0;
1.1.1.2 root 595: }
596: /* Fail if the extension version in the server is too old */
1.1.1.5 root 597: if (MajorVersion < DGA_MINMAJOR
598: || (MajorVersion == DGA_MINMAJOR && MinorVersion < DGA_MINMINOR))
599: {
1.1.1.3 root 600: fprintf (stderr,
601: "Xserver is running an old XFree86-DGA version"
602: " (%d.%d)\n", MajorVersion, MinorVersion);
603: fprintf (stderr, "Minimum required version is %d.%d\n",
1.1.1.5 root 604: DGA_MINMAJOR, DGA_MINMINOR);
605: return 0;
606: }
607: if (geteuid () != 0) {
608: fprintf (stderr, "UAE is not running as root, DGA extension disabled.\n");
609: return 0;
610: }
611: if (! XF86DGAGetVideo (display, screen, &fb_addr, &fb_width, &fb_bank, &fb_mem)
612: || fb_bank < fb_mem)
613: {
614: fprintf (stderr, "Problems with DGA - disabling DGA extension.\n");
1.1.1.3 root 615: return 0;
616: }
1.1.1.5 root 617: fprintf (stderr, "DGA extension: addr:%X, width %d, bank size %d mem size %d\n",
618: fb_addr, fb_width, fb_bank, fb_mem);
619:
620: return 1;
621: #else
622: return 0;
623: #endif
624: }
625:
626: static int vid_mode_available (void)
627: {
1.1.1.3 root 628: #ifdef USE_VIDMODE_EXTENSION
1.1.1.5 root 629: int MajorVersion, MinorVersion;
630: int EventBase, ErrorBase;
631:
632: if (! dgaavail)
633: return 0;
634: if (! XF86VidModeQueryVersion (display, &MajorVersion, &MinorVersion)) {
1.1.1.3 root 635: fprintf (stderr, "Unable to query video extension version\n");
636: return 0;
637: }
1.1.1.5 root 638: if (! XF86VidModeQueryExtension (display, &EventBase, &ErrorBase)) {
1.1.1.3 root 639: fprintf (stderr, "Unable to query video extension information\n");
640: return 0;
641: }
1.1.1.5 root 642: if (MajorVersion < VidMode_MINMAJOR
643: || (MajorVersion == VidMode_MINMAJOR && MinorVersion < VidMode_MINMINOR)) {
644: /* Fail if the extension version in the server is too old */
645: fprintf (stderr, "Xserver is running an old XFree86-VidMode version (%d.%d)\n",
646: MajorVersion, MinorVersion);
1.1.1.3 root 647: fprintf (stderr, "Minimum required version is %d.%d\n",
648: VidMode_MINMAJOR, VidMode_MINMINOR);
649: return 0;
650: }
1.1.1.5 root 651: if (! get_vidmodes ()) {
1.1.1.3 root 652: fprintf (stderr, "Error getting video mode information\n");
653: return 0;
1.1.1.2 root 654: }
1.1.1.5 root 655: return 1;
656: #else
657: return 0;
1.1.1.2 root 658: #endif
1.1.1.5 root 659: }
660:
661: static int shm_available (void)
662: {
663: #if SHM_SUPPORT_LINKS == 1
664: if (XShmQueryExtension (display))
665: return 1;
1.1.1.3 root 666: #endif
1.1.1.5 root 667: return 0;
668: }
669:
670: int graphics_setup (void)
671: {
672: char *display_name = 0;
673:
674: display = XOpenDisplay (display_name);
675: if (display == 0) {
676: fprintf (stderr, "Can't connect to X server %s\n", XDisplayName (display_name));
677: return 0;
678: }
679:
680: shmavail = shm_available ();
681: dgaavail = dga_available ();
682: vidmodeavail = vid_mode_available ();
1.1.1.3 root 683:
684: {
685: int local_byte_order;
686: int x = 0x04030201;
687: char *y=(char*)&x;
688:
689: local_byte_order = y[0] == 0x04 ? MSBFirst : LSBFirst;
690: if (ImageByteOrder(display) != local_byte_order)
691: inverse_byte_order = 1;
692: }
693:
694: return 1;
695: }
696:
1.1.1.5 root 697: static void lock_window_size (void)
1.1.1.3 root 698: {
1.1.1.5 root 699: XSizeHints hint;
1.1.1.3 root 700:
1.1.1.5 root 701: hint.flags = PMinSize | PMaxSize;
702: hint.min_width = current_width;
703: hint.min_height = current_height;
704: hint.max_width = current_width;
705: hint.max_height = current_height;
706: XSetWMNormalHints (display, mywin, &hint);
1.1.1.3 root 707: }
708:
1.1.1.5 root 709: static void init_dispinfo (struct disp_info *disp)
710: {
711: #if SHM_SUPPORT_LINKS == 1
712: disp->shminfo.shmid = -1;
713: #endif
714: disp->ximg = 0;
715: }
716:
717: static void graphics_subinit (void)
1.1.1.3 root 718: {
1.1.1.6 root 719: int i, j;
1.1.1.3 root 720: XSetWindowAttributes wattr;
1.1.1.7 root 721: XClassHint classhint;
722: XWMHints *hints;
1.1.1.5 root 723: unsigned long valuemask;
724:
725: dgamode = screen_is_picasso ? currprefs.gfx_pfullscreen : currprefs.gfx_afullscreen;
726: dgamode = dgamode && dgaavail;
727:
728: wattr.background_pixel = /*black.pixel*/0;
729: wattr.backing_store = Always;
730: wattr.backing_planes = bitdepth;
731: wattr.border_pixmap = None;
732: wattr.border_pixel = /*black.pixel*/0;
733: wattr.colormap = cmap;
734: valuemask = (CWEventMask | CWBackPixel | CWBorderPixel
735: | CWBackingStore | CWBackingPlanes | CWColormap);
736:
737: if (dgamode) {
738: wattr.event_mask = DGA_EVENTMASK;
739: wattr.override_redirect = 1;
740: valuemask |= CWOverrideRedirect;
741: } else
742: wattr.event_mask = EVENTMASK;
743:
744: XSync (display, 0);
1.1.1.7 root 745: delete_win = XInternAtom(display, "WM_DELETE_WINDOW", False);
1.1.1.5 root 746: mywin = XCreateWindow (display, rootwin, 0, 0, current_width, current_height,
747: 0, bitdepth, InputOutput, vis, valuemask, &wattr);
1.1.1.7 root 748: XSetWMProtocols (display, mywin, &delete_win, 1);
1.1.1.5 root 749: XSync (display, 0);
750:
751: XStoreName (display, mywin, "UAE");
1.1.1.7 root 752: XSetIconName (display, mywin, "UAE Screen");
753:
754: /* set class hint */
755: classhint.res_name = "UAE";
756: classhint.res_class = "UAEScreen";
757: XSetClassHint(display, mywin, &classhint);
758:
759: hints = XAllocWMHints();
760: /* Set window group leader to self to become an application
761: * that can be hidden by e.g. WindowMaker.
762: * Would be more useful if we could find out what the
763: * (optional) GTK+ window ID is :-/ */
764: hints->window_group = mywin;
765: hints->flags = WindowGroupHint;
766: XSetWMHints(display, mywin, hints);
767:
1.1.1.5 root 768: XMapRaised (display, mywin);
769: XSync (display, 0);
770: mygc = XCreateGC (display, mywin, 0, 0);
771:
772: if (dgamode) {
773: #ifdef USE_DGA_EXTENSION
774: enter_dga_mode ();
775: /*setuid(getuid());*/
776: picasso_vidinfo.rowbytes = fb_width * picasso_vidinfo.pixbytes;
777: #endif
778: } else {
779: get_image (current_width, current_height, &ami_dinfo);
780: if (screen_is_picasso) {
781: get_image (current_width, current_height, &pic_dinfo);
782: picasso_vidinfo.rowbytes = pic_dinfo.ximg->bytes_per_line;
783: }
784: }
785:
786: picasso_vidinfo.extra_mem = 1;
787:
788: if (need_dither) {
789: gfxvidinfo.maxblocklines = 0;
790: gfxvidinfo.rowbytes = gfxvidinfo.pixbytes * currprefs.gfx_width;
791: gfxvidinfo.linemem = (char *)malloc (gfxvidinfo.rowbytes);
792: } else if (! dgamode) {
793: gfxvidinfo.emergmem = 0;
794: gfxvidinfo.linemem = 0;
795: gfxvidinfo.bufmem = ami_dinfo.image_mem;
796: gfxvidinfo.rowbytes = ami_dinfo.ximg->bytes_per_line;
1.1.1.6 root 797: if (currprefs.x11_use_low_bandwidth) {
1.1.1.5 root 798: gfxvidinfo.maxblocklines = 0;
799: gfxvidinfo.rowbytes = ami_dinfo.ximg->bytes_per_line;
800: gfxvidinfo.linemem = (char *)malloc (gfxvidinfo.rowbytes);
801: } else {
802: gfxvidinfo.maxblocklines = 100; /* whatever... */
803: }
804: }
805:
806: if (visualInfo.VI_CLASS != TrueColor && ! screen_is_picasso) {
807: int i;
808: for (i = 0; i < 256; i++)
809: XStoreColor (display, cmap, parsed_xcolors + i);
810: }
811:
812: #ifdef USE_DGA_EXTENSION
813: if (dgamode) {
814: dga_colormap_installed = 0;
815: XF86DGAInstallColormap (display, screen, cmap2);
816: XF86DGAInstallColormap (display, screen, cmap);
817: }
818: #endif
819:
820: if (! dgamode) {
1.1.1.6 root 821: if (! currprefs.x11_hide_cursor)
1.1.1.5 root 822: XDefineCursor (display, mywin, xhairCursor);
823: else
824: XDefineCursor (display, mywin, blankCursor);
825: cursorOn = 1;
826: }
827:
828: if (screen_is_picasso) {
829: picasso_has_invalid_lines = 0;
830: picasso_invalid_start = picasso_vidinfo.height + 1;
831: picasso_invalid_stop = -1;
832: memset (picasso_invalid_lines, 0, sizeof picasso_invalid_lines);
833: }
1.1.1.6 root 834:
835: lastmx = lastmy = 0;
836: newmousecounters = 0;
837: inwindow = 0;
838: for (i = 0; hotkeys[i].syms[0] != 0; i++) {
839: hotkeys[i].mask = 0;
840: for (j = 0; hotkeys[i].syms[j] != 0; j++)
841: hotkeys[i].mask |= (1 << j);
842: }
1.1.1.5 root 843: }
844:
845: int graphics_init (void)
846: {
847: int i,j;
1.1.1.3 root 848: XPixmapFormatValues *xpfvs;
849:
1.1.1.6 root 850: if (currprefs.x11_use_mitshm && ! shmavail) {
1.1.1.5 root 851: fprintf (stderr, "MIT-SHM extension not supported by X server.\n");
852: }
1.1.1.3 root 853: if (currprefs.color_mode > 5)
1.1.1.5 root 854: fprintf (stderr, "Bad color mode selected. Using default.\n"), currprefs.color_mode = 0;
1.1.1.3 root 855:
856: x11_init_ok = 0;
857: need_dither = 0;
858: screen_is_picasso = 0;
1.1.1.5 root 859: dgamode = 0;
860:
861: init_dispinfo (&ami_dinfo);
862: init_dispinfo (&pic_dinfo);
1.1.1.3 root 863:
1.1.1.5 root 864: screen = XDefaultScreen (display);
865: rootwin = XRootWindow (display, screen);
1.1.1.3 root 866:
1.1 root 867: /* try for a 12 bit visual first, then a 16 bit, then a 24 bit, then 8 bit */
1.1.1.5 root 868: if (XMatchVisualInfo (display, screen, 12, TrueColor, &visualInfo)) {
869: } else if (XMatchVisualInfo (display, screen, 15, TrueColor, &visualInfo)) {
870: } else if (XMatchVisualInfo (display, screen, 16, TrueColor, &visualInfo)) {
871: } else if (XMatchVisualInfo (display, screen, 24, TrueColor, &visualInfo)) {
872: } else if (XMatchVisualInfo (display, screen, 8, PseudoColor, &visualInfo)) {
1.1 root 873: /* for our HP boxes */
1.1.1.5 root 874: } else if (XMatchVisualInfo (display, screen, 8, GrayScale, &visualInfo)) {
875: } else if (XMatchVisualInfo (display, screen, 4, PseudoColor, &visualInfo)) {
1.1 root 876: /* VGA16 server. Argh. */
1.1.1.5 root 877: } else if (XMatchVisualInfo (display, screen, 1, StaticGray, &visualInfo)) {
1.1 root 878: /* Mono server. Yuk */
879: } else {
1.1.1.5 root 880: fprintf (stderr, "Can't obtain appropriate X visual.\n");
1.1 root 881: return 0;
882: }
883: vis = visualInfo.visual;
884: bitdepth = visualInfo.depth;
1.1.1.3 root 885:
1.1 root 886: /* We now have the bitdepth of the display, but that doesn't tell us yet
887: * how many bits to use per pixel. The VGA16 server has a bitdepth of 4,
888: * but uses 1 byte per pixel. */
1.1.1.5 root 889: xpfvs = XListPixmapFormats (display, &i);
890: for (j = 0; j < i && xpfvs[j].depth != bitdepth; j++)
1.1 root 891: ;
1.1.1.5 root 892: if (j < i)
893: bit_unit = xpfvs[j].bits_per_pixel;
894: XFree (xpfvs);
1.1 root 895: if (j == i) {
1.1.1.5 root 896: fprintf (stderr, "Your X server is feeling ill.\n");
1.1 root 897: return 0;
898: }
1.1.1.3 root 899:
1.1.1.5 root 900: fprintf (stderr, "Using %d bit visual, %d bits per pixel\n", bitdepth, bit_unit);
1.1 root 901:
1.1.1.5 root 902: fixup_prefs_dimensions (&currprefs);
1.1.1.2 root 903:
1.1.1.3 root 904: gfxvidinfo.width = currprefs.gfx_width;
905: gfxvidinfo.height = currprefs.gfx_height;
906: current_width = currprefs.gfx_width;
907: current_height = currprefs.gfx_height;
1.1.1.5 root 908:
909: cmap = XCreateColormap (display, rootwin, vis, AllocNone);
910: cmap2 = XCreateColormap (display, rootwin, vis, AllocNone);
911: if (visualInfo.VI_CLASS == GrayScale || visualInfo.VI_CLASS == PseudoColor) {
912: XAllocColorCells (display, cmap, 0, 0, 0, pixel_return, 1 << bitdepth);
913: XAllocColorCells (display, cmap2, 0, 0, 0, pixel_return, 1 << bitdepth);
914: }
1.1.1.3 root 915:
916: if (bitdepth < 8 || (bitdepth == 8 && currprefs.color_mode == 3)) {
1.1 root 917: gfxvidinfo.pixbytes = 2;
1.1.1.6 root 918: currprefs.x11_use_low_bandwidth = 0;
1.1 root 919: need_dither = 1;
920: } else {
1.1.1.3 root 921: gfxvidinfo.pixbytes = bit_unit >> 3;
1.1 root 922: }
1.1.1.2 root 923:
1.1.1.5 root 924: if (! init_colors ())
1.1 root 925: return 0;
926:
1.1.1.5 root 927: blankCursor = XCreatePixmapCursor (display,
928: XCreatePixmap (display, rootwin, 1, 1, 1),
929: XCreatePixmap (display, rootwin, 1, 1, 1),
930: &black, &white, 0, 0);
931: xhairCursor = XCreateFontCursor (display, XC_crosshair);
1.1.1.3 root 932:
1.1.1.5 root 933: graphics_subinit ();
1.1.1.3 root 934:
1.1 root 935: buttonstate[0] = buttonstate[1] = buttonstate[2] = 0;
1.1.1.5 root 936: for (i = 0; i < 256; i++)
1.1 root 937: keystate[i] = 0;
1.1.1.5 root 938: grabbed = 0;
1.1.1.3 root 939:
1.1.1.2 root 940: return x11_init_ok = 1;
1.1 root 941: }
942:
1.1.1.5 root 943: static void destroy_dinfo (struct disp_info *dinfo)
1.1 root 944: {
1.1.1.5 root 945: if (dinfo->ximg == NULL)
1.1.1.2 root 946: return;
1.1.1.5 root 947: #if SHM_SUPPORT_LINKS == 1
948: if (dinfo->shminfo.shmid != -1)
949: shmdt (dinfo->shminfo.shmaddr);
950: dinfo->shminfo.shmid = -1;
951: #endif
952: XDestroyImage (dinfo->ximg);
953: dinfo->ximg = NULL;
954: }
1.1.1.3 root 955:
1.1.1.5 root 956: static void graphics_subshutdown (void)
957: {
958: XSync (display, 0);
1.1.1.2 root 959: #ifdef USE_DGA_EXTENSION
1.1.1.5 root 960: if (dgamode)
961: leave_dga_mode ();
1.1.1.2 root 962: #endif
1.1.1.5 root 963:
964: destroy_dinfo (&ami_dinfo);
965: destroy_dinfo (&pic_dinfo);
966:
967: XDestroyWindow (display, mywin);
968:
969: if (gfxvidinfo.linemem != NULL)
970: free (gfxvidinfo.linemem);
971: if (gfxvidinfo.emergmem != NULL)
972: free (gfxvidinfo.emergmem);
973: }
974:
975: void graphics_leave (void)
976: {
977: if (! x11_init_ok)
978: return;
979:
980: graphics_subshutdown ();
981:
982: if (autorepeatoff)
983: XAutoRepeatOn (display);
984:
985: XFlush (display);
986: XSync (display, 0);
987:
988: XFreeColormap (display, cmap);
989: XFreeColormap (display, cmap2);
990:
991: XCloseDisplay (display);
992: dumpcustom ();
1.1 root 993: }
994:
1.1.1.3 root 995: /* Decode KeySyms. This function knows about all keys that are common
1.1 root 996: * between different keyboard languages. */
997: static int kc_decode (KeySym ks)
998: {
1.1.1.3 root 999: switch (ks) {
1.1 root 1000: case XK_B: case XK_b: return AK_B;
1001: case XK_C: case XK_c: return AK_C;
1002: case XK_D: case XK_d: return AK_D;
1003: case XK_E: case XK_e: return AK_E;
1004: case XK_F: case XK_f: return AK_F;
1005: case XK_G: case XK_g: return AK_G;
1006: case XK_H: case XK_h: return AK_H;
1007: case XK_I: case XK_i: return AK_I;
1008: case XK_J: case XK_j: return AK_J;
1009: case XK_K: case XK_k: return AK_K;
1010: case XK_L: case XK_l: return AK_L;
1011: case XK_N: case XK_n: return AK_N;
1012: case XK_O: case XK_o: return AK_O;
1013: case XK_P: case XK_p: return AK_P;
1014: case XK_R: case XK_r: return AK_R;
1015: case XK_S: case XK_s: return AK_S;
1016: case XK_T: case XK_t: return AK_T;
1017: case XK_U: case XK_u: return AK_U;
1018: case XK_V: case XK_v: return AK_V;
1019: case XK_X: case XK_x: return AK_X;
1.1.1.3 root 1020:
1.1 root 1021: case XK_0: return AK_0;
1022: case XK_1: return AK_1;
1023: case XK_2: return AK_2;
1024: case XK_3: return AK_3;
1025: case XK_4: return AK_4;
1026: case XK_5: return AK_5;
1027: case XK_6: return AK_6;
1028: case XK_7: return AK_7;
1029: case XK_8: return AK_8;
1030: case XK_9: return AK_9;
1.1.1.3 root 1031:
1.1 root 1032: /* You never know which Keysyms might be missing on some workstation
1033: * This #ifdef should be enough. */
1034: #if defined(XK_KP_Prior) && defined(XK_KP_Left) && defined(XK_KP_Insert) && defined (XK_KP_End)
1035: case XK_KP_0: case XK_KP_Insert: return AK_NP0;
1036: case XK_KP_1: case XK_KP_End: return AK_NP1;
1037: case XK_KP_2: case XK_KP_Down: return AK_NP2;
1038: case XK_KP_3: case XK_KP_Next: return AK_NP3;
1039: case XK_KP_4: case XK_KP_Left: return AK_NP4;
1040: case XK_KP_5: case XK_KP_Begin: return AK_NP5;
1041: case XK_KP_6: case XK_KP_Right: return AK_NP6;
1042: case XK_KP_7: case XK_KP_Home: return AK_NP7;
1043: case XK_KP_8: case XK_KP_Up: return AK_NP8;
1044: case XK_KP_9: case XK_KP_Prior: return AK_NP9;
1045: #else
1046: case XK_KP_0: return AK_NP0;
1047: case XK_KP_1: return AK_NP1;
1048: case XK_KP_2: return AK_NP2;
1049: case XK_KP_3: return AK_NP3;
1050: case XK_KP_4: return AK_NP4;
1051: case XK_KP_5: return AK_NP5;
1052: case XK_KP_6: return AK_NP6;
1053: case XK_KP_7: return AK_NP7;
1054: case XK_KP_8: return AK_NP8;
1055: case XK_KP_9: return AK_NP9;
1056: #endif
1057: case XK_KP_Divide: return AK_NPDIV;
1058: case XK_KP_Multiply: return AK_NPMUL;
1059: case XK_KP_Subtract: return AK_NPSUB;
1060: case XK_KP_Add: return AK_NPADD;
1061: case XK_KP_Decimal: return AK_NPDEL;
1062: case XK_KP_Enter: return AK_ENT;
1063:
1064: case XK_F1: return AK_F1;
1065: case XK_F2: return AK_F2;
1066: case XK_F3: return AK_F3;
1067: case XK_F4: return AK_F4;
1068: case XK_F5: return AK_F5;
1069: case XK_F6: return AK_F6;
1070: case XK_F7: return AK_F7;
1071: case XK_F8: return AK_F8;
1072: case XK_F9: return AK_F9;
1073: case XK_F10: return AK_F10;
1.1.1.3 root 1074:
1.1 root 1075: case XK_BackSpace: return AK_BS;
1076: case XK_Delete: return AK_DEL;
1.1.1.3 root 1077: case XK_Control_L: return AK_CTRL;
1078: case XK_Control_R: return AK_RCTRL;
1.1 root 1079: case XK_Tab: return AK_TAB;
1080: case XK_Alt_L: return AK_LALT;
1081: case XK_Alt_R: return AK_RALT;
1082: case XK_Meta_R: case XK_Hyper_R: return AK_RAMI;
1083: case XK_Meta_L: case XK_Hyper_L: return AK_LAMI;
1084: case XK_Return: return AK_RET;
1085: case XK_space: return AK_SPC;
1086: case XK_Shift_L: return AK_LSH;
1087: case XK_Shift_R: return AK_RSH;
1088: case XK_Escape: return AK_ESC;
1089:
1.1.1.3 root 1090: case XK_Insert: return AK_HELP;
1091: case XK_Home: return AK_NPLPAREN;
1092: case XK_End: return AK_NPRPAREN;
1.1 root 1093: case XK_Caps_Lock: return AK_CAPSLOCK;
1.1.1.3 root 1094:
1.1 root 1095: case XK_Up: return AK_UP;
1096: case XK_Down: return AK_DN;
1097: case XK_Left: return AK_LF;
1098: case XK_Right: return AK_RT;
1.1.1.3 root 1099:
1.1.1.9 root 1100: #if 0
1.1 root 1101: case XK_F11: return AK_BACKSLASH;
1.1.1.9 root 1102: #else
1103: case XK_F11: frametime = 0; timeframes = 0; bogusframe = 1; break;
1104: #endif
1.1 root 1105: #ifdef XK_Page_Up /* These are missing occasionally */
1106: case XK_Page_Up: return AK_RAMI; /* PgUp mapped to right amiga */
1107: case XK_Page_Down: return AK_LAMI; /* PgDn mapped to left amiga */
1108: #endif
1109: }
1110: return -1;
1111: }
1112:
1.1.1.5 root 1113: static int decode_fr (KeySym ks)
1.1 root 1114: {
1115: switch(ks) { /* FR specific */
1116: case XK_A: case XK_a: return AK_Q;
1.1.1.3 root 1117: case XK_M: case XK_m: return AK_SEMICOLON;
1118: case XK_Q: case XK_q: return AK_A;
1.1 root 1119: case XK_Y: case XK_y: return AK_Y;
1.1.1.2 root 1120: case XK_W: case XK_w: return AK_Z;
1121: case XK_Z: case XK_z: return AK_W;
1.1.1.6 root 1122: #if 0
1.1 root 1123: case XK_bracketleft: return AK_LBRACKET;
1124: case XK_bracketright: return AK_RBRACKET;
1125: case XK_comma: return AK_M;
1126: case XK_less: case XK_greater: return AK_LTGT;
1127: case XK_period: return AK_COMMA;
1128: case XK_parenright: return AK_MINUS;
1129: case XK_equal: return AK_SLASH;
1130: case XK_numbersign: return AK_NUMBERSIGN;
1131: case XK_slash: return AK_PERIOD;
1132: case XK_minus: return AK_EQUAL;
1133: case XK_backslash: return AK_BACKSLASH;
1.1.1.6 root 1134: #else
1135: /* not sure for this one: my X 3.3 server doesn't handle this key always
1136: * correctly... But anyway, on new french keyboards, no more bracket key
1137: * at this place.
1138: */
1139: case XK_dead_circumflex:
1140: case XK_dead_diaeresis: return AK_LBRACKET;
1141: case XK_dollar:
1142: case XK_sterling: return AK_RBRACKET;
1143: case XK_comma: case XK_question: return AK_M;
1144: case XK_less: case XK_greater: return AK_LTGT;
1145: case XK_semicolon: case XK_period: return AK_COMMA;
1146: case XK_parenright: case XK_degree: return AK_MINUS;
1147: case XK_equal: case XK_plus: return AK_SLASH;
1148: case XK_numbersign: return AK_NUMBERSIGN;
1149: case XK_colon: case XK_slash: return AK_PERIOD;
1150: case XK_minus: case XK_6: return AK_6;
1151: case XK_ugrave: case XK_percent: return AK_QUOTE;
1152: /* found a spare key - I hope it deserves this place. */
1153: case XK_asterisk: case XK_mu: return AK_BACKSLASH;
1154: case XK_exclam: case XK_section: return AK_EQUAL;
1155: case XK_twosuperior: case XK_asciitilde: return AK_BACKQUOTE;
1156: case XK_Multi_key: return AK_RAMI;
1157: case XK_Mode_switch: return AK_RALT;
1158: #endif
1.1 root 1159: }
1160:
1161: return -1;
1162: }
1163:
1.1.1.5 root 1164: static int decode_us (KeySym ks)
1.1 root 1165: {
1.1.1.3 root 1166: switch(ks) { /* US specific */
1.1 root 1167: case XK_A: case XK_a: return AK_A;
1168: case XK_M: case XK_m: return AK_M;
1169: case XK_Q: case XK_q: return AK_Q;
1170: case XK_Y: case XK_y: return AK_Y;
1.1.1.2 root 1171: case XK_W: case XK_w: return AK_W;
1.1 root 1172: case XK_Z: case XK_z: return AK_Z;
1173: case XK_bracketleft: return AK_LBRACKET;
1174: case XK_bracketright: return AK_RBRACKET;
1175: case XK_comma: return AK_COMMA;
1176: case XK_period: return AK_PERIOD;
1177: case XK_slash: return AK_SLASH;
1178: case XK_semicolon: return AK_SEMICOLON;
1179: case XK_minus: return AK_MINUS;
1180: case XK_equal: return AK_EQUAL;
1181: /* this doesn't work: */
1182: case XK_quoteright: return AK_QUOTE;
1183: case XK_quoteleft: return AK_BACKQUOTE;
1184: case XK_backslash: return AK_BACKSLASH;
1185: }
1186:
1187: return -1;
1188: }
1189:
1.1.1.5 root 1190: static int decode_de (KeySym ks)
1.1 root 1191: {
1192: switch(ks) {
1193: /* DE specific */
1194: case XK_A: case XK_a: return AK_A;
1195: case XK_M: case XK_m: return AK_M;
1196: case XK_Q: case XK_q: return AK_Q;
1.1.1.2 root 1197: case XK_W: case XK_w: return AK_W;
1.1 root 1198: case XK_Y: case XK_y: return AK_Z;
1199: case XK_Z: case XK_z: return AK_Y;
1200: case XK_Odiaeresis: case XK_odiaeresis: return AK_SEMICOLON;
1201: case XK_Adiaeresis: case XK_adiaeresis: return AK_QUOTE;
1202: case XK_Udiaeresis: case XK_udiaeresis: return AK_LBRACKET;
1203: case XK_plus: case XK_asterisk: return AK_RBRACKET;
1204: case XK_comma: return AK_COMMA;
1205: case XK_period: return AK_PERIOD;
1206: case XK_less: case XK_greater: return AK_LTGT;
1207: case XK_numbersign: return AK_NUMBERSIGN;
1208: case XK_ssharp: return AK_MINUS;
1209: case XK_apostrophe: return AK_EQUAL;
1210: case XK_asciicircum: return AK_BACKQUOTE;
1211: case XK_minus: return AK_SLASH;
1212: }
1213:
1214: return -1;
1215: }
1216:
1.1.1.13! root 1217: static int decode_dk (KeySym ks)
! 1218: {
! 1219: switch(ks) {
! 1220: /* DK specific */
! 1221: case XK_A: case XK_a: return AK_A;
! 1222: case XK_M: case XK_m: return AK_M;
! 1223: case XK_Q: case XK_q: return AK_Q;
! 1224: case XK_W: case XK_w: return AK_W;
! 1225: case XK_Y: case XK_y: return AK_Y;
! 1226: case XK_Z: case XK_z: return AK_Z;
! 1227: case XK_AE: case XK_ae: return AK_SEMICOLON;
! 1228: case XK_Ooblique: case XK_oslash: return AK_QUOTE;
! 1229: case XK_Aring: case XK_aring: return AK_LBRACKET;
! 1230: case XK_apostrophe: case XK_asterisk: return AK_NUMBERSIGN;
! 1231: case XK_dead_diaeresis: case XK_dead_circumflex: return AK_RBRACKET;
! 1232: case XK_dead_acute: case XK_dead_grave: return AK_BACKSLASH;
! 1233: case XK_onehalf: case XK_section: return AK_BACKQUOTE;
! 1234: case XK_comma: return AK_COMMA;
! 1235: case XK_period: return AK_PERIOD;
! 1236: case XK_less: case XK_greater: return AK_LTGT;
! 1237: case XK_numbersign: return AK_NUMBERSIGN;
! 1238: case XK_plus: return AK_MINUS;
! 1239: case XK_asciicircum: return AK_BACKQUOTE;
! 1240: case XK_minus: return AK_SLASH;
! 1241: }
! 1242:
! 1243: return -1;
! 1244: }
! 1245:
1.1.1.5 root 1246: static int decode_se (KeySym ks)
1.1 root 1247: {
1248: switch(ks) {
1249: /* SE specific */
1250: case XK_A: case XK_a: return AK_A;
1251: case XK_M: case XK_m: return AK_M;
1252: case XK_Q: case XK_q: return AK_Q;
1.1.1.2 root 1253: case XK_W: case XK_w: return AK_W;
1.1 root 1254: case XK_Y: case XK_y: return AK_Y;
1255: case XK_Z: case XK_z: return AK_Z;
1256: case XK_Odiaeresis: case XK_odiaeresis: return AK_SEMICOLON;
1257: case XK_Adiaeresis: case XK_adiaeresis: return AK_QUOTE;
1258: case XK_Aring: case XK_aring: return AK_LBRACKET;
1259: case XK_comma: return AK_COMMA;
1260: case XK_period: return AK_PERIOD;
1261: case XK_minus: return AK_SLASH;
1262: case XK_less: case XK_greater: return AK_LTGT;
1263: case XK_plus: case XK_question: return AK_EQUAL;
1264: case XK_at: case XK_onehalf: return AK_BACKQUOTE;
1265: case XK_asciitilde: case XK_asciicircum: return AK_RBRACKET;
1266: case XK_backslash: case XK_bar: return AK_MINUS;
1.1.1.3 root 1267:
1.1 root 1268: case XK_numbersign: return AK_NUMBERSIGN;
1269: }
1270:
1271: return -1;
1272: }
1273:
1.1.1.5 root 1274: static int decode_it (KeySym ks)
1.1 root 1275: {
1276: switch(ks) {
1277: /* IT specific */
1278: case XK_A: case XK_a: return AK_A;
1279: case XK_M: case XK_m: return AK_M;
1280: case XK_Q: case XK_q: return AK_Q;
1.1.1.2 root 1281: case XK_W: case XK_w: return AK_W;
1.1 root 1282: case XK_Y: case XK_y: return AK_Y;
1283: case XK_Z: case XK_z: return AK_Z;
1284: case XK_Ograve: case XK_ograve: return AK_SEMICOLON;
1285: case XK_Agrave: case XK_agrave: return AK_QUOTE;
1286: case XK_Egrave: case XK_egrave: return AK_LBRACKET;
1287: case XK_plus: case XK_asterisk: return AK_RBRACKET;
1288: case XK_comma: return AK_COMMA;
1289: case XK_period: return AK_PERIOD;
1290: case XK_less: case XK_greater: return AK_LTGT;
1.1.1.3 root 1291: case XK_backslash: case XK_bar: return AK_BACKQUOTE;
1292: case XK_apostrophe: return AK_MINUS;
1.1 root 1293: case XK_Igrave: case XK_igrave: return AK_EQUAL;
1294: case XK_minus: return AK_SLASH;
1295: case XK_numbersign: return AK_NUMBERSIGN;
1296: }
1297:
1298: return -1;
1299: }
1300:
1.1.1.5 root 1301: static int decode_es (KeySym ks)
1.1.1.2 root 1302: {
1303: switch(ks) {
1304: /* ES specific */
1305: case XK_A: case XK_a: return AK_A;
1306: case XK_M: case XK_m: return AK_M;
1307: case XK_Q: case XK_q: return AK_Q;
1308: case XK_W: case XK_w: return AK_W;
1309: case XK_Y: case XK_y: return AK_Y;
1310: case XK_Z: case XK_z: return AK_Z;
1311: case XK_ntilde: case XK_Ntilde: return AK_SEMICOLON;
1312: #ifdef XK_dead_acute
1313: case XK_dead_acute: case XK_dead_diaeresis: return AK_QUOTE;
1314: case XK_dead_grave: case XK_dead_circumflex: return AK_LBRACKET;
1315: #endif
1316: case XK_plus: case XK_asterisk: return AK_RBRACKET;
1317: case XK_comma: return AK_COMMA;
1318: case XK_period: return AK_PERIOD;
1319: case XK_less: case XK_greater: return AK_LTGT;
1.1.1.3 root 1320: case XK_backslash: case XK_bar: return AK_BACKQUOTE;
1321: case XK_apostrophe: return AK_MINUS;
1.1.1.2 root 1322: case XK_Igrave: case XK_igrave: return AK_EQUAL;
1323: case XK_minus: return AK_SLASH;
1324: case XK_numbersign: return AK_NUMBERSIGN;
1325: }
1326:
1327: return -1;
1328: }
1329:
1.1.1.5 root 1330: static int keycode2amiga (XKeyEvent *event)
1.1 root 1331: {
1332: KeySym ks;
1333: int as;
1334: int index = 0;
1.1.1.3 root 1335:
1.1 root 1336: do {
1.1.1.5 root 1337: int hkreturn = -1, returnnow = 0;
1338: ks = XLookupKeysym (event, index);
1339: if (event->type == KeyPress) {
1340: int i, j;
1341: for (i = 0; hotkeys[i].syms[0] != 0; i++) {
1342: for (j = 0; hotkeys[i].syms[j] != 0; j++) {
1343: if (ks == hotkeys[i].syms[j]) {
1344: hotkeys[i].mask &= ~(1 << j);
1345: if (hotkeys[i].mask == 0) {
1346: returnnow = 1;
1347: hkreturn = hotkeys[i].retval;
1348: }
1349: }
1350: }
1351: }
1352: } else {
1353: int i, j;
1354: for (i = 0; hotkeys[i].syms[0] != 0; i++) {
1355: for (j = 0; hotkeys[i].syms[j] != 0; j++) {
1356: if (ks == hotkeys[i].syms[j]) {
1357: hotkeys[i].mask |= (1 << j);
1358: }
1359: }
1360: }
1361: }
1362: if (returnnow)
1363: return -2;
1.1 root 1364: as = kc_decode (ks);
1.1.1.3 root 1365:
1366: if (as == -1) {
1.1.1.5 root 1367: switch (currprefs.keyboard_lang) {
1.1 root 1368: case KBD_LANG_FR:
1.1.1.5 root 1369: as = decode_fr (ks);
1.1 root 1370: break;
1371:
1.1.1.3 root 1372: case KBD_LANG_US:
1.1.1.5 root 1373: as = decode_us (ks);
1.1 root 1374: break;
1.1.1.3 root 1375:
1.1 root 1376: case KBD_LANG_DE:
1.1.1.5 root 1377: as = decode_de (ks);
1.1 root 1378: break;
1.1.1.3 root 1379:
1.1.1.13! root 1380: case KBD_LANG_DK:
! 1381: as = decode_dk (ks);
! 1382: break;
! 1383:
1.1 root 1384: case KBD_LANG_SE:
1.1.1.5 root 1385: as = decode_se (ks);
1.1 root 1386: break;
1.1.1.3 root 1387:
1.1 root 1388: case KBD_LANG_IT:
1.1.1.5 root 1389: as = decode_it (ks);
1.1 root 1390: break;
1391:
1.1.1.2 root 1392: case KBD_LANG_ES:
1.1.1.5 root 1393: as = decode_es (ks);
1.1.1.2 root 1394: break;
1395:
1.1 root 1396: default:
1397: as = -1;
1398: break;
1399: }
1400: }
1.1.1.5 root 1401: if (-1 != as)
1.1 root 1402: return as;
1403: index++;
1404: } while (ks != NoSymbol);
1405: return -1;
1406: }
1407:
1408: static struct timeval lastMotionTime;
1409:
1.1.1.3 root 1410: static int refresh_necessary = 0;
1411:
1.1.1.5 root 1412: void handle_events (void)
1.1 root 1413: {
1414: newmousecounters = 0;
1.1.1.5 root 1415: gui_handle_events ();
1.1.1.3 root 1416:
1.1 root 1417: for (;;) {
1418: XEvent event;
1419: #if 0
1.1.1.5 root 1420: if (! XCheckMaskEvent (display, eventmask, &event))
1421: break;
1.1 root 1422: #endif
1.1.1.5 root 1423: if (! XPending (display))
1424: break;
1425:
1426: XNextEvent (display, &event);
1.1.1.3 root 1427:
1.1.1.5 root 1428: switch (event.type) {
1.1.1.3 root 1429: case KeyPress: {
1.1.1.5 root 1430: int i;
1431: int kc = keycode2amiga ((XKeyEvent *)&event);
1.1 root 1432:
1.1.1.5 root 1433: if (kc == -2) {
1434: for (i = 0; hotkeys[i].syms[0] != 0; i++) {
1435: if (hotkeys[i].mask == 0) {
1436: if (hotkeys[i].handler != NULL)
1437: hotkeys[i].handler();
1438: }
1439: }
1.1 root 1440: break;
1.1.1.5 root 1441: }
1.1 root 1442:
1.1.1.5 root 1443: if (kc == -1)
1.1 root 1444: break;
1.1.1.5 root 1445: if (! keystate[kc]) {
1446: keystate[kc] = 1;
1447: record_key (kc << 1);
1.1 root 1448: }
1449: break;
1450: }
1.1.1.3 root 1451: case KeyRelease: {
1.1.1.5 root 1452: int kc = keycode2amiga ((XKeyEvent *)&event);
1453: if (kc < 0)
1454: break;
1.1 root 1455: keystate[kc] = 0;
1456: record_key ((kc << 1) | 1);
1457: break;
1458: }
1459: case ButtonPress:
1460: buttonstate[((XButtonEvent *)&event)->button-1] = 1;
1461: break;
1462: case ButtonRelease:
1463: buttonstate[((XButtonEvent *)&event)->button-1] = 0;
1464: break;
1.1.1.5 root 1465: case MotionNotify:
1466: if (dgamode) {
1467: newmousecounters = 0;
1468: lastmx += ((XMotionEvent *)&event)->x_root;
1469: lastmy += ((XMotionEvent *)&event)->y_root;
1470: } else if (grabbed) {
1471: int realmove = 0;
1.1.1.12 root 1472: int tx, ty,ttx,tty;
1.1.1.5 root 1473:
1474: tx = ((XMotionEvent *)&event)->x;
1475: ty = ((XMotionEvent *)&event)->y;
1476:
1477: if (! event.xmotion.send_event) {
1478: newmousecounters = 0;
1479: lastmx += tx - oldx;
1480: lastmy += ty - oldy;
1481: realmove = 1;
1482: #undef ABS
1483: #define ABS(a) (((a)<0) ? -(a) : (a) )
1484: if (ABS(current_width / 2 - tx) > 3 * current_width / 8
1485: || ABS(current_height / 2 - ty) > 3 * current_height / 8)
1486: {
1487: #undef ABS
1488: XEvent event;
1.1.1.12 root 1489: ttx = current_width / 2;
1490: tty = current_height / 2;
1.1.1.5 root 1491: event.type = MotionNotify;
1492: event.xmotion.display = display;
1493: event.xmotion.window = mywin;
1.1.1.12 root 1494: event.xmotion.x = ttx;
1495: event.xmotion.y = tty;
1.1.1.5 root 1496: XSendEvent (display, mywin, False,
1497: PointerMotionMask, &event);
1.1.1.12 root 1498: XWarpPointer (display, None, mywin, 0, 0, 0, 0, ttx, tty);
1.1.1.5 root 1499: }
1.1.1.12 root 1500: } else {
1501: tx=event.xmotion.x;
1502: ty=event.xmotion.y;
1.1.1.5 root 1503: }
1504: oldx = tx;
1505: oldy = ty;
1506: } else if (inwindow) {
1507: lastmx = ((XMotionEvent *)&event)->x;
1508: lastmy = ((XMotionEvent *)&event)->y;
1.1.1.6 root 1509: if (! cursorOn && !currprefs.x11_hide_cursor) {
1.1.1.5 root 1510: XDefineCursor(display, mywin, xhairCursor);
1511: cursorOn = 1;
1512: }
1513: gettimeofday(&lastMotionTime, NULL);
1514: }
1515:
1516: if (ievent_alive) {
1517: if (lastmx < 0)
1518: lastmx = 0;
1519: if (lastmx > current_width)
1520: lastmx = current_width;
1521: if (lastmy < 0)
1522: lastmy = 0;
1523: if (lastmy > current_height)
1524: lastmy = current_height;
1525: }
1526: break;
1.1 root 1527: case EnterNotify:
1528: newmousecounters = 1;
1529: lastmx = ((XCrossingEvent *)&event)->x;
1530: lastmy = ((XCrossingEvent *)&event)->y;
1531: inwindow = 1;
1532: break;
1533: case LeaveNotify:
1534: inwindow = 0;
1535: break;
1536: case FocusIn:
1.1.1.5 root 1537: if (! autorepeatoff)
1538: XAutoRepeatOff (display);
1.1 root 1539: autorepeatoff = 1;
1540: break;
1541: case FocusOut:
1542: if (autorepeatoff)
1.1.1.5 root 1543: XAutoRepeatOn (display);
1.1 root 1544: autorepeatoff = 0;
1545: break;
1546: case Expose:
1.1.1.3 root 1547: refresh_necessary = 1;
1.1 root 1548: break;
1.1.1.7 root 1549: case ClientMessage:
1550: if (event.xclient.data.l[0]==delete_win) {
1551: uae_quit ();
1552: }
1553: break;
1.1 root 1554: }
1555: }
1.1.1.5 root 1556:
1557: #if defined PICASSO96
1558: if (! dgamode) {
1559: if (screen_is_picasso && refresh_necessary) {
1560: DO_PUTIMAGE (pic_dinfo.ximg, 0, 0, 0, 0,
1561: picasso_vidinfo.width, picasso_vidinfo.height);
1562: refresh_necessary = 0;
1563: memset (picasso_invalid_lines, 0, sizeof picasso_invalid_lines);
1564: } else if (screen_is_picasso && picasso_has_invalid_lines) {
1565: int i;
1566: int strt = -1;
1567:
1568: picasso_invalid_lines[picasso_vidinfo.height] = 0;
1569: for (i = picasso_invalid_start; i < picasso_invalid_stop + 2; i++) {
1570: if (picasso_invalid_lines[i]) {
1571: picasso_invalid_lines[i] = 0;
1572: if (strt != -1)
1573: continue;
1574: strt = i;
1575: } else {
1576: if (strt == -1)
1577: continue;
1578: DO_PUTIMAGE (pic_dinfo.ximg, 0, strt, 0, strt,
1579: picasso_vidinfo.width, i - strt);
1580: strt = -1;
1581: }
1.1.1.3 root 1582: }
1.1.1.5 root 1583: if (strt != -1)
1584: abort ();
1.1.1.3 root 1585: }
1586: }
1.1.1.5 root 1587: picasso_has_invalid_lines = 0;
1588: picasso_invalid_start = picasso_vidinfo.height + 1;
1589: picasso_invalid_stop = -1;
1.1.1.3 root 1590: #endif
1.1.1.5 root 1591:
1592: if (! dgamode) {
1593: if (! screen_is_picasso && refresh_necessary) {
1594: DO_PUTIMAGE (ami_dinfo.ximg, 0, 0, 0, 0, currprefs.gfx_width, currprefs.gfx_height);
1595: refresh_necessary = 0;
1596: }
1.1.1.6 root 1597: if (cursorOn && !currprefs.x11_hide_cursor) {
1.1.1.5 root 1598: struct timeval now;
1599: int diff;
1600: gettimeofday(&now, NULL);
1601: diff = (now.tv_sec - lastMotionTime.tv_sec) * 1000000 +
1602: (now.tv_usec - lastMotionTime.tv_usec);
1603: if (diff > 1000000) {
1604: XDefineCursor (display, mywin, blankCursor);
1605: cursorOn = 0;
1606: }
1.1 root 1607: }
1608: }
1609: /* "Affengriff" */
1.1.1.6 root 1610: if ((keystate[AK_CTRL] || keystate[AK_RCTRL]) && keystate[AK_LAMI] && keystate[AK_RAMI])
1.1.1.5 root 1611: uae_reset ();
1.1 root 1612: }
1613:
1.1.1.5 root 1614: int check_prefs_changed_gfx (void)
1.1 root 1615: {
1.1.1.5 root 1616: if (changed_prefs.gfx_width != currprefs.gfx_width
1617: || changed_prefs.gfx_height != currprefs.gfx_height)
1618: fixup_prefs_dimensions (&changed_prefs);
1619:
1620: if (changed_prefs.gfx_width == currprefs.gfx_width
1621: && changed_prefs.gfx_height == currprefs.gfx_height
1622: && changed_prefs.gfx_lores == currprefs.gfx_lores
1623: && changed_prefs.gfx_linedbl == currprefs.gfx_linedbl
1624: && changed_prefs.gfx_correct_aspect == currprefs.gfx_correct_aspect
1625: && changed_prefs.gfx_xcenter == currprefs.gfx_xcenter
1626: && changed_prefs.gfx_ycenter == currprefs.gfx_ycenter
1627: && changed_prefs.gfx_afullscreen == currprefs.gfx_afullscreen
1628: && changed_prefs.gfx_pfullscreen == currprefs.gfx_pfullscreen)
1629: return 0;
1.1.1.6 root 1630:
1631: graphics_subshutdown ();
1632: currprefs.gfx_width = changed_prefs.gfx_width;
1633: currprefs.gfx_height = changed_prefs.gfx_height;
1634: currprefs.gfx_lores = changed_prefs.gfx_lores;
1635: currprefs.gfx_linedbl = changed_prefs.gfx_linedbl;
1636: currprefs.gfx_correct_aspect = changed_prefs.gfx_correct_aspect;
1637: currprefs.gfx_xcenter = changed_prefs.gfx_xcenter;
1638: currprefs.gfx_ycenter = changed_prefs.gfx_ycenter;
1639: currprefs.gfx_afullscreen = changed_prefs.gfx_afullscreen;
1640: currprefs.gfx_pfullscreen = changed_prefs.gfx_pfullscreen;
1.1.1.10 root 1641:
1642: gui_update_gfx ();
1643:
1.1.1.6 root 1644: graphics_subinit ();
1645:
1646: if (! inwindow)
1647: XWarpPointer (display, None, mywin, 0, 0, 0, 0,
1648: current_width / 2, current_height / 2);
1649:
1650: notice_screen_contents_lost ();
1651: init_row_map ();
1652: if (screen_is_picasso)
1653: picasso_enablescreen (1);
1.1.1.5 root 1654: return 0;
1.1 root 1655: }
1656:
1.1.1.5 root 1657: int debuggable (void)
1.1 root 1658: {
1659: return 1;
1660: }
1661:
1.1.1.5 root 1662: int needmousehack (void)
1663: {
1.1.1.13! root 1664: if (dgamode || grabbed)
1.1.1.5 root 1665: return 0;
1666: else
1667: return 1;
1668: }
1669:
1670: void LED (int on)
1.1 root 1671: {
1.1.1.2 root 1672: #if 0 /* Maybe that is responsible for the joystick emulation problems on SunOS? */
1.1 root 1673: static int last_on = -1;
1674: XKeyboardControl control;
1675:
1.1.1.5 root 1676: if (last_on == on)
1677: return;
1.1 root 1678: last_on = on;
1679: control.led = 1; /* implementation defined */
1680: control.led_mode = on ? LedModeOn : LedModeOff;
1681: XChangeKeyboardControl(display, KBLed | KBLedMode, &control);
1.1.1.2 root 1682: #endif
1.1 root 1683: }
1684:
1.1.1.3 root 1685: #ifdef PICASSO96
1686:
1687: void DX_Invalidate (int first, int last)
1688: {
1.1.1.5 root 1689: if (first > last)
1690: return;
1691:
1692: picasso_has_invalid_lines = 1;
1693: if (first < picasso_invalid_start)
1694: picasso_invalid_start = first;
1695: if (last > picasso_invalid_stop)
1696: picasso_invalid_stop = last;
1697:
1698: while (first <= last) {
1.1.1.3 root 1699: picasso_invalid_lines[first] = 1;
1700: first++;
1.1.1.5 root 1701: }
1.1.1.3 root 1702: }
1703:
1704: int DX_BitsPerCannon (void)
1705: {
1706: return 8;
1707: }
1708:
1.1.1.5 root 1709: void DX_SetPalette (int start, int count)
1.1.1.3 root 1710: {
1.1.1.5 root 1711: if (! screen_is_picasso || picasso96_state.RGBFormat != RGBFB_CHUNKY)
1.1.1.3 root 1712: return;
1713:
1.1.1.5 root 1714: if (picasso_vidinfo.pixbytes != 1) {
1715: /* This is the case when we're emulating a 256 color display. */
1716: while (count-- > 0) {
1717: int r = picasso96_state.CLUT[start].Red;
1718: int g = picasso96_state.CLUT[start].Green;
1719: int b = picasso96_state.CLUT[start].Blue;
1720: picasso_vidinfo.clut[start++] = (doMask256 (r, red_bits, red_shift)
1721: | doMask256 (g, green_bits, green_shift)
1722: | doMask256 (b, blue_bits, blue_shift));
1723: }
1724: return;
1725: }
1726:
1.1.1.3 root 1727: while (count-- > 0) {
1728: XColor col = parsed_xcolors[start];
1729: col.red = picasso96_state.CLUT[start].Red * 0x0101;
1730: col.green = picasso96_state.CLUT[start].Green * 0x0101;
1731: col.blue = picasso96_state.CLUT[start].Blue * 0x0101;
1732: XStoreColor (display, cmap, &col);
1733: XStoreColor (display, cmap2, &col);
1734: start++;
1735: }
1736: #ifdef USE_DGA_EXTENSION
1.1.1.5 root 1737: if (dgamode) {
1738: dga_colormap_installed ^= 1;
1739: if (dga_colormap_installed == 1)
1740: XF86DGAInstallColormap (display, screen, cmap2);
1741: else
1742: XF86DGAInstallColormap (display, screen, cmap);
1743: }
1.1.1.3 root 1744: #endif
1745: }
1746:
1747: #define MAX_SCREEN_MODES 11
1748:
1749: static int x_size_table[MAX_SCREEN_MODES] = { 320, 320, 320, 320, 640, 640, 640, 800, 1024, 1152, 1280 };
1750: static int y_size_table[MAX_SCREEN_MODES] = { 200, 240, 256, 400, 350, 480, 512, 600, 768, 864, 1024 };
1751:
1752: int DX_FillResolutions (uae_u16 *ppixel_format)
1753: {
1754: Screen *scr = ScreenOfDisplay (display, screen);
1755: int i, count = 0;
1756: int w = WidthOfScreen (scr);
1757: int h = HeightOfScreen (scr);
1.1.1.5 root 1758: int emulate_chunky = 0;
1.1.1.3 root 1759:
1.1.1.5 root 1760: picasso_vidinfo.rgbformat = (bit_unit == 8 ? RGBFB_CHUNKY
1761: : bitdepth == 15 && bit_unit == 16 ? RGBFB_R5G5B5PC
1762: : bitdepth == 16 && bit_unit == 16 ? RGBFB_R5G6B5PC
1763: : bit_unit == 24 ? RGBFB_B8G8R8
1764: : bit_unit == 32 ? RGBFB_B8G8R8A8
1765: : RGBFB_NONE);
1766:
1767: *ppixel_format = 1 << picasso_vidinfo.rgbformat;
1768: if (visualInfo.VI_CLASS == TrueColor && (bit_unit == 16 || bit_unit == 32))
1769: *ppixel_format |= RGBFF_CHUNKY, emulate_chunky = 1;
1.1.1.3 root 1770:
1771: #if defined USE_DGA_EXTENSION && defined USE_VIDMODE_EXTENSION
1.1.1.5 root 1772: if (dgaavail && vidmodeavail) {
1773: for (i = 0; i < vidmodecount && count < MAX_PICASSO_MODES; i++) {
1774: int j;
1775: for (j = 0; j <= emulate_chunky && count < MAX_PICASSO_MODES; j++) {
1776: DisplayModes[count].res.width = allmodes[i]->hdisplay;
1777: DisplayModes[count].res.height = allmodes[i]->vdisplay;
1778: DisplayModes[count].depth = j == 1 ? 1 : bit_unit >> 3;
1779: DisplayModes[count].refresh = 75;
1780: count++;
1781: }
1.1.1.3 root 1782: }
1.1.1.5 root 1783: } else
1.1.1.3 root 1784: #endif
1.1.1.5 root 1785: {
1786: for (i = 0; i < MAX_SCREEN_MODES && count < MAX_PICASSO_MODES; i++) {
1787: int j;
1788: for (j = 0; j <= emulate_chunky && count < MAX_PICASSO_MODES; j++) {
1789: if (x_size_table[i] <= w && y_size_table[i] <= h) {
1790: if (x_size_table[i] > picasso_maxw)
1791: picasso_maxw = x_size_table[i];
1792: if (y_size_table[i] > picasso_maxh)
1793: picasso_maxh = y_size_table[i];
1794: DisplayModes[count].res.width = x_size_table[i];
1795: DisplayModes[count].res.height = y_size_table[i];
1796: DisplayModes[count].depth = j == 1 ? 1 : bit_unit >> 3;
1797: DisplayModes[count].refresh = 75;
1798: count++;
1799: }
1800: }
1801: }
1802: }
1.1.1.3 root 1803:
1804: return count;
1805: }
1806:
1807: static void set_window_for_picasso (void)
1808: {
1.1.1.5 root 1809: if (current_width == picasso_vidinfo.width && current_height == picasso_vidinfo.height)
1810: return;
1.1.1.3 root 1811:
1.1.1.5 root 1812: current_width = picasso_vidinfo.width;
1813: current_height = picasso_vidinfo.height;
1814: XResizeWindow (display, mywin, current_width, current_height);
1.1.1.3 root 1815: #if defined USE_DGA_EXTENSION && defined USE_VIDMODE_EXTENSION
1.1.1.5 root 1816: if (dgamode && vidmodeavail)
1.1.1.3 root 1817: switch_to_best_mode ();
1818: #endif
1819: }
1820:
1.1.1.5 root 1821: void gfx_set_picasso_modeinfo (int w, int h, int depth, int rgbfmt)
1.1.1.3 root 1822: {
1823: picasso_vidinfo.width = w;
1824: picasso_vidinfo.height = h;
1825: picasso_vidinfo.depth = depth;
1.1.1.4 root 1826: picasso_vidinfo.pixbytes = bit_unit >> 3;
1.1.1.3 root 1827:
1828: if (screen_is_picasso)
1829: set_window_for_picasso ();
1830: }
1831:
1832: void gfx_set_picasso_baseaddr (uaecptr a)
1833: {
1834: }
1835:
1836: void gfx_set_picasso_state (int on)
1837: {
1838: if (on == screen_is_picasso)
1839: return;
1.1.1.5 root 1840: graphics_subshutdown ();
1.1.1.3 root 1841: screen_is_picasso = on;
1.1.1.5 root 1842: if (on) {
1843: current_width = picasso_vidinfo.width;
1844: current_height = picasso_vidinfo.height;
1845: } else {
1846: current_width = gfxvidinfo.width;
1847: current_height = gfxvidinfo.height;
1848: }
1849: graphics_subinit ();
1.1.1.3 root 1850: if (on)
1.1.1.5 root 1851: DX_SetPalette (0, 256);
1852: }
1853:
1854: uae_u8 *gfx_lock_picasso (void)
1855: {
1856: #ifdef USE_DGA_EXTENSION
1857: if (dgamode)
1858: return fb_addr;
1.1.1.3 root 1859: else
1.1.1.5 root 1860: #endif
1861: return pic_dinfo.ximg->data;
1862: }
1863: void gfx_unlock_picasso (void)
1864: {
1.1.1.3 root 1865: }
1.1.1.5 root 1866: #endif
1.1.1.3 root 1867:
1.1.1.5 root 1868: int lockscr (void)
1.1 root 1869: {
1.1.1.5 root 1870: return 1;
1.1 root 1871: }
1.1.1.3 root 1872:
1.1.1.5 root 1873: void unlockscr (void)
1.1.1.3 root 1874: {
1875: }
1876:
1.1.1.5 root 1877: static void handle_mousegrab (void)
1.1.1.3 root 1878: {
1.1.1.5 root 1879: if (grabbed) {
1880: XUngrabPointer (display, CurrentTime);
1881: XUndefineCursor (display, mywin);
1882: grabbed = 0;
1883: } else if (! dgamode) {
1884: XGrabPointer (display, mywin, 1, 0, GrabModeAsync, GrabModeAsync,
1885: mywin, blankCursor, CurrentTime);
1886: oldx = current_width / 2;
1887: oldy = current_height / 2;
1888: XWarpPointer (display, None, mywin, 0, 0, 0, 0, oldx, oldy);
1889: grabbed = 1;
1890: }
1.1.1.3 root 1891: }
1.1.1.5 root 1892:
1893: static void handle_inhibit (void)
1.1.1.3 root 1894: {
1.1.1.6 root 1895: toggle_inhibit_frame (IHF_SCROLLLOCK);
1.1.1.5 root 1896: }
1897:
1.1.1.7 root 1898: #include "gensound.h"
1899: #include "sounddep/sound.h"
1900: #include "events.h"
1901: #include "audio.h"
1902:
1903: static void handle_interpol (void)
1904: {
1.1.1.8 root 1905: if (currprefs.sound_interpol == 0) {
1906: currprefs.sound_interpol = 1;
1907: printf ("Interpol on: rh\n");
1908: }
1909: else if (currprefs.sound_interpol == 1) {
1910: currprefs.sound_interpol = 2;
1911: printf ("Interpol on: crux\n");
1.1.1.7 root 1912: }
1.1.1.8 root 1913: else {
1914: currprefs.sound_interpol = 0;
1915: printf ("Interpol off\n");
1916: }
1.1.1.7 root 1917: }
1918:
1.1.1.5 root 1919: static void framerate_up (void)
1920: {
1.1.1.7 root 1921: if (currprefs.gfx_framerate < 20)
1922: changed_prefs.gfx_framerate = currprefs.gfx_framerate + 1;
1.1.1.5 root 1923: }
1924:
1925: static void framerate_down (void)
1926: {
1.1.1.7 root 1927: if (currprefs.gfx_framerate > 1)
1928: changed_prefs.gfx_framerate = currprefs.gfx_framerate - 1;
1.1.1.3 root 1929: }
1.1.1.6 root 1930:
1931: static void handle_modeswitch (void)
1932: {
1933: changed_prefs.gfx_afullscreen = changed_prefs.gfx_pfullscreen = !dgamode;
1934: }
1935:
1936: void target_save_options (FILE *f, struct uae_prefs *p)
1937: {
1938: fprintf (f, "x11.low_bandwidth=%s\n", p->x11_use_low_bandwidth ? "true" : "false");
1939: fprintf (f, "x11.use_mitshm=%s\n", p->x11_use_mitshm ? "true" : "false");
1940: fprintf (f, "x11.hide_cursor=%s\n", p->x11_hide_cursor ? "true" : "false");
1941: }
1942:
1943: int target_parse_option (struct uae_prefs *p, char *option, char *value)
1944: {
1945: return (cfgfile_yesno (option, value, "low_bandwidth", &p->x11_use_low_bandwidth)
1946: || cfgfile_yesno (option, value, "use_mitshm", &p->x11_use_mitshm)
1947: || cfgfile_yesno (option, value, "hide_cursor", &p->x11_hide_cursor));
1948: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.