From 2b31e0945e7575d16901a799397f8b90a7de0e54 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Mon, 6 Jul 2026 15:49:07 -0400 Subject: [PATCH] feat(a2b): promote create/set/draw-texture to IHost methods (trace parity kept) Runtime finding: SC0000's bg is a slot-0 full-screen slideshow (res 0x23 first), not the static-path res 0x21. Target corrected to 0x23. CaptureHost/CountHost no-op the new methods. Co-Authored-By: Claude Opus 4.8 (1M context) --- engine/Age.Engine.Tests/TextureOpsTests.cs | 35 ++++++++++++++++++++ engine/Age.Engine.Tests/WaitForInputTests.cs | 3 ++ engine/Age.Engine/Hosting/CaptureHost.cs | 3 ++ engine/Age.Engine/Hosting/IHost.cs | 3 ++ engine/Age.Engine/Vm/VirtualMachine.cs | 6 ++++ 5 files changed, 50 insertions(+) create mode 100644 engine/Age.Engine.Tests/TextureOpsTests.cs diff --git a/engine/Age.Engine.Tests/TextureOpsTests.cs b/engine/Age.Engine.Tests/TextureOpsTests.cs new file mode 100644 index 0000000..26fcf99 --- /dev/null +++ b/engine/Age.Engine.Tests/TextureOpsTests.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using Age.Engine.Hosting; +using Age.Engine.Sys4; +using Age.Engine.Vm; +using Xunit; + +public class TextureOpsTests +{ + private sealed class RecHost : IHost + { + public List<(long resId, int slot)> Sets = new(); + public List<(int slot, int w, int h)> Draws = new(); + public int Creates; + public void ShowText(int o, string t) { } + public void CallScript(long id) { } + public void OnStub(int op) { } + public void WaitForInput() { } + public void CreateTexture(int slot, int w, int h) => Creates++; + public void SetTexture(long resId, int slot) => Sets.Add((resId, slot)); + public void DrawTexture(int slot, int x, int y, int w, int h) => Draws.Add((slot, w, h)); + } + + [Fact] + public void SC0000FiresTextureOpsWithSlot0FullScreenSlideshow() + { + var table = OpcodeTableJson.Load(Paths.OpcodesJson); + var script = Sys4Loader.Load(Paths.Scripts()["SC0000.BIN"], table); + var host = new RecHost(); + new VirtualMachine(script, table, host).Run(); + Assert.True(host.Creates > 0, "create-texture should fire"); + // The intro loads a sequence of full-screen images into slot 0; res 0x23 is the first bg. + Assert.Contains(host.Sets, s => s.resId == 0x23 && s.slot == 0); + Assert.Contains(host.Draws, d => d.slot == 0 && d.w == 0x320 && d.h == 0x258); + } +} diff --git a/engine/Age.Engine.Tests/WaitForInputTests.cs b/engine/Age.Engine.Tests/WaitForInputTests.cs index 881e542..4c5067d 100644 --- a/engine/Age.Engine.Tests/WaitForInputTests.cs +++ b/engine/Age.Engine.Tests/WaitForInputTests.cs @@ -14,6 +14,9 @@ public class WaitForInputTests public void CallScript(long id) { } public void OnStub(int opcode) { } public void WaitForInput() => Waits++; + public void CreateTexture(int slot, int w, int h) { } + public void SetTexture(long resId, int slot) { } + public void DrawTexture(int slot, int x, int y, int w, int h) { } } [Fact] diff --git a/engine/Age.Engine/Hosting/CaptureHost.cs b/engine/Age.Engine/Hosting/CaptureHost.cs index e01521e..717042e 100644 --- a/engine/Age.Engine/Hosting/CaptureHost.cs +++ b/engine/Age.Engine/Hosting/CaptureHost.cs @@ -8,4 +8,7 @@ public sealed class CaptureHost : IHost public void CallScript(long id) => CallScriptCount++; public void OnStub(int opcode) { Stubs.TryGetValue(opcode, out var c); Stubs[opcode] = c + 1; } public void WaitForInput() { } + public void CreateTexture(int slot, int width, int height) { } + public void SetTexture(long resourceId, int slot) { } + public void DrawTexture(int slot, int x, int y, int width, int height) { } } diff --git a/engine/Age.Engine/Hosting/IHost.cs b/engine/Age.Engine/Hosting/IHost.cs index 8b4286d..3c21436 100644 --- a/engine/Age.Engine/Hosting/IHost.cs +++ b/engine/Age.Engine/Hosting/IHost.cs @@ -5,4 +5,7 @@ public interface IHost void CallScript(long id); void OnStub(int opcode); void WaitForInput(); + void CreateTexture(int slot, int width, int height); + void SetTexture(long resourceId, int slot); + void DrawTexture(int slot, int x, int y, int width, int height); } diff --git a/engine/Age.Engine/Vm/VirtualMachine.cs b/engine/Age.Engine/Vm/VirtualMachine.cs index f64366d..48fec88 100644 --- a/engine/Age.Engine/Vm/VirtualMachine.cs +++ b/engine/Age.Engine/Vm/VirtualMachine.cs @@ -168,6 +168,12 @@ public sealed class VirtualMachine case "end-text-line": case "set-font": case "comment": case "display-furigana": case "dev_ukn": return pc + 1; + case "create-texture": + _host.CreateTexture((int)Read(a[0]), (int)Read(a[1]), (int)Read(a[2])); return pc + 1; + case "set-texture": + _host.SetTexture(Read(a[0]), (int)Read(a[1])); return pc + 1; + case "draw-texture": + _host.DrawTexture((int)Read(a[1]), (int)Read(a[2]), (int)Read(a[3]), (int)Read(a[4]), (int)Read(a[5])); return pc + 1; default: _host.OnStub(op); return pc + 1; }