Exemplo n.º 1
0
        private static Word PopValue(CpuRegister sp, Memory memory)
        {
            Word value = memory.Read(sp.Value);

            sp.Increment();
            return(value);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 命令を実行します。
        /// </summary>
        /// <param name="rR1Field">命令語の中の r/r1 フィールドの値です。</param>
        /// <param name="xR2Field">命令語の中の x/r2 フィールドの値です。</param>
        /// <param name="registerSet">COMET II の一そろいのレジスタです。</param>
        /// <param name="memory">COMET II の主記憶です。</param>
        internal void Execute(UInt16 rR1Field, UInt16 xR2Field, CpuRegisterSet registerSet, Memory memory)
        {
            CpuRegister r       = m_registerHandler.GetRegister(rR1Field, registerSet);
            Word        operand = m_operandHandler.GetOperand(xR2Field, registerSet, memory);

            m_operator.Operate(r, operand, registerSet, memory);
        }
Exemplo n.º 3
0
 private static void DoJump(Boolean condition, Word operand, CpuRegister pr)
 {
     if (condition)
     {
         pr.Value = operand;
     }
 }
Exemplo n.º 4
0
        private static void UnconditionalJumpAction(
            CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
        {
            const Boolean Condition = true;

            DoJump(Condition, operand, registerSet.PR);
        }
Exemplo n.º 5
0
        private static void JumpOnOverflowAction(
            CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
        {
            Boolean condition = registerSet.FR.OF;

            DoJump(condition, operand, registerSet.PR);
        }
Exemplo n.º 6
0
        private static void JumpOnNonZeroAction(
            CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
        {
            Boolean condition = !registerSet.FR.ZF;

            DoJump(condition, operand, registerSet.PR);
        }
Exemplo n.º 7
0
        internal void OnReturingFromSubroutine(Object sender, ReturningFromSubroutineEventArgs e)
        {
            // RET 命令で SP が初期値ならば、実行を終了する。
            CpuRegister sp = e.SP;

            e.Cancel = (sp.Value == InitialSp);
        }
Exemplo n.º 8
0
        /// <summary>
        /// PR レジスタが指すアドレスの内容を読み出しその値を返します。
        /// PR レジスタの内容に 1 を加えます。
        /// </summary>
        /// <param name="pr">Program Register (PR) です。</param>
        /// <param name="memory">COMET II の主記憶です。</param>
        /// <returns>PR レジスタが指すアドレスの内容を返します。</returns>
        internal static Word Fetch(CpuRegister pr, Memory memory)
        {
            Word word = memory.Read(pr.Value);

            pr.Increment();
            return(word);
        }
Exemplo n.º 9
0
        /// <summary>
        /// それぞれのフラグの値を設定します。オーバーフローフラグは指定の値を、
        /// サインフラグとゼロフラグは指定のレジスタの値から設定します。
        /// </summary>
        /// <param name="r">サインフラグとゼロフラグの値の設定に使用するレジスタです。</param>
        /// <param name="overflowFlag">オーバーフローフラグに設定する値です。</param>
        internal void SetFlags(CpuRegister r, Boolean overflowFlag)
        {
            Boolean signFlag = r.Value.IsMinus();
            Boolean zeroFlag = r.Value.IsZero();

            SetFlags(overflowFlag, signFlag, zeroFlag);
        }
Exemplo n.º 10
0
        private static void LoadWithFrAction(
            CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
        {
            r.Value = operand;
            const Boolean OverflowFlag = false;

            registerSet.FR.SetFlags(r, OverflowFlag);
        }
Exemplo n.º 11
0
        private static void JumpOnPlusAction(
            CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
        {
            FlagRegister fr        = registerSet.FR;
            Boolean      condition = (!fr.SF && !fr.ZF);

            DoJump(condition, operand, registerSet.PR);
        }
Exemplo n.º 12
0
        private static void CallSubroutineAction(
            CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
        {
            CpuRegister pr = registerSet.PR;

            PushValue(registerSet.SP, memory, pr.Value);
            pr.Value = operand;
        }
Exemplo n.º 13
0
        private static Word DoGetRegister(UInt16 xR2Field, CpuRegisterSet registerSet)
        {
            ArgChecker.CheckRange(xR2Field, 0, RegisterDef.GrCount - 1, "x/r2");

            CpuRegister x = registerSet.GR[xR2Field];

            return(x.Value);
        }
Exemplo n.º 14
0
        private static void DoOperation(
            Alu.OperationMethod operationMethod, CpuRegister r, Word operand, FlagRegister fr, Memory memory)
        {
            Boolean overflowFlag;

            r.Value = operationMethod(r.Value, operand, out overflowFlag);
            fr.SetFlags(r, overflowFlag);
        }
Exemplo n.º 15
0
        /// <summary>
        /// <see cref="CpuRegisterSet"/> のインスタンスを初期化します。
        /// </summary>
        internal CpuRegisterSet()
        {
            m_generalRegisters = new GeneralRegisters();
            m_stackPointer     = new CpuRegister(RegisterDef.SP);
            m_programRegister  = new CpuRegister(RegisterDef.PR);
            m_flagRegister     = new FlagRegister();

            Reset();
        }
Exemplo n.º 16
0
        private static void DoShift(
            Alu.ShiftMethod shiftMethod, CpuRegister r, Word operand, FlagRegister fr)
        {
            UInt16 lastShiftedOutBit;

            r.Value = shiftMethod(r.Value, operand, out lastShiftedOutBit);
            Boolean overflowFlag = (lastShiftedOutBit != 0);

            fr.SetFlags(r, overflowFlag);
        }
Exemplo n.º 17
0
        private static void DoCompare(
            Alu.CompareMethod compareMethod, CpuRegister r, Word operand, FlagRegister fr)
        {
            Boolean signFlag;
            Boolean zeroFlag;

            compareMethod(r.Value, operand, out signFlag, out zeroFlag);
            const Boolean OverflowFlag = false;

            fr.SetFlags(OverflowFlag, signFlag, zeroFlag);
        }
Exemplo n.º 18
0
        private static void ReturnFromSubroutineAction(
            CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
        {
            Boolean cancel = OnReturningFromSubroutine(registerSet.SP);

            if (!cancel)
            {
                CpuRegister pr = registerSet.PR;
                pr.Value = PopValue(registerSet.SP, memory);
            }
        }
Exemplo n.º 19
0
        private static void DoLogic(
            Alu.OperationMethod operationMethod, CpuRegister r, Word operand, FlagRegister fr, Memory memory)
        {
            Boolean notUsed;

            r.Value = operationMethod(r.Value, operand, out notUsed);

            const Boolean OverflowFlag = false;

            fr.SetFlags(r, OverflowFlag);
        }
Exemplo n.º 20
0
        private static Boolean OnReturningFromSubroutine(CpuRegister sp)
        {
            Boolean cancel = false;

            if (ReturningFromSubroutine != null)
            {
                ReturningFromSubroutineEventArgs e = new ReturningFromSubroutineEventArgs(sp);
                ReturningFromSubroutine(null, e);
                cancel = e.Cancel;
            }

            return(cancel);
        }
Exemplo n.º 21
0
 private static void AddLogicalAction(
     CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
 {
     DoOperation(Alu.AddLogical, r, operand, registerSet.FR, memory);
 }
Exemplo n.º 22
0
 private static void SubtractArithmeticAction(
     CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
 {
     DoOperation(Alu.SubtractArithmetic, r, operand, registerSet.FR, memory);
 }
Exemplo n.º 23
0
 private static void LoadWithoutFrAction(
     CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
 {
     r.Value = operand;
 }
Exemplo n.º 24
0
 /// <summary>
 /// 演算を実行します。
 /// </summary>
 /// <param name="r">演算に使用するレジスタです。</param>
 /// <param name="operand">演算対象の値を保持する語です。</param>
 /// <param name="registerSet">COMET II の一そろいのレジスタです。</param>
 /// <param name="memory">COMET II の主記憶です。</param>
 internal void Operate(CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
 {
     m_operateAction(r, operand, registerSet, memory);
 }
Exemplo n.º 25
0
 private static void PopAction(
     CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
 {
     r.Value = PopValue(registerSet.SP, memory);
 }
Exemplo n.º 26
0
 private static void NoOperationAction(
     CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
 {
     //
 }
Exemplo n.º 27
0
 private static void SuperVisorCallAction(
     CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
 {
     OnCallingSuperVisor(operand);
 }
Exemplo n.º 28
0
 private static void PushAction(
     CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
 {
     PushValue(registerSet.SP, memory, operand);
 }
Exemplo n.º 29
0
 private static void StoreAction(
     CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory)
 {
     memory.Write(operand, r.Value);
 }
Exemplo n.º 30
0
 private static void PushValue(CpuRegister sp, Memory memory, Word value)
 {
     sp.Decrement();
     memory.Write(sp.Value, value);
 }