Code Monkey home page Code Monkey logo

chip-emul8's Introduction

Chip-Emul8

My first little emulator of a Chip-8

The Idea

So I first decided to code this Chip-8 emulator around a week ago as I've really wanted to get into emulation and as far as I was aware - writing one is the best way to learn about it. And I can definitely agree. I learnt a lot when going through this and searching the net for info, how to do certain things, using libraries etc and it has all been a great experience. The plan was that this would introduce me to the basics of emulation so I can progress to coding a Gameboy DMG-01 emulator... eventually.

What I Did

I started where most people probably would: how to code a chip 8 emulator search in Google. I found the multigesture post linked at the bottom and I got going. I modelled the CPU, added the emulators basic functions and it was all good. I then tweaked around with some of the modelling for example using the header so I could model the registers as uint8_t rather than unsigned char. These little things just made it a bit easier to understand and keep track of everything. After that I went on to begin decoding the opcodes using the Cowgod's technical reference linked down below (as best as I could) and then took a look at a couple of the other emulators down below as reference on some of the instructions I was unsure about. When I finished writing them for the first time and had fixed the small syntax errors etc. I ran the program and it was fine! I couldn't believe that it actually worked (wasn't what I was expecting but then again there are only 36 instructions). I went on to looking at how I was going to draw the graphics. From what I had looked up I was either going to use SDL2 or GLUT. After playing round with both I decided to go with GLUT - primarily because it ships with OSX but also because it just seemed a bit easier to setup and initialise. To draw the graphics on screen was fairly simple as the Chip-8 has monochrome graphics and a 64 x 32 pixel display. Just iterate through my screen array and draw the pixels. On first run the picture was a mess. So I spent around an hour going back through my opcodes optimising some and correcting others and now that is all done so here we have the Chip-Emul8.

Plans

The only thing I have planned for now is to implement sounds, that's it.

Screenshots

Mac

Linux

How To Use It

Currently I've only tested this on Mac and I believe you have to download GLUT on other OSs. First off, download the repo and open it up. Navigate to the directory and run

Mac

FYI: If you have updated to sierra, some of the GLUT library has been fully deprecated and so will no longer compile.

```make build```

After that, to use the emulator type

```./ch8 ./```

Controls... I'm not exactly sure as to the controls for all the games but the keys will be one of: 1, 2, 3, 4, q, w, e, r, t, y, a, s, d, f, z, x, c, v. To quit the emulator press esc.

Windows

To be done..

Linux

Exact same as Mac.

Feel free to use the code so long as you give credit to me.

Here are some useful links:

About the CHIP-8:

https://en.wikipedia.org/wiki/CHIP-8#Virtual_machine_description

Chip-8 Opcodes:

http://devernay.free.fr/hacks/chip8/C8TECH10.HTM

Writing an emulator:

http://www.multigesture.net/articles/how-to-write-an-emulator-chip-8-interpreter/

http://mattmik.com/files/chip8/mastering/chip8.html

http://emulator101.com/

http://fms.komkon.org/EMUL8/HOWTO.html

ROMS:

http://www.zophar.net/

Reading in files as byte arrays:

http://www.linuxquestions.org/questions/programming-9/c-howto-read-binary-file-into-buffer-172985/

Some other good emulators:

https://github.com/eshyong/Chip-8-Emulator

https://github.com/bryangarza/chip8

https://github.com/prophittcorey/iC8

chip-emul8's People

Contributors

shnupta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

chip-emul8's Issues

Building on Linux

I am very new to C development as well as this being my first Issue on github, so be patient with me if I did anything wrong.

I had to install the libraries libsdl2-mixer-dev and freeglut3-dev

I had to make a minor change to cpu.c, changing from this:
#include <SDL2_mixer/SDL_mixer.h>
to this:
#include <SDL2/SDL_mixer.h>

As well as a minor change to ch8.c, changing this:
#include <GLUT/glut.h> to #include <GL/glut.h>

And this is the command I used to compile (I'm not yet familiar enough with make):
gcc ch8.c cpu.c -std=c99 -lGLU -lGL -lglut -lSDL2_mixer -o ch8

I was hoping to build it without any changes to source, but I couldn't see any other way.
Does it still build on Mac with that minor change? or if it doesn't, is there a way to include both statements?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.