Commits

spencercw committed a3850a1

Load the BIOS and debugger plugins from the installation directory rather than the current directory.

Comments (0)

Files changed (3)

gb_emulator/include/gb_emulator/gb.hpp

 	friend class GbDebugger;
 
 public:
-	//! Constructor; loads the BIOS without executing a ROM.
-	Gb(const boost::filesystem::path &bios);
-
-	//! Constructor; loads the BIOS and the given ROM.
-	Gb(const boost::filesystem::path &bios, const boost::filesystem::path &rom);
+	//! Default constructor; loads the BIOS.
+	Gb();
 
 	//! Destructor.
 	~Gb();
 	bool gbc_;
 
 	// Filenames
+	boost::filesystem::path installDir_;
 	boost::filesystem::path biosFilename_;
 	boost::filesystem::path romFilename_;
 	boost::filesystem::path saveFilename_;

gb_emulator/src/gb.cpp

 #include <SDL/SDL.h>
 #include <sstream>
 #include <stdexcept>
+#include <string>
 
 #include "gb.pb.h"
 
 using std::setw;
 using std::string;
 using std::vector;
+using std::wstring;
 
-Gb::Gb(const fs::path &bios):
+Gb::Gb():
 	cpu_(*this),
 	timers_(*this),
 	input_(*this),
 	video_(*this),
 	debugger_(*this)
 {
-	init(bios);
-}
-
-Gb::Gb(const fs::path &bios, const fs::path &rom):
-	cpu_(*this),
-	timers_(*this),
-	input_(*this),
-	mem_(*this),
-	sound_(*this),
-	video_(*this),
-	debugger_(*this)
-{
-	init(bios);
-	loadRom(rom);
-}
-
-Gb::~Gb()
-{
-}
-
-void Gb::init(const fs::path &biosPath)
-{
 	gbc_ = true;
 
 #ifdef _WIN32
 	timeLast_.tv_nsec = 0;
 #endif
 
+	// Get the installation directory
+	{
+		static const size_t MAX_UNICODE_PATH_LEN = 32768;
+		wchar_t buf[MAX_UNICODE_PATH_LEN];
+		DWORD length = GetModuleFileName(NULL, buf, MAX_UNICODE_PATH_LEN);
+		if (!length || length == MAX_UNICODE_PATH_LEN)
+		{
+			ostringstream oss;
+			oss << "failed to locate installation directory: " << GetLastError();
+			throw runtime_error(oss.str());
+		}
+
+		installDir_ = fs::path(wstring(buf, length));
+		installDir_.remove_filename();
+	}
+
 	// Initialise SDL. Individual sub-systems are initialised by the relevant classes
 	if (SDL_Init(0))
 	{
 	}
 
 	// Load the BIOS
-	biosFilename_ = fs::absolute(biosPath);
+	biosFilename_ = installDir_ / "bios.bin";
 	biosFilename_.make_preferred();
 
 	// Check the file
 	}
 }
 
+Gb::~Gb()
+{
+}
+
 void Gb::loadRom(const fs::path &romPath)
 {
 	fs::path path = fs::absolute(romPath);
 #else
 	// Find any debugger plugins in this directory
 	vector<fs::path> pluginFiles;
-	for (fs::directory_iterator it(L"."), end; it != end; ++it)
+	for (fs::directory_iterator it(installDir_), end; it != end; ++it)
 	{
 		fs::path filename = it->path().filename();
 		if (starts_with(filename.native(), L"gb_debugger_") &&

gb_emulator_main/main.cpp

 		}
 
 		// Start the emulator
-		Gb gb("bios.bin");
+		Gb gb;
 		if (argc == 2)
 		{
 			gb.loadRom(argv[1]);