public void Run(int MaxCycles) { // TODO - reset? //Machine = new Tiny64.Machine(); /* * GR.Image.MemoryImage img = new GR.Image.MemoryImage( 320, 200, System.Drawing.Imaging.PixelFormat.Format8bppIndexed ); * C64Studio.CustomRenderer.PaletteManager.ApplyPalette( img );*/ State = EmulatorState.RUNNING; int usedCycles = 0; while (usedCycles < MaxCycles) { // round about one frame //int numCycles = 19656; ushort oldPC = Machine.CPU.PC; // TODO - single cycle steps? int curCycles = Machine.RunCycle(); if (Machine.TriggeredBreakpoints.Count > 0) { Debug.Log("Breakpoint triggered at $" + Machine.CPU.PC.ToString("X4")); State = EmulatorState.PAUSED; return; } usedCycles += curCycles; //Debug.Log( machine.CPU.PC.ToString( "X4" ) + ":" + opCode.ToString( "X2" ) + " A:" + CPU.Accu.ToString( "X2" ) + " X:" + CPU.X.ToString( "X2" ) + " Y:" + CPU.Y.ToString( "X2" ) + " " + ( Memory.RAM[0xc1] + ( Memory.RAM[0xc2] << 8 ) ).ToString( "X4" ) ); //Debug.Log( machine.CPU.PC.ToString( "X4" ) + ": A:" + machine.CPU.Accu.ToString( "X2" ) + " X:" + machine.CPU.X.ToString( "X2" ) + " Y:" + machine.CPU.Y.ToString( "X2" ) + " " + ( machine.Memory.RAM[0xc1] + ( machine.Memory.RAM[0xc2] << 8 ) ).ToString( "X4" ) ); //RenderFullImage( Machine, img ); } }
public void Run(int MaxCycles) { // TODO - reset? State = EmulatorState.RUNNING; int usedCycles = 0; while (usedCycles < MaxCycles) { // round about one frame //int numCycles = 19656; ushort oldPC = Machine.CPU.PC; // TODO - single cycle steps? int curCycles = Machine.RunCycle(); if (Machine.TriggeredBreakpoints.Count > 0) { Debug.Log("Breakpoint triggered at $" + Machine.CPU.PC.ToString("X4")); State = EmulatorState.PAUSED; return; } usedCycles += curCycles; //Debug.Log( machine.CPU.PC.ToString( "X4" ) + ":" + opCode.ToString( "X2" ) + " A:" + CPU.Accu.ToString( "X2" ) + " X:" + CPU.X.ToString( "X2" ) + " Y:" + CPU.Y.ToString( "X2" ) + " " + ( Memory.RAM[0xc1] + ( Memory.RAM[0xc2] << 8 ) ).ToString( "X4" ) ); //Debug.Log( machine.CPU.PC.ToString( "X4" ) + ": A:" + machine.CPU.Accu.ToString( "X2" ) + " X:" + machine.CPU.X.ToString( "X2" ) + " Y:" + machine.CPU.Y.ToString( "X2" ) + " " + ( machine.Memory.RAM[0xc1] + ( machine.Memory.RAM[0xc2] << 8 ) ).ToString( "X4" ) ); //RenderFullImage( Machine, img ); } }
private async Task BreakCurrentState() { Task task; lock (critical) { if (state == null) { return; } state.Session.Completed = true; state.TokenSource.Cancel(); task = state.ReadTask; state = null; } try { await task; } catch (OperationCanceledException) { } catch (Exception ex) { logger.Value.Info("Break read is failed"); logger.Value.Error(ex.Message, ex); } }
public async Task StartRead() { if (IsStarted()) { logger.Value.Info("Read is already run"); return; } logger.Value.Info("Read has started"); try { state = await Task.Run(() => InitState()).ConfigureAwait(false); state.ReadTask = Task.WhenAll( DataReadTask(), DataChunkTask(), DataSaveTask(), UpdateSessionTask()); await state.ReadTask; logger.Value.Info("Read has completed"); } catch (OperationCanceledException) { logger.Value.Info("Read has been cancelled"); } catch (Exception ex) { logger.Value.Info("Read has failed"); logger.Value.Error(ex.Message, ex); BreakCurrentState().Wait(); } }
public override EmulatorState Run(EmulatorState currentState) { EmulatorState newState = currentState.Clone(); newState.IncrementInstructionCount(); newState.IncrementCurrentIndex(1); return(newState); }
public void StepOver() { var opCode = Machine.CPU.OpcodeByValue[Machine.Memory.ReadByteDirect(Machine.CPU.PC)]; Machine.AddTemporaryBreakpoint((ushort)(Machine.CPU.PC + opCode.NumOperands + 1), false, false, true); State = EmulatorState.RUNNING; }
public void Run() { State = new EmulatorState(); State.Initialize(instructions); do { Instruction currentInstruction = InstructionFactory.CreateInstruction(State.GetCurrentInstruction()); State = currentInstruction.Run(State); } while (!State.TerminateRun); }
public void Stop() { _emulatorState = EmulatorState.ShutDown; if (null != _emulatorNative) { _emulatorNative.Shutdown(); } _mreShutdown.Set(); }
private void btnStop_Click(object sender, EventArgs e) { _emulatorState = EmulatorState.Stop; var buttons = new[] { btnRun, btnRun10x, btnRunOnMaximumSpeed, btnPause }; foreach (var btn in buttons) { btn.Checked = false; } }
public override EmulatorState Run(EmulatorState currentState) { EmulatorState newState = currentState.Clone(); newState.IncrementInstructionCount(); if (!newState.TerminateRun) { newState.IncrementCurrentIndex(argument); } return(newState); }
private void btnPause_Click(object sender, EventArgs e) { if (_emulatorState == EmulatorState.Execution || _emulatorState == EmulatorState.StepByStep) { _emulatorState = EmulatorState.Pause; btnPause.Checked = true; ShowCurrentSourceCodeLine(); } else if (_emulatorState == EmulatorState.Pause) { _emulatorState = EmulatorState.Execution; btnPause.Checked = false; } }
static void Main(string[] args) { var EmulatorState = new EmulatorState(); var Interpreter = new Interpreter(EmulatorState); //EmulatorState.Memory.WriteBytes(0x200, File.ReadAllBytes("../../../games/HIDDEN")); EmulatorState.Memory.WriteBytes(0x200, File.ReadAllBytes("../../../games/TETRIS")); //EmulatorState.Memory.WriteBytes(0x200, File.ReadAllBytes("../../../games/BRIX")); EmulatorState.Registers.PC = 0x200; int m = 0; while (true) { Interpreter.ExecuteFrame(); if ((m++ % 5) == 0) EmulatorState.Display.ConsoleOutput(); Thread.Sleep(20); } }
public Form1() { InitializeComponent(); EmulatorState = new EmulatorState(); Interpreter = new Interpreter(EmulatorState); var Timer = new System.Windows.Forms.Timer(); Timer.Interval = 20; Timer.Tick += Timer_Tick; Timer.Start(); EmulatorState.Memory.WriteBytes(0x200, File.ReadAllBytes("../../../games/HIDDEN")); //EmulatorState.Memory.WriteBytes(0x200, File.ReadAllBytes("../../../games/TETRIS")); //EmulatorState.Memory.WriteBytes(0x200, File.ReadAllBytes("../../../games/BRIX")); EmulatorState.Registers.PC = 0x200; }
private void Remulator_StepCompleted(object sender, EventArgs e) { // Simulate pause button press after each step if we are in step-by-step mode if (_emulatorState == EmulatorState.StepByStep) { _emulatorState = EmulatorState.Pause; _needToShowCurrentLineOfSourceCode = true; return; } if (_executionSpeed == 0) { return; } _needToShowCurrentLineOfSourceCode = _executionSpeed > 0; Thread.Sleep(_executionSpeed); }
private EmulatorState InitState() { lock (critical) { var newState = new EmulatorState(); dataFactory.Value.WithRepository <ISettingsRepository>(repo => { newState.Session.ReadTime = repo.GetReadTime() ?? -TimeSpan.FromSeconds(1); newState.Session.UpdateStopWatch(newState.Session.ReadTime); newState.Session.AllTime = repo.GetAllTime(); newState.Session.Velocity = repo.GetReadVelocity() ?? 1.0; }); logger.Value.InfoFormat("Init read session: AllTime: {0}\tReadTime: {1}\tReadVelocity:{2}", newState.Session.AllTime, newState.Session.ReadTime, newState.Session.Velocity); return(newState); } }
private void btnStep_Click(object sender, EventArgs e) { // If this is restart, then repoint PC to first ROM cell if (_emulatorState == EmulatorState.Stop) { _remu.state.PC = 0; _remu.halt = false; } _emulatorState = EmulatorState.StepByStep; var runButtons = new[] { btnRun, btnRun10x, btnRunOnMaximumSpeed, btnPause }; foreach (var btn in runButtons) { btn.Checked = false; } // We will stop after a moment so we can check Pause button here // This is easier that to invoke it in OnStepCompleted callback from another thread. btnPause.Checked = true; }
private void btnRun_Click(object sender, EventArgs e) { var speed = int.Parse((sender as ToolStripButton).Tag.ToString()); _executionSpeed = speed; // If this is restart, then repoint PC to first ROM cell if (_emulatorState == EmulatorState.Stop) { _remu.state.PC = 0; _remu.halt = false; } _emulatorState = EmulatorState.Execution; var runButtons = new[] { btnRun, btnRun10x, btnRunOnMaximumSpeed }; foreach (var btn in runButtons) { btn.Checked = btn == sender; } btnPause.Checked = false; }
public override void SetupComponent() { _emulatorState = EmulatorState.Setup; CallComponents(delegate(EmulatorComponent component) { component.SetupComponent(); }); }
public override void UninitializeComponent() { _emulatorState = EmulatorState.Uninitialize; CallComponents(delegate(EmulatorComponent component) { component.UninitializeComponent(); }); }
private void StartInternal() { Utility.SetCurrentThreadAffinity(); // Set the verbose flag if (_cmdLn.verbose) { _verbose = true; } // 1) Create all the EmulatorComponents first and configure them properly based on the config file if (_cmdLn.useDefaultConfig) { LoadDefaultComponents(); } for (int iConfig = 0; iConfig < _cmdLn.configFiles.Count; iConfig++) { string configFileName = _cmdLn.configFiles[iConfig]; ApplyConfig(configFileName); } string defaultConfigFileName = Application.ExecutablePath + ".emulatorconfig"; if (File.Exists(defaultConfigFileName)) { ApplyConfig(defaultConfigFileName); } // 2) Calling Setup() on all EmulatorComponents to allow each component to check for the // validity of each properties, allocate memory, ... etc. SetupComponent(); CheckForRequiredComponents(); // 3) Now that the components are in the correct state. Register each component with its collection, // if there is one. RegisterComponentsWithCollection(); try { //Initialization of EmulatorNative required before EmulatorComponents //TimingServices, for example, is dependent on EmulatorNative initialization _emulatorNative.Initialize(this.ManagedHal); // 4) Call InitializeComponent() on all EmulatorComponents to put each component into a // working / running state. InitializeComponent(); // 5) Load the assemblies LoadAssemblies(); // 6) Get into the initial state if (_cmdLn.waitForDebuggerOnStartup) { _emulatorNative.WaitForDebuggerOnStartup(); } if (String.IsNullOrEmpty(_cmdLn.commandLineArguments) == false) { _emulatorNative.SetCommandLineArguments(_cmdLn.commandLineArguments); } _emulatorState = EmulatorState.Running; //start time -- this allows components to hook into events before execution starts TimingServices.ResumeTime(); // 7) We start the emulator. this.Run(); } catch (EmulatorException e) { // if we are shutting down and received the unexpected shut down exception, we'll handle the exception if (e.ErrorCode == CLR_ERRORCODE.CLR_E_SHUTTING_DOWN) { Debug.Assert(this.State >= EmulatorState.ShutDown); } else { // otherwise, re-throw. throw; } } finally { bool needUnintialization = (this.State >= EmulatorState.Initialize); Stop(); if (needUnintialization) { UninitializeComponent(); } } }
public abstract EmulatorState Run(EmulatorState currentState);