PoC msp430 register/flag support

main
Clyne 12 months ago
parent 4fe405dbb3
commit 98e2c14086
Signed by: clyne
GPG Key ID: 3267C8EBF3F9AFC7

@ -0,0 +1,74 @@
/* LZSS encoder-decoder (Haruhiko Okumura; public domain) */
/* Modified by Clyne Sullivan to focus on streamed decompression. */
#ifndef EOF
#define EOF (-1)
#endif
#define EI 8 /* typically 10..13 */
#define EJ 3 /* typically 4..5 */
#define N (1 << EI) /* buffer size */
#define F ((1 << EJ) + 1) /* lookahead buffer size */
static unsigned char buffer[N * 2];
static const unsigned char *inbuffer;
static unsigned int insize, inidx;
static int buf, mask;
/* Prepares decode() to decompress the given data. */
void lzssinit(const unsigned char *inb, unsigned int ins)
{
inbuffer = inb;
insize = ins;
inidx = 0;
buf = 0;
mask = 0;
}
int getbit(int n) /* get n bits */
{
int i, x;
x = 0;
for (i = 0; i < n; i++) {
if (mask == 0) {
if (inidx >= insize)
return EOF;
buf = inbuffer[inidx++];
mask = 128;
}
x <<= 1;
if (buf & mask) x++;
mask >>= 1;
}
return x;
}
/* handleoutput() receives each decompressed byte, return zero if want more. */
int decode(int (*handleoutput)(int))
{
int i, j, k, r, c, ret;
for (i = 0; i < N - F; i++) buffer[i] = ' ';
r = N - F;
while ((c = getbit(1)) != EOF) {
if (c) {
if ((c = getbit(8)) == EOF) break;
if ((ret = handleoutput(c)))
return ret;
buffer[r++] =(unsigned char) c; r &= (N - 1);
} else {
if ((i = getbit(EI)) == EOF) break;
if ((j = getbit(EJ)) == EOF) break;
for (k = 0; k <= j + 1; k++) {
c = buffer[(i + k) & (N - 1)];
if ((ret = handleoutput(c)))
return ret;
buffer[r++] = (unsigned char)c; r &= (N - 1);
}
}
}
return EOF;
}

@ -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;

File diff suppressed because it is too large Load Diff

@ -22,6 +22,12 @@
#include <cctype>
#include <cstdlib>
__attribute__((weak))
int findword(const char *, int)
{
return -1;
}
[[nodiscard]]
static Error parseword(const char *start, const char *end)
{
@ -34,11 +40,13 @@ static Error parseword(const char *start, const char *end)
} else {
result = execute1(word);
}
} else if (isdigit(*start)) {
} else if (isdigit(*start) || (*start == '-' && isdigit(*(start + 1)))) {
push(std::atoi(start));
if (STATE)
compileliteral();
} else if (findword(start, end - start)) {
return Error::noword;
}
}

@ -110,7 +110,8 @@ enum class Error : int {
push,
pop,
rpush,
rpop
rpop,
noword
};
#endif // TYPES_HPP

Loading…
Cancel
Save