From 49d68fe54cb4165d89408d6a7b3b6f8104dca9f8 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 19 May 2021 15:18:44 -0600 Subject: [PATCH] Add NOP support and allow for unused symbols --- include/6502.hpp | 8 +++++--- src/6502-c++.cpp | 11 +++++++++-- test/tests.cpp | 8 ++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/6502.hpp b/include/6502.hpp index a423df7..92e1245 100644 --- a/include/6502.hpp +++ b/include/6502.hpp @@ -5,9 +5,6 @@ struct mos6502 : ASMLine { - - - enum class OpCode { unknown, @@ -41,6 +38,8 @@ struct mos6502 : ASMLine ldy, lsr, + nop, + ORA, pha, @@ -92,6 +91,7 @@ struct mos6502 : ASMLine case OpCode::ldx: case OpCode::ldy: case OpCode::lsr: + case OpCode::nop: case OpCode::ORA: case OpCode::pha: case OpCode::php: @@ -144,6 +144,7 @@ struct mos6502 : ASMLine case OpCode::ldx: case OpCode::ldy: case OpCode::lsr: + case OpCode::nop: case OpCode::ORA: case OpCode::pha: case OpCode::php: @@ -229,6 +230,7 @@ struct mos6502 : ASMLine case OpCode::bpl: return "bpl"; case OpCode::bcc: return "bcc"; case OpCode::bcs: return "bcs"; + case OpCode::nop: return "nop"; case OpCode::unknown: return ""; } diff --git a/src/6502-c++.cpp b/src/6502-c++.cpp index 77e1c39..f13e3f9 100644 --- a/src/6502-c++.cpp +++ b/src/6502-c++.cpp @@ -114,6 +114,8 @@ struct AVR : ASMLine mov, + nop, + out, pop, @@ -190,6 +192,7 @@ struct AVR : ASMLine if (o == "in") { return OpCode::in; } if (o == "out") { return OpCode::out; } if (o == "inc") { return OpCode::inc; } + if (o == "nop") { return OpCode::nop; } } } throw std::runtime_error(fmt::format("Unknown opcode: {}", o)); @@ -726,6 +729,10 @@ void translate_instruction(const Personality &personality, return; } } + case AVR::OpCode::nop: { + instructions.emplace_back(mos6502::OpCode::nop); + return; + } case AVR::OpCode::unknown: { throw std::runtime_error("Could not translate 'unknown' instruction"); } @@ -955,8 +962,8 @@ std::vector run(const Personality &personality, std::istream &input) try { i.text = new_labels.at(i.text); } catch (...) { - spdlog::error("Error looking up label name: '{}'", i.text); - throw; + spdlog::warn("Unused label: '{}', consider making function static until we remove unused functions", i.text); + } } } diff --git a/test/tests.cpp b/test/tests.cpp index a4d7cc7..232947f 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -59,7 +59,7 @@ quit REQUIRE(system(fmt::format("{} -f {} -t C64 {}", mos6502_cpp_executable, source_filename, optimization_level).c_str()) == EXIT_SUCCESS); - REQUIRE(system(fmt::format("xvfb-run {} +saveres -warp -moncommands {}", x64_executable, vice_script_filename).c_str()) == EXIT_SUCCESS); + REQUIRE(system(fmt::format("xvfb-run -d {} +saveres -warp -moncommands {}", x64_executable, vice_script_filename).c_str()) == EXIT_SUCCESS); std::ifstream memory_dump(ram_dump_filename, std::ios::binary); @@ -94,7 +94,7 @@ TEST_CASE("Can write to screen memory via function call") R"( void poke(unsigned int location, unsigned char value) { - *reinterpret_cast(location) = 10; + *reinterpret_cast(location) = value; } int main() @@ -109,7 +109,7 @@ int main() const auto result = execute_c64_program("write_to_screen_memory_via_function", program, o_level, 0x400, 0x401); REQUIRE(result.size() == 2); - CHECK(result[0] == 10); - CHECK(result[0] == 11); + CHECK(result[0] == 10); + CHECK(result[1] == 11); }