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,123 @@
using Contralto.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contralto.Scripting
{
/// <summary>
/// Records actions.
/// </summary>
public class ScriptRecorder
{
public ScriptRecorder(AltoSystem system, string scriptFile)
{
_script = new ScriptWriter(scriptFile);
_system = system;
_lastTimestamp = 0;
_firstTime = true;
}
public void End()
{
_script.End();
}
public void KeyDown(AltoKey key)
{
_script.AppendAction(
new KeyAction(
GetRelativeTimestamp(),
key,
true));
}
public void KeyUp(AltoKey key)
{
_script.AppendAction(
new KeyAction(
GetRelativeTimestamp(),
key,
false));
}
public void MouseDown(AltoMouseButton button)
{
_script.AppendAction(
new MouseButtonAction(
GetRelativeTimestamp(),
button,
true));
}
public void MouseUp(AltoMouseButton button)
{
_script.AppendAction(
new MouseButtonAction(
GetRelativeTimestamp(),
button,
false));
}
public void MouseMoveRelative(int dx, int dy)
{
_script.AppendAction(
new MouseMoveAction(
GetRelativeTimestamp(),
dx,
dy,
false));
}
public void MouseMoveAbsolute(int dx, int dy)
{
_script.AppendAction(
new MouseMoveAction(
GetRelativeTimestamp(),
dx,
dy,
true));
}
public void Command(string command)
{
_script.AppendAction(
new CommandAction(
GetRelativeTimestamp(),
command));
}
private ulong GetRelativeTimestamp()
{
if (_firstTime)
{
_firstTime = false;
//
// First item recorded, occurs at relative timestamp 0.
//
_lastTimestamp = ScriptManager.ScriptScheduler.CurrentTimeNsec;
return 0;
}
else
{
//
// relative time is delta between current system timestamp and the last
// recorded entry.
ulong relativeTimestamp = ScriptManager.ScriptScheduler.CurrentTimeNsec - _lastTimestamp;
_lastTimestamp = ScriptManager.ScriptScheduler.CurrentTimeNsec;
return relativeTimestamp;
}
}
private bool _enabled;
private AltoSystem _system;
private ulong _lastTimestamp;
private bool _firstTime;
private ScriptWriter _script;
}
}