# Look mom, a CHIP8 CPU being emulated in Node RED

**URL:** https://discourse.nodered.org/t/look-mom-a-chip8-cpu-being-emulated-in-node-red/83206
**Category:** Share Your Projects
**Tags:** fun
**Created:** [26 November 2023 19:28 UTC](https://discourse.nodered.org/t/look-mom-a-chip8-cpu-being-emulated-in-node-red/83206 "2023-11-26T19:28:28Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [2 December 2023 17:17 UTC](https://discourse.nodered.org/t/look-mom-a-chip8-cpu-being-emulated-in-node-red/83206/4 "2023-12-02T17:17:35Z")

</div>

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 😃
- Now renders Audio - square wave only. YES!!! audio is now rendered
- Reduce the use of `function` nodes where possible (@TotallyInformation😉 )

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](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 😉

Enjoy.

Keys for Space Invaders as example.

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

 ![Screenshot 2023-12-02 at 17.08.26](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/c/bc7a117044847b8149f1973c9cb085d009ec97b8.png)

 ![Screenshot 2023-12-02 at 17.13.45](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6b67f18fa7657ad9fb8a1eac1e9515a2dc7dd37c.png)

**Flow**

[flows-2.json](https://discourse.nodered.org/uploads/short-url/wQZibm24GL12UKkw08MGktDGsTk.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.

> [@\[Fun Exercise\]Make an MQTT broker in Node-RED](https://discourse.nodered.org/t/fun-exercise-make-an-mqtt-broker-in-node-red/82229):
>
> For fun, I thought - let's build an MQTT broker in Node-RED! slight_smile Anyway, I soon realised that I didn't know how to setup the TCP nodes properly - I often get confused by them frowning Can someone clue me in on what I should stick in the TCP in/out nodes (or whether I should be using the TCP request one instead?) Image of my initial flow idea (plan on using port 2883)

Have a great weekend!

---

_[View the full topic](https://discourse.nodered.org/t/look-mom-a-chip8-cpu-being-emulated-in-node-red/83206)._
