peripheral_8bit : ORIGIN = 0x0010, LENGTH = 0x00f0
peripheral_16bit : ORIGIN = 0x0100, LENGTH = 0x0100
- ram (wx) : ORIGIN = 0x4000, LENGTH = 0xbf00
+ ram (wx) : ORIGIN = 0x4000, LENGTH = 0xbfc0
/*rom (rx) : ORIGIN = 0x3000, LENGTH = 0x1000 */
vectors : ORIGIN = 0xffc0, LENGTH = 64
PROVIDE (__data_start_rom = _etext);
PROVIDE (__data_end_rom = _etext + SIZEOF (.data));
}
-/* hard-coded addresses for on-line re-sizing of the msp4th arrays */
-__msp4th_mathStackStartAddress = 0xff00;
-__msp4th_addrStackStartAddress = 0xff02;
-__msp4th_prog = 0xff04;
-__msp4th_progOpcodes = 0xff06;
-__msp4th_cmdList = 0xff08;
-__msp4th_lineBuffer = 0xff0a;
-__msp4th_lineBufferLength = 0xff0c;
-__msp4th_wordBuffer = 0xff0e;
-__msp4th_wordBufferLength = 0xff10;
-
__PC_AFTER_RESET = 0x3000;
__CRCDI = 0x0000;
__CRCDI_L = 0x0000;
peripheral_8bit : ORIGIN = 0x0010, LENGTH = 0x00f0
peripheral_16bit : ORIGIN = 0x0100, LENGTH = 0x0100
- ram (wx) : ORIGIN = 0x4000, LENGTH = 0xbf00
+ ram (wx) : ORIGIN = 0x4000, LENGTH = 0xbfc0
rom (rx) : ORIGIN = 0x3000, LENGTH = 0x1000
vectors : ORIGIN = 0xffc0, LENGTH = 64
PROVIDE (__data_start_rom = _etext);
PROVIDE (__data_end_rom = _etext + SIZEOF (.data));
}
-/* hard-coded addresses for on-line re-sizing of the msp4th arrays */
-__msp4th_mathStackStartAddress = 0xff00;
-__msp4th_addrStackStartAddress = 0xff02;
-__msp4th_prog = 0xff04;
-__msp4th_progOpcodes = 0xff06;
-__msp4th_cmdList = 0xff08;
-__msp4th_lineBuffer = 0xff0a;
-__msp4th_lineBufferLength = 0xff0c;
-__msp4th_wordBuffer = 0xff0e;
-__msp4th_wordBufferLength = 0xff10;
-
__PC_AFTER_RESET = 0x3000;
__CRCDI = 0x0000;
__CRCDI_L = 0x0000;
uint8_t __attribute__ ((section(".noinit"))) lineBufferArray[LINE_BUFFER_SIZE];
uint8_t __attribute__ ((section(".noinit"))) wordBufferArray[WORD_BUFFER_SIZE];
-void (*msp4th_putchar)(uint8_t);
-uint8_t (*msp4th_getchar)(void);
+struct msp4th_config __attribute__ ((section(".noinit"))) default_config;
-static __inline__ void config_default_msp4th(void)
+static __inline__ void setup_default_msp4th(void)
{
- int16_t i;
-
- msp4th_mathStackStartAddress = &mathStackArray[MATH_STACK_SIZE - 1];
- msp4th_addrStackStartAddress = &addrStackArray[ADDR_STACK_SIZE - 1];
- msp4th_prog = &progArray[0];
- msp4th_progOpcodes = &progOpcodesArray[0];
- msp4th_cmdList = &cmdListArray[0];
- msp4th_lineBuffer = &lineBufferArray[0];
- msp4th_lineBufferLength = LINE_BUFFER_SIZE;
- msp4th_wordBuffer = &wordBufferArray[0];
- msp4th_wordBufferLength = WORD_BUFFER_SIZE;
-
-
- for (i=0; i < MATH_STACK_SIZE; i++) {
- mathStackArray[i] = 0;
- }
-
- for (i=0; i < ADDR_STACK_SIZE; i++) {
- addrStackArray[i] = 0;
- }
-
- /* example initial line to execute
+ default_config.mathStackStartAddress = &mathStackArray[MATH_STACK_SIZE - 1];
+ default_config.addrStackStartAddress = &addrStackArray[ADDR_STACK_SIZE - 1];
+ default_config.prog = &progArray[0];
+ default_config.progOpcodes = &progOpcodesArray[0];
+ default_config.cmdList = &cmdListArray[0];
+ default_config.lineBuffer = &lineBufferArray[0];
+ default_config.lineBufferLength = LINE_BUFFER_SIZE;
+ default_config.wordBuffer = &wordBufferArray[0];
+ default_config.wordBufferLength = WORD_BUFFER_SIZE;
+ default_config.putchar = &uart_putchar;
+ default_config.getchar = &uart_getchar;
+
+
+ /* howto execute a line of words on init
uint8_t *str = (uint8_t *)"1 2 3 4 5 s.\r";
for (i=0; i < 14; i++) {
lineBufferArray[i] = str[i];
lineBufferArray[0] = 0;
wordBufferArray[0] = 0;
-
- msp4th_putchar = &uart_putchar;
- msp4th_getchar = &uart_getchar;
}
* - any 0xff character in the input
*/
while (1) {
- config_default_msp4th();
- init_msp4th();
- processLoop();
+ setup_default_msp4th();
+
+ msp4th_init(&default_config);
+ msp4th_processLoop();
}
return 0;
*/
#if defined(MSP430)
int16_t register *mathStackPtr asm("r6");
-#else
-int16_t *mathStackPtr;
-#endif
-
-#if defined(MSP430)
int16_t register *addrStackPtr asm("r7");
#else
+int16_t *mathStackPtr;
int16_t *addrStackPtr;
#endif
int16_t *prog; // user programs (opcodes) are placed here
-//int16_t *progOpcodes; // mapping between user word index and program opcodes
+int16_t *progOpcodes; // mapping between user word index and program opcodes
// start index into prog[]
+uint8_t *cmdList;
+uint8_t *lineBuffer;
+int16_t lineBufferLength;
+uint8_t *wordBuffer;
+int16_t wordBufferLength;
+void (*msp4th_putchar)(uint8_t c);
+uint8_t (*msp4th_getchar)(void);
+
+struct msp4th_config *config;
+
+
{
uint8_t c;
- c = msp4th_lineBuffer[lineBufferIdx++];
+ c = lineBuffer[lineBufferIdx++];
if (c == 0) {
getLine();
- c = msp4th_lineBuffer[lineBufferIdx++];
+ c = lineBuffer[lineBufferIdx++];
}
return (c);
} else if ( ((c == 255) || (c == '\ 4')) && (lineBufferIdx == 0)) {
xit = 1;
waiting = 0;
- msp4th_lineBuffer[lineBufferIdx++] = 'x';
- msp4th_lineBuffer[lineBufferIdx] = ' ';
+ lineBuffer[lineBufferIdx++] = 'x';
+ lineBuffer[lineBufferIdx] = ' ';
} else {
if (echo) {
msp4th_putchar(c);
if ( (c == '\r') ||
(c == '\n') ||
- (lineBufferIdx >= (msp4th_lineBufferLength - 1))) { // prevent overflow of line buffer
+ (lineBufferIdx >= (lineBufferLength - 1))) { // prevent overflow of line buffer
waiting = 0;
if (echo) { msp4th_putchar('\n'); }
}
- msp4th_lineBuffer[lineBufferIdx++] = c;
- msp4th_lineBuffer[lineBufferIdx] = 0;
+ lineBuffer[lineBufferIdx++] = c;
+ lineBuffer[lineBufferIdx] = 0;
}
}
}
do {
- msp4th_wordBuffer[k++] = c;
- msp4th_wordBuffer[k] = 0;
+ wordBuffer[k++] = c;
+ wordBuffer[k] = 0;
c = getKeyB();
- } while ((c > ' ') && (k < msp4th_wordBufferLength));
+ } while ((c > ' ') && (k < wordBufferLength));
}
{
msp4th_puts((uint8_t *)cmdListBi);
msp4th_puts((uint8_t *)cmdListBi2);
- msp4th_puts((uint8_t *)msp4th_cmdList);
+ msp4th_puts((uint8_t *)cmdList);
}
i = *mathStackPtr;
// prevent stack under-flow
- if (mathStackPtr < (int16_t *)msp4th_mathStackStartAddress) {
+ if (mathStackPtr < (int16_t *)config->mathStackStartAddress) {
mathStackPtr++;
}
{
int16_t i;
- i = lookupToken(msp4th_wordBuffer, (uint8_t *)cmdListBi);
+ i = lookupToken(wordBuffer, (uint8_t *)cmdListBi);
if(i){
i += 20000;
pushMathStack(1);
} else {
// need to test internal interp commands
- i = lookupToken(msp4th_wordBuffer, (uint8_t *)cmdListBi2);
+ i = lookupToken(wordBuffer, (uint8_t *)cmdListBi2);
if(i){
i += 10000;
pushMathStack(i);
pushMathStack(1);
} else {
- i = lookupToken(msp4th_wordBuffer, msp4th_cmdList);
+ i = lookupToken(wordBuffer, cmdList);
if(i){
pushMathStack(i);
pushMathStack(1);
n = 0;
// first check for neg sign
- if (msp4th_wordBuffer[i] == '-') {
+ if (wordBuffer[i] == '-') {
i = i + 1;
}
- if ((msp4th_wordBuffer[i] >= '0') && (msp4th_wordBuffer[i] <= '9')) {
+ if ((wordBuffer[i] >= '0') && (wordBuffer[i] <= '9')) {
// it is a number
isnum = 1;
// check if hex
- if(msp4th_wordBuffer[0] == '0' && msp4th_wordBuffer[1] == 'x'){
+ if(wordBuffer[0] == '0' && wordBuffer[1] == 'x'){
// base 16 number ... just assume all characters are good
i = 2;
n = 0;
- while(msp4th_wordBuffer[i]){
+ while(wordBuffer[i]){
n = n << 4;
- n = n + msp4th_wordBuffer[i] - '0';
- if(msp4th_wordBuffer[i] > '9'){
+ n = n + wordBuffer[i] - '0';
+ if(wordBuffer[i] > '9'){
n = n - 7;
// compensate for lowercase digits
- if (msp4th_wordBuffer[i] >= 'a') {
+ if (wordBuffer[i] >= 'a') {
n -= 0x20;
}
}
} else {
// base 10 number
n = 0;
- while(msp4th_wordBuffer[i]){
+ while(wordBuffer[i]){
n = n * 10;
- n = n + msp4th_wordBuffer[i] - '0';
+ n = n + wordBuffer[i] - '0';
i = i + 1;
}
- if(msp4th_wordBuffer[0] == '-'){
+ if(wordBuffer[0] == '-'){
n = -n;
}
}
uint16_t i;
// this function adds a new def to the list and creats a new opcode
i = 0;
- while(msp4th_wordBuffer[i]){
- msp4th_cmdList[cmdListIdx++] = msp4th_wordBuffer[i];
+ while(wordBuffer[i]){
+ cmdList[cmdListIdx++] = wordBuffer[i];
i = i + 1;
}
- msp4th_cmdList[cmdListIdx++] = ' ';
- msp4th_cmdList[cmdListIdx] = 0;
- i = lookupToken(msp4th_wordBuffer, msp4th_cmdList);
- msp4th_progOpcodes[i] = progIdx;
+ cmdList[cmdListIdx++] = ' ';
+ cmdList[cmdListIdx] = 0;
+ i = lookupToken(wordBuffer, cmdList);
+ progOpcodes[i] = progIdx;
}
} else {
pushAddrStack(progCounter);
- progCounter = msp4th_progOpcodes[opcode];
+ progCounter = progOpcodes[opcode];
}
break;
case 27: // depth ( -- n ) \ math stack depth
- pushMathStack((int16_t *)msp4th_mathStackStartAddress - mathStackPtr);
+ pushMathStack((int16_t *)config->mathStackStartAddress - mathStackPtr);
break;
case 28: // .h ( a -- )
break;
case 38: // pwrd ( -- ) \ print word buffer
- msp4th_puts(msp4th_wordBuffer);
+ msp4th_puts(wordBuffer);
break;
case 39: // emit ( c -- )
case 72: // s. ( -- ) \ print stack contents, TOS on right
{ // addr is strictly local to this block
int16_t *addr;
- addr = (int16_t *)msp4th_mathStackStartAddress;
+ addr = (int16_t *)config->mathStackStartAddress;
while (addr >= mathStackPtr) {
printNumber(*addr);
addr--;
case 73: // sh. ( -- ) \ print stack contents in hex, TOS on right
{ // addr is strictly local to this block
int16_t *addr;
- addr = (int16_t *)msp4th_mathStackStartAddress;
+ addr = (int16_t *)config->mathStackStartAddress;
while (addr >= mathStackPtr) {
printHexWord(*addr);
msp4th_putchar(' ');
* Public function prototypes
*/
-void init_msp4th(void)
+void msp4th_init(struct msp4th_config *c)
{
/*
* Get addresses of user-configurable arrays from the pre-known vector
* table locations.
*
- * Changing the values in the xStartAddress locations and calling
+ * Changing the values in the msp4th_* locations and calling
* init_msp4th() again restarts the interpreter with the new layout;
*/
- mathStackPtr = msp4th_mathStackStartAddress;
- addrStackPtr = msp4th_addrStackStartAddress;
+ mathStackPtr = c->mathStackStartAddress;
+ addrStackPtr = c->addrStackStartAddress;
+ prog = c->prog;
+ progOpcodes = c->progOpcodes;
+ cmdList = c->cmdList;
+ lineBuffer = c->lineBuffer;
+ lineBufferLength = c->lineBufferLength;
+ wordBuffer = c->wordBuffer;
+ wordBufferLength = c->wordBufferLength;
+ msp4th_putchar = c->putchar;
+ msp4th_getchar = c->getchar;
+
+ config = c;
xit = 0;
}
-void processLoop() // this processes the forth opcodes.
+void msp4th_processLoop() // this processes the forth opcodes.
{
uint16_t opcode;
uint16_t tmp;
execN(opcode - 20000);
} else {
pushAddrStack(progCounter);
- progCounter = msp4th_progOpcodes[opcode];
+ progCounter = progOpcodes[opcode];
}
} // while ()
}
#if !defined(__MSP4TH)
#define __MSP4TH
-#if defined(MSP430)
-extern int16_t *msp4th_mathStackStartAddress asm("__msp4th_mathStackStartAddress");
-extern int16_t *msp4th_addrStackStartAddress asm("__msp4th_addrStackStartAddress");
-extern int16_t *msp4th_prog asm("__msp4th_prog");
-extern int16_t *msp4th_progOpcodes asm("__msp4th_progOpcodes");
-extern uint8_t *msp4th_cmdList asm("__msp4th_cmdList");
-extern uint8_t *msp4th_lineBuffer asm("__msp4th_lineBuffer");
-extern int16_t msp4th_lineBufferLength asm("__msp4th_lineBufferLength");
-extern uint8_t *msp4th_wordBuffer asm("__msp4th_wordBuffer");
-extern int16_t msp4th_wordBufferLength asm("__msp4th_wordBufferLength");
-#else
-extern int16_t *msp4th_mathStackStartAddress;
-extern int16_t *msp4th_addrStackStartAddress;
-extern int16_t *msp4th_prog;
-extern int16_t *msp4th_progOpcodes;
-extern uint8_t *msp4th_cmdList;
-extern uint8_t *msp4th_lineBuffer;
-extern int16_t msp4th_lineBufferLength;
-extern uint8_t *msp4th_wordBuffer;
-extern int16_t msp4th_wordBufferLength;
-#endif
-
/*
- * Provide definitions for these functions in user code and assign the function
- * pointer before calling init_msp4th()
+ * Provide definitions for these arrays in user code and assign the
+ * pointers, then call msp4th_init(&config).
*/
-extern void (*msp4th_putchar)(uint8_t c);
-extern uint8_t (*msp4th_getchar)(void);
-void init_msp4th(void);
-void processLoop(void);
+struct msp4th_config {
+ int16_t *mathStackStartAddress;
+ int16_t *addrStackStartAddress;
+ int16_t *prog;
+ int16_t *progOpcodes;
+ uint8_t *cmdList;
+ uint8_t *lineBuffer;
+ int16_t lineBufferLength;
+ uint8_t *wordBuffer;
+ int16_t wordBufferLength;
+ void (*putchar)(uint8_t);
+ uint8_t (*getchar)(void);
+};
+
+void msp4th_init(struct msp4th_config *);
+void msp4th_processLoop(void);
#endif
uint8_t lineBufferArray[CMD_LIST_SIZE];
uint8_t wordBufferArray[CMD_LIST_SIZE];
+struct msp4th_config default_config;
+
+/*
int16_t *msp4th_mathStackStartAddress;
int16_t *msp4th_addrStackStartAddress;
int16_t *msp4th_prog;
int16_t msp4th_lineBufferLength;
uint8_t *msp4th_wordBuffer;
int16_t msp4th_wordBufferLength;
+*/
-void (*msp4th_putchar)(uint8_t);
-uint8_t (*msp4th_getchar)(void);
+//void (*msp4th_putchar)(uint8_t);
+//uint8_t (*msp4th_getchar)(void);
{
int16_t i;
+ default_config.mathStackStartAddress = &mathStackArray[MATH_STACK_SIZE - 1];
+ default_config.addrStackStartAddress = &addrStackArray[ADDR_STACK_SIZE - 1];
+ default_config.prog = &progArray[0];
+ default_config.progOpcodes = &progOpcodesArray[0];
+ default_config.cmdList = &cmdListArray[0];
+ default_config.lineBuffer = &lineBufferArray[0];
+ default_config.lineBufferLength = LINE_BUFFER_SIZE;
+ default_config.wordBuffer = &wordBufferArray[0];
+ default_config.wordBufferLength = WORD_BUFFER_SIZE;
+ default_config.putchar = &my_putchar;
+ default_config.getchar = &my_getchar;
+
+ /*
msp4th_mathStackStartAddress = &mathStackArray[MATH_STACK_SIZE - 1];
msp4th_addrStackStartAddress = &addrStackArray[ADDR_STACK_SIZE - 1];
msp4th_wordBuffer = &wordBufferArray[0];
msp4th_wordBufferLength = WORD_BUFFER_SIZE;
+ msp4th_putchar = &my_putchar;
+ msp4th_getchar = &my_getchar;
+ */
+
for (i=0; i < MATH_STACK_SIZE; i++) {
mathStackArray[i] = 0;
lineBufferArray[0] = 0;
wordBufferArray[0] = 0;
-
- msp4th_putchar = &my_putchar;
- msp4th_getchar = &my_getchar;
}
while (1) {
config_msp4th();
- init_msp4th();
- processLoop();
+
+ msp4th_init(&default_config);
+ msp4th_processLoop();
}
return 0;