Clarifying what the INSTRUCTION row means: it is the opcode at the program counter, so
while running it is the instruction executing and while stopped it is the next one to
execute -- which is what you want when single stepping. On halt the lamps are gated
off, because past the end the ROM reads zeros and opcode 0 is a move, which would
show a lie.
That choice also keeps the panel rule intact: ip is state, and the last executed
instruction would be history, the same category as the step counter that was removed.
A last instruction display would need a 74LS273 latch and an end of instruction strobe,
and would lag by one during RUN, mixing state and history on one panel. Recorded in
panel.md together with the halt detail.
The round cell display was right: eight neons on a circle, bit 0 at nine o'clock
marked with the wedge, the rest numbered 1 to 7, and it sits as the one instrument on
the left of an otherwise row based panel. The three rows move right and narrow to
7.4 mm pitch, the toggle bank follows them, the function switches stay along the
bottom edge, and the cartridge slot and the DE-9 move to the far right so nothing
overlaps.
Blue-grey plate with white legends, and the 8800 arrangement: indicator rows stacked
at the upper left (data pointer, cell, instruction), the toggle bank below them with
numbered positions, and the function switches pressed into the bottom edge. The
toggles are the chrome bat type the 8800 made famous, not the slide switches that were
there before. The cartridge slot and the DE-9 keep the right hand side, where the 8800
puts its own I/O.
The cell row now runs bit 7 to bit 0 left to right with the wedge and its LSB mark at
the right hand end, which is how the 8800 labels its rows: every lamp numbered, in a
line.
Colour is a taste question, so panel.md says explicitly that the blue is a reference to
the 8800 and swapping it back to the beige and orange costs nothing but paint.
It is the UART. The 6850 turns parallel bytes into asynchronous frames and back, and
in this machine it is exactly the physical end of two instructions: comma waits for
RDRF and reads the data register into the current cell, dot waits for TDRE and writes
the current cell out. Without it there is nowhere for input and output to land, so the
calculator cannot talk to a terminal and hello prints nothing.
Wiring notes now recorded: two registers selected by RS, the usual read/write and chip
select lines, RxD and TxD through a MAX232 to the DE-9, and a separate 2.4576 MHz
crystal divided by sixteen to get the 153.6 kHz baud clock -- 1 MHz cannot be divided
into it. At 9600 a byte takes 1.04 ms, so comma and dot block, and the panel lamps
pausing for a millisecond is normal.
Alternatives priced in effort: another makers 6850 or a 65C50 is a straight swap, an
i8251 needs different microcode, a 16550 is cheap but PC flavoured, plain TTL shift
registers are the most period correct and the most painful, and no serial at all leaves
a pure trainer that cannot run the calculator.
The stale panel section went too: the four digit displays, the ip and dp LED rows and
the three button set were still described there.
hardware/bom.md prices the whole machine: 34 logic chips and the peripherals come to
about 420 CNY, the plate, case, PCB and cartridge boards about 190, so a standard build
is roughly 650 CNY. A cheap build (flash instead of UV EPROM, NE-2 lamps, acrylic open
frame, single board) is about 400, and a deluxe one (10 mm neons, illuminated buttons,
silkscreened aluminium, eraser, spare cartridges) about 950.
Not in the table: the programmer (CH341A about 20, or a TL866 for 200), the UV eraser
(40, and only if the EPROM is a real 27C512), and the usual bench tools. Shipping and
the PCB lead time add a little.
The honest number is the hours: 8 to 12 for schematic and layout, 10 to 15 on a
breadboard, 15 to 20 to solder and debug, 5 to 8 for the plate -- call it 40 to 60 hours,
which is a month and a half of weekends. Money is not the constraint here.
Noted for later: the 6850 ACIA at 20 CNY a chip and getting scarce is the one part with
a real supply risk, and replacing it with a 16550 plus glue or an MCU bridge would cost
a lot of the period charm.
The dial was overlapping the CELL group rule: it is smaller and lower now, with the
buttons under it, and the rule runs clear above the top lamp.
The real question was cost of going all neon. The panel has 22 lamps -- eight on the
cell dial, eight instruction lamps, six on the dp row -- so it is about 65 CNY with
NE-2 and about 150 with 10 mm NH-4 lamps and illuminated buttons, against roughly 35
for 6 V filament bulbs. The money is not the issue; the high voltage is.
Notes recorded in panel.md: 65 to 90 V strike, 0.3 to 1 mA hold, so all 22 lit draw
two watts; ULN2803 is only rated for 50 V, so the drivers have to be MPSA42; and DC
electroplates the cathode until one side blackens, which is why old equipment lit
neons from AC -- either the rail or a reverse diode across each lamp. NE-2 glow dots
are 2 mm, which is small on a 200 mm panel, so the bigger domestic neons are the ones
that actually look impressive.
The matrix could not answer the one question a pointer display has to answer: where
am I now. A lamp cannot change colour and a matrix cannot light one cell on its own,
so the matrix was showing a field of bits with no indication of which one the machine
was standing on. Eleven square centimetres and 64 bulbs for that is a bad trade, so
it is gone.
What remains answers three questions and nothing else: the pointed cell byte on the
eight lamp dial, the current instruction on the eight instruction lamps, and the
pointer on six red neons fed straight from the dp counter. The buttons are now on
the plate too: STEP, START, HALT, RESET, with STEP resolved as staying -- single step
is the point of a trainer.
panel.md follows: the display table loses the matrix row, the button question is
closed, and section 3.1 explains why a matrix was the wrong device rather than the
pointer being hard to show.
The crosshair was a compromise: sixteen lamps to say where one pointer is. Six
red neons on the dp counter outputs say it exactly, need no decoder (open collector
buffers are enough for neon at two milliamps), and leave the matrix to do its own
job -- showing the LSB of every cell and nothing else.
It also fits the display rule better than it looks: six bits are the machine own
representation of its pointer, not a decimal readout, so results and step counts
still come only out of the serial port. panel.md records the decision with the two
alternatives that lost: the sixteen lamp crosshair and a red neon ring in every cell.
Mockup: the row sits under the matrix, bit 5 on the left, index digits beneath.
It is showing 33, which is bit 5 and bit 0 lit.
The question was what kind of lamp can turn from yellow to red, and the honest
answer is none, and it would not help anyway: in a lamp matrix a single cell cannot
be driven on its own. The matrix lights cells by row and column, so changing either
line lights eight cells, and giving every cell its own override would mean 64 extra
gates or 64 separate lines.
So the cursor is a separate indicator. Eight red neons down the left of the matrix
and eight across the top form a crosshair, and the lit pair crosses at the data
pointer. dp is six bits, which splits exactly into dp[5:3] for the row and dp[2:0]
for the column: sixteen lamps, zero decode logic.
The alternative is a red neon ring in every cell, driven as a second 8 by 8 matrix
that shares the sixteen drive lines and is selected in time, so the red dot lands on
the cell itself. That is 64 more neons and twice the panel density; the crosshair is
recommended for now. panel.md records both, with the reasoning.
hardware/panel.md is the orderable version of the mockup: mechanical sizes (200 x 100
mm plate in a 220 x 130 x 70 mm case), the grid, the section list, the connector
types (2 x 22 card edge slot, DE-9), the electrical budget (ULN2803 arrays, an 8 row
by 8 column lamp matrix, a 555 for the cursor blink), and the rule the panel has been
converging on -- every piece of information has exactly one representation, and all
numbers go out of the serial port.
One item left open on purpose: whether the button row keeps STEP. GPT render shows
START / HALT / RESET, but single step is the whole point of a trainer, so it should
either stay as a fourth button or START should distinguish tap from hold. That has
to be settled before the plate is drilled.
Light hammertone paint, orange hairline rules under small section legends, dark
lamps with amber lit ones, a red SEND button, and real hardware drawn on the plate:
a card edge slot with fingers and two screws for the 27C512 program cartridge, and a
DE-9 for the 6850 serial line. The cell dial keeps the LSB wedge at nine oclock and
labels the other seven lamps 1 to 7, which is better than labelling all eight:
the wedge already says which one is 0.
Also recorded in docs/hardware.md: the cartridge is a card edge one (a small PCB with
the EPROM, fingers into a 2x22 edge connector), with a bare ZIF-28 socket as the cheap
version. Neither needs a cable, because strict Harvard means there is no way to feed
a program in at run time -- swapping the chip is the delivery mechanism.
The wedge now sits at nine oclock, pointing right at the bit 0 lamp, and the bits
run clockwise from there, so bit 7 lands at half past ten. That puts the LSB mark
in the open space left of the dial instead of crowded under the CELL label.
The layout is no longer placed element by element. There is one module grid: three
columns of 56 mm at x 12, 72 and 132 with 4 mm gutters, two rows starting at y 25
and y 67, one rule at y 21.5, and the serial line spanning columns two and three in
the lower row. Every block is in a cell, so nothing can drift: a new element has to
occupy a cell or it does not go on the panel.
A row of six neon bars showing dp is a second, numeric way to say what the matrix
cursor already says in the place it belongs, so it goes. The comment left behind
says why, in the same terms as the missing step counter and the missing digits.
Panel now: the cell dial in column one, the instruction lamps and the input byte
and the serial line in column two, the 8 x 8 lamp matrix in column three, the
cartridge below the dial. One pointer representation, one byte representation,
one instruction representation, no numbers.
The ISA says nothing about how long memory is -- ">" and "<" are just moves, so
the model is an unbounded line of cells. Our implementations bound it: the build
option sets a ring of N cells (default 259, the machine 64) and the pointers wrap
modulo N. Measured peaks over every tape we ship are 155 cells (flagship), 51
(calculator), 49 (hello), 27 (term), so 64 never wraps in practice and the wrap
costs nothing in hardware: a six bit counter just rolls over.
The panel display follows the model rather than a circle: an 8 by 8 matrix of
lamps, one per cell, showing that cell LSB -- the only bit biz and rnz ever look
at -- with the pointer blinking like a cursor so dp is visible without a number.
The small dial in column one still shows the whole byte of the pointed cell, so
the two displays answer different questions: which cells are set, and what is in
the one the machine is standing on.
Hardware side this is the classic lamp matrix: eight row lines and eight column
lamp drivers, plus one gate that ORs the cursor into the pointed column and row.
Bulbs, not LEDs, but the drive is the same.
The eight bit lamps are no longer a block of two rows: they sit on a circle, the
same visual language as the 64 cell ring, so the panel reads as two dials of
different size. bit 7 is at twelve o'clock and bits run clockwise, which puts
bit 0 -- the LSB, the only bit biz and rnz ever look at -- at half past ten, and
that one gets an engraved wedge pointing at it plus a small 0. On the real panel
the wedge is a notch in the lamp bezel rather than a printed mark.
Lamps of 6.2 mm on a 22.8 mm circle leave three millimetres between neighbours, so
the dial stays legible at arms length. Buttons moved down a little to clear it.
The last panel was laid out element by element and looked it. It is now three
columns and three rows with a single rule under the title: cell bits in column one,
instruction lamps and dp bits in column two, the data ring in column three, then
controls and the input byte, then the cartridge and the serial line. Every block
shares a baseline and the gaps are uniform.
The mechanical dp dial is gone from the panel. It is an add on that either gets
built or does not; nothing in the machine depends on it, so the panel does not
reserve space. mechanics.md now says the same where it discusses the mechanical
address register.
The step count is the machine time, and nothing in the ISA can observe time -- so
the panel does not show it either. A running count is a debugging number, and
debugging numbers come out of the serial port; there is a comment where the
counter used to be saying exactly that.
The panel is now: the 64 cell ring with dp lit, the eight bit lamps of the pointed
cell, the eight instruction lamps, the dp bars, RUN / STEP / RESET, the eight input
switches, the ZIF cartridge and the serial line. The mechanical dp dial moved into
the space the counter left.
Dropping the decimal display is right on three counts and the mockup now reflects
it. The panel has the 64 cell ring with dp lit, the eight bit lamps of the pointed
cell with their bit numbers, the eight instruction lamps with the current one lit,
the dp bit bars, bakelite RUN / STEP / RESET, the eight input switches, the ZIF
cartridge and the serial line showing "> 12 34 + ." then "0046". A mechanical step
counter shows how far a single step run has gone.
Why it is better: numbers are the terminal job, and the "//->digits" machinery is
already in software where it belongs; the panel showing bits and position is the
truer picture of the machine; and it removes four Nixie tubes, four K155ID1 and the
170 V rail -- 150 to 300 CNY and a high voltage supply -- leaving only the 90 V neon
rail and 6 V for the bulbs.
panel_mockup_vintage.py now draws this state only panel, so the drawing and the
hardware stay in step.
Seven segment LEDs read as 1975, so the panel got a second mockup with period
display technology: four Nixie tubes for the digits (K155ID1 / 74141 BCD to
decimal drivers and a 170 V rail), a ring of 64 neon lamps with dp lit, grain of
wheat filament bulbs for the eight instruction lamps, neon bars for the ip and dp
rows, bakelite buttons with chrome bezels, hammertone paint and filled engraving,
and a second hand dial for the optional mechanical dp.
The honest costs: four IN-12 tubes are 100 to 240 CNY, four K155ID1 40 to 80, the
HV supply 20 to 40 more, 64 neon lamps around 60, plus a driver array for them --
a 6 bit to 1 of 64 decode is two 74LS154 and the lamps can be wired as an 8 by 8
matrix so only 16 high voltage transistors are needed, since a half selected
neon sees half the strike voltage and stays dark.
Rails become the 1960s set: 5 V for the TTL, 6 V for the bulbs, 90 V for the neon,
170 V for the tubes -- a transformer with several secondaries, or small modules
per rail. Both mockups are checked in with the scripts that draw them, so the
layout can be edited and regenerated.
hardware/panel-mockup.png (drawn by hardware/panel_mockup.py, no external assets
needed) is a 200 x 100 mm front panel sketch: four seven segment digits showing
the pointed cell, eight instruction lamps with the current one lit, a sixteen lamp
ip row and a six lamp dp row, RUN / STEP / RESET buttons, an eight switch input
byte with a SEND button, the 64 cell ring drawn as a dial with dp lit, the ZIF-28
socket for the 27C512 program cartridge, a UART line showing "> 12 34 + ." and
"0046", and the optional mechanical dp dial. Behind it all sits a 160 x 100 mm
Eurocard with about 34 DIP sockets, a 1 MHz can and a 5 V 2 A supply.
The script is checked in because the drawing is meant to be edited: python
hardware/panel_mockup.py out.png regenerates it.
hardware/ttl-schematic.md turns the verified RTL into a wiring plan: signal names,
the chip list with what each part does, clock/reset/single step, the one byte per
instruction fetch (ip counter straight into a 27C512, D2..D0 into a 74LS138), the
data path (6116 plus a 74LS299 for the rotate, a 74LS86 for the flip), dp from
either two 161s or the mechanical encoder behind a jumper, the loop stack, the
microcode ROM, the 6850 and the panel, plus a bring up order that installs one
block at a time.
Two decisions folded in while writing it:
* the loop stack lives in the unused part of the 6116 instead of a 74LS670 pair.
The stack has to hold 16 bit ip values and a 670 is four bits wide, so the
discrete version is four pairs and eight chips; the 6116 has 1984 free bytes
after the 64 cell ring, so one extra pointer and two accesses per push or pop
buys a 496 deep stack and keeps ip width and stack width independent.
* halt needs LEN: four 74LS688 comparing ip against a 16 bit DIP switch. That
brings the board to about 34 chips, which the note now says.
Mechanical dp plugs into the same board: a 74LS244 puts the encoder on the DP bus
behind a jumper, the step pulses come from DP_UP/DP_DN, and a BUSY contact gates
the clock so the sequencer waits for the mechanism to arrive -- slower, not
different, because nothing in the ISA can observe time.
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.
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.
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".
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.
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.
Restating the constraint correctly: program and data must not share storage. That
is already guaranteed by the instruction set, not by wiring -- none of the eight
instructions can read or write the program memory, ip only moves by one or by a
bracket jump, so there is no self modifying code and no way for data to become
instructions. The two also wrap differently: the tape is linear and halts at the
end, the data is a ring of 64 cells.
Given a strict Harvard split, the program side has two ordinary implementations:
* in place ROM: ip is the address of a parallel EEPROM or flash (28C256, 29C010,
39SF010), fifteen to seventeen address lines and eight data lines, no glue
logic; the chip in a wide socket is the cartridge and there is no boot step;
* on board program RAM plus a one shot load: a separate RAM or block RAM is
filled at reset from any small source (serial flash, microSD, UART, even a
24C512) and then executed in place. Swapping tapes no longer means burning a
chip; the price is a boot state machine and one more chip. It is still not the
data RAM -- only the boot logic can write it, so the Harvard property holds.
Both give random access, so the bracket scan question stays about speed only, and
the loop stack is still the default because the calculator main loop wraps the
whole tape. Media that cannot be addressed at all (mechanical tape, serial only
flash, floppy) remain useful as the source for the second variant.
The data ring is part of the ISA and cannot go away (64 addressable cells, one 6116
or 512 flip flops), but the program RAM and the loader are not part of the
machine: copying the tape into RAM would put another machine inside this one and
lose the premise that the tape is the program. So the default architecture is now
execute in place: ip is the address of the tape memory, the fetched byte yields
three bits of opcode, and the bracket scans are address increments and decrements.
That works with a parallel EEPROM or flash (28C256, 29C010, 39SF010): fifteen
address lines, eight data lines, no glue logic, and the chip in a socket is the
cartridge. On an FPGA the tape is block RAM initialised from the bitstream, which
also needs no loading step and no external chip. LOAD then RUN stays in the
document only as an optional peripheral for media that cannot be addressed:
mechanical tape, serial SPI flash, floppy.
One consequence is now stated as a requirement rather than an option: with in
place execution a bracket scan costs a clock per instruction, and the calculator
main loop wraps almost the whole 51378 instruction tape, so a scanning ] would
cost 51 k clocks per round -- 51 ms at 1 MHz, paid on every character read. The
loop stack implementation (pop on ], no rescan) is therefore the default, and it
is also what makes mechanical media viable at all.
The packer output is correspondingly simpler: the .bin is literally the memory
contents, ready for a programmer or a block RAM init file. No image layout, no
FAT, no loader to write.
With LOAD then RUN settled, the medium only has to deliver 19 to 51 KB once, so a
floppy is pure overkill and the useful axis is size. Section 9 now ranks the
candidates by area:
* a DIP-8 EEPROM or SPI flash (24C512, 25Q64) is a 10 mm square in an 8 pin socket
-- the ROM cartridge model, no filesystem at all because the chip is the address
space, about 3-10 CNY, writable with any CH341A class programmer;
* microSD is 15 by 11 mm and holds the whole tape library; the loader reads raw
sectors from LBA 0, so no FAT parser is needed either (dd from a PC writes the
card);
* a credit-card punched card at 2 mm pitch holds about 1000 instructions, which
runs hello (577) or full_add (95) but none of the big programs -- good as an art
cartridge, not as the main medium;
* a microcassette is 50 by 33 by 8 mm, a real small tape, 150 B/s so a 19 KB image
loads in two minutes, drives second hand;
* the 3.5 inch floppy, 90 by 94 mm, stays only if you want the clack.
Both small options also drop the filesystem question: one reads raw blocks, the
other is memory. A small AVR can act as the tape drive for a TTL machine behind a
DATA/STROBE handshake, and on an FPGA the loader is a few dozen lines. The packer
gains --at-lba 0 for the card case and --i2c-image for the programmer case; only
the floppy route would need --fat12.
A mechanical medium is only a bad *execution* memory; real machines loaded from the
medium into RAM and ran from there. That decouples the medium speed from the
machine: the medium just has to deliver tens of KB/s once, and execution costs no
traversal at all. With that architecture a 3.5 inch floppy is fine, and the note
now records what is still buyable: USB floppy drives are still made (about 50-120
CNY) but only expose whole 512 byte sectors, so a small microcontroller or a Pi
acts as the host and feeds them to the machine; a 34 pin drive plus an N82077AA
class controller is the all period correct route and much more work; Gotek style
emulators are the reliable but media-less option; audio cassettes are still
sold and load the 19 KB image in about two minutes, which is plenty when the
program then runs from RAM.
A floppy can even be the executing tape: at 300 rpm and 18 sectors per track it
streams 46 KB/s, so the 51378 instruction tape goes round in 0.4 s and with the
loop stack it only ever streams forward -- but you have to do MFM decoding and
sector framing yourself, and every input character waits 0.4 s. LOAD then RUN is
an order of magnitude simpler and a hundred times faster.
The real floppy risk is not the drive, it is the media: 20 to 30 year old disks
grow mould and lose their field, so keep several NOS disks and two copies of each
image. The software side is small: a --fat12 disk.img output on the packer,
writing HELLO.R8T and CALC.R8T into a standard 1.44 MB image that any USB drive
can put on a real disk.
Correcting an over-specification: ip only ever moves by one, and a bracket scan is
made of one-step moves, so any medium that can be iterated forwards and backwards
will do. Taking that further, the backward half is removable too: keep a five bit
LIFO of loop entry positions, push on [ when the low bit is one, and on ] always
pop -- the popped position is the matching [, and if the low bit is one we jump
back to it (it re-runs) and otherwise carry on. [ with a zero low bit still scans
forward, which it would anyway. That is equivalent to the reference scan for
well formed tapes, and since scans do not count as steps the four VMs still agree
on step counts. So a forward-only medium can execute directly.
What actually rules media out is speed. The runtime loops in our programs are
enormous: the calculator main loop wraps almost the whole 51378 instruction tape,
so every character read walks the entire tape. A paper tape reader at 50-300
characters per second would need 170-1000 seconds per keystroke; an audio
cassette around 130 s; magnetic tape or floppy class (30-500 k chars/s) gives 0.1
to 1.7 s; RAM needs no walk at all. So paper tape is a demo medium (the 577
instruction hello tape is about two seconds), and the practical machine stores
the tape in RAM or block RAM. The medium table and this analysis are in section
9, the loop-stack variant in section 4.
Nothing is committed to flash yet, so section 9 now records the constraint that
decides it: the [ skip scans forward but the ] jump scans backward, so whatever
holds the tape must support random access, or the machine has to copy the whole
tape into RAM at boot. That is why a serial SPI flash cannot execute directly:
it only streams forward. A parallel flash or EEPROM with an address bus can be
the tape itself (29C010 at 70-150 ns is comfortable at 1 MHz), and on an FPGA the
tape simply lives in block RAM next to the bitstream, no external chip at all.
The packed image the taper pack tool will emit is medium independent on purpose:
the same bytes initialise block RAM, program an EEPROM and drive the RTL
testbench, so M0 does not have to wait for the medium decision. Paper tape stays
a demo medium only: at 2.54 mm pitch the 577 instruction hello tape is about
1.5 m, and the calculator tape would be 130 m.
259 was never part of the machine, just the historical default, so
kDefaultMemoryCells is now R8FORGE_MEMORY_CELLS (1..65536, default 259) with a
range guard in CMake, the same way the cell width already worked. All five VMs
read it from geometry.hh, so nothing else had to change.
Measured the highest cell each tape in the tree actually touches by walking its
> and < and recording the peak (no tape does a < at cell 0, so none of them
depend on wrapping): calc 51, hello 49, signed_demo 34, term 27, and the
asm/test.r8asm self test 155, because it lays every macro cell block out side by
side. So a 64 cell ring runs every program we ship; only the self test needs
the default.
Verified: the full ctest suite is 8/8 at both 128 and 64 cells (11 bit); at the
hardware geometry of 8 bit plus 64 cells the widthfree label is 5/5, and the
calculator tape is byte for byte identical to the 259 cell build and its
sessions take the same 166348 steps. The self test also produces identical
output at 64 cells but 216 more steps, because its high cells fold back onto low
ones -- which is why SPEC section 1.2 states the rule: ring size must be at
least the highest cell a program touches plus one.
Hardware payoff: at 64 cells dp is a 6 bit counter whose wrap is free, so the
TTL build loses its modulo-259 comparator logic (four to five chips), the RAM
needs 64 bytes, and the drum shrinks to 8 tracks by 64 cells (at 3000 rpm that
is 52 s for a calculator session, so it wants to spin faster). hardware.md is
updated to the 8 bit / 64 cell machine throughout.
Decision: the physical machine uses 8 bit cells. 11 bits is half decimal
semantics and half superstition; at 8 bits a cell is a byte, so , and . are
plain byte I/O, the whole 259 cell ring is 259 bytes and fits one 6116, and the
datapath is one 74HC299 plus an XOR.
It also settles the instruction pointer problem: the 8 bit calculator is 51378
instructions, back under the historical 65536, where the 11 bit one had grown
to 73624 with its terminal front end. Measured tape sizes and step counts at 8
bits (build8, MSVC):
full_add 95 instructions, 36 bytes
hello 577 instructions, 217 bytes
term 16414 instructions, 6.2 KB
signed_demo 37511 instructions, 14.1 KB
asm/test.r8asm 43676 instructions, 16.4 KB, 99824 steps, 52 OUTs
calc 51378 instructions, 19.3 KB, 166348 steps for "12 34 + ."
The note now records the 8 bit numbers next to the 11/16/32 ones, recomputes the
TTL bill of materials (20-28 chips instead of 25-35: one RAM, one shift
register, four or five ip counters), gives the drum 8 tracks instead of 11, and
adds an optional M4 that widens the machine back to 11 bits by swapping the ROM
to demonstrate that width is a build parameter rather than runtime state.
Milestone M2 now expects exactly 99824 steps and M3 expects "046" from the
calculator, both of which the software side already produces.
docs/hardware.md turns the ISA into hardware requirements and works out what a
physical ROT-8 needs. The load-bearing observation is that nothing in the
instruction set can observe time -- no counters, no interrupts, and the I/O
behaviours are "block until a character" and "latch the cell" -- so any
implementation that reproduces the same sequence of (ip, dp, cells, output) is
the same machine, at any clock rate and any number of cycles per instruction.
That is what makes the build tractable: a microcoded sequencer, slow memory or
even a drum are all legal.
The note pins the parts that are easy to get wrong: the exact scan boundaries
for [ and ] (the ] case jumps back onto the [ itself so it re-tests, which the
reference rot8.c gets right and a naive implementation gets wrong), the halt
condition, cells starting at zero, and the input convention -- , blocks until a
character arrives and an explicit EOF reads as 0, otherwise every interactive
read would return zero and the program would exit at once.
Budget: 3 bits per instruction, so the flagship tape is 23.4 KB of ROM and the
calculator at 11 bits is 27.6 KB; the data ring is 259 cells by W bits at most
518 bytes. Two consequences: the instruction pointer needs at least 17 bits
because the calculator now assembles to 73624, past the historical INS_SIZE of
65536, and the 32 bit calculator (126 KB) does not fit the block RAM of the
small boards.
Three carriers are compared: FPGA first (Tang Nano 9K, about 58 KB of BSRAM, a
weekend of work), discrete TTL as the real machine (25-35 chips, 0.25-0.5 M
instructions per second, a few weeks) and electromechanical as the showpiece
(a drum with 11 tracks and 259 cells per track, read and write heads one cell
apart so a read-modify-write costs one cell time: 22 s for a whole calculator
session at 3000 rpm). The verification plan leans on what already exists: a
packer into the 3 bit format, the RTL testbench compared against tape_run step
by step, then the panel single-stepped against an exported trace.
Nothing is implemented; the note ends with the decisions that come first --
which carrier, which width (8, 11 or 16), program storage, and whether the
physical tape form matters. The first concrete step would be M0: the packer
plus a rot8.v testbench, which needs no hardware purchase and gives all three
carriers the same golden model.
It cannot. The calculator assembles to 73624 characters in the default flat
metric and 73940 with --synth-chars (identity layout), 316 more. Three reasons,
now written down in SPEC section 3.7:
* the travel term 2*(hi-lo) is translation invariant, so moving a group of cells
farther or nearer changes nothing; only a permutation or a spread can, and the
contiguous identity layout is already the tightest of those;
* the library blocks are expanded at dozens of call sites with different
addresses, so a single layout line is a guess that the real sites rarely
match;
* the model still ignores the hop between blocks, and the exact metric tends to
pick programs with more blocks (six blocks for the adder table against five,
82 emitted characters against 87 -- five characters, which the other tables
give back and more).
Cell placement is the lever that works, and it is already spent: the terminal
front end first put its borrowed classifier cells at 52..57 (77164 characters)
and moving them into 20..29 gave 73624, minus 3540. Five single-cell moves on
the current map were measured too (T and DEPTH to 17, HAVE and CNT to 52, S2
back to 52) and every one is longer: +182, +2900, +92, +134, +3810. So the map
is a local optimum and the only way down from 73.6k is to drop features.
The experiment left three metric-0 cache entries behind; they were deleted, so
the committed cache still holds only what the flat metric needs.
The calculator now behaves like the terminal tape from the previous commit:
every character is echoed, backspace edits the digit window, Enter commits the
line and prints the next prompt, and '.' puts its result on its own line:
> 12 34 + .
0046
> 12<BS>3 .
0013
> ^D
It is not the terminal's line buffer moved over: the calculator consumes one
character at a time, and replaying a buffered line would mean unrolling the
engine once per buffer cell, which does not fit. Line editing here is the
digit window: backspace shifts it right by one, pads a '0' in front, echoes
"space, backspace" and keeps accumulating.
Three things had to be learned the hard way, all recorded in docs/calc.md ?8:
* a borrowed constant cell gets eaten. KBS (the 8 that backspace subtracts)
lived in SC+5, and the operator step erases SC..SC+6 wholesale, so the first
byte after an operator was treated as a backspace -- every character of
"12 34 + ." came out as an erase. It is now loaded right before each use.
It also must not borrow R: the EOF test writes R every round.
* set_1 only forces the low bit; cells lent to the classifier have to be
re-initialised each round rather than assumed clean.
* the prompt after Enter has to be printed before the command dispatch and the
operators run, because EH (the "this was Enter" flag) borrows SC+3, which
mul uses as scratch -- the first version printed a prompt after every
multiplication.
The tape went 64983 -> 73624 characters (+8.6k: three copies for the window
shift alone are ~4.4k, the two subtracts ~3k). That is past the old
ROT-8-viz INS_SIZE of 65536; the current VM sizes its buffer from the tape and
runs 112802 characters at 16 bits and 336304 at 32 bits, so only the
historical budget is gone, not the ability to run it. Ducking under 65536
again would mean dropping line editing: echo plus the Enter prompt alone is
about +2.5k, still over.
Verified: ctest 8/8 (examples_test checks the new header stream), the width
matrix at 11, 16 and 32 bits (calc stream, terminal tape and the viz's serial
output all agree; 73624 / 112802 / 336304 characters), and docs/calc.md records
step counts for the whole session list -- "12 34 + ." is 287589 steps, about
17% more than before the front end.
Two separate things hid behind "32 bit works":
* tests/byte_op_test.cc could not compile at 32 bits at all (`1 << 32` in a
constexpr plus an int typed mask), so the whole 32 bit build stopped there --
only `r8forge` and the core library came out. kCellMod is now clamped at
31+ bits and main() prints "skipped" above 16 bits (every sweep there is 2^W
rows) and exits green. All ten targets build at 32 bits with MSVC, and the
same tree builds clean on a Gentoo box with GCC 16 -- the missing <cstring>
in asm_test.cc that stopped GCC first is in the previous commit.
* the digit drivers hardcoded a 4 cell window, so byte_op_test's digits /
digits_signed / undigits failed at every other width (16 bits wants 5 digits,
8 bits 3). drv/digits.r8asm, drv/digits_signed.r8asm and
drv/undigits_byte.r8asm now derive D = _CELL_SIZE * 30103 / 100000 + 1 and
space their cells by it, and the C++ side uses the same kDigits instead of a
literal 4 (including the T/F cells clb_digits_signed leaves behind).
With that, byte_op_test passes at 8, 11 and 16 bits (the 16 bit run takes about
450 s) and above 16 it skips. Two more width bugs fell out on the way: the
divmod divisor sweep used 1000 and 2047 unconditionally (they wrap at 8 bits),
and the undigits garbage guard OR'ed in bits above the cell, which at 8 bits
turned '0'+digit into a value over 255. test_divmod_signed also divided by the
recovered divisor without re-checking it, and at 8 bits the boundary value 1024
wraps to 0 -- that was a hard crash (divide by zero), not a failure.
CMakeLists.txt now refuses -DR8FORGE_CELL_SIZE outside 1..32 at configure time;
the range used to be a comment, so an out of range width was discovered as a
compiler error in whichever file shifted by it first. geometry.hh and SPEC
section 13 record that 32 is the ceiling because every VM stores a cell in
uint32_t -- going further means widening all five VMs, the assembler's immediate
type and ROT-8-viz's rot8_data.
Also recorded there: the %synth cache is keyed by the truth table, not the
width, so a 32 bit build hits the committed entries (0.4 s for the flagship
tape of 227075 characters). A full cold rebuild takes ~500 s on a 44 thread
machine, 479 s of which is the single 6 parameter full adder table.
std::strcmp needs it; MSVC pulls it in transitively so the Windows build never
noticed, but GCC 16 rejects the file. Found while trying to build a 32 bit
toolchain on a Linux box to time the %synth cache.
examples/term.r8asm was a per-character echo (prompt, echo, backspace erase,
newline, EOF). It is now a small shell: a 4 character line buffer, a backspace
that really removes a character, and Enter -- or EOF, for a half typed line --
commits the line and dispatches on its first character. 'l' prints the length,
'r' prints the buffer backwards, 'q' quits, anything else is ignored.
The header session "lhi" exercises the whole chain: EOF commits the pending
line, so examples_test sees the '3'. Three more sessions are documented in the
header: "rab" gives NUL+'b'+'a'+'r', "lab<BS>" gives '2' (the backspace really
dropped the 'b'), and "lhi<NL>rxy<NL>" prints '3' then the reversed second
line.
Three things ate most of the debugging time; all three are written up in the
file:
* "else" needs a flag cell. biz enters when the low bit is set, so "if not A
then B" cannot be inferred from "the last test missed": set FLAG=1 before the
test, clear it in the matched branch, look at FLAG afterwards. And biz tests
the CURRENT dp cell, so the order has to be "set FLAG, then .tp to the
condition cell, then biz" -- the wrong order made every character look like
a commit key.
* clb_sub_nc eats its operands, so the echo and the append both work from the
copy CE. The first version appended C (already zeroed by the comparison),
which left the line buffer empty: 'l' printed 0 and 'r' printed four NULs.
* the cell layout dominates the tape. copy / clb_sub_nc / clb_nonzero all emit
.tp internally, some of them inside %rep _CELL_SIZE, so a 20 cell gap costs
a couple of thousand characters: putting the constants at 22..28 gave 33067
characters, packing the hot cells into 0..27 gives 21721.
The buffer is left aligned with a length counter -- appending needs a dispatch
on LEN, but backspace is just LEN-- -- and 'r' prints all four cells instead of
dispatching on the length, which costs a NUL for the unused cells and is
documented.
tests/widths.ps1 now also checks term.r8asm at every width (its expected
stream is width independent, which is what makes it a good second program for
the matrix), and TODO/AGENTS/README record the item as done.
The TODO summary line still advertised the interactive calculator; it has been
finished (and is now an RPN stack). Point at docs/calc.md and list what is
really left: the terminal tape, the mini printf, the tape optimiser,
--profile, the cache check and CI.
The two register machine (A accumulator + P pending operand) could not nest:
"1 2 + 3 4 * + ." printed 0007 because the second operator overwrote the
first. The calculator now keeps a 3 cell stack (S0 is the top), operators run
immediately (pop two, push one), '.' is a real peek (repeated '.' shows the
same value, and it no longer flushes anything), and ',' clears both the stack
and the depth.
Depth is counted in DEPTH because the unary minus rule needs it: '-' is unary
iff the stack is empty. The previous "the previous character was an operator"
rule is wrong for a stack machine -- in "1 2 + -" the minus has to be a binary
subtraction (popping an empty cell yields 0, and 0 - top is exactly a
negation); treating it as unary would silently swallow the sign. The
"have == 0" rule from the original plan was already wrong for the old machine
("2 * -5" would lose its minus).
Sizing was driven by the tape: every push/pop is one copy per stack cell
(~500 characters), and the file has to stay under 65536. So 3 cells instead
of the 16 the TODO dreamed of: push is two copies (S2<-S1, S1<-S0), an
operator is two more (S1<-S2, then the result), and the new number is written
straight into clb_undigits' target cell (it erases N itself) so the extra
"result -> top" copy disappears -- that one was worth 540 characters. S2 sits
in cell 33, the freed OP cell: putting it at 51 cost 3.7k in walking alone.
64983 characters (was 62624) and 246142 steps for "12 34 + ." (was 280645 --
the old settle-the-pending-OP block is gone). The file header carries the
measured session list, the nesting cases, the stack move order (high to low,
or the source gets overwritten) and the older "2047 3 / ." caveat; docs/calc.md
gets the stack section, and SPEC 5.4/7.10 now point at DEPTH instead of NEED.
SPEC gains 7.10 with both contracts, the five design points and the measured
tape lengths; 5.4 stops saying "implementation pending" and spells out why the
range is asymmetric -- |N| can be outside the signed range while still fitting
unsigned, so 1024 has to print -1024 and the absolute value cannot be done by
clearing the sign bit.
Numbers re-measured on this machine, because some had drifted: the flagship is
62351 characters / 202159 steps (documented as 62513 / 206491), --opt takes it
to 56338, the calculator is 62624, the byte level test is 23 items over 22
macros, and asm/ has 55 macros in 23 files.
tests/widths.ps1 no longer compares the viz's serial output below 8 bit cells:
the viz prints one number per OUT there, so the 7 bit "viz FAILED" was the
script's expectation, not the tape -- the calculator itself passes at 7 bits
through r8forge_derive, and the same failure reproduces with the previous
calculator (checked against HEAD in a temp worktree). The TODO gains the open
question of whether the flagship should keep the 65536 limit at all, plus the
evidence that a 16 bit tape of 96052 characters runs fine in the viz.
'/' now goes through clb_divmod_signed and '.' through clb_digits_signed, so
the accumulator can be negative: "3 5 - ." prints "> -0002", "-5 2 * ."
prints "> -0010" and "-7 -2 / ." prints "> 0003". Add, subtract and multiply
needed nothing -- mod 2^W arithmetic is already two's complement correct.
The one new piece of state is NEED, "a new operand is expected": expression
start, just settled, just after an operator, just after ','. A '-' with
NEED == 1 is unary: set NEG, clear ISCMD (so step 3 leaves OP alone), and the
next number is negated in the flush. NEED == 0 means P already holds an
operand waiting to be settled, so '-' stays the binary minus.
The original plan was "HAVE == 0 means unary", which is wrong: HAVE only says
"digits are being accumulated", so after "2 *" it is 0 too and the minus in
"2 * -5 ." would be parsed as a subtraction.
Two consequences worth knowing: 2047 is now -1, so "2047 3 / ." correctly
prints "> 0000" instead of the old unsigned 0682 (write "1023 3 / ." for 341),
and the printable range is -1024..1023. The tape grows 59519 -> 62624
characters: the two wrappers plus the NEED/NEG judging.
The file header carries the measured sessions with their step counts and the
three cells the signed macros needed (T1 48, T2 49, SG 50), and examples_test
still checks the "12 34 + ." line.
clb_digits_signed N REG S T F prints '-' (45) and then |N| as the same four
zero padded digits; clb_divmod_signed N D Q R S T1 T2 F is the C style
truncated division (q = trunc(n/d), r = n - q*d, remainder follows the
dividend). Both are wrappers: clb_digits / clb_divmod still do the work, so
the tape only grows by the sign handling -- 572 characters for the display
(12151 vs 11579 in the same driver layout) and 1191 for the division
(6018 vs 4827).
The sign bit is read with rol + bit_copy + ror, 49 characters. clb_bit_mov is
deliberately NOT used: it eats the source bit, so N comes back as N - HALF and
1024 -- whose magnitude 1024 only fits the unsigned range -- prints as 0000.
A clb_sub_nc against a HALF constant was the other candidate: 765 characters
for the call plus ~60 for the constant cell.
A flag has to outlive the block that consumes it, because biz/rnz only exit
once the body clears the condition bit. So sign(N) is moved into T2, sign(D)
into F, and the remainder block flips F into sign(N)^sign(D) on its way out;
a single conditional negation of the quotient then carries the xor. The
negation scratch is S+6: the only cell in S with a "clean on entry" contract,
and clb_neg_ip leaves it zero again for clb_divmod.
Verified by r8forge_byte_op_test: all 2048 values for the display (worst
117606 steps) and 4202 division pairs -- every |a|,|b| <= 32 plus the
0/+-1/+-1023/+-1024 boundary combinations -- compared against C's / and %.
examples/signed_demo.r8asm is the single point regression that runs as a
program (the flagship cannot carry them: +12.1k / +5.6k on a 62351 tape).
The four decisions are settled and the work is not done, so each fact goes where it
belongs:
SPEC 5.4 two complement, the sign bit is _CELL_SIZE-1 (-1024..1023 at 11 bits,
-128..127 at 8 bits, symmetric, so no |MIN| trap), display -0042,
truncating division (the remainder takes the sign of the dividend),
silent wraparound. Addition, subtraction and multiplication need no
change: the arithmetic is already modulo 2^W.
TODO three independently verifiable steps -- clb_digits_signed (sign test
via clb_sub_nc against HALF = 2^(_CELL_SIZE-1), negate a copy, then the
existing digits), clb_divmod_signed (magnitudes, unsigned divide, signs
reapplied), and the calculator unary minus when HAVE is clear. Each
step lists its acceptance sweep.
AGENTS a short pointer so the next session sees the big queued thing.
The width trap is called out in all three: HALF must be %rep _CELL_SIZE; a literal
11 would misread the sign bit on an 8 bit machine.
The owner stated the rule plainly: apart from INP/OUT (which are host interface
decisions), machine semantics do not change unless explicitly asked -- the eight
instructions, biz/rnz testing the LSB, + rotating right, - flipping the low bit, how
steps are counted, the 259 cell ring, running from the first instruction to the end
of the tape. The reason is that three implementations cross check each other and
none of them is a second specification: a "harmless" tweak in one makes the other
two look broken, with nothing to adjudicate. Changing semantics means writing it in
SPEC first and changing all four machines together (SPEC 13); otherwise only tools
and views may change.
The other machine's ROT-8-viz was three commits behind and still had the old serial
INP ("only the low 7 bits change, leave the rest alone"), so the calculator printed
> 0000 there while the same 62800 character tape printed > 0005 in the current
checkout. Recompiling "fixed it by magic" -- it was the whole-cell INP commit.
Worth writing down because the failure mode is deceptive: viz is the authority, so
a stale authority looks like a program bug. The bullet now says to verify the
binary is fresh first, and names the symptom.