diff options
-rw-r--r-- | include/initrd.h | 2 | ||||
-rw-r--r-- | initrd/calc | 8 | ||||
-rw-r--r-- | initrd/init | 11 | ||||
-rw-r--r-- | src/initrd.c | 17 | ||||
-rw-r--r-- | src/main.c | 38 | ||||
-rw-r--r-- | src/script.c | 20 |
6 files changed, 51 insertions, 45 deletions
diff --git a/include/initrd.h b/include/initrd.h index 7bc34bb..1f7c0b6 100644 --- a/include/initrd.h +++ b/include/initrd.h @@ -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 index 0000000..7359f16 --- /dev/null +++ b/initrd/calc @@ -0,0 +1,8 @@ +while (1) { + print("> ") + input = gets() + answer = solve(input) + print("\n") + print(answer) + print("\n") +} diff --git a/initrd/init b/initrd/init index 7359f16..13e5876 100644 --- a/initrd/init +++ b/initrd/init @@ -1,8 +1,3 @@ -while (1) { - print("> ") - input = gets() - answer = solve(input) - print("\n") - print(answer) - print("\n") -} +choice = filemenu +print("\nChoice: ") +print(choice) diff --git a/src/initrd.c b/src/initrd.c index 37e3764..b8e8d09 100644 --- a/src/initrd.c +++ b/src/initrd.c @@ -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); @@ -45,7 +45,7 @@ int main(void) {
asm("cpsid i");
// disable cached writes for precise debug info
- *((uint32_t *)0xE000E008) |= 2;
+ //*((uint32_t *)0xE000E008) |= 2;
// prepare flash latency for 80MHz operation
FLASH->ACR &= ~(FLASH_ACR_LATENCY);
@@ -77,20 +77,7 @@ void kmain(void) keypad_start();
task_start(task_interpreter, 4096);
- /*char buf[2];
- flash_init();
- buf[0] = 'A';
- flash_write(buf, 0, 1);
- buf[0] = 0;
- flash_read(buf, 0x00000000, 1);
- buf[0] += ' ';
- buf[1] = '\0';
- dsp_puts(buf);*/
-
while (1) {
- //gpio_dout(GPIOA, 5,
- // (keypad_isdown(K0)));
- //delay(10);
gpio_dout(GPIOA, 5, 1);
delay(250);
gpio_dout(GPIOA, 5, 0);
@@ -140,26 +127,3 @@ end: delay(10);
}
-// for interactive use
-/*int ret = 0;
-char *linebuf = malloc(100), c[2] = {0, 0};
-while (1) {
- uint16_t index = 0;
- if (it.indent > 0)
- dsp_puts(">");
- dsp_puts("> ");
- do {
- c[0] = serial_get();
- if (c[0] >= ' ' || c[0] == '\r') {
- linebuf[index] = c[0];
- if (c[0] >= ' ')
- dsp_puts(c);
- }
- } while (linebuf[index] != '\r' && index++ < 100);
- linebuf[index] = '\0';
- dsp_puts("\n");
- ret = idoline(&it, linebuf);
- if (ret < 0)
- break;
-}*/
-
diff --git a/src/script.c b/src/script.c index 0ce5509..518edc5 100644 --- a/src/script.c +++ b/src/script.c @@ -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); |