upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/audio_hal_exe_calls.md20
-rw-r--r--docs/runtime_imports.md26
2 files changed, 34 insertions, 12 deletions
diff --git a/docs/audio_hal_exe_calls.md b/docs/audio_hal_exe_calls.md
index c04943c7d..a500e16fc 100644
--- a/docs/audio_hal_exe_calls.md
+++ b/docs/audio_hal_exe_calls.md
@@ -52,6 +52,26 @@ turns such an address back into a pointer. That is an inference from the shapes;
52`XApuEnqueueCommand` and `XApuDequeueResult` share one handle global, which `XApuDisconnect` clears: a command queue 52`XApuEnqueueCommand` and `XApuDequeueResult` share one handle global, which `XApuDisconnect` clears: a command queue
53with a result queue, connected once and torn down once. How `chad.dll`'s handle relates to it is not read. 53with a result queue, connected once and torn down once. How `chad.dll`'s handle relates to it is not read.
54 54
55`runtime/shims/xapu_queue.cpp` serves the five `xapu.dll` imports and `runtime/shims/xapu_chad.cpp` the five
56`chad.dll` ones.
57The `xapu.dll` signatures, structure layouts, command kinds, option bits and error codes come from Marvisak/VIctory
58(<https://github.com/Marvisak/VIctory>, GPL-3.0-or-later, `crates/victory-hle/src/modules/apu.rs` at commit `ffe310e`),
59which runs the retail executable through these calls. Only the facts are used (see
60[related_projects.md](related_projects.md)); the top of `xapu_queue.cpp` lists them. They agree with the shapes above:
61
62| Shape measured here | What the layout says |
63|---|---|
64| `XApuConnect`: a 24-byte title global first, a 16-byte output second | the global is an input of six dwords (processing kind, streams, commands per stream, memory bytes, frames per output, options); the output is the zeroed memory and a result event |
65| `XApuEnqueueCommand`: a stack-built command whose first dword is 1, 2 or 3 and second a stream slot, then 0 | a 24-byte command id (kind, stream, sequence, options, context): 1 activates, 2 deactivates, 3 processes an Opus packet; the third argument is an optional count of the commands accepted |
66| `XApuDequeueResult`: a 0x50-byte result, read at +0, +4 and +0x34 | the command id at +0, the output byte count at +0x34; `0x8AC81001` while none is ready |
67| `XApuDisconnect`: the handle, then `0x20` | the second argument is not read |
68
69What the results carry is the shim's own: each accepted command gets one result in command order, with the error codes
70of the layout. A process result carries the frame count and PCM when `runtime/opus_decoder` is built, and otherwise the
71frame count of the Opus packet's table-of-contents byte (RFC 6716, section 3.1) with zeros in its output (silence).
72`xapu_chad_test` covers the layouts and the silent path; `xapu_opus_test` covers the decoded path with a generated
73packet.
74
55## `xg_xs.dll` and `XCRDAPI.dll` 75## `xg_xs.dll` and `XCRDAPI.dll`
56 76
57| Import | Sites | What the sites show | 77| Import | Sites | What the sites show |
diff --git a/docs/runtime_imports.md b/docs/runtime_imports.md
index e38dfbf74..e408d223d 100644
--- a/docs/runtime_imports.md
+++ b/docs/runtime_imports.md
@@ -170,7 +170,7 @@ policy "other" (none is counted as returning an `HRESULT`), and they come from s
170| `xg_xs.dll` | 2: `XGCreateTextureComputer`, `XGSuggestSwizzleMode` | texture layout computation | 170| `xg_xs.dll` | 2: `XGCreateTextureComputer`, `XGSuggestSwizzleMode` | texture layout computation |
171| `XCRDAPI.dll` | 1: `DStorageGetFactory` | DirectStorage | 171| `XCRDAPI.dll` | 1: `DStorageGetFactory` | DirectStorage |
172| `chad.dll` | 5: `XDspActivate`, `XDspConnectWithMaximumStreamLimit`, `XDspDeactivate`, `XDspDisconnect`, `XDspSubmitCommand` | the audio DSP | 172| `chad.dll` | 5: `XDspActivate`, `XDspConnectWithMaximumStreamLimit`, `XDspDeactivate`, `XDspDisconnect`, `XDspSubmitCommand` | the audio DSP |
173| `xapu.dll` | 5: `XApuConnect`, `XApuDequeueResult`, `XApuDisconnect`, `XApuEnqueueCommand`, `XApuGetResultCount` | the audio processing unit | 173| `xapu.dll` | 5: `XApuConnect`, `XApuDequeueResult`, `XApuDisconnect`, `XApuEnqueueCommand`, `XApuGetResultCount` | the audio processing unit (Opus decode when `runtime/opus_decoder` is built) |
174| `AcpHal.dll` | 9: `AcpHalAllocateShapeContexts`, `AcpHalCreate`, `AcpHalReleaseShapeContexts`, `ApuAlloc`, `ApuCreateHeap`, `ApuFree`, `ApuIsVirtualAddressValid`, `ApuMapApuAddress`, `ApuMapVirtualAddress` | the audio hardware layer | 174| `AcpHal.dll` | 9: `AcpHalAllocateShapeContexts`, `AcpHalCreate`, `AcpHalReleaseShapeContexts`, `ApuAlloc`, `ApuCreateHeap`, `ApuFree`, `ApuIsVirtualAddressValid`, `ApuMapApuAddress`, `ApuMapVirtualAddress` | the audio hardware layer |
175 175
176The game executable imports two functions from `xg_xs.dll`, the console's texture layout library: 176The game executable imports two functions from `xg_xs.dll`, the console's texture layout library:
@@ -203,17 +203,19 @@ again at detach (reason 0), and there is no `exception`, `error` or `unimplement
203unimplemented imports is reached by the TLS callbacks or the `DllMain`s. 203unimplemented imports is reached by the TLS callbacks or the `DllMain`s.
204 204
205The executable's audio imports `xapu.dll` (`XApuConnect`, `XApuDequeueResult`, `XApuDisconnect`, 205The executable's audio imports `xapu.dll` (`XApuConnect`, `XApuDequeueResult`, `XApuDisconnect`,
206`XApuEnqueueCommand`, `XApuGetResultCount`) and `chad.dll` (`XDspActivate`, `XDspConnectWithMaximumStreamLimit`, 206`XApuEnqueueCommand`, `XApuGetResultCount`) are served by `runtime/shims/xapu_queue.cpp`; `chad.dll`
207`XDspDeactivate`, `XDspDisconnect`, `XDspSubmitCommand`) are served by `runtime/shims/xapu_chad.cpp`. The shapes were 207(`XDspActivate`, `XDspConnectWithMaximumStreamLimit`, `XDspDeactivate`, `XDspDisconnect`, `XDspSubmitCommand`) by
208read statically from the executable's call sites: one each, four for `XApuEnqueueCommand`. Both connects succeed with 208`runtime/shims/xapu_chad.cpp`. The shapes were read statically from the executable's call sites: one each, four for
209a handle; the APU connect also returns a zeroed shared buffer the title writes stream input to and reads output from. 209`XApuEnqueueCommand`. `XApuConnect` reads the title's 24-byte `ConnectInput` (process 1 = Opus at 48 kHz, stream
210Commands are accepted and not processed, so the audio stays silent. A stream open (type 1) and a stream close 210count, commands per stream, a shared buffer, options) and returns `{shared buffer, result event}`; it never writes the
211(type 2) each queue one result of the same type and slot, because the title frees a stream id only when the close 211input. Activate, process, deactivate and reset commands are copied from the title's stack command, and each queues one
212result arrives. `XDspActivate` writes its two outputs as pointers to zeroed memory, which the title reads as "command 212result in order. A process command decodes its Opus packet through `runtime/opus_decoder` (Rust over the BSD-3-Clause
213done" after each `XDspSubmitCommand`. `XApuConnect` leaves its first argument, a global of the title, untouched. The 213`opus-pure`) into the slot's output, honouring first frame, frame count, output length and the deinterleaved option;
214buffer size (128 stream slots), the two results and the zeroed DSP status are hypotheses, explained in the file. 214without the crate the result carries the table-of-contents frame count and silence. The layouts follow Marvisak/VIctory
215`xapu_chad_test` calls all ten in those shapes. With `--trace`, the first call of each, and the first command of each type, is an 215`crates/victory-hle/src/modules/apu.rs` (GPL-3.0-or-later). `XDspActivate` writes its two outputs as pointers to zeroed
216`audio_queue` event. 216memory, which the title reads as "command done" after each `XDspSubmitCommand`; the DSP stays silent. `xapu_chad_test`
217covers the layouts, the queue and the silent path; `xapu_opus_test` the decoded path. With `--trace`, the first call of
218each, and the first command of each type, is an `audio_queue` event.
217The table above was measured before this shim and still lists these ten as unimplemented; they are served now. The call shapes agree with `docs/audio_hal_exe_calls.md`, which was measured with `tools/import_call_sites.py`. 219The table above was measured before this shim and still lists these ten as unimplemented; they are served now. The call shapes agree with `docs/audio_hal_exe_calls.md`, which was measured with `tools/import_call_sites.py`.
218 220
219What this does not show: `--run` has not been run, so the entry point has not been called and no import is known to be 221What this does not show: `--run` has not been run, so the entry point has not been called and no import is known to be