org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
org.eclipse.jdt.core.formatter.align_with_spaces=false
+org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_assignment=0
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
+org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
+org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
org.eclipse.jdt.core.formatter.comment.format_source_code=true
org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
org.eclipse.jdt.core.formatter.comment.indent_root_tags=false
+org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
org.eclipse.jdt.core.formatter.comment.line_length=140
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
+org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.join_lines_in_comments=true
org.eclipse.jdt.core.formatter.join_wrapped_lines=true
+org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.lineSplit=140
org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=true
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
+org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
+org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
eclipse.preferences.version=1
-formatter_profile=_MyPrefrence
-formatter_settings_version=14
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
+formatter_profile=_ERA-MI
+formatter_settings_version=16
+sp_cleanup.add_default_serial_version_id=true
+sp_cleanup.add_generated_serial_version_id=false
+sp_cleanup.add_missing_annotations=true
+sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
+sp_cleanup.add_missing_nls_tags=false
+sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_missing_override_annotations_interface_methods=true
+sp_cleanup.add_serial_version_id=false
+sp_cleanup.always_use_blocks=false
+sp_cleanup.always_use_parentheses_in_expressions=false
+sp_cleanup.always_use_this_for_non_static_field_access=false
+sp_cleanup.always_use_this_for_non_static_method_access=false
+sp_cleanup.convert_functional_interfaces=true
+sp_cleanup.convert_to_enhanced_for_loop=true
+sp_cleanup.correct_indentation=true
+sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code_changes_only=false
+sp_cleanup.insert_inferred_type_arguments=false
+sp_cleanup.make_local_variable_final=true
+sp_cleanup.make_parameters_final=false
+sp_cleanup.make_private_fields_final=true
+sp_cleanup.make_type_abstract_if_missing_method=false
+sp_cleanup.make_variable_declarations_final=true
+sp_cleanup.never_use_blocks=true
+sp_cleanup.never_use_parentheses_in_expressions=true
+sp_cleanup.on_save_use_additional_actions=false
+sp_cleanup.organize_imports=true
+sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_with_declaring_class=true
+sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
+sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_redundant_modifiers=true
+sp_cleanup.remove_redundant_semicolons=true
+sp_cleanup.remove_redundant_type_arguments=true
+sp_cleanup.remove_trailing_whitespaces=true
+sp_cleanup.remove_trailing_whitespaces_all=true
+sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
+sp_cleanup.remove_unnecessary_casts=true
+sp_cleanup.remove_unnecessary_nls_tags=true
+sp_cleanup.remove_unused_imports=true
+sp_cleanup.remove_unused_local_variables=false
+sp_cleanup.remove_unused_private_fields=true
+sp_cleanup.remove_unused_private_members=false
+sp_cleanup.remove_unused_private_methods=true
+sp_cleanup.remove_unused_private_types=true
+sp_cleanup.sort_members=false
+sp_cleanup.sort_members_all=false
+sp_cleanup.use_anonymous_class_creation=false
+sp_cleanup.use_blocks=false
+sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_lambda=true
+sp_cleanup.use_parentheses_in_expressions=false
+sp_cleanup.use_this_for_non_static_field_access=true
+sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
+sp_cleanup.use_this_for_non_static_method_access=true
+sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
{
public final static Timeline TIMELINE = new Timeline(11);
- public static void main(String[] args)
- {
- }
}
\ No newline at end of file
import era.mi.logic.Bit;
import era.mi.logic.Simulation;
import era.mi.logic.wires.Wire;
-import era.mi.logic.wires.WireArrayObserver;
+import era.mi.logic.wires.WireObserver;
/**
* A basic component that recomputes all outputs (with a delay), when it is updated.
*
* @author Fabian Stemmler
*/
-public abstract class BasicComponent implements WireArrayObserver, Component
+public abstract class BasicComponent implements WireObserver, Component
{
private int processTime;
@Override
public void update(Wire initiator, Bit[] oldValues)
{
- Simulation.TIMELINE.addEvent((e) ->
- {
- compute();
- }, processTime);
+ Simulation.TIMELINE.addEvent(e -> compute(), processTime);
}
protected abstract void compute();
package era.mi.logic.components;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import era.mi.logic.Bit;
@Override
public List<WireEnd> getAllInputs()
{
- return Collections.unmodifiableList(Arrays.asList(in));
+ return List.of(in);
}
@Override
public List<WireEnd> getAllOutputs()
{
- return Collections.unmodifiableList(new ArrayList<WireEnd>());
+ return List.of();
}
}
package era.mi.logic.components;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import era.mi.logic.Bit;
public void handle(TimelineEvent e)
{
addToTimeline();
- out.feedSignals(new Bit[] { toggle ? Bit.ONE : Bit.ZERO });
+ out.feedSignals(toggle ? Bit.ONE : Bit.ZERO);
toggle = !toggle;
}
@Override
public List<WireEnd> getAllInputs()
{
- return Collections.unmodifiableList(Arrays.asList());
+ return List.of();
}
@Override
public List<WireEnd> getAllOutputs()
{
- return Collections.unmodifiableList(Arrays.asList(out));
+ return List.of(out);
}
}
--- /dev/null
+package era.mi.logic.components;
+
+import java.util.List;
+
+import era.mi.logic.Bit;
+import era.mi.logic.Simulation;
+import era.mi.logic.wires.Wire;
+import era.mi.logic.wires.Wire.WireEnd;
+import era.mi.logic.wires.WireObserver;
+
+public class Connector implements WireObserver, Component
+{
+ private boolean connected;
+ private final WireEnd a;
+ private final WireEnd b;
+
+ public Connector(WireEnd a, WireEnd b)
+ {
+ if (a.length() != b.length())
+ throw new IllegalArgumentException(String.format("WireArray width does not match: %d, %d", a.length(), b.length()));
+ this.a = a;
+ this.b = b;
+ a.addObserver(this);
+ b.addObserver(this);
+ }
+
+ public void connect()
+ {
+ connected = true;
+ update(a.getWire());
+ update(b.getWire());
+ }
+
+ public void disconnect()
+ {
+ connected = false;
+ a.clearSignals();
+ b.clearSignals();
+ }
+
+ public void setConnection(boolean connected)
+ {
+ if (connected)
+ connect();
+ else
+ disconnect();
+ }
+
+ @Override
+ public void update(Wire initiator, Bit[] oldValues)
+ {
+ if (connected)
+ Simulation.TIMELINE.addEvent(e -> update(initiator), 1);
+ }
+
+ private void update(Wire initiator)
+ {
+ if (initiator == a.getWire())
+ b.feedSignals(a.wireValuesExcludingMe());
+ else
+ a.feedSignals(b.wireValuesExcludingMe());
+ }
+
+ @Override
+ public List<WireEnd> getAllInputs()
+ {
+ return List.of(a, b);
+ }
+
+ @Override
+ public List<WireEnd> getAllOutputs()
+ {
+ return List.of(a, b);
+ }
+}
package era.mi.logic.components;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import era.mi.logic.wires.Wire;
private int selected = -1;
/**
- * Input {@link Wire}s and out must be of uniform length
+ * Output {@link Wire}s and in must be of uniform length
*
- * @param out Must be of uniform length with all inputs.
- * @param select Indexes the input array which is to be mapped to the output. Must have enough bits to index all inputs.
- * @param outputs One of these inputs is mapped to the output, depending on the select bits
+ * @param in Must be of uniform length with all outputs.
+ * @param select Indexes the output array to which the input is mapped. Must have enough bits to index all outputs.
+ * @param outputs One of these outputs receives the input signal, depending on the select bits
*/
public Demux(int processTime, WireEnd in, WireEnd select, WireEnd... outputs)
{
@Override
public List<WireEnd> getAllInputs()
{
- return Collections.unmodifiableList(Arrays.asList(in, select));
+ return List.of(in, select);
}
@Override
public List<WireEnd> getAllOutputs()
{
- return Collections.unmodifiableList(Arrays.asList(outputs));
+ return List.of(outputs);
}
}
package era.mi.logic.components;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import era.mi.logic.Bit;
import era.mi.logic.wires.Wire;
import era.mi.logic.wires.Wire.WireEnd;
-import era.mi.logic.wires.WireArrayObserver;
+import era.mi.logic.wires.WireObserver;
-public class Merger implements WireArrayObserver, Component
+public class Merger implements WireObserver, Component
{
private WireEnd out;
private WireEnd[] inputs;
@Override
public List<WireEnd> getAllInputs()
{
- return Collections.unmodifiableList(Arrays.asList(inputs));
+ return List.of(inputs);
}
@Override
public List<WireEnd> getAllOutputs()
{
- return Collections.unmodifiableList(Arrays.asList(out));
+ return List.of(out);
}
}
@Override
public List<WireEnd> getAllOutputs()
{
- return Collections.unmodifiableList(Arrays.asList(out));
+ return List.of(out);
}
}
import era.mi.logic.Bit;
import era.mi.logic.wires.Wire;
import era.mi.logic.wires.Wire.WireEnd;
-import era.mi.logic.wires.WireArrayObserver;
+import era.mi.logic.wires.WireObserver;
-public class Splitter implements WireArrayObserver
+public class Splitter implements WireObserver
{
private WireEnd input;
private WireEnd[] outputs;
package era.mi.logic.components;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import era.mi.logic.Bit;
-import era.mi.logic.wires.Wire;
import era.mi.logic.wires.Wire.WireEnd;
public class TriStateBuffer extends BasicComponent
@Override
public List<WireEnd> getAllInputs()
{
- return Collections.unmodifiableList(Arrays.asList(in, enable));
+ return List.of(in, enable);
}
@Override
public List<WireEnd> getAllOutputs()
{
- return Collections.unmodifiableList(Arrays.asList(out));
+ return List.of(out);
}
}
package era.mi.logic.components.gates;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import era.mi.logic.Bit;
@Override
public List<WireEnd> getAllInputs()
{
- return Collections.unmodifiableList(Arrays.asList(in));
+ return List.of(in);
}
@Override
public List<WireEnd> getAllOutputs()
{
- return Collections.unmodifiableList(Arrays.asList(out));
+ return List.of(out);
}
+ @Override
protected void compute()
{
Bit[] result = in[0].getValues();
package era.mi.logic.components.gates;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import era.mi.logic.Util;
@Override
public List<WireEnd> getAllInputs()
{
- return Collections.unmodifiableList(Arrays.asList(in));
+ return List.of(in);
}
@Override
public List<WireEnd> getAllOutputs()
{
- return Collections.unmodifiableList(Arrays.asList(out));
+ return List.of(out);
}
}
package era.mi.logic.tests;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.Arrays;
import java.util.function.LongConsumer;
import era.mi.logic.Bit;
import era.mi.logic.Simulation;
+import era.mi.logic.components.Connector;
import era.mi.logic.components.Demux;
import era.mi.logic.components.Merger;
import era.mi.logic.components.Mux;
import era.mi.logic.wires.Wire;
import era.mi.logic.wires.Wire.WireEnd;
+@SuppressWarnings("unused")
class ComponentTest
{
void circuitExampleTest()
{
Simulation.TIMELINE.reset();
- Wire a = new Wire(1, 1), b = new Wire(1, 1), c = new Wire(1, 10), d = new Wire(2, 1),
- e = new Wire(1, 1), f = new Wire(1, 1), g = new Wire(1, 1), h = new Wire(2, 1), i = new Wire(2, 1),
- j = new Wire(1, 1), k = new Wire(1, 1);
+ Wire a = new Wire(1, 1), b = new Wire(1, 1), c = new Wire(1, 10), d = new Wire(2, 1), e = new Wire(1, 1), f = new Wire(1, 1),
+ g = new Wire(1, 1), h = new Wire(2, 1), i = new Wire(2, 1), j = new Wire(1, 1), k = new Wire(1, 1);
new AndGate(1, f.createEnd(), a.createEnd(), b.createEnd());
new NotGate(1, f.createEnd(), g.createEnd());
new Merger(h.createEnd(), c.createEnd(), g.createEnd());
WireEnd enI = en.createEnd(), aI = a.createEnd(), bI = b.createEnd();
enI.feedSignals(Bit.ONE);
aI.feedSignals(Bit.ONE);
+ bI.feedSignals(Bit.Z);
Simulation.TIMELINE.executeAll();
void muxTest()
{
Simulation.TIMELINE.reset();
- Wire a = new Wire(4, 3), b = new Wire(4, 6), c = new Wire(4, 4), select = new Wire(2, 5),
- out = new Wire(4, 1);
+ Wire a = new Wire(4, 3), b = new Wire(4, 6), c = new Wire(4, 4), select = new Wire(2, 5), out = new Wire(4, 1);
WireEnd selectIn = select.createEnd();
selectIn.feedSignals(Bit.ZERO, Bit.ZERO);
void demuxTest()
{
Simulation.TIMELINE.reset();
- Wire a = new Wire(4, 3), b = new Wire(4, 6), c = new Wire(4, 4), select = new Wire(2, 5),
- in = new Wire(4, 1);
+ Wire a = new Wire(4, 3), b = new Wire(4, 6), c = new Wire(4, 4), select = new Wire(2, 5), in = new Wire(4, 1);
WireEnd selectIn = select.createEnd();
selectIn.feedSignals(Bit.ZERO, Bit.ZERO);
assertBitArrayEquals(d.getValues(), Bit.ZERO, Bit.ONE, Bit.ONE);
}
-
+
@Test
void notTest()
{
void rsLatchCircuitTest()
{
Simulation.TIMELINE.reset();
- Wire r = new Wire(1, 1), s = new Wire(1, 1), t1 = new Wire(1, 15), t2 = new Wire(1, 1),
- q = new Wire(1, 1), nq = new Wire(1, 1);
+ Wire r = new Wire(1, 1), s = new Wire(1, 1), t1 = new Wire(1, 15), t2 = new Wire(1, 1), q = new Wire(1, 1), nq = new Wire(1, 1);
new OrGate(1, t2.createEnd(), r.createEnd(), nq.createEnd());
new OrGate(1, t1.createEnd(), s.createEnd(), q.createEnd());
assertBitArrayEquals(w.getValues(), Bit.ONE, Bit.Z);
}
-// @Test
+ @Test
void wireConnections()
{
// Nur ein Experiment, was über mehrere 'passive' Bausteine hinweg passieren würde
cI.feedSignals(Bit.Z);
test.assertAfterSimulationIs(print, Bit.Z);
- new Connector(b, c);
+ new Connector(b.createEnd(), c.createEnd()).connect();
test.assertAfterSimulationIs(print, Bit.Z);
System.err.println("ONE");
bI.feedSignals(Bit.ONE);
bI.feedSignals(Bit.Z);
test.assertAfterSimulationIs(print, Bit.Z);
- new Connector(a, b);
+ new Connector(a.createEnd(), b.createEnd()).connect();
System.err.println("Z 2");
aI.feedSignals(Bit.Z);
test.assertAfterSimulationIs(print, Bit.Z);
import era.mi.logic.Simulation;
import era.mi.logic.wires.Wire;
import era.mi.logic.wires.Wire.WireEnd;
-import era.mi.logic.wires.WireArrayObserver;
+import era.mi.logic.wires.WireObserver;
-public class Connector implements WireArrayObserver
+public class Connector implements WireObserver
{
private final Wire a;
// private final WireArray b;
g.setColor(Color.BLACK);
break;
case U:
- g.setColor(Color.BLUE);
+ g.setColor(Color.MAGENTA);
break;
default:
throw new IllegalArgumentException();
{
if (!hasNext())
return -1;
- else
- return events.peek().timing;
+ return events.peek().timing;
}
public void reset()
private class InnerEvent
{
- private final long timing;
+ final long timing;
private final TimelineEventHandler function;
private final TimelineEvent event;
return timing;
}
+ @Override
public String toString()
{
return "timestamp: " + timing;
{
private Bit[] values;
public final int travelTime;
- private List<WireArrayObserver> observers = new ArrayList<WireArrayObserver>();
+ private List<WireObserver> observers = new ArrayList<WireObserver>();
public final int length;
private List<WireEnd> inputs = new ArrayList<WireEnd>();
}
/**
- * Adds an {@link WireArrayObserver}, who will be notified when the value of the {@link Wire} is updated.
+ * Adds an {@link WireObserver}, who will be notified when the value of the {@link Wire} is updated.
*
- * @param ob The {@link WireArrayObserver} to be notified of changes.
- * @return true if the given {@link WireArrayObserver} was not already registered, false otherwise
+ * @param ob The {@link WireObserver} to be notified of changes.
+ * @return true if the given {@link WireObserver} was not already registered, false otherwise
*
* @author Fabian Stemmler
*/
- public boolean addObserver(WireArrayObserver ob)
+ public boolean addObserver(WireObserver ob)
{
return observers.add(ob);
}
private void notifyObservers(Bit[] oldValues)
{
- for (WireArrayObserver o : observers)
+ for (WireObserver o : observers)
o.update(this, oldValues);
}
/**
* A {@link WireEnd} feeds a constant signal into the {@link Wire} it is tied to. The combination of all inputs determines the
- * {@link Wire}s final value. X dominates all other inputs Z does not affect the final value, unless there are no other inputs than
- * Z 0 and 1 turn into X when they are mixed
+ * {@link Wire}s final value. X dominates all other inputs Z does not affect the final value, unless there are no other inputs than Z 0
+ * and 1 turn into X when they are mixed
*
* @author Fabian Stemmler
*/
{
return inputValues[index];
}
-
+
/**
- * @return A copy (safe to modify) of the values the {@link WireEnd} is currently feeding into the associated
- * {@link Wire}.
+ * @return A copy (safe to modify) of the values the {@link WireEnd} is currently feeding into the associated {@link Wire}.
*/
public Bit[] getInputValues()
{
return getInputValues(0, length);
}
-
+
public Bit[] getInputValues(int start, int end)
{
int length = end - start;
{
return Wire.this.getValue(index);
}
-
+
/**
* @param index Index of the requested bit.
* @return The value of the indexed bit.
/**
* @param start Start of the wanted segment. (inclusive)
- * @param end End of the wanted segment. (exclusive)
- * @return The values of the segment of {@link Bit}s indexed.
+ * @param end End of the wanted segment. (exclusive)
+ * @return The values of the segment of {@link Bit}s indexed.
*
* @author Fabian Stemmler
*/
{
return Wire.this.getValues(start, end);
}
-
/**
* The {@link Wire} is interpreted as an unsigned integer with n bits.
*
- * @return <code>true</code> if all bits are either <code>Bit.ONE</code> or <code>Bit.ZERO</code> (they do not all have to have the same
- * value), not <code>Bit.X</code> or <code>Bit.Z</code>. <code>false</code> is returned otherwise.
+ * @return <code>true</code> if all bits are either <code>Bit.ONE</code> or <code>Bit.ZERO</code> (they do not all have to have the
+ * same value), not <code>Bit.X</code> or <code>Bit.Z</code>. <code>false</code> is returned otherwise.
*
* @author Fabian Stemmler
*/
{
return Wire.this.getSignedValue();
}
-
+
@Override
public String toString()
{
return Arrays.toString(values);
- //return String.format("%s \nFeeding: %s", WireArray.this.toString(), Arrays.toString(inputValues));
+ // return String.format("%s \nFeeding: %s", WireArray.this.toString(), Arrays.toString(inputValues));
}
public void disconnect()
return length;
}
- public boolean addObserver(WireArrayObserver ob)
+ public boolean addObserver(WireObserver ob)
{
return Wire.this.addObserver(ob);
}
-
+
public Wire getWire()
{
return Wire.this;
}
}
-
+
@Override
public String toString()
{
return String.format("wire 0x%08x value: %s inputs: %s", hashCode(), Arrays.toString(values), inputs);
- //Arrays.toString(values), inputs.stream().map(i -> Arrays.toString(i.inputValues)).reduce((s1, s2) -> s1 + s2)
+ // Arrays.toString(values), inputs.stream().map(i -> Arrays.toString(i.inputValues)).reduce((s1, s2) -> s1 + s2)
}
public static WireEnd[] extractEnds(Wire[] w)
+++ /dev/null
-package era.mi.logic.wires;
-
-import era.mi.logic.Bit;
-
-public interface WireArrayObserver
-{
- public void update(Wire initiator, Bit[] oldValues);
-}
--- /dev/null
+package era.mi.logic.wires;
+
+import era.mi.logic.Bit;
+
+public interface WireObserver
+{
+ public void update(Wire initiator, Bit[] oldValues);
+}