style update and add rp6502 doc

This commit is contained in:
rumbledethumps
2023-11-17 11:08:51 -08:00
parent b17c4d3434
commit 564c85235f
32 changed files with 261 additions and 351 deletions

View File

@@ -1,16 +1,8 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
#include <errno.h>
int __fastcall__ close(int fd)
int __fastcall__ close (int fd)
{
ria_set_ax(fd);
return ria_call_int_errno(RIA_OP_CLOSE);
ria_set_ax (fd);
return ria_call_int_errno (RIA_OP_CLOSE);
}

View File

@@ -1,14 +1,6 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
int __fastcall__ codepage(void)
int __fastcall__ codepage (void)
{
return ria_call_int(RIA_OP_CODEPAGE);
return ria_call_int (RIA_OP_CODEPAGE);
}

View File

@@ -1,10 +1,7 @@
; Copyright (c) 2023 Rumbledethumps
;
; SPDX-License-Identifier: Zlib
; SPDX-License-Identifier: BSD-3-Clause
; SPDX-License-Identifier: Unlicense
; Boilerplate crt0.s
; 2023, Rumbledethumps
;
; crt0.s
.export _init, _exit
.import _main

View File

@@ -1,18 +1,10 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
#include <time.h>
extern int __clock_gettimespec(struct timespec *ts, unsigned char op);
extern int __clock_gettimespec (struct timespec* ts, unsigned char op);
int clock_getres(clockid_t clock_id, struct timespec *res)
int clock_getres (clockid_t clock_id, struct timespec* res)
{
ria_set_ax(clock_id);
return __clock_gettimespec(res, RIA_OP_CLOCK_GETRES);
ria_set_ax (clock_id);
return __clock_gettimespec (res, RIA_OP_CLOCK_GETRES);
}

View File

@@ -1,20 +1,12 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
#include <time.h>
extern int __clock_gettimespec(struct timespec *ts, unsigned char op);
extern int __clock_gettimespec (struct timespec* ts, unsigned char op);
int clock_gettime(clockid_t clock_id, struct timespec *tp)
int clock_gettime (clockid_t clock_id, struct timespec* tp)
{
(void)clock_id;
/* time.s doesn't set the stack value for clock_id (bug?) */
ria_set_ax(CLOCK_REALTIME);
return __clock_gettimespec(tp, RIA_OP_CLOCK_GETTIME);
ria_set_ax (CLOCK_REALTIME);
return __clock_gettimespec (tp, RIA_OP_CLOCK_GETTIME);
}

View File

