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