Example #1
0
        private void SeekToBookmark(int bookmarkEventIndex)
        {
            Core core;

            int startIndex = 0;

            // First find the bookmark.
            if (bookmarkEventIndex == -1)
            {
                core = Core.Create(Core.LatestVersion, Core.Type.CPC6128);
                Display.GetFromBookmark(null);
            }
            else
            {
                Bookmark bookmark = (_historyEvents[bookmarkEventIndex] as BookmarkHistoryEvent).Bookmark;
                core = Core.Create(bookmark.Version, bookmark.State.GetBytes());
                Display.GetFromBookmark(bookmark);
                startIndex = bookmarkEventIndex;
            }

            for (int i = startIndex; i < _historyEvents.Count; i++)
            {
                HistoryEvent historyEvent = _historyEvents[i];
                if (historyEvent is CoreActionHistoryEvent coreActionHistoryEvent)
                {
                    core.PushRequest(CoreRequest.RunUntil(coreActionHistoryEvent.Ticks));
                    core.PushRequest(coreActionHistoryEvent.CoreAction);
                }
            }

            core.PushRequest(CoreRequest.RunUntil(_endTicks));

            Core              = core;
            Core.Auditors     = RequestProcessed;
            Core.IdleRequest += IdleRequest;

            SetCoreRunning();
        }
Example #2
0
        static public CoreRequest CoreRequestFromBytes(MemoryByteStream stream)
        {
            byte type = stream.ReadByte();

            switch (type)
            {
            case _coreActionKeyPress:
            {
                byte keyCode = stream.ReadByte();
                bool keyDown = stream.ReadBool();

                return(CoreRequest.KeyPress(keyCode, keyDown));
            }

            case _coreActionReset:
            {
                return(CoreRequest.Reset());
            }

            case _coreActionLoadDisc:
            {
                byte   drive = stream.ReadByte();
                byte[] media = stream.ReadArray();

                return(CoreRequest.LoadDisc(drive, media));
            }

            case _coreActionLoadTape:
            {
                byte[] media = stream.ReadArray();

                return(CoreRequest.LoadTape(media));
            }

            case _coreActionRunUntil:
            {
                UInt64 stopTicks = stream.ReadUInt64();

                return(CoreRequest.RunUntil(stopTicks));
            }

            case _coreActionLoadCore:
            {
                byte[] state = stream.ReadArray();

                return(CoreRequest.LoadCore(new MemoryBlob(state)));
            }

            case _coreActionCoreVersion:
            {
                Int32 version = stream.ReadInt32();

                return(CoreRequest.CoreVersion(version));
            }

            case _coreActionCreateSnapshot:
            {
                Int32 snapshotId = stream.ReadInt32();

                return(CoreRequest.CreateSnapshot(snapshotId));
            }

            case _coreActionDeleteSnapshot:
            {
                Int32 snapshotId = stream.ReadInt32();

                return(CoreRequest.DeleteSnapshot(snapshotId));
            }

            case _coreActionRevertToSnapshot:
            {
                Int32 snapshotId = stream.ReadInt32();

                return(CoreRequest.RevertToSnapshot(snapshotId, null));
            }

            default:
                throw new Exception(String.Format("Unknown CoreRequest type {0}!", type));
            }
        }
Example #3
0
 public CoreRequest IdleRequest()
 {
     return((RunningState == RunningState.Running) ? CoreRequest.RunUntil(Ticks + 1000) : null);
 }