Commit 190e081f authored by Vladimir Serbinenko's avatar Vladimir Serbinenko
Browse files

Extract file loading code into separate function

parent bef7ae60
......@@ -782,3 +782,39 @@ char *monitor11help = _("BK0011M BOS commands:\n\n\
break;
}
}
int load_file(FILE *f, int addr) {
int len;
d_byte c1, c2;
c1 = fgetc(f);
c2 = fgetc(f);
if (-1 == addr)
addr = c2 << 8 | c1;
c1 = fgetc(f);
c2 = fgetc(f);
len = c2 << 8 | c1;
int addr0 = addr;
fprintf(stderr, _("Reading file into %06o... "), addr);
/* the file is in little-endian format */
while (len > 0 && !feof(f)) {
c1 = fgetc(f);
c2 = fgetc(f);
if (OK != sc_word(addr, c2 << 8 | c1)) {
break;
}
addr += 2;
len -= 2;
}
fprintf(stderr, _("Done.\nLast filled address is %06o\n"), addr - 2);
return addr0;
}
void load_and_run(FILE *f) {
int addr0 = load_file(f, -1);
if (addr0 < 01000) {
lc_word(00776, &pdp.regs[PC]);
} else
pdp.regs[PC] = 01000;
sc_word(0320, 3);
}
......@@ -422,36 +422,7 @@ void ui_load(const char *s)
perror(s);
return;
}
c1 = fgetc(f);
c2 = fgetc(f);
if (-1 == addr)
addr = c2 << 8 | c1;
c1 = fgetc(f);
c2 = fgetc(f);
len = c2 << 8 | c1;
fprintf(stderr, _("Reading %s into %06o... "), s, addr);
if (addr < 01000) {
fprintf(stderr, _("Possible start addresses: "));
do {
c1 = fgetc(f);
c2 = fgetc(f);
fprintf(stderr, "%06o ", c2 << 8 | c1);
addr += 2;
len -= 2;
} while (len > 0 && addr < 01000 && !feof(f));
}
/* the file is in little-endian format */
while (len > 0 && !feof(f)) {
c1 = fgetc(f);
c2 = fgetc(f);
if (OK != sc_word(addr, c2 << 8 | c1)) {
break;
}
addr += 2;
len -= 2;
}
fprintf(stderr, _("Done.\nLast filled address is %06o\n"), addr - 2);
load_file(f, addr);
scr_dirty = 1;
scr_flush();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment