[PATCH 3/3] Add NF_SCREENSHOT API support, binding and (negative) test

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


---
 src/debug/natfeats.c        |  40 +++++++++++++++++++++++++++++++++++-
 tests/natfeats/natfeats.c   |  24 ++++++++++++++++++++++
 tests/natfeats/natfeats.h   |   7 +++++++
 tests/natfeats/nf_ahcc.tos  | Bin 1352 -> 1593 bytes
 tests/natfeats/test_out.txt |   2 ++
 5 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/src/debug/natfeats.c b/src/debug/natfeats.c
index 0652d041..2350a383 100644
--- a/src/debug/natfeats.c
+++ b/src/debug/natfeats.c
@@ -20,6 +20,7 @@ const char Natfeats_fileid[] = "Hatari natfeats.c : " __DATE__ " " __TIME__;
 #include "reset.h"
 #include "natfeats.h"
 #include "debugui.h"
+#include "screenSnapShot.h"
 #include "statusbar.h"
 #include "nf_scsidrv.h"
 #include "log.h"
@@ -242,6 +243,42 @@ static bool nf_fastforward(Uint32 stack, Uint32 subid, Uint32 *retval)
 	return true;
 }
 
+/**
+ * NF_SCREENSHOT - save screen shot to a file
+ * Stack arguments are:
+ * - pointer to buffer containing the file name (string)
+ * Returns true for success and false for failure in 'retval'
+ */
+static bool nf_screenshot(Uint32 stack, Uint32 subid, Uint32 *retval)
+{
+	const char *name, *errstr;
+	Uint32 ptr;
+
+	ptr = STMemory_ReadLong(stack);
+	LOG_TRACE(TRACE_NATFEATS, "NF_SCREENSHOT(0x%x)\n", ptr);
+
+	*retval = false;
+	if (subid) {
+		/* unrecognized subid, nothing saved */
+		return false;
+	}
+	if (!mem_string_ok(ptr)) {
+		return false;
+	}
+	name = (const char *)STMemory_STAddrToPointer (ptr);
+	if (strchr(name, PATHSEP)) {
+		LOG_TRACE(TRACE_NATFEATS, "NF_SCREENSHOT(\"%s\") ERROR, path separator in file name\n", name);
+		return true;
+	}
+	errstr = ScreenSnapShot_SaveToFile(name);
+	if (errstr) {
+		LOG_TRACE(TRACE_NATFEATS, "NF_SCREENSHOT(\"%s\") ERROR: %s!\n", name, errstr);
+	} else {
+		*retval = true;
+	}
+	return true;
+}
+
 #if NF_COMMAND
 /**
  * NF_COMMAND - execute Hatari (cli / debugger) command
@@ -286,7 +323,8 @@ static const struct {
 	{ "NF_SHUTDOWN", true,  nf_shutdown },
 	{ "NF_EXIT",     false, nf_exit },
 	{ "NF_DEBUGGER", false, nf_debugger },
-	{ "NF_FASTFORWARD", false,  nf_fastforward }
+	{ "NF_FASTFORWARD", false,  nf_fastforward },
+	{ "NF_SCREENSHOT",  false,  nf_screenshot }
 #if defined(__linux__)        
         ,{ "NF_SCSIDRV",  true, nf_scsidrv }
 #endif
diff --git a/tests/natfeats/natfeats.c b/tests/natfeats/natfeats.c
index e644622d..253ae0f2 100644
--- a/tests/natfeats/natfeats.c
+++ b/tests/natfeats/natfeats.c
@@ -20,6 +20,10 @@
 #define MSG_NF_MISSING \
 	"\r\nStart Hatari with option:\r\n\t--natfeats yes\r\n"
 
+/* negative test, names with path separators will be rejected by Hatari */
+#define NF_SCREENSHOT_NAME "/screenshot.png"
+
+
 /* NatFeats available & initialized */
 static int nf_ok;
 
@@ -107,6 +111,17 @@ bool nf_fastforward(bool enabled)
 	}
 }
 
+bool nf_screenshot(const char *name)
+{
+	long id;
+	if(nf_ok && (id = nf_id("NF_SCREENSHOT"))) {
+		return nf_call(id, name);
+	} else {
+		(void)Cconws("NF_SCREENSHOT unavailable!\r\n");
+		return false;
+	}
+}
+
 static void halt_reset(int subid)
 {
 	long id;
@@ -200,11 +215,20 @@ int main()
 	old_ff = nf_fastforward(1);
 	nf_print("Emulator name:\n");
 	nf_showname();
+
 	nf_print("Invoking debugger...\n");
 	nf_debugger();
+
+	nf_print("Saving '" NF_SCREENSHOT_NAME "' screenshot...\n");
+	if (nf_screenshot(NF_SCREENSHOT_NAME))
+		nf_print("  succeeded.\n");
+	else
+		nf_print("  failed!\n");
+
 	nf_print("Restoring fastforward & shutting down...\n");
 	nf_fastforward(old_ff);
 	nf_exit(0);
+
 	wait_key();
 	return 0;
 }
