5 Commits
Author SHA1 Message Date
dsh 7170ad4813 mechanics: what the mechanical address register costs, tape by tape
Answering "is it acceptable for shorter tapes": with the mechanical register the
cost is one physical step per pointer move, in either direction -- no direction
penalty like the drum, but every move pays.  Measured move counts at 8 bits
(tape_run --profile), and the times for a 3 ms direct drive stepper (200 steps per
rev, 3.1 steps per cell) and a 20 ms telephone uniselector:

  full_add            95 instructions      11 moves    0.03 s / 0.2 s
  hello              577                 139          0.4 s  / 2.8 s
  term             16414               13077         39 s    / 4.4 min
  asm/test.r8asm   43676               71885          3.6 min / 24 min
  signed_demo      37511              122178          6 min   / 41 min
  calc             51378              130589          6.5 min / 44 min

So short tapes are fine, comfortably: hello finishes inside a second even on the
slowest mechanism, and the practical line is about 20000 moves, which is roughly
20000 instructions, for "under a minute".  term sits right at the edge at 39 s.
The three big tapes need the two speed design: mechanical position authoritative
in single step and demo mode, a clutch that disengages it in run mode so an
electronic counter drives the 6116.  Same clutch idea as the step counter.
2026-11-20 17:20:15 +08:00
dsh 9590cfd35b mechanics: a VCR drum works as a spindle, and the numbers say only the delay
line is fast enough to be a daily machine

Size first, since that is the constraint.  A VHS head drum is 62 mm across and
spins at 1500 rpm with its own direct drive motor and a very good bearing, so it
is usable -- but as a spindle, not as a medium: its own heads are for tape, and
the video tape transport is exactly the complexity we do not want.  Strip the
heads, glue an annulus of floppy media onto the upper drum, and put two fixed
heads (cassette or stripe heads) at the rim: at 62 mm one cell is 3.0 mm of
circumference, so the heads can be crude and the read-modify-write pair sits 3 mm
apart with no machining.  A dead 2.5 inch hard disk spindle is cheaper and spins
five times faster, with a floppy head (100 um track) parked open loop over a disc
of floppy media.

What that costs in practice is now measured rather than guessed.  The 8 bit
calculator session is 166348 steps: 65311 forward pointer moves and 65278
backward ones.  On a 25 rev/s drum a forward move waits one cell (625 us) but a
backward move waits 64-k cells, about 38 ms for the usual k, so a session is 41
minutes and the flagship tape 23 minutes.  hello is 0.3 seconds.  A
magnetostrictive delay line has a full revolution of 0.5 ms instead of 40 ms: the
same session is 32 s and the flagship 18 s, because its backward move waits at
most one revolution.  So the drum is an exhibit machine, and the delay line is the
only mechanical memory that can be used interactively -- both because of the same
property, how long one lap takes.

Also recorded: what the drum needs besides the mechanism -- an index pulse, a 64x
clock resynchronised to it every revolution, a plain FM channel (one clock
transition per cell plus a data transition for a 1) read with a windowed latch,
and the second head for read-modify-write.
2026-11-20 16:54:32 +08:00
dsh a5dfd70499 docs: what a mechanical dp can actually mean when the memory is electronic
The question that exposes the gap in the previous note: if the ring lives in a
6116, what is a mechanical pointer pointing at?  The honest answer is that dp is
an address, so there are three coherent designs and they are different machines.

A. a mechanical address register.  The physical position of a 64 position device
(uniselector, or stepper plus ratchet) feeds A0..A5 of the SRAM through its
contact bank.  The position is genuinely part of the machine state and the panel
pointer does not lie, but it only selects which byte is addressed -- it is not
the byte.  Cheap (50-200 CNY) and two days of work, so it stays N1.

B. a drum.  Eight tracks by 64 cells rotating under fixed read and write heads:
then the memory itself is mechanical, dp becomes the phase of the rotation, >
waits for the next cell pulse, < waits almost a full turn, and + or - does a
read-modify-write between two heads one cell apart.  Expensive and months of
machining, but it is the 1950s machine.

C. a magnetostrictive delay line.  512 bits of sound circulating in a loop of
nickel wire with a transducer at each end: the ring is literally a loop, there
are no bearings and no heads to wear, > is free (wait for the next time slot), <
costs at most one revolution (0.5 ms at 1 Mbit/s).  An order of magnitude cheaper
than the drum and still electrically genuine, but it needs winding, biasing and
scope time.

Recommendation stays: A first because it is cheap and it is honest about being an
address register, then C if the wish is for the memory itself to be mechanical,
with B kept for when there must be a spinning drum.  The section now says all of
this, and the summary table no longer claims dp can simply "be mechanical".
2026-11-20 16:43:57 +08:00
dsh 1e7acc018e hardware: the 74LS machine gets a period bill of materials, and a mechanics plan
Two things: the TTL build is now the main target (Tang Nano looks too modern), and
the packer learned the format that makes the TTL build simple.

