rp6502 readline extras

This commit is contained in:
rumbledethumps committed 2026-04-27 17:45:33 -07:00
1 parent b906f632fa
commit 13662115df
5 files changed
+70

No files matched your search

+4
View File
@@ -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
+7
View File
@@ -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 */
+17
View File
@@ -0,0 +1,17 @@
#include <rp6502.h>
#include <errno.h>
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;
}
+24
View File
@@ -0,0 +1,24 @@
#include <rp6502.h>
#include <errno.h>
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;
}
+18
View File
@@ -0,0 +1,18 @@
#include <rp6502.h>
#include <errno.h>
#include <string.h>
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);
}