[hatari-devel] Autostart support for more options

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


Hi,

Attached is patch to support "autostart:" prefix for option values, to post-pone option actions until Hatari program autostart handling (i.e. Hatari providing virtual INF file for TOS when GEM desktop starts).

It's intention is to avoid catching/showing stuff that TOS bootup does; bus errors from HW checks, running AUTO programs etc.

One can use it e.g. to:
- fast-forward TOS bootup, but
- stop that just before the specified program starts
- slow down the emulation at that point, in addition to:
- enabling tracing,
- setting exception debugging mask, and
- executing some debugger commands:
----------------------------------
$ hatari --fast-forward autostart:true --slowdown autostart:8 \
  --trace autostart:os_base,xbios --debug-except autostart:bus,address \
  --parse autostart:debugger.ini test/program.tos
----------------------------------

Questions:
* Should I merge this before or after v2.6 release?
* Should I try to get it closer to program starting? [1]

[1] TOS will parse the provided INF file and Pexec's ACCs, before it Pexec's the program specified in the (virtual) INF file. I think I could post-pone those CLI option actions further, to first Pexec after INF reading.

Is that enough improvement to warrant a bit more complexity?


	- Eero
From ac1d8701f48995aa5a7eeb309770f42e9ccbdafb Mon Sep 17 00:00:00 2001
From: Eero Tamminen <oak@xxxxxxxxxxxxxx>
Date: Wed, 28 May 2025 10:57:00 +0300
Subject: [PATCH] Autostart prefix for options

By using "autostart:" prefix for options to:
- Set trace flags
- Set exception debug mask
- Parse debugger commands
- Toggle fast-forward
- Set slowndown factor

That action is post-poned until program autostart handling
(i.e. Hatari providing virtual TOS INF file for TOS).
---
 src/includes/inffile.h | 11 +++++++
 src/inffile.c          | 48 +++++++++++++++++++++++++++--
 src/options.c          | 70 +++++++++++++++++++++++++++++++++---------
 3 files changed, 112 insertions(+), 17 deletions(-)

diff --git a/src/includes/inffile.h b/src/includes/inffile.h
index 042e0411..090d3c13 100644
--- a/src/includes/inffile.h
+++ b/src/includes/inffile.h
@@ -13,6 +13,17 @@ typedef enum {
 	AUTOSTART_FOPEN
 } autostart_t;
 
+/* items to set along with autostarting */
+typedef struct {
+	const char *parseFile;
+	const char *traceFlags;
+	const char *exceptionMask;
+	bool toggleFastForward;
+	int slowDown;
+} autostart_actions_t;
+
+extern autostart_actions_t INF_AutoStartActions;
+
 extern bool INF_SetAutoStart(const char *prgname, int opt_id);
 extern bool INF_SetResolution(const char *resolution, int opt_id);
 extern void INF_SetVdiMode(int vdi_res);
diff --git a/src/inffile.c b/src/inffile.c
index 04bec57e..bbe4bb15 100644
--- a/src/inffile.c
+++ b/src/inffile.c
@@ -14,6 +14,7 @@ const char INFFILE_fileid[] = "Hatari inffile.c";
 
 #include "main.h"
 #include "configuration.h"
+#include "debugui.h"
 #include "inffile.h"
 #include "options.h"
 #include "gemdos.h"
@@ -27,6 +28,8 @@ const char INFFILE_fileid[] = "Hatari inffile.c";
 /* debug output + leaves virtual INF file behind */
 #define INF_DEBUG 0
 
