Crate svmap

source ·
Expand description

This crate provides a library to parse SVMap files (*.svmap), used to map/configure memory for emulators. This way emulator memory can be configured with editing a simple and human-readable text document instead of needing to reprogram and recompile an existing emulator.

Using SVMap it is possible to change the memory configuration in a similar way as is done in real life:

Put in an extra ram stick and boot the computer.

(Add “address1 ... address2 -> ram (stick 3)” to a SVMap file)

Example

An example of the memory layout for the MOS6502 CPU:

(Set up memory)
0x0000 ... 0x7FFF -> ram
0x8000 ... 0xFFFF -> rom

(Set up vectors)
@reset_vector = 0xFFFD

This can be parsed in the following manner:

#[derive(Clone)]
enum Region {
    Ram,
    Rom
}

#[derive(Clone)]
enum Vector {
    ResetVector
}

fn parse_region(identifier: &str) -> Result<Region, &str> {
    match identifier {
        "ram" => Ok(Region::Ram),
        "rom" => Ok(Region::Rom),
        _ => Err(identifier)
    }
}

fn parse_vector(identifier: &str) -> Result<Vector, &str> {
    match identifier {
        "reset_vector" => Ok(Vector::ResetVector),
        _ => Err(identifier)
    }
}

// MemoryLayout::from_file( ... ) is also possible.
let ml = MemoryLayout::from_lines(
    "(Set up memory)\n
    0x0000 ... 0x7FFF -> ram\n
    0x8000 ... 0xFFFF -> rom\n

    (Set up vectors)\n
    @reset_vector = 0xFFFD".into(),
    parse_region,
    parse_vector
).unwrap();

Structs

Enums

  • An error that occurred during parsing of a SVMap file.

Type Definitions

  • An unsigned integer used to store the addresses.