private static Word PopValue(CpuRegister sp, Memory memory) { Word value = memory.Read(sp.Value); sp.Increment(); return(value); }
/// <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); }
private static void DoJump(Boolean condition, Word operand, CpuRegister pr) { if (condition) { pr.Value = operand; } }
private static void UnconditionalJumpAction( CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory) { const Boolean Condition = true; DoJump(Condition, operand, registerSet.PR); }
private static void JumpOnOverflowAction( CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory) { Boolean condition = registerSet.FR.OF; DoJump(condition, operand, registerSet.PR); }
private static void JumpOnNonZeroAction( CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory) { Boolean condition = !registerSet.FR.ZF; DoJump(condition, operand, registerSet.PR); }
internal void OnReturingFromSubroutine(Object sender, ReturningFromSubroutineEventArgs e) { // RET 命令で SP が初期値ならば、実行を終了する。 CpuRegister sp = e.SP; e.Cancel = (sp.Value == InitialSp); }
/// <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); }
/// <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); }
private static void LoadWithFrAction( CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory) { r.Value = operand; const Boolean OverflowFlag = false; registerSet.FR.SetFlags(r, OverflowFlag); }
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); }
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; }
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); }
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); }
/// <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(); }
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); }
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); }
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); } }
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); }
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); }
private static void AddLogicalAction( CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory) { DoOperation(Alu.AddLogical, r, operand, registerSet.FR, memory); }
private static void SubtractArithmeticAction( CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory) { DoOperation(Alu.SubtractArithmetic, r, operand, registerSet.FR, memory); }
private static void LoadWithoutFrAction( CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory) { r.Value = operand; }
/// <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); }
private static void PopAction( CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory) { r.Value = PopValue(registerSet.SP, memory); }
private static void NoOperationAction( CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory) { // }
private static void SuperVisorCallAction( CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory) { OnCallingSuperVisor(operand); }
private static void PushAction( CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory) { PushValue(registerSet.SP, memory, operand); }
private static void StoreAction( CpuRegister r, Word operand, CpuRegisterSet registerSet, Memory memory) { memory.Write(operand, r.Value); }
private static void PushValue(CpuRegister sp, Memory memory, Word value) { sp.Decrement(); memory.Write(sp.Value, value); }