+autostart_actions_t INF_AutoStartActions;
+
 /* TOS resolution numbers used in Atari TOS INF files.
  *
  * Note: EmuTOS uses different numbers, so these are re-mapped.
@@ -880,18 +883,57 @@ bool INF_Overriding(autostart_t t)
 
 /*-----------------------------------------------------------------------*/
 /**
- * If given name matches virtual INF file name, return its handle, NULL otherwise
+ * If given name matches virtual INF file name, return its handle,
+ * NULL otherwise.  Runs also other actions configured to be done
+ * at same time with autostart (INF file overriding).
  */
 FILE *INF_OpenOverride(const char *filename)
 {
 	if (TosOverride.file && strcmp(filename, TosOverride.infname) == 0)
 	{
-		/* whether to "autostart" also exception debugging? */
+		autostart_actions_t const *act = &INF_AutoStartActions; /* alias */
+
+		/* toggle fast forwarding? */
+		if (act->toggleFastForward)
+		{
+			ConfigureParams.System.bFastForward = !ConfigureParams.System.bFastForward;
+			Log_Printf(LOG_WARN, "Fast forward: %d\n", ConfigureParams.System.bFastForward);
+		}
+
+		/* set/change slowdown? */
+		if (act->slowDown)
+		{
+			Main_SetVBLSlowdown(act->slowDown);
+			Log_Printf(LOG_WARN, "VBL wait slow down factor: %d\n", act->slowDown);
+		}
+
+		/* parse debugger commands? */
+		if (act->parseFile)
+		{
+			Log_Printf(LOG_WARN, "Parsing debugger command file: '%s'\n", act->parseFile);
+			DebugUI_AddParseFile(act->parseFile);
+		}
+
+		/* start/start tracing? */
+		if (act->traceFlags)
+		{
+			Log_SetTraceOptions(act->traceFlags);
+			Log_Printf(LOG_WARN, "Tracing flags: 0x%lx\n", LogTraceFlags);
+		}
+
+		/* start/change exception debugg mask? */
 		if (ConfigureParams.Debugger.nExceptionDebugMask & EXCEPT_AUTOSTART)
 		{
+			/* legacy/backwards compatible method */
 			ExceptionDebugMask = ConfigureParams.Debugger.nExceptionDebugMask & ~EXCEPT_AUTOSTART;
-			Log_Printf(LOG_INFO, "Exception debugging enabled (0x%x).\n", ExceptionDebugMask);
+			Log_Printf(LOG_WARN, "Exception debug mask: 0x%x)\n", ExceptionDebugMask);
+		}
+		else if (act->exceptionMask)
+		{
+			Log_SetExceptionDebugMask(act->exceptionMask);
+			Log_Printf(LOG_WARN, "Exception debug mask: 0x%x\n", ExceptionDebugMask);
 		}
+
 		Log_Printf(LOG_DEBUG, "Virtual INF file '%s' matched.\n", filename);
 		return TosOverride.file;
 	}
diff --git a/src/options.c b/src/options.c
index d1b160b9..cdc5f135 100644
--- a/src/options.c
+++ b/src/options.c
@@ -56,6 +56,8 @@ bool BenchmarkMode;	   /* Start in benchmark mode (try to run at maximum emulati
 
 static bool bBiosIntercept;
 
+#define AUTOSTART_PREFIX "autostart:"
+
 /*  List of supported options. */
 enum {
 	OPT_HEADER,	/* options section header */
@@ -662,7 +664,8 @@ static void Opt_ShowHelp(void)
 	       "\tEnable by using 'y', 'yes', 'on', 'true' or '1'\n"
 	       "<file>\tDevices accept also special 'stdout' and 'stderr' file names\n"
 	       "\t(if you use stdout for midi or printer, set log to stderr).\n"
-	       "\tSetting the file to 'none', disables given device or disk\n");
+	       "\tSetting the file to 'none', disables given device or disk\n"
+	       "'"AUTOSTART_PREFIX"' prefix => see manual on how it works.\n");
 }
 
 
@@ -799,6 +802,21 @@ static bool Opt_CountryCode(const char *arg, int optid, int *conf)
 
 }
 
