A Jack Virtual Machine running on the Web

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

A Jack Virtual Machine running on the Web

jconnell
Hello,

It looks as if many people who work through book or Coursera course put a lot of effort into their Chapter 9 projects. I know I did. I thought it'd be nice to be able to share Jack programs we've written directly on the web without requiring viewers to download the SDK. With that in mind, I've been working a Jack virtual machine that runs on the web.

Here are two demo of the Jack VM running the pong game, and the Space Invaders clone I created for my chapter 9 project.

Screenshot:


The VM has a couple of features so far:
- It runs .vm files from the SDK's Jack compiler (with or without OS files bundled).
- It supports all instructions, keyboard and screen I/O.
- On larger screens, it displays the screen at 2x resolution.
- The majority of it's implemented in WebAssembly, so it should have good support for desktop browsers.

Because this project targets the web, there are some neat possibilities with this:
- We could include Jack programs in any webpage with a 1-line include + some simple JavaScript for configuration.
- Instructors could make interactive slides by combing it this with something like reveal.js
- An interactive gallery of working Jack programs rather than static screenshots.
- Some day, maybe even a full-fleged Nand2Tetris "IDE" like the Web Assembly studio https://webassembly.studio.

What's Next?
- Tweak the VM execution speed so that it runs reasonably consistently across computers.
- Package up the player so that it can be included on any webpage with one line of JavaScript.
- Add an integrated Jack compiler so the player can load Jack programs from an HTML textarea.

The source is available on GitHub if you're curious. The source is a bit of a mess, but the test suite is pretty thorough. I'll be cleaning the code and organization up as I implement the next set of features.

Hope you like it!

Jim
Reply | Threaded
Open this post in threaded view
|

Re: A Jack Virtual Machine running on the Web

ivant
Amazing job!
Reply | Threaded
Open this post in threaded view
|

Re: A Jack Virtual Machine running on the Web

WBahn
Administrator
In reply to this post by jconnell
Very nice.

I could really envision taking the kind of things you are doing and integrating them into follow on courses in a CS curriculum. Imagine taking the N2T program and then taking a hardware course in which you implement the CPU in and FPGA and add in the peripherals to support the keyboard and screen physically but all add in a file system (probably on a SD card) and an interrupt system and a timer and a serial UART and modify the CPU to support them and then update the toolchain as needed. Another course on web programming could do what you are doing. A network communications course could add implement a network stack for a very simple network consisting of all of the Hack computers in the class. For the full versions of several classes, such as architecture, compiler, and operating systems, you could expand the hardware to support a larger register bank (so that you can do things like register scheduling in the compiler course) and pipelining and implement a simple version of what we would recognize today as an operating system with pre-emptive multitasking.

The problem would be getting all of the people in a CS department to get on board and give up some of the autonomy that is so dear and precious to many in academia.
Reply | Threaded
Open this post in threaded view
|

Re: A Jack Virtual Machine running on the Web

jconnell
That integrated curriculum sounds exactly like what I've been working through on my own. I think that'd be a really nice curriculum from a student perspective. What I appreciate about the N2T and the "more fun to go" section is there are so many places you can explore. The platform though fairly simple is powerful enough to do interesting things.

I chose this project because ultimately I wanted to work on some extensions for VS Code, but I don't have a lot of experience with front-end web or Web Assembly.

I'll likely tackle a Hack implementation in FPGA at some point this year.