mirror of
https://github.com/lefticus/6502-cpp.git
synced 2025-07-23 22:24:20 +00:00
Begin support for signed 'S' operations from AVR
This commit is contained in:
@@ -19,6 +19,7 @@ struct mos6502 : ASMLine
|
||||
bmi,
|
||||
bne,
|
||||
bpl,
|
||||
bvs,
|
||||
|
||||
cpx,
|
||||
cpy,
|
||||
@@ -79,6 +80,7 @@ struct mos6502 : ASMLine
|
||||
case OpCode::bpl:
|
||||
case OpCode::bcc:
|
||||
case OpCode::bcs:
|
||||
case OpCode::bvs:
|
||||
return true;
|
||||
case OpCode::adc:
|
||||
case OpCode::AND:
|
||||
@@ -145,6 +147,7 @@ struct mos6502 : ASMLine
|
||||
case OpCode::bpl:
|
||||
case OpCode::bcc:
|
||||
case OpCode::bcs:
|
||||
case OpCode::bvs:
|
||||
case OpCode::clc:
|
||||
case OpCode::dec:
|
||||
case OpCode::dex:
|
||||
@@ -251,6 +254,7 @@ struct mos6502 : ASMLine
|
||||
case OpCode::cpx: return "cpx";
|
||||
case OpCode::dey: return "dey";
|
||||
case OpCode::iny: return "iny";
|
||||
case OpCode::bvs: return "bvs";
|
||||
case OpCode::unknown: return "";
|
||||
}
|
||||
|
||||
|
@@ -94,6 +94,7 @@ struct AVR : ASMLine
|
||||
andi,
|
||||
|
||||
breq,
|
||||
brge,
|
||||
brlo,
|
||||
brne,
|
||||
brsh,
|
||||
@@ -207,6 +208,7 @@ struct AVR : ASMLine
|
||||
if (o == "nop") { return OpCode::nop; }
|
||||
if (o == "jmp") { return OpCode::jmp; }
|
||||
if (o == "tst") { return OpCode::tst; }
|
||||
if (o=="brge"){ return OpCode::brge; }
|
||||
}
|
||||
}
|
||||
throw std::runtime_error(fmt::format("Unknown opcode: {}", o));
|
||||
@@ -270,6 +272,24 @@ void indirect_store(std::vector<mos6502> &instructions,
|
||||
instructions.emplace_back(mos6502::OpCode::sta, Operand(Operand::Type::literal, "(" + to_address_low_byte + "), Y"));
|
||||
}
|
||||
|
||||
|
||||
// returns the "s_set","s_clear" labels to use for later
|
||||
[[nodiscard]] std::pair<std::string, std::string> setup_S_flag(std::vector<mos6502> &instructions)
|
||||
{
|
||||
const auto location = instructions.size();
|
||||
std::string n_set = fmt::format("n_set_{}", location);
|
||||
std::string s_set = fmt::format("s_set_{}", location);
|
||||
std::string s_clear = fmt::format("s_clear_{}", location);
|
||||
|
||||
instructions.emplace_back(mos6502::OpCode::bmi, Operand(Operand::Type::literal, n_set));
|
||||
instructions.emplace_back(mos6502::OpCode::bvs, Operand(Operand::Type::literal, s_set));
|
||||
instructions.emplace_back(mos6502::OpCode::jmp, Operand(Operand::Type::literal, s_clear));
|
||||
instructions.emplace_back(ASMLine::Type::Label, n_set);
|
||||
instructions.emplace_back(mos6502::OpCode::bvs, Operand(Operand::Type::literal, s_clear));
|
||||
instructions.emplace_back(mos6502::OpCode::jmp, Operand(Operand::Type::literal, s_set));
|
||||
return {s_set, s_clear};
|
||||
}
|
||||
|
||||
void fixup_16_bit_N_Z_flags(std::vector<mos6502> &instructions)
|
||||
{
|
||||
|
||||
@@ -481,6 +501,13 @@ void translate_instruction(const Personality &personality,
|
||||
|
||||
throw std::runtime_error("Unhandled 'std'");
|
||||
}
|
||||
case AVR::OpCode::brge: {
|
||||
const auto [s_set, s_clear] = setup_S_flag(instructions);
|
||||
instructions.emplace_back(ASMLine::Type::Label, s_clear);
|
||||
instructions.emplace_back(mos6502::OpCode::jmp, o1);
|
||||
instructions.emplace_back(ASMLine::Type::Label, s_set);
|
||||
return;
|
||||
}
|
||||
case AVR::OpCode::sub: {
|
||||
instructions.emplace_back(mos6502::OpCode::sec);
|
||||
instructions.emplace_back(mos6502::OpCode::lda, personality.get_register(o1_reg_num));
|
||||
|
Reference in New Issue
Block a user