directory ops

This commit is contained in:
rumbledethumps
2025-10-14 23:11:23 -07:00
parent a6763af95c
commit e6c138dc03
11 changed files with 138 additions and 8 deletions

View File

@@ -50,8 +50,28 @@ RIA_OP_READ_XRAM := $17
RIA_OP_WRITE_XSTACK := $18 RIA_OP_WRITE_XSTACK := $18
RIA_OP_WRITE_XRAM := $19 RIA_OP_WRITE_XRAM := $19
RIA_OP_LSEEK := $1A RIA_OP_LSEEK := $1A
RIA_OP_LSEEK_CC65 := $1A
RIA_OP_UNLINK := $1B RIA_OP_UNLINK := $1B
RIA_OP_RENAME := $1C 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 ; 6522 VIA
VIA := $FFD0 ; VIA base address VIA := $FFD0 ; VIA base address

View File

@@ -108,22 +108,58 @@ long __fastcall__ ria_call_long (unsigned char op);
#define RIA_OP_WRITE_XSTACK 0x18 #define RIA_OP_WRITE_XSTACK 0x18
#define RIA_OP_WRITE_XRAM 0x19 #define RIA_OP_WRITE_XRAM 0x19
#define RIA_OP_LSEEK 0x1A #define RIA_OP_LSEEK 0x1A
#define RIA_OP_LSEEK_CC65 0x1A
#define RIA_OP_UNLINK 0x1B #define RIA_OP_UNLINK 0x1B
#define RIA_OP_RENAME 0x1C #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. */ /* 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__ xregn (char device, char channel, unsigned char address, unsigned count,
...); ...);
int __cdecl__ xreg (char device, char channel, unsigned char address, ...); int __cdecl__ xreg (char device, char channel, unsigned char address, ...);
int phi2 (void); int __fastcall__ phi2 (void);
int codepage (int); int __fastcall__ codepage (int);
long lrand (void); long __fastcall__ lrand (void);
int __fastcall__ stdin_opt (unsigned long ctrl_bits, unsigned char str_length); 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_xstack (void* buf, unsigned count, int fildes);
int __fastcall__ read_xram (unsigned 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_xstack (const void* buf, unsigned count, int fildes);
int __fastcall__ write_xram (unsigned 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 */ /* Time zone hack */

View File

@@ -77,6 +77,7 @@ extern int optind, opterr, optopt;
int __fastcall__ write (int fd, const void* buf, unsigned count); int __fastcall__ write (int fd, const void* buf, unsigned count);
int __fastcall__ read (int fd, void* buf, unsigned count); int __fastcall__ read (int fd, void* buf, unsigned count);
off_t __fastcall__ lseek (int fd, off_t offset, int whence); 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() */ int __fastcall__ unlink (const char* name); /* Same as remove() */
/* Directories */ /* Directories */
@@ -98,6 +99,3 @@ int __fastcall__ exec (const char* progname, const char* cmdline);
/* End of unistd.h */ /* End of unistd.h */
#endif #endif

View File

@@ -0,0 +1,8 @@
#include <rp6502.h>
#include <fcntl.h>
int __fastcall__ f_closedir (int dirdes)
{
ria_set_ax (dirdes);
return ria_call_int (RIA_OP_CLOSEDIR);
}

10
libsrc/rp6502/f_lseek.c Normal file
View File

@@ -0,0 +1,10 @@
#include <rp6502.h>
#include <unistd.h>
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);
}

16
libsrc/rp6502/f_opendir.c Normal file
View File

@@ -0,0 +1,16 @@
#include <rp6502.h>
#include <errno.h>
#include <string.h>
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);
}

14
libsrc/rp6502/f_readdir.c Normal file
View File

@@ -0,0 +1,14 @@
#include <rp6502.h>
#include <errno.h>
#include <string.h>
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;
}

21
libsrc/rp6502/f_stat.c Normal file
View File

@@ -0,0 +1,21 @@
#include <rp6502.h>
#include <errno.h>
#include <string.h>
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;
}

View File

@@ -3,7 +3,6 @@
off_t __fastcall__ lseek (int fd, off_t offset, int whence) off_t __fastcall__ lseek (int fd, off_t offset, int whence)
{ {
/* Modified argument order for short stacking offset */
ria_push_long (offset); ria_push_long (offset);
ria_push_char (whence); ria_push_char (whence);
ria_set_ax (fd); ria_set_ax (fd);

8
libsrc/rp6502/syncfs.c Normal file
View File

@@ -0,0 +1,8 @@
#include <rp6502.h>
#include <unistd.h>
int __fastcall__ syncfs (int fd)
{
ria_set_ax (fd);
return ria_call_int (RIA_OP_SYNCFS);
}

View File

@@ -2,8 +2,8 @@
int __fastcall__ write_xram (unsigned buf, unsigned count, int fildes) int __fastcall__ write_xram (unsigned buf, unsigned count, int fildes)
{ {
ria_set_ax (fildes);
ria_push_int (buf); ria_push_int (buf);
ria_push_int (count); ria_push_int (count);
ria_set_ax (fildes);
return ria_call_int (RIA_OP_WRITE_XRAM); return ria_call_int (RIA_OP_WRITE_XRAM);
} }