Skip to content

A collection of my Nand2Tetris (Elements of Computing) games and demos.

License

Notifications You must be signed in to change notification settings

gav-/Nand2Tetris-Games_and_Demos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nand2Tetris Games and Demos

A collection of my Nand2Tetris games and demos. Nand2Tetris is an online, self-teachable course on Building a Modern Computer from First Principles: https://www.nand2tetris.org/

There is some discussion of these games and demos on the Nand2Tetris Questions and Answers Forum.

Table of Contents

General execution instructions

These programs are already compiled with the JackCompiler into vm code, they just need to be loaded into the VMEmulator and executed as follows:

  • Download and install the Nand2tetris Software Suite (http://www.nand2tetris.org/software.php)
  • Start the VMEmulator.
  • Using File -> Load Program, select the application's directory (e.g. GASchunky) and click the "Load Program" button.
  • Click the "Yes" button to the Confirmation Message pop-up.
  • Set the Animate: drop-down to "No animation".
  • Set the speed slider to "Fast" (not necessary for all demos).
  • Press "F5" to run.

Games and Demos

GASchunky: Real-time Plasma and Rotozoom.

Insert Work Bench Plasma Screenshot Rotozoom Screenshot

YouTube Video: Real-time Plasma and Rotozoom Demo
Watch the YouTube video

This is the most CPU intensive Nand2Tetris demo I have done so far. 'Fast' mode is required in the VMEmulator on an Intel i5 2500K CPU running Linux Mint with OpenJDK 1.7.0_25. All code is written in pure Jack and compiled with the provided complier running on the provided VMEmulator.

Conversion from a chunky bitmap to planar architecture is done on-the-fly with 17 greyscale shades. Each shade in the chunky source image is converted to a 4x4 pixel block in the final output through an ordered dither table. http://en.wikipedia.org/wiki/Ordered_dithering

The monitor image is an adaptation of 'Amiga Lagoon' artwork by the famous Amiga artist James "Jim" Sachs. http://www.palmerfamily.name/sachs.html http://www.youtube.com/user/JDSachs

The demon head was adapted from the fantastic Second Reality PC demo by Future Crew. http://www.youtube.com/watch?v=rFv7mHTf0nA

GASboing: Bouncing boing ball

Bouncing boing ball

YouTube Video: Bouncing Ball Demo
Watch the YouTube video

A classic bouncing boing ball demo that originated on the Amiga and has since been duplicated on many other systems.

This version was inspired by the bouncing ball segment in this ZX81 Demo "25thanni": https://youtu.be/sKj6TaADFWo?t=90

The change in direction of the ball's rotation on rebounding was the give away on how to achieve this effect cheaply. The original Amiga Boing Ball demo (https://youtu.be/-ga41edXw3A?t=27) used palette cycling to give the impression of rotation, we don't have that option on the Hack machine. I had already done significant experimentation with bitmap animations on Hack. The solution was to blit a sequence of pre-shifted bitmaps to screen giving the illusion of rotation AND horizontal movement. On rebounding, the sequence is simply reversed, changing the direction of rotation and horizontal motion.

Pre-calculation of expensive arithmetic is key to high performance animation. Copying a 16-bit word (16 consecutive pixels) to screen memory is cheap, calculating a bit shift for the next animation frame would be very expensive. I started with eight frames of the Boing Ball rotating, rendered with Blender.

The frames were scaled, cropped, quantised to two colours, shifted by two pixels, and padded to an image that was a multiple of 16 pixels in width (using Gimp). This GIF shows the eight frames played back in sequence. Note that each frame is the same size, overlaid on the previous, in the same location! Only the contents of each frame gives the illusion of motion: Alt text

Each frame was saved out, and converted into a Jack object via a Python script.

When playing back, the eight frames are blitted to the same location in screen memory. On completion of the eighth frame, the memory location is incremented by one word, and the sequence is repeated. The sequence was designed with enough background coloured border to ensure that the consecutive blitted frame would erase the trail of the previous, so no flickering occurs from blanking (at least for horizontal motion).

The vertical motion of the ball is from a pre-calculated sine table. There is also some blanking required to erase the remainder of the previous frame above (or below) the current one.

GASscroller: Sinus text scroller

Sinus text scroller

This is a classic scrolling text demo!

The font is actually from the one embedded into the VMEmulator (as at this stage in the course we hadn't made our own yet). It is printed to screen and read back into an array one character at a time during the program initialisation.

The text is scrolled smoothly from right to left in steps of 2 pixels per frame, with each word (16 horizontal pixels) offset vertically based on a value from a precalculated sine table.

The comments at the top of GASscroller.jack describe how the magic of updating ring buffers can reduce the number of calculations required to do this. Normally I keep references to any research I have done, and I don't see one here, but I do recall that I used some article about scrolling on the Commodore 64 for this one.

GASteroids: Classic asteroids like game

GASteroids Gameplay

YouTube Video: GASteroids Gameplay
Watch GASteroids Gameplay on YouTube

The player controls a spaceship in an asteroid field. The goal is to destroy asteroids and survive as long as possible.

The player can rotate the ship left and right, thrust forward, and fire weapons to destroy asteroids. Large asteroids split into smaller asteroids when hit. Small asteroids disappear when hit.

Colliding with an asteroid will destroy the player's ship. A new ship will be granted after each death.

Keyboard controls:

<space> - start game / spawn new ship / shoot weapon.
<left arrow> - rotate ship counter-clockwise.
<right arrow> - rotate ship clockwise.
<up arrow> - fire thrusters.
<-> - decrease frame delay (speed up game).
<+> - increase frame delay (slow down game).

This game uses line drawing for all the playfield elements. To refresh the playfield each frame, the elements are erased by redrawing them in the background colour before redrawing them in their new positions using the foreground colour. This technique causes some flickering, but otherwise the game is quite playable.

Copyright

All programs and files are Copyright 2013-2016 Gavin Stewart.

You are required to give attribution to the author (Gavin Stewart) for any use of these programs (GPLv3 Section 7b).

Trying to pass off my code as your own in your Elements of Computing classes will result in a cursed life of forever buggy software.

Licence

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/

About

A collection of my Nand2Tetris (Elements of Computing) games and demos.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages