#include #include #include "dat.h" #include "fns.h" void usage(void) { fprint(2, "usage: %s [ -t ] [ -s target cycle length ] prog\n", argv0); exits("usage"); } void openprog(char *f) { int fd; long n; Dir *d; usize s; fd = open(f, OREAD); if(fd < 0) sysfatal("cannot open program: %r"); d = dirfstat(fd); if(d->length > 0xFF00) sysfatal("program too big: cannot be bigger than $ff00"); romptr = mem+32768; romptr += 32768 - d->length; s = mem+65536-romptr; free(d); n = read(fd, romptr, s); if(n != s) fprint(2, "tried to read %ulld bytes, got %ld bytes\n", s, n); close(fd); } void main(int argc, char **argv) { int c; vlong t, t2, t3; vlong target; trace = 0; target = 1000; mem = malloc(0x10000); if(mem == nil) sysfatal("bad malloc for mem"); ARGBEGIN{ case 's': target = atoll(EARGF(usage())); break; case 't': trace = 1; break; default: usage(); break; }ARGEND if(!argc) usage(); openprog(*argv); rS = 0xFF; rP = 0x34; pc = 0xFFFC; pc = fetch16(); for(;;){ c = step(); while(c >= 0){ t = nsec(); --c; t2 = nsec(); t3 = t2-t; while(t3 < target){ t2 = nsec(); t3 = t2-t; } } } }