From 7a5926b5fd0793a3c001777e3ea09831c08c2a94 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 6 May 2021 16:49:33 -0600 Subject: [PATCH] Move start address and make c64 auto-startable --- src/6502-c++.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/6502-c++.cpp b/src/6502-c++.cpp index 4e800d2..7686d64 100644 --- a/src/6502-c++.cpp +++ b/src/6502-c++.cpp @@ -1200,13 +1200,6 @@ bool fix_overwritten_flags(std::vector &instructions) return false; } -void setup_target_cpu_state([[maybe_unused]] const std::vector &instructions, std::vector &new_instructions) -{ - // set __zero_reg__ (reg 1 on AVR) to 0 - new_instructions.emplace_back(mos6502::OpCode::lda, Operand(Operand::Type::literal, "#$00")); - new_instructions.emplace_back(mos6502::OpCode::sta, AVR::get_register(1)); -} - void run(std::istream &input) { std::regex Comment(R"(\s*\#.*)"); @@ -1320,11 +1313,16 @@ void run(std::istream &input) } } + constexpr static auto start_address = 0x0801; std::vector new_instructions; - new_instructions.emplace_back(ASMLine::Type::Directive, ".word $1000"); - new_instructions.emplace_back(ASMLine::Type::Directive, "* = $1000"); - setup_target_cpu_state(instructions, new_instructions); + new_instructions.emplace_back(ASMLine::Type::Directive, ".word " + std::to_string(start_address)); + new_instructions.emplace_back(ASMLine::Type::Directive, "* = " + std::to_string(start_address)); + new_instructions.emplace_back(ASMLine::Type::Directive, "; jmp to start of program with BASIC"); + new_instructions.emplace_back(ASMLine::Type::Directive, ".byt $0B,$08,$0A,$00,$9E,$32,$30,$36,$31,$00,$00,$00"); + // set __zero_reg__ (reg 1 on AVR) to 0 + new_instructions.emplace_back(mos6502::OpCode::lda, Operand(Operand::Type::literal, "#$00")); + new_instructions.emplace_back(mos6502::OpCode::sta, AVR::get_register(1)); new_instructions.emplace_back(mos6502::OpCode::jmp, Operand(Operand::Type::literal, "main"));