Estus-Dev / chip-8-database-rs

Easily access the CHIP-8 Database from Rust projects
MIT License
0 stars 0 forks source link

Unable to get extra data #4

Open Naginipython opened 9 months ago

Naginipython commented 9 months ago

As one can guess, I am trying to make a Chip-8 emulator in Rust, and I learned of this crate to easily receive the chip-8 database, so I don't have to worry much about the 'quirks' field for a title. However, even when I include the "extra-data" feature, my metadata doesn't include Quirk data. It does appear to show 'program' field correctly, from metadata. I'm unsure if I am missing something, or if the way to get Quirk data is more complicated than I'm seeing, or if this really is an issue. Cargo.toml:

...
[dependencies]
chip8_db = { version = "2.1.0", features = ["extra-data"] }
minifb = "0.25.0"
minifb_fonts = "0.1.3"
rand = "0.8.5"

lib.rs

use std::{fs::File, io::Read, process};
use chip8_db::Database;
...
pub fn load_rom(&mut self, game: &str) {
    let mut file = File::open(game).unwrap();
    let mut data = Vec::new();
    if let Err(e) = file.read_to_end(&mut data) {
        eprintln!("Error: {e}");
        process::exit(1);
    }

    let db = Database::new();
    let metadata = db.get_metadata(&data);
    println!("{metadata:?}");
    ...
}

And lastly, my metadata with INVADERS:

Metadata { hash: "f100197f0f2f05b4f3c8c31ab9c2c3930d3e9571", program: Some(Program { title: "Space Invaders", description: Some("Space Invaders (1978), by David Winter\n\nThe well known game. Destroy the invaders with your ship. Shoot with 5, move with 4 and 6. Press 5 to begin a game."), release: Some("1996"), origin: None, copyright: None, license: None, authors: Some(["David Winter"]), images: None, urls: None, roms: {"f100197f0f2f05b4f3c8c31ab9c2c3930d3e9571": Rom { file_name: Some("Space Invaders [David Winter] (alt).ch8"), embedded_title: None, description: None, release: None, platforms: [Superchip], quirky_platforms: None, authors: None, images: None, urls: None, tickrate: None, start_address: None, screen_rotation: None, keys: Some({P1A: 5, P1Left: 4, P1Right: 6}), touch_input_mode: None, font_style: None, colors: None }, "5c28a5f85289c9d859f95fd5eadbdcb1c30bb08b": Rom { file_name: Some("Space Invaders [David Winter].ch8"), embedded_title: Some("SPACE INVADERS 0.91 By David WINTER"), description: None, release: None, platforms: [Superchip], quirky_platforms: None, authors: None, images: None, urls: None, tickrate: None, start_address: None, screen_rotation: None, keys: Some({P1Left: 4, P1Right: 6, P1A: 5}), touch_input_mode: None, font_style: None, colors: None }} }), rom: Some(Rom { file_name: Some("Space Invaders [David Winter] (alt).ch8"), embedded_title: None, description: None, release: None, platforms: [Superchip], quirky_platforms: None, authors: None, images: None, urls: None, tickrate: None, start_address: None, screen_rotation: None, keys: Some({P1A: 5, P1Left: 4, P1Right: 6}), touch_input_mode: None, font_style: None, colors: None }) }
Estus-Dev commented 9 months ago

Thanks for pointing this out, I hope your CHIP-8 project is going well otherwise.

After refreshing my memory of what's going on here: This is due to how the CHIP-8 DB upstream is laid out. On this package's side I should update the docs with clearer instructions for this use case.

In the CHIP-8 DB schema, each ROM mainly gets its quirks from the platforms field. That ties back to platforms.json which contains a quirks dictionary.

So for most ROMs, you can just enable the quirks based on the platform and you're done. For instance if the platform is originalChip8 then the quirks would be:

"quirks": {
    "shift": false,
    "memoryIncrementByX": false,
    "memoryLeaveIUnchanged": false,
    "wrap": false,
    "jump": false,
    "vblank": true,
    "logic": true
}

There are a couple of ROMs out there which don't quite adhere to these platform definitions, in which case you'll find the quirkyPlatforms field has what you need to run that software. Anything specified in this field should override the platform's default quirks.

Naginipython commented 9 months ago

I am aware of how the chip8 database is structured, I was just confused about how to use the crate to receive the data from the database. I didn't quite understand what the feature "extra-data" does here, I had assumed it would allow for your example on README to also contain the fields "quirks" and "platforms", though, I'm realizing now that it would instead be in the database struct itself, not the metadata. With that realization, I'd like to suggest a feature for the crate, within metadata, if the feature of "extra-data" is added, can it also contain the quirks for the specific ROM, for the programmer to have quick access to modify their chip8 CPU? The current functionality of the SHA1 comparing is very nice.