Skip to content

Commit

Permalink
dcpu: load image from commandline (or out.hex if none), not stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
swetland committed Apr 5, 2012
1 parent 1612c0d commit 72884f8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions dcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (;;) {
Expand Down

0 comments on commit 72884f8

Please sign in to comment.