@@ -80,17 +80,19 @@ as a C declaration like so:
8080
8181.. c :function :: int doit (int arg0, int arg1);
8282
83- The RIA has registers called ``RIA_A ``, ``RIA_X ``, and ``RIA_SREG ``. An int is 16 bits,
84- so we set the ``RIA_A `` and ``RIA_X `` registers with arg1. I'll use "A" for the 6502
85- register and "RIA_A" for the RIA register in this explanation.
83+ The RIA has registers called ``RIA_A ``, ``RIA_X ``, and ``RIA_SREG ``. An int
84+ is 16 bits, so we set the ``RIA_A `` and ``RIA_X `` registers with arg1. I'll
85+ use "A" for the 6502 register and "RIA_A" for the RIA register in this
86+ explanation.
8687
8788We use the XSTACK for arg0. Reading ``RIA_XSTACK `` pops bytes; writing
8889pushes bytes. It's a top-down stack, so push each argument left to
8990right and maintain little-endian byte order.
9091
91- To execute the call, store the operation ID in ``RIA_OP ``. The operation begins
92- immediately. You can keep doing 6502 things, like running a loading animation, by
93- polling ``RIA_BUSY ``. Alternatively, JSR to ``RIA_SPIN `` to block.
92+ To execute the call, store the operation ID in ``RIA_OP ``. The operation
93+ begins immediately. You can keep doing 6502 things, like running a loading
94+ animation, by polling ``RIA_BUSY ``. Alternatively, JSR to ``RIA_SPIN `` to
95+ block.
9496
9597``JSR RIA_SPIN `` can unblock within 3 clock cycles and immediately loads A
9698and X. Sequential operations run fastest with this technique. Under the hood,
@@ -116,13 +118,14 @@ flag N. Once clear, we read ``RIA_A`` and ``RIA_X`` with absolute instructions.
116118 LDA RIA_A
117119 LDX RIA_X
118120
119- All operations returning ``RIA_A `` will also return ``RIA_X `` to assist with C
120- integer promotion. ``RIA_SREG `` is only updated for 32-bit returns. `` RIA_ERRNO ``
121- is only updated if there is an error.
121+ All operations returning ``RIA_A `` will also return ``RIA_X `` to assist with
122+ C integer promotion. ``RIA_SREG `` is only updated for 32-bit returns.
123+ `` RIA_ERRNO `` is only updated if there is an error.
122124
123125Some operations return strings or structures on the stack. You must pull the
124126entire stack before the next call. However, tail call optimizations are
125- possible. For example, you can chain `read_xstack() <READ_XSTACK _>`_ and `write_xstack() <WRITE_XSTACK _>`_ to
127+ possible. For example, you can chain
128+ `read_xstack() <READ_XSTACK >`_ and `write_xstack() <WRITE_XSTACK >`_ to
126129copy a file without using any RAM or XRAM.
127130
128131Short Stacking
@@ -153,23 +156,24 @@ Bulk Data
153156---------
154157
155158Functions that move bulk data come in two flavors, depending on
156- where the data lives. A RAM pointer is meaningless to the RIA because it cannot change 6502
157- RAM. Instead, use the XSTACK or XRAM to move data.
159+ where the data lives. A RAM pointer is meaningless to the RIA because it
160+ cannot change 6502 RAM. Instead, use the XSTACK or XRAM to move data.
158161
159162Bulk XSTACK Operations
160163~~~~~~~~~~~~~~~~~~~~~~
161164
162165These only work if the size is 512 bytes or less. Bulk data is passed on the
163166XSTACK, which is 512 bytes. A pointer appears in the C prototype to indicate
164- the type and direction (to or from the OS) of this data. Let's look at some examples.
167+ the type and direction (to or from the OS) of this data. Let's look at some
168+ examples.
165169
166170.. code-block :: C
167171
168172 int open(const char *path, int oflag);
169173
170174 Send ``oflag `` in ``RIA_A ``. ``RIA_X `` doesn't need to be set according to the
171- `OPEN `_ docs. Send the path on XSTACK by pushing the string starting with the last
172- character. You may omit pushing the terminating zero, but strings are
175+ `OPEN `_ docs. Send the path on XSTACK by pushing the string starting with
176+ the last character. You may omit pushing the terminating zero, but strings are
173177limited to a length of 255. Calling this from the C SDK will "just work"
174178because there's an implementation that pushes the string for you.
175179
@@ -178,18 +182,18 @@ because there's an implementation that pushes the string for you.
178182 int read_xstack(void *buf, unsigned count, int fildes)
179183
180184 Send ``count `` as a short stack and ``fildes `` in ``RIA_A ``. ``RIA_X `` doesn't
181- need to be set according to the `READ_XSTACK `_ docs. The returned value in AX indicates how
182- many values must be pulled from the stack. If you call this from the C SDK
183- then it will copy XSTACK to buf[] for you.
185+ need to be set according to the `READ_XSTACK `_ docs. The returned value in
186+ AX indicates how many values must be pulled from the stack. If you call this
187+ from the C SDK then it will copy XSTACK to buf[] for you.
184188
185189.. code-block :: C
186190
187191 int write_xstack(const void *buf, unsigned count, int fildes)
188192
189193 Send ``fildes `` in ``RIA_A ``. ``RIA_X `` doesn't need to be set according to the
190- `WRITE_XSTACK `_ docs. Push the buf data to XSTACK. Do not send ``count ``, the OS knows this
191- from its internal stack pointer. If you call this from the C SDK then it
192- will copy count bytes of buf[] to XSTACK for you.
194+ `WRITE_XSTACK `_ docs. Push the buf data to XSTACK. Do not send ``count ``,
195+ the OS knows this from its internal stack pointer. If you call this from the
196+ C SDK then it will copy count bytes of buf[] to XSTACK for you.
193197
194198Note that read() and write() are part of the C SDK, not an OS operation. C
195199requires these to support a count larger than the XSTACK can return so the
@@ -198,26 +202,26 @@ implementation makes multiple OS calls as necessary.
198202Bulk XRAM Operations
199203~~~~~~~~~~~~~~~~~~~~
200204
201- These load and save XRAM directly via `READ_XRAM `_ and `WRITE_XRAM `_. You can load game assets without
202- going through 6502 RAM or capture a screenshot with ease .
205+ These load and save XRAM directly via `READ_XRAM `_ and `WRITE_XRAM `_. You can
206+ directly load assets without going through 6502 RAM .
203207
204208.. code-block :: C
205209
206210 int read_xram(xram_addr buf, unsigned count, int fildes)
207211 int write_xram(xram_addr buf, unsigned count, int fildes)
208212
209- The OS expects ``buf `` and ``count `` on the XSTACK as integers with `` fildes `` in
210- ``RIA_A ``. The OS has direct access to XRAM so internally it will use
211- something like ``&XRAM[buf] ``. You will need to use ``RIA_RW0 `` or `` RIA_RW1 `` to access
212- this memory from the 6502.
213+ The OS expects ``buf `` and ``count `` on the XSTACK as integers with
214+ ``fildes `` in `` RIA_A ``. The OS has direct access to XRAM so internally it
215+ will use something like ``&XRAM[buf] ``. You will need to use ``RIA_RW0 `` or
216+ `` RIA_RW1 `` to access this memory from the 6502.
213217
214218These operations stand out for their high performance and ability to
215219run in the background while the 6502 does other work. Expect close to
216- 64 KB/sec, meaning a game level's worth of assets loads in under a
217- second.
220+ 512 KB/sec, meaning a full 64KB of XRAM can load or save in under 150ms.
218221
219- Bulk XRAM operations are why the Picocomputer 6502 was designed without
220- paged memory.
222+ Bulk XRAM operations are why the Picocomputer 6502 doesn't have paged memory.
223+ It's not necessary when "disk" access has no seek time and can move data as
224+ fast or faster then the CPU.
221225
222226
223227Application Programmer Interface
@@ -243,10 +247,10 @@ The OS is built around FAT filesystems, the de facto standard for
243247unsecured USB storage devices. POSIX filesystems are not fully
244248compatible with FAT but there is a solid intersection of basic IO that is
245249100% compatible. You will see some familiar POSIX functions like ``open() `` and
246- others like ``f_stat() `` which are similar to the POSIX function but tailored to
247- FAT. Should it ever become necessary to have a POSIX ``stat() ``, it can be
248- implemented in the C standard library or in an application by translating
249- ``f_stat() `` data.
250+ others like ``f_stat() `` which are similar to the POSIX function but
251+ tailored to FAT. Should it ever become necessary to have a POSIX ``stat() ``,
252+ it can be implemented in the C standard library or in an application by
253+ translating ``f_stat() `` data.
250254
251255ZXSTACK
252256-------
@@ -299,14 +303,16 @@ ARGV
299303.. c :function :: int _argv (char *argv, int size)
300304
301305
302- The virtual _argv is called by C initialization to provide argc and argv for main().
303- It returns an array of zero terminated string indexes followed by the strings.
306+ The virtual _argv is called by C initialization to provide argc and
307+ argv for main(). It returns an array of zero terminated string indexes
308+ followed by the strings.
304309 e.g. ["ABC", "DEF"] is 06 00 0A 00 00 00 41 42 43 00 44 45 46 00
305310 The returned data is guaranteed to be valid.
306311
307- Because this can use up to 512 bytes of RAM you must opt-in by providing storage
308- for the argv data. You may use static memory, or dynamically allocated memory which
309- can be freed after use. You may also reject an oversized argv by returning NULL.
312+ Because this can use up to 512 bytes of RAM you must opt-in by
313+ providing storage for the argv data. You may use static memory, or
314+ dynamically allocated memory which can be freed after use. You may also
315+ reject an oversized argv by returning NULL.
310316
311317 .. code-block :: c
312318
@@ -332,12 +338,14 @@ EXEC
332338
333339 The data sent by _exec() will be checked for pointer safety and sanity, but
334340 will assume the path points to a loadable ROM file. If EINVAL is returned,
335- the argv buffer is cleared so further attempts to _argv() will return an empty set.
336- If the ROM is invalid, the user will be left on the console with an error message.
341+ the argv buffer is cleared so further attempts to _argv() will return an
342+ empty set. If the ROM is invalid, the user will be left on the console
343+ with an error message.
337344
338345 :Op code: RIA_OP_EXEC 0x09
339346 :C proto: rp6502.h
340- :returns: Does not return on success — the new ROM begins executing. -1 on error.
347+ :returns: Does not return on success — the new ROM begins
348+ executing. -1 on error.
341349 :errno: EINVAL
342350
343351
@@ -430,8 +438,9 @@ TZSET
430438 char dstname[5]; /* Name when daylight true, e.g. CEST */
431439 };
432440
433- The virtual _tzset() is called internally by tzset(). Use `help set tz ` on the
434- console monitor to learn about configuring your time zone.
441+ The virtual _tzset() is called internally by tzset(). Use
442+ `help set tz ` on the console monitor to learn about configuring your
443+ time zone.
435444
436445 :Op code: RIA_OP_TZSET 0x0D
437446 :C proto: time.h
784793 char fname[255 + 1];
785794 } f_stat_t ;
786795
787- Returns file or directory info for requested path.
788- See the `FatFs documentation <https://elm-chan.org/fsw/ff/doc/sfileinfo.html >`__
796+ Returns file or directory info for requested path. See the
797+ `FatFs documentation <https://elm-chan.org/fsw/ff/doc/sfileinfo.html >`__
789798 for details about the data structure.
790799
791800 :Op code: RIA_OP_STAT 0x1F
@@ -825,8 +834,8 @@ READDIR
825834.. c:function:: int f_readdir (f_stat_t* dirent, int dirdes)
826835
827836
828- Returns directory entry info for the current read position of a directory descriptor,
829- then advances the read position.
837+ Returns directory entry info for the current read position of a
838+ directory descriptor, then advances the read position.
830839
831840 :Op code: RIA_OP_READDIR 0x21
832841 :C proto: rp6502.h
@@ -1162,8 +1171,8 @@ ROM Cartridge Menu
11621171
11631172The most straightforward use of the launcher is a menu-driven ROM selector,
11641173analogous to inserting a physical cartridge into a retro console. The launcher
1165- ROM scans the storage device for ``.rp6502`` files, presents a list to the user,
1166- and calls `EXEC`_ with the chosen filename. When that ROM stops — whether
1174+ ROM scans the storage device for ``.rp6502`` files, presents a list to the
1175+ user, and calls `EXEC`_ with the chosen filename. When that ROM stops — whether
11671176normally or due to an error — the process manager automatically re-executes the
11681177launcher, returning the user to the selection menu.
11691178
@@ -1187,9 +1196,9 @@ OS cannot alter the launcher ROM; OS launchers are meant to stay simple and
11871196 trustworthy. This indirection provides important capabilities:
11881197
11891198* **Fault recovery ** — If the OS kernel encounters a fatal error it cannot
1190- handle internally, it calls `EXIT `_ rather than locking up. The process manager
1191- re-executes the launcher, which can choose to relaunch the kernel or take
1192- some other action.
1199+ handle internally, it calls `EXIT `_ rather than locking up. The process
1200+ manager re-executes the launcher, which can choose to relaunch the kernel
1201+ or take some other action.
11931202
11941203* **Self-update ** — An OS can prepare its own ROM update and call `EXIT `_. The
11951204 launcher detects the pending update, applies it, and boots the new OS ROM —
@@ -1224,9 +1233,9 @@ get-only attribute also returns -1 with ``EINVAL``.
12241233 * - | 0x02
12251234 | ``RIA_ATTR_CODE_PAGE``
12261235 - Active OEM code page used by the filesystem, console, and default
1227- :doc: `VGA <vga >` font. Reverts to the system setting when the ROM stops. If the
1228- requested page is unavailable, the system setting is selected;
1229- follow a set with a get to confirm the result.
1236+ :doc: `VGA <vga >` font. Reverts to the system setting when the ROM
1237+ stops. If the requested page is unavailable, the system setting is
1238+ selected; follow a set with a get to confirm the result.
12301239 One of: 437, 720, 737, 771, 775, 850, 852, 855, 857, 860, 861, 862,
12311240 863, 864, 865, 866, 869, 932, 936, 949, 950.
12321241 * - | 0x03
0 commit comments