Skip to content

Commit

Permalink
Merge branch 'DC11'
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertvanheusden committed May 4, 2024
2 parents f0ae90e + 2fb3b0b commit 9c3acb5
Show file tree
Hide file tree
Showing 11 changed files with 441 additions and 40 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ add_executable(
console_ncurses.cpp
console_posix.cpp
cpu.cpp
dc11.cpp
debugger.cpp
disk_backend.cpp
disk_backend_file.cpp
Expand Down
1 change: 1 addition & 0 deletions ESP32/dc11.cpp
1 change: 1 addition & 0 deletions ESP32/dc11.h
45 changes: 27 additions & 18 deletions ESP32/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ void start_network(console *const c)

c->put_string_lf("");
c->put_string_lf(format("Local IP address: %s", WiFi.localIP().toString().c_str()));

static bool dc11_loaded = false;
if (!dc11_loaded) {
dc11_loaded = true;

Serial.println(F("* Adding DC11"));
dc11 *dc11_ = new dc11(1100, b);
b->add_DC11(dc11_);
}
}

void recall_configuration(console *const cnsl)
Expand Down Expand Up @@ -245,7 +254,6 @@ void setup() {
Serial.println(getCpuFrequencyMhz());
#endif

#if 1
#if defined(BUILD_FOR_RP2040)
SPI.setRX(MISO);
SPI.setTX(MOSI);
Expand All @@ -258,7 +266,6 @@ void setup() {
Serial.println(F("Cannot initialize SD card"));
}
#endif
#endif

#if defined(BUILD_FOR_RP2040)
LittleFSConfig cfg;
Expand All @@ -270,37 +277,40 @@ void setup() {
Serial.println(F("LittleFS.begin() failed"));
#endif

Serial.println(F("* Init bus"));
b = new bus();

Serial.println(F("* Allocate memory"));
uint32_t n_pages = DEFAULT_N_PAGES;

#if !defined(BUILD_FOR_RP2040)
Serial.print(F("Free RAM after init (decimal bytes): "));
Serial.println(ESP.getFreeHeap());

if (psramInit()) {
uint32_t free_psram = ESP.getFreePsram();
Serial.printf("Free PSRAM: %d decimal bytes (or %d pages (see 'ramsize' in the debugger))", free_psram, free_psram / 8192l);
n_pages = min(free_psram / 8192, uint32_t(128)); // start size is 1 MB max.
Serial.printf("Free PSRAM: %d decimal bytes (or %d pages (see 'ramsize' in the debugger))", free_psram, n_pages);
Serial.println(F(""));
}
#endif

Serial.println(F("Init bus"));
b = new bus();

Serial.println(F("Allocate memory"));
b->set_memory_size(DEFAULT_N_PAGES);
Serial.printf("Allocating %d (decimal) pages", n_pages);
b->set_memory_size(n_pages);
Serial.println(F(""));

Serial.println(F("Init CPU"));
Serial.println(F("* Init CPU"));
c = new cpu(b, &stop_event);

Serial.println(F("Connect CPU to BUS"));
b->add_cpu(c);

#if !defined(BUILD_FOR_RP2040) && defined(CONSOLE_SERIAL_RX)
constexpr uint32_t hwSerialConfig = SERIAL_8N1;
uint32_t bitrate = load_serial_speed_configuration();

Serial.print(F("Init console, baudrate: "));
Serial.print(F("* Init console, baudrate: "));
Serial.print(bitrate);
Serial.println(F("bps"));

#if !defined(BUILD_FOR_RP2040) && defined(CONSOLE_SERIAL_RX)
Serial_RS232.begin(bitrate, hwSerialConfig, CONSOLE_SERIAL_RX, CONSOLE_SERIAL_TX);
Serial_RS232.setHwFlowCtrlMode(0);

Expand All @@ -320,7 +330,7 @@ void setup() {

running = cnsl->get_running_flag();

Serial.println(F("Connect RK05 and RL02 devices to BUS"));
Serial.println(F("* Connect RK05 and RL02 devices to BUS"));
auto rk05_dev = new rk05(b, cnsl->get_disk_read_activity_flag(), cnsl->get_disk_write_activity_flag());
rk05_dev->begin();
b->add_rk05(rk05_dev);
Expand All @@ -329,12 +339,11 @@ void setup() {
rl02_dev->begin();
b->add_rl02(rl02_dev);

Serial.println(F("Init TTY"));
Serial.println(F("* Adding TTY"));
tty_ = new tty(cnsl, b);
Serial.println(F("Connect TTY to bus"));
b->add_tty(tty_);

#if !defined(BUILD_FOR_RP2040) // FIXME: led ring
#if !defined(BUILD_FOR_RP2040) && defined(NEOPIXELS_PIN)
Serial.println(F("Starting panel"));
xTaskCreate(&console_thread_wrapper_panel, "panel", 3072, cnsl, 1, nullptr);
#endif
Expand All @@ -351,7 +360,7 @@ void setup() {

Serial.flush();

Serial.println(F("Starting I/O"));
Serial.println(F("* Starting console"));
cnsl->start_thread();

cnsl->put_string_lf("PDP-11/70 emulator, (C) Folkert van Heusden");
Expand Down
44 changes: 25 additions & 19 deletions bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "bus.h"
#include "gen.h"
#include "cpu.h"
#include "dc11.h"
#include "kw11-l.h"
#include "log.h"
#include "memory.h"
Expand Down Expand Up @@ -40,6 +41,7 @@ bus::~bus()
delete tty_;
delete mmu_;
delete m;
delete dc11_;
}

#if IS_POSIX
Expand Down Expand Up @@ -68,7 +70,7 @@ json_t *bus::serialize() const
if (rk05_)
json_object_set(j_out, "rk05", rk05_->serialize());

// TODO: tm11
// TODO: tm11, dc11

return j_out;
}
Expand Down Expand Up @@ -122,7 +124,7 @@ bus *bus::deserialize(const json_t *const j, console *const cnsl, std::atomic_ui
b->add_rk05(rk05_);
}

// TODO: tm11
// TODO: tm11, dc11

return b;
}
Expand Down Expand Up @@ -158,6 +160,8 @@ void bus::reset()
tty_->reset();
if (kw11_l_)
kw11_l_->reset();
if (dc11_)
dc11_->reset();
}

void bus::add_KW11_L(kw11_l *const kw11_l_)
Expand Down Expand Up @@ -207,7 +211,13 @@ void bus::add_rl02(rl02 *const rl02_)
void bus::add_tty(tty *const tty_)
{
delete this->tty_;
this->tty_ = tty_;
this->tty_ = tty_;
}

void bus::add_DC11(dc11 *const dc11_)
{
delete this->dc11_;
this->dc11_ = dc11_;
}

void bus::init()
Expand Down Expand Up @@ -449,29 +459,20 @@ uint16_t bus::read(const uint16_t addr_in, const word_mode_t word_mode, const rm
}
}

