Add NOP support and allow for unused symbols

This commit is contained in:
Jason Turner 2021-05-19 15:18:44 -06:00
parent f64fa3cce6
commit 49d68fe54c
3 changed files with 18 additions and 9 deletions

View File

@ -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 "";
}

View File

@ -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<mos6502> 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);
}
}
}

View File

@ -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<volatile unsigned char *>(location) = 10;
*reinterpret_cast<volatile unsigned char *>(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);
}