⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 display.c

📁 树大根深三棱尽所标杆ssfsfsa fdsafs
💻 C
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************			       XCopilotThis code is part of XCopilot, a port of copilot     Portions of this code are Copyright (C) 1997 Ivan A. Curtis		       icurtis@radlogic.com.auThe original MS-Windows95 copilot emulator was written by Greg Hewgill.The following copyright notice appeared on the original copilot sources:		  Copyright (c) 1996 Greg HewgillSome of the code in this file was derived from code in whichthe following copyright notice appeared:		     XWindow Support for QuickCam		   by Paul Chinn <loomer@svpal.org>	      Modified by Scott Laird <scott@laird.com> 	 I took a bunch of this code from the source for VGB	  "Virtual GameBoy" emulator by Marat Fayzullin and			    Elan Feingold MC68000 Emulation code is from Bernd Schmidt's Unix Amiga Emulator.       The following copyright notice appeared in those files:	  Original UAE code Copyright (c) 1995 Bernd SchmidtThis code must not be distributed without these copyright notices intact.**************************************************************************************************************************************************************Filename:	display.cDescription:	Display module for xcopilot emulatorUpdate History:   (most recent first)   Gene McCulley   7-May-98 19:13 -- reworked main loop, added calibration   Gene McCulley   6-May-98 15:25 -- Changed pixel doubling to MagFactor                                     Dirty rectangle drawing                                     Bug fix for 2-bit, doubled, 16 bpp mode   Ian Goldberg    4-Sep-97 13:29 -- bug fixes for screen updates   Eric Howe       3-Sep-97 15:09 -- trap window closure from window manager   C. Chan-Nui    18-Jul-97 10:23 -- lazy screen updates   Brian Grossman 15-Jul-97 21:40 -- fixed pixeldoubling colors   Brandon Long   15-Jul-97 15:27 -- fixed byte-order display problems   Chris Bare     10-Jul-97 11:18 -- shaped screen, better bg colour   Brian Grossman 30-Jun-97 24:00 -- added pixeldoubling   Ian Goldberg   20-Jun-97 14:09 -- added support for greyscale and panning   Ian Goldberg   10-Apr-97 16:53 -- changed beeps into true amp/freq/dur sound   I. Curtis       9-Apr-97 11:43 -- 16bpp and keboard events courtesy of   	Andrew Pfiffer <andyp@co.intel.com>    I. Curtis       5-Mar-97 20:33 -- added key event processing code   I. Curtis      25-Feb-97 20:17 -- major tidy up   I. Curtis      23-Feb-97 21:17 -- Created.******************************************************************************/#include <config.h>#include <bittypes.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <signal.h>#include <unistd.h>#include <sys/time.h>#include <sys/ipc.h>#include <sys/shm.h>#include "display.h"#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/keysym.h>#include <X11/xpm.h>#include <X11/StringDefs.h>#include <X11/IntrinsicP.h>#include <X11/Shell.h>#ifdef USE_XSHM#include <X11/extensions/XShm.h> /* MIT Shared Memory Extensions */#endif#include <X11/extensions/shape.h>#include "cmap_mgr.h"#include "sysdeps.h"#include "shared.h"#include "dragonball.h"#include "case.xpm"#include "libmx.h"/***************************************************************************** *                                                                           * * 			   Global Variables                                  * *                                                                           * *****************************************************************************/#ifdef USE_XSHMXShmSegmentInfo xcpSHMInfo;	/* info about shm pixmap (if using shm) */#endifstatic int xcpUsingShm = 0;		/* set True if we are using MIT shm ext. */static int xcpStarted = 0;		/* set True once XCPilot is started */static int xcpQuit = 0;		/* set True if XCopilot must quit */static Display *xcpDisplay;		/* X Display connection */static Screen *xcpScreen;		/* X screen */static int xcpScreenNum;		/* screen number */static Window xcpLCDWindow;		/* window for Copilot LCD image */static Window xcpCaseWindow;		/* window for case */static XImage *xcpLCDImage;		/* XImage of LCD screen */static GC xcpLCDgc;			/* GC for rendering LCD XImage */static XColor xcpGreys[14];		/* Greyscales for LCD */static int xcpDepth;			/* Pixel depth of XImage */static int MagFactor = 1;       /* pixel magnification factor */static int (*oldErrorfunc)();static int hitError;static Atom xcpDeleteWindow;static shared_img *shared;static char *new_sbuf;static int screen_size = 0;static int buffer_size;extern int dbg_loadapp(FILE *out, FILE *in, char *cmd, char *line,		       shared_img *shptr);#define xcpOffPixel (xcpGreys[0].pixel)#define xcpOnPixel (xcpGreys[6].pixel)/************************************* * Menu Items                        * *                                   * * These structures hold the entries * * for menus                         * *************************************/mx_menu_item main_items[] = {  {MXItemFlag_Center, "XCopilot", 0},  {MXItemFlag_Left, "Load database...", 0},  {MXItemFlag_Left, "Load file...", 0},  {MXItemFlag_Left, "About...", 0},  {MXItemFlag_Left | MXItemFlag_Disabled, " ", 0},  {MXItemFlag_Left, "Quit", 0},};mx_menu_item about_items[] = {  {MXItemFlag_Center, NULL, 0},  {MXItemFlag_Left | MXItemFlag_Disabled, " ", 0},  {MXItemFlag_Center, "Unix/X Port by Ivan A. Curtis", 0},  {MXItemFlag_Left | MXItemFlag_Disabled, " ", 0},  {MXItemFlag_Center, "bugs fixed and features added by:", 0},  {MXItemFlag_Center, "Ian Goldberg", 0},  {MXItemFlag_Center, "Brian Grossman", 0},  {MXItemFlag_Center, "Chris Bare", 0},  {MXItemFlag_Center, "Brandon Long", 0},  {MXItemFlag_Center, "C. Chan-Nui", 0},  {MXItemFlag_Center, "Eric Howe", 0},  {MXItemFlag_Center, "Gene McCulley", 0},  {MXItemFlag_Center, "Jon Abbott", 0},  {MXItemFlag_Center, "Bill Janssen", 0},  {MXItemFlag_Center, "Felix Croes", 0},  {MXItemFlag_Center, "Max Okumoto", 0},  {MXItemFlag_Center, "Anders Hammarquist", 0},  {MXItemFlag_Left | MXItemFlag_Disabled, " ", 0},  {MXItemFlag_Center, "Copilot by Greg Hewgill", 0},  {MXItemFlag_Left | MXItemFlag_Disabled, " ", 0},};mx_menu_item appok_items[] = {  {MXItemFlag_Center, "XCopilot", 0},  {MXItemFlag_Left | MXItemFlag_Disabled, " ", 0},  {MXItemFlag_Center, "  App Loaded  ", 0},  {MXItemFlag_Left | MXItemFlag_Disabled, " ", 0},};mx_menu_item appfail_items[] = {  {MXItemFlag_Center, "XCopilot", 0},  {MXItemFlag_Left | MXItemFlag_Disabled, " ", 0},  {MXItemFlag_Center, "  Load App Failed  ", 0},  {MXItemFlag_Left | MXItemFlag_Disabled, " ", 0},};mx_menu_item ok_items[] = {  {MXItemFlag_Center, "OK", 0},};#include "icon2.xpm"static void set_icon(Widget w){  Pixmap pixmap, mask;  XpmAttributes attributes;  Arg args[2];  bzero((void*)&attributes, sizeof(attributes));  if(XpmCreatePixmapFromData(XtDisplay(w), DefaultRootWindow(XtDisplay(w)),                             pilot_xpm, &pixmap, &mask, &attributes))    return;                 XtSetArg(args[0], XtNiconPixmap, pixmap);  XtSetArg(args[1], XtNiconMask, mask);  XtSetValues(w, args, 2);}/*************************************** * This is a signal handler. It simply * * sets xcpQuit True, which causes the * * event loop to terminate             * ***************************************/static void xcpSignalQuit(int unused){  xcpQuit = 1;} /******************************************************** * Check if the X Shared Memory extension is available. * * Return:  0 = not available                           * *   1 = shared XImage support available                * *   2 = shared Pixmap support available also           * ********************************************************/static int xcpCheckXshm(Display *display){  int major, minor, ignore;  int pixmaps;#ifdef USE_XSHM  if (XQueryExtension(display, "MIT-SHM", &ignore, &ignore, &ignore)) {    if (XShmQueryVersion(display, &major, &minor, &pixmaps) == True) {      return (pixmaps == True) ? 2 : 1;    } else {      return 0;    }  } else {    return 0;  }#else  return 0;#endif}/************************************************ * Initialize xwindows, and prepare a shared    * * memory buffer for the LCD image. width and   * * height are the dimensions of the LCD screen. * * Returns a pointer to shared memory buffer    * * or regular ximage buffer.                    * ************************************************/#define CASEWIDTH 220#define CASEHEIGHT 337#define LCDWIDTH 160#define LCDHEIGHT 160int casewidth = CASEWIDTH,    caseheight = CASEHEIGHT,    lcdwidth = LCDWIDTH,    lcdheight = LCDHEIGHT ;static mx_appearance *app;    /* appearance structure form menu *//* panels for menus */static mx_panel *panel_main, *panel_about, *panel_ok;static mx_panel *panel_appok, *panel_appfail;/*************************************** * Put the LCD image on the LCD window * ***************************************/static void xcpPutImage(int x, int y, int width, int height) {#ifdef USE_XSHM  if (xcpUsingShm)    XShmPutImage(xcpDisplay, xcpLCDWindow, xcpLCDgc, xcpLCDImage, x, y, x, y, 		 width, height, False);  else#endif    XPutImage(xcpDisplay, xcpLCDWindow, xcpLCDgc, xcpLCDImage, x, y, x, y,	      width, height);}static int xcpHandleExpose(XEvent *event) {  xcpPutImage(event->xexpose.x, event->xexpose.y, event->xexpose.width,              event->xexpose.height);  return event->xexpose.count;}static void HandleExpose(Widget w, XtPointer client_data, XEvent *event,                         Boolean *continue_to_dispatch){  *continue_to_dispatch = True;  xcpHandleExpose(event);}/********************************* * Release allocated X resources * * in preparation for exit       * *********************************/static void xcpCleanup(void){  shared->CpuReq = cpuExit;  if (xcpStarted) {    if (xcpLCDImage) {      XDestroyImage(xcpLCDImage);    }#ifdef USE_XSHM    if (xcpUsingShm) {      XShmDetach(xcpDisplay, &xcpSHMInfo);      if (xcpSHMInfo.shmaddr) {	shmdt(xcpSHMInfo.shmaddr);      }      if (xcpSHMInfo.shmid > 0) {	shmctl(xcpSHMInfo.shmid, IPC_RMID, 0);      }    }#endif  }  exit(0);}static void do_menu(int x, int y){  int choice;  choice = mx_popup_menu(xcpDisplay, xcpScreenNum, panel_main, &x, &y, True);  switch (choice) {    char *appname;    int rx, ry;    case 1:            /* Load App.. */    case 2:      rx = x;      ry = y;      appname = mx_popup_filesel(xcpDisplay, xcpScreenNum, app, &rx, &ry,                                 choice - 1);      if (appname != NULL)        if (dbg_loadapp(NULL, NULL, NULL, appname, shared) == 0)          mx_popup_alert(xcpDisplay, xcpScreenNum, panel_appok, panel_ok, &x,                         &y);        else          mx_popup_alert(xcpDisplay, xcpScreenNum, panel_appfail, panel_ok,                         &x, &y);      break;    case 3:             /* About.. */      mx_popup_alert(xcpDisplay, xcpScreenNum, panel_about, panel_ok, &x, &y);      break;    case 5:             /* Quit */      xcpCleanup();      break;    default:      break;  }}/************************************************************ * Handle a key event                                       * * img is a pointer to the shared memory structure which    * * holds the custom registers which are shared between the  * * CPU and Display processes. down is 1 if the key is down, * * key is the number of the key                             * ************************************************************/static void xcpKeyEvent(int down, int key){  shared->keydown = down;  shared->key = key;  shared->run_updateisr = 1;}typedef struct _Key {  const char *name;  XRectangle bounds;} Key;static Key keys[] = {{"power", {0, 281, 16, 22}},                     {"up", {100, 280, 25, 12}},                     {"down", {100, 302, 25, 12}},                     {"datebook", {24, 277, 28, 29}},                     {"phone", {63, 277, 28, 29}},                     {"todo", {134, 277, 28, 29}},

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -