From 517f2afb9b954ffa42d410387651af62002e3c6c Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Mon, 11 Apr 2022 14:06:35 +0200 Subject: [PATCH] changes to make it compile on ESP32 (does currently not support "std::optional") --- ESP32/platformio.ini | 10 ++--- cpu.cpp | 100 +++++++++++++++++++++---------------------- cpu.h | 10 ++++- 3 files changed, 61 insertions(+), 59 deletions(-) diff --git a/ESP32/platformio.ini b/ESP32/platformio.ini index 93ccaf2..7fa928b 100644 --- a/ESP32/platformio.ini +++ b/ESP32/platformio.ini @@ -2,13 +2,9 @@ default_envs = serial32 src_dir = . -[env] -framework = arduino -lib_ldf_mode = deep+ -lib_deps = -src_filter = +<*> -<.git/> -<.svn/> - - - - - - - [env:serial32] +lib_ldf_mode = deep+ +src_filter = +<*> -<.git/> -<.svn/> - - - - - - platform = espressif32 board = wemos_d1_mini32 framework = arduino @@ -16,5 +12,5 @@ monitor_speed = 115200 upload_speed = 1000000 lib_deps = greiman/SdFat@^2.1.2 adafruit/Adafruit NeoPixel@^1.10.4 -build_flags = -std=c++17 -Ofast -DESP32=1 +build_flags = -std=gnu++17 -Ofast -DESP32=1 build_unflags = -std=gnu++11 -Os diff --git a/cpu.cpp b/cpu.cpp index 82c4551..3bec634 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -1433,7 +1433,7 @@ void cpu::trap(const uint16_t vector, const int new_ipl) D(fprintf(stderr, "TRAP %o: PC is now %06o, PSW is now %06o\n", vector, getPC(), new_psw);) } -std::tuple, uint16_t> cpu::addressing_to_string(const uint8_t mode_register, const uint16_t pc, const bool word_mode) const +cpu::operand_parameters cpu::addressing_to_string(const uint8_t mode_register, const uint16_t pc, const bool word_mode) const { assert(mode_register < 64); @@ -1453,43 +1453,43 @@ std::tuple, uint16_t> cpu::addressing_ switch(mode_register >> 3) { case 0: - return { reg_name, 2, { }, uint16_t(getRegister(reg) & mask) }; + return { reg_name, 2, -1, uint16_t(getRegister(reg) & mask) }; case 1: - return { format("(%s)", reg_name.c_str()), 2, { }, uint16_t(b->readWord(getRegister(reg)) & mask) }; + return { format("(%s)", reg_name.c_str()), 2, -1, uint16_t(b->readWord(getRegister(reg)) & mask) }; case 2: if (reg == 7) - return { format("#%06o", next_word), 4, next_word, uint16_t(next_word & mask) }; + return { format("#%06o", next_word), 4, int(next_word), uint16_t(next_word & mask) }; - return { format("(%s)+", reg_name.c_str()), 2, { }, uint16_t(b->readWord(getRegister(reg)) & mask) }; + return { format("(%s)+", reg_name.c_str()), 2, -1, uint16_t(b->readWord(getRegister(reg)) & mask) }; case 3: if (reg == 7) - return { format("@#%06o", next_word), 4, next_word, uint16_t(b->readWord(next_word) & mask) }; + return { format("@#%06o", next_word), 4, int(next_word), uint16_t(b->readWord(next_word) & mask) }; - return { format("@(%s)+", reg_name.c_str()), 2, { }, uint16_t(b->readWord(b->readWord(getRegister(reg))) & mask) }; + return { format("@(%s)+", reg_name.c_str()), 2, -1, uint16_t(b->readWord(b->readWord(getRegister(reg))) & mask) }; case 4: - return { format("-(%s)", reg_name.c_str()), 2, { }, uint16_t(b->readWord(getRegister(reg) - (word_mode == false || reg >= 6 ? 2 : 1)) & mask) }; + return { format("-(%s)", reg_name.c_str()), 2, -1, uint16_t(b->readWord(getRegister(reg) - (word_mode == false || reg >= 6 ? 2 : 1)) & mask) }; case 5: - return { format("@-(%s)", reg_name.c_str()), 2, { }, uint16_t(b->readWord(b->readWord(getRegister(reg) - 2)) & mask) }; + return { format("@-(%s)", reg_name.c_str()), 2, -1, uint16_t(b->readWord(b->readWord(getRegister(reg) - 2)) & mask) }; case 6: if (reg == 7) - return { format("%06o", (pc + next_word + 2) & 65535), 4, next_word, uint16_t(b->readWord(getRegister(reg) + next_word) & mask) }; + return { format("%06o", (pc + next_word + 2) & 65535), 4, int(next_word), uint16_t(b->readWord(getRegister(reg) + next_word) & mask) }; - return { format("%o(%s)", next_word, reg_name.c_str()), 4, next_word, uint16_t(b->readWord(getRegister(reg) + next_word) & mask) }; + return { format("%o(%s)", next_word, reg_name.c_str()), 4, int(next_word), uint16_t(b->readWord(getRegister(reg) + next_word) & mask) }; case 7: if (reg == 7) - return { format("@%06o", next_word), 4, next_word, uint16_t(b->readWord(b->readWord(getRegister(reg) + next_word)) & mask) }; + return { format("@%06o", next_word), 4, int(next_word), uint16_t(b->readWord(b->readWord(getRegister(reg) + next_word)) & mask) }; - return { format("@%o(%s)", next_word, reg_name.c_str()), 4, next_word, uint16_t(b->readWord(b->readWord(getRegister(reg) + next_word)) & mask) }; + return { format("@%o(%s)", next_word, reg_name.c_str()), 4, int(next_word), uint16_t(b->readWord(b->readWord(getRegister(reg) + next_word)) & mask) }; } - return { "??", 0, { }, 0123456 }; + return { "??", 0, -1, 0123456 }; } std::map > cpu::disassemble(const uint16_t addr) const @@ -1521,18 +1521,18 @@ std::map > cpu::disassemble(const uint16_t // TODO: 100000011 if (do_opcode == 0b000) { - auto dst_text = addressing_to_string(dst_register, (pc + 2) & 65535, word_mode); + auto dst_text { addressing_to_string(dst_register, (pc + 2) & 65535, word_mode) }; - auto next_word = std::get<2>(dst_text); - if (next_word.has_value()) - instruction_words.push_back(next_word.value()); + auto next_word = dst_text.instruction_part; + if (next_word != -1) + instruction_words.push_back(next_word); - work_values.push_back(std::get<3>(dst_text)); + work_values.push_back(dst_text.work_value); // single_operand_instructions switch(so_opcode) { case 0b00000011: - text = "SWAB " + std::get<0>(dst_text); + text = "SWAB " + dst_text.operand; break; case 0b000101000: @@ -1605,17 +1605,17 @@ std::map > cpu::disassemble(const uint16_t } if (text.empty() && name.empty() == false) - text = name + word_mode_str + space + std::get<0>(dst_text); + text = name + word_mode_str + space + dst_text.operand; } else if (do_opcode == 0b111) { std::string src_text = format("R%d", (instruction >> 6) & 7); - auto dst_text = addressing_to_string(dst_register, (pc + 2) & 65535, word_mode); + auto dst_text { addressing_to_string(dst_register, (pc + 2) & 65535, word_mode) }; - auto next_word = std::get<2>(dst_text); - if (next_word.has_value()) - instruction_words.push_back(next_word.value()); + auto next_word = dst_text.instruction_part; + if (next_word != -1) + instruction_words.push_back(next_word); - work_values.push_back(std::get<3>(dst_text)); + work_values.push_back(dst_text.work_value); switch(ado_opcode) { // additional double operand case 0: @@ -1644,7 +1644,7 @@ std::map > cpu::disassemble(const uint16_t } if (text.empty() && name.empty() == false) - text = name + space + src_text + comma + std::get<0>(dst_text); + text = name + space + src_text + comma + dst_text.operand; } else { switch(do_opcode) { @@ -1677,24 +1677,24 @@ std::map > cpu::disassemble(const uint16_t } // source - auto src_text = addressing_to_string(src_register, (pc + 2) & 65535, word_mode); + auto src_text { addressing_to_string(src_register, (pc + 2) & 65535, word_mode) }; - auto next_word_src = std::get<2>(src_text); - if (next_word_src.has_value()) - instruction_words.push_back(next_word_src.value()); + auto next_word_src = src_text.instruction_part; + if (next_word_src != -1) + instruction_words.push_back(next_word_src); - work_values.push_back(std::get<3>(src_text)); + work_values.push_back(src_text.work_value); // destination - auto dst_text = addressing_to_string(dst_register, (pc + std::get<1>(src_text)) & 65535, word_mode); + auto dst_text { addressing_to_string(dst_register, (pc + src_text.length) & 65535, word_mode) }; - auto next_word_dst = std::get<2>(dst_text); - if (next_word_dst.has_value()) - instruction_words.push_back(next_word_dst.value()); + auto next_word_dst = dst_text.instruction_part; + if (next_word_dst != -1) + instruction_words.push_back(next_word_dst); - work_values.push_back(std::get<3>(dst_text)); + work_values.push_back(dst_text.work_value); - text = name + word_mode_str + space + std::get<0>(src_text) + comma + std::get<0>(dst_text); + text = name + word_mode_str + space + src_text.operand + comma + dst_text.operand; } if (text.empty()) { // conditional branch instructions @@ -1837,27 +1837,27 @@ std::map > cpu::disassemble(const uint16_t text = format("TRAP %o", instruction & 255); if ((instruction & ~0b111111) == 0b0000000001000000) { - auto dst_text = addressing_to_string(dst_register, (pc + 2) & 65535, word_mode); + auto dst_text { addressing_to_string(dst_register, (pc + 2) & 65535, word_mode) }; - auto next_word = std::get<2>(dst_text); - if (next_word.has_value()) - instruction_words.push_back(next_word.value()); + auto next_word = dst_text.instruction_part; + if (next_word != -1) + instruction_words.push_back(next_word); - work_values.push_back(std::get<3>(dst_text)); + work_values.push_back(dst_text.work_value); - text = std::string("JMP ") + std::get<0>(dst_text); + text = std::string("JMP ") + dst_text.operand; } if ((instruction & 0b1111111000000000) == 0b0000100000000000) { - auto dst_text = addressing_to_string(dst_register, (pc + 2) & 65535, word_mode); + auto dst_text { addressing_to_string(dst_register, (pc + 2) & 65535, word_mode) }; - auto next_word = std::get<2>(dst_text); - if (next_word.has_value()) - instruction_words.push_back(next_word.value()); + auto next_word = dst_text.instruction_part; + if (next_word != -1) + instruction_words.push_back(next_word); - work_values.push_back(std::get<3>(dst_text)); + work_values.push_back(dst_text.work_value); - text = format("JSR R%d,", src_register & 7) + std::get<0>(dst_text); + text = format("JSR R%d,", src_register & 7) + dst_text.operand; } if ((instruction & 0b1111111111111000) == 0b0000000010000000) diff --git a/cpu.h b/cpu.h index 6d79d37..3f80277 100644 --- a/cpu.h +++ b/cpu.h @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -51,7 +50,14 @@ private: bool condition_code_operations(const uint16_t instr); bool misc_operations(const uint16_t instr); - std::tuple, uint16_t> addressing_to_string(const uint8_t mode_register, const uint16_t pc, const bool word_mode) const; + struct operand_parameters { + std::string operand; + int length; + int instruction_part; + uint16_t work_value; + }; + + operand_parameters addressing_to_string(const uint8_t mode_register, const uint16_t pc, const bool word_mode) const; std::map > disassemble(const uint16_t addr) const; void disassemble(void) const;