implemented freeze state saving and restoring of CPU registers

git-svn-id: svn+ssh://svn.phoenixbox.net/svn/apple1/trunk@81 64f78de7-aa59-e511-a0e8-0002a5492df0
This commit is contained in:
Daniel Loffgren 2016-01-17 09:29:48 +00:00
parent c32d5993c3
commit e5db11c190
2 changed files with 38 additions and 4 deletions

View File

@ -24,17 +24,51 @@ void saveFreeze(a1pia *pia, const char *fname) {
endwin();
fprintf(stderr, "Couldn't open %s for writing\n", fname);
}
// See header for a format description.
for (uint16_t offset = 0; offset < v6502_memoryStartCeiling; offset++) {
uint8_t byte = v6502_read(pia->cpu->memory, offset, NO);
fwrite(&byte, sizeof(uint8_t), 1, f);
}
uint8_t pcHigh = pia->cpu->pc >> 8;
fwrite(&pia->cpu->pc, sizeof(char), 1, f); // Low
fwrite(&pcHigh, sizeof(char), 1, f); // High
fwrite(&pia->cpu->ac, sizeof(char), 1, f);
fwrite(&pia->cpu->x, sizeof(char), 1, f);
fwrite(&pia->cpu->y, sizeof(char), 1, f);
fwrite(&pia->cpu->sr, sizeof(char), 1, f);
fwrite(&pia->cpu->sp, sizeof(char), 1, f);
fclose(f);
}
void loadFreeze(a1pia *pia, const char *fname) {
// TODO: implement me
FILE *f = fopen(fname, "r");
if (!f) {
endwin();
fprintf(stderr, "Couldn't open %s for reading\n", fname);
}
// See header for a format description.
for (uint16_t offset = 0; offset < v6502_memoryStartCeiling; offset++) {
uint8_t byte;
fread(&byte, sizeof(uint8_t), 1, f);
pia->cpu->memory->bytes[offset] = byte;
}
uint8_t pcLow, pcHigh;
fread(&pcLow, sizeof(char), 1, f); // Low
fwrite(&pcHigh, sizeof(char), 1, f); // High
pia->cpu->pc = pcLow | (pcHigh << 8);
fread(&pia->cpu->ac, sizeof(char), 1, f);
fread(&pia->cpu->x, sizeof(char), 1, f);
fread(&pia->cpu->y, sizeof(char), 1, f);
fread(&pia->cpu->sr, sizeof(char), 1, f);
fread(&pia->cpu->sp, sizeof(char), 1, f);
fclose(f);
}
char asciiCharFromCursesKey(int key) {

View File

@ -38,7 +38,7 @@ void pia_stop(a1pia *pia);
/* The freeze format is as follows:
* 0x00000-0x0FFFF: The contents of memory
* 0x10001-0x10002: CPU Program Counter
* 0x10001-0x10002: CPU Program Counter (Network byte order)
* 0x10003: CPU Accumulator
* 0x10004: CPU X Register
* 0x10005: CPU Y Register