Giter Club home page Giter Club logo

cmos2tetris's Introduction

Cmos2Tetris

The Hack computer is based on a minimalist 16-bit single-cycle CPU, with separate ROM and RAM, and a memory-mapped screen and keyboard. The system is described in the Nand2Tetris site, and the accompanying book. There are excellent Coursera courses based on the same material. The genius of the design is that it keeps everything as simple as possible but no simpler, so this is a non-trivial computer on which you can play Tetris, but still hold the hardware design in your head and visualise it working end to end.

This repo has several experiments based on the Hack architecture and extensions thereof, in various stages of planning and completion.

  • Hack emulator in C
  • Cmos2Tetris: Physical breadboard implementation with 74HC logic ICs
  • Hack++: an extension to expand memory capacity and interrupts, without any change to the CPU and instruction set. This will potentially enable porting of Fuzix and other 16-bit operating systems to the Hack++ platform.

Hack emulator in C

The "official" Java Hack emulator is sufficient for the purposes of the course, but it is rather slow, and I was curious to know how fast a C implementation could go. The answer is, pretty fast, around 25MHz (25 million instructions per second) on a Macbook with 2.2GHz i7. Too fast for typical test programs like Pong, which feel more at home at around 2-4MHz.

Installation

Instructions apply for MacOS, but should apply with little modification to Linux. The only external dependency is SDL2. brew install sdl2 Run make to compile hackcpu and hackio. hackcpu is a version without any IO support, and is useful mainly for testing.

Usage

hackio [-c maxcycles] [-r initialram] [-s MHz] [-d] [-i] prog.hack
 -c maxcycles    Number of clock cycles to run. Defaults to 0, runs indefinitely.
 -r initialram   Binary dump file to be loaded into RAM before starting the computer.
 -s MHz          Approximate CPU speed in MHz, defaults to 2. 0 runs as fast as possible.
 -d              Debug mode
 -i              Ignore (memory) errors and continue
 prog.hack       Hack machine language file

Run the supplied Pong.hack (part of the Nand2Tetris project files under CC BY-NC-SA 3.0

./hackio Pong.hack

Close the window to stop the emulator. To run it at full speed,

./hackio -s 0 Pong.hack

TODO

No tests!

Hack emulator in Python

Fairly slow, left here for reference. All future work will be done on the C

Cmos2Tetris, or, Hack on the Breadboard

No schematics, haphazard implementation in progress

Hack++

Pie in the sky for now

cmos2tetris's People

Contributors

ganeshv avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.