Skip to content

Commit

Permalink
Step out
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jul 27, 2024
1 parent 2fba518 commit 05a44dd
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
13 changes: 12 additions & 1 deletion platforms/shared/desktop/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,19 @@ void emu_debug_step_into(void)

void emu_debug_step_out(void)
{
HuC6280* processor = emu_get_core()->GetHuC6280();
std::stack<u16>* call_stack = processor->GetDisassemblerCallStack();

if (call_stack->size() > 0)
{
u16 return_address = call_stack->top();
processor->AddRunToBreakpoint(return_address);
debugger_command = Debugger_Command_Continue;
}
else
debugger_command = Debugger_Command_Step;

geargrafx->Pause(false);
debugger_command = Debugger_Command_Step;
}

void emu_debug_step_frame(void)
Expand Down
38 changes: 38 additions & 0 deletions src/huc6280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void HuC6280::Reset()
m_interrupt_request_register = 0;
m_breakpoint_hit = false;
m_run_to_breakpoint_requested = false;
ClearDisassemblerCallStack();
}

unsigned int HuC6280::Tick()
Expand Down Expand Up @@ -163,6 +164,8 @@ unsigned int HuC6280::Tick()
return m_cycles;
}

UpdateDisassemblerCallStack();

u8 opcode = Fetch8();
(this->*m_opcodes[opcode])();
DisassembleNextOPCode();
Expand Down Expand Up @@ -455,6 +458,17 @@ std::vector<HuC6280::GG_Breakpoint>* HuC6280::GetBreakpoints()
return &m_breakpoints;
}

void HuC6280::ClearDisassemblerCallStack()
{
while(!m_disassembler_call_stack.empty())
m_disassembler_call_stack.pop();
}

std::stack<u16>* HuC6280::GetDisassemblerCallStack()
{
return &m_disassembler_call_stack;
}

void HuC6280::CheckBreakpoints()
{
#ifndef GG_DISABLE_DISASSEMBLER
Expand Down Expand Up @@ -500,3 +514,27 @@ void HuC6280::CheckBreakpoints()

#endif
}

void HuC6280::UpdateDisassemblerCallStack()
{
#ifndef GG_DISABLE_DISASSEMBLER

u16 address = m_PC.GetValue();
u8 opcode = m_memory->Read(address);

// BSR rr, JSR hhll
if (opcode == 0x44 || opcode == 0x20)
{
u8 opcode_size = k_opcode_sizes[opcode];
if (m_disassembler_call_stack.size() < 256)
m_disassembler_call_stack.push(address + opcode_size);
}
// RTS
else if (opcode == 0x60)
{
if (m_disassembler_call_stack.size() > 0)
m_disassembler_call_stack.pop();
}

#endif
}
5 changes: 5 additions & 0 deletions src/huc6280.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define HUC6280_H

#include <vector>
#include <stack>
#include "common.h"
#include "huc6280_registers.h"

Expand Down Expand Up @@ -94,6 +95,8 @@ class HuC6280
bool AddBreakpoint(u16 address);
void AddRunToBreakpoint(u16 address);
std::vector<GG_Breakpoint>* GetBreakpoints();
void ClearDisassemblerCallStack();
std::stack<u16>* GetDisassemblerCallStack();

private:
typedef void (HuC6280::*opcodeptr) (void);
Expand Down Expand Up @@ -125,9 +128,11 @@ class HuC6280
std::vector<GG_Breakpoint> m_breakpoints;
GG_Breakpoint m_run_to_breakpoint;
bool m_run_to_breakpoint_requested;
std::stack<u16> m_disassembler_call_stack;

private:
void CheckBreakpoints();
void UpdateDisassemblerCallStack();

u8 Fetch8();
u16 Fetch16();
Expand Down
2 changes: 1 addition & 1 deletion src/memory_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ inline u8 Memory::Read(u16 address, bool block_transfer)
// HuCard ROM
u8* rom = m_cartridge->GetROM();
int rom_size = m_cartridge->GetROMSize();
if (physical_address >= rom_size)
if ((int)physical_address >= rom_size)
{
Debug("Attempted read out of ROM bounds at %06X", physical_address);
return 0xFF;
Expand Down

0 comments on commit 05a44dd

Please sign in to comment.