scemu/main.c

72 lines
1 KiB
C
Raw Normal View History

2025-09-09 15:29:39 +00:00
#include <u.h>
#include <libc.h>
#include "dat.h"
#include "fns.h"
void
usage(void)
{
fprint(2, "usage: %s [ -s target speed ] [ 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: size does not permit whole zp access");
romptr = mem+32768;
romptr = romptr + 32768 - d->length;
s = romptr-mem;
free(d);
n = read(fd, romptr, s);
if(n != s)
fprint(2, "tried to read %uld bytes, got %ld bytes\n", s, n);
close(fd);
}
void
main(int argc, char **argv)
{
int c;
vlong t, t2, t3;
vlong target;
target = 1000;
ARGBEGIN{
case 's':
target = atoll(EARGF(usage()));
break;
default:
usage();
break;
}ARGEND
openprog(*argv);
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;
}
}
}
}