Skip to content

Commit 25c254f

Browse files
Support for RP6502 Version 0.14 (#413)
* add RP6502 XREG helper macros * RP6502 change to RIA.errno_ for macro safety * settable codepage() on RP6502 * add xreg_ria_gamepad * remove oserror from platform rp6502 * add rp6502 dir ops * what's this? * rp6502 dir inc * code page * getcwd * f_getcwd
1 parent e9be6e5 commit 25c254f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+420
-258
lines changed

mos-platform/common/include/unistd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ typedef long int off_t;
7272
int write(int fd, const void* buf, unsigned count);
7373
int read(int fd, void* buf, unsigned count);
7474
off_t lseek(int fd, off_t offset, int whence);
75+
int syncfs (int fd);
7576
int unlink(const char* name); /* Same as remove() */
7677

7778
/* Directories */

mos-platform/rp6502/CMakeLists.txt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,44 @@ merge_libraries(rp6502-crt0
2626

2727
add_platform_library(rp6502-c
2828
abort.c
29+
chdir.c
2930
clock_getres.c
3031
clock_gettime.c
3132
clock_settime.c
3233
clock.c
3334
close.c
34-
codepage.c
35+
code_page.c
36+
errno.s
37+
f_chdrive.c
38+
f_chmod.c
39+
f_closedir.c
40+
f_getcwd.c
41+
f_getfree.c
42+
f_getlabel.c
43+
f_lseek.c
44+
f_mkdir.c
45+
f_opendir.c
46+
f_readdir.c
47+
f_rewinddir.c
48+
f_seekdir.c
49+
f_setlabel.c
50+
f_stat.c
51+
f_telldir.c
52+
f_utime.c
3553
getchar.c
3654
lrand.c
3755
lseek.c
3856
open.c
39-
oserror.s
4057
phi2.c
4158
putchar.c
4259
read_xram.c
4360
read_xstack.c
4461
read.c
62+
remove.c
63+
rename.c
4564
ria.s
4665
stdin_opt.c
47-
sysremove.c
48-
sysrename.c
66+
syncfs.c
4967
write_xram.c
5068
write_xstack.c
5169
write.c

mos-platform/rp6502/chdir.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <errno.h>
2+
#include <rp6502.h>
3+
#include <string.h>
4+
#include <unistd.h>
5+
6+
int chdir(const char *name) {
7+
size_t namelen = strlen(name);
8+
if (namelen > 255) {
9+
errno = EINVAL;
10+
return -1;
11+
}
12+
while (namelen) {
13+
ria_push_char(name[--namelen]);
14+
}
15+
return ria_call_int(RIA_OP_CHDIR);
16+
}

mos-platform/rp6502/clock_gettimespec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/* Internal method shared by clock_getres and clock_gettime. */
55
int __clock_gettimespec(struct timespec *ts, unsigned char op) {
6-
int ax = ria_call_int_errno(op);
6+
int ax = ria_call_int(op);
77
if (ax >= 0) {
88
ts->tv_sec = ria_pop_long();
99
ts->tv_nsec = ria_pop_long();

mos-platform/rp6502/clock_settime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ int clock_settime(clockid_t clock_id, const struct timespec *tp) {
55
ria_set_ax(clock_id);
66
ria_push_long(tp->tv_nsec);
77
ria_push_long(tp->tv_sec);
8-
return ria_call_int_errno(RIA_OP_CLOCK_SETTIME);
8+
return ria_call_int(RIA_OP_CLOCK_SETTIME);
99
}

mos-platform/rp6502/close.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
int close(int fd) {
55
ria_set_ax(fd);
6-
return ria_call_int_errno(RIA_OP_CLOSE);
6+
return ria_call_int(RIA_OP_CLOSE);
77
}

mos-platform/rp6502/code_page.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "rp6502.h"
2+
3+
int code_page(int cp) {
4+
ria_set_ax(cp);
5+
return ria_call_int(RIA_OP_CODE_PAGE);
6+
}

mos-platform/rp6502/codepage.c

Lines changed: 0 additions & 3 deletions
This file was deleted.

mos-platform/rp6502/errno.s

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.include "rp6502.inc"
2+
3+
; The errno on the RP6502 RIA is the errno for llvm-mos.
4+
; There is no oserror and nothing calls __mappederrno.
5+
6+
.global _errno
7+
.set _errno, RIA_ERRNO
8+
9+
; Request the RIA use llvm-mos values for RIA_ERRNO
10+
11+
.section .init.100,"ax",@progbits
12+
lda #$02 ; 2 = llvm-mos
13+
sta RIA_A
14+
lda #RIA_OP_ERRNO_OPT
15+
sta RIA_OP
16+
jsr RIA_SPIN

mos-platform/rp6502/f_chdrive.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <errno.h>
2+
#include <rp6502.h>
3+
#include <string.h>
4+
5+
int f_chdrive(const char *name) {
6+
size_t namelen = strlen(name);
7+
if (namelen > 255) {
8+
errno = EINVAL;
9+
return -1;
10+
}
11+
while (namelen) {
12+
ria_push_char(name[--namelen]);
13+
}
14+
return ria_call_int(RIA_OP_CHDRIVE);
15+
}

0 commit comments

Comments
 (0)