diff --git a/ESP32/disk_backend_esp32.cpp b/ESP32/disk_backend_esp32.cpp index 0b34005..b207d24 100644 --- a/ESP32/disk_backend_esp32.cpp +++ b/ESP32/disk_backend_esp32.cpp @@ -37,7 +37,7 @@ bool disk_backend_esp32::read(const off_t offset, const size_t n, uint8_t *const { DOLOG(debug, false, "disk_backend_esp32::read: read %zu bytes from offset %zu", n, offset); -#if defined(ESP32) +#if defined(ESP32) && !defined(SHA2017) digitalWrite(LED_BUILTIN, LOW); #endif @@ -49,7 +49,7 @@ bool disk_backend_esp32::read(const off_t offset, const size_t n, uint8_t *const if (fh->read(target, n) != size_t(n)) { DOLOG(debug, true, "fread error: %s", strerror(errno)); -#if defined(ESP32) +#if defined(ESP32) && !defined(SHA2017) digitalWrite(LED_BUILTIN, HIGH); #endif return false; @@ -57,7 +57,7 @@ bool disk_backend_esp32::read(const off_t offset, const size_t n, uint8_t *const yield(); -#if defined(ESP32) +#if defined(ESP32) && !defined(SHA2017) digitalWrite(LED_BUILTIN, HIGH); #endif @@ -68,7 +68,7 @@ bool disk_backend_esp32::write(const off_t offset, const size_t n, const uint8_t { DOLOG(debug, false, "disk_backend_esp32::write: write %zu bytes to offset %zu", n, offset); -#if defined(ESP32) +#if defined(ESP32) && !defined(SHA2017) digitalWrite(LED_BUILTIN, LOW); #endif @@ -80,7 +80,7 @@ bool disk_backend_esp32::write(const off_t offset, const size_t n, const uint8_t if (fh->write(from, n) != n) { DOLOG(ll_error, true, "RK05 fwrite error %s", strerror(errno)); -#if defined(ESP32) +#if defined(ESP32) && !defined(SHA2017) digitalWrite(LED_BUILTIN, HIGH); #endif return false; @@ -88,8 +88,8 @@ bool disk_backend_esp32::write(const off_t offset, const size_t n, const uint8_t yield(); -#if defined(ESP32) - digitalWrite(LED_BUILTIN, HIGH); +#if defined(ESP32) && !defined(SHA2017) + digitalWrite(LED_BUILTIN, HIGH); #endif return true; diff --git a/ESP32/main.ino b/ESP32/main.ino index 1104989..4afd2f5 100644 --- a/ESP32/main.ino +++ b/ESP32/main.ino @@ -188,8 +188,12 @@ std::optional select_disk_backend(console *const c) c->put_string("1. network (NBD), 2. local SD card, 9. abort"); int ch = -1; - while(ch == -1 && ch != '1' && ch != '2' && ch != '9') - ch = c->wait_char(500); + while(ch == -1 && ch != '1' && ch != '2' && ch != '9') { + auto temp = c->wait_char(500); + + if (temp.has_value()) + ch = temp.value(); + } c->put_string_lf(format("%c", ch)); @@ -208,8 +212,12 @@ std::optional select_disk_type(console *const c) c->put_string("1. RK05, 2. RL02, 9. abort"); int ch = -1; - while(ch == -1 && ch != '1' && ch != '2' && ch != '9') - ch = c->wait_char(500); + while(ch == -1 && ch != '1' && ch != '2' && ch != '9') { + auto temp = c->wait_char(500); + + if (temp.has_value()) + ch = temp.value(); + } c->put_string_lf(format("%c", ch)); @@ -525,7 +533,9 @@ void setup() Serial.print(F("Free RAM after init: ")); Serial.println(ESP.getFreeHeap()); +#if !defined(SHA2017) pinMode(LED_BUILTIN, OUTPUT); +#endif Serial.flush(); diff --git a/ESP32/platformio.ini b/ESP32/platformio.ini index c0cbd90..10114bd 100644 --- a/ESP32/platformio.ini +++ b/ESP32/platformio.ini @@ -2,10 +2,10 @@ # Released under MIT license [platformio] -default_envs = ESP32 +default_envs = ESP32-wemos src_dir = . -[env:ESP32] +[env:ESP32-wemos] lib_ldf_mode = deep+ build_src_filter = +<*> -<.git/> -<.svn/> - - - - - - platform = espressif32 @@ -20,15 +20,18 @@ lib_deps = greiman/SdFat@^2.1.2 build_flags = -std=gnu++17 -Ofast -DESP32=1 -ggdb3 -D_GLIBCXX_USE_C99 build_unflags = -std=gnu++11 -Os -#[env:PICO] -#lib_ldf_mode = deep+ -#src_filter = +<*> -<.git/> -<.svn/> - - - - - - -#platform = raspberrypi -#board = pico -#framework = arduino -#monitor_speed = 115200 -#upload_speed = 1000000 -#lib_deps = greiman/SdFat@^2.1.2 -# adafruit/Adafruit NeoPixel@^1.10.4 -#build_flags = -std=gnu++17 -Ofast -DESP32=1 -ggdb3 -D_GLIBCXX_USE_C99 -#build_unflags = -std=gnu++11 -Os +[env:SHA2017-badge] +lib_ldf_mode = deep+ +build_src_filter = +<*> -<.git/> -<.svn/> - - - - - - +platform = espressif32 +board = esp32doit-devkit-v1 +framework = arduino +monitor_speed = 115200 +upload_speed = 460800 +board_build.filesystem = littlefs +lib_deps = greiman/SdFat@^2.1.2 + adafruit/Adafruit NeoPixel + bblanchon/ArduinoJson@^6.19.4 +build_flags = -std=gnu++17 -Ofast -DESP32=1 -DSHA2017 -ggdb3 -D_GLIBCXX_USE_C99 +build_unflags = -std=gnu++11 -Os +upload_protocol = esptool diff --git a/README.md b/README.md index b6a94ca..c2a0543 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,9 @@ Wiring of the MAX232 connection: * RX : 16 +See SHA2017-badge.md if you want to flash your SHA20127 badge with this software. + + Released under MIT license. Folkert van Heusden diff --git a/SHA2017-badge.md b/SHA2017-badge.md new file mode 100644 index 0000000..ab8aa4e --- /dev/null +++ b/SHA2017-badge.md @@ -0,0 +1,12 @@ +This procedure will remove the default micropython environment. +Maybe you can undo that, but I have not tried that. + +* esptool.py erase\_flash + +* pio run -e SHA2017-badge + +* esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default\_reset --after hard\_reset write\_flash -z --flash\_mode dio --flash\_freq 80m --flash\_size detect 0x1000 ./.pio/build/ESP32-wemos/bootloader.bin + +* pio run -e SHA2017-badge -t upload + +After this, you can connect a serial terminal to /dev/ttyUSB0 at 115k2 bps. diff --git a/bus.cpp b/bus.cpp index 425dd93..5d4cf1c 100644 --- a/bus.cpp +++ b/bus.cpp @@ -650,6 +650,10 @@ void bus::addToMMR1(const int8_t delta, const uint8_t reg) if (MMR1 > 255) esp_backtrace_print(32); #else + if (MMR1 > 255) { + extern FILE *lfh; + fflush(lfh); + } assert(MMR1 < 256); #endif diff --git a/console.cpp b/console.cpp index 2d831df..4e36c8d 100644 --- a/console.cpp +++ b/console.cpp @@ -87,7 +87,7 @@ std::optional console::wait_char(const int timeout_ms) } } - return -1; + return { }; } void console::flush_input() diff --git a/cpu.cpp b/cpu.cpp index 0c1543d..b1b0d9d 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -1571,14 +1571,14 @@ bool cpu::misc_operations(const uint16_t instr) // PUSH link pushStack(getRegister(link_reg)); + b->addToMMR1(-2, 6); + // MOVE PC,link setRegister(link_reg, getPC()); // JMP dst setPC(dst_value); - b->addToMMR1(-2, 6); - return true; } @@ -1628,9 +1628,11 @@ void cpu::trap(uint16_t vector, const int new_ipl, const bool is_interrupt) } else { before_psw = getPSW(); + b->addToMMR1(-2, 6); before_pc = getPC(); + b->addToMMR1(-2, 6); // TODO set MMR2? @@ -2163,8 +2165,10 @@ void cpu::step_a() if ((b->getMMR0() & 0160000) == 0) b->clearMMR1(); - if (any_queued_interrupts && check_queued_interrupts()) - return; // documentation + if (any_queued_interrupts && check_queued_interrupts()) { + if ((b->getMMR0() & 0160000) == 0) + b->clearMMR1(); + } } void cpu::step_b()