diff options
Diffstat (limited to 'src/script.c')
-rw-r--r-- | src/script.c | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/src/script.c b/src/script.c index b69b023..be0fa37 100644 --- a/src/script.c +++ b/src/script.c @@ -1,3 +1,23 @@ +/** + * @file script.c + * Provides script library for using calculator hardware + * + * Copyright (C) 2018 Clyne Sullivan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + #include <script.h> #include <builtins.h> @@ -24,19 +44,41 @@ int script_color(instance *it); int script_rand(instance *it); int script_getkey(instance *it); int script_pixel(instance *it); +int script_menu(instance *it); void script_loadlib(instance *it) { inew_cfunc(it, "print", script_puts); inew_cfunc(it, "gets", script_gets); - inew_cfunc(it, "delay", script_delay); - inew_cfunc(it, "rect", script_rect); + inew_cfunc(it, "getkey", script_getkey); inew_cfunc(it, "ppos", script_ppos); + + inew_cfunc(it, "pixel", script_pixel); inew_cfunc(it, "line", script_line); + inew_cfunc(it, "rect", script_rect); inew_cfunc(it, "color", script_color); + inew_cfunc(it, "rand", script_rand); - inew_cfunc(it, "getkey", script_getkey); - inew_cfunc(it, "pixel", script_pixel); + inew_cfunc(it, "delay", script_delay); + + inew_cfunc(it, "menu", script_menu); +} + +int script_menu(instance *it) +{ + char listbuf[4]; + int nargs = igetarg_integer(it, 0); + float *resps = (float *)calloc(nargs, sizeof(float)); + strncpy(listbuf, " : \0", 4); + for (int i = 0; i < nargs; i++) { + listbuf[0] = i + '0'; + dsp_puts(listbuf); + dsp_puts((char *)igetarg(it, 1 + i * 2)->value.p); + dsp_puts("\n"); + resps[i] = igetarg(it, 2 + i * 2)->value.f; + } + free(resps); + return 0; } int script_puts(instance *it) @@ -125,7 +167,7 @@ int script_rand(instance *it) { unsigned int mod = igetarg_integer(it, 0); unsigned int val = random_get(); - variable *v = make_varf(0, (float)(mod % val)); + variable *v = make_varf(0, (float)(val % mod)); ipush(it, (uint32_t)v); return 0; } |