diff --git a/src/asm_pdp8.cpp b/src/asm_pdp8.cpp index 4be6b574..46d64b57 100644 --- a/src/asm_pdp8.cpp +++ b/src/asm_pdp8.cpp @@ -280,7 +280,7 @@ Error AsmPdp8::defineDec6String(StrScanner &scan, Insn &insn) { if (c == 0) return insn.setErrorIf(p, MISSING_CLOSING_DELIMITER); uint8_t dec6 = (c < 0x40) ? c : c - 0x40; - if (c < 0x20 || c >= 0x60) { + if (c <= 0x20 || c >= 0x60) { error.setErrorIf(p, ILLEGAL_CONSTANT); dec6 = 0; } diff --git a/src/dis_pdp8.cpp b/src/dis_pdp8.cpp index 3b2a4e0e..8120c269 100644 --- a/src/dis_pdp8.cpp +++ b/src/dis_pdp8.cpp @@ -42,7 +42,7 @@ void DisPdp8::reset() { Error DisPdp8::decodeImpl(DisMemory &memory, Insn &_insn, StrBuffer &out) const { DisInsn insn(_insn, memory, out); - const auto opc = insn.readUint16(); + const auto opc = insn.readUint12(); insn.setOpCode(opc); if (TABLE.searchOpCode(cpuType(), insn, out)) return _insn.setError(insn); diff --git a/src/insn_pdp8.h b/src/insn_pdp8.h index 7d2ab35f..5dbc9f5c 100644 --- a/src/insn_pdp8.h +++ b/src/insn_pdp8.h @@ -36,11 +36,12 @@ struct EntryInsn : EntryInsnBase { struct AsmInsn final : AsmInsnImpl, EntryInsn { AsmInsn(Insn &insn) : AsmInsnImpl(insn) {} - void emitInsn() { emitUint16(opCode()); } + void emitInsn() { emitUint16(opCode() & 07777); } }; struct DisInsn final : DisInsnImpl, EntryInsn { DisInsn(Insn &insn, DisMemory &memory, const StrBuffer &out) : DisInsnImpl(insn, memory, out) {} + uint16_t readUint12() { return readUint16() & 07777; } }; } // namespace pdp8 diff --git a/test/test_asm_pdp8.cpp b/test/test_asm_pdp8.cpp index 7c954515..d6941716 100644 --- a/test/test_asm_pdp8.cpp +++ b/test/test_asm_pdp8.cpp @@ -52,22 +52,23 @@ void test_cpu() { } void test_memory_reference() { + constexpr uint16_t ZP = 0000; constexpr uint16_t IA = 0400; - ATEST(04000, "AND 0022", 00000|0022); - ATEST(04000, "AND Z 0022", 00000|0022); - ATEST(04000, "AND 0022+7", 00000|0031); - ATEST(04000, "AND I 0043", 00000|0043|IA); - ATEST(04000, "AND I Z 0043", 00000|0043|IA); - ATEST(04000, "TAD 0064", 01000|0064); - ATEST(04000, "TAD I 0105", 01000|0105|IA); - ATEST(04000, "ISZ 0170", 02000|0170); - ATEST(04000, "ISZ I 0147", 02000|0147|IA); - ATEST(04000, "DCA 0170", 03000|0170); - ATEST(04000, "DCA I 0011", 03000|0011|IA); - ATEST(04000, "JMS 0032", 04000|0032); - ATEST(04000, "JMS I 0053", 04000|0053|IA); - ATEST(04000, "JMP 0074", 05000|0074); - ATEST(04000, "JMP I 0115", 05000|0115|IA); + ATEST(04000, "AND 0022", 00000|0022|ZP); + ATEST(04000, "AND Z 0022", 00000|0022|ZP); + ATEST(04000, "AND 0022+7", 00000|0031|ZP); + ATEST(04000, "AND I 0043", 00000|0043|ZP|IA); + ATEST(04000, "AND I Z 0043", 00000|0043|ZP|IA); + ATEST(04000, "TAD 0064", 01000|0064|ZP); + ATEST(04000, "TAD I 0105", 01000|0105|ZP|IA); + ATEST(04000, "ISZ 0170", 02000|0170|ZP); + ATEST(04000, "ISZ I 0147", 02000|0147|ZP|IA); + ATEST(04000, "DCA 0170", 03000|0170|ZP); + ATEST(04000, "DCA I 0011", 03000|0011|ZP|IA); + ATEST(04000, "JMS 0032", 04000|0032|ZP); + ATEST(04000, "JMS I 0053", 04000|0053|ZP|IA); + ATEST(04000, "JMP 0074", 05000|0074|ZP); + ATEST(04000, "JMP I 0115", 05000|0115|ZP|IA); constexpr uint16_t MP = 0200; ATEST(04000, "AND 4022", 00000|0022|MP); @@ -95,12 +96,12 @@ void test_memory_reference() { symtab.intern(04017, "label4017"); symtab.intern(04020, "label4020"); - ATEST(04000, "AND zero020", 00000|0020); - ATEST(04000, "AND z zero020", 00000|0020); - ATEST(04000, "AND i auto017", 00000|0017|IA); - ATEST(04000, "AND i z auto017", 00000|0017|IA); - ATEST(04000, "AND i label4017", 00000|0017|MP|IA); + ATEST(04000, "AND zero020", 00000|0020|ZP); + ATEST(04000, "AND z zero020", 00000|0020|ZP); + ATEST(04000, "AND i auto017", 00000|0017|ZP|IA); + ATEST(04000, "AND i z auto017", 00000|0017|ZP|IA); ATEST(04000, "AND label4020", 00000|0020|MP); + ATEST(04000, "AND i label4017", 00000|0017|MP|IA); } void test_group1() { @@ -720,17 +721,24 @@ void test_data_constant() { TEST(" 10", 00010); ERUS("DUBL UNDEF", "UNDEF", 0, 0); - TEST(R"("A)", 'A'|0200); - TEST(R"("Z)", 'Z'|0200); - TEST(R"("0)", '0'|0200); - TEST(R"("9)", '9'|0200); - TEST(R"("()", '('|0200); - TEST(R"("[)", '['|0200); + TEST(R"("A)", 0301); + TEST(R"("Z)", 0332); + TEST(R"("0)", 0260); + TEST(R"("9)", 0271); + TEST(R"("@)", 0300); + TEST(R"(" )", 0240); + TEST(R"("()", 0250); + TEST(R"("[)", 0333); TEST("TEXT //", 00000); TEST("TEXT ATEXTA", 02405, 03024, 0000); TEST("TEXT /BOB/", 00217, 00200); TEST("TEXT ;BOB;", 00217, 00200); + TEST("TEXT /0123456789:;<=>?/", 06061, 06263, 06465, 06667, 07071, 07273, 07475, 07677, 00000); + TEST(R"(TEXT ;!"#$%&'()*+,-./;)", 04142, 04344, 04546, 04750, 05152, 05354, 05556, 05700); + TEST("TEXT /@ABCDEFGHIJKLMNO/", 00001, 00203, 00405, 00607, 01011, 01213, 01415, 01617, 00000); + TEST(R"(TEXT /PQRSTUVWXYZ[\]^_/)", 02021, 02223, 02425, 02627, 03031, 03233, 03435, 03637, 00000); + ERRT("TEXT /B B/", ILLEGAL_CONSTANT, " B/", 00200, 00200); ERRT("TEXT /BOb/", ILLEGAL_CONSTANT, "b/", 00217, 00000); ERRT("TEXT /(){3/", ILLEGAL_CONSTANT, "{3/", 05051, 00063, 00000);