Format: r8forge_tape_pack --eprom writes one byte per instruction with the opcode
in the low three bits.  Then ip is the EPROM address and D2..D0 are the opcode --
no shift register, no 16 bit window, no decoder.  It wastes five bits per
instruction, and a 27C512 is exactly 64K, which is the historical instruction
budget: the 8 bit calculator (51378) and the flagship (43676) both fit.  Both
formats live in the same .r8t trailer now (format byte 1 = packed, 2 = one byte
per instruction), decode dispatches on it, and the test runs both and requires
the same output and step count.

Carrier: 74LS DIPs on a green board, 27C512 in a socket with its quartz window,
6116 SRAM, 74LS299 for the rotate, 6850 ACIA for serial, 74LS47 and four seven
segment displays on the panel, 1 MHz can oscillator.  About 31 to 40 chips, 400
to 700 CNY, a few weeks.  The FPGA stays as a bench-only stepping stone.

hardware/mechanics.md: where mechanics actually pays.  The program must stay
electronic (130 metres of paper tape for the calculator), and 512 relays for the
data ring are out, but the pointer is worth it -- > and < are 71 to 73 percent of
all steps, so a 64 position ratchet or uniselector makes the machine physically
walk the ring.  Also listed: an electromagnetic step counter (10 to 20 Hz, so
only in single step mode, with a clutch for free running), a paper tape punch or
plotter for output, a tape/card reader or plain keypad for input, and a hand crank
as the clock.  The rule that keeps this safe: mechanics only ever sit on sensor
and actuator pins and never in the logic path, and the handshake just stops the
sequencer while something moves -- since nothing in the ISA can observe time,
slower is not different.  A relay-only machine is priced honestly too: 60 to 120
relays, 10 to 50 Hz, hello in 10 to 40 seconds, the calculator in four hours, so
that one is an exhibit.

Also fixed: the synthesised macro fallback file name now carries a per-run token.
When the system temp directory is not writable every r8asm falls back to the same
working directory, so parallel ctest runs could write and import the same file --
which showed up as a random one-test failure in 0.39 seconds and nothing else.
2026-11-20 16:35:02 +08:00
dsh 9b31a51fec hardware: M0 -- the packer, the RTL, and a simulator that agrees byte for byte
The two things software cannot check by reading its own source are the 3 bit
packing and the bracket strategy, so both got a tool and a test.

New in the library (r8forge/tape.hh, src/tape.cc): the opcode numbering (taken
from ROT-8-viz enum, so the packed image and the hardware decoder cannot drift),
text <-> opcodes, opcodes <-> 3 bit bytes, the .r8t image with its trailer and
crc32, and a machine model that runs a packed tape the way a board would.  The
model takes the bracket strategy as an option: backward scan with loop stack or
not, and jump-back-onto-the-[ (the contract) or past it (what the interpreters
do).  All four combinations print the same thing, and the step count differs by
exactly the number of taken ] instructions -- which is what the test asserts.

Found and fixed while writing it: the loop stack discipline depends on the jump
convention.  Jumping onto the [ means the [ re-pushes, so ] must pop on the jump;
jumping past it means the entry must stay until the loop exits.  Mixing them up
emptied the stack on the second iteration of the calculator main loop -- caught
by the equivalence test on examples/calc.r8asm, not by reading the code.

Tools: r8forge_tape_pack (text tape -> image + --hex for $readmemh + --verify,
727 instructions become 273 bytes for hello, 62%, and the trailer sits past the
halt so address 0 of a ROM is instruction 0), and r8forge_tape_run now reads an
image directly and takes --loop-stack / --retest.

hardware/rot8.v: the 8 bit / 64 cell machine -- 3 bit opcodes from a byte
addressed memory read as a 16 bit window, a 6 bit dp with free wrap, the loop
stack bracket jump, blocking input, halt on ip == length, and a step counter that
counts instructions rather than cycles.  hardware/tb_rot8.v loads a --hex image
and prints the OUT stream in tape_run format.

Verified with Icarus Verilog 14 (the RTL against tape_run --loop-stack --retest):
  hello        577 instructions  417 steps  10 outs
  term         16414            17643      11 (fed "lhi")
  calc         51378           166741      19 (fed "12 34 + .": prints the prompt,
                                                046 and the next prompt)
  flagship     43676           100142      93
Every OUT stream identical.  ctest -R rtl_sim runs that comparison from an 8 bit
build (11 tests in the default build now, where the RTL test self-skips because
the RTL is the 8 bit machine).

Two traps worth remembering: Icarus passes plusargs through as raw bytes, so an
absolute +HEX path containing non-ASCII (this checkout is under a Chinese
directory name) arrives mangled, $readmemh silently leaves the memory empty and
the machine obediently runs LEN steps of opcode 0 printing nothing -- run vvp
from the directory holding the hex with a relative name.  And in_ready must not
be qualified with !in_valid or the input handshake deadlocks.
2026-11-20 16:25:54 +08:00