Giter VIP home page Giter VIP logo

chip-8-emulator's Introduction

chip-8-emulator

This Chip-8 emulator is implemented in C, leveraging the RayLib library for graphical and input handling capabilities.

Table of Contents

Introduction

Chip-8 is a simple, interpreted, programming language which was first used on some do-it-yourself computer systems in the late 1970s and early 1980s.

The Chip-8 Emulator project is my way of paying homage to early video games and learning more about how computers work. Chip-8 is an old and basic computer system from the late 1970s and early 1980s. It was used for simple games and programs on early computers.

I decided to create this emulator to have fun and to understand the basics of computer systems. Making the Chip-8 games run on modern computers helps us appreciate the history of gaming and how computers have evolved. During this project, I've learned about how computer instructions are translated, how memory works, and how pictures are drawn on the screen.

Along this project I have learned a lot including but not limited to:

  • Writing and understanding a 8-bit and 16-bit hex dump
  • How to disassemble and decode an opcode into instructions a CPU can use
  • How a CPU can utilize memory, stack, program counters, stack pointers, memory addresses, and registers
  • How a CPU implements fetch, decode, and execute

I hope my version of the Chip-8 emulator can easy to easily understood by beginners, as I have tried my outmost effort to write easy-to-understand code, and for this is the reason for me deciding to utilize RayLib, as it's an easy graphical library.

Getting Started

To be able to build the emulator you will need to install RayLib.

1. Clone the repository:

git clone https://github.com/khaledmust/chip-8-emulator.git

2. Navigate to the project directory

cd chip-8-emulator

3. Compile and run the game by providing the ROM name and path

make

./output ./roms/ROM_NAME

Usage

The Chip-8 keypad has been mapped to the following keys:

Keypad                   Keyboard
+-+-+-+-+                +-+-+-+-+
|1|2|3|C|                |1|2|3|4|
+-+-+-+-+                +-+-+-+-+
|4|5|6|D|                |Q|W|E|R|
+-+-+-+-+       =>       +-+-+-+-+
|7|8|9|E|                |A|S|D|F|
+-+-+-+-+                +-+-+-+-+
|A|0|B|F|                |Z|X|C|V|
+-+-+-+-+                +-+-+-+-+

Technical Implementation

Chip-8 Memory Layout

chip-8 memory layout

Chip-8 Instructions

The Chip-8 has 36 different instructions, including math, graphics, and flow control functions. All the instructions are 2-bytes long and are stored in the most-significant-byte first.

All those instructions are implemented in the chip8.c file.

The emulator starts by calling chip8_parse_code function, this function first parses 8-bits of opcode and then increment the PC to point to the next 8-bits opcode which is thenOR to the previous one to form 16-bits instruction.

chip-8 parsing opcode

Then the function chip8_inst_emulate is called which executes the opcode by first, calling an array of function pointer, then, executing the function the corresponds to the extracted nibble from the opcode.

chip-8 instruction table

Screenshots

License

This project is open source and available under the MIT License.

chip-8-emulator's People

Contributors

khaledmust avatar

Watchers

 avatar

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.