0% found this document useful (0 votes)
19 views2 pages

Create Interactive Programs in Jack

Nand to tetris

Uploaded by

otseme504
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Create Interactive Programs in Jack

Nand to tetris

Uploaded by

otseme504
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Project 9

In this project you will write a program in Jack: A simple, Java-like, object-based programming
language. This will set the stage for subsequent stages in our journey, in which we will build a Jack
compiler, and a basic operating system.
Objective
The "hidden agenda" of this project is to get acquainted with the Jack language, for two
subsequent landmarks: writing a Jack compiler in projects 10 and 11, and developing a basic
operating system in project 12 (the OS will be written in Jack, just like modern OSs are written in
high-level languages like C++). In addition, you’ll become familiar with the art of writing a program
that combines graphics, animation, and user interaction – a useful skill in and of itself.
Contract
Invent or adopt a simple computer game or some other interactive program, and implement it in
the Jack language. Examples include basic versions of Tetris, Snake, Space Invaders, Sokoban, Pong,
or simpler games like Hangman. More examples (some of them quite ambitious and impressive)
can be viewed in the “Cool Stuff” section of the Nand2Tetris website. Note that you don't have to
create a complete application. For example, you can create a basic version, or part of, some simple
game or cool interaction.
Compiling and Running a Jack Program
0. Create a folder for your program. Let's call it the program folder.
1. Write your Jack program – a set of one or more Jack classes – each stored in a separate
[Link] text file. Keep all these .jack files in the same program folder.
2. Compile the program folder using the supplied Jack compiler. This will cause the compiler
to translate all the .jack classes found in the folder into corresponding .vm files, stored in
the same folder. If a compilation error is reported, debug the program and re-compile until
no error messages are issued.
3. At this point the program folder should contain your source .jack files, along with the
compiled .vm files. To test the compiled program, load the program folder into the supplied
VM emulator. Then run the program in the VM emulator. If you encounter run-time errors
or undesired program behavior, fix the program and go to stage 2.
The Jack OS
Writing Jack programs requires working with the Jack OS, just like writing Java programs requires
working with the Java class library. The Jack OS is a set of libraries that extend the basic language's
capabilities and close gaps between it and the underlying hardware. Here is the Jack OS API, and
the list of OS error codes and their meaning.
We supply two Jack OS implementations: “native”, and “builtin”. The native OS implementation
was written in Jack and was then translated (using a Jack compiler) into the set of eight VM files

[Link] / Copyright © Noam Nisan and Shimon Schocken


stored in the nand2tetris/tools/os folder in your PC. The builtin OS implementation was written in
Java, and is embedded in the VM emulator available in nand2tetris/tools.
Which OS version to use is up to you. The builtin version is faster. The VM emulator does not care
which OS version is used, for the following reason: Suppose you've loaded a program folder into
the VM emulator, and proceeded to execute it. Whenever the emulator detects a call to some
[Link] (e.g. [Link]), it checks if this function is part of the loaded code base; if so, it
executes this function's VM code; otherwise, it reverts to using the built-in implementation of this
OS function.
Resources
You will need the supplied tools/JackCompiler, for translating your program into a set of .vm files,
and the supplied tools/VMEmulator, for running and testing the compiled code.
Bitmap editor: If you develop a program that needs high-speed graphics, it is recommended to
design sprites – repeating graphical images – for fast rendering of the key graphical elements of
your program. Such sprites, along with the Jack code for rendering them, can be designed and
generated, respectively, using this Bitmap Editor, created by Eric Umble. Here is a demo of a Dino
Adventure game that Eric developed with this editor (a simpler desktop bitmap editor, developed
by Golan Parashi, is also available in the nand2tetris/tools folder).
In addition to these resources, you will need resourcefulness – coming up with a compelling idea
for an interactive application or a simple game. This Youtube channel contains examples of "retro"
computer games. You can review it for ideas, as well as for technical tips.
Code example: The projects/9/Square folder includes the source code of a complete, 3-class
interactive Jack program. This program illustrates various programming techniques which are
commonly used in designing applications that combine graphics, animation, and user interaction.
Therefore, it is recommended to read and play with this program before starting to work on your
own program.
Evaluation
In Nand to Tetris courses, the Jack programs that learners write in this project are typically
evaluated along the following criteria: Code quality and documentation (40%), user experience
(50%), and originality (10%). Real cool programs can get an additional 10% bonus.