if (tm11 && a >= TM_11_BASE && a < TM_11_END && !peek_only) {
TRACE("READ-I/O TM11 register %d", (a - TM_11_BASE) / 2);

if (tm11 && a >= TM_11_BASE && a < TM_11_END && !peek_only)
return word_mode == wm_byte ? tm11->read_byte(a) : tm11->read_word(a);
}

if (rk05_ && a >= RK05_BASE && a < RK05_END && !peek_only) {
TRACE("READ-I/O RK05 register %d", (a - RK05_BASE) / 2);

if (rk05_ && a >= RK05_BASE && a < RK05_END && !peek_only)
return word_mode == wm_byte ? rk05_->read_byte(a) : rk05_->read_word(a);
}

if (rl02_ && a >= RL02_BASE && a < RL02_END && !peek_only) {
TRACE("READ-I/O RL02 register %d", (a - RL02_BASE) / 2);

if (rl02_ && a >= RL02_BASE && a < RL02_END && !peek_only)
return word_mode == wm_byte ? rl02_->read_byte(a) : rl02_->read_word(a);
}

if (tty_ && a >= PDP11TTY_BASE && a < PDP11TTY_END && !peek_only) {
TRACE("READ-I/O TTY register %d", (a - PDP11TTY_BASE) / 2);

if (tty_ && a >= PDP11TTY_BASE && a < PDP11TTY_END && !peek_only)
return word_mode == wm_byte ? tty_->read_byte(a) : tty_->read_word(a);
}

if (dc11_ && a >= DC11_BASE && a < DC11_END && !peek_only)
return word_mode == wm_byte ? dc11_->read_byte(a) : dc11_->read_word(a);

// LO size register field must be all 1s, so subtract 1
uint32_t system_size = m->get_memory_size() / 64 - 1;
Expand Down Expand Up @@ -724,6 +725,11 @@ write_rc_t bus::write(const uint16_t addr_in, const word_mode_t word_mode, uint1
return { false };
}

if (dc11_ && a >= DC11_BASE && a < DC11_END) {
word_mode == wm_byte ? dc11_->write_byte(a, value) : dc11_->write_word(a, value);
return { false };
}

if (a >= 0172100 && a <= 0172137) { // MM11-LP parity
TRACE("WRITE-I/O MM11-LP parity (%06o): %o", a, value);
return { false };
Expand Down
4 changes: 4 additions & 0 deletions bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdio.h>

#include "gen.h"
#include "dc11.h"
#include "mmu.h"
#include "rk05.h"
#include "rl02.h"
Expand Down Expand Up @@ -67,6 +68,7 @@ class bus
kw11_l *kw11_l_ { nullptr };
mmu *mmu_ { nullptr };
memory *m { nullptr };
dc11 *dc11_ { nullptr };

uint16_t microprogram_break_register { 0 };

Expand Down Expand Up @@ -101,6 +103,7 @@ class bus
void add_rl02 (rl02 *const rl02_ );
void add_tty (tty *const tty_ );
void add_KW11_L(kw11_l *const kw11_l_);
void add_DC11 (dc11 *const dc11_ );

memory *getRAM() { return m; }
cpu *getCpu() { return c; }
Expand All @@ -109,6 +112,7 @@ class bus
mmu *getMMU() { return mmu_; }
rk05 *getRK05() { return rk05_; }
rl02 *getRL02() { return rl02_; }
dc11 *getDC11() { return dc11_; }
tm_11 *getTM11() { return tm11; }

uint16_t read(const uint16_t a, const word_mode_t word_mode, const rm_selection_t mode_selection, const bool peek_only=false, const d_i_space_t s = i_space);
Expand Down
4 changes: 2 additions & 2 deletions cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1447,8 +1447,8 @@ bool cpu::single_operand_instructions(const uint16_t instr)
b->getMMU()->mmudebug(a.addr.value());

a.mode_selection = rm_prev;
a.space = word_mode == wm_byte ? d_space : i_space;
set_flags = putGAM(a, v);
a.space = word_mode == wm_byte ? d_space : i_space;
set_flags = putGAM(a, v);
}

if (set_flags)
Expand Down
Loading

0 comments on commit 9c3acb5

Please sign in to comment.