From ce1caff5a858fbdfd9e70aaed3f97f13708a96f1 Mon Sep 17 00:00:00 2001
From: folkert van heusden <mail@vanheusden.com>
Date: Wed, 22 Mar 2023 13:01:01 +0100
Subject: [PATCH] does not even compile yet

---
 RP2040/bus.cpp               |  1 +
 RP2040/bus.h                 |  1 +
 RP2040/console.cpp           |  1 +
 RP2040/console.h             |  1 +
 RP2040/cpu.cpp               |  1 +
 RP2040/cpu.h                 |  1 +
 RP2040/debugger.cpp          |  1 +
 RP2040/debugger.h            |  1 +
 RP2040/disk_backend.cpp      |  1 +
 RP2040/disk_backend.h        |  1 +
 RP2040/disk_backend_file.cpp |  1 +
 RP2040/disk_backend_file.h   |  1 +
 RP2040/error.cpp             |  1 +
 RP2040/error.h               |  1 +
 RP2040/gen.h                 |  1 +
 RP2040/kw11-l.cpp            |  1 +
 RP2040/kw11-l.h              |  1 +
 RP2040/loaders.cpp           |  1 +
 RP2040/loaders.h             |  1 +
 RP2040/log.cpp               |  1 +
 RP2040/log.h                 |  1 +
 RP2040/memory.cpp            |  1 +
 RP2040/memory.h              |  1 +
 RP2040/platformio.ini        | 17 +++++++
 RP2040/rk05.cpp              |  1 +
 RP2040/rk05.h                |  1 +
 RP2040/rl02.cpp              |  1 +
 RP2040/rl02.h                |  1 +
 RP2040/rp2040.h              | 11 +++++
 RP2040/tm-11.cpp             |  1 +
 RP2040/tm-11.h               |  1 +
 RP2040/tty.cpp               |  1 +
 RP2040/tty.h                 |  1 +
 RP2040/utils.cpp             |  1 +
 RP2040/utils.h               |  1 +
 debugger.cpp                 | 86 ++++++++++++++++++++++++++++++++++--
 36 files changed, 144 insertions(+), 3 deletions(-)
 create mode 120000 RP2040/bus.cpp
 create mode 120000 RP2040/bus.h
 create mode 120000 RP2040/console.cpp
 create mode 120000 RP2040/console.h
 create mode 120000 RP2040/cpu.cpp
 create mode 120000 RP2040/cpu.h
 create mode 120000 RP2040/debugger.cpp
 create mode 120000 RP2040/debugger.h
 create mode 120000 RP2040/disk_backend.cpp
 create mode 120000 RP2040/disk_backend.h
 create mode 120000 RP2040/disk_backend_file.cpp
 create mode 120000 RP2040/disk_backend_file.h
 create mode 120000 RP2040/error.cpp
 create mode 120000 RP2040/error.h
 create mode 120000 RP2040/gen.h
 create mode 120000 RP2040/kw11-l.cpp
 create mode 120000 RP2040/kw11-l.h
 create mode 120000 RP2040/loaders.cpp
 create mode 120000 RP2040/loaders.h
 create mode 120000 RP2040/log.cpp
 create mode 120000 RP2040/log.h
 create mode 120000 RP2040/memory.cpp
 create mode 120000 RP2040/memory.h
 create mode 100644 RP2040/platformio.ini
 create mode 120000 RP2040/rk05.cpp
 create mode 120000 RP2040/rk05.h
 create mode 120000 RP2040/rl02.cpp
 create mode 120000 RP2040/rl02.h
 create mode 100644 RP2040/rp2040.h
 create mode 120000 RP2040/tm-11.cpp
 create mode 120000 RP2040/tm-11.h
 create mode 120000 RP2040/tty.cpp
 create mode 120000 RP2040/tty.h
 create mode 120000 RP2040/utils.cpp
 create mode 120000 RP2040/utils.h