[Link] / Copyright © Noam Nisan and Shimon Schocken

Common questions

Powered by AI

The compilation of a Jack program involves writing Jack classes stored in individual .jack files within a program folder, which are then compiled into corresponding .vm files using the Jack compiler. This process translates the high-level Jack code into a format understood by the VM emulator. Execution involves loading the compiled program folder into the VM emulator, where it can be run and tested. The Jack OS, which extends the language's basic capabilities and bridges gaps with the hardware, provides necessary libraries for this process, similar to Java's class library. This OS is crucial for executing programs as it handles OS function calls that are not part of the loaded code base .

The "native" Jack OS implementation is written in Jack and translated into VM code using the Jack compiler, while the "builtin" version is written in Java and integrated into the VM emulator. The performance implication is that the "builtin" version typically runs faster in the VM emulator because it uses the Java-based implementation, while the "native" version relies entirely on Jack code execution, which may be slower. The choice between the two depends on user preference, as the VM emulator can switch between them without issues .

Success in Project 9 is typically evaluated based on code quality and documentation, which account for 40% of the assessment, user experience at 50%, and originality at 10%. Programs that are particularly impressive or original may receive an additional 10% bonus. These criteria focus on the ability to write clean, well-documented code, create engaging user experiences, and contribute original ideas to the interactive applications developed .

The VM emulator plays a critical role in executing and testing Jack programs by emulating the target hardware environment, enabling developers to run their compiled .vm files. It interacts with OS implementations by checking if OS function calls are part of the loaded code base; if not, it defaults to executing the builtin Java-based OS functions. This flexibility allows developers to choose between faster builtin implementations or full native execution for comprehensive testing and development .

Exploring the "Cool Stuff" section of the Nand2Tetris website is recommended as it provides examples of successful projects that showcase creative applications of the Jack language. This exposure can inspire developers by offering insights into innovative concepts and solutions, potentially leading to more original and engaging project ideas. Such resources also demonstrate practical implementations of course concepts, which can enhance understanding and provide motivation for developing compelling Jack programs .

Reviewing retro game mechanics from resources like the "RetroGameMechanicsExplained" YouTube channel can support the development of interactive applications in Jack by offering practical insights into classic design patterns and algorithms that are often applicable to modern app development. Understanding these mechanics can inspire innovative game design strategies and enhance the developer's ability to create nostalgic yet functional interactive experiences, leveraging time-tested gameplay concepts .

Creating sprite graphics for Jack programs involves challenges like designing efficient and clear visual assets given limited resolution and color capabilities, ensuring fast rendering for animations, and maintaining consistency across different graphical elements. Strategies to address these include using bitmap editors designed for Jack, like the one by Eric Umble, for precise control over pixel details and performance. Additionally, organizing assets into reusable components and optimizing rendering logic within Jack code can help manage resources effectively and achieve smooth animations .

The main objectives of working with the Jack language in Project 9 include getting acquainted with the language to prepare for writing a Jack compiler in projects 10 and 11 and developing a basic operating system in Project 12. Additionally, the project aims to familiarize learners with combining graphics, animation, and user interaction, which are essential skills for the subsequent tasks of compiler construction and OS development .

By using the Jack language to write an operating system, learners gain a deep understanding of computer system fundamentals, including how high-level languages interact with hardware. It also improves programming skills through practical application of algorithms and data structures within an OS context. This hands-on experience with OS development bridges the gap between theoretical learning and practical implementation, providing a comprehensive grasp of both language features and system design .

Integrating graphics, animation, and user interaction is crucial in developing a Jack program for Project 9 because it mirrors real-world application development where these elements create engaging and functional user interfaces. This integration enhances the user experience, making applications more intuitive and interactive. Additionally, skills in combining these elements are vital for advanced projects in the course, such as building compilers and operating systems that require dynamic and responsive interfaces .

You might also like