- char name[MAXNAME+2];
-#if 0
- void *dummyptr;
- int dummyint;
-#endif
- int i;
-
-#if 0
- display = XOpenDisplay(arg_display);
- if (display == 0)
- {
- fprintf(stderr, "%s: \"%s\": %s: %s\n", progname,
- XDisplayName(arg_display), "failed to open display",
- strerror(errno));
- return(1);
- }
-#endif
-
- defaultScreen = DefaultScreenOfDisplay(display);
- defaultVisual = DefaultVisualOfScreen(defaultScreen);
- defaultColourmap = DefaultColormapOfScreen(defaultScreen);
- defaultRootWindow = RootWindowOfScreen(defaultScreen);
- screenDepth = DefaultDepthOfScreen(defaultScreen);
- screenWidth = WidthOfScreen(defaultScreen);
- screenHeight = HeightOfScreen(defaultScreen);
- screenBlackPixel = BlackPixelOfScreen(defaultScreen);
- screenWhitePixel = WhitePixelOfScreen(defaultScreen);
-
-#if 0
- if (arg_install)
- {
- visualInfo.visualid = XVisualIDFromVisual(defaultVisual);
- dummyptr = XGetVisualInfo(display, VisualIDMask, &visualInfo, &dummyint);
- if (dummyptr == 0)
- {
- fprintf(stderr, "%s: \"%s\": %s: %s\n", progname,
- XDisplayName(arg_display), "failed to get visual info",
- strerror(errno));
- return(1);
- }
-
- memcpy(&visualInfo, dummyptr, sizeof(visualInfo));
- XFree(dummyptr);
-
- if (visualInfo.class != PseudoColor)
- {
- fprintf(stderr, "%s: \"%s\": %s\n", progname, XDisplayName(arg_display),
- "private colourmap only supported for pseudocolour display");
- return(1);
- }
-
- privateColourmap = XCreateColormap(display, defaultRootWindow,
- defaultVisual, AllocAll);
- if (privateColourmap == 0)
- {
- fprintf(stderr, "%s: \"%s\": %s: %s\n", progname,
- XDisplayName(arg_display), "failed to create colourmap",
- strerror(errno));
- return(1);
- }
-
- privateNumColours = visualInfo.colormap_size;
-
- privateColours = malloc(privateNumColours * sizeof(XColor));
- if (privateColours == 0)
- {
- fprintf(stderr, "%s: %s (%d): %s\n", progname, "malloc failed",
- privateNumColours * sizeof(XColor), strerror(errno));
- return(1);
- }
-
- for (dummyint = 0; dummyint < privateNumColours; dummyint++)
- privateColours[dummyint].pixel = dummyint;
-
- XQueryColors(display, defaultColourmap, privateColours, privateNumColours);
- XStoreColors(display, privateColourmap, privateColours, privateNumColours);
-
- privateFlags = malloc(privateNumColours);
- if (privateFlags == 0)
- {
- fprintf(stderr, "%s: %s (%d): %s\n", progname, "malloc failed",
- privateNumColours, strerror(errno));
- return(1);
- }
-
- memset(privateFlags, 0, privateNumColours);
-
- /* first two entries (black and white) are already allocated */
- privateFlags[0] = 1;
- privateFlags[1] = 1;
- }
-
- sizeHints.flags = PSize | PMinSize | PMaxSize;
- sizeHints.width = 20 * TILEX;
- sizeHints.height = 12 * TILEY + SCOREY;
- sizeHints.min_width = sizeHints.max_width = sizeHints.width;
- sizeHints.min_height = sizeHints.max_height = sizeHints.height;
-
- if (arg_geometry)
- {
- dummyint = XWMGeometry(display, XScreenNumberOfScreen(defaultScreen),
- arg_geometry, 0, 2, &sizeHints, &sizeHints.x,
- &sizeHints.y, &dummyint, &dummyint,
- &sizeHints.win_gravity);
- if (dummyint & (XValue | YValue))
- sizeHints.flags |= USPosition | PWinGravity;
- }
-
- xwindow = XCreateWindow(display, defaultRootWindow, sizeHints.x, sizeHints.y,
- sizeHints.width, sizeHints.height, 2, screenDepth,
- InputOutput, CopyFromParent, 0, 0);
- if (xwindow == 0)
- {
- fprintf(stderr, "%s: \"%s\": %s: %s\n", progname,
- XDisplayName(arg_display), "failed to open window",
- strerror(errno));
- return(1);
- }
-
- setWindowAttributes.background_pixel = screenBlackPixel;
- setWindowAttributes.border_pixel = screenWhitePixel;
- setWindowAttributes.backing_store = NotUseful;
- setWindowAttributes.override_redirect = False;
- setWindowAttributes.event_mask =
- KeyPressMask | EnterWindowMask | LeaveWindowMask | ExposureMask;
- setWindowAttributes.colormap =
- privateColourmap ? privateColourmap : defaultColourmap;
- XChangeWindowAttributes(display, xwindow,
- CWBackPixel | CWBorderPixel | CWBackingStore |
- CWOverrideRedirect | CWEventMask | CWColormap,
- &setWindowAttributes);
-
- XStoreName(display, xwindow, "Emerald Mine");
-
- wmHints.flags = InputHint | StateHint;
- wmHints.input = True;
- wmHints.initial_state = NormalState;
- XSetWMHints(display, xwindow, &wmHints);
-
- XSetWMNormalHints(display, xwindow, &sizeHints);
-
- deleteAtom = XInternAtom(display, "WM_DELETE_WINDOW", False);
- XSetWMProtocols(display, xwindow, &deleteAtom, 1);
-
- cursor = XCreateFontCursor(display, XC_trek);
- if (cursor) XDefineCursor(display, xwindow, cursor);
-
- XMapWindow(display, xwindow);
-#endif
-
-#if 0
- for (i = 0; i < 4; i++)
- {
- name[MAXNAME] = 0;
- if (arg_basedir)
- {
- snprintf(name, MAXNAME+2, "%s/%s/%s", arg_basedir, EM_GFX_DIR,
- xpmNames[i]);
- }
- else
- {
- snprintf(name, MAXNAME+2, "%s/%s", EM_GFX_DIR, xpmNames[i]);
- }
-
- if (name[MAXNAME]) snprintf_overflow("read graphics/ files");
-
- xpmAttributes[i].valuemask =
- XpmColormap | XpmReturnAllocPixels | XpmExactColors | XpmCloseness |
- XpmAllocColor | XpmFreeColors;
- xpmAttributes[i].colormap =
- privateColourmap ? privateColourmap : defaultColourmap;
- xpmAttributes[i].exactColors = False;
- xpmAttributes[i].closeness = xpmCloseness[i];
- xpmAttributes[i].alloc_color = xpmAllocColourFunc;
- xpmAttributes[i].free_colors = xpmFreeColoursFunc;
- dummyint = XpmReadFileToPixmap(display, xwindow, name, &xpmPixmaps[i],
- &xpmBitmaps[i], &xpmAttributes[i]);
- if (dummyint)
- {
- fprintf(stderr, "%s: \"%s\": \"%s\": %s: %s: %s\n", progname,
- XDisplayName(arg_display), name, "failed to read xpm",
- XpmGetErrorString(dummyint), strerror(errno));
- return(1);
- }
-
- xpmGot[i] = 1;
- }
-#endif
-
- for (i = 0; i < 4; i++)
- {
- name[MAXNAME] = 0;
- snprintf(name, MAXNAME+2, "%s/%s", EM_GFX_DIR, pcxNames[i]);
-
- if (name[MAXNAME])
- snprintf_overflow("read graphics/ files");
-
- if ((pcxBitmaps[i] = LoadImage(name)) == NULL)
- {
- printf("::: LoadImage() failed for file '%s'\n", name);
- return 1;
- }
- }
-
- objBitmap = pcxBitmaps[0];
- botBitmap = pcxBitmaps[1];
- sprBitmap = pcxBitmaps[2];
- ttlBitmap = pcxBitmaps[3];
-
-#if 0
- objPixmap = xpmPixmaps[0];
- botPixmap = xpmPixmaps[1];
- sprPixmap = xpmPixmaps[2];
- ttlPixmap = xpmPixmaps[3];
- objmaskBitmap = xpmBitmaps[0];
- botmaskBitmap = xpmBitmaps[1];
- sprmaskBitmap = xpmBitmaps[2];
- ttlmaskBitmap = xpmBitmaps[3];
-#else
- objPixmap = pcxBitmaps[0]->drawable;
- botPixmap = pcxBitmaps[1]->drawable;
- sprPixmap = pcxBitmaps[2]->drawable;
- ttlPixmap = pcxBitmaps[3]->drawable;
- objmaskBitmap = pcxBitmaps[0]->clip_mask;
- botmaskBitmap = pcxBitmaps[1]->clip_mask;
- sprmaskBitmap = pcxBitmaps[2]->clip_mask;
- ttlmaskBitmap = pcxBitmaps[3]->clip_mask;
-#endif
-
-#if 1
- for (i = 0; i < 4; i++)
- {
- Pixmap clip_mask;
-
- if ((clip_mask = XCreatePixmap(display, window->drawable,
- pcxBitmaps[i]->width * 2,
- pcxBitmaps[i]->height * 2, 1))
- == None)
- {
- printf("::: cannot create clip mask");
- return 1;
- }
-
-#if 0
- {
- XGCValues clip_gc_values;
- unsigned long clip_gc_valuemask;
- GC gc;
-
- clip_gc_values.graphics_exposures = False;
- clip_gc_valuemask = GCGraphicsExposures;
- if ((gc = XCreateGC(display, clip_mask,
- clip_gc_valuemask, &clip_gc_values)) == None)
- {
- printf("X CreateGC failed\n");
- exit(1);
- }
-
- XFillRectangle(display, clip_mask, gc, 0, 0,
- pcxBitmaps[i]->width * 2,
- pcxBitmaps[i]->height * 2);
- }
-#endif
-
-#if 0
- {
- byte * src_ptr;
- int src_width = pcxBitmaps[i]->width;
- int src_height = pcxBitmaps[i]->height;
-
-#if 0
- printf("::: %d, %d [%ld -> %ld (%ld)]\n",
- src_width, src_height,
- src_ptr,
- src_ptr + src_width * src_height * 1,
- src_width * src_height * 1);
-#endif
-
-#if 0
- for (i = src_ptr; i < src_ptr + src_width * src_height * 1; i++)
- {
- byte x = *(byte *)i;
-
- x = x * 1;
- }
-#endif
- }
-#endif
-
- if (ZOOM_FACTOR > 1)
- pcxBitmapsX2[i] = ZoomBitmap(pcxBitmaps[i],
- pcxBitmaps[i]->width * ZOOM_FACTOR,
- pcxBitmaps[i]->height * ZOOM_FACTOR);
- else
- pcxBitmapsX2[i] = pcxBitmaps[i];
-
-#if 1
-
-#if 0
- printf("::: CREATING NEW CLIPMASKS ...\n");
-#endif
-#if 1
- clip_mask = Pixmap_to_Mask(pcxBitmapsX2[i]->drawable,
- pcxBitmapsX2[i]->width,
- pcxBitmapsX2[i]->height);
-#endif
-#if 0
- printf("::: CREATING NEW CLIPMASKS DONE\n");
-#endif
-
- pcxBitmapsX2[i]->clip_mask = clip_mask;
-
- /* add clip mask GC */
- {
- XGCValues clip_gc_values;
- unsigned long clip_gc_valuemask;
-
- clip_gc_values.graphics_exposures = False;
- clip_gc_values.clip_mask = pcxBitmapsX2[i]->clip_mask;
- clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
- pcxBitmapsX2[i]->stored_clip_gc = XCreateGC(display,
- window->drawable,
- clip_gc_valuemask,
- &clip_gc_values);
- }
-
-#if 0
- printf("::: %ld, %ld, %ld, %ld, %ld, %ld, %ld\n",
- pcxBitmaps[i]->gc,
- pcxBitmaps[i]->clip_mask, pcxBitmapsX2[i]->clip_mask,
- pcxBitmaps[i]->width, pcxBitmaps[i]->height,
- pcxBitmapsX2[i]->width, pcxBitmapsX2[i]->height);
-#endif
-
-#if 0
- ZoomPixmap(display, pcxBitmaps[i]->gc,
- pcxBitmaps[i]->clip_mask, pcxBitmapsX2[i]->clip_mask,
- pcxBitmaps[i]->width, pcxBitmaps[i]->height,
- pcxBitmapsX2[i]->width, pcxBitmapsX2[i]->height);
-#endif
-
-#endif
- }
-
- objBitmap = pcxBitmapsX2[0];
- botBitmap = pcxBitmapsX2[1];
- sprBitmap = pcxBitmapsX2[2];
- ttlBitmap = pcxBitmapsX2[3];
-
- objPixmap = pcxBitmapsX2[0]->drawable;
- botPixmap = pcxBitmapsX2[1]->drawable;
- sprPixmap = pcxBitmapsX2[2]->drawable;
- ttlPixmap = pcxBitmapsX2[3]->drawable;
-#if 1
- objmaskBitmap = pcxBitmapsX2[0]->clip_mask;
- botmaskBitmap = pcxBitmapsX2[1]->clip_mask;
- sprmaskBitmap = pcxBitmapsX2[2]->clip_mask;
- ttlmaskBitmap = pcxBitmapsX2[3]->clip_mask;
-#endif
-#endif
-
-#if 1
- screenBitmap = CreateBitmap(22 * TILEX, 14 * TILEY, DEFAULT_DEPTH);
- scoreBitmap = CreateBitmap(20 * TILEX, SCOREY, DEFAULT_DEPTH);
-#endif
-
- screenPixmap = XCreatePixmap(display, xwindow, 22 * TILEX, 14 * TILEY,
- screenDepth);
- if (screenPixmap == 0)
- {
- fprintf(stderr, "%s: \"%s\": %s: %s\n", progname,
- XDisplayName(arg_display), "failed to create pixmap",
- strerror(errno));
- return(1);
- }
-
- scorePixmap = XCreatePixmap(display, xwindow, 20 * TILEX, SCOREY,
- screenDepth);
- if (scorePixmap == 0)
- {
- fprintf(stderr, "%s: \"%s\": %s: %s\n", progname,
- XDisplayName(arg_display), "failed to create pixmap",
- strerror(errno));
- return(1);
- }
-
-#if 1
- screenBitmap->drawable = screenPixmap;
- scoreBitmap->drawable = scorePixmap;
-#endif
-
- spriteBitmap = XCreatePixmap(display, xwindow, TILEX, TILEY, 1);
- if (spriteBitmap == 0)
- {
- fprintf(stderr, "%s: \"%s\": %s: %s\n", progname,
- XDisplayName(arg_display), "failed to create pixmap",
- strerror(errno));
- return(1);
- }
-
- redColour.pixel = screenWhitePixel;
- whiteColour.pixel = screenBlackPixel;
- gotRed = (xpmAllocColourFunc(display, privateColourmap ? privateColourmap :
- defaultColourmap,
- "red", &redColour, 0) > 0);
- gotWhite = (xpmAllocColourFunc(display, privateColourmap ? privateColourmap :
- defaultColourmap,
- "white", &whiteColour, 0) > 0);
-
- gcValues.graphics_exposures = False;
- screenGC = XCreateGC(display, screenPixmap, GCGraphicsExposures, &gcValues);
- if (screenGC == 0)
- {
- fprintf(stderr, "%s: \"%s\": %s: %s\n", progname,
- XDisplayName(arg_display), "failed to create graphics context",
- strerror(errno));
- return(1);
- }
-
- gcValues.graphics_exposures = False;
- scoreGC = XCreateGC(display, scorePixmap, GCGraphicsExposures, &gcValues);
- if (scoreGC == 0)
- {
- fprintf(stderr, "%s: \"%s\": %s: %s\n", progname,
- XDisplayName(arg_display), "failed to create graphics context",
- strerror(errno));
- return(1);
- }
-
- gcValues.function =
- objmaskBitmap ? GXcopyInverted : sprmaskBitmap ? GXcopy : GXset;
- gcValues.graphics_exposures = False;
- spriteGC = XCreateGC(display, spriteBitmap, GCFunction | GCGraphicsExposures,
- &gcValues);
- if (spriteGC == 0)
- {
- fprintf(stderr, "%s: \"%s\": %s: %s\n", progname,
- XDisplayName(arg_display), "failed to create graphics context",
- strerror(errno));
- return(1);
- }
-
- gcValues.foreground = redColour.pixel;
- gcValues.background = whiteColour.pixel;
- gcValues.line_style = LineDoubleDash;
- gcValues.graphics_exposures = False;
- antsGC = XCreateGC(display, screenPixmap,
- GCForeground | GCBackground | GCLineStyle |
- GCGraphicsExposures,
- &gcValues);
- if (antsGC == 0)
- {
- fprintf(stderr, "%s: \"%s\": %s: %s\n", progname,
- XDisplayName(arg_display), "failed to create graphics context",
- strerror(errno));
- return(1);
- }
-
- for (i = 0; i < 16; i++)
- keycodes[i] = XKeysymToKeycode(display, keysyms[i]);
-
- for (i = 0; i < 3; i++)
- northKeyCode[i] = keycodes[i + 0];
- for (i = 0; i < 3; i++)
- eastKeyCode[i] = keycodes[i + 3];
- for (i = 0; i < 3; i++)
- southKeyCode[i] = keycodes[i + 6];
- for (i = 0; i < 3; i++)
- westKeyCode[i] = keycodes[i + 9];
- for (i = 0; i < 3; i++)
- fireKeyCode[i] = keycodes[i + 12];
- for (i = 0; i < 1; i++)
- escKeyCode[i] = keycodes[i + 15];
-
- /* ----------------------------------------------------------------- */
-
-#if 0
- {
- Bitmap *bm = pcxBitmaps[2];
- Pixmap clip_mask = bm->clip_mask;
-
- if (clip_mask)
- {
-#if 1
- int width = bm->width;
- int height = bm->height;
-#else
- int width = 16 * 4;
- int height = 16 * 4;
-#endif
- XImage *src_ximage = XGetImage(display, clip_mask, 0, 0,
- width, height, AllPlanes, ZPixmap);
- XImage *dst_ximage = XGetImage(display, xwindow, 0, 0,
- width, height, AllPlanes, ZPixmap);
- int x, y;
-
- if (src_ximage == NULL)
- {
- printf("src_ximage failed\n");
- exit(1);
- }