]> code.bitgloo.com Git - clyne/calculator.git/commitdiff
graphing perfection
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 8 Mar 2018 17:17:58 +0000 (12:17 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 8 Mar 2018 17:17:58 +0000 (12:17 -0500)
initrd/init
libinterp.a
src/display_draw.c
src/heap.c
src/script.c
src/stdlib.c
src/stm32l4xx_it.c

index a2508224c1b9451a64983e480b914a03358e842a..49087471dca99fad4743d233a0fd3dd4059c7b2a 100644 (file)
@@ -58,7 +58,7 @@ do
                do
                        solve Fx > y
                        set y (0 - y)
-                       if ((y > ymin) & (y < ymax))
+                       if ((y >= ymin) & (y <= ymax))
                                pixel (cx + x * xinc) (cy + y * yinc) 511
                        end
                        set x (x + 1 / xinc)
index 2d0400d5b353ae437de29b69131a42fadc24320f..11ca083c3e1cf243d002cf66fcb3a122ca5e1f27 100644 (file)
Binary files a/libinterp.a and b/libinterp.a differ
index 62578e31f28d339754869edd7f4d6b02e7276bc0..f58dda77b5aa3d66277194b66b3c4c802e7130e7 100644 (file)
@@ -39,10 +39,15 @@ void dsp_putchar(int c)
                if (++cury == 12) {
                        UNLOCK;
                        dsp_rect(0, 0, LCD_WIDTH, LCD_HEIGHT, 0);
-                       LOCK;
                        cury = 0;
                }
                return;
+       } else if (c == '\b') {
+               if (curx > 0)
+                       curx--;
+               UNLOCK;
+               dsp_rect(curxo + curx * 12, curyo + cury * 26, 12, 26, 0);
+               return;
        }
 
        unsigned int start = ((c - ' ') / 16 * 192 * 26 + (c % 16) * 12) * 2;
index 92978b7251933db3bad6d227637917bf0b68330c..52b52533110cb63c6e8fce4a235e065f40fabb29 100644 (file)
@@ -1,7 +1,6 @@
 #include <heap.h>
-#include <task.h>
 
