38 Commits
Author SHA1 Message Date
starcells d545899107 Console rows erase to end of line
The log lines are not padded, so when a row got shorter than it had been in the
previous frame (the '  ..' trim marker is three characters, a value line is
more) the tail of the old row survived and read as one garbled line, e.g.
'.. t> 123'.

Each console row now ends with an erase-to-end-of-line when the view owns the
terminal, and the frames stop leaving debris behind.

Checked with ',.,.,.' fed 1 2 3 4: the trim marker shows as a clean '  ..' above
the last six events, and no row carries text from the frame before it.
2026-11-06 21:05:10 +08:00
starcells 90fe5ec84a Console is an event log: one line per INP and per OUT
requested change: keep the in (n) / out (n) inside the frame as single line
summaries, but log every event outside the frame so the interleaving of inputs
and outputs is readable:

    | in (2) 123 65   |
    | out (2) 123 65  |
    input> 123
    output> 123
    input> 65
    output> 65

The log keeps the last 6 events (older ones show as '..') so a long run does not
grow the console without bound; the prompt is still a separate empty 'input> '
line at the very bottom, which keeps the cursor the last thing on screen.

Tapes that only produce output now get the output> log too, which is what
replaces the replay that used to be printed after the run.
2026-11-06 21:00:11 +08:00
starcells 5783769db3 Console: records in order, prompt last, no duplicate replay
Three fixes from looking at a real run:

  * input> showed only the last value.  Both console lines now record every
    value (with the same '..' trim as the out box), so a run that read 123 then
    65 shows input> 123 65.
  * output> was printed above input> even though the output happened later.
    The order is now chronological: input record first, output record second,
    and the prompt is a separate empty 'input> ' line under both, so the cursor
    is always the very last thing and nothing can appear above it afterwards.
  * with the console showing output>, replaying every OUT value after the run
    was just noise: replay_output is off now (live still mutes OUT while the
    frame is being drawn, so the values only appear in the console).

Checked with tapes/echo2.rot8 (',.,.'), fed 123 then 65 through a pipe: while
waiting for the second value the console reads 'output> 123' then an empty
'input> ', and at the end 'input> 123 65' / 'output> 123 65' with nothing
printed after.  --input and --dump paths unchanged.
2026-11-06 20:52:25 +08:00
starcells 5a25c328d0 Console below the frame: prompt and output echo, records inside
Two things were wrong with the first attempt:

  * a tape that starts with INP never drew its opening frame, because the
    prompt ran before the hook and there was no iterator to render with.  The
    input callback now receives the iterator, so it can paint the frame and
    then ask -- the initial memory state is visible again.
  * putting the prompt inside the frame left the cursor at the end of the
    frame, which reads badly.  The records stay inside:

        | in (1) 13   |
        | out (1) 13  |

    and the prompt moved below the window, like a shell prompt under it:

        output> 13
        input> 13

    output> grows with every OUT; input> is the prompt while INP waits and
    becomes the value just given afterwards.  The cursor sits right after
    'input> ', outside the frame, so typing does not fight the drawing.

Tapes that never read input get none of the lines outside the frame, and the
existing tapes look exactly as before.

Checked: echo.rot8 first frame now shows step 0 / pc 0000 / op INP with the
memory grid, then input> below; --input 42 still prints 42; --dump and the
piped live run are unchanged.
2026-11-06 20:47:25 +08:00
starcells 2aa3f83ea4 Put the input prompt inside the frame, above the out box
Printing 'input> ' where the cursor happened to be made a mess of the frame, so
the prompt is now part of it:

    | in (1) 13                                              |
    | out (1) 13                                             |

While INP waits the line reads 'input> ' and the cursor is left at its end, so
the number is typed in place; afterwards the line turns into the record of what
was fed in, mirroring the out box.  A tape that never reads input gets no extra
line at all, so nothing changes for the existing tapes.

The frame also got a redraw helper, because the prompt has to repaint the frame
before asking; the live hook now goes through the same helper.

One case cannot use the frame: a tape like tapes/echo.rot8 (just ',.') reaches
INP before the first frame is drawn, so there is nothing to hang the prompt
above and it falls back to a plain 'input> ' on the current line.  Longer tapes
show it inside the frame.

Checked: --full frame shows in above out, compact frame shows the in line too,
wave/and/or/full_adder are unchanged, and the value still reaches the program.
2026-11-06 20:41:29 +08:00
starcells 6475938e6c Add a place to give the machine its input
INP read straight from stdin with scanf, which the live view cannot offer: the
view owns the terminal, and a tape that wants input either ate a number nobody
typed or blocked on a pipe.

INP now takes its value from, in order:

  1. a queue filled by --input "7,5" (spaces or commas, scripts and tests)
  2. a hook the live view installs: it prints 'input> ' under the frame and
     reads a line, redraws on the next tick, and feeds 0 when stdin is done so
     a tape behind a pipe still finishes
  3. stdin, exactly as before

So nothing changes for a plain run, and --live can drive programs that need
input.  tapes/echo.rot8 (just ',.') is the smallest tape that exercises it.

    rot8_test --input 42 tapes/echo.rot8        -> 42
    rot8_test --live tapes/echo.rot8            -> asks under the view