@@ -1,22 +1,13 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
#include <time.h>
int __clock_gettimespec(struct timespec *ts, unsigned char op)
int __clock_gettimespec (struct timespec* ts, unsigned char op)
/* Internal method shared by clock_getres and clock_gettime. */
{
int ax = ria_call_int_errno(op);
if (ax >= 0)
{
ts->tv_sec = ria_pop_long();
ts->tv_nsec = ria_pop_long();
int ax = ria_call_int_errno (op);
if (ax >= 0) {
ts->tv_sec = ria_pop_long ();
ts->tv_nsec = ria_pop_long ();
}
return ax;
}

View File

@@ -1,24 +1,15 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
#include <time.h>
int clock_gettimezone(clockid_t clock_id, struct _timezone *tz)
int clock_gettimezone (clockid_t clock_id, struct _timezone* tz)
{
int ax;
ria_set_ax(clock_id);
ax = ria_call_int_errno(RIA_OP_CLOCK_GETTIMEZONE);
if (ax >= 0)
{
ria_set_ax (clock_id);
ax = ria_call_int_errno (RIA_OP_CLOCK_GETTIMEZONE);
if (ax >= 0) {
char i;
for (i = 0; i < sizeof(struct _timezone); i++)
((char *)tz)[i] = ria_pop_char();
for (i = 0; i < sizeof (struct _timezone); i++)
((char*)tz)[i] = ria_pop_char ();
}
return ax;
}

View File

@@ -1,8 +1,6 @@
; Copyright (c) 2023 Rumbledethumps
;
; SPDX-License-Identifier: Zlib
; SPDX-License-Identifier: BSD-3-Clause
; SPDX-License-Identifier: Unlicense
; 2023, Rumbledethumps
;
.constructor initenv, 24
.import __environ, __envcount, __envsize

View File

@@ -1,8 +1,7 @@
; Copyright (c) 2023 Rumbledethumps
;
; SPDX-License-Identifier: Zlib
; SPDX-License-Identifier: BSD-3-Clause
; SPDX-License-Identifier: Unlicense
; 2023, Rumbledethumps
;
; Enables the C IRQ tools
.export initirq, doneirq
.import callirq, _exit

View File

@@ -1,14 +1,6 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
long __fastcall__ lrand(void)
long __fastcall__ lrand (void)
{
return ria_call_long(RIA_OP_LRAND);
return ria_call_long (RIA_OP_LRAND);
}

View File

@@ -1,19 +1,11 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
#include <unistd.h>
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_char(whence);
ria_set_ax(fd);
return ria_call_long_errno(RIA_OP_LSEEK);
ria_push_long (offset);
ria_push_char (whence);
ria_set_ax (fd);
return ria_call_long_errno (RIA_OP_LSEEK);
}

View File

@@ -1,8 +1,7 @@
; Copyright (c) 2023 Rumbledethumps
;
; SPDX-License-Identifier: Zlib
; SPDX-License-Identifier: BSD-3-Clause
; SPDX-License-Identifier: Unlicense
; 2023, Rumbledethumps
;
; No arguments
.constructor initmainargs, 24
.import __argc, __argv

View File

@@ -1,26 +1,16 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
#include <errno.h>
#include <string.h>
int __cdecl__ open(const char *name, int flags, ...)
int __cdecl__ open (const char* name, int flags, ...)
{
size_t namelen = strlen(name);
if (namelen > 255)
{
return _mappederrno(EINVAL);
size_t namelen = strlen (name);
if (namelen > 255) {
return _mappederrno (EINVAL);
}
while (namelen)
{
ria_push_char(name[--namelen]);
while (namelen) {
ria_push_char (name[--namelen]);
}
ria_set_ax(flags);
return ria_call_int_errno(RIA_OP_OPEN);
ria_set_ax (flags);
return ria_call_int_errno (RIA_OP_OPEN);
}

View File

@@ -1,14 +1,6 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
int __fastcall__ phi2(void)
int __fastcall__ phi2 (void)
{
return ria_call_int(RIA_OP_PHI2);
return ria_call_int (RIA_OP_PHI2);
}

View File

@@ -1,16 +1,8 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
#include <stdlib.h>
// Non-standard cc65
void _randomize(void)
void _randomize (void)
{
srand(ria_call_int(RIA_OP_LRAND));
srand (ria_call_int (RIA_OP_LRAND));
}

View File

@@ -1,29 +1,18 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
#include <unistd.h>
int __fastcall__ read(int fildes, void *buf, unsigned count)
int __fastcall__ read (int fildes, void* buf, unsigned count)
{
int total = 0;
while (count)
{
while (count) {
unsigned blockcount = (count > 256) ? 256 : count;
int bytes_read = read_xstack(&((char *)buf)[total], blockcount, fildes);
if (bytes_read < 0)
{
int bytes_read = read_xstack (&((char*)buf)[total], blockcount, fildes);
if (bytes_read < 0) {
return bytes_read;
}
total += bytes_read;
count -= bytes_read;
if (bytes_read < blockcount)
{
if (bytes_read < blockcount) {
break;
}
}

View File

@@ -1,17 +1,9 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
int __fastcall__ read_xram(unsigned buf, unsigned count, int fildes)
int __fastcall__ read_xram (unsigned buf, unsigned count, int fildes)
{
ria_push_int(buf);
ria_push_int(count);
ria_set_ax(fildes);
return ria_call_int_errno(RIA_OP_READ_XRAM);
ria_push_int (buf);
ria_push_int (count);
ria_set_ax (fildes);
return ria_call_int_errno (RIA_OP_READ_XRAM);
}

View File

@@ -1,22 +1,13 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
int __fastcall__ read_xstack(void *buf, unsigned count, int fildes)
int __fastcall__ read_xstack (void* buf, unsigned count, int fildes)
{
int i, ax;
ria_push_int(count);
ria_set_ax(fildes);
ax = ria_call_int_errno(RIA_OP_READ_XSTACK);
for (i = 0; i < ax; i++)
{
((char *)buf)[i] = ria_pop_char();
ria_push_int (count);
ria_set_ax (fildes);
ax = ria_call_int_errno (RIA_OP_READ_XSTACK);
for (i = 0; i < ax; i++) {
((char*)buf)[i] = ria_pop_char ();
}
return ax;
}

View File

@@ -1,8 +1,7 @@
; Copyright (c) 2023 Rumbledethumps
;
; SPDX-License-Identifier: Zlib
; SPDX-License-Identifier: BSD-3-Clause
; SPDX-License-Identifier: Unlicense
; 2023, Rumbledethumps
;
; Helpers for building API shims
.include "rp6502.inc"

View File

@@ -1,18 +1,10 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
#include <time.h>
int clock_settime(clockid_t clock_id, const struct timespec *tp)
int clock_settime (clockid_t clock_id, const struct timespec* tp)
{
ria_set_ax(clock_id);
ria_push_long(tp->tv_nsec);
ria_push_long(tp->tv_sec);
return ria_call_int_errno(RIA_OP_CLOCK_SETTIME);
ria_set_ax (clock_id);
ria_push_long (tp->tv_nsec);
ria_push_long (tp->tv_sec);
return ria_call_int_errno (RIA_OP_CLOCK_SETTIME);
}

View File

@@ -1,16 +1,9 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
int __fastcall__ stdin_opt(unsigned long ctrl_bits, unsigned char str_length)
int __fastcall__ stdin_opt (unsigned long ctrl_bits, unsigned char str_length)
{
ria_push_long(ctrl_bits);
ria_set_a(str_length);
return ria_call_int_errno(RIA_OP_STDIN_OPT);
ria_push_long (ctrl_bits);
ria_set_a (str_length);
return ria_call_int_errno (RIA_OP_STDIN_OPT);
}

View File

@@ -1,26 +1,16 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
#include <errno.h>
#include <string.h>
unsigned char __fastcall__ _sysremove(const char *name)
unsigned char __fastcall__ _sysremove (const char* name)
{
size_t namelen;
namelen = strlen(name);
if (namelen > 255)
{
return _mappederrno(EINVAL);
namelen = strlen (name);
if (namelen > 255) {
return _mappederrno (EINVAL);
}
while (namelen)
{
ria_push_char(name[--namelen]);
while (namelen) {
ria_push_char (name[--namelen]);
}
return ria_call_int_errno(RIA_OP_UNLINK);
return ria_call_int_errno (RIA_OP_UNLINK);
}

View File

@@ -1,32 +1,21 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
#include <errno.h>
#include <string.h>
unsigned char __fastcall__ _sysrename(const char *oldpath, const char *newpath)
unsigned char __fastcall__ _sysrename (const char* oldpath, const char* newpath)
{
size_t oldpathlen, newpathlen;
oldpathlen = strlen(oldpath);
newpathlen = strlen(newpath);
if (oldpathlen + newpathlen > 254)
{
return _mappederrno(EINVAL);
oldpathlen = strlen (oldpath);
newpathlen = strlen (newpath);
if (oldpathlen + newpathlen > 254) {
return _mappederrno (EINVAL);
}
while (oldpathlen)
{
ria_push_char(oldpath[--oldpathlen]);
while (oldpathlen) {
ria_push_char (oldpath[--oldpathlen]);
}
ria_push_char(0);
while (newpathlen)
{
ria_push_char(newpath[--newpathlen]);
ria_push_char (0);
while (newpathlen) {
ria_push_char (newpath[--newpathlen]);
}
return ria_call_int_errno(RIA_OP_RENAME);
return ria_call_int_errno (RIA_OP_RENAME);
}

View File

@@ -1,29 +1,18 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
#include <unistd.h>
int __fastcall__ write(int fildes, const void *buf, unsigned count)
int __fastcall__ write (int fildes, const void* buf, unsigned count)
{
int ax, total = 0;
while (count)
{
while (count) {
int blockcount = (count > 256) ? 256 : count;
ax = write_xstack(&((char *)buf)[total], blockcount, fildes);
if (ax < 0)
{
ax = write_xstack (&((char*)buf)[total], blockcount, fildes);
if (ax < 0) {
return ax;
}
total += ax;
count -= ax;
if (ax < blockcount)
{
if (ax < blockcount) {
break;
}
}

View File

@@ -1,17 +1,9 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
int __fastcall__ write_xram(unsigned buf, unsigned count, int fildes)
int __fastcall__ write_xram (unsigned buf, unsigned count, int fildes)
{
ria_push_int(buf);
ria_push_int(count);
ria_set_ax(fildes);
return ria_call_int_errno(RIA_OP_WRITE_XRAM);
ria_push_int (buf);
ria_push_int (count);
ria_set_ax (fildes);
return ria_call_int_errno (RIA_OP_WRITE_XRAM);
}

View File

@@ -1,20 +1,11 @@
/*
* Copyright (c) 2023 Rumbledethumps
*
* SPDX-License-Identifier: Zlib
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: Unlicense
*/
#include <rp6502.h>
int __fastcall__ write_xstack(const void *buf, unsigned count, int fildes)
int __fastcall__ write_xstack (const void* buf, unsigned count, int fildes)
{
unsigned i;
for (i = count; i;)
{
ria_push_char(((char *)buf)[--i]);
for (i = count; i;) {
ria_push_char (((char*)buf)[--i]);
}
ria_set_ax(fildes);
return ria_call_int_errno(RIA_OP_WRITE_XSTACK);
ria_set_ax (fildes);
return ria_call_int_errno (RIA_OP_WRITE_XSTACK);
}

View File

@@ -1,9 +1,6 @@
; Copyright (c) 2023 Rumbledethumps
;
; SPDX-License-Identifier: Zlib
; SPDX-License-Identifier: BSD-3-Clause
; SPDX-License-Identifier: Unlicense
; 2023, Rumbledethumps
;
; CC65 will promote variadic char arguments to int. It will not demote longs.
; int __cdecl__ xreg(char device, char channel, unsigned char address, ...);