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

📄 main.c

📁 树大根深三棱尽所标杆ssfsfsa fdsafs
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************			       XCopilotThis code is part of XCopilot, a port of copilot		  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 Hewgill 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:	main.cDescription:	main file for xcopilot emulatorUpdate History:   (most recent first)   Ian Goldberg   26-Jun-98 12:37 -- Made memversion command-line option                                     and XCOPILOTMEMVERSION env. var.   Gene McCulley  30-Apr-98 07:02 -- Made ramsize command-line option   Gene McCulley  28-Apr-98 16:23 -- Added ~/.xcopilot support   Ian Goldberg   25-Sep-97 11:09 -- rewrite of serial and gdb support   Ian Goldberg   11-Sep-97 09:48 -- added bus error support   Jeff Dionne    10-Jul-97 10:00 -- added support for gdb debugging via TCP   Ian Goldberg   06-Jul-97 17:34 -- added support for serial I/O via a pty   Brian Grossman 30-Jun-97 24:00 -- added pixeldoubling   Ian Goldberg   18-Apr-97 11:13 -- added support for gdb debugging via a pty   I. Curtis       9-Apr-97 11:42 -- v0.4   I. Curtis      18-Mar-97 14:00 -- v0.3   I. Curtis      26-Feb-97 13:52 -- first release   I. Curtis      23-Feb-97 20:43 -- Created.******************************************************************************/#include <config.h>#include <sys/time.h>#include <sys/stat.h>#include <sys/types.h>#include <pwd.h>#include <sys/wait.h>#include <termios.h>#ifdef HAVE_SYS_SELECT_H#include <sys/select.h>#endif#include <unistd.h>#include <sys/ipc.h>#include <sys/shm.h>#include <sys/stat.h>#include <fcntl.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>#include "config.h"#include "sysdeps.h"#include "shared.h"#include "memory.h"#include "custom.h"#include "newcpu.h"#include "display.h"#include "pilotcpu.h"#include "pdebug.h"#include "main.h"extern int tcp_open(char *name);/***************************************************************************** *				Global symbols				     * *****************************************************************************/char *id_version = "XCopilot "VERSION;/***************************************************************************** *				Local symbols				     * *****************************************************************************//* * These error messages correspond to the codes in memory.h */static const char *CpuInitErrors[] = {  "",  "ROM file not found",  "Error loading ROM file",  "Error loading RAM file",};/***************************************************************************** *				Local functions				     * *****************************************************************************//********************************************* * attach to the shared memory blocks        * * for the main memory and for the registers * * of the custom block                       * *********************************************/static shared_img *attach_shm(Pilot *pilot){  void *s;  s = shmat(pilot->shmid, (char *)0, 0);  if (s == (void *)-1) {    perror("shmat");    exit(1);  }  return((shared_img *)s);}/************************************* * This is the CPU emulation thread *************************************/static void cpu_proc(shared_img *shptr, Pilot *pilot){  int             r;  /*   * init cpu   * cpu event loop   */  r = CPU_init(shptr, pilot->RamSize, pilot->DataDir, pilot->RomFile,               pilot->RamFile, pilot->ScratchFile, pilot->ResetPilot,               pilot->NoCheck);  if (r != 0) {    fprintf(stderr, "E - %s\n", CpuInitErrors[r]);    exit(1);  }  /*   * fprintf(stderr, "I - calling CPU..\n"); fflush(stderr);   */  CPU(shptr);}/************************************* * This is the LCD emulation thread * *************************************/static void lcd_proc(shared_img *shptr, Pilot *pilot){  int no_x_shm = pilot->NoXShm;  int magfactor = pilot->MagFactor;  int private_cmap = pilot->PrivateColormap;  char *sbuf;   /*    * initialize memory    * init xwindows    * process events    */  memory_init(pilot->RamSize, pilot->DataDir, pilot->RomFile, pilot->RamFile,              pilot->ScratchFile, pilot->ResetPilot, pilot->NoCheck);#ifndef DISABLE_DISPLAY  sbuf = xcpInitialize(shptr, pilot->context, pilot->topWidget, no_x_shm, magfactor,                       private_cmap, NULL, pilot->bbg);  xcpEventLoop(pilot->context, pilot->topWidget, sbuf, shptr);#endif}/******************************** * This is the Debugger thread * ********************************/#define DEBUG_PORTNUM 2000static void debug_proc(shared_img *shptr, Pilot *pilot){  if (strcmp(pilot->Debugging, "old")) {    return;				/* we are not debugging */  }  /*   * initialize memory   * initialize Shptr in newcpu module   */  memory_init(pilot->RamSize, pilot->DataDir, pilot->RomFile, pilot->RamFile,              pilot->ScratchFile, pilot->ResetPilot, pilot->NoCheck);  MC68000_setshare(shptr);  /* Old-style debugging on port 2000 */  pdebug_loop(pilot->DebugArgs, DEBUG_PORTNUM, shptr);  // DAVIDM shptr->CpuReq = cpuExit;}static int correct_write(int fd, unsigned char *buf, int amt){    int wrote = 0;    while (amt) {	int res = write(fd, buf, amt);	if (res <= 0) return res;	wrote += res;	buf += res;	amt -= res;    }    return wrote;}static void attach_serial(unsigned use_serial, char *SerialPort, int *readfd,                          int *writefd){  /* Attach to the pty for serial I/O */  if (use_serial) {    close(0);    close(1);    if (open(SerialPort, O_RDWR) != 0) {	fprintf(stderr, "Error opening %s\n", SerialPort);	perror("read");	exit(1);    }    if (dup2(0,1) != 1) {	fprintf(stderr, "Error opening %s\n", SerialPort);	perror("dup2");	exit(1);    }    fprintf(stderr, "Serial I/O on %s\n", SerialPort);  }  *readfd = 0;  *writefd = 1;}static void attach_gdb(char *DebugArgs, int *gdbfd){    int gdb_fd;    /* Get a fd for talking to gdb, if necessary */    if (!DebugArgs) DebugArgs = "/dev/ptyqf";    if (strchr(DebugArgs, ':')) {        /* gdb on a TCP port, actually */        gdb_fd = tcp_open(DebugArgs);    } else {        gdb_fd = open(DebugArgs, O_RDWR);    }    if (gdb_fd < 0) {	perror("open");	fprintf(stderr, "Debugging failed on %s; "	                "resuming without debugging.\n", DebugArgs);    } else {	fprintf(stderr, "Debugging on %s\n", DebugArgs);    }    *gdbfd = gdb_fd;}static void set_baud(int fd, int baudrate){    struct termios tempio;    unsigned int brate;    /* get current setting */    if (tcgetattr(fd, &tempio) < 0) {	/* We can't do this on this kind of fd */	return;    }    switch (baudrate) {    case 300:	brate = B300;	break;    case 1200:	brate = B1200;	break;    case 2400:	brate = B2400;	break;    case 4800:	brate = B4800;	break;    case 9600:	brate = B9600;	break;    case 19200:	brate = B19200;	break;    case 38400:	brate = B38400;	break;#ifdef B57600    case 57600:        brate = B57600;        break;#endif    default:	fprintf(stderr, "E - unsupported baudrate %d; using 38400\n",			    baudrate);	brate = B38400;    }    tempio.c_iflag = 0;    tempio.c_oflag = 0;    tempio.c_cflag |= CLOCAL;    tempio.c_lflag = 0;    tempio.c_cc[VMIN] = 1;    tempio.c_cc[VTIME] = 0;    if (cfsetispeed(&tempio, brate) < 0) {	perror("E - cfsetispeed");    }    if (cfsetospeed(&tempio, brate) < 0) {	perror("E - cfsetospeed");    }    if (tcsetattr(fd, TCSANOW, &tempio) < 0) {	perror("E - tcsetattr");    }}static void set_flags(int fd, int flags){    struct termios tempio;    /* get current setting */    if (tcgetattr(fd, &tempio) < 0) {	/* We can't do this on this kind of fd */	return;    }    tempio.c_cflag &= ~(CSIZE|CSTOPB|PARENB|PARODD);    if (flags & 1) {	tempio.c_cflag |= CS8;    } else {	tempio.c_cflag |= CS7;    }    if (flags & 2) {	tempio.c_cflag |= CSTOPB;    }    if (flags & 4) {	tempio.c_cflag |= PARODD;    }    if (flags & 8) {	tempio.c_cflag |= PARENB;    }    if (tcsetattr(fd, TCSANOW, &tempio) < 0) {	perror("E - tcsetattr");    }}/****************************** * This is the gdb I/O thread * ******************************/static void gdb_proc(shared_img *shptr, Pilot *pilot){    fd_set	orig_readers;    fd_set	readers;    int		maxfd;    int		gdb_towrite = pilot->gdb_in;    int		gdb_fd = -1;    if (strcmp(pilot->Debugging, "gdb")) {	return;    }    attach_gdb(pilot->DebugArgs, &gdb_fd);    FD_ZERO(&orig_readers);    FD_SET(gdb_fd, &orig_readers);    FD_SET(gdb_towrite, &orig_readers);    maxfd = 0;    if (gdb_fd > maxfd) maxfd = gdb_fd;    if (gdb_towrite > maxfd) maxfd = gdb_towrite;    maxfd++;    /*     * WARNING: This uses a shared memory data structure to store the FIFO. The     * consumer is getting things from this _at the same time_ as this is     * producing.  Examine custom.c and take a course in concurrent programming     * before modifying this.  :-) - Ian     */    while(shptr->CpuReq != cpuExit) {	struct timeval tv;	int selres;	unsigned char buf[FIFO_SIZE];

⌨️ 快捷键说明

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