# HG changeset patch # User William Astle # Date 1541134800 21600 # Node ID e97f9a302c6acd4342cf5357ea5d0529bfc10576 # Parent ad0efd5835c302a14136b2a2c395adc5b6725ff7 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 . 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 in response: ...happy to see them picked up in mainline (if you choose to do so).... diff -r ad0efd5835c3 -r e97f9a302c6a docs/manual.docbook.sgml --- 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 @@ + + + + +emuext + + + +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 + + + + 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 + + + + As a convenience, each input file has a pragma state stack. This diff -r ad0efd5835c3 -r e97f9a302c6a lwasm/instab.c --- 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}, diff -r ad0efd5835c3 -r e97f9a302c6a lwasm/instab.h --- 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 }; diff -r ad0efd5835c3 -r e97f9a302c6a lwasm/lwasm.h --- 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 }; diff -r ad0efd5835c3 -r e97f9a302c6a lwasm/pass1.c --- 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; diff -r ad0efd5835c3 -r e97f9a302c6a lwasm/pragma.c --- 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 } };