3#include "absl/strings/str_format.h"
143 uint8_t opcode)
const {
147 uint32_t bank = pc & 0xFF0000;
154 return bank | ((pc + size) & 0xFFFF);
159 uint8_t opcode)
const {
162 uint32_t bank = pc & 0xFF0000;
195 call_stack_.emplace_back(pc, target, return_addr, is_long);
210 result.
message =
"Step controller not properly configured";
214 uint32_t pc_before =
get_pc_();
218 std::optional<CallStackEntry> call_made;
223 call_made =
CallStackEntry(pc_before, target, return_addr, is_long);
228 std::optional<CallStackEntry> return_made;
241 result.
call = call_made;
242 result.
ret = return_made;
245 result.
message = absl::StrFormat(
"Called $%06X from $%06X",
246 call_made->target_address,
247 call_made->call_address);
248 }
else if (return_made) {
249 result.
message = absl::StrFormat(
"Returned to $%06X", pc_after);
251 result.
message = absl::StrFormat(
"Stepped to $%06X", pc_after);
263 result.
message =
"Step controller not properly configured";
282 result.
call = step_result.call;
284 if (!step_result.success) {
296 result.
message = absl::StrFormat(
297 "Stepped over subroutine, returned to $%06X after %u instructions",
314 call_stack_.emplace_back(pc, target, ret, is_long);
323 result.
message = absl::StrFormat(
324 "Step over timed out after %u instructions", max_instructions);
334 result.
message =
"Step controller not properly configured";
339 result.
message =
"Cannot step out - call stack is empty";
360 call_stack_.emplace_back(pc, target, ret, is_long);
364 result.
ret = returned;
370 result.
message = absl::StrFormat(
371 "Stepped out to $%06X after %u instructions",
381 result.
message = absl::StrFormat(
382 "Step out timed out after %u instructions", max_instructions);
void ProcessInstruction(uint32_t pc)
StepResult StepInto()
Step a single instruction and update call stack.
uint32_t CalculateCallTarget(uint32_t pc, uint8_t opcode) const
uint32_t CalculateReturnAddress(uint32_t pc, uint8_t opcode) const
StepResult StepOver(uint32_t max_instructions=1000000)
Step over the current instruction.
static bool IsReturnInstruction(uint8_t opcode)
Check if an opcode is a return instruction (RTS/RTL/RTI)
static bool IsCallInstruction(uint8_t opcode)
Check if an opcode is a call instruction (JSR/JSL)
static bool IsBranchInstruction(uint8_t opcode)
Check if an opcode is a branch instruction.
static uint8_t GetInstructionSize(uint8_t opcode, bool m_flag, bool x_flag)
Get instruction size for step over calculations.
std::vector< CallStackEntry > call_stack_
StepResult StepOut(uint32_t max_instructions=1000000)
Step out of the current subroutine.
constexpr uint8_t JMP_IND
constexpr uint8_t JMP_LONG
constexpr uint8_t JMP_IND_L
constexpr uint8_t JMP_ABS
constexpr uint8_t JMP_ABS_X
Tracks call stack for intelligent stepping.
Result of a step operation.
std::optional< CallStackEntry > call
uint32_t instructions_executed
std::optional< CallStackEntry > ret