-s / --serial switches INP and OUT from decimal numbers to characters. The
character is the low 7 bits of the cell, so the 8th bit stays the tape's own:
INP writes bits 0..6 and leaves everything from bit 7 up untouched, which is
where a flag, a length or a counter can live without the I/O trampling it.
Checked by hand: a cell preset to 0x80 that then reads 'A' ends at 0xC1, at 8
and at 11 bits per cell.
* include/rot8/rot8_io.h, src/rot8_io.c: the mode itself, plus
rot8_io_wrote_serial() so the CLI can close the line (a serial OUT writes
no newline, that is the point); stdin is read as characters as well, and
EOF feeds 0 instead of blocking.
* src/rot8_viz.c: the frame shows characters in this mode -- the out/in
boxes list them, the console prints output> 'R' 82, unprintables become
\x0A so a frame stays one line of ASCII, and the live prompt takes the
first character typed instead of parsing a number.
* tests/vm_test.c: -s/--serial, a cell_size < 8 check (a 7 bit character
plus a flag does not fit in fewer bits), --input becomes the text itself
(one INP per character, which is why the arguments are now collected and
pushed after the whole command line is known), and one trailing newline
at the end because serial OUT has none.
* tapes/serial_echo.rot8: ,.,.,. -- read three characters, echo them.
* README: what the mode does, the bit 7 rule, and three ways to run it.
Decimal mode is unchanged: --input 7,5 still prints 7 and the existing demos
still print their numbers.
43 lines
1.6 KiB
C
43 lines
1.6 KiB
C
#ifndef ROT8_IO_H
|
|
#define ROT8_IO_H
|
|
|
|
#include "rot8/rot8.h"
|
|
|
|
void rot8_out_io(rot8_iter *it);
|
|
void rot8_inp_io(rot8_iter *it);
|
|
|
|
/* When muted, OUT puts nothing on stdout: a visualizer is drawing there. */
|
|
void rot8_io_set_quiet(bool quiet);
|
|
bool rot8_io_quiet(void);
|
|
|
|
/* Serial ASCII mode. With it on (and at least 8 bits per cell) OUT writes the
|
|
* low ROT8_SERIAL_BITS bits of the cell as one character, and INP reads one
|
|
* character into those same bits, leaving bit 7 and everything above it
|
|
* untouched -- so a tape can keep a flag, a length or a counter up there
|
|
* without the I/O noticing. Below 8 bits per cell there is no room for a
|
|
* character: leave the mode off. */
|
|
#define ROT8_SERIAL_BITS 7
|
|
#define ROT8_SERIAL_MASK ((rot8_data)0x7F)
|
|
|
|
void rot8_io_set_serial(bool serial);
|
|
bool rot8_io_serial(void);
|
|
/* True once OUT has actually written a character in serial mode; the CLI uses
|
|
* it to close the line it just put out. */
|
|
bool rot8_io_wrote_serial(void);
|
|
|
|
/* INP takes its value from the queue pushed here first, then from the hook,
|
|
* then from stdin. The queue is for scripts and tests (--input 1 2 3); the
|
|
* hook is for the live view, which has to stop and ask the person watching. */
|
|
typedef bool (*rot8_input_fn)(rot8_iter *it, void *ctx,
|
|
rot8_data *value);
|
|
|
|
void rot8_io_set_input_hook(rot8_input_fn fn, void *ctx);
|
|
void rot8_io_push_input(rot8_data value);
|
|
size_t rot8_io_pending_input(void);
|
|
|
|
/* Reads the instructions out of a tape into tape[0..size-1]. Returns false
|
|
* when the file cannot be opened; the tape is always NUL terminated. */
|
|
bool read_tape(const char *filename, char *tape, size_t size);
|
|
|
|
#endif
|