Workshop In Computer Construction - From Nand to Tetris
Project 9 - The High Level Language
Deadline May 12, 2003 at midnight
Description

Objectives: The major objective of this project is to get acquainted with the Jack language, for two purposes. First, you have to know Jack intimately in order to write the Jack compiler in Projects 10 and 11. Second, you have to be familiar with Jack's supporting libraries in order to write the computer's operating system in Project 12. The best way to gain this knowledge is to write a Jack application.

The contract: Adopt or invent an application idea, e.g. a simple computer game or some other interactive program. Then specify and build the application.

Running and compiling your Jack program

  1. Download the OS.zip file and extract its contents to a directory named project9 on your computer (you may want to give this directory a more descriptive name, e.g. the name of your program). The resulting set of .vm files constitute an implementation of the computer's operating system, including all the supporting Jack libraries.
  2. Write your Jack program (set of one or more Jack classes) using a plain text editor. Put each class in a separate ClassName.jack file. Put all the .jack files (of the same program) in the same program directory described in step 1.
  3. Compile your program using the supplied Jack Compiler. This is best done by applying the compiler to the name of the program directory. This will cause the compiler to translate all the .jack classes in that directory to corresponding .vm files. If a compilation error is reported, debug the program and re-compile until no error messages are issued.
  4. At this point, the program directory should contain three sets of files:
    1. Your source .jack files
    2. A compiled .vm file for each one of your source .jack files
    3. The supplied operating system .vm files
    To test the compiled program, invoke the VM Emulator and direct it to load the program by selecting the program directory name. Then execute the program. In case of run-time errors or undesired program behavior, fix the program and go back to stage 3.

Your Game: The game that you have to write should be similar to the Square Dance game (see below), and perhaps more sophisticated. As a general guideline, the hardware and software that we developed so far can be used to produce games at a level of sophistication similar to that of cellular phone games, like Snake. Your grade will reflect the complexity of your game. The more sophisticated your game, the more points you'll get.

Square Dance: This simple interactive game allows the user to move a square around the screen. The user can also change the square size during the movement.

When the program starts running, a square of size 30 by 30 pixels is placed at the top left corner of the screen. The program then listens, and responds to, the following keyboard keys:

  • right arrow: move the square to the right;
  • left arrow: move the square to the left;
  • up arrow: move the square up;
  • down arrow: move the square down;
  • x: increment the square size by 2 pixels;
  • z: decrement the square size by 2 pixels;
  • q: quit the game.
Movement speed: to control it, you can change the delay constant in the moveSquare method in class SquareGame.

Listening to the keyboard and drawing on the screen is done by OS methods invoked by the program.

This program looks rather simple but, hey -- it runs on a computer hardware, and involves three different programming languages, that we built from scratch during this course! When this square moves on the screen, about 2 million hardware and software objects interact with each other, and you have full control over every one of them.

Source:

  • Main.jack: a Jack class that initializes the square game and starts it.
  • Square.jack: a Jack class that implements a graphical square object. The square has properties (fields) x-location, y-location, and size. It also has several methods for drawing, erasing, and moving around the screen.
  • SquareGame.jack: a Jack class that puts the square in the top left corner of the screen, and then responds to a set of pre-defined keyboard events by moving the square on the screen.
SquareDance source is also available as zip file.

Requirements: You should submit the .jack sources of your game / application, as well as a detailed README explaining how to play with your game or activate your application. In addition, you should write how you implemented it, main algorithm and everything else you think the grader should know.

Grades and bonuses: The grade will be given according to the game / application quality and sophistication (Meaning - a working application does not give you the full grade automatically). In addition a 20 points bonus will be shared among the top 5 games / applications.

Submission Submit a tar file (created by `tar cvf`) contains all your source files (well documented !) and a README.
Resources
  • OS.zip - The operating system.
  • Chapter 9 of the book - "The High Level Language".
  • VM Emulator Tutorial (PPS,HTML,Software)
  • Guidelines.