Implement system menu show delay opcodes

This commit is contained in:
gamer147
2026-07-29 14:45:37 -04:00
parent 2065a1c504
commit 2993962307
8 changed files with 201 additions and 25 deletions

View File

@@ -0,0 +1,71 @@
using Age.Engine.Model;
using Age.Engine.Sys4;
using Age.Engine.Vm;
public class SystemMenuShowDelayOpcodeTests
{
private static readonly OpcodeTable Table = OpcodeTableJson.Load(Paths.OpcodesJson);
private static Operand I(long value) => new(0, value);
private static Operand G(long address) => new(3, address);
private static (int, Operand[]) Exit() => (0x2, Array.Empty<Operand>());
[Fact]
public void System4DelayRoundTripsThroughThePairedGetter()
{
Script system4 = ScriptAssembler.Assemble(Table, "SYSTEM4.BIN",
[
(0x149, [I(1000)]),
(0x148, [G(0x100)]),
Exit(),
], []);
var vm = new VirtualMachine(system4, Table, new RecordingHost());
Assert.Equal(0u, vm.SystemMenuShowDelayMilliseconds);
vm.Run();
Assert.Equal(1000u, vm.SystemMenuShowDelayMilliseconds);
Assert.Equal(1000, vm.Globals[0x100]);
}
[Fact]
public void SetterAndGetterPreserveTheCompleteNativeDword()
{
Script system4 = ScriptAssembler.Assemble(Table, "SYSTEM4.BIN",
[
(0x149, [I(0x80000001L)]),
(0x148, [G(0x100)]),
Exit(),
], []);
var vm = new VirtualMachine(system4, Table, new RecordingHost());
vm.Run();
Assert.Equal(0x80000001u, vm.SystemMenuShowDelayMilliseconds);
Assert.Equal(unchecked((int)0x80000001u), vm.Globals[0x100]);
}
[Fact]
public void RootSceneReloadRestoresTheZeroDefault()
{
Script reloadedSystem4 = ScriptAssembler.Assemble(Table, "SYSTEM4.BIN",
[
(0x148, [G(0x100)]),
Exit(),
], []);
Script initial = ScriptAssembler.Assemble(Table, "INITIAL",
[
(0x149, [I(1000)]),
(0x9, Array.Empty<Operand>()),
], []);
var provider = new MapProvider(new Dictionary<long, Script> { [0] = reloadedSystem4 });
var host = new RecordingHost();
var vm = new VirtualMachine(initial, Table, host, provider: provider);
vm.Run();
Assert.Equal(0u, vm.SystemMenuShowDelayMilliseconds);
Assert.Equal(0, vm.Globals[0x100]);
Assert.Equal(1, host.SceneContextResets);
}
}

View File

@@ -91,6 +91,9 @@ public sealed class VirtualMachine
// EngineCtx +0xa0d10: AGERC queries this through IAGEService to gray its native
// settings/save menu actions while CONFIG owns the scripted settings screen.
private int _systemMenuActionsEnabled = 1;
// EngineCtx +0x5511c: unsigned TIMER_SHOWMENU dwell threshold. Native op 0x148
// returns the same dword through the VM's signed integer-cell representation.
private uint _systemMenuShowDelayMilliseconds;
private readonly Dictionary<string, int> _valueSwitchTargets = new(StringComparer.Ordinal);
// Native EngineCtx owns 11 lazily allocated integer FIFOs at +0x55130. ATSEEK/MVSEEK use
// slot zero as their packed-coordinate flood-fill worklist; op 0x132 replaces a slot.
@@ -115,6 +118,7 @@ public sealed class VirtualMachine
public bool AutoMessageEnabled => _autoMessageEnabled;
public bool MessageSkipEnabled => _messageSkipEnabled;
public int SystemMenuActionsEnabled => _systemMenuActionsEnabled;
public uint SystemMenuShowDelayMilliseconds => _systemMenuShowDelayMilliseconds;
public string PendingDiagnosticText => _diagnosticOutput.PendingText;
/// <summary>
/// Zero-based active-frame cutoff selected by opcode 0x1ad, or null when no surviving marker
@@ -786,6 +790,7 @@ public sealed class VirtualMachine
_advReadSkipState = false;
_advTextStyle = AdvTextStyle.Default;
_systemMenuActionsEnabled = 1;
_systemMenuShowDelayMilliseconds = 0;
TextHistory.SetRecordingEnabled(true);
_host.SetMessageSkipActive(false);
_host.SetPhysicalMessageSkipActive(false);
@@ -2343,6 +2348,14 @@ public sealed class VirtualMachine
case "u0041FB10": // pre-reference compatibility
_systemMenuActionsEnabled = unchecked((int)Read(a[0]));
return pc + 1;
case "get-system-menu-show-delay": // 0x148: paired TIMER_SHOWMENU getter
case "u004160A0": // pre-reference compatibility
Write(a[0], unchecked((int)_systemMenuShowDelayMilliseconds));
return pc + 1;
case "set-system-menu-show-delay": // 0x149: top-edge dwell threshold in milliseconds
case "u0041FCE0": // pre-reference compatibility
_systemMenuShowDelayMilliseconds = unchecked((uint)Read(a[0]));
return pc + 1;
case "get-message-glyph-delay": // 0x7f
case "u00414C60":
Write(a[0], _messageGlyphDelayMilliseconds); return pc + 1;