1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-07-18 15:28:54 +00:00

size optimisations

This commit is contained in:
Stephen Crane 2018-11-27 07:58:22 +00:00
parent c4cc897319
commit e1919226e5
6 changed files with 12 additions and 4 deletions

View File

@ -18,10 +18,10 @@ static char chkpt[] = { "CHKPOINT" };
static int cpid = 0;
const char *checkpoint(sdtape &tape, const char *dir) {
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266)
tape.stop();
snprintf(buf, sizeof(buf), "%s%s.%03d", dir, chkpt, cpid++);
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266)
#if defined(USE_SD)
File file = SD.open(buf, O_WRITE | O_CREAT | O_TRUNC);
#elif defined(USE_SPIFFS)
@ -31,16 +31,16 @@ const char *checkpoint(sdtape &tape, const char *dir) {
#endif
hardware_checkpoint(file);
file.close();
#endif
tape.start(dir);
#endif
return buf;
}
void restore(sdtape &tape, const char *dir, const char *filename) {
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266)
tape.stop();
snprintf(buf, sizeof(buf), "%s%s", dir, filename);
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266)
#if defined(USE_SD)
File file = SD.open(buf, O_READ);
#elif defined(USE_SPIFFS)
@ -50,8 +50,8 @@ void restore(sdtape &tape, const char *dir, const char *filename) {
#endif
hardware_restore(file);
file.close();
#endif
int n = sscanf(buf + strlen(dir), "%[A-Z0-9].%d", chkpt, &cpid);
cpid = (n == 1)? 0: cpid+1;
#endif
tape.start(dir);
}

View File

@ -41,12 +41,14 @@ void i8080::ei() {
}
char *i8080::status(char *buf, size_t n, bool hdr) {
#if defined(CPU_DEBUG)
uint8_t op = _mem[PC];
snprintf(buf, n,
"%s%04x %02x %02x %04x %04x %04x %04x %d%d%d%d%d%d%d%d",
hdr? "_pc_ op aa _bc_ _de_ _hl_ _sp_ szih_p_c\r": "",
PC, op, A, BC, DE, HL, SP, flags.S, flags.Z, flags.I, flags.H,
flags._, flags.P, flags.__, flags.C);
#endif
return buf;
}

View File

@ -3,6 +3,7 @@
#undef sbi
#undef PC
#undef SP
class i8080: public CPU {
public:

View File

@ -25,12 +25,14 @@ uint8_t r6502::flags() {
}
char *r6502::status(char *buf, size_t n, bool hdr) {
#if defined(CPU_DEBUG)
flags();
snprintf(buf, n,
"%s%02x %02x %02x %02x %d%d%d%d%d%d%d%d %04x %02x",
hdr? "aa xx yy sp nv_bdizc _pc_ op\r\n": "",
A, X, Y, S, P.bits.N, P.bits.V, P.bits._, P.bits.B,
P.bits.D, P.bits.I, P.bits.Z, P.bits.C, PC, (uint8_t)_mem[PC]);
#endif
return buf;
}

View File

@ -7,6 +7,7 @@
#include "z80.h"
char *z80::status(char *buf, size_t n, bool hdr) {
#if defined(CPU_DEBUG)
uint8_t op = _mem[PC];
snprintf(buf, n,
"%s%04x %02x %04x %04x %04x %04x %04x %04x %04x %04x %04x %d%d%d "
@ -14,6 +15,7 @@ char *z80::status(char *buf, size_t n, bool hdr) {
hdr? "_pc_ op _af_ _bc_ _de_ _hl_ _af' _bc' _de' _hl' _ir_ imff _sp_ sz5h3pnc\r\n": "",
PC, op, AF, BC, DE, HL, AF_, BC_, DE_, HL_, IR, _im, _iff1, _iff2,
SP, flags.S, flags.Z, flags._5, flags.H, flags._3, flags.P, flags.N, flags.C);
#endif
return buf;
}

1
z80.h
View File

@ -3,6 +3,7 @@
#undef sbi
#undef inch
#undef SP
class z80: public CPU {
public: