Virtual Integrated Circuits

Changelog

This library is a Integrated Circuit Emulator backend that can simulate interractions between multiple chips.

You start by creating a Board, and then you add Traces or Sockets, and then you plug Chips and link Pins together to form a virtual circuit. You can then run the circuit to emulate the chips and links between them.

This library is a Backend emulator, it means that there is no interface (yet) to create boards. It'll only emulate chips.

Chips

example usage

```rust use virtic::chip::gates::GateAnd; use virtic::chip::generators::Generator; use virtic::chip::Chip; use virtic::{Board,State}; use std::time::Duration;

fn main() { // create a board let mut board = Board::new(); // place sockets with chips on the board let gen = board.newsocketwith(Box::new(Generator::new())); let andgate = board.newsocketwith(Box::new(GateAnd::new())); // place traces { // VCC let trc = board.newtrace(); trc.borrowmut().connect(gen.borrowmut().getpin(Generator::VCC).unwrap()); trc.borrowmut().connect(andgate.borrowmut().getpin(GateAnd::VCC).unwrap()); } { // GND let trc = board.newtrace(); trc.borrowmut().connect(gen.borrowmut().getpin(Generator::GND).unwrap()); trc.borrowmut().connect(andgate.borrowmut().getpin(GateAnd::GND).unwrap()); } { // link pin "A&B" to pin "C" let trc = board.newtrace(); trc.borrowmut().connect(andgate.borrowmut().getpin(GateAnd::AANDB).unwrap()); trc.borrowmut().connect(andgate.borrowmut().getpin(GateAnd::D).unwrap()); } // run the board to update its state // we simulate 1 second segmented by 100 milliseconds board.runduring(Duration::fromsecs(1), Duration::frommillis(100)); // test the chip println!("ABC:\tA&B\tA&B&C"); let ab = andgate.borrowmut().getpinstate(GateAnd::AANDB).asbool(); println!("000:\t{}\t{}", ab, andgate.borrowmut().getpinstate(GateAnd::CANDD).as_bool());

// set some pins manually and test the result
and_gate.borrow_mut().set_pin_state(GateAnd::A, &State::High);
and_gate.borrow_mut().set_pin_state(GateAnd::B, &State::High);
and_gate.borrow_mut().set_pin_state(GateAnd::C, &State::Low);
board.run_during(Duration::from_secs(1), Duration::from_millis(100));

let a_b = and_gate.borrow_mut().get_pin_state(GateAnd::A_AND_B).as_bool();
println!("110:\t{}\t{}", a_b, and_gate.borrow_mut().get_pin_state(GateAnd::C_AND_D).as_bool());


and_gate.borrow_mut().set_pin_state(GateAnd::C, &State::High);
board.run_during(Duration::from_secs(1), Duration::from_millis(100));

let a_b = and_gate.borrow_mut().get_pin_state(GateAnd::A_AND_B).as_bool();
println!("111:\t{}\t{}", a_b, and_gate.borrow_mut().get_pin_state(GateAnd::C_AND_D).as_bool());


and_gate.borrow_mut().set_pin_state(GateAnd::A, &State::Low);
and_gate.borrow_mut().set_pin_state(GateAnd::B, &State::Low);
and_gate.borrow_mut().set_pin_state(GateAnd::C, &State::High);
board.run_during(Duration::from_secs(1), Duration::from_millis(100));

let a_b = and_gate.borrow_mut().get_pin_state(GateAnd::A_AND_B).as_bool();
println!("001:\t{}\t{}", a_b, and_gate.borrow_mut().get_pin_state(GateAnd::C_AND_D).as_bool());

} ```

Documentation

Take a look at the generated documentation.

Examples

See examples : - readme : Same example as provided in this readme - ram-test : A simple test of a RAM chip - cpu-test : A simple circuit containing a minimal setup running a CPU processing factorial of 4