Пример #1
0
        /// <summary>
        /// Create a new instance of this device for the given cycle
        /// </summary>
        /// <param name="bankID">BankID of the device</param>
        /// <param name="cycle">Zero-based program cycle number</param>
        /// <param name="code">Data area section string from the assembly code file</param>
        public DataRamModel(Bank bankID, int cycle, string code) : base(bankID, cycle, VALUE_WIDTH, ADDR_WIDTH, PIPELINE_DELAY)
        {
            // name
            name = bankID == Bank.Bank_A
                                ? DevicePort.DataRam_A.ToString()
                                : DevicePort.DataRam_B.ToString();

            // instructions
            var instr = ActiveInstr(bankID, cycle);

            instructions.Add(instr);

            // connectionInputs
            connectionInputs = Connections(bankID, cycle);

            // output
            output = OutputCalc(bankID, cycle);

            // ram
            var field = bankID == Bank.Bank_A ? "DAram" : "DBram";

            ram = DFBState.GetCySimulatorPrivateField <long[]>(cycle, field);

            // address / addressPrev
            field       = bankID == Bank.Bank_A ? "Aaddrnext" : "Baddrnext";
            address     = DFBState.GetCySimulatorPrivateField <int?>(cycle, field);
            addressPrev = DFBState.GetCySimulatorPrivateField <int?>(cycle - 1, field);

            // valuePrev
            valuePrev = OutputCalc(bankID, cycle - 1).Value;

            // valueWritten
            var writeInstr = instructions[0].Equals("write(db)") || instructions[0].Equals("write(da)");

            if (writeInstr)
            {
                var mux1_Output = Mux1Model.OutputCalc(bankID, cycle);
                if (mux1_Output.Value.HasValue)
                {
                    valueWritten = mux1_Output.Value;
                }
            }

            ramItems = BuildRamItems(bankID, this.ram, code);

            var sb = new StringBuilder();

            foreach (var ramItem in RamItems)
            {
                sb.AppendFormat("{0,6} {1,8} {2,10} {3,11} {4}\n", "[" + ramItem.Address + "]", ramItem.ValHex, ramItem.ValDfb, ramItem.ValInt, ramItem.Comment);
            }
            ramString = sb.ToString().TrimEnd('\n');
        }
Пример #2
0
        /// <summary>
        /// Input connections to device
        /// </summary>
        /// <param name="bankID">BankID of the device</param>
        /// <param name="cycle">Zero-based program cycle number</param>
        /// <returns></returns>
        private static List <Connection> Connections(Bank bankID, int cycle)
        {
            var conns = new List <Connection>();

            DevicePort mux1PortOut       = DevicePort.Default;
            DevicePort dataRamPortOut    = DevicePort.Default;
            DevicePort mux2Mux1PortIn    = DevicePort.Default;
            DevicePort mux2DataRamPortIn = DevicePort.Default;

            PortStatus mux1PortOut_Stat;
            PortStatus dataRamPortOut_Stat;
            PortStatus mux2Mux1PortIn_Stat;
            PortStatus mux2DataRamPortIn_Stat;

            var mux1_label    = Mux1Model.OutputCalc(bankID, cycle).FormattedValue;
            var dataRam_label = DataRamModel.OutputCalc(bankID, cycle).FormattedValue;

            InputsUsed(bankID, cycle,
                       out mux1PortOut_Stat,
                       out dataRamPortOut_Stat,
                       out mux2Mux1PortIn_Stat,
                       out mux2DataRamPortIn_Stat);

            switch (bankID)
            {
            case Bank.Bank_A:
                mux1PortOut       = DevicePort.Mux_1A;
                dataRamPortOut    = DevicePort.DataRam_A;
                mux2Mux1PortIn    = DevicePort.Mux_2A;
                mux2DataRamPortIn = DevicePort.Mux_2A;
                break;

            case Bank.Bank_B:
                mux1PortOut       = DevicePort.Mux_1B;
                dataRamPortOut    = DevicePort.DataRam_B;
                mux2Mux1PortIn    = DevicePort.Mux_2B;
                mux2DataRamPortIn = DevicePort.Mux_2B;
                break;

            default:
                break;
            }

            conns.Add(new Connection(
                          BusType.Data,
                          mux1PortOut,
                          mux1PortOut_Stat,
                          mux1_label,
                          null,
                          mux2Mux1PortIn,
                          mux2Mux1PortIn_Stat));

            conns.Add(new Connection(
                          BusType.Data,
                          dataRamPortOut,
                          dataRamPortOut_Stat,
                          dataRam_label,
                          null,
                          mux2DataRamPortIn,
                          mux2DataRamPortIn_Stat));

            return(conns);
        }
