]> code.bitgloo.com Git - clyne/foci.git/commitdiff
msp430 improvements; fix compname bug
authorClyne Sullivan <clyne@bitgloo.com>
Mon, 27 Jan 2025 20:51:03 +0000 (15:51 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Mon, 27 Jan 2025 20:51:03 +0000 (15:51 -0500)
Makefile
foci.c
foci.h
msp430/main.c

index 54338b63d9bfe462ab54ff6dd5ad1599d7f16d4c..71dce0009ebeff5a82702677c4ab8cf0565d4c25 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,13 +5,17 @@ all: x86-64
 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
+
diff --git a/foci.c b/foci.c
index 107d31771b5ae8470649e62b11da2872afc6ccf6..8dedfbd0e80e6c91bd6ae8cef2547d480973f809 100644 (file)
--- a/foci.c
+++ b/foci.c
@@ -53,7 +53,7 @@ NAKED void compname(void)
     }
 
     RESTORE;
-    *--sp = *(unsigned char *)here;
+    *--sp = *(unsigned char *)here + 1;
     NEXT;
 }
 
@@ -172,18 +172,21 @@ static void dotimpl(intptr_t n)
 {
     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(' ');
 }
 
diff --git a/foci.h b/foci.h
index c7d6fcbe9e7649f16f817cb0d9f5f7a5e3638da4..9c21c2712b3187bb0cbc5dcc14e1ae61e3f0b802 100644 (file)
--- a/foci.h
+++ b/foci.h
@@ -82,9 +82,9 @@ register intptr_t *   sp  asm("r4"); // pointer to stack cells
 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);
index 1e691d36e7501f5fb6ae975c05b064b4b8d7acc7..fd0489fcba0e1dcaa089196b42e5c76b25afc58a 100644 (file)
@@ -7,14 +7,14 @@ int main()
     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;
 
@@ -35,16 +35,22 @@ int main()
 
 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;
 }