diff --git a/cpu.h b/cpu.h index 44b03b8..7bb5035 100644 --- a/cpu.h +++ b/cpu.h @@ -5,6 +5,8 @@ #include #endif +#undef PC + class CPU: public Checkpointable { public: virtual void run(unsigned instructions) =0; @@ -22,6 +24,7 @@ public: protected: CPU (Memory &mem, jmp_buf &e, statfn s): _mem(mem), _err(e), _status(s), _debug(false) {} Memory &_mem; + Memory::address PC; jmp_buf &_err; statfn _status; bool _debug; diff --git a/hardware.h b/hardware.h index 111ff4a..8c017be 100644 --- a/hardware.h +++ b/hardware.h @@ -27,7 +27,7 @@ //#define SPIRAM_CS PF_3 #define SPIRAM_SPI 1 #define SPIRAM_DEV SPI_for_SD -#define SPIRAM_SIZE 32768 +#define SPIRAM_SIZE 65536 // "tape" storage... #define SD_CS PF_3 diff --git a/i8080.cpp b/i8080.cpp index 6eb4c46..22c8b30 100644 --- a/i8080.cpp +++ b/i8080.cpp @@ -2,6 +2,7 @@ #include "memory.h" #include "cpu.h" +#include "ports.h" #include "i8080.h" #define CPU_STATE_FMT "%04x %02x %02x %04x %04x %04x %04x %d%d%d%d%d%d%d%d\r",\ @@ -117,7 +118,7 @@ int i8080::parity_table[] = { 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, }; -i8080::i8080(Memory &m, jmp_buf &jb, CPU::statfn s, Ports &d): CPU(m, jb, s) +i8080::i8080(Memory &m, jmp_buf &jb, CPU::statfn s, PortDevice &d): CPU(m, jb, s) { _ports = &d; diff --git a/i8080.h b/i8080.h index 63de916..74dc8d8 100644 --- a/i8080.h +++ b/i8080.h @@ -6,14 +6,7 @@ class i8080: public CPU { public: - - class Ports { - public: - virtual void out(byte p, byte v, i8080 *cpu) =0; - virtual byte in(byte p, i8080 *cpu) =0; - }; - - i8080(Memory &, jmp_buf &, CPU::statfn, Ports &); + i8080(Memory &, jmp_buf &, CPU::statfn, PortDevice &); void run(unsigned); void reset(); @@ -51,7 +44,7 @@ private: struct { byte L, H; }; word HL; }; - Memory::address PC, SP; + Memory::address SP; union { struct { unsigned C:1; @@ -66,7 +59,7 @@ private: byte SR; }; int _irq_pending; - Ports *_ports; + PortDevice *_ports; typedef void (i8080::*OP)(); OP _ops[256]; @@ -322,7 +315,8 @@ private: inline void _and(byte b) { A = A & b; _szp(A); - flags.C = flags.H = 0; + flags.C = 0; + flags.H = 1; } void anab() { _and(B); } diff --git a/ports.h b/ports.h new file mode 100644 index 0000000..127a352 --- /dev/null +++ b/ports.h @@ -0,0 +1,11 @@ +#ifndef __PORTS_H__ +#define __PORTS_H__ + +template +class PortDevice { +public: + virtual void out(word p, byte v, P *cpu) =0; + virtual byte in(word p, P *cpu) =0; +}; + +#endif diff --git a/r6502.h b/r6502.h index 19dfd0e..a0aa1cd 100644 --- a/r6502.h +++ b/r6502.h @@ -16,7 +16,6 @@ public: r6502 (Memory &, jmp_buf &, CPU::statfn); private: /* registers */ - Memory::address PC; byte S, A, X, Y; byte N, V, B, D, I, Z, C; union { diff --git a/spiram.cpp b/spiram.cpp index 843527d..792b255 100644 --- a/spiram.cpp +++ b/spiram.cpp @@ -21,7 +21,7 @@ spiram::operator byte() void spiram::checkpoint(Stream &s) { byte buf[Memory::page_size]; - for (int i = 0; i < pages(); i++) { + for (unsigned i = 0; i < pages(); i++) { spiRam.read_stream(i * 256, buf, sizeof(buf)); s.write(buf, sizeof(buf)); } @@ -30,7 +30,7 @@ void spiram::checkpoint(Stream &s) void spiram::restore(Stream &s) { byte buf[Memory::page_size]; - for (int i = 0; i < pages(); i++) { + for (unsigned i = 0; i < pages(); i++) { s.readBytes((char *)buf, sizeof(buf)); spiRam.write_stream(i * 256, buf, sizeof(buf)); }