changeset 472:e97f9a302c6a

Add emuext pragma and associated instructions. This provides two emulator specific instructions ("log" and "debug") enabled by the "emuext" pragma. This is from a patch provided by tim Lindner <tlindner@macmess.org>. From Tim's submission: ---- I stole the whole patch from Erik Gavriluk. I hope he doesn't mind. :) The two instructions are "debug" and "log". They are enabled with pragmas. I also added them to the manual. Hopefully all is well. ---- Said Erik Gavriluk <erik@bombfactory.com> in response: ...happy to see them picked up in mainline (if you choose to do so)....
author William Astle <lost@l-w.ca>
date Thu, 01 Nov 2018 23:00:00 -0600
parents ad0efd5835c3
children 8181ddd707f1
files docs/manual.docbook.sgml lwasm/instab.c lwasm/instab.h lwasm/lwasm.h lwasm/pass1.c lwasm/pragma.c
diffstat 6 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/docs/manual.docbook.sgml	Tue Jul 24 17:41:04 2018 -0600
+++ b/docs/manual.docbook.sgml	Thu Nov 01 23:00:00 2018 -0600
@@ -2063,6 +2063,36 @@
 </listitem>
 </varlistentry>
 
+
+
+
+<varlistentry>
+<term>emuext</term>
+<listitem>
+<para>
+
+This pragma enables two instructions useful when running code in compatible
+emulators. Break breaks into the debugger. Log writes printf-style
+output to the debug window
+
+</para>
+<programlisting>
+      LOG           ; log output
+      FDB   FSTR    ; pointer to format string
+      FDB   PX1     ; 16 bit pointer to 16 bit value
+      FDB   PY1     ; 16 bit pointer to 8 bit value (see format string!)
+      FDB   PX2     ; 16 bit pointer to 16 bit value
+      FDB   PY2     ; 16 bit pointer to 8 bit value
+      ; execution continues here ...
+      RTS
+
+; format string
+FSTR  FCC   "%hu,%hhu - %hu,%hhu"
+      FCB   10,0
+</programlisting>
+</listitem>
+</varlistentry>
+
 </variablelist>
 
 <para>As a convenience, each input file has a pragma state stack. This
--- a/lwasm/instab.c	Tue Jul 24 17:41:04 2018 -0600
+++ b/lwasm/instab.c	Thu Nov 01 23:00:00 2018 -0600
@@ -370,6 +370,10 @@
 	{ "negq",		{	-1,		-1,		-1,		12	},	insn_parse_conv,		insn_resolve_conv,				insn_emit_conv,				lwasm_insn_is6309conv },
 	{ "tstq",		{	0x10ed,	0x7c,	-1,		 9	},	insn_parse_conv,		insn_resolve_conv,				insn_emit_conv,				lwasm_insn_is6309conv },
 
+	// emulator extensions
+	{ "break",		{ 0x113e,	-1,		-1,		-1	},	insn_parse_inh,			insn_resolve_inh,				insn_emit_inh,				lwasm_insn_isemuext },
+	{ "log",		{ 0x103e,	-1,		-1,		-1	},	insn_parse_inh,			insn_resolve_inh,				insn_emit_inh,				lwasm_insn_isemuext },
+
 	{ "abx",		{	0x3a,	-1,		-1,		-1	},	insn_parse_inh,			insn_resolve_inh,				insn_emit_inh,				lwasm_insn_normal},
 	{ "adca",		{	0x99,	0xa9,	0xb9,	0x89},	insn_parse_gen8,		insn_resolve_gen8,				insn_emit_gen8,				lwasm_insn_normal},
 	{ "adcb",		{	0xd9,	0xe9,	0xf9,	0xc9},	insn_parse_gen8,		insn_resolve_gen8,				insn_emit_gen8,				lwasm_insn_normal},
--- a/lwasm/instab.h	Tue Jul 24 17:41:04 2018 -0600
+++ b/lwasm/instab.h	Thu Nov 01 23:00:00 2018 -0600
@@ -48,6 +48,7 @@
 	lwasm_insn_is6809		= 1 << 7,	/* insn is 6809 only */
 	lwasm_insn_is6809conv	= 1 << 8,	/* insn is 6809 convenience only */
 	lwasm_insn_is6309conv	= 1 << 9,	/* insn is 6309 convenience only */
+	lwasm_insn_isemuext		= 1 << 10,	/* insn is an emulator extension */
 	lwasm_insn_normal		= 0
 };
 
--- a/lwasm/lwasm.h	Tue Jul 24 17:41:04 2018 -0600
+++ b/lwasm/lwasm.h	Thu Nov 01 23:00:00 2018 -0600
@@ -107,6 +107,7 @@
 	PRAGMA_6309CONV				= 1 << 23,	// enable 6309 convenience ops
 	PRAGMA_NEWSOURCE			= 1 << 24,	// don't use compatibility source format
 	PRAGMA_OPERANDSIZE			= 1 << 25,	// warn if operand size is bigger than required
+	PRAGMA_EMUEXT				= 1 << 26,  // enable emulator extensions
 	PRAGMA_CLEARBIT				= 1 << 31	// reserved to indicate negated pragma flag status
 };
 
--- a/lwasm/pass1.c	Tue Jul 24 17:41:04 2018 -0600
+++ b/lwasm/pass1.c	Thu Nov 01 23:00:00 2018 -0600
@@ -294,6 +294,8 @@
 				if ((instab[opnum].flags & lwasm_insn_is6809conv) && !CURPRAGMA(cl, PRAGMA_6809)) continue;
 				// ignore 6309 convenience opcodes unless asked for
 				if ((instab[opnum].flags & lwasm_insn_is6309conv) && !CURPRAGMA(cl, PRAGMA_6309CONV)) continue;
+				// ignore emulator extension opcodes unless asked for
+				if ((instab[opnum].flags & lwasm_insn_isemuext) && !CURPRAGMA(cl, PRAGMA_EMUEXT)) continue;
 
 				if (!strcasecmp(instab[opnum].opcode, sym))
 					break;
--- a/lwasm/pragma.c	Tue Jul 24 17:41:04 2018 -0600
+++ b/lwasm/pragma.c	Thu Nov 01 23:00:00 2018 -0600
@@ -75,6 +75,7 @@
 	{ "newsource", "nonewsource", PRAGMA_NEWSOURCE },
 	{ "nooldsource", "oldsource", PRAGMA_NEWSOURCE },
 	{ "operandsizewarning", "nooperandsizewarning", PRAGMA_OPERANDSIZE },
+	{ "emuext", "noemuext", PRAGMA_EMUEXT },
 	{ 0, 0, 0 }
 };