summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2020-03-04 03:17:25 +0300
committerOxore <oxore@protonmail.com>2020-03-04 03:19:16 +0300
commit7d4dfd8af842796c4eb8a88df0cc5ab30f99232d (patch)
tree826f7b9453aa30ab18de73f97b18a6bb83b70734
parent0a6fad82f83d7a79aa7eadf73a21e6e80c8e810d (diff)
Rename Core to Cpu8051 and Ram to ProgramMemory, etc.
Adjust Readme.md
-rw-r--r--Readme.md4
-rw-r--r--src/cpu8051.rs (renamed from src/core.rs)12
-rw-r--r--src/main.rs26
-rw-r--r--src/progmem.rs (renamed from src/rom.rs)8
4 files changed, 25 insertions, 25 deletions
diff --git a/Readme.md b/Readme.md
index 9f2c932..6b8af9e 100644
--- a/Readme.md
+++ b/Readme.md
@@ -12,9 +12,9 @@
- At least one I/O Port (P0)
- Timer (with interrupts)
- Serial UART (with interrupts)
-- Cycle accurate emulation of program execution with synchronization of all the
+- Cycle accurate emulation of program execution and synchronization with all
peripherals.
-- Can bind execution speed to real host machine time with speed multiplier (e.g.
+- Locking execution speed to real host machine time with speed multiplier (e.g.
1 instruction per second, 1000 cycles per second).
- Every peripheral produces event with information of it's state if it changes.
CPU produces events on each step while in single step mode or when pause
diff --git a/src/core.rs b/src/cpu8051.rs
index 992f12c..2a0fbe8 100644
--- a/src/core.rs
+++ b/src/cpu8051.rs
@@ -1,5 +1,5 @@
use crate::memory::Memory;
-use crate::rom::Rom;
+use crate::progmem::ProgramMemory;
use std::fmt;
#[derive(Debug, Clone, Copy)]
@@ -78,10 +78,10 @@ pub struct Op {
operand3: Option<Operand>,
}
-pub struct Core {
+pub struct Cpu8051 {
pc: u16,
ram: [u8; u8::max_value() as usize + 1],
- progmem: Rom,
+ progmem: ProgramMemory,
extmem: [u8; u16::max_value() as usize + 1],
}
@@ -392,7 +392,7 @@ impl IncompleteOp {
}
}
-impl Core {
+impl Cpu8051 {
/// Constructor
pub fn new() -> Self {
let mut ram = [0; u8::max_value() as usize + 1];
@@ -401,12 +401,12 @@ impl Core {
Self {
pc: 0,
ram,
- progmem: Rom::new(),
+ progmem: ProgramMemory::new(),
extmem: [0xFF; u16::max_value() as usize + 1],
}
}
- pub fn rom(mut self, rom: Rom) -> Self {
+ pub fn rom(mut self, rom: ProgramMemory) -> Self {
self.progmem = rom;
self
}
diff --git a/src/main.rs b/src/main.rs
index b23d31d..f43a33e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,12 +7,12 @@ use std::sync::mpsc::{channel, Receiver, Sender};
use std::thread;
use std::time::Duration;
-mod core;
+mod cpu8051;
mod memory;
-mod rom;
+mod progmem;
-use self::core::Core;
-use self::rom::Rom;
+use self::cpu8051::Cpu8051;
+use self::progmem::ProgramMemory;
enum Control {
Run(bool),
@@ -25,16 +25,16 @@ struct BoundController {
_rx: Receiver<SimData>,
}
-struct BoundCore {
+struct BoundEmu {
_tx: Sender<SimData>,
rx: Receiver<Control>,
}
-fn new_bound_pair() -> (BoundCore, BoundController) {
+fn new_bound_pair() -> (BoundEmu, BoundController) {
let (tx_c, rx_c): (Sender<Control>, Receiver<Control>) = channel();
let (tx_d, rx_d): (Sender<SimData>, Receiver<SimData>) = channel();
(
- BoundCore {
+ BoundEmu {
_tx: tx_d,
rx: rx_c,
},
@@ -76,7 +76,7 @@ fn new_controller(name: &str) -> Result<&dyn Fn(BoundController), i32> {
}
}
-fn core_worker(mut core: Core, bound: BoundCore) {
+fn emu_worker(mut cpu: Cpu8051, bound: BoundEmu) {
let mut should_stop = false;
loop {
if should_stop {
@@ -86,8 +86,8 @@ fn core_worker(mut core: Core, bound: BoundCore) {
}
}
} else {
- println!("0x{:08x}: {}", core.pc(), core.op());
- core.step();
+ println!("0x{:08x}: {}", cpu.pc(), cpu.op());
+ cpu.step();
if let Ok(msg) = bound.rx.recv_timeout(Duration::from_millis(1000)) {
match msg {
Control::Run(run) => should_stop = !run,
@@ -134,7 +134,7 @@ fn main() {
let data =
fs::read_to_string(filename).unwrap_or_else(|_| panic!("Unable to read file {}", filename));
- let core = Core::new().rom(match Rom::from_hex(data) {
+ let cpu = Cpu8051::new().rom(match ProgramMemory::from_hex(data) {
Ok(value) => value,
Err(err_string) => {
println!("{}", err_string);
@@ -142,11 +142,11 @@ fn main() {
}
});
- /* Run core worker and controller */
+ /* Run cpu worker and controller */
let (bound_core, bound_controller) = new_bound_pair();
- core_worker(core, bound_core);
+ emu_worker(cpu, bound_core);
thread::spawn(move || {
let controller = {
diff --git a/src/rom.rs b/src/progmem.rs
index 82775a4..325eab1 100644
--- a/src/rom.rs
+++ b/src/progmem.rs
@@ -1,11 +1,11 @@
use crate::memory::Memory;
use std::fmt;
-pub struct Rom {
+pub struct ProgramMemory {
array: [u8; u16::max_value() as usize + 1],
}
-impl fmt::Debug for Rom {
+impl fmt::Debug for ProgramMemory {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut v: Vec<char> = vec![];
for (c, x) in self.array.iter().enumerate() {
@@ -83,7 +83,7 @@ impl HexLine {
}
}
-impl Rom {
+impl ProgramMemory {
/// Empty constructor
pub fn new() -> Self {
Self {
@@ -125,7 +125,7 @@ impl Rom {
}
}
-impl Memory<u16> for Rom {
+impl Memory<u16> for ProgramMemory {
fn get(&self, a: u16) -> u8 {
self.array[a as usize]
}