diff --git a/tests/natfeats/natfeats.h b/tests/natfeats/natfeats.h
index 9ffa2b19..9eccccf3 100644
--- a/tests/natfeats/natfeats.h
+++ b/tests/natfeats/natfeats.h
@@ -78,6 +78,13 @@ extern bool nf_debugger(void);
  */
 extern bool nf_fastforward(bool enabled);
 
+/**
+ * save screen shot with given file name
+ * (Hatari specific, name must be without path)
+ * returns false on failure, true on success
+ */
+extern bool nf_screenshot(const char *name);
+
 /**
  * terminate the execution of the emulation if possible
  * (runs in supervisor mode)
diff --git a/tests/natfeats/nf_ahcc.tos b/tests/natfeats/nf_ahcc.tos
index dfbc9718ed426244c02509ec089cca8fd5dfbd20..9011a00d2fe28fd17dfd5f162fc15920b70d1299 100644
GIT binary patch
delta 794
zcmX@XwUdV{L5hKac^d-*lf^_XPwij!4E8n*K7NiK&lzkye}bgkfh6lYr{zF#1wY4_
zek}*Toj~!niFM+N>mvHq9T=EAau~S4f)G9%kS_+|Pu!->|1Mq6qmqGvg#{|~L0oW?
z|9b`=pZh!(ex+b3p2-r7^7S9m#q_!LErHg304v=T&<|9@09B&`bO0yF0Zt7GFZ8**
zfR14Ok}d>R{{^BxqF*H*s@e{&+9BbU$8!M%GX}7ZAL&vC%pM2y8Nm8}Anak`sE2Be
zLelyIsMSEt!wcws)_3VDV8>Q~H37Y<#sIXQTb~(W2oDF;j5bs=Bn&JVpk~;C%~*nD
zh7L4rC%<JBV%#)|Nt|)RWC<o&Z<u{&kkkt4vmo2YA_2AU3e3JlhX30Vp819S-=oj$
z`0oFn0=q<pe{qu=m_!)^CQoBhVq#^Qyo*VOja4X-;jh)?J52KRejW$Z7#v?S=mSOW
z0rjT=+4ey8C7@0gAUhPuJ_e*~f&3URhjbMnyB8?72}myk(yI)ZfifHg3_$V;P=An<
zL&5@}+-#s+U&1Y?1|@%m3I+kiKfqM8j6ne8f7VBl{lyGk4e3k;jFW?yuZcScxw`rV
zd-#Vi__@Ug!+DeUGmB2vVA<~<oLH8bm#(0$Uz}W&nwnRfkzb-$ke9BmfW+6+<6=OQ
zXHZZmE=^8OO-)Hn0m>>Uq$OtNq^2lNe#)XVS%_6doR5u9f`d%}L?}qefmji86F3+E
DNkZ|%

delta 607
zcmdnVbApR2L5hKa*^PmLanD39Pwh?i4E8n*K7NiK&lzkye}bgkfg~%F({iA=f}dkd
zzm|jFPN2Bh#5!?ByNG^u2L>jO90o41AcW5b<cmT06SryeGo|Z!R04HOfeL*P7j*J}
z&%onzpU1+l6f8AovIL`iJxjWnKDWLl&^i{dQm24^pc)3Knk_&FaDp7*)R6E(pUVsA
z2v&}CA+UN5i28_rm3XM?b4aRRc{~?TP-6h=-~rmf4A#Sgu!DsIq)Q9v##cz%UU)p0
zFtA|o0=k`*Dcug_P@qDfwaj*tHJIcjog(`6xnZFKbf^TxY8H{n2~4uOOzA3M9R?5`
z5&dcmK*zG^GlThHud%>%SWI5UBrCp5jUlL6b`Jv=#~vp$i#?9-{_ja-_%~znJtn1k
zmNb~dfHb3@V+h2j&jk!X(Zf=f$ndwx%OOq7BN(PGk>US_0!E;-fPO1r1R69=jluCX
zgFcX@0hG%Cvh9Iv86frpvO|HifC4j+%qw63$}<6Rfs;eRKBopHe+9t`1_8xCK%bj2
t2!MU{ZSoH02a}Jm?4NvvRcrEJR#hP`Ha-asHU$Ye4mJV42)PUn1^~_8qznK6

diff --git a/tests/natfeats/test_out.txt b/tests/natfeats/test_out.txt
index c31d5698..79ac3e7e 100644
--- a/tests/natfeats/test_out.txt
+++ b/tests/natfeats/test_out.txt
@@ -8,5 +8,7 @@ You have entered debug mode. Type c to continue emulation, h for help.
 CPU=...
 00...
 Returning to emulation...
+Saving '/screenshot.png' screenshot...
+  failed!
 Restoring fastforward & shutting down...
 NatFeats: exit(0)
-- 
2.20.1


--------------6BD8094804F7DEED823E40A9
Content-Type: text/x-patch; charset=UTF-8;
 name="0002-NF-example-bindings-use-bool-where-appropriate.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0002-NF-example-bindings-use-bool-where-appropriate.patch"



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/