Implement native ADV message skip
This commit is contained in:
@@ -53,6 +53,21 @@ public class HotspotInputTests
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Sc0000MessageSkipHost : RecordingHost
|
||||
{
|
||||
public VirtualMachine Vm = null!;
|
||||
|
||||
public override void WaitForInput(int layoutSlot, Func<bool> serviceInputCallback,
|
||||
Func<AdvAutoWaitState> autoWaitState)
|
||||
{
|
||||
Vm.UpdatePointer(728, 572);
|
||||
while (serviceInputCallback()) { }
|
||||
Assert.True(Vm.TryActivatePointer(728, 572));
|
||||
while (serviceInputCallback()) { }
|
||||
throw new StopAtFirstWaitException();
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class AutoStateHost : RecordingHost
|
||||
{
|
||||
public AdvAutoWaitState State;
|
||||
@@ -209,6 +224,51 @@ public class HotspotInputTests
|
||||
Assert.False(resetHost.State.VoicePending);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MessageSkipOpcodes_RetainStateAcrossTransientResetUntilExplicitlyDisabled()
|
||||
{
|
||||
var table = OpcodeTableJson.Load(Paths.OpcodesJson);
|
||||
var script = ScriptAssembler.Assemble(table, "MESSAGE_SKIP", new List<(int, Operand[])>
|
||||
{
|
||||
(0x88, new[] { I(1) }),
|
||||
(0x19a, new[] { G(0x140) }),
|
||||
(0x1c7, new[] { G(0x141) }),
|
||||
(0x101, Array.Empty<Operand>()),
|
||||
(0x1c7, new[] { G(0x142) }),
|
||||
(0x88, new[] { I(0) }),
|
||||
(0x19a, new[] { G(0x143) }),
|
||||
(0x2, Array.Empty<Operand>()),
|
||||
}, Array.Empty<string>());
|
||||
var host = new RecordingHost();
|
||||
var vm = new VirtualMachine(script, table, host);
|
||||
|
||||
vm.Run();
|
||||
|
||||
Assert.Equal(1, vm.Globals.GetValueOrDefault(0x140));
|
||||
Assert.Equal(1, vm.Globals.GetValueOrDefault(0x141));
|
||||
Assert.Equal(1, vm.Globals.GetValueOrDefault(0x142));
|
||||
Assert.Equal(0, vm.Globals.GetValueOrDefault(0x143));
|
||||
Assert.False(vm.MessageSkipEnabled);
|
||||
Assert.Equal(new[] { true, false }, host.MessageSkipChanges);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Sc0000MessageSkipButton_EnablesPersistentServiceState()
|
||||
{
|
||||
var table = OpcodeTableJson.Load(Paths.OpcodesJson);
|
||||
var script = Sys4Loader.Load(Paths.Scripts()["SC0000.BIN"], table);
|
||||
var host = new Sc0000MessageSkipHost();
|
||||
var vm = new VirtualMachine(script, table, host, new VmOptions(MaxSteps: 1_000_000));
|
||||
host.Vm = vm;
|
||||
vm.Globals[0x6c1] = 1;
|
||||
|
||||
Assert.Throws<StopAtFirstWaitException>(() => vm.Run());
|
||||
|
||||
Assert.True(vm.MessageSkipEnabled);
|
||||
Assert.True(host.MessageSkip);
|
||||
Assert.Contains(true, host.MessageSkipChanges);
|
||||
}
|
||||
|
||||
private static Operand I(long value) => new(0, value);
|
||||
private static Operand G(long address) => new(3, address);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ internal class RecordingHost : IHost
|
||||
public readonly List<int> SfxReleases = new();
|
||||
public readonly List<(int Target, long Duration)> BgmFades = new();
|
||||
public readonly List<(long Resource, int Surface, long Flags, long SyncMask)> Movies = new();
|
||||
public readonly List<bool> MessageSkipChanges = new();
|
||||
public void ShowText(int offset, string text) => Lines.Add((offset, text));
|
||||
public void SetAdvTextCursor(int layoutSlot, int x, int y) => TextCursors.Add((layoutSlot, x, y));
|
||||
public void DrawStringToSurface(int surfaceSlot, int x, int y, string text)
|
||||
@@ -42,6 +43,11 @@ internal class RecordingHost : IHost
|
||||
public void Sleep(long duration) => SleptDurations.Add(duration);
|
||||
public void FrameYield() { }
|
||||
public bool IsMessageSkipActive => MessageSkip;
|
||||
public void SetMessageSkipActive(bool active)
|
||||
{
|
||||
MessageSkip = active;
|
||||
MessageSkipChanges.Add(active);
|
||||
}
|
||||
public bool IsAdvReadSkipActive => AdvReadSkip;
|
||||
public void PresentFrame(GfxState gfx)
|
||||
{
|
||||
|
||||
@@ -36,6 +36,7 @@ public interface IHost
|
||||
void FrameYield();
|
||||
// Native 0x1c7/0x1cc query two distinct ADV skip channels. Headless and non-interactive
|
||||
// hosts default to normal playback; the Godot host supplies the live interactive values.
|
||||
void SetMessageSkipActive(bool active) { }
|
||||
bool IsMessageSkipActive => false;
|
||||
bool IsAdvReadSkipActive => false;
|
||||
// Normal playback reaches op 0x21c and parks until a queued 0x223 transition completes. The
|
||||
|
||||
@@ -30,6 +30,7 @@ public sealed class VirtualMachine
|
||||
private long _autoMessageTime0Ms = 500;
|
||||
private long _autoMessageTime1Ms = 2000;
|
||||
private bool _autoVoicePending;
|
||||
private volatile bool _messageSkipEnabled;
|
||||
public long CallScriptDispatches { get; private set; }
|
||||
|
||||
public Dictionary<int, long> Globals { get; } = new();
|
||||
@@ -41,6 +42,7 @@ public sealed class VirtualMachine
|
||||
public string? HaltReason { get; private set; }
|
||||
public long Steps { get; private set; }
|
||||
public bool AutoMessageEnabled => _autoMessageEnabled;
|
||||
public bool MessageSkipEnabled => _messageSkipEnabled;
|
||||
|
||||
public VirtualMachine(Script s, OpcodeTable t, IHost host, VmOptions? o = null,
|
||||
IScriptProvider? provider = null, ITraceSink? sink = null)
|
||||
@@ -426,8 +428,17 @@ public sealed class VirtualMachine
|
||||
return pc + 1;
|
||||
case "sleep": // 0xc8 (duration) — pause the host duration ms; headless hosts no-op (parity). Frame pacing.
|
||||
_host.Sleep(Read(a[0])); return pc + 1;
|
||||
case "get-message-skip": // 0x1c7: Ctrl/message fast-forward run-state bit
|
||||
Write(a[0], _host.IsMessageSkipActive ? 1 : 0); return pc + 1;
|
||||
case "u0041B290":
|
||||
case "set-message-skip": // 0x88: persistent all-message fast-forward service state
|
||||
_messageSkipEnabled = Read(a[0]) != 0;
|
||||
_host.SetMessageSkipActive(_messageSkipEnabled);
|
||||
return pc + 1;
|
||||
case "u00414E50": // 0x19a: persistent state used by the SO001 active overlay
|
||||
Write(a[0], _messageSkipEnabled ? 1 : 0); return pc + 1;
|
||||
case "get-message-skip": // 0x1c7: persistent Skip or host-supplied Ctrl fast-forward
|
||||
// The native per-op tick continually re-arms the transient run-state bit while op 0x88's
|
||||
// persistent flag is set. The host channel carries the physically held Ctrl/input source.
|
||||
Write(a[0], _messageSkipEnabled || _host.IsMessageSkipActive ? 1 : 0); return pc + 1;
|
||||
case "get-adv-read-skip-state": // 0x1cc: per-message read/click skip service state
|
||||
case "get-adv-service-state": // compatibility with pre-recovery generated tables
|
||||
Write(a[0], _host.IsAdvReadSkipActive ? 1 : 0); return pc + 1;
|
||||
@@ -449,6 +460,9 @@ public sealed class VirtualMachine
|
||||
case "block-mark":
|
||||
case "reset-message-voice-state": // 0x1bc resets native per-message voice/queued-voice state
|
||||
_autoVoicePending = false; return pc + 1;
|
||||
case "u00415BF0":
|
||||
case "reset-message-skip-input": // 0x101 clears transient input/run bits, not op 0x88 state
|
||||
return pc + 1;
|
||||
case "end-text-line": case "set-font":
|
||||
case "comment": case "display-furigana": case "dev_ukn":
|
||||
return pc + 1;
|
||||
|
||||
Reference in New Issue
Block a user