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); }