kgabis / chip8

A CHIP-8 and SUPER CHIP emulator in C.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About

A CHIP-8/SUPER CHIP emulator library written in C. Most games should work but there might be some exceptions. Use at your own risk.

Usage

Please see example_sdl2.c for an example SDL2 client.

API should be quite simple and self-descriptive, here's how a theoretical client might look like:

    chip8_t *ch8 = chip8_make();
    if (ch8 == NULL) {
        goto end;
    }

    bool ok = chip8_load_program(ch8, program, program_size);
    if (!ok) {
        goto end;
    }
    
    while (true) {
        chip8_keyboard_input_t input = {};
        get_input(&input);
        int num_ticks = chip8_is_super(ch8) ? 16 : 8;

        for (int i = 0; i < num_ticks; i++) {
            ok = chip8_cpu_tick(ch8, &input);
            if (!ok) {
                goto end;
            }
        }

        if (chip8_should_beep(ch8)) {
            beep();
        }

        for (int y = 0; y < chip8_get_height(ch8); y++) {
            for (int x = 0; x < chip8_get_width(ch8); x++) {
                if (chip8_get_pixel(ch8, x, y)) {
                    draw_pixel(x, y);
                }
            }
        }

        sleep_ms(16);
    }
end:
    chip8_destroy(ch8);

Screenshots

blinky
car
breakout

License

The MIT License (MIT)

About

A CHIP-8 and SUPER CHIP emulator in C.


Languages

Language:C 100.0%