Top
Best
New

Posted by antirez 2 days ago

Implementing a Z80 / ZX Spectrum emulator with Claude Code(antirez.com)
110 points | 55 commentspage 2
kazinator 6 hours ago|
What'a a "clear room"? A clean room, but with plagiarized code, laundered through an LLM?
dist-epoch 15 hours ago||
> I believe automatic programming to be already super-human, not in the sense it is currently capable of producing code that humans can’t produce, but in the concurrent usage of different programming languages, system programming techniques, DSP stuff, operating system tricks, math, and everything needed to reach the result in the most immediate way.

As HN likes to say, only a amateur vibe-coder could believe this.

Zafira 14 hours ago|
It is really quite something how many people that have earned credibility designing well-loved tools seem to be true believers in the AI codswallop.
jlarcombe 12 hours ago||
it's fascinating / astonishing
themafia 13 hours ago||
in spectrum.c

> Address bits for pixel (x, y): > * 010 Y7 Y6 Y2 Y1 Y0 | Y5 Y4 Y3 X7 X6 X5 X4 X3

Which is wrong. It's x4-x0. Comment does not match the code below.

> static inline uint16_t zx_pixel_addr(int y, int col) {

It computes a pixel address with 0x4000 added to it only to always subtract 0x4000 from it later. The ZX apparently has ROM at 0x0000..0x3fff necessitating the shift in general but not in this case in particular.

This and the other inline function next to it for attributes are only ever used once.

> During the > * 192 display scanlines, the ULA fetches screen data for 128 T-states per > * line.

Yep.. but..

> Instead of a 69,888-byte lookup table

How does that follow? The description completely forgets to mention that it's 192 scan lines + 64+56 border lines * 224 T-States.

I'm bored. This is a pretty muddy implementation. It reminds me of the way children play with Duplo blocks.

antirez 13 hours ago||
What happened with the wrong pixel layout is that the specification was wrong (the problem is that sub agents spawned recently by Claude Code are Haiuku session, their weakest model -- you can see the broken specification under spectrum-specs), it entered the code, caused a bug that Claude later fixed, without updating the comment. This actually somewhat shows that even under adversarial documentation it can fix the problem.

IMHO zx_pixel_addr() is not bad, makes sense in this case. I'm a lot more unhappy with the actual implementation of the screen -> RGB conversion that uses such function, which is not as fast as it could be. For instance my own zx2040 emulator video RAM to ST77xx display conversion (written by hand, also on GitHub) is more optimized in this case. But the fact to provide the absolute address in the video memory is ok, instead of the offset. Just design.

> This and the other inline function next to it for attributes are only ever used once.

I agree with that but honestly 90% of the developers work in this way. And LLMs have such style for this reason. I stile I dislike as well...

About the lookup table, the code that it uses in the end was a hint I provided to it, in zx_contend_delay(). The old code was correct but extremely memory wasteful (there are emulators really taking this path of the huge lookup table, maybe to avoid the division for maximum speed), and there was the full comment about the T-states, but after the code was changed this half-comment is bad and totally useless indeed. In the Spectrum emulator I provided a few hints. In the Z80, no hint at all.

If you check the code in general, the Z80 implementation for instance, it is solid work on average. Normally after using automatic programming in this way, I would ask the agent (and likely Codex as well) to check that the comments match the documentation. Here, since it is an experiment, I did zero refinements, to show what is the actual raw output you get. And it is not bad, I believe.

P.S. I see your comment greyed out, I didn't downvote you.

dang 3 hours ago|||
> It reminds me of the way children play with Duplo blocks.

WTF? I appreciate your technical expertise but you can't be aggressive like this on HN, and we've had to ask you this before: https://news.ycombinator.com/item?id=45663563.

If you'd please review https://news.ycombinator.com/newsguidelines.html and stick to the rules when posting here, we'd appreciate it.

themafia 3 hours ago||
> you can't be aggressive

I disagree that this is "aggressive." It's certainly opinionated. I think the AI does a bad job here and I'm attempting to express that in a humorous and qualified way.

> WTF?

You don't consider this to be "aggressive?"

> stick to the rules when posting here

Do you genuinely think I'm trying to be disruptive?

nz 2 hours ago||
Even though I understand your sentiment, and think it is sincere, I think this is intellectually dishonest. Even though I have been programming since I was 16 (20 years), I still program like a child playing with Duplo blocks, when using a novel or otherwise unfamiliar technology. I bet that you do too. I also think that every programmer should play with their computers once in a while. Explore. Discover. Even if it means allowing yourself to be alienated from your means of production.
xcf_seetan 13 hours ago||
I had Claude make an quad core 32 bits z80 just for fun.

<https://pastebin.com/Z2b82LHG>

klelatti 12 hours ago|
Fascinating, but I'm not sure how these are consistent?

- Based on classic Z80 architecture by Zilog - Inspired by modern RISC designs (ARM, RISC-V, MIPS)

HarHarVeryFunny 11 hours ago|||
The Z80 itself was "inspired" by the 8080, notably having dual 8080 register sets. It might be regarded as a "clear" (sic) room reimplemention/enhancement of the 8080 given that it was the same 8080 designers who left Intel to found Zilog and create the Z80.
throwa356262 12 hours ago|||
Z80 is CISC. This looks like a MIPS.

Funny enough, there is a 32-bit version of Z80 called Z380.

UltraSane 12 hours ago||
It is "clean room"
paxys 3 hours ago||
What is "clear room"? If he means clean room, no, this doesn't qualify.

I wish people would stop using this phrase altogether for LLM-assisted coding. It has a specific legal and cultural meaning, and the giant amount of proprietary IP that has been (illegally?) fed to the model during training completely disqualifies any LLM output from claiming this status.

airza 14 hours ago||
You use clean room everywhere in the article and clear room in the title. Is this on purpose?
lazide 14 hours ago||
Literally nothing about it is either, either.
rustyhancock 14 hours ago||
Yes for a moment I thought clear room might mean something else for LLMs.

Essentially they can't do clean room anything!

You might as well hire the entire former mid level of a businesses programming team and claim it's clean room work

steve1977 14 hours ago||
Windows NT is not VMS! Trust me!
rustyhancock 14 hours ago||
Had to Google this but I do love a deep cut reference!

https://www.itprotoday.com/server-virtualization/windows-nt-...

HarHarVeryFunny 11 hours ago||
At first I thought it was brain slip in the HN title, then I saw TFA also said "clear", so thought it was perhaps a sarcastic jab at the original "clean" room story it is commenting on, but maybe in the end just an error ?

In any case, an interesting experiment.

HarHarVeryFunny 10 hours ago||
It would also be interesting to see how well the best open weights models such as Kimi K2.5 can do on a task like this with the same prompting to first gather specs, etc, etc.

In fact this would make for an interesting benchmark - writing entire non-trivial apps based on the same prompt. Each model might be expected to write and use it's own test cases, but then all could be judged based on a common set of test cases provided as part of the benchmark suite.

jlarcombe 12 hours ago||
How on earth does this count as "clean room" in any way, when many open-source Z80 emulators will without doubt have been part of its training data?
HarHarVeryFunny 11 hours ago|
Perhaps why the title said "clear" room ?
aichen_dev 10 hours ago||
[dead]
marcus_lam 15 hours ago|
[dead]
lazide 14 hours ago|
Except the AI was trained - by looking at the implementations? Or do you think Claude never saw the implementations in its training set?

Because that is exceptionally unlikely.

More comments...