@@ -54,10 +54,10 @@ and other hardware added "up". For example: VIA0 at $FFD0, VIA1 at
5454$FFC0, SID0 at $FF00, and SID1 at $FF20.
5555
5656
57- Application Binary Interface (ABI)
58- ==================================
57+ Application Binary Interface
58+ ============================
5959
60- The binary interface for calling the operating system is based on
60+ The ABI for calling the operating system is based on
6161fastcall from the `cc65 internals
6262<https://cc65.github.io/doc/cc65-intern.html> `_. The :doc: `os `
6363does not use or require anything from cc65 and is easy for
@@ -332,7 +332,7 @@ CODE_PAGE
332332 :errno: will not fail
333333
334334
335- lrand
335+ LRAND
336336-----
337337
338338.. c :function :: long lrand (void)
@@ -350,7 +350,7 @@ lrand
350350 :errno: will not fail
351351
352352
353- stdin_opt
353+ STDIN_OPT
354354---------
355355
356356.. c:function:: int stdin_opt(unsigned long ctrl_bits, unsigned char str_length)
@@ -377,7 +377,125 @@ stdin_opt
377377 :errno: will not fail
378378
379379
380- clock
380+ ERRNO_OPT
381+ ---------
382+
383+ .. c:function:: int errno_opt(char option)
384+
385+ |
386+
387+ :doc:`os` calls will set RIA_ERRNO when an error occurs. The compiler
388+ libraries use different constants in errno.h. Both cc65
389+ and llvm-mos set this automatically for C programs. The RIA_ERRNO value will not
390+ change until it is set. Note that the C `errno` maps directly to RIA_ERRNO.
391+
392+ :doc:`os` will map FatFs errors onto errno. RP6502 emulation and simulation
393+ software is expected to map their native errors as well. The table below
394+ shows the FatFs mappings. Because FatFs is to integral to the OS,
395+ calls are documented here with their native FatFs names to assist when
396+ cross referencing the `FatFs documentation <https:// elm-chan.org/fsw/ff/>`__.
397+
398+ :Op code: RIA_OP_ERRNO_OPT 0x06
399+ :C proto: None
400+ :param option: One of the values from the table below.
401+ :a regs: return, option
402+ :returns: 0 on success
403+ :errno: EINVAL
404+
405+ .. list-table::
406+ :header-rows: 1
407+ :widths: 25 25 25 25
408+
409+ * -
410+ - cc65
411+ - llvm_mos
412+ - FatFs
413+ * - option
414+ - 1
415+ - 2
416+ -
417+ * - ENOENT
418+ - 1
419+ - 2
420+ - FR_NO_FILE, FR_NO_PATH
421+ * - ENOMEM
422+ - 2
423+ - 12
424+ - FR_NOT_ENOUGH_CORE
425+ * - EACCES
426+ - 3
427+ - 23
428+ - FR_DENIED, FR_WRITE_PROTECTED
429+ * - ENODEV
430+ - 4
431+ - 19
432+ - FR_NOT_READY, FR_INVALID_DRIVE, FR_NOT_ENABLED, FR_NO_FILESYSTEM
433+ * - EMFILE
434+ - 5
435+ - 24
436+ - FR_TOO_MANY_OPEN_FILES
437+ * - EBUSY
438+ - 6
439+ - 16
440+ - FR_LOCKED
441+ * - EINVAL
442+ - 7
443+ - 22
444+ - FR_INVALID_NAME, FR_INVALID_PARAMETER
445+ * - ENOSPC
446+ - 8
447+ - 28
448+ -
449+ * - EEXIST
450+ - 9
451+ - 17
452+ - FR_EXIST
453+ * - EAGAIN
454+ - 10
455+ - 11
456+ - FR_TIMEOUT
457+ * - EIO
458+ - 11
459+ - 5
460+ - FR_DISK_ERR, FR_INT_ERR, FR_MKFS_ABORTED
461+ * - EINTR
462+ - 12
463+ - 4
464+ -
465+ * - ENOSYS
466+ - 13
467+ - 38
468+ -
469+ * - ESPIPE
470+ - 14
471+ - 29
472+ -
473+ * - ERANGE
474+ - 15
475+ - 34
476+ -
477+ * - EBADF
478+ - 16
479+ - 9
480+ - FR_INVALID_OBJECT
481+ * - ENOEXEC
482+ - 17
483+ - 8
484+ -
485+ * - EDOM
486+ - 18
487+ - 33
488+ -
489+ * - EILSEQ
490+ - 18
491+ - 84
492+ -
493+ * - EUNKNOWN
494+ - 18
495+ - 85
496+ -
497+
498+ CLOCK
381499-----
382500
383501.. c:function:: unsigned long clock(void)
@@ -393,7 +511,7 @@ clock
393511 :errno: will not fail
394512
395513
396- clock_getres
514+ CLOCK_GETRES
397515------------
398516
399517.. c:function:: int clock_getres(clockid_t clock_id, struct timespec *res)
@@ -417,7 +535,7 @@ clock_getres
417535 :errno: EINVAL
418536
419537
420- clock_gettime
538+ CLOCK_GETTIME
421539-------------
422540
423541.. c :function :: int clock_gettime (clockid_t clock_id, struct timespec *tp)
@@ -434,7 +552,7 @@ clock_gettime
434552 :errno: EINVAL, EUNKNOWN
435553
436554
437- clock_settime
555+ CLOCK_SETTIME
438556-------------
439557
440558.. c :function :: int clock_settime (clockid_t clock_id, const struct timespec *tp)
@@ -451,7 +569,7 @@ clock_settime
451569 :errno: EINVAL, EUNKNOWN
452570
453571
454- clock_gettimezone
572+ CLOCK_GETTIMEZONE
455573-----------------
456574
457575.. c :function :: int clock_gettimezone (uint32_t time, clockid_t clock_id, struct _timezone *tz)
@@ -482,7 +600,7 @@ clock_gettimezone
482600 :errno: EINVAL
483601
484602
485- open
603+ OPEN
486604----
487605
488606.. c :function :: int open (const char *path, int oflag)
521639 | If O_CREAT and O_EXCL are set, fail if the file exists.
522640
523641
524- close
642+ CLOSE
525643-----
526644
527645.. c :function :: int close (int fildes)
@@ -540,7 +658,7 @@ close
540658 FR_TIMEOUT
541659
542660
543- read
661+ READ
544662----
545663
546664.. c:function:: int read(int fildes, void *buf, unsigned count)
562680 FR_INVALID_OBJECT, FR_TIMEOUT
563681
564682
565- read_xstack
683+ READ_XSTACK
566684-----------
567685
568686.. c :function :: int read_xstack (void *buf, unsigned count, int fildes)
@@ -582,7 +700,7 @@ read_xstack
582700 :errno: EINVAL, FR_DISK_ERR, FR_INT_ERR, FR_DENIED,
583701 FR_INVALID_OBJECT, FR_TIMEOUT
584702
585- read_xram
703+ READ_XRAM
586704---------
587705
588706.. c :function :: int read_xram (unsigned buf, unsigned count, int fildes)
@@ -603,7 +721,7 @@ read_xram
603721 FR_INVALID_OBJECT, FR_TIMEOUT
604722
605723
606- write
724+ WRITE
607725-----
608726
609727.. c:function:: int write(int fildes, const void *buf, unsigned count)
@@ -625,7 +743,7 @@ write
625743 FR_INVALID_OBJECT, FR_TIMEOUT
626744
627745
628- write_xstack
746+ WRITE_XSTACK
629747------------
630748
631749.. c :function :: int write_xstack (const void *buf, unsigned count, int fildes)
@@ -646,7 +764,7 @@ write_xstack
646764 FR_INVALID_OBJECT, FR_TIMEOUT
647765
648766
649- write_xram
767+ WRITE_XRAM
650768----------
651769
652770.. c :function :: int write_xram (unsigned buf, unsigned count, int fildes)
@@ -667,7 +785,7 @@ write_xram
667785 FR_INVALID_OBJECT, FR_TIMEOUT
668786
669787
670- lseek
788+ LSEEK
671789-----
672790
673791.. c:function:: static long f_lseek(long offset, char whence, int fildes)
@@ -710,7 +828,7 @@ lseek
710828 - 1
711829
712830
713- unlink
831+ UNLINK
714832------
715833
716834.. c:function:: int unlink (const char* name)
@@ -729,7 +847,7 @@ unlink
729847 FR_LOCKED, FR_NOT_ENOUGH_CORE
730848
731849
732- rename
850+ RENAME
733851------
734852
735853.. c:function:: int rename (const char* oldname, const char* newname)
@@ -749,7 +867,7 @@ rename
749867 FR_LOCKED, FR_NOT_ENOUGH_CORE
750868
751869
752- exit
870+ EXIT
753871----
754872
755873.. c:function:: void exit(int status)
0 commit comments