Permalink
Browse files

dcpu: load image from commandline (or out.hex if none), not stdin

  • Loading branch information...
1 parent 1612c0d commit 72884f87ef5a4de8d259cf32a41eb1f7b779a20f @swetland swetland committed Apr 5, 2012
Showing with 9 additions and 3 deletions.
  1. +9 −3 dcpu.c
View
12 dcpu.c
@@ -152,22 +152,28 @@ void dumpstate(struct dcpu *d) {
d->r[0], d->r[1], d->r[2], d->r[3], d->r[4], d->r[5], d->r[6], d->r[7]);
}
-void load(struct dcpu *d, FILE *fp) {
+void load(struct dcpu *d, const char *fn) {
+ FILE *fp;
char buf[128];
u16 n = 0;
+ if (!(fp = fopen(fn, "r"))) {
+ fprintf(stderr, "cannot open: %s\n", fn);
+ exit(1);
+ }
while (!feof(fp) && fgets(buf, 128, fp)) {
if (!isalnum(buf[0]))
continue;
d->m[n++] = strtoul(buf, 0, 16);
}
fprintf(stderr,"< LOADED %d WORDS >\n", n);
+ fclose(fp);
}
int main(int argc, char **argv) {
struct dcpu d;
-
memset(&d, 0, sizeof(d));
- load(&d, stdin);
+
+ load(&d, argc > 1 ? argv[1] : "out.hex");
dumpheader();
for (;;) {

0 comments on commit 72884f8

Please sign in to comment.