diff --git a/asminc/rp6502.inc b/asminc/rp6502.inc index 4ab309901..fe5c16819 100644 --- a/asminc/rp6502.inc +++ b/asminc/rp6502.inc @@ -72,6 +72,9 @@ RIA_OP_GETCWD := $2B RIA_OP_SETLABEL := $2C RIA_OP_GETLABEL := $2D RIA_OP_GETFREE := $2E +RIA_OP_RLN_LASTKEY := $30 +RIA_OP_RLN_PEEK := $31 +RIA_OP_RLN_POKE := $32 ; RIA attribute IDs RIA_ATTR_ERRNO_OPT := $00 @@ -83,6 +86,7 @@ RIA_ATTR_BEL := $05 RIA_ATTR_LAUNCHER := $06 RIA_ATTR_EXIT_CODE := $07 RIA_ATTR_SIGINT := $08 +RIA_ATTR_RLN_CAPS := $09 ; 6522 VIA VIA := $FFD0 ; VIA base address diff --git a/include/rp6502.h b/include/rp6502.h index facac5e48..c6c3d9d40 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -129,6 +129,9 @@ long __fastcall__ ria_call_long (unsigned char op); #define RIA_OP_SETLABEL 0x2C #define RIA_OP_GETLABEL 0x2D #define RIA_OP_GETFREE 0x2E +#define RIA_OP_RLN_LASTKEY 0x30 +#define RIA_OP_RLN_PEEK 0x31 +#define RIA_OP_RLN_POKE 0x32 /* RIA attribute IDs */ @@ -141,6 +144,7 @@ long __fastcall__ ria_call_long (unsigned char op); #define RIA_ATTR_LAUNCHER 0x06 #define RIA_ATTR_EXIT_CODE 0x07 #define RIA_ATTR_SIGINT 0x08 +#define RIA_ATTR_RLN_CAPS 0x09 /* C API for the operating system. */ @@ -185,6 +189,9 @@ int __fastcall__ f_getcwd (char* name, int size); int __fastcall__ f_setlabel (const char* name); int __fastcall__ f_getlabel (const char* path, char* label); int __fastcall__ f_getfree (const char* name, unsigned long* free, unsigned long* total); +int __fastcall__ ria_readline_lastkey (char* key, int size); +int __fastcall__ ria_readline_peek (char* peek, int size); +int __fastcall__ ria_readline_poke (const char* poke); /* XREG location helpers */ diff --git a/libsrc/rp6502/ria_readline_lastkey.c b/libsrc/rp6502/ria_readline_lastkey.c new file mode 100644 index 000000000..2eaec058e --- /dev/null +++ b/libsrc/rp6502/ria_readline_lastkey.c @@ -0,0 +1,17 @@ +#include +#include + +int __fastcall__ ria_readline_lastkey (char* key, int size) +{ + int i, ax; + ax = ria_call_int (RIA_OP_RLN_LASTKEY); + if (ax > size) { + RIA.op = RIA_OP_ZXSTACK; + errno = ENOMEM; + return -1; + } + for (i = 0; i < ax; i++) { + key[i] = ria_pop_char (); + } + return ax; +} diff --git a/libsrc/rp6502/ria_readline_peek.c b/libsrc/rp6502/ria_readline_peek.c new file mode 100644 index 000000000..3e02c6eb3 --- /dev/null +++ b/libsrc/rp6502/ria_readline_peek.c @@ -0,0 +1,24 @@ +#include +#include + +int __fastcall__ ria_readline_peek (char* peek, int size) +{ + int i, ax; + char ch; + if (size < 1) { + errno = EINVAL; + return -1; + } + ax = ria_call_int (RIA_OP_RLN_PEEK); + i = 0; + while ((ch = ria_pop_char ()) != 0) { + if (i + 1 >= size) { + RIA.op = RIA_OP_ZXSTACK; + errno = ENOMEM; + return -1; + } + peek[i++] = ch; + } + peek[i] = 0; + return ax; +} diff --git a/libsrc/rp6502/ria_readline_poke.c b/libsrc/rp6502/ria_readline_poke.c new file mode 100644 index 000000000..e349c2246 --- /dev/null +++ b/libsrc/rp6502/ria_readline_poke.c @@ -0,0 +1,18 @@ +#include +#include +#include + +int __fastcall__ ria_readline_poke (const char* poke) +{ + int i; + size_t pokelen = strlen (poke); + if (pokelen > 254) { + errno = EINVAL; + return -1; + } + ria_push_char (0); + for (i = pokelen; i--; ) { + ria_push_char (poke[i]); + } + return ria_call_int (RIA_OP_RLN_POKE); +}