checkpointing io state

This commit is contained in:
Stephen Crane 2014-11-14 13:28:48 +00:00
parent a37eaee362
commit 8cc440325c
2 changed files with 34 additions and 2 deletions

View File

@ -64,7 +64,7 @@ void loop() {
unsigned key = ps2.read();
if (!ps2.isbreak())
io.down(key);
else {
else
switch (key) {
case PS2_F1:
reset();
@ -80,11 +80,17 @@ void loop() {
case PS2_F4:
io.load();
break;
case PS2_F6:
io.status(checkpoint(io.tape, PROGRAMS));
break;
case PS2_F7:
if (filename)
restore(io.tape, PROGRAMS, filename);
break;
default:
io.up(key);
break;
}
}
} else if (!halted)
cpu.run(CPU_INSTRUCTIONS);
}

26
io.cpp
View File

@ -228,7 +228,33 @@ Serial.println(dsp_cr, 16);
}
void io::checkpoint(Stream &s) {
s.write(dsp_cr);
s.write(dsp);
s.write(kbd_cr);
s.write(kbd);
s.write(kbd_int);
s.write(dsp_out);
s.write(r);
s.write(c);
for (int j = 0; j < ROWS; j++)
for (int i = 0; i < COLS; i++)
s.write(screen[j][i]);
}
void io::restore(Stream &s) {
dsp_cr = s.read();
dsp = s.read();
kbd_cr = s.read();
kbd = s.read();
kbd_int = s.read();
dsp_out = s.read();
r = s.read();
c = s.read();
for (int j = 0; j < ROWS; j++)
for (int i = 0; i < COLS; i++) {
char c = s.read();
screen[j][i] = c;
draw(c, i, j);
}
draw('_', c, r);
}