# Designing Hardware with Verilog¶

Big news! You can use the 8bitworkshop IDE to write Verilog code, and see it executed instantly in real-time on a simulated CRT. Most computers are fast enough to render a game at 60 Hz, which requires simulating Verilog at almost 5 million ticks per second. This is all done in JavaScript!

For example, here’s a simple clock divider module:

    module clock_divider(clk, clk_div2);
input clk;
output reg clk_div2;
always @(posedge clk)
clk_div2 <= ~clk_div2;
endmodule


The IDE instantly compiles this and starts simulating, showing the output signals on the scope:

There are a bunch of Verilog examples, from simple binary counters and video test patterns to sprite generators and video games. Many of them are based on old discrete arcade game designs, like Pong and Tank.

The book describes 8-bit and 16-bit CPUs, the latter of which powers a virtual game console with hardware sprites. There’s even a built-in assembler, which can be configured to generate code for any CPU you can design. Here’s some example code for the FEMTO-8 CPU described in the book:

          zero A	; A <= 0
ldb #1	; B <= 1
Loop:
add A,B	; A <= A + B
swapab	; swap A,B
bcc Loop	; repeat until carry set
reset	; end of loop; reset CPU


There’s also a new 8bitworkshop book! Designing Video Game Hardware in Verilog!

## But wait, there’s more…¶

That was the big news, now here’s the estoric stuff about the 3.3.0 IDE release:

• We now pass the --oldralloc flag to the SDCC (Z80) compiler. This makes it compile a lot faster, at the expense of slightly less optimal code. It also breaks certain bits of code – namely, the bcd_add function, and the vector game samples. You can use the “Revert File” menu item to reset these back to the original, and they should work.

• In the VCS platform, there’s a new “Ctrl-Click to Break” feature. You can ctrl-click on the VCS monitor and it’ll set a breakpoint whenever the raster beam passes that position. It’s rad!

• You can upload binary files and include them in 6502 assembly programs with the incbin directive.