1
0
mirror of https://github.com/livingcomputermuseum/ContrAlto.git synced 2026-03-01 17:36:14 +00:00

Initial commit of changes for 1.2.3. This includes:

- Scripting support: Allows for recording and playback of mouse/keyboard input and various system control actions.  Simple (i.e. basic) scripting format.

- Fix for stale packets left in ethernet input queue; packets received by pcap while Alto's receiver is off are discarded.

- Mouse input made more accurate, and tweaked to avoid Alto microcode bug that causes erroneous mouse inputs under very rare circumstances on real hardware, but much more frequently under emulation.

- Small code cleanup here and there.  Moved many UI strings to resources, many more to go.
This commit is contained in:
Josh Dersch
2018-03-20 14:16:07 -07:00
parent 6f20ebbfe7
commit d96d232fd3
39 changed files with 2733 additions and 510 deletions

View File

@@ -0,0 +1,126 @@
using Contralto.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contralto.Scripting
{
public static class ScriptManager
{
static ScriptManager()
{
_scheduler = new Scheduler();
}
public static Scheduler ScriptScheduler
{
get { return _scheduler; }
}
/// <summary>
/// Fired when playback of a script has completed or is stopped.
/// </summary>
public static event EventHandler PlaybackCompleted;
public static void StartRecording(AltoSystem system, string scriptPath)
{
// Stop any pending actions
StopRecording();
StopPlayback();
_scriptRecorder = new ScriptRecorder(system, scriptPath);
Log.Write(LogComponent.Scripting, "Starting recording to {0}", scriptPath);
//
// Record the absolute position of the mouse (as held in MOUSELOC in system memory).
// All other mouse movements in the script will be recorded relative to this point.
//
int x = system.Memory.Read(0x114, CPU.TaskType.Ethernet, false);
int y = system.Memory.Read(0x115, CPU.TaskType.Ethernet, false);
_scriptRecorder.MouseMoveAbsolute(x, y);
}
public static void StopRecording()
{
if (IsRecording)
{
_scriptRecorder.End();
_scriptRecorder = null;
}
Log.Write(LogComponent.Scripting, "Stopped recording.");
}
public static void StartPlayback(AltoSystem system, ExecutionController controller, string scriptPath)
{
// Stop any pending actions
StopRecording();
StopPlayback();
_scheduler.Reset();
_scriptPlayback = new ScriptPlayback(scriptPath, system, controller);
_scriptPlayback.PlaybackCompleted += OnPlaybackCompleted;
_scriptPlayback.Start();
Log.Write(LogComponent.Scripting, "Starting playback of {0}", scriptPath);
}
public static void StopPlayback()
{
if (IsPlaying)
{
_scriptPlayback.Stop();
_scriptPlayback = null;
PlaybackCompleted(null, null);
}
Log.Write(LogComponent.Scripting, "Stopped playback.");
}
public static void CompleteWait()
{
if (IsPlaying)
{
_scriptPlayback.Start();
Log.Write(LogComponent.Scripting, "Playback resumed after Wait.");
}
}
public static ScriptRecorder Recorder
{
get { return _scriptRecorder; }
}
public static ScriptPlayback Playback
{
get { return _scriptPlayback; }
}
public static bool IsRecording
{
get { return _scriptRecorder != null; }
}
public static bool IsPlaying
{
get { return _scriptPlayback != null; }
}
private static void OnPlaybackCompleted(object sender, EventArgs e)
{
_scriptPlayback = null;
PlaybackCompleted(null, null);
}
private static ScriptRecorder _scriptRecorder;
private static ScriptPlayback _scriptPlayback;
private static Scheduler _scheduler;
}
}