From 34bb14bc6ec813b5530795851608c7d91c12b4fb Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Sun, 27 Apr 2025 23:52:23 -0700 Subject: [PATCH 01/19] improve validation errors --- libsrc/rp6502/close.c | 2 +- libsrc/rp6502/open.c | 4 +++- libsrc/rp6502/stdin_opt.c | 1 - libsrc/rp6502/sysremove.c | 3 ++- libsrc/rp6502/sysrename.c | 3 ++- libsrc/rp6502/write_xstack.c | 3 ++- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libsrc/rp6502/close.c b/libsrc/rp6502/close.c index dd7e38115..9dea5bdc3 100644 --- a/libsrc/rp6502/close.c +++ b/libsrc/rp6502/close.c @@ -1,5 +1,5 @@ #include -#include +#include int __fastcall__ close (int fd) { diff --git a/libsrc/rp6502/open.c b/libsrc/rp6502/open.c index ab3a374a2..2061c9813 100644 --- a/libsrc/rp6502/open.c +++ b/libsrc/rp6502/open.c @@ -1,12 +1,14 @@ #include #include #include +#include int __cdecl__ open (const char* name, int flags, ...) { size_t namelen = strlen (name); if (namelen > 255) { - return _mappederrno (EINVAL); + RIA.errno = EINVAL; + return _mappederrno(RIA.errno); } while (namelen) { ria_push_char (name[--namelen]); diff --git a/libsrc/rp6502/stdin_opt.c b/libsrc/rp6502/stdin_opt.c index 3a9ccfde4..69e6f51cd 100644 --- a/libsrc/rp6502/stdin_opt.c +++ b/libsrc/rp6502/stdin_opt.c @@ -1,4 +1,3 @@ - #include int __fastcall__ stdin_opt (unsigned long ctrl_bits, unsigned char str_length) diff --git a/libsrc/rp6502/sysremove.c b/libsrc/rp6502/sysremove.c index d8c1ced98..22d2a65fc 100644 --- a/libsrc/rp6502/sysremove.c +++ b/libsrc/rp6502/sysremove.c @@ -7,7 +7,8 @@ unsigned char __fastcall__ _sysremove (const char* name) size_t namelen; namelen = strlen (name); if (namelen > 255) { - return _mappederrno (EINVAL); + RIA.errno = EINVAL; + return __mappederrno(RIA.errno); } while (namelen) { ria_push_char (name[--namelen]); diff --git a/libsrc/rp6502/sysrename.c b/libsrc/rp6502/sysrename.c index 46bdd8b31..e05ad725a 100644 --- a/libsrc/rp6502/sysrename.c +++ b/libsrc/rp6502/sysrename.c @@ -8,7 +8,8 @@ unsigned char __fastcall__ _sysrename (const char* oldpath, const char* newpath) oldpathlen = strlen (oldpath); newpathlen = strlen (newpath); if (oldpathlen + newpathlen > 510) { - return _mappederrno (EINVAL); + RIA.errno = EINVAL; + return __mappederrno(RIA.errno); } while (oldpathlen) { ria_push_char (oldpath[--oldpathlen]); diff --git a/libsrc/rp6502/write_xstack.c b/libsrc/rp6502/write_xstack.c index 29285a87e..b356ec706 100644 --- a/libsrc/rp6502/write_xstack.c +++ b/libsrc/rp6502/write_xstack.c @@ -5,7 +5,8 @@ int __fastcall__ write_xstack (const void* buf, unsigned count, int fildes) { unsigned i; if (count > 512) { - return _mappederrno (EINVAL); + RIA.errno = EINVAL; + return __mappederrno(RIA.errno); } for (i = count; i;) { ria_push_char (((char*)buf)[--i]); From 096095840f7583d0facc8beed830839e3d7fbfea Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Fri, 23 May 2025 19:25:46 -0700 Subject: [PATCH 02/19] fix RIA.errno macro conflict --- include/rp6502.h | 2 +- libsrc/rp6502/open.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/rp6502.h b/include/rp6502.h index 7deeebc4c..33e983de3 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -47,7 +47,7 @@ struct __RP6502 unsigned char step1; unsigned int addr1; unsigned char xstack; - unsigned int errno; + unsigned int errno_; unsigned char op; unsigned char irq; const unsigned char spin; diff --git a/libsrc/rp6502/open.c b/libsrc/rp6502/open.c index 2061c9813..187c57625 100644 --- a/libsrc/rp6502/open.c +++ b/libsrc/rp6502/open.c @@ -7,8 +7,8 @@ int __cdecl__ open (const char* name, int flags, ...) { size_t namelen = strlen (name); if (namelen > 255) { - RIA.errno = EINVAL; - return _mappederrno(RIA.errno); + RIA.errno_ = EINVAL; + return _mappederrno (RIA.errno_); } while (namelen) { ria_push_char (name[--namelen]); From 795cc55e450db3958445895fd1175e9e392003fd Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Fri, 23 May 2025 19:26:27 -0700 Subject: [PATCH 03/19] tzset() --- include/time.h | 1 + libsrc/rp6502/tzset.c | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 libsrc/rp6502/tzset.c diff --git a/include/time.h b/include/time.h index 5eb6f144a..d320fe3f1 100644 --- a/include/time.h +++ b/include/time.h @@ -134,6 +134,7 @@ extern struct _timezone { int __fastcall__ clock_getres (clockid_t clock_id, struct timespec *res); int __fastcall__ clock_gettime (clockid_t clock_id, struct timespec *tp); int __fastcall__ clock_settime (clockid_t clock_id, const struct timespec *tp); +void tzset (void); #endif diff --git a/libsrc/rp6502/tzset.c b/libsrc/rp6502/tzset.c new file mode 100644 index 000000000..be4236f2f --- /dev/null +++ b/libsrc/rp6502/tzset.c @@ -0,0 +1,9 @@ +#include +#include + +int clock_gettimezone (clockid_t clock_id, struct _timezone* tz); + +void tzset (void) +{ + clock_gettimezone (CLOCK_REALTIME, &_tz); +} From b6d261ba2b4eb2523808bff24aedc7132a913ad0 Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Sat, 24 May 2025 21:27:05 -0700 Subject: [PATCH 04/19] change to ria_tzset --- include/rp6502.h | 4 ++++ include/time.h | 1 - libsrc/rp6502/gettimezone.c | 3 ++- libsrc/rp6502/ria_tzset.c | 9 +++++++++ libsrc/rp6502/sysremove.c | 4 ++-- libsrc/rp6502/sysrename.c | 4 ++-- libsrc/rp6502/tzset.c | 9 --------- libsrc/rp6502/write_xstack.c | 4 ++-- 8 files changed, 21 insertions(+), 17 deletions(-) create mode 100644 libsrc/rp6502/ria_tzset.c delete mode 100644 libsrc/rp6502/tzset.c diff --git a/include/rp6502.h b/include/rp6502.h index 33e983de3..c1f60d89a 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -129,6 +129,10 @@ int __fastcall__ read_xram (unsigned buf, unsigned count, int fildes); int __fastcall__ write_xstack (const void* buf, unsigned count, int fildes); int __fastcall__ write_xram (unsigned buf, unsigned count, int fildes); +/* Time zone hack */ + +void ria_tzset (unsigned long time); + /* XREG location helpers */ #define xreg_ria_keyboard(...) xreg(0, 0, 0, __VA_ARGS__) diff --git a/include/time.h b/include/time.h index d320fe3f1..5eb6f144a 100644 --- a/include/time.h +++ b/include/time.h @@ -134,7 +134,6 @@ extern struct _timezone { int __fastcall__ clock_getres (clockid_t clock_id, struct timespec *res); int __fastcall__ clock_gettime (clockid_t clock_id, struct timespec *tp); int __fastcall__ clock_settime (clockid_t clock_id, const struct timespec *tp); -void tzset (void); #endif diff --git a/libsrc/rp6502/gettimezone.c b/libsrc/rp6502/gettimezone.c index f3cb2a061..86d0fefcc 100644 --- a/libsrc/rp6502/gettimezone.c +++ b/libsrc/rp6502/gettimezone.c @@ -1,10 +1,11 @@ #include #include -int clock_gettimezone (clockid_t clock_id, struct _timezone* tz) +int clock_gettimezone (time_t time, clockid_t clock_id, struct _timezone* tz) { int ax; ria_set_ax (clock_id); + ria_push_long (time); ax = ria_call_int_errno (RIA_OP_CLOCK_GETTIMEZONE); if (ax >= 0) { char i; diff --git a/libsrc/rp6502/ria_tzset.c b/libsrc/rp6502/ria_tzset.c new file mode 100644 index 000000000..3f39e44f2 --- /dev/null +++ b/libsrc/rp6502/ria_tzset.c @@ -0,0 +1,9 @@ +#include +#include + +int clock_gettimezone (time_t time, clockid_t clock_id, struct _timezone* tz); + +void ria_tzset (unsigned long time) +{ + clock_gettimezone (time, CLOCK_REALTIME, &_tz); +} diff --git a/libsrc/rp6502/sysremove.c b/libsrc/rp6502/sysremove.c index 22d2a65fc..2f1bcadbb 100644 --- a/libsrc/rp6502/sysremove.c +++ b/libsrc/rp6502/sysremove.c @@ -7,8 +7,8 @@ unsigned char __fastcall__ _sysremove (const char* name) size_t namelen; namelen = strlen (name); if (namelen > 255) { - RIA.errno = EINVAL; - return __mappederrno(RIA.errno); + RIA.errno_ = EINVAL; + return __mappederrno (RIA.errno_); } while (namelen) { ria_push_char (name[--namelen]); diff --git a/libsrc/rp6502/sysrename.c b/libsrc/rp6502/sysrename.c index e05ad725a..f61e96a1d 100644 --- a/libsrc/rp6502/sysrename.c +++ b/libsrc/rp6502/sysrename.c @@ -8,8 +8,8 @@ unsigned char __fastcall__ _sysrename (const char* oldpath, const char* newpath) oldpathlen = strlen (oldpath); newpathlen = strlen (newpath); if (oldpathlen + newpathlen > 510) { - RIA.errno = EINVAL; - return __mappederrno(RIA.errno); + RIA.errno_ = EINVAL; + return __mappederrno (RIA.errno_); } while (oldpathlen) { ria_push_char (oldpath[--oldpathlen]); diff --git a/libsrc/rp6502/tzset.c b/libsrc/rp6502/tzset.c deleted file mode 100644 index be4236f2f..000000000 --- a/libsrc/rp6502/tzset.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -int clock_gettimezone (clockid_t clock_id, struct _timezone* tz); - -void tzset (void) -{ - clock_gettimezone (CLOCK_REALTIME, &_tz); -} diff --git a/libsrc/rp6502/write_xstack.c b/libsrc/rp6502/write_xstack.c index b356ec706..1df1fd706 100644 --- a/libsrc/rp6502/write_xstack.c +++ b/libsrc/rp6502/write_xstack.c @@ -5,8 +5,8 @@ int __fastcall__ write_xstack (const void* buf, unsigned count, int fildes) { unsigned i; if (count > 512) { - RIA.errno = EINVAL; - return __mappederrno(RIA.errno); + RIA.errno_ = EINVAL; + return __mappederrno (RIA.errno_); } for (i = count; i;) { ria_push_char (((char*)buf)[--i]); From 77e325507e88fe8b68c7d61b72307956208a1653 Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Sun, 29 Jun 2025 20:16:07 -0700 Subject: [PATCH 05/19] settable codepage() on RP6502 --- include/rp6502.h | 2 +- libsrc/rp6502/codepage.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/rp6502.h b/include/rp6502.h index c1f60d89a..5ff7e8995 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -121,7 +121,7 @@ int __cdecl__ xregn (char device, char channel, unsigned char address, unsigned ...); int __cdecl__ xreg (char device, char channel, unsigned char address, ...); int phi2 (void); -int codepage (void); +int codepage (int); long lrand (void); int __fastcall__ stdin_opt (unsigned long ctrl_bits, unsigned char str_length); int __fastcall__ read_xstack (void* buf, unsigned count, int fildes); diff --git a/libsrc/rp6502/codepage.c b/libsrc/rp6502/codepage.c index e28726f04..d6c176347 100644 --- a/libsrc/rp6502/codepage.c +++ b/libsrc/rp6502/codepage.c @@ -1,6 +1,7 @@ #include -int __fastcall__ codepage (void) +int __fastcall__ codepage (int cp) { + ria_set_ax (cp); return ria_call_int (RIA_OP_CODEPAGE); } From 02cb5d23f76598858317ccf550ef6b6a0c23bc48 Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Sat, 19 Jul 2025 23:13:53 -0700 Subject: [PATCH 06/19] add xreg_ria_gamepad --- include/rp6502.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/rp6502.h b/include/rp6502.h index 5ff7e8995..640e4b59b 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -137,6 +137,7 @@ void ria_tzset (unsigned long time); #define xreg_ria_keyboard(...) xreg(0, 0, 0, __VA_ARGS__) #define xreg_ria_mouse(...) xreg(0, 0, 1, __VA_ARGS__) +#define xreg_ria_gamepad(...) xreg(0, 0, 2, __VA_ARGS__) #define xreg_vga_canvas(...) xreg(1, 0, 0, __VA_ARGS__) #define xreg_vga_mode(...) xreg(1, 0, 1, __VA_ARGS__) From fdcb890bfdd86127ce0943b9883a06f943b93618 Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Fri, 26 Sep 2025 17:19:50 -0700 Subject: [PATCH 07/19] remove oserror from rp6502 --- asminc/rp6502.inc | 25 +---------- include/rp6502.h | 7 +-- libsrc/rp6502/close.c | 2 +- libsrc/rp6502/crt0.s | 2 +- libsrc/rp6502/errno.s | 28 ++++++++++++ libsrc/rp6502/gettime.c | 4 +- libsrc/rp6502/gettimespec.c | 2 +- libsrc/rp6502/gettimezone.c | 2 +- libsrc/rp6502/lseek.c | 2 +- libsrc/rp6502/open.c | 6 +-- libsrc/rp6502/oserrlist.s | 86 ------------------------------------ libsrc/rp6502/oserror.s | 66 --------------------------- libsrc/rp6502/read_xram.c | 2 +- libsrc/rp6502/read_xstack.c | 2 +- libsrc/rp6502/remove.s | 14 ++++++ libsrc/rp6502/rename.s | 14 ++++++ libsrc/rp6502/ria.s | 22 +-------- libsrc/rp6502/settime.c | 2 +- libsrc/rp6502/stdin_opt.c | 2 +- libsrc/rp6502/sysremove.c | 6 +-- libsrc/rp6502/sysrename.c | 8 ++-- libsrc/rp6502/write_xram.c | 2 +- libsrc/rp6502/write_xstack.c | 6 +-- libsrc/rp6502/xregn.c | 2 +- 24 files changed, 85 insertions(+), 229 deletions(-) create mode 100644 libsrc/rp6502/errno.s delete mode 100644 libsrc/rp6502/oserrlist.s delete mode 100644 libsrc/rp6502/oserror.s create mode 100644 libsrc/rp6502/remove.s create mode 100644 libsrc/rp6502/rename.s diff --git a/asminc/rp6502.inc b/asminc/rp6502.inc index 816712abb..c3cec2182 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_ERRNO_OPT := $06 RIA_OP_CLOCK := $0F RIA_OP_CLOCK_GETRES := $10 RIA_OP_CLOCK_GETTIME := $11 @@ -72,27 +73,3 @@ VIA_PCR := VIA+$C ; Peripheral control register VIA_IFR := VIA+$D ; Interrupt flag register VIA_IER := VIA+$E ; Interrupt enable register VIA_PA2 := VIA+$F ; Port register A w/o handshake - -; Values in ___oserror are the union of these FatFs errors and errno.inc -.enum - FR_OK = 32 ; Succeeded - FR_DISK_ERR ; A hard error occurred in the low level disk I/O layer - FR_INT_ERR ; Assertion failed - FR_NOT_READY ; The physical drive cannot work - FR_NO_FILE ; Could not find the file - FR_NO_PATH ; Could not find the path - FR_INVALID_NAME ; The path name format is invalid - FR_DENIED ; Access denied due to prohibited access or directory full - FR_EXIST ; Access denied due to prohibited access - FR_INVALID_OBJECT ; The file/directory object is invalid - FR_WRITE_PROTECTED ; The physical drive is write protected - FR_INVALID_DRIVE ; The logical drive number is invalid - FR_NOT_ENABLED ; The volume has no work area - FR_NO_FILESYSTEM ; There is no valid FAT volume - FR_MKFS_ABORTED ; The f_mkfs() aborted due to any problem - FR_TIMEOUT ; Could not get a grant to access the volume within defined period - FR_LOCKED ; The operation is rejected according to the file sharing policy - FR_NOT_ENOUGH_CORE ; LFN working buffer could not be allocated - FR_TOO_MANY_OPEN_FILES ; Number of open files > FF_FS_LOCK - FR_INVALID_PARAMETER ; Given parameter is invalid -.endenum diff --git a/include/rp6502.h b/include/rp6502.h index 640e4b59b..479621395 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -86,11 +86,6 @@ void __fastcall__ ria_set_ax (unsigned int ax); int __fastcall__ ria_call_int (unsigned char op); long __fastcall__ ria_call_long (unsigned char op); -/* These run _mappederrno() on error */ - -int __fastcall__ ria_call_int_errno (unsigned char op); -long __fastcall__ ria_call_long_errno (unsigned char op); - /* OS operation numbers */ #define RIA_OP_EXIT 0xFF @@ -100,6 +95,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_ERRNO_OPT 0x06 #define RIA_OP_CLOCK 0x0F #define RIA_OP_CLOCK_GETRES 0x10 #define RIA_OP_CLOCK_GETTIME 0x11 @@ -124,6 +120,7 @@ int phi2 (void); int codepage (int); long lrand (void); int __fastcall__ stdin_opt (unsigned long ctrl_bits, unsigned char str_length); +int __fastcall__ errno_opt (unsigned char platform); int __fastcall__ read_xstack (void* buf, unsigned count, int fildes); int __fastcall__ read_xram (unsigned buf, unsigned count, int fildes); int __fastcall__ write_xstack (const void* buf, unsigned count, int fildes); diff --git a/libsrc/rp6502/close.c b/libsrc/rp6502/close.c index 9dea5bdc3..1981baaae 100644 --- a/libsrc/rp6502/close.c +++ b/libsrc/rp6502/close.c @@ -4,5 +4,5 @@ int __fastcall__ close (int fd) { ria_set_ax (fd); - return ria_call_int_errno (RIA_OP_CLOSE); + return ria_call_int (RIA_OP_CLOSE); } diff --git a/libsrc/rp6502/crt0.s b/libsrc/rp6502/crt0.s index 32d565fda..5cf63b615 100644 --- a/libsrc/rp6502/crt0.s +++ b/libsrc/rp6502/crt0.s @@ -46,6 +46,6 @@ _exit: sta RIA_A plx stx RIA_X - lda #$FF ; exit() + lda #RIA_OP_EXIT sta RIA_OP stp diff --git a/libsrc/rp6502/errno.s b/libsrc/rp6502/errno.s new file mode 100644 index 000000000..aef978bfa --- /dev/null +++ b/libsrc/rp6502/errno.s @@ -0,0 +1,28 @@ +; +; 2003-08-12, Ullrich von Bassewitz +; 2015-09-24, Greg King +; +; extern int __errno; +; /* Library errors go here. */ +; + + .include "rp6502.inc" + .include "errno.inc" + .export ___errno, _errno_opt + .import _ria_call_int + .constructor _errno_opt_constructor + +; The errno on the RIA is the errno for cc65 +___errno := RIA_ERRNO + +.code + +; Request the RIA use cc65 values for RIA_ERRNO +_errno_opt_constructor: + lda #$01 ; 1 = cc65 + +; int __fastcall__ errno_opt (unsigned char platform); +_errno_opt: + sta RIA_A + lda #RIA_OP_ERRNO_OPT + jmp _ria_call_int diff --git a/libsrc/rp6502/gettime.c b/libsrc/rp6502/gettime.c index ee63c31ec..339ddeadb 100644 --- a/libsrc/rp6502/gettime.c +++ b/libsrc/rp6502/gettime.c @@ -5,8 +5,6 @@ extern int __clock_gettimespec (struct timespec* ts, unsigned char op); int clock_gettime (clockid_t clock_id, struct timespec* tp) { - (void)clock_id; - /* time.s doesn't set the stack value for clock_id (bug?) */ - ria_set_ax (CLOCK_REALTIME); + ria_set_ax (clock_id); return __clock_gettimespec (tp, RIA_OP_CLOCK_GETTIME); } diff --git a/libsrc/rp6502/gettimespec.c b/libsrc/rp6502/gettimespec.c index 4dc3a0db3..5a07a46d8 100644 --- a/libsrc/rp6502/gettimespec.c +++ b/libsrc/rp6502/gettimespec.c @@ -4,7 +4,7 @@ int __clock_gettimespec (struct timespec* ts, unsigned char op) /* Internal method shared by clock_getres and clock_gettime. */ { - int ax = ria_call_int_errno (op); + int ax = ria_call_int (op); if (ax >= 0) { ts->tv_sec = ria_pop_long (); ts->tv_nsec = ria_pop_long (); diff --git a/libsrc/rp6502/gettimezone.c b/libsrc/rp6502/gettimezone.c index 86d0fefcc..4c4584c07 100644 --- a/libsrc/rp6502/gettimezone.c +++ b/libsrc/rp6502/gettimezone.c @@ -6,7 +6,7 @@ int clock_gettimezone (time_t time, clockid_t clock_id, struct _timezone* tz) int ax; ria_set_ax (clock_id); ria_push_long (time); - ax = ria_call_int_errno (RIA_OP_CLOCK_GETTIMEZONE); + ax = ria_call_int (RIA_OP_CLOCK_GETTIMEZONE); if (ax >= 0) { char i; for (i = 0; i < sizeof (struct _timezone); i++) { diff --git a/libsrc/rp6502/lseek.c b/libsrc/rp6502/lseek.c index 29506612c..caddb9bf6 100644 --- a/libsrc/rp6502/lseek.c +++ b/libsrc/rp6502/lseek.c @@ -7,5 +7,5 @@ off_t __fastcall__ lseek (int fd, off_t offset, int whence) ria_push_long (offset); ria_push_char (whence); ria_set_ax (fd); - return ria_call_long_errno (RIA_OP_LSEEK); + return ria_call_long (RIA_OP_LSEEK); } diff --git a/libsrc/rp6502/open.c b/libsrc/rp6502/open.c index 187c57625..5750eb769 100644 --- a/libsrc/rp6502/open.c +++ b/libsrc/rp6502/open.c @@ -7,12 +7,12 @@ int __cdecl__ open (const char* name, int flags, ...) { size_t namelen = strlen (name); if (namelen > 255) { - RIA.errno_ = EINVAL; - return _mappederrno (RIA.errno_); + errno = EINVAL; + return -1; } while (namelen) { ria_push_char (name[--namelen]); } ria_set_ax (flags); - return ria_call_int_errno (RIA_OP_OPEN); + return ria_call_int (RIA_OP_OPEN); } diff --git a/libsrc/rp6502/oserrlist.s b/libsrc/rp6502/oserrlist.s deleted file mode 100644 index ef322e293..000000000 --- a/libsrc/rp6502/oserrlist.s +++ /dev/null @@ -1,86 +0,0 @@ -; -; 2002-07-18, Ullrich von Bassewitz -; 2022, ChaN -; 2023, Rumbledethumps -; -; Defines the platform-specific error list. -; -; The table is built as a list of entries: -; -; .byte entrylen -; .byte errorcode -; .asciiz errormsg -; -; and, terminated by an entry with length zero that is returned if the -; error code could not be found. -; - -.export __sys_oserrlist - -.include "rp6502.inc" -.include "errno.inc" - -;---------------------------------------------------------------------------- -; Macros used to generate the list (may get moved to an include file?) - -; Regular entry -.macro sys_oserr_entry code, msg - .local Start, End -Start: - .byte End - Start - .byte code - .asciiz msg -End: -.endmacro - -; Sentinel entry -.macro sys_oserr_sentinel msg - .byte 0 ; Length is always zero - .byte 0 ; Code is unused - .asciiz msg -.endmacro - -;---------------------------------------------------------------------------- -; The error message table - -.rodata -__sys_oserrlist: - - sys_oserr_entry ENOENT , "No such file or directory" - sys_oserr_entry ENOMEM , "Out of memory" - sys_oserr_entry EACCES , "Permission denied" - sys_oserr_entry ENODEV , "No such device" - sys_oserr_entry EMFILE , "Too many open files" - sys_oserr_entry EBUSY , "Device or resource busy" - sys_oserr_entry EINVAL , "Invalid argument" - sys_oserr_entry ENOSPC , "No space left on device" - sys_oserr_entry EEXIST , "File exists" - sys_oserr_entry EAGAIN , "Try again" - sys_oserr_entry EIO , "I/O error" - sys_oserr_entry EINTR , "Interrupted system call" - sys_oserr_entry ENOSYS , "Function not implemented" - sys_oserr_entry ESPIPE , "Illegal seek" - sys_oserr_entry ERANGE , "Range error" - sys_oserr_entry EBADF , "Bad file number" - sys_oserr_entry ENOEXEC , "Exec format error" - sys_oserr_entry EUNKNOWN , "Unknown OS specific error" - sys_oserr_entry FR_DISK_ERR , "A hard error occurred in the low level disk I/O layer" - sys_oserr_entry FR_INT_ERR , "Assertion failed" - sys_oserr_entry FR_NOT_READY , "The physical drive cannot work" - sys_oserr_entry FR_NO_FILE , "Could not find the file" - sys_oserr_entry FR_NO_PATH , "Could not find the path" - sys_oserr_entry FR_INVALID_NAME , "The path name format is invalid" - sys_oserr_entry FR_DENIED , "Access denied due to prohibited access or directory full" - sys_oserr_entry FR_EXIST , "Access denied due to prohibited access" - sys_oserr_entry FR_INVALID_OBJECT , "The file/directory object is invalid" - sys_oserr_entry FR_WRITE_PROTECTED , "The physical drive is write protected" - sys_oserr_entry FR_INVALID_DRIVE , "The logical drive number is invalid" - sys_oserr_entry FR_NOT_ENABLED , "The volume has no work area" - sys_oserr_entry FR_NO_FILESYSTEM , "There is no valid FAT volume" - sys_oserr_entry FR_MKFS_ABORTED , "The f_mkfs() aborted due to any problem" - sys_oserr_entry FR_TIMEOUT , "Could not get a grant to access the volume within defined period" - sys_oserr_entry FR_LOCKED , "The operation is rejected according to the file sharing policy" - sys_oserr_entry FR_NOT_ENOUGH_CORE , "LFN working buffer could not be allocated" - sys_oserr_entry FR_TOO_MANY_OPEN_FILES , "Number of open files > FF_FS_LOCK" - sys_oserr_entry FR_INVALID_PARAMETER , "Given parameter is invalid" - sys_oserr_sentinel "Unknown error" diff --git a/libsrc/rp6502/oserror.s b/libsrc/rp6502/oserror.s deleted file mode 100644 index 706bcfa65..000000000 --- a/libsrc/rp6502/oserror.s +++ /dev/null @@ -1,66 +0,0 @@ -; -; 2000-05-17, Ullrich von Bassewitz -; 2022, ChaN -; 2023, Rumbledethumps -; -; int __fastcall__ __osmaperrno (unsigned char oserror); -; -; RP6502 will respond with a union of CC65 and FatFs errnos. -; This will map FatFs errors into the CC65 range for portable code. - -EFATFS_START := 32 - -.include "rp6502.inc" -.include "errno.inc" - -.code - -___osmaperrno: - cmp #EFATFS_START - bmi @L2 - - ldx #ErrTabSize -@L1: - cmp ErrTab-2,x ; Search for the error code - beq @L3 ; Jump if found - dex - dex - bne @L1 ; Next entry - -; Code not found, return EUNKNOWN - lda #EUNKNOWN -@L2: - rts - -; Found the code -@L3: - lda ErrTab-1,x - ldx #$00 ; High byte always zero - rts - -.rodata - -ErrTab: - - .byte FR_DISK_ERR , EIO ; A hard error occurred in the low level disk I/O layer -; .byte FR_INT_ERR , EUNKNOWN ; Assertion failed - .byte FR_NOT_READY , EBUSY ; The physical drive cannot work - .byte FR_NO_FILE , ENOENT ; Could not find the file - .byte FR_NO_PATH , ENOENT ; Could not find the path - .byte FR_INVALID_NAME , EINVAL ; The path name format is invalid - .byte FR_DENIED , EACCES ; Access denied due to prohibited access or directory full - .byte FR_EXIST , EEXIST ; Access denied due to prohibited access - .byte FR_INVALID_OBJECT , EINVAL ; The file/directory object is invalid - .byte FR_WRITE_PROTECTED , EACCES ; The physical drive is write protected - .byte FR_INVALID_DRIVE , ENODEV ; The logical drive number is invalid -; .byte FR_NOT_ENABLED , EUNKNOWN ; The volume has no work area -; .byte FR_NO_FILESYSTEM , EUNKNOWN ; There is no valid FAT volume -; .byte FR_MKFS_ABORTED , EUNKNOWN ; The f_mkfs() aborted due to any problem -; .byte FR_TIMEOUT , EUNKNOWN ; Could not get a grant to access the volume within defined period - .byte FR_LOCKED , EBUSY ; The operation is rejected according to the file sharing policy - .byte FR_NOT_ENOUGH_CORE , ENOMEM ; LFN working buffer could not be allocated - .byte FR_TOO_MANY_OPEN_FILES , EMFILE ; Number of open files > FF_FS_LOCK - .byte FR_INVALID_PARAMETER , EINVAL ; Given parameter is invalid - -ErrTabSize = (* - ErrTab) diff --git a/libsrc/rp6502/read_xram.c b/libsrc/rp6502/read_xram.c index f88a036ee..e14ac29d4 100644 --- a/libsrc/rp6502/read_xram.c +++ b/libsrc/rp6502/read_xram.c @@ -5,5 +5,5 @@ int __fastcall__ read_xram (unsigned buf, unsigned count, int fildes) ria_push_int (buf); ria_push_int (count); ria_set_ax (fildes); - return ria_call_int_errno (RIA_OP_READ_XRAM); + return ria_call_int (RIA_OP_READ_XRAM); } diff --git a/libsrc/rp6502/read_xstack.c b/libsrc/rp6502/read_xstack.c index 70eebad2f..952323f32 100644 --- a/libsrc/rp6502/read_xstack.c +++ b/libsrc/rp6502/read_xstack.c @@ -5,7 +5,7 @@ int __fastcall__ read_xstack (void* buf, unsigned count, int fildes) int i, ax; ria_push_int (count); ria_set_ax (fildes); - ax = ria_call_int_errno (RIA_OP_READ_XSTACK); + ax = ria_call_int (RIA_OP_READ_XSTACK); for (i = 0; i < ax; i++) { ((char*)buf)[i] = ria_pop_char (); } diff --git a/libsrc/rp6502/remove.s b/libsrc/rp6502/remove.s new file mode 100644 index 000000000..3bd91001d --- /dev/null +++ b/libsrc/rp6502/remove.s @@ -0,0 +1,14 @@ +; +; Ullrich von Bassewitz, 2003-08-12 +; +; int __fastcall__ remove (const char* name); +; + + .export _remove + + .import __sysremove + + +;-------------------------------------------------------------------------- + +_remove = __sysremove diff --git a/libsrc/rp6502/rename.s b/libsrc/rp6502/rename.s new file mode 100644 index 000000000..0b85a6134 --- /dev/null +++ b/libsrc/rp6502/rename.s @@ -0,0 +1,14 @@ +; +; Ullrich von Bassewitz, 2003-08-12 +; +; int __fastcall__ rename (const char* oldname, const char* newname); +; + + .export _rename + + .import __sysrename + + +;-------------------------------------------------------------------------- + +_rename = __sysrename diff --git a/libsrc/rp6502/ria.s b/libsrc/rp6502/ria.s index 78da4daba..5fb858a03 100644 --- a/libsrc/rp6502/ria.s +++ b/libsrc/rp6502/ria.s @@ -9,10 +9,8 @@ .export _ria_pop_long, _ria_pop_int .export _ria_set_axsreg, _ria_set_ax .export _ria_call_int, _ria_call_long -.export _ria_call_int_errno, _ria_call_long_errno -.importzp c_sp, sreg -.import ___mappederrno, incsp1 +.importzp sreg .code @@ -69,21 +67,3 @@ _ria_call_long: ldy RIA_SREG+1 sty sreg+1 rts - -; int __fastcall__ ria_call_int_errno(unsigned char op); -_ria_call_int_errno: - sta RIA_OP - jsr RIA_SPIN - ldx RIA_X - bmi ERROR - rts - -; long __fastcall__ ria_call_long_errno(unsigned char op); -_ria_call_long_errno: - jsr _ria_call_long - bmi ERROR - rts - -ERROR: - lda RIA_ERRNO - jmp ___mappederrno diff --git a/libsrc/rp6502/settime.c b/libsrc/rp6502/settime.c index 1ba1d2e3e..4b7f8c73e 100644 --- a/libsrc/rp6502/settime.c +++ b/libsrc/rp6502/settime.c @@ -6,5 +6,5 @@ int clock_settime (clockid_t clock_id, const struct timespec* tp) ria_set_ax (clock_id); ria_push_long (tp->tv_nsec); ria_push_long (tp->tv_sec); - return ria_call_int_errno (RIA_OP_CLOCK_SETTIME); + return ria_call_int (RIA_OP_CLOCK_SETTIME); } diff --git a/libsrc/rp6502/stdin_opt.c b/libsrc/rp6502/stdin_opt.c index 69e6f51cd..ddc1869a1 100644 --- a/libsrc/rp6502/stdin_opt.c +++ b/libsrc/rp6502/stdin_opt.c @@ -4,5 +4,5 @@ int __fastcall__ stdin_opt (unsigned long ctrl_bits, unsigned char str_length) { ria_push_long (ctrl_bits); ria_set_a (str_length); - return ria_call_int_errno (RIA_OP_STDIN_OPT); + return ria_call_int (RIA_OP_STDIN_OPT); } diff --git a/libsrc/rp6502/sysremove.c b/libsrc/rp6502/sysremove.c index 2f1bcadbb..32010d5bf 100644 --- a/libsrc/rp6502/sysremove.c +++ b/libsrc/rp6502/sysremove.c @@ -2,16 +2,16 @@ #include #include -unsigned char __fastcall__ _sysremove (const char* name) +int __fastcall__ _sysremove (const char* name) { size_t namelen; namelen = strlen (name); if (namelen > 255) { RIA.errno_ = EINVAL; - return __mappederrno (RIA.errno_); + return -1; } while (namelen) { ria_push_char (name[--namelen]); } - return ria_call_int_errno (RIA_OP_UNLINK); + return ria_call_int (RIA_OP_UNLINK); } diff --git a/libsrc/rp6502/sysrename.c b/libsrc/rp6502/sysrename.c index f61e96a1d..09f971918 100644 --- a/libsrc/rp6502/sysrename.c +++ b/libsrc/rp6502/sysrename.c @@ -2,14 +2,14 @@ #include #include -unsigned char __fastcall__ _sysrename (const char* oldpath, const char* newpath) +int __fastcall__ _sysrename (const char* oldpath, const char* newpath) { size_t oldpathlen, newpathlen; oldpathlen = strlen (oldpath); newpathlen = strlen (newpath); if (oldpathlen + newpathlen > 510) { - RIA.errno_ = EINVAL; - return __mappederrno (RIA.errno_); + errno = EINVAL; + return -1; } while (oldpathlen) { ria_push_char (oldpath[--oldpathlen]); @@ -18,5 +18,5 @@ unsigned char __fastcall__ _sysrename (const char* oldpath, const char* newpath) while (newpathlen) { ria_push_char (newpath[--newpathlen]); } - return ria_call_int_errno (RIA_OP_RENAME); + return ria_call_int (RIA_OP_RENAME); } diff --git a/libsrc/rp6502/write_xram.c b/libsrc/rp6502/write_xram.c index 31a553813..7251cdd43 100644 --- a/libsrc/rp6502/write_xram.c +++ b/libsrc/rp6502/write_xram.c @@ -5,5 +5,5 @@ int __fastcall__ write_xram (unsigned buf, unsigned count, int fildes) ria_push_int (buf); ria_push_int (count); ria_set_ax (fildes); - return ria_call_int_errno (RIA_OP_WRITE_XRAM); + return ria_call_int (RIA_OP_WRITE_XRAM); } diff --git a/libsrc/rp6502/write_xstack.c b/libsrc/rp6502/write_xstack.c index 1df1fd706..98c90c757 100644 --- a/libsrc/rp6502/write_xstack.c +++ b/libsrc/rp6502/write_xstack.c @@ -5,12 +5,12 @@ int __fastcall__ write_xstack (const void* buf, unsigned count, int fildes) { unsigned i; if (count > 512) { - RIA.errno_ = EINVAL; - return __mappederrno (RIA.errno_); + errno = EINVAL; + return -1; } for (i = count; i;) { ria_push_char (((char*)buf)[--i]); } ria_set_ax (fildes); - return ria_call_int_errno (RIA_OP_WRITE_XSTACK); + return ria_call_int (RIA_OP_WRITE_XSTACK); } diff --git a/libsrc/rp6502/xregn.c b/libsrc/rp6502/xregn.c index ec040be20..eaa6aa7b7 100644 --- a/libsrc/rp6502/xregn.c +++ b/libsrc/rp6502/xregn.c @@ -15,5 +15,5 @@ int __cdecl__ xregn (char device, char channel, unsigned char address, unsigned RIA.xstack = v; } va_end (args); - return ria_call_int_errno (RIA_OP_XREG); + return ria_call_int (RIA_OP_XREG); } From 23b8bafbf606d707edc588c26a403d395d0dc1b3 Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Sat, 27 Sep 2025 23:27:02 -0700 Subject: [PATCH 08/19] no need to expose errno_opt --- include/rp6502.h | 1 - libsrc/rp6502/errno.s | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/include/rp6502.h b/include/rp6502.h index 479621395..c443bd8f9 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -120,7 +120,6 @@ int phi2 (void); int codepage (int); long lrand (void); int __fastcall__ stdin_opt (unsigned long ctrl_bits, unsigned char str_length); -int __fastcall__ errno_opt (unsigned char platform); int __fastcall__ read_xstack (void* buf, unsigned count, int fildes); int __fastcall__ read_xram (unsigned buf, unsigned count, int fildes); int __fastcall__ write_xstack (const void* buf, unsigned count, int fildes); diff --git a/libsrc/rp6502/errno.s b/libsrc/rp6502/errno.s index aef978bfa..a9a50afec 100644 --- a/libsrc/rp6502/errno.s +++ b/libsrc/rp6502/errno.s @@ -8,7 +8,7 @@ .include "rp6502.inc" .include "errno.inc" - .export ___errno, _errno_opt + .export ___errno .import _ria_call_int .constructor _errno_opt_constructor @@ -20,9 +20,6 @@ ___errno := RIA_ERRNO ; Request the RIA use cc65 values for RIA_ERRNO _errno_opt_constructor: lda #$01 ; 1 = cc65 - -; int __fastcall__ errno_opt (unsigned char platform); -_errno_opt: sta RIA_A lda #RIA_OP_ERRNO_OPT jmp _ria_call_int From a6763af95c2487dccde55835afe915baf239f87a Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Sat, 4 Oct 2025 16:29:30 -0700 Subject: [PATCH 09/19] fix xreg.s --- libsrc/rp6502/xreg.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/rp6502/xreg.s b/libsrc/rp6502/xreg.s index a882ab10f..140d60855 100644 --- a/libsrc/rp6502/xreg.s +++ b/libsrc/rp6502/xreg.s @@ -6,7 +6,7 @@ .export _xreg .importzp c_sp -.import addysp, _ria_call_int_errno +.import addysp, _ria_call_int .include "rp6502.inc" @@ -32,6 +32,6 @@ ; run RIA operation lda #RIA_OP_XREG - jmp _ria_call_int_errno + jmp _ria_call_int .endproc From e6c138dc03b4b2f5539713b92a53417647283414 Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Tue, 14 Oct 2025 23:11:23 -0700 Subject: [PATCH 10/19] directory ops --- asminc/rp6502.inc | 20 ++++++++++++++++++ include/rp6502.h | 42 +++++++++++++++++++++++++++++++++++--- include/unistd.h | 4 +--- libsrc/rp6502/f_closedir.c | 8 ++++++++ libsrc/rp6502/f_lseek.c | 10 +++++++++ libsrc/rp6502/f_opendir.c | 16 +++++++++++++++ libsrc/rp6502/f_readdir.c | 14 +++++++++++++ libsrc/rp6502/f_stat.c | 21 +++++++++++++++++++ libsrc/rp6502/lseek.c | 1 - libsrc/rp6502/syncfs.c | 8 ++++++++ libsrc/rp6502/write_xram.c | 2 +- 11 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 libsrc/rp6502/f_closedir.c create mode 100644 libsrc/rp6502/f_lseek.c create mode 100644 libsrc/rp6502/f_opendir.c create mode 100644 libsrc/rp6502/f_readdir.c create mode 100644 libsrc/rp6502/f_stat.c create mode 100644 libsrc/rp6502/syncfs.c diff --git a/asminc/rp6502.inc b/asminc/rp6502.inc index c3cec2182..05dc93cbe 100644 --- a/asminc/rp6502.inc +++ b/asminc/rp6502.inc @@ -50,8 +50,28 @@ RIA_OP_READ_XRAM := $17 RIA_OP_WRITE_XSTACK := $18 RIA_OP_WRITE_XRAM := $19 RIA_OP_LSEEK := $1A +RIA_OP_LSEEK_CC65 := $1A RIA_OP_UNLINK := $1B RIA_OP_RENAME := $1C +RIA_OP_LSEEK_LLVM := $1D +RIA_OP_SYNCFS := $1E +RIA_OP_STAT := $1F +RIA_OP_OPENDIR := $20 +RIA_OP_READDIR := $21 +RIA_OP_CLOSEDIR := $22 +RIA_OP_TELLDIR := $23 +RIA_OP_SEEKDIR := $24 +RIA_OP_REWINDDIR := $25 +RIA_OP_CHMOD := $26 +RIA_OP_UTIME := $27 +RIA_OP_MKDIR := $28 +RIA_OP_CHDIR := $29 +RIA_OP_CHDRIVE := $2A +RIA_OP_GETCWD := $2B +RIA_OP_SETLABEL := $2C +RIA_OP_GETLABEL := $2D +RIA_OP_GETFREE := $2E + ; 6522 VIA VIA := $FFD0 ; VIA base address diff --git a/include/rp6502.h b/include/rp6502.h index c443bd8f9..b51382825 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -108,22 +108,58 @@ long __fastcall__ ria_call_long (unsigned char op); #define RIA_OP_WRITE_XSTACK 0x18 #define RIA_OP_WRITE_XRAM 0x19 #define RIA_OP_LSEEK 0x1A +#define RIA_OP_LSEEK_CC65 0x1A #define RIA_OP_UNLINK 0x1B #define RIA_OP_RENAME 0x1C +#define RIA_OP_LSEEK_LLVM 0x1D +#define RIA_OP_SYNCFS 0x1E +#define RIA_OP_STAT 0x1F +#define RIA_OP_OPENDIR 0x20 +#define RIA_OP_READDIR 0x21 +#define RIA_OP_CLOSEDIR 0x22 +#define RIA_OP_TELLDIR 0x23 +#define RIA_OP_SEEKDIR 0x24 +#define RIA_OP_REWINDDIR 0x25 +#define RIA_OP_CHMOD 0x26 +#define RIA_OP_UTIME 0x27 +#define RIA_OP_MKDIR 0x28 +#define RIA_OP_CHDIR 0x29 +#define RIA_OP_CHDRIVE 0x2A +#define RIA_OP_GETCWD 0x2B +#define RIA_OP_SETLABEL 0x2C +#define RIA_OP_GETLABEL 0x2D +#define RIA_OP_GETFREE 0x2E /* C API for the operating system. */ +typedef struct { + unsigned long fsize; /* File size (invalid for directory) */ + unsigned fdate; /* Date of file modification or directory creation */ + unsigned ftime; /* Time of file modification or directory creation */ + unsigned crdate; /* Date of object createion */ + unsigned crtime; /* Time of object createion */ + unsigned char fattrib; /* Object attribute */ + char altname[12 + 1]; /* Alternative object name */ + char fname[255 + 1]; /* Primary object name */ +} f_stat_t; + 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 (int); -long lrand (void); +int __fastcall__ phi2 (void); +int __fastcall__ codepage (int); +long __fastcall__ lrand (void); int __fastcall__ stdin_opt (unsigned long ctrl_bits, unsigned char str_length); int __fastcall__ read_xstack (void* buf, unsigned count, int fildes); int __fastcall__ read_xram (unsigned buf, unsigned count, int fildes); int __fastcall__ write_xstack (const void* buf, unsigned count, int fildes); int __fastcall__ write_xram (unsigned buf, unsigned count, int fildes); +long __fastcall__ f_lseek (long offset, int whence, int fildes); +int __fastcall__ f_stat (const char* path, f_stat_t* dirent); +int __fastcall__ f_opendir (const char* name); +int __fastcall__ f_readdir (f_stat_t *dirent, int dirdes); +int __fastcall__ f_closedir (int dirdes); + /* Time zone hack */ diff --git a/include/unistd.h b/include/unistd.h index 05b60f1fd..d48fe6f31 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -77,6 +77,7 @@ extern int optind, opterr, optopt; int __fastcall__ write (int fd, const void* buf, unsigned count); int __fastcall__ read (int fd, void* buf, unsigned count); off_t __fastcall__ lseek (int fd, off_t offset, int whence); +int __fastcall__ syncfs (int fd); int __fastcall__ unlink (const char* name); /* Same as remove() */ /* Directories */ @@ -98,6 +99,3 @@ int __fastcall__ exec (const char* progname, const char* cmdline); /* End of unistd.h */ #endif - - - diff --git a/libsrc/rp6502/f_closedir.c b/libsrc/rp6502/f_closedir.c new file mode 100644 index 000000000..03239c874 --- /dev/null +++ b/libsrc/rp6502/f_closedir.c @@ -0,0 +1,8 @@ +#include +#include + +int __fastcall__ f_closedir (int dirdes) +{ + ria_set_ax (dirdes); + return ria_call_int (RIA_OP_CLOSEDIR); +} diff --git a/libsrc/rp6502/f_lseek.c b/libsrc/rp6502/f_lseek.c new file mode 100644 index 000000000..da7c3dfdf --- /dev/null +++ b/libsrc/rp6502/f_lseek.c @@ -0,0 +1,10 @@ +#include +#include + +long __fastcall__ f_lseek (long offset, int whence, int fildes) +{ + ria_set_ax (fildes); + ria_push_long (offset); + ria_push_char (whence); + return ria_call_long (RIA_OP_LSEEK); +} diff --git a/libsrc/rp6502/f_opendir.c b/libsrc/rp6502/f_opendir.c new file mode 100644 index 000000000..29faf776e --- /dev/null +++ b/libsrc/rp6502/f_opendir.c @@ -0,0 +1,16 @@ +#include +#include +#include + +int __fastcall__ f_opendir (const char* name) +{ + size_t namelen = strlen (name); + if (namelen > 255) { + errno = EINVAL; + return -1; + } + while (namelen) { + ria_push_char (name[--namelen]); + } + return ria_call_int (RIA_OP_OPENDIR); +} diff --git a/libsrc/rp6502/f_readdir.c b/libsrc/rp6502/f_readdir.c new file mode 100644 index 000000000..f6fa42e1b --- /dev/null +++ b/libsrc/rp6502/f_readdir.c @@ -0,0 +1,14 @@ +#include +#include +#include + +int __fastcall__ f_readdir (f_stat_t *dirent, int dirdes) +{ + int i, ax; + ria_set_ax (dirdes); + ax = ria_call_int (RIA_OP_READDIR); + for (i = 0; i < sizeof (f_stat_t); i++) { + ((char*)dirent)[i] = ria_pop_char (); + } + return ax; +} diff --git a/libsrc/rp6502/f_stat.c b/libsrc/rp6502/f_stat.c new file mode 100644 index 000000000..3e3845639 --- /dev/null +++ b/libsrc/rp6502/f_stat.c @@ -0,0 +1,21 @@ +#include +#include +#include + +int __fastcall__ f_stat (const char* path, f_stat_t* dirent) +{ + int i, ax; + size_t pathlen = strlen (path); + if (pathlen > 255) { + errno = EINVAL; + return -1; + } + while (pathlen) { + ria_push_char (path[--pathlen]); + } + ax = ria_call_int (RIA_OP_STAT); + for (i = 0; i < sizeof (f_stat_t); i++) { + ((char*)dirent)[i] = ria_pop_char (); + } + return ax; +} diff --git a/libsrc/rp6502/lseek.c b/libsrc/rp6502/lseek.c index caddb9bf6..a40c7318d 100644 --- a/libsrc/rp6502/lseek.c +++ b/libsrc/rp6502/lseek.c @@ -3,7 +3,6 @@ off_t __fastcall__ lseek (int fd, off_t offset, int whence) { - /* Modified argument order for short stacking offset */ ria_push_long (offset); ria_push_char (whence); ria_set_ax (fd); diff --git a/libsrc/rp6502/syncfs.c b/libsrc/rp6502/syncfs.c new file mode 100644 index 000000000..34c12a8f6 --- /dev/null +++ b/libsrc/rp6502/syncfs.c @@ -0,0 +1,8 @@ +#include +#include + +int __fastcall__ syncfs (int fd) +{ + ria_set_ax (fd); + return ria_call_int (RIA_OP_SYNCFS); +} diff --git a/libsrc/rp6502/write_xram.c b/libsrc/rp6502/write_xram.c index 7251cdd43..0a46ec62c 100644 --- a/libsrc/rp6502/write_xram.c +++ b/libsrc/rp6502/write_xram.c @@ -2,8 +2,8 @@ int __fastcall__ write_xram (unsigned buf, unsigned count, int fildes) { + ria_set_ax (fildes); ria_push_int (buf); ria_push_int (count); - ria_set_ax (fildes); return ria_call_int (RIA_OP_WRITE_XRAM); } From f744f0b8a0839458590d5c1538ee9e64c20c7058 Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Wed, 15 Oct 2025 14:12:12 -0700 Subject: [PATCH 11/19] dir seeking --- include/rp6502.h | 21 ++++++++++++--------- libsrc/rp6502/f_closedir.c | 1 - libsrc/rp6502/f_lseek.c | 1 - libsrc/rp6502/f_readdir.c | 4 +--- libsrc/rp6502/f_rewinddir.c | 7 +++++++ libsrc/rp6502/f_seekdir.c | 8 ++++++++ libsrc/rp6502/f_telldir.c | 7 +++++++ 7 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 libsrc/rp6502/f_rewinddir.c create mode 100644 libsrc/rp6502/f_seekdir.c create mode 100644 libsrc/rp6502/f_telldir.c diff --git a/include/rp6502.h b/include/rp6502.h index b51382825..d40ba8a88 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -133,14 +133,14 @@ long __fastcall__ ria_call_long (unsigned char op); /* C API for the operating system. */ typedef struct { - unsigned long fsize; /* File size (invalid for directory) */ - unsigned fdate; /* Date of file modification or directory creation */ - unsigned ftime; /* Time of file modification or directory creation */ - unsigned crdate; /* Date of object createion */ - unsigned crtime; /* Time of object createion */ - unsigned char fattrib; /* Object attribute */ - char altname[12 + 1]; /* Alternative object name */ - char fname[255 + 1]; /* Primary object name */ + unsigned long fsize; + unsigned fdate; + unsigned ftime; + unsigned crdate; + unsigned crtime; + unsigned char fattrib; + char altname[12 + 1]; + char fname[255 + 1]; } f_stat_t; int __cdecl__ xregn (char device, char channel, unsigned char address, unsigned count, @@ -157,8 +157,11 @@ int __fastcall__ write_xram (unsigned buf, unsigned count, int fildes); long __fastcall__ f_lseek (long offset, int whence, int fildes); int __fastcall__ f_stat (const char* path, f_stat_t* dirent); int __fastcall__ f_opendir (const char* name); -int __fastcall__ f_readdir (f_stat_t *dirent, int dirdes); +int __fastcall__ f_readdir (f_stat_t* dirent, int dirdes); int __fastcall__ f_closedir (int dirdes); +long __fastcall__ f_telldir (int dirdes); +int __fastcall__ f_seekdir (long offs, int dirdes); +int __fastcall__ f_rewinddir (int dirdes); /* Time zone hack */ diff --git a/libsrc/rp6502/f_closedir.c b/libsrc/rp6502/f_closedir.c index 03239c874..279483ca9 100644 --- a/libsrc/rp6502/f_closedir.c +++ b/libsrc/rp6502/f_closedir.c @@ -1,5 +1,4 @@ #include -#include int __fastcall__ f_closedir (int dirdes) { diff --git a/libsrc/rp6502/f_lseek.c b/libsrc/rp6502/f_lseek.c index da7c3dfdf..ada9baab5 100644 --- a/libsrc/rp6502/f_lseek.c +++ b/libsrc/rp6502/f_lseek.c @@ -1,5 +1,4 @@ #include -#include long __fastcall__ f_lseek (long offset, int whence, int fildes) { diff --git a/libsrc/rp6502/f_readdir.c b/libsrc/rp6502/f_readdir.c index f6fa42e1b..45777c221 100644 --- a/libsrc/rp6502/f_readdir.c +++ b/libsrc/rp6502/f_readdir.c @@ -1,8 +1,6 @@ #include -#include -#include -int __fastcall__ f_readdir (f_stat_t *dirent, int dirdes) +int __fastcall__ f_readdir (f_stat_t* dirent, int dirdes) { int i, ax; ria_set_ax (dirdes); diff --git a/libsrc/rp6502/f_rewinddir.c b/libsrc/rp6502/f_rewinddir.c new file mode 100644 index 000000000..bd2ebaa1b --- /dev/null +++ b/libsrc/rp6502/f_rewinddir.c @@ -0,0 +1,7 @@ +#include + +int __fastcall__ f_rewinddir (int dirdes) +{ + ria_set_ax (dirdes); + return ria_call_int (RIA_OP_REWINDDIR); +} diff --git a/libsrc/rp6502/f_seekdir.c b/libsrc/rp6502/f_seekdir.c new file mode 100644 index 000000000..5c6890e3d --- /dev/null +++ b/libsrc/rp6502/f_seekdir.c @@ -0,0 +1,8 @@ +#include + +int __fastcall__ f_seekdir (long offs, int dirdes) +{ + ria_set_ax (dirdes); + ria_push_long (offs); + return ria_call_int (RIA_OP_SEEKDIR); +} diff --git a/libsrc/rp6502/f_telldir.c b/libsrc/rp6502/f_telldir.c new file mode 100644 index 000000000..1396e0a88 --- /dev/null +++ b/libsrc/rp6502/f_telldir.c @@ -0,0 +1,7 @@ +#include + +long __fastcall__ f_telldir (int dirdes) +{ + ria_set_ax (dirdes); + return ria_call_long (RIA_OP_TELLDIR); +} From 815135f71680cbbcacbaeaa6f93cffa878e9d59c Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Wed, 15 Oct 2025 23:41:44 -0700 Subject: [PATCH 12/19] chdir and friends --- include/rp6502.h | 8 ++++++++ libsrc/rp6502/chdir.s | 14 ++++++++++++++ libsrc/rp6502/f_chdrive.c | 16 ++++++++++++++++ libsrc/rp6502/f_chmod.c | 19 +++++++++++++++++++ libsrc/rp6502/f_mkdir.c | 16 ++++++++++++++++ libsrc/rp6502/f_utime.c | 21 +++++++++++++++++++++ libsrc/rp6502/syschdir.c | 16 ++++++++++++++++ 7 files changed, 110 insertions(+) create mode 100644 libsrc/rp6502/chdir.s create mode 100644 libsrc/rp6502/f_chdrive.c create mode 100644 libsrc/rp6502/f_chmod.c create mode 100644 libsrc/rp6502/f_mkdir.c create mode 100644 libsrc/rp6502/f_utime.c create mode 100644 libsrc/rp6502/syschdir.c diff --git a/include/rp6502.h b/include/rp6502.h index d40ba8a88..85916e390 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -162,6 +162,14 @@ int __fastcall__ f_closedir (int dirdes); long __fastcall__ f_telldir (int dirdes); int __fastcall__ f_seekdir (long offs, int dirdes); int __fastcall__ f_rewinddir (int dirdes); +int __fastcall__ f_chmod (const char* path, unsigned char attr, unsigned char mask); +int __fastcall__ f_utime (const char* path, unsigned fdate, unsigned ftime, unsigned crdate, unsigned crtime); +int __fastcall__ f_mkdir (const char* name); +int __fastcall__ f_chdrive (const char* name); +// int __fastcall__ f_getcwd(char* name, unsigned len); +// int __fastcall__ f_setlabel(const char* name); +// int __fastcall__ f_getlabel(const char* path, char* label); +// int __fastcall__ f_getfree(const char* name); /* Time zone hack */ diff --git a/libsrc/rp6502/chdir.s b/libsrc/rp6502/chdir.s new file mode 100644 index 000000000..bb467f671 --- /dev/null +++ b/libsrc/rp6502/chdir.s @@ -0,0 +1,14 @@ +; +; Ullrich von Bassewitz, 2003-08-12 +; +; int __fastcall__ chdir (const char* name); +; + + .export _chdir + + .import __syschdir + + +;-------------------------------------------------------------------------- + +_chdir = __syschdir diff --git a/libsrc/rp6502/f_chdrive.c b/libsrc/rp6502/f_chdrive.c new file mode 100644 index 000000000..8a3b8f93a --- /dev/null +++ b/libsrc/rp6502/f_chdrive.c @@ -0,0 +1,16 @@ +#include +#include +#include + +int __fastcall__ f_chdrive (const char* name) +{ + size_t namelen = strlen (name); + if (namelen > 255) { + errno = EINVAL; + return -1; + } + while (namelen) { + ria_push_char (name[--namelen]); + } + return ria_call_int (RIA_OP_CHDRIVE); +} diff --git a/libsrc/rp6502/f_chmod.c b/libsrc/rp6502/f_chmod.c new file mode 100644 index 000000000..7481cfb19 --- /dev/null +++ b/libsrc/rp6502/f_chmod.c @@ -0,0 +1,19 @@ +#include +#include +#include + +int __fastcall__ f_chmod (const char* path, unsigned char attr, unsigned char mask) +{ + size_t pathlen; + ria_set_a (mask); + pathlen = strlen (path); + if (pathlen > 255) { + errno = EINVAL; + return -1; + } + while (pathlen) { + ria_push_char (path[--pathlen]); + } + ria_push_char (attr); + return ria_call_int (RIA_OP_CHMOD); +} diff --git a/libsrc/rp6502/f_mkdir.c b/libsrc/rp6502/f_mkdir.c new file mode 100644 index 000000000..b27c21fd7 --- /dev/null +++ b/libsrc/rp6502/f_mkdir.c @@ -0,0 +1,16 @@ +#include +#include +#include + +int __fastcall__ f_mkdir (const char* name) +{ + size_t namelen = strlen (name); + if (namelen > 255) { + errno = EINVAL; + return -1; + } + while (namelen) { + ria_push_char (name[--namelen]); + } + return ria_call_int (RIA_OP_MKDIR); +} diff --git a/libsrc/rp6502/f_utime.c b/libsrc/rp6502/f_utime.c new file mode 100644 index 000000000..a5c3e9753 --- /dev/null +++ b/libsrc/rp6502/f_utime.c @@ -0,0 +1,21 @@ +#include +#include +#include + +int __fastcall__ f_utime (const char* path, unsigned fdate, unsigned ftime, unsigned crdate, unsigned crtime) +{ + size_t pathlen; + ria_set_ax (crtime); + pathlen = strlen (path); + if (pathlen > 255) { + errno = EINVAL; + return -1; + } + while (pathlen) { + ria_push_char (path[--pathlen]); + } + ria_push_int (fdate); + ria_push_int (ftime); + ria_push_int (crdate); + return ria_call_int (RIA_OP_UTIME); +} diff --git a/libsrc/rp6502/syschdir.c b/libsrc/rp6502/syschdir.c new file mode 100644 index 000000000..98ad91e47 --- /dev/null +++ b/libsrc/rp6502/syschdir.c @@ -0,0 +1,16 @@ +#include +#include +#include + +int __fastcall__ _syschdir (const char* name) +{ + size_t namelen = strlen (name); + if (namelen > 255) { + errno = EINVAL; + return -1; + } + while (namelen) { + ria_push_char (name[--namelen]); + } + return ria_call_int (RIA_OP_CHDIR); +} From 4b561acea52ffabb3200cc7696900814647e1af3 Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Thu, 16 Oct 2025 16:20:23 -0700 Subject: [PATCH 13/19] all dir commands --- include/rp6502.h | 9 ++++----- libsrc/rp6502/f_getcwd.c | 14 ++++++++++++++ libsrc/rp6502/f_getfree.c | 22 ++++++++++++++++++++++ libsrc/rp6502/f_getlabel.c | 21 +++++++++++++++++++++ libsrc/rp6502/f_setlabel.c | 16 ++++++++++++++++ 5 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 libsrc/rp6502/f_getcwd.c create mode 100644 libsrc/rp6502/f_getfree.c create mode 100644 libsrc/rp6502/f_getlabel.c create mode 100644 libsrc/rp6502/f_setlabel.c diff --git a/include/rp6502.h b/include/rp6502.h index 85916e390..b029789b8 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -166,11 +166,10 @@ int __fastcall__ f_chmod (const char* path, unsigned char attr, unsigned char ma int __fastcall__ f_utime (const char* path, unsigned fdate, unsigned ftime, unsigned crdate, unsigned crtime); int __fastcall__ f_mkdir (const char* name); int __fastcall__ f_chdrive (const char* name); -// int __fastcall__ f_getcwd(char* name, unsigned len); -// int __fastcall__ f_setlabel(const char* name); -// int __fastcall__ f_getlabel(const char* path, char* label); -// int __fastcall__ f_getfree(const char* name); - +int __fastcall__ f_getcwd (char* name, unsigned len); +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); /* Time zone hack */ diff --git a/libsrc/rp6502/f_getcwd.c b/libsrc/rp6502/f_getcwd.c new file mode 100644 index 000000000..477474cbf --- /dev/null +++ b/libsrc/rp6502/f_getcwd.c @@ -0,0 +1,14 @@ +#include +#include +#include + +int __fastcall__ f_getcwd (char* name, unsigned len) +{ + int i, ax; + ria_set_ax (len); + ax = ria_call_int (RIA_OP_GETCWD); + for (i = 0; i < ax; i++) { + name[i] = ria_pop_char (); + } + return ax; +} diff --git a/libsrc/rp6502/f_getfree.c b/libsrc/rp6502/f_getfree.c new file mode 100644 index 000000000..13240591f --- /dev/null +++ b/libsrc/rp6502/f_getfree.c @@ -0,0 +1,22 @@ +#include +#include +#include + +int __fastcall__ f_getfree (const char* name, unsigned long* free, unsigned long* total) +{ + int ax; + size_t namelen = strlen (name); + if (namelen > 255) { + errno = EINVAL; + return -1; + } + while (namelen) { + ria_push_char (name[--namelen]); + } + ax = ria_call_int (RIA_OP_GETFREE); + if (ax >= 0) { + *free = ria_pop_long (); + *total = ria_pop_long (); + } + return ax; +} diff --git a/libsrc/rp6502/f_getlabel.c b/libsrc/rp6502/f_getlabel.c new file mode 100644 index 000000000..89e72eac9 --- /dev/null +++ b/libsrc/rp6502/f_getlabel.c @@ -0,0 +1,21 @@ +#include +#include +#include + +int __fastcall__ f_getlabel (const char* path, char* label) +{ + int i, ax; + size_t pathlen = strlen (path); + if (pathlen > 255) { + errno = EINVAL; + return -1; + } + while (pathlen) { + ria_push_char (path[--pathlen]); + } + ax = ria_call_int (RIA_OP_GETLABEL); + for (i = 0; i < ax; i++) { + label[i] = ria_pop_char (); + } + return ax; +} diff --git a/libsrc/rp6502/f_setlabel.c b/libsrc/rp6502/f_setlabel.c new file mode 100644 index 000000000..0cf77ea15 --- /dev/null +++ b/libsrc/rp6502/f_setlabel.c @@ -0,0 +1,16 @@ +#include +#include +#include + +int __fastcall__ f_setlabel (const char* name) +{ + size_t namelen = strlen (name); + if (namelen > 255) { + errno = EINVAL; + return -1; + } + while (namelen) { + ria_push_char (name[--namelen]); + } + return ria_call_int (RIA_OP_SETLABEL); +} From 69149c65ec8ac3ee36e682be9abd14eff43ba465 Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Thu, 16 Oct 2025 18:14:44 -0700 Subject: [PATCH 14/19] remove blank line --- asminc/rp6502.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/asminc/rp6502.inc b/asminc/rp6502.inc index 05dc93cbe..69292b4aa 100644 --- a/asminc/rp6502.inc +++ b/asminc/rp6502.inc @@ -72,7 +72,6 @@ RIA_OP_SETLABEL := $2C RIA_OP_GETLABEL := $2D RIA_OP_GETFREE := $2E - ; 6522 VIA VIA := $FFD0 ; VIA base address VIA_PB := VIA+$0 ; Port register B From 9b54be41dacc46bd4dc6eec2183965a4b189fddb Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Mon, 20 Oct 2025 22:53:42 -0700 Subject: [PATCH 15/19] code page --- include/rp6502.h | 4 ++-- libsrc/rp6502/code_page.c | 7 +++++++ libsrc/rp6502/codepage.c | 7 ------- 3 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 libsrc/rp6502/code_page.c delete mode 100644 libsrc/rp6502/codepage.c diff --git a/include/rp6502.h b/include/rp6502.h index b029789b8..ceb8f2a52 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -92,7 +92,7 @@ long __fastcall__ ria_call_long (unsigned char op); #define RIA_OP_ZXSTACK 0x00 #define RIA_OP_XREG 0x01 #define RIA_OP_PHI2 0x02 -#define RIA_OP_CODEPAGE 0x03 +#define RIA_OP_CODE_PAGE 0x03 #define RIA_OP_LRAND 0x04 #define RIA_OP_STDIN_OPT 0x05 #define RIA_OP_ERRNO_OPT 0x06 @@ -147,7 +147,7 @@ int __cdecl__ xregn (char device, char channel, unsigned char address, unsigned ...); int __cdecl__ xreg (char device, char channel, unsigned char address, ...); int __fastcall__ phi2 (void); -int __fastcall__ codepage (int); +int __fastcall__ code_page (int); long __fastcall__ lrand (void); int __fastcall__ stdin_opt (unsigned long ctrl_bits, unsigned char str_length); int __fastcall__ read_xstack (void* buf, unsigned count, int fildes); diff --git a/libsrc/rp6502/code_page.c b/libsrc/rp6502/code_page.c new file mode 100644 index 000000000..b7baff27b --- /dev/null +++ b/libsrc/rp6502/code_page.c @@ -0,0 +1,7 @@ +#include + +int __fastcall__ code_page (int cp) +{ + ria_set_ax (cp); + return ria_call_int (RIA_OP_CODE_PAGE); +} diff --git a/libsrc/rp6502/codepage.c b/libsrc/rp6502/codepage.c deleted file mode 100644 index d6c176347..000000000 --- a/libsrc/rp6502/codepage.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int __fastcall__ codepage (int cp) -{ - ria_set_ax (cp); - return ria_call_int (RIA_OP_CODEPAGE); -} From f06acc993a6235899833abf512f62f8111fdcd2a Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Mon, 20 Oct 2025 23:06:32 -0700 Subject: [PATCH 16/19] code_page --- asminc/rp6502.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asminc/rp6502.inc b/asminc/rp6502.inc index 69292b4aa..1d850ec80 100644 --- a/asminc/rp6502.inc +++ b/asminc/rp6502.inc @@ -34,7 +34,7 @@ RIA_OP_EXIT := $FF RIA_OP_ZXSTACK := $00 RIA_OP_XREG := $01 RIA_OP_PHI2 := $02 -RIA_OP_CODEPAGE := $03 +RIA_OP_CODE_PAGE := $03 RIA_OP_LRAND := $04 RIA_OP_STDIN_OPT := $05 RIA_OP_ERRNO_OPT := $06 From 899ee2dac268726c525b0c69ba6bc26af3b60760 Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Tue, 21 Oct 2025 09:42:04 -0700 Subject: [PATCH 17/19] remove fresult --- include/rp6502.h | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/include/rp6502.h b/include/rp6502.h index ceb8f2a52..cff43ff66 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -284,30 +284,4 @@ typedef struct unsigned char has_opacity_metadata; // bool } vga_mode4_asprite_t; -/* Values in __oserror are the union of these FatFs errors and errno.h */ - -typedef enum -{ - FR_OK = 32, /* Succeeded */ - FR_DISK_ERR, /* A hard error occurred in the low level disk I/O layer */ - FR_INT_ERR, /* Assertion failed */ - FR_NOT_READY, /* The physical drive cannot work */ - FR_NO_FILE, /* Could not find the file */ - FR_NO_PATH, /* Could not find the path */ - FR_INVALID_NAME, /* The path name format is invalid */ - FR_DENIED, /* Access denied due to prohibited access or directory full */ - FR_EXIST, /* Access denied due to prohibited access */ - FR_INVALID_OBJECT, /* The file/directory object is invalid */ - FR_WRITE_PROTECTED, /* The physical drive is write protected */ - FR_INVALID_DRIVE, /* The logical drive number is invalid */ - FR_NOT_ENABLED, /* The volume has no work area */ - FR_NO_FILESYSTEM, /* There is no valid FAT volume */ - FR_MKFS_ABORTED, /* The f_mkfs() aborted due to any problem */ - FR_TIMEOUT, /* Could not get a grant to access the volume within defined period */ - FR_LOCKED, /* The operation is rejected according to the file sharing policy */ - FR_NOT_ENOUGH_CORE, /* LFN working buffer could not be allocated */ - FR_TOO_MANY_OPEN_FILES, /* Number of open files > FF_FS_LOCK */ - FR_INVALID_PARAMETER /* Given parameter is invalid */ -} FRESULT; - #endif /* _RP6502_H */ From 47c71604760c117b5bf8aefbdfccaf1b3f36fd82 Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Tue, 21 Oct 2025 20:58:50 -0700 Subject: [PATCH 18/19] getcwd --- include/rp6502.h | 2 +- libsrc/rp6502/f_getcwd.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/rp6502.h b/include/rp6502.h index cff43ff66..2c0e78b87 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -166,7 +166,7 @@ int __fastcall__ f_chmod (const char* path, unsigned char attr, unsigned char ma int __fastcall__ f_utime (const char* path, unsigned fdate, unsigned ftime, unsigned crdate, unsigned crtime); int __fastcall__ f_mkdir (const char* name); int __fastcall__ f_chdrive (const char* name); -int __fastcall__ f_getcwd (char* name, unsigned len); +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); diff --git a/libsrc/rp6502/f_getcwd.c b/libsrc/rp6502/f_getcwd.c index 477474cbf..ef9a0ef22 100644 --- a/libsrc/rp6502/f_getcwd.c +++ b/libsrc/rp6502/f_getcwd.c @@ -2,10 +2,10 @@ #include #include -int __fastcall__ f_getcwd (char* name, unsigned len) +int __fastcall__ f_getcwd (char* name, int size) { int i, ax; - ria_set_ax (len); + ria_set_ax (size); ax = ria_call_int (RIA_OP_GETCWD); for (i = 0; i < ax; i++) { name[i] = ria_pop_char (); From 4cb40a415561a89155e5ab9089f3681e5dbdb09d Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Wed, 22 Oct 2025 18:51:01 -0700 Subject: [PATCH 19/19] f_getcwd --- libsrc/rp6502/f_getcwd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libsrc/rp6502/f_getcwd.c b/libsrc/rp6502/f_getcwd.c index ef9a0ef22..3473b81e1 100644 --- a/libsrc/rp6502/f_getcwd.c +++ b/libsrc/rp6502/f_getcwd.c @@ -5,8 +5,12 @@ int __fastcall__ f_getcwd (char* name, int size) { int i, ax; - ria_set_ax (size); ax = ria_call_int (RIA_OP_GETCWD); + if (ax > size) { + RIA.op = RIA_OP_ZXSTACK; + errno = ENOMEM; + return -1; + } for (i = 0; i < ax; i++) { name[i] = ria_pop_char (); }