diff --git a/RP2040/bus.cpp b/RP2040/bus.cpp
new file mode 120000
index 0000000..54349cd
--- /dev/null
+++ b/RP2040/bus.cpp
@@ -0,0 +1 @@
+../bus.cpp
\ No newline at end of file
diff --git a/RP2040/bus.h b/RP2040/bus.h
new file mode 120000
index 0000000..16d9e36
--- /dev/null
+++ b/RP2040/bus.h
@@ -0,0 +1 @@
+../bus.h
\ No newline at end of file
diff --git a/RP2040/console.cpp b/RP2040/console.cpp
new file mode 120000
index 0000000..1e29138
--- /dev/null
+++ b/RP2040/console.cpp
@@ -0,0 +1 @@
+../console.cpp
\ No newline at end of file
diff --git a/RP2040/console.h b/RP2040/console.h
new file mode 120000
index 0000000..e323210
--- /dev/null
+++ b/RP2040/console.h
@@ -0,0 +1 @@
+../console.h
\ No newline at end of file
diff --git a/RP2040/cpu.cpp b/RP2040/cpu.cpp
new file mode 120000
index 0000000..89beeaf
--- /dev/null
+++ b/RP2040/cpu.cpp
@@ -0,0 +1 @@
+../cpu.cpp
\ No newline at end of file
diff --git a/RP2040/cpu.h b/RP2040/cpu.h
new file mode 120000
index 0000000..e9d4bdf
--- /dev/null
+++ b/RP2040/cpu.h
@@ -0,0 +1 @@
+../cpu.h
\ No newline at end of file
diff --git a/RP2040/debugger.cpp b/RP2040/debugger.cpp
new file mode 120000
index 0000000..39af298
--- /dev/null
+++ b/RP2040/debugger.cpp
@@ -0,0 +1 @@
+../debugger.cpp
\ No newline at end of file
diff --git a/RP2040/debugger.h b/RP2040/debugger.h
new file mode 120000
index 0000000..90051ef
--- /dev/null
+++ b/RP2040/debugger.h
@@ -0,0 +1 @@
+../debugger.h
\ No newline at end of file
diff --git a/RP2040/disk_backend.cpp b/RP2040/disk_backend.cpp
new file mode 120000
index 0000000..6acc92c
--- /dev/null
+++ b/RP2040/disk_backend.cpp
@@ -0,0 +1 @@
+../disk_backend.cpp
\ No newline at end of file
diff --git a/RP2040/disk_backend.h b/RP2040/disk_backend.h
new file mode 120000
index 0000000..288f0e0
--- /dev/null
+++ b/RP2040/disk_backend.h
@@ -0,0 +1 @@
+../disk_backend.h
\ No newline at end of file
diff --git a/RP2040/disk_backend_file.cpp b/RP2040/disk_backend_file.cpp
new file mode 120000
index 0000000..18dbf1a
--- /dev/null
+++ b/RP2040/disk_backend_file.cpp
@@ -0,0 +1 @@
+../disk_backend_file.cpp
\ No newline at end of file
diff --git a/RP2040/disk_backend_file.h b/RP2040/disk_backend_file.h
new file mode 120000
index 0000000..3ea9a2e
--- /dev/null
+++ b/RP2040/disk_backend_file.h
@@ -0,0 +1 @@
+../disk_backend_file.h
\ No newline at end of file
diff --git a/RP2040/error.cpp b/RP2040/error.cpp
new file mode 120000
index 0000000..14fd3ca
--- /dev/null
+++ b/RP2040/error.cpp
@@ -0,0 +1 @@
+../error.cpp
\ No newline at end of file
diff --git a/RP2040/error.h b/RP2040/error.h
new file mode 120000
index 0000000..5a002f4
--- /dev/null
+++ b/RP2040/error.h
@@ -0,0 +1 @@
+../error.h
\ No newline at end of file
diff --git a/RP2040/gen.h b/RP2040/gen.h
new file mode 120000
index 0000000..bc0aea6
--- /dev/null
+++ b/RP2040/gen.h
@@ -0,0 +1 @@
+../gen.h
\ No newline at end of file
diff --git a/RP2040/kw11-l.cpp b/RP2040/kw11-l.cpp
new file mode 120000
index 0000000..12a1881
--- /dev/null
+++ b/RP2040/kw11-l.cpp
@@ -0,0 +1 @@
+../kw11-l.cpp
\ No newline at end of file
diff --git a/RP2040/kw11-l.h b/RP2040/kw11-l.h
new file mode 120000
index 0000000..b7e88ef
--- /dev/null
+++ b/RP2040/kw11-l.h
@@ -0,0 +1 @@
+../kw11-l.h
\ No newline at end of file
diff --git a/RP2040/loaders.cpp b/RP2040/loaders.cpp
new file mode 120000
index 0000000..c8fc77d
--- /dev/null
+++ b/RP2040/loaders.cpp
@@ -0,0 +1 @@
+../loaders.cpp
\ No newline at end of file
diff --git a/RP2040/loaders.h b/RP2040/loaders.h
new file mode 120000
index 0000000..72369d4
--- /dev/null
+++ b/RP2040/loaders.h
@@ -0,0 +1 @@
+../loaders.h
\ No newline at end of file
diff --git a/RP2040/log.cpp b/RP2040/log.cpp
new file mode 120000
index 0000000..acdcf24
--- /dev/null
+++ b/RP2040/log.cpp
@@ -0,0 +1 @@
+../log.cpp
\ No newline at end of file
diff --git a/RP2040/log.h b/RP2040/log.h
new file mode 120000
index 0000000..49a04dd
--- /dev/null
+++ b/RP2040/log.h
@@ -0,0 +1 @@
+../log.h
\ No newline at end of file
diff --git a/RP2040/memory.cpp b/RP2040/memory.cpp
new file mode 120000
index 0000000..ce3ac52
--- /dev/null
+++ b/RP2040/memory.cpp
@@ -0,0 +1 @@
+../memory.cpp
\ No newline at end of file
diff --git a/RP2040/memory.h b/RP2040/memory.h
new file mode 120000
index 0000000..6bdcc98
--- /dev/null
+++ b/RP2040/memory.h
@@ -0,0 +1 @@
+../memory.h
\ No newline at end of file
diff --git a/RP2040/platformio.ini b/RP2040/platformio.ini
new file mode 100644
index 0000000..e9e9e44
--- /dev/null
+++ b/RP2040/platformio.ini
@@ -0,0 +1,17 @@
+[platformio]
+default_envs = RP2040
+src_dir = .
+
+[env:RP2040]
+lib_ldf_mode = deep+
+src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<build> -<player.cpp>
+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 -DRP2040=1 -ggdb3
+#-D_GLIBCXX_USE_C99
+build_unflags = -std=gnu++14 -Os
diff --git a/RP2040/rk05.cpp b/RP2040/rk05.cpp
new file mode 120000
index 0000000..718725a
--- /dev/null
+++ b/RP2040/rk05.cpp
@@ -0,0 +1 @@
+../rk05.cpp
\ No newline at end of file
diff --git a/RP2040/rk05.h b/RP2040/rk05.h
new file mode 120000
index 0000000..0692da0
--- /dev/null
+++ b/RP2040/rk05.h
@@ -0,0 +1 @@
+../rk05.h
\ No newline at end of file
diff --git a/RP2040/rl02.cpp b/RP2040/rl02.cpp
new file mode 120000
index 0000000..1febf02
--- /dev/null
+++ b/RP2040/rl02.cpp
@@ -0,0 +1 @@
+../rl02.cpp
\ No newline at end of file
diff --git a/RP2040/rl02.h b/RP2040/rl02.h
new file mode 120000
index 0000000..49b1e34
--- /dev/null
+++ b/RP2040/rl02.h
@@ -0,0 +1 @@
+../rl02.h
\ No newline at end of file
diff --git a/RP2040/rp2040.h b/RP2040/rp2040.h
new file mode 100644
index 0000000..91ac7c0
--- /dev/null
+++ b/RP2040/rp2040.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#if defined(RP2040)
+#include <Arduino.h>
+
+#include <SPI.h>
+
+#define USE_SDFAT
+#define SD_FAT_TYPE 1
+#include <SdFat.h>
+#endif
diff --git a/RP2040/tm-11.cpp b/RP2040/tm-11.cpp
new file mode 120000
index 0000000..533f071
--- /dev/null
+++ b/RP2040/tm-11.cpp
@@ -0,0 +1 @@
+../tm-11.cpp
\ No newline at end of file
diff --git a/RP2040/tm-11.h b/RP2040/tm-11.h
new file mode 120000
index 0000000..dd31375
--- /dev/null
+++ b/RP2040/tm-11.h
@@ -0,0 +1 @@
+../tm-11.h
\ No newline at end of file
diff --git a/RP2040/tty.cpp b/RP2040/tty.cpp
new file mode 120000
index 0000000..1acd74f
--- /dev/null
+++ b/RP2040/tty.cpp
@@ -0,0 +1 @@
+../tty.cpp
\ No newline at end of file
diff --git a/RP2040/tty.h b/RP2040/tty.h
new file mode 120000
index 0000000..321a9c7
--- /dev/null
+++ b/RP2040/tty.h
@@ -0,0 +1 @@
+../tty.h
\ No newline at end of file
diff --git a/RP2040/utils.cpp b/RP2040/utils.cpp
new file mode 120000
index 0000000..451eef0
--- /dev/null
+++ b/RP2040/utils.cpp
@@ -0,0 +1 @@
+../utils.cpp
\ No newline at end of file
diff --git a/RP2040/utils.h b/RP2040/utils.h
new file mode 120000
index 0000000..6cd5d4f
--- /dev/null
+++ b/RP2040/utils.h
@@ -0,0 +1 @@
+../utils.h
\ No newline at end of file
diff --git a/debugger.cpp b/debugger.cpp
index 65242ff..ceb6412 100644
--- a/debugger.cpp
+++ b/debugger.cpp
@@ -10,8 +10,12 @@
 #include "utils.h"
 
 
