ram size configurable at run time

This commit is contained in:
folkert van heusden 2024-04-17 21:49:35 +02:00
parent fdc39bc2af
commit 92c5c2c573
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
3 changed files with 45 additions and 11 deletions

26
bus.cpp
View file

@ -14,18 +14,10 @@
#include "tty.h"
#include "utils.h"
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
#if defined(ESP32)
#include <esp_debug_helpers.h>
#endif
// 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
constexpr int n_pages = 31; // 30=240kB (for EKBEEx.BIC)
#endif
constexpr const int di_ena_mask[4] = { 4, 2, 0, 1 };
bus::bus()
@ -49,6 +41,18 @@ bus::~bus()
delete m;
}
void bus::set_memory_size(const int n_pages)
{
this->n_pages = n_pages;
uint32_t n_bytes = n_pages * 8192l;
delete m;
m = new memory(n_bytes);
DOLOG(info, false, "Memory is now %u kB in size", n_bytes / 1024);
}
void bus::reset()
{
m->reset();
@ -403,7 +407,7 @@ uint16_t bus::read(const uint16_t addr_in, const word_mode_t word_mode, const rm
}
// LO size register field must be all 1s, so subtract 1
constexpr uint32_t system_size = n_pages * 8192l / 64 - 1;
uint32_t system_size = n_pages * 8192l / 64 - 1;
if (a == ADDR_SYSSIZE + 2) { // system size HI
uint16_t temp = system_size >> 16;
@ -434,7 +438,7 @@ uint16_t bus::read(const uint16_t addr_in, const word_mode_t word_mode, const rm
return 0;
}
if (m_offset >= n_pages * 8192) {
if (m_offset >= uint32_t(n_pages * 8192)) {
if (peek_only) {
DOLOG(debug, false, "READ from %06o - out of range!", addr_in);
return 0;
@ -1063,7 +1067,7 @@ write_rc_t bus::write(const uint16_t addr_in, const word_mode_t word_mode, uint1
DOLOG(debug, false, "WRITE to %06o/%07o %c %c: %06o", addr_in, m_offset, space == d_space ? 'D' : 'I', word_mode == wm_byte ? 'B' : 'W', value);
if (m_offset >= n_pages * 8192) {
if (m_offset >= uint32_t(n_pages * 8192)) {
c->trap(004); // no such RAM
throw 1;
}

11
bus.h
View file

@ -16,6 +16,13 @@
#include "rp2040.h"
#endif
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
// ESP32 goes in a crash-loop when allocating 128kB
// see also https://github.com/espressif/esp-idf/issues/1934
#define DEFAULT_N_PAGES 12
#else
#define DEFAULT_N_PAGES 31
#endif
#define ADDR_MMR0 0177572
#define ADDR_MMR1 0177574
@ -97,6 +104,7 @@ private:
rl02 *rl02_ { nullptr };
tty *tty_ { nullptr };
int n_pages { DEFAULT_N_PAGES };
memory *m { nullptr };
// 8 pages, D/I, 3 modes and 1 invalid mode
@ -132,6 +140,9 @@ public:
uint16_t get_console_switches() { return console_switches; }
void set_debug_mode() { console_switches |= 128; }
int get_memory_size() const { return n_pages; }
void set_memory_size(const int n_pages);
void mmudebug(const uint16_t a);
uint16_t get_console_leds() { return console_leds; }

View file

@ -987,6 +987,23 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
continue;
}
else if (parts[0] == "ramsize") {
if (parts.size() == 2)
b->set_memory_size(std::stoi(parts.at(1)));
else {
int n_pages = b->get_memory_size();
cnsl->put_string_lf(format("Memory size: %u pages or %u kB (decimal)", n_pages, n_pages * 8192 / 1024));
}
continue;
}
else if (parts[0] == "bl" && parts.size() == 2) {
setBootLoader(b, parts.at(1) == "rk05" ? BL_RK05 : BL_RL02);
cnsl->put_string_lf("Bootloader set");
continue;
}
else if (parts[0] == "trl") {
if (parts.size() == 1)
t_rl.reset();
@ -1066,6 +1083,8 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
"toggle - set switch (s=, 0...15 (decimal)) of the front panel to state (t=, 0 or 1)",
"cls - clear screen",
"stats - show run statistics",
"ramsize - set ram size (page count (8 kB))",
"bl - set bootload (rl02 or rk05)",
#if defined(ESP32)
"cfgnet - configure network (e.g. WiFi)",
"startnet - start network",