Leanpub Header

Skip to main content

Retrocomputing with Clash

Haskell for FPGA Hardware Design

Haskell for FPGA Hardware Design: Use abstractions like monads and lenses to implement 1970's retro-computing devices like arcade machines and home computers.

The author is letting you choose the price you pay for this book!

Pick Your Price...
PDF
EPUB
WEB
0
Pages
155,729Words
About

About

About the Book

Please visit https://retrocla.sh/ for sample chapters, print version, and links to the code repositories.

Haskell has become the functional programming language of choice for many developers due to its excellent tools for abstraction and principled program design. The open source Clash hardware description language unlocks these features for FPGA design as well.

Retrocompuing with Clash takes the experienced Haskell programmer on a journey into the world of hardware design with Clash. Our approach is based on using Haskell to its fullest potential, using abstractions like monads and lenses in building a library of reusable components.

But that wouldn't put the fun in functional programming! And so we put these components to good use in implementing various retro-computing devices:

  • A desktop calculator
  • Pong
  • A simple, but Turing-complete computer that uses Brainfuck as its machine code
  • An implementation of the CHIP-8 virtual computer specification
  • An Intel 8080 CPU
  • Space Invaders arcade machine
  • Compucolor II, a home computer from 1977 complete with keyboard, color video, and a floppy drive
I absolutely love the very Haskell approach to circuit design in this book, as opposed to my own write-Verilog-in-Haskell style. It leverages Haskell's type system in a very natural way to protect against many traps we as circuit designers often fall into.
The book clearly demonstrates the benefits of using a modern programming language for circuit design, where it builds reusable functionality and components at a far finer granularity than what I'm used to in traditional hardware description languages.
Another thing that's absolutely great is the book's use of SDL2 multimedia library to emulate peripherals like monitors which enables you to fully interact with the computers and games that you'll be building without having to go through the sometimes long and painful process of programming an FPGA.

– Christiaan Baaij, Clash lead developer, QBayLogic co-founder

This is the book for functional programmers looking to get into FPGAs and digital logic design. Learn Clash, the "I can’t believe it’s not Haskell!'" hardware description language, while indulging in nostalgia for the 1980s. Take a joyride through a variety of hands-on projects, including Pong, Space Invaders, and the Compucolor II, a personal computer based on the Intel 8080. Recommended.

– Miëtek Bak

Share this book

Price

Pick Your Price...

Minimum price

$39.99

$59.99

You pay

$59.99

Author earns

$47.99
$

All prices are in US $. You can pay in US $ or in your local currency when you check out.

EU customers: prices exclude VAT, which is added during checkout.

...Or Buy With Credits!

Number of credits (Minimum 3)

3
The author will earn $36.00 from your purchase!
You can get credits monthly with a Reader Membership

Author

About the Author

Gergő Érdi

Contents

Table of Contents

1Introduction

  1. 1.1Preliminaries
  2. 1.2Notation
  3. 1.3Resources
  4. 1.4Acknowledgements

2Into the world of FPGAs

  1. 2.1Computers everywhere
  2. 2.2Field-programmable Gate Arrays
  3. 2.3Retrocomputing
  4. 2.4Haskell meets Hardware

3Hello, Clash!

  1. 3.1Bit
  2. 3.2Signal
  3. 3.3Our first circuit
  4. 3.4Summary

4Combinational Circuits are Applicative Functors

  1. 4.1Signal is an applicative functor
  2. 4.2BitVectors and Vectors
  3. 4.3Controlling many LEDs
  4. 4.4Seven-segment display
  5. 4.5Summary

5State, Sequencing and Clocks: The Register Transfer-Level Model

  1. 5.1Clocks and registers
  2. 5.2The RTL model: register and delayed feedback
  3. 5.3Finally blinkenlights!
  4. 5.4Passing around Clock, Reset and Enable lines implicitly
  5. 5.5Multiple clocks
  6. 5.6Pushbutton-toggled LED
  7. 5.7Summary

