From 1ed8e1acabc3086afeff1dac9f0d717fed3d4111 Mon Sep 17 00:00:00 2001
From: p4plus2 <p4plus2@gmail.com>
Date: Thu, 14 Jan 2016 18:04:50 -0800
Subject: [PATCH 1/1] Mostly add console print support This also ignores some
 checksums and does some voodoo in the memory search

---
 include/interface/callbacks.hpp         |  5 +++++
 options.build                           |  4 ++--
 src/core/mainloop.cpp                   |  5 +++++
 src/core/moviedata.cpp                  |  1 +
 src/emulation/bsnes-legacy/core.cpp     |  6 ++++++
 src/platform/evdev/joystick.cpp         | 15 +++++++++++++--
 src/platform/portaudio/sound.cpp        |  1 +
 src/platform/wxwidgets/memorysearch.cpp |  5 +++--
 8 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/include/interface/callbacks.hpp b/include/interface/callbacks.hpp
index 7150cd0..a44370f 100644
--- a/include/interface/callbacks.hpp
+++ b/include/interface/callbacks.hpp
@@ -71,6 +71,11 @@ public:
  * Notify trace event.
  */
 	virtual void memory_trace(uint64_t proc, const char* str, bool insn) = 0;
+	
+/**
+ * Notify print event.
+ */
+	virtual void console_print(const char* str) = 0;
 };
 
 extern struct emucore_callbacks* ecore_callbacks;
diff --git a/options.build b/options.build
index ac76eb1..e0f6eba 100644
--- a/options.build
+++ b/options.build
@@ -44,7 +44,7 @@ HOSTCC=$(CC)
 USER_HOSTCCFLAGS=
 
 # C++ complier extra flags.
-USER_CFLAGS=-g
+USER_CFLAGS=-O2
 
 # Linker extra flags.
 USER_LDFLAGS=
@@ -91,7 +91,7 @@ SOUND=PORTAUDIO
 # - WIN32MM: Windows Multimedia (Win32 only).
 # - WXWIDGETS: wxWidgets (GRAPHICS=WXWIDGETS only)
 # - MACOSX: Mac OS X (Mac OS X only).
-JOYSTICK=DUMMY
+JOYSTICK=EVDEV
 
 # Set to non-empty value (e.g. 'yes') to enable use of Secret Rabbit Code (a.k.a. libsamperate).
 # This is used for high-quality samplerate conversion for dumping.
diff --git a/src/core/mainloop.cpp b/src/core/mainloop.cpp
index 25b877e..0406ed3 100644
--- a/src/core/mainloop.cpp
+++ b/src/core/mainloop.cpp
@@ -309,6 +309,11 @@ public:
 	{
 		CORE().dbg->do_callback_trace(proc, str, insn);
 	}
+	
+	void console_print(const char* str)
+	{
+		messages << str << std::flush;
+	}
 };
 
 namespace
diff --git a/src/core/moviedata.cpp b/src/core/moviedata.cpp
index b44f9fa..0429874 100644
--- a/src/core/moviedata.cpp
+++ b/src/core/moviedata.cpp
@@ -389,6 +389,7 @@ namespace
 	void warn_roms(moviefile& mov, loaded_rom& against, bool loadstate)
 	{
 		bool rom_ok = true;
+        return;
 		for(size_t i = 0; i < ROM_SLOT_COUNT; i++) {
 			if(mov.namehint[i] == "")
 				mov.namehint[i] = against.romimg[i].namehint;
diff --git a/src/emulation/bsnes-legacy/core.cpp b/src/emulation/bsnes-legacy/core.cpp
index 1481db4..48f63ad 100644
--- a/src/emulation/bsnes-legacy/core.cpp
+++ b/src/emulation/bsnes-legacy/core.cpp
@@ -1075,6 +1075,11 @@ namespace
 			ecore_callbacks->memory_write(_addr, val);
 		ecore_callbacks->memory_write(0x1000000 + addr, val);
 	}
+	
+	void console_print(char *str)
+	{
+		ecore_callbacks->console_print(str);
+	}
 
 	void bsnes_debug_write2(uint8_t clazz, unsigned offset, uint8_t val)
 	{
@@ -1223,6 +1228,7 @@ namespace
 			return std::make_pair((width < 400) ? 2 : 1, (height < 400) ? 2 : 1);
 		}
 		void c_install_handler() {
+			SNES::cpu.debug_print = console_print;
 #ifdef BSNES_SUPPORTS_ADV_BREAKPOINTS
 			SNES::bus.debug_read = bsnes_debug_read;
 			SNES::bus.debug_write = bsnes_debug_write;
diff --git a/src/platform/evdev/joystick.cpp b/src/platform/evdev/joystick.cpp
index 755a8a9..3edf930 100644
--- a/src/platform/evdev/joystick.cpp
+++ b/src/platform/evdev/joystick.cpp
@@ -16,6 +16,7 @@
 #include <cerrno>
 #include <fcntl.h>
 #include <cstdint>
+
 extern "C"
 {
 #include <linux/input.h>
@@ -282,6 +283,16 @@ namespace
 	{
 		FD_ZERO(&s);
 	}
+    
+	void do_fd_set(int f, fd_set& s)
+	{
+		FD_SET(f, &s);
+	}
+    
+	bool do_fd_isset(int f, fd_set& s)
+	{
+		return FD_ISSET(f, &s);
+	}
 
 	struct _joystick_driver drv = {
 		.init = []() -> void {
@@ -301,7 +312,7 @@ namespace
 				int limit = 0;
 				for(auto fd : gamepad_map) {
 					limit = max(limit, fd.first + 1);
-					FD_SET(fd.first, &rfds);
+					do_fd_set(fd.first, rfds);
 				}
 				if(!limit) {
 					usleep(POLL_WAIT);
@@ -315,7 +326,7 @@ namespace
 					continue;
 				std::set<int> cleanup;
 				for(auto fd : gamepad_map)
-					if(FD_ISSET(fd.first, &rfds)) {
+					if(do_fd_isset(fd.first, rfds)) {
 						while(true) {
 							int r = read_one_input_event(fd.first);
 							if(!r)
diff --git a/src/platform/portaudio/sound.cpp b/src/platform/portaudio/sound.cpp
index 9931d2b..d379896 100644
--- a/src/platform/portaudio/sound.cpp
+++ b/src/platform/portaudio/sound.cpp
@@ -246,6 +246,7 @@ namespace
 	//Switch input device only in split-duplex configuration.
 	unsigned switch_devices_inonly(PaDeviceIndex dev)
 	{
+        return 3;
 		if(!check_indev(dev))
 			return 2;
 		close_input();
diff --git a/src/platform/wxwidgets/memorysearch.cpp b/src/platform/wxwidgets/memorysearch.cpp
index b50b77a..fceecd4 100644
--- a/src/platform/wxwidgets/memorysearch.cpp
+++ b/src/platform/wxwidgets/memorysearch.cpp
@@ -1057,8 +1057,9 @@ void wxwindow_memorysearch::on_button_click(wxCommandEvent& e)
 				continue;
 			uint64_t addr = addresses[r];
 			try {
-				std::string n = pick_text(this, "Name for watch", (stringfmt()
-					<< "Enter name for watch at 0x" << std::hex << addr << ":").str());
+				std::string n = pick_text(this, "Name for watch",
+					(stringfmt() << "Enter name for watch at 0x" << std::hex << addr << ":").str(), 
+					(stringfmt() << "0x" << std::hex << addr << ":").str());
 				if(n == "")
 					continue;
 				memwatch_item e;
-- 
2.5.3

