diff --git a/bus.cpp b/bus.cpp index dcf7897..2f96e8c 100644 --- a/bus.cpp +++ b/bus.cpp @@ -17,7 +17,7 @@ // see also https://github.com/espressif/esp-idf/issues/1934 constexpr int n_pages = 12; #else -constexpr int n_pages = 16; +constexpr int n_pages = 32; #endif constexpr uint16_t di_ena_mask[4] = { 4, 2, 0, 1 }; @@ -867,7 +867,29 @@ void bus::write(const uint16_t a, const bool word_mode, uint16_t value, const bo void bus::writePhysical(const uint32_t a, const uint16_t value) { DOLOG(debug, true, "physicalWRITE %06o to %o", value, a); - m->writeWord(a, value); + + if (a >= n_pages * 8192) { + DOLOG(debug, true, "physicalWRITE to %o: trap 004", a); + c->schedule_trap(004); + } + else { + m->writeWord(a, value); + } +} + +uint16_t bus::readPhysical(const uint32_t a) +{ + if (a >= n_pages * 8192) { + DOLOG(debug, true, "physicalREAD from %o: trap 004", a); + c->schedule_trap(004); + + return 0; + } + else { + uint16_t value = m->readWord(a); + DOLOG(debug, true, "physicalREAD %06o from %o", value, a); + return value; + } } uint16_t bus::readWord(const uint16_t a, const d_i_space_t s) diff --git a/bus.h b/bus.h index 9a07fef..bfb0bbc 100644 --- a/bus.h +++ b/bus.h @@ -130,6 +130,7 @@ public: void writeByte(const uint16_t a, const uint8_t value) { return write(a, true, value, false); } void writeWord(const uint16_t a, const uint16_t value); + uint16_t readPhysical(const uint32_t a); void writePhysical(const uint32_t a, const uint16_t value); void writeUnibusByte(const uint16_t a, const uint8_t value); diff --git a/cpu.cpp b/cpu.cpp index 0950aff..7ccc82a 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -10,6 +10,8 @@ #include "log.h" #include "utils.h" +uint16_t oldpc = 0; + #define SIGN(x, wm) ((wm) ? (x) & 0x80 : (x) & 0x8000) #define IS_0(x, wm) ((wm) ? ((x) & 0xff) == 0 : (x) == 0) @@ -88,7 +90,7 @@ void cpu::reset() memset(regs0_5, 0x00, sizeof regs0_5); memset(sp, 0x00, sizeof sp); pc = 0; - psw = 7 << 5; + psw = 0; // 7 << 5; fpsr = 0; init_interrupt_queue(); } @@ -605,7 +607,8 @@ bool cpu::double_operand_instructions(const uint16_t instr) result = (dst_value - ssrc_value) & 0xffff; if (set_flags) { - setPSW_v(sign(ssrc_value) != sign(dst_value) && sign(ssrc_value) == sign(result)); + //setPSW_v(sign(ssrc_value) != sign(dst_value) && sign(ssrc_value) == sign(result)); + setPSW_v(((ssrc_value ^ dst_value) & 0x8000) && !((dst_value ^ result) & 0x8000)); setPSW_c(uint16_t(dst_value) < uint16_t(ssrc_value)); } } @@ -1346,14 +1349,27 @@ bool cpu::single_operand_instructions(const uint16_t instr) set_flags = a != ADDR_PSW; - // read from previous space - v = b -> read(a, false, true); + if (a >= 0160000) { + // read from previous space + v = b -> read(a, false, true); + } + else { + auto phys = b->calculate_physical_address((getPSW() >> 12) & 3, a); + + //b->check_address(true, true, phys, false, word_mode, (getPSW() >> 12) & 3); + + extern FILE *lfh; + fflush(lfh); + + v = b->readPhysical(word_mode ? phys.physical_data : phys.physical_instruction); + } } if (set_flags) { - setPSW_n(SIGN(v, false)); + setPSW_c(true); setPSW_z(v == 0); - setPSW_v(false); + setPSW_n(SIGN(v, false)); + // deze niet? setPSW_v(false); } // put on current stack @@ -1388,16 +1404,27 @@ bool cpu::single_operand_instructions(const uint16_t instr) DOLOG(debug, true, "MTPI/D %06o -> %o / %o", a, phys.physical_instruction, phys.physical_data); - b->check_address(true, true, phys, false, word_mode, (getPSW() >> 12) & 3); +// FILE *fh = fopen("og2-kek.dat", "a+"); +// fprintf(fh, "%lu %06o MTPI %06o: %06o\n", mtpi_count, oldpc, a, v); +// fclose(fh); + DOLOG(debug, true, "%lu %06o MTPI %06o: %06o", mtpi_count, oldpc, a, v); + + mtpi_count++; + + //b->check_address(true, true, phys, false, word_mode, (getPSW() >> 12) & 3); + + extern FILE *lfh; + fflush(lfh); b->writePhysical(word_mode ? phys.physical_data : phys.physical_instruction, v); } } if (set_flags) { - setPSW_n(SIGN(v, false)); + setPSW_c(true); setPSW_z(v == 0); - setPSW_v(false); + setPSW_n(SIGN(v, false)); + // deze niet? setPSW_v(false); } break; @@ -2281,6 +2308,7 @@ void cpu::step_b() instruction_count++; uint16_t temp_pc = getPC(); + oldpc = temp_pc; if ((b->getMMR0() & 0160000) == 0) b->setMMR2(temp_pc); diff --git a/cpu.h b/cpu.h index b5355f9..ec10c89 100644 --- a/cpu.h +++ b/cpu.h @@ -26,6 +26,8 @@ private: uint64_t running_since { 0 }; bool mode11_70 { true }; + uint64_t mtpi_count { 0 }; + // level, vector std::map > queued_interrupts; std::mutex qi_lock; diff --git a/debugger.cpp b/debugger.cpp index bc9ec4d..cba1882 100644 --- a/debugger.cpp +++ b/debugger.cpp @@ -49,6 +49,17 @@ int disassemble(cpu *const c, console *const cnsl, const int pc, const bool inst instruction.c_str(), MMR0.c_str(), MMR2.c_str() ); + { + std::string temp = format("R0: %s, R1: %s, R2: %s, R3: %s, R4: %s, R5: %s, SP: %s, PC: %06o, PSW: %s, instr: %s", + registers[0].c_str(), registers[1].c_str(), registers[2].c_str(), registers[3].c_str(), registers[4].c_str(), registers[5].c_str(), registers[6].c_str(), pc, + psw.c_str(), + data["instruction-values"][0].c_str() + ); + + FILE *fh = fopen("compare.dat", "a+"); + fprintf(fh, "%s\n", temp.c_str()); + fclose(fh); + } if (cnsl) cnsl->debug(result); diff --git a/loaders.cpp b/loaders.cpp index e6f566b..01079ba 100644 --- a/loaders.cpp +++ b/loaders.cpp @@ -26,11 +26,13 @@ void setBootLoader(bus *const b, const bootloader_t which) cpu *const c = b -> getCpu(); uint16_t offset = 0; + uint16_t start = 0; const uint16_t *bl = nullptr; int size = 0; if (which == BL_RK05) { - offset = 01000; + /* + start = offset = 01000; static uint16_t rk05_code[] = { 0012700, @@ -43,13 +45,44 @@ void setBootLoader(bus *const b, const bootloader_t which) 0100376, 0005007 }; + */ + + // from https://github.com/amakukha/PyPDP11.git + offset = 02000; + start = 02002; + + static uint16_t rk05_code[] = { + 0042113, // "KD" + 0012706, 02000, // MOV #boot_start, SP + 0012700, 0000000, // MOV #unit, R0 ; unit number + 0010003, // MOV R0, R3 + 0000303, // SWAB R3 + 0006303, // ASL R3 + 0006303, // ASL R3 + 0006303, // ASL R3 + 0006303, // ASL R3 + 0006303, // ASL R3 + 0012701, 0177412, // MOV #RKDA, R1 ; csr + 0010311, // MOV R3, (R1) ; load da + 0005041, // CLR -(R1) ; clear ba + 0012741, 0177000, // MOV #-256.*2, -(R1) ; load wc + 0012741, 0000005, // MOV #READ+GO, -(R1) ; read & go + 0005002, // CLR R2 + 0005003, // CLR R3 + 0012704, 02020, // MOV #START+20, R4 + 0005005, // CLR R5 + 0105711, // TSTB (R1) + 0100376, // BPL .-2 + 0105011, // CLRB (R1) + 0005007 // CLR PC + }; bl = rk05_code; - size = 9; + size = sizeof(rk05_code)/sizeof(rk05_code[0]); } else if (which == BL_RL02) { - offset = 01000; + start = offset = 01000; /* from https://www.pdp-11.nl/peripherals/disk/rl-info.html static uint16_t rl02_code[] = { @@ -93,7 +126,7 @@ void setBootLoader(bus *const b, const bootloader_t which) 0005007, }; - size = 10; + size = sizeof(rl02_code)/sizeof(rl02_code[0]); bl = rl02_code; } @@ -101,7 +134,7 @@ void setBootLoader(bus *const b, const bootloader_t which) for(int i=0; i writeWord(offset + i * 2, bl[i]); - c -> setRegister(7, offset); + c -> setRegister(7, start); } uint16_t loadTape(bus *const b, const std::string & file) diff --git a/log.cpp b/log.cpp index e277e41..c4e375a 100644 --- a/log.cpp +++ b/log.cpp @@ -13,7 +13,7 @@ static const char *logfile = strdup("/tmp/myip.log"); log_level_t log_level_file = warning; log_level_t log_level_screen = warning; -static FILE *lfh = nullptr; +FILE *lfh = nullptr; static int lf_uid = -1; static int lf_gid = -1;