clean:
rm -f main foci.o
+foci.o: foci.h foci.c
+
x86-64: CC := gcc -DFOCI_X86_64
-x86-64: x86/main.c foci.o
- $(CC) $(CFLAGS) $^ -o main
+x86-64: foci.o x86/main.o
+ $(CC) $(CFLAGS) $(LDFLAGS) $^ -o main
arm-cm4: CC := arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -DFOCI_ARM
arm-cm4: foci.o
msp430: CC := msp430-elf-gcc -DFOCI_MSP430 -mmcu=msp430g2553
-msp430: msp430/main.c foci.o
- $(CC) $(CFLAGS) -Lmsp430 $^ -o main
+msp430: LDFLAGS += -Lmsp430
+msp430: foci.o msp430/main.o
+ $(CC) $(CFLAGS) $(LDFLAGS) $^ -o main
+
}
RESTORE;
- *--sp = *(unsigned char *)here;
+ *--sp = *(unsigned char *)here + 1;
NEXT;
}
{
static const char dottbl[16] = "0123456789abcdef";
static char dotbuf[16] = {0};
- int i;
+ int i = 0;
if (n < 0) {
n *= -1;
foci_putchar('-');
}
- for (i = 0; n > 0; n /= 10)
+ do {
dotbuf[i++] = dottbl[n % BASE];
+ n /= BASE;
+ } while (n);
while (--i >= 0)
foci_putchar(dotbuf[i]);
+
foci_putchar(' ');
}
register intptr_t *** rp asm("r5"); // stack of pp
register intptr_t ** pp asm("r6"); // pointer to ip
register intptr_t tmp asm("r7");
-#define STASH asm("push r4; push r5; push r6")
-#define RESTORE asm("pop r6; pop r5; pop r4")
-#define NEXT asm("incd r6;\n br @r6")
+#define STASH asm("push r4\npush r5\npush r6")
+#define RESTORE asm("pop r6\npop r5\npop r4")
+#define NEXT asm("incd r6\nbr @r6")
#endif // FOCI_MSP430
extern void foci_putchar(int);
WDTCTL = WDTPW | WDTHOLD;
DCOCTL = 0;
- BCSCTL1 = CALBC1_1MHZ;
- DCOCTL = CALDCO_1MHZ;
+ BCSCTL1 = CALBC1_8MHZ;
+ DCOCTL = CALDCO_8MHZ;
P1SEL = BIT1 | BIT2; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 | BIT2; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
- UCA0BR0 = 104; // 1MHz 9600
- UCA0BR1 = 0; // 1MHz 9600
+ UCA0BR0 = 208; // 8MHz 38400
+ UCA0BR1 = 0;
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST;
void foci_putchar(int ch)
{
- while (!(IFG2 & UCA0TXIFG));
+ do asm("nop");
+ while ((IFG2 & UCA0TXIFG) == 0 || (UCA0STAT & UCBUSY) == UCBUSY);
UCA0TXBUF = ch;
+ while ((UCA0STAT & UCBUSY) == UCBUSY);
}
int foci_getchar(void)
{
int ch;
- while (!(IFG2 & UCA0RXIFG));
+ do asm("nop");
+ while ((IFG2 & UCA0RXIFG) == 0 || (UCA0STAT & UCBUSY) == UCBUSY);
ch = UCA0RXBUF;
+ do asm("nop");
+ while ((UCA0STAT & UCBUSY) == UCBUSY);
+
foci_putchar(ch);
return ch;
}