Giter VIP home page Giter VIP logo

agnes's Introduction

About

agnes is a NES emulation library written in C with an easy to use API. It consists of only 2 files (agnes.h and agnes.c).

Features

  • Only 2 files (agnes.h and agnes.c).
  • Easy to use.
  • MIT licensed.
  • Supports NROM, UxROM, MMC1 and MMC3 mappers.

API example

agnes_t *agnes = agnes_make();
agnes_load_ines_data(agnes, game_data, game_data_size);
while (true) {
    agnes_input_t input;
    get_input(&input);

    agnes_set_input(agnes, &input, NULL);

    agnes_next_frame(agnes);

    for (int y = 0; y < AGNES_SCREEN_HEIGHT; y++) {
        for (int x = 0; x < AGNES_SCREEN_WIDTH; x++) {
            agnes_color_t c = agnes_get_screen_pixel(agnes, x, y);
            display_pixel(x, y, c);
        }
    }
}
agnes_destroy(agnes);

Full and working examples can be found in examples directory.

Screenshots

Super Mario Bros Super Mario Bros 3 Kirby's Adventure Rad Racer II Contra Donkey Kong

Installation

Run:

git clone https://github.com/kgabis/agnes.git

and copy agnes.h and agnes.c to you source code tree.

Testing

Run run_tests.sh ROM_DIRECTORY (in tests directory) to compile and run tests.

Since I cannot add roms to this project they must be downloaded manually. Please look at contents of examples/recs.tar.gz for names of roms that are required to run tests. Emulator testing roms (such as nestest.nes or official_only.nes) can be obtained from here. If you want to update add a recording or update an existing one run recorder (located in tests dir).

TODO

  • APU emulation.
  • Optimizations.
  • More mappers.
  • Being able to access CPU and PPU state using API.

Splitting and joining

agnes.c can be split into separate files by running utils/split.py:

utils/split.py --input agnes.c --output-path src

It can be joined back into a single file with utils/join.py:

utils/join.py --template utils/agnes.c.templ --path src --output agnes.c

Contributing

I will always merge working bug fixes. However, if you want to add something new to the API, please create an "issue" on github for this first so we can discuss if it should end up in the library before you start implementing it.

Acknowledgements

NesDev Wiki

Other open-source NES emulators, that were extremely helpful as a reference:

Also, many thanks to Mateusz Belicki for all his suggestions and help.

License

The MIT License (MIT)

agnes's People

Contributors

kgabis avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

agnes's Issues

Non mirrored CHR banks causes out of bounds memory access

I created a ROM that can crash the emulator or allow it to access out of bounds memory.

The ROM essentially writes a value from 0 to 255 to the MMC3 CHR banks registers, then increments this value every frame.

If the ROM has just one bank, the expected behavior is for that one bank to be mirrored.

I fixed it in the tool I included agnes in with modulus at the mapper level, but this breaks CHR RAM and doesn't properly respect powers of two for mirroring.

	int modValue = mapper->agnes->gamepack.chr_rom_banks_count*8;
    switch (mapper->chr_mode) {
        case 0: { // R0_1, R0_2, R1_1, R1_2, R2, R3, R4, R5
            mapper->chr_bank_offsets[0] = ((mapper->regs[0]%modValue) & 0xfe) * 1024;
			//similar modulus for all other lines

A real fix would probably be to allocate memory to the next power of two at load (for weird CHR bank values like 3 rather than 4), then AND instead of %

I've attached the ROM (It is homebrew, not commercial):
anim.zip

Why header only?

The concept of NES emulation library is great.
I think release it as a dynamically linked library is good enough, why restrict to header-only?

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.