private void UpdateStack() { var oldStackList = MachineStack.Reverse().ToList(); MachineStack.Clear(); int currentSp = _debugger.CPU.SP; ushort topStack = IsAnApp ? TopStackApp : (ushort)0xFFFF; // avoid generating a massive callstack if (currentSp < MachineStackBottom) { int maxStackSize = topStack - MachineStackBottom; topStack = (ushort)(currentSp + maxStackSize); } if ((currentSp < _oldSp) || (currentSp < topStack && oldStackList.Count == 0)) { // new stack entries to add while (currentSp != _oldSp && currentSp <= topStack) { CallStackEntry callStackEntry = CheckValidCall(currentSp); MachineStack.Push(new StackEntry((ushort)currentSp, ReadShort((ushort)currentSp), callStackEntry)); currentSp += 2; } } else if (currentSp > _oldSp) { // stack entries to remove oldStackList.RemoveAll(s => s.Address < currentSp); } foreach (StackEntry stackEntry in oldStackList) { int data = ReadShort((ushort)currentSp); if (stackEntry.Data != data) { CallStackEntry callStackEntry = CheckValidCall(currentSp); MachineStack.Push(new StackEntry((ushort)currentSp, (ushort)data, callStackEntry)); } else { MachineStack.Push(stackEntry); } currentSp += 2; } _oldSp = _debugger.CPU.SP; UpdateCallstack(); }
public StackEntry(ushort address, ushort data, CallStackEntry entry) { Address = address; Data = data; CallStackEntry = entry; }