aboutsummaryrefslogtreecommitdiffstats
path: root/alee.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'alee.cpp')
-rw-r--r--alee.cpp57
1 files changed, 56 insertions, 1 deletions
diff --git a/alee.cpp b/alee.cpp
index 55cae57..cc9abde 100644
--- a/alee.cpp
+++ b/alee.cpp
@@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-#include "alee.hpp"
+#include "libalee/alee.hpp"
#include "memdict.hpp"
#include <charconv>
@@ -24,6 +24,13 @@
#include <iostream>
#include <vector>
+#ifdef ALEE_MSP430
+#include "lzss.h"
+static const
+#include "msp430fr2476_all.h"
+static Error findword(State&, Word);
+#endif // ALEE_MSP430
+
static bool okay = false;
static void readchar(State&);
@@ -34,6 +41,9 @@ int main(int argc, char *argv[])
{
MemDict dict;
State state (dict, readchar);
+#ifdef ALEE_MSP430
+ Parser::customParse = findword;
+#endif // ALEE_MSP430
dict.initialize();
@@ -153,3 +163,48 @@ void parseFile(State& state, std::istream& file)
}
}
+#ifdef ALEE_MSP430
+#define LZSS_MAGIC_SEPARATOR (0xFB)
+
+static char lzword[32];
+static int lzwlen;
+static char lzbuf[32];
+static char *lzptr;
+
+Error findword(State& state, Word word)
+{
+ char *ptr = lzword;
+ for (auto it = word.begin(&state.dict); it != word.end(&state.dict); ++it) {
+ *ptr = *it;
+ if (islower(*ptr))
+ *ptr -= 32;
+ ++ptr;
+ }
+ 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++ = (char)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 Error::noword;
+ } else {
+ Parser::processLiteral(state, (Cell)lzwlen);
+ return Error::none;
+ }
+}
+#endif // ALEE_MSP430
+