feat(a2a): add IHost.WaitForInput hook (wait-for-input 0x72); trace parity preserved
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
31
engine/Age.Engine.Tests/WaitForInputTests.cs
Normal file
31
engine/Age.Engine.Tests/WaitForInputTests.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Age.Engine.Hosting;
|
||||||
|
using Age.Engine.Sys4;
|
||||||
|
using Age.Engine.Vm;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
public class WaitForInputTests
|
||||||
|
{
|
||||||
|
private sealed class CountHost : IHost
|
||||||
|
{
|
||||||
|
public int Waits;
|
||||||
|
public List<int> Emitted = new();
|
||||||
|
public void ShowText(int offset, string text) => Emitted.Add(offset);
|
||||||
|
public void CallScript(long id) { }
|
||||||
|
public void OnStub(int opcode) { }
|
||||||
|
public void WaitForInput() => Waits++;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WaitForInputFiresAndEmittedIsStable()
|
||||||
|
{
|
||||||
|
var table = OpcodeTableJson.Load(Paths.OpcodesJson);
|
||||||
|
var script = Sys4Loader.Load(Paths.Scripts()["SC0000.BIN"], table);
|
||||||
|
var host = new CountHost();
|
||||||
|
var vm = new VirtualMachine(script, table, host);
|
||||||
|
vm.Run();
|
||||||
|
Assert.True(host.Waits > 0, "wait-for-input (0x72) should fire at least once");
|
||||||
|
Assert.Equal(186, host.Emitted.Count); // unchanged vs the A1 SC0000 trace
|
||||||
|
Assert.Equal("exit", vm.HaltReason);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,4 +7,5 @@ public sealed class CaptureHost : IHost
|
|||||||
public void ShowText(int offset, string text) => Emitted.Add((offset, text));
|
public void ShowText(int offset, string text) => Emitted.Add((offset, text));
|
||||||
public void CallScript(long id) => CallScriptCount++;
|
public void CallScript(long id) => CallScriptCount++;
|
||||||
public void OnStub(int opcode) { Stubs.TryGetValue(opcode, out var c); Stubs[opcode] = c + 1; }
|
public void OnStub(int opcode) { Stubs.TryGetValue(opcode, out var c); Stubs[opcode] = c + 1; }
|
||||||
|
public void WaitForInput() { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ public interface IHost
|
|||||||
void ShowText(int offset, string text);
|
void ShowText(int offset, string text);
|
||||||
void CallScript(long id);
|
void CallScript(long id);
|
||||||
void OnStub(int opcode);
|
void OnStub(int opcode);
|
||||||
|
void WaitForInput();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,7 +164,8 @@ public sealed class VirtualMachine
|
|||||||
_host.ShowText(off, text);
|
_host.ShowText(off, text);
|
||||||
}
|
}
|
||||||
return pc + 1;
|
return pc + 1;
|
||||||
case "end-text-line": case "wait-for-input": case "set-font":
|
case "wait-for-input": _host.WaitForInput(); return pc + 1;
|
||||||
|
case "end-text-line": case "set-font":
|
||||||
case "comment": case "display-furigana": case "dev_ukn":
|
case "comment": case "display-furigana": case "dev_ukn":
|
||||||
return pc + 1;
|
return pc + 1;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user