class ThreeWireDriver: input_a: BusWire input_b: BusWire input_c: BusWire output: BusWire input_driver_a: BusWire input_driver_b: BusWire input_driver_c: BusWire and_gate_one_to_or: BusWire and_gate_two_to_or: BusWire and_gate_three_to_or: BusWire and_gate_one: AndGate and_gate_two: AndGate and_gate_three: AndGate or_gate: OrGate def __init__(self): self.input_a = BusWire() self.input_b = BusWire() self.input_c = BusWire() self.and_gate_one_to_or = BusWire() self.and_gate_two_to_or = BusWire() self.and_gate_three_to_or = BusWire() self.input_driver_a = BusWire() self.input_driver_b = BusWire() self.input_driver_c = BusWire() self.output = BusWire() self.and_gate_one = AndGate() self.and_gate_two = AndGate() self.and_gate_three = AndGate() self.or_gate = OrGate() self.and_gate_one.input.append(self.input_a) self.and_gate_one.input.append(self.input_driver_a) self.and_gate_one_to_or.set_input(self.and_gate_one.output) self.and_gate_two.input.append(self.input_b) self.and_gate_two.input.append(self.input_driver_b) self.and_gate_two_to_or.set_input(self.and_gate_two.output) self.and_gate_three.input.append(self.input_c) self.and_gate_three.input.append(self.input_driver_c) self.and_gate_three_to_or.set_input(self.and_gate_three.output) self.or_gate.input.append(self.and_gate_one_to_or) self.or_gate.input.append(self.and_gate_two_to_or) self.or_gate.input.append(self.and_gate_three_to_or) self.output.set_input(self.or_gate.output) def notify(self): self.and_gate_one.notify() self.and_gate_two.notify() self.and_gate_three.notify() self.or_gate.notify()
class SingleWireDriver: input_data: BusWire input_driver: BusWire output: BusWire and_gate: AndGate def __init__(self): self.input_data = BusWire() self.input_driver = BusWire() self.output = BusWire() self.and_gate = AndGate() self.and_gate.input.append(self.input_data) self.and_gate.input.append(self.input_driver) self.output.set_input(self.and_gate.output) def notify(self): self.and_gate.notify()
class TwoWireDemultiplexer: input: BusWire input_op: BusWire output_a: BusWire output_b: BusWire not_to_and: BusWire and_gate_one: AndGate and_gate_two: AndGate not_gate: NotGate def __init__(self): self.input = BusWire() self.input_op = BusWire() self.output_a = BusWire() self.output_b = BusWire() self.not_to_and = BusWire() self.and_gate_one = AndGate() self.and_gate_two = AndGate() self.not_gate = NotGate() self.not_gate.input.set_input(self.input_op) self.not_to_and.set_input(self.not_gate.output) self.and_gate_one.input.append(self.input) self.and_gate_one.input.append(self.input_op) self.and_gate_two.input.append(self.input) self.and_gate_two.input.append(self.not_to_and) self.output_a.set_input(self.and_gate_one.output) self.output_b.set_input(self.and_gate_two.output) def notify(self): self.not_gate.notify() self.and_gate_one.notify() self.and_gate_two.notify()
class FourWireMultiplexer: input_a: BusWire input_b: BusWire input_c: BusWire input_d: BusWire output: BusWire op_a: BusWire op_b: BusWire not_a_one_to_and: BusWire not_a_tow_to_and: BusWire not_b_one_to_and: BusWire not_c_two_to_and: BusWire and_one_to_or: BusWire and_two_to_or: BusWire and_three_to_or: BusWire and_four_to_or: BusWire and_gate_one: AndGate not_gate_one: NotGate not_gate_two: NotGate and_gate_two: AndGate not_gate_three: NotGate and_gate_three: AndGate not_gate_four: NotGate and_gate_four: AndGate or_gate: OrGate def __init__(self): self.input_a = BusWire() self.input_b = BusWire() self.input_c = BusWire() self.input_d = BusWire() self.output = BusWire() self.op_a = BusWire() self.op_b = BusWire() self.not_a_one_to_and = BusWire() self.not_a_tow_to_and = BusWire() self.not_b_one_to_and = BusWire() self.not_c_two_to_and = BusWire() self.and_one_to_or = BusWire() self.and_two_to_or = BusWire() self.and_three_to_or = BusWire() self.and_four_to_or = BusWire() self.and_gate_one = AndGate() self.not_gate_one = NotGate() self.not_gate_two = NotGate() self.and_gate_two = AndGate() self.not_gate_three = NotGate() self.and_gate_three = AndGate() self.not_gate_four = NotGate() self.and_gate_four = AndGate() self.or_gate = OrGate() ##For and_gate_one self.not_gate_one.input.set_input(self.op_a) self.not_gate_three.input.set_input(self.op_a) self.not_gate_two.input.set_input(self.op_b) self.not_a_one_to_and.set_input(self.not_gate_one.output) self.not_a_tow_to_and.set_input(self.not_gate_two.output) self.and_gate_one.input.append(self.input_a) self.and_gate_one.input.append(self.not_a_one_to_and) self.and_gate_one.input.append(self.not_a_tow_to_and) self.and_one_to_or.set_input(self.and_gate_one.output) ##For and_gate_two self.not_b_one_to_and.set_input(self.not_gate_three.output) self.and_gate_two.input.append(self.not_b_one_to_and) self.and_gate_two.input.append(self.input_b) self.and_gate_two.input.append(self.op_b) self.and_two_to_or.set_input(self.and_gate_two.output) ##For and_gate_three self.not_gate_four.input.set_input(self.op_b) self.not_c_two_to_and.set_input(self.not_gate_four.output) self.and_gate_three.input.append(self.op_a) self.and_gate_three.input.append(self.input_c) self.and_gate_three.input.append(self.not_c_two_to_and) self.and_three_to_or.set_input(self.and_gate_three.output) ##For and_gate_four self.and_gate_four.input.append(self.input_d) self.and_gate_four.input.append(self.op_b) self.and_four_to_or.set_input(self.and_gate_four.output) self.and_gate_four.input.append(self.op_a) ##For or_gate self.or_gate.input.append(self.and_one_to_or) self.or_gate.input.append(self.and_two_to_or) self.or_gate.input.append(self.and_three_to_or) self.or_gate.input.append(self.and_four_to_or) self.output.set_input(self.or_gate.output) def set_data(self): self.not_gate_one.notify() self.not_gate_two.notify() self.not_gate_three.notify() self.not_gate_four.notify() self.and_gate_one.notify() self.and_gate_two.notify() self.and_gate_three.notify() self.and_gate_four.notify() self.or_gate.notify() def notify(self): self.set_data()
class ProcessorSystem: clock: Clock instruction_counter: InstructionCounter rom: BasicRom control_unit: ControlUnit ram: BasicRam adding_unit: AddingUnit register: Register reg_multiplexer: FourWireMultiplexer reg_demultiplexer: FourWireDemultiplexer console_out: ConsoleOut adding_ram_demux: TwoWireDemultiplexer reg_to_ram_adding_driver: SingleWireDriver adding_ldi_ram_to_data_driver: ThreeWireDriver clock_to_ic: BusWire ic_to_rom: BusWire rom_to_cu: BusWire cu_to_ic_data: BusWire cu_to_ic_op: BusWire cu_to_reg_demux_op_a: BusWire cu_to_reg_demux_op_b: BusWire cu_to_reg_op: BusWire cu_to_reg_mux_op_a: BusWire cu_to_reg_mux_op_b: BusWire cu_to_adding_ram_driver_op: BusWire cu_to_adding_ram_demux: BusWire cu_to_cout_op: BusWire cu_to_ram_adress: BusWire cu_to_ram_op: BusWire cu_to_adding_ldi_ram_driver_in_a: BusWire cu_to_adding_ldi_ram_driver_op_a: BusWire cu_to_adding_ldi_ram_driver_op_b: BusWire cu_to_adding_ldi_ram_driver_op_c: BusWire cu_to_adding_data: BusWire adding_ldi_ram_to_reg_demux: BusWire reg_demux_out_a_to_reg_a: BusWire reg_demux_out_b_to_reg_b: BusWire reg_demux_out_c_to_reg_c: BusWire reg_demux_out_d_to_reg_d: BusWire reg_out_a_to_reg_mux_in_a: BusWire reg_out_b_to_reg_mux_in_b: BusWire reg_out_c_to_reg_mux_in_c: BusWire reg_out_d_to_reg_mux_in_d: BusWire reg_mux_out_to_adding_ram_driver: BusWire adding_ram_driver_to_adding_ram_demux_in: BusWire adding_ram_demux_out_a_to_adding: BusWire adding_ram_demux_out_b_to_ram: BusWire adding_to_adding_ldi_ram_driver_in_b: BusWire ram_to_adding_ldi_ram_in_c: BusWire counter: int def __init__(self): self.counter = 0 self.clock = Clock(10) self.instruction_counter = InstructionCounter() self.rom = BasicRom(64) self.control_unit = ControlUnit() self.ram = BasicRam(8, 8) self.adding_unit = AddingUnit() self.register = Register() self.reg_multiplexer = FourWireMultiplexer() self.reg_demultiplexer = FourWireDemultiplexer() self.console_out = ConsoleOut() self.adding_ram_demux = TwoWireDemultiplexer() self.reg_to_ram_adding_driver = SingleWireDriver() self.adding_ldi_ram_to_data_driver = ThreeWireDriver() self.clock_to_ic = BusWire() self.ic_to_rom = BusWire() self.rom_to_cu = BusWire() self.cu_to_ic_data = BusWire() self.cu_to_ic_op = BusWire() self.cu_to_reg_demux_op_a = BusWire() self.cu_to_reg_demux_op_b = BusWire() self.cu_to_reg_op = BusWire() self.cu_to_reg_mux_op_a = BusWire() self.cu_to_reg_mux_op_b = BusWire() self.cu_to_adding_ram_driver_op = BusWire() self.cu_to_adding_ram_demux = BusWire() self.cu_to_cout_op = BusWire() self.cu_to_ram_adress = BusWire() self.cu_to_ram_op = BusWire() self.cu_to_adding_ldi_ram_driver_in_a = BusWire() self.cu_to_adding_ldi_ram_driver_op_a = BusWire() self.cu_to_adding_ldi_ram_driver_op_b = BusWire() self.cu_to_adding_ldi_ram_driver_op_c = BusWire() self.cu_to_adding_data = BusWire() self.adding_ldi_ram_to_reg_demux = BusWire() self.reg_demux_out_a_to_reg_a = BusWire() self.reg_demux_out_b_to_reg_b = BusWire() self.reg_demux_out_c_to_reg_c = BusWire() self.reg_demux_out_d_to_reg_d = BusWire() self.reg_out_a_to_reg_mux_in_a = BusWire() self.reg_out_b_to_reg_mux_in_b = BusWire() self.reg_out_c_to_reg_mux_in_c = BusWire() self.reg_out_d_to_reg_mux_in_d = BusWire() self.reg_mux_out_to_adding_ram_driver = BusWire() self.adding_ram_driver_to_adding_ram_demux_in = BusWire() self.adding_ram_demux_out_a_to_adding = BusWire() self.adding_ram_demux_out_b_to_ram = BusWire() self.adding_to_adding_ldi_ram_driver_in_b = BusWire() self.ram_to_adding_ldi_ram_in_c = BusWire() self.clock_to_ic.set_input(self.clock.output) self.instruction_counter.input.set_input(self.clock_to_ic) self.ic_to_rom.set_input(self.instruction_counter.output) self.rom.input_wire.set_input(self.ic_to_rom) self.rom_to_cu.set_input(self.rom.output_wire) self.control_unit.input_wire.set_input(self.rom_to_cu) self.cu_to_ic_op.set_input(self.control_unit.ic_out_op) self.instruction_counter.op_input.set_input(self.cu_to_ic_op) self.cu_to_ic_data.set_input(self.control_unit.ic_out_data) self.instruction_counter.data_input.set_input(self.cu_to_ic_data) # self.cu_to_reg_demux_op_a.set_input(self.control_unit.reg_demux_op_a) self.reg_demultiplexer.input_op_one.set_input(self.cu_to_reg_demux_op_a) self.cu_to_reg_demux_op_b.set_input(self.control_unit.reg_demux_op_b) self.reg_demultiplexer.input_op_two.set_input(self.cu_to_reg_demux_op_b) self.cu_to_reg_mux_op_a.set_input(self.control_unit.reg_mux_op_a) self.reg_multiplexer.op_a.set_input(self.cu_to_reg_mux_op_a) self.cu_to_reg_mux_op_b.set_input(self.control_unit.reg_mux_op_b) self.reg_multiplexer.op_b.set_input(self.cu_to_reg_mux_op_b) self.reg_demux_out_a_to_reg_a.set_input(self.reg_demultiplexer.output_a) self.register.input_a.set_input(self.reg_demux_out_a_to_reg_a) self.reg_demux_out_b_to_reg_b.set_input(self.reg_demultiplexer.output_b) self.register.input_b.set_input(self.reg_demux_out_b_to_reg_b) self.reg_demux_out_c_to_reg_c.set_input(self.reg_demultiplexer.output_c) self.register.input_c.set_input(self.reg_demux_out_c_to_reg_c) self.reg_demux_out_d_to_reg_d.set_input(self.reg_demultiplexer.output_d) self.register.input_d.set_input(self.reg_demux_out_d_to_reg_d) self.cu_to_reg_op.set_input(self.control_unit.reg_op) self.register.input_op.set_input(self.cu_to_reg_op) self.reg_out_a_to_reg_mux_in_a.set_input(self.register.out_a) self.reg_multiplexer.input_a.set_input(self.reg_out_a_to_reg_mux_in_a) self.reg_out_b_to_reg_mux_in_b.set_input(self.register.out_b) self.reg_multiplexer.input_b.set_input(self.reg_out_b_to_reg_mux_in_b) self.reg_out_c_to_reg_mux_in_c.set_input(self.register.out_c) self.reg_multiplexer.input_c.set_input(self.reg_out_c_to_reg_mux_in_c) self.reg_out_d_to_reg_mux_in_d.set_input(self.register.out_d) self.reg_multiplexer.input_d.set_input(self.reg_out_d_to_reg_mux_in_d) self.reg_mux_out_to_adding_ram_driver.set_input(self.reg_multiplexer.output) self.reg_to_ram_adding_driver.input_data.set_input(self.reg_mux_out_to_adding_ram_driver) self.cu_to_adding_ram_driver_op.set_input(self.control_unit.reg_to_adding_driver_out_op) self.reg_to_ram_adding_driver.input_driver.set_input(self.cu_to_adding_ram_driver_op) self.adding_ram_driver_to_adding_ram_demux_in.set_input(self.reg_to_ram_adding_driver.output) self.adding_ram_demux.input.set_input(self.adding_ram_driver_to_adding_ram_demux_in) self.cu_to_adding_ram_demux.set_input(self.control_unit.reg_to_adding_ram_demux_out_o) self.adding_ram_demux.input_op.set_input(self.cu_to_adding_ram_demux) self.adding_ram_demux_out_a_to_adding.set_input(self.adding_ram_demux.output_a) self.adding_unit.input_a.set_input(self.adding_ram_demux_out_a_to_adding) self.cu_to_adding_data.set_input(self.control_unit.addi_out_data) self.adding_unit.input_b.set_input(self.cu_to_adding_data) self.adding_ram_demux_out_b_to_ram.set_input(self.adding_ram_demux.output_b) self.ram.input.set_input(self.adding_ram_demux_out_b_to_ram) self.console_out.input.set_input(self.adding_ram_demux_out_b_to_ram) self.cu_to_cout_op.set_input(self.control_unit.cout_out_op) self.console_out.input_op.set_input(self.cu_to_cout_op) self.cu_to_ram_op.set_input(self.control_unit.ram_out_op) self.ram.opcode.set_input(self.cu_to_ram_op) self.cu_to_ram_adress.set_input(self.control_unit.ram_out_adress) self.ram.address.set_input(self.cu_to_ram_adress) self.cu_to_adding_ldi_ram_driver_in_a.set_input(self.control_unit.ldi_out_data) self.adding_ldi_ram_to_data_driver.input_a.set_input(self.cu_to_adding_ldi_ram_driver_in_a) self.adding_to_adding_ldi_ram_driver_in_b.set_input(self.adding_unit.output) self.adding_ldi_ram_to_data_driver.input_b.set_input(self.adding_to_adding_ldi_ram_driver_in_b) self.ram_to_adding_ldi_ram_in_c.set_input(self.ram.output) self.adding_ldi_ram_to_data_driver.input_c.set_input(self.ram_to_adding_ldi_ram_in_c) self.cu_to_adding_ldi_ram_driver_op_a.set_input(self.control_unit.adding_ldi_ram_driver_out_op_a) self.adding_ldi_ram_to_data_driver.input_driver_a.set_input(self.cu_to_adding_ldi_ram_driver_op_a) self.cu_to_adding_ldi_ram_driver_op_b.set_input(self.control_unit.adding_ldi_ram_driver_out_op_b) self.adding_ldi_ram_to_data_driver.input_driver_b.set_input(self.cu_to_adding_ldi_ram_driver_op_b) self.cu_to_adding_ldi_ram_driver_op_c.set_input(self.control_unit.adding_ldi_ram_driver_out_op_c) self.adding_ldi_ram_to_data_driver.input_driver_c.set_input(self.cu_to_adding_ldi_ram_driver_op_c) self.adding_ldi_ram_to_reg_demux.set_input(self.adding_ldi_ram_to_data_driver.output) self.reg_demultiplexer.input.set_input(self.adding_ldi_ram_to_reg_demux) self.control_unit.three_wire_driver = self.adding_ldi_ram_to_data_driver self.control_unit.single_wire_driver = self.reg_to_ram_adding_driver self.control_unit.register = self.register self.control_unit.four_wire_demultiplexer = self.reg_demultiplexer self.control_unit.four_wire_multiplexer = self.reg_multiplexer self.control_unit.two_wire_demultiplexer = self.adding_ram_demux self.control_unit.ram = self.ram self.control_unit.console_out = self.console_out self.control_unit.adding_unit = self.adding_unit self.control_unit.clock = self.clock def flashcommand(self, command: str): self.rom.add_instruction(self.counter, command) self.counter += 1 def run(self): self.clock.add_notify(self.instruction_counter) self.clock.add_notify(self.rom) self.clock.add_notify(self.control_unit) self.clock.run()