Tests: --input with one value, with a list, a live run fed through a pipe
(prints 5), and a live run with stdin already closed (feeds 0, terminates).
The --dump path and the untouched tapes (and, or, full_adder, wave) still work.
2026-11-06 20:35:30 +08:00
starcells bda173b078 Make the live view work behind a pipe, and fit small terminals
A terminal can be a pipe: web terminals and IDE panels hand the program a
pipe for stdout, so isatty() says no, --live quietly fell back to printing
one frame after another and -f was ignored.  Add -t to say "there is a
terminal at the other end anyway" (and --no-tty for the opposite), and say
so on stderr when the fallback happens, so the flag can be found.

Frames no longer end with a newline, so a frame of N lines needs N rows
instead of N+1 and a 24 row terminal shows the whole compact frame.  The
size heuristics follow from that: shorter than 30 rows -> compact, size
unknown (behind a pipe) -> compact, LINES is honoured when the console
cannot be asked, and --full forces the tall frame.

Colour is now only switched off for a real console that cannot do VT, not
for every stream that is not a console: behind a pipe the far end may be
perfectly capable.
2026-11-05 21:48:58 +08:00
starcells b654bd644d Add a live memory view for the tape
The machine can now hand a hook the whole execution, and rot8_viz draws
what it sees: the 256 cell tape as a hex map, the cell under the pointer
with its eight bits, the program counter and the values OUT produced.

    rot8_test --live tapes/wave.rot8     # redraw in place while it runs
    rot8_test --dump tapes/and.rot8      # one static snapshot at the end

Frames are plain ASCII, so the view survives pipes, ssh and logs; colour
is ANSI and only used when the terminal can take it.  Running without
--live or --dump behaves exactly as before: the tape just runs.

rot8.h gains rot8_run_hooked() plus read-only accessors for the tape,
the program counter and the step count, so that tools do not have to
reach into rot8_iter.  read_tape() now reports a missing file and stops
at the end of the buffer instead of writing past it.  Also fixes the
ROR/FLB opcode comments, which had the BF characters the wrong way round.

tapes/wave.rot8 is a small demo: it walks a single set bit across 240
cells, which looks like a wave moving over the tape.
2026-11-05 21:25:42 +08:00
starcells c916215dab 202606281714 2026-06-27 19:14:33 +08:00
starcells 5a8cadcd9a 202606281508 2026-06-28 03:08:40 +08:00
starcells 5674ff2e4a Adjusted build part in README 2026-06-20 01:36:59 +08:00
starcells e91b01c7d4 Fixed wrong type of var get in function rot8_io.c/read_type 2026-06-19 22:25:58 +08:00
starcells 853a6c50d9 [fix]202606142131 2026-06-14 21:31:25 +08:00
starcells 363b91615d Told cell and unit apart,completed README.md 2026-06-14 21:27:42 +08:00
starcells 22fd42dcfe Full Adder!!! 2026-06-12 21:08:08 +08:00
starcells f29a644419 Safe OR. 2026-06-12 08:28:47 +08:00
starcells 9fd51c919f Safe AND 2026-06-10 20:59:01 +08:00
starcells 004f13b795 [fix]202605160034 2026-05-16 00:35:11 +08:00
starcells 7a81913ed6 [err]202505140007 2026-05-14 00:07:16 +08:00
starcells b211ce0180 Fixed read_tape. 2026-05-04 16:05:51 +08:00
starcells c6cce2a9a5 Input completed. 2026-05-04 16:00:49 +08:00
starcells d7de27a54b [err]202605041103 2026-05-04 11:03:59 +08:00
starcells 8e5bb3855f Renamed UNIT_SIZE. 2026-04-18 23:01:01 +08:00
starcells d4b16d3030 Standarized variable types. 2026-04-18 22:56:24 +08:00
starcells 954ed0828d 202604082015 2026-04-18 20:15:58 +08:00
starcells dc701fdd70 Standarized name of BIZ and RNZ/ 2026-04-11 00:15:02 +08:00
starcells fd48b9b927 Fixed test. 2026-04-10 01:48:51 +08:00
starcells cfa296ee8f Restored test. 2026-04-09 22:16:48 +08:00
starcells c16c4d3e53 Changed RET to RIZ. 2026-04-09 18:01:27 +08:00
starcells 045eb4332c Added clang-format file. 2026-04-07 17:57:54 +08:00
starcells 68bfe71cd6 Formatted all files,adjusted cmakelists *2 2026-03-27 23:52:48 +08:00
starcells b2c7e9800e Formatted all files,adjusted cmakelists 2026-03-27 23:52:26 +08:00
starcells 1ed9ee7771 Cleaned gitignore *2 2026-03-27 23:35:14 +08:00
starcells 2b54042edb Cleaned gitignore. 2026-03-27 23:34:29 +08:00
starcells 123c8cd298 Fixed loop. 2026-03-27 17:55:25 +08:00
starcells 0e2bf983f7 First workable version 2026-03-17 00:42:42 +08:00
starcells c4759c824a Adjusted structure.TODO:bnz_check 2026-03-13 01:29:55 +08:00
starcells 5913329846 first commit 2026-03-10 00:49:55 +08:00