1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
/*!
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:
```txt
(Set up memory)
0x0000 ... 0x7FFF -> ram
0x8000 ... 0xFFFF -> rom
(Set up vectors)
@reset_vector = 0xFFFD
```
This can be parsed in the following manner:
```rust
# use svmap::{ MemoryLayout, Error };
#[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)
}
}
# fn main() {
// 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();
# }
```
*/
mod memory_region;
mod memory_layout;
mod address_vector;
mod error;
pub use crate::memory_region::*;
pub use crate::memory_layout::*;
pub use crate::address_vector::*;
pub use crate::error::*;
/// An unsigned integer used to store the addresses.
// If needed for whatever reason in the future, this type can be changed to any unsigned integer
// type (u8, u16, u32, u64, u128).
pub type AddressType = u64;