fun-a-day, day 4

today i took a diversion and worked on some C code.

in particular i:

 - created a term.c replacement for term.py
 - started extending the Console device in uxnemu

the second task will eventually mean you can run the terminal
from uxn itself. here are the new Console ports:

    ADDR NAME      COMMENT
    0x10 vector    callback used when stdin has data ready
    0x12 stdin     characters from stdin become available here
    0x13 exec      (new) address of string describing program (see below)
    0x15 mode      (new) start execution with given mode (see below)
    0x16 dead      (new) whether program is running (0), dead (1), or failed to start (255)
    0x17 exit      (new) program's exit code (0 is ok, 1-255 is an error)
    0x18 stdout    write characters to stdout here
    0x19 stderr    write characters to stderr here

the idea is that exec will contain the program and arguments to run.
each argument is terminated by a null character (\0) and the list
of arguments requires an extra null character as well:

    "bash 00 "-i 00 "-l 00 00

the mode will be a series of bit flags determining how to execute
the given program. it is not fully specified but will likely have
at least the following:

    0x01    write to child stdin
    0x02    read from child stdout
    0x04    read from child stderr
    ....
    0x80    allocate a pty (implies 0x07)

when any data is written to the dead port (0x16) that will cause the
subprocess to be killed if it has not already exited. the emulator's file
descriptors will be cleaned up once one of the following happens:

    * child process has been killed (e.g. #01 #16 DEO)
    * after child process exists, read from port 0x6 or 0x7
         (e.g. #16 DEI or #17 DEI)

some details that aren't totally clear to me yet:

 * how to set environment variables? (e.g. TERM)
 * how to set terminal attributes? (e.g. termios)
 * support reading pipes directly rather than overloading stdin/stdout?
 * alternate vector for pipe data?
 * more detailed support for signals and signal masks?
 * expose PIDs to uxn?
 * is any of this applicable to windows?

as you can see there's still a lot to do. but i think in the next
day or so i'll have a patch ready for uxnemu

back to funaday 2023 home