]> code.bitgloo.com Git - clyne/calculator.git/commitdiff
adding support for loading files throught script
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 29 Mar 2018 02:33:39 +0000 (22:33 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 29 Mar 2018 02:33:39 +0000 (22:33 -0400)
include/initrd.h
initrd/calc [new file with mode: 0644]
initrd/init
src/initrd.c
src/main.c
src/script.c

index 7bc34bbcc0db1c77ae04c7f81394d4c8df628940..1f7c0b6a52589cb97ff60178ca53a281cf19c4e2 100644 (file)
@@ -65,4 +65,6 @@ char *initrd_getfile(const char *name);
  */
 uint32_t initrd_getfilesize(const char *name);
 
+char *initrd_getnfile(unsigned int index);
+
 #endif // INITRD_H_
diff --git a/initrd/calc b/initrd/calc
new file mode 100644 (file)
index 0000000..7359f16
--- /dev/null
@@ -0,0 +1,8 @@
+while (1) {
+       print("> ")
+       input = gets()
+       answer = solve(input)
+       print("\n")
+       print(answer)
+       print("\n")
+}
index 7359f164cbabae0af6d6b4c636d11bafe753f7bf..13e5876c7db5a7c708150d08dbbca8cb4ca8955f 100644 (file)
@@ -1,8 +1,3 @@
-while (1) {
-       print("> ")
-       input = gets()
-       answer = solve(input)
-       print("\n")
-       print(answer)
-       print("\n")
-}
+choice = filemenu
+print("\nChoice: ")
+print(choice)
index 37e3764f778917107dc045022b90e37a5edffc05..b8e8d09a80c09902ebcd266e7801807eac19d7a3 100644 (file)
@@ -90,6 +90,23 @@ initrd_file *initrd_getfileptr(const char *name)
        return 0;
 }
 
+char *initrd_getnfile(unsigned int index)
+{
+       initrd_file *file = (initrd_file *)((uint8_t *)initrd_start + sizeof(initrd_header));
+       uint32_t offset = sizeof(initrd_header);
+
+       for (unsigned int i = 0; i < index; i++) {
+               uint32_t size = initrd_getsize(file) + sizeof(initrd_file);
+               offset += size;
+               file = (initrd_file *)((uint8_t *)file + size);
+               if (file->name[0] == '\n')
+                       file = (initrd_file *)((uint32_t)file + 1);
+       }
+       if ((uint32_t)file >= (uint32_t)initrd_start + initrd_size)
+               return 0;
+       return file->name;
+}
+
 char *initrd_getfile(const char *name)
 {
        initrd_file *file = initrd_getfileptr(name);
index 65fa1d3141e6d77b8f68d9a960a3c76286b3746b..c9d37896648a1b545ac57ebbbf7fb4b6fdfa2691 100644 (file)
@@ -45,7 +45,7 @@ int main(void)
 {\r
        asm("cpsid i");\r
        // disable cached writes for precise debug info\r
-       *((uint32_t *)0xE000E008) |= 2;\r
+       //*((uint32_t *)0xE000E008) |= 2;\r
 \r
        // prepare flash latency for 80MHz operation\r
        FLASH->ACR &= ~(FLASH_ACR_LATENCY);\r
@@ -77,20 +77,7 @@ void kmain(void)
        keypad_start();\r
        task_start(task_interpreter, 4096);\r
 \r
-       /*char buf[2];\r
-       flash_init();\r
-       buf[0] = 'A';\r
-       flash_write(buf, 0, 1);\r
-       buf[0] = 0;\r
-       flash_read(buf, 0x00000000, 1);\r
-       buf[0] += ' ';\r
-       buf[1] = '\0';\r
-       dsp_puts(buf);*/\r
-\r
        while (1) {\r
-               //gpio_dout(GPIOA, 5,\r
-               //      (keypad_isdown(K0)));\r
-               //delay(10);\r
                gpio_dout(GPIOA, 5, 1);\r
                delay(250);\r
                gpio_dout(GPIOA, 5, 0);\r
@@ -140,26 +127,3 @@ end:
                delay(10);\r
 }\r
 \r
-// for interactive use\r
-/*int ret = 0;\r
-char *linebuf = malloc(100), c[2] = {0, 0};\r
-while (1) {\r
-       uint16_t index = 0;\r
-       if (it.indent > 0)\r
-               dsp_puts(">");\r
-       dsp_puts("> ");\r
-       do {\r
-               c[0] = serial_get();\r
-               if (c[0] >= ' ' || c[0] == '\r') {\r
-                       linebuf[index] = c[0];\r
-                       if (c[0] >= ' ')\r
-                               dsp_puts(c);\r
-               }\r
-       } while (linebuf[index] != '\r' && index++ < 100);\r
-       linebuf[index] = '\0';\r
-       dsp_puts("\n");\r
-       ret = idoline(&it, linebuf);\r
-       if (ret < 0)\r
-               break;\r
-}*/\r
-\r
index 0ce5509ddbaac93460e54ceb1468e291409c1fc8..518edc55e2e04652d47eb080980cb5a82d731ccc 100644 (file)
@@ -25,6 +25,7 @@
 #include <display.h>
 #include <display_draw.h>
 #include <heap.h>
+#include <initrd.h>
 #include <random.h>
 #include <serial.h>
 #include <stdlib.h>
@@ -46,6 +47,7 @@ int script_rand(instance *it);
 int script_getkey(instance *it);
 int script_pixel(instance *it);
 int script_menu(instance *it);
+int script_filemenu(instance *it);
 
 void script_loadlib(instance *it)
 {
@@ -64,6 +66,7 @@ void script_loadlib(instance *it)
        inew_cfunc(it, "delay", script_delay);
 
        inew_cfunc(it, "menu", script_menu);
+       inew_cfunc(it, "filemenu", script_filemenu);
 }
 
 int script_menu(instance *it)
@@ -83,6 +86,23 @@ int script_menu(instance *it)
        return 0;
 }
 
+int script_filemenu(instance *it)
+{
+       char listbuf[4];
+       char *buf = calloc(17, 1);
+       char *fname;
+       strncpy(listbuf, " : \0", 4);
+       dsp_puts("Choose a file: \n");
+       for (unsigned int i = 0; (fname = initrd_getnfile(i)) != 0; i++) {
+               listbuf[0] = i + '0';
+               dsp_puts(listbuf);
+               dsp_puts(strncpy(buf, fname, 16));
+               dsp_puts("\n");
+       }
+       free(buf);
+       return script_gets(it);
+}
+
 int script_puts(instance *it)
 {
        variable *v = igetarg(it, 0);