aboutsummaryrefslogtreecommitdiffstats
path: root/src/script.c
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2018-03-27 12:00:57 -0400
committerClyne Sullivan <clyne@bitgloo.com>2018-03-27 12:00:57 -0400
commitefd1e11475088284803f5db0f554f6ef2d0268f5 (patch)
tree1dc9cb84ed50bb19ab805f73a2ed8baefa02fb7f /src/script.c
parentb398f319c74d12f2d1641c1fc16dbd5e14bff0b4 (diff)
functional keypad, va_arg bug discovery
Diffstat (limited to 'src/script.c')
-rw-r--r--src/script.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/script.c b/src/script.c
index be0fa37..0ce5509 100644
--- a/src/script.c
+++ b/src/script.c
@@ -35,6 +35,7 @@
#define igetarg_integer(it, n) ((int)igetarg(it, n)->value.f)
int script_puts(instance *it);
+int script_putchar(instance *it);
int script_gets(instance *it);
int script_delay(instance *it);
int script_rect(instance *it);
@@ -49,6 +50,7 @@ int script_menu(instance *it);
void script_loadlib(instance *it)
{
inew_cfunc(it, "print", script_puts);
+ inew_cfunc(it, "putchar", script_putchar);
inew_cfunc(it, "gets", script_gets);
inew_cfunc(it, "getkey", script_getkey);
inew_cfunc(it, "ppos", script_ppos);
@@ -86,7 +88,7 @@ int script_puts(instance *it)
variable *v = igetarg(it, 0);
if (v->type == NUMBER) {
char buf[33];
- snprintf(buf, 33, "%f", v->value.f);
+ snprintf(buf, 33, "%d", (int)v->value.f); // TODO
dsp_puts(buf);
} else if (v->type == STRING) {
dsp_puts((const char *)v->value.p);
@@ -94,6 +96,18 @@ int script_puts(instance *it)
return 0;
}
+int script_putchar(instance *it)
+{
+ variable *v = igetarg(it, 0);
+ char buf[2];
+
+ buf[0] = (int)v->value.f;
+ buf[1] = '\0';
+ dsp_puts(buf);
+
+ return 0;
+}
+
int script_gets(instance *it)
{
char *s = malloc(64);
@@ -101,7 +115,11 @@ int script_gets(instance *it)
int index = 0;
do {
- c[0] = serial_get();
+ do {
+ c[0] = keypad_get();
+ delay(1);
+ } while (c[0] == 0);
+ //c[0] = serial_get();
s[index] = c[0];
if (c[0] == '\b' || c[0] == 127) {
index--;
@@ -109,10 +127,10 @@ int script_gets(instance *it)
dsp_puts("\b");
index--;
}
- } else if (c[0] != '\r') {
+ } else if (c[0] != '\n'/*'\r'*/) {
dsp_puts(c);
}
- } while (s[index] != '\r' && index++ < 63);
+ } while (s[index] != '\n'/*'\r'*/ && index++ < 63);
s[index] = '\0';
variable *r = make_vars(0, s);