+/**
+ * Return true if given string has autostart prefix, and set
+ * string pointer to address after the prefix.
+ */
+static bool Opt_HasAutoStartPrefix(const char **arg)
+{
+	const size_t len = strlen(AUTOSTART_PREFIX);
+	if (strncmp(*arg, AUTOSTART_PREFIX, len) == 0)
+	{
+		*arg = *arg + len;
+		return true;
+	}
+	return false;
+}
+
 /**
  * Parse "<drive>=<value>". If single digit "<drive>" and/or '=' missing,
  * assume drive ID 0, and interpret whole arg as "<value>".
@@ -907,7 +925,10 @@ static int Opt_WhichOption(int argc, const char * const argv[], int idx)
 			/* early check for bools */
 			if (strcmp(opt->arg, "<bool>") == 0)
 			{
-				if (!Opt_Bool(argv[idx+1], opt->id, NULL))
+				const char *value = argv[idx+1];
+
+				Opt_HasAutoStartPrefix(&value);
+				if (!Opt_Bool(value, opt->id, NULL))
 				{
 					return OPT_ERROR;
 				}
@@ -1089,11 +1110,10 @@ bool Opt_ParseParameters(int argc, const char * const argv[])
 {
 	int ncpu, skips, planes, cpuclock, threshold, memsize;
 	int dev, port, freq, temp, drive, year;
+	bool valid, has, ok = true;
 	const char *errstr, *str;
-	int i, ok = true;
 	float zoom;
-	int val;
-	bool valid;
+	int i, val;
 
 	/* Defaults for loading initial memory snap-shots */
 	bLoadMemorySave = false;
@@ -1125,7 +1145,11 @@ bool Opt_ParseParameters(int argc, const char * const argv[])
 			break;
 
 		case OPT_FASTFORWARD:
-			ok = Opt_Bool(argv[++i], OPT_FASTFORWARD, &ConfigureParams.System.bFastForward);
+			str = argv[++i];
+			if (Opt_HasAutoStartPrefix(&str)) {
+				INF_AutoStartActions.toggleFastForward = true;
+			}
+			ok = Opt_Bool(str, OPT_FASTFORWARD, &ConfigureParams.System.bFastForward);
 			break;
 
 		case OPT_AUTOSTART:
@@ -1221,7 +1245,14 @@ bool Opt_ParseParameters(int argc, const char * const argv[])
 			break;
 
 		case OPT_SLOWDOWN:
-			val = atoi(argv[++i]);
+			str = argv[++i];
+			has = Opt_HasAutoStartPrefix(&str);
+			val = atoi(str);
+			if (has)
+			{
+				INF_AutoStartActions.slowDown = val;
+				break;
+			}
 			errstr = Main_SetVBLSlowdown(val);
 			if (errstr)
 			{
@@ -2133,9 +2164,12 @@ bool Opt_ParseParameters(int argc, const char * const argv[])
 			break;
 
 		case OPT_EXCEPTIONS:
-			i += 1;
-			/* sets ConfigureParams.Debugger.nExceptionDebugMask */
-			errstr = Log_SetExceptionDebugMask(argv[i]);
+			str = argv[++i];
+			if (Opt_HasAutoStartPrefix(&str)) {
+				INF_AutoStartActions.exceptionMask = str;
+				break;
+			}
+			errstr = Log_SetExceptionDebugMask(str);
 			if (errstr)
 			{
 				if (!errstr[0])
@@ -2212,8 +2246,12 @@ bool Opt_ParseParameters(int argc, const char * const argv[])
 			break;
 
 		case OPT_TRACE:
-			i += 1;
-			errstr = Log_SetTraceOptions(argv[i]);
+			str = argv[++i];
+			if (Opt_HasAutoStartPrefix(&str)) {
+				INF_AutoStartActions.traceFlags = str;
+				break;
+			}
+			errstr = Log_SetTraceOptions(str);
 			if (errstr)
 			{
 				if (!errstr[0])
@@ -2262,8 +2300,12 @@ bool Opt_ParseParameters(int argc, const char * const argv[])
 			break;
 
 		case OPT_PARSE:
-			i += 1;
-			ok = DebugUI_AddParseFile(argv[i]);
+			str = argv[++i];
+			if (Opt_HasAutoStartPrefix(&str)) {
+				INF_AutoStartActions.parseFile = str;
+			} else {
+				ok = DebugUI_AddParseFile(str);
+			}
 			break;
 
 		case OPT_SAVECONFIG:
-- 
2.39.5



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