133 points · by rbanffy · 7y ago · 29 comments
if(~old_download && ioctl_download) begin
cnt <= 8'b0;
timeout <= 32'b0;
end
timeout <= timeout + 1'b1;
That's why in Verilog RTL we generally try to keep always blocks as small as possible, so they focus on assigning the same small set of signals in all branches.It's hard to change your mindset from a programming language to a hardware description language and not make mistakes like these, especially when just starting to learn Verilog. :-)
This code would work just fine (many people would argue it's not very readable -- but it saves you a lot of else branches):
// Default
timeout <= timeout + 1'b1;
// Special cases
if(~old_download && ioctl_download) begin
cnt <= 8'b0;
timeout <= 32'b0;
endI hope my next project will have cleaner code, be more readable and have less issues like these. HDL languages seem to have a rather steep learning curve and it takes some effort to distance yourself from the usual programming mindset.
When performing boolean condition testing, eg "if (~a & b)", always use "!" for negation instead of "~", "&&" for logical and, and "||" for logical or for exactly the same reasons you should do it for C code.
If the operands are all 1 bit, either option works fine. But if you ever accidentally use a vector where you intended a bit, one generates a warning and the other doesn't.
There is a follow up - it can also play music, just like the original could. Check it out: https://www.youtube.com/watch?v=ROPyR-tV7A4
A quick question: Were the original PDP-1 manuals enough to implement the system from scratch? Were there details or hidden issues you had to "guess"?
The original instruction test tapes helped me a lot with debugging the various corner cases. For example, the multiply step opcode (MUS) is re-used in later versions which had full hardware multiply (MUL). The backwards compatibility was retained by flipping a switch inside the computer to selecting between MUS and MUL. I had some programs failing mysteriously because of this.
There were also various pixel brightness available and after implementing it, I discovered Spacewar actually uses that to make some stars brighter than others.
Music playing capability was very advanced for its time (having 4 voices) and after everything was a "silent movie" for a while, there was a rewarding moment when I finally fixed a bug and Mozart started playing from the speakers.
A cool machine, very advanced for its time...
Cheers!