+#if defined(ESP32) || defined(RP2040)
 #if defined(ESP32)
 #include "esp32.h"
+#else
+#include "rp2040.h"
+#endif
 
 void setBootLoader(bus *const b);
 
@@ -498,9 +502,85 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
 
 			*cnsl->get_running_flag() = false;
 
-			if (!single_step) {
-				auto speed = c->get_mips_rel_speed();
-				cnsl->debug("MIPS: %.2f, relative speed: %.2f%%, instructions executed: %lu", std::get<0>(speed), std::get<1>(speed), std::get<2>(speed));
+			c->reset();
+#endif
+			continue;
+		}
+#if defined(ESP32) || define(RP2040)
+		else if (cmd == "cfgdisk") {
+			configure_disk(cnsl);
+
+			continue;
+		}
+#endif
+#if defined(ESP32)
+		else if (cmd == "cfgnet") {
+			configure_network(cnsl);
+
+			continue;
+		}
+		else if (cmd == "startnet") {
+			start_network(cnsl);
+
+			continue;
+		}
+#endif
+		else if (cmd == "quit" || cmd == "q") {
+#if defined(ESP32)
+			ESP.restart();
+#endif
+			break;
+		}
+		else if (cmd == "help" || cmd == "h" || cmd == "?") {
+			cnsl->put_string_lf("disassemble/d - show current instruction (pc=/n=)");
+			cnsl->put_string_lf("go            - run until trap or ^e");
+#if !defined(ESP32) && !define(RP2040)
+			cnsl->put_string_lf("quit/q        - stop emulator");
+#endif
+			cnsl->put_string_lf("examine/e     - show memory address (<b|w> <octal address> [<n>])");
+			cnsl->put_string_lf("reset/r       - reset cpu/bus/etc");
+			cnsl->put_string_lf("single/s      - run 1 instruction (implicit 'disassemble' command)");
+			cnsl->put_string_lf("sbp/cbp/lbp   - set/clear/list breakpoint(s)");
+			cnsl->put_string_lf("trace/t       - toggle tracing");
+			cnsl->put_string_lf("strace        - start tracing from address - invoke without address to disable");
+			cnsl->put_string_lf("mmudump       - dump MMU settings (PARs/PDRs)");
+			cnsl->put_string_lf("setpc         - set PC to value");
+			cnsl->put_string_lf("setmem        - set memory (a=) to value (v=), both in octal, one byte");
+			cnsl->put_string_lf("toggle        - set switch (s=, 0...15 (decimal)) of the front panel to state (t=, 0 or 1)");
+#if defined(ESP32)
+			cnsl->put_string_lf("cfgnet        - configure network (e.g. WiFi)");
+			cnsl->put_string_lf("startnet      - start network");
+#endif
+#if defined(ESP32) || define(RP2040)
+			cnsl->put_string_lf("cfgdisk       - configure disk");
+#endif
+
+			continue;
+		}
+		else {
+			cnsl->put_string_lf("?");
+			continue;
+		}
+
+		c->emulation_start();
+
+		*cnsl->get_running_flag() = true;
+
+		while(*stop_event == EVENT_NONE) {
+			if (!single_step)
+				DOLOG(debug, false, "---");
+
+			c->step_a();
+
+			if (trace_start_addr != -1 && c->getPC() == trace_start_addr)
+				tracing = true;
+
+			if (tracing || single_step)
+				disassemble(c, single_step ? cnsl : nullptr, c->getPC(), false);
+
+			if (c->check_breakpoint() && !single_step) {
+				cnsl->put_string_lf("Breakpoint");
+				break;
 			}
 
 			if (*stop_event == EVENT_INTERRUPT) {