Skip to content

Commit 2257f41

Browse files
enable stdio on rp6502 target (#395)
* rp6502 xstack bump to 512 * xstack bump to 512 * xstack bump to 512 * connect stdio * upgrade api to use ria.s * remove header * style * style * nits
1 parent 04fb58a commit 2257f41

29 files changed

+449
-220
lines changed

mos-platform/rp6502/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ add_platform_library(rp6502-c
3636
lrand.c
3737
lseek.c
3838
open.c
39+
oserror.s
3940
phi2.c
4041
putchar.c
4142
read_xram.c
4243
read_xstack.c
4344
read.c
45+
ria.s
4446
stdin_opt.c
4547
sysremove.c
4648
sysrename.c

mos-platform/rp6502/clock.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
#include <rp6502.h>
1+
#include "rp6502.h"
22
#include <time.h>
33

4-
long clock(void) {
5-
RIA.op = RIA_OP_CLOCK;
6-
while (RIA.busy & RIA_BUSY_BIT)
7-
;
8-
return (long)RIA.a | ((long)RIA.x << 8) | ((long)RIA.sreg << 16);
9-
}
4+
long clock(void) { return ria_call_long(RIA_OP_CLOCK); }

mos-platform/rp6502/clock_getres.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
#include <rp6502.h>
1+
#include "rp6502.h"
22
#include <time.h>
33

4+
int __clock_gettimespec(struct timespec *ts, unsigned char op);
5+
46
int clock_getres(clockid_t clock_id, struct timespec *res) {
5-
RIA.a = clock_id;
6-
RIA.x = clock_id >> 8;
7-
RIA.op = RIA_OP_CLOCK_GETRES;
8-
while (RIA.busy & RIA_BUSY_BIT)
9-
;
10-
int ax = RIA.a | (RIA.x << 8);
11-
if (ax >= 0) {
12-
res->tv_sec = (long)RIA.xstack | ((long)RIA.xstack << 8) |
13-
((long)RIA.xstack << 16) | ((long)RIA.xstack << 24);
14-
res->tv_nsec = (long)RIA.xstack | ((long)RIA.xstack << 8) |
15-
((long)RIA.xstack << 16) | ((long)RIA.xstack << 24);
16-
}
17-
return ax;
7+
ria_set_ax(clock_id);
8+
return __clock_gettimespec(res, RIA_OP_CLOCK_GETRES);
189
}

mos-platform/rp6502/clock_gettime.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
#include <rp6502.h>
1+
#include "rp6502.h"
22
#include <time.h>
33

4-
int clock_gettime(clockid_t clock_id, struct timespec *res) {
5-
RIA.a = clock_id;
6-
RIA.x = clock_id >> 8;
7-
RIA.op = RIA_OP_CLOCK_GETTIME;
8-
while (RIA.busy & RIA_BUSY_BIT)
9-
;
10-
int ax = RIA.a | (RIA.x << 8);
11-
if (ax >= 0) {
12-
res->tv_sec = RIA.xstack | (RIA.xstack << 8) | ((long)RIA.xstack << 16) |
13-
((long)RIA.xstack << 24);
14-
res->tv_nsec = RIA.xstack | (RIA.xstack << 8) | ((long)RIA.xstack << 16) |
15-
((long)RIA.xstack << 24);
16-
}
17-
return ax;
4+
int __clock_gettimespec(struct timespec *ts, unsigned char op);
5+
6+
int clock_gettime(clockid_t clock_id, struct timespec *tp) {
7+
ria_set_ax(clock_id);
8+
return __clock_gettimespec(tp, RIA_OP_CLOCK_GETTIME);
189
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "rp6502.h"
2+
#include <time.h>
3+
4+
/* Internal method shared by clock_getres and clock_gettime. */
5+
int __clock_gettimespec(struct timespec *ts, unsigned char op) {
6+
int ax = ria_call_int_errno(op);
7+
if (ax >= 0) {
8+
ts->tv_sec = ria_pop_long();
9+
ts->tv_nsec = ria_pop_long();
10+
}
11+
return ax;
12+
}

mos-platform/rp6502/clock_settime.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
#include <rp6502.h>
1+
#include "rp6502.h"
22
#include <time.h>
33

44
int clock_settime(clockid_t clock_id, const struct timespec *tp) {
5-
RIA.a = clock_id;
6-
RIA.x = clock_id >> 8;
7-
RIA.xstack = tp->tv_nsec >> 24;
8-
RIA.xstack = tp->tv_nsec >> 16;
9-
RIA.xstack = tp->tv_nsec >> 8;
10-
RIA.xstack = tp->tv_nsec;
11-
RIA.xstack = tp->tv_sec >> 24;
12-
RIA.xstack = tp->tv_sec >> 16;
13-
RIA.xstack = tp->tv_sec >> 8;
14-
RIA.xstack = tp->tv_sec;
15-
RIA.op = RIA_OP_CLOCK_SETTIME;
16-
while (RIA.busy & RIA_BUSY_BIT)
17-
;
18-
return RIA.a | (RIA.x << 8);
5+
ria_set_ax(clock_id);
6+
ria_push_long(tp->tv_nsec);
7+
ria_push_long(tp->tv_sec);
8+
return ria_call_int_errno(RIA_OP_CLOCK_SETTIME);
199
}

mos-platform/rp6502/close.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
#include <rp6502.h>
1+
#include <fcntl.h>
2+
#include "rp6502.h"
23

34
int close(int fd) {
4-
RIA.a = fd;
5-
RIA.x = fd >> 8;
6-
RIA.op = RIA_OP_CLOSE;
7-
while (RIA.busy & RIA_BUSY_BIT)
8-
;
9-
return RIA.a | (RIA.x << 8);
5+
ria_set_ax(fd);
6+
return ria_call_int_errno(RIA_OP_CLOSE);
107
}

mos-platform/rp6502/codepage.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
#include "rp6502.h"
22

3-
int codepage(void) {
4-
RIA.op = RIA_OP_CODEPAGE;
5-
while (RIA.busy & RIA_BUSY_BIT)
6-
;
7-
return RIA.a | (RIA.x << 8);
8-
}
3+
int codepage(void) { return ria_call_int(RIA_OP_CODEPAGE); }

mos-platform/rp6502/exit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "rp6502.h"
22

33
void _Exit(int status) {
4-
RIA.a = status;
5-
RIA.x = status >> 8;
4+
ria_set_ax(status);
65
RIA.op = RIA_OP_EXIT;
76
}

mos-platform/rp6502/getchar.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#include "rp6502.h"
22
#include <stdio.h>
3+
#include <unistd.h>
34

45
int __getchar(void) {
5-
RIA.xstack = 1;
6-
RIA.a = 0;
7-
RIA.op = RIA_OP_READ_XSTACK;
8-
while (RIA.busy & RIA_BUSY_BIT)
9-
;
10-
if (RIA.a)
6+
ria_push_char(1);
7+
ria_set_a(STDIN_FILENO);
8+
if (ria_call_int_errno(RIA_OP_READ_XSTACK) == 1)
119
return RIA.xstack;
1210
return EOF;
1311
}

0 commit comments

Comments
 (0)