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.
This commit is contained in:
1 parent
9b31a51fec
commit
1e7acc018e
7 files changed
+241
-44
No files matched your search
+15
-2
@@ -1,4 +1,5 @@
|
||||
#include "r8forge/r8asm.hh"
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
@@ -629,10 +630,22 @@ r8asm::ast_node r8asm::parse(const token_stream &stream) {
|
||||
if (!ec)
|
||||
dirs.push_back(work_dir);
|
||||
|
||||
// The file name carries a per-run token: when the system temp directory
|
||||
// is not writable every process falls back to the *same* working
|
||||
// directory, and two runs in parallel (ctest -j) would write and import
|
||||
// the same file -- one of them then assembles the other's body, or
|
||||
// imports a half written one. That is a race that shows up as a
|
||||
// random, fast, one-test failure and nothing else. A clock tick is
|
||||
// enough of a token here and needs no platform include.
|
||||
const std::string unique =
|
||||
name + "." +
|
||||
std::to_string(std::chrono::steady_clock::now()
|
||||
.time_since_epoch()
|
||||
.count()) +
|
||||
".synth.r8asm";
|
||||
std::string path;
|
||||
for (size_t d = 0; d < dirs.size(); d++) {
|
||||
const std::filesystem::path candidate =
|
||||
dirs[d] / (name + ".synth.r8asm");
|
||||
const std::filesystem::path candidate = dirs[d] / unique;
|
||||
std::ofstream file(candidate, std::ios::binary);
|
||||
if (!file)
|
||||
continue;
|
||||
|
||||
+32
-3
@@ -133,18 +133,30 @@ uint32_t get_u32(const std::vector<uint8_t> &v, size_t at) {
|
||||
}
|
||||
|
||||
constexpr size_t kTrailer = 16;
|
||||
constexpr unsigned kFormatPacked = 1; // 3 bits per instruction
|
||||
constexpr unsigned kFormatEprom = 2; // one byte per instruction, low 3 bits
|
||||
|
||||
} // namespace
|
||||
|
||||
std::vector<uint8_t> tape_image_encode(const std::vector<uint8_t> &code,
|
||||
size_t width, size_t ring) {
|
||||
std::vector<uint8_t> image = tape_pack(code);
|
||||
size_t width, size_t ring,
|
||||
unsigned format) {
|
||||
std::vector<uint8_t> image;
|
||||
if (format == kFormatEprom) {
|
||||
// One byte per instruction: what a plain EPROM wants, because `ip` is then
|
||||
// the address and D2..D0 are the opcode -- no shift register, no two byte
|
||||
// window, no decoder. It wastes five bits per instruction, and a 27C512
|
||||
// happens to be exactly 64K, which is the historical instruction budget.
|
||||
image.assign(code.begin(), code.end());
|
||||
} else {
|
||||
image = tape_pack(code);
|
||||
}
|
||||
const size_t at = image.size();
|
||||
image.resize(at + kTrailer, 0);
|
||||
put_u32(image, at + 0, uint32_t(code.size()));
|
||||
image[at + 4] = uint8_t(width);
|
||||
image[at + 5] = uint8_t(ring > 255 ? 0 : ring);
|
||||
image[at + 6] = 1; // format version
|
||||
image[at + 6] = uint8_t(format == kFormatEprom ? kFormatEprom : kFormatPacked);
|
||||
std::memcpy(&image[at + 8], "R8T1", 4);
|
||||
const std::vector<uint8_t> body(image.begin(), image.begin() + std::ptrdiff_t(at));
|
||||
put_u32(image, at + 12, crc32(body));
|
||||
@@ -169,6 +181,7 @@ bool tape_image_decode(const std::vector<uint8_t> &bytes, tape_image &img,
|
||||
const size_t length = get_u32(bytes, body);
|
||||
const unsigned width = bytes[body + 4];
|
||||
const unsigned ring = bytes[body + 5];
|
||||
const unsigned format = bytes[body + 6];
|
||||
if (width < 1 || width > 32) {
|
||||
error = "image says " + std::to_string(width) + " bits per cell";
|
||||
return false;
|
||||
@@ -181,6 +194,22 @@ bool tape_image_decode(const std::vector<uint8_t> &bytes, tape_image &img,
|
||||
}
|
||||
img.width = width;
|
||||
img.ring = ring ? size_t(ring) : kDefaultMemoryCells;
|
||||
img.format = format;
|
||||
if (format == kFormatEprom) {
|
||||
if (payload.size() < length) {
|
||||
error = "eprom image holds " + std::to_string(payload.size()) +
|
||||
" bytes, too few for " + std::to_string(length) + " instructions";
|
||||
return false;
|
||||
}
|
||||
img.code.assign(payload.begin(), payload.begin() + std::ptrdiff_t(length));
|
||||
for (size_t i = 0; i < img.code.size(); i++)
|
||||
if (img.code[i] > uint8_t(opcode::inp)) {
|
||||
error = "eprom instruction " + std::to_string(i) + " is 0x" +
|
||||
std::to_string(int(img.code[i])) + ", not an opcode";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return tape_unpack(payload, length, img.code, error);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user