Chip-8 emulator.

Over the past two days I’ve been porting a Chip-8 emulator to Unity C#, I was originally writing my own but that quickly got complex very fast so I decided to take the smaller task of just porting it to work within Unity games, note that this is just an educational project and I have taken away from it a lot more knowledge about emulation, lower level coding drawing textures.

This is the result in its current form:):
1206671--48675--$Screenshot.png

Controls:
1234
qwer
asdf
zxcv

Pong:
2 = move paddle up
q = move paddle down
x= other paddle up
c = other paddle down

The rest just play around with it, you will get the gist :smile:
To play click the GUI button of a game, then hit enter to load it.

Todo:
-Perfect framerate(ATM it is to high and games are dificult IMO)
-Make scene with cubes that hold the roms, then make a little in game console :slight_smile:
-Post the code.

Thanks hope you enjoy :smile:

Here is the source code, included are a selection of roms that apparently are fully legal etc.

Haha, very nice work! Made a Chip-8 emulator of my own a few years back but never managed to get it working to 100%, maybe i should port that to Unity as well just for the fun of it : D

Edit: Cant get any of the games to start : /

To start a game you just need to call:

Chip8.LoadProgram(TextAsset,float);

The TextAsset is the rom with the extension .bytes, and float is the clockspeed.

Maybe the script is not working because the directory is kind of changed, try re applying the games to the array games on the chip8 game object.

I mean when i tried the webplayer.
Do you have super chip support? : p

Edit: Missed the part were it said i have to press enter : D
Edit2: I think i found a small bug in your code, when you set the “clockSpeed” you need to have { } after the “if” or things will get strange i think : p

Nah, too hard. This was just a test to see how emulators work… I was thinking of a game much like Notches 0x10c and thought that emulating would be a good idea, but now I think that I still must emulate in some form but mine will be much different. I started wanting to do a full NES emulator inside of Unity but quickly I realised how difficult that would be and thus decided to do the most simple but awesome thing I could find. and this was it :slight_smile:

Though I don’t take credit for this, I admit entirely that it is 95% someone elses work(It is just a line by line conversion of this one and some parts were I got stuck had a look at the C# version on that page)

Fixed :smile:

Reading through that article, it actually tells you to familiarize yourself with bitwise operations before you start as a prerequisite.

Don’t use this project as a way to learn how to program. (If bitwise operations confuse you, study them first)

The wikipedia page linked explains how left shifts and ORs work, with an example in C/C++/C#. You should’ve known way ahead of time what the operators were.

The author says in plain English that he used a left shift followed by an OR.

So what did actually happen?
First we shifted … left 8 bits, which adds 8 zeros.

Next we use the bitwise OR operation to merge them.

The fact that, after being told explicitly what the code did and being told to learn how to use bitwise operators, you still needed someone to convert the line tells me that you should focus more on learning line by line what the code actually does, rather than what it’s equivalent is in another language. Especially when it’s almost exactly the same in C#.

Do note that I have no ill intent in posting this, just a friendly reminder to actually do the prerequisites of a project before you start, since from your previous questions about this project show that you probably didn’t. I’ve been programming for less than two years and I read through K&R, Programming iOS 5 and am working my way through C# in a Nutshell. It’s not a big list, and I could’ve learned a lot faster, but I felt it was important to get grounded in the basics.

Other than that, nice job. It’s good to take on different projects to broaden your field of knowledge. :slight_smile:

Nooo, seems like i have deleted my old Chip8 emulator : (

Indeed, I didn’t read that part.

Noooooo! Thats a shame :frowning:

I started a new one instead ; )

Cool, in Unity?

EDIT: Congrats on 1000 posts :slight_smile:

Very cool, you’ve come a long way.