Пример #3
0
        /// <summary>
        /// Input to the device for the given cycle
        /// </summary>
        /// <param name="bankID">BankID of the device</param>
        /// <param name="cycle">Zero-based program cycle number</param>
        /// <param name="input0">First input</param>
        /// <param name="input0src">First input source</param>
        /// <param name="input1">Second input</param>
        /// <param name="input1src">Second input source</param>
        private static void InputCalc(Bank bankID, int cycle,
                                      out LabeledValue <long?> input0,
                                      out LabeledValue <DevicePort?> input0src,
                                      out LabeledValue <long?> input1,
                                      out LabeledValue <DevicePort?> input1src)
        {
            var valLabel = "In:";
            var srcLabel = "Src:";

            input0    = new LabeledValue <long?>(valLabel);
            input1    = new LabeledValue <long?>(valLabel);
            input0src = new LabeledValue <DevicePort?>(srcLabel);
            input1src = new LabeledValue <DevicePort?>(srcLabel);

            // Input latching occurs as follows (variant pipeline):
            // Pipeline					[t-1]		[now]
            // Cycle					cycle		cycle-1
            // dmux(_r_, _r_)			->ram in	output->
            // dmux(__, __)							->mux1in & output->

            var ramSource = bankID == Bank.Bank_A
                                                ? DevicePort.DataRam_A
                                                : DevicePort.DataRam_B;

            var mux1Source = bankID == Bank.Bank_A
                                                ? DevicePort.Mux_1A
                                                : DevicePort.Mux_1B;

            // Get [now] / cycle-1 input values
            var instr1 = InstrForCycle(bankID, cycle - 1);

            switch (instr1)
            {
            // These inputs latched from data ram in [t-1]
            case "bra":
            case "sra":
            case "brm":
            case "srm":
                input1.Value             = DataRamModel.OutputCalc(bankID, cycle - 1).Value;
                input1.FormattedValue    = FormatValue(VALUE_WIDTH, input1.Value);
                input1src.Value          = ramSource;
                input1src.FormattedValue = input1src.Value.ToString();
                break;

            // These inputs latch from mux1 [now]
            case "ba":
            case "sa":
            case "bm":
            case "sm":
                input1.Value             = Mux1Model.OutputCalc(bankID, cycle).Value;
                input1.FormattedValue    = FormatValue(VALUE_WIDTH, input1.Value);
                input1src.Value          = mux1Source;
                input1src.FormattedValue = input1src.Value.ToString();
                break;
            }

            // Get [t-1] / cycle input values
            var instr0 = InstrForCycle(bankID, cycle);

            switch (instr0)
            {
            case "bra":
            case "sra":
            case "brm":
            case "srm":
                input0.Value             = DataRamModel.OutputCalc(bankID, cycle).Value;
                input0.FormattedValue    = FormatValue(VALUE_WIDTH, input0.Value);
                input0src.Value          = ramSource;
                input0src.FormattedValue = input0src.Value.ToString();
                break;

            // no op:
            case "ba":
            case "sa":
            case "bm":
            case "sm":
            default:
                break;
            }
        }
Пример #4
0
        /// <summary>
        /// Input connections to device
        /// </summary>
        /// <param name="bankID">BankID of the device</param>
        /// <param name="cycle">Zero-based program cycle number</param>
        /// <returns></returns>
        private static List <Connection> Connections(Bank bankID, int cycle)
        {
            var conns = new List <Connection>();

            DevicePort acuAddrPortOut = DevicePort.Default;
            DevicePort mux1PortOut    = DevicePort.Default;

            DevicePort ramACUPortIn  = DevicePort.Default;
            DevicePort ramMux1PortIn = DevicePort.Default;

            PortStatus acuAddrPortOut_Stat;
            PortStatus mux1PortOut_Stat;

            PortStatus ramACUPortIn_Stat;
            PortStatus ramMux1PortIn_Stat;

            InputsUsed(bankID, cycle,
                       out acuAddrPortOut_Stat,
                       out mux1PortOut_Stat,
                       out ramACUPortIn_Stat,
                       out ramMux1PortIn_Stat);

            var mux1_Model = Mux1Model.OutputCalc(bankID, cycle);
            var mux1_label = mux1_Model.FormattedValue;

            var acu_Model = ACUModel.OutputCalc(bankID, cycle);
            var acu_label = acu_Model.FormattedValue;

            switch (bankID)
            {
            case Bank.Bank_A:
                acuAddrPortOut = DevicePort.ACU_A;
                ramACUPortIn   = DevicePort.DataRam_A;
                mux1PortOut    = DevicePort.Mux_1A;
                ramMux1PortIn  = DevicePort.DataRam_A;
                break;

            case Bank.Bank_B:
                acuAddrPortOut = DevicePort.ACU_B;
                ramACUPortIn   = DevicePort.DataRam_B;
                mux1PortOut    = DevicePort.Mux_1B;
                ramMux1PortIn  = DevicePort.DataRam_B;
                break;
            }

            conns.Add(new Connection(
                          BusType.Address,
                          acuAddrPortOut,
                          acuAddrPortOut_Stat,
                          acu_label,
                          null,
                          ramACUPortIn,
                          ramACUPortIn_Stat));

            conns.Add(new Connection(
                          BusType.Data,
                          mux1PortOut,
                          mux1PortOut_Stat,
                          mux1_label,
                          null,
                          ramMux1PortIn,
                          ramMux1PortIn_Stat));

            return(conns);
        }