-#define HEAP_ALIGN 16
+#define HEAP_ALIGN 4
 
 typedef struct {
        uint32_t size;
@@ -10,7 +9,7 @@ typedef struct {
 
 static alloc_t *free_blocks;
 static void *heap_end;
-static uint32_t heap_used;
+uint32_t heap_used;
 
 void heap_init(void *buf)
 {
@@ -21,17 +20,29 @@ void heap_init(void *buf)
 
 void *malloc(uint32_t size)
 {
-       //task_hold(1);
        size = (size + sizeof(alloc_t) + HEAP_ALIGN) & ~(HEAP_ALIGN - 1);
 
        alloc_t *node = free_blocks;
        alloc_t *prev = 0;
        while (node != 0) {
                if (node->size >= size) {
-                       if (prev != 0)
-                               prev->next = node->next;
-                       else
-                               free_blocks = node->next;
+                       /*if (node->size > size + sizeof(alloc_t) + HEAP_ALIGN) {
+                               alloc_t *rem = (alloc_t *)((uint8_t *)node +
+                                       sizeof(alloc_t) + size);
+                               rem->size = node->size - size - sizeof(alloc_t);
+                               rem->next = node->next;
+                               if (prev != 0)
+                                       prev->next = rem;
+                               else
+                                       free_blocks = rem;
+                               node->size = size;
+                       } else {*/
+                               if (prev != 0)
+                                       prev->next = node->next;
+                               else
+                                       free_blocks = node->next;
+                       //}
+
                        node->next = 0;
                        heap_used += node->size;
                        return (void *)((uint8_t *)node + sizeof(alloc_t));
@@ -48,7 +59,6 @@ void *malloc(uint32_t size)
        heap_end = (void *)((uint8_t *)heap_end + size);
        heap_used += size;
 
-       //task_hold(0);
        return (void *)((uint8_t *)node + sizeof(alloc_t)); 
 }
 
index 495e409f4af60b6ec9b7fb4d52f1e8232406a725..8fad2f33d2cd480696f708c10f36d58576683fc7 100644 (file)
@@ -22,7 +22,6 @@ int script_color(interpreter *it);
 int script_rand(interpreter *it);
 int script_getkey(interpreter *it);
 int script_pixel(interpreter *it);
-int script_solve(interpreter *it);
 
 void script_loadlib(interpreter *it)
 {
@@ -36,7 +35,6 @@ void script_loadlib(interpreter *it)
        inew_cfunc(it, "rand", script_rand);
        inew_cfunc(it, "getkey", script_getkey);
        inew_cfunc(it, "pixel", script_pixel);
-       inew_cfunc(it, "solve", script_solve);
 }
 
 int script_puts(interpreter *it)
@@ -50,14 +48,21 @@ int script_gets(interpreter *it)
 {
        char *s = malloc(64);
        char c[2] = {0, 0};
-       uint16_t index = 0;
+       int index = 0;
 
        do {
                c[0] = serial_get();
                s[index] = c[0];
-               if (c[0] != '\r')
+               if (c[0] == '\b' || c[0] == 127) {
+                       index--;
+                       if (index > -1) {
+                               dsp_puts("\b");
+                               index--;
+                       }
+               } else if (c[0] != '\r') {
                        dsp_puts(c);
-       } while (s[index] != '\r' && index++ < 23);
+               }
+       } while (s[index] != '\r' && index++ < 63);
        s[index] = '\0';
 
        variable *r = make_vars(0, s);
@@ -135,18 +140,3 @@ int script_pixel(interpreter *it)
        return 0;
 }
 
-int script_solve(interpreter *it)
-{
-       const char *expr = igetarg_string(it, 0);
-       int len = strlen(expr);
-       char *buf = (char *)malloc(len + 2);
-       strcpy(buf, expr);
-       buf[len] = ')';
-       buf[len + 1] = '\0';
-       variable *r = idoexpr(it, buf);
-       if (r == 0)
-               r = make_varn(0, 0.0f);
-       iret(it, r);
-       free(r);
-       return 0;
-}
index ec67ff357082f5ab8bd05b9bdccafe632bdc7a50..e34d2a0f5e2b69898ac0a0745e2ef5136f37ce9c 100644 (file)
@@ -67,15 +67,49 @@ float strtof(const char *s, char **endptr)
 {
        (void)s;
        (void)endptr;
-       return 0.0f;
+
+       float res = 0.0f;
+       char neg = 0;
+       unsigned int i = 0;
+
+       if (s[0] == '-') {
+               neg = 1;
+               i++;
+       }
+
+       for (; isdigit(s[i]); i++) {
+               res *= 10.0f;
+               res += (s[i] - '0');
+       }
+
+       if (s[i] != '.')
+               goto end;
+
+       float div = 0.1f;
+       for (i++; isdigit(s[i]); i++) {
+               res += div * (s[i] - '0');
+               div /= 10.0f;
+       }
+
+end:
+       return (neg == 0) ? res : -res;
 }
 
 int atoi(const char *s)
 {
+       unsigned int i = 0;
+       char neg = 0;
        int n = 0;
-       for (unsigned int i = 0; isdigit(s[i]); i++) {
+
+       if (s[0] == '-') {
+               neg = 1;
+               i = 1;
+       }
+
+       for (; isdigit(s[i]); i++) {
                n *= 10;
                n += s[i] - '0';
        }
-       return n;
+
+       return (neg == 0) ? n : -n;
 }
index e54a19271ecde59017925f5bc4c3e1146ab4d32b..228dc67e59eb66f91ce7be5c22707a5a5425c5ce 100644 (file)
@@ -12,12 +12,16 @@ void serial_puts(const char *s)
 \r
 void perror(const char *s)\r
 {\r
-       //extern task_t *current;\r
+       extern uint32_t heap_used;\r
        serial_puts(s);\r
-       //char buf[200];\r
-       //snprintf(buf, 200, "xPSR: %x\r\nPC: %x\r\nLR: %x\r\n", current->sp[0],\r
-       //      current->sp[1], current->sp[2]);\r
-       //serial_puts(buf);\r
+\r
+       static char buf[200];\r
+       uint32_t *psp;\r
+       asm("mrs %0, psp" : "=r"(psp));\r
+\r
+       snprintf(buf, 200, "\r\nPC: %x\r\nLR: %x\r\nmemused: %db\r\n",\r
+               psp[6], psp[5], heap_used);\r
+       serial_puts(buf);\r
 }\r
 \r
 __attribute__ ((naked))\r