Exemple #1
0
 public void Jsr_RegisterOperand_PCSetToRegisterValue()
 {
     var prev = new MutableState()
         .Set(Register.A, 0x10);
     var next = new Jsr(new Reg(Register.A)).Apply(prev);
     Assert.AreEqual(0x10, next.Get(Register.PC));
 }
Exemple #2
0
 public static MutableState ReadFromFile(string path)
 {
     var state = new MutableState();
     var image = Dcpu.LoadImage(path);
     Array.Copy (image, state._memory, Dcpu.MAX_ADDRESS + 1);
     return state;
 }
Exemple #3
0
 public void Jsr_RegisterOperand_PCValuePushedOnStack()
 {
     var prev = new MutableState()
         .Set(Register.A, 0x10)
         .Set(Register.PC, 0x5)
         .Set(Register.SP, 0xFFFF);
     var next = new Jsr(new Reg(Register.A)).Apply(prev);
     Assert.AreEqual(5, next.Get(0xFFFE));
     Assert.AreEqual(0xFFFE, next.Get(Register.SP));
 }
Exemple #4
0
        public void FetchNextInstruction_InstructionGetsCorrectlyDecoded()
        {
            var state = new MutableState()
                .Set((ushort)0, 0x7C02)  // ADD A, next word
                .Set((ushort)1, 0x002A); // 42

            ushort pc=0, sp=0;
            var op = Dcpu.FetchNextInstruction(state, ref pc, ref sp);

            Assert.AreEqual(2, pc);
            Assert.IsTrue(op is Add);

            state = op.Apply(state);
            Assert.AreEqual(42, state.Get(Register.A));
        }