Exemple #1
0
        /// <summary>
        /// Commits changes stored in the Delta object.
        /// </summary>
        /// <remarks>
        /// The Delta object is added to the History, and a new
        /// one is allocated.
        /// </remarks>
        /// <returns>Commited Delta object</returns>
        public DataDelta Commit()
        {
            if (Delta.PCWritten)
            {
                _pc = Delta.PC;
            }
            if (Delta.SPWritten)
            {
                _sp = Delta.SP;
            }
            foreach (DataDelta.WrittenLocation location in Delta.WrittenLocations.Values)
            {
                _memory[location.Address] = location.Value;
            }
            if (HistorySize > 0)
            {
                if (HistorySize == _history.Count)
                {
                    _history.RemoveAt(0);
                }
                _history.Add(_delta);
            }
            DataDelta result = _delta;

            _delta = new DataDelta();
            return(result);
        }
Exemple #2
0
 /// <summary>
 /// Clears the Data object.
 /// </summary>
 /// <remarks>
 /// Contents of the memory, registers and the currect Delta object is
 /// cleared.
 /// </remarks>
 public void Clear()
 {
     _memory = new ushort[Size];
     _pc     = 0;
     _sp     = (ushort)(Size - 1);
     _history.Clear();
     _delta = new DataDelta();
 }
Exemple #3
0
        /// <summary>
        /// Uncommits the last DataDelta object from history. (Currect Delta is discarded.)
        /// </summary>
        /// <remarks>
        /// Assuming that Commit() is called after every instruction, calling Uncommit() and
        /// Rollback() after that undoes last executed instruction.
        ///
        /// Uncommit fails if the History is empty.
        /// </remarks>
        /// <returns>A value indicating whether Uncommit was successful.</returns>
        public bool Uncommit()
        {
            if (History.Count > 0)
            {
                _delta = History[History.Count - 1];
                History.RemoveAt(History.Count - 1);

                if (Delta.PCWritten)
                {
                    _pc = Delta.OldPC;
                }
                if (Delta.SPWritten)
                {
                    _sp = Delta.OldSP;
                }
                foreach (DataDelta.WrittenLocation location in Delta.WrittenLocations.Values)
                {
                    _memory[location.Address] = location.OldValue;
                }
                return(true);
            }
            return(false);
        }
Exemple #4
0
        /// <summary>
        /// Uncommits the last DataDelta object from history. (Currect Delta is discarded.)
        /// </summary>
        /// <remarks>
        /// Assuming that Commit() is called after every instruction, calling Uncommit() and
        /// Rollback() after that undoes last executed instruction.
        /// 
        /// Uncommit fails if the History is empty.
        /// </remarks>
        /// <returns>A value indicating whether Uncommit was successful.</returns>
        public bool Uncommit()
        {
            if (History.Count > 0)
            {
                _delta = History[History.Count - 1];
                History.RemoveAt(History.Count - 1);

                if (Delta.PCWritten) _pc = Delta.OldPC;
                if (Delta.SPWritten) _sp = Delta.OldSP;
                foreach (DataDelta.WrittenLocation location in Delta.WrittenLocations.Values)
                {
                    _memory[location.Address] = location.OldValue;
                }
                return true;
            }
            return false;
        }
Exemple #5
0
 /// <summary>
 /// Discards the Delta object.
 /// </summary>
 public void Rollback()
 {
     _delta = new DataDelta();
 }
Exemple #6
0
 /// <summary>
 /// Commits changes stored in the Delta object.
 /// </summary>
 /// <remarks>
 /// The Delta object is added to the History, and a new
 /// one is allocated.
 /// </remarks>
 /// <returns>Commited Delta object</returns>
 public DataDelta Commit()
 {
     if (Delta.PCWritten) _pc = Delta.PC;
     if (Delta.SPWritten) _sp = Delta.SP;
     foreach (DataDelta.WrittenLocation location in Delta.WrittenLocations.Values)
     {
         _memory[location.Address] = location.Value;
     }
     if (HistorySize > 0)
     {
         if (HistorySize == _history.Count)
             _history.RemoveAt(0);
         _history.Add(_delta);
     }
     DataDelta result = _delta;
     _delta = new DataDelta();
     return result;
 }
Exemple #7
0
 /// <summary>
 /// Clears the Data object.
 /// </summary>
 /// <remarks>
 /// Contents of the memory, registers and the currect Delta object is
 /// cleared.
 /// </remarks>
 public void Clear()
 {
     _memory = new ushort[Size];
     _pc = 0;
     _sp = (ushort)(Size - 1);
     _history.Clear();
     _delta = new DataDelta();
 }
Exemple #8
0
 /// <summary>
 /// Discards the Delta object.
 /// </summary>
 public void Rollback()
 {
     _delta = new DataDelta();
 }
 /// <summary>
 /// Sets the NextDelta and the corresponding PC.
 /// </summary>
 /// <remarks>
 /// This method should be used when stepping back to avoid
 /// reexecuting the undone instruction in CalculateNextDelta.
 /// </remarks>
 /// <param name="nextDelta">The Delta of the next instruction</param>
 /// <param name="pc">The address of the instruction</param>
 public void SetNextDelta(DataDelta nextDelta, ushort pc)
 {
     _nextDelta = nextDelta;
     _nextDeltaPC = pc;
 }