Live data from Hacker News

NandGame – Build a Computer from Scratch

nandgame.com

61–70 of 141 posts

Re: NandGame – Build a Computer from Scratch

#61
post #57
post #48

Earlier quoted context omitted.

I would recommended just using the Nand2Tetris book Elements of Computing Systems and implement the computer on an FPGA. I went through the course using the original project’s simulation tools, and I am now circling back and implementing the Hack CPU on a Xilinx FPGA using VHDL.

That's my plan too! I'm still working on the Coursera course and I just started working on the ALU. Can you suggest any resources for FPGAs? What kind of hardware do you intend to implement the Hack CPU on?

I am currently using a Digilent Nexys A7-100T.

https://store.digilentinc.com/nexys-a7-fpga-trainer-board-re...

It has a USB host port for a keyboard and VGA out for the display. The jury is still out as to whether I can build the entire CPU using nand gates, including the ROM and RAM memory. Doing so will use a lot of the FPGA's resources from calculations I've seen. If that's not possible for the memory, then I plan on using the block RAM that's included on the Xilinx board, but for everything else I plan on following the book's design as close as possible. So far, I am in chapters 1-3 simply porting my solutions in the course's HDL to VHDL, which is relatively straightforward so far. I'm taking my time to make sure I'm doing things "professionally", as I'd like to learn the Xilinx toolchain in my professional work at some point. My experience with FPGAs has been implementing them with LabVIEW, which actually makes learning VHDL somewhat mechanical although a bit frustrating. (If I had an FPGA big enough that's targetable via LabVIEW, I could probably build and test the computer in a day or two aside from the VGA and keyboard.) The combinatorial gates are done now, and I've implemented a DFF and am building things from there. So now I'm learning about clocking and such with VHDL. The most troublesome part I anticipate is what to do about the ROM and RAM memory and the display and keyboard. I'd also like to update the CPU where I can interactively download new code to the CPU from a PC using the assembler and software stack I'm building, which is in F#.

I have several books I am using as reference:

- VHDL By Example by Blaine C. Readler (great first intro to VHDL)

- Digital Design Using Digilent FPGA Boards: VHDL/Vivado Edition by Haskell and Hanna

