From 2138f3c902f2bcbe538a62fae5e7e36c36ea2c2a Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Wed, 10 Jan 2024 21:24:55 -0800 Subject: [PATCH 1/5] add clock() to RP6502 --- include/rp6502.h | 1 + include/time.h | 2 ++ libsrc/rp6502/clock.c | 7 +++++++ 3 files changed, 10 insertions(+) create mode 100644 libsrc/rp6502/clock.c diff --git a/include/rp6502.h b/include/rp6502.h index 2b40cfc71..61664c78f 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -101,6 +101,7 @@ long __fastcall__ ria_call_long_errno (unsigned char op); #define RIA_OP_CODEPAGE 0x03 #define RIA_OP_LRAND 0x04 #define RIA_OP_STDIN_OPT 0x05 +#define RIA_OP_CLOCK 0x0F #define RIA_OP_CLOCK_GETRES 0x10 #define RIA_OP_CLOCK_GETTIME 0x11 #define RIA_OP_CLOCK_SETTIME 0x12 diff --git a/include/time.h b/include/time.h index f8977ab0c..5eb6f144a 100644 --- a/include/time.h +++ b/include/time.h @@ -86,6 +86,8 @@ struct tm { # define CLOCKS_PER_SEC 135 /* FIXME */ #elif defined(__GEOS__) # define CLOCKS_PER_SEC 1 +#elif defined (__RP6502__) +# define CLOCKS_PER_SEC 100 #elif defined(__TELESTRAT__) # define CLOCKS_PER_SEC 10 #elif defined(__ATARI__) || defined (__LYNX__) diff --git a/libsrc/rp6502/clock.c b/libsrc/rp6502/clock.c new file mode 100644 index 000000000..f8756f553 --- /dev/null +++ b/libsrc/rp6502/clock.c @@ -0,0 +1,7 @@ +#include +#include + +clock_t __fastcall__ clock (void) +{ + return ria_call_long (RIA_OP_CLOCK); +} From 9ffa2d05e65fd0aa3455235ffc5cc74cd9159c58 Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Tue, 30 Jan 2024 00:17:28 -0800 Subject: [PATCH 2/5] rp6502 validate write_xstack count --- include/rp6502.h | 3 +-- libsrc/rp6502/write_xstack.c | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/rp6502.h b/include/rp6502.h index 61664c78f..53028c35a 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -47,8 +47,7 @@ struct __RP6502 unsigned char step1; unsigned int addr1; unsigned char xstack; - unsigned char errno_lo; - unsigned char errno_hi; + unsigned int errno; unsigned char op; unsigned char irq; const unsigned char spin; diff --git a/libsrc/rp6502/write_xstack.c b/libsrc/rp6502/write_xstack.c index b53aa95e7..ff979899d 100644 --- a/libsrc/rp6502/write_xstack.c +++ b/libsrc/rp6502/write_xstack.c @@ -1,8 +1,12 @@ #include +#include int __fastcall__ write_xstack (const void* buf, unsigned count, int fildes) { unsigned i; + if (count > 256) { + return _mappederrno (EINVAL); + } for (i = count; i;) { ria_push_char (((char*)buf)[--i]); } From 7b790cf8833668c21447490b8b84a0e704a3f134 Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Sun, 4 Feb 2024 23:38:44 -0800 Subject: [PATCH 3/5] add RIA_OP_CLOCK to asm inc --- asminc/rp6502.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/asminc/rp6502.inc b/asminc/rp6502.inc index 7dd1b8fcd..816712abb 100644 --- a/asminc/rp6502.inc +++ b/asminc/rp6502.inc @@ -37,6 +37,7 @@ RIA_OP_PHI2 := $02 RIA_OP_CODEPAGE := $03 RIA_OP_LRAND := $04 RIA_OP_STDIN_OPT := $05 +RIA_OP_CLOCK := $0F RIA_OP_CLOCK_GETRES := $10 RIA_OP_CLOCK_GETTIME := $11 RIA_OP_CLOCK_SETTIME := $12 From f42e6a26b2b6f5f7df260cec15e21b04c8fee12c Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Sat, 17 Feb 2024 15:47:51 -0800 Subject: [PATCH 4/5] xstack bump to 512 --- libsrc/rp6502/read.c | 2 +- libsrc/rp6502/sysrename.c | 2 +- libsrc/rp6502/write.c | 2 +- libsrc/rp6502/write_xstack.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libsrc/rp6502/read.c b/libsrc/rp6502/read.c index eb96f779c..87a9bbf7d 100644 --- a/libsrc/rp6502/read.c +++ b/libsrc/rp6502/read.c @@ -5,7 +5,7 @@ int __fastcall__ read (int fildes, void* buf, unsigned count) { int total = 0; while (count) { - unsigned blockcount = (count > 256) ? 256 : count; + unsigned blockcount = (count > 512) ? 512 : count; int bytes_read = read_xstack (&((char*)buf)[total], blockcount, fildes); if (bytes_read < 0) { return bytes_read; diff --git a/libsrc/rp6502/sysrename.c b/libsrc/rp6502/sysrename.c index 96eca24cf..46bdd8b31 100644 --- a/libsrc/rp6502/sysrename.c +++ b/libsrc/rp6502/sysrename.c @@ -7,7 +7,7 @@ unsigned char __fastcall__ _sysrename (const char* oldpath, const char* newpath) size_t oldpathlen, newpathlen; oldpathlen = strlen (oldpath); newpathlen = strlen (newpath); - if (oldpathlen + newpathlen > 254) { + if (oldpathlen + newpathlen > 510) { return _mappederrno (EINVAL); } while (oldpathlen) { diff --git a/libsrc/rp6502/write.c b/libsrc/rp6502/write.c index 11241dab5..23877b6e8 100644 --- a/libsrc/rp6502/write.c +++ b/libsrc/rp6502/write.c @@ -5,7 +5,7 @@ int __fastcall__ write (int fildes, const void* buf, unsigned count) { int ax, total = 0; while (count) { - int blockcount = (count > 256) ? 256 : count; + int blockcount = (count > 512) ? 512 : count; ax = write_xstack (&((char*)buf)[total], blockcount, fildes); if (ax < 0) { return ax; diff --git a/libsrc/rp6502/write_xstack.c b/libsrc/rp6502/write_xstack.c index ff979899d..29285a87e 100644 --- a/libsrc/rp6502/write_xstack.c +++ b/libsrc/rp6502/write_xstack.c @@ -4,7 +4,7 @@ int __fastcall__ write_xstack (const void* buf, unsigned count, int fildes) { unsigned i; - if (count > 256) { + if (count > 512) { return _mappederrno (EINVAL); } for (i = count; i;) { From 4d3153e10e185323ca0d89c4d17b43bdffa803ca Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Sat, 17 Feb 2024 16:02:57 -0800 Subject: [PATCH 5/5] add rp6502 xregn --- include/rp6502.h | 2 ++ libsrc/rp6502/xregn.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 libsrc/rp6502/xregn.c diff --git a/include/rp6502.h b/include/rp6502.h index 53028c35a..7deeebc4c 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -117,6 +117,8 @@ long __fastcall__ ria_call_long_errno (unsigned char op); /* C API for the operating system. */ +int __cdecl__ xregn (char device, char channel, unsigned char address, unsigned count, + ...); int __cdecl__ xreg (char device, char channel, unsigned char address, ...); int phi2 (void); int codepage (void); diff --git a/libsrc/rp6502/xregn.c b/libsrc/rp6502/xregn.c new file mode 100644 index 000000000..ec040be20 --- /dev/null +++ b/libsrc/rp6502/xregn.c @@ -0,0 +1,19 @@ +#include +#include + +int __cdecl__ xregn (char device, char channel, unsigned char address, unsigned count, + ...) +{ + va_list args; + va_start (args, count); + RIA.xstack = device; + RIA.xstack = channel; + RIA.xstack = address; + while (count--) { + unsigned v = va_arg (args, unsigned); + RIA.xstack = v >> 8; + RIA.xstack = v; + } + va_end (args); + return ria_call_int_errno (RIA_OP_XREG); +}