diff --git a/bus.cpp b/bus.cpp index 705a461..dc80970 100644 --- a/bus.cpp +++ b/bus.cpp @@ -31,9 +31,7 @@ bus::bus() { m = new memory(n_pages * 8192l); - memset(pages, 0x00, sizeof pages); - - CPUERR = MMR0 = MMR1 = MMR2 = MMR3 = PIR = CSR = 0; + reset(); #if defined(BUILD_FOR_RP2040) xSemaphoreGive(lf_csr_lock); // initialize @@ -50,6 +48,26 @@ bus::~bus() delete m; } +void bus::reset() +{ + m->reset(); + + memset(pages, 0x00, sizeof pages); + + CPUERR = MMR0 = MMR1 = MMR2 = MMR3 = PIR = CSR = 0; + + if (c) + c->reset(); + if (tm11) + tm11->reset(); + if (rk05_) + rk05_->reset(); + if (rl02_) + rl02_->reset(); + if (tty_) + tty_->reset(); +} + void bus::add_cpu(cpu *const c) { delete this->c; @@ -80,11 +98,6 @@ void bus::add_tty(tty *const tty_) this->tty_ = tty_; } -void bus::clearmem() -{ - m->reset(); -} - void bus::init() { MMR0 = 0; diff --git a/bus.h b/bus.h index 607aa60..94a67ba 100644 --- a/bus.h +++ b/bus.h @@ -123,7 +123,7 @@ public: bus(); ~bus(); - void clearmem(); + void reset(); void set_console_switches(const uint16_t new_state) { console_switches = new_state; } void set_console_switch(const int bit, const bool state) { console_switches &= ~(1 << bit); console_switches |= state << bit; } diff --git a/debugger.cpp b/debugger.cpp index fc68676..6791db5 100644 --- a/debugger.cpp +++ b/debugger.cpp @@ -419,13 +419,8 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto continue; } else if (cmd == "reset" || cmd == "r") { -#if defined(ESP32) - ESP.restart(); -#else *stop_event = EVENT_NONE; - - c->reset(); -#endif + b->reset(); continue; } #if defined(ESP32) || defined(BUILD_FOR_RP2040) diff --git a/rk05.cpp b/rk05.cpp index 35b8610..d4f1956 100644 --- a/rk05.cpp +++ b/rk05.cpp @@ -28,9 +28,9 @@ rk05::rk05(const std::vector & files, bus *const b, std::atomic_ disk_read_acitivity(disk_read_acitivity), disk_write_acitivity(disk_write_acitivity) { - memset(registers, 0x00, sizeof registers); - fhs = files; + + reset(); } rk05::~rk05() @@ -39,6 +39,11 @@ rk05::~rk05() delete fh; } +void rk05::reset() +{ + memset(registers, 0x00, sizeof registers); +} + uint8_t rk05::readByte(const uint16_t addr) { uint16_t v = readWord(addr & ~1); diff --git a/rk05.h b/rk05.h index 8d4a4ee..e915888 100644 --- a/rk05.h +++ b/rk05.h @@ -28,7 +28,7 @@ class rk05 { private: bus *const b { nullptr }; - uint16_t registers [ 7]; + uint16_t registers [7]; std::vector fhs; std::atomic_bool *const disk_read_acitivity { nullptr }; @@ -38,6 +38,8 @@ public: rk05(const std::vector & files, bus *const b, std::atomic_bool *const disk_read_acitivity, std::atomic_bool *const disk_write_acitivity); virtual ~rk05(); + void reset(); + uint8_t readByte(const uint16_t addr); uint16_t readWord(const uint16_t addr); diff --git a/rl02.cpp b/rl02.cpp index 650507f..f4cfdee 100644 --- a/rl02.cpp +++ b/rl02.cpp @@ -28,10 +28,9 @@ rl02::rl02(const std::vector & files, bus *const b, std::atomic_ disk_read_acitivity(disk_read_acitivity), disk_write_acitivity(disk_write_acitivity) { - memset(registers, 0x00, sizeof registers); - memset(xfer_buffer, 0x00, sizeof xfer_buffer); - fhs = files; + + reset(); } rl02::~rl02() @@ -40,6 +39,12 @@ rl02::~rl02() delete fh; } +void rl02::reset() +{ + memset(registers, 0x00, sizeof registers); + memset(xfer_buffer, 0x00, sizeof xfer_buffer); +} + uint8_t rl02::readByte(const uint16_t addr) { uint16_t v = readWord(addr & ~1); @@ -118,13 +123,13 @@ void rl02::writeWord(const uint16_t addr, uint16_t v) else if (command == 6 || command == 7) { // read data / read data without header check *disk_read_acitivity = true; - bool proceed = true; + bool proceed = true; uint32_t temp_disk_offset = disk_offset; - uint32_t memory_address = registers[(RL02_BAR - RL02_BASE) / 2]; + uint32_t memory_address = registers[(RL02_BAR - RL02_BASE) / 2]; - uint32_t count = (65536l - registers[(RL02_MPR - RL02_BASE) / 2]) * 2; + uint32_t count = (65536l - registers[(RL02_MPR - RL02_BASE) / 2]) * 2; DOLOG(debug, false, "RL02 read %d bytes (dec) from %d (dec) to %06o (oct)", count, disk_offset, memory_address); diff --git a/rl02.h b/rl02.h index 8bb41f2..ea08179 100644 --- a/rl02.h +++ b/rl02.h @@ -38,6 +38,8 @@ public: rl02(const std::vector & files, bus *const b, std::atomic_bool *const disk_read_acitivity, std::atomic_bool *const disk_write_acitivity); virtual ~rl02(); + void reset(); + uint8_t readByte(const uint16_t addr); uint16_t readWord(const uint16_t addr); diff --git a/tm-11.cpp b/tm-11.cpp index 758363d..057376d 100644 --- a/tm-11.cpp +++ b/tm-11.cpp @@ -13,6 +13,8 @@ tm_11::tm_11(const std::string & file, memory *const m) : m(m) { fh = fopen(file.c_str(), "rb"); + + reset(); } tm_11::~tm_11() @@ -20,6 +22,13 @@ tm_11::~tm_11() fclose(fh); } +void tm_11::reset() +{ + memset(registers, 0x00, sizeof registers ); + memset(xfer_buffer, 0x00, sizeof xfer_buffer); + offset = 0; +} + uint8_t tm_11::readByte(const uint16_t addr) { uint16_t v = readWord(addr & ~1); diff --git a/tm-11.h b/tm-11.h index ed99330..421c2da 100644 --- a/tm-11.h +++ b/tm-11.h @@ -31,6 +31,8 @@ public: tm_11(const std::string & file, memory *const m); virtual ~tm_11(); + void reset(); + uint8_t readByte(const uint16_t addr); uint16_t readWord(const uint16_t addr); diff --git a/tty.cpp b/tty.cpp index a481c06..ed5bb3f 100644 --- a/tty.cpp +++ b/tty.cpp @@ -33,6 +33,8 @@ tty::tty(console *const c, bus *const b) : c(c), b(b) { + reset(); + #if defined(BUILD_FOR_RP2040) xSemaphoreGive(chars_lock); // initialize #endif @@ -54,6 +56,11 @@ tty::~tty() #endif } +void tty::reset() +{ + memset(registers, 0x00, sizeof registers); +} + uint8_t tty::readByte(const uint16_t addr) { uint16_t v = readWord(addr & ~1); diff --git a/tty.h b/tty.h index b356a0e..b14c96e 100644 --- a/tty.h +++ b/tty.h @@ -50,6 +50,8 @@ public: tty(console *const c, bus *const b); virtual ~tty(); + void reset(); + uint8_t readByte(const uint16_t addr); uint16_t readWord(const uint16_t addr);