1,327 karma · joined January 8, 2017
Living at Mexico. Always programming new things. 5x IOCCC winner. Wrote the JS1K Chess.
* Website: [nanochess.org](https://nanochess.org/) * Mastodon: [@nanochess@mastodon.social](https://mastodon.social/@nanochess) * Twitter: [@nanochess](https://x.com/nanochess) * My books: [Lulu.com](https://lulu.com/spotlight/nanochess) * Instagram: [@nanochess](https://instagram.com/nanochess)

The emulated C compiler processed a whole file ccvars.c before getting stuck in ccinter.c (this is the 5gb mark, approximately 78 millions of instructions executed). I stopped the process as soon as I saw it was stuck, but the emulator is fast, and I got extra 3 gb in the log. All this happened in less than two minutes.
You cannot choose the source, these come mixed from ST, TI, and other manufacturers. I preferred the laser-engraved ones instead of the white ink ones just to have an uniform look.
The crystal oscillator needs something faster so it requires 74F04, and the link communication buffer requires 74F244 or 74AS244. These are more expensive, the 74F are 2 dollars each chip, and the 74AS are 4 dollars each chip.
I was already proficient in Z80 and 16-bit x86, so learning another instruction set was pretty welcome. The fun came from developing things for the first time and discovering how to actually do things, a 32-bit operating system, a K&R C compiler, and the assorted utilities.
Enforcing limitations was inspired by the IOCCC, and later by my boot sector programs. The type of things you do after work, just to test yourself and have some fun.
Just provide the emulator with an ISO CD image, and once it boots up, type DIR D: this single operation requires just about 28 kb of transputer RAM memory for the operating system, the command-line processor, and the buffers.
There's a file browser embedded in the text editor, so you can navigate using the arrows keys and choosing text files to read.
In fact, we need very little info to read CD-ROM directories. A directory search only requires a 2 kb buffer and some variables to keep track, read until you find the first part of the path, read that block, and repeat recursively until you find the desired file.
Reading a file from the CD-ROM can also be done just keeping a 2 kb. buffer and some position variables. My transputer operating system is inefficient in this because it reads the CD-ROM discs in terms of 512-byte sectors, cached by the host system.
unsigned char memory[65536];
int reg[8];
int main(void)
{
int pc = 0;
/* In this point you read something into memory */
while (1) {
instruction = memory[pc];
if (instruction == 0x76) break; /* HLT */
pc = (pc + 1) & 0xffff;
if ((instruction & 0xc0) == 0x40) /* Handle MOV r,r (opcodes 0x40-0x7f) */
reg[(instruction >> 3) & 7] = reg[instruction & 7];
}
return 0;
}What it does? It simply reads each instruction from memory (PC is the Program Counter), and increments PC continuously limiting it to 16-bit.
It does a comparison for each possible instruction, for this example I only handled the most basic one of 8080 (MOV r,r) and HLT, but this is already 64 cases of the 256 possible!
Then I added iteratively chunks of opcodes to emulate and used language C macros to reduce the code size. For example, there is #define d(e) to join two 8-bit registers into a 16-bit value, and #define Q to read the accumulator.
In the end, to stay inside the size limit of the IOCCC, I removed the tree of 'if' statements and replaced it with a tree of trinary operators ?: (a way of doing 'if' inside an expression) and this is what the macros C and S does.
TO CURVE REPEAT 4 [LT 10 FD 10] END
TO PETAL [CURVE LT 140 CURVE] END
TO FLOWER REPEAT 4 [PETAL LT 50] END
FLOWER
RT 180
FD 50
RT 140
PETAL
PU
FD 50
Emulator link: https://parkertomatoes.github.io/v86/?type=mbr&content=Dg4fB...