- Effective Coding with VHDL: Principles and Best Practices by Ricardo Jasinski (I'm using this to sort through the various ways to do things in VHDL and have best practices in my code.)

- VHDL for Logic Synthesis by Andrew Rushton

- FPGA Prototyping by VHDL Examples: Xilinx MicroBlaze MCS SoC by Pong Chu

Re: NandGame – Build a Computer from Scratch

#62
post #51

Earlier quoted context omitted.

Last time I tried a Zachtronics game I thought it was awesome and that it was far too much like my actual job so I refunded it. Would have played so much of it if I was still in school.

The main issues I've found in his games (at least for Shenzen I/O and TIS-100) is that the difficulty ramps up a lot in the later levels, and there are artificial limitations that are make the game way harder and less fun. For example, the lack of a "swap dat acc" instruction, having just 2 registers at most, among others. You can work around that but the game's idea shouldn't require you to exploit weaknesses of its…

I feel like that's the point of the game, is it not? I always thought of Shenzhen I/O as a hacking game, not an engineering game. The best solutions are elegant, but in a kind of fucked up and convoluted way. This, to me, is the appeal, but I can see why it turns some people off.

Re: NandGame – Build a Computer from Scratch

#63
Not that this will ever matter for someone who isn't a circuit designer, but the "optimal" solution for the latch is actually really bad.

If you use a "select" block (which should really be called "mux") and tie the output to the input, you create a race condition. If the data input is 1, and you change set from 1 to 0, the output can actually glitch to 0 for a very short period of time, which is a big no-no. (If you draw the equivalent circuit out with just nand gates and assume they all have some delay between input and output, you'll see why).

A safer solution would be to cross couple two nand gates into an SR latch [0], use another two nand gates to control the Set and Reset signals, and an inverter to create NOT(data).

Of course in reality, a latch is usually custom built out of transistors rather than logic gates, but there are some cases where I've used logic-gate-latches to make things easier.

[0] http://electronics-course.com/sr-nand-latch

Re: NandGame – Build a Computer from Scratch

#64

Earlier quoted context omitted.

> it seems like XOR counts as 6 even though there's apparently a way to do it with fewer? This is a great game and tbh I think you're just butthurt because you couldn't figure out any of the optimal solutions. Xor is the first one and it sounds like you didn't solve it. (fwiw I haven't figured it out yet either) 1. It does only save one solution for each level but if you can do it in fewer nands, why do you need to k…

> This is a great game and tbh I think you're just butthurt because you couldn't figure out any of the optimal solutions. There's no need to be rude. Insults like this don't add to your argument. > 1. It does only save one solution for each level but if you can do it in fewer nands, why do you need to keep the fewest components? Most puzzle games like this work this way Because they're separate optimization goals. I…

Yeah I mean I guess you're right - the verbiage could be improved. I just don't think it's worth getting hung up on. It's still a fun little game. I've heard that everything in a processor can be built up out of nand gates and always wondered how that worked so it's been neat to work through it.

It's kind of a learning-first game though so I guess if your goal is to beat the game and get every achievement, yeah you'll be disappointed.

Re: NandGame – Build a Computer from Scratch

#66

Earlier quoted context omitted.

> it seems like XOR counts as 6 even though there's apparently a way to do it with fewer? This is a great game and tbh I think you're just butthurt because you couldn't figure out any of the optimal solutions. Xor is the first one and it sounds like you didn't solve it. (fwiw I haven't figured it out yet either) 1. It does only save one solution for each level but if you can do it in fewer nands, why do you need to k…

> Most puzzle games like this work this way As far as Zachtronics games go, you've been able to save multiple solutions since IIRC Infinifactory, and those games all have two or three optimisation goals. I think Silicon Zeroes only remembers one solution per puzzle, however in most of its levels its goals are quite closely related. OCTOPTICOM also only saves one solution per level, but only has one optimisation goal,…

Okay Zachtronics games look awesome. I'll definitely have to try them out.

On the other hand, my experience with games "like this" are mostly free mobile games or other little browser games. For a paid game I would totally expect to be able to save multiple solutions.

Re: NandGame – Build a Computer from Scratch

#67
post #51

Earlier quoted context omitted.

Last time I tried a Zachtronics game I thought it was awesome and that it was far too much like my actual job so I refunded it. Would have played so much of it if I was still in school.

The main issues I've found in his games (at least for Shenzen I/O and TIS-100) is that the difficulty ramps up a lot in the later levels, and there are artificial limitations that are make the game way harder and less fun. For example, the lack of a "swap dat acc" instruction, having just 2 registers at most, among others. You can work around that but the game's idea shouldn't require you to exploit weaknesses of its…

Have to agree with this. I kept thinking "Instead of playing this, I'd be way better of buying an Arduino and building something real instead. I'd learn a real skill and it would be less unnecessarily difficult on top of that."

Re: NandGame – Build a Computer from Scratch

#68
post #60
post #2

I've done the Coursera course, Nand2Tetris, that inspired this website [1] and found it deeply intellectually satisfying and engaging. If anyone is interested in learning about the logical primitives that build up to a computer, and how they're implemented using logic gates, I would deeply recommend the course! ----------- [1] https://www.nand2tetris.org/

Course materials (projects) seem to contain only slides, with bullet points, not real explanations. Am I missing something? Should I buy the book to actually have the course?

You are probably looking for the videos on coursera [1].

[1] https://www.coursera.org/learn/build-a-computer

Re: NandGame – Build a Computer from Scratch

#69
post #2

I've done the Coursera course, Nand2Tetris, that inspired this website [1] and found it deeply intellectually satisfying and engaging. If anyone is interested in learning about the logical primitives that build up to a computer, and how they're implemented using logic gates, I would deeply recommend the course! ----------- [1] https://www.nand2tetris.org/

For a more accessible yet also very comprehensive book, see Petzold's Code: http://www.charlespetzold.com/code/

Re: NandGame – Build a Computer from Scratch

#70
post #68
post #60

Earlier quoted context omitted.

Course materials (projects) seem to contain only slides, with bullet points, not real explanations. Am I missing something? Should I buy the book to actually have the course?

You are probably looking for the videos on coursera [1]. [1] https://www.coursera.org/learn/build-a-computer

Thanks. Even though I am not the op
Post reply on HN