From b9c4448926fd2faf5b838137c45a8ba5aa2d73d1 Mon Sep 17 00:00:00 2001 From: Dan White Date: Mon, 13 May 2013 14:07:23 -0500 Subject: [PATCH] msp4th: o2w prints opcode name string --- msp4th/msp4th.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/msp4th/msp4th.c b/msp4th/msp4th.c index 69fda0d..bd0f706 100644 --- a/msp4th/msp4th.c +++ b/msp4th/msp4th.c @@ -137,9 +137,9 @@ const uint8_t cmdListBi[] = { "call2 call3 call4 ndrop swpb " // 61 -> 65 "+! roll pick tuck max " // 66 -> 70 "min s. sh. neg echo " // 71 -> 75 - "init " // 76 + "init o2w " // 76 -> 77 }; -#define LAST_PREDEFINED 76 // update this when we add commands to the built in list +#define LAST_PREDEFINED 77 // update this when we add commands to the built in list // these commands are interps @@ -743,6 +743,57 @@ void luFunc(void) } +void opcode2word(void) +{ + // given an opcode, print corresponding ASCII word name + + int16_t i; + int16_t n; + int16_t opcode; + uint8_t *list; + + i = 0; + n = 1; // opcode indices are 1-based + opcode = popMathStack(); + +#define BUILTIN_OPCODE_OFFSET 20000 +#define BUILTIN_INTERP_OFFSET 10000 + + // where is the opcode defined? + // remove offset + if (opcode >= BUILTIN_OPCODE_OFFSET) { + list = (uint8_t *)cmdListBi; + opcode -= BUILTIN_OPCODE_OFFSET; + } else if (opcode >= BUILTIN_INTERP_OFFSET) { + list = (uint8_t *)cmdListBi2; + opcode -= BUILTIN_INTERP_OFFSET; + } else { + list = cmdList; + } + + // walk list to get word + // skip to start of the expected location + while (n < opcode) { + while (list[i] > ' ') { + i++; + } + i++; + n++; + } + + if (list[i] !=0) { + // not end of list, print next word + while (list[i] > ' ') { + msp4th_putchar(list[i++]); + } + } else { + msp4th_putchar('?'); + } + + msp4th_putchar(' '); +} + + void numFunc(void) { // the word to test is in wordBuffer @@ -1447,6 +1498,10 @@ void execN(int16_t opcode) msp4th_init((struct msp4th_config *)popMathStack()); break; + case 77: // o2w ( opcode -- ) \ leaves name of opcode in wordBuffer + opcode2word(); + break; + default: break; } -- 2.25.1