6Time-domain Multiplexing

  1. 6.1Does this have anything to do with mux?
  2. 6.2Seven-segment displays, revisited
  3. 6.3Keyboard matrix sweeping
  4. 6.4Showing keypad input on a seven-segment output
  5. 6.5Summary

7Project: Pocket Calculator

  1. 7.1A Minimal Viable Calculator
  2. 7.2Binary Coded Decimal arithmetic
  3. 7.3State and state transitions
  4. 7.4An interactive software implementation
  5. 7.5Hooking it up to hardware peripherals
  6. 7.6Summary

8Video Output Using VGA

  1. 8.1Basic operation of a CRT display
  2. 8.2Video Graphics Array
  3. 8.3VGA from Clash
  4. 8.4Summary

9Generative Graphics

  1. 9.1Combinational patterns
  2. 9.2Stateful pattern generators
  3. 9.3Animation
  4. 9.4Coordinate transformations
  5. 9.5Animation, differently
  6. 9.6High-level simulation with SDL2
  7. 9.7Summary

10Project: Pong

  1. 10.1What is Pong?
  2. 10.2Top-level design
  3. 10.3What is our state?
  4. 10.4Drawing
  5. 10.5Summary

11Asynchronous Serial Communication

  1. 11.1Synchronicity
  2. 11.2Universal Asynchronous Serial Communication
  3. 11.3Serial Transmitter
  4. 11.4Serial Receiver
  5. 11.5Applications
  6. 11.6Summary

12Programmable Machines

  1. 12.1RAM machines
  2. 12.2Memory
  3. 12.3CPU
  4. 12.4Summary

13Brainfuck

  1. 13.1Why Brainfuck
  2. 13.2Brainfuck as a programming language
  3. 13.3Brainfuck as byte code
  4. 13.4Brainfuck with external memory
  5. 13.5A complete Brainfuck computer
  6. 13.6Brainfuck as machine code
  7. 13.7High-level simulation of the CPU
  8. 13.8The logic board
  9. 13.9Low-level simulation of the logic board
  10. 13.10Top-level circuit and peripherals
  11. 13.11Summary

14CHIP-8

  1. 14.1History
  2. 14.2The CHIP-8 computer
  3. 14.3Instruction set
  4. 14.4Video
  5. 14.5CPU
  6. 14.6Simulation, take 1
  7. 14.7The complete machine
  8. 14.8Simulation, take 2
  9. 14.9Memory contention
  10. 14.10Summary

15Address decoding and memory maps

  1. 15.1Room for improvement
  2. 15.2A whirlwind intro to Template Haskell
  3. 15.3A memory map DSL
  4. 15.4Backpane connections
  5. 15.5Access contention
  6. 15.6Summary

16Intel 8080

  1. 16.1History
  2. 16.2Veracity
  3. 16.3Interface
  4. 16.4Instruction set architecture
  5. 16.5Instruction decoding
  6. 16.6Microcoded implementation
  7. 16.7Micro-architecture & micro-instructions
  8. 16.8A direct software implementation
  9. 16.9The complete CPU
  10. 16.10Summary

17Project: Tiny BASIC

  1. 17.1What is Tiny BASIC?
  2. 17.2Asynchronous Communications Interface Adapter
  3. 17.3The core logic board
  4. 17.4Version 1: serial I/O
  5. 17.5PS/2 keyboard interface
  6. 17.6Textual video
  7. 17.7Screen editing
  8. 17.8Version 2: Keyboard and video
  9. 17.9Summary

18Space Invaders

  1. 18.1The design of Space Invaders
  2. 18.2How it fits together
  3. 18.3Peripherals
  4. 18.4Video
  5. 18.5Logic board
  6. 18.6Simulation
  7. 18.7Summary

19Compucolor II

  1. 19.1Design
  2. 19.2A Minimal Viable Compucolor II
  3. 19.3Detailed rendering with SDL
  4. 19.4Video hardware
  5. 19.5TMS 5501
  6. 19.6Keyboard
  7. 19.7Floppy drive
  8. 19.8Cycle-count accuracy
  9. 19.9Slowing down the CPU
  10. 19.10Our complete computer
  11. 19.11Summary

20Parting words

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub