Add inverter

master
D4VID 4 weeks ago
parent 364839cd05
commit 49504196aa

@ -99,7 +99,7 @@ pub fn route(module: Module) -> Result<(Vec<lw::Component>, Vec<lw::Wire>), Erro
for (i, cell) in module.cells.iter().enumerate() {
println!("{}: {:?}", i, cell);
let components = match cell.cell_type.as_str() {
"$and" => basic_gate(
"$and" => binary_op(
cell,
"MHG.AndGate",
board_address,
@ -107,7 +107,7 @@ pub fn route(module: Module) -> Result<(Vec<lw::Component>, Vec<lw::Wire>), Erro
&mut next_position,
&mut connection_map,
),
"$xor" => basic_gate(
"$xor" => binary_op(
cell,
"MHG.XorGate",
board_address,
@ -123,6 +123,14 @@ pub fn route(module: Module) -> Result<(Vec<lw::Component>, Vec<lw::Wire>), Erro
&mut wires,
&mut connection_map,
),
"$not" => unary_op(
cell,
"MHG.Inverter",
board_address,
&mut next_address,
&mut next_position,
&mut connection_map,
),
_ => return Err(Error::UnsupportedCell),
};
cells.extend(components);
@ -277,7 +285,7 @@ fn output_port(
return vec![peg, label];
}
fn basic_gate(
fn binary_op(
cell: &Cell,
text_id: &str,
parent_address: u32,
@ -318,6 +326,42 @@ fn basic_gate(
return vec![component];
}
fn unary_op(
cell: &Cell,
text_id: &str,
parent_address: u32,
next_address: &mut u32,
next_position: &mut Vector3<i32>,
connection_map: &mut HashMap<(usize, &str), lw::PegAddress>,
) -> Vec<lw::Component> {
let input = lw::Input::new(cell.inputs["A"][0] as i32);
let output = lw::Output::new(cell.outputs["Y"][0] as i32);
let component = lw::Component {
address: *next_address,
parent: parent_address,
numeric_id: COMPONENT_MAP[text_id],
position: *next_position,
rotation: quaternion::id(),
inputs: vec![input],
outputs: vec![output],
custom_data: vec![],
};
connection_map.insert(
(cell.index, "A"),
lw::PegAddress::input(component.address, 0),
);
connection_map.insert(
(cell.index, "Y"),
lw::PegAddress::output(component.address, 0),
);
*next_address += 1;
next_position[2] += 3 * SQUARE;
return vec![component];
}
fn or_gate(
cell: &Cell,
parent_address: u32,

Loading…
Cancel
Save