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

@@ -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)
{
/* Modified argument order for short stacking offset */
ria_push_long (offset);
ria_push_char (whence);
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)
{
ria_set_ax (fildes);
ria_push_int (buf);
ria_push_int (count);
ria_set_ax (fildes);
return ria_call_int (RIA_OP_WRITE_XRAM);
}