From d9a56801f7124e5b499efd82a4582808bfd81ce2 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Thu, 17 Mar 2022 21:22:26 +0100 Subject: [PATCH] misc esp32 tweaks --- bus.cpp | 18 +++++++++--------- cpu.cpp | 16 +++++----------- memory.cpp | 8 ++++++++ rk05.cpp | 2 ++ 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/bus.cpp b/bus.cpp index a0d21e2..a38aa08 100644 --- a/bus.cpp +++ b/bus.cpp @@ -13,19 +13,19 @@ #include "tm-11.h" #include "tty.h" -bus::bus() : c(nullptr), tm11(nullptr), rk05_(nullptr), rx02_(nullptr), tty_(nullptr) -{ #if defined(ESP32) - // ESP32 goes in a crash-loop when allocating 128kB - // see also https://github.com/espressif/esp-idf/issues/1934 - int n = 12; +// ESP32 goes in a crash-loop when allocating 128kB +// see also https://github.com/espressif/esp-idf/issues/1934 +constexpr int n_pages = 12; #else - int n = 16; +constexpr int n_pages = 16; #endif - m = new memory(n * 8192); +bus::bus() : c(nullptr), tm11(nullptr), rk05_(nullptr), rx02_(nullptr), tty_(nullptr) +{ + m = new memory(n_pages * 8192); - for(int i=0; i busError(); diff --git a/cpu.cpp b/cpu.cpp index d7d1fa0..f097165 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -1517,14 +1517,6 @@ bool cpu::step() if (getPC() & 1) busError(); - if (getPC() == 06746) - { - FILE *fh = fopen("debug.dat", "wb"); - for(int i=0; i<256; i++) - fputc(b -> readByte(getPC() + i), fh); - fclose(fh); - } - disassemble(); b -> setMMR2(getPC()); @@ -1547,9 +1539,11 @@ bool cpu::step() { FILE *fh = fopen("fail.dat", "wb"); - for(int i=0; i<256; i++) - fputc(b -> readByte(getPC() - 2 + i), fh); - fclose(fh); + if (fh) { + for(int i=0; i<256; i++) + fputc(b -> readByte(getPC() - 2 + i), fh); + fclose(fh); + } } busError(); exit(1); diff --git a/memory.cpp b/memory.cpp index de5460a..bc1b9b8 100644 --- a/memory.cpp +++ b/memory.cpp @@ -1,11 +1,19 @@ // (C) 2018 by Folkert van Heusden // Released under Apache License v2.0 +#if defined(ESP32) +#include +#endif #include #include "memory.h" memory::memory(const uint32_t size) : size(size) { +#if defined(ESP32) + Serial.print(F("Memory size (in bytes, decimal): ")); + Serial.println(size); +#endif + m = new uint8_t[size](); } diff --git a/rk05.cpp b/rk05.cpp index 63c2a59..248c1b0 100644 --- a/rk05.cpp +++ b/rk05.cpp @@ -199,6 +199,8 @@ void rk05::writeWord(const uint16_t addr, uint16_t v) while(temp > 0) { uint32_t cur = std::min(uint32_t(sizeof xfer_buffer), temp); + yield(); + #if defined(ESP32) if (fh.read(xfer_buffer, cur) != size_t(cur)) D(fprintf(stderr, "RK05 fread error: %s\n", strerror(errno));)