From e1919226e58cb152516ed4af4a8d2ef284611b41 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Tue, 27 Nov 2018 07:58:22 +0000 Subject: [PATCH] size optimisations --- checkpoint.cpp | 8 ++++---- i8080.cpp | 2 ++ i8080.h | 1 + r6502.cpp | 2 ++ z80.cpp | 2 ++ z80.h | 1 + 6 files changed, 12 insertions(+), 4 deletions(-) diff --git a/checkpoint.cpp b/checkpoint.cpp index 9cf4689..938aee0 100644 --- a/checkpoint.cpp +++ b/checkpoint.cpp @@ -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); } diff --git a/i8080.cpp b/i8080.cpp index e5e2fc2..5bf4794 100644 --- a/i8080.cpp +++ b/i8080.cpp @@ -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; } diff --git a/i8080.h b/i8080.h index fcc2409..927e8ee 100644 --- a/i8080.h +++ b/i8080.h @@ -3,6 +3,7 @@ #undef sbi #undef PC +#undef SP class i8080: public CPU { public: diff --git a/r6502.cpp b/r6502.cpp index fb588cd..d0e7664 100644 --- a/r6502.cpp +++ b/r6502.cpp @@ -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; } diff --git a/z80.cpp b/z80.cpp index fe472ca..26b65da 100644 --- a/z80.cpp +++ b/z80.cpp @@ -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; } diff --git a/z80.h b/z80.h index 393a77c..048051a 100644 --- a/z80.h +++ b/z80.h @@ -3,6 +3,7 @@ #undef sbi #undef inch +#undef SP class z80: public CPU { public: