spencercw avatar spencercw committed 1c6b368

Make the debugger work better when a ROM is loaded from the interface.

Comments (0)

Files changed (6)

gb_emulator/include/gb_emulator/gb_debugger.h

 	class Listener
 	{
 	public:
+		//! Event triggered when the debugger has suspended the emulator.
 		virtual void onSuspend()
 		{
 		}

gb_emulator/include/gb_emulator/gb_disassembler.h

 #include <stdint.h>
 
 #include <map>
-#include <queue>
+#include <deque>
 #include <string>
 
 #include <boost/shared_ptr.hpp>
 private:
 	const std::basic_string<uint8_t> *data_;
 	std::map<uint32_t, boost::shared_ptr<GbInstruction> > disassembly_;
-	std::queue<uint32_t> disassemblyQueue_;
+	std::deque<uint32_t> disassemblyQueue_;
 
 	bool disassembleOp(uint32_t &addr);
 };

gb_emulator/src/cdb_file.cpp

 	};
 
 	// Clear any existing parsed data
+	valid_ = false;
 	modules_.clear();
 	symbols_.clear();
+	files_.clear();
+	lines_.clear();
+	asmLines_.clear();
+	typeCache_.clear();
+	filenameCache_.clear();
 
 	// Open the file
 	if (!fs::exists(path))

gb_emulator/src/gb.cpp

 	timers_.reset();
 
 	loadRom(romPath);
+
+	// Reinitialise the debugger
+	if (!debuggers_.empty())
+	{
+		debugger_.init();
+	}
 }
 
 void Gb::loadRom(const fs::path &romPath)

gb_emulator/src/gb_debugger.cpp

 
 void GbDebugger::init()
 {
+	stack_.clear();
+	step_.reset();
+	continue_ = false;
+
 	// Load the CDB file for the ROM if available
 	if (!gb_.romFilename_.empty())
 	{

gb_emulator/src/gb_disassembler.cpp

 using std::hex;
 using std::make_pair;
 using std::map;
-using std::queue;
 using std::setfill;
 using std::setw;
 
 {
 	data_ = &data;
 
+	// Clear any existing data
+	disassembly_.clear();
+	disassemblyQueue_.clear();
+
 	if (entryPoint >= data.size())
 	{
 		return;
 	}
 		
 	// Do automatic disassembly to pick up anything that wasn't in the symbols
-	disassemblyQueue_.push(entryPoint);
-	for (; !disassemblyQueue_.empty(); disassemblyQueue_.pop())
+	disassemblyQueue_.push_back(entryPoint);
+	for (; !disassemblyQueue_.empty(); disassemblyQueue_.pop_front())
 	{
 		for (uint32_t addr = disassemblyQueue_.front(); ; ++addr)
 		{
 void GbDisassembler::update(uint32_t addr)
 {
 	// Start disassembling
-	disassemblyQueue_.push(addr);
-	for (; !disassemblyQueue_.empty(); disassemblyQueue_.pop())
+	disassemblyQueue_.push_back(addr);
+	for (; !disassemblyQueue_.empty(); disassemblyQueue_.pop_front())
 	{
 		for (addr = disassemblyQueue_.front(); ; ++addr)
 		{
 		// at runtime
 		if (operand < ROM_BANKX)
 		{
-			disassemblyQueue_.push(operand);
+			disassemblyQueue_.push_back(operand);
 		}
 		break;
 					
 	case JR_Z_N:
 	case JR_NC_N:
 	case JR_C_N:
-		disassemblyQueue_.push(addr + 1 + static_cast<int>(static_cast<int8_t>(operand)));
+		disassemblyQueue_.push_back(addr + 1 + static_cast<int>(static_cast<int8_t>(operand)));
 		break;
 					
 	case RST_00:
-		disassemblyQueue_.push(0x00);
+		disassemblyQueue_.push_back(0x00);
 		break;
 	case RST_08:
-		disassemblyQueue_.push(0x08);
+		disassemblyQueue_.push_back(0x08);
 		break;
 	case RST_10:
-		disassemblyQueue_.push(0x10);
+		disassemblyQueue_.push_back(0x10);
 		break;
 	case RST_18:
-		disassemblyQueue_.push(0x18);
+		disassemblyQueue_.push_back(0x18);
 		break;
 	case RST_20:
-		disassemblyQueue_.push(0x20);
+		disassemblyQueue_.push_back(0x20);
 		break;
 	case RST_28:
-		disassemblyQueue_.push(0x28);
+		disassemblyQueue_.push_back(0x28);
 		break;
 
 	case RET:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.