#include #include #include /*#include */ /*#include */ #include #define DEPTH 8 #include #include #include #include #include #include #include #include #include #define CG3_MMAP_OFFSET 0x04000000 #include #include #include #include #include #include "dga/dga.h" #include "doomdef.h" static Display *display=0; static int screen; static int root; static Visual *vis ; static Window win; static Colormap cmap ; static sigset_t signalset; static int input_pending; static u_char * f_fb; static Dga_window clientp ; static int win_x, win_y, win_w, win_h; static int f_dpy_pitch; static int f_dpy_width; static int f_dpy_height; unsigned char *win_ptr; int framecount = 0; long long frametime; #define POINTER_WARP_COUNTDOWN 1 XEvent report; boolean grabMouse; int doPointerWarp = POINTER_WARP_COUNTDOWN; static int multiply=1; unsigned exptable2[256]; unsigned exptable3[256]; // long long exptable8[256]; int showkeysym=0; static void blocksigio(void) { if(sigprocmask(SIG_BLOCK, & signalset, NULL) < 0) perror("sigprocmask"); } static void unblocksigio(void) { if(sigprocmask(SIG_UNBLOCK, & signalset, NULL) < 0) perror("sigprocmask"); } static void gotio(void) { // fprintf(stderr, "got SIGPOLL\n"); input_pending = 1; } int xlatekey(void) { int rc; rc = XKeycodeToKeysym(display, report.xkey.keycode, 0); if (showkeysym) printf("k=[%d] \r", rc); switch(rc) { case XK_Left: rc = KEY_LEFTARROW; break; case XK_Right: rc = KEY_RIGHTARROW; break; case XK_Down: rc = KEY_DOWNARROW; break; case XK_Up: rc = KEY_UPARROW; break; case XK_Escape: rc = KEY_ESCAPE; break; case XK_Return: rc = KEY_ENTER; break; case XK_Tab: rc = KEY_TAB; break; case XK_F1: rc = KEY_F1; break; case XK_F2: rc = KEY_F2; break; case XK_F3: rc = KEY_F3; break; case XK_F4: rc = KEY_F4; break; case XK_F5: rc = KEY_F5; break; case XK_F6: rc = KEY_F6; break; case XK_F7: rc = KEY_F7; break; case XK_F8: rc = KEY_F8; break; case XK_F9: rc = KEY_F9; break; case XK_F10: rc = KEY_F10; break; case XK_F11: rc = KEY_F11; break; case XK_F12: rc = KEY_F12; break; case XK_BackSpace: case XK_Delete: rc = KEY_BACKSPACE; break; case XK_Pause: rc = KEY_PAUSE; break; case XK_KP_Equal: case XK_equal: rc = KEY_EQUALS; break; case XK_KP_Subtract: case XK_minus: rc = KEY_MINUS; break; case XK_Shift_L: case XK_Shift_R: rc = KEY_RSHIFT; break; case XK_Control_L: case 65512: case 65312: case 65406: case XK_Control_R: rc = KEY_RCTRL; break; case XK_Alt_L: case XK_Meta_L: // case XK_Alt_R: // case XK_Meta_R: rc = KEY_RALT; break; case 268828432: rc = KEY_F11; break; case 268828433: rc = KEY_F12; break; default: if (rc >= XK_space && rc <= XK_asciitilde) rc = rc - XK_space + ' '; if (rc >= 'A' && rc <= 'Z') rc = rc - 'A' + 'a'; break; } return rc; } void I_ShutdownGraphics(void) { dga_win_ungrab(clientp, 1) ; XDgaUnGrabWindow(display, win) ; XCloseDisplay(display); } /* ================ = = I_Error = ================ */ extern boolean demorecording; void I_Error (char *error, ...) { va_list argptr; char string[1024]; if (demorecording) G_CheckDemoStatus(); D_QuitNetGame (); I_ShutdownGraphics(); va_start (argptr,error); fprintf (stderr, "Error: "); vfprintf (stderr,error,argptr); fprintf (stderr, "\n"); va_end (argptr); exit(-1); } /* ==================== = = I_StartFrame = ==================== */ void I_StartFrame (void) { } static int lastmousex = 0; static int lastmousey = 0; boolean mousemoved = false; boolean shmFinished; void I_GetEvent(void) { event_t event; XNextEvent(display, &report); switch (report.type) { case KeyPress: event.type = ev_keydown; event.data1 = xlatekey(); D_PostEvent(&event); break; case KeyRelease: event.type = ev_keyup; event.data1 = xlatekey(); D_PostEvent(&event); break; case ButtonPress: event.type = ev_mouse; event.data1 = (report.xbutton.state & Button1Mask) | (report.xbutton.state & Button2Mask ? 2 : 0) | (report.xbutton.state & Button3Mask ? 4 : 0) | (report.xbutton.button == Button1) | (report.xbutton.button == Button2 ? 2 : 0) | (report.xbutton.button == Button3 ? 4 : 0); event.data2 = event.data3 = 0; D_PostEvent(&event); break; case ButtonRelease: event.type = ev_mouse; event.data1 = (report.xbutton.state & Button1Mask) | (report.xbutton.state & Button2Mask ? 2 : 0) | (report.xbutton.state & Button3Mask ? 4 : 0) ^ (report.xbutton.button == Button1 ? 1 : 0) ^ (report.xbutton.button == Button2 ? 2 : 0) ^ (report.xbutton.button == Button3 ? 4 : 0); event.data2 = event.data3 = 0; D_PostEvent(&event); break; case MotionNotify: event.type = ev_mouse; event.data1 = (report.xmotion.state & Button1Mask) | (report.xmotion.state & Button2Mask ? 2 : 0) | (report.xmotion.state & Button3Mask ? 4 : 0); event.data2 = (report.xmotion.x - lastmousex) << 2; event.data3 = (lastmousey - report.xmotion.y) << 2; if (event.data2 || event.data3) { lastmousex = report.xmotion.x; lastmousey = report.xmotion.y; if (report.xmotion.x != win_w/2 && report.xmotion.y != win_h/2) { D_PostEvent(&event); mousemoved = false; } else { mousemoved = true; } } break; case Expose: case ConfigureNotify: break; default: break; } } /* ==================== = = I_StartTic = ==================== */ void I_StartTic (void) { if (!display) return; if(input_pending) { blocksigio(); while( XEventsQueued(display, QueuedAfterFlush)) I_GetEvent(); input_pending = 0; unblocksigio(); } if (grabMouse) { if (!--doPointerWarp) { XWarpPointer( display, None, win, 0, 0, 0, 0, win_w/2, win_h/2); doPointerWarp = POINTER_WARP_COUNTDOWN; } } mousemoved = false; } /* ==================== = = I_UpdateNoBlit = ==================== */ void I_UpdateNoBlit (void) { } void dgarender(void) { static int lasttic; int tics, i; static unsigned char *bigscreen=0; int incamt; long long *olineptrs[4]; unsigned int *ilineptr; int x, y; incamt = (multiply*f_dpy_pitch - win_w) / 8; ilineptr = (unsigned int *) (screens[0]); for (i=0 ; i 20) tics = 20; for (i=0 ; i