#define DUMPFILE "rom.dump" #define ROMSIZE (2<<20) #include #include #include #include #include #include #include #include extern const char *__progname; static int dfd; static unsigned char ibuf[512]; static int ibfill; static int ibptr; static unsigned char *rom; static void opendump(void) { void *mmrv; dfd = open(DUMPFILE,O_RDWR|O_CREAT,0666); if (dfd < 0) { fprintf(stderr,"%s: open %s: %s\r\n",__progname,DUMPFILE,strerror(errno)); exit(1); } ftruncate(dfd,ROMSIZE); mmrv = mmap(0,ROMSIZE,PROT_READ|PROT_WRITE,MAP_FILE|MAP_SHARED,dfd,0); if (mmrv == MAP_FAILED) { fprintf(stderr,"%s: mmap %s: %s\r\n",__progname,DUMPFILE,strerror(errno)); exit(1); } rom = mmrv; } static void nonblocking(int fd) { fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0)|O_NONBLOCK); } static int get1(int tmo) { struct pollfd pfd; int i; if (ibptr >= ibfill) { fflush(0); while (1) { ibfill = read(0,&ibuf[0],sizeof(ibuf)); if (ibfill > 0) { ibptr = 0; break; } if (ibfill < 0) { switch (errno) { case EINTR: continue; break; case EWOULDBLOCK: pfd.fd = 0; pfd.events = POLLIN | POLLRDNORM; i = poll(&pfd,1,tmo); if (i == 0) return(-1); continue; break; } fprintf(stderr,"%s: input read: %s\r\n",__progname,strerror(errno)); exit(1); } fprintf(stderr,"%s: input EOF\r\n",__progname); exit(1); } } return(ibuf[ibptr++]); } static void require(const char *s) { int c; const char *sp; sp = s; while (*sp) { c = get1(1000); if (c < 0) { fprintf(stderr,"%s: read timeout at\r\n%.*s <<>> %s\r\n", __progname, (int)(sp-s), s, sp); exit(1); } if (c != (unsigned char)*sp) { fprintf(stderr,"%s: unexpected character %02x at\r\n%.*s <<>> %s\r\n", __progname, c, (int)(sp-s), s, sp); exit(1); } sp ++; } } static void drain(int tmo) { do ibptr = ibfill; while (get1(tmo) >= 0); } static int xval(unsigned char c) { switch (c) { case '0': return(0); break; case '1': return(1); break; case '2': return(2); break; case '3': return(3); break; case '4': return(4); break; case '5': return(5); break; case '6': return(6); break; case '7': return(7); break; case '8': return(8); break; case '9': return(9); break; case 'a': case 'A': return(10); break; case 'b': case 'B': return(11); break; case 'c': case 'C': return(12); break; case 'd': case 'D': return(13); break; case 'e': case 'E': return(14); break; case 'f': case 'F': return(15); break; } return(-1); } static void getrom(void) { int a; int c1; int c2; int v1; int v2; for (a=0;a