aboutsummaryrefslogtreecommitdiffstats
path: root/msp430.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'msp430.cpp')
-rw-r--r--msp430.cpp55
1 files changed, 53 insertions, 2 deletions
diff --git a/msp430.cpp b/msp430.cpp
index 6c92f47..e0d4ae5 100644
--- a/msp430.cpp
+++ b/msp430.cpp
@@ -16,6 +16,7 @@
// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#include <algorithm>
+#include <cctype>
#include <msp430.h>
@@ -24,10 +25,22 @@
#include "state.hpp"
#include "types.hpp"
+#include "lzss.h"
+static const
+#include "msp430fr2476_all.h"
+
+#define MCLK_FREQ_MHZ (16)
+#define LZSS_MAGIC_SEPARATOR (0xFB)
+
using DoubleCell = Cell;
static char strbuf[80];
+static uint8_t lzword[32];
+static int lzwlen;
+static uint8_t lzbuf[32];
+static uint8_t *lzptr;
+
static void serput(int c);
static void serputs(const char *s);
static void printint(DoubleCell n, int base);
@@ -37,7 +50,6 @@ static void initGPIO();
static void initClock();
static void initUART();
static void Software_Trim();
-#define MCLK_FREQ_MHZ (16)
static void doparse();
@@ -55,7 +67,7 @@ constexpr WordSet words (
Word("@", WordWrap<peek>),
Word("c@", WordWrap<peek, [] { *sp() &= 0xFF; }>),
Word("!", WordWrap<[] { auto a = (Cell *)pop(); *a = pop(); }>),
- Word("c!", WordWrap<[] { auto a = (char *)pop(); *a = pop(); }>),
+ Word("c!", WordWrap<[] { auto a = (char *)pop(); *a = (char)pop(); }>),
Word("_d", WordWrap<[] { *sp() += (Cell)DICT.data(); }>),
Word("_jmp", WordWrap<[] { jump((FuncList)*++IP); }>),
Word("_jmp0", WordWrap<[] {
@@ -193,6 +205,45 @@ void printint(DoubleCell n, int base)
serput(' ');
}
+int findword(const char *word, int len)
+{
+ uint8_t *ptr = lzword;
+ for (int i = 0; i < len; ++i) {
+ if (islower(word[i]))
+ *ptr++ = word[i] - 32;
+ else
+ *ptr++ = word[i];
+ }
+ lzwlen = (int)(ptr - lzword);
+
+ lzptr = lzbuf;
+ lzssinit(msp430fr2476_all_lzss, msp430fr2476_all_lzss_len);
+
+ auto ret = decode([](int c) {
+ if (c != LZSS_MAGIC_SEPARATOR) {
+ *lzptr++ = (uint8_t)c;
+ } else {
+ if (lzwlen == lzptr - lzbuf - 2 && std::equal(lzbuf, lzptr - 2, lzword)) {
+ lzwlen = (*(lzptr - 2) << 8) | *(lzptr - 1);
+ return 1;
+ } else {
+ lzptr = lzbuf;
+ }
+ }
+ return 0;
+ });
+
+ if (ret == EOF) {
+ return -1;
+ } else {
+ push(lzwlen);
+ if (STATE)
+ compileliteral();
+
+ return 0;
+ }
+}
+
void initMCU()
{
WDTCTL = WDTPW | WDTHOLD;