#memory #emulator #parse #vector #file #map

svmap

A library to parse SVMap, used to map memory for emulators

5 unstable releases

0.3.0 Jun 10, 2023
0.2.1 Jun 5, 2023
0.2.0 Jun 5, 2023
0.1.1 May 28, 2023
0.1.0 May 28, 2023

#321 in Emulators

36 downloads per month

MIT license

25KB
477 lines

SVMap

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.

Example of a SVMap file:

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

(Set up vectors)
@reset_vector = 0xFFFD

See lib.rs for more information.


lib.rs:

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();

Dependencies

~2–3MB
~54K SLoC