Look mom, a CHIP8 CPU being emulated in Node RED

Yup you herd me!

So...

It does not have Input (if someone is daring enough to add it - manipulating the registers, I think is the key) or Beeps, and it requires that you install the canvas package for Node JS.
This package requires the following libs

  • build-essential
  • libcairo2-dev
  • libpango1.0-dev
  • libjpeg-dev
  • libgif-dev
  • ibrsvg2-dev

This is to enable out-of-browser canvas's

I use the canvas package inside the Render Video and Pixel Buffer nodes

I also use node-red-contrib-image-tools to display the video

  • Deploy
  • Load the invaders ROM (public domain) - there are a few on the web for CHIP8
  • Click Start

The CPU executes various writes to the pixel buffer, and I wait for 80ms after the last write before rendering a frame - this seems to be a good middle ground for smooth video.

I print out the current executing Opcode and Args for that operation (just to feel like a real nerd :nerd_face: )

Anyway this was fun - so enjoy
I'm sure some optimisations/improvements can be had

flows.json (30.7 KB)

Nov-26-2023 19-06-31

EDIT

I forgot to credit the original code that helped me write it.

Based of : GitHub - taniarascia/chip8: 🎮 ‎ A Chip-8 emulator written in JavaScript for web, CLI, and native UI.
Reference : CHIP-8 - Wikipedia

8 Likes

You are crazy :slight_smile:

1 Like

Its the Discord community I hang around with :wink:

2 Likes

So....

For those monitoring this:

  • Pointless
  • Silly
  • But Crazy achievement in Node RED

If not following: What has been achieved here, is Emulating A CHIP8 Console CPU with Node RED only
It's now become quite a project of mine, and has become an almost Full CHIP8 Console.

The following changes/break throughs have been made since I last posted:

  • No longer needs ANY external lib/Node RED Module
  • The rendering is now achieved with a Native Canvas object in a browser window (HTTP IN)
    • I have employed a type of RFB to send pixel changes over a web socket to the Browser window
  • Now Supports Input. YES!!! you can now play the games :smiley:
  • Now renders Audio - square wave only. YES!!! audio is now rendered
  • Reduce the use of function nodes where possible (@TotallyInformation :wink: )

This started as a fun time waster, and I quickly realised what has been achieved here...
A CPU Stack being emulated / Run inside a Node RED flow!

It's pretty crazy to think, you can see the CPU being executed in a flow.

  1. Import The flow (again, no external libs or Node RED modules are needed - its using all core nodes)
  2. Deploy
  3. On a new browser tab - Go to http://x.x.x.x:1880/chip8
  4. Click the title (this is to allow audio to be played - most browsers require interaction for audio to be allowed) - the video panel should go black
  5. Go back to the flow editor, Inject your chosen ROM (I have included 2)
  6. Inject Start

There are some CPU instructions that I need to fix - but mostly its playable.
To load a new ROM - you have to redo the above steps (you might need to disable/enable the flow - Hey it's a Console being emulated in Node RED, give me a break :wink:

Enjoy.

Keys for Space Invaders as example.

W - Start new Game / Fire
Q - Move Left
E - Move Right

Flow

flows-2.json (33.4 KB)

This whole thing started when @cymplecy implemented an MQTT Broker in Node RED - so wanted to push the bounderies of what is possible after seeing his work.

Have a great weekend!

4 Likes

Small Update

  • I have updated the CPU Clock - it now runs a lot faster
  • You can now load a new ROM without reinitializing everything
    Just be sure to inject Start after loading a new ROM - and to follow the initial Init routine above

Dec-03-2023 11-27-33

Flow
flows-3.json (33.7 KB)

1 Like

Keys for Space Invaders as example.

W - Start new Game / Fire
Q - Move Left
E - Move Right

I was about to write something very positive about your work, but then i realised what abomination of inputs you used. How dare you to ignore the mighty WASD?! :rofl:

1 Like

You can probably change it all.
But the array in the page Node for the map will need updating + maybe updating the CPU instruction for Input. It's shifting bits based on the index

it was based on the work here: GitHub - taniarascia/chip8: 🎮 ‎ A Chip-8 emulator written in JavaScript for web, CLI, and native UI.

1 Like